Article View: comp.lang.c
Article #1173Re: BizFuss (was Re: Taming The Switch-Statement)
From: bartc
Date: Fri, 30 Oct 2026 15:36
Date: Fri, 30 Oct 2026 15:36
51 lines
3164 bytes
3164 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)))
> #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.
Technical Details
Message-ID:
<11c2dim$cbae$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>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 15:36:54 +0000 Organization: A noiseless patient Spider Lines: 51 Message-ID: <11c2dim$cbae$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 15:36:55 +0000 (UTC) Injection-Info: dont-email.me; logging-data="404814"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T+6+sKYtUFZq1nkG7/eBj"; posting-host="971608b32304486bbd993112f7ae4068" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:v/LOnneZ6ZWFXk+6QoEMyJcBhk0= sha256:vMqJ+KuKAmZwb4GNqH7OY+7uTLOjB1HPMq4zX/v43aE= sha1:4uBQ9tBotfRwm2Uto0hOV8zjPX8= sha256:OL9gVNnn1DfbOXlmiywabcbmzaMnWFNYOF7n6Ss+758= Content-Language: en-GB In-Reply-To: <11c1kee$2lqi$2@dont-email.me>