August 23, 2024
P41 - A list of Goldbach compositions.
Given a range of integers by its lower and upper limit, print a list of all even numbers and their Goldbach composition.
> p41:printGoldbachList(9, 20).
10 = 3 + 7
12 = 1 + 11
14 = 1 + 13
16 = 3 + 13
18 = 1 + 17
20 = 1 + 19
erlang
%A list of Goldbach compositions.
-module(p41).
-export([printGoldbachList/2]).
printGoldbachList(St, End) ->
Ls = lists:seq(St, End),
Even = lists:filter(fun(X) -> X rem 2 == 0 end, Ls),
lists:foreach(fun(X) ->
{H1, H2} = p40:goldbach(X),
io:format("~w = ~w + ~w~n", [X, H1, H2])
end,Even).