no checks is faster than all checks :(
This commit is contained in:
parent
532b1cb85f
commit
d5a771ff14
@ -5,7 +5,7 @@ import kotlin.math.min
|
|||||||
/**
|
/**
|
||||||
* Counter for X digits of a given base. Skips situations where faces are the same.
|
* 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.
|
* Increase the counter.
|
||||||
@ -17,7 +17,9 @@ class CounterSkip(size: Int): Counter(size, 18) {
|
|||||||
var last = super.increase()
|
var last = super.increase()
|
||||||
lmi = min(lastModifiedIndex, lmi)
|
lmi = min(lastModifiedIndex, lmi)
|
||||||
// are we having an invalid situation? this would be two consecutive moves on the same face
|
// 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()
|
last = super.increase()
|
||||||
lmi = min(lastModifiedIndex, lmi)
|
lmi = min(lastModifiedIndex, lmi)
|
||||||
}
|
}
|
||||||
@ -26,14 +28,23 @@ class CounterSkip(size: Int): Counter(size, 18) {
|
|||||||
return last
|
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.
|
* 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 {
|
private fun containsConsecutiveSameFaceMoves(): Boolean {
|
||||||
for (i in 1 until this.counter.size) {
|
for (i in 1 until this.counter.size) {
|
||||||
// perhaps is a speedup
|
// 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 true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user