#Pure bash, 43
Pure bash, 43
echo $[$1<2?1:$[$1<2?2:$1]#`printf 1%0$1d`]
Not sure if this is bending the rules too much - I'm not using any of the listed banned builtins, but I am using base conversion.
printf 1%0$1d
outputs a1
followed by n0
s$[b#a]
is an arithmetic expansion to treata
as a baseb
number, which gives the required result. Unfortunately base <2 does not work, so the extra?:
bits handle input n=1.
Maximum input is 15, because bash uses signed 64-bit integers (up to 231-1).