Skip to content

Commit 73c30ac

Browse files
committed
Reformat all of 2017, general clean-up
Run all of 2017 through ruff, and apply minimal cosmetic updates to avoid lint warnings. No outputs were changed (apart from the matplotlib plot _sizes_ which are now slightly larger).
1 parent d77fdfa commit 73c30ac

26 files changed

+72575
-40495
lines changed

2017/Day 01.ipynb

+18-14
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@
3030
" same_as_next = (\n",
3131
" digit\n",
3232
" for digit, next in zip(inputvalue, inputvalue[1:] + inputvalue[0])\n",
33-
" if digit == next)\n",
33+
" if digit == next\n",
34+
" )\n",
3435
" return sum(map(int, same_as_next))\n",
3536
"\n",
37+
"\n",
3638
"tests = {\n",
37-
" '1122': 3,\n",
38-
" '1111': 4,\n",
39-
" '1234': 0,\n",
40-
" '91212129': 9,\n",
39+
" \"1122\": 3,\n",
40+
" \"1111\": 4,\n",
41+
" \"1234\": 0,\n",
42+
" \"91212129\": 9,\n",
4143
"}\n",
4244
"for in_, out in tests.items():\n",
4345
" assert captcha_next(in_) == out\n",
4446
"\n",
45-
"print('Part 1:', captcha_next(inputvalue))"
47+
"print(\"Part 1:\", captcha_next(inputvalue))"
4648
]
4749
},
4850
{
@@ -64,20 +66,22 @@
6466
" same_as_halfway = (\n",
6567
" digit\n",
6668
" for digit, other in zip(inputvalue, inputvalue[halfway:] + inputvalue[:halfway])\n",
67-
" if digit == other)\n",
69+
" if digit == other\n",
70+
" )\n",
6871
" return sum(map(int, same_as_halfway))\n",
6972
"\n",
73+
"\n",
7074
"tests = {\n",
71-
" '1212': 6,\n",
72-
" '1221': 0,\n",
73-
" '123425': 4,\n",
74-
" '123123': 12,\n",
75-
" '12131415': 4,\n",
75+
" \"1212\": 6,\n",
76+
" \"1221\": 0,\n",
77+
" \"123425\": 4,\n",
78+
" \"123123\": 12,\n",
79+
" \"12131415\": 4,\n",
7680
"}\n",
7781
"for in_, out in tests.items():\n",
7882
" assert captcha_halfway(in_) == out\n",
7983
"\n",
80-
"print('Part 2:', captcha_halfway(inputvalue))"
84+
"print(\"Part 2:\", captcha_halfway(inputvalue))"
8185
]
8286
}
8387
],
@@ -97,7 +101,7 @@
97101
"name": "python",
98102
"nbconvert_exporter": "python",
99103
"pygments_lexer": "ipython3",
100-
"version": "3.7.1"
104+
"version": "3.12.0"
101105
}
102106
},
103107
"nbformat": 4,

2017/Day 02.ipynb

+11-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
"def checksum(sheet):\n",
3030
" return sum(max(row) - min(row) for row in sheet)\n",
3131
"\n",
32-
"assert checksum([[5, 1, 9, 5],\n",
33-
" [7, 5, 3],\n",
34-
" [2, 4, 6, 8]]) == 18\n",
35-
"print('Part 1:', checksum(inputvalue))"
32+
"\n",
33+
"assert checksum([[5, 1, 9, 5], [7, 5, 3], [2, 4, 6, 8]]) == 18\n",
34+
"print(\"Part 1:\", checksum(inputvalue))"
3635
]
3736
},
3837
{
@@ -53,7 +52,13 @@
5352
],
5453
"source": [
5554
"from itertools import combinations\n",
56-
"sum(int(div) for row in inputvalue for div in (max(a, b) / min(a, b) for a, b in combinations(row, 2)) if div.is_integer())"
55+
"\n",
56+
"sum(\n",
57+
" int(div)\n",
58+
" for row in inputvalue\n",
59+
" for div in (max(a, b) / min(a, b) for a, b in combinations(row, 2))\n",
60+
" if div.is_integer()\n",
61+
")"
5762
]
5863
}
5964
],
@@ -73,7 +78,7 @@
7378
"name": "python",
7479
"nbconvert_exporter": "python",
7580
"pygments_lexer": "ipython3",
76-
"version": "3.7.1"
81+
"version": "3.12.0"
7782
}
7883
},
7984
"nbformat": 4,

