Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Perl, 209 (203) char</h2> <p>Rewritten to keep track of the location of each disk as opposed to the list of disks that are contained on each rod.</p> <p><strike>306</strike> <strike>291</strike> <strike>263</strike> <strike>244</strike> <strike>236</strike> <strike>213</strike> 209 chars after removing unnecessary whitespace.</p> <pre><code>sub M{my($r,$s)=@_;if(--$m){M($r,$r^$s);$_.=",$r$s";M($r^$s,$s)}s/(.),?\1//; $R[++$m]=$p}map@R[/\d+/g]=(++$i)x99,split/,/,&lt;&gt;;do{1until ($n=$R[1])-($p=$R[++$m]||$n-1|2);M$n,$p}while 1&lt;grep@R~~$_,1..3;s/^,//;print </code></pre> <p><code>$R[j]</code>: the location of disk j</p> <p><code>$n</code>: the location of disk #1</p> <p><code>$m</code>: the number of disks to move</p> <p><code>$p</code>: the location to move the disks to</p> <p><code>&amp;M(r,s)</code>: move <code>$m-1</code> disks from r to s. Appends to <code>$_</code> and sets <code>@R</code></p> <p>The substitution inside <code>sub M</code> optimizes the output, removing extraneous steps. It could be removed (12 characters) and the output would still be valid.</p> <p>Another 12 characters can be removed if the perl interpreter is invoked with the command-line switch <code>-apF,</code>. With the extra 6 chars for the command-line switch, this gets us down to net 203 characters:</p> <pre><code># invoke as perl -apF, ... sub M{my($r,$s)=@_;if(--$m){M($r,$r^$s);$_=$a.=",$r$s";M($r^$s,$s)} s/(.),\1//;$R[++$m]=$p}map@R[/\d+/g]=(++$i)x99,@F; do{1until($n=$R[1])-($p=$R[++$m]||$n-1|2);M$n,$p}while 1&lt;grep@R~~$_,1..3;s/^,// </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload