diff --git a/2024/go/day06/day06.go b/2024/go/day06/day06.go new file mode 100644 index 0000000..d0388f4 --- /dev/null +++ b/2024/go/day06/day06.go @@ -0,0 +1,291 @@ +package day06 + +import ( + "adventofcode2024/utils/grid2d" + "adventofcode2024/utils/inputs" + "fmt" + _ "strings" +) + +type Direction int + +const ( + _ Direction = iota + Up + Down + Left + Right +) + +type Pos struct { + x int + y int +} +type Loc struct { + dir Direction + pos Pos + count int +} + +type Point struct { + dirs []Direction + display string +} + +func (d Direction) String() string { + return [...]string{"-", "Up", "Down", "Left", "Right"}[d] +} + +func (l Loc) String() string { + return fmt.Sprintf("Direction: %s, Position: %d %d", l.dir, l.pos.x, l.pos.y) +} + +func Part1(input string) int { + var loc Loc + grid := inputs.ToGrid2D(input, "\n", "", "", func(c string) string { return c }) + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + if grid.Get(x, y) == "^" { + loc = Loc{dir: Up, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y) == "v" { + loc = Loc{dir: Down, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y) == ">" { + loc = Loc{dir: Right, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y) == "<" { + loc = Loc{dir: Left, pos: Pos{x: x, y: y}} + } + } + } + fmt.Println(grid.Matrix()) + fmt.Printf("%v\n", loc) + grid.Set(loc.pos.x, loc.pos.y, "X") + loc.count = 1 + move1(&loc, grid) + return loc.count +} + +func Part2(input string) int { + var loc Loc + grid := inputs.ToGrid2D(input, "\n", "", Point{}, func(c string) Point { return Point{dirs: make([]Direction, 1), display: c} }) + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + if grid.Get(x, y).display == "^" { + loc = Loc{dir: Up, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == "v" { + loc = Loc{dir: Down, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == ">" { + loc = Loc{dir: Right, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == "<" { + loc = Loc{dir: Left, pos: Pos{x: x, y: y}} + } + } + } + fmt.Println(grid.Matrix()) + fmt.Printf("%v\n", loc) + point := grid.Get(loc.pos.x, loc.pos.y) + grid.Set(loc.pos.x, loc.pos.y, Point{dirs: append(point.dirs, Up), display: "X"}) + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + grid = inputs.ToGrid2D(input, "\n", "", Point{}, func(c string) Point { return Point{dirs: make([]Direction, 1), display: c} }) + p := grid.Get(x, y) + if p.display == "." { + grid.Set(x, y, Point{dirs: p.dirs, display: "#"}) + l := loc + if isLoop(&l, grid) { + loc.count++ + } + grid.Set(x, y, Point{dirs: p.dirs, display: "."}) + } + } + } + return loc.count +} + +func isLoop(loc *Loc, grid *grid2d.Grid[Point]) bool { + for { + _, _, err := move2(loc, grid) + if err != nil { return false } + if contains(loc.dir, grid.Get(loc.pos.x, loc.pos.y)) { + return true + } else { + p := grid.Get(loc.pos.x, loc.pos.y) + grid.Set(loc.pos.x, loc.pos.y, Point{dirs: append(p.dirs, loc.dir), display: "X"}) + } + } +} + +func Part2b(input string) int { + var loc Loc + grid := inputs.ToGrid2D(input, "\n", "", Point{}, func(c string) Point { return Point{dirs: make([]Direction, 1), display: c} }) + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + if grid.Get(x, y).display == "^" { + loc = Loc{dir: Up, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == "v" { + loc = Loc{dir: Down, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == ">" { + loc = Loc{dir: Right, pos: Pos{x: x, y: y}} + } + if grid.Get(x, y).display == "<" { + loc = Loc{dir: Left, pos: Pos{x: x, y: y}} + } + } + } + fmt.Println(grid.Matrix()) + fmt.Printf("%v\n", loc) + point := grid.Get(loc.pos.x, loc.pos.y) + grid.Set(loc.pos.x, loc.pos.y, Point{dirs: append(point.dirs, Up), display: "X"}) + loc.count = 0 + for { + _, _, err := move2(&loc, grid) + if err != nil { + break + } + if contains(loc.dir, grid.Get(loc.pos.x, loc.pos.y)) { + loc.count++ + break + } + } + return loc.count +} + +func move1(loc *Loc, grid *grid2d.Grid[string]) int { + return -1 +} + +func move2(loc *Loc, grid *grid2d.Grid[Point]) (int, int, error) { + x, y, err := doMove(loc, grid) + if err != nil { + return x, y, err + } + if x == loc.pos.x && y == loc.pos.y { + move2(loc, grid) + } + return x, y, nil +} + +func canBlock(loc *Loc, point Point) bool { + val := false + switch loc.dir { + case Up: + if contains(Right, point) { + val = true + } + case Down: + if contains(Left, point) { + val = true + } + case Left: + if contains(Up, point) { + val = true + } + case Right: + if contains(Down, point) { + val = true + } + } + return val +} + +func contains(v Direction, point Point) bool { + for _, d := range point.dirs { + if d == v { + return true + } + } + return false +} + +func checkMove(loc *Loc, grid *grid2d.Grid[string]) bool { + switch loc.dir { + case Down: + if loc.pos.y+1 >= grid.SizeY() { + return false + } + if grid.Get(loc.pos.x, loc.pos.y+1) == "#" { + loc.dir = Left + } else { + loc.pos.y++ + } + case Up: + if loc.pos.y-1 < 0 { + return false + } + if grid.Get(loc.pos.x, loc.pos.y-1) == "#" { + loc.dir = Right + } else { + loc.pos.y-- + } + case Left: + if loc.pos.x-1 < 0 { + return false + } + if grid.Get(loc.pos.x-1, loc.pos.y) == "#" { + loc.dir = Up + } else { + loc.pos.x-- + } + case Right: + if loc.pos.x+1 >= grid.SizeX() { + return false + } + if grid.Get(loc.pos.x+1, loc.pos.y) == "#" { + loc.dir = Down + } else { + loc.pos.x++ + } + } + return true +} + +func doMove(loc *Loc, grid *grid2d.Grid[Point]) (int, int, error) { + x := loc.pos.x + y := loc.pos.y + switch loc.dir { + case Down: + if loc.pos.y+1 >= grid.SizeY() { + return x, y, fmt.Errorf("outside") + } + if grid.Get(loc.pos.x, loc.pos.y+1).display == "#" { + loc.dir = Left + } else { + loc.pos.y++ + } + case Up: + if loc.pos.y-1 < 0 { + return x, y, fmt.Errorf("outside") + } + if grid.Get(loc.pos.x, loc.pos.y-1).display == "#" { + loc.dir = Right + } else { + loc.pos.y-- + } + case Left: + if loc.pos.x-1 < 0 { + return x, y, fmt.Errorf("outside") + } + if grid.Get(loc.pos.x-1, loc.pos.y).display == "#" { + loc.dir = Up + } else { + loc.pos.x-- + } + case Right: + if loc.pos.x+1 >= grid.SizeX() { + return x, y, fmt.Errorf("outside") + } + if grid.Get(loc.pos.x+1, loc.pos.y).display == "#" { + loc.dir = Down + } else { + loc.pos.x++ + } + } + return x, y, nil +} diff --git a/2024/go/day06/day06_test.go b/2024/go/day06/day06_test.go new file mode 100644 index 0000000..8d3a4c3 --- /dev/null +++ b/2024/go/day06/day06_test.go @@ -0,0 +1,35 @@ +package day06 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPart1(t *testing.T) { + r := Part1(`....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#...`) + require.Equal(t, 41, r) +} + +func TestPart2(t *testing.T) { + r := Part2(`....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#...`) + require.Equal(t, 6, r) +} diff --git a/2024/go/day06/input.txt b/2024/go/day06/input.txt new file mode 100644 index 0000000..86fc58b --- /dev/null +++ b/2024/go/day06/input.txt @@ -0,0 +1,130 @@ +...#..................#...................#......................#..............................#.............................#... +....#.......................#........#.#..............##...........#.....#..........#..........................#.................. +.............#........................................................................#.........#.#..#..#..........#.............. +..........#.......#..........#..................#........##...................#..............#.................................... +....................#..........................................................#..#.....................................#......... +....#............................#..............................................#.....................#..........##....#.......... +.......#.............#......................................................................#.............#.........#............. +....###......................#....#...........#.....#................................#..........................#................. +..........#..#...........#..#........................................................#.....#...........#................#......... +..#....#......#....#....#...................................................................#..................................... +....................#............#............................................#......#....#...............................#....... +..........#.......#.........#.......#............................................................................................. +.......#...#.......................................#...................#.......................................................... +.......#........#............................#.....#.......#..............................................#..................#...# +.....................#.................................#................#...#...............#.....#.#..........................#.. +.....#..........................................#......................#.............##..............................#........#... +.....#......#.........................#..........................#..........................................................#..#.. +.#......#.............#......#.................................................#.....#...................##......#................ +.............................................................................##................................................... +........................................#.......................................#........#.............................#.#.......# +...........#.....................................#.............................#......#......#..#....................#..#......... +.............................................#.......................#..................##....#.....#............................. +........................#..............................................................#.......................................... +#..............#.........................#........#...#...............#..............#..................#....................##... +...#...#.............................#.......#................................................#........................#....#..... +.....#.........................#..#.......................#..........#.....................#..................#.#.....#........... +..................#........#..#.......#...................................................................................#....#.. +..#...#...............................................#.#..#........................................................#....#......#. +...............#...............#..........................#............................#..........#.............#................. +............#.....#........#.........................................................#........#........#.....#........#......#.... +............................#.........#....#........#.....#...#.............#.................................#................... +........#..................#....#..........................................................#.#.#.................................. +....................................................................................................................#............. +#............#.............#..................#......................................................................#............ +...............................#....#..........#...........##........................................................#.........#.# +................#.........................................#.................................................#........#............ +..............................................#............#................#........#........................#................... +..................#.........#..........................#.............#...............#............#....................#.......... +........................#...#...............................................#..............#.....#.....................#.......... +...........#.......................................#..............................#..................#....#...##.................. +#...............#..................#...............................#...............................#.....................#........ +.............#...............................................................##................................................... +.................#.............#.......................#...#............#.#....#................................#...........#..... +#......#......#..................................##.................#.#...............................#........................... +.#...............#..........#...............................................#...#..........#..........#........................... +.....................................#............................#....#.............................................#...#........ +......#...#.............#.#....................#.........#..........##.................................#..........#..........#.... +.............................#..................#....#..............##.......................#.#.....#........#................... +.................................................#.#......................................................#................#...... +......................................#..........................................#......#......................................... +#....................#...........................................................#..................#............................. +.....#.........#...................................................#....#.#....#.#.........#...................................... +........#..........#......#.............#................................#.....#................#................................. +...........#................................#...........#..........#......#.............#........................#................ +.......#...............#....................#..#................................................#................................. +.....................#.........#..#............#..........#...........#...........#...............................#............... +................#...#........#...........#..........................................................#..#...................#...... +.........................................................#.....................#...#......................#.#....................# +................#......#....#.#..............#............#....................................................................... +..........#.....................................#......................................................................#.......... +#......................................#.......#.....##..#.....................#.........#.......#................................ +........#...#..............#....................#................................#..............................................#. +.##............................................................................#......#................................#.......... +.#........................#..............#..............................................#........#.....#.......#.................. +#......................................#.....................#...................................................................# +............................#.....#.....#............#...............#...#.......#.........#...................................... +.#.........................#.......................#.........#.......#.................#............................#..#.......... +.............................................................................................................#........##.......... +...........#...#...#.#................#.....................................#........#............................................ +......#.......................#..........#.......#................................................................#............... +........#....#........#..................#....##.....#............#..............................#...........#...........#..#..... +..................................#...............................................................................#............... +.....................#.#.......................#....................................#............................................. +........................................................................................#.........#.................#.........#... +..........................#..........#....#..........................................#.......................#............#.#..... +...............................................#.#....#...............................#...................#......................# +.....#...........#........#.#.......#.............................#..................#............................................ +...............#.........................................................#....................#.................#.............#... +#....................................##..........#................................................................#............... +...............#.................#...#..............#......................................................#..............#....... +...................#......#.............................................#......................................................#.# +..#.............#.......#......#....#..#..#....................................................................................... +.........#....................................................#.....................................#..............#.............. +..............#..............#................................................................#.......................#........... +..........................#.................#.......................................................##...................#.#...... +...............#..#...................................................................................................#.......###. +...#.....................#..#........#..........#..................................................................##............. +.................#.......................................###..............#.........................#............................. +...#.....................................................#.......#..........................#................#..#................. +...................................................#..................#.........................................................#. +.....#.............#...................#...................#.....................................#................................ +.....................#.........................#......#........................................................................... +...........#...............#......#.....##...#...#.............................................#........#.#...............#...#... +..............#..............##...........#.......................#..#.^.......................................................... +...................#.............................................................................................................. +..................#.......#..........#.......#..................#..........#...................................#.................. +..............................................................................................#..................................# +......................................................#................#......................#................................... +..............#.........#..............................#.....................#......................#............................. +#................#.........#................#.............................#......................#..#...#..............#.......... +.#..#........#................#...............#..................#........#.....................#............#........#........... +.....................................................#.#.........#......................#.............................#........#.. +......................#.....................#..#......#..........................#............................#......#............ +......................#.........................#..#..................................#.......................#..............#.... +..........................#..................#.............#......................................................#............... +..........................#....#........................................#..#...#....#.................#........................... +.......#...........#.......................#............##........#....................................................#.......... +#..........................................................................#...........#.......................................... +............................................................#.................#..#........................................##...... +..#...............................................#....#.................................................##.....#...##.....#...... +...#.....##..............................#.........................................................#............#................. +.....#....##............................#....##..........#...#.................................................................... +..................................................#..........................#.........##.......#.......................#......... +.........#.....#..........#........#........................#.##..#............#.......................................#.......... +.....#...............#.......#..........#.#..........#.....................#.....................................#.....#.......... +....#......#............................................................................................##...#.#.#.........#...... +...........#........................#.....#....................#..................#.#........#.................................... +....................................................#................#.#................................................#......... +..........#..............#.......................#.................#...................................#.............#.#......##.. +................##......................................................#.................#.......#.#....................#........ +................#......................................................#.............##...............#.....#......#.......#...... +..............................#............................#..........#...........#............................................... +.......#.............#....................................................................#..............................#.#...... +...#.....................#.#...............................................................#...#..#....#.......................... +....#.........##......#..............................................................................#..................#......... +....#..........................................#......#...................#........##............#................................ +..#.......#......#............#........#...#.#...........................#.......#................................................ +..........................#...#....................#...............#...#......#.#...#...#...............#.#.#..................... +....##.#....................................................................#...#.....##........................#.##.............. +.............................................#.................................................................................... diff --git a/2024/go/day07/day07.go b/2024/go/day07/day07.go new file mode 100644 index 0000000..6f4c336 --- /dev/null +++ b/2024/go/day07/day07.go @@ -0,0 +1,140 @@ +package day07 + +import ( + "adventofcode2024/utils" + "fmt" + "strconv" + "strings" +) + +type Op int + +const ( + Add Op = iota + Mul + Conc +) + +func Part1(input string) int { + val := 0 + lines := strings.Split(input, "\n") + for _, line := range lines { + parts := strings.Split(line, ":") + result := utils.MustAtoi(parts[0]) + numStrings := strings.Fields(parts[1]) + var numbers []int + for _, numStr := range numStrings { + num := utils.MustAtoi(numStr) + numbers = append(numbers, num) + } + bitmask := 1 << (len(numbers) - 1) + for i := 0; i < bitmask; i++ { + calc := 0 + switch isNthBitSet(i, 0) { + case true: + calc = numbers[0] + numbers[1] + case false: + calc = numbers[0] * numbers[1] + } + + for n := 1; n < len(numbers)-1; n++ { + switch isNthBitSet(i, n) { + case true: + calc = calc + numbers[n+1] + case false: + calc = calc * numbers[n+1] + } + } + if calc == result { + fmt.Printf("result: %v numbers:%v count: %d\n", result, numbers, bitmask) + val += result + break + } + } + } + return val +} + +func Part2(input string) int { + val := 0 + lines := strings.Split(input, "\n") + for _, line := range lines { + parts := strings.Split(line, ":") + result := utils.MustAtoi(parts[0]) + numStrings := strings.Fields(parts[1]) + var numbers []int + for _, numStr := range numStrings { + num := utils.MustAtoi(numStr) + numbers = append(numbers, num) + } + operations := []Op{Add, Mul, Conc} + results := [][]Op{} + generatePermutations(operations, len(numbers)-1, []Op{}, &results) + for _, op := range results { + calc := 0 + switch op[0] { + case Add: + calc = numbers[0] + numbers[1] + case Mul: + calc = numbers[0] * numbers[1] + case Conc: + calc = concat(numbers[0], numbers[1]) + } + + for n := 1; n < len(numbers)-1; n++ { + switch op[n] { + case Add: + calc = calc + numbers[n+1] + case Mul: + calc = calc * numbers[n+1] + case Conc: + calc = concat(calc, numbers[n+1]) + } + } + if calc == result { + fmt.Printf("result: %v numbers:%v\n", result, numbers) + val += result + break + } + } + } + return val +} + +func isNthBitSet(num, n int) bool { + return num&(1< 0 { + antinodes++ + } + } + } + return antinodes +} + +func Part2(input string) int { + grid := inputs.ToGrid2D(input, "\n", "", pt{display: '.'}, func(c string) pt { return pt{display: rune(c[0]), paired: make(map[loc]pt), visited: make(map[rune]bool)}}) + for x1 := 0; x1 < grid.SizeX(); x1++ { + for y1 := 0; y1 < grid.SizeY(); y1++ { + pt1 := grid.Get(x1, y1) + if pt1.display != '.' { + for x2 := 0; x2 < grid.SizeX(); x2++ { + for y2 := 0; y2 < grid.SizeY(); y2++ { + pt2 := grid.Get(x2, y2) + if x1 != x2 && y1 != y2 && pt1.display == pt2.display && !isPaired(x1, y1, pt1, pt2) { + pt1.paired[loc{x: x2, y: y2}] = pt2 + pt2.paired[loc{x: x1, y: y1}] = pt1 + pt1.antinodes++ + pt2.antinodes++ + grid.Set(x1, y1, pt1) + grid.Set(x2, y2, pt2) + } + } + } + } + } + } + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + pt1 := grid.Get(x, y) + if pt1.display != '.' { + for ploc := range pt1.paired { + addAntiNodes_p2(pt1.display, x, y, ploc.x, ploc.y, grid) + } + } + } + } + antinodes := 0 + fmt.Printf("%v\n", grid.StringWithFormatter(formatter)) + for x := 0; x < grid.SizeX(); x++ { + for y := 0; y < grid.SizeY(); y++ { + pt := grid.Get(x, y) + if pt.antinodes > 0 { + antinodes++ + } else { + if pt.display != '.' { antinodes++ } + } + } + } + return antinodes +} + +func formatter(p pt, x int, y int) string { + if p.antinodes > 0 { + return "#" + } + return "." +} + +func isPaired(x int, y int, p1 pt, pt2 pt) bool { + return p1.paired[loc{x: x, y: y}].display == pt2.display +} + +func addAntiNodes(x1 int, y1 int, x2 int, y2 int, grid *grid2d.Grid[pt]) { + px1, py1, px2, py2 := offsetPoints(x1, y1, x2, y2) + + if px1 < 0 || px1 >= grid.SizeX() || py1 < 0 || py1 >= grid.SizeY() { + return + } + pt1 := grid.Get(px1, py1) + pt1.antinodes++ + grid.Set(px1, py1, pt1) + if px2 < 0 || px2 >= grid.SizeX() || py2 < 0 || py2 >= grid.SizeY() { + return + } + pt2 := grid.Get(px2, py2) + pt2.antinodes++ + grid.Set(px2, py2, pt2) +} + +func addAntiNodes_p2(frequency rune, x1 int, y1 int, x2 int, y2 int, grid *grid2d.Grid[pt]) { + px1, py1, px2, py2 := offsetPoints(x1, y1, x2, y2) + if !(px1 < 0 || px1 >= grid.SizeX() || py1 < 0 || py1 >= grid.SizeY()) { + pt1 := grid.Get(px1, py1) + if !pt1.visited[frequency] { + pt1.antinodes++ + pt1.visited[frequency] = true + grid.Set(px1, py1, pt1) + addAntiNodes_p2(frequency, x1, y1, px1, py1, grid) + } + } + if !(px2 < 0 || px2 >= grid.SizeX() || py2 < 0 || py2 >= grid.SizeY()) { + pt2 := grid.Get(px2, py2) + if !pt2.visited[frequency] { + pt2.antinodes++ + pt2.visited[frequency] = true + grid.Set(px2, py2, pt2) + addAntiNodes_p2(frequency, x2, y2, px2, py2, grid) + } + } +} + +// Function to calculate two points symmetrically placed above and below the line +func offsetPoints(x1, y1, x2, y2 int) (int, int, int, int) { + dx := x1 - x2 + dy := y1 - y2 + + p1x := x1 + dx + p1y := y1 + dy + p2x := x2 - dx + p2y := y2 - dy + return p1x, p1y, p2x, p2y +} diff --git a/2024/go/day08/day08_test.go b/2024/go/day08/day08_test.go new file mode 100644 index 0000000..7ed15be --- /dev/null +++ b/2024/go/day08/day08_test.go @@ -0,0 +1,39 @@ +package day08 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPart1(t *testing.T) { + r := Part1(`............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............`) + require.Equal(t, 14, r) +} + +func TestPart2(t *testing.T) { + r := Part2(`............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............`) + require.Equal(t, 34, r) +} diff --git a/2024/go/day08/input.txt b/2024/go/day08/input.txt new file mode 100644 index 0000000..701cc7a --- /dev/null +++ b/2024/go/day08/input.txt @@ -0,0 +1,50 @@ +.....y..........................p................r +........I......................................... +......................4.s......................... +..........4....................................... +....y............................................. +......................................p.........r. +..........0..s......N..................1.....p.... +..y........4.......................p.............. +...............0.................................. +..............0....t....N....h.................... +.............N.................................... +......j...................s............H...l..O... +..........q.................H................O.... +..f...e.qj.....y...0.............................. +...........t..........................k..Q..r..... +.........6................Q..s...x......W......... +....2..b...e....t..4.........c.....xW.j........... +...e....................w................1.....O.. +..e..j..5...........................c............. +.........B..2...............MK................H... +...2......b...g..X...q..........h...............O. +...q...2..........m....k...i...............QV.x... +...................i.........W.k.............HQ... +........b...X...............D..........c...N...... +................................l..........h.....I +.m...........g......l.......c.............3......V +....X.......m........g...V.K...7......F.d......... +.........b.X...U..........................C....... +.....................l..............o.1....C...... +............u.............K..............3...d.... +......................i.T....f................V... +..............................1.k................. +.B.....E......9..m....K..5.M...................... +...P...............M...95....o..i........I........ +...............................S......3......wI... +.....EP...........9........5..T.R................. +.P..........v..9......f.............R.Co..w3...... +..........h...SG..v.E...7..f.T.................... +..........6..........L.................Y.......d.. +..........B...............U........D.............. +....B................U.....8..M....n...J.......... +.........................L................Fw...... +....L6E.P.................7.UG....J.....Y.D....... +........t........v...SJ........n..d............... +......................8v.....uG................... +..................L.....n......................... +...............T..............n......D............ +..............o.........8................J.Y.R.... +..................S...............u....F.......R.. +........6..............u.....7.8..........Y..F.... diff --git a/2024/go/go.mod b/2024/go/go.mod index d7d05a2..1ff1c1b 100644 --- a/2024/go/go.mod +++ b/2024/go/go.mod @@ -7,6 +7,6 @@ require golang.org/x/exp v0.0.0-20221208152030-732eee02a75a require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.10.0 // indirect + github.com/stretchr/testify v1.10.0 // direct gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/2024/go/main.go b/2024/go/main.go index 46934c6..0c51cbd 100644 --- a/2024/go/main.go +++ b/2024/go/main.go @@ -10,8 +10,11 @@ import ( "adventofcode2024/day01" "adventofcode2024/day02" "adventofcode2024/day03" - "adventofcode2024/day04" - + "adventofcode2024/day04" + "adventofcode2024/day05" + "adventofcode2024/day06" + "adventofcode2024/day07" + "adventofcode2024/day08" ) // Usage: go run main.go // assumes input is in day/input.txt @@ -32,6 +35,19 @@ func main() { case 4: fmt.Printf("part 1: %d\n", day04.Part1(utils.Readfile(d))) fmt.Printf("part 2: %d\n", day04.Part2(utils.Readfile(d))) + case 5: + fmt.Printf("part 1: %d\n", day05.Part1(utils.Readfile(d))) + fmt.Printf("part 2: %d\n", day05.Part2(utils.Readfile(d))) + case 6: + fmt.Printf("part 1: %d\n", day06.Part1(utils.Readfile(d))) + fmt.Printf("part 2: %d\n", day06.Part2(utils.Readfile(d))) + case 7: + fmt.Printf("part 1: %d\n", day07.Part1(utils.Readfile(d))) + fmt.Printf("part 2: %d\n", day07.Part2(utils.Readfile(d))) + case 8: + fmt.Printf("part 1: %d\n", day08.Part1(utils.Readfile(d))) + fmt.Printf("part 2: %d\n", day08.Part2(utils.Readfile(d))) + default: panic(fmt.Errorf("no such day: %d", d)) } @@ -39,7 +55,7 @@ func main() { // Reads day from os.Args. func day() int { - latest := 3 + latest := 7 if len(os.Args) == 1 { return latest }