diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.pbxproj b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.pbxproj index d279d27..b9370fc 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.pbxproj +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.pbxproj @@ -259,6 +259,11 @@ TargetAttributes = { BDBA864A22419F4D00AFC095 = { CreatedOnToolsVersion = 10.1; + SystemCapabilities = { + com.apple.BackgroundModes = { + enabled = 0; + }; + }; }; BDBA865C22419F4E00AFC095 = { CreatedOnToolsVersion = 10.1; @@ -489,7 +494,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 7FWE3GPY5W; INFOPLIST_FILE = RSSchool_T1/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -497,6 +504,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "RSSchool.RSSchool-T1"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -505,7 +513,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 7FWE3GPY5W; INFOPLIST_FILE = RSSchool_T1/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -513,6 +523,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "RSSchool.RSSchool-T1"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.xcworkspace/xcuserdata/yaroslav.xcuserdatad/UserInterfaceState.xcuserstate b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.xcworkspace/xcuserdata/yaroslav.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..ca4aeee Binary files /dev/null and b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.xcworkspace/xcuserdata/yaroslav.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/xcuserdata/yaroslav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/xcuserdata/yaroslav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..28d08c5 --- /dev/null +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/xcuserdata/yaroslav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/1/SummArray.m b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/1/SummArray.m index 0c4d86e..ae5cbce 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/1/SummArray.m +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/1/SummArray.m @@ -4,7 +4,15 @@ @implementation SummArray // Complete the summArray function below. - (NSNumber *)summArray:(NSArray *)array { - return @(0); + int summ = 0; + + for(NSNumber *numbers in array) { + summ += [numbers integerValue]; + } + + + + return @(summ); } @end diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/2/Diagonal.m b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/2/Diagonal.m index 2a23f76..304d059 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/2/Diagonal.m +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/2/Diagonal.m @@ -4,7 +4,27 @@ @implementation Diagonal // Complete the diagonalDifference function below. - (NSNumber *) diagonalDifference:(NSArray *)array { - return 0; + + int diagonalSumOne = 0; + int diagonaleSumTwo = 0; + int diagonalPositionOne = 0; + int diagonalPositionTwo = [array count] - 1; + + + for(NSString *str in array) { + NSArray *line = [str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + + diagonalSumOne += [line[diagonalPositionOne]intValue]; + diagonalPositionOne += 1; + + diagonaleSumTwo += [line[diagonalPositionTwo] integerValue]; + diagonalPositionTwo -= 1; + + + + } + + return @(abs(diagonalSumOne - diagonaleSumTwo)); } @end diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/3/Pangrams.m b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/3/Pangrams.m index a0b341a..778ef2e 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/3/Pangrams.m +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/3/Pangrams.m @@ -4,7 +4,15 @@ @implementation Pangrams // Complete the pangrams function below. - (BOOL)pangrams:(NSString *)string { - return NO; + NSArray *alphabetLetters = [@"a b c d e f g h j k l m n o p q r s t u v w x y z" componentsSeparatedByString:@" "]; + NSString *lowerCaseString = [[NSString alloc] initWithString:[[string stringByReplacingOccurrencesOfString:@" " withString:@""] lowercaseString]]; + + for (NSString *str in alphabetLetters) { + if ([lowerCaseString rangeOfString:str].location == NSNotFound) { + return NO; + } + } + return YES; } @end diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/4/Encryption.m b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/4/Encryption.m index 025be5d..866b248 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/4/Encryption.m +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/4/Encryption.m @@ -4,7 +4,40 @@ @implementation Encryption // Complete the encryption function below. - (NSString *)encryption:(NSString *)string { - return @""; + + double square = sqrt([string length]); + double sqrtValue = floor(square); + double ceilValue = ceil(square); + int rowCount = sqrtValue; + int columnCount = ceilValue; + + if(sqrtValue * ceilValue >= [string length]) { + rowCount = sqrtValue; + columnCount = ceilValue; + } else { + rowCount = ceilValue; + columnCount = ceilValue; + } + + NSMutableArray *array = [NSMutableArray array]; + + for(int i = 0; i < columnCount; i++) { + for(int k = 0; k < rowCount; k++) { + + int position = i + k * columnCount; + if(position >= [string length]) { + break; + } + + unichar item = [string characterAtIndex:position]; + [array addObject: [NSString stringWithFormat:@"%c", item]]; + } + if(i != columnCount - 1) { + [array addObject:@" "]; + } + } + + return [array componentsJoinedByString:@""]; } @end diff --git a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/5/Sorted.m b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/5/Sorted.m index 22c8828..ebc4ed6 100644 --- a/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/5/Sorted.m +++ b/Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/5/Sorted.m @@ -8,6 +8,88 @@ @implementation Sorted // Complete the sorted function below. - (ResultObject*)sorted:(NSString*)string { ResultObject *value = [ResultObject new]; + value.status = NO; + + NSArray *tempArray = [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSMutableArray *array = [tempArray mutableCopy]; + int arrayCount = [array count]; + + //get sorted array + NSArray* sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id n1, id n2) { + NSNumber *first = [NSNumber numberWithInteger:[n1 integerValue]]; + NSNumber *second = [NSNumber numberWithInteger:[n2 integerValue]]; + return [first compare:second]; + }]; + + if ([tempArray isEqualToArray:sortedArray]) { + value.status = YES; + return value; + } + + for (int i = arrayCount - 1; i > 0; i--) { + if ([array[i] integerValue] < [array[i - 1] integerValue]) { + //find element to swap + + int j = i - 1; + while (j >= 0 && [array[i] integerValue] < [array[j] integerValue]) { + j--; + } + + id temp = array[i]; + array[i] = array[j + 1]; + array[j + 1] = temp; + + if ([array isEqualToArray:sortedArray]) { + value.status = YES; + value.detail = [NSString stringWithFormat:@"swap %d %d", j+2, i+1]; + } + break; + } + } + + if (!(value.status)) { + //try to reverse + + // Finding the first mismatch. + int front; + int indexFront = 1; + for (front = 0; front < arrayCount; front++) + { + if ([sortedArray[front] integerValue]!= [tempArray[front] integerValue]) + { + //front contains first mistmatch index + indexFront += front; + break; + } + } + + // Finding the last mismatch. + int back; + int indexBack = 1; + for (back = arrayCount - 1; back >= 0; back--) + { + if ([sortedArray[back] integerValue] != [tempArray[back] integerValue]) + { + //back contains last mismatch + indexBack += back; + break; + } + } + + // Check if subarray is decreasing + do + { + front++; + if ([tempArray[front - 1] integerValue] < [tempArray[front] integerValue]) + { + return value; + } + } while (front != back); + + value.status = YES; + value.detail = [NSString stringWithFormat:@"reverse %d %d", indexFront, indexBack]; + return value; + } return value; }