Last active
January 29, 2017 05:28
-
-
Save keisukeYamagishi/60723b37db550ffa23b89e81a54a222b to your computer and use it in GitHub Desktop.
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
// | |
// SHIRandomArray.h | |
// logicObj_C | |
// | |
// Created by tomyAmi on 2015/02/08. | |
// Copyright (c) 2015年 tomyAmi. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface SHIRandomArray : NSObject | |
/** | |
* 投げた分の数字をランダムに並び替える | |
* | |
* @param number | |
*/ | |
-(NSArray *)randomArray:(NSArray *)array; | |
-(BOOL)judgementArrary:(NSArray*)ary; | |
-(NSMutableArray*)insertNumber:(NSInteger)number; | |
@end |
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
// | |
// SHIRandomArray.m | |
// logicObj_C | |
// | |
// Created by tomyAmi on 2015/02/08. | |
// Copyright (c) 2015年 tomyAmi. All rights reserved. | |
// | |
#import "SHIRandomArray.h" | |
@implementation SHIRandomArray | |
-(NSArray *)randomArray:(NSArray *)array{ | |
NSMutableArray* ary = array.mutableCopy; | |
for(NSInteger n = 0; n < array.count;n++){ | |
NSInteger random = arc4random() % array.count; | |
[ary exchangeObjectAtIndex:n withObjectAtIndex:random]; | |
} | |
return ary.mutableCopy; | |
} | |
/********************************************* | |
* | |
* TEST CODE | |
* | |
* | |
*/ | |
-(BOOL)judgementArrary:(NSArray*)ary{ | |
BOOL bo = NO; | |
for(NSInteger i=0;i<ary.count;i++){ | |
int count = 0; | |
for(NSInteger n = 0;n<ary.count;n++){ | |
if([ary[n]integerValue]==[ary[i]integerValue]){ | |
count++; | |
if(count==2){ | |
bo = YES; | |
} | |
} | |
} | |
} | |
if(bo==YES)NSLog(@"\n BUSTED \n"); | |
return bo; | |
} | |
-(NSMutableArray*)insertNumber:(NSInteger)number{ | |
NSMutableArray* array = [NSMutableArray array]; | |
for(NSInteger i = 0; i<number;i++){ | |
[array addObject:[NSNumber numberWithInteger:i]]; | |
} | |
return array; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
create random array