advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 532e0745993e72b4da9646b42eadd4459bcb7d52
parent 3ed41539edcb675ec3561bb81a95e96b130ebe75
Author: bsandro <email@bsandro.tech>
Date:   Sun, 18 Dec 2022 21:19:16 +0000

Day 18 go format

Diffstat:
Mday18/main.go | 39++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/day18/main.go b/day18/main.go @@ -25,29 +25,29 @@ func day18(input_file string) { } defer input.Close() sideTrans := [6]Side{ - {{0,0,0},{1,1,0},}, - {{0,0,0},{1,0,1},}, - {{0,0,0},{0,1,1},}, - - {{0,0,1},{1,1,1},}, - {{0,1,0},{1,1,1},}, - {{1,0,0},{1,1,1},}, + {{0, 0, 0}, {1, 1, 0}}, + {{0, 0, 0}, {1, 0, 1}}, + {{0, 0, 0}, {0, 1, 1}}, + + {{0, 0, 1}, {1, 1, 1}}, + {{0, 1, 0}, {1, 1, 1}}, + {{1, 0, 0}, {1, 1, 1}}, } scanner := bufio.NewScanner(input) sides := make(map[string]bool) // side:inner for scanner.Scan() { in := scanner.Text() var c Vec3 - num,err:=fmt.Sscanf(in, "%d,%d,%d", &c.x, &c.y, &c.z) - if num!=3&&err!=nil{ + num, err := fmt.Sscanf(in, "%d,%d,%d", &c.x, &c.y, &c.z) + if num != 3 && err != nil { log.Fatal("parse error", err) } - for _,s:=range sideTrans{ + for _, s := range sideTrans { side := Side{ - {c.x+s[0].x, c.y+s[0].y, c.z+s[0].z}, - {c.x+s[1].x, c.y+s[1].y, c.z+s[1].z}, + {c.x + s[0].x, c.y + s[0].y, c.z + s[0].z}, + {c.x + s[1].x, c.y + s[1].y, c.z + s[1].z}, } - if _,exists:=sides[side.String()];exists { + if _, exists := sides[side.String()]; exists { sides[side.String()] = true } else { sides[side.String()] = false @@ -57,20 +57,25 @@ func day18(input_file string) { if err = scanner.Err(); err != nil { log.Fatal(err) } - sum:=0 - for _,v:=range sides { - if !v { sum++ } + sum := 0 + for _, v := range sides { + if !v { + sum++ + } } fmt.Println("Part 1:", sum) } type Vec3 struct { - x,y,z int + x, y, z int } + func (v3 Vec3) String() string { return fmt.Sprintf("%d:%d:%d", v3.x, v3.y, v3.z) } + type Side [2]Vec3 + func (s Side) String() string { return fmt.Sprintf("%s-%s", s[0].String(), s[1].String()) }