aboutsummaryrefslogtreecommitdiff
path: root/challenge-126/stuart-little/python/ch-1.py
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2021-08-18 15:07:49 -0400
committerDave Jacoby <jacoby.david@gmail.com>2021-08-18 15:07:49 -0400
commit710837b2a38b5fbd4404f8d9be06ef368af0d366 (patch)
tree8796e6c6c7be4f7f935e68f3f0bff99bed04eb57 /challenge-126/stuart-little/python/ch-1.py
parent637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3 (diff)
parent73470591f10490d6385145990c49825266f80b2b (diff)
downloadperlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.tar.gz
perlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.tar.bz2
perlweeklychallenge-club-710837b2a38b5fbd4404f8d9be06ef368af0d366.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-126/stuart-little/python/ch-1.py')
-rwxr-xr-xchallenge-126/stuart-little/python/ch-1.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-126/stuart-little/python/ch-1.py b/challenge-126/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..aea89f2b33
--- /dev/null
+++ b/challenge-126/stuart-little/python/ch-1.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+# run <script> <number>
+
+import sys
+
+def no1(nr):
+ if len(nr)==0:
+ return 0
+ if nr[0] == '1':
+ return 9**(len(nr)-1)
+ return (int(nr[0])-1) * 9**(len(nr)-1) + no1(nr[1:])
+
+print(no1(sys.argv[1]) if '1' not in sys.argv[1] else (no1(sys.argv[1])-1))