aboutsummaryrefslogtreecommitdiff
path: root/challenge-195/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-12-24 08:40:55 +0000
committerGitHub <noreply@github.com>2022-12-24 08:40:55 +0000
commit9af7a6fb5c30a5d3813c99d8c16f22ea0a10f673 (patch)
treededb149ca155f9edef7752a2b68c56a1611a139b /challenge-195/sgreen/python/ch-1.py
parent03a5b2e285225643226df71df1370033e195f9e0 (diff)
parent1c0933f0c2594679a6396cd86c5455b81d455ac7 (diff)
downloadperlweeklychallenge-club-9af7a6fb5c30a5d3813c99d8c16f22ea0a10f673.tar.gz
perlweeklychallenge-club-9af7a6fb5c30a5d3813c99d8c16f22ea0a10f673.tar.bz2
perlweeklychallenge-club-9af7a6fb5c30a5d3813c99d8c16f22ea0a10f673.zip
Merge pull request #7299 from simongreen-net/master
Simon's solution to challenge 195 and 196
Diffstat (limited to 'challenge-195/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-195/sgreen/python/ch-1.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-195/sgreen/python/ch-1.py b/challenge-195/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..4b3831a16c
--- /dev/null
+++ b/challenge-195/sgreen/python/ch-1.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import sys
+
+
+def is_simple_number(n):
+ # Determine if the number is simple
+ seen = {}
+ for i in str(n):
+ if i in seen:
+ # We've seen the digit before. It's not simple
+ return False
+ seen[i] = 1
+
+ # It is simple
+ return True
+
+
+def main(n):
+ # Iterate through the list counting the number of simple numbers
+ simple_count = 0
+ for i in range(1, n+1):
+ if is_simple_number(i):
+ simple_count += 1
+
+ # Print the result
+ print(simple_count)
+
+
+if __name__ == '__main__':
+ main(int(sys.argv[1]))