Skip to content

Commit 273101c

Browse files
committed
Refactor helpers to parse input
1 parent fb5c85f commit 273101c

38 files changed

+97
-89
lines changed

2018/original_solutions/day22.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def explore(source, targets):
111111
(NARROW, NEITHER): TORCH
112112
}
113113

114-
depth, tx, ty = get_ints(fin, True)
114+
depth, tx, ty = read_ints(fin)
115115
global_target = (tx, ty)
116116
log('depth: {} target: {}\n', depth, global_target)
117117

2018/original_solutions/day23.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
##################################################
1212

13-
intmat = get_int_matrix(fin, True)
13+
intmat = read_ints_lines(fin)
1414
bots = []
1515

1616
for l in intmat:

2018/original_solutions/day25.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def dist1d(a, b):
1515
def manhattan(ax, ay, az, at, bx, by, bz, bt):
1616
return dist1d(ax, bx) + dist1d(ay, by) + dist1d(az, bz) + dist1d(at, bt)
1717

18-
intmat = get_int_matrix(fin, True, as_tuples=True)
18+
intmat = read_ints_lines(fin, tuple, tuple)
1919
consts = defaultdict(set)
2020

2121
for p in intmat:

2019/original_solutions/day01.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
##################################################
1212

13-
nums = get_ints(fin, True)
13+
nums = read_ints(fin)
1414

1515
f = []
1616

2019/original_solutions/day02.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
##################################################
1212

13-
inp = get_ints(fin, True)
13+
inp = read_ints(fin)
1414

1515
pc = 0
1616
prog = inp[:]

2019/original_solutions/day07.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def halt(self):
283283

284284
##################################################
285285

286-
ints = get_ints(fin, True)
286+
ints = read_ints(fin)
287287

288288
vms = []
289289
vms.append(IntcodeVM(ints))

2019/original_solutions/day09.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def _usage():
279279
# eprint(*fin, sep='')
280280
timer_start()
281281

282-
prog = get_ints(fin, True)
282+
prog = read_ints(fin)
283283
vm = IntcodeVM(prog)
284284

285285
print('Input 1 for part1!')

2019/original_solutions/day10.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
##################################################
1111

12-
charmat = get_char_matrix(fin)
12+
charmat = read_char_matrix(fin)
1313

1414
def frac(x1, y1, x2, y2):
1515
if x1 == x2:

2019/original_solutions/day11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
##################################################
1111

12-
program = get_ints(fin, True)
12+
program = read_ints(fin)
1313

1414
BLACK, WHITE = 0, 1
1515
LEFT, RIGHT = 0, 1

2019/original_solutions/day13.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
##################################################
1111

12-
program = get_ints(fin, True)
12+
program = read_ints(fin)
1313

1414
vm = IntcodeVM(program)
1515
screen = set()

2019/original_solutions/day15.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
HITWALL, MOVED, FOUNDOXYGEN = 0, 1, 2
1515

1616
from lib.intcode import IntcodeVM
17-
prog = get_ints(fin, True)
17+
prog = read_ints(fin)
1818
vm = IntcodeVM(prog)
1919

2020
def path_to_moves(path):

2019/original_solutions/day17.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##################################################
1010

1111
from lib.intcode import IntcodeVM
12-
prog = get_ints(fin, True)
12+
prog = read_ints(fin)
1313
vm = IntcodeVM(prog)
1414

1515
def vm_write(v):

2019/original_solutions/day18.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def search2(bots, mykeys=frozenset()):
128128
return best
129129

130130

131-
grid = get_char_matrix(fin)
131+
grid = read_char_matrix(fin)
132132

133133
G = {}
134134
keys = {}

2019/original_solutions/day19.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##################################################
1010

1111
from lib.intcode import IntcodeVM
12-
prog = get_ints(fin, True)
12+
prog = read_ints(fin)
1313
vm = IntcodeVM(prog)
1414

1515
n = 0

2019/original_solutions/day21.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##################################################
1010

1111
from lib.intcode import IntcodeVM
12-
prog = get_ints(fin, True)
12+
prog = read_ints(fin)
1313
vm = IntcodeVM(prog)
1414

1515
def vm_write(v):

2019/original_solutions/day23.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
##################################################
99

1010
from lib.intcode import IntcodeVM
11-
prog = get_ints(fin, True)
11+
prog = read_ints(fin)
1212

1313
Q = []
1414
for i in range(50):

2019/original_solutions/day24.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
##################################################
1111

12-
orig_grid = get_char_matrix(fin)
12+
orig_grid = read_char_matrix(fin)
1313

1414
# orig_grid = [
1515
# list('....#'),

2019/original_solutions/day25.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##################################################
1010

1111
from lib.intcode import IntcodeVM
12-
prog = get_ints(fin, True)
12+
prog = read_ints(fin)
1313
vm = IntcodeVM(prog)
1414

1515
Q = deque()

2020/original_solutions/day01.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fin = advent.get_input()
66
eprint(*fin, sep=''); fin.seek(0, 0)
77

8-
ints = get_ints(fin, True)
8+
ints = read_ints(fin)
99

1010
print(ints)
1111
for i, x in enumerate(ints):

2020/original_solutions/day03.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# eprint(*fin, sep=''); fin.seek(0, 0)
88
timer_start()
99

10-
orig = get_char_matrix(fin)
10+
orig = read_char_matrix(fin)
1111

1212
h = len(orig)
1313
w = len(orig[0])

2020/original_solutions/day09.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
fin = advent.get_input()
77
timer_start()
88

9-
ints = get_ints(fin, True)
9+
ints = read_ints(fin)
1010

1111
for k in range(25, len(ints)):
1212
ok = False

