aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Manfredi <manfredi@cpan.org>2023-05-15 15:00:06 +0000
committerLeo Manfredi <manfredi@cpan.org>2023-05-15 15:00:06 +0000
commit03871563f8bf8d03f2308c684b57282968f2018b (patch)
tree7798afe54ad60cb8a53514f728c0b27d915aa8d3
parent2c1bcc0ab979fa1d961919dc782cdcc322d7ed63 (diff)
downloadperlweeklychallenge-club-03871563f8bf8d03f2308c684b57282968f2018b.tar.gz
perlweeklychallenge-club-03871563f8bf8d03f2308c684b57282968f2018b.tar.bz2
perlweeklychallenge-club-03871563f8bf8d03f2308c684b57282968f2018b.zip
Perl Solution for Challenge-217 Task #2 by Leo Manfredi
-rwxr-xr-xchallenge-217/manfredi/perl/ch-2.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-217/manfredi/perl/ch-2.pl b/challenge-217/manfredi/perl/ch-2.pl
new file mode 100755
index 0000000000..c0255b11c3
--- /dev/null
+++ b/challenge-217/manfredi/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use v5.36;
+
+say "challenge-217-task2";
+
+# Task 2: Max Number
+# You are given a list of positive integers.
+# Write a script to concatenate the integers to form the highest possible value.
+
+# Example 1
+# Input: @list = (1, 23)
+# Output: 231
+
+# Example 2
+# Input: @list = (10, 3, 2)
+# Output: 3210
+
+# Example 3
+# Input: @list = (31, 2, 4, 10)
+# Output: 431210
+
+sub max_number {
+ my @list = @{+shift};
+ $" = ', ';
+ say "Input: \@list = (@list)";
+ my $out = join "", sort { $b cmp $a } @list;
+ say "Output: $out\n";
+}
+
+while (<DATA>) {
+ chomp;
+ my @list = split /\s*,\s*/;
+ max_number(\@list);
+}
+
+
+__DATA__
+1, 23
+10, 3 ,2
+31, 2 , 4, 10
+5, 11, 4, 1, 2
+1, 10