From e416a50231b5baceb335a3c71bf5bfeb2237573a Mon Sep 17 00:00:00 2001 From: Codinget Date: Sat, 10 Dec 2022 18:57:16 +0000 Subject: [PATCH] day 10, wren --- d10-wren/main.wren | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 d10-wren/main.wren diff --git a/d10-wren/main.wren b/d10-wren/main.wren new file mode 100644 index 0000000..7d34721 --- /dev/null +++ b/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) \ No newline at end of file