-
-
Save raydiak/a9063c068f93a162ca2e to your computer and use it in GitHub Desktop.
1/p + 1/q + 1/r = 1/2 where 0 < p <= q <= r
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
#!/usr/bin/env perl6 | |
my $bound = 100; | |
my @answers; | |
Pl: for 3..$bound -> $p { | |
my $pv = 1 / $p; | |
Ql: for $p..$bound -> $q { | |
my $qv = 1 / $q; | |
Rl: for $q..$bound -> $r { | |
my $rv = 1 / $r; | |
my $v = $pv + $qv + $rv; | |
push @answers, {:$p,:$q,:$r} if $v == 1/2; | |
last Pl if @answers == 10; | |
} | |
} | |
} | |
.say for @answers; | |
#`[[[ | |
p => 3, q => 7, r => 42 | |
p => 3, q => 8, r => 24 | |
p => 3, q => 9, r => 18 | |
p => 3, q => 10, r => 15 | |
p => 3, q => 12, r => 12 | |
p => 4, q => 5, r => 20 | |
p => 4, q => 6, r => 12 | |
p => 4, q => 8, r => 8 | |
p => 5, q => 5, r => 10 | |
p => 6, q => 6, r => 6 | |
]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment