Last active
September 9, 2015 16:19
-
-
Save QuantumFractal/ea0dde30b31fcc1fa2ab to your computer and use it in GitHub Desktop.
Google Code Jam Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' All Your Base | |
2009 1-C | |
thomas moll 2015 | |
''' | |
import sys | |
filename = 'A-large-practice.in' | |
outfile = 'file.out' | |
def main(): | |
with open(filename, 'r') as in_file: | |
lines = in_file.readlines() | |
with open(outfile, 'w') as out_file: | |
for x,line in enumerate(lines[1:]): | |
value = find_smallest(line.strip()) | |
out_file.write("Case #"+str(x+1)+": "+str(value)+"\n") | |
def find_smallest(line): | |
values = {line[0]: 1} | |
for digit in line: | |
if digit not in values: | |
size = len(values) | |
if size == 1: | |
values[digit] = 0 | |
else: | |
values[digit] = size | |
result = 0 | |
base = max(len(values), 2) | |
for digit in line: | |
result *= base | |
result += values[digit] | |
return result | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TODO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment