-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlottocheck
105 lines (90 loc) · 3.92 KB
/
lottocheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
#set -x
# Description: See http://www.rawiriblundell.com/?p=1534
inputDir=/home/rawiri/bin/lottoresults
resultsFile=/home/rawiri/bin/lottoresults/nzlottoresults
for i in {1..1546}; do
# For numbers below 9 we need to convert to e.g. 09
if [[ "$i" -le 9 ]]; then
j=$(sed 's/\<[0-9]\>/0&/' <<< "$i")
else
j="$i"
fi
# grep out the draw numbers and into an array
drawArray=( $(grep "Draw $j:" "${resultsFile}" | cut -d: -f2-) )
# Set the bonusball
bBall="${drawArray[6]}"
# if the array has 8 numbers, then we set the powerball
if [[ "${#drawArray[@]}" -eq 8 ]]; then
pBall="${drawArray[7]}"
fi
inputFile="${inputDir}/result-$i"
while IFS= read -r -a lineArray; do
numCount=0
bonusBall=false
powerBall=false
for num in "${drawArray[@]:0:5}"; do
if [[ "${lineArray[@]}" =~ ${num} ]]; then
let numCount++
fi
done
# Now check the bonus ball
if [[ "${lineArray[@]:0:6}" =~ ${bBall} ]]; then
bonusBall=true
fi
# Now check the power ball
if [[ -n "${pBall}" ]] && [[ "${lineArray[7]}" = "${pBall}" ]]; then
powerBall=true
fi
# Results
# We need more than two matches to bother checking further
if [[ ${numCount} -ge 2 ]]; then
# Division 7 Powerball
if [[ "${numCount}" -eq 3 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 7 winner WITH POWERBALL!"
fi
# Division 6 Lotto (three matches incl Bonus Ball a.k.a two matches excl Bonus Ball)
if [[ "${numCount}" -eq 2 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 6 winner!"
# Division 6 Powerball
elif [[ "${numCount}" -eq 2 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 6 winner WITH POWERBALL!"
fi
# Division 5 Lotto
if [[ "${numCount}" -eq 4 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 5 winner!"
# Division 5 Powerball
elif [[ "${numCount}" -eq 4 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 5 winner WITH POWERBALL!"
fi
# Division 4 Lotto
if [[ "${numCount}" -eq 3 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 4 winner!"
# Division 4 Powerball
elif [[ "${numCount}" -eq 3 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 4 winner WITH POWERBALL!"
fi
# Division 3 Lotto
if [[ "${numCount}" -eq 5 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 3 winner!"
# Division 3 Powerball
elif [[ "${numCount}" -eq 5 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 3 winner WITH POWERBALL!"
fi
# Division 2 Lotto
if [[ "${numCount}" -eq 4 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 2 winner!"
# Division 2 Powerball
elif [[ "${numCount}" -eq 4 ]] && [[ "${bonusBall}" = true ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 2 winner WITH POWERBALL!"
fi
# Division 1 Lotto
if [[ "${numCount}" -eq 6 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = false ]]; then
printf "%s\n" "Draw $i: Division 1 winner!"
# Division 1 Powerball
elif [[ "${numCount}" -eq 6 ]] && [[ "${bonusBall}" = false ]] && [[ "${powerBall}" = true ]]; then
printf "%s\n" "Draw $i: Division 1 winner WITH POWERBALL!"
fi
fi
done < <(tail -10 "${inputFile}" | tr -d "|")
done