aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolathian <horvath6@gmail.com>2023-04-23 19:44:33 +0200
committerSolathian <horvath6@gmail.com>2023-04-23 19:44:33 +0200
commiteb32888413cd1e683a4e7a155ebb5c23881f3aee (patch)
treea66986bdc0463e2bd73e4e5bd0560abe9a116762
parent3bcdfe001066427080c312acaa506ea3c8a845e2 (diff)
downloadperlweeklychallenge-club-eb32888413cd1e683a4e7a155ebb5c23881f3aee.tar.gz
perlweeklychallenge-club-eb32888413cd1e683a4e7a155ebb5c23881f3aee.tar.bz2
perlweeklychallenge-club-eb32888413cd1e683a4e7a155ebb5c23881f3aee.zip
Added file for challenge
-rw-r--r--challenge-213/solathian/perl/ch-1.pl22
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