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
+"(*+*)*(*+* +*/*) **** ** * * *+*+*/* **** ** * * | |
*+*-*/* **** ** * * *+* ****-* **** ** * * *-(*-*/ | |
*) ** (*+*/*) **** ** * * *-* **** ** * * *-*+*/* | |
**** ** * * *+* **** ** * * *-* * * ***((* - */*) | |
** * * *-*/*) * * **** ** * * *+*/* ****-* ***(*-* | |
/*)**(*+*/*) * * ***((*-*/*)** * * *-*/*) * * **** | |
** * * *+*/* **** ** * * *+*+*/*-* * *".split(<***> | |
).map: {.(|(<* * *>xx.count)).chr.print given EVAL | |
"(* ** *+*+*-*/*+$_)" } |
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
use v6; | |
sub primes-list(Bool $use-wheel) { | |
my @start = $use-wheel ?? (2, 3) !! (2); | |
my @sieve; | |
my $i = @start-1; | |
my $p = @start[$i]; | |
my $q = $p*$p; | |
my $n = $p; | |
my \incr = $use-wheel ?? 2 !! 1; | |
@start, -> *@primes { |
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
#!/usr/bin/env perl6 | |
use v6; | |
sub sort-promise ($in, $out) { | |
start { | |
my @same; | |
earliest $in { | |
more * { push @same, $in.receive } | |
done * { return } | |
} | |
my ($less_c, $more_c) = Channel.new xx 2; |
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
#!/usr/bin/env perl6 | |
use v6; | |
sub mysort( Supply $s ) { | |
my (@same, @supplies, @promises); | |
my $p = Promise.new; | |
$s.tap( -> $val { | |
if @same { | |
given $val <=> @same[0] { | |
when Same { push @same, $val } | |
when Less { @supplies[0].emit( $val ) } |
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
use v6; | |
class Cache::LRU { | |
has Hash[Node] %.entries; | |
has Node $.lru; | |
class Node { | |
has $value is required; | |
has $prev is rw; | |
has $next is rw; | |
method splice() { |
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
#!/usr/bin/env perl6 | |
use v6; | |
sub sort-promise ($c) { | |
my @same; | |
earliest $c { | |
more $c { push @same, $c.receive } | |
done $c { return } | |
} | |
my @chans = Channel.new xx 2; |
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
use v6; | |
constant DEBUGGING = False; | |
my class PrimesI does Iterator { | |
has @!primes = (2, 3); | |
has @!sieve = (Any xx 3); | |
has $!p = 3; | |
has $!q = $!p * $!p; | |
has $!n = $!p; | |
method pull-one returns Int { | |
return @!primes.shift if @!primes and @!primes[0] < 4; |
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
#!perl | |
use strict; | |
use warnings; | |
package primes; | |
sub new { bless [2, 3], shift } | |
sub next { | |
my ($self) = @_; | |
bless $self, 'primes0' if @$self == 1; | |
shift @$self; |
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
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class Primes | |
{ | |
public static void my_insert(ArrayList<Integer> factors, Integer factor) { | |
int where = factor, count = factors.size(); | |
while( where < count && factors.get(where) != null ) where += factor; | |
if( where >= count ) { |
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
<script> | |
(function (factors, primes) { | |
var a_prime = 3, a_squared_prime = 9, maybe_prime = 3; | |
function insertPrimeIntoSieve( factor ) { | |
/* This functions deliberately makes factors a sparse array */ | |
/* It will have nulls in the places which might be prime, */ | |
/* and primes in the places which are surely composites. */ | |
var where = factor; | |
while( factors[where] ) | |
where += factor; |
OlderNewer