# Lottery - Challenge

## Recommended Posts

Last time I had a >Paper, Rock, Scissors - Challenge and now I think it's time for a new one.

Challenge: Create a lottery game with the least amount of lines in AutoIt. The user should be prompted to enter a string of 7 lottery numbers from 1 to 49 and have either a comma (,) or single space as the delimiter e.g. 1,5,10,37,15,43,2. It should be checked against 7 random numbers to see if they all match. If all 7 match then they win, otherwise they lose. The numbers should be valid and contain zero duplicates in both the user's choice and computer generated sequence.

Good luck.

Note: I am not playing this time around as some people said it was unfair that I took part last time. Oh and serious contenders need only apply please.

PS. I created this in C# using 4 lines of code when the idea was presented to me by a mate...so yeah...good luck! -_0

NO /AutoItExecuteScript workarounds.

Edited by guinness

• Replies 74
• Created

#### Top Posters In This Topic

I know that it is more then 4 lines, but thought I would give it a shot: 37 with blank lines and winner/loser msgbox

```#include<array.au3>

Local \$sNumbers, \$aNumbers, \$aLottery[7], \$bDupe1 = False, \$bDupe2 = False, \$iCount = 0, \$sTemp = '', \$bFailed = False

Do
\$bFailed = False
\$sNumbers = InputBox('Lottery', 'Pick 7 unique numbers 1-49, separate the numbers with a comma!')
;\$sNumbers = '1,2,3,4,5,6,7'
\$aNumbers = StringSplit(\$sNumbers, ',', 2)
\$aNumbers = _ArrayUnique(\$aNumbers)

For \$x = 0 To UBound(\$aLottery) - 1
\$aLottery[\$x] = Random(1, 49, 1)
If \$aNumbers[\$x] > 49 Or \$aNumbers[\$x] < 1 Then \$bFailed = True
Next
\$aLottery = _ArrayUnique(\$aLottery)

Until UBound(\$aNumbers) = 8 And UBound(\$aLottery) = 8 And \$bFailed = False

\$iCount = 0
For \$x = 1 To UBound(\$aLottery) - 1
For \$y = 1 To UBound(\$aNumbers) - 1
If \$aNumbers[\$y] = \$aLottery[\$x] Then
\$sTemp &= \$aNumbers[\$y] & ' vs ' & \$aLottery[\$x] & @CRLF
ConsoleWrite(\$aNumbers[\$y] & ' vs ' & \$aLottery[\$x] & @CRLF)
\$iCount += 1
EndIf

If \$iCount = 7 Then ExitLoop 2
Next
Next

If \$iCount = 7 Then
MsgBox('', 'Jackpot Winner', 'Your numbers matched the lottery numbers - pick up your prices ' & \$sNumbers)
Else
MsgBox('', 'Jackpot Loser', 'Failed to pick the winning numbers ' & @CRLF & @CRLF & 'Your numbers = ' & \$sNumbers & @CRLF & 'Pick numbers = ' & _ArrayToString(\$aLottery, ',', 1))
EndIf```

I will try again, when I have more time, but I want to see someone do it 4 lines - lol

edit, had to change condition for \$aLottery, was not checking the size

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

• Moderators

guinness,

By all means join in - just do not declare yourself the winner!

But I would wait a while to see what others come up with first.

M23

Edited by Melba23
Typo

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

##### Share on other sites

9 lines

Edit

Failed... try again

Edited by mikell

##### Share on other sites

Array.au3 is about a thousand lines.

Monkey's are, like, natures humans.

##### Share on other sites

Array.au3 is about a thousand lines.

Includes I am not excepting in the line count, otherwise my 4 line C# version wouldn't be 4 lines.

##### Share on other sites

I started to script this challenge just because no one replied.... but now, I can see my script is a bit longer than expected... ;-). Anyway, I think it works with all the requirements so, one more for the collection :-P.

```#include <array.au3>
Local \$aArray[49], \$sCombination = "", \$counter = 0, \$sRightNumbers = ""
For \$i = 0 To UBound(\$aArray) - 1
\$aArray[\$i] = \$i + 1
Next
For \$i = UBound(\$aArray) - 1 To UBound(\$aArray) - 7 Step -1
\$iRandom = Random(0, \$i, 1)
\$sCombination &= \$aArray[\$iRandom] & ","
_ArrayDelete(\$aArray, \$iRandom)
Next
\$aWinner = StringSplit(StringTrimRight(\$sCombination, 1), ",")
\$sInput = InputBox("Lottery numbers", "Write 7 numbers from 1 to 49 separated by single space or comma")
\$aInput = StringSplit(\$sInput, " ,")
\$aUnique = _ArrayUnique(\$aInput, 1, 1)
If \$aUnique[0] <> 7 Then
MsgBox(16, "Error", "You must use 7 different numbers")
Exit 1
Else
For \$i = 1 To 7
\$aUnique[\$i] = Number(\$aUnique[\$i])
\$aWinner[\$i] = Number(\$aWinner[\$i])
If \$aInput[\$i] <= 49 Then
\$iSearch = _ArraySearch(\$aWinner, \$aInput[\$i])
If Not @error Then
\$sRightNumbers &= \$aInput & ","
\$counter += 1
EndIf
Else
MsgBox(16, "Error", "Only numbers from 1 to 49 are allowed")
Exit 1
EndIf
Next
EndIf
_ArraySort(\$aWinner, 0, 1)
_ArraySort(\$aUnique, 0, 1)
If \$counter = 7 Then
MsgBox(64, "Yeaaah " & \$counter & " from 7", "Lottery numbers: " & _ArrayToString(\$aWinner, ", ", 1) & @CRLF & "Your numbers : " & _ArrayToString(\$aUnique, ", ", 1) & @CRLF & "Congratulations, you got the 1st prize ;-)")
Else
MsgBox(64, "oooooh " & \$counter & " from 7", "Lottery numbers: " & _ArrayToString(\$aWinner, ", ", 1) & @CRLF & "Your numbers : " & _ArrayToString(\$aUnique, ", ", 1) & @CRLF & "I'm sorry but you have lost, keep playing :-P")
EndIf```
##### Share on other sites

4 lines of code

Edited by FireFox
##### Share on other sites

No, includes, no error checks and no ternary operator. If you enter an empty string you will confuse it. You have to check yourself that you have entered 7 unique numbers between 1 and 49 separated by spaces otherwise you might think you have won when you haven't. An additional error check would require an extra line of code.

```Local \$a2[3] = ["lost","won",5 & Random(1,49,1)]
While Not StringInStr(\$a2[2],"|",0,6)
\$a2[2] = StringRegExpReplace(\$a2[2] & StringRegExpReplace(\$a2[2] & "|" & 5 & Random(1,49,1) , "(" & \$a2[2] & ")", "")  , "\|+", "|")
WEnd
MsgBox(0, "Lottery", "You " & \$a2[StringStripWS(StringRegExpReplace(StringRegExpReplace(InputBox("Enter 7 Numbers",""), "(\A| )", "5"), "("&\$a2[2]&")", ""), 8) = ""])```

:

Edit : Changed one word in the description.

Edited by czardas
##### Share on other sites

Second shot - 21 lines

```#include<array.au3>

Local \$sNumbers, \$aNumbers, \$aLottery[7], \$bDupe1 = False, \$bDupe2 = False, \$iCount = 0, \$sTemp = '', \$bFailed = False

Do
\$bFailed = False
\$aNumbers = _ArrayUnique(StringSplit(InputBox('Lottery', 'Pick 7 unique numbers 1-49, separate the numbers with a comma!'), ',', 2))

For \$x = 0 To UBound(\$aLottery) - 1
\$aLottery[\$x] = Random(1, 49, 1)
If \$aNumbers[\$x] > 49 Or \$aNumbers[\$x] < 1 Then \$bFailed = True
Next
\$aLottery = _ArrayUnique(\$aLottery)

Until UBound(\$aNumbers) = 8 And UBound(\$aNumbers) = 8 And \$bFailed = False

For \$x = 1 To UBound(\$aLottery) - 1
For \$y = 1 To UBound(\$aNumbers) - 1
If \$aNumbers[\$y] = \$aLottery[\$x] Then \$iCount += 1

If \$iCount = 7 Then
MsgBox('', 'Jackpot Winner', 'Your numbers matched the lottery numbers - pick up your prices ' & \$sNumbers)
ExitLoop 2
EndIf
Next
Next

If \$iCount <> 7 Then MsgBox('', 'Jackpot Loser', 'Failed to pick the winning numbers ' & @CRLF & @CRLF & 'Your numbers = ' & _ArrayToString(\$aNumbers, ',', 1) & @CRLF & 'Pick numbers = ' & _ArrayToString(\$aLottery, ',', 1))```

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

