Skip to content

Commit 3d768e6

Browse files
committed
Day 05
1 parent 5a57efa commit 3d768e6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

05_cpu_jump.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def run(input, lim)
2+
input = input.dup
3+
n = 0
4+
pc = 0
5+
while pc >= 0 && (offset = input[pc])
6+
n += 1
7+
input[pc] = offset + (offset >= lim ? -1 : 1)
8+
pc += offset
9+
end
10+
n
11+
end
12+
13+
input = ARGF.map(&method(:Integer)).freeze
14+
15+
puts run(input, Float::INFINITY)
16+
puts run(input, 3)

0 commit comments

Comments
 (0)