diff --git a/day10/day10 b/day10/day10 index 74cb0a3..83f6975 100755 Binary files a/day10/day10 and b/day10/day10 differ diff --git a/day10/main.go b/day10/main.go index 70ff280..0e445e1 100644 --- a/day10/main.go +++ b/day10/main.go @@ -16,9 +16,6 @@ var watch1, watch2 int func main() { input := stdinToStringSlice() - for i := 0; i < 500; i++ { - allBots = append(allBots, Bot{id: i}) - } watch1 = 61 watch2 = 17 //outputBins := make(map[int][]int) @@ -27,14 +24,10 @@ func main() { if inst[0] == "bot" { // And instruction // make sure we have this bot - botNum := atoi(inst[1]) + botNum := inst[0] + inst[1] botIdx := findBotIdx(botNum) - if inst[5] == "bot" { - allBots[botIdx].giveLowTo = atoi(inst[6]) - } - if inst[10] == "bot" { - allBots[botIdx].giveHighTo = atoi(inst[11]) - } + allBots[botIdx].giveLowTo = inst[5] + inst[6] + allBots[botIdx].giveHighTo = inst[10] + inst[11] } } // Run sim @@ -42,34 +35,43 @@ func main() { inst := strings.Fields(input[i]) if inst[0] == "value" { val := atoi(inst[1]) - botNum := atoi(inst[5]) + botNum := inst[4] + inst[5] botIdx := findBotIdx(botNum) allBots[botIdx].chips = append(allBots[botIdx].chips, val) allBots[botIdx].Trigger() } } + for i := range allBots { + fmt.Println(allBots[i]) + } } -func findBotIdx(id int) int { +func findBotIdx(id string) int { + fmt.Println("Find bot", id) for i := range allBots { if allBots[i].id == id { return i } } - return -1 + // We didn't find the bot + b := new(Bot) + b.id = id + allBots = append(allBots, *b) + return len(allBots) - 1 } type Bot struct { - id int + id string chips []int - giveLowTo int - giveHighTo int + giveLowTo string + giveHighTo string } func (b *Bot) Trigger() { + if strings.HasPrefix(b.id, "output") { + return + } if len(b.chips) == 2 { - fmt.Println("Triggering", b.id, b.chips) - //checkWatches(b) low := b.chips[0] high := b.chips[1] if b.chips[0] > b.chips[1] { @@ -78,10 +80,8 @@ func (b *Bot) Trigger() { } giveLowIdx := findBotIdx(b.giveLowTo) - fmt.Println("Trig2: ", b.giveLowTo, allBots[giveLowIdx]) allBots[giveLowIdx].chips = append(allBots[giveLowIdx].chips, low) - fmt.Println("3") giveHighIdx := findBotIdx(b.giveHighTo) allBots[giveHighIdx].chips = append(allBots[giveHighIdx].chips, high) diff --git a/day10/output b/day10/output deleted file mode 100644 index c840f0c..0000000 --- a/day10/output +++ /dev/null @@ -1,627 +0,0 @@ -Triggering 88 [67 19] -Trig2: 77 {77 [71] 93 84} -3 -Triggering 77 [71 19] -Trig2: 93 {93 [3] 44 70} -3 -Triggering 93 [3 19] -Trig2: 44 {44 [2] 9 144} -3 -Triggering 44 [2 3] -Trig2: 9 {9 [13] 173 197} -3 -Triggering 9 [13 2] -Trig2: 173 {173 [41] 177 174} -3 -Triggering 173 [41 2] -Trig2: 177 {177 [59] 21 132} -3 -Triggering 177 [59 2] -Trig2: 21 {21 [47] 114 119} -3 -Triggering 21 [47 2] -Trig2: 114 {114 [31] 109 186} -3 -Triggering 114 [31 2] -Trig2: 109 {109 [73] 167 86} -3 -Triggering 109 [73 2] -Trig2: 167 {167 [17] 7 96} -3 -Triggering 167 [17 2] -Trig2: 7 {7 [29] 76 80} -3 -Triggering 7 [29 2] -Trig2: 76 {76 [43] 165 41} -3 -Triggering 76 [43 2] -Trig2: 165 {165 [11] 63 196} -3 -Triggering 165 [11 2] -Trig2: 63 {63 [7] 92 74} -3 -Triggering 63 [7 2] -Trig2: 92 {92 [] 42 187} -3 -Triggering 84 [67 71] -Trig2: 70 {70 [19] 144 78} -3 -Triggering 70 [19 67] -Trig2: 144 {144 [3] 197 14} -3 -Triggering 144 [3 19] -Trig2: 197 {197 [13] 174 81} -3 -Triggering 197 [13 3] -Trig2: 174 {174 [41] 132 141} -3 -Triggering 174 [41 3] -Trig2: 132 {132 [59] 119 170} -3 -Triggering 132 [59 3] -Trig2: 119 {119 [47] 186 97} -3 -Triggering 119 [47 3] -Trig2: 186 {186 [31] 86 178} -3 -Triggering 186 [31 3] -Trig2: 86 {86 [73] 96 106} -3 -Triggering 86 [73 3] -Trig2: 96 {96 [17] 80 155} -3 -Triggering 96 [17 3] -Trig2: 80 {80 [29] 41 191} -3 -Triggering 80 [29 3] -Trig2: 41 {41 [43] 196 192} -3 -Triggering 41 [43 3] -Trig2: 196 {196 [11] 74 140} -3 -Triggering 196 [11 3] -Trig2: 74 {74 [7] 187 125} -3 -Triggering 74 [7 3] -Trig2: 187 {187 [] 149 8} -3 -Triggering 78 [71 67] -Trig2: 14 {14 [19] 81 200} -3 -Triggering 14 [19 67] -Trig2: 81 {81 [13] 141 94} -3 -Triggering 81 [13 19] -Trig2: 141 {141 [41] 170 6} -3 -Triggering 141 [41 13] -Trig2: 170 {170 [59] 97 5} -3 -Triggering 170 [59 13] -Trig2: 97 {97 [47] 178 67} -3 -Triggering 97 [47 13] -Trig2: 178 {178 [31] 106 169} -3 -Triggering 178 [31 13] -Trig2: 106 {106 [73] 155 99} -3 -Triggering 106 [73 13] -Trig2: 155 {155 [17] 191 32} -3 -Triggering 155 [17 13] -Trig2: 191 {191 [29] 192 154} -3 -Triggering 191 [29 13] -Trig2: 192 {192 [43] 140 51} -3 -Triggering 192 [43 13] -Trig2: 140 {140 [11] 125 60} -3 -Triggering 140 [11 13] -Trig2: 125 {125 [7] 8 156} -3 -Triggering 125 [7 11] -Trig2: 8 {8 [] 13 75} -3 -Triggering 200 [71 67] -Trig2: 94 {94 [19] 6 25} -3 -Triggering 94 [19 67] -Trig2: 6 {6 [41] 5 24} -3 -Triggering 6 [41 19] -Trig2: 5 {5 [59] 67 85} -3 -Triggering 5 [59 19] -Trig2: 67 {67 [47] 169 30} -3 -Triggering 67 [47 19] -Trig2: 169 {169 [31] 99 159} -3 -Triggering 169 [31 19] -Trig2: 99 {99 [73] 32 201} -3 -Triggering 99 [73 19] -Trig2: 32 {32 [17] 154 206} -3 -Triggering 32 [17 19] -Trig2: 154 {154 [29] 51 12} -3 -Triggering 154 [29 17] -Trig2: 51 {51 [43] 60 31} -3 -Triggering 51 [43 17] -Trig2: 60 {60 [13] 156 208} -3 -Triggering 60 [13 17] -Trig2: 156 {156 [11] 75 90} -3 -Triggering 156 [11 13] -Trig2: 75 {75 [] 61 104} -3 -Triggering 25 [71 67] -Trig2: 24 {24 [41] 85 83} -3 -Triggering 24 [41 67] -Trig2: 85 {85 [59] 30 199} -3 -Triggering 85 [59 41] -Trig2: 30 {30 [47] 159 68} -3 -Triggering 30 [47 41] -Trig2: 159 {159 [31] 201 23} -3 -Triggering 159 [31 41] -Trig2: 201 {201 [73] 206 198} -3 -Triggering 201 [73 31] -Trig2: 206 {206 [19] 12 43} -3 -Triggering 206 [19 31] -Trig2: 12 {12 [29] 31 4} -3 -Triggering 12 [29 19] -Trig2: 31 {31 [43] 208 143} -3 -Triggering 31 [43 19] -Trig2: 208 {208 [17] 90 163} -3 -Triggering 208 [17 19] -Trig2: 90 {90 [13] 104 34} -3 -Triggering 90 [13 17] -Trig2: 104 {104 [] 136 10} -3 -Triggering 83 [71 67] -Trig2: 199 {199 [59] 68 135} -3 -Triggering 199 [59 67] -Trig2: 68 {68 [47] 23 87} -3 -Triggering 68 [47 59] -Trig2: 23 {23 [41] 198 171} -3 -Triggering 23 [41 47] -Trig2: 198 {198 [73] 43 17} -3 -Triggering 198 [73 41] -Trig2: 43 {43 [31] 4 181} -3 -Triggering 43 [31 41] -Trig2: 4 {4 [29] 143 166} -3 -Triggering 4 [29 31] -Trig2: 143 {143 [43] 163 33} -3 -Triggering 143 [43 29] -Trig2: 163 {163 [19] 34 116} -3 -Triggering 163 [19 29] -Trig2: 34 {34 [17] 10 20} -3 -Triggering 34 [17 19] -Trig2: 10 {10 [] 158 130} -3 -Triggering 135 [71 67] -Trig2: 87 {87 [59] 171 111} -3 -Triggering 87 [59 67] -Trig2: 171 {171 [47] 17 202} -3 -Triggering 171 [47 59] -Trig2: 17 {17 [73] 181 162} -3 -Triggering 17 [73 47] -Trig2: 181 {181 [41] 166 205} -3 -Triggering 181 [41 47] -Trig2: 166 {166 [31] 33 139} -3 -Triggering 166 [31 41] -Trig2: 33 {33 [43] 116 150} -3 -Triggering 33 [43 31] -Trig2: 116 {116 [29] 20 131} -3 -Triggering 116 [29 31] -Trig2: 20 {20 [19] 130 73} -3 -Triggering 20 [19 29] -Trig2: 130 {130 [] 110 105} -3 -Triggering 111 [71 67] -Trig2: 202 {202 [59] 162 184} -3 -Triggering 202 [59 67] -Trig2: 162 {162 [73] 205 39} -3 -Triggering 162 [73 59] -Trig2: 205 {205 [47] 139 115} -3 -Triggering 205 [47 59] -Trig2: 139 {139 [41] 150 153} -3 -Triggering 139 [41 47] -Trig2: 150 {150 [43] 131 148} -3 -Triggering 150 [43 41] -Trig2: 131 {131 [31] 73 204} -3 -Triggering 131 [31 41] -Trig2: 73 {73 [29] 105 112} -3 -Triggering 73 [29 31] -Trig2: 105 {105 [] 89 19} -3 -Triggering 184 [71 67] -Trig2: 39 {39 [73] 115 3} -3 -Triggering 39 [73 67] -Trig2: 115 {115 [59] 153 134} -3 -Triggering 115 [59 67] -Trig2: 153 {153 [47] 148 122} -3 -Triggering 153 [47 59] -Trig2: 148 {148 [43] 204 137} -3 -Triggering 148 [43 47] -Trig2: 204 {204 [41] 112 36} -3 -Triggering 204 [41 43] -Trig2: 112 {112 [31] 19 118} -3 -Triggering 112 [31 41] -Trig2: 19 {19 [] 2 164} -3 -Triggering 3 [71 73] -Trig2: 134 {134 [67] 122 66} -3 -Triggering 134 [67 71] -Trig2: 122 {122 [59] 137 1} -3 -Triggering 122 [59 67] -Trig2: 137 {137 [47] 36 18} -3 -Triggering 137 [47 59] -Trig2: 36 {36 [43] 118 121} -3 -Triggering 36 [43 47] -Trig2: 118 {118 [41] 164 55} -3 -Triggering 118 [41 43] -Trig2: 164 {164 [] 91 203} -3 -Triggering 66 [73 71] -Trig2: 1 {1 [67] 18 209} -3 -Triggering 1 [67 71] -Trig2: 18 {18 [59] 121 168} -3 -Triggering 18 [59 67] -Trig2: 121 {121 [47] 55 126} -3 -Triggering 121 [47 59] -Trig2: 55 {55 [43] 203 193} -3 -Triggering 55 [43 47] -Trig2: 203 {203 [] 172 64} -3 -Triggering 209 [73 71] -Trig2: 168 {168 [67] 126 26} -3 -Triggering 168 [67 71] -Trig2: 126 {126 [59] 193 56} -3 -Triggering 126 [59 67] -Trig2: 193 {193 [47] 64 98} -3 -Triggering 193 [47 59] -Trig2: 64 {64 [] 123 48} -3 -Triggering 26 [73 71] -Trig2: 56 {56 [67] 98 147} -3 -Triggering 56 [67 71] -Trig2: 98 {98 [59] 48 45} -3 -Triggering 98 [59 67] -Trig2: 48 {48 [] 107 58} -3 -Triggering 147 [73 71] -Trig2: 45 {45 [67] 58 95} -3 -Triggering 45 [67 71] -Trig2: 58 {58 [] 15 101} -3 -Triggering 95 [73 71] -Trig2: 101 {101 [] 188 100} -3 -Triggering 95 [73 71] -Trig2: 101 {101 [71] 188 100} -3 -Triggering 101 [71 71] -Trig2: 188 {188 [] 128 38} -3 -Triggering 147 [73 71] -Trig2: 45 {45 [67 71] 58 95} -3 -Triggering 26 [73 71] -Trig2: 56 {56 [67 71] 98 147} -3 -Triggering 209 [73 71] -Trig2: 168 {168 [67 71] 126 26} -3 -Triggering 66 [73 71] -Trig2: 1 {1 [67 71] 18 209} -3 -Triggering 3 [71 73] -Trig2: 134 {134 [67 71] 122 66} -3 -Triggering 184 [71 67] -Trig2: 39 {39 [73 67] 115 3} -3 -Triggering 111 [71 67] -Trig2: 202 {202 [59 67] 162 184} -3 -Triggering 135 [71 67] -Trig2: 87 {87 [59 67] 171 111} -3 -Triggering 83 [71 67] -Trig2: 199 {199 [59 67] 68 135} -3 -Triggering 25 [71 67] -Trig2: 24 {24 [41 67] 85 83} -3 -Triggering 200 [71 67] -Trig2: 94 {94 [19 67] 6 25} -3 -Triggering 78 [71 67] -Trig2: 14 {14 [19 67] 81 200} -3 -Triggering 84 [67 71] -Trig2: 70 {70 [19 67] 144 78} -3 -Triggering 92 [2 5] -Trig2: 42 {42 [23] 207 149} -3 -Triggering 42 [23 2] -Trig2: 207 {207 [53] 37 62} -3 -Triggering 207 [53 2] -Trig2: 37 {37 [37] 29 157} -3 -Triggering 37 [37 2] -Trig2: 29 {29 [61] 0 16} -3 -Triggering 29 [61 2] -Trig2: 0 {0 [] 35 103} -3 -Triggering 187 [3 5] -Trig2: 149 {149 [23] 62 13} -3 -Triggering 149 [23 3] -Trig2: 62 {62 [53] 157 138} -3 -Triggering 62 [53 3] -Trig2: 157 {157 [37] 16 180} -3 -Triggering 157 [37 3] -Trig2: 16 {16 [61] 0 189} -3 -Triggering 16 [61 3] -Trig2: 0 {0 [2] 35 103} -3 -Triggering 0 [2 3] -Trig2: 35 {35 [] 0 50} -3 -Triggering 8 [7 5] -Trig2: 13 {13 [23] 138 61} -3 -Triggering 13 [23 5] -Trig2: 138 {138 [53] 180 52} -3 -Triggering 138 [53 5] -Trig2: 180 {180 [37] 189 27} -3 -Triggering 180 [37 5] -Trig2: 189 {189 [61] 0 108} -3 -Triggering 189 [61 5] -Trig2: 0 {0 [2 3] 35 103} -3 -Triggering 75 [11 7] -Trig2: 61 {61 [23] 52 136} -3 -Triggering 61 [23 7] -Trig2: 52 {52 [53] 27 28} -3 -Triggering 52 [53 7] -Trig2: 27 {27 [37] 108 46} -3 -Triggering 27 [37 7] -Trig2: 108 {108 [61] 0 175} -3 -Triggering 108 [61 7] -Trig2: 0 {0 [2 3 5] 35 103} -3 -Triggering 104 [13 11] -Trig2: 136 {136 [23] 28 158} -3 -Triggering 136 [23 11] -Trig2: 28 {28 [53] 46 102} -3 -Triggering 28 [53 11] -Trig2: 46 {46 [37] 175 195} -3 -Triggering 46 [37 11] -Trig2: 175 {175 [61] 0 133} -3 -Triggering 175 [61 11] -Trig2: 0 {0 [2 3 5 7] 35 103} -3 -Triggering 10 [17 13] -Trig2: 158 {158 [23] 102 110} -3 -Triggering 158 [23 13] -Trig2: 102 {102 [53] 195 117} -3 -Triggering 102 [53 13] -Trig2: 195 {195 [37] 133 183} -3 -Triggering 195 [37 13] -Trig2: 133 {133 [61] 0 47} -3 -Triggering 133 [61 13] -Trig2: 0 {0 [2 3 5 7 11] 35 103} -3 -Triggering 130 [19 17] -Trig2: 110 {110 [23] 117 89} -3 -Triggering 110 [23 17] -Trig2: 117 {117 [53] 183 72} -3 -Triggering 117 [53 17] -Trig2: 183 {183 [37] 47 65} -3 -Triggering 183 [37 17] -Trig2: 47 {47 [61] 0 152} -3 -Triggering 47 [61 17] -Trig2: 0 {0 [2 3 5 7 11 13] 35 103} -3 -Triggering 105 [29 19] -Trig2: 89 {89 [23] 72 2} -3 -Triggering 89 [23 19] -Trig2: 72 {72 [53] 65 160} -3 -Triggering 72 [53 19] -Trig2: 65 {65 [37] 152 194} -3 -Triggering 65 [37 19] -Trig2: 152 {152 [61] 0 190} -3 -Triggering 152 [61 19] -Trig2: 0 {0 [2 3 5 7 11 13 17] 35 103} -3 -Triggering 19 [31 29] -Trig2: 2 {2 [23] 160 91} -3 -Triggering 2 [23 29] -Trig2: 160 {160 [53] 194 151} -3 -Triggering 160 [53 23] -Trig2: 194 {194 [37] 190 82} -3 -Triggering 194 [37 23] -Trig2: 190 {190 [61] 0 146} -3 -Triggering 190 [61 23] -Trig2: 0 {0 [2 3 5 7 11 13 17 19] 35 103} -3 -Triggering 164 [41 31] -Trig2: 91 {91 [29] 151 172} -3 -Triggering 91 [29 31] -Trig2: 151 {151 [53] 82 79} -3 -Triggering 151 [53 29] -Trig2: 82 {82 [37] 146 22} -3 -Triggering 82 [37 29] -Trig2: 146 {146 [61] 0 53} -3 -Triggering 146 [61 29] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23] 35 103} -3 -Triggering 203 [43 41] -Trig2: 172 {172 [31] 79 123} -3 -Triggering 172 [31 41] -Trig2: 79 {79 [53] 22 40} -3 -Triggering 79 [53 31] -Trig2: 22 {22 [37] 53 69} -3 -Triggering 22 [37 31] -Trig2: 53 {53 [61] 0 142} -3 -Triggering 53 [61 31] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29] 35 103} -3 -Triggering 64 [47 43] -Trig2: 123 {123 [41] 40 107} -3 -Triggering 123 [41 43] -Trig2: 40 {40 [53] 69 124} -3 -Triggering 40 [53 41] -Trig2: 69 {69 [37] 142 0} -3 -Triggering 69 [37 41] -Trig2: 142 {142 [61] 0 35} -3 -Triggering 142 [61 37] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29 31 41] 35 103} -3 -Triggering 35 [2 61] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29 31 41 37] 35 103} -3 -Triggering 48 [59 47] -Trig2: 107 {107 [43] 124 15} -3 -Triggering 107 [43 47] -Trig2: 124 {124 [53] 0 145} -3 -Triggering 124 [53 43] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29 31 41 37 2] 35 103} -3 -Triggering 58 [67 59] -Trig2: 15 {15 [47] 145 188} -3 -Triggering 15 [47 59] -Trig2: 145 {145 [53] 103 128} -3 -Triggering 145 [53 47] -Trig2: 103 {103 [3] 50 129} -3 -Triggering 103 [3 47] -Trig2: 50 {50 [61] 0 127} -3 -Triggering 50 [61 3] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29 31 41 37 2 43] 35 103} -3 -Triggering 188 [71 59] -Trig2: 128 {128 [53] 129 182} -3 -Triggering 128 [53 59] -Trig2: 129 {129 [47] 127 49} -3 -Triggering 129 [47 53] -Trig2: 127 {127 [61] 0 11} -3 -Triggering 127 [61 47] -Trig2: 0 {0 [2 3 5 7 11 13 17 19 23 29 31 41 37 2 43 3] 35 103} -3 diff --git a/day10/problem b/day10/problem new file mode 100644 index 0000000..4cc466e --- /dev/null +++ b/day10/problem @@ -0,0 +1,70 @@ +Advent of Code + +--- Day 10: Balance Bots --- + + You come upon a factory in which many robots are zooming around handing small microchips to + each other. + + Upon closer examination, you notice that each bot only proceeds when it has two microchips, + and once it does, it gives each one to a different bot or puts it in a marked "output" bin. + Sometimes, bots take microchips from "input" bins, too. + + Inspecting one of the microchips, it seems like they each contain a single number; the bots + must use some logic to decide what to do with each chip. You access the local control computer + and download the bots' instructions (your puzzle input). + + Some of the instructions specify that a specific-valued microchip should be given to a + specific bot; the rest of the instructions indicate what a given bot should do with its + lower-value or higher-value chip. + + For example, consider the following instructions: + + value 5 goes to bot 2 + bot 2 gives low to bot 1 and high to bot 0 + value 3 goes to bot 1 + bot 1 gives low to output 1 and high to bot 0 + bot 0 gives low to output 2 and high to output 0 + value 2 goes to bot 2 + + • Initially, bot 1 starts with a value-3 chip, and bot 2 starts with a value-2 chip and a + value-5 chip. + • Because bot 2 has two microchips, it gives its lower one (2) to bot 1 and its higher one + (5) to bot 0. + • Then, bot 1 has two microchips; it puts the value-2 chip in output 1 and gives the value-3 + chip to bot 0. + • Finally, bot 0 has two microchips; it puts the 3 in output 2 and the 5 in output 0. + + In the end, output bin 0 contains a value-5 microchip, output bin 1 contains a value-2 + microchip, and output bin 2 contains a value-3 microchip. In this configuration, bot number 2 + is responsible for comparing value-5 microchips with value-2 microchips. + + Based on your instructions, what is the number of the bot that is responsible for comparing + value-61 microchips with value-17 microchips? + + Your puzzle answer was ______. + +--- Part Two --- + + What do you get if you multiply together the values of one chip in each of outputs 0, 1, and + 2? + + Your puzzle answer was _______. + +References + + Visible links + . http://adventofcode.com/ + . http://adventofcode.com/2016/about + . http://adventofcode.com/2016/support + . http://adventofcode.com/2016/events + . http://adventofcode.com/2016/settings + . http://adventofcode.com/2016/auth/logout + . http://adventofcode.com/2016 + . http://adventofcode.com/2016 + . http://adventofcode.com/2016/leaderboard + . http://adventofcode.com/2016/stats + . http://adventofcode.com/2016/sponsors + . http://adventofcode.com/2016/sponsors + . https://www.youtube.com/watch?v=JnkMyfQ5YfY&t=40 + . http://adventofcode.com/2016 + . http://adventofcode.com/2016/day/10/input