Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12266 > unrolled thread

sample scripts for solving euler problems

Started byscripts examples <example.scripts@gmail.com>
First post2012-02-28 20:02 -0800
Last post2012-03-02 17:40 +0100
Articles 5 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  sample scripts for solving euler problems scripts examples <example.scripts@gmail.com> - 2012-02-28 20:02 -0800
    Re: sample scripts for solving euler problems scripts examples <example.scripts@gmail.com> - 2012-02-29 18:19 -0800
    Re: sample scripts for solving euler problems Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-03-01 21:44 +0000
    Re: sample scripts for solving euler problems Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-03-02 07:23 -0800
      Re: sample scripts for solving euler problems Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-02 17:40 +0100

#12266 — sample scripts for solving euler problems

Fromscripts examples <example.scripts@gmail.com>
Date2012-02-28 20:02 -0800
Subjectsample scripts for solving euler problems
Message-ID<496fa250-5efc-44f6-b88a-bca6dda08ec8@k4g2000yqa.googlegroups.com>
   Got a web site setup for solving euler problems in python, perl,
ruby and javascript.

   Feel free to give me any feedback, thanks.

[toc] | [next] | [standalone]


#12316

Fromscripts examples <example.scripts@gmail.com>
Date2012-02-29 18:19 -0800
Message-ID<40778fd6-ce2e-4d89-a152-8e6523f9b457@p21g2000yqm.googlegroups.com>
In reply to#12266
On Feb 28, 8:02 pm, scripts examples <example.scri...@gmail.com>
wrote:
>    Got a web site setup for solving euler problems in python, perl,
> ruby and javascript.
>
>    Feel free to give me any feedback, thanks.

Sorry, forgot the link.  Here it is: examplescripts.weebly.com

[toc] | [prev] | [next] | [standalone]


#12334

FromDr J R Stockton <reply1209@merlyn.demon.co.uk>
Date2012-03-01 21:44 +0000
Message-ID<lvuWSlPN3+TPFwZh@invalid.uk.co.demon.merlyn.invalid>
In reply to#12266
In comp.lang.javascript message <496fa250-5efc-44f6-b88a-bca6dda08ec8@k4
g2000yqa.googlegroups.com>, Tue, 28 Feb 2012 20:02:20, scripts examples
<example.scripts@gmail.com> posted:

>   Got a web site setup for solving euler problems in python, perl,
>ruby and javascript.
>
>   Feel free to give me any feedback, thanks.


You need to describe more closely the particular class of problems,
although that might have been sufficiently obvious if you had given a
URL or even a real name - see sig. line 4.

-- 
(c) John Stockton, nr London UK.  ???@merlyn.demon.co.uk  Turnpike v6.05  MIME.
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
     Check boilerplate spelling -- error is a public sign of incompetence.
    Never fully trust an article from a poster who gives no full real name.

[toc] | [prev] | [next] | [standalone]


#12346

FromAsen Bozhilov <asen.bozhilov@gmail.com>
Date2012-03-02 07:23 -0800
Message-ID<13347583.271.1330701787117.JavaMail.geo-discussion-forums@yner4>
In reply to#12266
scripts examples написа:
> Got a web site setup for solving euler problems in python, perl,
> ruby and javascript.
> 
>    Feel free to give me any feedback, thanks.

I looked at Project Euler Problem 1. Obviously you can solve the problem with the formula of arithmetic progression sum: 

<URL: http://en.wikipedia.org/wiki/Arithmetic_progression> 

Even and without formula, you can solve it more elegant. The solution in Python is on a line: 

sum(range(3, 10, 3)) + sum(range(5, 10, 5)); #23
sum(range(3, 1000, 3)) + sum(range(5, 1000, 5)); #266333

JavaScript solution would be: 

function multiples(x) {
    var sum = 0, i;
    for (i = 3; i < x; i += 3) sum += i;
    for (i = 5; i < x; i += 5) sum += i; 
    
    return sum;
}  

[toc] | [prev] | [next] | [standalone]


#12348

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-03-02 17:40 +0100
Message-ID<1414254.xrXxnZYpxU@PointedEars.de>
In reply to#12346
Asen Bozhilov wrote:

> scripts examples написа:
>> Got a web site setup for solving euler problems in python, perl,
>> ruby and javascript.
>> 
>>    Feel free to give me any feedback, thanks.
> 
> I looked at Project Euler Problem 1. Obviously you can solve the problem
> with the formula of arithmetic progression sum:
> 
> <URL: http://en.wikipedia.org/wiki/Arithmetic_progression>
> 
> Even and without formula, you can solve it more elegant. The solution in
> Python is on a line:
> 
> sum(range(3, 10, 3)) + sum(range(5, 10, 5)); #23
> sum(range(3, 1000, 3)) + sum(range(5, 1000, 5)); #266333
> 
> JavaScript solution would be:
> 
> function multiples(x) {
>     var sum = 0, i;
>     for (i = 3; i < x; i += 3) sum += i;
>     for (i = 5; i < x; i += 5) sum += i;
>     
>     return sum;
> }

Or in JavaScript 1.7+:

  function range (start, end, step)
  {
    for (var i = start; i < end; i += step)
    {
      yield i;
    }
  }

  function sum ()
  {
    return (+x) + (+y);
  }

  [i for each (i in range(3, 10, 3))].reduce(sum)
  + [i for each (i in range(5, 10, 5))].reduce(sum)

Or, more compatible to other ECMAScript implementations:

  function range (start, end, step)
  {
    var a = [];

    for (var i = start; i < end; i += step)
    {
      a.push(i);
    }

    return a;
  }

  range(3, 10, 3).reduce(sum) + range(5, 10, 5).reduce(sum)


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web