From a7ba598a54a8883c83cb9ef2b04d653eecd92e28 Mon Sep 17 00:00:00 2001 From: j-james Date: Sun, 11 Dec 2022 18:15:44 -0800 Subject: Reorganize 2019 solutions --- 2019/eight.go | 87 ----------------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 2019/eight.go (limited to '2019/eight.go') diff --git a/2019/eight.go b/2019/eight.go deleted file mode 100644 index 74be0e1..0000000 --- a/2019/eight.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "strconv" -) - -func main() { - if len(os.Args) < 2 { - panic("runtime error: missing operand") - } - file, err := ioutil.ReadFile(os.Args[1]) - if err != nil { - panic(err) - } - image := sliceify(file, 25, 6, len(file)/(25*6)) - - checksum(image) - decode(image) -} - -func sliceify(file []byte, width int, height int, depth int) [][][]int { - var image [][][]int - pointer := 0 - - for i := 0; i < depth; i++ { - var b [][]int - for j := 0; j < height; j++ { - var a []int - for k := 0; k < width; k++ { - element, err := strconv.Atoi(string(file[pointer])) - if err != nil { - panic(err) - } - a = append(a, element) - pointer++ - } - b = append(b, a) - } - image = append(image, b) - } - return image -} - -func count(layer [][]int, val int) int { - total := 0 - for i := 0; i < len(layer); i++ { - for j := 0; j < len(layer[i]); j++ { - if layer[i][j] == val { - total++ - } - } - } - return total -} - -func checksum(image [][][]int) { - min := count(image[0], 0) - layer := -1 - for i := 0; i < len(image); i++ { - total := count(image[i], 0) - if total < min { - min = total - layer = i - } - } - fmt.Println(count(image[layer], 1) * count(image[layer], 2)) -} - -func decode(image [][][]int) { - for i := 0; i < len(image[0]); i++ { - for j := 0; j < len(image[0][0]); j++ { - for k := 0; k < len(image); k++ { - if image[k][i][j] == 0 { - fmt.Print(" ") - break - } else if image[k][i][j] == 1 { - fmt.Print("X") - break - } - } - } - fmt.Println() - } -} -- cgit v1.2.3-70-g09d2