Subject: 2 tiny C riddles

From: Omer Mussaev <[email-masked]>
Date: Tue, 21 Nov 2000 21:28:04 +0200

They come from various sources, and you may have encountered them
earlier.
Anyway:

1.   You are given following piece of code:

int i, j=20;
for (i=0 ; i<j ; i-- )
   printf ("-");

you have to show 3 ways to make this code to print 20 dashes.

2. You have 2 pieces of code:

----------------
signed i ;
while (1) i++ ;
----------------
and
----------------
signed float f ;
while (1) f++ ;
----------------

Assuming you have run those for enogh time, on intel P6 arch, what will
be minimal and maximal values of
i and f?

Enjoy

---

From: Omer Zak <[email-masked]>
Date: Tue, 21 Nov 2000 22:14:20 +0200 (IST)

> you have to show 3 ways to make this code to print 20 dashes.

BUT!!! in each way, you are permitted to change only one character in the
above piece of code.
                                             --- Omer
There is no IGLU cabal.  The former IGLU cabal members are now busy
looking for the 4th solution to the above riddle.
WARNING TO SPAMMERS:  see at http://www.zak.co.il/spamwarning.html

---

From: Omer Mussaev <[email-masked]>
Date: Wed, 22 Nov 2000 11:19:48 +0200

> BUT!!! in each way, you are permitted to change only one character in the

Hmm. Well, that was the important part that I missed. Yes, you are permitted
to
change only _one_ character in code.

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 22 Nov 2000 15:31:47 +0200

> you have to show 3 ways to make this code to print 20 dashes.

This is a beautiful riddle :) I got the first two rather quickly, but I
couldn't find the third until I went to the bathroom and had some time to
think :) (I'm sure you didn't really want to know that...)

Anyway, in a couple of days please post the answer, so I can see if I got
the same 3, and so that people who didn't waste their time on this riddle will
also know the answer.

> 2. You have 2 pieces of code:

Am I missing something here? This doesn't seem like a riddle, but rather
requires knowing the exact details of the P6 floating point and integer
architecture... Or is the point you're trying to make that the answer for
the "float" question different in nature from the "int" one (I won't say any
more to not ruin it for others)?

-- 
Nadav Har'El                        |  Wednesday, Nov 22 2000, 24 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |As every cat owner knows, nobody owns a
http://nadav.harel.org.il           |cat.

---

From: "Nadav Har'El" <[email-masked]>
Date: Mon, 27 Nov 2000 10:36:52 +0200

> you have to show 3 ways to make this code to print 20 dashes.

By now I hope that all of you solved this very nice riddle. So you may be
ready for the next challenge. By changing only one character in the above
program, make it print 21 (that's right, twenty-one!) dashes.

As far as I see, there's only one solution to this new problem, but feel
free to surprise me with two solutions :)

I'll post the solution on Friday, so you have until then to think about it!

-- 
Nadav Har'El                        |     Monday, Nov 27 2000, 29 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Help Wanted: Telepath. You know where to
http://nadav.harel.org.il           |apply.