Given the totally arbitrary choice between writing fast vs. slow code, it seems that developers unfairly discriminate against slowness every time. It's time to rectify this situation with a slow code competition. Let's see who can write a code snippet that will take the longest amount of time to print the numbers one through ten.
These are the only rules:
- You can use any language you choose, including pseudocode.
- Your code snippet must be ten lines of code or less. Preprocessor directives and such may be omitted.
- It must complete in some finite amount of time.
- Sleep (and similar) statements are not allowed.
- You can't stay awake until 4:00am trying to think of a way to "win."
Yes, I realize this is a stupid competition with lots of loopholes in the rules. I'm mainly curious to see how people who are much smarter than me might approach the problem. Without further ado, here's my submission:
/* Variables /
unsigned long counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, currentNumber = 0;
time_t markTime = time(NULL);
while(++currentNumber <= 10) {
/* Wait until the system time wraps.
* This should take a few hundred billion years on a 64-bit system. */
while(time(NULL) > markTime) { /* do nothing */ }
/* Update the time reference so the above WHILE loop doesn't immediately fall through
* the next time around. */
markTime = time(NULL);
/* If every counter has wrapped back to zero */
if(++counter1 == 0) {
if(++counter2 == 0) {
if(++counter3 == 0) {
if(++counter4 == 0) {
/* Print the number */
printf("%d", (int)currentNumber);
} } } }
}