diff options
| -rw-r--r-- | challenge-213/solathian/perl/ch-1.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-213/solathian/perl/ch-1.pl b/challenge-213/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..a37700a617 --- /dev/null +++ b/challenge-213/solathian/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!usr/bin/perl +use v5.36; + +# Challenge 213 - 1 - Fun Sort +# You are given a list of positive integers. +# Write a script to sort the all even integers first then all odds in ascending order. + +funSort(1,2,3,4,5,6); # Output: (2,4,6,1,3,5) +funSort(1,2); # 2,1 +funSort(1); # 1 +funSort(78,22,11,14,25,76); + +sub funSort(@input) +{ + @input = sort @input; + my @odd = grep{ ($_% 2) != 0} @input; + my @even = grep{ ($_% 2) == 0} @input; + say join(',', @even, @odd ); + + # in one line + # say join(',', (grep{ ($_% 2) == 0} sort @input), grep{ ($_% 2) != 0} @input); +}
\ No newline at end of file |
