71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
rotations := Decode("input.txt")
|
|
|
|
rotation := 50
|
|
zeroamount := 0
|
|
|
|
for _, i := range rotations {
|
|
b := i % 100 // for large number rotations eg. L392 -> L92
|
|
|
|
r := rotation + b
|
|
if r > 99 {
|
|
r = r - 100
|
|
} else if r < 0 {
|
|
r = r + 100
|
|
}
|
|
|
|
if r == 0 {
|
|
zeroamount = zeroamount + 1
|
|
}
|
|
|
|
fmt.Printf("rotation is now at: %d+%d=%d, rotation %d\n", rotation, b, r, i)
|
|
rotation = r
|
|
}
|
|
|
|
fmt.Println("zero amount is:", zeroamount)
|
|
|
|
}
|
|
|
|
func Decode(filename string) []int {
|
|
f, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
scanner := bufio.NewScanner(f)
|
|
|
|
var rotations []int
|
|
|
|
for scanner.Scan() {
|
|
if strings.Contains(scanner.Text(), "L") {
|
|
a := strings.Replace(scanner.Text(), "L", "", 1)
|
|
|
|
b, _ := strconv.Atoi(a)
|
|
c := b-b*2 // makes negative, this is so janky
|
|
rotations = append(rotations, c)
|
|
fmt.Printf("converted %s to int %d\n", scanner.Text(), c)
|
|
|
|
} else if strings.Contains(scanner.Text(), "R") {
|
|
a := strings.Replace(scanner.Text(), "R", "", 1)
|
|
|
|
b, _ := strconv.Atoi(a)
|
|
rotations = append(rotations, b)
|
|
fmt.Printf("converted %s to int %d\n", scanner.Text(), b)
|
|
}
|
|
}
|
|
|
|
return rotations
|
|
}
|