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 06:35:32 -0800 Organization: A noiseless patient Spider Lines: 71 Message-ID: <86qzq2e1u3.fsf@linuxsc.com> References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <20260302110720.00007698@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 02 Mar 2026 14:35:53 +0000 (UTC) Injection-Info: dont-email.me; posting-host="879346d16fc7c1cd3f18baf5c462c148"; logging-data="1296664"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6OpATsq7it5ch6LZ0ZEsbZN0qdZwK9Q4=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Y513BTILB74QFMCCR0wNrxnejGo= sha1:JVj44zYSGP5pESWsl4OccvZkOck= Xref: csiph.com comp.lang.c:396728 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, and I found it more interesting to write that version than one where for() or while() were used. I think that would make a nice second-level challenge. For a third challenge, write a version that doesn't use for(), while(), do/while(), goto, and also does not have recursive function calls.