Created
April 4, 2016 16:10
-
-
Save MadcapJake/280cdf8e42ad8a650cbbe9e01f9fe86f to your computer and use it in GitHub Desktop.
Chemical programming in Perl 6
This file contains hidden or 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 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Video] "Unconventional Programming with Chemical Computing" by Carin Meier
[Article] "Chemical Computing with Clojure" by Carin Meier
[PDF] "Principles of Chemical Programming" by Jean-Pierre Banâtre, Pascal Fradet and Yann Radenac
[Code] Same algorithm in Clojure