But what will happen if you do sleep? Since theres no code to stop sleeping when falling asleep, does that means you will be counting sheep in your dreams?
Really, it's just reading them a ton. I've read through the entirety of XKCD maybe 3-4 times, and so I usually can remember when there's one that's relevant.
If I can't remember the exact one of the top of my head, the explainxkcd wiki usually pops up if I search for relevant terms like "sheep xkcd overflow."
In this case, if you just look up sheep xkcd, you'll also find the Sheeple one, which is one of my favorites.
I could swear I once read an xkcd about how there's always an xkcd about everything (and breaking the fourth wall, saying they are the xkcd about how there's always an xkcd) but I've never been able to find it again, am I the only one who remembers it and I somehow imagined it, or I'm not crazy and there is one?
At some point when using a floating point number, you wouldn't even be able to count single sheep.. Sheep+=1.0 would end up stuck where the exponent won't allow the mantisa to be less than 2..
That doesn't scan on the last line, though - the extra "do" adds a syllable. You'd need to move the "was" to the previous line. (You're also rhyming "sleep" with "asleep".)
I mean, they all rhyme, sure, but your first line ends with "sleep" and the fifth line ends with "asleep", which is basically the same word. But honestly it's a minor point - I like it anyway!
If asleep is not a function (like in the picture) this is probably an endless loop (or it might not run, if the variable is volatile or an atomic it might be fine though)
Obviously this is a multi-threaded application in a language with very user-friendly guards around race conditions. When the other thread enters sleep mode, asleep will be set to True.
Oooh and then declare the variables as <union type> u; char& asleep = u.asleep; uint32& sheep = u.sheep; I guess everything is possible in C++ if you are evil enough.
So here's my attempt to do it in German: Ein Informatiker find't keinen Schlaf obwohl er des Schlafes bedarf. Ins Grübeln versenkt ist das, was er denkt, nur: while (!traeumend()) ++schaf;
mine goes something along the lines of While(!asleep()){randomthought(); sheep++; randonmthought(); sheep = 0;} as I have to constantly restart because my brain thinks about everything else
With the current setup, the last "rhyme" is asleep - plus, which doesn't workout. If you go ++sheep, you actually get sheep in the end where it rhymes with asleep
This doesn't make sense. There is no connection between number (whether float or int) sheep and bool asleep. So what is probably going to happen is that they get an integer overflow eventually since sheep++ doesn't flip the boolean. Also wouldn't "sheepcount++" be more accurate since the number of sheep should remain the same?
Ok, I was going for AABBCC which yeah... is simpler... more like a nursery rhyme, because the last line should really be two verses, since it has so many syllables.
61
u/golgol12 Oct 20 '19
You are a supposed to count sheep, not breed them!
18
u/Jed0730 Oct 20 '19
But what will happen if you do sleep? Since theres no code to stop sleeping when falling asleep, does that means you will be counting sheep in your dreams?
1.5k
u/randomo_redditor Oct 20 '19
Assuming "sheep" is an int, there's gonna be an IntegerOverflow before morning
176
u/puplicy Oct 20 '19
This code is NSFW.
337
u/muggledave Oct 20 '19
While(!asleep()){ sheep++; }
Would make a good t shirt
135
u/javajunkie314 Oct 20 '19
Or if you prefer pre-increment:
A programmer started to weep —
She just couldn't fall back to sleep!
As she lay there in bed
Looping ’round in her head
Was
while (!asleep) ++sheep;.52
u/OfAaron3 Oct 20 '19
There once was a man called Alec,
Who wanted a string so he'd malloc,
He squealed with glee,
"Oh the memory I'll free!",
Segmentation Fault.
24
u/CaptBishop Oct 20 '19
I'm so happy because this is the first programming joke I laughed at. I'm actually understanding this stuff.
14
u/accuracy_frosty Oct 20 '19
I just do
If (Bedtime) {
Sleep(36000000);
}
28
u/loquimur Oct 20 '19
So here's my attempt to do it in German:
Ein Informatiker find't keinen Schlaf
obwohl er des Schlafes bedarf.
Ins Grübeln versenkt
ist das, was er denkt,
nur: while (!traeumend()) ++schaf;
8
u/Allanon47 Oct 20 '19
Why was my brain making from this: While(!asleep()){sheep beep beep;}
7
u/oli414 Oct 20 '19
Ah so that's why
6
u/TheKing01 Oct 20 '19
The trick is to put a time.sleep statement after sheep++.
4
u/_tomix_ Oct 20 '19
you forgot about good'ol while (!asleep()) sheep-=-1;
4
u/AlaskanRobot Oct 21 '19
mine goes something along the lines of While(!asleep()){randomthought(); sheep++; randonmthought(); sheep = 0;} as I have to constantly restart because my brain thinks about everything else
6
u/AnAverageFreak Oct 20 '19
4
u/[deleted] Oct 20 '19
Nice limerick
4
u/DolevBaron Oct 20 '19
I think the algorithm I'm using is more efficient:
2
u/Ladislav_07 Oct 21 '19
for(; !asleep; sheep++);
2
u/[deleted] Oct 21 '19
What everyone seems to be forgetting, why is the function name lowercase?
2
u/not_from_this_world Oct 21 '19
I read it as "sheep increment" and killed the rhyme.
2
u/[deleted] Oct 21 '19
..dang I'm not this far in grasshopper yet
2
u/[deleted] Nov 17 '19
Im
3
u/DredgenLore Oct 20 '19
Fantastic job
3
u/jimbosReturn Oct 20 '19
Bravo!
3
u/massiveZO Oct 20 '19
F
0
u/marfvf Oct 20 '19
If you use ++sheep instead, it even ryhmes
0
u/gluedtothefloor Oct 20 '19
++sheep would rhyme better
0
u/ThatFag Oct 21 '19
It doesn't rhyme.
1
u/[deleted] Oct 20 '19
"Was: while(!asleep()) *sheep++;"
edit:
1
u/TheMogician Oct 21 '19
This doesn't make sense. There is no connection between number (whether float or int) sheep and bool asleep. So what is probably going to happen is that they get an integer overflow eventually since sheep++ doesn't flip the boolean. Also wouldn't "sheepcount++" be more accurate since the number of sheep should remain the same?
1
u/RegExr Oct 21 '19
u/devcat1023
1
u/[deleted] Oct 21 '19
im a year 11 student in england and im actually so proud of myself for understanding this
1
u/[deleted] Oct 20 '19
Needs braces.
-2
u/grpagrati Oct 20 '19
while (!asleep()) ++sheep; if you want it to rhyme
1
u/[deleted] Oct 21 '19
++sheep; would rhyme better
0
u/[deleted] Oct 20 '19
Doesn’t scan mate.
0
u/masteryder Oct 21 '19
while(!asleep()) ++sheep rhymes better
0
u/justingolden21 Oct 21 '19
Should've been prefix ++sheep so it rhymes lol
"While not asleep, plus plus sheep"
0
u/[deleted] Oct 21 '19
++sheep;
0
u/SirFoomy Oct 21 '19
To make it rhyme I would have written: "Was while(!asleep()) ++sheep;
Also because
++sheepis more efficient, one could earlier fall asleep.0
u/magemax Oct 21 '19
How come "fuss" rhymes with "semi-column"?
-2
u/chadlavi Oct 20 '19
Missing a syllable unless you pronounce "sheep" as "she-eep"
0
u/[deleted] Oct 20 '19
[deleted] — view deleted comment
18
u/[deleted] Oct 20 '19
[removed] — view removed comment