aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/abigail/python/ch-2.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-03-15 18:13:51 +0800
committer冯昶 <seaker@qq.com>2021-03-15 18:13:51 +0800
commit8b6be37fe4dac8b4c6489a95e55514b76b298d15 (patch)
treeae36c8ec2c71f606c0e36adaa19dba366a68a0b4 /challenge-102/abigail/python/ch-2.py
parent865acfd056fb6f409ec6b1a81d60b931cbcb69fe (diff)
parentc9aec2da6bcb04b488183f09ca94bee488557aff (diff)
downloadperlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.gz
perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.bz2
perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.zip
Merge branch 'master' of github.com:seaker/perlweeklychallenge-club
Diffstat (limited to 'challenge-102/abigail/python/ch-2.py')
-rw-r--r--challenge-102/abigail/python/ch-2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-102/abigail/python/ch-2.py b/challenge-102/abigail/python/ch-2.py
new file mode 100644
index 0000000000..e8c3ee71ec
--- /dev/null
+++ b/challenge-102/abigail/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as python ch-2.py < input-file
+#
+
+import fileinput
+
+#
+# Working from the end of the required string backwards, we alternate
+# placing a hash, and placing a number. We place them in an array @out,
+# and at the end, print out said array in reverse order.
+#
+for index in fileinput . input ():
+ index = int (index)
+ out = []
+ hash = 0
+ while index > 0:
+ hash = not hash
+ if hash:
+ out . append ("#")
+ index = index - 1
+ else:
+ out . append (str (index + 1))
+ index = index - len (str (index + 1))
+ out . reverse ()
+ print ("" . join (out))