-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_count_passphrases.go
58 lines (51 loc) · 1.02 KB
/
04_count_passphrases.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"metalim/advent/2017/lib/source"
"sort"
. "github.com/logrusorgru/aurora"
)
func main() {
var ins source.Inputs
ins = ins.Test(1, `aa bb cc dd aa`, `0`)
ins = ins.Test(1, `aa bb cc dd aaa`, `1`)
ins = ins.Test(2, `abcde xyz ecdab`, `0`)
for p := range ins.Advent(2017, 4) {
fmt.Println(Brown("\n" + p.Name))
ssw := p.Lines().Words()
fmt.Println(len(ssw), "lines", Black(ssw[0]).Bold())
if p.Part(1) {
var count int
LINES:
for _, l := range ssw {
words := map[string]bool{}
for _, w := range l {
if words[w] {
continue LINES
}
words[w] = true
}
count++
}
p.SubmitInt(1, count)
}
if p.Part(2) {
var count int
LINES2:
for _, l := range ssw {
words := map[string]bool{}
for _, w := range l {
rs := []rune(w)
sort.Slice(rs, func(i, j int) bool { return rs[i] < rs[j] })
w = string(rs)
if words[w] {
continue LINES2
}
words[w] = true
}
count++
}
p.SubmitInt(2, count)
}
}
}