Skip to content

Instantly share code, notes, and snippets.

@HelixSpiral
Created January 10, 2012 07:06
Show Gist options
  • Save HelixSpiral/1587585 to your computer and use it in GitHub Desktop.
Save HelixSpiral/1587585 to your computer and use it in GitHub Desktop.
One Hundred Doors
/* http://rosettacode.org/wiki/100_doors */
#include <stdio.h>
int main()
{
int x, y;
int doors[100] = { 0 };
/* Loop the 100 times */
for(x = 1; x <= 100; ++x)
for(y = x; y <= 100; y += x)
doors[y] = (doors[y] == 1) ? 0 : 1;
for(x = 1; x <= 100; ++x)
printf("Door[%d] - %s\r\n", x, (doors[x] == 1) ? "Open" : "Closed");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment