Created
October 20, 2014 21:55
-
-
Save lizmat/ab00347d5cc44a23c65b to your computer and use it in GitHub Desktop.
take problems on JVM
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
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