Skip to content

Instantly share code, notes, and snippets.

@chanwit
Created July 13, 2009 15:53
Show Gist options
  • Save chanwit/146210 to your computer and use it in GitHub Desktop.
Save chanwit/146210 to your computer and use it in GitHub Desktop.
// My stupid algorithm on Groovy's list reshape:
def reshape = { x, size ->
int j = 0
def result = []
def sublist = []
x.each {
j++
sublist.add(it)
if(j == size) {
j = 0
result.add(sublist)
sublist = []
}
}
result.add(sublist)
return result
}
def x = reshape([1,2,3,4,5], 2)
println x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment