|
Joined: 26 Oct 2007
Posts: 2
|
Hi,
I've just started learn erlang and after reading a large chunk of programming erlang I've started working on a few little puzzle programs from the facebook jobs page to get more familiar with the language.
(Warning my code is probably bad, I just started yesterday)
The following bit of code when given the following list
["ANDROMEDA","BARBARA","CAMERON","DAGMAR","EKATERINA","FLANNERY","GREGORY","HAMILTON","ISABELLA","JEBEDIAH","KIMBERLEY","LARISSA","MEREDITH","NORMAN","OSWALD","PENELOPE","QUENTIN","RANDALL","SAVANNAH","TABITHA","URSULA","VIVIENNE","WINONA","XAVIER","YVONNE","ZENOBIA"]
returns
Code:
[[9,"AOEA",4,[[3,2]]],
[7,"AAA",3,[[3,2]]],
[7,"AEO",3,[[3,2]]],
[6,"AA",2,[[3,2]]],
[9,"EAEIA",5,[[3,2]]],
[8,"AE",2,[[3,2]]],
[7,"EO",2,[[3,2]]],
[8,"AIO",3,[[3,2]]],
[8,"IAEA",4,[[3,2]]],
[8,"EEIA",4,[[3,2]]],
[9,"IEE",3,[[3,2]]],
[7,"AIA",3,[[3,2]]],
[8,"EEI",3,[[3,2]]],
[6,"OA",2,[[3,2]]],
[6,"OA",2,[[3,2]]],
[8,"EEOE",4,[[3,2]]],
[7,"UEI",3,[[3,2]]],
[7,"AA",2,[[3,2]]],
[8,"AAA",3,[[3,2]]],
[7,"AIA",3,[[3,2]]],
[6,"UUA",3,[[3,2]]],
[8,"IIEE",4,[[3,2]]],
[6,"IOA",3,[[3|...]]],
[6,"AIE",3,[[...]]],
[6,"OE",2,[...]],
[7,"EOIA",4|...]]
Notice the [...] starting at the end? I'm not sure whats causing this and was hoping someone could help.
heres the code.
Code:
-module(puzzle_11).
-export([test/1,get_lens/1,is_prime/1]).
-import(lib_misc, [pmap/2]).
-import(string, [len/1]).
test(L) ->
J = lists:map(fun(X) -> get_lens(X) end, L),
J.
get_lens(L) ->
A = len(L),
A2 = A div 2,
B = lists:filter(fun(X) -> lists:member(X,"AEIOU") end, L),
C = len(B),
D = primes_acc(lists:seq(1,A2)),
[A,B,C,D].
primes_acc(N) ->
primes_acc(N,[]).
primes_acc([H|T], Primes) ->
case is_prime(H) of
true -> primes_acc(T, [H|Primes]);
false -> primes_acc(T, Primes)
end;
primes_acc([],Primes) ->
[Primes].
is_prime(N) when N < 2 -> false;
is_prime(N) when N == 2; N == 3 -> true;
is_prime(N) ->
lists:all(fun(A) -> N rem A =/= 0 end, lists:seq(2, N div 2)).
|
|
|