Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Spreading out the elements

by sfink (Deacon)
on Jul 07, 2007 at 23:07 UTC ( #625457=note: print w/ replies, xml ) Need Help??


in reply to Spreading out the elements

I came up with this before reading fenLisesi's response, which uses the same "algorithm". Still, it's smaller, infinitesimally more efficient, and (very arguably) easier to follow.

Oh, and I generally come up with completely charred tomatoes mixed in between a combination of tough-as-boiled-beaver and still-dripping-blood beef chunks. (And don't forget the burned onions and the bloody carrot chunks resulting from my pathetic skewering skills, from which I end up with more holes in my thumb than in the vegetables.)

I shouldn't be allowed near a grill.

sub interleave { my ($a, $b) = @_; return scalar("B" x $b) if $a < 1; return "A" . ("B" x $b) if $a < 2; my $groups = $a - 1; my $bchunk = int($b / $groups); my $big = $b % $groups; return ("A" . ("B" x $bchunk)) x ($groups - $big) . ("A" . ("B" x ($bchunk + 1))) x $big . "A"; }


Comment on Re: Spreading out the elements
Download Code
Replies are listed 'Best First'.
Re^2: Spreading out the elements
by oko1 (Deacon) on Jul 08, 2007 at 05:07 UTC
    > I shouldn't be allowed near a grill.

    If they make one that's operable via Perl, you'll be quite the Grillmeister. :) Wow. This appears to do it all, in a tiny little chunk of code. Very, very nice.

    I'm going to spend some time twisting my brain and figuring out how the heck this thing works (not Perl-wise; you're right, that's pretty obvious.) Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-07-30 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls