diff options
| -rwxr-xr-x | challenge-217/manfredi/perl/ch-2.pl | 43 |
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 |
