• Re: BizFuss (was Re: Taming The Switch-Statement)

    From Lawrence D?Oliveiro@3:633/10 to All on Fri Oct 30 08:27:59 2026
    On Thu, 29 Oct 2026 08:30:33 +0100, Rosario19 wrote:

    for(x=1;x<20;++x)
    {if(x%2==0) printf("%d divides by 2\n",x);
    if(x%3==0) printf("%d divides by 3\n",x);
    if(x%3!=0&&x%2!=0)
    printf("%d no divides (by 3 or 2)\n",x);
    }

    Generalization I call ?bizzfuzz? -- substitute whatever
    factors and limit you want:

    factors = (2, 3, 5, 7) # factors to be checked in order
    limit = 200

    for n in range(1, limit + 1) :
    i = (list(n % factors[j] == 0 for j in range(len(factors))) + [True]).index(True)
    if i < len(factors) :
    print("%d is divisible by %d" % (n, factors[i]))
    else :
    print("%d is not divisible by any of (%s)" % (n, ", ".join(str(f) for f in factors)))
    #end if
    #end for

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bartc@3:633/10 to All on Fri Oct 30 11:47:59 2026
    On 30/10/2026 08:27, Lawrence D?Oliveiro wrote:
    On Thu, 29 Oct 2026 08:30:33 +0100, Rosario19 wrote:

    for(x=1;x<20;++x)
    {if(x%2==0) printf("%d divides by 2\n",x);
    if(x%3==0) printf("%d divides by 3\n",x);
    if(x%3!=0&&x%2!=0)
    printf("%d no divides (by 3 or 2)\n",x);
    }

    Generalization I call ?bizzfuzz? -- substitute whatever
    factors and limit you want:

    factors = (2, 3, 5, 7) # factors to be checked in order
    limit = 200

    for n in range(1, limit + 1) :
    i = (list(n % factors[j] == 0 for j in range(len(factors))) + [True]).index(True)
    if i < len(factors) :
    print("%d is divisible by %d" % (n, factors[i]))
    else :
    print("%d is not divisible by any of (%s)" % (n, ", ".join(str(f) for f in factors)))

    Why not just this here:

    print(n, " is not divisible by any of ", factors)


    In any case, this doesn't do the same thing. It generates this for example:

    167 is not divisible by any of (2, 3, 5, 7)
    168 is divisible by 2
    169 is not divisible by any of (2, 3, 5, 7)

    It only shows one of the factors then proceeds to the next. It should
    show all that are true.

    This was supposed to be my version of your code, but it does the task properly:

    factors := (2, 3, 5, 7)
    limit := 200

    for n to limit do
    x := 0
    for f in factors when n rem f = 0 do
    println n, "is divisible by", f
    ++x
    end
    unless x then
    println n, "is not divisible by any of", factors
    end
    end

    That output becomes:

    167 is not divisible by any of (2,3,5,7)
    168 is divisible by 2
    168 is divisible by 3
    168 is divisible by 7
    169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    Your Python: 340 characters
    Mine: 222 (as above; scripting)
    C: 393 (not shown; not elegant)
    Mine: 314 (not shown; systems lang)



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bartc@3:633/10 to All on Fri Oct 30 15:36:54 2026
    On 30/10/2026 08:27, Lawrence D?Oliveiro wrote:
    On Thu, 29 Oct 2026 08:30:33 +0100, Rosario19 wrote:

    for(x=1;x<20;++x)
    {if(x%2==0) printf("%d divides by 2\n",x);
    if(x%3==0) printf("%d divides by 3\n",x);
    if(x%3!=0&&x%2!=0)
    printf("%d no divides (by 3 or 2)\n",x);
    }

    Generalization I call ?bizzfuzz? -- substitute whatever
    factors and limit you want:

    factors = (2, 3, 5, 7) # factors to be checked in order
    limit = 200

    for n in range(1, limit + 1) :
    i = (list(n % factors[j] == 0 for j in range(len(factors))) + [True]).index(True)
    if i < len(factors) :
    print("%d is divisible by %d" % (n, factors[i]))
    else :
    print("%d is not divisible by any of (%s)" % (n, ", ".join(str(f) for f in factors)))
    #end if
    #end for


    This a Python version that displays all the factors that work (so it corresponds to the behaviour of the C):

    factors = [2, 3, 5, 7]
    limit = 200

    for n in range(1, limit + 1) :
    d = []
    for f in factors:
    if n % f == 0: d.append(f)

    if len(d):
    print(n, "is divisible by", d)
    else:
    print(n, "is not divisible by any of", factors)


    Output for the 168 example in my other post will be:

    167 is not divisible by any of [2, 3, 5, 7]
    168 is divisible by [2, 3, 7]
    169 is not divisible by any of [2, 3, 5, 7]

    Size is 226 characters with hard tabs.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Keith Thompson@3:633/10 to All on Fri Oct 30 12:04:48 2026
    Lawrence D?Oliveiro <ldo@nz.invalid> writes:
    On Thu, 29 Oct 2026 08:30:33 +0100, Rosario19 wrote:

    for(x=1;x<20;++x)
    {if(x%2==0) printf("%d divides by 2\n",x);
    if(x%3==0) printf("%d divides by 3\n",x);
    if(x%3!=0&&x%2!=0)
    printf("%d no divides (by 3 or 2)\n",x);
    }

    Generalization I call ?bizzfuzz? -- substitute whatever
    factors and limit you want:

    factors = (2, 3, 5, 7) # factors to be checked in order
    limit = 200

    for n in range(1, limit + 1) :
    [SNIP]

    comp.lang.python is down the hall, just past the water cooler, on
    the left.

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Kenny McCormack@3:633/10 to All on Fri Oct 30 20:10:07 2026
    Subject: Python is the universal language (Was: BizFuss (was Re: Taming The Switch-Statement))

    In article <11c2poh$gqls$2@kst.eternal-september.org>,
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
    ...
    [SNIP]

    comp.lang.python is down the hall, just past the water cooler, on
    the left.

    Haven't you heard? Python is the new universal language and is, thus,
    on-topic wherever you go.

    --
    The randomly chosen signature file that would have appeared here is more than 4-ish
    lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/Aspergers

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Rosario19@3:633/10 to All on Sat Oct 31 11:36:49 2026
    On Fri, 30 Oct 2026 08:27:59 -0000 (UTC), Lawrence D˜Oliveiro wrote:

    On Thu, 29 Oct 2026 08:30:33 +0100, Rosario19 wrote:

    for(x=1;x<20;++x)
    {if(x%2==0) printf("%d divides by 2\n",x);
    if(x%3==0) printf("%d divides by 3\n",x);
    if(x%3!=0&&x%2!=0)
    printf("%d no divides (by 3 or 2)\n",x);
    }

    Generalization I call ?bizzfuzz? -- substitute whatever
    factors and limit you want:

    factors = (2, 3, 5, 7) # factors to be checked in order
    limit = 200

    for n in range(1, limit + 1) :
    i = (list(n % factors[j] == 0 for j in range(len(factors))) + [True]).index(True)
    if i < len(factors) :
    print("%d is divisible by %d" % (n, factors[i]))
    else :
    print("%d is not divisible by any of (%s)" % (n, ", ".join(str(f) for f in factors)))
    #end if
    #end for

    In APL modulo translation is 80 characters, 1 line

    2 3 7{leftbrace}a{leftarrow}{alpha}{diamond}{leftbrace}0={notequalunderbar}k{leftarrow}a/{dieresistilde}0=a{stile}{omega}:{quad}{leftarrow}{omega},{apostrophe}
    is not divisible by {apostrophe},a{diamond}{quad}{leftarrow}{omega},{apostrophe} is
    divisible by
    {apostrophe},k{rightbrace}{dieresis}{iota}{omega}{rightbrace}20


    2 3 7{a¬??{0=?k¬a/­0=a|?:ý¬?,' is not divisible by ',a?ý¬?,' is
    divisible by ',k}­ø?}20
    1 is not divisible by 2 3 7
    2 is divisible by 2
    3 is divisible by 3
    4 is divisible by 2
    5 is not divisible by 2 3 7
    6 is divisible by 2 3
    7 is divisible by 7
    8 is divisible by 2
    9 is divisible by 3
    10 is divisible by 2
    11 is not divisible by 2 3 7
    12 is divisible by 2 3
    13 is not divisible by 2 3 7
    14 is divisible by 2 7
    15 is divisible by 3
    16 is divisible by 2
    17 is not divisible by 2 3 7
    18 is divisible by 2 3
    19 is not divisible by 2 3 7
    20 is divisible by 2



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Rosario19@3:633/10 to All on Sat Oct 31 11:39:53 2026
    On Fri, 30 Oct 2026 11:47:59 +0000, bartc wrote:

    That output becomes:

    167 is not divisible by any of (2,3,5,7)
    168 is divisible by 2
    168 is divisible by 3
    168 is divisible by 7
    169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    Your Python: 340 characters
    Mine: 222 (as above; scripting)
    C: 393 (not shown; not elegant)
    Mine: 314 (not shown; systems lang)

    The APL one is 80 characters
    Is more long the string to write that the code to execute...

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bartc@3:633/10 to All on Sat Oct 31 12:21:13 2026
    On 31/10/2026 10:39, Rosario19 wrote:
    On Fri, 30 Oct 2026 11:47:59 +0000, bartc wrote:

    That output becomes:

    167 is not divisible by any of (2,3,5,7)
    168 is divisible by 2
    168 is divisible by 3
    168 is divisible by 7
    169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    Your Python: 340 characters
    Mine: 222 (as above; scripting)
    C: 393 (not shown; not elegant)
    Mine: 314 (not shown; systems lang)

    The APL one is 80 characters

    That's not quite right:

    * You're using 2,3,7 not 2,3,5,7, which would add 2 characters

    * You're doing 20 iterations not 200 (adds 1 more character!)

    * You missed out 'any of ' (adds 6 characters, however your output seems
    to have unnecessary space so perhaps that can be trimmed)

    Is more long the string to write that the code to execute...

    The point about the version I posted is that it does the correct task
    but much cleanly than Python, which had lots of unnecessary
    complications. So anyone could follow it.

    But I modified my version to be compact, and it looks like this:

    f:=(2,3,5,7)
    for n to 20 do
    d::=()
    for x in f when n rem x=0 do d&:=x od
    ?n,(d|"is divisible by"|"is not divisible by"),(d|d|f)
    od

    This is 134 characters (131 without those indents). It suffers from
    named symbols such as 'rem' needing 5 characters rather than 1.

    Note that your APL (with '5' added), because it uses Unicode, takes up
    105 bytes; my version is still 131/134 bytes while still just about
    being understandable.

    That's pretty good even if a big chunk of the APL (38 characters/bytes)
    is those strings.

    It would be interesting if somebody were to post a version in code-golf C.

    (The output from my version here is this, but it can vary provided the
    same info is displayed:)

    1 is not divisible by (2,3,5,7)
    2 is divisible by (2)
    3 is divisible by (3)
    4 is divisible by (2)
    5 is divisible by (5)
    6 is divisible by (2,3)
    7 is divisible by (7)
    8 is divisible by (2)
    9 is divisible by (3)
    10 is divisible by (2,5)
    11 is not divisible by (2,3,5,7)
    12 is divisible by (2,3)
    13 is not divisible by (2,3,5,7)
    14 is divisible by (2,7)
    15 is divisible by (3,5)
    16 is divisible by (2)
    17 is not divisible by (2,3,5,7)
    18 is divisible by (2,3)
    19 is not divisible by (2,3,5,7)
    20 is divisible by (2,5)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Rosario19@3:633/10 to All on Sat Oct 31 14:30:54 2026
    On Sat, 31 Oct 2026 12:21:13 +0000, bartc <bc@freeuk.com> wrote:

    On 31/10/2026 10:39, Rosario19 wrote:
    On Fri, 30 Oct 2026 11:47:59 +0000, bartc wrote:

    That output becomes:

    167 is not divisible by any of (2,3,5,7)
    168 is divisible by 2
    168 is divisible by 3
    168 is divisible by 7
    169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    Your Python: 340 characters
    Mine: 222 (as above; scripting)
    C: 393 (not shown; not elegant)
    Mine: 314 (not shown; systems lang)

    The APL one is 80 characters

    That's not quite right:

    * You're using 2,3,7 not 2,3,5,7, which would add 2 characters

    * You're doing 20 iterations not 200 (adds 1 more character!)

    code I posted is 2 input one left (the list 2 3 7) and one in the
    right (the number 20) and the APL function in the middle.

    80 charaters refer only for APL function.
    So the number of characters of the function + the input is more than
    80. It is possible change the input [input left the list 2 3 5 7,
    input right the integer 200] for have this

    2 3 5 7{a???{0=?k?a/?0=a|?:???,' is not divisible by ',a????,' is divisible by ',k}???}200
    1 is not divisible by 2 3 5 7
    2 is divisible by 2
    3 is divisible by 3
    4 is divisible by 2
    5 is divisible by 5
    6 is divisible by 2 3
    7 is divisible by 7
    8 is divisible by 2
    9 is divisible by 3
    10 is divisible by 2 5
    11 is not divisible by 2 3 5 7
    12 is divisible by 2 3
    13 is not divisible by 2 3 5 7
    14 is divisible by 2 7
    15 is divisible by 3 5
    16 is divisible by 2
    17 is not divisible by 2 3 5 7
    18 is divisible by 2 3
    19 is not divisible by 2 3 5 7
    20 is divisible by 2 5
    21 is divisible by 3 7
    22 is divisible by 2
    23 is not divisible by 2 3 5 7
    24 is divisible by 2 3
    25 is divisible by 5
    ...............
    196 is divisible by 2 7
    197 is not divisible by 2 3 5 7
    198 is divisible by 2 3
    199 is not divisible by 2 3 5 7
    200 is divisible by 2 5




    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bartc@3:633/10 to All on Sat Oct 31 13:27:45 2026
    On 31/10/2026 12:21, bartc wrote:
    On 31/10/2026 10:39, Rosario19 wrote:
    On Fri, 30 Oct 2026 11:47:59 +0000, bartcÿ wrote:

    That output becomes:

    ÿÿ 167 is not divisible by any of (2,3,5,7)
    ÿÿ 168 is divisible by 2
    ÿÿ 168 is divisible by 3
    ÿÿ 168 is divisible by 7
    ÿÿ 169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    ÿ Your Python:ÿ 340 characters
    ÿ Mine:ÿÿÿÿÿÿÿÿ 222ÿÿÿ (as above; scripting)
    ÿ C:ÿÿÿÿÿÿÿÿÿÿÿ 393ÿÿÿ (not shown; not elegant)
    ÿ Mine:ÿÿÿÿÿÿÿÿ 314ÿÿÿ (not shown; systems lang)

    The APL one is 80 characters

    That's not quite right:

    * You're using 2,3,7 not 2,3,5,7, which would add 2 characters

    * You're doing 20 iterations not 200 (adds 1 more character!)

    * You missed out 'any of ' (adds 6 characters, however your output seems
    ÿ to have unnecessary space so perhaps that can be trimmed)

    Is more long the string to write that the code to execute...

    The point about the version I posted is that it does the correct task
    but much cleanly than Python, which had lots of unnecessary
    complications. So anyone could follow it.

    But I modified my version to be compact, and it looks like this:

    ÿ f:=(2,3,5,7)
    ÿ for n to 20 do
    ÿÿ d::=()
    ÿÿ for x in f when n rem x=0 do d&:=x od
    ÿÿ ?n,(d|"is divisible by"|"is not divisible by"),(d|d|f)
    ÿ od

    This is 134 characters (131 without those indents). It suffers from
    named symbols such as 'rem' needing 5 characters rather than 1.

    Note that your APL (with '5' added), because it uses Unicode, takes up
    105 bytes; my version is still 131/134 bytes while still just about
    being understandable.

    The following is 118 bytes/chars ('%' means integer division). But it
    removes the duplicate parts of the strings, which could probably be done
    in APL too.

    f:=(2,3,5,7)
    for n to 20 do
    d::=()
    for x in f when n%x*x=n do d&:=x od
    ?n,(d|"is"|"is not"),"divisible by",(d|d|f)
    od

    More reductions are possible via tweaks in this syntax, with the result
    still using both standard ASCII, and being more understandable compared to:

    2 3 5 7{a¬??{0=?k¬a/­0=a|?:ý¬?,' is not divisible by ',a?ý¬?,' is
    divisible by ',k}­ø?}20

    (But I'm not making any such changes! I avoid syntax that is too quaint.
    At best I might allow (a|a|b), the equivalent of (a?a:b) in C, to be
    written as (a||b). That would save one character here, but it is also genuinely useful.)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bartc@3:633/10 to All on Sat Oct 31 13:38:05 2026
    On 31/10/2026 13:30, Rosario19 wrote:
    On Sat, 31 Oct 2026 12:21:13 +0000, bartc <bc@freeuk.com> wrote:

    On 31/10/2026 10:39, Rosario19 wrote:
    On Fri, 30 Oct 2026 11:47:59 +0000, bartc wrote:

    That output becomes:

    167 is not divisible by any of (2,3,5,7)
    168 is divisible by 2
    168 is divisible by 3
    168 is divisible by 7
    169 is not divisible by any of (2,3,5,7)

    Sizes (with hard tabs and no comments):

    Your Python: 340 characters
    Mine: 222 (as above; scripting)
    C: 393 (not shown; not elegant)
    Mine: 314 (not shown; systems lang)

    The APL one is 80 characters

    That's not quite right:

    * You're using 2,3,7 not 2,3,5,7, which would add 2 characters

    * You're doing 20 iterations not 200 (adds 1 more character!)

    code I posted is 2 input one left (the list 2 3 7) and one in the
    right (the number 20) and the APL function in the middle.

    80 charaters refer only for APL function.

    OK. I trusted you and didn't bother counting!

    But then the 80 characters is misleading if comparing with my figures
    where the inputs (factors and iterations) are hard-coded within the source.

    So the true figure with 2 3 5 7 and let's say 20 iterations still, would
    be 89 characters. I posted just now a version of mine, which still has
    some conventional structure, with 118 characters, so it's not far off.

    So the number of characters of the function + the input is more than
    80. It is possible change the input [input left the list 2 3 5 7,
    input right the integer 200] for have this

    2 3 5 7{a???{0=?k?a/?0=a|?:???,' is not divisible by ',a????,' is divisible by ',k}???}200

    I don't know what Thunderbird did with the Unicode here; it was alright earlier.

    1 is not divisible by 2 3 5 7
    2 is divisible by 2

    I suggested you can save characters (2 or 4?) by trimming those strings,
    as there is extra white space here.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Rosario19@3:633/10 to All on Sat Oct 31 18:14:46 2026
    On Sat, 31 Oct 2026 13:38:05 +0000, bartc wrote:
    1 is not divisible by 2 3 5 7
    2 is divisible by 2

    I suggested you can save characters (2 or 4?) by trimming those strings,
    as there is extra white space here.

    Yes it seems is possible eliminate the extra spaces, and instead of
    print in stdout strings, return one table and reduce to 73 the lenght
    of the [anonymous] function without input and the name (i call that
    function below f)

    in codegolf I think there are people tha use specializated language
    for codegolf can reduce all this to 10-35 characters max zipping the
    strings too.

    f{leftarrow}{leftbrace}a{leftarrow}{alpha}{diamond}{commabar}{leftbrace}0={notequalunderbar}k{leftarrow}a/{dieresistilde}0=a{stile}{omega}:{omega},{apostrophe}is
    not divisible by{apostrophe},a{diamond}{omega},{apostrophe}is
    divisible
    by{apostrophe},k{rightbrace}{dieresis}{iota}{omega}{rightbrace}

    f?{a??¦?{0=?k?a/?0=a|?:?,'is not divisible by',a¦?,'is divisible
    by',k}?¬?}

    2 3 5 f 20
    1 is not divisible by 2 3 5
    2 is divisible by 2
    3 is divisible by 3
    4 is divisible by 2
    5 is divisible by 5
    6 is divisible by 2 3
    7 is not divisible by 2 3 5
    8 is divisible by 2
    9 is divisible by 3
    10 is divisible by 2 5
    11 is not divisible by 2 3 5
    12 is divisible by 2 3
    13 is not divisible by 2 3 5
    14 is divisible by 2
    15 is divisible by 3 5
    16 is divisible by 2
    17 is not divisible by 2 3 5
    18 is divisible by 2 3
    19 is not divisible by 2 3 5
    20 is divisible by 2 5


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)