blob: 53435051c14086e63f866207c5128d28715712b2 (
plain)
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
|
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
f, err := os.Open("input")
if err != nil {
log.Fatalf("%+v", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
bits := make([]int, 12)
for scanner.Scan() {
num := scanner.Text()
for n := 0; n < 12; n++ {
if num[n] == '1' {
bits[n]++
}
}
}
gamma := 0
epsilon := 0
for n := 0; n < 12; n++ {
gamma *= 2
epsilon *= 2
if bits[n] > 500 {
gamma++
} else {
epsilon++
}
}
fmt.Println(gamma * epsilon)
}
|