diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-23 18:46:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-23 18:46:28 +0100 |
| commit | 2bfca8e4877d83e08187b58433dccf3aacd069bb (patch) | |
| tree | f7d8de91ea1c7b38c8b7dbca4729af02855fa56a | |
| parent | aff2c17aafd8934f0d82485e8f930aa43d39ab33 (diff) | |
| parent | eb32888413cd1e683a4e7a155ebb5c23881f3aee (diff) | |
| download | perlweeklychallenge-club-2bfca8e4877d83e08187b58433dccf3aacd069bb.tar.gz perlweeklychallenge-club-2bfca8e4877d83e08187b58433dccf3aacd069bb.tar.bz2 perlweeklychallenge-club-2bfca8e4877d83e08187b58433dccf3aacd069bb.zip | |
Merge pull request #7955 from Solathian/branch-for-challenge-213
Added file for challenge
| -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 |
