' Version: 14
Dim Shared Alphabet3
(8) As LetterBin
' 000 001 010 011 100 101 110 111
Alphabet1(1).Signature = "0"
Alphabet1(2).Signature = "1"
Call NewAlphabet
(Alphabet1
(), Alphabet2
()) Call NewAlphabet
(Alphabet2
(), Alphabet3
()) Call NewAlphabet
(Alphabet3
(), Alphabet4
()) Call NewAlphabet
(Alphabet4
(), Alphabet5
()) Call NewAlphabet
(Alphabet5
(), Alphabet6
()) Call NewAlphabet
(Alphabet6
(), Alphabet7
()) Call NewAlphabet
(Alphabet7
(), Alphabet8
()) Call NewAlphabet
(Alphabet8
(), Alphabet9
()) Call NewAlphabet
(Alphabet9
(), Alphabet10
()) Call NewAlphabet
(Alphabet10
(), Alphabet11
()) Call NewAlphabet
(Alphabet11
(), Alphabet12
()) Call NewAlphabet
(Alphabet12
(), Alphabet13
())
'''
TheString = TestData(n)
GuessesCorrect = 0
GuessesTotal = 0
GuessStreak = 0
GuessStreakBest = 0
' Uncomment this to manually test one string.
'''
'1
TheString = "00000010000000001010000001100000001001000001000100001000110001000101001000010110000010101000001101000011001000100101001"
'''
'Cls: Locate 1, 1
'Input "", TheString
'''
' Main prediction call
GuessPredicted
= Analyze
(Left$(TheString
, j
), 0)
' Reconciliation
GuessesCorrect = GuessesCorrect + 1
GuessStreak = GuessStreak + 1
If (GuessStreak
> GuessStreakBest
) Then GuessStreakBest
= GuessStreak
Print "I am RIGHT this round." GuessStreak = 0
Print "I am WRONG this round." GuessesTotal = GuessesTotal + 1
' Draw bottom graph
ProgressGraph
(1 + Int(j
* f
), 1) = GuessesCorrect
/ GuessesTotal
ProgressGraph
(1 + Int(j
* f
), 2) = 120 ProgressGraph
(1 + Int(j
* f
), 2) = 251
Dim Partialguess
(1 To 10, 2) As Double ' Change the upper bound to a higer number for more accuracy.
' Create shifted versions of string, i.e. ABCD -> BCDA, CDAB, DABC, ABCD, BCDA, etc.
Fingerprint(1) = TheStringIn
Fingerprint
(n
) = Right$(Fingerprint
(n
- 1), Len(Fingerprint
(n
- 1)) - 1) + Left$(Fingerprint
(n
- 1), 1)
' Initialize partial results.
Partialguess(n, 1) = -999
Call CreateHisto
(Fingerprint
(), Alphabet1
(), 1) Call CreateHisto
(Fingerprint
(), Alphabet2
(), 2) Call CreateHisto
(Fingerprint
(), Alphabet3
(), 3) Call CreateHisto
(Fingerprint
(), Alphabet4
(), 4) Call CreateHisto
(Fingerprint
(), Alphabet5
(), 5) Call CreateHisto
(Fingerprint
(), Alphabet6
(), 6) Call CreateHisto
(Fingerprint
(), Alphabet7
(), 7) Call CreateHisto
(Fingerprint
(), Alphabet8
(), 8) Call CreateHisto
(Fingerprint
(), Alphabet9
(), 9) Call CreateHisto
(Fingerprint
(), Alphabet10
(), 10) 'Call CreateHisto(Fingerprint(), Alphabet11(), 11)
'Call CreateHisto(Fingerprint(), Alphabet12(), 12)
'Call CreateHisto(Fingerprint(), Alphabet13(), 13)
If (pswitch
= 1) Then ' Set the last number >=1 to print stats for that histogram. If (Len(TheStringIn
) >= 10) Then Call PrintHisto
(Alphabet10
(), 0) 'If (Len(TheStringIn) >= 11) Then Call PrintHisto(Alphabet11(), 0)
'If (Len(TheStringIn) >= 12) Then Call PrintHisto(Alphabet12(), 0)
'If (Len(TheStringIn) >= 13) Then Call PrintHisto(Alphabet13(), 0)
If (Len(TheStringIn
) >= 1) Then Call MakeGuess
(TheStringIn
, Alphabet1
(), 1, Partialguess
(), pswitch
) ' Set the last number =1 to print guess for that histogram. If (Len(TheStringIn
) >= 2) Then Call MakeGuess
(TheStringIn
, Alphabet2
(), 2, Partialguess
(), pswitch
) If (Len(TheStringIn
) >= 3) Then Call MakeGuess
(TheStringIn
, Alphabet3
(), 3, Partialguess
(), pswitch
) If (Len(TheStringIn
) >= 4) Then Call MakeGuess
(TheStringIn
, Alphabet4
(), 4, Partialguess
(), 0) If (Len(TheStringIn
) >= 5) Then Call MakeGuess
(TheStringIn
, Alphabet5
(), 5, Partialguess
(), 0) If (Len(TheStringIn
) >= 6) Then Call MakeGuess
(TheStringIn
, Alphabet6
(), 6, Partialguess
(), 0) If (Len(TheStringIn
) >= 7) Then Call MakeGuess
(TheStringIn
, Alphabet7
(), 7, Partialguess
(), 0) If (Len(TheStringIn
) >= 8) Then Call MakeGuess
(TheStringIn
, Alphabet8
(), 8, Partialguess
(), 0) If (Len(TheStringIn
) >= 9) Then Call MakeGuess
(TheStringIn
, Alphabet9
(), 9, Partialguess
(), 0) If (Len(TheStringIn
) >= 10) Then Call MakeGuess
(TheStringIn
, Alphabet10
(), 10, Partialguess
(), 0) 'If (Len(TheStringIn) >= 11) Then Call MakeGuess(TheStringIn, Alphabet11(), 11, Partialguess(), 0)
'If (Len(TheStringIn) >= 12) Then Call MakeGuess(TheStringIn, Alphabet12(), 12, Partialguess(), 0)
'If (Len(TheStringIn) >= 13) Then Call MakeGuess(TheStringIn, Alphabet13(), 13, Partialguess(), 0)
If (Partialguess
(k
, 1) <> -999) Then Print Partialguess
(k
, 1);
j = 0
r = 0
If (Partialguess
(k
, 1) <> -999) Then
' This is the made-up part of the model:
' The variable r contributes to weighted average.
' The variable j is used for normalization.
' Scaling factor h influences weighted average calculaton.
' The factors multiplying h are totally arbitrary. Notes:
' setting o(h^2) means the later alphabets count for more.
' Partialguess(k, 1) euqals the calculated guess at frequency k.
' Partialguess(k, 2) euqals the peak count of the unscaled histogram.
' ...while Partialguess(k, 2) is here, it does not seem to help calculations.
h
= 1 + k
- LBound(Partialguess
)
h = h ^ 2
' Standard weighted average:
r = r + h * Partialguess(k, 1)
j = j + h
r = r / j
r = 1
r = 0
TheReturn = r
Analyze = TheReturn
TheReturn = 0
j = 1
k = 0
If (arralpha
(n
).Count
>= j
) Then TheReturn
= TheReturn
+ Val(Right$(arralpha
(n
).Signature
, 1)) k = k + 1
j = arralpha(n).Count
TheReturn = TheReturn / k
arrbeta(wid, 1) = TheReturn
arrbeta(wid, 2) = j
TheReturn = .5
arrbeta(wid, 1) = TheReturn
arrbeta(wid, 2) = j
arralpha(n).Count = 0
For k
= 1 To Len(arrfinger
(j
)) - (Len(arrfinger
(j
)) Mod w
) Step w
'- 0 Step 1 'w 'make the 0 a -w? might not matter at all If (Mid$(arrfinger
(j
), k
, w
) = arralpha
(n
).Signature
) Then arralpha(n).Count = arralpha(n).Count + 1
j = w
Print arr
(n
).Signature; arr
(n
).Count
Sub NewAlphabet
(arrold
() As LetterBin
, arrnew
() As LetterBin
) n = 0
n = n + 1
arrnew(n).Signature = arrold(j).Signature
arrnew(j).Signature = "0" + arrnew(j).Signature
arrnew(j).Signature = "1" + arrnew(j).Signature
If (LowLimit
< HighLimit
) Then piv = Partition(arr(), LowLimit, HighLimit)
Call QuickSort
(arr
(), LowLimit
, piv
- 1) Call QuickSort
(arr
(), piv
+ 1, HighLimit
)
pivot = arr(HighLimit).Count
i = LowLimit - 1
For j
= LowLimit
To HighLimit
- 1 tmp = arr(j).Count - pivot
i = i + 1
Swap arr
(i
+ 1), arr
(HighLimit
) Partition = i + 1
n = alwayszero
'''
' Systematic cases:
'''
n = n + 1: TestData(n) = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
n = n + 1: TestData(n) = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
n = n + 1: TestData(n) = "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
n = n + 1: TestData(n) = "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010"
n = n + 1: TestData(n) = "0010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010"
n = n + 1: TestData(n) = "0100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100"
n = n + 1: TestData(n) = "1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001"
n = n + 1: TestData(n) = "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101"
n = n + 1: TestData(n) = "1011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011011"
n = n + 1: TestData(n) = "0110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110"
'
'''
' Community hand-typed cases:
'''
' (from Cobalt) (Results in: 48% - Claims he made this data hand but behavior in Discord raises doubt.)
n = n + 1: TestData(n) = "1010001101110110000000011100110100101010111110101001100101110100000111101011011000010101101100000110010010010101010110111111111001000100101011101000011110011000000100111100001100111000111100100000000111010011010011001111101000010011101111000011100011010110101101000111101111100101100100000101111011001101100000111011000001001111000110000001110101100101"
' (from Keybone) (Results in: 82%)
n = n + 1: TestData(n) = "101010101010101010101001010101010101001010111001010101010101010101010100010101010101010100101001010101001100101010001010100101010100101010100101010101010101010011011110010101010100100101010110010011001010011001010100010100101010010101010101010010101010101010010101001010101010100110010101010100101010101010011001001010100101010010101010100101010010101001010100101001010010101010111010100110011001010101010100110101001010101010100101001010111010101010101010100101001010101010010101010101001010101001010101001010100101010100101010010101010101001010101001010101010101001010101001010100101010101010010101010010010101010101010101010010100101010101001010100101001010101001111101010101010100101010110011001010101010101010110101010101101010101010100101010010101010010101010101101110010101001010101010110010100101010101001011010101010100110101010100101010010101010100101010101001010101010101001010101010011010101010101110110100101010111010101011011001011001010101001010101010101010101010011001010101010100101010101010101010010100101"
' (from Keybone) (Results in: 54%)
n = n + 1: TestData(n) = "0101110101100011010100101011001110001011001010001110101111010100111011100100101001010011110101101000101010001010101111001010111010101010100001010101000101101100101111101010010101110110111001000101000011010101010001001001001111101011101010100010110101110101100000101010101110111010100100100001110111100101011110101010001010001110010110111110110010101001001011101000101001011100011101000010101010101101010010110100101101000101111010101110111001010011101111010101000010101111100010101011110101011011110100001010110"
' (from Loudar) (Results in: 71%)
n = n + 1: TestData(n) = "1011001010010100100100110010101010101001010101010101011010010101001010101001010010100110101011010101010101011010101101010101010101010010110101010101100101010101010110101101011010010101010010100110101101001010110101011010010101101010110100101111010101010011011011010010110101010010110100101101010100101011010010101001010101010001011101011010010101011100111010010001101011110010011010001011100110101010010011010101001001010010000101010110001"
' (from Luke) (Results in: 51% - I have long suspected Luke to be a computer. The numbers are now in.)
n = n + 1: TestData(n) = "01100101001010001100001101101111011010010101010110110101001000001111001111110101000101111011010101111101010101101010101001010101011000010101010101001011010100110100110100110011010101010101110101010111111101011010100000001101111000010111000110111001000010100001101010110100000111101011111100001011001010110010110" ' Luke 50
' (from Sarafromct) (Results in: 64%)
n = n + 1: TestData(n) = "10101010101011101000011101010111010101010101100111001010100111100001011011110101000001111010101101010000001111110011111110111101110111001110110010000100010101010101010100101011010110101010101010101001000000001111110000011110101010101010100010101110101010101101111111111111111111101010101010101000000" ' 63
' (from Spriggs) (Results in: 85%)
n = n + 1: TestData(n) = "10111010101010101010101001010101010101001010101001010101010101010101010101010101010101010101010101010101001010100100100101010101010101001010100101010101010100101010100101010101010101010101001010010110010101010010101010101010101010101010100101001001001010101010101010101010101001010101001001101010010"
' (from Spriggs) (Results in: 67%)
n = n + 1: TestData(n) = "11111011110100101011111111110100000011011110101100111100111111110111101110100111100110011111110101111111010111101111100111110111111111111011100111110111111110010000101011111001110101101010110111110"
' (from Hotpants) (Results in: 62%)
n = n + 1: TestData(n) = "01010100011001010010101010101010101000110101010111101010100100011010101010100100101110010010010100001010101001010101010110010001001011000100100110101001001001010000000001010101101111101001010100010101001001010101000100101001100100010011010101010101010111010010101011101011011010110100100010010100100100010010001001" ' Tom
'
'''
' Known-Random cases:
'''
' (using RND) (Results in: 45%)
n = n + 1: TestData(n) = "11100101110011011010110100110011111011010110100100000110000100101001001010011100111101101110000001000000011011100101110000000111100100011101000000101000110100001000000001111010101011000010001110111110001001110101011000010101001111010100100000011100110110110000111010001010000011010000101111101011000"
' (from Spriggs) (Results in: 52%)
n = n + 1: TestData(n) = "010101111010111100110000001001100100101100000101110001100101000010001001111101111111111100011110000011011110011000100011100100001101110011001001011001000011110010001000111100011100011110010110011110111010110100001000110000010000111000111011100110011010101111111100100010001111111100010100001011000011"
' (Wolfrm rule 30, central column) (Results in: 47%)
n = n + 1: TestData(n) = "110111001100010110010011101011100111010101100001100101011010101111110000111100010101110000010010110001"
' (using RND) (Results in: 46%)
n = n + 1: TestData(n) = "111001011100110110101101001100111110110101101001000001100001001010010010100111001111011011100000010000000110111001011100000001111001000111010000001010001101000010000000011110101010110000100011101111100010011101010110000101010011110101001000000111001101101100001110100010100000110100001011111010110000"
' (using RND) (Results in: 46%)
n = n + 1: TestData(n) = "111001011100110110101101001100111110110101101001000001100001001010010010100111001111011011100000010000000110111001011100000001111001000111010000001010001101000010000000011110101010110000100011101111100010011101010110000101010011110101001000000111001101101100001110100010100000110100001011111010110000101110111110011100001000110010010001100111101000001101011000010101101011111010010001010010110110011000001001101000011100000011110001110011100010101010111101100100100001001000101101110110101100001111011101000100111110000001110000111011101000110110100111101101001100100110000111110111101001100010011110"
' (using RND) (Results in: 45%)
n = n + 1: TestData(n) = "111001011100110110101101001100111110110101101001000001100001001010010010100111001111011011100000010000000110111001011100000001111001000111010000001010001101000010000000011110101010110000100011101111100010011101010110000101010011110101001000000111001101101100001110100010100000110100001011111010110000101110111110011100001000110010010001100111101000001101011000010101101011111010010001010010110110011000001001101000011100000011110001110011100010101010111101100100100001001000101101110110101100001111011101000100111110000001110000111011101000110110100111101101001100100110000111110111101001100010011110111001001100111000110011011000100101100010101010000010000111111010111111011100011100001000011000100100111001100001111010001010000001011100000101110000110010111110010101010110111110011100100001011101010000011011110110100010110111000100000110000001001010001011010000010001111110100100010011100011001000"
' (using RND) (Results in: 48%)
n = n + 1: TestData(n) = "111001011100110110101101001100111110110101101001000001100001001010010010100111001111011011100000010000000110111001011100000001111001000111010000001010001101000010000000011110101010110000100011101111100010011101010110000101010011110101001000000111001101101100001110100010100000110100001011111010110000101110111110011100001000110010010001100111101000001101011000010101101011111010010001010010110110011000001001101000011100000011110001110011100010101010111101100100100001001000101101110110101100001111011101000100111110000001110000111011101000110110100111101101001100100110000111110111101001100010011110111001001100111000110011011000100101100010101010000010000111111010111111011100011100001000011000100100111001100001111010001010000001011100000101110000110010111110010101010110111110011100100001011101010000011011110110100010110111000100000110000001001010001011010000010001111110100100010011100011001000011101011010100110110000110010010011110111001001011111011000000100010011011100111110111011111101100011011101001111110100011010000111001001010111011101000001010010010100111010001001010101001000010011100111010101000110010110101111001110000010110110010101001000011000101000001100110100111101000110111101101010011011000101100101001010001100110101000101110000101100110010011010001010101010101101110101110110101100101001111100110110101011001000001100101001011000101100001001000001010111010100010100101011001111001011011100011001110010111011110010111101011101000100100010111010000001010011101010001110110110101011000101010100000001110110101011110101111100100101101000001011000101001110010010010000111001101010100101111101001110010001011000001001000111010001000011000111000000111001110111110011110110101100111011001100101101010101100010100100001010010110010000001100110010010100110011110110000001001000111001001010010000011111110011110010001100011100011010000111100111111010010001010011100100111100111101111110101000010011100011111100010000011111101101010010100000011011001110001100001011111100111000001110111011001111110011011100111000110110110011110000111000010011011000011001111111110010100000111110011111100100001100000000110001111101101011100011111011110001100100001100011100011111000000110011011100110101101001001111101101000000110101101001100011100011001110001000000111111100110101001110100010010010100000010100001010001011011001101010011111001101110110010101000111101100111000011000111001100011011011010100111111001100000100100110000100101001111111100110010111100000111101101001111001010011010011011100101001001001110101110001101010001111010101100101010111000111000011000001010010010101010100001110010001001001110110011100110011111001100111010011110100100110010000100011010001110000000100001100000010000111000111111000111100010001101011000101000010100011100011111000100010101000001001011001000101101111110111110110001101001001011100011110001101100010100101101011001001100111000000111111110110100010111111101000000001111000100001111111011000101001111110010000110101100010000011100110111101011011100110"
'
'''
' Pathological cases:
'''
n = n + 1: TestData(n) = "011111101111111110101111110011111110110111110111011110111001110111010110111101001111101010111110010111100110111011010110" ' seed 0
n = n + 1: TestData(n) = "100000010000000001010000001100000001001000001000100001000110001000101001000010110000010101000001101000011001000100101001" ' seed 1
n = n + 1: TestData(n) = "001111111110111111101011111100111110111011110110111110101011110111100110111111000111111110010111110011101110101101110010" ' seed 00
n = n + 1: TestData(n) = "011111101111111110101111110011111110110111110111011110111001110111010110111101001111101010111110010111100110111011010110" ' seed 01
n = n + 1: TestData(n) = "100000010000000001010000001100000001001000001000100001000110001000101001000010110000010101000001101000011001000100101001" ' seed 10
n = n + 1: TestData(n) = "110000000001000000010100000011000001000100001001000001010100001000011001000000111000000001101000001100010001010010001101" ' seed 11
n = n + 1: TestData(n) = "000111111111011111101101111101011111110011111110101011101110110110101110011101111011101010011110110011111011110011011110" ' seed 000
n = n + 1: TestData(n) = "001111111110111111101011111100111110111011110110111110101011110111100110111111000111111110010111110011101110101101110010" ' seed 001
n = n + 1: TestData(n) = "010111111111011111101101111101011110111011110101011111100111111110010111110111001110111110001111110100111110101101110100" ' seed 010
n = n + 1: TestData(n) = "011111101111111110101111110011111110110111110111011110111001110111010110111101001111101010111110010111100110111011010110" ' seed 011
n = n + 1: TestData(n) = "100000010000000001010000001100000001001000001000100001000110001000101001000010110000010101000001101000011001000100101001" ' seed 100
n = n + 1: TestData(n) = "101000000000100000010010000010100001000100001010100000011000000001101000001000110001000001110000001011000001010010001011" ' seed 101
LoadTestData = n
''''''''''
' Code for creating pathological strings:
'Dim x$
'Dim q
'x$ = "101"
'Print x$;
'Do
' Cls
' Locate 1, 1
' q = Analyze(x$, 0)
' If (q = 1) Then
' x$ = x$ + "0"
' Else
' x$ = x$ + "1"
' End If
' Print x$
' _Display
' _Delay .015
' _Limit 120
'Loop Until Len(x$) = 120
'Open "nnn.txt" For Output As #1
'Print #1, x$
'Close #1
''''''''''