-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
51 lines (47 loc) · 876 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'io/console'
require_relative '../common/intcode'
INST = File.read('data.txt').split(',').map(&:to_i)
def part1
script = [
'OR A T',
'AND B T',
'AND C T',
'NOT T J',
'AND D J',
'NOT A T',
'OR T J',
'WALK',
]
c = Cpu.new INST
script.each do |s|
c.write_string s
c.write_input 10
end
c.run
c.read_all_out.last
end
def part2
script = [
'OR A T',
'AND B T',
'AND C T',
'NOT T J',
'AND D J',
'AND I T',
'AND E T',
'OR H T',
'AND T J',
'NOT A T',
'OR T J',
'RUN',
]
c = Cpu.new INST
script.each do |s|
c.write_string s
c.write_input 10
end
c.run
c.read_all_out.last
end
puts 'Part 1: %s' % part1
puts 'Part 2: %s' % part2