Erlang Mailing Lists

Author Message

<  Erlang  ~  Newbie problem

shawn
Posted: Fri Oct 26, 2007 6:51 pm Reply with quote
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)).
View user's profile Send private message
michal
Posted: Mon Oct 29, 2007 7:36 am Reply with quote
User Joined: 20 Jul 2006 Posts: 44 Location: London
Hi,
When a list is printed out in the Erlang shell it can happen that it is too long to fit the terminal, so to make a print out more readable, the [...] notation is used. It means that the list has more elements but only few first were printed out.

Michal

_________________
http://www.erlang-consulting.com
View user's profile Send private message
shawn
Posted: Mon Oct 29, 2007 4:07 pm Reply with quote
Joined: 26 Oct 2007 Posts: 2
Thank you Michal. That makes sense as it works fine for shorter lists.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum