in reply to Functional shuffle
This can probably be golfed to high heaven, but my question is, is it "functional" enough?
use strict; sub functional_FY { return @_ if @_ < 2; my $i = rand @_; @_[ 0, $i ] = @_[ $i, 0 ]; return ( shift, functional_FY( @_ ) ); } print "@{ [ functional_FY( 1..10 ) ] }\n";
Golf 1:
sub functional_FY { return @_ if @_ < 2; return ( splice( @_, rand @_, 1 ), &functional_FY ); }
Golf 2:
sub functional_FY { return @_ < 2 ? @_ : ( splice( @_, rand @_, 1 ), &functional_FY ); }
the lowliest monk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Functional shuffle
by Roy Johnson (Monsignor) on Apr 01, 2005 at 23:39 UTC | |
by bart (Canon) on Apr 02, 2005 at 11:56 UTC | |
by tlm (Prior) on Apr 02, 2005 at 16:11 UTC | |
by Roy Johnson (Monsignor) on Apr 04, 2005 at 14:01 UTC | |
by kelan (Deacon) on Apr 02, 2005 at 14:04 UTC | |
Re^2: Functional shuffle
by Roy Johnson (Monsignor) on Apr 02, 2005 at 01:11 UTC | |
by tlm (Prior) on Apr 02, 2005 at 02:37 UTC |