aoc-2015/jour14/troupeau.m

60 lines
1.4 KiB
Mathematica
Raw Permalink Normal View History

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