Solution to Problem 24 in Erlang:
-module(e24).
-module(e24).
-on_load(e24/0).
fac(0) -> 1;
fac(N) -> N * fac(N - 1).
list_ref(0, [Head|_]) -> Head;
list_ref(X, [_|Tail]) -> list_ref(X - 1, Tail).
nthLP(N, P, Rem) ->
if
length(Rem) == 1 ->
P ++ Rem;
true ->
K = fac(9 - length(P)),
Elem = list_ref(trunc(N / K), Rem),
nthLP(N rem K, P ++ [Elem], Rem -- [Elem])
end.
e24() -> io:format("~B~B~B~B~B~B~B~B~B~B~n",
nthLP(999999, [], [0,1,2,3,4,5,6,7,8,9])).
Solution to Problem 39 in Python:
import math
sols = {}
for a in range(2,500):
for b in range(a, 500):
c2 = a ** 2 + b ** 2
c = int(math.sqrt(c2))
if c2 == c * c:
p = a + b + c
if p <= 1000:
if p in sols.keys():
sols[p] += 1
else:
sols[p] = 1
ans = 0
maxsols = 0
for p in sols.keys():
if maxsols < sols[p]:
ans = p
maxsols = sols[p]
print ans
No comments:
Post a Comment