From ff81c3e7c8789a493f5f2d6ac192483cabf9ccf4 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 25 Aug 2018 10:52:34 +0200 Subject: [PATCH] small speedup achieved, can now eliminate same-face combinations from investigated solutions --- src/main/kotlin/be/nielandt/CounterSkipSameFaces.kt | 7 +++---- src/main/kotlin/be/nielandt/CrossSolver.kt | 2 +- src/main/kotlin/be/nielandt/Move.kt | 5 ++++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/be/nielandt/CounterSkipSameFaces.kt b/src/main/kotlin/be/nielandt/CounterSkipSameFaces.kt index dcf921f..806d612 100644 --- a/src/main/kotlin/be/nielandt/CounterSkipSameFaces.kt +++ b/src/main/kotlin/be/nielandt/CounterSkipSameFaces.kt @@ -31,10 +31,9 @@ class CounterSkipSameFaces(size: Int, base: Int = 10): Counter(size, base) { */ private fun containsConsecutiveSameFaceMoves(): Boolean { for (i in 1 until this.counter.size) { - val current = Move.values()[this.counter[i]] - val previous = Move.values()[this.counter[i - 1]] - if (current sameFace previous) - return true + // perhaps is a speedup + if(this.counter[i]%6 == this.counter[i-1]%6) + return true } return false } diff --git a/src/main/kotlin/be/nielandt/CrossSolver.kt b/src/main/kotlin/be/nielandt/CrossSolver.kt index fca6f0b..3277445 100644 --- a/src/main/kotlin/be/nielandt/CrossSolver.kt +++ b/src/main/kotlin/be/nielandt/CrossSolver.kt @@ -21,7 +21,7 @@ open abstract class CrossSolver { fun printResults(results: Map>) { println("results: ") results.forEach { color, moveList -> - println("> color ${colorLetter(color)}, moves $moveList") + println("> color ${colorLetter(color)}, moves (${moveList.size}) $moveList") } } } diff --git a/src/main/kotlin/be/nielandt/Move.kt b/src/main/kotlin/be/nielandt/Move.kt index a40d66f..05e9aba 100644 --- a/src/main/kotlin/be/nielandt/Move.kt +++ b/src/main/kotlin/be/nielandt/Move.kt @@ -6,7 +6,10 @@ import java.util.* * All the possible moves on the cube. */ enum class Move { - F, F_, F2, B, B_, B2, L, L_, L2, R, R_, R2, U, U_, U2, D, D_, D2; + // these are purposely put in this order: Move.index % 6 will result in the same value for the same face + F, B, U, D, L, R, + F_, B_, U_, D_, L_, R_, + F2, B2, U2, D2, L2, R2; /** * Static methods for the Move object.