1. Qiita
  2. 投稿
  3. Objective-C

ズンドコキヨシ with Objective-C

  • 3
    いいね
  • 0
    コメント

Objective-Cで書いてみた

    NSString *zun = @"ズン";
    NSString *doko = @"ドコ";
    NSArray *expected = @[zun,zun,zun,zun,doko];
    NSMutableArray *list = [NSMutableArray array];
    NSUInteger loc = 0;
    NSUInteger len = 0;

    while (![[list subarrayWithRange:NSMakeRange(loc, len)] isEqualToArray:expected]) {
        int val = arc4random_uniform(2);
        switch (val) {
            case 0:
                NSLog(@"%@",zun);
                [list addObject:zun];
                break;
            case 1:
                NSLog(@"%@",doko);
                [list addObject:doko];
            default:
                break;
        }

        len++;
        len = len > expected.count ? expected.count : len;
        loc = list.count > expected.count - 1 ? list.count - expected.count : 0;
    };

    NSLog(@"キ・ヨ・シ!");

こういうの書いてみるとSwiftの便利さが身に染みますね。。

Comments Loading...