Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
Replies
6 replies
Answers
1 answer
Subscribers
6 subscribers
Views
7076 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
How to make combinations in expression.
davids735
over 7 years ago
I'm sure this has to be a relatively simple problem, but I can't seem to figure out the answer. I want all the combinations you can have selecting 2 items from the same array, repeats allowed.
Say my array is {1,2,3,4,5}
I want to output {11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 41, 42, 43, 44, 45, 51, 52, 53, 54, 55}
And if possible, I want to expand this to have a means of creating 3 and 4 and 5 digit combinations.
OriginalPostID-273492
Discussion posts and replies are publicly visible
0
Mike Schmitt
Certified Lead Developer
over 7 years ago
AFAIK this should be possible with a 2-layer expression rule construct, a parent rule and a sub-rule which you can call using apply(). I guess it might be possible with only 1 layer, but if so I can't think of how, off the top of my head.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
davids735
over 7 years ago
Using Apply and Merge I can get (11,22,33,44,55) pretty easily. The closest I've come so far is {11, 222, 3333, 44444, 555555}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 7 years ago
I've come up with the following pair of rules which seems to do what you want. See code below and screenshot attached. Note that I didn't include a lot of error checking or null handling, which you would want to do if you implement this for real use.
Parent Rule (named i.e. TEST_textCombinations_parentRule):
with(
local!array: {
"1", "2", "3", "4", "5" /* for example */
},
apply(
rule!TEST_textCombinations_subRule(
array: local!array,
index: _
),
enumerate(length(local!array))+1
)
)
Child Rule (TEST_textCombinations_subRule):
apply(
fn!concat,
merge(
repeat(
length(ri!array),
index(ri!array, ri!index)
),
ri!array
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
vinayakb
over 7 years ago
How about sending two context parameters in the apply function. Multi array traverse that should work for you.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Vinay Kumar Rai
over 7 years ago
Hi @David, another approach, only single rule is used, please find attached screenshot
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Jasmin
over 7 years ago
Hi @David , I have one more approach ,
Parent rule-- apply(rule!Test_createCombinations(_,{1,2,3,4,5}),{1,2,3,4,5})
/* riinput- single integer field from parent rule it will come one by one through partial function */
/* ri!array - multiple number integer field it will take whole array from parent rule */
child Rule -- apply(fn!concat(ri!input,_),ri!array)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel