Skip to content

Commit 3fc9af9

Browse files
committed
day 4
1 parent 87567dd commit 3fc9af9

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

4/4.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# allow importing from parent folder
2+
import sys
3+
sys.path.append('../AOC-2024')
4+
5+
from utils.readfile import *
6+
from utils.calc import *
7+
from utils.graph import *
8+
from utils.util import *
9+
import re
10+
import math
11+
import copy
12+
import numpy as np
13+
from itertools import combinations, permutations, product
14+
import re
15+
import time
16+
17+
18+
grid = read_raw_text("4")
19+
width = grid.index("\n")+1
20+
21+
start_time = time.time()
22+
23+
24+
print("PART 1:")
25+
26+
n = 0
27+
for i in range(len(grid)):
28+
if grid[i]=="X":
29+
for x in [1,-1,width,-width,width-1,width+1,-width+1,-width-1]:
30+
n += grid[i::x][:4] == "XMAS"
31+
32+
print(n)
33+
34+
35+
36+
print("PART 2:")
37+
38+
n = 0
39+
for i in range(width, len(grid) - width - 1):
40+
if grid[i]=="A":
41+
l = grid[i-width-1] + grid[i+width+1]
42+
m = grid[i-width+1] + grid[i+width-1]
43+
n += (m in ["MS", "SM"]) and l in ["MS", "SM"]
44+
45+
print(n)

4/4.rock

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
isnum wants num
2+
val = num
3+
cut it
4+
for x in val
5+
if x < "0" or x > "9"
6+
give 0
7+
8+
9+
cast num with 10
10+
give num
11+
12+
13+
solve takes the line
14+
test = the line
15+
n = 0
16+
res = 0
17+
cut the line with "mul("
18+
roll it
19+
for x in the line
20+
cut x with ")"
21+
x = roll x
22+
cut x with ","
23+
if x = 2
24+
num = 1
25+
num = num * isnum taking x at 0
26+
num = num * isnum taking x at 1
27+
res = res + num
28+
29+
30+
give res
31+
32+
33+
something = 1
34+
while it isnt silent
35+
the input is with it
36+
listen to something
37+
38+
39+
say solve taking the input
40+
final = 0
41+
cut the input with "do()"
42+
for x in the input
43+
cut x with "don't()"
44+
v = x at 0
45+
final is with solve taking v
46+
47+
say final

3/3_golf.py 4/4_lyrics.rock

File renamed without changes.

0 commit comments

Comments
 (0)