This commit is contained in:
2022-12-15 14:56:28 +01:00
parent 108980344b
commit cc58326f8c
20 changed files with 145 additions and 145 deletions

View File

@@ -1,21 +1,21 @@
package main
import (
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
)
func main() {
pairs := common.ParsePairs(*bufio.NewScanner(os.Stdin))
sum := 0
sum := 0
for i, pair := range pairs {
if pair.CheckOrder() {
sum += (i + 1)
}
}
for i, pair := range pairs {
if pair.CheckOrder() {
sum += (i + 1)
}
}
fmt.Println(sum)
}

View File

@@ -1,26 +1,26 @@
package main
import (
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"sort"
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"sort"
)
func main() {
packets := common.ParsePackets(*bufio.NewScanner(os.Stdin), []string{"[[2]]", "[[6]]"})
sort.Slice(packets, func(i int, j int) bool {
return packets[i].Compare(packets[j]) < 0
})
sort.Slice(packets, func(i int, j int) bool {
return packets[i].Compare(packets[j]) < 0
})
result := 1
for i := 0; i < len(packets); i++ {
if packets[i].IsSeparator() {
result *= (i+1)
}
}
result := 1
for i := 0; i < len(packets); i++ {
if packets[i].IsSeparator() {
result *= (i+1)
}
}
fmt.Println(result)
}