A difficult puzzle

I saw a video talking about this puzzle and thought that people here might enjoy it, especially programmers and maths folks. Just watching the video and working through the author's own solution is very interesting.

The puzzle consists of two phases. Firstly, discovering what you need to do – you can shortcut that part by watching the CTC video below. Secondly, working out how to do it – you can skip to the author's solution if you just want to see how it works.

Adventure page with link to python code - Adventure

Video from Cracking The Cryptic going through the discovery part of the puzzle to reveal the main task - The Hardest Puzzle Ever: Adventure by Jon Schneider - YouTube

An explanation and worked solution from the puzzle author Jon Schneider - Solution: Adventure