[gcj] Re: Cryptopanagrams

2020-04-03 Thread PAGADALA SAINADTH
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Solution {
static Scanner sc = new Scanner(System.in);

public static void main(String args[]) {
int te = sc.nextInt();
for (int i = 0; i < te; i++) {
BigInteger n = sc.nextBigInteger();
int l = sc.nextInt();
BigInteger[] products = new BigInteger[l];
for (int j = 0; j < l; j++) {
products[j] = sc.nextBigInteger();
}
BigInteger[] primes = new BigInteger[l + 1];

int k = 0;
for (int j = 0; j < l; j++) {
Map.Entry temp = primeFactors
(products[j]);
if (j == 0) {
// initially both the prime factors should be inserted 
Map.Entry temp1 = primeFactors
(products[j + 1]);
if (temp.getKey().equals(temp1.getKey()) || temp.getKey
().equals(temp1.getValue())) {
primes[k] = temp.getValue();
primes[++k] = temp.getKey();
} else {
primes[k] = temp.getKey();
primes[++k] = temp.getValue();
}
} else if (temp.getKey().equals(primes[k - 1])) { 
// one the prime divides with previous product value so we need to skip it
primes[k] = temp.getValue();
} else {
primes[k] = temp.getKey();
}
k++;
}
for (int j = 0; j < primes.length; j++) {
System.out.println(primes[j]);
}
Set set = new HashSet<>();
Collections.addAll(set, primes); 
// removes duplicates from primes
List alpha = new ArrayList(set);
Collections.sort(alpha); // sorts the List
String s = "";
for (int j = 0; j < primes.length; j++) {
s += (char) ('A' + alpha.indexOf(primes[j])); 
// append charecters to string s
}
System.out.print("Case #" + Integer.toString(i + 1) + ": " + s);
System.out.println();
}

}


/* Generate Prime Factors returns a key, value pair which are factors of 
BigInteger */
public static Map.Entry primeFactors(BigInteger 
n) {
BigInteger x = BigInteger.valueOf(2);
Map.Entry temp = new AbstractMap.SimpleEntry
(x, x);
if (n.mod(x).equals(BigInteger.valueOf(0))) {
temp = new AbstractMap.SimpleEntry(BigInteger.valueOf(2), n.
divide(BigInteger.valueOf(2)));
return temp;
}
for (BigInteger i = BigInteger.valueOf(3); i.multiply(i).compareTo
(n) <= 0; i = i.add(x)) {
if (n.mod(i).equals(BigInteger.valueOf(0))) {
temp = new AbstractMap.SimpleEntry(i, n.divide(i));
return temp;
}
}
return temp;
}
}

This i have written the code in java using BigInteger. Though i executes 
correctly for various inputs and outputs, it results in WA. Could any one 
please check this once?

On Tuesday, March 31, 2020 at 11:29:54 PM UTC+5:30, porker2008 wrote:
>
> C++ does not have built-in support for big integers
>
> You can consider using other languages like python or Java(BigInteger)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/4d1ba38c-cb72-4220-af55-b3fa176cece7%40googlegroups.com.


Re: [gcj] Re: Cryptopanagrams

2020-04-01 Thread driss kahfy
Hello, I rewrite my code ; it is runing  well with yout test case but I had
the same error message "RE" when I submitted it :




















































*import mathPremier =

Re: [gcj] Re: Cryptopanagrams

2020-04-01 Thread paulmcq
No need to roll your own bignum for C++. For example, use GMP:
https://gmplib.org/manual/C_002b_002b-Interface-General.html

