Article View: comp.lang.c
Article #1205Re: BizFuss (was Re: Taming The Switch-Statement)
From: bartc
Date: Sat, 31 Oct 2026 13:27
Date: Sat, 31 Oct 2026 13:27
73 lines
4379 bytes
4379 bytes
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.)
Technical Details
Message-ID:
<11c4qch$14p4f$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me> <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me> <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me> <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <tft5elp1q2ns7rhfp3rod862ks5ip3p0ms@4ax.com> <11c1kee$2lqi$2@dont-email.me> <11c205f$73k2$1@dont-email.me> <t8hbelloceeupncsjjl41ah7jd4vv2gms3@4ax.com> <11c4mfp$13b6a$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: bartc <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: BizFuss (was Re: Taming The Switch-Statement) Date: Sat, 31 Oct 2026 13:27:45 +0000 Organization: A noiseless patient Spider Lines: 73 Message-ID: <11c4qch$14p4f$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me> <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me> <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me> <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <tft5elp1q2ns7rhfp3rod862ks5ip3p0ms@4ax.com> <11c1kee$2lqi$2@dont-email.me> <11c205f$73k2$1@dont-email.me> <t8hbelloceeupncsjjl41ah7jd4vv2gms3@4ax.com> <11c4mfp$13b6a$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 31 Oct 2026 13:27:46 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1205391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DjGOU+o2ULkdhPSJA0jFu"; posting-host="e68c21d34812d47967f764b98d287209" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ZxF2EIkLjDfdLYbpwxIPS6K6e5I= sha256:+wMVu2t/JasFvld2loHrs4WKwVy29/7eh0ENyYaNCVg= sha1:IdM6mCHlbTYGh0qiUO8+Fw7tXKk= sha256:XL9QwEYHrdQTSTk73+mA75t73ak1P3ieMPahY1Kb7P8= In-Reply-To: <11c4mfp$13b6a$1@dont-email.me> Content-Language: en-GB