2020/original_solutions/day11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# eprint(*fin, sep=''); fin.seek(0, 0)
2222
timer_start()
2323

24-
orig_grid = get_char_matrix(fin)
24+
orig_grid = read_char_matrix(fin)
2525
grid = copy.deepcopy(orig_grid)
2626

2727
while 1:

2020/original_solutions/day15.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fin = advent.get_input()
1010
timer_start()
1111

12-
nums = get_ints(fin, True)
12+
nums = read_ints(fin)
1313
# nums = [1,3,2]
1414
# nums = [0,3,6]
1515

2020/original_solutions/day17.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
fin = ftest
1616
timer_start()
1717

18-
startgrid = get_char_matrix(fin)
18+
startgrid = read_char_matrix(fin)
1919
cube = defaultdict(lambda: '.')
2020

2121
for x, row in enumerate(startgrid):

2021/original_solutions/day01.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
advent.setup(2021, 1)
66
fin = advent.get_input()
77

8-
ints = get_ints(fin)
8+
ints = read_ints(fin)
99
ans = 0
1010

1111
for a, b in zip(ints, ints[1:]):

2021/original_solutions/day06.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
timer_start()
1616

1717
ans = 0
18-
try: ints = get_ints(fin, True); fin.seek(0, 0)
18+
try: ints = read_ints(fin); fin.seek(0, 0)
1919
except: pass
2020
try: lines = get_lines(fin); fin.seek(0, 0)
2121
except: pass
22-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
22+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2323
except: pass
2424

2525
fish = list()

2021/original_solutions/day07.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
timer_start()
1515

1616
ans = 0
17-
try: ints = get_ints(fin, True); fin.seek(0, 0)
17+
try: ints = read_ints(fin); fin.seek(0, 0)
1818
except: pass
1919
try: lines = get_lines(fin); fin.seek(0, 0)
2020
except: pass
21-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
21+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2222
except: pass
2323

2424

2021/original_solutions/day08.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
timer_start()
2424

2525
ans = 0
26-
try: ints = get_ints(fin, True); fin.seek(0, 0)
26+
try: ints = read_ints(fin); fin.seek(0, 0)
2727
except: pass
2828
try: lines = get_lines(fin); fin.seek(0, 0)
2929
except: pass
30-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
30+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
3131
except: pass
3232

3333
sigs = []

2021/original_solutions/day09.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
timer_start()
2020

2121
ans = 0
22-
try: ints = get_ints(fin, True); fin.seek(0, 0)
22+
try: ints = read_ints(fin); fin.seek(0, 0)
2323
except: pass
2424
try: lines = get_lines(fin); fin.seek(0, 0)
2525
except: pass
26-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
26+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2727
except: pass
2828

2929
chmat = deepcopy(mat)

2021/original_solutions/day10.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
timer_start()
2424

2525
ans = 0
26-
try: ints = get_ints(fin, True); fin.seek(0, 0)
26+
try: ints = read_ints(fin); fin.seek(0, 0)
2727
except: pass
2828
try: lines = get_lines(fin); fin.seek(0, 0)
2929
except: pass
30-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
30+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
3131
except: pass
3232

3333

2021/original_solutions/day11.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
timer_start()
2424

2525
ans = 0
26-
try: ints = get_ints(fin, True); fin.seek(0, 0)
26+
try: ints = read_ints(fin); fin.seek(0, 0)
2727
except: pass
2828
try: lines = get_lines(fin); fin.seek(0, 0)
2929
except: pass
30-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
30+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
3131
except: pass
3232

3333
mat = [[int(x) for x in row] for row in mat]

2021/original_solutions/day12.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
timer_start()
2121

2222
ans = 0
23-
try: ints = get_ints(fin, True); fin.seek(0, 0)
23+
try: ints = read_ints(fin); fin.seek(0, 0)
2424
except: pass
2525
try: lines = get_lines(fin); fin.seek(0, 0)
2626
except: pass
27-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
27+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2828
except: pass
2929

3030
G = defaultdict(list)

2021/original_solutions/day13.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
timer_start()
1818

1919
ans = 0
20-
try: ints = get_ints(fin, True); fin.seek(0, 0)
20+
try: ints = read_ints(fin); fin.seek(0, 0)
2121
except: pass
2222
try: lines = get_lines(fin); fin.seek(0, 0)
2323
except: pass
24-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
24+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2525
except: pass
2626

2727
sheet = {}

2021/original_solutions/day15.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# eprint(*fin, sep='', end='----- end of input -----\n\n'); fin.seek(0, 0)
2424
timer_start()
2525

26-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
26+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2727
except: pass
2828

2929
ans = 0

2021/original_solutions/day22.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
# eprint(*fin, sep='', end='----- end of input -----\n\n'); fin.seek(0, 0)
1919
timer_start()
2020

21-
try: ints = get_ints(fin, True); fin.seek(0, 0)
21+
try: ints = read_ints(fin); fin.seek(0, 0)
2222
except: pass
2323
try: lines = get_lines(fin); fin.seek(0, 0)
2424
except: pass
25-
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
25+
try: mat = read_char_matrix(fin); fin.seek(0, 0)
2626
except: pass
2727

2828
cub = set()

2021/original_solutions/day25.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
....v..v.>
2121
''')
2222

23-
mat = get_char_matrix(fin, rstrip=False, lstrip=False)
23+
mat = read_char_matrix(fin)
2424

2525
def step(mat):
2626
n = 0

2022/original_solutions/day08.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
35390
1717
''')
1818

19-
mat = get_char_matrix(fin, rstrip=True, lstrip=True)
19+
mat = read_char_matrix(fin)
2020

2121
imat = []
2222
for l in mat:

0 commit comments

Comments
 (0)