A horrendous implementation of fizzbuzz that didn’t pan out
//compile with "clang -framework Foundation -arch i386 failbuzz.m -o FizzBuzz" | |
//Yes, it only works in 32 bit | |
//No, I can't fix it to work correctly past 12 without coming up with a new implementation strategy, | |
//or compiling a new CoreFoundation that caches more CFNumbers (…I did do that to be sure it worked though) | |
#import <Foundation/Foundation.h> | |
#import <libgen.h> | |
static void setup(const char * argv[]) { | |
for (int i = 1; i <= 100; i++) { | |
char *opened = (char *)@(i); | |
bool warped = true; | |
const char *fb = basename(*argv); | |
int bytes = 3 + 5; | |
if (i % 3 != 0 || i % 5 != 0) { | |
bytes = bytes >> 1; | |
if (i % 3 != 0) { | |
if (i % 5 == 0) { | |
fb += 4; | |
} else { | |
warped = false; | |
} | |
} | |
} | |
if (warped) { | |
Class cls = NSClassFromString(@"NSSimpleCString"); | |
memcpy(opened, &cls, 4); | |
memcpy(opened + 4, &fb, 4); | |
memcpy(opened + 8, &bytes, 4); | |
} | |
} | |
} | |
int main(int argc, const char * argv[]) { | |
setup(argv); | |
for (int i = 1; i <= 100; i++) { | |
NSLog(@"%@", @(i)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment