-
-
Save kirqe/ed55f8c1cd2f40a583bddefb61b9e140 to your computer and use it in GitHub Desktop.
This file contains 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 m(n) | |
seq = (0..n/2).to_a | |
res = [] | |
seq.each do |e| | |
r = (0..e).to_a | |
r << r.last while r.length < seq.length | |
res << r + r.reverse.drop(1) | |
end | |
res + res.reverse.drop(1) | |
end | |
m(7).each do |e| | |
p e | |
end | |
[0, 0, 0, 0, 0, 0, 0] | |
[0, 1, 1, 1, 1, 1, 0] | |
[0, 1, 2, 2, 2, 1, 0] | |
[0, 1, 2, 3, 2, 1, 0] | |
[0, 1, 2, 2, 2, 1, 0] | |
[0, 1, 1, 1, 1, 1, 0] | |
[0, 0, 0, 0, 0, 0, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment