Compare commits
4
Commits
day23
...
04bbac8559
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04bbac8559
|
||
|
|
3c9af95ec4
|
||
|
|
50af2114d4
|
||
|
|
f8fa61672f
|
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
-----BEGIN SSH SIGNATURE-----
|
||||||
|
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgZ+OuJYdd3UiUbyBuO1RlsQR20a
|
||||||
|
Qm5mKneuMxRjGo3zkAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx
|
||||||
|
OQAAAED8T4C6WILXYZ1KxqDIlVhlrAEjr1Vc+tn8ypcVM3bN7iOexVvuUuvm90nr8eEwKU
|
||||||
|
acrdDxmq2S+oysQbK+pMUE
|
||||||
|
-----END SSH SIGNATURE-----
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,11 @@
|
|||||||
|
...........
|
||||||
|
.....###.#.
|
||||||
|
.###.##..#.
|
||||||
|
..#.#...#..
|
||||||
|
....#.#....
|
||||||
|
.##..S####.
|
||||||
|
.##..#...#.
|
||||||
|
.......##..
|
||||||
|
.##.#.####.
|
||||||
|
.##..##.##.
|
||||||
|
...........
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
...................................................................................................................................
|
||||||
|
.#.......#..#...#.......#......#....#..#...#...#....#.#..........................................#...............#..........#......
|
||||||
|
.............##..................#......#.#....#.......................##..#........................#......#..........#............
|
||||||
|
......#..........................#....#.....#.............#................##....#.#.............#.........#.##...........#........
|
||||||
|
.#................#............................#...........................#..##.....#..................#..##..#.#.........##......
|
||||||
|
.....#.............#.....##.............##..........#...........#.............#.....#...........#.#.......#....#......#..........#.
|
||||||
|
........#....................#....#.#.#......##........#...........#...........#..........#...#..........#......................#..
|
||||||
|
.........#.#...#.......#........#........##...#...#..##........................................##...#.#........................#...
|
||||||
|
......#.....#..#..#.#..#..............#...#..#.....#...........#.....#........#.#...........#...........#.#...............#.....#..
|
||||||
|
...........#.......####..#.#..............##................#.#.#.....................##.....................#...#..............#..
|
||||||
|
......###...#......#................##...#...#....#...........#...#..............#.........#..#..................................#.
|
||||||
|
...............#..##..........#...........................##......#.##.........................#..#.#...........#.#...........#....
|
||||||
|
...##........#...#...#...##...##...........#..#...................#...................#.#..#.........#.......#..#...........##...#.
|
||||||
|
................#.....#..##......#.....#.....##............#..#..........##...........................#.#.......##.....#.....#.....
|
||||||
|
.#..#.......#.#...#..##.....#............................#......#...#....#................#.#..#.....#.......##................#...
|
||||||
|
...............#.....#........................#..........#.....#..............................................#..................#.
|
||||||
|
.....#......#..........................................#....................................#..#.......#.#..#......#.#....#..##....
|
||||||
|
............##............#.......###.......................#..#....#......................................#..#.........#..........
|
||||||
|
..#...............#.....#...#...#......................#...#.#..............................#.#..#.#.....#.#.#..#....#.....#...##..
|
||||||
|
.#.............................##.................#.......#.......##....#....................#.....#.#........#.....#........#.....
|
||||||
|
.#....##...................##.....#.#..............#.#....#....#..#....#......#..........#.....##............#....#.............##.
|
||||||
|
.........#....#.....#..#.........#....#.#..........#...#...#.......#....#..##.......................#.#..#........#..#....#..#.#...
|
||||||
|
..#..................#.......#..#.#..............##.......#........#..............#.........#..#....#......#..#..........#.........
|
||||||
|
........#.....#......#.....#......#...#.......#....#.......#.#..#................#....................##.............#.......#.....
|
||||||
|
..#.................#..............#...........................................#.....#..................#...#.#..................#.
|
||||||
|
.......#......#.....#...........................#.....#..................#.....................#.....#.#......#........#.#.......#.
|
||||||
|
..#.#.#...................#...#..#................#....#.......#......................#...............#.........##...#.#.....###...
|
||||||
|
.....#...#....##....#........####...........#.................#...#...........................................#..............##....
|
||||||
|
..##.#..#.#..........#.#.#..#................................#..#.............#..#......#...........................#.##...........
|
||||||
|
..............#.............................##........#..##........................#.............................#........#........
|
||||||
|
........#.........#........#..#........#..#........#...#.#........#...........#.........................#.#..........#...#......#..
|
||||||
|
.........##.....#........#.....................#..#.............#.....#........#....................#....#.#.#......#.....#........
|
||||||
|
......................#...................####..#.........#....#.........#...........#..................#..#.................#.....
|
||||||
|
..#.........#...#.....##................##.##....#.....#....#..............................#..#.............#..#...................
|
||||||
|
..........##......#..#..............#.#....#......#................#.....#....#..............#..................#..................
|
||||||
|
.#.#..####...#....................#.#.#.....#...#...................#....#.#.....#.#.......#.#...........#......#.#................
|
||||||
|
.......#.........#..#.#..............###.......#....#.........................#.......#.###...#............#....#.#..#....###.#....
|
||||||
|
........#....#...#......#.................#..........................#.........................#...........##.............#.#......
|
||||||
|
.#..............#.....................#......#.............##............#..#..........#...................#...#....#..............
|
||||||
|
......#..#..#.#...............#........###.......#.#...........#...........#.#.........#..#.....................#......#..#.#......
|
||||||
|
.....#...............#.........#....#..........#.......#.......#......#...#..##.....#.....#........#.#.......#.......#..#...#......
|
||||||
|
..#............#.....................#...#.......#....###...........#.....#.#.................#................#.........#..##.#...
|
||||||
|
..............................#.....#..................................#.....##...............#.......#.........#.....#....##......
|
||||||
|
..#...##...#...#..............#.................##..#......#.................#....#......#...#...#......#..........................
|
||||||
|
.........#....#..............#........#..#...............#....#...#.....#..#......#.........#.......#.#..#........#...........#....
|
||||||
|
........#..#....................#.........#...##.#.#..............#......#.#..........##...##....#......................#..........
|
||||||
|
.##..#....#....#.......##......#............#..#......#.....##..................#####..#...#......#.#...#..........#.#.....#..#....
|
||||||
|
..#...........#....................#.......#......#.........#...............#......#........##........#.................#.....#.#..
|
||||||
|
..#....#.#...............#.#.........................#.............####..............................##................###.........
|
||||||
|
.....#.......................................#....#...##...#.......#.......#.....#.##..##.................#.....................##.
|
||||||
|
.........#...........#..#..##.#..........#..#.........#..#.....#...................................##....#...............#..#.#....
|
||||||
|
.....#..#...........##............#........#..................#............#..........#..........#..#...........#..................
|
||||||
|
............................#.........#...............#..................#.#....#.#..#........#.....#...........#...........#......
|
||||||
|
................#...##.#....#..##..........#.#........##.#..#..#.....................#....#.................#.#...............#....
|
||||||
|
.#.....#..............#.#..........#..#........#...............#..#.#..##..#.#.#.........................#.................#.......
|
||||||
|
....#..............#................#.....#..#.......#..#.#.........#..........#..........#.....#..........##.....#............#...
|
||||||
|
..............##...........#.......#......#..................#.......#.....#.#...#...............#.#........#......#............#..
|
||||||
|
................#.....#....#........#....#.......#.#.##.....#...#..#.##...#................#.#.....#....#.............#............
|
||||||
|
...........#.#.##..####.....#....#.#...#.#...........#...#.......................#.#....#.....#..#................###..............
|
||||||
|
...................#....#..........#.#..##.....#..#..#......###............#..#...........#....#......#............................
|
||||||
|
...........................................#.......#..............#.##.......##.......#...#.....#.#..#.....#..###..................
|
||||||
|
............###........#.......#.#....#.....#....#..#........#.........##....#.....#..........#......#............#..#.#...........
|
||||||
|
............#..........#................##.#..............#.....#................#....................................#..#.........
|
||||||
|
...........#.....#.....................#...#.....#.......#..........#....#.....###.....##.#.##.#.....#......#......#.......#.......
|
||||||
|
.....................#..#.....#...##.....#..#...........#....#....##............##.................##............##................
|
||||||
|
.................................................................S.................................................................
|
||||||
|
........#.#........#..........#.....#......#........#.#............#.#.........##...#............#...#.....#...........#.....#.....
|
||||||
|
..................##.......#......#..#..................#..##......#.........#...#.........#............#....#...........##........
|
||||||
|
..................#...........#.##.......#..............#....................#.#....#...##...#.....#.......#..#.....##.............
|
||||||
|
...........#....#....##...#................................#.........#.................#....#.......................#...#..........
|
||||||
|
.............#.#.#.....#.#...#.......#.#...........#....#.#.........#........##......#.......#.......##...#..........#.##..........
|
||||||
|
...........##.#....#....#..#.....#...............#......................#...........#.....#...........#.#.......#..................
|
||||||
|
.#.......................#.#...##.#....#.#...........#.#....##.##......#........................##....#.#....#.....................
|
||||||
|
...#..................#.#...........##....###.................#....................##......#.....#............#.##....#.......##...
|
||||||
|
.#..................####...#.#..#.##.#...####...#......#....................#..........................#....#......................
|
||||||
|
.....#..........#.....#.#...............#.........##...#......#.#.....#...........#.....#............##......#.....#...............
|
||||||
|
......#........#....#..#............................###.#...##........#........#.................#..#........#...............##....
|
||||||
|
......................#.........................##....#...#..............#..#............#.#....#......##.#......#.........##......
|
||||||
|
..................#....#...#.#.......#..............#..#..#...#.......#...#.....#.....#...............#.#.#...............#........
|
||||||
|
...#...##......................##..##...........#......#.............#............#...........##.......#....#......................
|
||||||
|
.............................##...........##...#...#.....#....#.......#.#..#.....##...............#..#.#......#..............##....
|
||||||
|
...#..#.#...#.......#..................#............#....#.#.##.#.........#......#........#..#..........#....##...........#....#...
|
||||||
|
.....#.............................#......#.#.....#.##.#.................#.........#..#..#.#.#........................#.#.......#..
|
||||||
|
....#........#........#....#.#.#.....#.##............###.#..........#...##......#........##...#.........#.............#........#...
|
||||||
|
..#..............................#.............................#......#...................#...#......#.............#...............
|
||||||
|
.......#...#...............#.................##....................#....##.......#....##....##...#..................#..............
|
||||||
|
.........................#...#..#.....##.............#...##.......#.....#...#..............#.....#.#.#..#........................#.
|
||||||
|
......#.......##.#.............#....................#...#...........#...#..##....#.....#............#...........#........#.........
|
||||||
|
...#....#...#......#........................#.....#.........#......#........#.....#.#...........#.#..............#......#....#.....
|
||||||
|
........#..........#...................#...........##.#..#...#................#....##.............#................#....#..........
|
||||||
|
........#.......#....#.............#..........#...................#.#....#.#........#..#..............................#..........#.
|
||||||
|
............#........#....................#.#.........#......#.............#................#...#.............#....#...............
|
||||||
|
..#..............................#..#....##.....#......................##...#..#.........#......#......................#...#...#.#.
|
||||||
|
.##....#.............#...........##..................#...#..............#.......#................................#.........#.......
|
||||||
|
.....#......#.#.....##...........#.....#.......#..........##..#.............#.#.........#.#.#.............##........#......#..#....
|
||||||
|
.......#.......#.#.#..#......................#....#............##....#...........#.........................#......#................
|
||||||
|
.........##.........#..............#.#.#....#...#.......#.................................#..##..................##.###.##...#.....
|
||||||
|
......................#...#.#.......#..#.#..........#........#.......#.................#..................................#........
|
||||||
|
....##........#.........#.........................#................#......#...#.....#..................................#..#.#......
|
||||||
|
...##..............#..................#...#......#........###..#.......#..........#..............................#......#..........
|
||||||
|
.#.#.#....#..........#......#.#.........#.....#...............................#.....#.#............#....#........#.............#...
|
||||||
|
........#.........#.........#......................#..#......##.....#..#..........................#......##....#......##.##.....#..
|
||||||
|
.##...#.......#.#....#..#.#...................#.........#....#...........#.....#.........#............##......#............#.......
|
||||||
|
.##..#.........#..........#.#.................................#.#.#...............................#............#......##...#.#.....
|
||||||
|
......#........#..#...#............#..............#............#......##.....#.................................#......#.#.....#....
|
||||||
|
..........#........#...........#....................................#.....#...............................#............##....#.##..
|
||||||
|
........#.............#..#......##..................#.............#..#...#.#.....#...#...............#........................#....
|
||||||
|
....#...............#..........#....#...........................#....##.##...................#.#.......#...#.##....#........##..#..
|
||||||
|
......#.....#..#..........###...#.................####.###..........#...........#..........#......#............................#...
|
||||||
|
.#...#......#........#..#............##...............#.##......#...#.....#....................#.........#............#...#........
|
||||||
|
................##...................#.##..............#...#..#.......#.......###........#..#..#........#...##.....................
|
||||||
|
..............#....#..#..#.............##..............#................................#.....#..#....###.##..............#........
|
||||||
|
..#..............#........................................#..........#.....#..................#............#..#....................
|
||||||
|
.........#...#.....#...#...##...........#.###............##...#........#......................##......#....#.......#...............
|
||||||
|
....#....#.....#.......#......................................#.#.#....#..#..#..........#...................#........#...#.........
|
||||||
|
..#..#..................#..............#...#..#.........#......#....#.#................##..........#..#................#...........
|
||||||
|
...#...................#...........#....#...#.............##...#.......#.#..........#..#...............#....#....#.............#...
|
||||||
|
.......................##.#.#..##........#....#.........#.#.#.....##..............#.......#.......##.#..........#.#................
|
||||||
|
.....#..#..................#..##....#.......#.............#...#.....#.............#.............#.#...............#.....##......##.
|
||||||
|
...#.#.....#..........#.#............#..#..........................##.............#....#.......#.#...#...#....................#.#..
|
||||||
|
............##.#............#....#....#....#..##...#...............................#...#...#.........#.......................##.##.
|
||||||
|
....#.#...............#...#.......#............#..#...........................#..............#..........#....#...#...#..#...#....#.
|
||||||
|
.......#..#..#.#..#......#..........................#...............#.........#...........#................#..#...#................
|
||||||
|
...#..#...#.....#.#.......#....................................................#........#..........#.#...#......#..........#.......
|
||||||
|
..#...#.......#..#..............#.#...#.....#...#....#............#..........##...#.........##.............#.......................
|
||||||
|
...#.............#...#....#...#.....#.#.#..............#..........#........#........##...........#..#.#......................#.....
|
||||||
|
.#.......#.................#...............#..........#.....................#.....#............#......##....#.....#...#....###.....
|
||||||
|
...##...........#..........#.#........#............#..#.#........................#.....##............#...##.#.......#.##....#......
|
||||||
|
...........#........#...........#.......#......#...#.....#............................#........#..#................#...#....##.....
|
||||||
|
...##.##.........#.####..#............#..#.....#.......................#......#..........#.#..#.#....##........#....#.....#..#..##.
|
||||||
|
...................................................................................................................................
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||||
|
|
||||||
|
func run(scan *bufio.Scanner) (*result, error) {
|
||||||
|
|
||||||
|
for scan.Scan() {
|
||||||
|
_ = scan.Text()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result{}, nil
|
||||||
|
}
|
||||||
@@ -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, 0)
|
||||||
|
is.Equal(result.valuePT2, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 0)
|
||||||
|
is.Equal(result.valuePT2, 0)
|
||||||
|
}
|
||||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,30 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||||
|
|
||||||
|
func run(scan *bufio.Scanner) (*result, error) {
|
||||||
|
|
||||||
|
for scan.Scan() {
|
||||||
|
_ = scan.Text()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result{}, nil
|
||||||
|
}
|
||||||
@@ -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, 0)
|
||||||
|
is.Equal(result.valuePT2, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 0)
|
||||||
|
is.Equal(result.valuePT2, 0)
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
module go.sour.is/advent-of-code
|
module go.sour.is/advent-of-code
|
||||||
|
|
||||||
go 1.21.4
|
go 1.23.2
|
||||||
|
|
||||||
toolchain go1.21.5
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/matryer/is v1.4.1
|
github.com/matryer/is v1.4.1
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package aoc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
@@ -109,8 +111,8 @@ func (m *cmap[C, N]) String() string {
|
|||||||
|
|
||||||
for k, nbs := range m.neighbors {
|
for k, nbs := range m.neighbors {
|
||||||
fmt.Fprintln(b, k)
|
fmt.Fprintln(b, k)
|
||||||
for to, v := range nbs {
|
for to, c := range nbs {
|
||||||
fmt.Fprintln(b, " ", to, k)
|
fmt.Fprintln(b, " ", to, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package main
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"bufio"
|
||||||
|
"strings"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
func main() {
|
||||||
|
//Enter your code here. Read input from STDIN. Print output to STDOUT
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
|
var nodes int
|
||||||
|
var tree *node
|
||||||
|
var target [2]int
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
text := scanner.Text()
|
||||||
|
if nodes == 0 {
|
||||||
|
nodes, _ = strconv.Atoi(text)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if tree == nil {
|
||||||
|
for _, s := range strings.Fields(text) {
|
||||||
|
v, _ := strconv.Atoi(s)
|
||||||
|
tree = insertNode(tree, &node{value:v})
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, s := range strings.Fields(text) {
|
||||||
|
v, _ := strconv.Atoi(s)
|
||||||
|
target[i] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if target[0]>target[1] {
|
||||||
|
target[0], target[1] = target[1], target[0]
|
||||||
|
}
|
||||||
|
fmt.Fprintln(os.Stderr, tree)
|
||||||
|
if n := lsa(tree, target); n != nil {
|
||||||
|
fmt.Println(n.value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
type node struct{
|
||||||
|
value int
|
||||||
|
left *node
|
||||||
|
right *node
|
||||||
|
}
|
||||||
|
func insertNode(root, n *node) *node {
|
||||||
|
if root == nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
if root.value > n.value {
|
||||||
|
root.left = insertNode(root.left, n)
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
root.right = insertNode(root.right, n)
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *node) String() string {
|
||||||
|
if n == nil { return "nil" }
|
||||||
|
return fmt.Sprintf("%v (%v %v)", n.value, n.left, n.right)
|
||||||
|
}
|
||||||
|
|
||||||
|
func lsa(tree *node, target [2]int) *node {
|
||||||
|
if tree == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if target[0]>tree.value {
|
||||||
|
return lsa(tree.right, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
if target[1]<tree.value {
|
||||||
|
return lsa(tree.left, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Complete the 'countingSort' function below.
|
||||||
|
*
|
||||||
|
* The function is expected to return an INTEGER_ARRAY.
|
||||||
|
* The function accepts INTEGER_ARRAY arr as parameter.
|
||||||
|
*/
|
||||||
|
|
||||||
|
func countingSort(arr []int32) []int32 {
|
||||||
|
freq := make([]int32, 100)
|
||||||
|
for _, i := range arr {
|
||||||
|
freq[i]++
|
||||||
|
}
|
||||||
|
return freq
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||||||
|
|
||||||
|
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||||||
|
checkError(err)
|
||||||
|
|
||||||
|
defer stdout.Close()
|
||||||
|
|
||||||
|
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||||||
|
|
||||||
|
nTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||||
|
checkError(err)
|
||||||
|
n := int32(nTemp)
|
||||||
|
|
||||||
|
arrTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
||||||
|
|
||||||
|
var arr []int32
|
||||||
|
|
||||||
|
for i := 0; i < int(n); i++ {
|
||||||
|
arrItemTemp, err := strconv.ParseInt(arrTemp[i], 10, 64)
|
||||||
|
checkError(err)
|
||||||
|
arrItem := int32(arrItemTemp)
|
||||||
|
arr = append(arr, arrItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := countingSort(arr)
|
||||||
|
|
||||||
|
for i, resultItem := range result {
|
||||||
|
fmt.Fprintf(writer, "%d", resultItem)
|
||||||
|
|
||||||
|
if i != len(result) - 1 {
|
||||||
|
fmt.Fprintf(writer, " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, "\n")
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func readLine(reader *bufio.Reader) string {
|
||||||
|
str, _, err := reader.ReadLine()
|
||||||
|
if err == io.EOF {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimRight(string(str), "\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkError(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 119 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user