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";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|