Should I be writing about Erlang?

12:21 am Erlang, Programming, Tutorials

I’m becoming ever more convinced that the answer is yes. I’ve been playing, a bit, a game called Project Euler, a game for programmers wherein the object is to find solutions to deceptively simple problems. It’s surprisingly entertaining, and your score is a result of the function of programmers which have not succeeded in a task.

There are people who take long roundabout approaches to get to results like these, when instead they could be doing things like

p1() -> lists:sum(

    [ X || X <- lists:seq(1,10),

      ((X rem 3) == 0) orelse ((X rem 5) == 0) ]

).

As a result, I’m starting to think that I need to start explaining things. Anyone agree or disagree?

7 Responses

  1. MachinShin Says:

    I agree 155.25471%.
    you should write those tutorials you keep saying you’ll write too.

    –vat

  2. stonecypher Says:

    I’ve written several already. You’ve even read a few.

  3. Gokul Nair Says:

    how about this O(1) instead?

    x = int((10-1)/3);
    y = int((10-1)/5);
    z = int((10-1)/lcm(3, 5));

    (
    (3 * (x * (x+1)/2)) +
    (5 * (y * (y+1)/2))
    ) -
    (lcm(3, 5) * (z * (z+1)/2))

  4. Gokul Nair Says:

    Ofcourse, you can substitute any number instead of the 10 above. Like 1000, for instance, as noted in the original problem.

  5. John Haugeland Says:

    Uh. That doesn’t generate a list of numbers at all, and I don’t think there’s a way to implement lowest common multiple which is less than o(lg n), assuming that’s what lcm() is meant to be.

    So, … unless I’m missing something, fail.

  6. Gokul Nair Says:

    You are definitely missing the most important point here, i.e. the problem in Project Euler requires you to output the sum of the numbers generated and not the numbers itself. Please read the question first: http://projecteuler.net/

  7. Gokul Nair Says:

    Let me list it out for you:

    “If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.”

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.