Problem 115

Red, green or blue tiles

Problem 117

Red, green or blue tiles

Problem 116

A row of five grey square tiles is to have a number of its tiles replaced with coloured oblong tiles chosen from red (length two), green (length three), or blue (length four).
If red tiles are chosen there are exactly seven ways this can be done.
png116_1.png
If green tiles are chosen there are three ways.
png116_2.png
And if blue tiles are chosen there are two ways.
png116_3.png
Assuming that colours cannot be mixed there are 7 + 3 + 2 = 12 ways of replacing the grey tiles in a row measuring five units in length.
How many different ways can the grey tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used?
NOTE: This is related to Problem 117.
from tools import memoize_two_values


@memoize_two_values
def ways(l=2, blocks=50):
    # All black
    total = 1
    for pos in range(blocks - l + 1):
        total += ways(l, (blocks - (l + pos)))

    return total


# -3 as this will count all black as being valid.
def rgb_ways(blocks):
    return ways(2, blocks) + ways(3, blocks) + ways(4, blocks) - 3


def run(limit=50):
    return rgb_ways(50)