Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #397387

Re: Sort of trivial code challenge - may be interesting to you anyway

Path csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Sort of trivial code challenge - may be interesting to you anyway
Date Mon, 06 Apr 2026 12:02:25 -0700
Organization A noiseless patient Spider
Lines 52
Message-ID <86se97zzcu.fsf@linuxsc.com> (permalink)
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> <86ikbdebo8.fsf@linuxsc.com> <10o7he5$2cb17$1@dont-email.me> <865x718b5q.fsf@linuxsc.com> <10p0u54$32bhs$1@dont-email.me> <10p24th$3mc94$1@dont-email.me> <86h5qg66v7.fsf@linuxsc.com> <10p7g4c$1haut$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Date Mon, 06 Apr 2026 19:02:26 +0000 (UTC)
Injection-Info dont-email.me; posting-host="d9fa7580ab63f06b181c1510d363a99a"; logging-data="2429356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SQofc5SHG2kMelt5FMo3lds6oT91fSfA="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:1KVB+iK1kGhuMUD6WHXyKhjsIx4= sha1:x2nutJRx5/8n5MBtEKW+M21xuto=
Xref csiph.com comp.lang.c:397387

Show key headers only | View raw


Bart <bc@freeuk.com> writes:

> On 15/03/2026 22:54, Tim Rentsch wrote:
>
>> Bart <bc@freeuk.com> writes:
>>
>>> On 13/03/2026 11:58, Bart wrote:
>>>
>>> [characterizing my earlier code as a finite state machine]
>>>
>>>> Ideally it would just have a loop.  (In my languages, there is a
>>>> feature called 'doswitch',
>>>
>>> I ported this (C version using 'goto') to my scripting language just
>>> to see what it would look like:
>>>
>>>   https://github.com/sal55/langs/blob/master/tr.q
>>>
>>> This doesn't use 'goto', nor conventional loops.  However 'doswitch'
>>> does loop.
>>>
>>> An alternative method could use 'recase' (in C terms, jumping directly
>>> to a case label).  It's just goto 'under the hood', but much less
>>> underhand than 'longjmp'.
>>>
>>> Other ways of control flow include label pointers (also in some C
>>> extensions).
>>
>> None of these more elaborate control structures are needed.  The
>> board display behavior can easily be expressed using conventional
>> control structures, in standard C:
>>
>>      void
>>      show_board( unsigned height, unsigned width, unsigned cutoff ){
>>        const  int       D =  digits_width( cutoff );
>>        const  unsigned  R =  cutoff < height ? cutoff : height;
>>          unsigned   r = 0,   c = 0;
>>
>>          while(  r < R  ){
>>              unsigned v = r + c*height;
>>              if(  v < cutoff    )  printf( " %*u", D, v+1 );
>>              if(  ++c >= width  )  putchar( '\n' ),  c = 0,  r++;
>>          }
>>      }
>
> Yes, but you'd prohibited many standard features including loops for
> your challenge.

I was responding to a context where the prohibitions had already
been violated.  I was simply pointing out that if those rules are
going to be ignored then there are easier ways to solve the problem
than importing exotic control structures from other languages.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-12 05:50 -0700
  Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 11:58 +0000
    Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 23:00 +0000
      Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:54 -0700
        Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-15 23:42 +0000
          Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-06 12:02 -0700
    Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:43 -0700

csiph-web