Skip to content

Commit da146d2

Browse files
committed
Start a personal library for AoC
1 parent 23105a3 commit da146d2

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

2020/1a_v2.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from aoc import *
2+
3+
4+
def main():
5+
print(sum(load_ints('1.txt')))
6+
7+
8+
main()

2020/aoc.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def lines(path):
2+
"""
3+
Return a list of lines from the file `path`
4+
"""
5+
with open(path) as f:
6+
return f.readlines()
7+
8+
9+
def file(path):
10+
"""
11+
Return contents of a file at `path` as a string
12+
"""
13+
with open(path) as f:
14+
return f.read()
15+
16+
17+
def filerstrip(path):
18+
"""
19+
Return rstripped file contents of file at `path`
20+
"""
21+
return file(path).rstrip()
22+
23+
24+
def load_map(path):
25+
"""
26+
Return list of strings ("2D array") from the file at `path`
27+
"""
28+
with open(path) as f:
29+
lines = f.readlines()
30+
return list(map(lambda x: x.rstrip(), lines))
31+
32+
33+
def load_ints(path):
34+
"""
35+
Return a list of ints loaded from file at `path`
36+
"""
37+
with open(path) as f:
38+
lines = f.readlines()
39+
return list(map(lambda x: int(x.rstrip()), lines))

0 commit comments

Comments
 (0)