# Thread: What's that code snippet?

1. Originally Posted by Swammerdami
Originally Posted by Jayjay
I agree that the commented out return statement is not equivalent to the one that's not. The former checks if the decimal part of f is larger than splitp, implying that splitp is a floating point between 0 and 1. The latter checks if f is greater than splitp. Hmm.
This was addressed in the post immediately before yours. Let me be more explicit:

(1) item_rand() utilizes TWO random numbers: (a) an integer in the range {0, 1, 2, ..., size-1} and a "splitting" probability 0 < p < 1.
(2) item_rand() derives BOTH the random numbers it needs from a SINGLE call to a random-number generator.
(3) Since item_rand() may be called millions of times while setup() is called only once, a TINY bit of time can be saved by adding K to R[K].rh_splitp. Obviously setup() and item_rand() must agree on whether this micro-optimization is in use or not! setup() is a MUCH longer routine than item_rand() and is NOT shown.

The optimizations (2) and (3) are much less interesting than the algorithm implemented by setup()/item_rand(). It can be used by MANY simulation programs and does what it does MUCH faster than a naive approach.
Optimized Monte-Carlo generator?

2. More snippets please! Surely there are lots of code snippets that are amusing, instructive, scary, puzzling, disgusting or worth looking at for some reason!
I think Jayjay's Mondrian snippet prints "Hello world." Am I close?

Originally Posted by barbos
Originally Posted by Swammerdami
... the algorithm implemented by setup()/item_rand() [] can be used by MANY simulation programs and does what it does MUCH faster than a naive approach.
Optimized Monte-Carlo generator?
Yes!
Among how many distinct arbitrary-probability items will item_rand() choose from?
(I barely remember my English. Is "choose from among" an English idiom? Did I illegally split a preposition?)

The following was output by a program that called item_rand() for each character. What did that program do? Be specific.
To say,
'Thy past know,
Feed'st is't not my still shown.
To whom ther's gainst that kept strange, had night,
For them thin my loss, he roses return'd loves test high defections fix'd that pour'st though win my heart,
As he leave memory
My spirit, now untains as play as your nature hap to the golder ther with my truth defection the was those jacks truth's and mock to hath canst my in tabless bold,
Bare flower pale same;
And hooks, that thy name to shadows I be fair far that their special neight in thee hourse her with from their body's ending thy fate,
And not by all my babe, youthful doth flies
When so sullence he trial love to the posters brain widow'd chaste me I not love which his grow shall carcely and error and it lame, thou show!

Thou pine and the thought kill I saw you not beauty grief, all mayst hope.

Like a heart stransfix the word
No profane, and age,
Which glory;
That a fortify the guides to large? Is thy powers with taugh'd each borrows not could many lamb he leaguest, 'tis fell keeps your never speed,
The worst others been
To spends
For if thou not keep,
Laid best in my loves, thy see them bore thus vainly charg'd the eyes shall be deceiv'd;
But yet whit doth fingers not able arigour fix'd'?
Be scandles their we, what thoughts of my lays shame,
Commit the world with three shall I still I this writ and stol'n from the love ere iniquid place?
I have his purple same;
Coral be so it thier wrongs

There I boast thou did example married, delight,

3. Where is my Prize then?

Can I at least get a job at Google?

4. Originally Posted by barbos
Where is my Prize then?
Prizes for best SUBMISSIONS only. So far, Jayjay is in in 1st place with his Mondrian snippet. I'm tied with myself for 2nd.

Can I at least get a job at Google?
I dunno; can you?

5. OK, I submit... let's see what I have here,...... I submit my avatar.

6. Originally Posted by Swammerdami

Snippet #3

17/91; 78/85; 19/51; 23/38; 29/33; 77/29; 95/23; 77/19; 1/17; 11/13; 13/11; 15/2; 1/7; 55/1
I am not a Mensa material.

7. Originally Posted by barbos
Originally Posted by Swammerdami

Snippet #3

17/91; 78/85; 19/51; 23/38; 29/33; 77/29; 95/23; 77/19; 1/17; 11/13; 13/11; 15/2; 1/7; 55/1
I am not a Mensa material.
That "tiny" program contains the Sieve of Eratosthenes; and outputs the entire sequence of prime numbers!
(In the form 22, 23, 25, 27, 211, ... with non-power-of-two numbers ignored. ... If you wait long enough.)

Who created that "programming language"? Google "Genius who died of Covid-19"

8. char conundrum(char x){
if( (x >= 65) && (x <= 90) ) return (x | 0x20);
if( (x >= 97) && (x <= 122) ) return x(x & 0xDF);
return(x);
}

9. Originally Posted by steve_bank
char conundrum(char x){
if( (x >= 65) && (x <= 90) ) return (x | 0x20);
if( (x >= 97) && (x <= 122) ) return x(x & 0xDF);
return(x);
}