diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-23 10:08:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-23 10:08:55 +0100 |
| commit | c82c4c1db8564c896d8d9366b246f86755527666 (patch) | |
| tree | fdae4fcbb706150a67181eefbdbdc998d3b3591d | |
| parent | 5f14b5870373a7d2e2289e75e55135bbc44083f3 (diff) | |
| parent | e300352273eb3e133665afbffe334e205d9ee10a (diff) | |
| download | perlweeklychallenge-club-c82c4c1db8564c896d8d9366b246f86755527666.tar.gz perlweeklychallenge-club-c82c4c1db8564c896d8d9366b246f86755527666.tar.bz2 perlweeklychallenge-club-c82c4c1db8564c896d8d9366b246f86755527666.zip | |
Merge pull request #7939 from deoac/new-branch
Initial submission
| -rwxr-xr-x | challenge-213/shimon-ben-avraham/raku/ch-1.raku | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/challenge-213/shimon-ben-avraham/raku/ch-1.raku b/challenge-213/shimon-ben-avraham/raku/ch-1.raku new file mode 100755 index 0000000000..de8e496141 --- /dev/null +++ b/challenge-213/shimon-ben-avraham/raku/ch-1.raku @@ -0,0 +1,56 @@ +#! /usr/bin/env raku +use v6.d; + +#=============================================================================== +# +# FILE: <ch-1.raku> +# +# DESCRIPTION: A solution to the Perl Weekly Challenge 213, Challenge 1 +# +# AUTHOR: Shimon Bollinger (deoac.shimon@gmail.com) +# REVISION: Last modified: Fri 21 Apr 2023 03:18:29 PM EDT +#=============================================================================== + +=begin comment + Task 1: Fun Sort + Submitted by: Mohammad S Anwar + You are given a list of positive integers. + + Write a script to sort the all even integers first + then all odds in ascending order. + + Example 1 + Input: @list = (1,2,3,4,5,6) + Output: (2,4,6,1,3,5) + Example 2 + Input: @list = (1,2) + Output: (2,1) + Example 3 + Input: @list = (1) + Output: (1) +=end comment + +sub FunSort (@list) { + return @list if @list.elems == 1; + + my %split = @list.classify:{ $_ %% 2 ?? 'even' !! 'odd' }; + my @evens = |%split<even>.sort; + my @odds = |%split<odd>.sort; + my @retval = |@evens, |@odds; +} # end of sub MAIN (ℕ @list) + +use Test; +my @list; + +@list = (1,2,3,4,5,6); +ok FunSort(@list), (2,4,6,1,3,5); + +@list = (1,2); +ok FunSort(@list), (2,1); + +@list = (1); +ok FunSort(@list), (1); + +@list = (1..^100).pick(50).grep: (* > 0); +say FunSort(@list); + |
