Skip to content

Instantly share code, notes, and snippets.

@yangwansu
Created January 9, 2014 05:38
Show Gist options
  • Save yangwansu/8329870 to your computer and use it in GitHub Desktop.
Save yangwansu/8329870 to your computer and use it in GitHub Desktop.
http://euler.synap.co.kr/prob_detail.php?id=1 10보다 작은 자연수 중에서 3 또는 5의 배수는 3, 5, 6, 9 이고, 이것을 모두 더하면 23입니다. 1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면 얼마일까요?
def func={start,end ->
sum=0;
(start..<end).each {
if(it%3 == 0 || it%5==0){
sum+=it
}
}
return sum;
}
print func(1, 1000)
def sum=0
(1..<1000).grep{ it%3==0||it%5==0}.each{sum+=it}
println sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment