aboutsummaryrefslogtreecommitdiff
path: root/challenge-117/abigail/bash/ch-2.sh
blob: a5a5593dad8c2581844ac589221c94d5e0374934 (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
#!/bin/sh

#
# See ../README.md
#

#
# Run as: bash ch-2.sh < input-file
#

set -f

function steps () {
    local x=$1
    local y=$2
    local path=$3
    if   ((x == 0 && y == 0))
    then echo $path
         return
    fi
    if   ((x > 0)) 
    then steps $((x - 1)) $y         ${path}R
         steps $((x - 1)) $((y + 1)) ${path}L
    fi
    if   ((y > 0))
    then steps $x         $((y - 1)) ${path}H
    fi
}

read number
steps $number 0 ""