Jump to content

Lottery - Challenge


Recommended Posts

  • Moderators

guinness,

16 lines (although I have added comments and the possibility for a sneak peek at the result to check it works): :)

;#include <Array.au3> ; Uncomment to see answer

; Create an array and set 7 unique elements
Global $aCheck[52]
Do
    $iRandom = Random(1, 50, 1)
    If Not $aCheck[$iRandom] Then
        $aCheck[$iRandom] = 1
        $aCheck[0] +=1
    EndIf
Until $aCheck[0] = 7

;_ArrayDisplay($aCheck, "", Default, 8) ; Uncomment to see answer

; Get the 7 choices
For $iChoice In StringSplit(InputBox("Enter 7 numbers", "From 1-50, comma or space delimited"), " ,", 2)
    ; Count the choices
    $aCheck[51] += 1
    ; Check against the selections and prevent double counts
    If $iChoice > 0 And $iChoice < 51 And $aCheck[$iChoice] Then
        $aCheck[$iChoice] = ""
        $aCheck[0] -= 1
    EndIf
Next
; Give the result
ConsoleWrite( ( ($aCheck[51] = 7) ? (($aCheck[0]) ? ("Lost") : ("Won")) : ("Enter 7 numbers"))& @CRLF)
You can insert the choices in any order - double choices are not honoured - must have 7 choices.

M23

Edited by Melba23
Added bounds check for choices

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

  • Moderators

mikell,

Yes, but it does not count it as a valid match twice (I did say "double choices are not honoured ") - try it and see. ;)

M23

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

Wow so many posts, so thanks to sahsanu,czardas, nitekram (again! super awesome), jguinch (very nice), Melba23.

By the way I ran you code and got Variable used without being declared.: for $iMax.

To all,

So far jguinch is top of the leader board, but I will let this competition run for another day or so before closing.

czardas,

I think these are good because it makes a change from all the support questions we get around here. I was also hoping the coders who stay in Chat might give it a go too, but one can only hope!

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,

Oops. Added a line from a more advanced version - try again now. ;)

M23

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

Thanks.

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

Mine is a bit long but it was fun trying ...

#include<Array.au3>
local $num,$count=0,$winningNums[7],$loser=true, $correctNums
while($count<UBound($winningNums-1))
    $num=round(Random(1,50),0)
    if _ArraySearch($winningNums,$num)= -1 Then
        _arrayPush($winningNums,$num)
        $count+=1
    EndIf
WEnd
while $loser=true
$playerString=InputBox("enter your numbers","enter 7 unique comma separated nums from 1-50")
dim $playerNums=StringSplit($playerString,",")
dim $uniqueCheck=_ArrayUnique($playerNums)
if $uniqueCheck[1] <> ubound($winningNums) Then
    MsgBox("","Error","Your numbers are not unique, please try again")
EndIf
for $a=0 to UBound($winningNums)-1
    if _arraySearch($playerNums,$winningNums[$a])<>-1 Then
        $correctNums+=1
    EndIf
    if $correctNums=7 Then
        MsgBox("","","you win!")
        $loser=False
    EndIf
Next
WEnd
Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

What about a 3-liner ? :D

Do
   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) ) , UBound(StringRegExp(StringRegExpReplace($comp[0], '\b(\d+)\b(?=.*\b\1\b.*)', ''), '\d+', 3) ), (($comp[1] = 7) ? (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)) : Sleep(1) ), (($comp[2] <> "") ? StringRegExp($comp[2], '^([1-4]?[0-9],){6}[1-4]?[0-9]$') : MsgBox(5, "", "invalid entry, retry ?") ), UBound(StringRegExp(StringRegExpReplace($comp[0] &","& $comp[2], '\b(\d+)\b(?=.*\b\1\b.*)', ''), '\d+', 3) ), (($comp[3] = 1) ? (MsgBox(0, "", "You " & (( $comp[4] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & $comp[0] & @CRLF & "Your choice : " & $comp[2] & @CRLF & @CRLF & "You found " & 14-$comp[4] & " good numbers") ) : Sleep(1) ) ]
Until $comp[3] = 1 or $comp[3] = 2

Edit

Thanks jguinch for the regex simplification

BTW conceptually I took a lot from your code  ;)

Edited by mikell
Link to comment
Share on other sites

  • Moderators

guinness,

Down to 8 lines: :)

