Added the first days
This commit is contained in:
parent
7ebc2cd003
commit
6ed18289c8
26 changed files with 6168 additions and 0 deletions
42
2021/03/first.go
Normal file
42
2021/03/first.go
Normal file
|
@ -0,0 +1,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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue