Skip to content

Instantly share code, notes, and snippets.

@kirqe
Created July 7, 2018 15:24
Show Gist options
  • Save kirqe/ed55f8c1cd2f40a583bddefb61b9e140 to your computer and use it in GitHub Desktop.
Save kirqe/ed55f8c1cd2f40a583bddefb61b9e140 to your computer and use it in GitHub Desktop.
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