day 10, wren

main
Codinget 2 years ago
parent 8b771666f3
commit e416a50231
  1. 53
      d10-wren/main.wren

@ -0,0 +1,53 @@
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)
Loading…
Cancel
Save