logan_2023/day5/README.md
2023-12-06 01:24:01 -07:00

1.8 KiB

AoC 2023 Day 5 (GDScript & Python)

Today's code was written for Godot, somewhat lazily.

I also made a port to Python because I'm lazy and didn't feel like waiting all day to test the script (see commentary for more info). The Python versions are a direct port of the GDScript versions, so there's some seemingly strange choices in them.

Requirements:

  • Godot: Godot 4 Editor or a compiled Godot 4 based project
  • Python: Python ≥ 3.6 compatible interpreter

Usage:

  • To use the Godot version, run godot --headless -s d5p1.gd -- $INPUT where $INPUT is the path to your input file relative to the project root. Your input file should have an extension, ideally .txt.
  • To use the Python version, run python3 d5p2.py $INPUT.

Commentary (Spoilers):

**Reveal** Godot fought me at many points. It seems to have some behavior inconsistencies, as well as some poorly made functions (namely range). Admittedly it's not meant to do this, but I feel like it shouldn't be this bad.

Part 2 is not great. Originally it was written such that in order to find the answer, 1,809,081,164 iterations of the main while loop were required. This was definitely not good. On my 3700X it would've taken ~8h22m to find the answer. Fortunately I thought of a better way while porting Part 2 to Python. Instead of 1,809,081,164 iterations, it instead now takes 34,039,469 iterations (53x improvement!). Sadly, it's also slower per iteration now. I still feel like there is a far faster way to determine the answer, but at least it can finish in less time than it takes to port it to another language.

The Python versions are as close to 1:1 with the GDScript versions as I can reasonably manage. Their biggest advantage is that they're way faster, even with stock Python.