Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't make me REPETEND myself...
#7
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?

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
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: 3 Guest(s)