Day 10
This commit is contained in:
34
day10/ex2/main.go
Normal file
34
day10/ex2/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"aoc2022/day10/common"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
program := common.Parse(*bufio.NewScanner(os.Stdin))
|
||||
cpu := common.NewCPU()
|
||||
screen := [240]rune{}
|
||||
i := 0
|
||||
done := false
|
||||
|
||||
for !done {
|
||||
xValue := cpu.GetRegisterValue("X")
|
||||
if xValue >= (i % 40) - 1 && xValue <= (i % 40) + 1 {
|
||||
screen[i] = '#'
|
||||
} else {
|
||||
screen[i] = '.'
|
||||
}
|
||||
done = program.ExecuteCycles(cpu, 1)
|
||||
i = (i + 1) % 240
|
||||
}
|
||||
|
||||
for i := 0; i < 6; i++ {
|
||||
for j := 0; j < 40; j++ {
|
||||
fmt.Print(string(screen[i*40+j]))
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user