Skip to content

Instantly share code, notes, and snippets.

@iambowen
Last active December 22, 2015 03:09
Show Gist options
  • Save iambowen/6408599 to your computer and use it in GitHub Desktop.
Save iambowen/6408599 to your computer and use it in GitHub Desktop.
First problem to solve.

The following is the description of first problem we need to solve, try finish it before Friday. There's no rule to complete the issue, you can use either languages with either way. Clean code is also not a requirement. In another way, there's no "Jiecao" to finish that.

Problem 1

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.

Problem from

@iambowen
Copy link
Author

iambowen commented Sep 9, 2013

(1...1000).inject(0) {|sum, value| (value.modulo(3).zero? or value.modulo(5).zero?) ? sum + value : sum} 

233168

@fuying
Copy link

fuying commented Sep 9, 2013

_.reduce(_.range(1000), function(memo, num){ if (num % 3 === 0 || num % 5 === 0){ return memo+num; }else{ return memo;} }, 0);

Language: underscore.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment