From ebac4b18af015635450325e7c770794cd70a6d2c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 4 May 2020 14:12:36 +0200 Subject: Task one done. --- challenge-059/luca-ferrari/raku/ch-1.p6 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-059/luca-ferrari/raku/ch-1.p6 (limited to 'challenge-059') diff --git a/challenge-059/luca-ferrari/raku/ch-1.p6 b/challenge-059/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..ad73ef8831 --- /dev/null +++ b/challenge-059/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,28 @@ +#!env raku + + +# You are given a linked list and a value k. +# Write a script to partition the linked list such that all nodes +# less than k come before nodes greater than or equal to k. +# Make sure you preserve the original +# relative order of the nodes in each of the two partitions. +# +# For example: +# +# Linked List: 1 → 4 → 3 → 2 → 5 → 2 +# +# k = 3 +# +# Expected Output: 1 → 2 → 2 → 4 → 3 → 5. + + +# example of invocation +# % raku ch-1.p6 --k=4 +# Index 4 makes 1 4 3 2 5 2 to become 1 3 2 2 4 5 + +sub MAIN( Int:D :$k = 3 ) { + + my @L = 1, 4, 3, 2, 5, 2 ; + my @l = | @L.grep( * < $k ), | @L.grep( * >= $k ); + say "Index $k makes { @L } to become { @l }"; +} -- cgit