-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b5d084
commit 39c8f9c
Showing
1 changed file
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,75 @@ | ||
package day5 | ||
|
||
var ogOrg = map[int][]string{ | ||
1: {"N", "R", "G", "P"}, | ||
2: {"J", "T", "B", "L", "F", "G", "D", "C"}, | ||
3: {"M", "S", "V"}, | ||
4: {"L", "S", "R", "C", "Z", "P"}, | ||
5: {"P", "S", "L", "V", "C", "W", "D", "Q"}, | ||
6: {"C", "T", "N", "W", "D", "M", "S"}, | ||
7: {"H", "D", "G", "W", "P"}, | ||
8: {"Z", "L", "P", "H", "S", "C", "M", "V"}, | ||
9: {"R", "P", "F", "L", "W", "G", "Z"}, | ||
} | ||
|
||
func shift(src int, dst int, ogOrg map[int][]string) map[int][]string { | ||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
var inputOrganisation = func() map[int][]string { | ||
return map[int][]string{ | ||
1: {"N", "R", "G", "P"}, | ||
2: {"J", "T", "B", "L", "F", "G", "D", "C"}, | ||
3: {"M", "S", "V"}, | ||
4: {"L", "S", "R", "C", "Z", "P"}, | ||
5: {"P", "S", "L", "V", "C", "W", "D", "Q"}, | ||
6: {"C", "T", "N", "W", "D", "M", "S"}, | ||
7: {"H", "D", "G", "W", "P"}, | ||
8: {"Z", "L", "P", "H", "S", "C", "M", "V"}, | ||
9: {"R", "P", "F", "L", "W", "G", "Z"}, | ||
} | ||
} | ||
|
||
func shiftSingle(src, dst int, ogOrg map[int][]string) map[int][]string { | ||
item := ogOrg[src][len(ogOrg[src])-1] | ||
ogOrg[src] = ogOrg[src][:len(ogOrg[src])-2] | ||
ogOrg[src] = ogOrg[src][:len(ogOrg[src])-1] | ||
ogOrg[dst] = append(ogOrg[dst], item) | ||
return ogOrg | ||
} | ||
|
||
func shiftMulti(src, dst, numCrates int, ogOrg map[int][]string) map[int][]string { | ||
items := ogOrg[src][len(ogOrg[src])-numCrates : len(ogOrg[src])] | ||
ogOrg[src] = ogOrg[src][:len(ogOrg[src])-numCrates] | ||
ogOrg[dst] = append(ogOrg[dst], items...) | ||
return ogOrg | ||
} | ||
|
||
func parseInputLine(input string) (int, int, int) { | ||
var count, from, to int | ||
fmt.Sscanf(input, "move %d from %d to %d", &count, &from, &to) | ||
return count, from, to | ||
} | ||
|
||
func giveTopItems(ogOrg map[int][]string) string { | ||
keys := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
ans := "" | ||
for _, element := range keys { | ||
ans += ogOrg[element][len(ogOrg[element])-1] | ||
} | ||
return ans | ||
} | ||
|
||
func Day5Logic() (string, string) { | ||
return day5LogicPart1(), day5LogicPart2() | ||
} | ||
|
||
func day5LogicPart1() string { | ||
return "" | ||
inputs := strings.Split(input5, "\n") | ||
structure := inputOrganisation() | ||
for _, move := range inputs { | ||
count, from, to := parseInputLine(move) | ||
for i := 0; i < count; i++ { | ||
structure = shiftSingle(from, to, structure) | ||
} | ||
} | ||
return giveTopItems(structure) | ||
} | ||
|
||
func day5LogicPart2() string { | ||
return "" | ||
inputs := strings.Split(input5, "\n") | ||
structure := inputOrganisation() | ||
for _, move := range inputs { | ||
count, from, to := parseInputLine(move) | ||
structure = shiftMulti(from, to, count, structure) | ||
} | ||
return giveTopItems(structure) | ||
} |