Algorithm that decides whether collection of primes exists which satisfies 3 equations Suppose someone gives you a list of $n$ positive numbers $(a_1, \ldots , a_n)$, together with an upper limit $N$ and asks you to find prime numbers $p_1, \ldots ,p_n$ in the range $2, \ldots , N$ satisfying
$p_2 = p_1 + a_1$ and $p_3 = p_2 + a_2$ ... and ... $p_n = p_{n-1} + a_{n-1}$
How do you write down a general algorithm for deciding whether or not collection of prime numbers $(p_1, \ldots , p_n)$ exists that satisfies these 3 equations?
What will it look like?

Here is some pseudo-code for my brutish approach to it.    
Let A = {a1, a2, ..., an}
Let sieve = {p | p is prime and less than N}
If ((size of sieve < size of A) OR (some a[i] == 1 for i > 1))
    return False;
Let primeDiffs = {sieve[i] - sieve[i-1] | i in [2..(size of sieve)]}
For i in [1..(size of primeDiffs - size of A)] {
    For j in [1..(size of A)] {
        If(A[j] /= primeDiffs[i+j])
            continue
    }
    return True
}
return False

Essentially just generate all the primes that you need, build the set of the consecutive differences of those primes, and iterate over that set seeing if all of your set $\{a_1, a_2, \dotsc, a_n\}$ matches your current position in the set of differences.
You can do some clever checking on the $\{a_1, a_2, \dotsc, a_n\}$ set at the start like make sure none of $\{a_2, a_3 \dotsc, a_n\}$ are $1$ (the only primes with a difference of $1$ are $2$ and $3$).
