Skip to content

Commit 4395356

Browse files
committed
cosmetics
1 parent c324a1c commit 4395356

File tree

14 files changed

+23
-23
lines changed

14 files changed

+23
-23
lines changed

2020/day02/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def all_passwords():
1111
valid = 0
1212
for n_from, n_to, char, passwd in all_passwords():
1313
n = passwd.count(char)
14-
if n >= n_from and n <= n_to:
14+
if n_from <= n <= n_to:
1515
valid += 1
1616

1717
print(valid)

2020/day04/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def valid(p):
3939
for p in load_passports('input.txt'):
4040
def valid(p):
4141
constraints = {
42-
'byr': (r'^(\d{4})$', lambda g: int(g[0]) >= 1920 and int(g[0]) <= 2002),
43-
'iyr': (r'^(\d{4})$', lambda g: int(g[0]) >= 2010 and int(g[0]) <= 2020),
44-
'eyr': (r'^(\d{4})$', lambda g: int(g[0]) >= 2020 and int(g[0]) <= 2030),
45-
'hgt': (r'^(\d+)(in|cm)$', lambda g: int(g[0]) >= {'in': 59, 'cm': 150}[g[1]] and int(g[0]) <= {'in': 76, 'cm': 193}[g[1]]),
42+
'byr': (r'^(\d{4})$', lambda g: 1920 <= int(g[0]) <= 2002),
43+
'iyr': (r'^(\d{4})$', lambda g: 2010 <= int(g[0]) <= 2020),
44+
'eyr': (r'^(\d{4})$', lambda g: 2020 <= int(g[0]) <= 2030),
45+
'hgt': (r'^(\d+)(in|cm)$', lambda g: {'in': 59, 'cm': 150}[g[1]] <= int(g[0]) <= {'in': 76, 'cm': 193}[g[1]]),
4646
'hcl': (r'^#[\da-f]{6}$', None),
4747
'ecl': (r'^(amb|blu|brn|gry|grn|hzl|oth)$', None),
4848
'pid': (r'^\d{9}$', None),

2020/day05/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def calc_id(seat):
2323
print(highest_id)
2424

2525
# Part Two
26-
all_seats = dict( (id, True) for id in range(highest_id+1) )
26+
all_seats = { id: True for id in range(highest_id+1) }
2727
for seat in load_data('input.txt'):
2828
id = calc_id(seat)
2929
del all_seats[id]

2020/day15/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
input = "20,9,11,0,1,2"
44

55
spoken = list(map(int, input.split(',')))
6-
last = dict((n, i) for i, n in enumerate(spoken[:-1]))
6+
last = { n: i for i, n in enumerate(spoken[:-1]) }
77

88
def play(limit):
99
while len(spoken) < limit:

2020/day16/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def load_data(filename):
1111
break
1212
name, ranges = line.split(': ')
1313
ranges = ranges.split(' or ')
14-
s = set([])
14+
s = set()
1515
for r in ranges:
1616
numbers = r.split('-')
1717
s |= set(range(int(numbers[0]), int(numbers[1])+1))
@@ -34,7 +34,7 @@ def load_data(filename):
3434

3535
rules, my_ticket, nearby_tickets = load_data('input.txt')
3636

37-
all_rules = set([])
37+
all_rules = set()
3838
for _, valid_numbers in rules:
3939
all_rules |= valid_numbers
4040

@@ -53,7 +53,7 @@ def load_data(filename):
5353
field_map = {}
5454
nearby_tickets = np.array(nearby_tickets)
5555
for rule_no, (name, s) in enumerate(rules):
56-
possible_fields = set([])
56+
possible_fields = set()
5757
for field_no in range(nearby_tickets.shape[1]):
5858
if all( x in s for x in nearby_tickets[:,field_no] ):
5959
possible_fields |= set([field_no])

2020/day21/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def load_food():
88
allergens = set(tokens[1].strip(')\n').split(', '))
99
yield ingredients, allergens
1010

11-
ingredients_with_allergens = set([])
11+
ingredients_with_allergens = set()
1212
all_ingredients = []
1313
known_allergens = {}
1414
allergens_candidates = {}

2021/day17/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def launch(vx, vy):
1212
y += vy
1313
if highest_y < y:
1414
highest_y = y
15-
if x >= target['x_from'] and x <= target['x_to'] and y >= target['y_from'] and y <= target['y_to']:
15+
if target['x_from'] <= x <= target['x_to'] and target['y_from'] <= y <= target['y_to']:
1616
return True, highest_y
1717
if y < target['y_from']:
1818
return False, highest_y

2021/day22/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def set(self, new_aabb, v):
4242
if stop <= new_start or new_stop <= start:
4343
skip = True
4444
elif stop > new_stop or start < new_start:
45-
if start < new_start and stop > new_start:
45+
if start < new_start < stop:
4646
cuts.append(aabb[:j] + [ (start, new_start) ] + aabb[j+1:])
47-
if stop > new_stop and start < new_stop:
47+
if start < new_stop < stop:
4848
cuts.append(aabb[:j] + [ (new_stop, stop) ] + aabb[j+1:])
4949
aabb[j] = ( max(start, new_start), min(stop, new_stop) )
5050
if skip:

2021/day24/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121
self.input = None
2222

2323
def reset(self):
24-
self.values = dict(zip(self.regs, [0] * len(self.regs)))
24+
self.values = { reg: 0 for reg in self.regs }
2525

2626
def load(self, code):
2727
self.code = code

2022/day03/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def load_data(filename):
99
# Part One
1010

1111
def priority(char):
12-
if char >= 'a' and char <= 'z':
12+
if 'a' <= char <= 'z':
1313
return ord(char) - ord('a') + 1
14-
if char >= 'A' and char <= 'Z':
14+
if 'A' <= char <= 'Z':
1515
return ord(char) - ord('A') + 27
1616

1717
total = 0

2022/day15/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def load_data(filename):
1414
from itertools import pairwise, product
1515

1616
the_row = 2_000_000
17-
beacons_in_the_row = set([])
17+
beacons_in_the_row = set()
1818
all_intervals = []
1919
for (sx, sy), (bx, by) in load_data('input.txt'):
2020
if by == the_row:
@@ -43,7 +43,7 @@ def load_data(filename):
4343
for f, t in all_intervals:
4444
r = t - f + 1
4545
for bx in beacons_in_the_row:
46-
if bx >= f and bx <= t:
46+
if f <= bx <= t:
4747
r -= 1
4848
total += r
4949

2022/day18/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def neighbours(x, y, z):
3636

3737
def isolated(x, y, z):
3838
visited = { (x, y, z): None }
39-
lookup = dict( (c, None) for c in neighbours(x, y, z) if c not in cubes )
39+
lookup = { c: None for c in neighbours(x, y, z) if c not in cubes }
4040
while len(lookup) > 0:
4141
x, y, z = next(iter(lookup))
4242
del lookup[ (x, y, z) ]
4343
visited[ (x, y, z) ] = None
4444
if x in (minx, maxx) or y in (miny, maxy) or z in (minz, maxz):
4545
return False
46-
lookup.update( (c, None) for c in neighbours(x, y, z) if c not in cubes and c not in visited and c not in lookup )
46+
lookup |= { c: None for c in neighbours(x, y, z) if c not in cubes and c not in visited and c not in lookup }
4747
return True
4848

4949
cubes_isolated = []

2022/day23/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def planned(x, y, i):
6868
i += 1
6969

7070
while True:
71-
new_elves, _, _ = next_state(i, elves)
71+
new_elves, *_ = next_state(i, elves)
7272
i += 1
7373
if new_elves == elves:
7474
break

2022/day24/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def can_walk(x, y, t):
4242
return False
4343
return True
4444
for (nx, ny, nt) in possible_moves:
45-
if nx >= 0 and nx < w and ny >= 0 and ny < h and nt < max_minutes:
45+
if 0 <= nx < w and 0 <= ny < h and nt < max_minutes:
4646
if can_walk(nx, ny, nt):
4747
yield (nx, ny, nt), 1
4848

0 commit comments

Comments
 (0)