From e300352273eb3e133665afbffe334e205d9ee10a Mon Sep 17 00:00:00 2001 From: deoac Date: Fri, 21 Apr 2023 15:19:44 -0400 Subject: Initial submission --- challenge-213/shimon-ben-avraham/raku/ch-1.raku | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 challenge-213/shimon-ben-avraham/raku/ch-1.raku 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: +# +# 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.sort; + my @odds = |%split.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); + -- cgit