Browse Source

[2020-12-05] Add solutions for day05

master
Elis Hirwing 10 months ago
parent
commit
1abc9306a3
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 2
      Makefile
  2. 3
      day05/example.txt
  3. 891
      day05/input.txt
  4. 23
      day05/lib.go
  5. 14
      day05/parse.go
  6. 18
      day05/solve1.go
  7. 28
      day05/solve2.go
  8. 4
      main.go

2
Makefile

@ -15,6 +15,8 @@ day04:
go run main.go day04 input
day05:
go run main.go day05 input
day06:
day07:
day08:

3
day05/example.txt

@ -0,0 +1,3 @@
BFFFBBFRRR
FFFBBBFRRR
BBFFBBFRLL

891
day05/input.txt

@ -0,0 +1,891 @@
FBBBBBBRRL
BBFFFBBLRL
FBFFBFFLRL
FFBBBFBLRR
FFBFBFFLLL
BFBBBBFLLL
FFBFFFFLLR
FBBFBFBLRR
BBBFFFFRRR
BFBFFFBLLR
BFFBBFBLLL
FBBFFBFLRL
FBBBFBFRLR
BFBBBBBRRL
BBFFBBFLLR
FFBBBFBRRL
FFBBFFBLLL
BFFFFBFLLR
FBBFBBBLRR
FBBBFFFRRR
BFBFFFFLRL
BBFFFBBLRR
FBFBBFBLRR
FBBBBBFLLR
FFBBBFBRRR
BBBFFBBLLL
FFFBBBBLLR
FBBFBBFLLL
FBFFBFFRLL
BFBBFBFLLL
FFBBBBFRLR
BFBBFFBLLL
FFBFFBFLLR
BFBBBBFRLL
BBBBFFFRLR
FBFFFBBRRR
BBBFFBFRLR
BBFBFBFLRL
FBBBBBBRLR
FBBFFFBRRL
BBFBFBBLLL
BBFBFBFLLL
BBFBBBBRRL
BBBFFBFRRL
FBFBBBBLLR
BFFBFFFLLR
FBBBBFFRRR
BBFBFBFRLR
BFFFBBFLLR
BFBFFBFRLL
FFBFFFBRLL
BFFFFFBLRL
BFBFBFBLLR
BBFBBBBLLR
BFFBFBBRRL
FBFBBFBRRR
FBBBFBFRRR
FBFFFBBLLL
FBBFFFFLRL
FFBFFBBLLL
BFBBBFBRLL
BBBBFBFRRL
F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L
FBFBFBFLLR
BBFFBFBLRR
BFFBFBFRLR
BBBFBBFRRL
BBBFBBFLRL
FBFBFFBLLR
BFBFFBBRRR
FBFFFBFLLR
BBBFBFBRRR
BBBFFFFLLL
BBBFFBFRLL
BFBFFBBRLR
BFFFBBFRRR
BBBFFBBLLR
BFBFFFBLLL
FFFBBFBLRR
FBBFFBBLRL
FBBBBFFRLL
BFBFFBBRLL
BFFBBFBLRL
BBBBFFBRLL
BBFFFFBLLR
FFFBBBFLRL
FFFBBBBLRL
BBFFFFBRLL
FFFBBBFRLR
BBBFFFBRLL
FFBBFFBLLR
FFFBBBBRRR
BBFFBFFLLL
BFBBFBFRLR
BBBFBFFRRR
BFFBFFFLLL
BFBBFFBLLR
BBBFBBBLLL
FBBBBBBLLR
BBBFFFFRLL
FFBBFFBRLL
FBFBBBFRLR
BBFFFBFLRR
BBFBFBBRRR
BFBBFFFLLL
FBBFBBFLLR
FBFBBFBLLL
BFBBBBFLRR
BBBFBFFLLR
BFFBBBBRRL
BFBFFBBLRL
FFBFFBFLLL
FFBBFFFLLL
BFBBBFFLRL
BFFFFBBRRL
FFBBFBFLRL
FBBBBBBLRR
FFBFFBBRRL
BFFBBFBLRR
BBBBFFBRRL
BFFBBFFLLR
BFBBFFBRRL
FFFBBFBRRL
BFBBFFBLRL
FFBBFBBLLR
BFFFBFFLLR
BBFFBFBLRL
FBBBBFBRLL
FBBFBFBLLR
FFBFFFBLRL
FFBBFBBRRL
BBFFFFBRLR
FBFBFFBLLL
BFFBFFFLRR
BFBFBFFLLR
FFBFBFBLRL
BBFFFBBRRR
FBFBFBBLLR
FBFFBFBRLR
FBFFBBBRRR
FBBBFFBLLL
BBFBBBBRLL
FBBBFFFLRL
FFFBBFFRLR
BFBFFFBRRR
BFFBBFBRLL
FBBFFFFRLL

23
day05/lib.go

@ -0,0 +1,23 @@
package day05
import (
"log"
"strconv"
"strings"
)
func getSeatId(instruction string) int {
instruction = strings.ReplaceAll(instruction, "F", "0")
instruction = strings.ReplaceAll(instruction, "B", "1")
instruction = strings.ReplaceAll(instruction, "L", "0")
instruction = strings.ReplaceAll(instruction, "R", "1")
seatId, err := strconv.ParseInt(instruction, 2, 32)
if err != nil {
log.Fatal("Couldn't parse integer: ", err)
}
return int(seatId)
}

14
day05/parse.go

@ -0,0 +1,14 @@
package day05
import (
"git.elis.nu/etu/aoc2020/utils"
)
var rows []string
func ParseFile(input string) {
// Parse file
for _, line := range utils.GetLinesFromFile("day05/" + input + ".txt") {
rows = append(rows, line)
}
}

18
day05/solve1.go

@ -0,0 +1,18 @@
package day05
import (
"log"
"sort"
)
func Solve1() {
var seatIds []int
for _, row := range rows {
seatIds = append(seatIds, getSeatId(row))
}
sort.Ints(seatIds)
log.Printf("2020-12-05.01: Answer: %d\n", seatIds[len(seatIds)-1])
}

28
day05/solve2.go

@ -0,0 +1,28 @@
package day05
import (
"log"
"sort"
)
func Solve2() {
var seatIds []int
var missingSeat int
for _, row := range rows {
seatIds = append(seatIds, getSeatId(row))
}
sort.Ints(seatIds)
lastId := seatIds[0] - 1
for _, seatId := range seatIds {
if lastId != seatId-1 {
missingSeat = seatId - 1
break
}
lastId = seatId
}
log.Printf("2020-12-05.02: Answer: %d\n", missingSeat)
}

4
main.go

@ -8,6 +8,7 @@ import (
"git.elis.nu/etu/aoc2020/day02"
"git.elis.nu/etu/aoc2020/day03"
"git.elis.nu/etu/aoc2020/day04"
"git.elis.nu/etu/aoc2020/day05"
"git.elis.nu/etu/aoc2020/utils"
)
@ -28,5 +29,8 @@ func main() {
case "day04":
utils.Perf("2020-12-04", day04.ParseFile, day04.Solve1, day04.Solve2)
case "day05":
utils.Perf("2020-12-05", day05.ParseFile, day05.Solve1, day05.Solve2)
}
}

Loading…
Cancel
Save