day 16a complete

This commit is contained in:
2021-12-17 13:23:44 +00:00
parent 6111f86a04
commit 0db2c0a79e
5 changed files with 78 additions and 200 deletions

View File

@ -1,9 +1,9 @@
package main
import (
"AdventOfCode2021/shared"
"bufio"
"fmt"
"math"
"os"
)
@ -13,7 +13,7 @@ func main() {
gamma, epsilon := findGammaAndEpsilon(content)
fmt.Println(binaryToInteger(gamma) * binaryToInteger(epsilon))
fmt.Println(shared.BinaryToInteger(&gamma) * shared.BinaryToInteger(&epsilon))
}
@ -40,17 +40,6 @@ func findGammaAndEpsilon(content *[]string) (gamma string, epsilon string) {
return
}
func binaryToInteger(input string) (value int) {
n := 0
for i := len(input) - 1; i >= 0; i-- {
if input[i] == '1' {
value += (int(math.Pow(float64(2), float64(n))))
}
n++
}
return
}
func returnContent(path string) *[]string {
//read file and return it as an array of integers