Skip to content

Instantly share code, notes, and snippets.

@MadcapJake
Created April 4, 2016 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadcapJake/280cdf8e42ad8a650cbbe9e01f9fe86f to your computer and use it in GitHub Desktop.
Save MadcapJake/280cdf8e42ad8a650cbbe9e01f9fe86f to your computer and use it in GitHub Desktop.
Chemical programming in Perl 6
sub prime-reaction(@ (Int $a, Int $b)) {
$a > $b && $a %% $b ?? [($a div $b), $b] !! [$a, $b]
}
my @molecules = 2..101;
sub mix-and-react(@mols is raw) {
my @mixed = (@mols.pick: *).rotor(2);
@mols = @mixed.map(&prime-reaction).flat;
}
sub reaction-cycle(UInt $n) {
my @mols = @molecules;
mix-and-react(@mols) for [^$n];
@mols;
}
say reaction-cycle(1000).unique.sort;