Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl6
sub cubic(\a,\b,\c,\d) {
my \Δ0 = b² - 3 × a × c;
my \Δ1 = 2 * b³ - 9 × a × b × c + 27 × a² × d;
my \C = ( ( Δ1 + sqrt( Δ1² - 4 × Δ0³ + 0i) ) / 2 ).roots(3)[0];
my \ς = 1.roots(3); # cubic roots of unity
return [0,1,2].map: -> \k {
( -1 / ( 3 × a ) ) × ( b + ς[k] × C + Δ0 / ( C × ς[k] ) )
}
sub foo {
my @a = 1, 2;
my @b = 3, 4;
return @a, @b;
}
my (@c, @d) = foo();
say @c.perl;
say @d.perl;
#!/usr/bin/env perl6
use v6.c;
sub MAIN(Str $module) {
my $cu = $*REPO.need(CompUnit::DependencySpecification.new(:short-name($module)));
say $cu.distribution.prefix.child('sources/' ~ $cu.repo-id).path;
}
=begin pod

Keybase proof

I hereby claim:

  • I am bduggan on github.
  • I am bduggan (https://keybase.io/bduggan) on keybase.
  • I have a public key ASBRgyH0MlOEH4mWtv2eEswD4rWkMv3tM8WE39sKljcq3Ao

To claim this, I am signing this object:

#!/usr/bin/env perl6
# parse a little slim (<http://slim-lang.com>)
grammar slim {
rule TOP { <line>+ %% <eol>}
token line { <indentation> <tag> [ ' ' <text> ]? }
token indentation { <indent>* }
token indent { ' ' }
token tag { \w+ }
#!/usr/bin/env perl6
my @dates = Date.today, Date.today.succ ... ∞;
my %taken =
# first wednesday
plug-central => { $_.day-of-week == 3 and $_.weekday-of-month == 1 },
# second tuesday
plug-north => { $_.day-of-week == 2 and $_.weekday-of-month == 2 },
use nqp;
use QAST:from<NQP>;
# Slang to make "dog" a synonym for "do"
role Dogdo::Grammar {
token statement_prefix:sym<dog> { <sym><.kok> <blorst> }
}
role Dogdo::Actions {
use nqp;
use QAST:from<NQP>;
# Slang to make "dog" a synonym for "do"
role Dogdo::Grammar {
token statement_prefix:sym<dog> { <sym><.kok> <blorst> }
}
role Dogdo::Actions {
@bduggan
bduggan / div.p6
Last active August 30, 2016 13:37
#!/usr/bin/env perl6
grammar divspl {
rule TOP { <x=int>..<y=int> <assignment>+ }
rule assignment { <word> '=' <mod=int> }
token word { \w+ }
token int { \d+ }
}
# Custom operator:
@bduggan
bduggan / rsa.p6
Last active October 12, 2016 14:48
sub random-prime(:$digits) {
repeat { $_ = (10**$digits .. (10**($digits+1))).pick } until .is-prime;
return $_;
}
sub encrypt(:$message, :$key) {
return expmod($message,$key[0],$key[1])
}
sub decrypt(:$message, :$key) {