How about this idea? Post fragments of C code which
seem fun, interesting or instructive. Puzzles can
be posed in various ways. (What does this do? Can you
see the bug? How to code this for better efficiency?
Code for better readability, etc.) Best, perhaps, would
be fragments from another's admirable application.
"What does this do?" puzzles might need comments removed
and symbols obfuscated, as I've done in both of the
following fragments.
Fragments #1 and #2 are unrelated to each other.
Please "reverse-engineer" them before Googl'ing for
exact provenance.
Fragment #1
int hw(uint64 x)
{
uint64 y;
y = x & (x >H0);
if (y & (y >2 * H0))
return 1;
y = x & (x >H1);
if (y & (y >2 * H1))
return 1;
y = x & (x >H2);
if (y & (y >2 * H2))
return 1;
y = x & (x >1);
return (y & (y >2));
}
Fragment #2
void baz(int b, int c)
{
int a, d, e, f, g;
if (e = b, g = a = -1, c)
while (d = b) {
b = c-1, f = c = d;
while (f--)
foo(g -= a);
d = -e, e = a, a = d;
}
}
What does each of these fragments do?
James Dow Allen 9 1978
James Dow Allen wrote:
>
.... snip ...
>
Fragment #1
int hw(uint64 x) {
uint64 y;
y = x & (x >H0);
nothing. H0 is undefined.
.... snip ...
>
Fragment #2
void baz(int b, int c) {
int a, d, e, f, g;
if (e = b, g = a = -1, c)
while (d = b) {
nothing. d is uninitialized.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
On Wed, 06 Feb 2008 00:20:17 -0500, CBFalconer wrote:
James Dow Allen wrote:
>>
(...)
>> Fragment #2 void baz(int b, int c) { int a, d, e, f, g;
if (e = b, g = a = -1, c) while (d = b) {
nothing. d is uninitialized.
'd' is initialised using input argument 'b' (it is not a comparison to 'b').
- Anand
--
ROT-13 email address to reply.
CBFalconer said:
James Dow Allen wrote:
>>
... snip ...
>> Fragment #1 int hw(uint64 x) { uint64 y;
y = x & (x >H0);
nothing. H0 is undefined.
Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly
J Random Newbie.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Anand Hariharan wrote:
CBFalconer wrote:
>James Dow Allen wrote:
>>>
(...)
>>> Fragment #2 void baz(int b, int c) { int a, d, e, f, g;
if (e = b, g = a = -1, c) while (d = b) {
nothing. d is uninitialized.
'd' is initialised using input argument 'b' (it is not a
comparison to 'b').
Woops - you're right.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
In article <Ab******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>CBFalconer said:
>James Dow Allen wrote:
>>>
... snip ...
>>> Fragment #1 int hw(uint64 x) { uint64 y;
y = x & (x >H0);
nothing. H0 is undefined.
Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly J Random Newbie.
Oh. The. Irony.
Note that recently the regs are getting more and more open (and openness
is a good thing - don't get me wrong!) about the fact that there are
different rules for the Clique than for, as RH so quaintly puts it, J
Random Newbie.
Note also that CBF's Clique membership seems to be in a probationary
status these days... ga*****@xmission.xmission.com (Kenny McCormack) writes:
In article <Ab******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>CBFalconer said:
>>James Dow Allen wrote:
... snip ...
Fragment #1 int hw(uint64 x) { uint64 y;
y = x & (x >H0);
nothing. H0 is undefined.
Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly J Random Newbie.
Oh. The. Irony.
Note that recently the regs are getting more and more open (and openness
is a good thing - don't get me wrong!) about the fact that there are
different rules for the Clique than for, as RH so quaintly puts it, J
Random Newbie.
Note also that CBF's Clique membership seems to be in a probationary
status these days...
"Chuck" is probably one of the most useless posters to a Usenet
technical group I have ever witnessed. No wonder his code is so awful -
I doubt if he was ever allowed to post in a real team as I have rarely
seen anyone so antisocial and up themselves. Better to killfile him,
much as a I abhor doing so.
Re: What does this code do?
Decrease productivity of newsgroup readers ? :-)
On Feb 9, 5:51 am, Dave Hansen <i...@hotmail.comwrote:
On Feb 8, 3:12 am, James Dow Allen <jdallen2...@yahoo.comwrote:
[...]
Richard Bos wrote:
that I can't be bothered to figure out.
He didn't say he couldn't, but that he couldn't be bothered.
Apparently he's decided it's beneath him.
But I like a puzzle. I'm thinking "spiral..."
Yes, with a nearby spiralling thread I'm surprised
only Dave got this. It would be interesting to
know why Bos disliked the code so much. (Omission
of comments was deliberate.) I don't generally pack
multiple statements onto one line, but did so
almost whimsically in the fragment. Avoiding
new lines seems not too egregious in simple idioms like
d = e, e = a, a = d; /* swap */
All other things being equal (though of course
they never are!) the succincter code is the better
code: one FOR is better than four FOR's. For this
reason, my spiraller seems OK.
James
In article <47*****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
....
>Get off your friggin' high horse, mister perfect-maths-wizard. You have not the slightest idea how I tested your program wand why I could not be arsed to do more of an effort. But since you asked for it, I'll tell you now: I couldn't be arsed because it was crappy code, used in a crappy puzzle, by a crappy programmer who should have known better than to consider that crap even remotely acceptable. And in the future, I won't even be making what little effort I have this time; your programming inadequacy is not worth it.
Somebody did not get enough mommy love. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Chris Cioffi |
last post by:
I started writing this list because I wanted to have definite points
to base a comparison on and as the starting point of writing something
myself. After looking around, I think it would be a...
|
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?...
|
by: mark | r |
last post by:
is there an industry standard method of costing out a project
the problem i have is that when talking to a developer they say "i dont know
how long it will take" which just isnt acceptable
#...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there...
|
by: GTO |
last post by:
I do not believe that C# is the future of C++. I also do not believe that
adding two thousand new library functions to the standard library is the
future of C++. But what is the future of C++? Is...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |