AdventOfCode day14
<p>I am trying to solve Day14 of Advent of code and I am getting 2660 instead of the 2640. What am I doing wrong? I have looked at other solutions and it seems like they are following the same approach. <a href="http://adventofcode.com/day/14" rel="nofollow">http://adventofcode.com/day/14</a></p>

<pre><code>     - (void)day14:(NSArray *)inputs
{
    NSMutableDictionary *reindeerDictionary = [[NSMutableDictionary alloc] init];
    NSError *error = nil;

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\w*) can fly (\\d*) km/s for (\\d*) seconds, but then must rest for (\\d*) seconds." options:0 error:&amp;error];
    NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
    f.numberStyle = NSNumberFormatterDecimalStyle;

    if(error) {
        NSLog(@"Error in regex formatting:%@", error);
    }

    for (NSString *input in inputs)
    {
        NSArray *matches = [regex matchesInString:input options:0 range:NSMakeRange(0,input.length)];
        for (NSTextCheckingResult *result in matches) {
            NSMutableDictionary *reindeer = [[NSMutableDictionary alloc] init];
            reindeer[@"speed"] = [f numberFromString:[input substringWithRange:[result rangeAtIndex:2]]];
            reindeer[@"flyTime"] = [f numberFromString:[input substringWithRange:[result rangeAtIndex:3]]];
            reindeer[@"restTime"] = [f numberFromString:[input substringWithRange:[result rangeAtIndex:4]]];
            reindeer[@"points"] = @0;
            reindeerDictionary[[input substringWithRange:[result rangeAtIndex:1]]] = reindeer;
        }
    }

    int maxSeconds = 1000;
    NSNumber *maxDistanceFlown = @0;


    for (int i = 0; i &lt;= maxSeconds; i++) {
        for (NSString *reindeerName in reindeerDictionary.allKeys) {
            NSMutableDictionary *reindeer = reindeerDictionary[reindeerName];

            NSNumber *speed = reindeer[@"speed"];
            NSNumber *flyingPeriod = reindeer[@"flyTime"];
            NSNumber *restPeriod = reindeer[@"restTime"];
            int distanceFlown = [reindeer[@"distanceFlown"] intValue];
            int relativeSeconds = i % (restPeriod.intValue + flyingPeriod.intValue);

            //Check if going at full speed vs rest
            if (relativeSeconds &lt; flyingPeriod.intValue) {
                distanceFlown += speed.intValue;
                reindeer[@"distanceFlown"] = @(distanceFlown);

                NSNumber *distanceFlown = reindeer[@"distanceFlown"];
                if (distanceFlown &gt; maxDistanceFlown) {
                    maxDistanceFlown = distanceFlown;
                }
            }
        }
    }

    NSLog(@"Part 1: Winning Distance: %@\n",maxDistanceFlown);

}
</code></pre>