On Wednesday, April 1, 2020 at 5:25:29 AM UTC-5, /dev/joe wrote:
>
> That is the trade-off you face when choosing a language. Some languages 
> may have more helpful features but be slower. In this case, once you start 
> doing math with bignums the speed advantage may be mostly negated, plus you 
> spend time coding up your own bignum class in C++. I will point out this 
> relevant bit from the FAQ, however:
> During the round, can I use code written before the round?
>
> As long as you have a license to use it, yes. That means you can write 
> your own helper code, or collect your own personal library of code, as long 
> as the license terms of the code permit it. Some Code Jam contestants will 
> have competed on an ACM ICPC team, and many of those teams have their own 
> code books; check with your team's coach whether it's permissible for you 
> to use that code in a different context.
>
>
> On Tue, Mar 31, 2020 at 10:23 PM PAGADALA SAINADTH  > wrote:
>
>> hmm got it. But in general, python and java results in more execution 
>> time when compared to c++ right? Is there any alternative when the input is 
>> 10^100 *?.*
>> Any way thanks for the reply .
>>
>> On Tuesday, March 31, 2020 at 11:29:54 PM UTC+5:30, porker2008 wrote:
>>>
>>> C++ does not have built-in support for big integers
>>>
>>> You can consider using other languages like python or Java(BigInteger)
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Code Jam" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to googl...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/google-code/0c3f36b0-5e45-4043-a77c-2d66299cad6c%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/8100d667-f728-4149-b655-a173a702b0e0%40googlegroups.com.


Re: [gcj] Re: Cryptopanagrams

2020-04-01 Thread Joseph DeVincentis
That is the trade-off you face when choosing a language. Some languages may
have more helpful features but be slower. In this case, once you start
doing math with bignums the speed advantage may be mostly negated, plus you
spend time coding up your own bignum class in C++. I will point out this
relevant bit from the FAQ, however:
During the round, can I use code written before the round?

As long as you have a license to use it, yes. That means you can write your
own helper code, or collect your own personal library of code, as long as
the license terms of the code permit it. Some Code Jam contestants will
have competed on an ACM ICPC team, and many of those teams have their own
code books; check with your team's coach whether it's permissible for you
to use that code in a different context.


On Tue, Mar 31, 2020 at 10:23 PM PAGADALA SAINADTH <
sainadth1123...@gmail.com> wrote:

> hmm got it. But in general, python and java results in more execution time
> when compared to c++ right? Is there any alternative when the input is
> 10^100 *?.*
> Any way thanks for the reply .
>
> On Tuesday, March 31, 2020 at 11:29:54 PM UTC+5:30, porker2008 wrote:
>>
>> C++ does not have built-in support for big integers
>>
>> You can consider using other languages like python or Java(BigInteger)
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/0c3f36b0-5e45-4043-a77c-2d66299cad6c%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAMAzhziw8dKN1Q3MQpRuAJ2g0Vg0cKV-2RC1_O6V-Q3raU0KsQ%40mail.gmail.com.


[gcj] Re: Cryptopanagrams

2020-03-31 Thread PAGADALA SAINADTH
hmm got it. But in general, python and java results in more execution time 
when compared to c++ right? Is there any alternative when the input is 
10^100 *?.*
Any way thanks for the reply .

On Tuesday, March 31, 2020 at 11:29:54 PM UTC+5:30, porker2008 wrote:
>
> C++ does not have built-in support for big integers
>
> You can consider using other languages like python or Java(BigInteger)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/0c3f36b0-5e45-4043-a77c-2d66299cad6c%40googlegroups.com.


[gcj] Re: Cryptopanagrams

2020-03-31 Thread porker2008
C++ does not have built-in support for big integers

You can consider using other languages like python or Java(BigInteger)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/5740ed59-b347-4531-867f-47f618c89429%40googlegroups.com.


[gcj] Re: Cryptopanagrams

2020-03-31 Thread PAGADALA SAINADTH
https://github.com/sainadth/CodeJam2019/blob/master/Cryptopangrams.cpp
I have written the code in c++ even satisfying your test case. But it 
results in WA
Could please help me dude?

On Tuesday, March 31, 2020 at 6:20:26 AM UTC+5:30, porker2008 wrote:
>
> you can try the following test case
>
> 1
> 10 3
> 9 9 15
>
> Expected output would be
>
> Case #1: AAAB
>
> Explanation 
>
> A = 3
> B = 5
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/fbd894c4-469d-42ad-9202-cb1f9b4dcff8%40googlegroups.com.


