diff --git a/2019/day25/cli_processor.go b/2019/day25/cli_processor.go new file mode 100644 index 0000000..f32fb0b --- /dev/null +++ b/2019/day25/cli_processor.go @@ -0,0 +1,264 @@ +package main + +import ( + "errors" + "strings" + + "github.com/nsf/termbox-go" +) + +type CliProc struct { + History []string + HistoryIdx int + Suggestions []string // Suggestions are 'autocomplete' commands + Proposals []string // Proposals are proposed 'next' commands + + Buffer string + Cursor int + + Complete bool +} + +func NewCLI() *CliProc { + c := CliProc{} + return &c +} + +func (c *CliProc) handleEvent(event termbox.Event) error { + if c.Complete { + return nil + } + if event.Ch == 0 { + switch event.Key { + case termbox.KeyEnter: + // Execute command + c.Complete = true + + case termbox.KeySpace: + c.putInBuffer(" ") + + case termbox.KeyBackspace, termbox.KeyBackspace2: + if c.Cursor > 0 { + c.Buffer = c.Buffer[:c.Cursor-1] + c.Buffer[c.Cursor:] + c.Cursor = c.Cursor - 1 + } + case termbox.KeyDelete: + if c.Cursor < len(c.Buffer) { + c.Buffer = c.Buffer[:c.Cursor] + c.Buffer[c.Cursor+1:] + } + + case termbox.KeyArrowLeft: + if c.Cursor > 0 { + c.Cursor = c.Cursor - 1 + } + case termbox.KeyArrowRight: + if c.Cursor < len(c.Buffer) { + c.Cursor = c.Cursor + 1 + } else { + // Complete suggestion + } + case termbox.KeyHome: + c.Cursor = 0 + case termbox.KeyEnd: + c.Cursor = len(c.Buffer) + + case termbox.KeyArrowUp: + val, err := c.HistoryBack() + if err != nil { + return err + } + c.Buffer = val + c.Cursor = len(c.Buffer) + + case termbox.KeyArrowDown: + val, err := c.HistoryForward() + if err != nil { + return err + } + c.Buffer = val + c.Cursor = len(c.Buffer) + + case termbox.KeyTab: + // Complete suggestion + args := strings.Split(c.Buffer, " ") + acText := strings.TrimPrefix(c.GetAutocompleteText(), args[len(args)-1]) + if len(acText) > 0 { + c.Buffer = c.Buffer + acText + c.Cursor = len(c.Buffer) + } + + case termbox.KeyCtrlU: + // Delete everything from the cursor forward + c.Buffer = c.Buffer[c.Cursor:] + c.Cursor = 0 + } + } else { + c.putInBuffer(string(event.Ch)) + /* + if c.Cursor == len(c.Buffer) { + c.Buffer = c.Buffer + string(event.Ch) + } else { + c.Buffer = c.Buffer[:c.Cursor] + string(event.Ch) + c.Buffer[c.Cursor:] + } + c.Cursor = c.Cursor + 1 + */ + } + return nil +} + +func (c *CliProc) putInBuffer(v string) { + c.Buffer = c.Buffer[:c.Cursor] + v + c.Buffer[c.Cursor:] + c.Cursor = c.Cursor + 1 +} + +func (c *CliProc) ClearBuffer() { + c.Buffer = "" + c.Cursor = 0 + c.Complete = false +} + +func (c *CliProc) GetBuffer() string { + return c.Buffer +} + +func (c *CliProc) HistoryBack() (string, error) { + if len(c.History) < c.HistoryIdx+1 { + return "", errors.New("Already at oldest command") + } + c.HistoryIdx = c.HistoryIdx + 1 + return c.History[len(c.History)-c.HistoryIdx], nil +} + +func (c *CliProc) HistoryForward() (string, error) { + if c.HistoryIdx == 0 { + return "", errors.New("Already at most recent command") + } + c.HistoryIdx = c.HistoryIdx - 1 + if c.HistoryIdx == 0 { + return "", nil + } + return c.History[len(c.History)-c.HistoryIdx], nil +} + +func (c *CliProc) Suggest(cmd string) string { + allSuggestions := c.GetAllSuggestions(cmd) + if len(allSuggestions) == 0 { + return "" + } + return allSuggestions[0] +} + +func (c *CliProc) GetDisplaySuggestions() []string { + var ret []string + v := c.GetAllSuggestions(c.Buffer) + if len(c.Buffer) > 0 { + for k := range v { + if strings.HasPrefix(v[k], c.Buffer) { + ret = append(ret, v[k]) + } + } + } else { + // Normally, filter out 'drop's + for k := range v { + if !strings.HasPrefix(v[k], "drop ") { + ret = append(ret, v[k]) + } + } + } + return ret +} + +func (c *CliProc) GetAllSuggestions(cmd string) []string { + var ret []string + args := strings.Fields(cmd) + if len(args) == 0 { + // Return all commands + for _, v := range c.Suggestions { + ret = append(ret, v) + } + return ret + } else if len(args) == 1 && !strings.HasSuffix(cmd, " ") { + for _, v := range c.Suggestions { + if strings.HasPrefix(v, args[0]) { + ret = append(ret, v) + } + } + } + return ret +} + +func (c *CliProc) Draw(x, y int, bg, fg termbox.Attribute) { + DrawString("[ "+strings.Join(c.GetDisplaySuggestions(), ", ")+" ]", x, y, bg, fg) + y = y + 1 + prompt := '>' + termbox.SetCell(x, y, prompt, bg, fg) + x = x + 2 + for k := range c.Buffer { + useFg, useBg := bg, fg + if k == c.Cursor { + useFg, useBg = fg, bg + } + termbox.SetCell(x+k, y, rune(c.Buffer[k]), useFg, useBg) + } + args := strings.Split(c.Buffer, " ") + acText := strings.TrimPrefix(c.GetAutocompleteText(), args[len(args)-1]) + if len(acText) > 0 { + for k := range acText { + useFg, useBg := bg|termbox.AttrBold, fg + if k == 0 && c.Cursor == len(c.Buffer) { + useFg, useBg = fg|termbox.AttrBold, bg + } + termbox.SetCell(x+len(c.Buffer)+k, y, rune(acText[k]), useFg, useBg) + } + } else { + if c.Cursor == len(c.Buffer) { + termbox.SetCell(x+len(c.Buffer), y, ' ', fg, bg) + } + } +} + +func (c *CliProc) GetAutocompleteText() string { + suggestions := c.GetAllSuggestions(c.Buffer) + if len(suggestions) == 1 { + args := strings.Split(c.Buffer, " ") + return strings.TrimPrefix(suggestions[0], args[len(args)-1]) + } else if len(suggestions) > 1 { + // Find how many characters we _can_ autocomplete + var ret string + for k := range suggestions[0] { + allHave := true + for wrk := range suggestions { + if len(suggestions[wrk]) <= k || suggestions[0][k] != suggestions[wrk][k] { + allHave = false + break + } + } + if allHave { + ret = ret + string(suggestions[0][k]) + } + } + return ret + } + return "" +} + +func (c *CliProc) ClearSuggestions() { + c.Suggestions = nil +} + +func (c *CliProc) AddSuggestion(s string) { + c.AddSuggestions([]string{s}) +} +func (c *CliProc) AddSuggestions(s []string) { + c.Suggestions = append(c.Suggestions, s...) +} + +func (c *CliProc) RemoveSuggestion(s string) { + var i int + for i = range c.Suggestions { + if c.Suggestions[i] == s { + break + } + } + c.Suggestions = append(c.Suggestions[:i], c.Suggestions[i+1:]...) +} diff --git a/2019/day25/debug-log b/2019/day25/debug-log new file mode 100644 index 0000000..9c0d1a1 --- /dev/null +++ b/2019/day25/debug-log @@ -0,0 +1,1382 @@ +2687: ADD 2101 (3094, -3, 2693) + +2695: ADD 21201 (-3, 1, -3) + +2011: ADD 21101 (0, 0, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2055: ADD 21201 (-1, 1, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2603: ADD 21101 (-1, 0, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2055: ADD 21201 (-1, 1, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2603: ADD 21101 (-1, 0, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2055: ADD 21201 (-1, 1, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2603: ADD 21101 (-1, 0, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2055: ADD 21201 (-1, 1, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2603: ADD 21101 (-1, 0, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2055: ADD 21201 (-1, 1, -1) + +2015: ADD 1201 (-1, 1894, 2020) + +2027: ADD 21101 (0, 0, 3) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2577: ADD 20101 (0, 2524, -4) + +2041: ADD 1201 (-1, 1934, 2050) + +2128: ADD 1101 (0, 0, 2124) + +2136: ADD 21101 (13, 0, 2) + +2144: ADD 21101 (2173, 0, 4) + +2148: ADD 21101 (2154, 0, 0) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2179: ADD 1201 (-2, 0, 2183) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2179: ADD 1201 (-2, 0, 2183) + +2190: ADD 1201 (-2, 1, 2194) + +2194: ADD 21001 (4606, 0, -1) + +2198: ADD 21201 (-1, 0, 1) + +2528: ADD 1201 (-3, 0, 2523) + +2540: ADD 21101 (2585, 0, 2) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +2588: ADD 22201 (-4, -3, -4) + +2592: ADD 22201 (-4, -2, -4) + +2607: ADD 201 (-3, 2523, 2615) + +2611: ADD 1001 (2615, 3094, 2615) + +1223: ADD 21201 (-3, 1, -3) + +2554: ADD 2101 (0, -4, 2558) + +2558: ADD 2001 (4664, -3, 2566) + +2562: ADD 101 (3094, 2566, 2566) + +2577: ADD 20101 (0, 2524, -4) + +2220: ADD 21101 (258, 0, 1) + +2224: ADD 21101 (0, 2230, 0) + +1237: ADD 22101 (0, -1, 1) + +1241: ADD 21101 (0, 1256, 2) + +1245: ADD 21101 (1251, 0, 0) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +2231: ADD 21201 (-1, 0, 1) + +2235: ADD 21101 (0, 2241, 0) + +1237: ADD 22101 (0, -1, 1) + +1241: ADD 21101 (0, 1256, 2) + +1245: ADD 21101 (1251, 0, 0) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +2250: ADD 1201 (-2, 0, 2256) + +2258: ADD 1201 (-2, 3, 2262) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +1163: ADD 21201 (-2, 1, -2) + +1237: ADD 22101 (0, -1, 1) + +1241: ADD 21101 (0, 1256, 2) + +1245: ADD 21101 (1251, 0, 0) + +1177: ADD 1201 (-5, 0, 1182) + +1185: ADD 21101 (0, 0, -3) + +1189: ADD 21201 (-5, 1, -5) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +1200: ADD 2201 (-5, -3, 1205) + +1216: ADD 21101 (0, 1222, 0) + +1259: ADD 22201 (-4, -3, -1) + +1263: ADD 22201 (-2, -1, -1) + +1223: ADD 21201 (-3, 1, -3) + +25: ADD 21101 (31, 0, 0) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3094) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3095) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3096) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3097) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3098) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3099) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3100) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3101) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3102) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3103) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3104) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3105) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3106) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3107) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3108) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3109) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3110) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3111) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3112) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3113) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3114) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3115) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3116) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3117) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3118) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3119) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3120) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3121) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3122) + +1163: ADD 21201 (-2, 1, -2) + +1148: ADD 22201 (1, -6, 1) + +1152: ADD 21201 (-2, 0, 2) + +2709: ADD 1201 (-1, 0, 2715) + +2713: ADD 1101 (0, -1, 3123) + +1163: ADD 21201 (-2, 1, -2) + +2660: ADD 21101 (0, 0, -3) + diff --git a/2019/day25/event_buffer.go b/2019/day25/event_buffer.go new file mode 100644 index 0000000..9fd82b0 --- /dev/null +++ b/2019/day25/event_buffer.go @@ -0,0 +1,175 @@ +package main + +import ( + "strconv" + "time" + + "github.com/nsf/termbox-go" +) + +const ( + DefaultExpireTime = time.Second / 2 +) + +type EventBuffer struct { + UpdateTime time.Time + TimeoutLen time.Duration + Buffer []termbox.Event + CursorPos int +} + +func NewEventBuffer() *EventBuffer { + return &EventBuffer{ + TimeoutLen: DefaultExpireTime, + CursorPos: -1, + } +} + +func (eb *EventBuffer) checkExpiration() { + if eb.TimeoutLen != -1 && time.Now().Sub(eb.UpdateTime) > eb.TimeoutLen { + eb.Clear() + } +} + +func (eb *EventBuffer) StartsWith(r rune) bool { + eb.checkExpiration() + return len(eb.Buffer) > 0 && eb.Buffer[0].Ch == r +} + +func (eb *EventBuffer) Add(event termbox.Event) { + eb.checkExpiration() + if event.Key == termbox.KeyCtrlU { + eb.Clear() + } else if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 { + eb.Backspace() + } else { + eb.Buffer = append(eb.Buffer, event) + } + eb.UpdateTime = time.Now() +} + +func (eb *EventBuffer) Backspace() { + eb.checkExpiration() + if len(eb.Buffer) >= 1 { + eb.Buffer = eb.Buffer[:len(eb.Buffer)-1] + } + eb.UpdateTime = time.Now() +} + +func (eb *EventBuffer) MoveCursorBack() { + if eb.CursorPos > 0 { + eb.CursorPos-- + } +} + +func (eb *EventBuffer) MoveCursorForward() { + if eb.CursorPos < len(eb.Buffer) { + eb.CursorPos++ + } +} + +func (eb *EventBuffer) SetCursorToStart() { + eb.CursorPos = 0 +} + +func (eb *EventBuffer) SetCursorToEnd() { + eb.CursorPos = len(eb.Buffer) +} + +func (eb *EventBuffer) Clear() { + eb.Buffer = nil + eb.UpdateTime = time.Now() +} + +func (eb *EventBuffer) Events() []termbox.Event { + eb.checkExpiration() + return eb.Buffer +} + +func (eb *EventBuffer) String() string { + eb.checkExpiration() + var ret string + for _, v := range eb.Buffer { + if v.Ch != 0 { + ret = ret + string(v.Ch) + } else { + switch v.Key { + case termbox.KeySpace: + ret = ret + " " + case termbox.KeyArrowUp: + ret = ret + string(ChUpKeyValue) + case termbox.KeyArrowRight: + ret = ret + string(ChRightKeyValue) + case termbox.KeyArrowDown: + ret = ret + string(ChDownKeyValue) + case termbox.KeyArrowLeft: + ret = ret + string(ChLeftKeyValue) + case termbox.KeyEnter: + ret = ret + string(ChEnterKeyValue) + } + } + } + return ret +} + +func (eb *EventBuffer) SetToString(s string) { + eb.Clear() + for _, v := range s { + if v == '\n' { + eb.Add(termbox.Event{Ch: 0, Key: termbox.KeyEnter}) + } else { + eb.Add(termbox.Event{Ch: v}) + } + } +} + +func (eb *EventBuffer) MatchesString(s string) bool { + eb.checkExpiration() + if len(s) != len(eb.Buffer) { + return false + } + return s == eb.String() +} + +func (eb *EventBuffer) MatchesEvents(events []termbox.Event) bool { + eb.checkExpiration() + if len(events) != len(eb.Buffer) { + return false + } + for k := range events { + if events[k].Ch != eb.Buffer[k].Ch || events[k].Key != eb.Buffer[k].Key { + return false + } + } + return true +} + +func (eb *EventBuffer) StartsWithKey(key termbox.Key) bool { + eb.checkExpiration() + if len(eb.Buffer) > 0 { + return eb.Buffer[0].Key == key + } + return false +} + +func (eb *EventBuffer) Size() int { + eb.checkExpiration() + return len(eb.Buffer) +} + +func (eb *EventBuffer) IsNumber() bool { + _, err := strconv.Atoi(eb.String()) + return err == nil +} + +func (eb *EventBuffer) Number() (int, error) { + return strconv.Atoi(eb.String()) +} + +func (eb *EventBuffer) OptNumber(def int) int { + ret, err := strconv.Atoi(eb.String()) + if err != nil { + return def + } + return ret +} diff --git a/2019/day25/input b/2019/day25/input new file mode 100644 index 0000000..a39706c --- /dev/null +++ b/2019/day25/input @@ -0,0 +1 @@ +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,-202,-191,-194,-192,-197,-205,-191,-207,-276,-278,-222,-201,-196,-282,-206,-219,-196,-286,-207,-206,-210,-223,-222,-223,-225,-280,-293,-296,-232,-220,-231,-300,-212,-223,-218,-304,-236,-228,-223,-239,-227,-310,-227,-240,-244,-314,-248,-237,-250,-243,-239,-247,-237,-308,-345,-273,-260,-248,-243,-263,-329,-252,-252,-248,-260,-267,-266,-253,-337,-249,-260,-255,-259,-342,-260,-267,-280,-270,-271,-348,-281,-268,-272,-279,-285,-342,-355,-280,-278,-279,-284,-277,-361,-282,-278,-274,-275,-290,-298,-300,-369,-300,-292,-290,-373,-309,-375,-299,-298,-301,-310,-302,-297,-370,-383,-302,-316,-321,-311,-315,-299,-321,-308,-392,-306,-322,-330,-312,-397,-326,-334,-317,-401,-330,-338,-324,-325,-337,-329,-339,-341,-398,-411,-347,-335,-346,-415,-334,-352,-350,-346,-341,-338,-422,-334,-345,-340,-344,-427,-345,-357,-357,-351,-432,-365,-361,-353,-367,-370,-354,-363,-351,-427,-464,-441,-397,-373,-434,-447,-376,-380,-374,-375,-373,-452,-454,-398,-377,-372,-458,-376,-388,-382,-377,-387,-396,-465,-400,-398,-468,-404,-404,-395,-403,-473,-390,-396,-476,-406,-409,-395,-480,-408,-404,-483,-418,-396,-486,-403,-399,-409,-417,-413,-421,-493,37,-5,73,71,-8,75,62,58,-12,62,55,74,64,48,50,-19,45,63,-22,61,48,44,-26,50,37,44,48,-31,33,40,48,41,43,30,37,-25,-38,-63,0,0,109,7,21102,0,1,-2,22208,-2,-5,-1,1205,-1,1169,22202,-2,-4,1,22201,1,-6,1,21201,-2,0,2,21102,1162,1,0,2106,0,-3,21201,-2,1,-2,1105,1,1136,109,-7,2105,1,0,109,6,1201,-5,0,1182,20102,1,0,-2,21101,0,0,-3,21201,-5,1,-5,22208,-3,-2,-1,1205,-1,1229,2201,-5,-3,1205,20102,1,0,1,21202,-3,1,2,22102,1,-2,3,21101,0,1222,0,2105,1,-4,21201,-3,1,-3,1106,0,1192,109,-6,2105,1,0,109,2,22101,0,-1,1,21101,0,1256,2,21101,1251,0,0,1106,0,1174,109,-2,2105,1,0,109,5,22201,-4,-3,-1,22201,-2,-1,-1,204,-1,109,-5,2106,0,0,109,3,2101,0,-2,1280,1006,0,1303,104,45,104,32,1201,-1,66,1291,21002,0,1,1,21101,0,1301,0,1106,0,1234,104,10,109,-3,2105,1,0,0,0,109,2,1201,-1,0,1309,1101,0,0,1308,21101,4601,0,1,21102,1,13,2,21102,4,1,3,21101,0,1353,4,21101,1343,0,0,1106,0,1130,21001,1308,0,-1,109,-2,2105,1,0,70,109,3,2101,0,-2,1360,20008,0,1309,-1,1206,-1,1419,1005,1308,1398,1101,0,1,1308,21008,1309,-1,-1,1206,-1,1387,21102,106,1,1,1106,0,1391,21102,92,1,1,21102,1,1398,0,1105,1,1234,104,45,104,32,1201,-2,1,1408,20101,0,0,1,21102,1,1417,0,1105,1,1234,104,10,109,-3,2106,0,0,109,3,2102,1,-2,1128,21102,34,1,1,21101,1441,0,0,1105,1,1234,1001,1128,0,1447,20101,0,0,1,21102,1,1456,0,1106,0,1234,21101,41,0,1,21102,1,1467,0,1105,1,1234,1001,1128,1,1473,20102,1,0,1,21101,1482,0,0,1106,0,1234,21102,1,46,1,21101,1493,0,0,1105,1,1234,21001,1128,3,1,21102,4,1,2,21102,1,1,3,21102,1273,1,4,21101,0,1516,0,1105,1,1130,21002,1128,1,1,21102,1,1527,0,1105,1,1310,1001,1128,2,1532,21001,0,0,-1,1206,-1,1545,21102,1545,1,0,2105,1,-1,109,-3,2105,1,0,109,0,99,109,2,1101,0,0,1550,21102,4601,1,1,21102,1,13,2,21102,1,4,3,21102,1664,1,4,21102,1,1582,0,1105,1,1130,2,2486,1352,1551,1101,0,0,1552,21001,1550,0,1,21101,0,33,2,21102,1,1702,3,21102,1,1609,0,1105,1,2722,21007,1552,0,-1,1205,-1,1630,20107,0,1552,-1,1205,-1,1637,21101,0,1630,0,1106,0,1752,21101,0,548,1,1105,1,1641,21102,687,1,1,21102,1648,1,0,1106,0,1234,21102,1,4457,1,21102,1,1659,0,1106,0,1424,109,-2,2106,0,0,109,4,21202,-2,-1,-2,1201,-3,0,1675,21008,0,-1,-1,1206,-1,1697,1201,-3,2,1687,20101,-27,0,-3,22201,-3,-2,-3,2001,1550,-3,1550,109,-4,2106,0,0,109,5,21008,1552,0,-1,1206,-1,1747,1201,-3,1901,1716,21001,0,0,-2,1205,-4,1736,20207,-2,1551,-1,1205,-1,1747,1102,-1,1,1552,1106,0,1747,22007,1551,-2,-1,1205,-1,1747,1101,0,1,1552,109,-5,2106,0,0,109,1,21102,826,1,1,21101,1765,0,0,1105,1,1234,20102,1,1550,1,21101,1776,0,0,1105,1,2863,21101,1090,0,1,21102,1,1787,0,1106,0,1234,99,1105,1,1787,109,-1,2106,0,0,109,1,21102,1,512,1,21101,1809,0,0,1106,0,1234,99,1105,1,1809,109,-1,2106,0,0,109,1,1102,1,1,1129,109,-1,2105,1,0,109,1,21102,1,377,1,21102,1,1842,0,1105,1,1234,1106,0,1831,109,-1,2105,1,0,109,1,21101,0,407,1,21101,0,1863,0,1106,0,1234,99,1106,0,1863,109,-1,2106,0,0,109,1,21102,1,452,1,21101,0,1885,0,1106,0,1234,99,1105,1,1885,109,-1,2105,1,0,1941,1947,1953,1958,1965,1972,1978,3584,4102,4099,3470,4223,3883,4100,3983,4146,4026,3610,3464,3599,3502,3738,3509,4167,3991,3449,3751,3564,3734,4060,3697,3805,4201,4057,3543,3545,3992,3674,4039,3751,2281,2468,2418,2450,2487,2125,2505,5,95,108,104,104,23,5,96,91,108,108,1,4,101,105,112,3,6,104,104,106,107,94,-1,6,109,104,109,107,94,-1,5,111,91,100,93,23,5,114,95,108,108,1,109,3,21102,1,1993,0,1106,0,2634,1006,1129,2010,21101,0,316,1,21101,2007,0,0,1105,1,1234,1106,0,2076,21101,0,0,-1,1201,-1,1894,2020,20102,1,0,1,21102,0,1,2,21101,0,0,3,21102,2037,1,0,1106,0,2525,1206,1,2054,1201,-1,1934,2050,21102,1,2051,0,105,1,0,1106,0,2076,21201,-1,1,-1,21207,-1,7,-2,1205,-2,2014,21102,177,1,1,21101,0,2076,0,1105,1,1234,109,-3,2105,1,0,109,3,2001,1128,-2,2089,20102,1,0,-1,1205,-1,2108,21102,1,201,1,21102,2105,1,0,1106,0,1234,1105,1,2119,22102,1,-1,1,21102,2119,1,0,1106,0,1424,109,-3,2106,0,0,0,109,1,1101,0,0,2124,21102,4601,1,1,21101,13,0,2,21102,1,4,3,21101,2173,0,4,21101,2154,0,0,1106,0,1130,1005,2124,2168,21102,1,226,1,21102,2168,1,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2124,2275,1201,-2,0,2183,20008,0,1128,-1,1206,-1,2275,1201,-2,1,2194,21001,0,0,-1,21201,-1,0,1,21102,5,1,2,21102,1,1,3,21102,1,2216,0,1105,1,2525,1206,1,2275,21101,258,0,1,21101,0,2230,0,1105,1,1234,21201,-1,0,1,21101,0,2241,0,1105,1,1234,104,46,104,10,1102,1,1,2124,1201,-2,0,2256,1102,-1,1,0,1201,-2,3,2262,21002,0,1,-1,1206,-1,2275,21101,2275,0,0,2105,1,-1,109,-3,2106,0,0,0,109,1,1101,0,0,2280,21101,4601,0,1,21102,1,13,2,21101,0,4,3,21102,2329,1,4,21101,2310,0,0,1106,0,1130,1005,2280,2324,21101,0,273,1,21102,1,2324,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2280,2413,1201,-2,0,2339,21008,0,-1,-1,1206,-1,2413,1201,-2,1,2350,21001,0,0,-1,21202,-1,1,1,21102,1,5,2,21102,1,1,3,21102,2372,1,0,1105,1,2525,1206,1,2413,21102,301,1,1,21102,2386,1,0,1105,1,1234,22101,0,-1,1,21101,0,2397,0,1106,0,1234,104,46,104,10,1101,1,0,2280,1201,-2,0,2412,101,0,1128,0,109,-3,2105,1,0,109,1,21102,-1,1,1,21101,2431,0,0,1106,0,1310,1205,1,2445,21102,1,133,1,21102,1,2445,0,1106,0,1234,109,-1,2106,0,0,109,1,21102,3,1,1,21101,2463,0,0,1105,1,2081,109,-1,2105,1,0,109,1,21101,4,0,1,21101,0,2481,0,1106,0,2081,109,-1,2105,1,0,59,109,1,21101,5,0,1,21102,1,2500,0,1106,0,2081,109,-1,2105,1,0,109,1,21102,1,6,1,21101,0,2518,0,1105,1,2081,109,-1,2105,1,0,0,0,109,5,1201,-3,0,2523,1102,1,1,2524,21202,-4,1,1,21101,2585,0,2,21102,1,2550,0,1106,0,1174,1206,-2,2576,2101,0,-4,2558,2001,0,-3,2566,101,3094,2566,2566,21008,0,-1,-1,1205,-1,2576,1101,0,0,2524,20101,0,2524,-4,109,-5,2106,0,0,109,5,22201,-4,-3,-4,22201,-4,-2,-4,21208,-4,10,-1,1206,-1,2606,21101,-1,0,-4,201,-3,2523,2615,1001,2615,3094,2615,21002,0,1,-1,22208,-4,-1,-1,1205,-1,2629,1102,0,1,2524,109,-5,2105,1,0,109,4,21102,1,3094,1,21102,1,30,2,21102,1,1,3,21102,2706,1,4,21102,2659,1,0,1105,1,1130,21101,0,0,-3,203,-2,21208,-2,10,-1,1205,-1,2701,21207,-2,0,-1,1205,-1,2663,21207,-3,29,-1,1206,-1,2663,2101,3094,-3,2693,1202,-2,1,0,21201,-3,1,-3,1106,0,2663,109,-4,2106,0,0,109,2,1201,-1,0,2715,1101,0,-1,0,109,-2,2106,0,0,0,109,5,1202,-2,1,2721,21207,-4,0,-1,1206,-1,2739,21101,0,0,-4,21201,-4,0,1,21201,-3,0,2,21102,1,1,3,21102,1,2758,0,1106,0,2763,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,2786,22207,-5,-3,-1,1206,-1,2786,21201,-5,0,-5,1105,1,2858,22102,1,-5,1,21201,-4,-1,2,21202,-3,2,3,21101,2805,0,0,1106,0,2763,22102,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2824,21102,1,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2850,21201,-2,0,1,21201,-4,-1,2,21101,0,2850,0,106,0,2721,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0,109,3,21208,-2,0,-1,1205,-1,2902,21207,-2,0,-1,1205,-1,2882,1106,0,2888,104,45,21202,-2,-1,-2,22102,1,-2,1,21102,1,2899,0,1105,1,2909,1105,1,2904,104,48,109,-3,2106,0,0,109,4,22101,0,-3,1,21102,1,10,2,21101,0,2926,0,1106,0,3010,22102,1,1,-2,21201,2,0,-1,1206,-2,2948,21202,-2,1,1,21102,2948,1,0,1105,1,2909,22101,48,-1,-1,204,-1,109,-4,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21102,0,1,-4,21101,0,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,2959,3033,21001,0,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,3059,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,3078,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,3024,22102,1,-4,-7,21201,-3,0,-6,109,-8,2106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3131,3143,0,3464,3252,3389,0,11,61,105,95,94,17,50,97,83,78,79,83,108,-19,2,7,-79,-9,-2,2,-83,-11,-7,-86,-3,-16,-7,-11,-6,-21,-21,-94,-30,-96,-25,-19,-23,-31,-101,-29,-25,-104,-21,-34,-38,-108,-39,-34,-32,-33,-31,-114,-43,-47,-35,-49,-105,-120,-69,-43,-123,-49,-56,-57,-47,-128,-40,-51,-46,-50,-133,-51,-63,-63,-57,-138,-69,-58,-62,-65,-143,-79,-69,-63,-68,-148,-79,-68,-82,-83,-63,-81,-77,-85,-145,-158,-75,-88,-92,-162,-91,-85,-89,-97,-167,-96,-104,-87,-171,-106,-104,-105,-97,-176,-94,-109,-114,-104,-112,-114,-169,3259,3268,0,3698,0,3324,3124,8,72,88,105,104,85,90,87,100,55,29,48,44,63,-20,54,40,-30,34,-32,43,39,49,48,39,31,-39,44,46,31,40,40,44,-46,18,30,19,-50,32,32,12,28,29,17,21,13,-59,24,18,-62,13,15,14,9,-67,-3,7,6,-71,-7,3,-1,0,-7,-63,3331,3354,0,3252,0,4255,3556,22,65,74,90,87,6,41,86,76,88,70,0,44,63,70,74,79,63,71,57,69,57,58,34,39,81,-4,60,74,73,61,56,72,72,-12,71,65,-15,50,52,-18,68,59,61,53,50,54,46,-26,51,51,53,47,34,44,43,55,-21,3396,3408,0,3124,0,0,0,11,72,87,92,87,95,83,84,14,57,77,77,55,34,55,60,-26,56,41,40,-30,38,54,40,34,34,42,30,31,-39,32,28,40,26,-44,34,24,-47,32,33,29,33,27,31,35,25,13,-57,22,20,16,28,15,6,18,-65,2,2,15,4,1,7,-72,14,5,7,-1,-63,3471,3479,0,0,0,3124,0,7,65,89,99,98,108,85,108,76,8,27,27,36,-48,16,32,18,13,-53,18,10,27,-57,8,10,9,17,-62,16,16,19,7,10,5,21,-1,-3,-72,-3,5,7,-76,6,1,-2,-11,3,-10,-10,-6,-14,-59,-87,1,-10,-5,-84,-10,-24,-94,-21,-11,-14,-14,-99,-22,-22,-18,-103,-23,-20,-33,-23,-39,-109,-27,-26,-30,-44,-114,-28,-44,-52,-34,-105,3563,3584,0,0,3324,3625,4166,20,51,84,80,93,8,62,88,70,84,83,75,79,71,-1,33,66,74,79,63,75,40,32,70,77,-11,57,63,69,54,-16,51,61,-19,69,58,63,-23,63,57,39,53,-28,51,52,38,51,36,44,49,47,-37,41,39,-40,43,30,26,-44,26,33,-16,3632,3641,0,3556,0,3961,0,8,64,102,98,100,88,88,85,92,56,27,54,51,42,51,49,39,-31,51,36,35,42,47,-37,46,40,-40,31,23,43,25,-45,30,22,22,35,-50,22,32,-53,25,23,-56,27,14,10,-60,-22,11,2,14,19,-66,-28,14,4,-2,-71,11,-4,10,9,-3,1,-7,-65,3705,3712,0,3833,0,3252,3753,6,59,107,91,88,90,90,40,38,70,68,58,-12,66,56,-15,68,55,51,-19,47,44,44,50,54,44,58,56,-28,54,39,38,45,-33,50,44,-36,35,27,47,29,-41,38,36,43,24,36,-33,3760,3772,0,4116,3698,0,0,11,68,86,102,87,99,102,80,98,92,94,100,60,24,43,39,51,37,-33,31,47,33,-37,27,-39,30,28,45,-43,40,24,30,22,35,18,29,29,17,30,-27,-55,28,15,11,30,-53,21,7,-63,1,11,10,-67,-2,10,6,13,-3,-5,-74,-7,3,10,0,-67,-80,3,-10,-4,1,-14,-14,-73,3840,3852,0,0,3904,3698,0,11,58,98,90,91,95,85,84,96,86,90,82,51,38,59,64,-22,60,45,44,-26,38,-28,58,42,42,52,36,32,44,29,45,30,-39,47,32,42,29,-44,35,30,18,30,34,-50,19,27,29,-54,-4,24,25,15,19,11,7,20,16,9,3,-66,19,-50,-55,3911,3925,0,0,0,4297,3833,13,54,100,86,103,15,63,98,77,93,94,78,90,90,35,49,68,64,-6,59,61,59,73,-11,53,69,55,-15,49,59,58,-19,64,58,57,-23,59,52,39,49,48,-29,40,48,50,-33,55,44,49,-23,3968,3991,0,3625,0,4020,0,22,50,88,92,7,41,77,83,70,81,77,65,83,67,-3,34,74,79,71,76,56,63,67,28,55,82,79,70,72,78,85,9,-4,68,78,0,75,-9,73,73,61,63,62,-15,71,62,64,56,53,57,49,-9,4027,4036,0,3961,0,0,4393,8,59,102,104,103,93,87,97,99,79,5,24,20,-50,26,17,31,11,21,-56,30,7,17,16,22,-62,2,14,3,-66,17,4,0,-70,6,-3,11,-9,1,-76,-7,-2,0,-1,1,-82,-18,-2,-16,-86,-4,-12,-16,-19,-19,-8,-17,-5,-95,-28,-24,-28,-29,-31,-19,-33,-25,-20,-105,-39,-28,-32,-30,-28,-28,-98,-113,-67,-33,-116,-52,-36,-50,-120,-37,-50,-54,-35,-94,4123,4131,0,0,0,3753,0,7,76,108,88,88,97,89,102,34,48,66,69,73,62,62,61,73,3,72,61,77,55,53,-2,-17,34,53,49,68,-15,59,45,-25,39,49,48,-29,39,46,48,51,55,-21,4173,4182,0,0,3556,0,0,8,75,96,89,96,20,53,83,106,72,11,44,38,37,35,37,38,36,-48,17,29,33,20,-53,-4,14,12,-44,-12,20,23,8,6,-63,-14,4,7,11,0,0,-1,11,-72,4,-5,-7,-3,-10,-5,-1,-11,-81,-17,-5,-16,-85,-4,-18,-17,-4,-14,-26,-10,-93,-12,-26,-23,-19,-30,-30,-31,-19,-102,-26,-35,-37,-33,-40,-35,-31,-41,-97,4262,4270,0,3324,0,0,0,7,68,97,107,89,93,89,97,26,43,91,73,85,91,85,72,72,76,68,3,78,-6,63,74,60,59,79,57,0,54,67,57,52,50,-5,4304,4315,0,3904,0,0,0,10,68,86,106,92,89,82,100,88,93,91,77,6,38,18,36,36,33,-25,-52,-2,30,27,9,21,10,10,8,-47,-62,-15,12,4,-1,16,1,-69,13,14,8,7,2,14,-76,0,-9,-14,3,4,0,-14,-7,-16,-8,-3,-5,-89,-20,-9,-13,-16,-94,-25,-23,-27,-14,-10,-100,-18,-18,-38,-22,-22,-106,-23,-29,-109,-28,-42,-45,-48,-38,-42,-50,-35,-53,-35,-51,-107,4400,4408,0,0,4020,4457,0,7,76,108,102,104,86,91,88,48,36,55,51,-19,46,58,66,46,59,-25,48,58,55,55,-30,36,47,45,50,30,37,41,-38,38,39,41,27,-43,22,34,42,22,35,-35,-50,-51,-2,16,13,30,26,26,15,27,9,15,27,-49,4464,4484,0,4393,0,4556,0,19,64,81,78,95,91,81,91,95,5,39,75,71,68,75,79,77,70,74,79,71,2,38,-41,42,29,25,-45,32,22,40,35,-50,31,27,26,23,-43,-56,8,-58,21,22,8,21,20,21,17,3,-54,15,0,8,12,1,11,-1,11,-7,-77,-8,-3,-1,-2,0,-83,3,-12,-10,-11,-88,-3,-21,-9,-19,-23,-5,-95,-7,-18,-13,-17,-100,-28,-34,-34,-26,-21,-33,-23,-19,-95,4563,4588,1553,4457,0,0,0,24,56,89,75,88,87,88,84,70,13,50,67,75,79,68,78,66,78,60,-10,27,64,66,65,67,12,53,97,83,93,105,105,87,91,83,25,24,23,3625,4653,27,1796,3324,4664,8388636,0,3698,4670,16413,0,3833,4684,542,0,3389,4694,65567,0,4020,4714,32,1850,3464,4726,33,1818,3961,4746,34,1872,3556,4754,163,0,4297,4762,134217764,0,4116,4770,37,1829,3904,4784,16777254,0,3252,4789,268435495,0,10,91,104,87,84,98,86,16,95,93,81,5,104,111,109,93,111,13,102,98,96,95,91,14,92,82,11,77,74,92,29,9,95,111,101,89,101,85,102,82,84,19,78,95,95,92,88,86,72,91,89,4,76,69,70,0,66,80,66,61,72,11,98,99,95,102,86,94,15,90,78,98,76,19,84,85,76,88,93,8,76,82,74,71,87,84,80,77,64,69,75,65,79,7,105,96,102,106,100,98,102,7,91,103,108,98,89,89,101,7,90,102,107,91,99,98,84,13,92,96,87,89,93,87,97,81,11,86,88,87,87,4,111,92,104,93,5,104,105,110,107,92 diff --git a/2019/day25/main.go b/2019/day25/main.go new file mode 100644 index 0000000..8f2ce52 --- /dev/null +++ b/2019/day25/main.go @@ -0,0 +1,96 @@ +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, -202, -191, -194, -192, -197, -205, -191, -207, -276, -278, -222, -201, -196, -282, -206, -219, -196, -286, -207, -206, -210, -223, -222, -223, -225, -280, -293, -296, -232, -220, -231, -300, -212, -223, -218, -304, -236, -228, -223, -239, -227, -310, -227, -240, -244, -314, -248, -237, -250, -243, -239, -247, -237, -308, -345, -273, -260, -248, -243, -263, -329, -252, -252, -248, -260, -267, -266, -253, -337, -249, -260, -255, -259, -342, -260, -267, -280, -270, -271, -348, -281, -268, -272, -279, -285, -342, -355, -280, -278, -279, -284, -277, -361, -282, -278, -274, -275, -290, -298, -300, -369, -300, -292, -290, -373, -309, -375, -299, -298, -301, -310, -302, -297, -370, -383, -302, -316, -321, -311, -315, -299, -321, -308, -392, -306, -322, -330, -312, -397, -326, -334, -317, -401, -330, -338, -324, -325, -337, -329, -339, -341, -398, -411, -347, -335, -346, -415, -334, -352, -350, -346, -341, -338, -422, -334, -345, -340, -344, -427, -345, -357, -357, -351, -432, -365, -361, -353, -367, -370, -354, -363, -351, -427, -464, -441, -397, -373, -434, -447, -376, -380, -374, -375, -373, -452, -454, -398, -377, -372, -458, -376, -388, -382, -377, -387, -396, -465, -400, -398, -468, -404, -404, -395, -403, -473, -390, -396, -476, -406, -409, -395, -480, -408, -404, -483, -418, -396, -486, -403, -399, -409, -417, -413, -421, -493, 37, -5, 73, 71, -8, 75, 62, 58, -12, 62, 55, 74, 64, 48, 50, -19, 45, 63, -22, 61, 48, 44, -26, 50, 37, 44, 48, -31, 33, 40, 48, 41, 43, 30, 37, -25, -38, -63, 0, 0, 109, 7, 21102, 0, 1, -2, 22208, -2, -5, -1, 1205, -1, 1169, 22202, -2, -4, 1, 22201, 1, -6, 1, 21201, -2, 0, 2, 21102, 1162, 1, 0, 2106, 0, -3, 21201, -2, 1, -2, 1105, 1, 1136, 109, -7, 2105, 1, 0, 109, 6, 1201, -5, 0, 1182, 20102, 1, 0, -2, 21101, 0, 0, -3, 21201, -5, 1, -5, 22208, -3, -2, -1, 1205, -1, 1229, 2201, -5, -3, 1205, 20102, 1, 0, 1, 21202, -3, 1, 2, 22102, 1, -2, 3, 21101, 0, 1222, 0, 2105, 1, -4, 21201, -3, 1, -3, 1106, 0, 1192, 109, -6, 2105, 1, 0, 109, 2, 22101, 0, -1, 1, 21101, 0, 1256, 2, 21101, 1251, 0, 0, 1106, 0, 1174, 109, -2, 2105, 1, 0, 109, 5, 22201, -4, -3, -1, 22201, -2, -1, -1, 204, -1, 109, -5, 2106, 0, 0, 109, 3, 2101, 0, -2, 1280, 1006, 0, 1303, 104, 45, 104, 32, 1201, -1, 66, 1291, 21002, 0, 1, 1, 21101, 0, 1301, 0, 1106, 0, 1234, 104, 10, 109, -3, 2105, 1, 0, 0, 0, 109, 2, 1201, -1, 0, 1309, 1101, 0, 0, 1308, 21101, 4601, 0, 1, 21102, 1, 13, 2, 21102, 4, 1, 3, 21101, 0, 1353, 4, 21101, 1343, 0, 0, 1106, 0, 1130, 21001, 1308, 0, -1, 109, -2, 2105, 1, 0, 70, 109, 3, 2101, 0, -2, 1360, 20008, 0, 1309, -1, 1206, -1, 1419, 1005, 1308, 1398, 1101, 0, 1, 1308, 21008, 1309, -1, -1, 1206, -1, 1387, 21102, 106, 1, 1, 1106, 0, 1391, 21102, 92, 1, 1, 21102, 1, 1398, 0, 1105, 1, 1234, 104, 45, 104, 32, 1201, -2, 1, 1408, 20101, 0, 0, 1, 21102, 1, 1417, 0, 1105, 1, 1234, 104, 10, 109, -3, 2106, 0, 0, 109, 3, 2102, 1, -2, 1128, 21102, 34, 1, 1, 21101, 1441, 0, 0, 1105, 1, 1234, 1001, 1128, 0, 1447, 20101, 0, 0, 1, 21102, 1, 1456, 0, 1106, 0, 1234, 21101, 41, 0, 1, 21102, 1, 1467, 0, 1105, 1, 1234, 1001, 1128, 1, 1473, 20102, 1, 0, 1, 21101, 1482, 0, 0, 1106, 0, 1234, 21102, 1, 46, 1, 21101, 1493, 0, 0, 1105, 1, 1234, 21001, 1128, 3, 1, 21102, 4, 1, 2, 21102, 1, 1, 3, 21102, 1273, 1, 4, 21101, 0, 1516, 0, 1105, 1, 1130, 21002, 1128, 1, 1, 21102, 1, 1527, 0, 1105, 1, 1310, 1001, 1128, 2, 1532, 21001, 0, 0, -1, 1206, -1, 1545, 21102, 1545, 1, 0, 2105, 1, -1, 109, -3, 2105, 1, 0, 109, 0, 99, 109, 2, 1101, 0, 0, 1550, 21102, 4601, 1, 1, 21102, 1, 13, 2, 21102, 1, 4, 3, 21102, 1664, 1, 4, 21102, 1, 1582, 0, 1105, 1, 1130, 2, 2486, 1352, 1551, 1101, 0, 0, 1552, 21001, 1550, 0, 1, 21101, 0, 33, 2, 21102, 1, 1702, 3, 21102, 1, 1609, 0, 1105, 1, 2722, 21007, 1552, 0, -1, 1205, -1, 1630, 20107, 0, 1552, -1, 1205, -1, 1637, 21101, 0, 1630, 0, 1106, 0, 1752, 21101, 0, 548, 1, 1105, 1, 1641, 21102, 687, 1, 1, 21102, 1648, 1, 0, 1106, 0, 1234, 21102, 1, 4457, 1, 21102, 1, 1659, 0, 1106, 0, 1424, 109, -2, 2106, 0, 0, 109, 4, 21202, -2, -1, -2, 1201, -3, 0, 1675, 21008, 0, -1, -1, 1206, -1, 1697, 1201, -3, 2, 1687, 20101, -27, 0, -3, 22201, -3, -2, -3, 2001, 1550, -3, 1550, 109, -4, 2106, 0, 0, 109, 5, 21008, 1552, 0, -1, 1206, -1, 1747, 1201, -3, 1901, 1716, 21001, 0, 0, -2, 1205, -4, 1736, 20207, -2, 1551, -1, 1205, -1, 1747, 1102, -1, 1, 1552, 1106, 0, 1747, 22007, 1551, -2, -1, 1205, -1, 1747, 1101, 0, 1, 1552, 109, -5, 2106, 0, 0, 109, 1, 21102, 826, 1, 1, 21101, 1765, 0, 0, 1105, 1, 1234, 20102, 1, 1550, 1, 21101, 1776, 0, 0, 1105, 1, 2863, 21101, 1090, 0, 1, 21102, 1, 1787, 0, 1106, 0, 1234, 99, 1105, 1, 1787, 109, -1, 2106, 0, 0, 109, 1, 21102, 1, 512, 1, 21101, 1809, 0, 0, 1106, 0, 1234, 99, 1105, 1, 1809, 109, -1, 2106, 0, 0, 109, 1, 1102, 1, 1, 1129, 109, -1, 2105, 1, 0, 109, 1, 21102, 1, 377, 1, 21102, 1, 1842, 0, 1105, 1, 1234, 1106, 0, 1831, 109, -1, 2105, 1, 0, 109, 1, 21101, 0, 407, 1, 21101, 0, 1863, 0, 1106, 0, 1234, 99, 1106, 0, 1863, 109, -1, 2106, 0, 0, 109, 1, 21102, 1, 452, 1, 21101, 0, 1885, 0, 1106, 0, 1234, 99, 1105, 1, 1885, 109, -1, 2105, 1, 0, 1941, 1947, 1953, 1958, 1965, 1972, 1978, 3584, 4102, 4099, 3470, 4223, 3883, 4100, 3983, 4146, 4026, 3610, 3464, 3599, 3502, 3738, 3509, 4167, 3991, 3449, 3751, 3564, 3734, 4060, 3697, 3805, 4201, 4057, 3543, 3545, 3992, 3674, 4039, 3751, 2281, 2468, 2418, 2450, 2487, 2125, 2505, 5, 95, 108, 104, 104, 23, 5, 96, 91, 108, 108, 1, 4, 101, 105, 112, 3, 6, 104, 104, 106, 107, 94, -1, 6, 109, 104, 109, 107, 94, -1, 5, 111, 91, 100, 93, 23, 5, 114, 95, 108, 108, 1, 109, 3, 21102, 1, 1993, 0, 1106, 0, 2634, 1006, 1129, 2010, 21101, 0, 316, 1, 21101, 2007, 0, 0, 1105, 1, 1234, 1106, 0, 2076, 21101, 0, 0, -1, 1201, -1, 1894, 2020, 20102, 1, 0, 1, 21102, 0, 1, 2, 21101, 0, 0, 3, 21102, 2037, 1, 0, 1106, 0, 2525, 1206, 1, 2054, 1201, -1, 1934, 2050, 21102, 1, 2051, 0, 105, 1, 0, 1106, 0, 2076, 21201, -1, 1, -1, 21207, -1, 7, -2, 1205, -2, 2014, 21102, 177, 1, 1, 21101, 0, 2076, 0, 1105, 1, 1234, 109, -3, 2105, 1, 0, 109, 3, 2001, 1128, -2, 2089, 20102, 1, 0, -1, 1205, -1, 2108, 21102, 1, 201, 1, 21102, 2105, 1, 0, 1106, 0, 1234, 1105, 1, 2119, 22102, 1, -1, 1, 21102, 2119, 1, 0, 1106, 0, 1424, 109, -3, 2106, 0, 0, 0, 109, 1, 1101, 0, 0, 2124, 21102, 4601, 1, 1, 21101, 13, 0, 2, 21102, 1, 4, 3, 21101, 2173, 0, 4, 21101, 2154, 0, 0, 1106, 0, 1130, 1005, 2124, 2168, 21102, 1, 226, 1, 21102, 2168, 1, 0, 1106, 0, 1234, 109, -1, 2106, 0, 0, 109, 3, 1005, 2124, 2275, 1201, -2, 0, 2183, 20008, 0, 1128, -1, 1206, -1, 2275, 1201, -2, 1, 2194, 21001, 0, 0, -1, 21201, -1, 0, 1, 21102, 5, 1, 2, 21102, 1, 1, 3, 21102, 1, 2216, 0, 1105, 1, 2525, 1206, 1, 2275, 21101, 258, 0, 1, 21101, 0, 2230, 0, 1105, 1, 1234, 21201, -1, 0, 1, 21101, 0, 2241, 0, 1105, 1, 1234, 104, 46, 104, 10, 1102, 1, 1, 2124, 1201, -2, 0, 2256, 1102, -1, 1, 0, 1201, -2, 3, 2262, 21002, 0, 1, -1, 1206, -1, 2275, 21101, 2275, 0, 0, 2105, 1, -1, 109, -3, 2106, 0, 0, 0, 109, 1, 1101, 0, 0, 2280, 21101, 4601, 0, 1, 21102, 1, 13, 2, 21101, 0, 4, 3, 21102, 2329, 1, 4, 21101, 2310, 0, 0, 1106, 0, 1130, 1005, 2280, 2324, 21101, 0, 273, 1, 21102, 1, 2324, 0, 1106, 0, 1234, 109, -1, 2106, 0, 0, 109, 3, 1005, 2280, 2413, 1201, -2, 0, 2339, 21008, 0, -1, -1, 1206, -1, 2413, 1201, -2, 1, 2350, 21001, 0, 0, -1, 21202, -1, 1, 1, 21102, 1, 5, 2, 21102, 1, 1, 3, 21102, 2372, 1, 0, 1105, 1, 2525, 1206, 1, 2413, 21102, 301, 1, 1, 21102, 2386, 1, 0, 1105, 1, 1234, 22101, 0, -1, 1, 21101, 0, 2397, 0, 1106, 0, 1234, 104, 46, 104, 10, 1101, 1, 0, 2280, 1201, -2, 0, 2412, 101, 0, 1128, 0, 109, -3, 2105, 1, 0, 109, 1, 21102, -1, 1, 1, 21101, 2431, 0, 0, 1106, 0, 1310, 1205, 1, 2445, 21102, 1, 133, 1, 21102, 1, 2445, 0, 1106, 0, 1234, 109, -1, 2106, 0, 0, 109, 1, 21102, 3, 1, 1, 21101, 2463, 0, 0, 1105, 1, 2081, 109, -1, 2105, 1, 0, 109, 1, 21101, 4, 0, 1, 21101, 0, 2481, 0, 1106, 0, 2081, 109, -1, 2105, 1, 0, 59, 109, 1, 21101, 5, 0, 1, 21102, 1, 2500, 0, 1106, 0, 2081, 109, -1, 2105, 1, 0, 109, 1, 21102, 1, 6, 1, 21101, 0, 2518, 0, 1105, 1, 2081, 109, -1, 2105, 1, 0, 0, 0, 109, 5, 1201, -3, 0, 2523, 1102, 1, 1, 2524, 21202, -4, 1, 1, 21101, 2585, 0, 2, 21102, 1, 2550, 0, 1106, 0, 1174, 1206, -2, 2576, 2101, 0, -4, 2558, 2001, 0, -3, 2566, 101, 3094, 2566, 2566, 21008, 0, -1, -1, 1205, -1, 2576, 1101, 0, 0, 2524, 20101, 0, 2524, -4, 109, -5, 2106, 0, 0, 109, 5, 22201, -4, -3, -4, 22201, -4, -2, -4, 21208, -4, 10, -1, 1206, -1, 2606, 21101, -1, 0, -4, 201, -3, 2523, 2615, 1001, 2615, 3094, 2615, 21002, 0, 1, -1, 22208, -4, -1, -1, 1205, -1, 2629, 1102, 0, 1, 2524, 109, -5, 2105, 1, 0, 109, 4, 21102, 1, 3094, 1, 21102, 1, 30, 2, 21102, 1, 1, 3, 21102, 2706, 1, 4, 21102, 2659, 1, 0, 1105, 1, 1130, 21101, 0, 0, -3, 203, -2, 21208, -2, 10, -1, 1205, -1, 2701, 21207, -2, 0, -1, 1205, -1, 2663, 21207, -3, 29, -1, 1206, -1, 2663, 2101, 3094, -3, 2693, 1202, -2, 1, 0, 21201, -3, 1, -3, 1106, 0, 2663, 109, -4, 2106, 0, 0, 109, 2, 1201, -1, 0, 2715, 1101, 0, -1, 0, 109, -2, 2106, 0, 0, 0, 109, 5, 1202, -2, 1, 2721, 21207, -4, 0, -1, 1206, -1, 2739, 21101, 0, 0, -4, 21201, -4, 0, 1, 21201, -3, 0, 2, 21102, 1, 1, 3, 21102, 1, 2758, 0, 1106, 0, 2763, 109, -5, 2105, 1, 0, 109, 6, 21207, -4, 1, -1, 1206, -1, 2786, 22207, -5, -3, -1, 1206, -1, 2786, 21201, -5, 0, -5, 1105, 1, 2858, 22102, 1, -5, 1, 21201, -4, -1, 2, 21202, -3, 2, 3, 21101, 2805, 0, 0, 1106, 0, 2763, 22102, 1, 1, -5, 21101, 1, 0, -2, 22207, -5, -3, -1, 1206, -1, 2824, 21102, 1, 0, -2, 22202, -3, -2, -3, 22107, 0, -4, -1, 1206, -1, 2850, 21201, -2, 0, 1, 21201, -4, -1, 2, 21101, 0, 2850, 0, 106, 0, 2721, 21202, -3, -1, -3, 22201, -5, -3, -5, 109, -6, 2105, 1, 0, 109, 3, 21208, -2, 0, -1, 1205, -1, 2902, 21207, -2, 0, -1, 1205, -1, 2882, 1106, 0, 2888, 104, 45, 21202, -2, -1, -2, 22102, 1, -2, 1, 21102, 1, 2899, 0, 1105, 1, 2909, 1105, 1, 2904, 104, 48, 109, -3, 2106, 0, 0, 109, 4, 22101, 0, -3, 1, 21102, 1, 10, 2, 21101, 0, 2926, 0, 1106, 0, 3010, 22102, 1, 1, -2, 21201, 2, 0, -1, 1206, -2, 2948, 21202, -2, 1, 1, 21102, 2948, 1, 0, 1105, 1, 2909, 22101, 48, -1, -1, 204, -1, 109, -4, 2105, 1, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 109, 8, 21102, 0, 1, -4, 21101, 0, 0, -3, 21102, 51, 1, -2, 21201, -2, -1, -2, 1201, -2, 2959, 3033, 21001, 0, 0, -1, 21202, -3, 2, -3, 22207, -7, -1, -5, 1205, -5, 3059, 21201, -3, 1, -3, 22102, -1, -1, -5, 22201, -7, -5, -7, 22207, -3, -6, -5, 1205, -5, 3078, 22102, -1, -6, -5, 22201, -3, -5, -3, 22201, -1, -4, -4, 1205, -2, 3024, 22102, 1, -4, -7, 21201, -3, 0, -6, 109, -8, 2106, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3131, 3143, 0, 3464, 3252, 3389, 0, 11, 61, 105, 95, 94, 17, 50, 97, 83, 78, 79, 83, 108, -19, 2, 7, -79, -9, -2, 2, -83, -11, -7, -86, -3, -16, -7, -11, -6, -21, -21, -94, -30, -96, -25, -19, -23, -31, -101, -29, -25, -104, -21, -34, -38, -108, -39, -34, -32, -33, -31, -114, -43, -47, -35, -49, -105, -120, -69, -43, -123, -49, -56, -57, -47, -128, -40, -51, -46, -50, -133, -51, -63, -63, -57, -138, -69, -58, -62, -65, -143, -79, -69, -63, -68, -148, -79, -68, -82, -83, -63, -81, -77, -85, -145, -158, -75, -88, -92, -162, -91, -85, -89, -97, -167, -96, -104, -87, -171, -106, -104, -105, -97, -176, -94, -109, -114, -104, -112, -114, -169, 3259, 3268, 0, 3698, 0, 3324, 3124, 8, 72, 88, 105, 104, 85, 90, 87, 100, 55, 29, 48, 44, 63, -20, 54, 40, -30, 34, -32, 43, 39, 49, 48, 39, 31, -39, 44, 46, 31, 40, 40, 44, -46, 18, 30, 19, -50, 32, 32, 12, 28, 29, 17, 21, 13, -59, 24, 18, -62, 13, 15, 14, 9, -67, -3, 7, 6, -71, -7, 3, -1, 0, -7, -63, 3331, 3354, 0, 3252, 0, 4255, 3556, 22, 65, 74, 90, 87, 6, 41, 86, 76, 88, 70, 0, 44, 63, 70, 74, 79, 63, 71, 57, 69, 57, 58, 34, 39, 81, -4, 60, 74, 73, 61, 56, 72, 72, -12, 71, 65, -15, 50, 52, -18, 68, 59, 61, 53, 50, 54, 46, -26, 51, 51, 53, 47, 34, 44, 43, 55, -21, 3396, 3408, 0, 3124, 0, 0, 0, 11, 72, 87, 92, 87, 95, 83, 84, 14, 57, 77, 77, 55, 34, 55, 60, -26, 56, 41, 40, -30, 38, 54, 40, 34, 34, 42, 30, 31, -39, 32, 28, 40, 26, -44, 34, 24, -47, 32, 33, 29, 33, 27, 31, 35, 25, 13, -57, 22, 20, 16, 28, 15, 6, 18, -65, 2, 2, 15, 4, 1, 7, -72, 14, 5, 7, -1, -63, 3471, 3479, 0, 0, 0, 3124, 0, 7, 65, 89, 99, 98, 108, 85, 108, 76, 8, 27, 27, 36, -48, 16, 32, 18, 13, -53, 18, 10, 27, -57, 8, 10, 9, 17, -62, 16, 16, 19, 7, 10, 5, 21, -1, -3, -72, -3, 5, 7, -76, 6, 1, -2, -11, 3, -10, -10, -6, -14, -59, -87, 1, -10, -5, -84, -10, -24, -94, -21, -11, -14, -14, -99, -22, -22, -18, -103, -23, -20, -33, -23, -39, -109, -27, -26, -30, -44, -114, -28, -44, -52, -34, -105, 3563, 3584, 0, 0, 3324, 3625, 4166, 20, 51, 84, 80, 93, 8, 62, 88, 70, 84, 83, 75, 79, 71, -1, 33, 66, 74, 79, 63, 75, 40, 32, 70, 77, -11, 57, 63, 69, 54, -16, 51, 61, -19, 69, 58, 63, -23, 63, 57, 39, 53, -28, 51, 52, 38, 51, 36, 44, 49, 47, -37, 41, 39, -40, 43, 30, 26, -44, 26, 33, -16, 3632, 3641, 0, 3556, 0, 3961, 0, 8, 64, 102, 98, 100, 88, 88, 85, 92, 56, 27, 54, 51, 42, 51, 49, 39, -31, 51, 36, 35, 42, 47, -37, 46, 40, -40, 31, 23, 43, 25, -45, 30, 22, 22, 35, -50, 22, 32, -53, 25, 23, -56, 27, 14, 10, -60, -22, 11, 2, 14, 19, -66, -28, 14, 4, -2, -71, 11, -4, 10, 9, -3, 1, -7, -65, 3705, 3712, 0, 3833, 0, 3252, 3753, 6, 59, 107, 91, 88, 90, 90, 40, 38, 70, 68, 58, -12, 66, 56, -15, 68, 55, 51, -19, 47, 44, 44, 50, 54, 44, 58, 56, -28, 54, 39, 38, 45, -33, 50, 44, -36, 35, 27, 47, 29, -41, 38, 36, 43, 24, 36, -33, 3760, 3772, 0, 4116, 3698, 0, 0, 11, 68, 86, 102, 87, 99, 102, 80, 98, 92, 94, 100, 60, 24, 43, 39, 51, 37, -33, 31, 47, 33, -37, 27, -39, 30, 28, 45, -43, 40, 24, 30, 22, 35, 18, 29, 29, 17, 30, -27, -55, 28, 15, 11, 30, -53, 21, 7, -63, 1, 11, 10, -67, -2, 10, 6, 13, -3, -5, -74, -7, 3, 10, 0, -67, -80, 3, -10, -4, 1, -14, -14, -73, 3840, 3852, 0, 0, 3904, 3698, 0, 11, 58, 98, 90, 91, 95, 85, 84, 96, 86, 90, 82, 51, 38, 59, 64, -22, 60, 45, 44, -26, 38, -28, 58, 42, 42, 52, 36, 32, 44, 29, 45, 30, -39, 47, 32, 42, 29, -44, 35, 30, 18, 30, 34, -50, 19, 27, 29, -54, -4, 24, 25, 15, 19, 11, 7, 20, 16, 9, 3, -66, 19, -50, -55, 3911, 3925, 0, 0, 0, 4297, 3833, 13, 54, 100, 86, 103, 15, 63, 98, 77, 93, 94, 78, 90, 90, 35, 49, 68, 64, -6, 59, 61, 59, 73, -11, 53, 69, 55, -15, 49, 59, 58, -19, 64, 58, 57, -23, 59, 52, 39, 49, 48, -29, 40, 48, 50, -33, 55, 44, 49, -23, 3968, 3991, 0, 3625, 0, 4020, 0, 22, 50, 88, 92, 7, 41, 77, 83, 70, 81, 77, 65, 83, 67, -3, 34, 74, 79, 71, 76, 56, 63, 67, 28, 55, 82, 79, 70, 72, 78, 85, 9, -4, 68, 78, 0, 75, -9, 73, 73, 61, 63, 62, -15, 71, 62, 64, 56, 53, 57, 49, -9, 4027, 4036, 0, 3961, 0, 0, 4393, 8, 59, 102, 104, 103, 93, 87, 97, 99, 79, 5, 24, 20, -50, 26, 17, 31, 11, 21, -56, 30, 7, 17, 16, 22, -62, 2, 14, 3, -66, 17, 4, 0, -70, 6, -3, 11, -9, 1, -76, -7, -2, 0, -1, 1, -82, -18, -2, -16, -86, -4, -12, -16, -19, -19, -8, -17, -5, -95, -28, -24, -28, -29, -31, -19, -33, -25, -20, -105, -39, -28, -32, -30, -28, -28, -98, -113, -67, -33, -116, -52, -36, -50, -120, -37, -50, -54, -35, -94, 4123, 4131, 0, 0, 0, 3753, 0, 7, 76, 108, 88, 88, 97, 89, 102, 34, 48, 66, 69, 73, 62, 62, 61, 73, 3, 72, 61, 77, 55, 53, -2, -17, 34, 53, 49, 68, -15, 59, 45, -25, 39, 49, 48, -29, 39, 46, 48, 51, 55, -21, 4173, 4182, 0, 0, 3556, 0, 0, 8, 75, 96, 89, 96, 20, 53, 83, 106, 72, 11, 44, 38, 37, 35, 37, 38, 36, -48, 17, 29, 33, 20, -53, -4, 14, 12, -44, -12, 20, 23, 8, 6, -63, -14, 4, 7, 11, 0, 0, -1, 11, -72, 4, -5, -7, -3, -10, -5, -1, -11, -81, -17, -5, -16, -85, -4, -18, -17, -4, -14, -26, -10, -93, -12, -26, -23, -19, -30, -30, -31, -19, -102, -26, -35, -37, -33, -40, -35, -31, -41, -97, 4262, 4270, 0, 3324, 0, 0, 0, 7, 68, 97, 107, 89, 93, 89, 97, 26, 43, 91, 73, 85, 91, 85, 72, 72, 76, 68, 3, 78, -6, 63, 74, 60, 59, 79, 57, 0, 54, 67, 57, 52, 50, -5, 4304, 4315, 0, 3904, 0, 0, 0, 10, 68, 86, 106, 92, 89, 82, 100, 88, 93, 91, 77, 6, 38, 18, 36, 36, 33, -25, -52, -2, 30, 27, 9, 21, 10, 10, 8, -47, -62, -15, 12, 4, -1, 16, 1, -69, 13, 14, 8, 7, 2, 14, -76, 0, -9, -14, 3, 4, 0, -14, -7, -16, -8, -3, -5, -89, -20, -9, -13, -16, -94, -25, -23, -27, -14, -10, -100, -18, -18, -38, -22, -22, -106, -23, -29, -109, -28, -42, -45, -48, -38, -42, -50, -35, -53, -35, -51, -107, 4400, 4408, 0, 0, 4020, 4457, 0, 7, 76, 108, 102, 104, 86, 91, 88, 48, 36, 55, 51, -19, 46, 58, 66, 46, 59, -25, 48, 58, 55, 55, -30, 36, 47, 45, 50, 30, 37, 41, -38, 38, 39, 41, 27, -43, 22, 34, 42, 22, 35, -35, -50, -51, -2, 16, 13, 30, 26, 26, 15, 27, 9, 15, 27, -49, 4464, 4484, 0, 4393, 0, 4556, 0, 19, 64, 81, 78, 95, 91, 81, 91, 95, 5, 39, 75, 71, 68, 75, 79, 77, 70, 74, 79, 71, 2, 38, -41, 42, 29, 25, -45, 32, 22, 40, 35, -50, 31, 27, 26, 23, -43, -56, 8, -58, 21, 22, 8, 21, 20, 21, 17, 3, -54, 15, 0, 8, 12, 1, 11, -1, 11, -7, -77, -8, -3, -1, -2, 0, -83, 3, -12, -10, -11, -88, -3, -21, -9, -19, -23, -5, -95, -7, -18, -13, -17, -100, -28, -34, -34, -26, -21, -33, -23, -19, -95, 4563, 4588, 1553, 4457, 0, 0, 0, 24, 56, 89, 75, 88, 87, 88, 84, 70, 13, 50, 67, 75, 79, 68, 78, 66, 78, 60, -10, 27, 64, 66, 65, 67, 12, 53, 97, 83, 93, 105, 105, 87, 91, 83, 25, 24, 23, 3625, 4653, 27, 1796, 3324, 4664, 8388636, 0, 3698, 4670, 16413, 0, 3833, 4684, 542, 0, 3389, 4694, 65567, 0, 4020, 4714, 32, 1850, 3464, 4726, 33, 1818, 3961, 4746, 34, 1872, 3556, 4754, 163, 0, 4297, 4762, 134217764, 0, 4116, 4770, 37, 1829, 3904, 4784, 16777254, 0, 3252, 4789, 268435495, 0, 10, 91, 104, 87, 84, 98, 86, 16, 95, 93, 81, 5, 104, 111, 109, 93, 111, 13, 102, 98, 96, 95, 91, 14, 92, 82, 11, 77, 74, 92, 29, 9, 95, 111, 101, 89, 101, 85, 102, 82, 84, 19, 78, 95, 95, 92, 88, 86, 72, 91, 89, 4, 76, 69, 70, 0, 66, 80, 66, 61, 72, 11, 98, 99, 95, 102, 86, 94, 15, 90, 78, 98, 76, 19, 84, 85, 76, 88, 93, 8, 76, 82, 74, 71, 87, 84, 80, 77, 64, 69, 75, 65, 79, 7, 105, 96, 102, 106, 100, 98, 102, 7, 91, 103, 108, 98, 89, 89, 101, 7, 90, 102, 107, 91, 99, 98, 84, 13, 92, 96, 87, 89, 93, 87, 97, 81, 11, 86, 88, 87, 87, 4, 111, 92, 104, 93, 5, 104, 105, 110, 107, 92} +} diff --git a/2019/day25/map.txt b/2019/day25/map.txt new file mode 100644 index 0000000..c4ba499 --- /dev/null +++ b/2019/day25/map.txt @@ -0,0 +1,122 @@ + 9 5-6 + | | | + 8-4 7 + | + 1 | + | | + 0-3 + | | + 2 | + | + C-B-A + | | + D E + | + F + | + H-G + | + I + | + * + +0: Hull Breach () +1: Hallway (giant electromagnet -> prevents movement) +2: Science Lab (astronaut ice cream) +3: Passages (mouse) +4: Arcade (spool of cat6) +5: Engineering (hypercube) +6: Crew Quarters (sand) +7: Navigation (antenna) +8: Observatory () +9: Stables (infinite loop -> Locks up game) +A: Warp Drive Maintenance (mutex) +B: Gift Wrapping Center (boulder) +C: Sick Bay () +D: Holodeck (escape pod -> Launched into Space -> Exit) +E: Kitchen () +F: Hot Chocolate Fountain (photons -> Eaten by a Grue) +G: Corridor (molten lava) +H: Storage () +I: Security Checkpoint () +*: GOAL! + +# All Items: +astronaut ice cream +mouse +spool of cat6 +hypercube +sand +antenna +mutex +boulder + +# Entry Attempts: +* 1: Too Light + astronaut ice cream + mouse + mutex + boulder + +* 2: Too Heavy + astronaut ice cream + mouse + spool of cat6 + hypercube + sand + antenna + mutex + boulder + +* 3: Too Heavy + astronaut ice cream + mouse + spool of cat6 + hypercube + sand + antenna + +* 4: Too Heavy + astronaut ice cream + mouse + spool of cat6 + hypercube + sand + +* 5: Too Light + astronaut ice cream + mouse + spool of cat6 + hypercube + +* 6: Too Heavy + astronaut ice cream + mouse + spool of cat6 + sand + +* 7: Too Light + astronaut ice cream + mouse + spool of cat6 + hypercube + +* 8: Too Heavy + astronaut ice cream + mouse + spool of cat6 + hypercube + antenna + +* 9: Too Heavy + mutex + mouse + spool of cat6 + hypercube + antenna + +* 10: Too Heavy + astronaut ice cream + mouse + spool of cat6 + antenna diff --git a/2019/day25/saveslot-quick.sav b/2019/day25/saveslot-quick.sav new file mode 100644 index 0000000..2e77dec --- /dev/null +++ b/2019/day25/saveslot-quick.sav @@ -0,0 +1 @@ +{"Title":"Day 25: Cryostasis","Program":{"OriginalCode":[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,-202,-191,-194,-192,-197,-205,-191,-207,-276,-278,-222,-201,-196,-282,-206,-219,-196,-286,-207,-206,-210,-223,-222,-223,-225,-280,-293,-296,-232,-220,-231,-300,-212,-223,-218,-304,-236,-228,-223,-239,-227,-310,-227,-240,-244,-314,-248,-237,-250,-243,-239,-247,-237,-308,-345,-273,-260,-248,-243,-263,-329,-252,-252,-248,-260,-267,-266,-253,-337,-249,-260,-255,-259,-342,-260,-267,-280,-270,-271,-348,-281,-268,-272,-279,-285,-342,-355,-280,-278,-279,-284,-277,-361,-282,-278,-274,-275,-290,-298,-300,-369,-300,-292,-290,-373,-309,-375,-299,-298,-301,-310,-302,-297,-370,-383,-302,-316,-321,-311,-315,-299,-321,-308,-392,-306,-322,-330,-312,-397,-326,-334,-317,-401,-330,-338,-324,-325,-337,-329,-339,-341,-398,-411,-347,-335,-346,-415,-334,-352,-350,-346,-341,-338,-422,-334,-345,-340,-344,-427,-345,-357,-357,-351,-432,-365,-361,-353,-367,-370,-354,-363,-351,-427,-464,-441,-397,-373,-434,-447,-376,-380,-374,-375,-373,-452,-454,-398,-377,-372,-458,-376,-388,-382,-377,-387,-396,-465,-400,-398,-468,-404,-404,-395,-403,-473,-390,-396,-476,-406,-409,-395,-480,-408,-404,-483,-418,-396,-486,-403,-399,-409,-417,-413,-421,-493,37,-5,73,71,-8,75,62,58,-12,62,55,74,64,48,50,-19,45,63,-22,61,48,44,-26,50,37,44,48,-31,33,40,48,41,43,30,37,-25,-38,-63,0,0,109,7,21102,0,1,-2,22208,-2,-5,-1,1205,-1,1169,22202,-2,-4,1,22201,1,-6,1,21201,-2,0,2,21102,1162,1,0,2106,0,-3,21201,-2,1,-2,1105,1,1136,109,-7,2105,1,0,109,6,1201,-5,0,1182,20102,1,0,-2,21101,0,0,-3,21201,-5,1,-5,22208,-3,-2,-1,1205,-1,1229,2201,-5,-3,1205,20102,1,0,1,21202,-3,1,2,22102,1,-2,3,21101,0,1222,0,2105,1,-4,21201,-3,1,-3,1106,0,1192,109,-6,2105,1,0,109,2,22101,0,-1,1,21101,0,1256,2,21101,1251,0,0,1106,0,1174,109,-2,2105,1,0,109,5,22201,-4,-3,-1,22201,-2,-1,-1,204,-1,109,-5,2106,0,0,109,3,2101,0,-2,1280,1006,0,1303,104,45,104,32,1201,-1,66,1291,21002,0,1,1,21101,0,1301,0,1106,0,1234,104,10,109,-3,2105,1,0,0,0,109,2,1201,-1,0,1309,1101,0,0,1308,21101,4601,0,1,21102,1,13,2,21102,4,1,3,21101,0,1353,4,21101,1343,0,0,1106,0,1130,21001,1308,0,-1,109,-2,2105,1,0,70,109,3,2101,0,-2,1360,20008,0,1309,-1,1206,-1,1419,1005,1308,1398,1101,0,1,1308,21008,1309,-1,-1,1206,-1,1387,21102,106,1,1,1106,0,1391,21102,92,1,1,21102,1,1398,0,1105,1,1234,104,45,104,32,1201,-2,1,1408,20101,0,0,1,21102,1,1417,0,1105,1,1234,104,10,109,-3,2106,0,0,109,3,2102,1,-2,1128,21102,34,1,1,21101,1441,0,0,1105,1,1234,1001,1128,0,1447,20101,0,0,1,21102,1,1456,0,1106,0,1234,21101,41,0,1,21102,1,1467,0,1105,1,1234,1001,1128,1,1473,20102,1,0,1,21101,1482,0,0,1106,0,1234,21102,1,46,1,21101,1493,0,0,1105,1,1234,21001,1128,3,1,21102,4,1,2,21102,1,1,3,21102,1273,1,4,21101,0,1516,0,1105,1,1130,21002,1128,1,1,21102,1,1527,0,1105,1,1310,1001,1128,2,1532,21001,0,0,-1,1206,-1,1545,21102,1545,1,0,2105,1,-1,109,-3,2105,1,0,109,0,99,109,2,1101,0,0,1550,21102,4601,1,1,21102,1,13,2,21102,1,4,3,21102,1664,1,4,21102,1,1582,0,1105,1,1130,2,2486,1352,1551,1101,0,0,1552,21001,1550,0,1,21101,0,33,2,21102,1,1702,3,21102,1,1609,0,1105,1,2722,21007,1552,0,-1,1205,-1,1630,20107,0,1552,-1,1205,-1,1637,21101,0,1630,0,1106,0,1752,21101,0,548,1,1105,1,1641,21102,687,1,1,21102,1648,1,0,1106,0,1234,21102,1,4457,1,21102,1,1659,0,1106,0,1424,109,-2,2106,0,0,109,4,21202,-2,-1,-2,1201,-3,0,1675,21008,0,-1,-1,1206,-1,1697,1201,-3,2,1687,20101,-27,0,-3,22201,-3,-2,-3,2001,1550,-3,1550,109,-4,2106,0,0,109,5,21008,1552,0,-1,1206,-1,1747,1201,-3,1901,1716,21001,0,0,-2,1205,-4,1736,20207,-2,1551,-1,1205,-1,1747,1102,-1,1,1552,1106,0,1747,22007,1551,-2,-1,1205,-1,1747,1101,0,1,1552,109,-5,2106,0,0,109,1,21102,826,1,1,21101,1765,0,0,1105,1,1234,20102,1,1550,1,21101,1776,0,0,1105,1,2863,21101,1090,0,1,21102,1,1787,0,1106,0,1234,99,1105,1,1787,109,-1,2106,0,0,109,1,21102,1,512,1,21101,1809,0,0,1106,0,1234,99,1105,1,1809,109,-1,2106,0,0,109,1,1102,1,1,1129,109,-1,2105,1,0,109,1,21102,1,377,1,21102,1,1842,0,1105,1,1234,1106,0,1831,109,-1,2105,1,0,109,1,21101,0,407,1,21101,0,1863,0,1106,0,1234,99,1106,0,1863,109,-1,2106,0,0,109,1,21102,1,452,1,21101,0,1885,0,1106,0,1234,99,1105,1,1885,109,-1,2105,1,0,1941,1947,1953,1958,1965,1972,1978,3584,4102,4099,3470,4223,3883,4100,3983,4146,4026,3610,3464,3599,3502,3738,3509,4167,3991,3449,3751,3564,3734,4060,3697,3805,4201,4057,3543,3545,3992,3674,4039,3751,2281,2468,2418,2450,2487,2125,2505,5,95,108,104,104,23,5,96,91,108,108,1,4,101,105,112,3,6,104,104,106,107,94,-1,6,109,104,109,107,94,-1,5,111,91,100,93,23,5,114,95,108,108,1,109,3,21102,1,1993,0,1106,0,2634,1006,1129,2010,21101,0,316,1,21101,2007,0,0,1105,1,1234,1106,0,2076,21101,0,0,-1,1201,-1,1894,2020,20102,1,0,1,21102,0,1,2,21101,0,0,3,21102,2037,1,0,1106,0,2525,1206,1,2054,1201,-1,1934,2050,21102,1,2051,0,105,1,0,1106,0,2076,21201,-1,1,-1,21207,-1,7,-2,1205,-2,2014,21102,177,1,1,21101,0,2076,0,1105,1,1234,109,-3,2105,1,0,109,3,2001,1128,-2,2089,20102,1,0,-1,1205,-1,2108,21102,1,201,1,21102,2105,1,0,1106,0,1234,1105,1,2119,22102,1,-1,1,21102,2119,1,0,1106,0,1424,109,-3,2106,0,0,0,109,1,1101,0,0,2124,21102,4601,1,1,21101,13,0,2,21102,1,4,3,21101,2173,0,4,21101,2154,0,0,1106,0,1130,1005,2124,2168,21102,1,226,1,21102,2168,1,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2124,2275,1201,-2,0,2183,20008,0,1128,-1,1206,-1,2275,1201,-2,1,2194,21001,0,0,-1,21201,-1,0,1,21102,5,1,2,21102,1,1,3,21102,1,2216,0,1105,1,2525,1206,1,2275,21101,258,0,1,21101,0,2230,0,1105,1,1234,21201,-1,0,1,21101,0,2241,0,1105,1,1234,104,46,104,10,1102,1,1,2124,1201,-2,0,2256,1102,-1,1,0,1201,-2,3,2262,21002,0,1,-1,1206,-1,2275,21101,2275,0,0,2105,1,-1,109,-3,2106,0,0,0,109,1,1101,0,0,2280,21101,4601,0,1,21102,1,13,2,21101,0,4,3,21102,2329,1,4,21101,2310,0,0,1106,0,1130,1005,2280,2324,21101,0,273,1,21102,1,2324,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2280,2413,1201,-2,0,2339,21008,0,-1,-1,1206,-1,2413,1201,-2,1,2350,21001,0,0,-1,21202,-1,1,1,21102,1,5,2,21102,1,1,3,21102,2372,1,0,1105,1,2525,1206,1,2413,21102,301,1,1,21102,2386,1,0,1105,1,1234,22101,0,-1,1,21101,0,2397,0,1106,0,1234,104,46,104,10,1101,1,0,2280,1201,-2,0,2412,101,0,1128,0,109,-3,2105,1,0,109,1,21102,-1,1,1,21101,2431,0,0,1106,0,1310,1205,1,2445,21102,1,133,1,21102,1,2445,0,1106,0,1234,109,-1,2106,0,0,109,1,21102,3,1,1,21101,2463,0,0,1105,1,2081,109,-1,2105,1,0,109,1,21101,4,0,1,21101,0,2481,0,1106,0,2081,109,-1,2105,1,0,59,109,1,21101,5,0,1,21102,1,2500,0,1106,0,2081,109,-1,2105,1,0,109,1,21102,1,6,1,21101,0,2518,0,1105,1,2081,109,-1,2105,1,0,0,0,109,5,1201,-3,0,2523,1102,1,1,2524,21202,-4,1,1,21101,2585,0,2,21102,1,2550,0,1106,0,1174,1206,-2,2576,2101,0,-4,2558,2001,0,-3,2566,101,3094,2566,2566,21008,0,-1,-1,1205,-1,2576,1101,0,0,2524,20101,0,2524,-4,109,-5,2106,0,0,109,5,22201,-4,-3,-4,22201,-4,-2,-4,21208,-4,10,-1,1206,-1,2606,21101,-1,0,-4,201,-3,2523,2615,1001,2615,3094,2615,21002,0,1,-1,22208,-4,-1,-1,1205,-1,2629,1102,0,1,2524,109,-5,2105,1,0,109,4,21102,1,3094,1,21102,1,30,2,21102,1,1,3,21102,2706,1,4,21102,2659,1,0,1105,1,1130,21101,0,0,-3,203,-2,21208,-2,10,-1,1205,-1,2701,21207,-2,0,-1,1205,-1,2663,21207,-3,29,-1,1206,-1,2663,2101,3094,-3,2693,1202,-2,1,0,21201,-3,1,-3,1106,0,2663,109,-4,2106,0,0,109,2,1201,-1,0,2715,1101,0,-1,0,109,-2,2106,0,0,0,109,5,1202,-2,1,2721,21207,-4,0,-1,1206,-1,2739,21101,0,0,-4,21201,-4,0,1,21201,-3,0,2,21102,1,1,3,21102,1,2758,0,1106,0,2763,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,2786,22207,-5,-3,-1,1206,-1,2786,21201,-5,0,-5,1105,1,2858,22102,1,-5,1,21201,-4,-1,2,21202,-3,2,3,21101,2805,0,0,1106,0,2763,22102,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2824,21102,1,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2850,21201,-2,0,1,21201,-4,-1,2,21101,0,2850,0,106,0,2721,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0,109,3,21208,-2,0,-1,1205,-1,2902,21207,-2,0,-1,1205,-1,2882,1106,0,2888,104,45,21202,-2,-1,-2,22102,1,-2,1,21102,1,2899,0,1105,1,2909,1105,1,2904,104,48,109,-3,2106,0,0,109,4,22101,0,-3,1,21102,1,10,2,21101,0,2926,0,1106,0,3010,22102,1,1,-2,21201,2,0,-1,1206,-2,2948,21202,-2,1,1,21102,2948,1,0,1105,1,2909,22101,48,-1,-1,204,-1,109,-4,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21102,0,1,-4,21101,0,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,2959,3033,21001,0,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,3059,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,3078,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,3024,22102,1,-4,-7,21201,-3,0,-6,109,-8,2106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3131,3143,0,3464,3252,3389,0,11,61,105,95,94,17,50,97,83,78,79,83,108,-19,2,7,-79,-9,-2,2,-83,-11,-7,-86,-3,-16,-7,-11,-6,-21,-21,-94,-30,-96,-25,-19,-23,-31,-101,-29,-25,-104,-21,-34,-38,-108,-39,-34,-32,-33,-31,-114,-43,-47,-35,-49,-105,-120,-69,-43,-123,-49,-56,-57,-47,-128,-40,-51,-46,-50,-133,-51,-63,-63,-57,-138,-69,-58,-62,-65,-143,-79,-69,-63,-68,-148,-79,-68,-82,-83,-63,-81,-77,-85,-145,-158,-75,-88,-92,-162,-91,-85,-89,-97,-167,-96,-104,-87,-171,-106,-104,-105,-97,-176,-94,-109,-114,-104,-112,-114,-169,3259,3268,0,3698,0,3324,3124,8,72,88,105,104,85,90,87,100,55,29,48,44,63,-20,54,40,-30,34,-32,43,39,49,48,39,31,-39,44,46,31,40,40,44,-46,18,30,19,-50,32,32,12,28,29,17,21,13,-59,24,18,-62,13,15,14,9,-67,-3,7,6,-71,-7,3,-1,0,-7,-63,3331,3354,0,3252,0,4255,3556,22,65,74,90,87,6,41,86,76,88,70,0,44,63,70,74,79,63,71,57,69,57,58,34,39,81,-4,60,74,73,61,56,72,72,-12,71,65,-15,50,52,-18,68,59,61,53,50,54,46,-26,51,51,53,47,34,44,43,55,-21,3396,3408,0,3124,0,0,0,11,72,87,92,87,95,83,84,14,57,77,77,55,34,55,60,-26,56,41,40,-30,38,54,40,34,34,42,30,31,-39,32,28,40,26,-44,34,24,-47,32,33,29,33,27,31,35,25,13,-57,22,20,16,28,15,6,18,-65,2,2,15,4,1,7,-72,14,5,7,-1,-63,3471,3479,0,0,0,3124,0,7,65,89,99,98,108,85,108,76,8,27,27,36,-48,16,32,18,13,-53,18,10,27,-57,8,10,9,17,-62,16,16,19,7,10,5,21,-1,-3,-72,-3,5,7,-76,6,1,-2,-11,3,-10,-10,-6,-14,-59,-87,1,-10,-5,-84,-10,-24,-94,-21,-11,-14,-14,-99,-22,-22,-18,-103,-23,-20,-33,-23,-39,-109,-27,-26,-30,-44,-114,-28,-44,-52,-34,-105,3563,3584,0,0,3324,3625,4166,20,51,84,80,93,8,62,88,70,84,83,75,79,71,-1,33,66,74,79,63,75,40,32,70,77,-11,57,63,69,54,-16,51,61,-19,69,58,63,-23,63,57,39,53,-28,51,52,38,51,36,44,49,47,-37,41,39,-40,43,30,26,-44,26,33,-16,3632,3641,0,3556,0,3961,0,8,64,102,98,100,88,88,85,92,56,27,54,51,42,51,49,39,-31,51,36,35,42,47,-37,46,40,-40,31,23,43,25,-45,30,22,22,35,-50,22,32,-53,25,23,-56,27,14,10,-60,-22,11,2,14,19,-66,-28,14,4,-2,-71,11,-4,10,9,-3,1,-7,-65,3705,3712,0,3833,0,3252,3753,6,59,107,91,88,90,90,40,38,70,68,58,-12,66,56,-15,68,55,51,-19,47,44,44,50,54,44,58,56,-28,54,39,38,45,-33,50,44,-36,35,27,47,29,-41,38,36,43,24,36,-33,3760,3772,0,4116,3698,0,0,11,68,86,102,87,99,102,80,98,92,94,100,60,24,43,39,51,37,-33,31,47,33,-37,27,-39,30,28,45,-43,40,24,30,22,35,18,29,29,17,30,-27,-55,28,15,11,30,-53,21,7,-63,1,11,10,-67,-2,10,6,13,-3,-5,-74,-7,3,10,0,-67,-80,3,-10,-4,1,-14,-14,-73,3840,3852,0,0,3904,3698,0,11,58,98,90,91,95,85,84,96,86,90,82,51,38,59,64,-22,60,45,44,-26,38,-28,58,42,42,52,36,32,44,29,45,30,-39,47,32,42,29,-44,35,30,18,30,34,-50,19,27,29,-54,-4,24,25,15,19,11,7,20,16,9,3,-66,19,-50,-55,3911,3925,0,0,0,4297,3833,13,54,100,86,103,15,63,98,77,93,94,78,90,90,35,49,68,64,-6,59,61,59,73,-11,53,69,55,-15,49,59,58,-19,64,58,57,-23,59,52,39,49,48,-29,40,48,50,-33,55,44,49,-23,3968,3991,0,3625,0,4020,0,22,50,88,92,7,41,77,83,70,81,77,65,83,67,-3,34,74,79,71,76,56,63,67,28,55,82,79,70,72,78,85,9,-4,68,78,0,75,-9,73,73,61,63,62,-15,71,62,64,56,53,57,49,-9,4027,4036,0,3961,0,0,4393,8,59,102,104,103,93,87,97,99,79,5,24,20,-50,26,17,31,11,21,-56,30,7,17,16,22,-62,2,14,3,-66,17,4,0,-70,6,-3,11,-9,1,-76,-7,-2,0,-1,1,-82,-18,-2,-16,-86,-4,-12,-16,-19,-19,-8,-17,-5,-95,-28,-24,-28,-29,-31,-19,-33,-25,-20,-105,-39,-28,-32,-30,-28,-28,-98,-113,-67,-33,-116,-52,-36,-50,-120,-37,-50,-54,-35,-94,4123,4131,0,0,0,3753,0,7,76,108,88,88,97,89,102,34,48,66,69,73,62,62,61,73,3,72,61,77,55,53,-2,-17,34,53,49,68,-15,59,45,-25,39,49,48,-29,39,46,48,51,55,-21,4173,4182,0,0,3556,0,0,8,75,96,89,96,20,53,83,106,72,11,44,38,37,35,37,38,36,-48,17,29,33,20,-53,-4,14,12,-44,-12,20,23,8,6,-63,-14,4,7,11,0,0,-1,11,-72,4,-5,-7,-3,-10,-5,-1,-11,-81,-17,-5,-16,-85,-4,-18,-17,-4,-14,-26,-10,-93,-12,-26,-23,-19,-30,-30,-31,-19,-102,-26,-35,-37,-33,-40,-35,-31,-41,-97,4262,4270,0,3324,0,0,0,7,68,97,107,89,93,89,97,26,43,91,73,85,91,85,72,72,76,68,3,78,-6,63,74,60,59,79,57,0,54,67,57,52,50,-5,4304,4315,0,3904,0,0,0,10,68,86,106,92,89,82,100,88,93,91,77,6,38,18,36,36,33,-25,-52,-2,30,27,9,21,10,10,8,-47,-62,-15,12,4,-1,16,1,-69,13,14,8,7,2,14,-76,0,-9,-14,3,4,0,-14,-7,-16,-8,-3,-5,-89,-20,-9,-13,-16,-94,-25,-23,-27,-14,-10,-100,-18,-18,-38,-22,-22,-106,-23,-29,-109,-28,-42,-45,-48,-38,-42,-50,-35,-53,-35,-51,-107,4400,4408,0,0,4020,4457,0,7,76,108,102,104,86,91,88,48,36,55,51,-19,46,58,66,46,59,-25,48,58,55,55,-30,36,47,45,50,30,37,41,-38,38,39,41,27,-43,22,34,42,22,35,-35,-50,-51,-2,16,13,30,26,26,15,27,9,15,27,-49,4464,4484,0,4393,0,4556,0,19,64,81,78,95,91,81,91,95,5,39,75,71,68,75,79,77,70,74,79,71,2,38,-41,42,29,25,-45,32,22,40,35,-50,31,27,26,23,-43,-56,8,-58,21,22,8,21,20,21,17,3,-54,15,0,8,12,1,11,-1,11,-7,-77,-8,-3,-1,-2,0,-83,3,-12,-10,-11,-88,-3,-21,-9,-19,-23,-5,-95,-7,-18,-13,-17,-100,-28,-34,-34,-26,-21,-33,-23,-19,-95,4563,4588,1553,4457,0,0,0,24,56,89,75,88,87,88,84,70,13,50,67,75,79,68,78,66,78,60,-10,27,64,66,65,67,12,53,97,83,93,105,105,87,91,83,25,24,23,3625,4653,27,1796,3324,4664,8388636,0,3698,4670,16413,0,3833,4684,542,0,3389,4694,65567,0,4020,4714,32,1850,3464,4726,33,1818,3961,4746,34,1872,3556,4754,163,0,4297,4762,134217764,0,4116,4770,37,1829,3904,4784,16777254,0,3252,4789,268435495,0,10,91,104,87,84,98,86,16,95,93,81,5,104,111,109,93,111,13,102,98,96,95,91,14,92,82,11,77,74,92,29,9,95,111,101,89,101,85,102,82,84,19,78,95,95,92,88,86,72,91,89,4,76,69,70,0,66,80,66,61,72,11,98,99,95,102,86,94,15,90,78,98,76,19,84,85,76,88,93,8,76,82,74,71,87,84,80,77,64,69,75,65,79,7,105,96,102,106,100,98,102,7,91,103,108,98,89,89,101,7,90,102,107,91,99,98,84,13,92,96,87,89,93,87,97,81,11,86,88,87,87,4,111,92,104,93,5,104,105,110,107,92],"Code":[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,-202,-191,-194,-192,-197,-205,-191,-207,-276,-278,-222,-201,-196,-282,-206,-219,-196,-286,-207,-206,-210,-223,-222,-223,-225,-280,-293,-296,-232,-220,-231,-300,-212,-223,-218,-304,-236,-228,-223,-239,-227,-310,-227,-240,-244,-314,-248,-237,-250,-243,-239,-247,-237,-308,-345,-273,-260,-248,-243,-263,-329,-252,-252,-248,-260,-267,-266,-253,-337,-249,-260,-255,-259,-342,-260,-267,-280,-270,-271,-348,-281,-268,-272,-279,-285,-342,-355,-280,-278,-279,-284,-277,-361,-282,-278,-274,-275,-290,-298,-300,-369,-300,-292,-290,-373,-309,-375,-299,-298,-301,-310,-302,-297,-370,-383,-302,-316,-321,-311,-315,-299,-321,-308,-392,-306,-322,-330,-312,-397,-326,-334,-317,-401,-330,-338,-324,-325,-337,-329,-339,-341,-398,-411,-347,-335,-346,-415,-334,-352,-350,-346,-341,-338,-422,-334,-345,-340,-344,-427,-345,-357,-357,-351,-432,-365,-361,-353,-367,-370,-354,-363,-351,-427,-464,-441,-397,-373,-434,-447,-376,-380,-374,-375,-373,-452,-454,-398,-377,-372,-458,-376,-388,-382,-377,-387,-396,-465,-400,-398,-468,-404,-404,-395,-403,-473,-390,-396,-476,-406,-409,-395,-480,-408,-404,-483,-418,-396,-486,-403,-399,-409,-417,-413,-421,-493,37,-5,73,71,-8,75,62,58,-12,62,55,74,64,48,50,-19,45,63,-22,61,48,44,-26,50,37,44,48,-31,33,40,48,41,43,30,37,-25,-38,-63,4457,0,109,7,21102,0,1,-2,22208,-2,-5,-1,1205,-1,1169,22202,-2,-4,1,22201,1,-6,1,21201,-2,0,2,21102,1162,1,0,2106,0,-3,21201,-2,1,-2,1105,1,1136,109,-7,2105,1,0,109,6,1201,-5,0,1182,20102,1,166,-2,21101,0,0,-3,21201,-5,1,-5,22208,-3,-2,-1,1205,-1,1229,2201,-5,-3,1205,20102,1,176,1,21202,-3,1,2,22102,1,-2,3,21101,0,1222,0,2105,1,-4,21201,-3,1,-3,1106,0,1192,109,-6,2105,1,0,109,2,22101,0,-1,1,21101,0,1256,2,21101,1251,0,0,1106,0,1174,109,-2,2105,1,0,109,5,22201,-4,-3,-1,22201,-2,-1,-1,204,-1,109,-5,2106,0,0,109,3,2101,0,-2,1280,1006,4463,1303,104,45,104,32,1201,-1,66,1291,21002,68,1,1,21101,0,1301,0,1106,0,1234,104,10,109,-3,2105,1,0,1,4457,109,2,1201,-1,0,1309,1101,0,0,1308,21101,4601,0,1,21102,1,13,2,21102,4,1,3,21101,0,1353,4,21101,1343,0,0,1106,0,1130,21001,1308,0,-1,109,-2,2105,1,0,70,109,3,2101,0,-2,1360,20008,4649,1309,-1,1206,-1,1419,1005,1308,1398,1101,0,1,1308,21008,1309,-1,-1,1206,-1,1387,21102,106,1,1,1106,0,1391,21102,92,1,1,21102,1,1398,0,1105,1,1234,104,45,104,32,1201,-2,1,1408,20101,0,4646,1,21102,1,1417,0,1105,1,1234,104,10,109,-3,2106,0,0,109,3,2102,1,-2,1128,21102,34,1,1,21101,1441,0,0,1105,1,1234,1001,1128,0,1447,20101,0,4457,1,21102,1,1456,0,1106,0,1234,21101,41,0,1,21102,1,1467,0,1105,1,1234,1001,1128,1,1473,20102,1,4458,1,21101,1482,0,0,1106,0,1234,21102,1,46,1,21101,1493,0,0,1105,1,1234,21001,1128,3,1,21102,4,1,2,21102,1,1,3,21102,1273,1,4,21101,0,1516,0,1105,1,1130,21002,1128,1,1,21102,1,1527,0,1105,1,1310,1001,1128,2,1532,21001,4459,0,-1,1206,-1,1545,21102,1545,1,0,2105,1,-1,109,-3,2105,1,0,268517888,4130,-1,109,2,1101,0,0,1550,21102,4601,1,1,21102,1,13,2,21102,1,4,3,21102,1664,1,4,21102,1,1582,0,1105,1,1130,2,2486,1352,1551,1101,0,0,1552,21001,1550,0,1,21101,0,33,2,21102,1,1702,3,21102,1,1609,0,1105,1,2722,21007,1552,0,-1,1205,-1,1630,20107,0,1552,-1,1205,-1,1637,21101,0,1630,0,1106,0,1752,21101,0,548,1,1105,1,1641,21102,687,1,1,21102,1648,1,0,1106,0,1234,21102,1,4457,1,21102,1,1659,0,1106,0,1424,109,-2,2106,0,0,109,4,21202,-2,-1,-2,1201,-3,0,1675,21008,4649,-1,-1,1206,-1,1697,1201,-3,2,1687,20101,-27,4651,-3,22201,-3,-2,-3,2001,1550,-3,1550,109,-4,2106,0,0,109,5,21008,1552,0,-1,1206,-1,1747,1201,-3,1901,1716,21001,1909,0,-2,1205,-4,1736,20207,-2,1551,-1,1205,-1,1747,1102,-1,1,1552,1106,0,1747,22007,1551,-2,-1,1205,-1,1747,1101,0,1,1552,109,-5,2106,0,0,109,1,21102,826,1,1,21101,1765,0,0,1105,1,1234,20102,1,1550,1,21101,1776,0,0,1105,1,2863,21101,1090,0,1,21102,1,1787,0,1106,0,1234,99,1105,1,1787,109,-1,2106,0,0,109,1,21102,1,512,1,21101,1809,0,0,1106,0,1234,99,1105,1,1809,109,-1,2106,0,0,109,1,1102,1,1,1129,109,-1,2105,1,0,109,1,21102,1,377,1,21102,1,1842,0,1105,1,1234,1106,0,1831,109,-1,2105,1,0,109,1,21101,0,407,1,21101,0,1863,0,1106,0,1234,99,1106,0,1863,109,-1,2106,0,0,109,1,21102,1,452,1,21101,0,1885,0,1106,0,1234,99,1105,1,1885,109,-1,2105,1,0,1941,1947,1953,1958,1965,1972,1978,3584,4102,4099,3470,4223,3883,4100,3983,4146,4026,3610,3464,3599,3502,3738,3509,4167,3991,3449,3751,3564,3734,4060,3697,3805,4201,4057,3543,3545,3992,3674,4039,3751,2281,2468,2418,2450,2487,2125,2505,5,95,108,104,104,23,5,96,91,108,108,1,4,101,105,112,3,6,104,104,106,107,94,-1,6,109,104,109,107,94,-1,5,111,91,100,93,23,5,114,95,108,108,1,109,3,21102,1,1993,0,1106,0,2634,1006,1129,2010,21101,0,316,1,21101,2007,0,0,1105,1,1234,1106,0,2076,21101,0,0,-1,1201,-1,1894,2020,20102,1,1898,1,21102,0,1,2,21101,0,0,3,21102,2037,1,0,1106,0,2525,1206,1,2054,1201,-1,1934,2050,21102,1,2051,0,105,1,1938,1106,0,2076,21201,-1,1,-1,21207,-1,7,-2,1205,-2,2014,21102,177,1,1,21101,0,2076,0,1105,1,1234,109,-3,2105,1,0,109,3,2001,1128,-2,2089,20102,1,4462,-1,1205,-1,2108,21102,1,201,1,21102,2105,1,0,1106,0,1234,1105,1,2119,22102,1,-1,1,21102,2119,1,0,1106,0,1424,109,-3,2106,0,0,1,109,1,1101,0,0,2124,21102,4601,1,1,21101,13,0,2,21102,1,4,3,21101,2173,0,4,21101,2154,0,0,1106,0,1130,1005,2124,2168,21102,1,226,1,21102,2168,1,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2124,2275,1201,-2,0,2183,20008,4633,1128,-1,1206,-1,2275,1201,-2,1,2194,21001,4634,0,-1,21201,-1,0,1,21102,5,1,2,21102,1,1,3,21102,1,2216,0,1105,1,2525,1206,1,2275,21101,258,0,1,21101,0,2230,0,1105,1,1234,21201,-1,0,1,21101,0,2241,0,1105,1,1234,104,46,104,10,1102,1,1,2124,1201,-2,0,2256,1102,-1,1,4633,1201,-2,3,2262,21002,4636,1,-1,1206,-1,2275,21101,2275,0,0,2105,1,-1,109,-3,2106,0,0,1,109,1,1101,0,0,2280,21101,4601,0,1,21102,1,13,2,21101,0,4,3,21102,2329,1,4,21101,2310,0,0,1106,0,1130,1005,2280,2324,21101,0,273,1,21102,1,2324,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2280,2413,1201,-2,0,2339,21008,4645,-1,-1,1206,-1,2413,1201,-2,1,2350,21001,4646,0,-1,21202,-1,1,1,21102,1,5,2,21102,1,1,3,21102,2372,1,0,1105,1,2525,1206,1,2413,21102,301,1,1,21102,2386,1,0,1105,1,1234,22101,0,-1,1,21101,0,2397,0,1106,0,1234,104,46,104,10,1101,1,0,2280,1201,-2,0,2412,101,0,1128,4645,109,-3,2105,1,0,109,1,21102,-1,1,1,21101,2431,0,0,1106,0,1310,1205,1,2445,21102,1,133,1,21102,1,2445,0,1106,0,1234,109,-1,2106,0,0,109,1,21102,3,1,1,21101,2463,0,0,1105,1,2081,109,-1,2105,1,0,109,1,21101,4,0,1,21101,0,2481,0,1106,0,2081,109,-1,2105,1,0,59,109,1,21101,5,0,1,21102,1,2500,0,1106,0,2081,109,-1,2105,1,0,109,1,21102,1,6,1,21101,0,2518,0,1105,1,2081,109,-1,2105,1,0,0,1,109,5,1201,-3,0,2523,1102,1,1,2524,21202,-4,1,1,21101,2585,0,2,21102,1,2550,0,1106,0,1174,1206,-2,2576,2101,0,-4,2558,2001,4784,-3,2566,101,3094,2566,2566,21008,3103,-1,-1,1205,-1,2576,1101,0,0,2524,20101,0,2524,-4,109,-5,2106,0,0,109,5,22201,-4,-3,-4,22201,-4,-2,-4,21208,-4,10,-1,1206,-1,2606,21101,-1,0,-4,201,-3,2523,2615,1001,2615,3094,2615,21002,3099,1,-1,22208,-4,-1,-1,1205,-1,2629,1102,0,1,2524,109,-5,2105,1,0,109,4,21102,1,3094,1,21102,1,30,2,21102,1,1,3,21102,2706,1,4,21102,2659,1,0,1105,1,1130,21101,0,0,-3,203,-2,21208,-2,10,-1,1205,-1,2701,21207,-2,0,-1,1205,-1,2663,21207,-3,29,-1,1206,-1,2663,2101,3094,-3,2693,1202,-2,1,3098,21201,-3,1,-3,1106,0,2663,109,-4,2106,0,0,109,2,1201,-1,0,2715,1101,0,-1,3123,109,-2,2106,0,0,1702,109,5,1202,-2,1,2721,21207,-4,0,-1,1206,-1,2739,21101,0,0,-4,21201,-4,0,1,21201,-3,0,2,21102,1,1,3,21102,1,2758,0,1106,0,2763,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,2786,22207,-5,-3,-1,1206,-1,2786,21201,-5,0,-5,1105,1,2858,22102,1,-5,1,21201,-4,-1,2,21202,-3,2,3,21101,2805,0,0,1106,0,2763,22102,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2824,21102,1,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2850,21201,-2,0,1,21201,-4,-1,2,21101,0,2850,0,106,0,2721,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0,109,3,21208,-2,0,-1,1205,-1,2902,21207,-2,0,-1,1205,-1,2882,1106,0,2888,104,45,21202,-2,-1,-2,22102,1,-2,1,21102,1,2899,0,1105,1,2909,1105,1,2904,104,48,109,-3,2106,0,0,109,4,22101,0,-3,1,21102,1,10,2,21101,0,2926,0,1106,0,3010,22102,1,1,-2,21201,2,0,-1,1206,-2,2948,21202,-2,1,1,21102,2948,1,0,1105,1,2909,22101,48,-1,-1,204,-1,109,-4,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21102,0,1,-4,21101,0,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,2959,3033,21001,0,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,3059,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,3078,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,3024,22102,1,-4,-7,21201,-3,0,-6,109,-8,2106,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3131,3143,0,3464,3252,3389,0,11,61,105,95,94,17,50,97,83,78,79,83,108,-19,2,7,-79,-9,-2,2,-83,-11,-7,-86,-3,-16,-7,-11,-6,-21,-21,-94,-30,-96,-25,-19,-23,-31,-101,-29,-25,-104,-21,-34,-38,-108,-39,-34,-32,-33,-31,-114,-43,-47,-35,-49,-105,-120,-69,-43,-123,-49,-56,-57,-47,-128,-40,-51,-46,-50,-133,-51,-63,-63,-57,-138,-69,-58,-62,-65,-143,-79,-69,-63,-68,-148,-79,-68,-82,-83,-63,-81,-77,-85,-145,-158,-75,-88,-92,-162,-91,-85,-89,-97,-167,-96,-104,-87,-171,-106,-104,-105,-97,-176,-94,-109,-114,-104,-112,-114,-169,3259,3268,0,3698,0,3324,3124,8,72,88,105,104,85,90,87,100,55,29,48,44,63,-20,54,40,-30,34,-32,43,39,49,48,39,31,-39,44,46,31,40,40,44,-46,18,30,19,-50,32,32,12,28,29,17,21,13,-59,24,18,-62,13,15,14,9,-67,-3,7,6,-71,-7,3,-1,0,-7,-63,3331,3354,0,3252,0,4255,3556,22,65,74,90,87,6,41,86,76,88,70,0,44,63,70,74,79,63,71,57,69,57,58,34,39,81,-4,60,74,73,61,56,72,72,-12,71,65,-15,50,52,-18,68,59,61,53,50,54,46,-26,51,51,53,47,34,44,43,55,-21,3396,3408,0,3124,0,0,0,11,72,87,92,87,95,83,84,14,57,77,77,55,34,55,60,-26,56,41,40,-30,38,54,40,34,34,42,30,31,-39,32,28,40,26,-44,34,24,-47,32,33,29,33,27,31,35,25,13,-57,22,20,16,28,15,6,18,-65,2,2,15,4,1,7,-72,14,5,7,-1,-63,3471,3479,0,0,0,3124,0,7,65,89,99,98,108,85,108,76,8,27,27,36,-48,16,32,18,13,-53,18,10,27,-57,8,10,9,17,-62,16,16,19,7,10,5,21,-1,-3,-72,-3,5,7,-76,6,1,-2,-11,3,-10,-10,-6,-14,-59,-87,1,-10,-5,-84,-10,-24,-94,-21,-11,-14,-14,-99,-22,-22,-18,-103,-23,-20,-33,-23,-39,-109,-27,-26,-30,-44,-114,-28,-44,-52,-34,-105,3563,3584,0,0,3324,3625,4166,20,51,84,80,93,8,62,88,70,84,83,75,79,71,-1,33,66,74,79,63,75,40,32,70,77,-11,57,63,69,54,-16,51,61,-19,69,58,63,-23,63,57,39,53,-28,51,52,38,51,36,44,49,47,-37,41,39,-40,43,30,26,-44,26,33,-16,3632,3641,0,3556,0,3961,0,8,64,102,98,100,88,88,85,92,56,27,54,51,42,51,49,39,-31,51,36,35,42,47,-37,46,40,-40,31,23,43,25,-45,30,22,22,35,-50,22,32,-53,25,23,-56,27,14,10,-60,-22,11,2,14,19,-66,-28,14,4,-2,-71,11,-4,10,9,-3,1,-7,-65,3705,3712,0,3833,0,3252,3753,6,59,107,91,88,90,90,40,38,70,68,58,-12,66,56,-15,68,55,51,-19,47,44,44,50,54,44,58,56,-28,54,39,38,45,-33,50,44,-36,35,27,47,29,-41,38,36,43,24,36,-33,3760,3772,0,4116,3698,0,0,11,68,86,102,87,99,102,80,98,92,94,100,60,24,43,39,51,37,-33,31,47,33,-37,27,-39,30,28,45,-43,40,24,30,22,35,18,29,29,17,30,-27,-55,28,15,11,30,-53,21,7,-63,1,11,10,-67,-2,10,6,13,-3,-5,-74,-7,3,10,0,-67,-80,3,-10,-4,1,-14,-14,-73,3840,3852,0,0,3904,3698,0,11,58,98,90,91,95,85,84,96,86,90,82,51,38,59,64,-22,60,45,44,-26,38,-28,58,42,42,52,36,32,44,29,45,30,-39,47,32,42,29,-44,35,30,18,30,34,-50,19,27,29,-54,-4,24,25,15,19,11,7,20,16,9,3,-66,19,-50,-55,3911,3925,0,0,0,4297,3833,13,54,100,86,103,15,63,98,77,93,94,78,90,90,35,49,68,64,-6,59,61,59,73,-11,53,69,55,-15,49,59,58,-19,64,58,57,-23,59,52,39,49,48,-29,40,48,50,-33,55,44,49,-23,3968,3991,0,3625,0,4020,0,22,50,88,92,7,41,77,83,70,81,77,65,83,67,-3,34,74,79,71,76,56,63,67,28,55,82,79,70,72,78,85,9,-4,68,78,0,75,-9,73,73,61,63,62,-15,71,62,64,56,53,57,49,-9,4027,4036,0,3961,0,0,4393,8,59,102,104,103,93,87,97,99,79,5,24,20,-50,26,17,31,11,21,-56,30,7,17,16,22,-62,2,14,3,-66,17,4,0,-70,6,-3,11,-9,1,-76,-7,-2,0,-1,1,-82,-18,-2,-16,-86,-4,-12,-16,-19,-19,-8,-17,-5,-95,-28,-24,-28,-29,-31,-19,-33,-25,-20,-105,-39,-28,-32,-30,-28,-28,-98,-113,-67,-33,-116,-52,-36,-50,-120,-37,-50,-54,-35,-94,4123,4131,0,0,0,3753,0,7,76,108,88,88,97,89,102,34,48,66,69,73,62,62,61,73,3,72,61,77,55,53,-2,-17,34,53,49,68,-15,59,45,-25,39,49,48,-29,39,46,48,51,55,-21,4173,4182,0,0,3556,0,0,8,75,96,89,96,20,53,83,106,72,11,44,38,37,35,37,38,36,-48,17,29,33,20,-53,-4,14,12,-44,-12,20,23,8,6,-63,-14,4,7,11,0,0,-1,11,-72,4,-5,-7,-3,-10,-5,-1,-11,-81,-17,-5,-16,-85,-4,-18,-17,-4,-14,-26,-10,-93,-12,-26,-23,-19,-30,-30,-31,-19,-102,-26,-35,-37,-33,-40,-35,-31,-41,-97,4262,4270,0,3324,0,0,0,7,68,97,107,89,93,89,97,26,43,91,73,85,91,85,72,72,76,68,3,78,-6,63,74,60,59,79,57,0,54,67,57,52,50,-5,4304,4315,0,3904,0,0,0,10,68,86,106,92,89,82,100,88,93,91,77,6,38,18,36,36,33,-25,-52,-2,30,27,9,21,10,10,8,-47,-62,-15,12,4,-1,16,1,-69,13,14,8,7,2,14,-76,0,-9,-14,3,4,0,-14,-7,-16,-8,-3,-5,-89,-20,-9,-13,-16,-94,-25,-23,-27,-14,-10,-100,-18,-18,-38,-22,-22,-106,-23,-29,-109,-28,-42,-45,-48,-38,-42,-50,-35,-53,-35,-51,-107,4400,4408,0,0,4020,4457,0,7,76,108,102,104,86,91,88,48,36,55,51,-19,46,58,66,46,59,-25,48,58,55,55,-30,36,47,45,50,30,37,41,-38,38,39,41,27,-43,22,34,42,22,35,-35,-50,-51,-2,16,13,30,26,26,15,27,9,15,27,-49,4464,4484,0,4393,0,4556,0,19,64,81,78,95,91,81,91,95,5,39,75,71,68,75,79,77,70,74,79,71,2,38,-41,42,29,25,-45,32,22,40,35,-50,31,27,26,23,-43,-56,8,-58,21,22,8,21,20,21,17,3,-54,15,0,8,12,1,11,-1,11,-7,-77,-8,-3,-1,-2,0,-83,3,-12,-10,-11,-88,-3,-21,-9,-19,-23,-5,-95,-7,-18,-13,-17,-100,-28,-34,-34,-26,-21,-33,-23,-19,-95,4563,4588,1553,4457,0,0,0,24,56,89,75,88,87,88,84,70,13,50,67,75,79,68,78,66,78,60,-10,27,64,66,65,67,12,53,97,83,93,105,105,87,91,83,25,24,23,3625,4653,27,1796,4457,4664,8388636,0,-1,4670,16413,0,-1,4684,542,0,-1,4694,65567,0,4020,4714,32,1850,3464,4726,33,1818,3961,4746,34,1872,4457,4754,163,0,4457,4762,134217764,0,4116,4770,37,1829,4457,4784,16777254,0,-1,4789,268435495,0,10,91,104,87,84,98,86,16,95,93,81,5,104,111,109,93,111,13,102,98,96,95,91,14,92,82,11,77,74,92,29,9,95,111,101,89,101,85,102,82,84,19,78,95,95,92,88,86,72,91,89,4,76,69,70,0,66,80,66,61,72,11,98,99,95,102,86,94,15,90,78,98,76,19,84,85,76,88,93,8,76,82,74,71,87,84,80,77,64,69,75,65,79,7,105,96,102,106,100,98,102,7,91,103,108,98,89,89,101,7,90,102,107,91,99,98,84,13,92,96,87,89,93,87,97,81,11,86,88,87,87,4,111,92,104,93,5,104,105,110,107,92,31,166,1251,1993,0,10,10,2659,3094,30,1,2706,30,1,1162,3123,29,1343,4601,13,4,1353,13,1,1162,4649,0,1417,4784,1251,4785,1256,4,4,1,1222,93,3,4,100,1,2850,0,29,0,0,1,2850,0,28,0,0,1,2850,0,27,0,0,1,2850,0,26,0,0,1,2850,0,25,0,0,1,2850,0,24,-512,0,1,2850,1,23,0,0,1,2850,0,22,0,0,1,2850,0,21,0,0,1,2850,0,20,0,0,1,2850,0,19,-16384,0,1,2850,1,18,0,0,1,2850,0,17,-65536,0,1,2850,1,16,0,0,1,2850,0,15,0,0,1,2850,0,14,0,0,1,2850,0,13,0,0,1,2850,0,12,0,0,1,2850,0,11,0,0,1,2850,0,10,0,0,1,2850,0,9,0,0,1,2850,0,8,4146,0,1,2850,0,7,3983,1,1,2850,0,6,4100,1,1,2850,0,5,3883,1,1,2850,1,4,4223,1,1,2850,0,3,3470,1,1,2850,0,2,4099,1,1,2850,0,1,4102,1,1,2850,0,0,3584,1,1],"Ptr":2665,"RelBase":4802,"State":0,"Error":null,"Pause":false,"Bail":false,"WaitingForInput":true,"WaitingForOutput":false,"Debug":false},"LastPI":1136,"Mode":1,"Events":{"UpdateTime":"2020-11-05T15:09:24.679427498-06:00","TimeoutLen":500000000,"Buffer":null,"CursorPos":-1},"Cli":{"History":null,"HistoryIdx":0,"Suggestions":["take sand","take antenna","take boulder","take mutex","south","north","drop astronaut ice cream","drop mouse","drop spool of cat6","drop hypercube"],"Proposals":null,"Buffer":"","Cursor":0,"Complete":false},"TheLog":["","","== Hull Breach ==","You got in through a hole in the floor here. To keep your ship from also freezing, the hole has been sealed.","","Doors here lead:","- north","- east","- south","","Command?","south","","","","== Science Lab ==","You see evidence here of prototype polymer design work.","","Doors here lead:","- north","","Items here:","- astronaut ice cream","","Command?","take astronaut ice cream","","You take the astronaut ice cream.","","Command?","north","","","","== Hull Breach ==","You got in through a hole in the floor here. To keep your ship from also freezing, the hole has been sealed.","","Doors here lead:","- north","- east","- south","","Command?","east","","","","== Passages ==","They're a little twisty and starting to look all alike.","","Doors here lead:","- north","- south","- west","","Items here:","- mouse","","Command?","take mouse","","You take the mouse.","","Command?","north","","","","== Arcade ==","None of the cabinets seem to have power.","","Doors here lead:","- north","- south","- west","","Items here:","- spool of cat6","","Command?","take spool of cat6","","You take the spool of cat6.","","Command?","north","","","","== Engineering ==","You see a whiteboard with plans for Springdroid v2.","","Doors here lead:","- east","- south","","Items here:","- hypercube","","Command?","take hypercube","","You take the hypercube.","","Command?","east","","","","== Crew Quarters ==","The beds are all too small for you.","","Doors here lead:","- south","- west","","Items here:","- sand","","Command?","take sand","","You take the sand.","","Command?","south","","","","== Navigation ==","Status: Stranded. Please supply measurements from fifty stars to recalibrate.","","Doors here lead:","- north","","Items here:","- antenna","","Command?","take antenna","","You take the antenna.","","Command?","north","","","","== Crew Quarters ==","The beds are all too small for you.","","Doors here lead:","- south","- west","","Command?","west","","","","== Engineering ==","You see a whiteboard with plans for Springdroid v2.","","Doors here lead:","- east","- south","","Command?","south","","","","== Arcade ==","None of the cabinets seem to have power.","","Doors here lead:","- north","- south","- west","","Command?","south","","","","== Passages ==","They're a little twisty and starting to look all alike.","","Doors here lead:","- north","- south","- west","","Command?","south","","","","== Warp Drive Maintenance ==","It appears to be working normally.","","Doors here lead:","- north","- south","- west","","Items here:","- mutex","","Command?","take mutex","","You take the mutex.","","Command?","west","","","","== Gift Wrapping Center ==","How else do you wrap presents on the go?","","Doors here lead:","- east","- south","- west","","Items here:","- boulder","","Command?","take boulder","","You take the boulder.","","Command?","south","","","","== Holodeck ==","Someone seems to have left it on the Giant Grid setting.","","Doors here lead:","- north","- south","","Items here:","- escape pod","","Command?","south","","","","== Hot Chocolate Fountain ==","Somehow, it's still working.","","Doors here lead:","- north","- south","","Items here:","- photons","","Command?","south","","","","== Corridor ==","The metal walls and the metal floor are slightly different colors. Or are they?","","Doors here lead:","- north","- west","","Items here:","- molten lava","","Command?","west","","","","== Storage ==","The boxes just contain more boxes. Recursively.","","Doors here lead:","- east","- south","","Command?","south","","","","== Security Checkpoint ==","In the next room, a pressure-sensitive floor will verify your identity.","","Doors here lead:","- north","- south","","Command?","drop boulder","","You drop the boulder.","","Command?","drop mutex","","You drop the mutex.","","Command?","drop antenna","","You drop the antenna.","","Command?","drop sand","","You drop the sand.","","Command?","","Quick Loaded","Unrecognized command.","","Command?","south","","","","== Pressure-Sensitive Floor ==","Analyzing...","","Doors here lead:","- north","","A loud, robotic voice says \"Alert! Droids on this ship are heavier than the detected value!\" and you are ejected back to the checkpoint.","","","","== Security Checkpoint ==","In the next room, a pressure-sensitive floor will verify your identity.","","Doors here lead:","- north","- south","","Items here:","- mutex","- boulder","- antenna","- sand","","Command?",""],"LogStartIdx":0,"LogDisplayLines":19,"StatusText":"Receiving '\n'","StatusSpinner":8,"Inventory":["astronaut ice cream","mouse","spool of cat6","hypercube"]} diff --git a/2019/day25/screen.go b/2019/day25/screen.go new file mode 100644 index 0000000..0d347f6 --- /dev/null +++ b/2019/day25/screen.go @@ -0,0 +1,404 @@ +package main + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "os" + "strconv" + "strings" + "time" + + intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor" + termboxScreen "github.com/br0xen/termbox-screen" + termboxUtil "github.com/br0xen/termbox-util" + "github.com/nsf/termbox-go" +) + +const ( + ModeWaiting = iota + ModeInput +) + +const ( + Bg = termbox.ColorBlack + Fg = termbox.ColorGreen +) + +var spinner []rune + +type Screen struct { + Title string + Program *intcode.Program + LastPI int + Mode int + Events *EventBuffer + Cli *CliProc + + TheLog []string + LogStartIdx int + LogDisplayLines int + + StatusText string + StatusSpinner int + + Inventory []string + + id int +} + +func NewScreen(p *intcode.Program) *Screen { + s := Screen{ + Title: "Day 25: Cryostasis", + Program: p, + Mode: ModeWaiting, + Events: NewEventBuffer(), + Cli: NewCLI(), + StatusSpinner: 0, + } + spinner = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▁'} + + // Process to update screen from program + go func() { + for { + if p.WaitingForInput || p.State == intcode.RET_DONE { + if !s.Cli.Complete { + s.Mode = ModeInput + } else { + s.Mode = ModeWaiting + inp := s.Cli.GetBuffer() + s.Cli.ClearBuffer() + if s.IsEngineCommand(inp) { + if err := s.ProcessCommand(inp); err != nil { + s.Logln("Engine Error: " + err.Error()) + } + continue + } + for k := range inp { + for !p.WaitingForInput { + time.Sleep(1) + } + s.StatusText = "Transmitting " + inp[0:k] + s.Log(string(inp[k])) + s.Program.Input(int(inp[k])) + } + s.StatusText = "Please Wait..." + s.Program.Input(int('\n')) + s.Logln("") + if strings.HasPrefix(inp, "take ") { + s.Cli.RemoveSuggestion(inp) + invAdd := strings.TrimPrefix(inp, "take ") + s.Inventory = append(s.Inventory, invAdd) + } else if strings.HasPrefix(inp, "drop ") { + invRem := strings.TrimPrefix(inp, "drop ") + for i := range s.Inventory { + if s.Inventory[i] == invRem { + s.Inventory = append(s.Inventory[:i], s.Inventory[i+1:]...) + break + } + } + } + } + } + if p.WaitingForOutput { + v := s.Program.Output() + s.StatusText = "Receiving '" + string(v) + "'" + if v == '\n' { + s.Logln("") + } else { + s.Log(string(v)) + } + } + } + }() + + // And actually run the program + s.Logln("Welcome to the Day25 Cryostasis Engine!") + s.Logln("Type '/start' to start") + s.Logln("Type '/load ' to load a save") + go func() { + ret := p.Run() + if ret == intcode.RET_DONE { + s.Logln("Program is done") + } else if ret == intcode.RET_ERR { + s.Logln("Program errored") + } + s.Logln("Type '/quit' to quit") + }() + return &s +} + +func (s *Screen) Id() int { return s.id } + +func (s *Screen) Initialize(bundle termboxScreen.Bundle) error { + s.Events.Clear() + s.TheLog = nil + return nil +} + +func (s *Screen) HandleNoneEvent(event termbox.Event) int { + // Update the display + return s.Id() +} + +func (s *Screen) HandleKeyEvent(event termbox.Event) int { + switch event.Key { + case termbox.KeyF5: + if err := s.SaveState("quick"); err != nil { + s.Logln("Engine Error: " + err.Error()) + } else { + s.Logln("Quick Saved") + } + case termbox.KeyF7: + if err := s.LoadState("quick"); err != nil { + s.Logln("Engine Error: " + err.Error()) + } else { + s.Logln("Quick Loaded") + } + case termbox.KeyPgup, termbox.KeyCtrlB: + // Page down the log + wrkLog := s.GetWrappedLog() + if s.LogStartIdx < len(wrkLog)-s.LogDisplayLines { + s.LogStartIdx = s.LogStartIdx + s.LogDisplayLines + } + if s.LogStartIdx > len(wrkLog)-s.LogDisplayLines { + s.LogStartIdx = len(wrkLog) - s.LogDisplayLines + } + + case termbox.KeyPgdn, termbox.KeyCtrlF: + // Page up the log + if s.LogStartIdx > 0 { + s.LogStartIdx = s.LogStartIdx - s.LogDisplayLines + } + if s.LogStartIdx < 0 { + s.LogStartIdx = 0 + } + default: + if s.Mode == ModeInput { + err := s.Cli.handleEvent(event) + if err != nil { + s.Log(err.Error()) + } + } + } + return s.Id() +} + +// ╭╼╾╮ +// │┼━│ +// ├┴┬┤ +// ╰──╯ +func (s *Screen) DrawScreen() { + s.DrawHeader() + s.DrawLog() + s.DrawInventory() + s.DrawTerminal() +} + +func (s *Screen) DrawLog() { + w, h := termbox.Size() + y := 1 + logW := w - 2 + h = h - 4 + s.LogDisplayLines = h - 1 + + wrkLog := s.GetWrappedLog() + currStart := len(wrkLog) - s.LogDisplayLines - s.LogStartIdx + if currStart < 0 { + currStart = 0 + } + statusStart := (len(wrkLog) - s.LogDisplayLines - currStart) + if statusStart < 0 { + statusStart = 0 + } + logStatus := fmt.Sprintf("%d/%d (%d:%d)", statusStart, len(wrkLog), s.LogStartIdx, currStart) + _, nY := termboxUtil.DrawStringAtPoint("╭"+logStatus+strings.Repeat("─", (logW-1-(len(logStatus))))+"╮", 1, y, Fg, Bg) + + for len(wrkLog) < s.LogDisplayLines { + wrkLog = append([]string{"~"}, wrkLog...) + } + for k := currStart; k < len(wrkLog) && k < currStart+s.LogDisplayLines; k++ { + nY = nY + 1 + v := "~" + if k >= 0 { + v = wrkLog[k] + } + if len(v) > logW-4 { + v = v[:logW-4] + } else if len(v) < logW-4 { + v = termboxUtil.AlignTextWithFill(v, logW-4, termboxUtil.AlignLeft, ' ') + } + _, nY = termboxUtil.DrawStringAtPoint(v, 2, nY, Fg, Bg) + termbox.SetCell(1, nY, '│', Fg, Bg) + termbox.SetCell((w - 1), nY, '│', Fg, Bg) + } + + termboxUtil.DrawStringAtPoint("├"+strings.Repeat("─", (logW-1))+"┤", 1, nY+1, Fg, Bg) +} + +func (s *Screen) DrawInventory() { + w, _ := termbox.Size() + title := "Inventory" + longest := len(title) + for k := range s.Inventory { + if len(s.Inventory[k]) > longest { + longest = len(s.Inventory[k]) + } + } + title = "┬" + title + strings.Repeat("─", longest-len(title)) + "╮" + termboxUtil.DrawStringAtPoint(title, w-(longest+2), 1, Fg, Bg) + for k := range s.Inventory { + termboxUtil.DrawStringAtPoint(s.Inventory[k], w-(longest+1), 2+k, Fg, Bg) + termbox.SetCell((w - longest - 2), 2+k, '│', Fg, Bg) + termbox.SetCell((w - 1), 2+k, '│', Fg, Bg) + } + + termboxUtil.DrawStringAtPoint("╰"+strings.Repeat("─", len(title)-6)+"┤", w-(longest+2), 2+len(s.Inventory), Fg, Bg) +} + +func (s *Screen) DrawTerminal() { + w, h := termbox.Size() + termbox.SetCell(1, h-2, '│', Fg, Bg) + termbox.SetCell((w - 1), h-2, '│', Fg, Bg) + if s.Mode == ModeInput && !s.Cli.Complete { + s.Cli.Draw(2, h-3, Fg, Bg) + } else { + s.DrawStatusLine() + } + termboxUtil.DrawStringAtPoint("╰"+strings.Repeat("─", (w-3))+"╯", 1, h-1, Fg, Bg) +} + +func (s *Screen) DrawStatusLine() { + _, h := termbox.Size() + if s.Program.Ptr != s.LastPI { + s.StatusSpinner = (s.StatusSpinner + 1) % len(spinner) + s.LastPI = s.Program.Ptr + } + status := string(spinner[s.StatusSpinner]) + " " + strconv.Itoa(s.LastPI) + for len(status) < 10 { + status = status + " " + } + termboxUtil.DrawStringAtPoint(status+" - "+s.StatusText, 2, h-2, Fg, Bg) +} + +func (s *Screen) DrawHeader() { + width, _ := termbox.Size() + spaces := strings.Repeat(" ", ((width-len(s.Title))/2)+1) + termboxUtil.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, s.Title, spaces), 0, 0, Bg, Fg) +} + +func (s *Screen) ResizeScreen() { + s.Initialize(nil) +} + +func (s *Screen) GetWrappedLog() []string { + w, _ := termbox.Size() + var wrkLog []string + for _, v := range s.TheLog { + var line string + pts := strings.Fields(v) + for k := range pts { + if len(line) == 0 { + line = pts[k] + } else { + if len(line+" "+pts[k]) < w-4 { + line = line + " " + pts[k] + } else { + wrkLog = append(wrkLog, line) + line = pts[k] + } + } + } + wrkLog = append(wrkLog, line) + } + return wrkLog +} + +func (s *Screen) Logln(msg string) { + s.TheLog = append(s.TheLog, msg) +} +func (s *Screen) Log(msg string) { + last := s.TheLog[len(s.TheLog)-1] + last = last + msg + s.TheLog[len(s.TheLog)-1] = last + if last == "Command?" { + s.ParseLogForCommands() + } +} + +func (s *Screen) ParseLogForCommands() { + // First fine the _previous_ 'Command?' + s.Cli.ClearSuggestions() + for k := len(s.TheLog) - 1; k >= 0; k-- { + if strings.HasPrefix(s.TheLog[k], "== ") { + // Room start + break + } + if strings.HasPrefix(s.TheLog[k], "- ") { + val := strings.TrimPrefix(s.TheLog[k], "- ") + switch val { + case "north", "east", "south", "west": + s.Cli.AddSuggestion(val) + default: + var have bool + for _, v := range s.Inventory { + if v == val { + have = true + break + } + } + if !have { + s.Cli.AddSuggestion("take " + val) + } + } + } + } + for _, v := range s.Inventory { + s.Cli.AddSuggestions([]string{"drop " + v}) + } +} + +func (s *Screen) IsEngineCommand(inp string) bool { + return inp == "/quit" || strings.HasPrefix(inp, "/save") || strings.HasPrefix(inp, "/load") +} +func (s *Screen) ProcessCommand(inp string) error { + if inp == "/quit" { + s.id = -1 + } else if strings.HasPrefix(inp, "/save ") { + pts := strings.Split(inp, " ") + if len(pts) == 2 { + return s.SaveState(pts[1]) + } + return errors.New("No filename given") + } else if strings.HasPrefix(inp, "/load ") { + pts := strings.Split(inp, " ") + if len(pts) == 2 { + return s.LoadState(pts[1]) + } + return errors.New("No filename given") + } + return nil +} + +func (s *Screen) SaveState(slot string) error { + // Save the engine state first + f, err := os.OpenFile("saveslot-"+slot+".sav", os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer f.Close() + enc := json.NewEncoder(f) + enc.Encode(s) + return nil +} + +func (s *Screen) LoadState(slot string) error { + hold, err := ioutil.ReadFile("saveslot-" + slot + ".sav") + if err != nil { + return err + } + json.NewDecoder(bytes.NewBuffer(hold)).Decode(&s) + return nil +} diff --git a/2019/day25/util.go b/2019/day25/util.go new file mode 100644 index 0000000..c8856f3 --- /dev/null +++ b/2019/day25/util.go @@ -0,0 +1,33 @@ +package main + +import ( + "strings" + + termboxUtil "github.com/br0xen/termbox-util" + "github.com/nsf/termbox-go" +) + +// Some characters for display +const ( + ChUpKeyValue = '↑' + ChRightKeyValue = '→' + ChDownKeyValue = '↓' + ChLeftKeyValue = '←' + ChEnterKeyValue = '⏎' + ChCursor = '┇' +) + +func DrawString(v string, x, y int, fg, bg termbox.Attribute) (int, int) { + termboxUtil.DrawStringAtPoint(v, x, y, fg, bg) + return (x + len(v)), (y + 1) +} + +func FilterStrings(h []string, n string) []string { + var ret []string + for _, v := range h { + if strings.HasPrefix(v, n) { + ret = append(ret, v) + } + } + return ret +} diff --git a/2019/intcode-processor/opt_proc.go b/2019/intcode-processor/opt_proc.go new file mode 100644 index 0000000..8888496 --- /dev/null +++ b/2019/intcode-processor/opt_proc.go @@ -0,0 +1,118 @@ +package intcodeprocessor + +import ( + "fmt" + "math" + "strconv" +) + +type OptProc struct { + OriginalCode []int + Code []int + Ptr int + RelBase int + + State int + Error error + + Pause bool + Bail bool + WaitingForInput bool + WaitingForOutput bool + + Debug bool + DebugToFile bool +} + +func NewOptProc(prog []int) *OptProc { + p := new(OptProc) + p.State = RET_OK + p.OriginalCode = make([]int, len(prog)) + max := math.MaxInt16 + if 2*len(prog) > max { + max = 2 * len(prog) + } + p.Code = make([]int, max) + copy(p.OriginalCode, prog) + return p +} + +func (p *OptProc) Run(in <-chan int, out chan<- int) int { + p.Ptr = 0 + p.RelBase = 0 + copy(p.Code, p.OriginalCode) + + for p.State == RET_OK { + ins := fmt.Sprintf("%05d", p.Code[p.Ptr]) + opcode, _ := strconv.Atoi(ins[3:]) + arg := func(i int) int { + switch ins[3-i] { + case '1': // Immediate mode + return p.Ptr + i + case '2': // Relative mode + return p.RelBase + p.Code[p.Ptr+i] + default: // 1, position mode + return p.Code[p.Ptr+i] + } + } + switch opcode { + case OP_ADD: + p.Code[arg(3)] = p.Code[arg(1)] + p.Code[arg(2)] + p.Ptr = p.Ptr + 4 + case OP_MLT: + p.Code[arg(3)] = p.Code[arg(1)] * p.Code[arg(2)] + p.Ptr += 4 + case OP_INP: + p.WaitingForInput = true + v := <-in + p.WaitingForInput = false + p.Code[arg(1)] = v + p.Ptr += 2 + + case OP_OUT: + p.WaitingForOutput = true + out <- p.Code[arg(1)] + p.WaitingForOutput = false + p.Ptr += 2 + + case OP_JIT: + if p.Code[arg(1)] != 0 { + p.Ptr = p.Code[arg(2)] + } else { + p.Ptr += 3 + } + case OP_JIF: + if p.Code[arg(1)] == 0 { + p.Ptr = p.Code[arg(2)] + } else { + p.Ptr += 3 + } + case OP_ILT: + if p.Code[arg(1)] < p.Code[arg(2)] { + p.Code[arg(3)] = 1 + } else { + p.Code[arg(3)] = 0 + } + p.Ptr += 4 + case OP_IEQ: + if p.Code[arg(1)] == p.Code[arg(2)] { + p.Code[arg(3)] = 1 + } else { + p.Code[arg(3)] = 0 + } + p.Ptr += 4 + case OP_RBS: + p.RelBase += p.Code[arg(1)] + p.Ptr += 2 + case OP_EXT: + p.State = RET_DONE + default: + p.State = RET_ERR + } + } + return p.State +} + +func (p *OptProc) IsStopped() bool { + return p.State != RET_OK +} diff --git a/2019/intcode-processor/processor.go b/2019/intcode-processor/processor.go index dd3520b..74f9192 100644 --- a/2019/intcode-processor/processor.go +++ b/2019/intcode-processor/processor.go @@ -1,12 +1,15 @@ package intcodeprocessor import ( + "bytes" + "encoding/json" "errors" "fmt" "io/ioutil" "math" "os" "strings" + "time" helpers "git.bullercodeworks.com/brian/adventofcode/helpers" ) @@ -37,21 +40,23 @@ const ( ) type Program struct { - originalCode []int - code []int - ptr int - relBase int + OriginalCode []int + Code []int + Ptr int + RelBase int - state int - error error + State int + Error error - bail bool - waitingForInput bool - input chan int - waitingForOutput bool - output chan int + Pause bool + Bail bool + WaitingForInput bool + InputChan chan int + WaitingForOutput bool + OutputChan chan int - debug bool + Debug bool + DebugToFile bool } func ReadIntCodeFile(fn string) []int { @@ -70,157 +75,180 @@ func ReadIntCodeFile(fn string) []int { func NewProgram(prog []int) *Program { p := new(Program) - p.originalCode = make([]int, len(prog)) - p.code = make([]int, len(prog)) - copy(p.originalCode, prog) + p.OriginalCode = make([]int, len(prog)) + p.Code = make([]int, len(prog)) + copy(p.OriginalCode, prog) p.Reset() return p } -func (p *Program) EnableDebug() { - p.debug = true +func (p *Program) SaveState(slot string) error { + f, err := os.OpenFile("saveslot-"+slot+".sav", os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer f.Close() + enc := json.NewEncoder(f) + enc.Encode(p) + return nil } -func (p *Program) DisableDebug() { - p.debug = false +func (p *Program) LoadState(slot string) error { + hold, err := ioutil.ReadFile("saveslot-" + slot + ".sav") + if err != nil { + return err + } + json.NewDecoder(bytes.NewBuffer(hold)).Decode(&p) + return nil +} + +func (p *Program) Pointer() int { + return p.Ptr } func (p *Program) DebugLog(l string) { - if p.debug { + if p.Debug { fmt.Print(l) } } +func (p *Program) OutputToFile(l string) { + f, err := os.OpenFile("debug-log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println(err) + return + } + defer f.Close() + _, err = fmt.Fprintln(f, l) +} + func (p *Program) Reset() { - copy(p.code, p.originalCode) - p.ptr = 0 - p.state = RET_OK - p.error = nil - p.waitingForInput = false - p.waitingForOutput = false - p.input = make(chan int) - p.output = make(chan int) - p.relBase = 0 -} - -func (p *Program) GetCode() []int { - return p.code -} - -func (p *Program) State() int { - return p.state -} - -func (p *Program) Error() error { - return p.error + copy(p.Code, p.OriginalCode) + p.Ptr = 0 + p.State = RET_OK + p.Error = nil + p.Pause = false + p.WaitingForInput = false + p.WaitingForOutput = false + p.InputChan = make(chan int) + p.OutputChan = make(chan int) + p.RelBase = 0 } func (p *Program) ForceQuit() { - p.bail = true - close(p.input) - close(p.output) + p.Bail = true + close(p.InputChan) + close(p.OutputChan) } func (p *Program) Run() int { for { - p.state = p.Step() - if p.state != RET_OK { - return p.state + p.State = p.Step() + if p.State != RET_OK { + return p.State } } } func (p *Program) Step() int { - if p.bail { - p.error = errors.New("Force Quit") + for p.Pause { + time.Sleep(1) + } + if p.Bail { + p.Error = errors.New("Force Quit") return RET_ERR } - if len(p.code) < p.ptr { - p.error = errors.New("Pointer Exception") + if len(p.Code) < p.Ptr { + p.Error = errors.New("Pointer Exception") return RET_ERR } p.DebugLog(p.String() + "\n") intcode := p.readNext() - p.ptr++ + p.Ptr++ switch p.opCode(intcode) { case OP_ADD: v1, v2, v3 := p.readNextThree() - p.DebugLog(fmt.Sprintf("ADD %d (%d, %d, %d)\n", intcode, v1, v2, v3)) - p.ptr = p.ptr + 3 + debug := fmt.Sprintf("ADD %d (%d, %d, %d)\n", intcode, v1, v2, v3) + p.DebugLog(debug) + if p.DebugToFile { + p.OutputToFile(fmt.Sprintf("%d: %s", p.Ptr, debug)) + } + p.Ptr = p.Ptr + 3 p.opAdd(intcode, v1, v2, v3) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_MLT: v1, v2, v3 := p.readNextThree() p.DebugLog(fmt.Sprintf("MLT %d (%d, %d, %d)\n", intcode, v1, v2, v3)) - p.ptr = p.ptr + 3 + p.Ptr = p.Ptr + 3 p.opMult(intcode, v1, v2, v3) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_INP: v1 := p.readNext() p.DebugLog(fmt.Sprintf("INP %d (%d)\n", intcode, v1)) - p.ptr++ + p.Ptr++ p.opInp(intcode, v1) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_OUT: v1 := p.readNext() - p.ptr++ + p.Ptr++ p.DebugLog(fmt.Sprintf("OUT %d (%d)\n", intcode, v1)) p.opOut(intcode, v1) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_JIT: v1, v2 := p.readNextTwo() p.DebugLog(fmt.Sprintf("JIT %d (%d, %d)\n", intcode, v1, v2)) - p.ptr = p.ptr + 2 + p.Ptr = p.Ptr + 2 p.opJumpIfTrue(intcode, v1, v2) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_JIF: v1, v2 := p.readNextTwo() p.DebugLog(fmt.Sprintf("JIF %d (%d, %d)\n", intcode, v1, v2)) - p.ptr = p.ptr + 2 + p.Ptr = p.Ptr + 2 p.opJumpIfFalse(intcode, v1, v2) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_ILT: v1, v2, dest := p.readNextThree() p.DebugLog(fmt.Sprintf("ILT %d (%d, %d, %d)\n", intcode, v1, v2, dest)) - p.ptr = p.ptr + 3 + p.Ptr = p.Ptr + 3 p.opIfLessThan(intcode, v1, v2, dest) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_IEQ: v1, v2, dest := p.readNextThree() - p.DebugLog(fmt.Sprintf("IEQ %d (%d, %d, %d)\n", intcode, v1, v2, dest)) - p.ptr = p.ptr + 3 + debug := fmt.Sprintf("IEQ %d (%d, %d, %d)\n", intcode, v1, v2, dest) + p.DebugLog(debug) + p.Ptr = p.Ptr + 3 p.opIfEqual(intcode, v1, v2, dest) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK case OP_RBS: v1 := p.readNext() p.DebugLog(fmt.Sprintf("RBS %d (%d)\n", intcode, v1)) - p.ptr = p.ptr + 1 + p.Ptr = p.Ptr + 1 p.opModRelBase(intcode, v1) - if p.error != nil { + if p.Error != nil { return RET_ERR } return RET_OK @@ -229,31 +257,31 @@ func (p *Program) Step() int { p.DebugLog(fmt.Sprintf("EXT %d\n", intcode)) return RET_DONE } - p.error = errors.New(fmt.Sprintf("Invalid OpCode (%d)", intcode)) + p.Error = errors.New(fmt.Sprintf("Invalid OpCode (%d)", intcode)) p.DebugLog(p.String()) return RET_ERR } func (p *Program) GetCurrentOpCode() int { - return p.code[p.ptr] + return p.Code[p.Ptr] } func (p *Program) GetProgramValueAt(idx int) int { p.ensureLength(idx) - return p.code[idx] + return p.Code[idx] } func (p *Program) SetProgramValueAt(idx, val int) { p.ensureLength(idx) - p.code[idx] = val + p.Code[idx] = val } func (p *Program) NeedsInput() bool { - return p.waitingForInput + return p.WaitingForInput } func (p *Program) NeedsOutput() bool { - return p.waitingForOutput + return p.WaitingForOutput } func (p *Program) opCode(intcode int) int { @@ -266,33 +294,33 @@ func (p *Program) paramMode(intcode, pNum int) int { } func (p *Program) ensureLength(idx int) { - for len(p.code) < idx+1 { - p.code = append(p.code, 0) + for len(p.Code) < idx+1 { + p.Code = append(p.Code, 0) } } func (p *Program) readNext() int { - p.ensureLength(p.ptr) - return p.code[p.ptr] + p.ensureLength(p.Ptr) + return p.Code[p.Ptr] } func (p *Program) readNextTwo() (int, int) { - p.ensureLength(p.ptr + 1) - return p.code[p.ptr], p.code[p.ptr+1] + p.ensureLength(p.Ptr + 1) + return p.Code[p.Ptr], p.Code[p.Ptr+1] } func (p *Program) readNextThree() (int, int, int) { - p.ensureLength(p.ptr + 2) - return p.code[p.ptr], p.code[p.ptr+1], p.code[p.ptr+2] + p.ensureLength(p.Ptr + 2) + return p.Code[p.Ptr], p.Code[p.Ptr+1], p.Code[p.Ptr+2] } func (p *Program) get(mode, v int) int { if mode == MODE_POS { p.ensureLength(v) - return p.code[v] + return p.Code[v] } else if mode == MODE_REL { - p.ensureLength(p.relBase + v) - return p.code[p.relBase+v] + p.ensureLength(p.RelBase + v) + return p.Code[p.RelBase+v] } return v } @@ -300,21 +328,21 @@ func (p *Program) get(mode, v int) int { func (p *Program) set(mode, idx, v int) { if mode == MODE_POS { p.ensureLength(idx) - p.code[idx] = v + p.Code[idx] = v } else if mode == MODE_REL { - p.ensureLength(p.relBase + idx) - p.code[p.relBase+idx] = v + p.ensureLength(p.RelBase + idx) + p.Code[p.RelBase+idx] = v } } func (p *Program) Input(v int) { - p.input <- v - //p.waitingForInput = false + p.InputChan <- v + //p.WaitingForInput = false } func (p *Program) Output() int { - v := <-p.output - p.waitingForOutput = false + v := <-p.OutputChan + p.WaitingForOutput = false return v } @@ -330,29 +358,29 @@ func (p *Program) opMult(intcode, a1, a2, dest int) { func (p *Program) opInp(intcode, dest int) { destmd := p.paramMode(intcode, 0) - p.waitingForInput = true - p.set(destmd, dest, <-p.input) - p.waitingForInput = false + p.WaitingForInput = true + p.set(destmd, dest, <-p.InputChan) + p.WaitingForInput = false } func (p *Program) opOut(intcode, val int) { valmd := p.paramMode(intcode, 0) ret := p.get(valmd, val) - p.waitingForOutput = true - p.output <- ret + p.WaitingForOutput = true + p.OutputChan <- ret } func (p *Program) opJumpIfTrue(intcode, v1, v2 int) { v1md, v2md := p.paramMode(intcode, 0), p.paramMode(intcode, 1) if p.get(v1md, v1) != 0 { - p.ptr = p.get(v2md, v2) + p.Ptr = p.get(v2md, v2) } } func (p *Program) opJumpIfFalse(intcode, v1, v2 int) { v1md, v2md := p.paramMode(intcode, 0), p.paramMode(intcode, 1) if p.get(v1md, v1) == 0 { - p.ptr = p.get(v2md, v2) + p.Ptr = p.get(v2md, v2) } } @@ -376,17 +404,17 @@ func (p *Program) opIfEqual(intcode, v1, v2, dest int) { func (p *Program) opModRelBase(intcode, v1 int) { v1md := p.paramMode(intcode, 0) - p.relBase = p.relBase + p.get(v1md, v1) + p.RelBase = p.RelBase + p.get(v1md, v1) } func (p Program) String() string { var ret string - ret = ret + fmt.Sprintf("(PTR: %d, RBS: %d)\n", p.ptr, p.relBase) - for k := range p.code { - if k == p.ptr { - ret = fmt.Sprintf("%s [%d]", ret, p.code[k]) + ret = ret + fmt.Sprintf("(PTR: %d, RBS: %d)\n", p.Ptr, p.RelBase) + for k := range p.Code { + if k == p.Ptr { + ret = fmt.Sprintf("%s [%d]", ret, p.Code[k]) } else { - ret = fmt.Sprintf("%s %d", ret, p.code[k]) + ret = fmt.Sprintf("%s %d", ret, p.Code[k]) } } return ret