2017/Day 03.ipynb

+12-11
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,24 @@
3030
"source": [
3131
"import math\n",
3232
"\n",
33+
"\n",
3334
"def spiraldistance(pos):\n",
3435
" if pos == 1:\n",
3536
" return 0\n",
3637
" prev = int(math.sqrt(pos))\n",
3738
" if prev % 2 == 0:\n",
3839
" prev -= 1\n",
3940
" sidelength = prev + 1\n",
40-
" offset = (pos - (prev ** 2)) % sidelength\n",
41+
" offset = (pos - (prev**2)) % sidelength\n",
4142
" middle = sidelength // 2\n",
4243
" return middle + abs(middle - offset)\n",
4344
"\n",
44-
"tests = {\n",
45-
" 1: 0,\n",
46-
" 12: 3,\n",
47-
" 23: 2,\n",
48-
" 1024: 31\n",
49-
"}\n",
45+
"\n",
46+
"tests = {1: 0, 12: 3, 23: 2, 1024: 31}\n",
5047
"for pos, expected in tests.items():\n",
51-
" assert spiraldistance(pos) == expected, f'spiraldistance({pos}) => {spiraldistance(pos)}, not {expected}'\n",
48+
" assert (\n",
49+
" spiraldistance(pos) == expected\n",
50+
" ), f\"spiraldistance({pos}) => {spiraldistance(pos)}, not {expected}\"\n",
5251
"\n",
5352
"spiraldistance(inputvalue)"
5453
]
@@ -79,6 +78,7 @@
7978
"source": [
8079
"from itertools import count, cycle, islice, product\n",
8180
"\n",
81+
"\n",
8282
"def summed_larger():\n",
8383
" grid = {(0, 0): 1}\n",
8484
" directions = tuple((x, y) for x, y in product((-1, 0, 1), repeat=2) if x or y)\n",
@@ -91,16 +91,17 @@
9191
" value = sum(grid.get((x + dx, y + dy), 0) for dx, dy in directions)\n",
9292
" yield value\n",
9393
" grid[(x, y)] = value\n",
94-
" if num == size ** 2: # next spiral ring\n",
94+
" if num == size**2: # next spiral ring\n",
9595
" size += 2\n",
9696
" x += 1\n",
9797
" step = next(steps)\n",
9898
" else:\n",
99-
" if (num - ((size - 2) ** 2)) % (size - 1) == 0: # change direction\n",
99+
" if (num - ((size - 2) ** 2)) % (size - 1) == 0: # change direction\n",
100100
" step = next(steps)\n",
101101
" x += step[0]\n",
102102
" y += step[1]\n",
103103
"\n",
104+
"\n",
104105
"print(list(islice(summed_larger(), 25)))\n",
105106
"next(filter(lambda v: v > inputvalue, summed_larger()))"
106107
]
@@ -122,7 +123,7 @@
122123
"name": "python",
123124
"nbconvert_exporter": "python",
124125
"pygments_lexer": "ipython3",
125-
"version": "3.7.1"
126+
"version": "3.12.0"
126127
}
127128
},
128129
"nbformat": 4,

2017/Day 04.ipynb

