<filename>2015/python/day25/chal49.py
import sys
import re

'''
The voice on the other end of the phone continues with how the codes are actually generated. The first code is 20151125. After that, each code is generated by taking the previous one, multiplying it by 252533, and then keeping the remainder from dividing that value by 33554393.
'''

def increment(last_value):
    inter = last_value * 252533
    next_value = inter % 33554393
    return next_value


def printPaper(paper):
    print "#"*len(paper[0])
    for line in paper:
        print line
    print "#"*len(paper[0]), "\n"

# ######################
if len(sys.argv) != 2:
    print "need an input file"
    exit(1)

f = open(sys.argv[1])
column = row = None
for line in f:
    matchObj = re.match(r'To continue, please consult the code grid in the manual.  Enter the code at row (\d*), column (\d*).', line, re.M | re.I)

    row = int(matchObj.group(1)) - 1
    column = int(matchObj.group(2)) - 1

value = None
paper = []
start = 20151125
paper.append([start])
last_value = start
while value is None:
    paper.append([])
    last_i = len(paper)-1
    for i in range(last_i, -1, -1):
        paper[i].append(increment(last_value))
        j = len(paper[i])-1
        last_value = paper[i][-1]
        if row == i and column == j:
            value = last_value
    # printPaper(paper)

print "Value =", value

<filename>2015/python/day25/chal49.py
import sys
import re

'''
The voice on the other end of the phone continues with how the codes are actually generated. The first code is 20151125. After that, each code is generated by taking the previous one, multiplying it by 252533, and then keeping the remainder from dividing that value by 33554393.
'''

def increment(last_value):
    inter = last_value * 252533
    next_value = inter % 33554393
    return next_value


def printPaper(paper):
    print "#"*len(paper[0])
    for line in paper:
        print line
    print "#"*len(paper[0]), "\n"

# ######################
if len(sys.argv) != 2:
    print "need an input file"
    exit(1)

f = open(sys.argv[1])
column = row = None
for line in f:
    matchObj = re.match(r'To continue, please consult the code grid in the manual.  Enter the code at row (\d*), column (\d*).', line, re.M | re.I)

    row = int(matchObj.group(1)) - 1
    column = int(matchObj.group(2)) - 1

value = None
paper = []
start = 20151125
paper.append([start])
last_value = start
while value is None:
    paper.append([])
    last_i = len(paper)-1
    for i in range(last_i, -1, -1):
        paper[i].append(increment(last_value))
        j = len(paper[i])-1
        last_value = paper[i][-1]
        if row == i and column == j:
            value = last_value
    # printPaper(paper)

print "Value =", value

The voice on the other end of the phone continues with how the codes are actually generated. The first code is 20151125. After that, each code is generated by taking the previous one, multiplying it by 252533, and then keeping the remainder from dividing that value by 33554393. # ###################### # printPaper(paper)