Skip to content

Instantly share code, notes, and snippets.

@phimuemue
Created March 9, 2014 10:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phimuemue/9445584 to your computer and use it in GitHub Desktop.
Save phimuemue/9445584 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#define MAXSIZE 20
volatile char counterarray[MAXSIZE] = {0};
#define MAXDEPTH 10
int depth=0;
int olddepth=0;
int searcher=0;
int searchermax[MAXDEPTH];
int counter[MAXDEPTH];
int lastloop;
#define _ counter[depth]
#define times [counterarray]=1; \
depth++; \
searcher = 0;\
for(searcher=-1; counterarray[searcher]==0; ++searcher){ \
searchermax[depth]=searcher+1; \
} \
counterarray[searcher] = 0; \
for(counter[depth]=0; \
olddepth=depth, \
(lastloop=!!(counter[olddepth]<searchermax[olddepth])), \
counter[olddepth]==searchermax[olddepth]?depth--:1, \
olddepth = depth, \
lastloop; \
_=counter[olddepth]++)
#define NEWLINE printf("\n")
int main(int argc, char** argv){
printf("3 times hello:\n");
3 times printf("Hello.\n");
NEWLINE;
printf("Now a simple football match simulation:\n");
3 times printf("Score: 0 : %d\n", _);
NEWLINE;
printf("Nested tests\n");
2 times {
printf("Counting: ");
9 times {
printf("%d ", _);
}
printf("\n");
}
NEWLINE;
5 times {
printf("Counting up to %d: ", _);
_ times {
printf("%d ", _);
}
printf("\n");
}
NEWLINE;
printf("Some identity matrices:\n");
7 times {
printf("Dimension %d\n", _);
int n = _;
n times {
int outer = _;
n times {
printf("%c ", (_==outer?'1':'0'));
}
printf("\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment