no checks is faster than all checks :(

This commit is contained in:
Joachim 2018-08-25 22:19:49 +02:00
parent 532b1cb85f
commit d5a771ff14

View File

@ -5,7 +5,7 @@ import kotlin.math.min
/**
* Counter for X digits of a given base. Skips situations where faces are the same.
*/
class CounterSkip(size: Int): Counter(size, 18) {
class CounterSkip(size: Int) : Counter(size, 18) {
/**
* Increase the counter.
@ -17,7 +17,9 @@ class CounterSkip(size: Int): Counter(size, 18) {
var last = super.increase()
lmi = min(lastModifiedIndex, lmi)
// are we having an invalid situation? this would be two consecutive moves on the same face
while (containsConsecutiveSameFaceMoves() && !atMax()) {
while (
(containsConsecutiveSameFaceMoves() && !atMax()) ||
(this.counter?.size > 1 && !atMax() && containsPalindrome())) {
last = super.increase()
lmi = min(lastModifiedIndex, lmi)
}
@ -26,13 +28,22 @@ class CounterSkip(size: Int): Counter(size, 18) {
return last
}
private fun containsPalindrome(): Boolean {
val i1 = this.counter.size / 2
for (i in 0 until i1) {
if (this.counter[i] != this.counter[this.counter.size - 1 - i])
return false
}
return true
}
/**
* Are there two moves in the current counter / chain that act on the same face? This would be F+F2 for example.
*/
private fun containsConsecutiveSameFaceMoves(): Boolean {
for (i in 1 until this.counter.size) {
// perhaps is a speedup
if(this.counter[i]%6 == this.counter[i-1]%6)
if (this.counter[i] % 6 == this.counter[i - 1] % 6)
return true
}
return false