In a week, Bella either eat a mango, a guava, or an apple each day. If she will not eat the same fruit for two
consecutive days, and the fruit eaten on the 1st and the last day will not repeat, how many different ways are there
for her to eat fruits?
I ran a program which brute force counted, confirming Brian Smith's answer of 126.
I checked integers from 0 to 3^7, converted to base 3 in text format, then applied the imposed conditions.
--------
count = 0
successes = []
for n in range((3**7):
pattern = base2base(n,10,3).zfill(7)
if pattern[0] == pattern[-1]:
continue
fail = False
for index,char in enumerate(pattern):
if index == 0:
continue
if char == pattern[index-1]:
fail = True
break
if not fail:
count += 1
successes.append(pattern)
print(count)
|
Posted by Larry
on 2024-05-31 17:28:43 |