• test for repdigit - so called "Schnapszahl in German"

    From kuku@physik.rwth-aachen.de@21:1/5 to All on Sat Jul 2 00:40:41 2022
    Probably because a drunken person may see double digits a repdigit number is called "Schnapszahl". Anyway, don't want to bother you with local peculiarities, instead give a weekend riddle: How do I test (most elegantly as always is a demand in FORTH :)
    whether a number consists of equal digits before being printed in the current base?

    Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers?

    The FORTH words I have so far are:

    : b base ! . decimal ; ok

    : t 81 2 do cr i ." base:" . ." 80 ->" 80 i b ." 42-> " 42 i b loop ;

    Would be fine if FORTH could sort out the hits rather than the human eye.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sat Jul 2 05:33:56 2022
    : findBase 81 2 do i base ! dup base @ /mod = if ." Got it! Base: " base @ decimal . leave then loop drop decimal ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sat Jul 2 05:54:43 2022
    : findBase 81 2 do i base ! dup base @ /mod = if ." Got it! Base: " base @ decimal . leave then loop drop decimal ;

    OK, a little refined to limit memory access:
    : findBase2 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . leave then loop drop ;
    (and that closing "decimal" not needed as long as you'll search the numbers not larger than 80)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexander Wegel@21:1/5 to kuku@physik.rwth-aachen.de on Sat Jul 2 19:14:48 2022
    kuku@physik.rwth-aachen.de <kuku@physik.rwth-aachen.de> wrote:

    Probably because a drunken person may see double digits a repdigit number is called "Schnapszahl". Anyway, don't want to bother you with local peculiarities, instead give a weekend riddle: How do I test (most elegantly as always is a demand in FORTH :) whether a number consists of equal digits before being printed in the current base?

    Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers?

    The FORTH words I have so far are:

    : b base ! . decimal ; ok

    : t 81 2 do cr i ." base:" . ." 80 ->" 80 i b ." 42-> " 42 i b loop ;

    Would be fine if FORTH could sort out the hits rather than the human eye.

    The following detects Schnapszahlen having two places only (and gives
    false results outside that range) for the sake of simplicity:

    : ten base @ ;
    : snaps? ten 1+ mod 0= ;

    The thing to take home: a schnapszahl is a multiple of 11 in the current
    number base.

    cheers

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexander Wegel@21:1/5 to Alexander Wegel on Sat Jul 2 19:18:19 2022
    Alexander Wegel <awegel@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current number base.

    Anyway, it's just the same principle as in zbigs code 8-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to Alexander Wegel on Sun Jul 3 00:26:13 2022
    Alexander Wegel schrieb am Samstag, 2. Juli 2022 um 19:18:21 UTC+2:
    Alexander Wegel <awe...@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current number base.
    Anyway, it's just the same principle as in zbigs code 8-)

    Alexander, thanks for the "multiple of 11" remark, but doesn't help in the problem solution.
    One could extend the rule to 111 for 3 digit results and so on.

    @Zbig: the problem to solve is: name all bases in which the given number (80,42) is a repdigit number.
    For the 80, the result should be:

    80
    base number
    3 2222
    9 22
    19 44
    39 22
    79 11

    Your algorithm finds the 9 (only)


    42
    base number
    4 222
    13 33
    20 22
    41 11

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to Gerry Jackson on Sun Jul 3 01:14:33 2022
    Gerry Jackson schrieb am Sonntag, 3. Juli 2022 um 09:49:10 UTC+2:
    On 03/07/2022 08:26, ku...@physik.rwth-aachen.de wrote:
    Alexander Wegel schrieb am Samstag, 2. Juli 2022 um 19:18:21 UTC+2:
    Alexander Wegel <awe...@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current >>> number base.
    Anyway, it's just the same principle as in zbigs code 8-)

    Alexander, thanks for the "multiple of 11" remark, but doesn't help in the problem solution.
    One could extend the rule to 111 for 3 digit results and so on.

    @Zbig: the problem to solve is: name all bases in which the given number (80,42) is a repdigit number.
    For the 80, the result should be:

    80
    base number
    3 2222
    9 22
    22 in base 9 is decimal 20


    Sorry, this meant to be 9 88. One more reason to let FORTH do the job and then copy/paste :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sun Jul 3 00:47:20 2022
    @Zbig: the problem to solve is: name all bases in which the given number (80,42) is a repdigit number.

    No, that ("all bases") wasn't present in the conditions.

    For the 80, the result should be:

    80
    base number
    3 2222
    9 22
    19 44
    39 22
    79 11

    Your algorithm finds the 9 (only)

    You can simply remove "leave" word -- or (even better) replace it with "cr".
    As for the schnapsen with more than two digits: it's doable, but I think it would need some recursive algorithm.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 08:49:09 2022
    On 03/07/2022 08:26, kuku@physik.rwth-aachen.de wrote:
    Alexander Wegel schrieb am Samstag, 2. Juli 2022 um 19:18:21 UTC+2:
    Alexander Wegel <awe...@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current >>> number base.
    Anyway, it's just the same principle as in zbigs code 8-)

    Alexander, thanks for the "multiple of 11" remark, but doesn't help in the problem solution.
    One could extend the rule to 111 for 3 digit results and so on.

    @Zbig: the problem to solve is: name all bases in which the given number (80,42) is a repdigit number.
    For the 80, the result should be:

    80
    base number
    3 2222
    9 22

    22 in base 9 is decimal 20

    19 44
    39 22
    79 11

    Your algorithm finds the 9 (only)


    42
    base number
    4 222
    13 33
    20 22
    41 11: divisor ( #digits -- n-ones ) 0 tuck ?do base @ * 1+ loop ;

    \ Extending Alexander Wegel's idea to 11...1, in bases 2 to 36 ANS max
    \ base

    : #digits ( ud -- #digs ) <# #s #> nip ;

    : repdigit? ( ud -- f )
    2dup #digits dup 2 < if drop nip exit then
    divisor sm/rem drop 0=
    ;

    : report ( n f -- )
    0= if drop exit then
    base @ >r decimal cr ." Base: " r@ 2 .r
    ." , Number: #" dup 0 .r
    r> base ! ." , Repdigit: " .
    ;

    : repdigit ( n -- )
    dup 0 ( -- n ud )
    37 2
    do
    i base ! 2>r
    2r@ repdigit? ( -- n f )
    over swap report 2r> ( -- n ud )
    loop 2drop drop decimal
    ;

    #42 repdigit cr
    Base: 4, Number: #42, Repdigit: 222
    Base: 13, Number: #42, Repdigit: 33
    Base: 20, Number: #42, Repdigit: 22 ok

    #80 repdigit
    Base: 3, Number: #80, Repdigit: 2222
    Base: 9, Number: #80, Repdigit: 88
    Base: 15, Number: #80, Repdigit: 55
    Base: 19, Number: #80, Repdigit: 44 ok


    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 01:31:09 2022
    kuku@physik.rwth-aachen.de schrieb am Sonntag, 3. Juli 2022 um 10:14:34 UTC+2:
    Gerry Jackson schrieb am Sonntag, 3. Juli 2022 um 09:49:10 UTC+2:
    But ok, extending

    : repdigit ( n -- )
    dup 0 ( -- n ud )
    80 2
    do
    i base ! 2>r compiled
    over swap report 2r> ( -- n ud )
    loop 2drop drop decimal ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 01:27:11 2022
    kuku@physik.rwth-aachen.de schrieb am Sonntag, 3. Juli 2022 um 10:14:34 UTC+2:
    Gerry Jackson schrieb am Sonntag, 3. Juli 2022 um 09:49:10 UTC+2:

    Nice solution, Gerry. Only solutions
    80:
    base number
    39 22
    79 11
    are missing.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sun Jul 3 01:28:01 2022
    You can simply remove "leave" word -- or (even better) replace it with "cr". As for the schnapsen with more than two digits: it's doable, but I think it would need some recursive algorithm.

    Uh, I forgot: in such case we also need to insert "decimal" at the end back.
    So to sum up it'll look like this:

    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;
    80 findbase2 Got it! Base: 9
    Got it! Base: 15
    Got it! Base: 19
    Got it! Base: 39
    Got it! Base: 79
    It found even more for 80, than you expected. :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to Zbig on Sun Jul 3 01:35:26 2022
    Zbig schrieb am Sonntag, 3. Juli 2022 um 10:28:02 UTC+2:
    ...
    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;
    80 findbase2 Got it! Base: 9
    Got it! Base: 15
    Got it! Base: 19
    Got it! Base: 39
    Got it! Base: 79
    It found even more for 80, than you expected. :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to Zbig on Sun Jul 3 01:37:42 2022
    Zbig schrieb am Sonntag, 3. Juli 2022 um 10:28:02 UTC+2:
    ...
    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;
    80 findbase2 Got it! Base: 9
    Got it! Base: 15
    Got it! Base: 19
    Got it! Base: 39
    Got it! Base: 79
    It found even more for 80, than you expected. :)

    My first approach liested them all, but as said, the human eye is the weak link in the chain of recognition.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 10:44:38 2022
    On 03/07/2022 09:27, kuku@physik.rwth-aachen.de wrote:
    kuku@physik.rwth-aachen.de schrieb am Sonntag, 3. Juli 2022 um 10:14:34 UTC+2:
    Gerry Jackson schrieb am Sonntag, 3. Juli 2022 um 09:49:10 UTC+2:

    Nice solution, Gerry. Only solutions
    80:
    base number
    39 22
    79 11
    are missing.

    THe Forth I use only goes up to base 36

    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to All on Sun Jul 3 04:09:34 2022
    @Zbig:
    Your
    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;

    doesn't find Base 3 2222 as the result.

    BTW, my problem outline was :
    "Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers? "

    I think, this implies "all bases".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexander Wegel@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 13:06:56 2022
    kuku@physik.rwth-aachen.de <kuku@physik.rwth-aachen.de> wrote:

    Alexander Wegel schrieb am Samstag, 2. Juli 2022 um 19:18:21 UTC+2:
    Alexander Wegel <awe...@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current number base.
    Anyway, it's just the same principle as in zbigs code 8-)

    Alexander, thanks for the "multiple of 11" remark, but doesn't help in the problem solution.
    One could extend the rule to 111 for 3 digit results and so on.

    Yes, i was confused by your mentioning of "double digits", which are
    apparently not part of the problem posed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 04:10:47 2022
    On Sunday, July 3, 2022 at 10:37:44 AM UTC+2, kuku@physik.rwth-aachen.de wrote:
    Zbig schrieb am Sonntag, 3. Juli 2022 um 10:28:02 UTC+2:
    ...
    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;
    80 findbase2 Got it! Base: 9
    Got it! Base: 15
    Got it! Base: 19
    Got it! Base: 39
    Got it! Base: 79
    It found even more for 80, than you expected. :)
    My first approach liested them all, but as said, the human eye is the weak link in the chain of recognition.

    I had no time for a simple solution.

    : same? ( c-addr u -- f )
    DUP 1 = IF 2DROP FALSE EXIT ENDIF
    over C@ >S 1 /STRING
    0 ?DO C@+ S
    <> IF DROP -S FALSE UNLOOP EXIT
    ENDIF
    LOOP
    DROP -S TRUE ;

    : ?. ( u -- ) dup (.) same? IF . ELSE DROP ENDIF ;

    : .solutions ( n1 -- )
    >S BASE @
    #81 2 DO I BASE !
    S (.) same? IF CR BASE @ DEC. S ?. ENDIF
    LOOP
    BASE ! -S ;

    FORTH> 42 .solutions
    4 222
    13 33
    20 22
    41 11 ok
    FORTH> 80 .solutions
    3 2222
    9 88
    15 55
    19 44
    39 22
    79 11 ok
    FORTH>

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to Marcel Hendrix on Sun Jul 3 04:29:54 2022
    On Sunday, July 3, 2022 at 1:22:31 PM UTC+2, Marcel Hendrix wrote:
    On Sunday, July 3, 2022 at 1:09:36 PM UTC+2, ku...@physik.rwth-aachen.de wrote:
    [..]
    BTW, my problem outline was :
    "Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers? "
    I think, this implies "all bases".
    What's so special about 42 and 80?

    FORTH> : test #81 1 do i .solutions loop ; ok
    FORTH> test
    [..]

    60 is special in that it has the most schnappses.
    testing with ** 60 **
    9 66
    11 55
    14 44
    19 33
    29 22
    59 11

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to kuku@physik.rwth-aachen.de on Sun Jul 3 04:22:29 2022
    On Sunday, July 3, 2022 at 1:09:36 PM UTC+2, kuku@physik.rwth-aachen.de wrote: [..]
    BTW, my problem outline was :
    "Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers? "
    I think, this implies "all bases".

    What's so special about 42 and 80?

    FORTH> : test #81 1 do i .solutions loop ; ok
    FORTH> test
    2 11
    3 11
    4 11
    5 11
    2 111
    6 11
    3 22
    7 11
    8 11
    4 22
    9 11
    10 11
    5 22
    11 11
    3 111
    12 11
    6 22
    13 11
    2 1111
    4 33
    14 11
    7 22
    15 11
    16 11
    5 33
    8 22
    17 11
    18 11
    9 22
    19 11
    4 111
    6 33
    20 11
    10 22
    21 11
    22 11
    5 44
    7 33
    11 22
    23 11
    24 11
    3 222
    12 22
    25 11
    8 33
    26 11
    6 44
    13 22
    27 11
    28 11
    9 33
    14 22
    29 11
    2 11111
    5 111
    30 11
    7 44
    15 22
    31 11
    10 33
    32 11
    16 22
    33 11
    6 55
    34 11
    8 44
    11 33
    17 22
    35 11
    36 11
    18 22
    37 11
    12 33
    38 11
    3 1111
    7 55
    9 44
    19 22
    39 11
    40 11
    4 222
    13 33
    20 22
    41 11
    6 111
    42 11
    10 44
    21 22
    43 11
    8 55
    14 33
    44 11
    22 22
    45 11
    46 11
    7 66
    11 44
    15 33
    23 22
    47 11
    48 11
    9 55
    24 22
    49 11
    16 33
    50 11
    12 44
    25 22
    51 11
    52 11
    8 66
    17 33
    26 22
    53 11
    10 55
    54 11
    13 44
    27 22
    55 11
    7 111
    18 33
    56 11
    28 22
    57 11
    58 11
    9 66
    11 55
    14 44
    19 33
    29 22
    59 11
    60 11
    5 222
    30 22
    61 11
    2 111111
    4 333
    8 77
    20 33
    62 11
    15 44
    31 22
    63 11
    12 55
    64 11
    10 66
    21 33
    32 22
    65 11
    66 11
    16 44
    33 22
    67 11
    22 33
    68 11
    9 77
    13 55
    34 22
    69 11
    70 11
    11 66
    17 44
    23 33
    35 22
    71 11
    8 111
    72 11
    36 22
    73 11
    14 55
    24 33
    74 11
    18 44
    37 22
    75 11
    10 77
    76 11
    12 66
    25 33
    38 22
    77 11
    78 11
    3 2222
    9 88
    15 55
    19 44
    39 22
    79 11 ok
    FORTH>

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sun Jul 3 07:50:49 2022
    : findBase 81 2 do base dup i swap ! @ over swap /mod = if ." Got it! Base: " i decimal . cr then loop drop decimal ;
    doesn't find Base 3 2222 as the result.

    BTW, my problem outline was :
    "Idea behind is in what base the decimal numbers 42 and 80 are repdigit numbers? "
    I think, this implies "all bases".
    No, it doesn't; it says: "find a base meeting a condition ... " (not "find all possible bases
    in the range ... ").
    So you don't want to follow the path and complete it by yourself?
    OK, have a solution then; it's somewhat crude, but we've got Sunday in Poland today, you know:

    variable wrong
    0 wrong !
    : num2str abs 0 <# #s swap #> ;
    : checkIt over c@ -rot 0 do dup i + c@ >r over r> = 0= if 1 wrong ! leave then loop 2drop ;
    : findBases cr 81 min dup 2 do base i swap ! dup num2str checkIt wrong @ 0= if decimal ." Schapps at the base " i . cr then 0 wrong ! loop drop decimal ;

    The test:

    80 findBases
    Schapps at the base 3
    Schapps at the base 9
    Schapps at the base 15
    Schapps at the base 19
    Schapps at the base 39
    Schapps at the base 79

    42 findBases
    Schapps at the base 4
    Schapps at the base 13
    Schapps at the base 20
    Schapps at the base 41

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Marcel Hendrix on Mon Jul 4 01:07:00 2022
    On 3/07/2022 21:10, Marcel Hendrix wrote:

    I had no time for a simple solution.

    : same? ( c-addr u -- f )
    DUP 1 = IF 2DROP FALSE EXIT ENDIF
    over C@ >S 1 /STRING
    0 ?DO C@+ S
    <> IF DROP -S FALSE UNLOOP EXIT
    ENDIF
    LOOP
    DROP -S TRUE ;

    : .solutions ( n1 -- )
    >S BASE @
    #81 2 DO I BASE !
    S (.) same? IF CR BASE @ DEC. S ?. ENDIF
    LOOP
    BASE ! -S ;

    : same? ( c-addr u -- f )
    DUP 1 > IF
    OVER C@ >R 1 /STRING
    R> SKIP 0= NIP EXIT
    THEN 2DROP FALSE ;

    : .solutions ( n1 -- )
    BASE @ SWAP
    81 2 DO I BASE !
    DUP (.) same? IF CR I DEC. DUP ?. THEN
    LOOP DROP BASE ! ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to dxforth on Sun Jul 3 09:24:26 2022
    On Sunday, July 3, 2022 at 5:07:03 PM UTC+2, dxforth wrote:
    [..]
    : same? ( c-addr u -- f )
    DUP 1 > IF
    OVER C@ >R 1 /STRING
    SKIP 0= NIP EXIT
    THEN 2DROP FALSE ;

    What if there are n (>2) digits and less than n are different?
    Or are you prepared to spend a day proving that that is
    not possible :--?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Marcel Hendrix on Mon Jul 4 12:32:48 2022
    On 4/07/2022 02:24, Marcel Hendrix wrote:
    On Sunday, July 3, 2022 at 5:07:03 PM UTC+2, dxforth wrote:
    [..]
    : same? ( c-addr u -- f )
    DUP 1 > IF
    OVER C@ >R 1 /STRING
    SKIP 0= NIP EXIT
    THEN 2DROP FALSE ;

    What if there are n (>2) digits and less than n are different?
    Or are you prepared to spend a day proving that that is
    not possible :--?

    It demonstrates what's possible without much effort. Are you
    saying it produces results different from yours?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to dxforth on Sun Jul 3 22:16:52 2022
    On Monday, July 4, 2022 at 4:32:54 AM UTC+2, dxforth wrote:
    On 4/07/2022 02:24, Marcel Hendrix wrote:
    On Sunday, July 3, 2022 at 5:07:03 PM UTC+2, dxforth wrote:
    [..]
    : same? ( c-addr u -- f )
    DUP 1 > IF
    OVER C@ >R 1 /STRING
    SKIP 0= NIP EXIT
    THEN 2DROP FALSE ;

    What if there are n (>2) digits and less than n are different?
    Or are you prepared to spend a day proving that that is
    not possible :--?
    It demonstrates what's possible without much effort. Are you
    saying it produces results different from yours?

    I'm sorry! I see now you have inverted the exit test and then
    SKIP is indeed possible. I didn't think enough about it and
    used the ugly LOOP with all its administrative problems.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kuku@physik.rwth-aachen.de@21:1/5 to All on Sun Jul 3 23:39:43 2022
    Thanks to all for the discussion and interesting solutions. In our local newspaper there is a math riddle column
    coming up with some brainteaser every weekend. The 42 is special since it is mentioned e.g. here:
    https://www.scientificamerican.com/article/for-math-fans-a-hitchhikers-guide-to-the-number-42/
    I have no idea about the 80. all which comes to mind is, that the column width of punched cards was 80 :)

    --
    Christoph

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to do-not-use@swldwa.uk on Mon Jul 4 09:31:14 2022
    In article <t9rhlk$2uh87$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 03/07/2022 08:26, kuku@physik.rwth-aachen.de wrote:
    Alexander Wegel schrieb am Samstag, 2. Juli 2022 um 19:18:21 UTC+2:
    Alexander Wegel <awe...@arcor.de> wrote:

    The thing to take home: a schnapszahl is a multiple of 11 in the current >>>> number base.
    Anyway, it's just the same principle as in zbigs code 8-)

    Alexander, thanks for the "multiple of 11" remark, but doesn't help in
    the problem solution.
    One could extend the rule to 111 for 3 digit results and so on.

    @Zbig: the problem to solve is: name all bases in which the given
    number (80,42) is a repdigit number.
    For the 80, the result should be:

    80
    base number
    3 2222
    9 22

    22 in base 9 is decimal 20

    19 44
    39 22
    79 11

    Your algorithm finds the 9 (only)


    42
    base number
    4 222
    13 33
    20 22
    41 11: divisor ( #digits -- n-ones ) 0 tuck ?do base @ * 1+ loop ;

    \ Extending Alexander Wegel's idea to 11...1, in bases 2 to 36 ANS max
    \ base

    : #digits ( ud -- #digs ) <# #s #> nip ;

    : repdigit? ( ud -- f )
    2dup #digits dup 2 < if drop nip exit then
    divisor sm/rem drop 0=
    ;

    : report ( n f -- )
    0= if drop exit then
    base @ >r decimal cr ." Base: " r@ 2 .r
    ." , Number: #" dup 0 .r
    r> base ! ." , Repdigit: " .
    ;

    : repdigit ( n -- )
    dup 0 ( -- n ud )
    37 2
    do
    i base ! 2>r
    2r@ repdigit? ( -- n f )
    over swap report 2r> ( -- n ud )
    loop 2drop drop decimal
    ;

    #42 repdigit cr
    Base: 4, Number: #42, Repdigit: 222
    Base: 13, Number: #42, Repdigit: 33
    Base: 20, Number: #42, Repdigit: 22 ok

    #80 repdigit
    Base: 3, Number: #80, Repdigit: 2222
    Base: 9, Number: #80, Repdigit: 88
    Base: 15, Number: #80, Repdigit: 55
    Base: 19, Number: #80, Repdigit: 44 ok

    A better algorithm is this for every BASE and number:

    1. BASE > number , trivially true
    2. n' = base + 1
    3. temp= n' * base + 1
    If temp > number, goto 4
    set n' to temp, and goto 2
    4. if n' divides number, number is repdigit
    terminate


    --
    Gerry

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)