-
Notifications
You must be signed in to change notification settings - Fork 0
/
05.go
46 lines (40 loc) · 794 Bytes
/
05.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
package main
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
)
const numBits = 10
const allSeats = 128 * 8
func main() {
maxID := 0
myID := 0
bytes, _ := ioutil.ReadAll(os.Stdin)
lines := strings.Split(string(bytes), "\n")
var present [allSeats]bool
for _, line := range lines {
id := 0
reg, _ := regexp.Compile("B|R")
matches := reg.FindAllStringIndex(strings.TrimSpace(line), -1)
for _, pos := range matches {
bit := (numBits - 1 - pos[0])
id |= 1 << bit
}
present[id] = true
if id > maxID {
maxID = id
}
}
for id, taken := range present {
if id > 0 && id < allSeats-1 {
if !taken && present[id-1] && present[id+1] {
myID = id
break
}
}
}
fmt.Printf("The highest ID seen is %d\n", maxID)
fmt.Printf("My ID is %d\n", myID)
}