Skip to content

Commit 6bb7b3d

Browse files
committed
add some AOC leaderboards, aoc solutions
1 parent 3224561 commit 6bb7b3d

File tree

7 files changed

+166
-2
lines changed

7 files changed

+166
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,5 @@ acm-practice/2017-11-30/*.ans
262262
facebook-hacker-cup/**/*.txt
263263
facebook-hacker-cup/**/*.zip
264264

265+
**/advent-of-code/**/*.html
266+
**/advent-of-code/**/*.answer
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if False:
2+
x = input()
3+
# copilot wrote this. It does the trick for part 2, but not part 2:
4+
while True:
5+
for i in range(len(x)-1):
6+
if x[i].lower() == x[i+1].lower() and x[i] != x[i+1]:
7+
x = x[:i] + x[i+2:]
8+
break
9+
else:
10+
break
11+
print(len(x))
12+
else:
13+
y = input()
14+
import string
15+
ans = 100000000000000000
16+
for letter in string.ascii_lowercase:
17+
x = y
18+
x = x.replace(letter, '')
19+
x = x.replace(letter.upper(), '')
20+
stack = []
21+
for c in x:
22+
if stack and stack[-1].lower() == c.lower() and stack[-1] != c:
23+
stack.pop()
24+
else:
25+
stack.append(c)
26+
ans = min(len(stack), ans)
27+
print(ans)
350 KB
Loading
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
from collections import defaultdict, deque, Counter
2+
# d = deque()
3+
# d.append(5)
4+
# x = d.popleft()
5+
import re
6+
# m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
7+
# # or re.search
8+
# >>> m.group(0) # The entire match
9+
# 'Isaac Newton'
10+
# >>> m.group(1) # The first parenthesized subgroup.
11+
# 'Isaac'
12+
# >>> m.group(2) # The second parenthesized subgroup.
13+
# 'Newton'
14+
# >>> m.group(1, 2) # Multiple arguments give us a tuple.
15+
# ('Isaac', 'Newton')
16+
from heapq import heappush, heappop
17+
# >>> heap = []
18+
# >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
19+
# >>> for item in data:
20+
# ... heappush(heap, item)
21+
# heap[0] is the smallest item
22+
import string
23+
# string.ascii_lowercase == 'abcde...'
24+
# string.ascii_uppercase == 'ABCDE...'
25+
from functools import lru_cache
26+
# @lru_cache(maxsize=None)
27+
import numpy as np
28+
29+
import sys
30+
31+
sys.setrecursionlimit(100000)
32+
33+
def get_ints(s):
34+
return list(map(int, re.findall(r"-?\d+", s))) # copied from mcpower from mserrano on betaveros' recommendation
35+
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
36+
directions = 'RDLU'
37+
octs = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
38+
def is_grid_valid(n,m, r,c,):
39+
return (0<=r<n) and (0<=c<m)
40+
def sign_of(x):
41+
if x==0:
42+
return 0
43+
return x/abs(x)
44+
####################################
45+
46+
PART = 1
47+
PART = 2
48+
if PART == 1:
49+
ans = 0
50+
inps = []
51+
while True:
52+
try:
53+
inps.append(input())
54+
except EOFError:
55+
break
56+
r, c = 0,0
57+
grid = set()
58+
for inp in inps:
59+
d, x, _ = inp.split()
60+
x = int(x)
61+
dr, dc = dirs[directions.index(d)]
62+
for _ in range(x):
63+
r += dr
64+
c += dc
65+
grid.add((r,c))
66+
def dfs(r,c):
67+
for dr, dc in dirs:
68+
nr, nc = r+dr, c+dc
69+
if (nr,nc) not in grid:
70+
grid.add((nr, nc))
71+
dfs(nr, nc)
72+
dfs(1,1)
73+
74+
print(len(grid))
75+
else:
76+
ans = 0
77+
inps = []
78+
while True:
79+
try:
80+
inps.append(input())
81+
except EOFError:
82+
break
83+
r, c = 0,0
84+
grid = set()
85+
prev_d = None
86+
for i in range(len(inps)):
87+
inp = inps[i]
88+
def get_d_x(inp):
89+
_,_,y = inp.split()
90+
y = y[1:-1]
91+
x = y[1:-1]
92+
d = int(y[-1])
93+
# print(x)
94+
x = int(x, 16)
95+
return d, x
96+
# def get_d_x(inp):
97+
# d, x, _ = inp.split()
98+
# x = int(x)
99+
# return directions.index(d), x
100+
101+
d, x = get_d_x(inp)
102+
nd, nx = get_d_x(inps[(i+1)%len(inps)])
103+
pd, px = get_d_x(inps[(i-1)%len(inps)])
104+
dr, dc = dirs[d]
105+
106+
if (d+1)%4 == nd:
107+
x += 1
108+
if (d-1)%4 != pd:
109+
x -= 1
110+
111+
nr, nc = r+dr*x, c+dc*x
112+
ans += (nr + r) * (nc - c)
113+
r, c = nr, nc
114+
print(abs(ans // 2))

miscellaneous/advent-of-code/2023/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Still on the east coast this year, and furthermore I'm back in school, with an 8
55
I started using Github Copilot (AI autocomplete) a few months ago, and I've used it for these problems. Sometimes it helps greatly, saving me tons of keystrokes and dozens of seconds. It's also allowed me to avoid activating my brain or pencil/paper to figure out how exactly some repeated rules should be: if I just write a rule once, copilot usually infers how to mechanically repeat the rule for the other cases. However, this has bitten me in the ass a few times when it did a bad job, I assumed it was correct without checking, and had to waste much more time debugging due to it.
66

77
I also started writing my own AOC CLI tool: https://github.com/VitamintK/wang-aoc-cli
8-
I really could have just used one that someone else wrote, like https://github.com/wimglenn/advent-of-code-wim, but it's been satisfying to make my own. So far, I haven't implemented any real time-savers yet (like running on example and real at the same time, and submitting from the CLI), but the command to download the input directly instead of copy-pasting saves me ~2 seconds every day, and the command to automatically create the files (.py, .in) that I use have been nice quality-of-life changes that mean that I only have to get to my computer by 11:59 instead of 11:57.
8+
I really could have just used one that someone else wrote, like https://github.com/wimglenn/advent-of-code-wim, but it's been satisfying to make my own. Up until and including Day 16, I haven't implemented any real time-savers yet (like running on example and real at the same time, and submitting from the CLI), but the command to download the input directly instead of copy-pasting saves me ~2 seconds every day, and the command to automatically create the files (.py, .in) that I use have been nice quality-of-life changes that mean that I only have to get to my computer by 11:59 instead of 11:57.
9+
For Day 17, I did implement those real time-savers, which I imagine will shave off one to two dozen seconds every day.
10+
Loading
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
2017 is here: https://github.com/VitamintK/FrivolousStuffs/tree/master/advent_of_code/2017
1+
2017 is here: https://github.com/VitamintK/FrivolousStuffs/tree/master/advent_of_code/2017
2+
3+
![summary of my stars](my_star_summary.jpg)
4+
5+
Results per year:
6+
7+
2018
8+
![2018](2018/ldrbrd.png)
9+
10+
2019
11+
![2019](2019/ldrbrd.png)
12+
13+
2020
14+
![2020](2020/ldrbrd.png)
15+
16+
2021
17+
![2021](2021/ldrbrd.png)
18+
19+
2022
20+
![2022](2022/ldrbrd.jpg)

0 commit comments

Comments
 (0)