Created
August 13, 2019 15:10
Star
You must be signed in to star a gist
おっぱいそんちくびんびん♪ (Objective-C) (GCC 7.4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
おっぱい.m (Objective-C traditional style) | |
2019/08/14: initial release | |
Ubuntu 18.04.2 LTS (Bionic Beaver) | |
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 | |
Copyright (C) 2017 Free Software Foundation, Inc. | |
gnustep 7.9 | |
gnustep-devel 7.9 | |
libobjc.so 4.0.0 | |
$ gcc おっぱい.m -o おっぱい `gnustep-config --base-libs` `gnustep-config --objc-flags` | |
Dedicated to shirasu | |
https://gist.github.com/8q/a5331c6ef8a205b32125 | |
*/ | |
#import <Foundation/Foundation.h> | |
static NSString * gs_realStr; | |
static NSArray * gs_oppaiElements; | |
void oppaiPrint(NSString *format, ...) { | |
va_list args; | |
va_start(args, format); | |
fputs([[[[NSString alloc] initWithFormat:format arguments:args] autorelease] UTF8String], stdout); | |
va_end(args); | |
} | |
NSNumber * oppaiRand() { | |
#if __APPLE__ | |
return [NSNumber numberWithInt:(int)arc4random_uniform(6)]; | |
#else | |
static int oppaiRandMax = RAND_MAX - (RAND_MAX % 6); | |
int r; | |
do { | |
r = random(); | |
} while (oppaiRandMax <= r); | |
return [NSNumber numberWithInt:(r % 6)]; | |
#endif | |
} | |
NSArray * makeOppaiNumList() { | |
NSMutableArray * numList = [NSMutableArray array]; | |
while ([numList count] < 6) { | |
NSNumber * n = oppaiRand(); | |
if (![numList containsObject:n]) { | |
[numList addObject:n]; | |
} | |
} | |
return numList; | |
} | |
NSString * makeOppaiStr() { | |
NSMutableString * oppaiString = [NSMutableString string]; | |
NSArray * oppaiNumList = makeOppaiNumList(); | |
for (id obj in oppaiNumList) { | |
[oppaiString appendString:[gs_oppaiElements objectAtIndex:[obj intValue]]]; | |
} | |
return oppaiString; | |
} | |
void congratulations(int count) { | |
oppaiPrint(@"おめでとうございます!\x20" | |
@"あなたは%d回目に%@しました。\n", count, gs_realStr | |
); | |
} | |
void mainLoop() { | |
int count = 0; | |
NSString * testString = [NSString string]; | |
do { | |
++count; | |
testString = makeOppaiStr(); | |
oppaiPrint(@"%d %@\n", count, testString); | |
} while (![testString isEqualToString:gs_realStr]); | |
congratulations(count); | |
} | |
int main() { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
gs_realStr = @"おっぱいそんちくびんびん"; | |
gs_oppaiElements = [NSArray arrayWithObjects:@"おっ", @"ぱい", @"そん", @"ちく", @"びん", @"びん", nil]; | |
#if !(__APPLE__) | |
srandom([[NSDate date] timeIntervalSinceReferenceDate]); | |
#endif | |
mainLoop(); | |
oppaiPrint(@"end\n"); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment