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. I want
to learn from my mistakes.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 5 18:03:33 2019
@author: michaelsexton
"""
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)
--
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/78fb9c71-085a-4306-838d-ae3ab29d6cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.