Following the ancient ioccc.org tradition, I thought this would be a fun thing to try in Jow Forums. For those of you who may not be familiar with it, the ioccc consists in writing the most obscure/obfuscated C code possible. To change it up a bit, I decided to make it the following way: A task will be given (i.e print the time) and you have to obfuscate that, so that we can compare results and see who is the most original.
A comment: This is NOT a code golf (making the shortest code possible), although that is also welcome if it obfuscates the code.
RULES: Submitted code must be made in C99 or earlier versions of the language Submitted code MUST COMPILE with gcc file.c Submitted code can have warnings of any kind as long as it compiles The program CAN CRASH if the appropriate input arguments are not supplied Code must succesfully perform the task in hand (obviously) Code must be under 4096 bytes (Jow Forums post limit reasons) Code must not use Windows-specific headers (#include ) Macros are ALLOWED
THE TASK: Make a program that checks whether two given strings (via CLI ARGUMENTS) are an anagram (two words have the EXACT SAME letters in different order), and prints whether its an anagram or not via stdout. Example: restful - fluster: anagram funeral - real fun: NOT anagram (second word has a space) forty five - over fifty: anagram
Example program (output doesnt have to be exactly like this): $./ana restful fluster anagram: yes
#include #include #define z while #define y for int main(int argc, char **argv) { int c = 0; int d[26] = {0}; int e[26] = {0}; z (argv[1][c] != '\0') { d[argv[1][c]-'a']++; c++; } c = 0; z (argv[2][c] != '\0') { e[argv[2][c]-'a']++; c++; } y (c = 0; c < 26; c++) { if (d[c] != e[c]) { puts("anagrams.\n"); _Exit(0); } } puts("not anagrams.\n"); _Exit(0); }
Jason Baker
not work :(
Ethan Sanders
just ascii?
Elijah Jackson
yeah, otherwise c-strings wouldn't work as arguments
Easton Davis
like i don't have anything better to do enjoy your dead thread op
Ian James
I gave up because it's starting to get tedious and boring but here is a partial solution. All that's left to do is to sum the results at *b to see if it's zero so it knows whether to branch to x or y.
Well, color me retarded. I jumped the gun, thinking this was just an obfuscated C general. Completely missed the prompt.
Gavin Evans
its okay :) thats a nice hello world lol
Robert Nelson
>tfw not at home and can't join now Wait for me guys
Angel Gray
Bumping so this doesn't die while I obfuscate the shit out of a 10-line file.
Ayden Morgan
now do fizzbuzz
Thomas Wright
rate #include #define i int #define c char void main(i _,c*__[]) { i m[]={33752327,185405715,387784485,690695989,993870663,1229935449,1634035563}; c*d=(c*)m;i a=1,b=1,e=0;while(1[__][e]&&2[__][e]){a*=d[(e[__[1]]|0x20)-0x61]; b*=d[(__[2][e++]|0x20)-0x61];}putchar(!(a-b)+48); }
bonus points: case insensitive
Chase Baker
awesome, best one by far
Adrian Perry
>void main 0/10
Justin Richardson
still dont understand how this works after 10 mins lol, here's a more readable version:
void main(int argc,char*argv[]) { int m[]={33752327,185405715,387784485,690695989,993870663,1229935449,1634035563}; char* d = (char*)m; int a=1,b=1,e=0;
while(argv[1][e] && argv[2][e]) { a *= d[(argv[1][e] | 0x20)-0x61]; b *= d[(argv[2][e] | 0x20)-0x61]; e++; } putchar(!(a-b)+48); }
btw, I think the program fails with different lengths. ex: ./ana ana naan gives 1
Isaac Butler
This, except I'm phoneposting from bed
Samuel Clark
ok I understand now lol, you set the bit corresponing to the case in ascii and then you subtract the index, and multiply it by a unique number in the array (7 ints = 7 * 4 = 28) and because mult is commutative you check the result being the same at the end
Michael Nguyen
You don’t need to bump in Jow Forums
Isaiah Jenkins
Not just unique numbers, but prime numbers. Fundamental theorem of arithmetic states that a product of primes gets you a unique number that's only divisible into those prime numbers. And thanks to the conmutative property, we can multiply these numbers in any order. So two words having the same letters in any order will always produce the same number.
Brandon Lopez
>first year comp sci busy work project nypa
Xavier Cook
Bump
Alexander Sanchez
Not the task given, but: pastebin.com/c6uUsCzx Here's the funny part: It wasn't meant to be obfuscated. It's shitty code I wrote ages ago as a beginner.