Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

HOP, flip, and swap

by tlm (Prior)
on Aug 07, 2005 at 20:17 UTC ( [id://481736]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub permute {
      my @items = @_;
    ...
        return @items;
      }
    }
    
  2. or download this
      15 = 2*3! + 1*2! + 1*1!
    
  3. or download this
    sub fb_to_perm {
      my @arr = @{ shift() };
    ...
      push @ret, @arr;
      return @ret;
    }
    
  4. or download this
    my $n = 0;
    {
    ...
      ++$n;
      redo;
    }
    
  5. or download this
    A B C D 000_F   B A C D 100_F   C A B D 200_F   D A B C 300_F
    A B D C 001_F   B A D C 101_F   C A D B 201_F   D A C B 301_F
    ...
    A C D B 011_F   B C D A 111_F   C B D A 211_F   D B C A 311_F
    A D B C 020_F   B D A C 120_F   C D A B 220_F   D C A B 320_F
    A D C B 021_F   B D C A 121_F   C D B A 221_F   D C B A 321_F
    
  6. or download this
    A B C D 000_F
    
    ...
    
    C D B A 221_F
    D A B C 300_F
    
  7. or download this
    A B C D 000_F
    A C B D 010_F
    ...
    D A B C 300_F
    D B A C 310_F
    D C A B 320_F
    
  8. or download this
    sub offsets {
      my $p = $_[ 0 ];
    ...
    
      return ( $i, $d );
    }
    
  9. or download this
    sub perms {
      my @arr = @_;
    ...
        redo;
      }
    }
    
  10. or download this
        my $j = @arr - $i;
        @arr[ $j+1..$#arr ] = reverse @arr[ $j+1..$#arr ];
        @arr[ $j, $j+$d ] = @arr[ $j+$d, $j ];
    
  11. or download this
        @arr[ 0..$i-1 ] = reverse @arr[ 0..$i-1 ];
    
  12. or download this
        if ( $i % 2 ) {
          @arr[ $i-1, 0 ] = @arr[ 0, $i-1 ];
    ...
        else {
          @arr[ $i-1, $d-1 ] = @arr[ $d-1, $i-1 ];
        }
    
  13. or download this
    Iterator {...}
    
  14. or download this
    \sum_{k=0}^{m-1}k*k! = m!-1
    
  15. or download this
    (m - 1)*(m - 1)! + (m - 1)! - 1 = m! - 1
    
  16. or download this
    sub n_to_fb {
      my ( $n, $m ) = @_;
    ...
      }
      return $n ? undef : \@fb;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://481736]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-25 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found