27
1
Write a program (or function) that takes in a positive integer.
If the input is 1
, print (or return) two diamonds neighboring side-by-side, each with a side length of 1 slash:
/\/\
\/\/
For every input N
greater than 1, look at the output for N-1
and for each pair of neighboring diamonds, insert a new diamond in between them whose side length is the sum of the side lengths of the two neighbors. Print (or return) this new diamond pattern.
So when 2
is input, we look at the output for 1
and can see that there are two neighboring diamonds, both with side length 1. So we insert a side length 2 (1+1) diamond in between them:
/\
/\/ \/\
\/\ /\/
\/
For input 3
we look at the output for 2
and add two diamonds with side length 3 (1+2 and 2+1) in between the two pairs of neighboring diamonds:
/\ /\
/ \ /\ / \
/\/ \/ \/ \/\
\/\ /\ /\ /\/
\ / \/ \ /
\/ \/
Continuing the pattern, the output for 4
is:
/\ /\
/\ / \ / \ /\
/ \ /\ / \ / \ /\ / \
/ \ / \ / \ /\ / \ / \ / \
/\/ \/ \/ \/ \/ \/ \/ \/\
\/\ /\ /\ /\ /\ /\ /\ /\/
\ / \ / \ / \/ \ / \ / \ /
\ / \/ \ / \ / \/ \ /
\/ \ / \ / \/
\/ \/
And so on.
Your outputs may have trailing spaces on any lines but only up to one trailing newline (and no leading newlines).
The shortest code in bytes wins.
1
Relevant OEIS: https://oeis.org/A002487.
– orlp – 2015-09-04T02:09:32.140