Red, Green, and Blue Tiles
Using a combination of grey squares (length 1), red tiles (length 2), green tiles (length 3), and blue tiles (length 4), in how many ways can a row measuring fifty units in length be tiled? Note: T...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Using a combination of grey square tiles and oblong tiles chosen from: red tiles (measuring two units), green tiles (measuring three units), and blue tiles (measuring four units), it is possible to tile a row measuring five units in length in exactly fifteen different ways.

How many ways can a row measuring fifty units in length be tiled?
Note: This is related to
hrefhttps://projecteuler.net/problem=116Problem 116.
Problem 117: Red, Green, and Blue Tiles
Mathematical Development
Theorem 1 (Tetranacci recurrence). Let denote the number of distinct tilings of a row of length using tiles of lengths 1, 2, 3, and 4. Then:
with initial conditions , , , .
Proof. Every tiling of a row of length ends with exactly one tile of length (provided ). Removing this last tile yields a valid tiling of the prefix of length . Conversely, appending any tile of length to a valid tiling of length produces a valid tiling of length . This establishes a bijection between tilings of length and the disjoint union , where is the set of tilings of length . Therefore:
For , , giving the stated four-term recurrence.
The initial conditions are verified by enumeration: (empty row), (grey), (grey-grey, red), (grey-grey-grey, red-grey, grey-red, green).
Theorem 2 (Generating function). The ordinary generating function for is:
Proof. A tiling of length is a sequence of tiles with and . The generating function for a single tile is . Since tiles are placed sequentially and independently, the generating function for all tilings is:
This is valid for where is the dominant root.
Theorem 3 (Asymptotic growth). as , where is the unique real root greater than 1 of:
and .
Proof. The characteristic polynomial of the recurrence is . Since and , there is a root . By Descartes’ rule, has exactly one positive real root.
The remaining three roots have modulus less than (they form a complex-conjugate pair and possibly a negative real root, all inside the circle ). By the general theory of linear recurrences with constant coefficients, where , so the dominant term is .
The constant where .
Lemma 1 (Verification). , , .
Proof. Direct computation from the recurrence:
- (but actually )
Editorial
Allowing colors to mix changes the structure completely from Problem 116. Now a tiling of length can end with any tile of length 1, 2, 3, or 4, and removing that last tile leaves a smaller valid tiling. That gives the four-term recurrence immediately, with the first few values determined by direct enumeration.
The implementation evaluates this recurrence from the bottom up. Starting from the base cases, it extends the table one length at a time, each entry being the sum of the previous four compatible states. By the time the table reaches 50, the desired count has already been accumulated.
Pseudocode
Initialize the tiling counts for row lengths 0, 1, 2, and 3.
For each row length from 4 up to 50:
Count the tilings whose last tile has length 1.
Count the tilings whose last tile has length 2.
Count the tilings whose last tile has length 3.
Count the tilings whose last tile has length 4.
Add those four contributions to obtain the new state.
Return the count for length 50.
Complexity Analysis
- Time: using the iterative approach with a rolling window of 4 values. Alternatively, via matrix exponentiation of the companion matrix.
- Space: for the rolling window (4 integer variables).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 117: Red, Green, and Blue Tiles
* Tetranacci recurrence: f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4)
* f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 4.
* Answer: f(50) = 100808458960497.
*/
int main() {
const int N = 50;
vector<long long> f(N + 1, 0);
f[0] = 1;
for (int i = 1; i <= N; i++) {
for (int L = 1; L <= 4 && L <= i; L++) {
f[i] += f[i - L];
}
}
// Cross-checks
assert(f[0] == 1);
assert(f[1] == 1);
assert(f[2] == 2);
assert(f[3] == 4);
assert(f[4] == 8);
assert(f[N] == 100808458960497LL);
cout << f[N] << endl;
return 0;
}
"""
Problem 117: Red, Green, and Blue Tiles
Count ways to tile a row of 50 units using grey (1), red (2), green (3),
and blue (4) tiles, with colors freely mixed.
Recurrence: f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) (tetranacci)
"""
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
def solve_dp(n: int):
"""Compute f(n) using the tetranacci recurrence."""
if n == 0: return 1
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
for L in range(1, min(4, i) + 1):
f[i] += f[i - L]
return f[n]
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
def solve_brute(n: int):
"""Enumerate all valid tilings recursively."""
if n == 0:
return 1
count = 0
for L in range(1, min(4, n) + 1):
count += solve_brute(n - L)
return count
# ---------------------------------------------------------------------------
# Compute and verify
# ---------------------------------------------------------------------------
# Cross-check brute force and DP for small values
for n in range(16):
assert solve_dp(n) == solve_brute(n), f"Mismatch at n={n}"
# Verify initial conditions
assert solve_dp(0) == 1
assert solve_dp(1) == 1
assert solve_dp(2) == 2
assert solve_dp(3) == 4
assert solve_dp(4) == 8
answer = solve_dp(50)
assert answer == 100808458960497, f"Expected 100808458960497, got {answer}"
print(answer)
# ---------------------------------------------------------------------------
# 4-Panel Visualization
# ---------------------------------------------------------------------------
ns = list(range(0, 51))
vals = [solve_dp(n) for n in ns]