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 1944
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: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |