Created
June 27, 2013 09:19
-
-
Save aya-eiya/5875143 to your computer and use it in GitHub Desktop.
ちょっとしたことがGroovy「ある値まで一定間隔のRangeのリストを作りたい」 ref: http://qiita.com/aya_eiya/items/d48541f1ca2e57c16ef2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getSteps = {start=1,max,step=1000 -> | |
if(max <= start + step) return [[start..max]] | |
def rs = (start..max).step(step).inject([]) {a,c -> (c>start) && a << [ ((a!=[])?a.last().to[0]+1:start)..c-1];a} | |
(rs.last().to[0] != max) && rs << [rs.last().to[0]+1..max];rs | |
} | |
println""" | |
getSteps(max=10020) = ${getSteps(max=10020)} | |
""" | |
println""" | |
getSteps(100,1000) = ${getSteps(100,1000)} | |
""" | |
println""" | |
getSteps(100,1015,10) = ${getSteps(100,1015,10)} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment