Created
September 30, 2016 14:37
-
-
Save zoffixznet/da7782c0cce54d4e80cb859bbe05ddbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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