diff --git a/2020/dec17/README.md b/2020/dec17/README.md index 34eb3ed..2956d0b 100644 --- a/2020/dec17/README.md +++ b/2020/dec17/README.md @@ -1 +1,14 @@ +# Part 1 + +These things are rather hard to debug. + +I chose a different approach from the last life-game door: while looping over the cells, each one checks how many neighbours it has rather than adding itself to its neighbours' counts. It is probably far less efficient, but way easier to test as it feels more natural. + +# Part 2 + +OK. Great. 4 dimensions. Should I support N dimensions or just wrap `for` loops around my loops? Declare the number of dimensions as a const and work from there? + +It seems at this moment that fast is the priority. + + [Read the story](./STORY.md) diff --git a/2020/dec17/STORY.md b/2020/dec17/STORY.md index 53534f3..5e129e1 100644 --- a/2020/dec17/STORY.md +++ b/2020/dec17/STORY.md @@ -1,2 +1,402 @@ +# Day 17: Conway Cubes + +As your flight slowly drifts through the sky, the Elves at the Mythical Information Bureau at the North Pole contact you. They'd like some help debugging a malfunctioning experimental energy source aboard one of their super-secret imaging satellites. + +The experimental energy source is based on cutting-edge technology: a set of Conway Cubes contained in a pocket dimension! When you hear it's having problems, you can't help but agree to take a look. + +The pocket dimension contains an infinite 3-dimensional grid. At every integer 3-dimensional coordinate (x,y,z), there exists a single cube which is either active or inactive. + +In the initial state of the pocket dimension, almost all cubes start inactive. The only exception to this is a small flat region of cubes (your puzzle input); the cubes in this region start in the specified active (#) or inactive (.) state. + +The energy source then proceeds to boot up by executing six cycles. + +Each cube only ever considers its neighbors: any of the 26 other cubes where any of their coordinates differ by at most 1. For example, given the cube at x=1,y=2,z=3, its neighbors include the cube at x=2,y=2,z=2, the cube at x=0,y=2,z=3, and so on. + +During a cycle, all cubes simultaneously change their state according to the following rules: + +- If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive. +- If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive. + +The engineers responsible for this experimental energy source would like you to simulate the pocket dimension and determine what the configuration of cubes should be at the end of the six-cycle boot process. + +For example, consider the following initial state: + + .#. + ..# + ### + +Even though the pocket dimension is 3-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1 region of the 3-dimensional space.) + +Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z coordinate (and the frame of view follows the active cells in each cycle): + +Before any cycles: + + z=0 + .#. + ..# + ### + + +After 1 cycle: + + z=-1 + #.. + ..# + .#. + + z=0 + #.# + .## + .#. + + z=1 + #.. + ..# + .#. + + +After 2 cycles: + + z=-2 + ..... + ..... + ..#.. + ..... + ..... + + z=-1 + ..#.. + .#..# + ....# + .#... + ..... + + z=0 + ##... + ##... + #.... + ....# + .###. + + z=1 + ..#.. + .#..# + ....# + .#... + ..... + + z=2 + ..... + ..... + ..#.. + ..... + ..... + + +After 3 cycles: + + z=-2 + ....... + ....... + ..##... + ..###.. + ....... + ....... + ....... + + z=-1 + ..#.... + ...#... + #...... + .....## + .#...#. + ..#.#.. + ...#... + + z=0 + ...#... + ....... + #...... + ....... + .....## + .##.#.. + ...#... + + z=1 + ..#.... + ...#... + #...... + .....## + .#...#. + ..#.#.. + ...#... + + z=2 + ....... + ....... + ..##... + ..###.. + ....... + ....... + ....... + +After the full six-cycle boot process completes, 112 cubes are left in the active state. + +Starting with your given initial configuration, simulate six cycles. How many cubes are left in the active state after the sixth cycle? + +Your puzzle answer was 209. + +## Part Two + +For some reason, your simulated results don't match what the experimental energy source engineers expected. Apparently, the pocket dimension actually has four spatial dimensions, not three. + +The pocket dimension contains an infinite 4-dimensional grid. At every integer 4-dimensional coordinate (x,y,z,w), there exists a single cube (really, a hypercube) which is still either active or inactive. + +Each cube only ever considers its neighbors: any of the 80 other cubes where any of their coordinates differ by at most 1. For example, given the cube at x=1,y=2,z=3,w=4, its neighbors include the cube at x=2,y=2,z=3,w=3, the cube at x=0,y=2,z=3,w=4, and so on. + +The initial state of the pocket dimension still consists of a small flat region of cubes. Furthermore, the same rules for cycle updating still apply: during each cycle, consider the number of active neighbors of each cube. + +For example, consider the same initial state as in the example above. Even though the pocket dimension is 4-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1x1 region of the 4-dimensional space.) + +Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z and w coordinate: + +Before any cycles: + + z=0, w=0 + .#. + ..# + ### + + +After 1 cycle: + + z=-1, w=-1 + #.. + ..# + .#. + + z=0, w=-1 + #.. + ..# + .#. + + z=1, w=-1 + #.. + ..# + .#. + + z=-1, w=0 + #.. + ..# + .#. + + z=0, w=0 + #.# + .## + .#. + + z=1, w=0 + #.. + ..# + .#. + + z=-1, w=1 + #.. + ..# + .#. + + z=0, w=1 + #.. + ..# + .#. + + z=1, w=1 + #.. + ..# + .#. + + +After 2 cycles: + + z=-2, w=-2 + ..... + ..... + ..#.. + ..... + ..... + + z=-1, w=-2 + ..... + ..... + ..... + ..... + ..... + + z=0, w=-2 + ###.. + ##.## + #...# + .#..# + .###. + + z=1, w=-2 + ..... + ..... + ..... + ..... + ..... + + z=2, w=-2 + ..... + ..... + ..#.. + ..... + ..... + + z=-2, w=-1 + ..... + ..... + ..... + ..... + ..... + + z=-1, w=-1 + ..... + ..... + ..... + ..... + ..... + + z=0, w=-1 + ..... + ..... + ..... + ..... + ..... + + z=1, w=-1 + ..... + ..... + ..... + ..... + ..... + + z=2, w=-1 + ..... + ..... + ..... + ..... + ..... + + z=-2, w=0 + ###.. + ##.## + #...# + .#..# + .###. + + z=-1, w=0 + ..... + ..... + ..... + ..... + ..... + + z=0, w=0 + ..... + ..... + ..... + ..... + ..... + + z=1, w=0 + ..... + ..... + ..... + ..... + ..... + + z=2, w=0 + ###.. + ##.## + #...# + .#..# + .###. + + z=-2, w=1 + ..... + ..... + ..... + ..... + ..... + + z=-1, w=1 + ..... + ..... + ..... + ..... + ..... + + z=0, w=1 + ..... + ..... + ..... + ..... + ..... + + z=1, w=1 + ..... + ..... + ..... + ..... + ..... + + z=2, w=1 + ..... + ..... + ..... + ..... + ..... + + z=-2, w=2 + ..... + ..... + ..#.. + ..... + ..... + + z=-1, w=2 + ..... + ..... + ..... + ..... + ..... + + z=0, w=2 + ###.. + ##.## + #...# + .#..# + .###. + + z=1, w=2 + ..... + ..... + ..... + ..... + ..... + + z=2, w=2 + ..... + ..... + ..#.. + ..... + ..... + +After the full six-cycle boot process completes, 848 cubes are left in the active state. + +Starting with your given initial configuration, simulate six cycles in a 4-dimensional space. How many cubes are left in the active state after the sixth cycle? + +Your puzzle answer was 1492. [Go to December 18](../dec18/STORY.md) diff --git a/2020/dec17/dec17.go b/2020/dec17/dec17.go index bb35f71..fbc0c1f 100644 --- a/2020/dec17/dec17.go +++ b/2020/dec17/dec17.go @@ -3,27 +3,51 @@ package dec17 import ( "fmt" - "github.com/ablqk/adventofcode/doors" + "github.com/ablqk/adventofcode/2020/dec17/energysource/source4d" "github.com/ablqk/adventofcode/pkg/fileread" ) // New instance of the Door for December 17 -func New(input string) doors.Solver { - return dec17{input} +func New(input string, iterations int) Dec17 { + return Dec17{ + input: input, + iterations: iterations, + } } -type dec17 struct { - input string +type Dec17 struct { + input string + iterations int } // Solve the day's problem -func (d dec17) Solve() (string, error) { - var count int - err := fileread.ReadAndApply(d.input, func(s string) error { - return nil - }) +func (d Dec17) Solve() (string, error) { + state, err := newState(d.input) if err != nil { - return "", err + return "", fmt.Errorf("cannot parse input file: %w", err) } - return fmt.Sprintf("%d", count), nil + + actives := state.CountActiveCellsAfter(d.iterations) + return fmt.Sprintf("After %d iterations, we have %d active cells", d.iterations, actives), nil +} + +// Source of Experimental Energy +type source interface { + CountActiveCellsAfter(times int) int +} + +// newState parses the input file and returns a source +func newState(input string) (source, error) { + state := source4d.New() + var y int + err := fileread.ReadAndApply(input, func(s string) error { + for x, c := range s { + if c == '#' { + state.Activate(x, y, 0, 0) + } + } + y++ + return nil + }) + return state, err } diff --git a/2020/dec17/dec17_test.go b/2020/dec17/dec17_test.go index 906b800..044b059 100644 --- a/2020/dec17/dec17_test.go +++ b/2020/dec17/dec17_test.go @@ -7,7 +7,8 @@ import ( ) func TestDec17_Solve(t *testing.T) { - s, err := New("testdata/in.txt").Solve() + s, err := New("testdata/in.txt", 6).Solve() assert.NoError(t, err) - assert.Contains(t, s, "") + // assert.Contains(t, s, "6 iterations, we have 112 active") // part 1 + assert.Contains(t, s, "6 iterations, we have 848 active") } diff --git a/2020/dec17/energysource/source3d/iteration.go b/2020/dec17/energysource/source3d/iteration.go new file mode 100644 index 0000000..27b13f8 --- /dev/null +++ b/2020/dec17/energysource/source3d/iteration.go @@ -0,0 +1,49 @@ +package source3d + +// iterate once and return a new State +func (s *State) iterate() *State { + next := New() + for z := s.min.z - 1; z <= s.max.z+1; z++ { + for y := s.min.y - 1; y <= s.max.y+1; y++ { + for x := s.min.x - 1; x <= s.max.x+1; x++ { + c := coord3D{x, y, z} + active := s.nextCellState(c) + if active { + next.Activate(x, y, z) + } + } + } + } + return next +} + +// nextCellState returns the activation (or dis- thereof) of a cell: it returns the next state of this cell +func (s *State) nextCellState(c coord3D) bool { + _, isActive := s.active[c] + activeNeighbours := s.countNeighbours(c) + // If a cube is active and exactly 2 or 3 of its neighbours are also active, the cube remains active. Otherwise, the cube becomes inactive. + if isActive && (activeNeighbours == 2 || activeNeighbours == 3) { + return true + } + // If a cube is inactive but exactly 3 of its neighbours are active, the cube becomes active. Otherwise, the cube remains inactive. + return !isActive && activeNeighbours == 3 +} + +// countNeighbours simply returns the number of active neighbours for a given cell +func (s *State) countNeighbours(c coord3D) int { + var activeNeighbours int + for x := c.x - 1; x <= c.x+1; x++ { + for y := c.y - 1; y <= c.y+1; y++ { + for z := c.z - 1; z <= c.z+1; z++ { + if x == c.x && y == c.y && z == c.z { + continue // yuck + } + _, ok := s.active[coord3D{x, y, z}] + if ok { + activeNeighbours++ + } + } + } + } + return activeNeighbours +} diff --git a/2020/dec17/energysource/source3d/iteration_test.go b/2020/dec17/energysource/source3d/iteration_test.go new file mode 100644 index 0000000..52aec70 --- /dev/null +++ b/2020/dec17/energysource/source3d/iteration_test.go @@ -0,0 +1,113 @@ +package source3d + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestState_Iterate(t *testing.T) { + tt := map[string]struct { + activeCells []coord3D + times int + expectedActiveCells int + }{ + // example from the STORY, before iterating + "stagnant": { + activeCells: []coord3D{ + {0, -1, 0}, + {1, 0, 0}, + {-1, 1, 0}, + {0, 1, 0}, + {1, 1, 0}, + }, + times: 0, + expectedActiveCells: 5, + }, + // example from the STORY, one iteration + "one iteration": { + activeCells: []coord3D{ + {0, -1, 0}, + {1, 0, 0}, + {-1, 1, 0}, + {0, 1, 0}, + {1, 1, 0}, + }, + times: 1, + expectedActiveCells: 11, + }, + // example from the STORY, full + "3 iterations": { + activeCells: []coord3D{ + {0, -1, 0}, + {1, 0, 0}, + {-1, 1, 0}, + {0, 1, 0}, + {1, 1, 0}, + }, + times: 3, + expectedActiveCells: 38, + }, + } + + for name, tc := range tt { + t.Run(name, func(t *testing.T) { + s := New() + for _, c := range tc.activeCells { + s.activate(c) + } + assert.Equal(t, tc.expectedActiveCells, s.CountActiveCellsAfter(tc.times)) + }) + } +} + +func Test_countNeighbours(t *testing.T) { + tt := map[string]struct { + state State + coord coord3D + expected int + }{ + "only you can make the darkness bright": { + state: State{ + active: map[coord3D]struct{}{ + {0, 0, 0}: {}, + }, + }, + coord: coord3D{0, 0, 0}, + expected: 0, + }, + "corners": { + state: State{ + active: map[coord3D]struct{}{ + {-1, 1, 1}: {}, + {-1, 1, -1}: {}, + {1, 1, 1}: {}, + {-1, -1, 1}: {}, + }, + }, + coord: coord3D{0, 0, 0}, + expected: 4, + }, + "story's example": { + state: State{ + active: map[coord3D]struct{}{ + {0, -1, 0}: {}, + {1, 0, 0}: {}, + {-1, 1, 0}: {}, + {0, 1, 0}: {}, + {1, 1, 0}: {}, + }, + min: coord3D{-1,-1,-1}, + max: coord3D{1,1,1}, + }, + coord: coord3D{0, -1, 0}, + expected: 1, + }, + } + + for name, tc := range tt { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.expected, tc.state.countNeighbours(tc.coord)) + }) + } +} diff --git a/2020/dec17/energysource/source3d/state.go b/2020/dec17/energysource/source3d/state.go new file mode 100644 index 0000000..f46667f --- /dev/null +++ b/2020/dec17/energysource/source3d/state.go @@ -0,0 +1,83 @@ +package source3d + +import ( + "fmt" +) + +// State is an implementation of the Experimental Energy Source +// It represents the state of the Source at a given point in the iterative dimension (think time, for example) +type State struct { + active map[coord3D]struct{} + min coord3D + max coord3D +} + +type coord3D struct { + x, y, z int +} + +func New() *State { + return &State{active: make(map[coord3D]struct{})} +} + +// Activate sets the given cell to Active +func (s *State) Activate(x, y, z int) { + c := coord3D{x: x, y: y, z: z} + s.activate(c) +} + +func (s *State) activate(c coord3D) { + s.active[c] = struct{}{} + s.updateBoundaries(c) +} + +func (s *State) updateBoundaries(c coord3D) { + if c.x < s.min.x { + s.min.x = c.x + } + if c.x > s.max.x { + s.max.x = c.x + } + if c.y < s.min.y { + s.min.y = c.y + } + if c.y > s.max.y { + s.max.y = c.y + } + if c.z < s.min.z { + s.min.z = c.z + } + if c.z > s.max.z { + s.max.z = c.z + } +} + +// CountActiveCells returns the number of active cells +func (s *State) CountActiveCellsAfter(times int) int { + n := s + for i := 0; i < times; i++ { + n = n.iterate() + } + return len(n.active) +} + +// String returns a representation of the State's cells +func (s *State) String() string { + str := "==== state ====" + for z := s.min.z - 1; z <= s.max.z+1; z++ { + str += fmt.Sprintln("\nz = ", z) + for y := s.min.y - 1; y <= s.max.y+1; y++ { + for x := s.min.x - 1; x <= s.max.x+1; x++ { + c := coord3D{x, y, z} + _, active := s.active[c] + if active { + str += "#" + } else { + str += "." + } + } + str += "\n" + } + } + return str +} diff --git a/2020/dec17/energysource/source3d/state_test.go b/2020/dec17/energysource/source3d/state_test.go new file mode 100644 index 0000000..f7d7297 --- /dev/null +++ b/2020/dec17/energysource/source3d/state_test.go @@ -0,0 +1,44 @@ +package source3d + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestState_Activate(t *testing.T) { + tt := map[string]struct { + activeCells []coord3D + min, max coord3D + }{ + "one": { + activeCells: []coord3D{{1, 2, 3}}, + min: coord3D{0, 0, 0}, + max: coord3D{1, 2, 3}, + }, + "some": { + activeCells: []coord3D{ + {1, 2, 3}, + {-1, 0, 2}, + {1, 2, 3}, + {-1, -2, 3}, + {1, 2, 3}, + }, + min: coord3D{-1, -2, 0}, + max: coord3D{1, 2, 3}, + }, + } + + for name, tc := range tt { + t.Run(name, func(t *testing.T) { + s := New() + for _, c := range tc.activeCells { + s.activate(c) + } + _, isActive := s.active[tc.activeCells[0]] + assert.True(t, isActive) + assert.Equal(t, tc.min, s.min) + assert.Equal(t, tc.max, s.max) + }) + } +} diff --git a/2020/dec17/energysource/source4d/iteration.go b/2020/dec17/energysource/source4d/iteration.go new file mode 100644 index 0000000..4f40692 --- /dev/null +++ b/2020/dec17/energysource/source4d/iteration.go @@ -0,0 +1,53 @@ +package source4d + +// iterate once and return a new State +func (s *State) iterate() *State { + next := New() + for w := s.min.w - 1; w <= s.max.w+1; w++ { + for z := s.min.z - 1; z <= s.max.z+1; z++ { + for y := s.min.y - 1; y <= s.max.y+1; y++ { + for x := s.min.x - 1; x <= s.max.x+1; x++ { + c := coord4D{x, y, z, w} + active := s.nextCellState(c) + if active { + next.Activate(x, y, z, w) + } + } + } + } + } + return next +} + +// nextCellState returns the activation (or dis- thereof) of a cell: it returns the next state of this cell +func (s *State) nextCellState(c coord4D) bool { + _, isActive := s.active[c] + activeNeighbours := s.countNeighbours(c) + // If a cube is active and exactly 2 or 3 of its neighbours are also active, the cube remains active. Otherwise, the cube becomes inactive. + if isActive && (activeNeighbours == 2 || activeNeighbours == 3) { + return true + } + // If a cube is inactive but exactly 3 of its neighbours are active, the cube becomes active. Otherwise, the cube remains inactive. + return !isActive && activeNeighbours == 3 +} + +// countNeighbours simply returns the number of active neighbours for a given cell +func (s *State) countNeighbours(c coord4D) int { + var activeNeighbours int + for x := c.x - 1; x <= c.x+1; x++ { + for y := c.y - 1; y <= c.y+1; y++ { + for z := c.z - 1; z <= c.z+1; z++ { + for w := c.w - 1; w <= c.w+1; w++ { + if x == c.x && y == c.y && z == c.z && w == c.w { + continue // yuck, really... + } + _, ok := s.active[coord4D{x, y, z, w}] + if ok { + activeNeighbours++ + } + } + } + } + } + return activeNeighbours +} diff --git a/2020/dec17/energysource/source4d/iteration_test.go b/2020/dec17/energysource/source4d/iteration_test.go new file mode 100644 index 0000000..f774028 --- /dev/null +++ b/2020/dec17/energysource/source4d/iteration_test.go @@ -0,0 +1,62 @@ +package source4d + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestState_iterate(t *testing.T) { + tt := map[string]struct { + activeCells []coord4D + times int + expectedActiveCells int + }{ + // example from the STORY, before iterating + "stagnant": { + activeCells: []coord4D{ + {0, -1, 0, 0}, + {1, 0, 0, 0}, + {-1, 1, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + }, + times: 0, + expectedActiveCells: 5, + }, + // example from the STORY, one iteration + "one iteration": { + activeCells: []coord4D{ + {0, -1, 0, 0}, + {1, 0, 0, 0}, + {-1, 1, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + }, + times: 1, + expectedActiveCells: 29, + }, + // example from the STORY, full + "2 iterations": { + activeCells: []coord4D{ + {0, -1, 0, 0}, + {1, 0, 0, 0}, + {-1, 1, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + }, + times: 2, + expectedActiveCells: 60, + }, + } + + for name, tc := range tt { + t.Run(name, func(t *testing.T) { + s := New() + for _, c := range tc.activeCells { + s.activate(c) + } + assert.Equal(t, tc.expectedActiveCells, s.CountActiveCellsAfter(tc.times)) + }) + } +} diff --git a/2020/dec17/energysource/source4d/state.go b/2020/dec17/energysource/source4d/state.go new file mode 100644 index 0000000..79ac2c4 --- /dev/null +++ b/2020/dec17/energysource/source4d/state.go @@ -0,0 +1,64 @@ +package source4d + +// State is an implementation of the Experimental Energy Source +// It represents the state of the Source at a given point in the iterative dimension (think time, for example) +type State struct { + active map[coord4D]struct{} + min coord4D + max coord4D +} + +type coord4D struct { + x, y, z, w int +} + +func New() *State { + return &State{active: make(map[coord4D]struct{})} +} + +// Activate sets the given cell to Active +func (s *State) Activate(x, y, z, w int) { + c := coord4D{x: x, y: y, z: z, w:w} + s.activate(c) +} + +func (s *State) activate(c coord4D) { + s.active[c] = struct{}{} + s.updateBoundaries(c) +} + +func (s *State) updateBoundaries(c coord4D) { + if c.x < s.min.x { + s.min.x = c.x + } + if c.x > s.max.x { + s.max.x = c.x + } + if c.y < s.min.y { + s.min.y = c.y + } + if c.y > s.max.y { + s.max.y = c.y + } + if c.z < s.min.z { + s.min.z = c.z + } + if c.z > s.max.z { + s.max.z = c.z + } + if c.w < s.min.w { + s.min.w = c.w + } + if c.w > s.max.w { + s.max.w = c.w + } +} + +// CountActiveCells returns the number of active cells after a given number of iterations +func (s *State) CountActiveCellsAfter(times int) int { + n := s + for i := 0; i < times; i++ { + n = n.iterate() + } + return len(n.active) +} diff --git a/2020/dec17/energysource/source4d/state_test.go b/2020/dec17/energysource/source4d/state_test.go new file mode 100644 index 0000000..be078f6 --- /dev/null +++ b/2020/dec17/energysource/source4d/state_test.go @@ -0,0 +1,44 @@ +package source4d + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestState_Activate(t *testing.T) { + tt := map[string]struct { + activeCells []coord4D + min, max coord4D + }{ + "one": { + activeCells: []coord4D{{1, 2, 3, 0}}, + min: coord4D{0, 0, 0, 0}, + max: coord4D{1, 2, 3, 0}, + }, + "some": { + activeCells: []coord4D{ + {1, 2, 3, 0}, + {-1, 0, 2, 0}, + {1, 2, 3, -2}, + {-1, -2, 3, 0}, + {1, 2, 3,5}, + }, + min: coord4D{-1, -2, 0, -2}, + max: coord4D{1, 2, 3, 5}, + }, + } + + for name, tc := range tt { + t.Run(name, func(t *testing.T) { + s := New() + for _, c := range tc.activeCells { + s.activate(c) + } + _, isActive := s.active[tc.activeCells[0]] + assert.True(t, isActive) + assert.Equal(t, tc.min, s.min) + assert.Equal(t, tc.max, s.max) + }) + } +} diff --git a/2020/dec17/input.txt b/2020/dec17/input.txt index e69de29..2869685 100644 --- a/2020/dec17/input.txt +++ b/2020/dec17/input.txt @@ -0,0 +1,8 @@ +##..#### +.###.... +#.###.## +#....#.. +...#..#. +#.#...## +..#.#.#. +.##...#. diff --git a/2020/dec17/testdata/in.txt b/2020/dec17/testdata/in.txt index 2e65efe..eedd3d2 100644 --- a/2020/dec17/testdata/in.txt +++ b/2020/dec17/testdata/in.txt @@ -1 +1,3 @@ -a \ No newline at end of file +.#. +..# +### diff --git a/cmd/main.go b/cmd/main.go index a805dd1..c57d8d1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -81,7 +81,7 @@ func main() { case 16: o = dec16.New("2020/dec16/rules.txt", "2020/dec16/nearby.txt", "79,149,97,163,59,151,101,89,173,139,167,61,73,71,137,53,83,157,131,67") case 17: - o = dec17.New("2020/dec17/input.txt") + o = dec17.New("2020/dec17/input.txt", 6) case 18: o = dec18.New("2020/dec18/input.txt") case 19: diff --git a/pkg/match/findsum_test.go b/pkg/match/findsum_test.go index 4555b1f..9392f85 100644 --- a/pkg/match/findsum_test.go +++ b/pkg/match/findsum_test.go @@ -78,7 +78,7 @@ func BenchmarkFindSum2_100k(b *testing.B) { func randomInts(size int) []int { lines := make([]int, size) for i := 0; i < size; i++ { - lines[i] = rand.Int() & 1024 + 2100 // no 2 values will add up to 2020 + lines[i] = rand.Int() & 1023 + 2100 // no 2 values will add up to 2020 } return lines }