Skip to content

Instantly share code, notes, and snippets.

@jackie-scholl
Last active December 13, 2015 21:08
Show Gist options
  • Save jackie-scholl/4974981 to your computer and use it in GitHub Desktop.
Save jackie-scholl/4974981 to your computer and use it in GitHub Desktop.
#include <stdio.h> // Import the standard I/O library
int main(int m, char**g){ // m is the argument count, g is the argument array
int i, n, x=1; // x iterates over g, i is used in two for loops, n is used for ADDn and SUBTRACTn
while(x<m){
char *f=g[x++], l=*f, *a=g[x++], *b=g[f[1]&2? x++:x]; // f is the function, l is the first character thereof, a is the first operand, b is the second operand. Increment x if required.
if (l==68) { // DIVIDE
for(i=0; i<8; i++) putchar(a[i%4]); // Print first four characters twice
printf(" and "); // Print " and "
for(i=0; i<8; i++) putchar(a[i|4]); // Print second four characters twice
} else for(i=0; i<8; i++)
putchar(l&8? (i<4? a:b)[i&2? i|4:i%4]: // INTERSECT
l&4? i<4? a[i+4]:b[i-4]: // UNION
l&2? (n=f[8]-48, a[i+n<8? i+n:i]): // SUBTRACTn
(n=f[3]-48, a[i<n? i:i-n])); // ADDn
putchar(10); // Print a newline
}
}
@jackie-scholl
Copy link
Author

ACSL #2 codegolfing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment