diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-12-29 01:45:22 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-29 01:45:22 +0000 |
| commit | 5fc8f804852823a7311fb64dd328d08d32391dbd (patch) | |
| tree | a398e7f756851ef27d498f718c3845a14f0b19cb | |
| parent | 6a64d6f60114dd9be9cc1c820eaf7c729f20b1c7 (diff) | |
| parent | fc9429cb389cec41cbc8c303e18d5591420f0291 (diff) | |
| download | perlweeklychallenge-club-5fc8f804852823a7311fb64dd328d08d32391dbd.tar.gz perlweeklychallenge-club-5fc8f804852823a7311fb64dd328d08d32391dbd.tar.bz2 perlweeklychallenge-club-5fc8f804852823a7311fb64dd328d08d32391dbd.zip | |
Merge pull request #1076 from noudald/challenge-040-noud
Solution to challenge 40 task 1 and 2 in Raku by Noud
| -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]); |
