Solve a Rubik's cube: Difference between revisions

Content added Content deleted
m (Thundergnat moved page Solve a Rubik's Cube to Solve a Rubik's cube: capitalization policy)
m (syntax highlighting fixup automation)
Line 23:
 
For the single line example, typical timings are around 240 milliseconds which is much faster than Kotlin due, no doubt, to JVM warm up time.
<langsyntaxhighlight lang="go">/**********************************************************************
*
* A cube 'state' is an int array with 40 entries, the first 20
Line 310:
fmt.Println("\nAverage number of moves =", float64(aggregateMoves)/float64(lineCount))
fmt.Println("\nAverage time =", elapsedTime/int64(lineCount), "milliseconds")
}</langsyntaxhighlight>
 
{{out}}
Line 320:
=={{header|Julia}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="julia">#=**********************************************************************
*
* A cube 'state' is a vector<int> with 40 entries, the first 20
Line 511:
 
pochmann("rubikdata.txt")
</langsyntaxhighlight>{{out}}
Using the 100-line database:
<pre style="height:45ex">
Line 627:
 
To aid readability I've also inserted spaces between each move in the results and added the total moves needed for each line.
<langsyntaxhighlight lang="scala">// version 1.2.21
 
/**********************************************************************
Line 859:
println("\nAverage number of moves = ${aggregateMoves.toDouble() / lineCount}")
println("\nAverage time = ${elapsedTime / lineCount} milliseconds")
}</langsyntaxhighlight>
 
{{out}}
Line 987:
=={{header|Nim}}==
{{trans|Kotlin}}
<syntaxhighlight lang="nim">#[
<lang Nim>#[
**********************************************************************
*
Line 1,190:
let elapsedTime = cpuTime() - startTime
echo &"\nAverage number of moves = {aggregateMoves / lineCount}"
echo &"\nAverage time = {elapsedTime * 1000 / lineCount.toFloat:.2f} milliseconds"</langsyntaxhighlight>
 
{{out}}
Line 1,319:
The final stage (pll) would probably benefit the most from being replaced with standard algorithms.<br>
While technically this works under pwa/p2js, you should expect a blank screen for nearly 3 minutes.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\rubik_cfop.exw
Line 1,708:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{Out}}
The "hardest case" from http://www.cube20.org with a high threshold. You can try this manually.
Line 1,774:
Translation/de-golf(hrumph) of Tomas Sirgedas' winning entry from http://tomas.rokicki.com/cubecontest as held in 2004.<br>
Faster and shorter solutions (in most cases) than cfop, however probably nigh on impossible to debug/enhance...
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\rubik_tomas.exw
Line 1,990:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s (%d move%s)\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tomas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"UL DL RF UB FD BR DB UF DR UR BL FL FDR BLU DLB URB RUF FLD BRD FUL"</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,003:
 
Despite this, the script is taking an average of just over a second to calculate the number of moves for each line which is probably not too bad for an interpreted language.
<langsyntaxhighlight lang="ecmascript">/**********************************************************************
*
* A cube 'state' is an int array with 40 entries, the first 20
Line 2,260:
var elapsedTime = ((endTime - startTime) * 1000).round
System.print("\nAverage number of moves = %(aggregateMoves/lineCount)")
System.print("\nAverage time = %(elapsedTime/lineCount) milliseconds")</langsyntaxhighlight>
 
{{out}}