From b6fb49a0b434f1a5d68c434503d70b64cb4383c7 Mon Sep 17 00:00:00 2001 From: Mia Date: Wed, 23 Feb 2022 13:41:21 -0500 Subject: [PATCH] fix borrow() --- subtraction/sub | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/subtraction/sub b/subtraction/sub index e21b79f..58e44d1 100755 --- a/subtraction/sub +++ b/subtraction/sub @@ -20,20 +20,24 @@ borrow(){ b="${1%$2}"; b="${b#${3%?}}" [ "$b" -gt 0 ] && { c1="$2"; + o="${1%$b$2}"; #echo "++ ${o} $((b-1)) $((c1+90))/$c1" [ "$b" -eq 10 ] && { - o="${1%$b$2}"; : $((b-=1)); o="${o}0${b}$c1" # eg 21 = 2090 10 + : $((b-=1)); o="${o}0${b}$c1" # eg 21 = 2090 10 # tbh idk why this works; 2090 should acctually be 1 10 9 10 # which somehow becomes 209 10 ? I'm guessing a second borrow call is made # and that somehow corrects it; but again idk; a second borrow call /is/ made # but idk how it corrects it } || { - o="${1%$b$2}"; : $((b-=1)); o="$o$b$c1" + : $((b-=1)); [ "$4" != ":" -a "$4" ] && { + o="$o$b$((c1+90))" + } || o="$o$b$c1" } : $((c1+=10)) echo "$o $c1" } || { # otherwise use recusion o="${1#${3%?}}"; o="${o%$2}" - borrow "$1" "$o" "${3%?}" + #echo "| $1 $o ${3%?}" + borrow "$1" "$o" "${3%?}" "${4}:" } } [ -z "${1##*.*}" -o -z "${2##*.*}" ] && {