Jump to content

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

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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."

From my dad

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

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

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

Link to comment
Share on other sites

It's an awesome start, cheers nitekram. I haven't started with my version unless someone wants me to?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

guinness,

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

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

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

Link to comment
Share on other sites

I will wait about 4 days or so. Though I am sure someone will come up with idea I have in mind.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You might want to check your code again.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
Link to comment
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
Link to comment
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."

From my dad

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

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

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

Link to comment
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."

From my dad

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

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

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

Link to comment
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
Link to comment
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 ?

Link to comment
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."

From my dad

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

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...