Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!
The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.
100 people standing in a circle in an order 1 to 100. No. 1 has a sword. He kills the next person (i.e. No. 2) and gives the sword to the next (i.e. No. 3). All people do the same until only 1 survives. Which number survives at the last? There are 100 people starting from 1 to 100.
can anyone please tell me how can i do it?
Discussion posts and replies are publicly visible
Thats no appian related question, is it ;)?
No just wanted to try using appian. Whether is it possible using expressuin rules or not?
You can implement recursive and iterative algorithms. So, the answer is: Yes!
sure it is ;)looping functions might be your friend :)a!forEach is one of themhttps://docs.appian.com/suite/help/23.2/fnc_looping_a_foreach.html
a!localVariables( local!makeArray: a!forEach( items: enumerate(ri!number) + 1, expression: fv!item ), local!resultArray, local!position: 1, a!forEach( items: local!makeArray, expression: { local!position+1, mod(local!position,length(fv!item)), remove(local!resultArray,local!position) } ) )
I tried this code but not able to get the possible solution. If you find any possible please help me with this. Thanks in advance
Is this some sort of exam question?
Yeah its a puzzle problem. You can refer this - https://www.geeksforgeeks.org/puzzle-100-people-in-a-circle-with-gun-puzzle/
i was just trying to implement using appian.
As Appian follows a functional approach, you cannot modify variables during runtime. You line 14 will not work.
Make this recursive, or use the reduce() function. It allows you to modify data across iterations.
appian.rocks/.../
This is my example with a recursive rule to solve the puzzle (#73).
As always, make sure to save recursive rules before testing.
/* rule!chris_test_kc_recur( list (Number Array, 1+enumerate(100)) index (Number, 1) ) */ if( count(ri!list)<=1, index(ri!list,1,null), a!localVariables( local!removeIndex: if( ri!index=count(ri!list), 1, if( ri!index>count(ri!list), 2, ri!index+1 ) ), local!list: remove(ri!list,local!removeIndex), rule!chris_test_kc_recur( list: local!list, index: local!removeIndex ) ) )
can you please share me the code rule!chris_test_kc_recur? That would be helpful