diff options
author | Julien Dessaux | 2021-12-07 14:26:36 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-12-07 14:26:36 +0100 |
commit | 6ed18289c89eaff3557907df63cf58bd2009b3ee (patch) | |
tree | 903d730030c18ab25c212938794c1c03f65f800f /2021/05/first.go | |
parent | Initial import (diff) | |
download | advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.tar.gz advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.tar.bz2 advent-of-code-6ed18289c89eaff3557907df63cf58bd2009b3ee.zip |
Added the first days
Diffstat (limited to '2021/05/first.go')
-rw-r--r-- | 2021/05/first.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/2021/05/first.go b/2021/05/first.go new file mode 100644 index 0000000..3bd007b --- /dev/null +++ b/2021/05/first.go @@ -0,0 +1,48 @@ +package main + +import ( + "bufio" + "fmt" + "os" + + "git.adyxax.org/aoc/2021/05/line" +) + +func main() { + matrix := make([][]int, 1000) + for i := 0; i < 1000; i++ { + matrix[i] = make([]int, 1000) + } + + parser := line.NewParser(bufio.NewReader(os.Stdin)) + for { + l, err := parser.Parse() + if err != nil { + break + } + if l.X1 == l.X2 { + if l.Y1 > l.Y2 { + l.Y1, l.Y2 = l.Y2, l.Y1 + } + for i := l.Y1; i <= l.Y2; i++ { + matrix[l.X1][i]++ + } + } else if l.Y1 == l.Y2 { + if l.X1 > l.X2 { + l.X1, l.X2 = l.X2, l.X1 + } + for i := l.X1; i <= l.X2; i++ { + matrix[i][l.Y1]++ + } + } + } + score := 0 + for i := 0; i < 1000; i++ { + for j := 0; j < 1000; j++ { + if matrix[i][j] >= 2 { + score++ + } + } + } + fmt.Println(score) +} |