Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement all tasks from 1 assignment #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "7422266F-657A-4924-A1CA-158561499E67"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ios.stage-task1.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
12 changes: 11 additions & 1 deletion Objc_Task1/ios.stage-task1/Exercises/Exercise-1/OddNumbers.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
@implementation OddNumbers

- (NSInteger)oddNumbers:(NSArray <NSNumber *> *)array {
return -1;
NSInteger counter = 0;

for(int i = 0; i < [array count]; i++)
{
if(array[i].integerValue % 2 == 1)
{
counter++;
}
}

return counter;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
@implementation NSString (ValidNumber)

- (BOOL)isValidNumber {
return false;
BOOL isValid = false;

if([self length] > 0 && [self length] <= 100)
{
for(int i = 0; i < [self length]; i++)
{
char ch = [self characterAtIndex: i];
if(ch < '0' || ch > '9')
return false;
}

isValid = true;
}
return isValid;
}

@end
Original file line number Diff line number Diff line change
@@ -1,9 +1,94 @@
#import "NSArray+MinRotated.h"
#import <math.h>

@implementation NSArray (MinRotated)

-(int)minElement
{
NSNumber *min = [self objectAtIndex:0];
int minIdx = 0;
for(int j = 0; j < [self count]; j++)
{
if([[self objectAtIndex: j] intValue] < [min intValue])
{
min = [self objectAtIndex: j];
minIdx = j;
}
}

return minIdx;
}

-(int)findPivot
{
int start = 0;
int end = [self count] - 1;

if([[self objectAtIndex:0]intValue] <= [[self objectAtIndex: end]intValue])
{
return 0;
}

while (start <= end)
{
int mid = (start + end) / 2;

if([[self objectAtIndex: mid] intValue] > [[self objectAtIndex: mid + 1] intValue]){
return mid + 1;
}
else if([[self objectAtIndex: start] intValue] <= [[self objectAtIndex: mid] intValue])
{
start = mid + 1;
}
else
{
end = mid - 1;
}
}

return 0;
}

- (NSNumber *)minRotated {
return nil;
NSMutableArray *main = [NSMutableArray array];
NSMutableArray *arr = [NSMutableArray array];
NSMutableArray *rotation = [NSMutableArray array];

main = [NSMutableArray arrayWithArray:[self sortedArrayUsingSelector:@selector(compare:)]];

for(int i = 0; i < [main count]; i++)
{
NSNumber *temp = [main objectAtIndex: i];
if([temp intValue] < 0)
{
while ([temp intValue] != 0) {
[arr addObject: @(abs(temp.intValue % 10))];
temp = @(([temp intValue]) / 10);
}
NSNumber *num = [arr objectAtIndex: [arr count] - 1];
[arr replaceObjectAtIndex: [arr count] - 1 withObject:@(-[num intValue])];
}
else
{
while ([temp intValue] != 0) {
[arr addObject: @(temp.intValue % 10)];
temp = @([temp intValue] / 10);
}
}


arr = [NSMutableArray arrayWithArray: [[arr reverseObjectEnumerator] allObjects]];

[rotation addObject:@([arr findPivot])];
[arr removeAllObjects];
}

NSNumber *res = nil;
if([rotation count] != 0)
{
res = [main objectAtIndex: [rotation minElement]];
}
return res;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
@implementation NumberConverter

- (NSArray *)numberConverter:(NSNumber *)number {
return nil;
NSMutableArray *array = [NSMutableArray array];

while ([number intValue] != 0) {
[array addObject:@(abs([number intValue] % 10))];
number = @([number intValue] / 10);
}

NSMutableArray *res = [NSMutableArray array];

for(int i = 0; i < [array count]; i++)
{
[res addObject:[[array objectAtIndex:i] stringValue]];
}

return res;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,41 @@ @implementation LeaderBoardTracker

- (NSArray <NSNumber *> *)trackLeaderBoard:(NSArray <NSNumber *> *)rankedArray
playerArray:(NSArray <NSNumber *> *)playerArray {
return @[];

NSMutableArray<NSNumber *> *positions = [NSMutableArray array];

if([playerArray count] != 0){
if([rankedArray count] != 0)
{
for(int i = 0; i < [playerArray count]; i++)
{
int pos = 1;
for(int j = 0; j < [rankedArray count]; j++)
{
if([[rankedArray objectAtIndex:j] intValue] == [[playerArray objectAtIndex:i] intValue] || [[rankedArray objectAtIndex:j] intValue] < [[playerArray objectAtIndex:i] intValue])
{
[positions addObject:@(pos)];
break;
}
if( j == [rankedArray count] - 1)
{
[positions addObject:@(pos + 1)];
break;
}
if(j != [rankedArray count] - 1 && [[rankedArray objectAtIndex:j] intValue] != [[rankedArray objectAtIndex:j + 1] intValue]){
pos++;
}
}
}
}
else{
for(int i = 0; i < [playerArray count]; i++){
[positions addObject:@(1)];
}
}
}

return positions;
}

@end