Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't make me REPETEND myself...
#13
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$)))
Shoot first and shoot people who ask questions, later.
Reply


Messages In This Thread
Don't make me REPETEND myself... - by Pete - 07-31-2022, 08:57 PM
RE: Don't make me REPETEND myself... - by bplus - 07-31-2022, 11:20 PM
RE: Don't make me REPETEND myself... - by Pete - 08-01-2022, 01:00 AM
RE: Don't make me REPETEND myself... - by bplus - 08-01-2022, 03:57 PM
RE: Don't make me REPETEND myself... - by Pete - 08-01-2022, 07:10 PM
RE: Don't make me REPETEND myself... - by Jack - 08-01-2022, 07:47 PM
RE: Don't make me REPETEND myself... - by Pete - 08-03-2022, 12:30 AM
RE: Don't make me REPETEND myself... - by Jack - 08-03-2022, 01:39 AM
RE: Don't make me REPETEND myself... - by Pete - 08-03-2022, 02:49 AM
RE: Don't make me REPETEND myself... - by Stuart - 08-03-2022, 08:21 AM
RE: Don't make me REPETEND myself... - by Dav - 08-03-2022, 10:37 AM
RE: Don't make me REPETEND myself... - by Pete - 08-03-2022, 05:39 PM
RE: Don't make me REPETEND myself... - by Pete - 08-03-2022, 06:48 PM
RE: Don't make me REPETEND myself... - by Pete - 08-03-2022, 10:43 PM
RE: Don't make me REPETEND myself... - by Stuart - 08-04-2022, 07:13 AM
RE: Don't make me REPETEND myself... - by Pete - 08-04-2022, 08:37 AM
RE: Don't make me REPETEND myself... - by Jack - 08-04-2022, 09:23 AM
RE: Don't make me REPETEND myself... - by Stuart - 08-04-2022, 10:30 AM
RE: Don't make me REPETEND myself... - by bplus - 08-04-2022, 01:26 PM
RE: Don't make me REPETEND myself... - by Pete - 08-04-2022, 06:30 PM
RE: Don't make me REPETEND myself... - by Pete - 08-04-2022, 09:17 PM
RE: Don't make me REPETEND myself... - by Jack - 08-04-2022, 10:37 PM
RE: Don't make me REPETEND myself... - by Pete - 08-05-2022, 10:05 AM
RE: Don't make me REPETEND myself... - by Pete - 08-14-2022, 11:48 AM



Users browsing this thread: 4 Guest(s)