package com.racesoft.codeeval;

import com.racesoft.codeeval.util.NumericUtils;

import java.util.stream.IntStream;

/**
 * Sum of primes ( https://www.codeeval.com/open_challenges/4/ )
 *
 * <b>Note:</b> whilst this Java 8 solution works, Code Eval supports only Java 7 for now
 *
 * @author Silviu BURCEA (silviuburceadev@gmail.com)
 *
 * @since 0.0.1
 * @version 0.0.1
 */
public class SumOfPrimes {

    public long solve(long limit) {
        return IntStream.iterate(2, i -> i + 1)
                .filter(NumericUtils::isPrime)
                .limit(limit)
                .sum();
    }

    public static void main(String[] args) {
        System.out.println(new SumOfPrimes().solve(1000));
    }
}
