adventofcode/2015/day08/main.go
2016-12-16 16:21:15 -06:00

49 lines
1.1 KiB
Go

package main
import (
"fmt"
"io"
"log"
"strings"
)
func main() {
var input []string
var readInp string
for {
_, err := fmt.Scan(&readInp)
if err != nil {
if err != io.EOF {
log.Fatal(err)
}
break
}
input = append(input, readInp)
}
var codeCount int
var stringCount int
for i := range input {
codeCount += len(input[i])
var skipChars int
fmt.Printf("%s -> %d\n", input[i], len(input[i]))
tmpInput := strings.Replace(input[i], "\\\"", "\"", -1)
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
tmpInput = strings.Replace(tmpInput, "\\\\", "\\", -1)
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
tmpInput = strings.TrimSuffix(strings.TrimPrefix(tmpInput, "\""), "\"")
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
// Now search for hex sequences
for j := range tmpInput {
if len(tmpInput) > j+3 {
if tmpInput[j] == '\\' && tmpInput[j+1] == 'x' {
skipChars += 3
}
}
}
fmt.Printf("Minus %d for hex\n", skipChars)
stringCount += len(tmpInput) - skipChars
}
fmt.Printf("Code: %d, String: %d\n", codeCount, stringCount)
fmt.Printf("Difference: %d\n", (codeCount - stringCount))
}