blob: 9a9072a56c32e48e089ce4f796f83cc1fd1fe270 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/bin/sh
#
# See ../README.md
#
#
# Run as: bash ch-2.sh < input-file
#
#
# 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.
#
while read index
do declare -a out
hash=0
i=0
while ((index > 0))
do ((i ++))
if ((hash = !hash))
then out[$i]="#"
((index --))
else number=$((index + 1))
out[$i]=$number
((index -= ${#number}))
fi
done
for ((; i; i --))
do printf "%s" ${out[$i]}
done
echo
done
|