Do
    ; Get computer generated sequence - use nonnumeric first element so Number returns 0
    $vComputer = "=," & Random(1, 50, 1) & "," & Random(1, 50, 1) & "," & Random(1, 50, 1) & "," & Random(1, 50, 1) & "," & Random(1, 50, 1) & "," & Random(1, 50, 1) & "," & Random(1, 50, 1)
    ; Uncomment to cheat <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; ConsoleWrite("Computer: " & $vComputer & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<
    ; Get user input if no duplicates in computer list
    $sInput = ( (StringRegExp($vComputer, "(?U)([^,]+),(?=(?:[^,]*,)*?\1(?:,|$))")) ? ("") : (StringReplace(InputBox("Enter 7 numbers", "Between 1-50, comma/space delimited"), " ", ",")) )
; Check no duplicates in user list and that list has correct number of values
Until StringRegExp($sInput, "(?U)([^,]+),(?=(?:[^,]*,)*?\1(?:,|$))") = 0 And StringSplit($sInput, ",")[0] = 7
; Loop through the computer values
For $sElement in StringSplit($vComputer, ",", 2)
    ; Check for exact match with user input - leading and trailing commas prevent part matches - add number of matches to start of computer string
    If StringInStr("," & $sInput & ",", "," & $sElement & ",") <> 0 Then $vComputer = (Number(Stringleft($vComputer, 1)) + 1) & $vComputer
Next
; Give result
ConsoleWrite( ( (StringLeft($vComputer, 1) = 7) ? ("Won") : ("Lost") ) & " - Computer: " & StringTrimLeft($vComputer, StringInStr($vComputer, ",")) & " - User: " & $sInput & @CRLF)
At least mine is just about understandable! :D

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

Mikell, your mastering Regular Expressions ridiculed me! :unsure:

Just one thing, you can replace this : StringReplace(StringRegExpReplace($comp[0], 'b(d+)b(?=.*b1b.*)', ''), ",,", ",")

I used this replacement because I'm not very good with regexps.

Congratulations my friend !

Link to comment
Share on other sites

another attempt

Only raw autoit code (also no regexp usage :( )

all rules cheched

(Before shave version)

Global $a[50][2], $in1 = StringStripWS(StringReplace(InputBox("Lottery", "Please enter 7 numbers (ranging from 1 to 49)"), ",", " "), 7), $in2, $in = StringSplit($in1, " ,"), $Strike = 0, $x0 = 1, $x1 = 49, $x3 = 7
For $i = 1 To UBound($in) - 1
    If $in[0] <> $x3 Or $in[$i] < $x0 Or $in[$i] > $x1 Then Exit MsgBox(0, "Wrong input", "your input does not conform with guinness's rules")
    If $a[$in[$i]][1] Then Exit MsgBox(0, "Wrong input", "your entered duplicate numbers")
    $a[$in[$i]][1] = Int($in[$i]) + SetRnd(Random(1, 49, 1)) ; <-- added Int()
Next
For $i = 1 To UBound($in) - 1
    $Strike += $a[$in[$i]][0] = $a[$in[$i]][1]
Next
MsgBox(0, "Result", "You entered this " & UBound($in) - 1 & " numbers:" & @CR & @CR & $in1 & @CR & @CR & "of which " & $Strike & " matching to those random generated by PC" & @CR & @CR & $in2)
Func SetRnd($rnd)
    If $a[$rnd][0] Then SetRnd(Random(1, 49, 1))
    If Not $a[$rnd][0] Then
        $a[$rnd][0] = $rnd
        $in2 &= $rnd & " "
    EndIf
EndFunc   ;==>SetRnd

EDIT:

shaved out 2 unnecessary lines of code (15 lines now)
it should work as well

also added an Int() statement

a bit shaved new version ( 12 lines now)

Global $a[50][2], $in1 = StringStripWS(StringReplace(InputBox("Lottery", "Please enter 7 numbers (ranging from 1 to 49)"), ",", " "), 7), $in2, $in = StringSplit($in1, " ,"), $Strike = 0, $x0 = 1, $x1 = 49, $x3 = 7
For $i = 1 To UBound($in) - 1
    If $in[0] <> $x3 Or $in[$i] < $x0 Or $in[$i] > $x1 Then Exit MsgBox(0, "Wrong input", "your input does not conform with guinness's rules")
    If $a[$in[$i]][1] Then Exit MsgBox(0, "Wrong input", "your entered duplicate numbers")
    $a[$in[$i]][1] = Int($in[$i]) + SetRnd(Random(1, 49, 1))
Next
MsgBox(0, "Result", "You entered this " & UBound($in) - 1 & " numbers:" & @CR & @CR & $in1 & @CR & @CR & "of which " & ($a[$in[1]][0] = $a[$in[1]][1]) + ($a[$in[2]][0] = $a[$in[2]][1]) + ($a[$in[3]][0] = $a[$in[3]][1]) + ($a[$in[4]][0] = $a[$in[4]][1]) + ($a[$in[5]][0] = $a[$in[5]][1]) + ($a[$in[6]][0] = $a[$in[6]][1]) + ($a[$in[7]][0] = $a[$in[7]][1]) & " matching to those random generated by PC" & @CR & @CR & $in2)
Func SetRnd($rnd) ; this generates unique random numbers
    If $a[$rnd][0] Then SetRnd(Random(1, 49, 1)) ; iterate if already existent
    If Not $a[$rnd][0] Then $in2 &= $rnd & " "
    $a[$rnd][0] = $rnd
EndFunc   ;==>SetRnd

could be removed 2 other lines of code, but this would result in a (too) long horizzontal line of code ( I do not like)

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Similar to the zero in roulette, which is the only thing that makes the "game" profitable to casinos.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Don't forget the rules ;) 7 whole numbers 1-49, no duplicates in both the user's and computer's choice, all 7 must match.

mikell, 

Nice. Passed my testing.

Melba23,

Numbers out of the range are excepted it seems. Other than that it passed my tests.

PincoPanco,

Seems to pass my tests.

Great everyone.

Edit: Retracted some smiley faces. I have used my quota for the year in this one thread.

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

  • Moderators

guinness,

 

Numbers out of the range are excepted it seems

But will never match. i am still working on how to prevent them altogether. ;)

Sorry about the 49/50 mixup - at least the user was told to choose 1-50!! :D

M23

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

In my version it reported an input error, win or lose. The win or lose was only if the input was valid.

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

Here's my final entry - based on the premise that you have exactly the same chance of winning the lottery whether 7 numbers are generated, by the computer, or not. There is a 1 in 432938943360 chance you will hit the jackpot - which amounts to the same thing. In fact only error checking for the input is missing. Can you fix that without adding an extra 2 lines of code?

MsgBox(InputBox("","Enter 7 numbers 1 - 49")*0,"Lottery","You "&StringLeft("did not ",(Random(0,432938,1)&Random(1,943360,1)<>49*48*47*46*45*44*43)*8)&"win")

;

Fixed - Computer generated 12 digit random number was not exactly correct. It should be accurate now.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

guinness,

The user now cannot enter a value > 49 - still 8 lines: :)

