Compare commits

..

No commits in common. "e0f1c3d9bcef754a7384c06d55e8ae8a244c39a9" and "2fdf520e2b7a49bc02939e7e859e532f2c73d26a" have entirely different histories.

6 changed files with 0 additions and 100 deletions

View File

@ -33,6 +33,3 @@ var Day09Data string
//go:embed day_10/data.txt
var Day10Data string
//go:embed day_11/data.txt
var Day11Data string

View File

@ -1 +0,0 @@
64554 35 906 6 6960985 5755 975820 0

View File

@ -1 +0,0 @@
125 17

View File

@ -1,73 +0,0 @@
package day_11
import (
"strconv"
"strings"
)
type Stones map[uint64]uint64
// task:https://adventofcode.com/2024/day/11
func SolveBasic(input string) int {
stones := load(input)
for i := 0; i < 25; i++ {
stones = blink(stones)
}
sum := uint64(0)
for _, st := range stones {
sum += st
}
return int(sum)
}
// task:https://adventofcode.com/2024/day/11#part2
func SolveComplex(input string) int {
stones := load(input)
for i := 0; i < 75; i++ {
stones = blink(stones)
}
sum := uint64(0)
for _, st := range stones {
sum += st
}
return int(sum)
}
func blink(before Stones) Stones {
after := Stones{}
for stone, count := range before {
if stone == 0 {
after[1] += count
} else if val := fromUint(stone); len(val)%2 == 0 {
after[parseUint(val[:len(val)/2])] += count
after[parseUint(val[len(val)/2:])] += count
} else {
after[stone*2024] += count
}
}
return after
}
func fromUint(stone uint64) string {
return strconv.FormatUint(stone, 10)
}
func load(input string) Stones {
stones := Stones{}
for _, substring := range strings.Split(input, " ") {
stones[parseUint(substring)]++
}
return stones
}
func parseUint(substring string) uint64 {
if val, err := strconv.ParseUint(substring, 10, 64); err == nil {
return val
} else {
panic(err)
}
}

View File

@ -1,17 +0,0 @@
package day_11_test
import (
"advent_of_code_2024/day_11"
_ "embed"
"testing"
)
//go:embed example_data.txt
var ExampleData string
func TestBasicSolutionExample(t *testing.T) {
result := day_11.SolveBasic(ExampleData)
if result != 55312 {
t.Fatalf("Expected 55312 received %d", result)
}
}

View File

@ -11,7 +11,6 @@ import (
"advent_of_code_2024/day_08"
"advent_of_code_2024/day_09"
"advent_of_code_2024/day_10"
"advent_of_code_2024/day_11"
_ "embed"
"fmt"
"os"
@ -61,10 +60,6 @@ func main() {
fmt.Printf("Day 10. Basic: %d\n", day_10.SolveBasic(Day10Data)) //
case "10-complex":
fmt.Printf("Day 10. Complex: %d\n", day_10.SolveComplex(Day10Data)) //
case "11-basic":
fmt.Printf("Day 11. Basic: %d\n", day_11.SolveBasic(Day11Data)) //
case "11-complex":
fmt.Printf("Day 11. Complex: %d\n", day_11.SolveComplex(Day11Data)) //
}
}