From de54724f21ae55f717e652b3ad1aca9a78a2321a Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 20 Dec 2021 23:55:42 +0000 Subject: [PATCH] day 20a incomplete --- day20/20a/main.go | 78 +++++++++++++++++++++++++++++++++++ day20/input | 102 ++++++++++++++++++++++++++++++++++++++++++++++ day20/testInput | 7 ++++ 3 files changed, 187 insertions(+) create mode 100644 day20/20a/main.go create mode 100644 day20/input create mode 100644 day20/testInput diff --git a/day20/20a/main.go b/day20/20a/main.go new file mode 100644 index 0000000..90b630f --- /dev/null +++ b/day20/20a/main.go @@ -0,0 +1,78 @@ +package main + +import ( + "AdventOfCode2021/shared" + "bufio" + "fmt" + "os" + "strconv" +) + +func main() { + //content := returnContent("../input") + content := returnContent("../testInput") + + fmt.Println(*content) + + key := (*content)[0] + + input := [][]int{} + + for i := 2; i < len(*content); i++ { + input = append(input, (*content)[i]) + } + + for x := 1; x < len(input)-1; x++ { + for y := 1; y < len(input[0]); y++ { + binary := GetSurroundingValue(&input, x, y) + newValue := shared.BinaryToInteger(&binary) + + fmt.Println(newValue, key[newValue]) + + } + } + +} + +func GetSurroundingValue(input *[][]int, xVal int, yVal int) (binary string) { + for x := xVal - 1; x <= xVal+1; x++ { + for y := yVal - 1; y <= yVal+1; y++ { + binary += strconv.Itoa((*input)[x][y]) + } + } + return +} + +func returnContent(path string) *[][]int { + //read file and return it as an array of integers + + file, err := os.Open(path) + var content [][]int + + if err != nil { + fmt.Println("Unlucky, the file didn't open") + return &content + } + defer file.Close() + + scanner := bufio.NewScanner(file) + + for scanner.Scan() { + line := scanner.Text() + + nums := []int{} + + for i := 0; i < len(line); i++ { + num := 0 + + if line[i] == '#' { + num = 1 + } + + nums = append(nums, num) + } + content = append(content, nums) + } + + return &content +} diff --git a/day20/input b/day20/input new file mode 100644 index 0000000..31095db --- /dev/null +++ b/day20/input @@ -0,0 +1,102 @@ +##..#..##.#..#...####..#.#..##.###.......###.###..#..######...#.#....#...##.###.......#.#..####.#..#......#.#...##.#..##.#.##.#..####.#..##.....#.....#....###.#.#....##..##.##.####.##.###..###..####..#.#.#####..#####.####..######.##....#..#.#...#..##..###....#...#####.#..###...##..#.######..#.##.#....######.....###..##..######.....#..##.##..#.###...####.#...#.##.#.#....####.##.###...####.#.#.#.###..##..##....#.#.#..###.##.###..##.#...##.#.#####.#..#...####..###.###...###.#..#..##.#...#....##.#....##...##.#. + +#..##.#..#.##..#.#.##...##.####.....#..#.#######.#.####.##.#.#......#.#..####.#..#####.#...###..###. +.#...#...#..###.#..#.......########..###...###.#....######.#.#..##..#..###..####.#.#..#..#..#.#.#..# +#.##....#.###..#.#....###..#....##.##..#####.###.#.#.....#.###...#.#..#.###.##..##..#..#..#########. +.#######.##.#########.#..###...#..#.###...##..#.#########..#.##.#.##..###..##.#.###..##.#.###.#..#.. +#......####.#.....###..#...####.####.###...#.##.##.##.....#.#..#....#..###.....##.#.#...###.##.##.## +...##.#####.#.#..##...##....#.#..#.#...###..#.#.#..#.#..##..#.##.#.##.####.#..#....##.##..##.##.###. +#.#...##..##..#...##..##.######.#..##..#.##.#########..##.#.#..#..#...#########..#.###..####..#...## +#####..####..###...##...#.##.##.#..#.#....#....#.#####....##..###.#####.##..#.##...###..##...#.#.### +.#.##.####.....#.#.##.####.##.####.######..##..#.#..###..#.##.#####.#.####.#.##.#.#......########.#. +..#......##...##...#..###....#....####..###.##..####...#.#..#.#...#...##.##.#...#.#........#........ +.....#.#.#..#..#.####.#...####.#####.###.#.#.##.#.#.#.......#.#..##.#.###..##........###.....##..##. +##...#.###...####.#...##..##..##.#.###..##.##..##..###..###.#.##.#.##...#.#..###.##..#....###..#.##. +##.##....##..#.....###.#####.....##..##..###..###.#...##..#..#..###....#...#.##.###.##.##...#.....#. +###.######.#.#....#.#....##...####..#.##....#.##..##.#####.#.......#....#.#.#####.#..###...##.##...# +##.##.###.#..##.###....#.##..........##.##.#...#...#..###......#..#.###..##.#####.###..##.###.###.#. +..##.....#.####...##.....##.#..#....##...#.#...#..###..#..##.###.#...#..#.###.#.....#.#.###.##..#.## +#..#.######.#.#.####.#.#####..#..#..#.##..#..##.#...#.....##..#....#.#..#.##..###..#..##.#########.. +..#.#.###.....##.#.##.#.##...###...#######.###.#...#..#.###.#.#..#....##..#.#..##....#.##.#.##....## +#.#.##.#.#.###..#.#..#.####..#....#...#..##..####....#.#...#.#...#.#.....#..###.##.#..#.##...#.#..#. +..###...#..###...##..##....#.....#.#.##.......##..#...##.##.##...####.#..#..##.....##..#..#..#.....# +..#.#....#..###..###..###.....##.#..##.##.###..#.##.#.#...##..#.......#.#....####...#.#####...#..##. +.#.######...#.....#....#.##.#.#.#####.##.#.#.#.#..###...#.#..#..##.###.##.....##.#..#.####.#.....#.. +....#.#...##..#..##.###.#######..##...#..##..########..##....#........#..###.##.#.##.......##.#.#### +##.#.##..#..#.....##...#.#...###.##.#..#..####....###..#..#....#..#..##....###..#..#..#..###...#.... +##..##.#..#.##.#.#####..#.#.##.#.####..#.#.#.#.#..#.#....######.#..##.......###..#.###.#..##..#.##.. +###...##.####.#.#..#####.....###.#.####...###.#.#.#....###.####.##.####..##..##..#.#.####...#..#.##. +..##..#..#.###.######..##..####.#......#.#.###.#.#...#....#.#....#.##.#####.....#.##.#.#.#.##.##..#. +#.#..#.#.#.###..##..#####..##....#.###..##.##..#.#..###.....##.#.#.#####........#####.#####.#.#..#.# +..#.##.....#..###...#.......#.#.##..#.#....#####.###.###.########.#.#.###..#..##...#..#..#........## +#..##.#..#....##.#....####.#..##..#......#....##.#...#..##.##.###...#.....##....#.####.#...#.###.##. +###.###.#..####.##..###..##..###..#..##.#.#.####...#..##..#..###.##.#..##..####.#.###..#...##.....#. +##..###...#...#.#.#.##.#####..#..####.#.#...#..#.#.#.#.#.##.####...########..#.###..##.#..#.#######. +######.##.#.#.#.#.######.##.####..####.#.#..#...###.....#.###..#.#.#.###.#......#..#..##..###.###... +#.##.##.###..###.#.#...#.#.#.#....#.#...#.###..####.#.##.....##.##..##....##..#.##...#.........#.### +.#..##....#.#..#.#..#....#.##.####.##.#.#...#.#.##.#..#..#.###..#..####..##......##.#.#....##..#...# +.#..#####...#.#..#.#....#.#.###########..##........##.###.##..#..##...###..##.#####..###.#.##...#... +###..##...#..##.###....#####...#.##...#..#.....#.##.#.####...##...######..#.#.##...########....#.#.# +##..####.##.#...#.#.###..###..#...##...#....##..#.....##.#.###....#..#...#.##...#.###.....###..###.# +#.###.#.##...##....####.#.#.###.#.#.#....#.##.........##..#.###..##..#...#.#.##....#..#.###.#..##... +#....#####..#.#.##..##...#...#.....#.#.#..##.#.##.#...##.###.###...#.###.#.##.####..#.....###..###.. +#...#####.###.#....#..#..#..#.#.#..###....#.#.###.##.##.##..##..#..####.#...#.#.#.##....#....#.##.## +.##.....#.......#..##.##..#...##..#...#....#.#......##.#.####.#.#####.##...##.#.....#.#.###.#.####.# +#.###.#..#.###...#.........##..##..#.#.#.#..#.#..#..#.##..#.....##....##..##.#...##..###.#.#.#....#. +#####.####..###.##.###.###..#.##..######..###.##..#..##..#.##.#.#.###...#####.##.#..###.#.##.##.#... +.##.#...#.#.#....##.##...####.##..##.#.#.#.#..##.#.#.##.####....####.#.##..##...#......#.#####.##..# +.####......#.#.#...#.###.##..####.#.#..#.##.#.##...#..##.#.#..#....#.#.#..#..##..##.#...#.#.##.##.#. +.####..###.#.....#..#.##......####....#.#.#...##.#....##.#.#######...#..#..##....#...###..#.##.....# +###......##..####.#..#.#..###....#.##.#......#...#..##..#.#.#.##..##.##..#.#..#######..#..##.##.#... +#.#.#...##.#.#...#........##.#..#.#.#..#..##.#.......#..#.####..###.##..#.##.#....##.##..###..####.# +...####...##...#.##.#.##....#.###..##.###..##...#..#####...###.....###.##.###.##.#..#....#.##.#.#..# +.###.#..#..#...#..#.#.#.##.##..#.##.#.#...##..#......#...#..##.#.#.....#.#.....#.##....#..#....##... +.....#.##..#...###.#..#.....#####..#.....#.#.###.####....#.###.#.####.###.#.##.#.###.#.##.###..#.... +.#.#..##....#...#..##.....##.#.#..#.#.#..#.......##.###.###.#.########.#.##.#.....#.###.#..#.###.### +####.#.#.#####.#.####.##.##.######.##..#...###......##...#######.#.##.####..#..##.####...##..##...## +###.#.....#.#####.#.#.########.##..#.#...#.######.###...##..#.#.#####..#.##.#.#.#..#..##..####.#.... +###.#.#....#####.####.##.##..#..#.#.###...###.#...##...#.##...#.#.#.#.######..##....##.#.#...####..# +##..#.#.......###.##.#.##.##.###.#.........#.#.#......####.#.######.#####.#.#.##...##.#.#.#......#.. +#..##.##.#.....#.#..###..##...#.####.#.####..#.#####.#.##...##...##.#####..#..##..###..#.#..#..###.. +.#..#.###.....#.###.#..#...##.##.##..##.#.####..#..##....#....##.##...#.##.....###..#####....#....#. +###.##.#.##.##.##...#####..##......##....##.##.#....########....####..#..##.#.##...#.##..#.###...#.. +.###....#.##.#...###...##.#.#.#.#....#...###..#..#.......#....##.....#.#..##.##.#####.##.##.#....#.. +#...##.###...#.....#...#..####.#..#..##...###..##..##.....####.#######.#.#.#.##...#...###.##..##.#.# +###...##.###....#..#..###.#....#.#..##..#.#.##....####.###...#####...##...#...#..####.#......##...#. +###....##.#.###...#....###..#######.....##..##.#...####..###.##.#.####..#..##..####...####.#.#.#.... +..##...###..##.##.#..###.##..####.#.##.........#####..####..##.##......#...##.#.##.#.#.#.#.#.#####.# +#.#.##.#.#####.##....#.....###....###.....#####.#.###..#.###.##.......#...####...##.#...##.#...##... +..####.###..###..#...###..#.#..##..##..##..##..##..####.########.#.####.....#...#.#.######...#...##. +#.####..#..##.##..#.#.##...#..###.#.....###....#..#.#.......#####.##...##...#...#.....##...##.....## +#.#....#.#####...###.####.#..####.#...##..##..###..##...#..#.#..#.####.#..##.##.#.##.#.#.#.#.####..# +#####.#.#.##.#...#.##.#...#####.#.....#..####...##.###........##....####...#..###..###......#.....## +..#..##..##..##....####.#.#.#...##.###.#...####..#....###.##.#..#.##...#..#.##..#.#.#...#..###....#. +#..#..####.######.##.#.###.#....#.#...##########..##.#....#...#.#.####..##.##..#..##.#...##..####.#. +##.####.####....###..#.###...#.####.#....##.##.#.#####.##.###..###...##.#...###..#.#..###.#.##..#... +#.#..#...##..######.#.####.#.###..##..#...#.#.####.#..##.##....#..###....#...###.#..##.#...#.#.##### +#...#..###...#....#..#.#..##.....#######.#...#...#...###.#.###......######..#.#.###..#.##..###.#.... +..###.##..###.......#.##..#.##...##.#.###.##......##...##...##.#.#.##.....##..#.##..#..#..#.#...#..# +.###.####..##..#####..##.###.#...###.#.###.###....#########..#..#.####.##.##.#..##.##...##...#.#.#.# +##...#..#.#.####.#...##....#.####.#....#....###..##.####......###.####...###.###.##..###.#...#...##. +.########....#..##...#.##.#.###.#.#.#..##........#.###..#..####.#....#...####.###.###.####.###.##... +########...#...##.#.####.##..#.###..##..#####.###.###.####..##.##.#.#.#.####.####...##.######.###... +.##...#.##.##.###..####..#####..##.##.####...###..#.######.##.#.#....#.###...#......#.####.###.#..## +..###.#.####.#.#.......#...###.#.####...#..####..#.#######..#..###.#####.#...######.####..#...#..##. +#.#..###...#.#.##....##...#######...#.#..###.#.#...###......#.##.#.#####...##..##.#...###.....#.###. +#...##.#.######..##...##.#..##..#...#.##..#...###..#.##.#..#.....#....###.#...####..#.#...#.###.#### +.##....###.#..###.#####.#..#....######.##..##..####..#####..#..###.##.##.#.#.#.###..#.....###...###. +.#.#.###.##.#..#.###.##.##.##..######..#..###...##.#....####.##...#.###.#.#.#.#######..#...#.##..... +.##.#..#####.#...#.#..#.#.#..#.#....#..####...##...###.#...##.#..##.#..##.#.#..#..####...#.####...## +........###...#.#.#.#..#..#.#..#...###..##.#.#..##.##.#..##...#.###.#...#.##..#.###..######..#.##### +.#.#...#.#.###.#..#####.##..#.#...#.#######.#.#.#.#..#.#.#.####.#.##..##.#..#..#..#..##.#####.#....# +#.#.####..####.##...##.####.##.##.#...##..#.#..##.....#####.....#.#...#..#.##..#.#...###...#..###... +.#.#.#..#....###.#.##.#####.###..##.#.##..##.#.####.#.#.#.#.#..##.#.#.#....########..#.###...#.#.#.. +###..##....###.##.##...##.#.###.#.#.#.####...##.#.##.#..##..####..#...#.#...###..########.##.###...# +.##.....#......#...####.#....#.#.#.##.....#.#.#.#.##.#.....#.#.....#.###..###.#...##....#.##...#.### +#....##....#.###.###..##...##..#.###.#..#.####...###.#..##....#...#..##.##.##.##.###.#......###.#... +##...#...#.##.#.########.#..#####.###.#..##.#.###..#.###.#..#...#.#.#.#..#...###.#.#....#...####..#. +.###.##.#..#.###.#.#.....#.#......##...#####....#...####...#.###..#..##.#####..#...#..##..#.######.. +..####....##.#...###.#....##....####..##.#.##...#...#.....#..####.####...#.#.#####........##.###.### +#..#.##.#..##..#..#....#.#.#.##.#...###...#.....##..###....#..#.#.##.#.#..#.##.#..#......#.........# +.#.......#.####.###...##.########...#..#......##.#..#####..#.##.#..#####.#########.#.##.#.#..#.....# +##.##.....###..#.####.##..#.#.#..#.##..#....#.#.###.###...#####....#.#.#####.##.#....#....#..##....# diff --git a/day20/testInput b/day20/testInput new file mode 100644 index 0000000..000a554 --- /dev/null +++ b/day20/testInput @@ -0,0 +1,7 @@ +..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# + +#..#. +#.... +##..# +..#.. +..### \ No newline at end of file