Advent of Code: Day 25

Source

Part 1: Take the relation:

F(n) = \left\{\begin{matrix} 20151225 & \textrm{if}\ n = 1 \\ 252533F(n-1) \mod 33554393 & \textrm{otherwise} \end{matrix}\right.

Arrange the values according to Cantor's diagonal argument. Find the value at a specific cell.

target_row = int(sys.argv[1])
target_col = int(sys.argv[2])

row = 1
col = 1
val = 20151125

while True:
    if target_row == row and target_col == col:
        print(val)
        sys.exit(0)
    else:
        val = (val * 252533) % 33554393

    if row == 1:
        row = col + 1
        col = 1
    else:
        row -= 1
        col += 1

Merry Christmas!