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 natural ($a) { $a.subst(/(\d+)/, ->$/ {0~$0.chars~$0},:g)~$a } | |
sub ncollate (@list){ # this works... but yuck | |
@list[@list.kv.map( { [$^k, $^v.&natural] } ).sort( { $^a[1] unicmp $^b[1] } )[*;0]] | |
}; | |
my @words = <32nd 3rd 144th 17th 2 95 apple ball Bald | |
Æon æon aether Évian evoke außen Autumn file3 file21 file17>; | |
#say @words.sort; |
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
# Testing against https://github.com/samcv/MoarVM/tree/natural | |
# using a Perl6 / NQP build against that branch. | |
# For these very limited character sets, I would expect these to return | |
# essentially the same results, except perhaps for digit clusters with leading zeros | |
use experimental :collation; | |
# Ideally, numerics would sort before alphabetics; the UCA sorts | |
# numbers after letters so that may not be practical. |
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
(cb e4ae25d 1e3716ac46 5 83cc4a 677ced28 2456 7048bbe40 7098 7290ddc7) | |
(cb e4ae25d 1e3716ac46 5 83cc4a 677ced28 7098 2456 7048bbe40 7290ddc7) | |
------------------------------------------------------------ | |
(a bc9835 1ea5969c5 3 3a7c47a33 8c654 80 83c3358 317995 632923) | |
(a bc9835 1ea5969c5 3 3a7c47a33 8c654 80 83c3358 632923 317995) | |
------------------------------------------------------------ | |
(ada4 c e3 e9836a 6e 34e093 95 142a47c 513c2b 79388a0d) | |
(ada4 c e3 e9836a 6e 34e093 95 513c2b 142a47c 79388a0d) | |
------------------------------------------------------------ | |
(da9 db39c67d3 e06d97 6750951822 5ab8a02 07be3e3a5c 32d 063 284c 9877ed6) |
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
# When trying to read and write some PPM files through a pipe, able to read a Proc through a pipe using default filehandle '-' | |
# but not able to figure out the syntax to write to the default file handle throug a Proc pipe. | |
# The two scripts below demonstrate. Both require that imagemagick is installed and ready to use, specifically the 'convert' program. | |
# Using the camelia.png file from from: | |
# https://github.com/thundergnat/rc/blob/master/img/camelia.png | |
# downloaded to the same directory that the script is in; ppm-read.pipe.p6 succesfully reads a Proc on the | |
# default file handle to generate camelia.ppm, but ppm-convert.pipe.p6 is unable to write to a Proc on the |
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 NativeCall; | |
class Xdo is export { | |
has Pointer $.id is rw; | |
submethod BUILD { | |
sub xdo_new(Str) returns Pointer is native('xdo') { * } | |
self.id = xdo_new(''); | |
} |
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 Rat::Precise; # thundergnat++ | |
constant D = 54; # does double-duty: number-of-decimals (π), terms in Taylor series (𝑒) | |
constant d = 15; # digits past decimal for output | |
# exponentiation where base and exponent are both FatRat | |
multi infix:<**> (FatRat $base, FatRat $exp where * >= 1 --> FatRat) { | |
2 R** $base**($exp/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
# Challenge #1 | |
#`[ Slow, naive, brute force perfect number calculation | |
sub is-perfect (Int $n) { | |
($n == sum grep $n %% *, 1 .. $n div 2) ?? | |
$n !! | |
Empty | |
} | |
] |
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 wat ($n) { | |
($n .. 1).map: -> $m { say "uno: $m" } | |
($n .. 1).map: -> $m { say "dos: $m" } | |
} | |
for ^2 -> $m { say "|$m|"; wat($m) } # explicit for loop variable | |
say ''; | |
for ^2 { say "|$_|"; wat($_) } # implicit for loop variable |
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
# Generated by running in the perl6-Math-Sequences directory: | |
# grep '&NOSEQ ...' ./lib/Math/Sequences/Integer.pm6 | |
# If we don't yet have a formula for a given sequence, we use &NOSEQ in a | |
our @A000001 is export = 0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, &NOSEQ ... *; | |
our @A000014 is export = 0, 1, 1, 0, 1, 1, 2, 2, 4, 5, 10, 14, &NOSEQ ... *; | |
our @A000019 is export = 1, 1, 2, 2, 5, 4, 7, 7, 11, 9, 8, 6, &NOSEQ ... *; | |
our @A000029 is export = 1, 2, 3, 4, 6, 8, 13, 18, 30, 46, 78, &NOSEQ ... *; | |
our @A000031 is export = 1, 2, 3, 4, 6, 8, 14, 20, 36, 60, 108, &NOSEQ ... *; | |
our @A000041 is export = 1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, &NOSEQ ... *; |
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
my %core = ( | |
:A000001("groups") | |
:A000002("kolakoski") | |
:A000004("zeroes") | |
:A000005("divisors") | |
:A000007("zeros-powers") | |
:A000009("distinct-partitions") | |
:A000010("totient") | |
:A000012("ones") | |
:A000014("series-reduced-trees") |
OlderNewer