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


Groups > comp.lang.javascript > #12346

Re: sample scripts for solving euler problems

From Asen Bozhilov <asen.bozhilov@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: sample scripts for solving euler problems
Date 2012-03-02 07:23 -0800
Organization http://groups.google.com
Message-ID <13347583.271.1330701787117.JavaMail.geo-discussion-forums@yner4> (permalink)
References <496fa250-5efc-44f6-b88a-bca6dda08ec8@k4g2000yqa.googlegroups.com>

Show all headers | View raw


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;
}  

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web