+14-12
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
" words = phrase.split()\n",
3131
" return len(words) == len(set(words))\n",
3232
"\n",
33+
"\n",
3334
"tests = {\n",
34-
" 'aa bb cc dd ee': True,\n",
35-
" 'aa bb cc dd aa': False,\n",
36-
" 'aa bb cc dd aaa': True,\n",
35+
" \"aa bb cc dd ee\": True,\n",
36+
" \"aa bb cc dd aa\": False,\n",
37+
" \"aa bb cc dd aaa\": True,\n",
3738
"}\n",
3839
"for phrase, expected in tests.items():\n",
3940
" assert is_valid(phrase) == expected\n",
4041
"\n",
41-
"print('Part 1:', sum(map(is_valid, phrases)))"
42+
"print(\"Part 1:\", sum(map(is_valid, phrases)))"
4243
]
4344
},
4445
{
@@ -57,21 +58,22 @@
5758
"source": [
5859
"def is_valid_no_anagram(phrase):\n",
5960
" words = phrase.split()\n",
60-
" sorted_set = {''.join(sorted(w)) for w in words}\n",
61+
" sorted_set = {\"\".join(sorted(w)) for w in words}\n",
6162
" return len(words) == len(sorted_set)\n",
6263
"\n",
64+
"\n",
6365
"tests = {\n",
64-
" 'abcde fghij': True,\n",
65-
" 'abcde xyz ecdab': False,\n",
66-
" 'a ab abc abd abf abj': True,\n",
67-
" 'iiii oiii ooii oooi oooo': True,\n",
68-
" 'oiii ioii iioi iiio': False,\n",
66+
" \"abcde fghij\": True,\n",
67+
" \"abcde xyz ecdab\": False,\n",
68+
" \"a ab abc abd abf abj\": True,\n",
69+
" \"iiii oiii ooii oooi oooo\": True,\n",
70+
" \"oiii ioii iioi iiio\": False,\n",
6971
"}\n",
7072
"\n",
7173
"for phrase, expected in tests.items():\n",
7274
" assert is_valid_no_anagram(phrase) == expected\n",
7375
"\n",
74-
"print('Part 2:', sum(map(is_valid_no_anagram, phrases)))"
76+
"print(\"Part 2:\", sum(map(is_valid_no_anagram, phrases)))"
7577
]
7678
}
7779
],
@@ -91,7 +93,7 @@
9193
"name": "python",
9294
"nbconvert_exporter": "python",
9395
"pygments_lexer": "ipython3",
94-
"version": "3.7.1"
96+
"version": "3.12.0"
9597
}
9698
},
9799
"nbformat": 4,

2017/Day 05.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
" instructions[pos] -= 1\n",
3030
" pos += delta\n",
3131
" steps += 1\n",
32-
" return steps\n"
32+
" return steps"
3333
]
3434
},
3535
{
@@ -47,7 +47,7 @@
4747
],
4848
"source": [
4949
"assert execute([0, 3, 0, 1, -3]) == 5\n",
50-
"print('Part 1:', execute(instructions[:]))"
50+
"print(\"Part 1:\", execute(instructions[:]))"
5151
]
5252
},
5353
{
@@ -65,7 +65,7 @@
6565
],
6666
"source": [
6767
"assert execute([0, 3, 0, 1, -3], True) == 10\n",
68-
"print('Part 2:', execute(instructions[:], True))"
68+
"print(\"Part 2:\", execute(instructions[:], True))"
6969
]
7070
}
7171
],
@@ -85,7 +85,7 @@
8585
"name": "python",
8686
"nbconvert_exporter": "python",
8787
"pygments_lexer": "ipython3",
88-
"version": "3.7.1"
88+
"version": "3.12.0"
8989
}
9090
},
9191
"nbformat": 4,

2017/Day 06.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"\n",
5858
"assert find_circle([0, 2, 7, 0]) == 5\n",
5959
"\n",
60-
"print('Part 1:', find_circle(banks))"
60+
"print(\"Part 1:\", find_circle(banks))"
6161
]
6262
},
6363
{
@@ -78,7 +78,7 @@
7878
"assert find_circle(test) == 4\n",
7979
"\n",
8080
"# starting from the last banks state, length of the loop\n",
81-
"print('Part 2:', find_circle(banks))"
81+
"print(\"Part 2:\", find_circle(banks))"
8282
]
8383
}
8484
],
@@ -98,7 +98,7 @@
9898
"name": "python",
9999
"nbconvert_exporter": "python",
100100
"pygments_lexer": "ipython3",
101-
"version": "3.7.1"
101+
"version": "3.12.0"
102102
}
103103
},
104104
"nbformat": 4,

0 commit comments

Comments
 (0)