Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Tasks/Task1/RSSchool_T1/RSSchool_T1.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@
TargetAttributes = {
BDBA864A22419F4D00AFC095 = {
CreatedOnToolsVersion = 10.1;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 0;
};
};
};
BDBA865C22419F4E00AFC095 = {
CreatedOnToolsVersion = 10.1;
Expand Down Expand Up @@ -489,14 +494,17 @@
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)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "RSSchool.RSSchool-T1";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -505,14 +513,17 @@
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)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "RSSchool.RSSchool-T1";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RSSchool_T1Tests/Encryption_Test.m"
timestampString = "575223578.9751641"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "8"
endingLineNumber = "8"
landmarkName = "Encryption_Test"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
10 changes: 9 additions & 1 deletion Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/1/SummArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 21 additions & 1 deletion Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/2/Diagonal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/3/Pangrams.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 34 additions & 1 deletion Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/4/Encryption.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
82 changes: 82 additions & 0 deletions Tasks/Task1/RSSchool_T1/RSSchool_T1/Exercises/5/Sorted.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down