I have a function get_appendable_values(sequence)
that takes a sequence (even empty) and returns a list of all the values appendable (as a last element) to that sequence. I need to generate all the possible sequences of 4 elements, with respect to the rules defined in this function and starting with an empty sequence.
Example :
Let's say the implementation of get_appendable_values
is :
def get_appendable_values(sequence):
'''Dummy rules'''
if len(sequence) == 2:
return [4, 12]
if sequence[-1] == 4:
return [7]
return [0, 9]
Expected output :
[[0, 0, 4, 7],
[0, 0, 12, 0],
[0, 0, 12, 9],
[0, 9, 4, 7],
[0, 9, 12, 0],
[0, 9, 12, 9],
[9, 0, 4, 7],
[9, 0, 12, 0],
[9, 0, 12, 9],
[9, 9, 4, 7],
[9, 9, 12, 0],
[9, 9, 12, 9]]
I have the feeling that recursion is the key, but I could not figure it out.