Skip to content

Instantly share code, notes, and snippets.

@hollasch
Created April 1, 2014 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hollasch/9925199 to your computer and use it in GitHub Desktop.
Save hollasch/9925199 to your computer and use it in GitHub Desktop.
Runnable form of Duff's Device, written for clarity.
#include <stdio.h>
void send (int count)
{
int n = (count+7) / 8;
switch (count % 8) {
do {
case 0: printf("%d.8\n", n);
case 7: printf("%d.7\n", n);
case 6: printf("%d.6\n", n);
case 5: printf("%d.5\n", n);
case 4: printf("%d.4\n", n);
case 3: printf("%d.3\n", n);
case 2: printf("%d.2\n", n);
case 1: printf("%d.1\n", n);
} while (--n > 0);
}
}
int main (int arc, char *argv[])
{
send (atoi(argv[1]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment