commit 1b3f3dc5dc653da9efa35d575dea3ced8fa9fedc parent a89768987882d6fbcf70391a0c5c596048cfa0bd Author: Shimmy Xu <shimmy.xu@shimmy1996.com> Date: Sat, 5 Dec 2020 11:35:45 -0600 Add 2020 day 05 Diffstat:
A | 2020/day05/input.txt | | | 839 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | 2020/day05/main.go | | | 66 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 905 insertions(+), 0 deletions(-) diff --git a/2020/day05/input.txt b/2020/day05/input.txt @@ -0,0 +1,839 @@ +BFBFFFFLLL +BBFBBFBRLL +BFBBFFFRRR +FBFFBBBLLL +FFBBFBBRLL +BBBFFFFLRL +BFBBBFBRRR +FBBFFFBLRL +FFBFBBFLLR +FBFFFFBLRL +BBFFBBFRLL +BBFBBBBLLR +FFBBBBFRLR +BBFFBFFRLR +BFFBBFFRRL +BBFBBBFLLR +FBFBBBBRRL +BFFFBFFLRL +FBFFFBFRLL +FBBBFFBLRR +FFFBFBBRLR +FBBFBBFLLR +FBFBFFFLRL +BFFBFBFLLR +BBFBFBBRRL +BFFBBFBRLR +FBFBFFFRRL +BFBFFBBRRL +FBFBFBFLLL +BFFBFFBRRL +FFBBBBBRRL +FFFBFBFRLR +BBFFFBBLRL +BFBFBFFRLL +BFBFFFBRLR +FBBBFFFRRR +BBFFFBFRLL +FBBBFBFRLL +FFBBBFFLRR +FBFBBFBLRL +FBBBBBFLLR +FBFFBBBLRL +FFFBBFFRRL +FBBBFFFRLR +BBFBFFFRLR +BBFBBFBLLL +FBFFBBBRRL +BFFFFBFRRR +FBBFFBFLRR +FBFBBBFLRL +BFBBBBBRRL +BBFFFFBLRL +FBFFFBFLLL +FFFBBFFLLR +FBBBFBFLRR +BBBFFBFRRL +BFBFFFFRLR +FFBFFFBRLR +FBFFBFBRLL +FBBFFFFRLL +FFFBBFBRRR +FBBBBFFLRR +BFBBBFBRLR +BFFFFFFRR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BRRL +BFBFBFBRRR +FFFBBBFRLR +BBFFBFBLLR +BFBBBBFRLL +BBFBFFBLLR +FFBBFBBRRR +FBBBFBBLRL +BFBBBBFRRR +BFBFBFBRLL +BFBBFFFRRL +FFBFBFFRLL +FBBFBBFRLR +BFFBFFFRLL +BFBBBFBLRR +BBFFFFFRRR +FBFBBBBRLR +FFBBFBFRLR +FFBFFFFLLL +FBBFFBFRRR +FFBFFBFRLL +FBBFFBBLRR +FBBBFBFRLR +BFBBBBFLRR +FFBFBBBLLR +BFFFBBFRRR +FBBBFFBRLL +FBFBBBFLRR +BBFFBFFRLL +FBFFFFBRLL +FBFFBFBLRL diff --git a/2020/day05/main.go b/2020/day05/main.go @@ -0,0 +1,66 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func readInput(filename string) (res []string) { + file, _ := os.Open(filename) + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + res = append(res, scanner.Text()) + } + return +} + +func main() { + input := readInput("./input.txt") + // 919 + fmt.Println(part1(input)) + // 642 + fmt.Println(part2(input)) +} + +func decodeSeat(line string) int { + var row, col int + for i := 0; i < 7; i++ { + row <<= 1 + if line[i] == 'B' { + row += 1 + } + } + for i := 7; i < 10; i++ { + col <<= 1 + if line[i] == 'R' { + col += 1 + } + } + return row*8 + col +} + +func part1(input []string) (max_id int) { + for _, line := range input { + id := decodeSeat(line) + if id > max_id { + max_id = id + } + } + return +} + +func part2(input []string) int { + listed_id := make(map[int]bool) + for _, line := range input { + listed_id[decodeSeat(line)] = true + } + max_id := part1(input) + for i := 0; i < max_id; i++ { + if !listed_id[i] && listed_id[i-1] && listed_id[i+1] { + return i + } + } + return 0 +}