m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/08/a.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:23:39 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:23:39 +0100
commit1362f76e60c32a7bf0e7240b01524d16734f8dd4 (patch)
tree134e5794c1784259e81cc383712dde4e0fd6afb9 /08/a.rb
parente2dd1e03066c593a1df19190c4c72f27ea9714dd (diff)
Add day 8
Diffstat (limited to '08/a.rb')
-rw-r--r--08/a.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/08/a.rb b/08/a.rb
new file mode 100644
index 0000000..60122eb
--- /dev/null
+++ b/08/a.rb
@@ -0,0 +1,25 @@
+code = []
+
+File.readlines('input.txt').each do |line|
+ instruction, number = line.split
+ code.push [instruction, number.to_i]
+end
+
+visited = {}
+current_line = 0
+acc = 0
+
+while !visited[current_line]
+ visited[current_line] = true
+ case code[current_line][0]
+ when 'nop'
+ current_line += 1
+ when 'acc'
+ acc += code[current_line][1]
+ current_line += 1
+ when 'jmp'
+ current_line += code[current_line][1]
+ end
+end
+
+puts acc