diff options
| -rw-r--r-- | challenge-133/luca-ferrari/raku/ch-1.p6 | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-133/luca-ferrari/raku/ch-1.p6 b/challenge-133/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..0f7a2ce5c4 --- /dev/null +++ b/challenge-133/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,18 @@ +#!raku + + +sub MAIN( Int $n where { $n > 0 } ) { + $n.say and exit if $n == 1; + + my Int $current-solution = $n +> 1; # divide by two + my Int $next-solution = 0; + while ( $next-solution < $current-solution ) { + $next-solution = ( $current-solution + $n / $current-solution ) +> 1 if ! $next-solution; + ( $current-solution, $next-solution ) = $next-solution, + ( $next-solution + $n / $next-solution ) +> 1; + + } + + $current-solution.say; + +} |
