This file contains hidden or 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
| def fibonacci(n): | |
| if n <= 2: | |
| return 1 | |
| elif n <= 0: | |
| return 0 | |
| if n % 2 == 0: | |
| x = n/2 | |
| return fibonacci(x) * (fibonacci(x + 1) + fibonacci(x - 1)) | |
| else: |
This file contains hidden or 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
| def quicksort(array): | |
| if len(array) <= 1: | |
| return array | |
| less = [] | |
| more = [] | |
| equal = [] | |
| pivot = array[len(array)/2] | |
| for x in array: | |
| if x < pivot: | |
| less.append(x) |
This file contains hidden or 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
| - (void)test { | |
| NSArray *test = @[@"ASDASD", @"BAQWEQWE", @"ASDQWEQEW", @"RTYTYERTRWEEWR", @"NBVBCVVA"]; | |
| for (unichar i = 'a'; i <= 'z' ; i++) { | |
| NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(NSString *evaluatedObject, NSDictionary *bindings) { | |
| return tolower([evaluatedObject characterAtIndex:0]) == i; | |
| }]; | |
| NSArray *filteredArray = [test filteredArrayUsingPredicate:filterPredicate]; | |
| } | |
| } |
This file contains hidden or 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
| array = [1,2,3] | |
| for x in range(len(array)-1): | |
| indexToSwap = x | |
| for y in range(x+1, len(array)): | |
| if array[indexToSwap] > array[y]: | |
| indexToSwap = y | |
| array[x], array[indexToSwap] = array[indexToSwap], array[x] | |
| print array |
NewerOlder