Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Challenge: "Insanity" Cube Puzzle

by Ieronim (Friar)
on Jul 06, 2006 at 16:52 UTC ( [id://559625]=note: print w/replies, xml ) Need Help??


in reply to Re: Challenge: "Insanity" Cube Puzzle
in thread Challenge: "Insanity" Cube Puzzle

The total number of iterations needed to find all unique solutions is ((3*4)^4)/8 == 2592, as the unique solution does not depend on the cubes' order :) And all 8 solutions can be built using simple permutation of an array representing the unique one.

My regexp solution really uses the smallest possible number of loops, i think. Be stricter, it does not use loops at all to find the solution — only during the pre-processing :)))

It's difficult to make a good benchmark, as all presented scripts print their output directly to STDOUT and need to be a bit modified to become comparable by cmpthese(). But i'll try to do it today, if i have enough time.

Replies are listed 'Best First'.
Re^3: Challenge: "Insanity" Cube Puzzle
by Limbic~Region (Chancellor) on Jul 06, 2006 at 16:58 UTC
    Ieronim,
    I told liverpole in the CB that I didn't really have time to play with this but since he indicated I was the reason he posted it as a Challenge (see some of my previous posts), I felt obligated to do so. Without thinking about it too much, I decided just to brute-force it and then see if there were any obvious optimizations on that. I do not expect it to be the fastest but it is fast enough.

    With regards to benchmarking, it is almost never a good idea to include IO. Basically, the routines should be verified to produce essentially the same results first and then the output should be omitted. In other words, doing any preparation IO work before the bench, run the bench, and omit any IO output.

    Update: Depending on how you count, the following only loops 1,152 times and still finds duplicates.

    And the following performs even fewer (< 500):

    Cheers - L~R

      I compared my new solution with your final and semi-final.

      Here's the benchmark's code:

      And here are the results:
      Rate L~R (semi) L~R (final) ieronim (new) L~R (semi) 15.5/s -- -94% -97% L~R (final) 258/s 1566% -- -48% ieronim (new) 500/s 3128% 94% --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://559625]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-24 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found