Skip to content

Instantly share code, notes, and snippets.

@dizzi
Last active December 12, 2015 01:58
Show Gist options
  • Save dizzi/4694646 to your computer and use it in GitHub Desktop.
Save dizzi/4694646 to your computer and use it in GitHub Desktop.
def pyramider(max, lvl, count, maxlvl){
if(count>=max)return lvl-1
print " "*(maxlvl)
(1..lvl).each{print String.format("%3d", count+it)}
println ""
return pyramider(max, lvl+1, count+lvl, maxlvl-1<0?0:maxlvl-1)
}
pyramider(30, 1, 0, pyramider(30, 1, 0, 0))
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
Result: 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment