Compare commits
4 commits
7bff779701
...
1579b57608
Author | SHA1 | Date | |
---|---|---|---|
1579b57608 | |||
50bed585db | |||
e2c541d9fd | |||
8a8af36570 |
6 changed files with 128 additions and 15 deletions
9
jour14/input
Normal file
9
jour14/input
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
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.
|
|
@ -1,4 +1,5 @@
|
||||||
#import "raindeer.h"
|
#import "raindeer.h"
|
||||||
|
#import "troupeau.h"
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -8,10 +9,12 @@ int main()
|
||||||
NSString *path = @"input";
|
NSString *path = @"input";
|
||||||
NSError *err;
|
NSError *err;
|
||||||
NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path
|
NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path
|
||||||
encoding:NSUTF8StringEncoding
|
encoding:NSUTF8StringEncoding
|
||||||
error:&err];
|
error:&err];
|
||||||
|
|
||||||
NSArray *lines = [contentFile componentsSeparatedByString:@"\n"];
|
NSArray *lines = [contentFile componentsSeparatedByString:@"\n"];
|
||||||
NSMutableArray *listDeer = [[NSMutableArray alloc] init];
|
NSMutableArray *listDeer = [[NSMutableArray alloc] init];
|
||||||
|
Troupeau *troupeau = [[Troupeau alloc] init];
|
||||||
|
|
||||||
for (NSString *tmp in lines)
|
for (NSString *tmp in lines)
|
||||||
{
|
{
|
||||||
|
@ -22,24 +25,18 @@ int main()
|
||||||
zatSpeed:[[parsedSpace objectAtIndex:3] integerValue]
|
zatSpeed:[[parsedSpace objectAtIndex:3] integerValue]
|
||||||
boostTime:[[parsedSpace objectAtIndex:6] integerValue]
|
boostTime:[[parsedSpace objectAtIndex:6] integerValue]
|
||||||
LunchTime:[[parsedSpace objectAtIndex:13] integerValue]];
|
LunchTime:[[parsedSpace objectAtIndex:13] integerValue]];
|
||||||
[listDeer addObject:rd];
|
[troupeau newDeer:rd];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = 0;
|
const int time = 2503;
|
||||||
int tmp = 0;
|
NSLog(@"le résultat de la première sélection est : %d", [troupeau courseUne:time]);
|
||||||
for (Raindeer *rd in listDeer)
|
NSLog(@"le résultat de la deuxième sélection est : %d", [troupeau courseDeux:time]);
|
||||||
{
|
|
||||||
tmp = [rd calculDistance:2503];
|
|
||||||
if (tmp > ret)
|
|
||||||
ret = tmp;
|
|
||||||
[rd release];
|
|
||||||
}
|
|
||||||
NSLog(@"le résultat est : %d", ret);
|
|
||||||
|
|
||||||
//finir le main par ça
|
//finir le main par ça
|
||||||
[contentFile release];
|
[contentFile release];
|
||||||
[listDeer release];
|
[listDeer release];
|
||||||
|
[troupeau dealloc];
|
||||||
[myPool drain];
|
[myPool drain];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,21 @@
|
||||||
int speed;
|
int speed;
|
||||||
int boostTime;
|
int boostTime;
|
||||||
int pause;
|
int pause;
|
||||||
|
int points;
|
||||||
|
|
||||||
|
int cooldown;
|
||||||
|
int hypervitesse;
|
||||||
|
int distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// permet de générer des setters et getter selon des attributs
|
// permet de générer des setters et getter selon des attributs
|
||||||
// ici retain, nonatomic et assign
|
// ici retain, nonatomic et assign
|
||||||
@property (retain, nonatomic) NSString *name;
|
@property (retain, nonatomic) NSString *name;
|
||||||
@property (assign) int speed, boostTime, pause;
|
@property (assign) int speed, boostTime, pause, points, cooldown, hypervitesse, distance;
|
||||||
|
|
||||||
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause;
|
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause;
|
||||||
- (int) calculDistance:(int)time;
|
- (int) calculDistance:(int)time;
|
||||||
|
- (void) updateDistance;
|
||||||
|
- (void) updatePoints;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
@implementation Raindeer
|
@implementation Raindeer
|
||||||
|
|
||||||
// permet de créer les getters et setters à partir de property
|
// permet de créer les getters et setters à partir de property
|
||||||
@synthesize name, speed, boostTime, pause;
|
@synthesize name, speed, boostTime, pause, points, cooldown, hypervitesse, distance;
|
||||||
|
|
||||||
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)boostTime LunchTime:(int)pause
|
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)boostTime LunchTime:(int)pause
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,10 @@
|
||||||
new.speed = speed;
|
new.speed = speed;
|
||||||
new.boostTime = boostTime;
|
new.boostTime = boostTime;
|
||||||
new.pause = pause;
|
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;
|
return new;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +35,28 @@
|
||||||
return ret;
|
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
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[name release];
|
[name release];
|
||||||
|
|
15
jour14/troupeau.h
Normal file
15
jour14/troupeau.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#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
|
59
jour14/troupeau.m
Normal file
59
jour14/troupeau.m
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#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
|
Loading…
Add table
Reference in a new issue