Skip to content

Instantly share code, notes, and snippets.

@Tux
Created April 17, 2015 14:45
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 Tux/587e5914afda17e1b1ee to your computer and use it in GitHub Desktop.
Save Tux/587e5914afda17e1b1ee to your computer and use it in GitHub Desktop.
This hangs
use v6;
class RangeSet {
has Pair @.p;
method add (Int $from, Any $to) {
@.p.push: $from => $to.Num;
}
method to_list () {
gather {
my Int $max = -1;
for sort @.p -> $r {
my $from = ($r.key, $max + 1).max.Int;
($from, $r.value).perl.say;
take $from .. $r.value;
$r.value == Inf and last;
$max = ($max, $r.value).max.Int;
}
}
}
}
my RangeSet $rs .= new;
$rs.add(0,1);
$rs.add(3,3);
$rs.add(5,Inf);
my Int @c = $rs.to_list;
#@crange.perl.say;
for 1..9 -> $t {
my @x = (10 * $t + 1) .. (10 * $t + 9);
my @z = @c ?? (@x[@c]:v) !! @x;
@z.perl.say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment