Skip to content

Commit

Permalink
solve day8 from 2020
Browse files Browse the repository at this point in the history
  • Loading branch information
SylivanKenobi committed Dec 4, 2024
1 parent 136b340 commit ff75e29
Show file tree
Hide file tree
Showing 4 changed files with 1,466 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 2020/Day8.1/day8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
file = File.open('input.txt')
input = file.read.split("\n")

i = 0
result = 0
command_history = []
while i < input.length
pp "#{input[i]} #{i} #{result}"
if command_history.include?(i)
break
end
command = input[i].scan(/[a-zA-Z]+/)[0]
number = input[i].scan(/[0-9]+/)[0].to_i
operator = input[i].scan(/\+|\-/)[0]
case command
when "acc"
command_history.append(i)
if operator == "+"
result = result + number
else
result = result - number
end
i = i + 1
when "jmp"
command_history.append(i)
if operator == "+"
i = i + number
else
i = i - number
end
when "nop"
command_history.append(i)
i = i + 1
end
end
pp result
Loading

0 comments on commit ff75e29

Please sign in to comment.