aboutsummaryrefslogtreecommitdiff
path: root/challenge-050/paulo-custodio/python/ch-2.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
committerLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
commit65b9d6b25e0a823ca7ab6d15744ff98eb3697471 (patch)
treefcbcdebd50e3e146dfecf519701ec04b191053eb /challenge-050/paulo-custodio/python/ch-2.py
parentbd1fe7ae50ca42bda58c134b9edfdc287fb3f386 (diff)
parent68e321dd32a834f54b55d5e8924f04358e41cf1f (diff)
downloadperlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.gz
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.bz2
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-050/paulo-custodio/python/ch-2.py')
-rw-r--r--challenge-050/paulo-custodio/python/ch-2.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-050/paulo-custodio/python/ch-2.py b/challenge-050/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..7b3baa0f9d
--- /dev/null
+++ b/challenge-050/paulo-custodio/python/ch-2.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+# Challenge 050
+#
+# TASK #2
+# Contributed by Ryan Thompson.
+# Noble Integer
+# You are given a list, @L, of three or more random integers between 1 and 50.
+# A Noble Integer is an integer N in @L, such that there are exactly N integers
+# greater than N in @L. Output any Noble Integer found in @L, or an empty list
+# if none were found.
+#
+# An interesting question is whether or not there can be multiple Noble Integers
+# in a list.
+#
+# For example,
+#
+# Suppose we have list of 4 integers [2, 6, 1, 3].
+#
+# Here we have 2 in the above list, known as Noble Integer, since there are
+# exactly 2 integers in the list i.e.3 and 6, which are greater than 2.
+#
+# Therefore the script would print 2.
+
+import sys
+
+def noble_int(nums):
+ out = []
+ for n in nums:
+ num_greater = len([x for x in filter(lambda x: x > n, nums)])
+ if num_greater == n:
+ out.append(n)
+ return out
+
+nums = [int(x) for x in range(1, len(sys.argv))]
+noble = noble_int(nums)
+print("("+", ".join(str(x) for x in noble)+")")