diff --git a/jour14/input b/jour14/input deleted file mode 100644 index 6cf5489..0000000 --- a/jour14/input +++ /dev/null @@ -1,9 +0,0 @@ -Dancer can fly 27 km/s for 5 seconds, but then must rest for 132 seconds. -Cupid can fly 22 km/s for 2 seconds, but then must rest for 41 seconds. -Rudolph can fly 11 km/s for 5 seconds, but then must rest for 48 seconds. -Donner can fly 28 km/s for 5 seconds, but then must rest for 134 seconds. -Dasher can fly 4 km/s for 16 seconds, but then must rest for 55 seconds. -Blitzen can fly 14 km/s for 3 seconds, but then must rest for 38 seconds. -Prancer can fly 3 km/s for 21 seconds, but then must rest for 40 seconds. -Comet can fly 18 km/s for 6 seconds, but then must rest for 103 seconds. -Vixen can fly 18 km/s for 5 seconds, but then must rest for 84 seconds. diff --git a/jour14/jour14.m b/jour14/jour14.m index f70231e..a2d52c1 100644 --- a/jour14/jour14.m +++ b/jour14/jour14.m @@ -1,5 +1,4 @@ #import "raindeer.h" -#import "troupeau.h" #import <Foundation/Foundation.h> int main() @@ -9,12 +8,10 @@ int main() NSString *path = @"input"; NSError *err; NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path - encoding:NSUTF8StringEncoding - error:&err]; - + encoding:NSUTF8StringEncoding + error:&err]; NSArray *lines = [contentFile componentsSeparatedByString:@"\n"]; NSMutableArray *listDeer = [[NSMutableArray alloc] init]; - Troupeau *troupeau = [[Troupeau alloc] init]; for (NSString *tmp in lines) { @@ -25,18 +22,24 @@ int main() zatSpeed:[[parsedSpace objectAtIndex:3] integerValue] boostTime:[[parsedSpace objectAtIndex:6] integerValue] LunchTime:[[parsedSpace objectAtIndex:13] integerValue]]; - [troupeau newDeer:rd]; + [listDeer addObject:rd]; } } - const int time = 2503; - NSLog(@"le résultat de la première sélection est : %d", [troupeau courseUne:time]); - NSLog(@"le résultat de la deuxième sélection est : %d", [troupeau courseDeux:time]); + int ret = 0; + int tmp = 0; + for (Raindeer *rd in listDeer) + { + tmp = [rd calculDistance:2503]; + if (tmp > ret) + ret = tmp; + [rd release]; + } + NSLog(@"le résultat est : %d", ret); //finir le main par ça [contentFile release]; [listDeer release]; - [troupeau dealloc]; [myPool drain]; return 0; } diff --git a/jour14/raindeer.h b/jour14/raindeer.h index 376ee97..103b76c 100644 --- a/jour14/raindeer.h +++ b/jour14/raindeer.h @@ -6,21 +6,14 @@ int speed; int boostTime; int pause; - int points; - - int cooldown; - int hypervitesse; - int distance; } // permet de générer des setters et getter selon des attributs // ici retain, nonatomic et assign @property (retain, nonatomic) NSString *name; -@property (assign) int speed, boostTime, pause, points, cooldown, hypervitesse, distance; +@property (assign) int speed, boostTime, pause; + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause; - (int) calculDistance:(int)time; -- (void) updateDistance; -- (void) updatePoints; @end diff --git a/jour14/raindeer.m b/jour14/raindeer.m index 105ae21..177475f 100644 --- a/jour14/raindeer.m +++ b/jour14/raindeer.m @@ -4,7 +4,7 @@ @implementation Raindeer // permet de créer les getters et setters à partir de property -@synthesize name, speed, boostTime, pause, points, cooldown, hypervitesse, distance; +@synthesize name, speed, boostTime, pause; + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)boostTime LunchTime:(int)pause { @@ -15,10 +15,6 @@ new.speed = speed; new.boostTime = boostTime; new.pause = pause; - new.points = 1; //pas sur que ce soit la bonne méthode mais chut - new.cooldown = 0; - new.hypervitesse = boostTime; - new.distance = 0; } return new; } @@ -35,28 +31,6 @@ return ret; } -- (void) updateDistance -{ - if (cooldown > 0) - { - cooldown--; - if (cooldown == 0) - hypervitesse = boostTime; - } - else - { - distance = distance + speed; - hypervitesse--; - if (hypervitesse == 0) - cooldown = pause; - } -} - -- (void) updatePoints -{ - points++; -} - - (void) dealloc { [name release]; diff --git a/jour14/troupeau.h b/jour14/troupeau.h deleted file mode 100644 index f29b54f..0000000 --- a/jour14/troupeau.h +++ /dev/null @@ -1,15 +0,0 @@ -#import "raindeer.h" -#import <Foundation/Foundation.h> - -@interface Troupeau : NSObject -{ - NSMutableArray *troupeau; - NSArray *recetteTriDistance; -} - -- (id) init; -- (void) newDeer:(Raindeer*)rd; -- (int) courseUne:(int)time; -- (int) courseDeux:(int)time; - -@end diff --git a/jour14/troupeau.m b/jour14/troupeau.m deleted file mode 100644 index fbad31e..0000000 --- a/jour14/troupeau.m +++ /dev/null @@ -1,59 +0,0 @@ -#import "troupeau.h" -#import "raindeer.h" - -@implementation Troupeau - -- (id) init -{ - self = [super init]; - if (self) - { - NSSortDescriptor *recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance" - ascending:NO]; - recetteTriDistance = [NSArray arrayWithObject:recetteTri]; - troupeau = [[NSMutableArray alloc] init]; - } - return self; -} - -- (void) newDeer:(Raindeer*)rd -{ - [troupeau addObject:rd]; -} - -- (int) courseUne:(int)time -{ - int ret = 0, tmp = 0; - for (Raindeer *rd in troupeau) - { - tmp = [rd calculDistance:time]; - if (tmp > ret) - ret = tmp; - } - return ret; -} - -- (int) courseDeux:(int)time -{ - while (time >= 0) - { - for (Raindeer *rd in troupeau) - [rd updateDistance]; - [troupeau sortUsingDescriptors:recetteTriDistance]; - [[troupeau firstObject] updatePoints]; - time--; - } - NSSortDescriptor *descPoints = [[NSSortDescriptor alloc] initWithKey:@"points" - ascending:NO]; - NSArray *tmp = [NSArray arrayWithObject:descPoints]; - NSArray *sortedPoints = [troupeau sortedArrayUsingDescriptors:tmp]; - return [[sortedPoints firstObject] points]; -} - -- (void) dealloc -{ - [troupeau release]; - [super dealloc]; -} - -@end