aboutsummaryrefslogtreecommitdiff
path: root/2021/18/first.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-12-20 23:15:56 +0100
committerJulien Dessaux2021-12-20 23:16:51 +0100
commit11088124920c7bc8bd1c54c4265e9dcafb7a024b (patch)
treed9743eaf93ad6abd7ae46a8abda07e19a0527ad6 /2021/18/first.go
parentAdded solutions for 17th day: target practice (diff)
downloadadvent-of-code-11088124920c7bc8bd1c54c4265e9dcafb7a024b.tar.gz
advent-of-code-11088124920c7bc8bd1c54c4265e9dcafb7a024b.tar.bz2
advent-of-code-11088124920c7bc8bd1c54c4265e9dcafb7a024b.zip
Added solutions for 18th day: snailfish arithmetic
Diffstat (limited to '')
-rw-r--r--2021/18/first.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/2021/18/first.go b/2021/18/first.go
new file mode 100644
index 0000000..ffe7050
--- /dev/null
+++ b/2021/18/first.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "os"
+
+ "git.adyxax.org/aoc/2021/18/pairs"
+)
+
+func main() {
+ parser := pairs.NewParser(os.Stdin)
+ pair, err := parser.Parse()
+ if err != nil {
+ log.Fatalf("%w", err)
+ }
+ for {
+ pair2, err := parser.Parse()
+ if err != nil {
+ break
+ }
+ pair = pair.Add(pair2)
+ }
+ fmt.Println(pair)
+ pair.Reduce()
+ fmt.Println(pair)
+ fmt.Println(pair.Magnitude())
+}