You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
911 B
53 lines
911 B
import "aoc" for AoC
|
|
|
|
class CPU {
|
|
construct new() {
|
|
_cycle = 0
|
|
_x = 1
|
|
|
|
_every20 = 0
|
|
_str = ""
|
|
}
|
|
|
|
every20 { _every20 }
|
|
str { _str }
|
|
|
|
tick() {
|
|
_cycle = _cycle + 1
|
|
if(_cycle % 40 == 20) {
|
|
_every20 = _every20 + _x * _cycle
|
|
}
|
|
var px = _cycle % 40
|
|
if(px == _x || px == _x + 1 || px == _x + 2) {
|
|
_str = _str + "#"
|
|
} else {
|
|
_str = _str + "."
|
|
}
|
|
if(_cycle % 40 == 0) {
|
|
_str = _str + "\n"
|
|
}
|
|
}
|
|
|
|
noop() {
|
|
tick()
|
|
}
|
|
|
|
addx(x) {
|
|
tick()
|
|
tick()
|
|
_x = _x + x
|
|
}
|
|
}
|
|
|
|
var cpu = CPU.new()
|
|
|
|
for(line in AoC.input.split("\n").where {|l| l != ""}) {
|
|
if(line == "noop") {
|
|
cpu.noop()
|
|
} else {
|
|
cpu.addx(Num.fromString(line.split(" ")[1]))
|
|
}
|
|
}
|
|
|
|
System.print(cpu.every20)
|
|
System.print(cpu.str) |