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
70 changes: 66 additions & 4 deletions CaesarCipher/CaesarCipher/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
// main.m
// CaesarCipher
//
// Created by Michael Kavouras on 6/21/15.
// Created by Ayuna Vogel 🇷🇺🇺🇸 {{ in 💛 with 🚕 city }} on 6/21/15.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice emojis!

// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//


//we want to know if two distinct looking ciphers correspond to the same input message. Write a method called codeBreaker, which accepts two cipher strings as paramaters and returns a boolean value which tells us whether they are actually the same input message encoded using two different offsets. hint: the maximum offset is 25

#import <Foundation/Foundation.h>

@interface CaesarCipher : NSObject

- (NSString *)encode:(NSString *)string offset:(int)offset;
- (NSString *)decode:(NSString *)string offset:(int)offset;
- (BOOL)codeBreaker:(NSString *)message1 sameAs:(NSString *)message2;

@end


@implementation CaesarCipher

- (NSString *)encode:(NSString *)string offset:(int)offset {
Expand Down Expand Up @@ -50,11 +52,71 @@ - (NSString *)decode:(NSString *)string offset:(int)offset {
return [self encode:string offset: (26 - offset)];
}

- (BOOL)codeBreaker:(NSString *)message1 sameAs:(NSString *)message2 {
if (message1.length != message2.length) {
NSLog(@"These words are not same because they have different length.");
return NO;
}
else {
for (int i = 1; i < 25; i++) {
if ([message1 isEqualToString:[self encode:message2 offset:i]]) {
NSLog(@"The encoded strings represent the same word.");
return YES;
}
}
NSLog(@"These are different words of the same length.");
return NO;
}
return 0;
}

@end


int main(int argc, const char * argv[]) {
@autoreleasepool {

CaesarCipher *msgCipher = [[CaesarCipher alloc]init];

NSString *msg1 = @"new";
NSString *encodedString1 = [msgCipher encode:msg1 offset:5];
NSLog(@"First string encoded, cipher is %@", encodedString1);

NSString *decodedString1 = [msgCipher decode:encodedString1 offset:5];
NSLog(@"First string decoded, the word is %@", decodedString1);

NSLog(@"\n");

NSString *msg2 = @"york";
NSString *encodedString2 = [msgCipher encode:msg2 offset:18];
NSLog(@"Second string encoded, cipher is %@", encodedString2);

NSString *decodedString2 = [msgCipher decode:encodedString2 offset:18];
NSLog(@"Second string decoded, the word is %@", decodedString2);

NSLog(@"\n");

NSLog(@"Do the first and second ciphers represent the same word?");
BOOL inputsAreSame = [msgCipher codeBreaker:encodedString1 sameAs:encodedString2];
NSLog(@"\n");

NSString *msg3 = @"city";
NSString *encodedString3 = [msgCipher encode:msg3 offset:2];
NSLog(@"Third string encoded, the code is %@", encodedString3);
NSString *decodedString3 = [msgCipher decode:encodedString3 offset:2];
NSLog(@"Third string decoded, the word is %@", decodedString3);
NSLog(@"\n");
NSLog(@"Do the second and third ciphers represent the same word?");
BOOL inputsAreSame2 = [msgCipher codeBreaker:encodedString2 sameAs:encodedString3];
NSLog(@"\n");

NSString *msg4 = @"city";
NSString *encodedString4 = [msgCipher encode:msg4 offset:7];
NSLog(@"The code for the fourth encoded string is %@", encodedString4);
NSString *decodedString4 = [msgCipher decode:encodedString4 offset:7];
NSLog(@"Fourth string decoded, the word is %@", decodedString4);
NSLog(@"\n");
NSLog(@"Do third and fourth strings encode the same word?");
BOOL inputsAreSame3 = [msgCipher codeBreaker:encodedString3 sameAs:encodedString4];
}
}
}
43 changes: 42 additions & 1 deletion Election/Election/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// main.m
// Election
//
// Created by Michael Kavouras on 6/21/15.
// Created by Ayuna Vogel 🇷🇺🇺🇸 {{ in 💛 with 🚕 city }} on 6/21/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

Expand Down Expand Up @@ -198,14 +198,55 @@ - (BOOL)pollsOpen {
return answer != 0;
}

@end

// VotingSimulator class
@interface VotingSimulator : NSObject

-(void)simulate;

@end

@implementation VotingSimulator

