Thunderball frequency checker [CSV & Arrays]

Post your working scripts, libraries and tools
ameyrick
Posts: 119
Joined: 20 Apr 2014, 18:12

Thunderball frequency checker [CSV & Arrays]

21 Apr 2018, 19:23

Hi all,
Thought I'd brush up on some AHK.
Browsing the forum & playing with CSV data and arrays, I came up with a thunderball frequency checker.
Just thought I'd share, If it helps others, Great! Any comments or advice welcome. Thanks!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;csvdata from https://www.national-lottery.co.uk/results/thunderball/draw-history/csv

;functions########################################
StrSplit(InputVar, Delimiter="", OmitChars="") {
	array := []
	Loop Parse, InputVar, %Delimiter%, %OmitChars%
		array.Insert(A_LoopField)
	return array
}



;variables#######################################
;1-39 Main numbers array
Ball := []
Loop, 39
{
	Ball[(A_Index)] := 0
}

;Thunderball array
TBall := []
Loop, 14
{
	TBall[(A_Index)] := 0
}

;array of imported csv data
;https://www.national-lottery.co.uk/results/thunderball/draw-history/csv
csvdata := []
Loop Read, thunderball-draw-history.csv 
{
	subarray := StrSplit(A_LoopReadLine, "csv")
	csvdata.Insert(subarray)
}



;main############################################
;Tally the frequency of each ball drawn
for line, subarray in csvdata 
{
	IfLess line, 2 ; skip line 1 in csv file
	continue
	
	for column, ball_number in subarray
	{
		IfLess column, 2 ;skip date field
		continue
		
		IfGreater column, 7 ;skip Ball Set,Machine,DrawNumber
		continue
		
		IfEqual column, 7 ; Thunderball
		{
			TBall[(ball_number)] := TBall[(ball_number)]+1 ;tally++
		}
		
		Ball[(ball_number)] := Ball[(ball_number)]+1 ; tally++
		
	}
}



;output results
;main numbers 1-39
for ball, freq in Ball 
{
	MsgBox % "ball: " ball " freq: " freq
}


;thunderball 1-14
for tball, freq in TBall
{
	MsgBox % "thunderball: " tball " freq: " freq
}


Return to “Scripts and Functions”

Who is online

Users browsing this forum: adegard and 50 guests