aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Manfredi <manfredi@cpan.org>2023-05-16 08:52:57 +0000
committerLeo Manfredi <manfredi@cpan.org>2023-05-16 08:52:57 +0000
commit351ab7549b122a1c6eb162fd15248f2d2696aa39 (patch)
tree25270a30be5d8ac74a57afc942abbbd9d114f8da
parent03871563f8bf8d03f2308c684b57282968f2018b (diff)
downloadperlweeklychallenge-club-351ab7549b122a1c6eb162fd15248f2d2696aa39.tar.gz
perlweeklychallenge-club-351ab7549b122a1c6eb162fd15248f2d2696aa39.tar.bz2
perlweeklychallenge-club-351ab7549b122a1c6eb162fd15248f2d2696aa39.zip
Python Solution for Challenge-217 Task #2 by Leo Manfredi
-rwxr-xr-xchallenge-217/manfredi/python/ch-2.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-217/manfredi/python/ch-2.py b/challenge-217/manfredi/python/ch-2.py
new file mode 100755
index 0000000000..5742710086
--- /dev/null
+++ b/challenge-217/manfredi/python/ch-2.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# Python 3.9.2 on Debian GNU/Linux 11 (bullseye)
+
+print('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
+
+def max_number(nums: list[int]) -> int:
+ print(f"Input: list = {nums}")
+ out = ''.join(sorted([ str(i) for i in nums], reverse = True))
+ return int(out)
+
+
+def main():
+ print("Output: ", max_number([1, 23]), "\n")
+ print("Output: ", max_number([10, 3 ,2]), "\n")
+ print("Output: ", max_number([31, 2 , 4, 10]), "\n")
+ print("Output: ", max_number([5, 11, 4, 1, 2]), "\n")
+ print("Output: ", max_number([1, 10]), "\n")
+
+
+if __name__ == '__main__':
+ main()