-(void)simulate {
// Create an Election object, and give the Election a name
Election *iceCreamElection = [[Election alloc]init];
[iceCreamElection setElectionName:@"Choose the best ice cream flavor ever!"];

// Create a few Contender objects. Add these to the Election object. Make sure that the contender names are distinct!
Contender *chocoholic = [[Contender alloc]init];
Contender *political = [[Contender alloc]init];
Contender *boring = [[Contender alloc]init];

[chocoholic initWithName:@"Double chocolate chocolate chip with chocolate frosting please"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need to run initWithName AND init (line 218). You can just run

Contender *chocoholic = [[Contender alloc]  initWithName@"Double chocolate chocolate chip with chocolate frosting please"];

[political initWithName:@"Rainbow sherbet #lovewins"];
[boring initWithName:@"Fat free vanilla frozen yogurt"];

[iceCreamElection addContender:chocoholic];
[iceCreamElection addContender:political];
[iceCreamElection addContender:boring];

// Create a ElectionManager object. Ask it to manage the Election object created above.
ElectionManager *manager = [[ElectionManager alloc]init];
[manager manage:iceCreamElection];
// Ask the ElectionManager to initiatePolling
[manager initiatePolling];
// Follow the instructions on the console. After each round of polling you will be asked(within the console) whether you want to continue or not.
// Ask the ElectionManager to displayResults
[manager displayResults];

}

@end

int main(int argc, const char * argv[]) {
@autoreleasepool {

NSLog(@"Choose the best ice cream flavor ever!");
VotingSimulator *vSimulator = [[VotingSimulator alloc]init];
[vSimulator simulate];

}
return 0;
}
72 changes: 69 additions & 3 deletions Person/Person/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// main.m
// Person
//
// Created by Michael Kavouras on 6/21/15.
// Created by Ayuna Vogel 🇷🇺🇺🇸 {{ in 💛 with 🚕 city }} on 6/21/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

Expand All @@ -19,12 +19,23 @@ - (NSString *)city;
- (void)setPhoneNumber:(NSString *)phoneNumber;
- (NSString *)phoneNumber;

-(BOOL)checkSameCity:(Person *)otherPerson;

-(Person *)registerChild;

-(void)claimChild:(Person *)claimedChild;

-(void)setChild:(Person *)myNewChild;

-(Person *)child;

@end

@implementation Person {
NSString *_name;
NSString *_phoneNumber;
NSString *_city;
Person *_child;
}

- (void)setName:(NSString *)name {
Expand All @@ -51,13 +62,68 @@ - (NSString *)phoneNumber {
return _phoneNumber;
}

-(void)setChild:(Person *)myNewChild {
_child = myNewChild;
}

-(Person *)child {
return _child;
}

-(BOOL)checkSameCity:(Person *)otherPerson {
NSString *otherPersonCity = [otherPerson city];
BOOL isEqual = [_city isEqualToString:otherPersonCity];
return isEqual;
}

-(Person *)registerChild {
Person *child = [[Person alloc] init];
[child setCity:_city];
[child setPhoneNumber:_phoneNumber];
[child setName:@"Bob"];
return child;
}

-(void)claimChild:(Person *)claimedChild {
_child = claimedChild;
[claimedChild setCity:_city];
[claimedChild setPhoneNumber:_phoneNumber];
}
@end


int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");

Person *aPerson = [[Person alloc] init];
[aPerson setName:@"Mary"];
[aPerson setCity:@"New York"];
[aPerson setPhoneNumber:@"3333333333"];

Person *otherPerson = [[Person alloc] init];
[otherPerson setName:@"Kate"];
[otherPerson setCity:@"New Orleans"];

NSLog(@"Do Mary and Kate live in the same city? %d", [otherPerson checkSameCity:aPerson]);

Person *child = [aPerson registerChild];
NSLog(@"%@'s city is %@ and phone number is %@, same as Mary's", [child name], [child city], [child phoneNumber]);

// scenario: adoption. Orange is the New Black, season 3.
Person *biologicalMother = [[Person alloc] init];
[biologicalMother setName:@"Dayanara Diaz"];
[biologicalMother setCity:@"Litchfield"];
[biologicalMother setPhoneNumber:@"123"];
Person *newborn = [biologicalMother registerChild];
NSLog(@"Dayanara's baby's city is %@ and phone number is %@", [newborn city], [newborn phoneNumber]);

Person *adoptedMother = [[Person alloc] init];
[adoptedMother setName:@"Delia Mendez (Pornstache's mother)"];
[adoptedMother setCity:@"New York"];
[adoptedMother setPhoneNumber:@"456"];
[adoptedMother claimChild:newborn];
NSLog(@"After Daya's mother lied to Delia Mendez, Pornstache's mother, that the baby was born dead, Caesar pickes up Dayanara's newborn from the hospital. Caesar gets arrested at the end of Season 3 (sorry for spoiler alert!), and the child is taken by the authorities. What's going to happen to the baby? Hopefully, Delia will find the child (?), and the baby's new city will be %@ and the phone number will be %@. Can't wait for Season 4! They are filiming an episode right by my house on Tuesday!!", [newborn city], [newborn phoneNumber]);

}
return 0;
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
change to practice: type literally anything

### 1. Objective-C Classes

You are provided with a `Person` class. This class has private properties `name`, `phoneNumber` and `city`, along with their getter and setter methods.
Expand Down