In a certain island, onethird of the native people are liars who
always lie, onethird are knights who always tell the truth, and
onethird are knaves that is, people who strictly alternate between
speaking the truth and telling a lie, irrespective of order. The
chances of encountering any one of the three natives on a road on
the island are the same.
Four friends Art, Ben, Cal and Dan – who are natives of this island
got the top four ranks in a certain quiz The following statements
are made by each of Art, Ben, Cal and Dan.
Art
1. Exactly two of us are knights.
2. Ben got the first rank and Cal got the third rank.
Ben
1. Dan got the fourth rank.
2. Exactly one of us is a knave.
Cal
1. The absolute difference between Ben's rank and mine is 2.
2. Dan is not a liar.
Dan
1. Exactly one of us is a liar.
2. I am a knave.
Assuming no ties, determine the probability that:
(i) The absolute difference between Cal's rank and Dan’s rank is
1.
(ii) Exactly three of the four friends are liars.
(iii) Exactly two of the four friends are knaves.
(iv) At least one of the four friends is a knight.
*** For Art’s second statement  assume the entire statement is a
lie if the whole statement or any of its parts thereof is false.
For example A2 is false if in reality Ben got the first rank and
Cal got the fourth rank.
DefDbl AZ
Dim crlf$, types$
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$)  Len(a$)) & a$
mform$ = a$
End Function
Private Sub Form_Load()
ChDir "C:Program Files (x86)DevStudioVBprojectslooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
types$ = "0123" ' liar,second is truth,first is truth, knight
places$ = "abcd": h$ = places$
Do
For a = 0 To 3
a1 = a 2: a2 = a Mod 2
For b = 0 To 3
b1 = b 2: b2 = b Mod 2
For c = 0 To 3
c1 = c 2: c2 = c Mod 2
For d = 0 To 3
d1 = d 2: d2 = d Mod 2
ktct = Abs((a = 3) + (b = 3) + (c = 3) + (d = 3))
kvct = Abs((a = 1 Or a = 2) + (b = 1 Or b = 2) + (c = 1 Or c = 2) + (d = 1 Or d = 2))
ctgno = 1
For i = 1 To kvct
ctgno = ctgno / 2
Next
situations = situations + ctgno
If Abs(ktct = 2) = a1 And Abs(Mid(places$, 1, 1) = "b" And Mid(places$, 3, 1) = "c") = a2 Then
If Abs(Mid(places$, 4, 1) = "d") = b1 Then
If Abs(kvct = 1) = b2 Then
br = InStr(places$, "b")
cr = InStr(places$, "c")
If Abs(Abs(cr  br) = 2) = c1 And Abs(d <> 0) = c2 Then
lct = Abs((a = 0) + (b = 0) + (c = 0) + (d = 0))
If Abs(lct = 1) = d1 And Abs(d = 1 Or d = 2) = d2 Then
Text1.Text = Text1.Text & a & b & c & d & " " & places$ & crlf
dr = InStr(places$, "d")
If Abs(cr  dr) = 1 Then pt1ct = pt1ct + ctgno
If lct = 3 Then pt2ct = pt2ct + ctgno
If kvct = 2 Then pt3ct = pt3ct + ctgno
If ktct > 0 Then pt4ct = pt4ct + ctgno
DoEvents
End If
End If
End If
End If
End If
Next d
Next c
Next b
Next a
permute places$
Loop Until places$ = h$
Text1.Text = Text1.Text & crlf & mform(pt1ct, "####0") & mform(situations, "#####0") & mform(pt1ct / situations, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt2ct, "####0") & mform(situations, "#####0") & mform(pt2ct / situations, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt3ct, "####0") & mform(situations, "#####0") & mform(pt3ct / situations, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt4ct, "####0") & mform(situations, "#####0") & mform(pt4ct / situations, "#0.000000") & crlf
Text1.Text = Text1.Text & situations & crlf & "done"
End Sub
finds
ABCD order
0000 adbc
0011 adbc
0100 adbc
0000 adcb
0011 adcb
0100 adcb
1231 bacd
3231 bacd
0000 badc
0011 badc
0100 badc
0000 bcda
0011 bcda
0100 bcda
0000 bdac
0011 bdac
0100 bdac
1020 bdca
0220 cabd
0320 cabd
0000 cadb
0011 cadb
0100 cadb
0000 cbda
0011 cbda
0100 cbda
0000 cdab
0011 cdab
0100 cdab
0000 dabc
0011 dabc
0100 dabc
0000 dacb
0011 dacb
0100 dacb
0000 dbca
0011 dbca
0100 dbca
0000 dcba
0011 dcba
0100 dcba
9.3750 1944 0.004823
6.0000 1944 0.003086
3.7500 1944 0.001929
0.8750 1944 0.000450
1944
which shows, in the first 41 lines, the possibilities. They are not all equally probable, as:
0 represents liar: truth value for two statements 00.
1 represents knave: truth value for two statements 01, in that order.
2 represents knave: truth value for two statements 10, in that order.
3 represents knightr: truth value for two statements 11.
The two knave situations count for only 1/3 of possibilities, so only half of a unit counts for a situation having one knave; only 1/4 for a situation having two knaves, etc. These situations add up to the correct 1944, which is 3^4 * 4!, that they would be if the order of the statements didn't matter.
With these weights, the probability for part (i) is 9.375/1944, for part (ii) is 6/1944, for (iii), 3.75/1944 and for part (iv), .875/1944. Decimal values are shown to the side above.
(Edited to show true values of the counts, rather than rounded to an integer, as the counts include the weighting consideration for knave count).
Edited on July 17, 2014, 12:49 pm

Posted by Charlie
on 20140717 12:33:20 