diff options
| -rw-r--r-- | challenge-071/luca-ferrari/raku/ch-2.p6 | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/challenge-071/luca-ferrari/raku/ch-2.p6 b/challenge-071/luca-ferrari/raku/ch-2.p6 index 43e64e31ed..947f83a1ca 100644 --- a/challenge-071/luca-ferrari/raku/ch-2.p6 +++ b/challenge-071/luca-ferrari/raku/ch-2.p6 @@ -36,17 +36,17 @@ sub MAIN( Int $N where { $N > 0 }, *@list ) { # build the list backward and keep the root # at the list - my $root = Nil; + my $head = Nil; my $current = Nil; loop ( my $i = @list.elems - 1; $i >= 0; $i-- ) { - $root = Node.new( value => @list[ $i ], - next => $root ); + $head = Node.new( value => @list[ $i ], + next => $head ); } # compute the size of the list - my $size-of-the-list = $root.size; + my $size-of-the-list = $head.size; "Size of the list is $size-of-the-list".say; - $root.put; + $head.put; @@ -57,12 +57,12 @@ sub MAIN( Int $N where { $N > 0 }, *@list ) { # particular case: remove the root - $root = $root.next if ( $index == $index-to-remove || $N > $size-of-the-list ); + $head = $head.next if ( $index == $index-to-remove || $N > $size-of-the-list ); # remove a specific element, but only if this has not been already done # by removing the root element and thus changing the size of the list - if ( $root.size == $size-of-the-list ) { - $current = $root; + if ( $head.size == $size-of-the-list ) { + $current = $head; while ( $current ) { if ( ( $index + 1 ) == ( $size-of-the-list - $N + 1 ) ) { $current.next = $current.next.next; @@ -76,6 +76,6 @@ sub MAIN( Int $N where { $N > 0 }, *@list ) { # print the modified list - $root.put; + $head.put; } |
