Skip to content

Instantly share code, notes, and snippets.

@LucasAlfare
Created December 28, 2022 17:14
Show Gist options
  • Save LucasAlfare/002a52b48d007190e79c5ededad3e522 to your computer and use it in GitHub Desktop.
Save LucasAlfare/002a52b48d007190e79c5ededad3e522 to your computer and use it in GitHub Desktop.
draft puzzle state with hexadecimals
import java.math.BigInteger
import kotlin.math.max
import kotlin.math.min
fun Long.toHexString(): String = BigInteger(this.toString()).toString(16)
class Hexrray(var n: Long) {
operator fun get(i: Int) =
(n shr (48 - ((min(48, i + 1)) * 4))) and 0xf
operator fun set(i: Int, value: Long) {
val idx = 48 - (min(48, i + 1) * 4)
n = n and (0xFL shl idx).inv()
n = n or (value shl idx)
}
fun swap(idxA: Int, idxB: Int) {
val i = min(idxA, idxB)
val j = max(idxA, idxB)
val a = this[i]
val b = this[j]
this[i] = b
this[j] = a
}
}
class Dino(var state: Long = 0x123456789abc) {
private val hexrray = Hexrray(state)
fun move(m: Int) {
// TODO
}
override fun toString() = hexrray.n.toHexString()
}
fun main() {
val d = Dino()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment