diff options
| -rw-r--r-- | challenge-040/noud/perl6/ch1.p6 | 34 | ||||
| -rw-r--r-- | challenge-040/noud/perl6/ch2.p6 | 19 |
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-040/noud/perl6/ch1.p6 b/challenge-040/noud/perl6/ch1.p6 new file mode 100644 index 0000000000..7e47a94853 --- /dev/null +++ b/challenge-040/noud/perl6/ch1.p6 @@ -0,0 +1,34 @@ +# Show multiple arrays content +# +# You are given two or more arrays. Write a script to display values of each +# list at a given index. +# +# For example: +# Array 1: [ I L O V E Y O U ] +# Array 2: [ 2 4 0 3 2 0 1 9 ] +# Array 3: [ ! ? £ $ % ^ & * ] +# +# We expect the following output: +# +# I 2 ! +# L 4 ? +# O 0 £ +# V 3 $ +# E 2 % +# Y 0 ^ +# O 1 & +# U 9 * + +my @arr1 = <I L O V E Y O U>; +my @arr2 = <2 4 0 3 2 0 1 9 5 6 7 8>; +my @arr3 = <! ? £ $ % ^ & * ( )>; + +sub print_intertwined(**@arrs) { + my $sub_arr_max = max(($_.elems for @arrs)); + @arrs = ((|$_, " " xx $sub_arr_max - $_.elems).flat for @arrs); + for [Z] @arrs -> @arr { + say join(" ", @arr); + } +} + +print_intertwined(@arr1, @arr2, @arr3); diff --git a/challenge-040/noud/perl6/ch2.p6 b/challenge-040/noud/perl6/ch2.p6 new file mode 100644 index 0000000000..1c7059f187 --- /dev/null +++ b/challenge-040/noud/perl6/ch2.p6 @@ -0,0 +1,19 @@ +# Sort SubList +# +# You are given a list of numbers and set of indices belong to the list. Write +# a script to sort the values belongs to the indices. +# +# For example, +# List: [ 10, 4, 1, 8, 12, 3 ] +# Indices: 0,2,5 +# +# We would sort the values at indices 0, 2 and 5 i.e. 10, 1 and 3. +# +# Final List would look like below: +# List: [ 1, 4, 3, 8, 12, 10 ] + +sub subsort(@arr, @ind) { + @arr[@ind] = @arr[@ind].sort; @arr; +} + +say subsort([10, 4, 1, 8, 12, 3], [0, 2, 5]); |
