Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
Date: Mon, 02 Mar 2026 21:15:19 -0800
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <86ikbdebo8.fsf@linuxsc.com>
References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <20260302110720.00007698@yahoo.com> <86qzq2e1u3.fsf@linuxsc.com> <10o4ilk$1bo87$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Tue, 03 Mar 2026 05:15:24 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="9dc790098ce30bad4f358538e3d50880"; logging-data="1839364"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OaShICQluq6p1Jk8nDaYp21ujzrraPqc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:/yVFt23bQLKtdNw7g7T8X/C4XbM= sha1:DESiMMsBOtMm5ActDdr+Cn1hj2c=
Xref: csiph.com comp.lang.c:396734
Bart writes:
> On 02/03/2026 14:35, Tim Rentsch wrote:
>
>> Michael S writes:
>>
>>> On Mon, 02 Mar 2026 00:44:57 -0800
>>> Tim Rentsch wrote:
>>>
>>>> DFS writes:
>>>>
>>>>> Challenge is to output sequential numbers by column then row:
>>>>>
>>>>> 1 6 11 16 21
>>>>> 2 7 12 17 22
>>>>> 3 8 13 18 23
>>>>> 4 9 14 19 24
>>>>> 5 10 15 20 25
>>>>
>>>> [...]
>>>>
>>>>> Simple enough. But the following 2 requirements take it from
>>>>> trivial to less trivial!
>>>>>
>>>>> --------------------------------------------------------------------
>>>>> 1) must be able to cut the output off at any arbitrary value
>>>>> lower than rows x columns
>>>>> --------------------------------------------------------------------
>>>>
>>>> [...]
>>>>
>>>>> --------------------------------------------------------------------
>>>>> 2) if you don't specify rows and columns, your solution must try
>>>>> to calculate them to form a square (same # of rows and columns)
>>>>> that includes only 1 to N.
>>>>>
>>>>> If rows=columns can't be calculated, return message 'not
>>>>> possible'
>>>>> --------------------------------------------------------------------
>>>>
>>>> A straightfoward exercise. Here is a counter challenge to make
>>>> things more interesting: as above, but don't use nested loops
>>>> (or goto's, etc).
>>>
>>> Does 'etc' include function calls?
>>> I guess that the answer is 'yes', but would like it confirmed.
>>
>> I don't think of function calls as being in the same category
>> as control flow statements. I guess the point of your question
>> is one loop could be in a function called from within another
>> loop. The "don't use nested loops" is meant to include dynamic
>> nesting as well as static nesting. In other words one loop
>> running, by any means, during the time another loop is in
>> progress, is disallowed. So a call to a function where the call
>> is inside a loop, and where the called function effects a loop
>> in some way, is not allowed any more than 'for(...) for(...)'
>> would be. Is that specific and well-defined enough to answer
>> your question? There is no prohibition against function calls
>> per se; the relevant condition is about loops, including
>> simulated loops that don't use for() or while() or do/while().
>>
>>> Another counter challenge could have been to commpletely avoid
>>> loops/goto. But given the hint above it would not be interesting.
>>
>> I am confident it wouldn't be challenging for someone with your
>> level of experience, but it could be interesting for some other
>> folks.
>>
>> The version of this program that I wrote has no for()'s,
>> while()'s, do/while()'s, or switch() statements, and also has
>> no nested loops,
>
> Doesn't the prior condition preclude that? Since if there are zero
> loops, it's hard to make them nested!
I see no reason to answer your questions since you seem to have
no interest in writing C code.