aboutsummaryrefslogtreecommitdiff
path: root/challenge-148/2colours/raku/ch-2.raku
blob: 8fb3b5e51d3f1d309d2beb3e0570515c857a9099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env raku

sub cardano-sum($a, $b, $c) {
  ($a+$b*$c**0.5 andthen .sign*.abs**(1/3))+($a-$b*$c**0.5 andthen .sign*.abs**(1/3))
}


my $cardano-triplets = gather {
  for 1..Inf -> $biggest {
    for 1..$biggest -> $mid {
      for 1..$mid -> $smallest {
        .take if cardano-sum(|$_) =~= 1 for permutations(($biggest, $mid, $smallest));
      }
    }
  }
}
.join(" ").say for $cardano-triplets.head(5);