08-03-2022, 06:48 PM
Here's a nice little routine I coded using the Euclidean algorithm to determine the GCF and then reducing the fraction. The example uses that big eventual repeating decimal in the last post: .000000000000001184237892933500309785207112630208333333... While the numerator in this example reduces to 1 and only requires 1 loop to calculate, you can remove the REM statements to test something a bit more complicated that takes 4 loops to calculate.
Code: (Select All)
WIDTH 166, 25
_SCREENMOVE 0, 0
a$ = "117239551400416530668735504150390625"
b$ = "99000000000000000000000000000000000000000000000000"
REM a$ = "156"
REM b$ = "388"
gfca$ = a$: gfcb$ = b$
IF VAL(gfca$) < VAL(gfcb$) THEN SWAP gfca$, gfcb$
DO
i = i + 1
x = VAL(gfca$) MOD VAL(gfcb$)
SWAP gfca$, gfcb$: gfcb$ = LTRIM$(STR$(x))
IF x = 0 THEN EXIT DO
LOOP
PRINT "Loops:"; i; " ";
PRINT a$; "/"; b$; " ";
PRINT "GFC = "; gfca$; " ";
PRINT LTRIM$(STR$(VAL(a$) / VAL(gfca$))) + "/" + LTRIM$(STR$(VAL(b$) / VAL(gfca$)))
If eggs are brain food, Biden takes his scrambled.