Advent of Code Pre-Party
As December is closing in, I'm slowly getting ready again to participate in Advent of Code. For those who don't know, it's a coding advent calendar, releasing one puzzle every day you can solve using whatever programming language you like. It used to run up until Christmas, but this years' edition is reduced to twelve days.
I'll be solving the puzzles using Python. As of now, I have no idea how long I'll continue and if I manage to finish all twelve days, but I'm sure I'll start.
For those interested, I have a few utility Python functions I use to give me some of a headstart to each day. They are all related to reading input and transforming it into a usable data structure.
Maybe you'll benefit from using part of it. Feel free to do so!
The first function accepts the path to an input file as parameter, reads the file and then simply returns it as a string.
def read_to_string(path):
with open(path) as f:
string = f.read()
return string
The other function has proven to be quite useful over the last couple of years. Again it accepts the path to an input file as parameter, but now splits this input into multiple lines, returning a list where each item contains one line.
def read_to_list(path):
with open(path) as f:
lines = f.read().splitlines()
return lines
Both very easy, but very useful at the same time. I'm ready for this year's Advent of Code! Are you?