day07 refactor start

This commit is contained in:
alexchao26
2020-08-03 09:43:06 -04:00
parent 2c04472991
commit b16265925a
3 changed files with 16 additions and 15 deletions
+1
View File
@@ -12,3 +12,4 @@ Day | Name | Type of Algo & Notes
4 | Secure Container | - May appear math-y, but it's really a string manipulation problem 4 | Secure Container | - May appear math-y, but it's really a string manipulation problem
5 | Sunny with a Chance of Asteroids | - Yay more Intcode!........ <br> - This gave me fits... <br> - Good application for recursion (in my opinion) 5 | Sunny with a Chance of Asteroids | - Yay more Intcode!........ <br> - This gave me fits... <br> - Good application for recursion (in my opinion)
6 | Universal Orbit Map | - __Tree traversal__ and depth calculations. It's not quite a Graph, but it has a __directed graph__ algo feel too 6 | Universal Orbit Map | - __Tree traversal__ and depth calculations. It's not quite a Graph, but it has a __directed graph__ algo feel too
7 | Amplification Circuit | - More Intcode... Piping together multiple Intcode computers 😳😳😳
+1
View File
@@ -0,0 +1 @@
3,8,1001,8,10,8,105,1,0,0,21,42,55,64,77,94,175,256,337,418,99999,3,9,102,4,9,9,1001,9,5,9,102,2,9,9,101,3,9,9,4,9,99,3,9,102,2,9,9,101,5,9,9,4,9,99,3,9,1002,9,4,9,4,9,99,3,9,102,4,9,9,101,5,9,9,4,9,99,3,9,102,5,9,9,1001,9,3,9,1002,9,5,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,99
+14 -15
View File
@@ -2,26 +2,25 @@ package main
import ( import (
"fmt" "fmt"
"strconv"
"strings"
"./intcode" "adventofcode/day07/part1/intcode"
"./permutations" "adventofcode/day07/part1/permutations"
"adventofcode/util"
) )
// input to first amp = 0
// output of each amp is input of next amp
// final output is from amp #5 / E to thrusters
func main() { func main() {
// input to first amp = 0 readInput := util.ReadFile("../input.txt")
// output of each amp is input of next amp strSplit := strings.Split(readInput, ",")
// final output is from amp #5 / E to thrusters
input := []int{3, 8, 1001, 8, 10, 8, 105, 1, 0, 0, 21, 42, 55, 64, 77, 94, 175, 256, 337, 418, 99999, 3, 9, 102, 4, 9, 9, 1001, 9, 5, 9, 102, 2, 9, 9, 101, 3, 9, 9, 4, 9, 99, 3, 9, 102, 2, 9, 9, 101, 5, 9, 9, 4, 9, 99, 3, 9, 1002, 9, 4, 9, 4, 9, 99, 3, 9, 102, 4, 9, 9, 101, 5, 9, 9, 4, 9, 99, 3, 9, 102, 5, 9, 9, 1001, 9, 3, 9, 1002, 9, 5, 9, 4, 9, 99, 3, 9, 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, 2, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 102, 2, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 101, 1, 9, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1002, 9, 2, 9, 4, 9, 3, 9, 1001, 9, 1, 9, 4, 9, 99} input := make([]int, len(strSplit))
for i, v := range strSplit {
// input := []int{3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0} input[i], _ = strconv.Atoi(v)
// void return value }
// phase sequence = 1, initial input = 0
// fmt.Println("output of A amp run", intcode.RunDiagnostics(input, 4, 0)) // outputs 3
// fmt.Println("output of A amp run", intcode.RunDiagnostics(input, 3, 4)) // outputs 43
// fmt.Println("output of A amp run", intcode.RunDiagnostics(input, 2, 43)) // outputs 432...
// fmt.Println("output of A amp run", intcode.RunDiagnostics(input, 1, 432)) // outputs 4321
// fmt.Println("output of A amp run", intcode.RunDiagnostics(input, 0, 4321)) // outputs 43210
// create all permutations of 0, 1, 2, 3, 4 // create all permutations of 0, 1, 2, 3, 4
perms := permutations.CreatePermutations() perms := permutations.CreatePermutations()