Skip to content

Commit fb63fb2

Browse files
committed
cosmetics
1 parent 76bbb10 commit fb63fb2

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

2023/day05/run.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def load_data(filename):
99
if line.startswith('seeds:'):
1010
seeds = list(map(int, line.split(': ')[1].split()))
1111
elif line.endswith(':'):
12-
map_from, _, map_to = line[:-len(" map:")].split('-')
12+
map_from, map_to = line[:-len(" map:")].split('-to-')
1313
elif line == '':
1414
if len(current_map) > 0:
1515
maps[ (map_from, map_to) ] = current_map
@@ -35,8 +35,6 @@ def load_data(filename):
3535
if src <= value < src + r:
3636
value = dst + value - src
3737
break
38-
else:
39-
pass
4038
key = next_key
4139
min_location = min(min_location, value)
4240

@@ -50,7 +48,8 @@ def load_data(filename):
5048
min_location = float('inf')
5149

5250
for i in range(0, len(seeds), 2):
53-
ranges_from = P.closed(seeds[i], seeds[i] + seeds[i+1] - 1)
51+
src, r = seeds[i:i+2]
52+
ranges_from = P.closed(src, src + r - 1)
5453
key = 'seed'
5554
while key != 'location':
5655
translated = P.empty()

2023/day06/run.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def load_data(filename):
44
with open(filename, 'r') as f:
55
times = f.readline().rstrip('\n').split()[1:]
66
distances = f.readline().rstrip('\n').split()[1:]
7-
return map(int, times), map(int, distances)
7+
return list(map(int, times)), list(map(int, distances))
88

99
# Part One
1010

@@ -17,15 +17,13 @@ def distance(total_time, button_time):
1717
return (total_time - button_time) * speed
1818

1919
for t, record_distance in zip(times, distances):
20-
variants = [ 1 for b in range(t+1) if distance(t, b) > record_distance ]
21-
total *= len(variants)
20+
variants = sum( 1 for b in range(t+1) if distance(t, b) > record_distance )
21+
total *= variants
2222

2323
print(total)
2424

2525
# Part Two
2626

27-
times, distances = load_data('input.txt')
28-
2927
time = int(''.join(map(str, times)))
3028
record_distance = int(''.join(map(str, distances)))
3129

@@ -37,7 +35,7 @@ def search(low, high, f):
3735
low = mid
3836
else:
3937
high = mid
40-
return mid
38+
return high
4139

4240
def lower_bound(x):
4341
if distance(time, x) <= record_distance:

0 commit comments

Comments
 (0)