On a remote island, its inhabitants might lie at any given moment. However, they are restricted by the island code NOT to tell 3 lies in a row.
A group of visitors to the island meets an inhabitant of the island.
Responding to various queries of the visitors he made precisely 17 consecutive statements.
How many combinations of truths/lies can there be?
The below computer program finds 76424, a different solution from Brian Smith. The below is wrong. I misread the statement as not allowing more than 3 lies in a row. It should be not to allow more than 2 lies in a row.
global seq seqSet lieCt
seq=[]; seqSet=[]; lieCt=0;
addOn;
disp(length(seqSet))
function addOn
global seq seqSet lieCt
for i=[true false]
lieCtSave=lieCt;
seqSave = seq;
if i==true
seq=[seq true];
lieCt=0;
else
if lieCt<3
seq=[seq false];
lieCt=lieCt+1;
else
seq=seqSave;
lieCt=lieCtSave;
break
end
end
if length(seq)<17
addOn
else
seqSet=[seqSet; seq];
end
seq=seqSave;
lieCt=lieCtSave;
end
end
finds 76424 ways.
The first 25 and last 26 of these are shown below (1 = truth, 0 = lie), with a section from the middle shown in between:
>> for k=1:25 disp(seqSet(k,:))
end
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1
1 1 1 1 1 1 1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