From 44b41f2e16ab83801cfa34fb07fa5c2ef46be24c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 6 Oct 2021 12:03:06 +0200 Subject: Task 1 done --- challenge-133/luca-ferrari/raku/ch-1.p6 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-133/luca-ferrari/raku/ch-1.p6 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; + +} -- cgit