From b16265925a4ce30b8c5663fd68b8c2de041a57b6 Mon Sep 17 00:00:00 2001 From: alexchao26 Date: Mon, 3 Aug 2020 09:43:06 -0400 Subject: [PATCH] day07 refactor start --- README.md | 1 + day07/input.txt | 1 + day07/part1/main.go | 29 ++++++++++++++--------------- 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 day07/input.txt diff --git a/README.md b/README.md index a868ec8..7f61ebb 100644 --- a/README.md +++ b/README.md @@ -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 5 | Sunny with a Chance of Asteroids | - Yay more Intcode!........
- This gave me fits...
- 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 +7 | Amplification Circuit | - More Intcode... Piping together multiple Intcode computers 😳😳😳 diff --git a/day07/input.txt b/day07/input.txt new file mode 100644 index 0000000..a4594a3 --- /dev/null +++ b/day07/input.txt @@ -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 diff --git a/day07/part1/main.go b/day07/part1/main.go index a36a597..b6d8a36 100644 --- a/day07/part1/main.go +++ b/day07/part1/main.go @@ -2,26 +2,25 @@ package main import ( "fmt" + "strconv" + "strings" - "./intcode" - "./permutations" + "adventofcode/day07/part1/intcode" + "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() { - // input to first amp = 0 - // output of each amp is input of next amp - // final output is from amp #5 / E to thrusters + readInput := util.ReadFile("../input.txt") + strSplit := strings.Split(readInput, ",") - 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, 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 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} - - // input := []int{3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0} - // 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 + input := make([]int, len(strSplit)) + for i, v := range strSplit { + input[i], _ = strconv.Atoi(v) + } // create all permutations of 0, 1, 2, 3, 4 perms := permutations.CreatePermutations()