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: Tue, 03 Mar 2026 06:20:33 -0800
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <86a4wpdmfi.fsf@linuxsc.com>
References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <10o53k6$1i0ef$2@dont-email.me> <86ms0peby6.fsf@linuxsc.com> <10o6nci$21m76$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Tue, 03 Mar 2026 14:20:39 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="9dc790098ce30bad4f358538e3d50880"; logging-data="2191717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ehk9AEVUS8v3ebZD5gq0Ja33fxLeK4Go="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:xgbVaXZbJ1EK1kIOvHh9u2wVeWY= sha1:l5H0I150Isi+tdKGaoGxmwp1az8=
Xref: csiph.com comp.lang.c:396736
DFS writes:
> On 3/3/2026 12:09 AM, Tim Rentsch wrote:
>
>> DFS writes:
>>
>>> On 3/2/2026 3:44 AM, Tim Rentsch wrote:
>>>
>>>> DFS writes:
>>>>
>>>>
>>>> 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).
>>>
>>> Done.
I should have added, I appreciate your taking on the challenge.
> Recursion means the function calls itself.
What you're describing is called direct recursion. The word
recursion by itself, without the adjective, includes the case
of mutually recursive functions.
> [...]
>
>> The latest challenge, which I just got through doing, is to
>> disallow if, for, while, goto, return, and to forbid functions
>> and function calls except for calls to C standard library
>> functions.
>
> Yikes!
>
> Is main() OK?
Yes, sorry, not mentioning main() was an oversight on my part.
(Still not okay to call it.)
> How about the use of variables?
Sure.
> What written languages are allowed?
Standard ISO C. Okay not to be strictly conforming. :)
> nested ternaries? How deep?
Sure. As deep as you can stand, within reason. My own code
sometimes used ?: at the end of another ?: but not in the middle
(ie, ... ? ... ? ... : ... : ... never appeared).
>> Also no math library. :)
>
> Using math.h allowed me to easily create a one-line formula.
> But I could probably now do it in 3-4 lines without math.h.
Yes it isn't hard.
>> The program is a bit on the long side because of argument
>> processing but the matrix print code is less than 20 lines,
>> including 5 blank lines.
>
> I'll have to bow out for now, but would like to see your latest code.
My rule is not to post my own code until others have made a good
faith effort on the challenge.
> I note that the no-loops challenge was a worthwhile pursuit I never
> even considered.
Yes, no loops is fun. Once you get used to it, using tail-recursive
functions in place of loops often seems like a better choice.
> I think a recursive function could be really short and sweet, so I'm
> going to try that.
By all means. The version I first wrote had two tail-recursive
functions, one to find the appropriate number of rows and columns
for a given cutoff, and one to show the matrix of values.