Quantcast
Viewing all articles
Browse latest Browse all 35

Generate valid Fibonacci tilings

Background

The Fibonacci tiling is a tiling of the (1D) line using two segments: a short one, S, and a long one, L (their length ratio is the golden ratio, but that's not relevant to this challenge). For a tiling using these two prototiles to actually be a Fibonacci tiling, the following conditions have to be fulfilled:

  • The tiling must not contain the subsequence SS.
  • The tiling must not contain the subsequence LLL.
  • If a new tiling is composed by performing all of the following substitutions, the result must still be a Fibonacci tiling:
    1. LLS
    2. SL
    3. L(empty string)

Let's look at some examples:

SLLSLLSLLSLS

This looks like a valid tiling, because it doesn't contain two *S*s or three *L*s but let's perform the composition:

LSLSLSLL

That still looks fine, but if we compose this again, we get

LLLS

which is not a valid Fibonacci tiling. Therefore, the two previous sequences weren't valid tilings either.

On the other hand, if we start with

LSLLSLSLLSLSLL

and repeatedly compose this to shorter sequences

LSLLSLLSLSLSLLLS

all results are valid Fibonacci tilings, because we never obtain SS or LLL anywhere inside those strings.

For further reading, there is a thesis which uses this tiling as a simple 1D analogy to Penrose tilings.

The Challenge

Write a program or function which, given a non-negative integer N, returns all valid Fibonacci tiling in the form of strings containing N characters (being S or L).

You may take input via function argument, STDIN or ARGV and return or print the result.

This is code golf, the shortest answer (in bytes) wins.

Examples

N      Output0      (an empty string)1      S, L2      SL, LS, LL3      LSL, SLS, LLS, SLL4      SLSL, SLLS, LSLS, LSLL, LLSL5      LLSLL, LLSLS, LSLLS, LSLSL, SLLSL, SLSLL...8      LLSLLSLS, LLSLSLLS, LSLLSLLS, LSLLSLSL, LSLSLLSL, SLLSLLSL, SLLSLSLL, SLSLLSLL, SLSLLSLS

Viewing all articles
Browse latest Browse all 35

Trending Articles