19 lines, but I can drop 3 more if I do not report that they lost, only if they won...

16 lines lied

18, after double checking

back to 17 lines

```#include<array.au3>
Local \$aNumbers, \$aLottery[7], \$iCount = 0, \$bFailed = False, \$swon = False

Do
\$bFailed = False
\$aNumbers = _ArrayUnique(StringSplit(InputBox('Lottery', 'Pick 7 unique numbers 1-49, separate the numbers with a comma!'), ',', 2))
If UBound(\$aNumbers) <> 8 Then ContinueLoop
For \$x = 0 To UBound(\$aLottery) - 1
\$aLottery[\$x] = Random(1, 49, 1)
If \$aNumbers[\$x+1] > 49 Or \$aNumbers[\$x+1] < 1 And \$x = 6 Then \$bFailed = True
Next
\$aLottery = _ArrayUnique(\$aLottery)

Until UBound(\$aNumbers) = 8 And UBound(\$aNumbers) = 8 And \$bFailed = False

For \$x = 0 To UBound(\$aLottery) - 1
If _ArraySearch(\$aLottery, \$aNumbers[\$x], 1) <> -1 Then \$iCount += 1
Next

If \$iCount = 7 Then \$swon = True

MsgBox('', 'Jackpot ' & \$swon, 'Numbers:' & @CRLF & @CRLF & 'Your numbers = ' & _ArrayToString(\$aNumbers, ',', 1) & @CRLF & 'Pick numbers = ' & _ArrayToString(\$aLottery, ',', 1))```
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

Is the ternary operator allowed ?

##### Share on other sites

Everything except what's written in red on the 1st post.

##### Share on other sites

This is a great idea of yours guinness: a bit of light relief from all the complicated stuff I find myself working on nowadays. I didn't take a look at the paper rock scissors thread, so I didn't realise it was a challenge. Anyway my contribution doesn't quite fulfil all the criteria, so it's wide open everyone.

Edited by czardas
##### Share on other sites

OK, I have 4 lines, with error checks, using the ternary operator (of course) !

```While @error = 0
Local \$comp[] = [ ( Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) ) , SetError( (     UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) = 7 ) ? 1 : 0  ) ]
WEnd
Local \$a[] = [ InputBox("Lottery", "Enter your numbers from 1 to 49, separates by a comma (ex : 1,5,10,37,15,43,2)", "1,2,3,4,5,6,7", "", 500, 150) , (   StringRegExp(\$a[0], "^(([1-9]|([1-4]\d)),){6}([1-9]|([1-4]\d))\$")   ) ? 1 : (0 * MsgBox(16, "Lottery", "You must enter 7 numbers, separate by a comma")) , ((\$a[1] = 0) ? 0 :     (((UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) +   UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) ) = 7 ) ? 1 : 0 * MsgBox(16, "Lottery", "You cannot choose a same number more than one time") ) ) , StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,") ) , (( \$a[2] = 0 )? 0 : MsgBox(0, "", "You " & (( \$a[3] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & \$comp[0] & @CRLF & "Your choice : " & \$a[0] & @CRLF & @CRLF & "You found " & \$a[3] & " good numbers" ) ) ]```

For more visibility, with underscores :

