Zig some zags

This commit is contained in:
Nick Chambers 2022-10-07 23:24:53 -05:00
parent 26485da5ea
commit 615a322641
1 changed files with 24 additions and 0 deletions

24
bash/zigzag Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
zig_len=7 zag_len=20 zog_len=50
offset=$(( zag_len - zig_len ))
for (( idx = 0; idx < zig_len; idx += 1 )); do
zigs+=*
done
for (( idx = 0; idx < zog_len; idx += 1 )); do
printf '%*s%s\n' "$offset" "" "$zigs"
if (( (offset + zig_len) == zag_len )); then
dir=left
elif (( offset == 0 )); then
dir=right
fi
if [[ $dir = left ]]; then
(( offset -= 1 ))
else
(( offset += 1 ))
fi
done