advent-of-code/2021/python/shared.py

32 lines
764 B
Python
Raw Normal View History

2022-12-09 16:43:00 +00:00
def get_fname(day: int) -> str:
import sys
if sys.argv[-1] == "--sample":
return f"../samples/day{day:02}.txt"
else:
return f"../full/day{day:02}.txt"
def load_file_char_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [list(x) for x in my_file]
def load_file_int_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [list(map(int, x)) for x in my_file]
def load_file_word_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [x.split(" ") for x in my_file]