From 26ae49523623bfe48ad8ccfa78efbea4d1378133 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 3 Mar 2021 02:51:30 +0100 Subject: Ruby solution for week 102, part 2 --- challenge-102/abigail/python/ch-2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-102/abigail/python/ch-2.py (limited to 'challenge-102/abigail/python/ch-2.py') 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)) -- cgit