From eb32888413cd1e683a4e7a155ebb5c23881f3aee Mon Sep 17 00:00:00 2001 From: Solathian Date: Sun, 23 Apr 2023 19:44:33 +0200 Subject: Added file for challenge --- challenge-213/solathian/perl/ch-1.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-213/solathian/perl/ch-1.pl 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 -- cgit