in reply to Re^3: Algorithm RFC: fast (pseudo-)random shuffle with no repetition
in thread Algorithm RFC: fast (pseudo-)random shuffle with no repetition

A good algorithm must not fail on edge cases.

One can easily find many where there are no or only few solutions.

Now try blindly guessing permutations, till you find the only possible solution for ( (1)x8 , 2..8 )

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Re^4: Algorithm RFC: fast (pseudo-)random shuffle with no repetition
  • Download Code

Replies are listed 'Best First'.
Re^5: Algorithm RFC: fast (pseudo-)random shuffle with no repetition
by karlgoethebier (Abbot) on Sep 24, 2023 at 14:09 UTC

    Do you mean like this (1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8)? Because then I actually get more results quickly. However, something is not quite right with the regular expressions. I must be swapping $m3 with $m2. This is a bit of a mystery to me at the moment.

    «The Crux of the Biscuit is the Apostrophe»

      I didn't run your code, and I don't trust it either.

      But I assumed you wanted a brute force try and error shuffling.

      > Do you mean like this (1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8)

      Yes.

      And there is only one possible solution

      (1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1)

      Trying 1e15 shuffles to finally get there seems like a good way to transform your hardware into an electric heater only.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

        there is only one possible solution

        I count 7! = 5,040 solutions.

        Trying 1e15 shuffles

        There are 15!/8! = 32,432,400 permutations of the set (and for that matter 15! is only about 1.3e12). I don't see mention in Algorithm::Permute of how it handles duplicate elements, but I know that Algorithm::Loops handles them correctly.

        That said I do agree with the thrust of your point. :)

        So this aren’t valid permutations?

        karl@h3002993:~/src/perl$ ./pmute.pl 1 8 1 2 1 7 1 3 1 6 1 5 1 4 1 karl@h3002993:~/src/perl$ ./pmute.pl 1 3 1 4 1 7 1 5 1 2 1 6 1 8 1 karl@h3002993:~/src/perl$ ./pmute.pl 1 4 1 8 1 6 1 5 1 3 1 2 1 7 1 karl@h3002993:~/src/perl$ ./pmute.pl 1 5 1 8 1 2 1 4 1 6 1 3 1 7 1 karl@h3002993:~/src/perl$ ./pmute.pl 1 7 1 5 1 4 1 3 1 8 1 2 1 6 1

        FYI

        karl@h3002993:~/src/perl$ time ./pmute.pl 1 4 1 3 1 2 1 6 1 5 1 7 1 8 1 real 0m0,081s user 0m0,076s sys 0m0,004s karl@h3002993:~/src/perl$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 1 On-line CPU(s) list: 0 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz …

        «The Crux of the Biscuit is the Apostrophe»

        Somehow I also calculate differently:

        CL-USER> (expt 10 15) 1000000000000000 CL-USER> (* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 1307674368000

        «The Crux of the Biscuit is the Apostrophe»