```While @error = 0
Local \$comp[] = [ ( Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) ) , _
SetError( ( _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) = 7 ) ? 1 : 0  ) ]

WEnd

Local \$a[] = [ InputBox("Lottery", "Enter your numbers from 1 to 49, separates by a comma (ex : 1,5,10,37,15,43,2)", "1,2,3,4,5,6,7", "", 500, 150) , _
(   StringRegExp(\$a[0], "^(([1-9]|([1-4]\d)),){6}([1-9]|([1-4]\d))\$")   ) ? 1 : (0 * MsgBox(16, "Lottery", "You must enter 7 numbers, separate by a comma")) , _
((\$a[1] = 0) ? 0 : _
(((UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) ) = 7 ) ? 1 : 0 * MsgBox(16, "Lottery", "You cannot choose a same number more than one time") ) ) , _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,") ) , _
(( \$a[2] = 0 )? 0 : _
MsgBox(0, "", "You " & (( \$a[3] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & \$comp[0] & @CRLF & "Your choice : " & \$a[0] & @CRLF & @CRLF & "You found " & \$a[3] & " good numbers" ) _
) _
]```

Is this OK ?

##### Share on other sites

OK, I have 4 lines, with error checks, using the ternary operator (of course) !

```While @error = 0
Local \$comp[] = [ ( Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) ) , SetError( (     UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) +    UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) = 7 ) ? 1 : 0  ) ]
WEnd
Local \$a[] = [ InputBox("Lottery", "Enter your numbers from 1 to 49, separates by a comma (ex : 1,5,10,37,15,43,2)", "1,2,3,4,5,6,7", "", 500, 150) , (   StringRegExp(\$a[0], "^(([1-9]|([1-4]\d)),){6}([1-9]|([1-4]\d))\$")   ) ? 1 : (0 * MsgBox(16, "Lottery", "You must enter 7 numbers, separate by a comma")) , ((\$a[1] = 0) ? 0 :     (((UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) +   UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) +  UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) ) = 7 ) ? 1 : 0 * MsgBox(16, "Lottery", "You cannot choose a same number more than one time") ) ) , StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,") ) + StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,") ) , (( \$a[2] = 0 )? 0 : MsgBox(0, "", "You " & (( \$a[3] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & \$comp[0] & @CRLF & "Your choice : " & \$a[0] & @CRLF & @CRLF & "You found " & \$a[3] & " good numbers" ) ) ]```

For more visibility, with underscores :

```While @error = 0
Local \$comp[] = [ ( Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) & "," &  Random (1, 49, 1) ) , _
SetError( ( _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$comp[0], ",", ",,") & "," , StringRegExpReplace(\$comp[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) = 7 ) ? 1 : 0  ) ]

WEnd

Local \$a[] = [ InputBox("Lottery", "Enter your numbers from 1 to 49, separates by a comma (ex : 1,5,10,37,15,43,2)", "1,2,3,4,5,6,7", "", 500, 150) , _
(   StringRegExp(\$a[0], "^(([1-9]|([1-4]\d)),){6}([1-9]|([1-4]\d))\$")   ) ? 1 : (0 * MsgBox(16, "Lottery", "You must enter 7 numbers, separate by a comma")) , _
((\$a[1] = 0) ? 0 : _
(((UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,"), 3 ) ) + _
UBound( StringRegExp( "," & StringReplace(\$a[0], ",", ",,") & "," , StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,"), 3 ) ) ) = 7 ) ? 1 : 0 * MsgBox(16, "Lottery", "You cannot choose a same number more than one time") ) ) , _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){0}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){1}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){2}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){3}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){4}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){5}([^,]+).*", ",\$1,") ) + _
StringRegExp("," & \$comp[0] & ",", StringRegExpReplace(\$a[0] , "(?:[^,]+,){6}([^,]+).*", ",\$1,") ) , _
(( \$a[2] = 0 )? 0 : _
MsgBox(0, "", "You " & (( \$a[3] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & \$comp[0] & @CRLF & "Your choice : " & \$a[0] & @CRLF & @CRLF & "You found " & \$a[3] & " good numbers" ) _
) _
]```

Is this OK ?

I would say you win, I cannot even keep track of that many in one line, let alone spread out like you did - lol, my mind cannot handle it.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

## Create an account

Register a new account

• ### Similar Content

• #### Mixed Base Conversion (coding challenge)

By Gianni,

• 5 replies
• 709 views
• #### Challenge: Solving Josephus problem 1 2

By guinness,

• 31 replies
• 3,084 views
• #### Trim text in a file without storing the contents of anywhere 1 2

By TheDcoder,

• 22 replies
• 3,763 views
• #### Hey Everyone (please VOTE in Challenge)

By TheSaint,

• 3 replies
• 2,081 views
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...