18
0
Given as input a positive integer n>=1
, output the first n
rows of the following triangle:
1
1 0 1
0 0 1 0 0
1 1 1 0 1 1 1
0 0 0 0 1 0 0 0 0
1 1 1 1 1 0 1 1 1 1 1
0 0 0 0 0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
The rows alternate between all zeroes and all ones, except the center column is flipped.
Test cases
Input:
3
Output:
1 1 0 1 0 0 1 0 0
Input:
10
Output:
1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
Your code must work for any n<100
. This is code-golf, hence the shortest code in bytes wins!
Trailing spaces / newlines and leading newlines are allowed!
Is excess white space acceptable and if so, which (leading lines / leading / trailing / training lines)? – Jonathan Allan – 2017-08-13T17:39:31.873
I recommend allowing trailing space/newline and leading newline or consistent leading whitespace. – Mr. Xcoder – 2017-08-13T17:41:26.893
1Can we return a a list of lists of numbers? – Erik the Outgolfer – 2017-08-13T17:42:56.703
@StepHen Right, but are you sure that's supposed to be part of the challenge? – totallyhuman – 2017-08-13T17:44:16.143
8@EriktheOutgolfer list of lists is fine! – None – 2017-08-13T17:50:55.057
1Since a list of lists is fine, I'm assuming that the centered alignment is not required, is it? – Luis Mendo – 2017-08-13T20:39:24.947
@LuisMendo List of lists is a list of lists, otherwise you must output what you see.Center aligment IS required. – None – 2017-08-13T20:58:28.970
1It's your challenge, but in my opinion if you are flexible enough to allow a list of lists it doesn't make any sense to be strict with the formatting – Luis Mendo – 2017-08-13T22:59:42.877