2022 day 10

This commit is contained in:
2022-12-10 08:12:17 +00:00
parent c474e4b25e
commit 47a16a9b6a
4 changed files with 205 additions and 2 deletions

143
2022/10/input Normal file
View File

@@ -0,0 +1,143 @@
noop
noop
noop
addx 5
addx 1
addx 4
addx 1
noop
addx 4
noop
addx 1
addx 4
addx 8
addx -7
addx 3
addx 1
noop
addx 4
addx 2
addx 5
addx -1
noop
addx -37
noop
noop
addx 3
addx 2
addx 13
addx 12
addx -15
addx -2
addx 2
addx -11
addx 18
addx 2
addx -15
addx 16
addx 5
addx 2
addx 5
noop
noop
noop
addx 3
addx -2
addx -38
noop
addx 3
addx 4
noop
noop
noop
noop
noop
addx 5
addx 5
noop
noop
addx 21
addx -17
addx 6
noop
noop
noop
noop
addx 5
noop
noop
noop
noop
noop
addx 3
addx 5
addx -38
noop
noop
addx 5
addx -2
addx 1
addx 7
noop
addx 22
addx -18
addx -11
addx 27
addx -13
addx 2
addx 5
addx -8
addx 9
addx 2
noop
addx 7
noop
addx 1
noop
addx -38
noop
addx 2
addx 5
addx -3
noop
addx 8
addx 11
addx -6
noop
addx 24
addx -31
addx 10
addx 2
addx 5
addx 3
noop
addx 2
addx -29
addx 21
addx 11
addx 5
addx -39
addx 4
addx -2
addx 2
addx 7
noop
addx -1
addx 2
noop
addx 4
noop
addx 1
addx 2
addx 5
addx 2
noop
noop
addx -6
addx 9
addx -18
addx 25
addx 3
noop
addx -17
noop

28
2022/10/part1 Executable file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python
CLOCK = 1
X = 1
X_VALUES = []
with open('input') as f:
for line in f:
ins, *args = line.rstrip().split(" ")
if ins == "noop":
CLOCK += 1
X_VALUES.append(X)
elif ins == "addx":
CLOCK += 2
X_VALUES.append(X)
X_VALUES.append(X)
X += int(args[0])
print(
(X_VALUES[19] * 20) +
(X_VALUES[59] * 60) +
(X_VALUES[99] * 100) +
(X_VALUES[139] * 140) +
(X_VALUES[179] * 180) +
(X_VALUES[219] * 220)
)

32
2022/10/part2 Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python
CLOCK = 0
X = 1
OUT = []
def clock():
global CLOCK, X, OUT
pos = CLOCK%40
if X == pos or X-1 == pos or X+1 == pos:
OUT.append('#')
else:
OUT.append('.')
if pos == 39:
OUT.append("\n")
CLOCK += 1
with open('input') as f:
for line in f:
ins, *args = line.rstrip().split(" ")
if ins == "noop":
clock()
elif ins == "addx":
clock()
clock()
X += int(args[0])
print(''.join(OUT))

View File

@@ -9,7 +9,7 @@ a programming language I'm interested in learning more about.
2018, 2019, and 2020 were in their own separate repositories, but have been 2018, 2019, and 2020 were in their own separate repositories, but have been
`git subtree`'d into this one - no point creating a new repository every year. `git subtree`'d into this one - no point creating a new repository every year.
* [2022](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2022) 🌟 `18` - Python * [2022](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2022) 🌟 `20` - Python
* [2021](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2021) 🌟 ` 5` - Python * [2021](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2021) 🌟 ` 5` - Python
* [2020](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2020) 🌟 `20` - Javascript * [2020](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2020) 🌟 `20` - Javascript
* [2019](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2019) 🌟 `22` - Zig * [2019](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2019) 🌟 `22` - Zig
@@ -18,6 +18,6 @@ a programming language I'm interested in learning more about.
* 2016 🌟 `16` - LISP? * 2016 🌟 `16` - LISP?
* 2015 🌟 ` 9` - Ruby? * 2015 🌟 ` 9` - Ruby?
Total: 🌟 `96` Total: 🌟 `98`
Maybe I'll backfill some of the old years one day. Maybe I'll backfill some of the old years one day.