Jump to content
UBot Underground

Generate All Possible Combinations


Recommended Posts

I need this pretty often, I could not find it anywhere on here so, for the next person that wishes to:

 

1. import 3 lists

2. export all possible combinations of the 3 lists

 

I made a simple little UI, you will need to write in your variables or import from text files then just hit run.

 

Enjoy.

 

comment ("gpv - ui")
ui block text("var 1",#var_01)
ui open file("",#var_01)
ui block text("var 2",#var_02)
ui open file("",#var_02)
ui block text("var 3",#var_03)
ui open file("",#var_03)
ui block text("output",#output)
ui button("run") {
    input_to_list()
    loop_process()
}
comment ("gpv - create lists from variables")
define input_to_list {
    clear_vars_lists()
    add list to list(%var_01,$list from text(#var_01,$new line),"Delete","Global")
    add list to list(%var_02,$list from text(#var_02,$new line),"Delete","Global")
    add list to list(%var_03,$list from text(#var_03,$new line),"Delete","Global")
    set_pos_0()
}
comment ("gpv - set all var positions to 0")
define set_pos_0 {
    set(#var_01_pos,0,"Global")
    set(#var_02_pos,0,"Global")
    set(#var_03_pos,0,"Global")
}
comment ("gpv - this is the loop, the main and most important element, it will process all 3 variable lists to output all possible combinations")
define loop_process {
    clear list(%output)
    set(#var_01_pos,0,"Global")
    loop($list total(%var_01)) {
        set(#var_02_pos,0,"Global")
        loop($list total(%var_02)) {
            set(#var_03_pos,0,"Global")
            loop($list total(%var_03)) {
                set(#temp,$nothing,"Global")
                set(#temp,"{$list item(%var_01,#var_01_pos)} {$list item(%var_02,#var_02_pos)} {$list item(%var_03,#var_03_pos)}","Global")
                add item to list(%output,#temp,"Delete","Global")
                set(#temp,$nothing,"Global")
                increment(#var_03_pos)
            }
            increment(#var_02_pos)
        }
        increment(#var_01_pos)
    }
    clear_vars_lists()
    set_pos_0()
    set_vars_nothing()
    set(#output,$text from list(%output,$new line),"Global")
}
comment ("gpv - clear input vars")
define set_vars_nothing {
    set(#var_01,$nothing,"Global")
    set(#var_02,$nothing,"Global")
    set(#var_03,$nothing,"Global")
}
comment ("gpv - clear input lists")
define clear_vars_lists {
    clear list(%var_01)
    clear list(%var_02)
    clear list(%var_03)
}

generate_all_possible_combinations.ubot

Edited by GoTRooT
  • Like 2
Link to post
Share on other sites

Looks good and it made me think what if you could accept any number of lists and do this. Use a list to store each list in a list item and make a crazy amount of variations. Although I'm not sure what I'd use it for  :lol:

  • Like 2
Link to post
Share on other sites
  • 3 weeks later...

Looks good and it made me think what if you could accept any number of lists and do this. Use a list to store each list in a list item and make a crazy amount of variations. Although I'm not sure what I'd use it for  :lol:

 

:D I read your answer, took a look at the code and the first thing that comes to my mind was to add a kind of level 1 loop that would be run as many times as the user want (ui input) and this way you could combines like 10, 20 or how many lists you freakin want to, to infinity...

 

Plus multiple threads all the way so the number of combinations would grow expotentionally :D

Thanks to both of you guys for making my brain do some abstract thinking B)

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...