Swammerdami
Squadron Leader
There are several programmers here at TFT. Let's play a game. (I might have posted this in the Games subforum but there doesn't seem to be one.)
Post a code snippet (in any programming language) and/or guess the intent or context of a prior submission. Submissions may be made in any language, and with whatever level of obfuscation etc. seem most appropriate. Consider the problem space to be quite flexible: if you wish you can reverse the puzzling and pose a task, asking for a code snippet. Or the snippet might have a bug, with identifying or fixing the bug being the puzzle.
I'll start. The cute and useful algorithm that this snippet helps implement is mentioned in one of Knuth's books. If unfamiliar with that algorithm, careful contemplation of this snippet MIGHT lead you to guess the context and re-discover an elegant algorithm.
Snippet #1
An alternative (somewhat less obfuscated?) return statement is shown commented-out.
Post a code snippet (in any programming language) and/or guess the intent or context of a prior submission. Submissions may be made in any language, and with whatever level of obfuscation etc. seem most appropriate. Consider the problem space to be quite flexible: if you wish you can reverse the puzzling and pose a task, asking for a code snippet. Or the snippet might have a bug, with identifying or fixing the bug being the puzzle.
I'll start. The cute and useful algorithm that this snippet helps implement is mentioned in one of Knuth's books. If unfamiliar with that algorithm, careful contemplation of this snippet MIGHT lead you to guess the context and re-discover an elegant algorithm.
Snippet #1
Code:
ITEM item_rand(struct rhtable *rhp, int size)
{
double f = unif_rand(0.0, 1.0) * size;
rhp += (int)f;
return rhp->rh_item[f > rhp->rh_splitp];
// return rhp->rh_item[f - (int)f > rhp->rh_splitp ? 1 : 0];
}