Started AOC 2020 - solved the first 4.5 days.

This commit is contained in:
Anna Rose Wiggins 2020-12-08 09:09:09 +00:00
parent bab5f879b0
commit 04f29cdb4d
9 changed files with 389 additions and 0 deletions

46
2020/day05.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
)
func calculateSeatNumber(input string) int {
if input == "" {
return 0
}
row, err := strconv.ParseInt(strings.ReplaceAll(strings.ReplaceAll(input[0:7], "F", "0"), "B", "1"), 2, 32)
if err != nil {
log.Panicf(err.Error())
}
col, err := strconv.ParseInt(strings.ReplaceAll(strings.ReplaceAll(input[7:10], "L", "0"), "R", "1"), 2, 32)
if err != nil {
log.Panicf(err.Error())
}
return int((row * 8) + col)
}
func main() {
step := os.Args[1]
values := fileutils.InputParserStrings(os.Args[2])
switch step {
case "1":
max := 0
for _, line := range values {
seatNumber := calculateSeatNumber(line)
if seatNumber > max {
max = seatNumber
}
}
fmt.Println("Highest Seat Number:", max)
case "2":
// build a map of all seat numbers then just print the ones between 0 and 1024 that don't exist
}
}