Added the first days

This commit is contained in:
Julien Dessaux 2021-12-07 14:26:36 +01:00
parent 7ebc2cd003
commit 6ed18289c8
26 changed files with 6168 additions and 0 deletions

42
2021/03/first.go Normal file
View 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)
}