Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Fibonacci domino tiling

There's classic combinatorial result that the number of ways to tile a 2*n strip by 1*2 dominoes is the nth Fibonacci number. You goal is to print all the tilings for a given n, drawn with dashes and vertical lines like these 8 tilings for n=5:

|————
|————
——|——
——|——
|||——
|||——
————|
————|
||——|
||——|
|——||
|——||
——|||
——|||
|||||
|||||

You are to provide a program or named function that take n as input and prints the required output. Fewest bytes wins.

Input

A number n between 1 and 10 inclusive via STDIN or function input.

Output

Print every possible domino tilings of the 2*n strip, drawn horizontally. The tilings may be in any order, but each should appear exactly once. They must be separated by a blank line.

A vertical domino is made of two vertical bars (|) and a horizontal domino is made of two em dashes (). You may use hyphens (-) in place of em dashes to stay in ASCII.

You can do anything with whitespace as long as the printed output looks the same.

Answer*

Draft saved
Draft discarded
Cancel

AltStyle によって変換されたページ (->オリジナル) /