Compare commits

..

1 Commits

Author SHA1 Message Date
xuu
284c2b923a
chore: add day 10 pt1
Some checks failed
Go Test / build (pull_request) Failing after 19s
2023-12-10 11:56:16 -07:00
2 changed files with 24 additions and 18 deletions

View File

@ -29,7 +29,7 @@ func run(scan *bufio.Scanner) (*result, error) {
} }
dist := m.buildPath() dist := m.buildPath()
return &result{valuePT1: dist}, nil return &result{valuePT1: dist}, nil
} }
@ -75,19 +75,19 @@ func (m *Path) readLine(text string) {
} }
func (m *Path) buildPath() int { func (m *Path) buildPath() int {
m.start() m.start()
// log(m.n) log(m.n)
i := 0 i := 0
for m.next() { for m.next() {
// log(m.n) log(m.n)
i++ i++
} }
// log(m.n) log(m.n)
// log("length", (m.l+2)/2) log("length", (m.l+2)/2)
return (m.l+2)/2 return (m.l+2)/2
} }
func (m *Path) start() { func (m *Path) start() {
m.n = &node{value: 'S', pos: m.s} m.n = &node{value: 'S', pos: m.s}
// log(m.n) log(m.n)
switch { switch {
case m.peek(UP) != nil: case m.peek(UP) != nil:

View File

@ -34,8 +34,11 @@ func TestExample1(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.Equal(result.valuePT1, 4) is.Equal(result.valuePT1, 4)
t.Log(result.valuePT2)
is.Equal(result.valuePT2, uint64(0))
} }
func TestExample2(t *testing.T) { func TestExample2(t *testing.T) {
@ -45,8 +48,11 @@ func TestExample2(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.Equal(result.valuePT1, 8) is.Equal(result.valuePT1, 8)
t.Log(result.valuePT2)
is.Equal(result.valuePT2, uint64(0))
} }
func TestExample3(t *testing.T) { func TestExample3(t *testing.T) {
@ -56,10 +62,10 @@ func TestExample3(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.Equal(result.valuePT1, 23) is.Equal(result.valuePT1, 23)
// t.Log(result.valuePT2) t.Log(result.valuePT2)
is.Equal(result.valuePT2, 4) is.Equal(result.valuePT2, 4)
} }
@ -70,10 +76,10 @@ func TestExample4(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.Equal(result.valuePT1, 70) is.Equal(result.valuePT1, 70)
// t.Log(result.valuePT2) t.Log(result.valuePT2)
is.Equal(result.valuePT2, 8) is.Equal(result.valuePT2, 8)
} }
@ -84,10 +90,10 @@ func TestExample5(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.Equal(result.valuePT1, 80) is.Equal(result.valuePT1, 80)
// t.Log(result.valuePT2) t.Log(result.valuePT2)
is.Equal(result.valuePT2, 10) is.Equal(result.valuePT2, 10)
} }
@ -98,12 +104,12 @@ func TestInput(t *testing.T) {
result, err := run(scan) result, err := run(scan)
is.NoErr(err) is.NoErr(err)
// t.Log(result.valuePT1) t.Log(result.valuePT1)
is.True(result.valuePT1 != 51) t.Log(result.valuePT1 != 51)
is.Equal(result.valuePT1, 6649) is.Equal(result.valuePT1, 6649)
// t.Log(result.valuePT2) t.Log(result.valuePT2)
is.True(result.valuePT2 != 0) is.Equal(result.valuePT2, uint64(0))
} }
// first: 51 false // first: 51 false