Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #10276

Long winter evenings

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.programming
Subject Long winter evenings
Date Mon, 4 Nov 2019 17:37:09 +0000
Organization Fix this later
Lines 35
Message-ID <qppnk6$584$1@dont-email.me> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 4 Nov 2019 17:37:10 -0000 (UTC)
Injection-Info reader02.eternal-september.org; posting-host="b7f4f89913745d6a2d387554174ef4ae"; logging-data="5380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BrTsrhLwPxUrlJqH1A2DbbnSgCXUqphnk7+aiQPsuvQ=="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0
Cancel-Lock sha1:Yuk9zzVLWd7myhK8Ckz3AznZe60=
Content-Language en-GB
X-Mozilla-News-Host news://news.eternal-september.org:119
Xref csiph.com comp.programming:10276

Show key headers only | View raw


I have just written a program in C, which for reasons that will remain 
shrouded in the mists of wossname I wanted to be as short as possible. 
The program solves a highly specific and relatively antiquated problem.

Now that the nights are drawing in, some of you might be at a loose end 
and wish for something to help you pass the time.

So here's the puzzle, which is in two parts:

(1) What, *exactly*, does the program do? That is, what is the 
significance of the printed result?

(2) Is there a way to make the program shorter, without compromising its 
rigorous adherence to ISO C90? (See below.)

#include <stdio.h>
int r(int*c){int f=0;if(*c%5==1)*c/= 5,*c*=4,f=1;return f;}
int t(int c){int f=1,i;for(i=0;f&&i<5;i++)f=r(&c);return f*!(c%5);}
int main(void){int n=0,d=0;while(!d)d=t(++n);printf("%d\n",n);return 0;}

Four obvious shortenings are excluded:
A. Lose the space between "#include" and "<stdio.h>";
B. Lose the second and third newlines;
C. Lose "void";
D. Lose "return 0;"

If nobody gets it within a week or so, I'll post the solution to (1). 
(If I could think of a solution to (2), I'd have written it that way to 
start with!)

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Back to comp.programming | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Long winter evenings Richard Heathfield <rjh@cpax.org.uk> - 2019-11-04 17:37 +0000
  Re: Long winter evenings David Brown <david.brown@hesbynett.no> - 2019-11-04 22:39 +0100
    Re: Long winter evenings Richard Heathfield <rjh@cpax.org.uk> - 2019-11-04 21:51 +0000
      Re: Long winter evenings David Brown <david.brown@hesbynett.no> - 2019-11-05 10:42 +0100
    Re: Long winter evenings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-04 22:24 +0000
  Re: Long winter evenings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-04 22:19 +0000
    Re: Long winter evenings Richard Heathfield <rjh@cpax.org.uk> - 2019-11-04 22:30 +0000
      Re: Long winter evenings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-04 23:59 +0000
        Re: Long winter evenings Richard Heathfield <rjh@cpax.org.uk> - 2019-11-05 01:03 +0000
          Re: Long winter evenings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-05 04:01 +0000
            Re: Long winter evenings Richard Heathfield <rjh@cpax.org.uk> - 2019-11-05 07:42 +0000
  Re: Long winter evenings Melzzzzz <Melzzzzz@zzzzz.com> - 2019-11-04 23:00 +0000
  Re: Long winter evenings Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-06 04:58 -0800

csiph-web