Jump to content

Finding all possible combinations of numbers


Mia
 Share

Recommended Posts

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

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

for $n = 0 to 9999
    msgbox(0, '' , StringFormat("%04i" , $n))
next

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

12 minutes ago, kylomas said:

That may have been "tongue in cheek".

@kylomas: :DI think we need an emoji for that. I missed that, and maybe the OP would too.

Edited by RTFC
Link to comment
Share on other sites

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 :shifty:

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

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

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

ahh, the Bayesian solution to the ever difficult maths problem of N + 1

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

wouldnt you want to stringright, 4?

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

You were talking to @sadrazc, right?

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...