2020-12-08 09:09:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2020-12-14 23:27:46 +00:00
|
|
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
2020-12-08 09:09:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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]
|
2020-12-14 23:27:46 +00:00
|
|
|
values := util.InputParserStrings(os.Args[2])
|
2020-12-08 09:09:09 +00:00
|
|
|
|
|
|
|
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
|
2020-12-09 09:18:03 +00:00
|
|
|
seatMap := make(map[int]bool)
|
|
|
|
for _, line := range values {
|
|
|
|
seatNumber := calculateSeatNumber(line)
|
|
|
|
seatMap[seatNumber] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 1024; i++ {
|
|
|
|
if _, ok := seatMap[i]; !ok {
|
|
|
|
fmt.Println("Didn't find seat ", i)
|
|
|
|
}
|
|
|
|
}
|
2020-12-08 09:09:09 +00:00
|
|
|
}
|
|
|
|
}
|