Skip to content

Instantly share code, notes, and snippets.

View hakank's full-sized avatar

Hakan Kjellerstrand hakank

View GitHub Profile
@masak
masak / find-all-cycles.pl
Created March 12, 2012 10:43
Find and show all cycles of a permutation
use v6;
sub MAIN(*@p) {
die "Arguments need to be integers"
unless all(@p) ~~ /^ \d+ $/;
die "Arguments need to be 1..N in some order"
unless sort(@p) ~~ [1..@p];
say "($_)" for sort *.[0], gather for @p -> $e {
next if (state %handled).exists($e);