Do
    ; Get computer generated sequence - use nonnumeric first element so Number returns 0
    $vComputer = "=," & 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)
    ; Uncomment to cheat <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; ConsoleWrite("Computer: " & $vComputer & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<
    ; Get user input if no duplicates in computer list
    $sInput = ( (StringRegExp($vComputer, "(?U)([^,]+),(?=(?:[^,]*,)*?\1(?:,|$))")) ? ("") : (StringReplace(InputBox("Enter 7 numbers", "Between 1-49, comma/space delimited"), " ", ",")) )
; Check no duplicates in user list - 7 user numbers are 1-49
Until StringRegExp($sInput, "(?U)([^,]+),(?=(?:[^,]*,)*?\1(?:,|$))") = 0 And StringRegExp($sInput, "^(([1-9]|[1-4][0-9])(,|$)){7}") = 1
; Loop through the computer values
For $sElement in StringSplit($vComputer, ",", 2)
    ; Check for exact match with user input - leading and trailing commas prevent part matches - add number of matches to start of computer string
    If StringInStr("," & $sInput & ",", "," & $sElement & ",") <> 0 Then $vComputer = (Number(Stringleft($vComputer, 1)) + 1) & $vComputer
Next
; Give result
ConsoleWrite( ( (StringLeft($vComputer, 1) = 7) ? ("Won") : ("Lost") ) & " - Computer: " & StringTrimLeft($vComputer, StringInStr($vComputer, ",")) & " - User: " & $sInput & @CRLF)
M23

Edit: Now gives number of matches in result

Edited by Melba23

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

Last try -- added a little precision to the error checking

Do
  Local $a[] = [(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) ), ((UBound(StringRegExp(StringRegExpReplace($a[0], '\b(\d+)\b(?=.*\b\1\b.*)', ''), '\d+', 3) ) = 7) ? (InputBox("Lottery", "Enter 7 numbers from 1 to 49 separated by a comma", "1,2,3,4,5,6,7", "", 500, 150)) : "#¤$" ), ((($a[1] <> "") ? ((StringRegExp($a[1], '^([1-4]?[0-9],){6}[1-4]?[0-9]$')) ? 9 : (($a[1] <> "#¤$") ? MsgBox(0, "", "please enter a valid sequence") : 0)) : MsgBox(5, "", "want to quit, or retry ?") )), UBound(StringRegExp(StringRegExpReplace($a[0] &","& $a[1], '\b(\d+)\b(?=.*\b\1\b.*)', ''), '\d+', 3) ), (($a[2] = 9) ? (MsgBox(0, "", "You " & (( $a[3] = 7 ) ? "win" : "loose" ) & @CRLF & @CRLF & "Computer choice : " & $a[0] & @CRLF & "Your choice : " & $a[1] & @CRLF & @CRLF & "You found " & 14-$a[3] & " good numbers")) : Sleep(1))]
Until $a[2] = 9 or $a[2] = 2
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...