This file contains 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
//Draws a Cartesian Coordinate system and graphs an equation on it. | |
//Equation comes from GraphViewController (data source) | |
- (void)drawRect:(CGRect)rect | |
{ | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGPoint midPoint; //center in coordinate system | |
midPoint.x = self.bounds.origin.x + self.bounds.size.width/2; | |
midPoint.y = self.bounds.origin.y + self.bounds.size.height/2; | |
This file contains 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)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
{ | |
if ([segue.identifier isEqualToString:@"graph"]) { | |
[segue.destinationViewController setGraphStack:[self.brain program]]; | |
} | |
} |
This file contains 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
@class GraphView; | |
@protocol GraphViewDataSource | |
- (float)deltaY:(GraphView *)sender; | |
@end | |
@interface GraphView : UIView | |
@property (nonatomic) CGFloat xValue; | |
@property (nonatomic, weak) IBOutlet id <GraphViewDataSource> dataSource; |
This file contains 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
@interface GraphViewController() <GraphViewDataSource> | |
@property (nonatomic, weak) IBOutlet GraphView *graphView; | |
@end |
This file contains 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
- (float)deltaY:(GraphView *)sender | |
{ | |
float xVar = sender.xValue; | |
id xVar2 = [NSNumber numberWithFloat:xVar]; | |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; | |
[dict setValue:xVar2 forKey: @"x"]; | |
float result = [CalculatorBrain runProgram:self.graphStack usingVariableValues:dict]; |
This file contains 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
//Iterates through program, an array of operations and NSNumbers | |
//Returns human-readable list of numbers and operations in RPN | |
+ (NSString *)descriptionOfProgram:(id)program | |
{ | |
NSString *description = [[NSString alloc] init]; | |
if ([program isKindOfClass:[NSArray class]]) { | |
for (int i=0; i<[program count]; i++) { | |
if ([[program objectAtIndex:i] isKindOfClass:[NSNumber class]]) { |
This file contains 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
+ (BOOL)isOperation:(NSString *)argument | |
{ | |
NSSet *operations = [NSSet setWithObjects:@"+",@"-",@"/",@"*",@"sin",@"cos",@"sqrt",@"pi",nil]; | |
if ([operations containsObject:argument]) | |
return YES; | |
else | |
return NO; | |
} | |
//Converts variables in program to their double value |
This file contains 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)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
self.title = _photoName; | |
_imageView.image = _image; | |
_imageView.frame = (CGRect){CGPointZero, _imageView.image.size}; | |
_scroller.contentSize = _imageView.image.size; | |
_scroller.minimumZoomScale = .3; |
This file contains 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
# ---------- | |
# User Instructions: | |
# | |
# Define a function, search() that takes no input | |
# and returns a list | |
# in the form of [optimal path length, x, y]. For | |
# the grid shown below, your function should output | |
# [11, 4, 5]. | |
# | |
# If there is no valid path from the start point |
This file contains 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
# ---------- | |
# User Instructions: | |
# | |
# Implement the function optimum_policy2D() below. | |
# | |
# You are given a car in a grid with initial state | |
# init = [x-position, y-position, orientation] | |
# where x/y-position is its position in a given | |
# grid and orientation is 0-3 corresponding to 'up', | |
# 'left', 'down' or 'right'. |
OlderNewer