2023 Day 17 Complete

This commit is contained in:
2023-12-17 10:52:08 -06:00
parent a34f05d1af
commit d64a18280f
16 changed files with 517 additions and 131 deletions

View File

@@ -4,13 +4,13 @@ import (
"fmt"
"strings"
"../../"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
pw := "fbgdceah" // Part 2 Puzzle input
input := aoc.StdinToStringSlice()
if aoc.ArgIsSet("-1") {
input := h.StdinToStringSlice()
if h.ArgIsSet("-1") {
pw = "abcdefgh" // Part 1 Puzzle input
pw = scramblePassword(pw, input)
fmt.Println(scramblePassword(pw, input))
@@ -23,7 +23,7 @@ func unscramblePassword(pw string, inst []string) string {
// Brute force it.
// Just get all permutations of the runes and return the one
// for which the instructions return the input
tst := aoc.StringPermutations(pw)
tst := h.StringPermutations(pw)
for i := range tst {
if scramblePassword(tst[i], inst) == pw {
return tst[i]
@@ -37,15 +37,15 @@ func scramblePassword(pw string, inst []string) string {
pts := strings.Fields(inst[i])
switch pts[0] + " " + pts[1] {
case "swap position":
pw = swapPos(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[5]))
pw = swapPos(pw, h.Atoi(pts[2]), h.Atoi(pts[5]))
case "swap letter":
pw = swapLetter(pw, pts[2], pts[5])
case "reverse positions":
pw = reverse(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[4]))
pw = reverse(pw, h.Atoi(pts[2]), h.Atoi(pts[4]))
case "rotate left":
pw = rotate(pw, aoc.Atoi(pts[2])*-1)
pw = rotate(pw, h.Atoi(pts[2])*-1)
case "rotate right":
pw = rotate(pw, aoc.Atoi(pts[2]))
pw = rotate(pw, h.Atoi(pts[2]))
case "rotate based":
rotIdx := strings.Index(pw, pts[6])
if rotIdx >= 4 {
@@ -54,7 +54,7 @@ func scramblePassword(pw string, inst []string) string {
rotIdx++
pw = rotate(pw, rotIdx)
case "move position":
pw = move(pw, aoc.Atoi(pts[2]), aoc.Atoi(pts[5]))
pw = move(pw, h.Atoi(pts[2]), h.Atoi(pts[5]))
}
}
return pw