Skip to content

Commit

Permalink
2024 day 4 update
Browse files Browse the repository at this point in the history
  • Loading branch information
dbut2 committed Dec 4, 2024
1 parent 009b19b commit ca45fb7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
11 changes: 5 additions & 6 deletions 2024/02/02.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ func solve(input [][]int) int {
}

func isSafe(ints []int) bool {
increasing := ints[1] > ints[0]
shouldIncrease := ints[1] > ints[0]
for i := 1; i < len(ints); i++ {
if ints[i] == ints[i-1] {
distance := math.Abs(ints[i] - ints[i-1])
if distance < 1 || distance > 3 {
return false
}
if increasing != (ints[i] > ints[i-1]) {
return false
}
if math.Abs(ints[i]-ints[i-1]) > 3 {
increases := ints[i] > ints[i-1]
if shouldIncrease != increases {
return false
}
}
Expand Down
4 changes: 1 addition & 3 deletions 2024/04/01.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ func solve(input space.Grid[byte]) int {
count := 0
for cell := range input.Cells() {
for _, dir := range slices.Concat(space.Directions, space.Diagonals) {
cell := cell
found := true
for i := range word {
nextCell := input.Get(cell)
nextCell := input.Get(cell.Move(dir.Multiply(i)))
if nextCell == nil || *nextCell != word[i] {
found = false
break
}
cell = cell.Move(dir)
}
if found {
count++
Expand Down
1 change: 1 addition & 0 deletions pkg/grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"slices"
)

// Deprecated. Use space.Grid instead.
type Grid[T any] map[[2]int]*T

func (g Grid[T]) Set(x, y int, cell T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/lists/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (q *Queue[T]) Seq(yield func(T) bool) {
}
}

// TODO: fix the failing cases when using ll
//type Queue[T any] struct {
// linked Linked[T]
//}
Expand Down
1 change: 1 addition & 0 deletions pkg/ll/ll.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ll

// Deprecated. Use lists.DoublyLinked instead.
type Double[T any] struct {
Val T
Prev *Double[T]
Expand Down
4 changes: 4 additions & 0 deletions pkg/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (d *Direction) Add(b Direction) Direction {
return Direction{d[0] + b[0], d[1] + b[1]}
}

func (d *Direction) Multiply(n int) Direction {
return Direction{d[0] * n, d[1] * n}
}

var (
North = Direction{0, -1}
South = Direction{0, 1}
Expand Down

0 comments on commit ca45fb7

Please sign in to comment.