Skip to content

Instantly share code, notes, and snippets.

@Catfish-Man
Last active May 31, 2018 07:25
Show Gist options
  • Save Catfish-Man/40089da8e784ae38c27ee6ebe27c5ad1 to your computer and use it in GitHub Desktop.
Save Catfish-Man/40089da8e784ae38c27ee6ebe27c5ad1 to your computer and use it in GitHub Desktop.
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