Skip to content

Commit

Permalink
Refactor helpers to parse input
Browse files Browse the repository at this point in the history
  • Loading branch information
mebeim committed Dec 11, 2022
1 parent fb5c85f commit 273101c
Show file tree
Hide file tree
Showing 38 changed files with 97 additions and 89 deletions.
2 changes: 1 addition & 1 deletion 2018/original_solutions/day22.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def explore(source, targets):
(NARROW, NEITHER): TORCH
}

depth, tx, ty = get_ints(fin, True)
depth, tx, ty = read_ints(fin)
global_target = (tx, ty)
log('depth: {} target: {}\n', depth, global_target)

Expand Down
2 changes: 1 addition & 1 deletion 2018/original_solutions/day23.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##################################################

intmat = get_int_matrix(fin, True)
intmat = read_ints_lines(fin)
bots = []

for l in intmat:
Expand Down
2 changes: 1 addition & 1 deletion 2018/original_solutions/day25.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def dist1d(a, b):
def manhattan(ax, ay, az, at, bx, by, bz, bt):
return dist1d(ax, bx) + dist1d(ay, by) + dist1d(az, bz) + dist1d(at, bt)

intmat = get_int_matrix(fin, True, as_tuples=True)
intmat = read_ints_lines(fin, tuple, tuple)
consts = defaultdict(set)

for p in intmat:
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day01.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##################################################

nums = get_ints(fin, True)
nums = read_ints(fin)

f = []

Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day02.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##################################################

inp = get_ints(fin, True)
inp = read_ints(fin)

pc = 0
prog = inp[:]
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day07.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def halt(self):

##################################################

ints = get_ints(fin, True)
ints = read_ints(fin)

vms = []
vms.append(IntcodeVM(ints))
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day09.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _usage():
# eprint(*fin, sep='')
timer_start()

prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

print('Input 1 for part1!')
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day10.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

##################################################

charmat = get_char_matrix(fin)
charmat = read_char_matrix(fin)

def frac(x1, y1, x2, y2):
if x1 == x2:
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day11.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

##################################################

program = get_ints(fin, True)
program = read_ints(fin)

BLACK, WHITE = 0, 1
LEFT, RIGHT = 0, 1
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day13.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

##################################################

program = get_ints(fin, True)
program = read_ints(fin)

vm = IntcodeVM(program)
screen = set()
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day15.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
HITWALL, MOVED, FOUNDOXYGEN = 0, 1, 2

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

def path_to_moves(path):
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day17.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##################################################

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

def vm_write(v):
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day18.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def search2(bots, mykeys=frozenset()):
return best


grid = get_char_matrix(fin)
grid = read_char_matrix(fin)

G = {}
keys = {}
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day19.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##################################################

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

n = 0
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day21.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##################################################

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

def vm_write(v):
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day23.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
##################################################

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)

Q = []
for i in range(50):
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day24.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

##################################################

orig_grid = get_char_matrix(fin)
orig_grid = read_char_matrix(fin)

# orig_grid = [
# list('....#'),
Expand Down
2 changes: 1 addition & 1 deletion 2019/original_solutions/day25.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##################################################

from lib.intcode import IntcodeVM
prog = get_ints(fin, True)
prog = read_ints(fin)
vm = IntcodeVM(prog)

Q = deque()
Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day01.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fin = advent.get_input()
eprint(*fin, sep=''); fin.seek(0, 0)

ints = get_ints(fin, True)
ints = read_ints(fin)

print(ints)
for i, x in enumerate(ints):
Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day03.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# eprint(*fin, sep=''); fin.seek(0, 0)
timer_start()

orig = get_char_matrix(fin)
orig = read_char_matrix(fin)

h = len(orig)
w = len(orig[0])
Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day09.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
fin = advent.get_input()
timer_start()

ints = get_ints(fin, True)
ints = read_ints(fin)

for k in range(25, len(ints)):
ok = False
Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day11.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# eprint(*fin, sep=''); fin.seek(0, 0)
timer_start()

orig_grid = get_char_matrix(fin)
orig_grid = read_char_matrix(fin)
grid = copy.deepcopy(orig_grid)

while 1:
Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day15.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
fin = advent.get_input()
timer_start()

nums = get_ints(fin, True)
nums = read_ints(fin)
# nums = [1,3,2]
# nums = [0,3,6]

Expand Down
2 changes: 1 addition & 1 deletion 2020/original_solutions/day17.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
fin = ftest
timer_start()

startgrid = get_char_matrix(fin)
startgrid = read_char_matrix(fin)
cube = defaultdict(lambda: '.')

for x, row in enumerate(startgrid):
Expand Down
2 changes: 1 addition & 1 deletion 2021/original_solutions/day01.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
advent.setup(2021, 1)
fin = advent.get_input()

ints = get_ints(fin)
ints = read_ints(fin)
ans = 0

for a, b in zip(ints, ints[1:]):
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day06.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

fish = list()
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day07.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass


Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day08.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

sigs = []
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day09.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

chmat = deepcopy(mat)
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day10.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass


Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day11.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

mat = [[int(x) for x in row] for row in mat]
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day12.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

G = defaultdict(list)
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day13.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
timer_start()

ans = 0
try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

sheet = {}
Expand Down
2 changes: 1 addition & 1 deletion 2021/original_solutions/day15.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# eprint(*fin, sep='', end='----- end of input -----\n\n'); fin.seek(0, 0)
timer_start()

try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

ans = 0
Expand Down
4 changes: 2 additions & 2 deletions 2021/original_solutions/day22.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# eprint(*fin, sep='', end='----- end of input -----\n\n'); fin.seek(0, 0)
timer_start()

try: ints = get_ints(fin, True); fin.seek(0, 0)
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = get_char_matrix(fin, rstrip=False, lstrip=False); fin.seek(0, 0)
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass

cub = set()
Expand Down
2 changes: 1 addition & 1 deletion 2021/original_solutions/day25.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
....v..v.>
''')

mat = get_char_matrix(fin, rstrip=False, lstrip=False)
mat = read_char_matrix(fin)

def step(mat):
n = 0
Expand Down
2 changes: 1 addition & 1 deletion 2022/original_solutions/day08.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
35390
''')

mat = get_char_matrix(fin, rstrip=True, lstrip=True)
mat = read_char_matrix(fin)

imat = []
for l in mat:
Expand Down
Loading

0 comments on commit 273101c

Please sign in to comment.