🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1164

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

#1164
From: bartc
Date: Fri, 30 Oct 2026 11:47
70 lines
3695 bytes
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)

Technical Details
Message-ID: <11c205f$73k2$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-mail
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>

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: Fri, 30 Oct 2026 11:47:59 +0000
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <11c205f$73k2$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 30 Oct 2026 11:47:59 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="233090"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19cogTftHLXJhXshqx3U/wg"; posting-host="971608b32304486bbd993112f7ae4068"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9VFRDfvpVgBQbHR+K+Bx+ch3Aos= sha256:HxUfQXlkwNzL83e6KuuPHfWfBoDyzPObAOm8jZ7ApRA=
	sha1:beRDryV6WFfuEdKD+9JaolIfSew= sha256:kYGvppUNRsVAD8XEeZDRQOpsE4BrcF6w/VNUWztRChQ=
In-Reply-To: <11c1kee$2lqi$2@dont-email.me>
Content-Language: en-GB