aoc-2015/jour14/troupeau.m

60 lines
1.4 KiB
Mathematica
Raw Normal View History

2021-03-26 16:53:45 +01:00
#import "troupeau.h"
#import "raindeer.h"
@implementation Troupeau
- (id) init
{
self = [super init];
if (self)
{
2021-03-29 16:26:13 +02:00
NSSortDescriptor *recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
ascending:NO];
recetteTriDistance = [NSArray arrayWithObject:recetteTri];
troupeau = [[NSMutableArray alloc] init];
2021-03-26 16:53:45 +01:00
}
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
{
2021-03-30 01:49:26 +02:00
while (time >= 0)
2021-03-26 16:53:45 +01:00
{
for (Raindeer *rd in troupeau)
2021-03-30 01:49:26 +02:00
[rd updateDistance];
2021-03-29 16:26:13 +02:00
[troupeau sortUsingDescriptors:recetteTriDistance];
[[troupeau firstObject] updatePoints];
2021-03-26 16:53:45 +01:00
time--;
}
2021-03-30 01:49:26 +02:00
NSSortDescriptor *descPoints = [[NSSortDescriptor alloc] initWithKey:@"points"
ascending:NO];
NSArray *tmp = [NSArray arrayWithObject:descPoints];
NSArray *sortedPoints = [troupeau sortedArrayUsingDescriptors:tmp];
return [[sortedPoints firstObject] points];
2021-03-26 16:53:45 +01:00
}
- (void) dealloc
{
[troupeau release];
[super dealloc];
}
@end