-
Notifications
You must be signed in to change notification settings - Fork 3
/
problem27.erl
38 lines (33 loc) · 923 Bytes
/
problem27.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-module(problem27).
-export([problem27/0]).
-include_lib("eunit/include/eunit.hrl").
-import(euler_helper,[prime/1]).
problem27() ->
List = [{num_quad_primes(A,B),A,B} || A <- lists:seq(-999,999), B <- lists:seq(-999,999), num_quad_primes(A,B) > 0],
{FN, FA, FB} = lists:foldl(
fun({N,A,B},{NMax,AMax,BMax}) ->
if
N > NMax -> {N,A,B};
true ->
{NMax,AMax,BMax}
end
end,
{-1,error,error},
List),
{FN,FA*FB}.
num_quad_primes(A,B) ->
num_quad_primes(0,A,B).
num_quad_primes(N,A,B) ->
IsPrime = prime(N*N + A*N +B),
if
IsPrime ->
num_quad_primes(N+1,A,B);
true ->
N
end.
%% tests
num_quad_primes_test_() ->
[
?_assertEqual(40,num_quad_primes(1,41)),
?_assertEqual(80,num_quad_primes(-79,1601))
].