[gcj] Re: Cryptopanagrams

2020-03-30 Thread porker2008
you can try the following test case

1
10 3
9 9 15

Expected output would be

Case #1: AAAB

Explanation 

A = 3
B = 5

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/efd1f928-abf9-43a9-95d0-e7b193d237c7%40googlegroups.com.


[gcj] Re: Cryptopanagrams Python3 algorithm works on my computer, not on Google's interface

2019-04-08 Thread F S
On Sunday, April 7, 2019 at 11:20:55 PM UTC+2, Michael wrote:
> My Cryptopangrams gave the correct output for the sample input when I ran it 
> on my computer, however, it did not give the correct output when I ran it on 
> Google's competition interface. Please, any help is greatly appreciated.
> When I run the sample inputs on my computer I get:
> Case #1: CJQUIZKNOWBEVYOFDPFLUXALGORITHMS
> Case #2: SUBDERMATOGLYPHICFJKNQVWXZ
> But when I run the sample inputs on Google's Server, I get: 
> Case #1: COZGNSRVXKBFWMXHEYHTGPATIXQNDJUL
> Case #2: CVJUKGNBHYWTQOIASMXDZLEFPR
> 
> 
> #!/usr/bin/env python3
> # -*- coding: utf-8 -*-
> """
> Created on Fri Apr  5 18:03:33 2019
> 
> @author: michaels
> """
> import string
> 
> def GCD(a,b):
> while a!=0 and b!=0:
> remainder = a % b
> a = b
> b = remainder
> if a==0:
> return b
> if b==0:
> return a
> 
> def output(message):
> for i in range(len(message)):
> print("Case #" + str(i+1) + ": " + str(message[i]))
>   
> def characters(primes):
> uppercase = string.ascii_uppercase
> dictionary = {}
> for i in range(len(primes)):
> dictionary[primes[i]] = uppercase[i]
> return dictionary
> 
> 
> def findPrimes(NandL, numbers):
> primes = []
> charNumbers = []
> for i in range(NandL[1]-1):
> primes.append(GCD(numbers[i], numbers[i+1]))
> charNumbers.append(int(numbers[0]/primes[0])) 
> for i in range(len(primes)):
> charNumbers.append(primes[i])
> charNumbers.append(int(numbers[-1]/primes[-1])) 
> return charNumbers
> 
> def sort(primes): 
> for i in range(len(primes)):
> minimum = i
> for x in range(i + 1, len(primes)):
> if primes[x] < primes[minimum]:
> minimum = x
> primes[minimum], primes[i] = primes[i], primes[minimum]
> primes = list(dict.fromkeys(primes))
> return primes
> 
> def findMessage(charPrimes, sortedPrimes):
> message = ""
> characters = string.ascii_uppercase
> dictionary = {}
> for i in range(len(characters)):
> dictionary[sortedPrimes[i]] = characters[i]
> for i in range(len(charPrimes)):
> message = message + dictionary[charPrimes[i]]
> return message
> 
> def inputs():
> NandL = (str(input()))
> NandL = [int(s) for s in NandL.split() if s.isdigit()]
> L = str(input())
> numbers = [int(s) for s in L.split() if s.isdigit()]
> charPrimes = findPrimes(NandL, numbers)
> sortedPrimes = charPrimes.copy()
> sortedPrimes = sort(sortedPrimes)
> message = findMessage(charPrimes, sortedPrimes)
> return message
> 
> 
> if __name__ == "__main__":
> 
> T = int(input())
> message = []
> for i in range(T):
> message.append(inputs())
> 
> output(message)


Are you sure that the following:

primes = list(dict.fromkeys(primes)) 
return primes 

will keep the order of the primes? It is extremely weird to create a dict from 
an array to create a list. I must be missing something.

Also, why do you re-implement your own sort? I feel weird that you know about 
dict.fromkeys(), but don't know about sort()... This whole function is just 
"return sorted( set( primes ) )"

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/70d32c2d-79c5-4b6e-bbba-a8580c6daf18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.