Compare commits

...

3 Commits

Author SHA1 Message Date
xuu
77a0669f45
feat: add day 4 2024
Some checks failed
Go Bump / bump (push) Failing after 9s
Go Test / build (push) Failing after 54s
2024-12-06 11:28:30 -07:00
xuu
c077b91c41
fix(aoc2024): clean up day 3
Some checks failed
Go Bump / bump (push) Failing after 9s
Go Test / build (push) Failing after 52s
2024-12-04 08:24:59 -07:00
xuu
b3c36c1af1 Merge pull request 'AOC 2024 Day 3' (#23) from working2024D3 into main
Some checks failed
Go Bump / bump (push) Failing after 10s
Go Test / build (push) Failing after 57s
Reviewed-on: #23
2024-12-03 16:16:23 -07:00
5 changed files with 360 additions and 17 deletions

View File

@ -25,7 +25,9 @@ func run(read io.Reader) (*result, error) {
sum := 0
sum2 := 0
lexer := Lexer(read)
lexer, stop := Lexer(read)
defer stop()
active := true
for lexer.NextTok() {
@ -52,7 +54,7 @@ func run(read io.Reader) (*result, error) {
return &result{sum, sum2}, nil
}
func Lexer(in io.Reader) *lexer {
func Lexer(in io.Reader) (*lexer, func()) {
seq := func(yield func(rune) bool) {
buf := make([]byte, 256)
s, _ := in.Read(buf)
@ -72,10 +74,10 @@ func Lexer(in io.Reader) *lexer {
}
}
next, stop := iter.Pull(seq)
lex := lexer{iter: next, stop: stop}
lex := lexer{iter: next}
lex.readRune()
lex.readRune()
return &lex
return &lex, stop
}
type lexer struct {
@ -83,15 +85,12 @@ type lexer struct {
next rune
iter func() (rune, bool)
stop func()
buf []rune
token string
literal []rune
}
func (l *lexer) Stop() { l.stop() }
func (l *lexer) readRune() {
if l.rune == -1 {
return
@ -172,16 +171,6 @@ func (l *lexer) NextTok() bool {
return true
}
func (l *lexer) Iter() iter.Seq2[string, string] {
return func(yield func(string, string) bool) {
for l.NextTok() {
if !yield(l.token, string(l.literal)) {
return
}
}
}
}
func readMul(lex *lexer) int {
if lex.token != "TokMUL" || string(lex.literal) != "mul" {
return 0

10
aoc2024/day04/example.txt Normal file
View File

@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXM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AAXXMAMASAMMASMMMAMMSMMSSSMSASXMSSXMXXMAMMSSMMXXAXAAMMX
MSMMSSMMMSAAAAXMAXMAMMMSMMMSAAMMMAMAXXSMSMSMAMASXMSXSASMSMMSASMSMSAASMMMMMMSMXSASXMMMSXMASAMAMMMMAXASXXSAAAAAAMASAAXAXAAMXSMSSMAMAXMASMMMSSS
AAXAAAAXXSMMSSSXAMSAMXAAAAXSASAMMAMSAMXAAAAMASAMAAXMAXSAAASMMSAXAMMXMAMSAMXAXMSAMMAAAAXAXSXMMSXXMASAMMAMXSSMMSMAMSMAMMSMMSAMXAMASMMASXAAAAAA
SSSSSSMMXMAMMMXMAMSMMMSSSMXXMMMXSXSMSXMAMSMSXMXSMMMXMASXXSMSMMMMXMAMXAXSXMSAMXMXMSSMSXMSAMXASMXMAMAMXMMMMMAMXXMXXAXXXAXSXXXMSAMAXXASMSSMMMSM

163
aoc2024/day04/main.go Normal file
View File

@ -0,0 +1,163 @@
package main
import (
"bufio"
_ "embed"
"fmt"
aoc "go.sour.is/advent-of-code"
)
// var log = aoc.Log
func main() { aoc.MustResult(aoc.Runner(run)) }
type result struct {
valuePT1 int
valuePT2 int
}
type record struct {
p aoc.Point[int]
d [2]int
}
func (r result) String() string { return fmt.Sprintf("%#v", r) }
func run(scan *bufio.Scanner) (*result, error) {
m := make([][]rune, 0, 1000)
var records []record
var records2 []record
for scan.Scan() {
txt := scan.Text()
m = append(m, []rune(txt))
}
for x, row := range m {
for y, c := range row {
if c == 'X' {
rs := search1(record{
p: aoc.Point[int]{x, y},
}, m)
records = append(records, rs...)
}
if c == 'A' {
rs := search2(record{
p: aoc.Point[int]{x, y},
}, m)
if len(rs) == 2 {
records2 = append(records2, rs...)
}
}
}
}
for _, r := range records2 {
fmt.Println(r)
}
return &result{len(records), len(records2)/2}, nil
}
func search1(r record, m [][]rune) []record {
var ds = [][2]int{
{1, 0}, // up
{0, 1}, // right
{-1, 0}, // down
{0, -1}, // left
{1, 1}, // up-right
{1, -1}, // up-left
{-1, 1}, // down-right
{-1, -1}, // down-left
}
var records []record
for _, d := range ds {
p := r.p
if !check1(m, p, d) {
continue
}
records = append(records, record{
p: p,
d: d,
})
}
return records
}
func check1(m [][]rune, p aoc.Point[int], d [2]int) bool {
for _, r := range []rune{'M', 'A', 'S'} {
p[0] += d[0]
p[1] += d[1]
if p[0] < 0 || p[0] >= len(m) {
return false
}
if p[1] < 0 || p[1] >= len(m[0]) {
return false
}
if m[p[0]][p[1]] != r {
return false
}
}
return true
}
func search2(r record, m [][]rune) []record {
var ds = [][2]int{
{1, 1}, // up-right
{1, -1}, // up-left
{-1, 1}, // down-right
{-1, -1}, // down-left
}
var records []record
for _, d := range ds {
p := r.p
if !check2(m, p, d) {
continue
}
records = append(records, record{
p: p,
d: d,
})
}
return records
}
func check2(m [][]rune, p aoc.Point[int], d [2]int) bool {
p0 := p[0] - d[0]
p1 := p[1] - d[1]
if p0 < 0 || p0 >= len(m) {
return false
}
if p1 < 0 || p1 >= len(m[0]) {
return false
}
if m[p0][p1] != 'M' {
return false
}
p0 = p[0] + d[0]
p1 = p[1] + d[1]
if p0 < 0 || p0 >= len(m) {
return false
}
if p1 < 0 || p1 >= len(m[0]) {
return false
}
if m[p0][p1] != 'S' {
return false
}
return true
}

View File

@ -0,0 +1,41 @@
package main
import (
"bufio"
"bytes"
"testing"
_ "embed"
"github.com/matryer/is"
)
//go:embed example.txt
var example []byte
//go:embed input.txt
var input []byte
func TestExample(t *testing.T) {
is := is.New(t)
scan := bufio.NewScanner(bytes.NewReader(example))
result, err := run(scan)
is.NoErr(err)
t.Log(result)
is.Equal(result.valuePT1, 18)
is.Equal(result.valuePT2, 9)
}
func TestSolution(t *testing.T) {
is := is.New(t)
scan := bufio.NewScanner(bytes.NewReader(input))
result, err := run(scan)
is.NoErr(err)
t.Log(result)
is.Equal(result.valuePT1, 2536)
is.Equal(result.valuePT2, 1875)
}