added rest of the code
This commit is contained in:
1
25/input
Normal file
1
25/input
Normal file
@ -0,0 +1 @@
|
||||
To continue, please consult the code grid in the manual. Enter the code at row 3010, column 3019.
|
||||
38
25/part1.py
Normal file
38
25/part1.py
Normal file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_PARSE = re.compile(r'.* (\d+),.* (\d+).$')
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def get_position(row, col):
|
||||
triangle = (row + col-1) * (row + col) / 2
|
||||
return triangle - row + 1
|
||||
|
||||
|
||||
def main():
|
||||
code_first = 20151125
|
||||
code_mul = 252533
|
||||
code_mod = 33554393
|
||||
|
||||
for line in read_file('input'):
|
||||
match = re.match(RE_PARSE, line)
|
||||
row = int(match.group(1))
|
||||
col = int(match.group(2))
|
||||
code = code_first
|
||||
iterations = get_position(row, col)
|
||||
for x in range(iterations-1):
|
||||
code = (code * code_mul) % code_mod
|
||||
print code
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user