brokendidge
April 4th, 2008, 05:46 AM
Since i cannot figure it out myself i hope one of you can help me with creating the right algorhytm for a specific permutation generator.
Problem:
We have
A = number of RED marbles in sample
B = number of GREEN marbles in samle
…….
X = number of (last color) marbles in sample
Lets say we have the sample ABX that holds the following marbles: "red red red green green Brown"
This creates a samle-string like "RRRGGB"
What is the algorhytm to write out all the unique permutations. The algorhytm should be able to handle different sample sizes and color combinations in the sample.
After creating the permutations I want to translate the letters into rhythm-patterns/sound effects. So in fact I’m looking for a groove generator that creates a groove from x different components with their own specific amount of counts in the beat. So R can be a 2-count, G a 3-count and B a 6 count sound-effect. The Samplestring above should create all grooves of 18 counts.
So far only red eyes and sleep deprevation, no results…
Help me out!
(Pseudocode of explaination instead of code is also welcome)
Dwellerofholes
April 6th, 2008, 10:55 AM
copy all the values, in the case rrrgb to separate variables. then you can either do a table of binary, as rows of successive binary numbers create all possible permutations, or you could iterate the original string and place values. I did this with pizza toppings a while back in basic and i chose the binary technique.
brokendidge
April 9th, 2008, 06:27 AM
With following Excel Macro procedure i have the desired solution.
(gained with blood, sweat & tears of course)
Hopefully it lives on on other systems...
Sub Create_permutations()
' create_permutations
' recorded: 5-4-2008 by Myself ;-)
'Put original string in Cell A12
K_origineel = "A"
Rij_origineel = 12
rij = Rij_origineel
R_origineel = Trim(Str(rij))
K = K_origineel
R = R_origineel
positie = K & R
Range(positie).Select
origineel = ActiveCell.Value
For cyclusnr = 1 To Len(origineel) number of cycli to make
'count for the number of permutations in this cycle
Aantal_permutaties = 0
Do While Len(ActiveCell.Value) > 0
Aantal_permutaties = Aantal_permutaties + 1
ActiveCell.Offset(1, 0).Select
Loop
regelsterug = -1 * (Aantal_permutaties)
'take the first permutation in column to work with in cyclus-column
ActiveCell.Offset(regelsterug, 0).Select
'MsgBox "nr of permutations in cyclus " & Str(cyclusnr) & " = " & Str(Aantal_permutaties)
For permutatienr = 1 To Aantal_permutaties
'Create the rest string. Original minus permutation used
If Aantal_permutaties = 1 Then
rest = origineel
Else
'If cyclusnr = 1 Then
' permutatie = ActiveCell.Value
'Else
'If Permutatienr < permutaties Then
'read next permutation in column
If permutatienr = 1 Then
ActiveCell.Offset((permutatienr - 1), 0).Select
permutatie = ActiveCell.Value
ActiveCell.Offset(-(permutatienr - 1), 0).Select
Else
ActiveCell.Offset((permutatienr - 1), -1).Select
permutatie = ActiveCell.Value
ActiveCell.Offset(-(permutatienr - 1), 1).Select
End If
Range(positie).Select
'End If
'End If
'ActiveCell.Offset(0, 2).Select
If Len(permutatie) < Len(origineel) Then
temp = origineel
For j = 1 To Len(permutatie)
teken = Mid$(permutatie, j, 1)
plaatsgevonden = InStr(1, origineel, teken, vbTextCompare)
If plaatsgevonden = 1 Then
origineel = Mid$(origineel, 2, Len(origineel) - 1)
Else
origineel = Mid$(origineel, 1, plaatsgevonden - 1) & Mid$(origineel, plaatsgevonden + 1, Len(origineel) - plaatsgevonden)
End If
Next j
rest = origineel
origineel = temp
End If
End If
'MsgBox "reststring van permutatie " & permutatienr & "( = " & permutatie & ") van " & Aantal_permutaties & " in cyclus " & Str(cyclusnr) & " = " & rest
' inspect number of elements in rest string en make unique string
' append each value to the permutation
lengte = Len(rest)
If lengte = 0 Then
aantal_elementsoorten = 0
Else
If lengte = 1 Then
elementsoorten_uniek = rest
Else
elementsoorten_uniek = ""
For j = 1 To Len(rest) - 1
teken1 = Mid$(rest, j, 1)
If j = 1 Then
elementsoorten_uniek = elementsoorten_uniek & teken1
End If
teken2 = Mid$(rest, j + 1, 1)
'MsgBox "teken1=" & teken1 & " teken2=" & teken2
elementsoorten_uniek = elementsoorten_uniek & teken2
End If
'MsgBox "In loopnr. " & Str(i) & " element sorts_uniek=" & elementsoorten_uniek
Next j
End If
aantal_elementsoorten = Len(elementsoorten_uniek)
End If
'MsgBox "element sorts_uniek of permution " & permutatie & " in cyclus " & Str(cyclusnr) & " = " & elementsoorten_uniek
'ga back to startposition and i columns to the right and write the permutations here. O.K. easy way out ;-))
K = K_origineel
R = R_origineel
positie = K & R
Range(positie).Select
'Move i columns to the right for empty column for this cyclus
ActiveCell.Offset(0, cyclusnr).Select
If aantal_elementsoorten > 0 Then
For j = 1 To aantal_elementsoorten
If Len(ActiveCell.Value) > 0 Then
'cel not empty? push cells downwards. prefents moving all around.
Selection.Insert Shift:=xlDown
End If
ActiveCell.Value = permutatie & Mid$(elementsoorten_uniek, j, 1)
Next j
End If
'ActiveCell.Offset(0, 1).Select
'MsgBox "end op loop " & permutatienr & " of " & Aantal_permutaties & " within cyclus nr. " & Str(cyclusnr)
Next permutatienr
'MsgBox "end of cyclus nr. " & Str(cyclusnr)
Next cyclusnr
End Sub