Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created September 30, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/da7782c0cce54d4e80cb859bbe05ddbd to your computer and use it in GitHub Desktop.
Save zoffixznet/da7782c0cce54d4e80cb859bbe05ddbd to your computer and use it in GitHub Desktop.
my @spans = lines q:to/SPANS/;
<----->
<----------->
<---->
<----->
<------------------->
<---->
<----->
<-------->
<---->
<----->
<-------->
<---->
SPANS
constant $max = 40;
my @available = @spans».trim.sort: -*.chars;
say "=" x $max;
put join "", gather loop {
my $cur = 0;
for ^@available -> $i {
last if $i >= @available;
if @available[$i].chars + $cur <= $max {
$cur += @available[$i].chars;
@available.splice($i,1).take;
redo;
}
}
last unless @available;
$cur = 0;
take "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment