Skip to main content
added 2 characters in body
Source Link
Rod
  • 18.6k
  • 4
  • 32
  • 89

Python 2, 140140 137 bytes

n=input() x=[[0,]*n+[1]+n*[0,]]x=[] a=[0]*n+[1]+n*[0] z=n%2 exec'x+=[[exec'x+=[a];a=[(i%2^z)*sum(x[-1][ia[i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1)];z^=1;'*n print map(sum,zip(*x))[1:-1] 

Try it online!Try it online! or Try all test casesTry it online!

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 

Python 2, 140 137 bytes

n=input() x=[] a=[0]*n+[1]+n*[0] z=n%2 exec'x+=[a];a=[(i%2^z)*sum(a[i-1:i+2])for i in range(2*n+1)];z^=1;'*n print map(sum,zip(*x))[1:-1] 

Try it online! or Try it online!

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 
added 52 characters in body
Source Link
Rod
  • 18.6k
  • 4
  • 32
  • 89

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 
added 379 characters in body
Source Link
Rod
  • 18.6k
  • 4
  • 32
  • 89

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

Python 2, 140 bytes

n=input() x=[[0,]*n+[1]+n*[0,]] z=n%2 exec'x+=[[(i%2^z)*sum(x[-1][i-1:i+2])for i in range(2*n+1)]];z^=1;'*(n-1) print map(sum,zip(*x))[1:-1] 

Try it online! or Try all test cases

For n=3
Starts with a list with n zeros surround an one - [[0, 0, 0, 1, 0, 0, 0]]
Generate the full pyramid

[[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 2, 0, 1, 0]] 

Rotate 90º and sum each row

[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 2], [0, 1, 0], [0, 0, 1], [0, 0, 0]] 
Source Link
Rod
  • 18.6k
  • 4
  • 32
  • 89
Loading