Last active
January 30, 2021 12:43
-
-
Save ohbarye/8fe350b0d65afdc87aed4e848a544bed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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