mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 20:53:30 +02:00
2020-day15 so close :( 600/209. difficult to just understand the prompt. brute forced a dictionary for pt 2
2017-day10 weird fake hashing, xor and hexadecimals
This commit is contained in:
+37
-22
@@ -15,32 +15,47 @@ func main() {
|
||||
flag.Parse()
|
||||
fmt.Println("Running part", part)
|
||||
|
||||
var ans int
|
||||
if part == 1 {
|
||||
ans := part1(util.ReadFile("./input.txt"))
|
||||
util.CopyToClipboard(fmt.Sprintf("%v", ans))
|
||||
fmt.Println("Output:", ans)
|
||||
ans = rambunctiousRecitation(util.ReadFile("./input.txt"), 2020)
|
||||
} else {
|
||||
ans := part2(util.ReadFile("./input.txt"))
|
||||
util.CopyToClipboard(fmt.Sprintf("%v", ans))
|
||||
fmt.Println("Output:", ans)
|
||||
// brute force, takes ~5seconds to run
|
||||
ans = rambunctiousRecitation(util.ReadFile("./input.txt"), 30000000)
|
||||
}
|
||||
fmt.Println("Output:", ans)
|
||||
}
|
||||
|
||||
func part1(input string) int {
|
||||
parsed := parseInput(input)
|
||||
_ = parsed
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func part2(input string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func parseInput(input string) (ans []int) {
|
||||
lines := strings.Split(input, "\n")
|
||||
for _, l := range lines {
|
||||
ans = append(ans, mathutil.StrToInt(l))
|
||||
func rambunctiousRecitation(input string, turnToReturn int) int {
|
||||
var startingNums []int
|
||||
for _, num := range strings.Split(input, ",") {
|
||||
startingNums = append(startingNums, mathutil.StrToInt(num))
|
||||
}
|
||||
return ans
|
||||
|
||||
said := map[int][]int{}
|
||||
var numSaidLast int
|
||||
// populate the starting map with the numbers from the input
|
||||
for i, num := range startingNums {
|
||||
said[num] = append(said[num], i+1)
|
||||
numSaidLast = num
|
||||
}
|
||||
|
||||
// then picking up from the next turn (len of input), continue until the
|
||||
// desired turn is reached
|
||||
for i := len(startingNums); i <= turnToReturn; i++ {
|
||||
indexSlice := said[numSaidLast]
|
||||
// if the length of the slice of incides is 1, that means it was only
|
||||
// called once. Say zero, add to the zero slice of indices
|
||||
if len(indexSlice) == 1 {
|
||||
numSaidLast = 0
|
||||
said[0] = append(said[0], i)
|
||||
} else {
|
||||
// otherwise determine the diff between the last 2 times it was said
|
||||
length := len(indexSlice)
|
||||
numSaidLast = indexSlice[length-1] - indexSlice[length-2]
|
||||
// add this index i to the indices slice for the number that is said
|
||||
said[numSaidLast] = append(said[numSaidLast], i)
|
||||
}
|
||||
}
|
||||
|
||||
return numSaidLast
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user