adventofcode/2016/day06/main.go

56 lines
967 B
Go
Raw Permalink Normal View History

2016-12-06 13:06:52 +00:00
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
input := stdinToStringSlice()
var partOne, partTwo string
for j := range input[0] {
freq := make(map[byte]int)
for i := range input {
freq[input[i][j]]++
}
partOne += getTopByte(freq)
partTwo += getBottomByte(freq)
}
fmt.Println("Answer to Part 1: " + partOne)
fmt.Println("Answer to Part 2: " + partTwo)
}
func getTopByte(f map[byte]int) string {
var topByte byte
var topByteCnt int
for k, v := range f {
if v > topByteCnt {
topByteCnt = v
topByte = k
}
}
return string(topByte)
}
func getBottomByte(f map[byte]int) string {
var botByte byte
var botByteCnt int
for k, v := range f {
if v < botByteCnt || botByte == 0 {
botByteCnt = v
botByte = k
}
}
return string(botByte)
}
func stdinToStringSlice() []string {
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
return input
}