Jump to content

Creating a product code from defined letters/numbers


 Share

Recommended Posts

Hi everyone

I am thinking of creating our own product codes in the form of 2 letters and 2 numbers but they need to be 8 chars in length, I know I will need to loop through but am unsure of how to start it.

Currently we use, for example January a,b,1,2 so we would want eg, aa12ab22 OR 1a2bb1a2

No character should repeat four times aaaa isn't acceptable.

How can I setup my script to produce ALL permutations of the above in one run?

Hope that's clear enough for someone to point me in the right direction

Edited by Phaser
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Not exactly certain what you need, but you might want to look at _ArrayPermute() <- helpfile

Hi JohnOne arraypermute I have looked at, it will only give me single digits without repeates also only gives the amount of gigures you give it, ie, if I give it Dim $aArray[3] = [1,2,3] it will only produce strings 3 long, I need strings of the same chars 8 long, eg 11122233 or 12311213

I've been looking on google and everything seems to be pointing towards a brute force type of loop, I have no intention to find peoples passwords but this is very close to what I want to do, I don't want to store the strings in an array I just want to write them to a file 1 at a time.

Edited by Phaser
Link to comment
Share on other sites

I beg to differ

Directlt from helpfile

#include <Array.au3>

Dim $aArray[8] = ["a","a","1","2","a","b","2","2"]
$aNewArray = _ArrayPermute($aArray, ",") ;Using Default Parameters
_ArrayDisplay($aNewArray, "Array Permuted")

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I beg to differ

Directlt from helpfile

#include <Array.au3>

Dim $aArray[8] = ["a","a","1","2","a","b","2","2"]
$aNewArray = _ArrayPermute($aArray, ",") ;Using Default Parameters
_ArrayDisplay($aNewArray, "Array Permuted")

Ah ok, that's looking helpful, how did you reach the [a,a,1,2,a,b,2,2] would the results be different if you had [a,a,1,1,b,b,2,2]
Link to comment
Share on other sites

Its how you put values into the array elements manually, you could use StringSplit() function I suppose.

And Yes, if you have different values in the array, the permutations will be different.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Its how you put values into the array elements manually, you could use StringSplit() function I suppose.

And Yes, if you have different values in the array, the permutations will be different.

mm sadly not what I am looking for, I just tried a few tests and it seems arraypermute will only do up to 10 chars, I know I said 8 but I need it to be flexible up to 12 sometimes, here's what I have so far

$letters[2]=["a","b"];Jan

$numbers[2]=[1,2];Jan

$seq_length = 8;Jan 1 to 16 set to 12 for Jan 17 onwards

So I would start with $letters[0] and generate, for example

aaabbb11

aababb11

ababbb11

Not allowing repeats more than 3 and using each char to build up my long list, what do I need to do to accomplish this, I just can't get my head around it.

@czardas; yes that is what I am after, ALL permutations of set chars and I decide the length of the string, we have not needed to go above 16 chars in the past but I would like it to be flexible

What about this? 1a2abaaa yes again, as long as no char repeats 4 times in a row, I know this will create a lot of permutations so isn't suitable to put them in an array thats why I will be printing them 1 at a time after each generation, once I have ALL possible conbinations I will be inserting them into a mysql db and assigning them to the products when needed.

Edited by Phaser
Link to comment
Share on other sites

I think you will find that there are an awful lot of results.

I hope so, how do I do it?

If someone could show me the pseudo code in steps I could fumble my way to something that may work

Edited by Phaser
Link to comment
Share on other sites

I hope so, how do I do it?

If someone could show me the pseudo code in steps I could fumble my way to something that may work

This is what I'm thinking.

1. Get permutations from the four chars to ensure all four will appear.

2. Insert patterns of one or two chars after each of the chars within the string until you have eight characters.

There are still some details to iron out.

Link to comment
Share on other sites

This is what I'm thinking.

1. Get permutations from the four chars to ensure all four will appear.

2. Insert patterns of one or two chars after each of the chars within the string until you have eight characters.

There are still some details to iron out.

Well, it mustn't do any duplicates so it should start somewhere and end when all have been produced, some sort of loop maybe? as there's going to be a lot of them, I don't think manually inserting patterns is going to work, after a while we wont know what we already have.

Edited by Phaser
Link to comment
Share on other sites

Well, it mustn't do any duplicates so it should start somewhere and end when all have been produced, some sort of loop maybe?

Providing you don't insert more than two characters after each of the unique characters in all the four character permutations, you won't get should be able to avoid any character repeating more than 3 times. The method has limits. It won't work on strings longer than 12 (4x3) chars.

Edit

This is trickier than I thought.

Edited by czardas
Link to comment
Share on other sites

Providing you don't insert more than two characters after each of the unique characters in all the four character permutations, you won't get any character repeat more than 3 times. The method has limits. It won't work on strings longer than 12 (4x3) chars.

Just looking at something I just found in php on the web, it does exactly what I want BUT allows bbbbbb21 too many bs' together, thanks for your help so far

Link to comment
Share on other sites

Don't mind me but ..

Can you not have 2 Array Permutes of 6 char each and combine them to give final figure?

Just speaking out loud ..

Chimaera

Link to comment
Share on other sites

You can probably get all permutations of eight characters with some quite simple code and just delete anything with repeats longer than three characters. The only thing that worries me is the length of time these processes will take. I was trying to find a method that cuts out unecessary permutations during the procedure. I overlooked something in the method. There are a percentage of permutations missing from my final result and I haven't figured it out yet. I also have to work right now, so it'll have to wait unless someone produces another solution, or can fix my broken one.

A possible fix is to reverse the strings I produced, add the new strings to the list and use ArrayUnique on the whole lot. You might have to wait a while for the results though.

Edited by czardas
Link to comment
Share on other sites

This is what I came up with really quick, not sure if it fits the criteria but it should work well.

#include <array.au3>
Global $Array1[4] = [1, 2, "a", "b"]
Global $Result1 = _ArrayPermute($Array1)
$Array2 = $Array1
_ArrayReverse($Array2)
Global $Result2 = _ArrayPermute($Array2)
Global $Code1[$Result2[0]][2]
For $I = 0 To UBound($Code1) - 1
    $Code1[$I][0] = $Result1[$I]
    $Code1[$I][1] = $Result2[$I]
Next

_ArrayDisplay($Code1, "8 Character code")

Global $Code2[UBound($Code1)][3]
For $I = 0 To UBound($Code2) - 1
    $Code2[$I][0] = $Result1[$I]
    $Code2[$I][1] = $Result2[$I]
    $Code2[$I][2] = $Result1[$I]
Next

_ArrayDisplay($Code2, "12 Character code")
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

How many characters are you using? Also, what do you mean a few permutations are missing? That would be quite remarkable if that were true because the _ArrayPermute function will output every possible permutation of the information fed to it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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