Creating list of possibilities/combinations

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cdev007
Posts: 11
Joined: Sun Oct 04, 2020 7:41 pm

Creating list of possibilities/combinations

Post by cdev007 » Wed Sep 01, 2021 6:03 pm

Thought I'd contribute this to the forum in case anyone in the future wants it. I don't remember the technical name for this pattern though it uses the rule of product or multiplication principle.

I was wanting to create a pattern where I could create the following pattern while being able to adjust the quantity of numbers and the maximum number.

Example

111; 112; 113; 114; 121; 122; 123; 124; 131; 132; 133 ... 442; 443; 444

So here is my code. (Its not the cleanest because I took it from my stack where other factors and variables existed) Just create a single button and change the two constants and it will put the result into a property of the button.


Code: Select all

local golf
constant numofcolumns = 5
constant numoflines = 6
local numofcolumns1
local tcount
local numtoprint
local butprop1
local asdf


on mouseup
   put empty into butprop1
   put "rowsbycols" & numoflines & "x" & numofcolumns into asdf
   put numoflines^numofcolumns into numtoprint
   put numofcolumns into numofcolumns1
   put 0 into tcount
   firstprint
   createcombinations
end mouseup



on firstprint 
 put empty into golf
 put 1 into tcount
 repeat with i = 1 to numofcolumns
    put 1 into golf[i]
 end repeat
 printthings
end firstprint


on createcombinations
 if golf[numofcolumns1] = numoflines then
    put 1 into golf[numofcolumns1]
    put numofcolumns1 - 1 into numofcolumns1
    send "createcombinations" to me in 0 milliseconds 
 else
    put 1 + golf[numofcolumns1] into golf[numofcolumns1]
    printthings
    put numofcolumns into numofcolumns1
    send "createcombinations" to me in 0 milliseconds 
 end if
end createcombinations




on printthings
   put golf into butprop1[tcount]
   put 1 + tcount into tcount
   if tcount > numtoprint then
      set the asdf of btn "testt" to butprop1
      exit to top
   end if
end printthings

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”