Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created October 20, 2014 21:55
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 lizmat/ab00347d5cc44a23c65b to your computer and use it in GitHub Desktop.
Save lizmat/ab00347d5cc44a23c65b to your computer and use it in GitHub Desktop.
take problems on JVM
sub ROLLPICKGRABN( # N times
$self, $count, @pairs is rw, :$keep
) is hidden_from_backtrace {
my Int $total = $self.total;
my Int $rand;
my Int $seen;
my int $todo = ($keep ?? $count !! ($total min $count)) + 1;
gather {
while $todo = $todo - 1 {
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;
take $pair.key;
last if $keep;
$pair.value--;
$total = $total - 1;
last;
}
}
}
}
Seems to happen in take
Exception in thread "main" org.perl6.nqp.runtime.UnwindException
at org.perl6.nqp.runtime.ThreadContext.<init>(ThreadContext.java:119)
at org.perl6.nqp.runtime.GlobalContext.getCurrentThreadContext(GlobalContext.java:333)
at org.perl6.nqp.runtime.GlobalContext.<init>(GlobalContext.java:248)
at org.perl6.nqp.runtime.CompilationUnit.enterFromMain(CompilationUnit.java:56)
at perl6.main(gen/jvm/main.nqp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment