Skip to content

Commit

Permalink
day 10 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-W-Kozdon committed Dec 10, 2022
1 parent d9b54fa commit ef3aca3
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 0 deletions.
78 changes: 78 additions & 0 deletions adventOfCode22d10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 10 13:22:18 2022
@author: xBubblex
"""

import re
import numpy as np

def load_files():
fContent = []
with open("input10.txt") as f:

for (lineIndex, line) in enumerate(f): #loading the file into an np.array
if bool(line):
fContent.append(line.strip("\n").split(" "))
for lineIdx, line in enumerate(fContent):
if len(fContent[lineIdx]) == 2:
fContent[lineIdx][1] = int(line[1])
if len(fContent[lineIdx]) != 2:
fContent[lineIdx] += [0]

return(fContent)

# print(load_files())

class Signal():
def __init__(self):
self.signal = load_files()
self.signalStr = [1]
self.totalStr = 0
self.params = [20, 40]

def find_str(self):
# print(len(self.signal))
# for line in self.signal:
# print(line[1])
toAdd1 = 0
toAdd2 = 0
for lineIdx, line in enumerate(self.signal):
# print(self.signalStr[-1], line)

if line[0] != "noop":
toAdd1 = line[1]
self.signalStr += [self.signalStr[-1]]
self.signalStr += [self.signalStr[-1] + line[1]]
if line[0] == "noop":
self.signalStr += [self.signalStr[-1]]


# self.signalStr.pop(0)
# self.signalStr.pop(0)
# print(self.signalStr)
# print(self.signalStr[220])
for lineIdx, line in enumerate(self.signalStr):

self.signalStr[lineIdx] = line * (lineIdx + 1)

# print(self.signalStr)
# print(self.signalStr.index(21))
# print(self.signalStr[20])
# print(self.signalStr)
# print(self.signalStr[self.params[0] - 1::self.params[1]])
self.totalStr = sum(self.signalStr[self.params[0] - 1::self.params[1]])
return self

def run():
signal = Signal()
signal.find_str()
print(signal.totalStr)
return signal.totalStr

print(run())

# x = [2 * i for i in range(20)]
# print(x)
# print(x[2::5])
146 changes: 146 additions & 0 deletions input10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
addx 1
addx 4
noop
noop
noop
noop
addx 6
addx -1
noop
addx 5
noop
addx 5
noop
noop
noop
addx 1
addx 3
addx 1
addx 6
addx -1
noop
noop
noop
addx 7
noop
addx -39
noop
noop
noop
addx 7
addx 3
addx -2
addx 2
noop
addx 3
addx 2
addx 5
addx 2
addx -8
addx 13
noop
addx 3
addx -2
addx 2
addx 5
addx -31
addx 36
addx -2
addx -36
noop
noop
noop
addx 3
addx 5
addx 2
addx -7
addx 15
addx -5
addx 5
addx 2
addx 1
addx 4
noop
addx 3
noop
addx 2
addx -13
addx -16
addx 2
addx 35
addx -40
noop
noop
addx 7
noop
noop
noop
addx 5
noop
addx 5
addx 10
addx -10
noop
noop
noop
addx 3
noop
addx 16
addx -9
noop
noop
noop
addx 3
noop
addx 7
addx -32
addx 35
addx -38
addx 22
addx 10
addx -29
addx 2
noop
addx 3
addx 5
addx 2
addx 2
addx -12
addx 13
noop
noop
addx 7
addx 5
noop
noop
noop
addx 7
addx -6
addx 2
addx 5
addx -38
addx 1
noop
noop
addx 2
noop
addx 3
addx 5
noop
addx 4
addx -2
addx 5
addx 2
addx 1
noop
addx 4
addx 4
addx -14
addx 16
noop
addx -13
addx 18
addx -1
noop
noop
noop

0 comments on commit ef3aca3

Please sign in to comment.