Task




Find and display here on this page, the longest sequence of consecutive prime numbers where the differences between the primes are strictly ascending.


Do the same for sequences of primes where the differences are strictly descending.



In both cases, show the sequence for primes   <   1,000,000.



If there are multiple sequences of the same length, only the first need be shown.



F primes_upto(limit)
   V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
   L(n) 0 .< Int(limit ^ 0.5 + 1.5)
      I is_prime[n]
         L(i) (n * n .. limit).step(n)
            is_prime[i] = 0B
   R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)
 
V primelist = primes_upto(1'000'000)
 
V listlen = primelist.len
 
V pindex = 1
V old_diff = -1
V curr_list = [primelist[0]]
[Int] longest_list
 
L pindex < listlen
 
   V diff = primelist[pindex] - primelist[pindex - 1]
   I diff > old_diff
      curr_list.append(primelist[pindex])
      I curr_list.len > longest_list.len
         longest_list = curr_list
   E
      curr_list = [primelist[pindex - 1], primelist[pindex]]
 
   old_diff = diff
   pindex++
 
print(longest_list)
 
pindex = 1
old_diff = -1
curr_list = [primelist[0]]
longest_list.drop()
 
L pindex < listlen
 
   V diff = primelist[pindex] - primelist[pindex - 1]
   I diff < old_diff
      curr_list.append(primelist[pindex])
      I curr_list.len > longest_list.len
         longest_list = curr_list
   E
      curr_list = [primelist[pindex - 1], primelist[pindex]]
 
   old_diff = diff
   pindex++
 
print(longest_list)