aboutsummaryrefslogtreecommitdiff
path: root/challenge-050
diff options
context:
space:
mode:
authoruser-person <60802990+user-person@users.noreply.github.com>2020-03-08 15:45:25 -0400
committerGitHub <noreply@github.com>2020-03-08 15:45:25 -0400
commit5dc6b4235c4ff49c245eeb429da1993fc53141d8 (patch)
tree309440460a98270109f1c0c832c48c3322ea8cfc /challenge-050
parent3f54c0f817fd90c25485767df844d08f89974c57 (diff)
downloadperlweeklychallenge-club-5dc6b4235c4ff49c245eeb429da1993fc53141d8.tar.gz
perlweeklychallenge-club-5dc6b4235c4ff49c245eeb429da1993fc53141d8.tar.bz2
perlweeklychallenge-club-5dc6b4235c4ff49c245eeb429da1993fc53141d8.zip
Create ch-2.py
Diffstat (limited to 'challenge-050')
-rw-r--r--challenge-050/user-person/python/ch-2.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/challenge-050/user-person/python/ch-2.py b/challenge-050/user-person/python/ch-2.py
new file mode 100644
index 0000000000..4ccab6057d
--- /dev/null
+++ b/challenge-050/user-person/python/ch-2.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+
+###########################################################################
+# script name: ch-2.py #
+# #
+# https://github.com/user-person #
+# #
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-050/ #
+# #
+# 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 re
+import sys
+
+def nobleInt(ints):
+ seen = dict()
+ ints.sort(key=int)
+
+ for i in ints:
+ count = 0
+
+ for j in ints:
+
+ if int(i) < int(j):
+ count += 1
+
+ if int(count) == int(i):
+ if i in seen:
+ seen[i] += 1
+ else:
+ seen.update({i:1})
+ return seen.keys()
+
+input = "[2, 6, 1, 3]"
+
+if len(sys.argv) > 1:
+ input = ' '.join(sys.argv[1:])
+else:
+ print('default input:',input)
+
+input = re.sub(r'[][, ]+', ' ', input)
+input = re.sub(r'\A\s+|\s+\Z', '', input)
+L = re.split(r' ', input)
+
+nobleInteger = nobleInt(L)
+
+if nobleInteger:
+ for kys in nobleInteger:
+ print('noble integer:',kys)
+else:
+ print('No noble integer.')