Mia Posted December 15, 2016 Share Posted December 15, 2016 Hi, Any idea how to find all possible combinations of numbers of a chain of 4 numbers. (a lot of ) Example: 0123 0124 0125 0126 0127 ... and so on until 9999 Big thanks! Link to comment Share on other sites More sharing options...
jchd Posted December 15, 2016 Share Posted December 15, 2016 (edited) Do you mean 0 to 9999 or something else? As numbers (no leading zeros) or as strings? Which form should have the result: array or whatelse? Try to use more precise terms else you'll get fuzzy/wrong anwsers. Edited December 15, 2016 by jchd 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Mia Posted December 16, 2016 Author Share Posted December 16, 2016 2 minutes ago, jchd said: Do you mean 0 to 9999 or something else? As numbers (no leading zeros) or as strings? Which form should have the result: array or whatelse? Try to use more precise terms else you'll get fuzzy/wrong anwsers. As strings. Example: 0001 counts as 4 chars. Link to comment Share on other sites More sharing options...
iamtheky Posted December 16, 2016 Share Posted December 16, 2016 for $n = 0 to 9999 msgbox(0, '' , StringFormat("%04i" , $n)) next ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Mia Posted December 16, 2016 Author Share Posted December 16, 2016 Results can simply be shown in console with ConsoleWrite to make it simple (sorry for the double post, can't find the edit button) Link to comment Share on other sites More sharing options...
SadBunny Posted December 16, 2016 Share Posted December 16, 2016 Here's another very fast algorithm: #include <Array.au3> Dim $aList[0] Do $x = StringFormat("%04i", Random(0, 9999, 1)) If _ArraySearch($aList, $x) == -1 Then ReDim $aList[UBound($aList)] _ArrayAdd($aList, $x) EndIf Until UBound($aList) = 10000 _ArraySort($aList) _ArrayDisplay($aList) Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Mia Posted December 16, 2016 Author Share Posted December 16, 2016 Thanks everyone! Link to comment Share on other sites More sharing options...
InunoTaishou Posted December 16, 2016 Share Posted December 16, 2016 Or this #include <Array.au3> Global $aNumbers[10000] For $i = 0 to UBound($aNumbers) - 1 $aNumbers[$i] = StringFormat("%04i", $i) Next _ArrayDisplay($aNumbers) Link to comment Share on other sites More sharing options...
RTFC Posted December 16, 2016 Share Posted December 16, 2016 Also check out _ArrayPermute. 8 hours ago, SadBunny said: another very fast algorithm @SadBunny: ReDim inside a loop is actually slowing the script down needlessly. Instead, I would just allocate the array once outside the loop and apply an upper bound in _ArraySearch that increments on successive iterations. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
kylomas Posted December 16, 2016 Share Posted December 16, 2016 @RTFC - 16 minutes ago, RTFC said: another very fast algorithm That may have been "tongue in cheek". Note the random list that is generated, then sorted. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
RTFC Posted December 16, 2016 Share Posted December 16, 2016 (edited) 12 minutes ago, kylomas said: That may have been "tongue in cheek". @kylomas: I think we need an emoji for that. I missed that, and maybe the OP would too. Edited December 16, 2016 by RTFC My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
SadBunny Posted December 16, 2016 Share Posted December 16, 2016 No, RTFC is right. The untold millions of random numbers that the script searches the array for would be much faster inserted in that array, had it not to redim the array ten thousand times The speed difference between iamtheky's slow and inefficient procedure and my much superior solution using RNG and array manipulation (which if nothing else at least sounds more Random (1337,1337,1)...) should be immediately clear when running both scripts. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
iamtheky Posted December 16, 2016 Share Posted December 16, 2016 That is barely passable as prng, and the speed difference is only evident because I msgbox the return. At some point you have to loop through contents and format strings, any hopes of being superior at that are delusional. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted December 16, 2016 Share Posted December 16, 2016 3 hours ago, kylomas said: 3 hours ago, RTFC said: another very fast algorithm That may have been "tongue in cheek". Note the random list that is generated, then sorted. kylomas +1 _ArraySearch + ReDim + _ArrayAdd = HighSpeed (well known) Link to comment Share on other sites More sharing options...
SadBunny Posted December 16, 2016 Share Posted December 16, 2016 41 minutes ago, mikell said: _ArraySearch + ReDim + _ArrayAdd = HighSpeed (well known) See? Thanks. Finally someone who understands. The proof of the pudding is in the selection of random pudding molecules and then eating them, but only if they don't equal any of the molecules you have already eaten. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
iamtheky Posted December 16, 2016 Share Posted December 16, 2016 ahh, the Bayesian solution to the ever difficult maths problem of N + 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
kylomas Posted December 16, 2016 Share Posted December 16, 2016 Ok, bars open. All y'all need a drinkl! Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
czardas Posted December 16, 2016 Share Posted December 16, 2016 (edited) StringFormat() is slightly slower than concatenation: $number = StringTrimLeft('000' & $number, 4). Edited December 16, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
iamtheky Posted December 16, 2016 Share Posted December 16, 2016 (edited) wouldnt you want to stringright, 4? Edited December 16, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jchd Posted December 17, 2016 Share Posted December 17, 2016 You were talking to @sadrazc, right? czardas 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now