DefDbl A-Z
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)\DevStudio\VB\projects\flooble"
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
observedct = observedct + 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.0000") & mform(situations, "#####0") & mform(pt1ct / situations, "#0.000000") & mform(pt1ct / observedct, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt2ct, "##0.0000") & mform(situations, "#####0") & mform(pt2ct / situations, "#0.000000") & mform(pt2ct / observedct, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt3ct, "##0.0000") & mform(situations, "#####0") & mform(pt3ct / situations, "#0.000000") & mform(pt3ct / observedct, "#0.000000") & crlf
Text1.Text = Text1.Text & mform(pt4ct, "##0.0000") & mform(situations, "#####0") & mform(pt4ct / situations, "#0.000000") & mform(pt4ct / observedct, "#0.000000") & crlf
Text1.Text = Text1.Text & observedct & " " & 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 0.418994
6.0000 1944 0.003086 0.268156
3.7500 1944 0.001929 0.167598
0.8750 1944 0.000450 0.039106
22.375 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.
The overall situations (weighted) add to only 22.375 so the a priori probability of encountering this set of statements would be 22.375 / 1944.
With these weights, the probability for part (i) is 9.375/22.375, for part (ii) is 6/22.375, for (iii), 3.75/22.375 and for part (iv), .875/22.375. Decimal values are shown in the last column above. The next-to-last column represents only the probability that the situation would be as described AND that the requested condition within that be the case. The final column is the result modified by the Baysian condition that we already know the given statements were in fact made.