This commit is contained in:
Nico 2020-12-05 14:00:00 +00:00
parent 0b1b7c11df
commit fb159a9a6d
1 changed files with 32 additions and 32 deletions

64
five.go
View File

@ -1,22 +1,22 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
"fmt"
)
// diff finds the difference between two ints
func diff(a,b int) int {
func diff(a, b int) int {
if a > b {
return a-b
return a - b
}
return b-a
return b - a
}
func main() {
d, _ := ioutil.ReadFile("in5.txt")
s := strings.Split(string(d) , "\n")
s := strings.Split(string(d), "\n")
max := 0
for _, code := range s {
rowUpper := 127
@ -27,37 +27,37 @@ func main() {
col := 0 // will store the col when it's completed
for i, sym := range code {
switch sym {
case 'F': // The lower half
if i == 6 { // the last command
row = rowLower
} else {
rowUpper = rowUpper-(diff(rowLower, rowUpper)/2)-1
}
case 'B': // The upper half
if i == 6 {
row = rowUpper
} else {
rowLower = rowLower+(diff(rowLower, rowUpper)/2)+1
}
case 'L': // Lower Half
if i == 9 {
col = colLower
} else {
colUpper = colUpper-(diff(colLower, colUpper)/2)-1
}
case 'R': // Upper Half
if i == 9 {
col = colUpper
} else {
colLower = colLower+(diff(colLower, colUpper)/2)+1
}
case 'F': // The lower half
if i == 6 { // the last command
row = rowLower
} else {
rowUpper = rowUpper - (diff(rowLower, rowUpper) / 2) - 1
}
case 'B': // The upper half
if i == 6 {
row = rowUpper
} else {
rowLower = rowLower + (diff(rowLower, rowUpper) / 2) + 1
}
case 'L': // Lower Half
if i == 9 {
col = colLower
} else {
colUpper = colUpper - (diff(colLower, colUpper) / 2) - 1
}
case 'R': // Upper Half
if i == 9 {
col = colUpper
} else {
colLower = colLower + (diff(colLower, colUpper) / 2) + 1
}
}
}
id := row*8+col
id := row*8 + col
if id > max {
max = id
}
}
fmt.Println(max)
}
}