Skip to content

Instantly share code, notes, and snippets.

@ohbarye
Last active January 30, 2021 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohbarye/8fe350b0d65afdc87aed4e848a544bed to your computer and use it in GitHub Desktop.
Save ohbarye/8fe350b0d65afdc87aed4e848a544bed to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"strings"
)
func main() {
bytes, _ := ioutil.ReadFile("./input.txt")
input := strings.TrimRight(string(bytes), "\n")
max := -1
for _, code := range strings.Fields(input) {
a := 64
row := 0
for _, c := range code[:7] {
if c == 'B' {
row += a
}
a /= 2
}
a = 4
col := 0
for _, c := range code[7:] {
if c == 'R' {
col += a
}
a /= 2
}
ans := row * 8 + col
if ans > max {
max = ans
}
}
println(max)
}
package main
import (
"io/ioutil"
"sort"
"strings"
)
func main() {
bytes, _ := ioutil.ReadFile("./input.txt")
input := strings.TrimRight(string(bytes), "\n")
ar := make([]int, 500)
for _, code := range strings.Fields(input) {
a := 64
row := 0
for _, c := range code[:7] {
if c == 'B' {
row += a
}
a /= 2
}
a = 4
col := 0
for _, c := range code[7:] {
if c == 'R' {
col += a
}
a /= 2
}
ans := row*8 + col
ar = append(ar, ans)
}
sort.Ints(ar)
prev := -1
for _, id := range ar {
if prev+2 == id {
println(id - 1)
}
prev = id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment