This was my solution for CodeJam Qualification Round
Question 3 : CryptoPangrams
link :
https://codingcompetitions.withgoogle.com/codejam/round/0000000000051705/000000000008830b
I am getting a correct answer for the 2 sample cases provided but it fails in
all the test cases. I tried setting Errors for Please suggest!
I
``
import string
def main(N, numbers):
primelist, numlist = [], []
firsti, n1, n2 = None , None, None
def primes_gen(N):
out = list()
check = [True] * (N+1)
for p in range(2, N+1):
if (check[p]):
out.append(p)
for i in range(p, N+1, p):
check[i] = False
return out
primelist = primes_gen(N)
for i in primelist:
if numbers[0] % i == 0:
firsti = i
break
secondi = numbers[0] / firsti
if numbers[1] % firsti == 0:
n1 = secondi
n2 = firsti
else:
n1 = firsti
n2 = secondi
numlist.append(n1)
numlist.append(n2)
numbers.pop(0)
def listgen(numbers, n2):
nx = numbers[0] / n2
numlist.append(nx)
if len(numbers) > 1:
numbers.pop(0)
listgen(numbers,nx)
listgen(numbers,n2)
newlist = (list(set(numlist)))
newlist.sort()
dictionary = dict(zip(newlist, list(string.ascii_uppercase)))
result = []
for i in numlist:
a = dictionary[i]
result.append(a)
return (''.join(map(str,result)))
T = int(input())
for i in range(T):
N, n = map(int,input().split())
if n < 25:
raise ValueError()
numbers = [int(k) for k in input().split()]
if len(numbers) != n:
raise ValueError()
print ('Case #' + str(i+1) + ':' + ' ' + str(main(N,numbers)))
``
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/af572abe-0fe4-45b4-a4c6-e5e09472303c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.