Added the first days
This commit is contained in:
parent
7ebc2cd003
commit
6ed18289c8
26 changed files with 6168 additions and 0 deletions
5
2021/02/first.b98
Normal file
5
2021/02/first.b98
Normal file
|
@ -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
|
42
2021/02/first.go
Normal file
42
2021/02/first.go
Normal file
|
@ -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)
|
||||
}
|
1000
2021/02/input
Normal file
1000
2021/02/input
Normal file
File diff suppressed because it is too large
Load diff
5
2021/02/second.b98
Normal file
5
2021/02/second.b98
Normal file
|
@ -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
|
44
2021/02/second.go
Normal file
44
2021/02/second.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue