diff options
author | Julien Dessaux | 2021-12-07 14:26:36 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-12-07 14:26:36 +0100 |
commit | 6ed18289c89eaff3557907df63cf58bd2009b3ee (patch) | |
tree | 903d730030c18ab25c212938794c1c03f65f800f /2021/02 | |
parent | Initial import (diff) | |
download | advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.tar.gz advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.tar.bz2 advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.zip |
Added the first days
Diffstat (limited to '')
-rw-r--r-- | 2021/02/first.b98 | 5 | ||||
-rw-r--r-- | 2021/02/first.go | 42 | ||||
-rw-r--r-- | 2021/02/input | 1000 | ||||
-rw-r--r-- | 2021/02/second.b98 | 5 | ||||
-rw-r--r-- | 2021/02/second.go | 44 |
5 files changed, 1096 insertions, 0 deletions
diff --git a/2021/02/first.b98 b/2021/02/first.b98 new file mode 100644 index 0000000..fd7a917 --- /dev/null +++ b/2021/02/first.b98 @@ -0,0 +1,5 @@ +v pos in 0,0, depth in 1,0 +>00p10p>#;~:'f-#v_$&00g+00p v@,a.*g01g00; + >'d-#v_$&10g+10pv + >&10g\-10p v + ^ ;,a.g01.g00; ~ < # we do not forget to strip the \n from the input diff --git a/2021/02/first.go b/2021/02/first.go new file mode 100644 index 0000000..1550bcb --- /dev/null +++ b/2021/02/first.go @@ -0,0 +1,42 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strconv" + "strings" +) + +func main() { + f, err := os.Open("input") + if err != nil { + log.Fatalf("%+v", err) + } + defer f.Close() + + scanner := bufio.NewScanner(f) + scanner.Split(bufio.ScanLines) + + pos := 0 + depth := 0 + for scanner.Scan() { + elts := strings.Split(scanner.Text(), " ") + i, err := strconv.Atoi(elts[1]) + if err != nil { + log.Fatalf("%+v", err) + } + switch elts[0] { + case "forward": + pos += i + case "down": + depth += i + case "up": + depth -= i + default: + panic(elts[0]) + } + } + fmt.Println(pos * depth) +} diff --git a/2021/02/input b/2021/02/input new file mode 100644 index 0000000..594c25f --- /dev/null +++ b/2021/02/input @@ -0,0 +1,1000 @@ +forward 5 +down 9 +forward 2 +up 2 +forward 4 +forward 4 +up 5 +down 3 +forward 2 +forward 9 +down 7 +forward 2 +down 2 +forward 1 +up 9 +forward 1 +forward 4 +up 5 +down 9 +forward 8 +forward 3 +up 1 +down 2 +down 3 +forward 7 +forward 2 +up 3 +forward 9 +forward 9 +down 3 +up 8 +forward 5 +forward 7 +forward 2 +down 7 +forward 5 +down 4 +up 7 +forward 8 +forward 1 +down 3 +down 1 +forward 6 +up 7 +forward 6 +down 3 +forward 9 +forward 6 +up 3 +down 1 +forward 8 +up 7 +down 9 +down 2 +down 1 +down 5 +forward 4 +down 8 +forward 2 +down 5 +down 6 +down 5 +forward 5 +down 8 +up 8 +forward 3 +forward 4 +forward 8 +forward 9 +down 2 +forward 7 +forward 3 +forward 9 +down 3 +up 1 +down 5 +forward 2 +down 9 +down 2 +down 5 +down 2 +down 9 +up 3 +forward 6 +up 9 +down 1 +forward 8 +up 6 +down 1 +forward 1 +up 1 +forward 3 +down 8 +down 1 +down 9 +forward 4 +forward 1 +down 3 +forward 8 +down 9 +forward 7 +up 6 +down 8 +down 6 +down 8 +down 7 +down 1 +down 8 +down 1 +forward 5 +down 9 +forward 4 +down 2 +forward 8 +up 1 +forward 7 +down 7 +down 6 +forward 4 +forward 6 +down 2 +down 2 +up 7 +down 2 +up 9 +forward 6 +forward 3 +down 8 +forward 9 +down 9 +down 9 +down 8 +forward 2 +forward 5 +forward 8 +forward 1 +down 3 +forward 1 +forward 2 +forward 9 +up 5 +forward 4 +forward 2 +down 6 +forward 3 +forward 7 +forward 1 +forward 8 +down 7 +forward 4 +up 3 +down 9 +up 2 +forward 2 +forward 7 +down 9 +up 9 +forward 9 +up 8 +up 7 +down 8 +down 9 +forward 1 +forward 5 +up 7 +down 3 +up 9 +forward 9 +down 4 +down 7 +down 7 +down 1 +down 4 +down 5 +up 2 +forward 2 +forward 2 +forward 6 +down 7 +forward 7 +down 5 +forward 8 +down 7 +forward 6 +down 2 +up 2 +down 5 +down 1 +up 4 +down 8 +up 9 +forward 1 +down 9 +down 6 +down 8 +up 7 +up 1 +forward 7 +down 8 +forward 1 +down 4 +down 2 +forward 3 +forward 6 +forward 8 +down 2 +forward 7 +forward 8 +up 3 +down 1 +down 8 +up 3 +down 4 +down 5 +forward 6 +forward 9 +down 3 +up 2 +down 9 +up 2 +down 3 +down 9 +forward 4 +forward 6 +down 7 +down 8 +down 4 +forward 7 +up 2 +down 5 +up 3 +down 5 +up 1 +up 1 +forward 5 +forward 9 +down 9 +up 4 +up 4 +up 8 +up 5 +forward 7 +forward 6 +up 6 +down 5 +forward 4 +forward 3 +up 6 +down 6 +forward 5 +up 6 +up 7 +forward 1 +forward 2 +forward 5 +down 3 +forward 6 +down 6 +down 3 +up 9 +down 4 +down 5 +down 4 +forward 1 +down 1 +forward 3 +up 4 +forward 1 +forward 5 +up 3 +forward 6 +forward 5 +forward 9 +forward 6 +down 2 +forward 2 +down 1 +down 4 +forward 6 +forward 8 +down 8 +up 5 +forward 8 +forward 3 +forward 1 +forward 3 +forward 6 +down 1 +down 9 +up 7 +down 2 +forward 6 +down 4 +down 7 +down 5 +forward 2 +down 1 +forward 2 +forward 8 +forward 4 +up 3 +down 1 +forward 6 +forward 3 +down 3 +down 9 +forward 1 +up 5 +forward 3 +forward 3 +up 5 +down 7 +forward 8 +up 5 +forward 2 +forward 2 +down 6 +up 8 +up 5 +forward 2 +forward 1 +down 9 +forward 7 +down 5 +forward 3 +down 3 +down 5 +down 5 +up 7 +down 8 +forward 2 +forward 4 +forward 5 +forward 1 +down 6 +forward 3 +down 1 +down 7 +forward 3 +forward 7 +down 5 +down 3 +forward 6 +down 3 +down 2 +down 4 +down 9 +forward 7 +down 2 +up 2 +up 6 +up 9 +up 8 +forward 9 +down 1 +forward 4 +forward 2 +forward 7 +forward 2 +down 8 +down 3 +forward 4 +forward 6 +down 8 +forward 7 +forward 6 +up 3 +down 6 +down 1 +down 3 +down 8 +down 2 +down 7 +down 9 +forward 4 +forward 7 +forward 8 +forward 5 +forward 9 +up 5 +down 2 +forward 9 +forward 6 +up 6 +forward 7 +down 2 +down 3 +forward 4 +down 6 +down 1 +down 2 +down 8 +forward 3 +down 3 +forward 3 +down 5 +up 8 +down 5 +forward 8 +down 1 +forward 1 +forward 4 +forward 7 +down 2 +down 5 +forward 5 +down 8 +forward 2 +down 2 +forward 5 +forward 6 +forward 4 +down 7 +up 7 +down 1 +forward 7 +forward 8 +down 6 +up 7 +forward 6 +up 6 +down 8 +forward 5 +forward 8 +up 4 +up 2 +up 1 +down 8 +down 6 +up 2 +down 5 +down 1 +forward 5 +forward 7 +down 2 +up 3 +up 3 +forward 9 +down 1 +forward 6 +down 2 +forward 2 +down 1 +down 9 +forward 7 +down 5 +down 8 +up 1 +forward 1 +down 7 +forward 3 +down 4 +up 4 +down 6 +forward 1 +forward 3 +down 2 +forward 3 +forward 5 +forward 6 +up 2 +up 9 +forward 4 +down 4 +up 1 +up 3 +forward 8 +forward 1 +down 9 +down 9 +forward 2 +down 1 +up 9 +up 3 +up 1 +up 5 +forward 6 +down 9 +forward 6 +forward 9 +forward 6 +forward 4 +up 2 +down 6 +up 3 +forward 3 +forward 1 +up 4 +forward 7 +down 9 +down 3 +forward 9 +down 4 +down 8 +down 3 +up 8 +down 8 +down 8 +forward 2 +forward 8 +up 9 +forward 2 +up 6 +forward 7 +down 1 +forward 5 +forward 4 +forward 1 +forward 7 +up 9 +down 8 +forward 1 +up 5 +forward 9 +forward 2 +forward 8 +down 1 +forward 7 +down 2 +up 8 +down 6 +up 9 +up 3 +down 6 +forward 5 +down 1 +forward 1 +forward 6 +forward 6 +up 1 +forward 5 +forward 1 +up 2 +forward 9 +forward 6 +down 3 +up 1 +forward 7 +forward 2 +down 1 +forward 6 +down 3 +up 2 +down 3 +down 8 +forward 4 +down 2 +up 7 +down 6 +up 5 +down 7 +forward 4 +down 9 +down 3 +forward 2 +up 5 +up 4 +forward 9 +down 1 +up 2 +forward 4 +down 9 +down 8 +forward 5 +forward 2 +down 5 +forward 6 +down 4 +forward 7 +forward 1 +forward 6 +down 3 +down 9 +forward 9 +forward 2 +forward 6 +down 7 +down 5 +down 3 +forward 7 +down 3 +down 3 +down 4 +down 4 +down 7 +down 7 +down 7 +up 7 +up 9 +up 7 +up 3 +up 4 +down 9 +down 4 +up 3 +forward 2 +up 1 +down 9 +down 6 +up 1 +up 2 +down 7 +down 9 +up 2 +forward 7 +down 4 +forward 3 +down 1 +down 7 +forward 7 +up 7 +forward 3 +forward 1 +forward 6 +forward 2 +down 9 +forward 8 +up 8 +down 8 +down 9 +up 1 +down 4 +down 6 +down 8 +up 4 +down 1 +forward 1 +forward 1 +forward 4 +forward 7 +forward 1 +down 4 +forward 5 +up 3 +forward 4 +down 5 +down 1 +up 2 +down 7 +forward 7 +down 7 +up 9 +down 9 +down 3 +up 2 +up 8 +up 8 +up 7 +forward 7 +forward 5 +forward 3 +forward 2 +down 5 +forward 4 +forward 1 +down 6 +down 1 +forward 8 +down 6 +down 3 +down 5 +down 9 +down 3 +forward 7 +forward 6 +down 6 +forward 9 +up 7 +forward 3 +up 5 +down 5 +down 5 +forward 4 +up 6 +down 6 +forward 3 +up 2 +forward 4 +up 1 +down 5 +forward 6 +forward 9 +down 2 +up 2 +down 2 +up 7 +forward 3 +up 2 +forward 9 +forward 5 +down 5 +down 7 +down 8 +down 6 +up 9 +up 5 +forward 7 +down 8 +down 1 +forward 7 +up 2 +forward 4 +forward 2 +up 9 +down 8 +forward 1 +forward 7 +down 2 +down 3 +down 6 +down 3 +forward 1 +up 6 +forward 8 +down 9 +down 9 +forward 8 +up 8 +down 6 +forward 4 +up 1 +forward 5 +down 3 +down 7 +down 7 +down 3 +up 2 +forward 4 +down 9 +forward 2 +down 9 +forward 9 +forward 4 +forward 5 +down 4 +forward 1 +up 1 +forward 4 +up 3 +up 4 +forward 7 +down 9 +forward 6 +down 1 +down 1 +down 2 +down 4 +forward 7 +forward 8 +forward 6 +down 8 +forward 2 +down 3 +up 5 +forward 2 +up 5 +forward 8 +down 8 +down 8 +up 8 +forward 6 +up 1 +down 3 +forward 6 +down 1 +forward 9 +up 1 +forward 7 +forward 7 +down 1 +forward 5 +forward 2 +up 7 +down 1 +forward 2 +down 4 +forward 3 +down 9 +forward 6 +up 5 +forward 1 +forward 5 +down 7 +forward 6 +down 8 +forward 9 +down 1 +forward 9 +down 1 +forward 5 +up 9 +forward 1 +forward 6 +forward 5 +down 7 +down 6 +down 5 +down 9 +forward 9 +down 2 +down 8 +down 8 +forward 2 +forward 3 +forward 3 +down 3 +forward 8 +forward 8 +down 8 +forward 1 +up 1 +forward 4 +down 7 +forward 1 +up 2 +forward 9 +forward 1 +down 6 +up 9 +down 3 +down 1 +up 1 +up 6 +up 7 +forward 9 +up 2 +forward 4 +up 8 +down 6 +forward 3 +forward 7 +down 6 +down 5 +down 3 +forward 5 +down 1 +forward 2 +forward 9 +down 8 +up 6 +forward 3 +forward 2 +up 7 +down 3 +forward 5 +forward 9 +down 5 +down 1 +up 4 +down 8 +forward 1 +forward 3 +forward 3 +down 2 +forward 5 +down 1 +forward 2 +up 3 +forward 8 +down 2 +up 8 +down 6 +down 8 +forward 4 +down 4 +up 7 +up 6 +down 7 +forward 2 +up 3 +forward 3 +down 8 +forward 8 +down 5 +forward 5 +down 3 +up 7 +down 1 +down 2 +up 8 +down 6 +up 6 +down 7 +forward 5 +up 3 +forward 7 +forward 2 +down 9 +down 1 +down 4 +down 7 +forward 9 +up 7 +forward 5 +up 8 +forward 8 +up 1 +forward 2 +down 7 +down 5 +down 6 +down 4 +up 4 +forward 5 +forward 6 +up 4 +forward 8 +forward 4 +forward 3 +up 5 +down 6 +up 4 +forward 8 +down 7 +forward 3 +down 2 +down 7 +down 5 +down 4 +forward 5 +up 4 +forward 4 +down 7 +down 3 +down 9 +down 7 +forward 2 +forward 1 +down 7 +down 8 +forward 1 +forward 2 +down 5 +up 1 +down 1 +forward 5 +down 2 +forward 9 +forward 7 +down 2 +forward 6 +forward 9 +up 5 +forward 3 +up 5 +forward 7 +down 6 +down 3 +up 3 +down 4 +forward 2 +up 4 +forward 5 +up 9 +down 3 +up 1 +down 1 +up 3 +forward 4 +forward 5 +down 3 +forward 5 +down 6 +down 2 +forward 5 +forward 3 +down 7 +down 8 +forward 4 +down 5 +forward 7 +forward 2 +forward 7 +down 7 +up 1 +forward 6 +down 1 +forward 1 +down 4 +forward 1 +up 6 +forward 8 +forward 6 +forward 7 +up 6 +up 7 +up 2 +down 9 +forward 4 +up 3 +down 1 +down 1 +forward 3 +down 4 +down 6 +down 8 +forward 9 +forward 6 +down 1 +forward 5 diff --git a/2021/02/second.b98 b/2021/02/second.b98 new file mode 100644 index 0000000..2c5504c --- /dev/null +++ b/2021/02/second.b98 @@ -0,0 +1,5 @@ +v pos in 0,0, depth in 1,0, aim in 2,0 +>00p10p20p>#;~:'f-#v_$&:00g+00p v@,a.*g01g00; + >'d-#v_$&20g+20pv>20g*10g+10pv + >&20g\-20p v < + ^ ;,a.g01.g00; ~ << # we do not forget to strip the \n from the input diff --git a/2021/02/second.go b/2021/02/second.go new file mode 100644 index 0000000..e6d0e94 --- /dev/null +++ b/2021/02/second.go @@ -0,0 +1,44 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strconv" + "strings" +) + +func main() { + f, err := os.Open("input") + if err != nil { + log.Fatalf("%+v", err) + } + defer f.Close() + + scanner := bufio.NewScanner(f) + scanner.Split(bufio.ScanLines) + + aim := 0 + pos := 0 + depth := 0 + for scanner.Scan() { + elts := strings.Split(scanner.Text(), " ") + i, err := strconv.Atoi(elts[1]) + if err != nil { + log.Fatalf("%+v", err) + } + switch elts[0] { + case "forward": + pos += i + depth += i * aim + case "down": + aim += i + case "up": + aim -= i + default: + panic(elts[0]) + } + } + fmt.Println(pos * depth) +} |