08-03-2022, 12:30 AM
I tried do view the code for the windows calculator, but my browser wouldn't load it.
So I had a couple of tests that required me to rethink the repetend routine a bit.
Here is where I'm at so far with a few test cases included. It works on all of these. If you can find a repetition that breaks it, let me know.
Also, I'm trying to figure out if I should bother with times where there are not enough digits reported to fully identify a repeating decimal. If so, how many repeating digits would be enough to would be a repetend if more digits were reported?
So I had a couple of tests that required me to rethink the repetend routine a bit.
Here is where I'm at so far with a few test cases included. It works on all of these. If you can find a repetition that breaks it, let me know.
Also, I'm trying to figure out if I should bother with times where there are not enough digits reported to fully identify a repeating decimal. If so, how many repeating digits would be enough to would be a repetend if more digits were reported?
Code: (Select All)
_SCREENMOVE 0, 0
WIDTH 160, 42
DO
p = p + 1
SELECT CASE p
CASE 1: a$ = ".0033125"
CASE 2: a$ = "33125"
CASE 3: a$ = ".331253312533125"
CASE 4: a$ = ".00000331253312533125"
CASE 5: a$ = ".333"
CASE 6: a$ = ".000001666"
CASE 7: a$ = ".00000333"
CASE 8: a$ = "3.141592174932847"
CASE 9: a$ = "6.00000011127501112750111275"
CASE 10: a$ = ".01111411111411114111114"
CASE 11: a$ = ".000881834215167548500881834215167548500881834215167548500881834215167"
CASE ELSE
END
END SELECT
a$ = MID$(a$, INSTR(a$, ".") + 1)
i = 1: j = 0: k = 0
DO
j = j + 1: k = k + 1
z$ = MID$(a$, i, j)
mp% = INSTR(LEN(z$) + i, a$, z$)
REM COLOR 14, 0: PRINT z$, "i ="; i; "Len ="; LEN(z$); "Prog ="; i + LEN(z$); "mp% ="; mp%; "case ="; p; a$: COLOR 7, 0: SLEEP
IF VAL(z$) AND mp% = LEN(z$) + i THEN
FOR k = 0 TO LEN(MID$(a$, i)) / LEN(z$) - 1
IF MID$(a$, i + k * LEN(z$), LEN(z$)) <> z$ THEN mp% = -1: EXIT FOR
NEXT
IF mp% > 0 THEN
SELECT CASE LEN(z$)
CASE 1
IF i = 1 THEN
msg$ = "Repetend infinite: " + STRING$(3, z$) + "..."
ELSE
msg$ = "Repetend eventually infinite: " + STRING$(3, z$) + "..."
END IF
CASE ELSE
msg$ = "Repetend " + z$ + " " + "length = " + LTRIM$(STR$(LEN(z$)))
END SELECT
EXIT DO
END IF
END IF
IF LEN(z$) >= LEN(a$) - i + 1 / 2 THEN msg$ = "Non-repetend.": EXIT DO
IF mp% = 0 THEN j = 0: i = i + 1
LOOP
PRINT msg$, a$: PRINT
LOOP