adventofcode/2019/day25/main.go

97 lines
24 KiB
Go
Raw Normal View History

2020-11-06 21:04:08 +00:00
package main
import (
"fmt"
"os"
"time"
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
termboxScreen "github.com/br0xen/termbox-screen"
)
const (
MODE_RUN = iota
MODE_EXIT
)
var UI *termboxScreen.Manager
func main() {
var err error
filename := h.GetArgNumber(1)
var prog []int
if filename != "" {
prog = intcode.ReadIntCodeFile("input")
} else {
prog = LoadMyInput()
}
p := intcode.NewProgram(prog)
UI = termboxScreen.NewManager()
if err = UI.AddAndInitializeScreen(NewScreen(p)); err != nil {
UI.Close()
fmt.Println(err.Error())
os.Exit(1)
}
UI.SetRefreshRate(time.Second / 10)
if err := UI.Loop(); err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
}
/*
func part1(prog []int) {
p := intcode.NewProgram(prog)
go func() {
for p.State == intcode.RET_OK {
printAllOutput(p)
for !p.NeedsInput() {
time.Sleep(time.Millisecond)
}
var err error
var inp string
err = errors.New("Need Input")
for err != nil {
fmt.Print("> ")
reader := bufio.NewReader(os.Stdin)
inp, err = reader.ReadString('\n')
if inp == "\n" {
err = errors.New("Need Input")
}
}
fmt.Print("Sending input: ")
for k := range inp {
for !p.NeedsInput() {
time.Sleep(1)
}
fmt.Print(string(inp[k]))
p.Input(int(inp[k]))
}
fmt.Println()
}
}()
fmt.Println("BEGIN")
p.Run()
fmt.Println("END")
}
func printAllOutput(p *intcode.Program) {
for {
if p.NeedsInput() {
return
}
if p.NeedsOutput() {
out := p.Output()
fmt.Print(string(out))
}
time.Sleep(1)
}
}
*/
func LoadMyInput() []int {
return []int{109, 4795, 21102, 3124, 1, 1, 21102, 1, 13, 0, 1105, 1, 1424, 21102, 166, 1, 1, 21102, 24, 1, 0, 1106, 0, 1234, 21101, 31, 0, 0, 1105, 1, 1984, 1106, 0, 13, 6, 4, 3, 2, 52, 51, 21, 4, 28, 56, 55, 3, 19, -9, -10, 47, 89, 88, 90, 90, 6, 77, 73, 85, 71, 1, 76, 68, 63, 65, 22, -27, 70, 76, 81, 87, 5, 105, 105, 107, 108, 95, 4, 97, 92, 109, 109, 5, 110, 105, 110, 108, 95, 4, 115, 96, 109, 109, 13, -3, 59, 101, 85, 92, 97, 13, 84, 80, 92, 78, 34, -15, 26, -16, 46, 88, 72, 79, 84, 0, 72, 76, -3, 85, 74, 79, 75, -8, 64, 68, 75, 57, 65, 70, 64, 66, 72, 8, -41, 32, -22, 56, 77, 82, -4, 60, 76, 62, 70, -2, 74, -11, 55, 52, 68, 67, 73, 56, 60, 52, -20, 44, 56, 66, -24, 48, 58, 42, 49, 54, -16, -53, 10, 0, 56, 99, 96, 95, 82, 94, 83, 45, -9, 23, -13, 61, 85, 88, 74, 71, 82, 73, 79, 73, 89, 67, 65, -4, 62, 73, 70, 69, 56, 68, 57, 2, -35, 24, -14, 64, 85, 90, 4, 70, 67, 79, 7, 83, -2, 68, 75, -5, 78, 65, 57, 75, -10, 76, 53, 76, 0, -37, 31, -21, 57, 78, 83, -3, 64, 74, 72, 0, 76, -9, 73, 58, 57, -13, 70, 57, 49, 67, -18, 54, 64, 48, 55, -23, 48, 44, 56, 42, -14, -51, 14, -4, 74, 95, 100, 14, 97, 77, 86, 79, 9, 92, 79, 75, 5, 27, -17, 61, 82, 87, 1, 68, 78, 76, 4, 80, -5, 66, 58, 78, 60, -10, 73, 60, 52, 70, -15, 57, 67, 51, 58, -6, -43, 14, -4, 74, 95, 100, 14, 81, 94, 90, 90, 9, 92, 79, 75, 5, 60, -50, 23, 42, 38, -32, 38, 39, 30, 42, 47, -38, 30, 36, 28, 25, 41, 38, 34, 31, 18, 23, 29, 19, 33, -52, 20, 29, -55, 27, 27, 27, 8, 15, -61, 22, 16, -64, 24, 13, 18, -54, -69, -70, -14, 7, 12, -74, -8, -11, 1, -71, 5, -80, -4, -3, 3, -15, -84, -85, -109, 29, -19, 59, 80, 85, -1, 82, 62, 71, 64, -6, 77, 64, 60, -10, 62, 66, 57, 59, 63, 57, 67, 51, -19, 56, 58, 57, 57, -10, -47, 44, -34, 39, 58, 54, -16, 60, 61, 57, 64, 48, 56, -23, 52, 40, 60, 38, -28, 44, 53, -31, 55, 32, 55, -35, 48, 42, 41, -39, 32, 38, 42, -42, -44, 12, 33, 38, -48, 28, 19, 25, 32, -52, -76, -77, 59, -49, 13, 55, -30, 42, 51, -33, 49, 50, 32, 31, 31, 39, 36, 48, -42, 24, 35, 32, 34, 29, 21, 35, 19, 25, 37, -53, 14, 10, 26, 18, -57, -59, -3, 18, 23, -63, 1, 17, 3, -67, 1, -4, 14, -2, 6, -73, -8, 14, -76, -12, -78, -40, 2, 4, -13, -82, -106, -107, 35, -25, 53, 74, 79, 0, 74, 60, -10, 65, 53, 72, 64, 52, 56, 52, 50, -19, 53, 57, 62, 56, -24, 58, 54, 38, 39, 40, -29, -31, 2, 56, 35, -34, -58, -59, 138, -128, -74, -108, -33, -31, -26, -44, -101, -114, -33, -37, -51, -39, -35, -47, -54, -122, -37, -45, -52, -59, -58, -128, -46, -65, -42, -49, -133, -132, -102, -60, -68, -56, -55, -139, -141, -106, -61, -65, -72, -78, -64, -148, -70, -72, -151, -68, -81, -81, -72, -156, -74, -86, -86, -80, -161, -97, -81, -95, -165, -94, -98, -103, -83, -97, -102, -90, -173, -90, -103, -111, -99, -178, -95, -108, -112, -182, -115, -115, -101, -117, -120, -104, -120, -122, -191, -106, -128, -118, -110, -127, -196, -196, -199, -135, -123, -134, -203, -115, -126, -121, -207, -143, -127, -141, -211, -143, -139, -145, -148, -132, -148, -150, -219, -154, -156, -155, -148, -224, -141, -147, -227, -144, -157, -161, -231, -165, -161, -165, -168, -161, -157, -159, -166, -162, -157, -228, -265, 138, -128, -74, -108, -33, -31, -26, -44, -101, -114, -33, -37, -51, -39, -35, -47, -54, -122, -37, -45, -52, -59, -58, -128, -46, -65, -42, -49, -133, -132, -102, -60, -68, -56, -55, -139, -141, -106, -61, -65, -72, -78, -64, -148, -70, -72, -151, -68, -81, -81, -72, -156, -74, -86, -86, -80, -161, -97, -81, -95, -165, -90, -94, -97, -97, -86, -102, -90, -173, -90, -103, -111, -99, -178, -95, -108, -112, -182, -115, -115, -101, -117, -120, -104, -120, -122, -191, -106, -128, -118, -110, -127, -196, -196, -199, -135, -123, -134, -203, -115, -126, -121, -207, -143, -127, -141, -211, -143, -139, -145, -148, -132, -148, -150, -219, -154, -156, -155, -148, -224, -141, -147, -227, -144, -157, -161, -231, -165, -161, -165, -168, -161, -157, -159, -166, -162, -157, -228, -265, 263, -253, -199, -233, -158, -156, -151, -169, -226, -239, -158, -162, -176, -164, -160, -172, -179, -247, -162, -170, -177, -184, -183, -253, -171, -190, -167, -174, -258, -257, -227, -183, -197, -187, -175, -182, -193, -184, -268, -2
}