Improve performance of day 5
This commit is contained in:
parent
fb5c2ab07b
commit
6b5c65a811
@ -1,21 +1,21 @@
|
|||||||
package solutions
|
package solutions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func seatStrToSeatId(seat string) int {
|
func seatStrToSeatId(seat string) int {
|
||||||
lowRegex := regexp.MustCompile("[FL]")
|
rowStr := seat[:7]
|
||||||
highRegex := regexp.MustCompile("[BR]")
|
rowStr = strings.ReplaceAll(rowStr, "F", "0")
|
||||||
|
rowStr = strings.ReplaceAll(rowStr, "B", "1")
|
||||||
|
columnStr := seat[7:]
|
||||||
|
columnStr = strings.ReplaceAll(columnStr, "L", "0")
|
||||||
|
columnStr = strings.ReplaceAll(columnStr, "R", "1")
|
||||||
|
|
||||||
seatStr := lowRegex.ReplaceAllString(seat, "0")
|
row, _ := strconv.ParseInt(rowStr, 2, 64)
|
||||||
seatStr = highRegex.ReplaceAllString(seatStr, "1")
|
column, _ := strconv.ParseInt(columnStr, 2, 64)
|
||||||
|
|
||||||
row, _ := strconv.ParseInt(seatStr[:7], 2, 64)
|
|
||||||
column, _ := strconv.ParseInt(seatStr[7:], 2, 64)
|
|
||||||
|
|
||||||
return int(row*8 + column)
|
return int(row*8 + column)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user