jjmerelo
,
Raku core devmy $digits-of-ᴨ = Channel.new;
my &sequence-gap-four = { $^α, $^α+4 … ∞ };
my @σ-plus = sequence-gap-four( 5 );
my $one = start {
while my $σ = shift @σ-plus { $digits-of-ᴨ.send( 1.0 / $σ ) };
}
my @σ-minus = sequence-gap-four( 3 );
my $two = start {
while my $σ = shift @σ-minus { $digits-of-ᴨ.send( -1.0 / $σ ) };
}
my $ᴨ-so-far = 1;
my $p = start react {
whenever $digits-of-ᴨ -> $ε {
atomic-assign( $ᴨ-so-far, atomic-fetch( $ᴨ-so-far ) + $ε);
say $ᴨ-so-far*4;
}
}
await $p, $one, $two;
say "$_ → " ~ $_.Bool for (^10).map: { $_ but so $_ %% 2 };
use Colorizable;
for ^10 -> $κ {
my $ψ = ($κ but uniname(~$κ)) but Colorizable;
(given $ψ mod 3 {
when 0 { $ψ.colorize(:fg(red)) }
when 1 { $ψ.colorize(:fg(yellow)) }
when 2 { $ψ.colorize(:fg(blue)) }
}).say
};
sub priming( UInt $num where * --> Array[UInt] ) {
my @these-primes = (^($num/2)).grep: *.is-prime;
my UInt @factors = @these-primes.grep: !( $num mod * );
if ( (1,|@factors).sum == $num ) {
return @factors but "👑";
} elsif !@factors {
return @factors but "🍅";
} else {
return @factors;
}
}
for ^1000 -> $n {
my $result = priming($n);
say $n, ", ", ~$result;
}
grammar Measurements {
token TOP { <quantity> \h* <unit>? }
token quantity { <:N>+ }
token unit { ["g" | "tbsp" | "clove" | "cup" ] s? }
}
for "3 tbsps", "½ cup", "𐄩 cloves" -> $m {
say Measurements.parse( $m );
}
「3 tbsps」
quantity => 「3」
unit => 「tbsps」
「½ cup」
quantity => 「½」
unit => 「cup」
「𐄩 cloves」
quantity => 「𐄩」
unit => 「cloves」
my @unit-types=<g tbsp clove cup sp pinch>;
my @products=<lentils apple egg garlic>;
role Measures {
token quantity { <:N>+ }
token unit { @unit-types s? }
}
grammar Measured-Ingredients does Measures {
token TOP { <measured-ingredient> }
token measured-ingredient {
[ <quantity> \h* <unit> \h+ <product> || <quantity> \h+ <product>] s?
}
token product {:i @products }
}
for "1 cup lentils", "½ clove garlic", "2 eggs" -> $m {
say Measured-Ingredients.parse( $m );
}
for
indexed loopssub factors( $num ) {
my @these-primes = (^($num/2)).grep: *.is-prime;
print "\nFactors for $num →";
loop ( my $i = 1; $i < @these-primes.elems; $i++ ) {
(@these-primes[$i]~" ").print unless $num mod @these-primes[$i];
}
}
factors( $_ ) for 2..5000;
constant MAX-NUM = 5_000;
my @these-primes = (^(MAX-NUM/2)).grep: *.is-prime;
sub is-mod( $n, $b ) { ! ($n mod $b ) }
my @modders = @these-primes.map: -> $b { ( -> $c { is-mod( $c, $b ) } ) but $b };
(2..MAX-NUM).race.map: -> $n {
say $n, " ",
@modders.grep( *.Int <= $n/2)
.grep( { $_($n) } )
.map( *.Int ~ " " )
.join( ", " )
|| '🍅';
;}