<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Josephus Problem</title><link>https://community.appian.com/discussions/f/rules/29603/josephus-problem</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Josephus Problem</title><link>https://community.appian.com/thread/117572?ContentTypeID=1</link><pubDate>Fri, 11 Aug 2023 05:33:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:691bf3e7-34a4-4e9e-9e88-bf119f31f4fd</guid><dc:creator>Nikhil Chandra Reddy Tetali</dc:creator><description>&lt;p&gt;Here is the solution to your challenge. We have also added a feather so that the user may choose the number of players and who should start the game.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;reduce(
  rule!EI_subEliminateTask(list: _, value: _),
  {
    ldrop(
      enumerate(ri!players) + 1,
      ri!startPlayer - 1
    ),
    if(
      ri!startPlayer = 1,
      {},
      enumerate(ri!startPlayer - 1) + 1
    )
  },
  repeat(ri!players - 1, 0)
)

subrule: rule!EI_subEliminateTask(list: _, value: _),
code: { ldrop(ri!list, 2), ri!list[1] }&lt;/pre&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/15/Screenshot-from-2023_2D00_08_2D00_11-10_2D00_47_2D00_55.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/15/Screenshot-from-2023_2D00_08_2D00_11-10_2D00_48_2D00_09.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117552?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2023 18:06:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:02e080c2-9555-48e3-a24b-54c209763064</guid><dc:creator>jamesm4933</dc:creator><description>&lt;p&gt;It&amp;#39;s called the Josephus Problem.&amp;nbsp; It was inspired by a story in &amp;quot;The Jewish War&amp;quot; by Flavius Josephus.&lt;/p&gt;
&lt;p&gt;Apparently, the solutions for n=2 up to group size 78 are sequence number A006257 in the &lt;a href="https://oeis.org/A006257"&gt;On-line Encyclopedia of Integer Sequences&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Josephus_problem"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.gutenberg.org/files/2850/2850-h/2850-h.htm#link32HCH0008"&gt;The Jewish War&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117546?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2023 16:13:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a363c295-05cc-4413-9990-8d9f5b11b23a</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Yes this is the code for the rule.&amp;nbsp; Being recursive, it calls itself&amp;nbsp;&lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f609.svg" title="Wink"&gt;&amp;#x1f609;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Optimized a bit:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;if(
  count(ri!list)&amp;lt;=1,
  index(ri!list,1,null),
  a!localVariables(
    local!removeIndex: if(ri!index=count(ri!list),1,
    if(ri!index&amp;gt;count(ri!list),2,ri!index+1)
    ),
    rule!chris_test_kc_recur(
      list: remove(ri!list,local!removeIndex),
      index: local!removeIndex
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/15/pastedimage1691683864766v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117541?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2023 14:27:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fb8db1bd-a5a0-478d-84a7-a7b834c9924c</guid><dc:creator>Mike Schmitt</dc:creator><description>[quote userid="213297" url="~/discussions/f/rules/29603/kill-in-the-circle/117502#117502"]please share me the code rule!chris_test_kc_recur[/quote]
&lt;p&gt;lol, he did say this is a recursive rule...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117506?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2023 06:55:08 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:552ff4a8-66e2-4b26-a1cb-0de344e21d2d</guid><dc:creator>Richard Michaelis</dc:creator><description>&lt;p&gt;why not trying yourself than getting it served already prepared? :) The question was , if it was possible. yes it is. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117502?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2023 04:32:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ead2b0f8-d631-40d5-b0cc-28dc9a0a2f9c</guid><dc:creator>afzalk0001</dc:creator><description>&lt;p&gt;can you please share me the code rule!chris_test_kc_recur? That would be helpful&lt;/p&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117488?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 15:41:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b1b0de68-1945-41d8-9120-fc0a022f6a65</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;This is my example with a recursive rule to&amp;nbsp;solve the puzzle (#73).&lt;/p&gt;
&lt;p&gt;As always, make sure to save recursive rules before testing.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;/* rule!chris_test_kc_recur(
      list (Number Array, 1+enumerate(100))
      index (Number, 1)
   )
*/

if(
  count(ri!list)&amp;lt;=1,
  index(ri!list,1,null),
  a!localVariables(
    local!removeIndex: if(
      ri!index=count(ri!list),
      1,
      if(
        ri!index&amp;gt;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
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117468?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:55:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:698381a7-b949-4047-9b51-54302ddf66c8</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;As Appian follows a functional approach, you cannot modify variables during runtime. You line 14 will not work.&lt;/p&gt;
&lt;p&gt;Make this recursive, or use the reduce() function. It allows you to modify data across iterations.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://appian.rocks/2022/08/29/complex-algorithms-in-appian/"&gt;appian.rocks/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117466?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:49:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ac6bdca3-e1cd-41bf-9a00-7c47f9752888</guid><dc:creator>afzalk0001</dc:creator><description>&lt;p&gt;Yeah its a puzzle problem. You can refer this -&amp;nbsp;&lt;a href="https://www.geeksforgeeks.org/puzzle-100-people-in-a-circle-with-gun-puzzle/"&gt;https://www.geeksforgeeks.org/puzzle-100-people-in-a-circle-with-gun-puzzle/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;i was just trying to implement using appian.&lt;/p&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117464?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:46:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1ab371ae-780b-4f7e-83bb-7b3feccce05e</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;Is this some sort of exam question?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117461?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:40:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b50ca0c7-cf05-4a84-bb27-5d80d0cc4315</guid><dc:creator>afzalk0001</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;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)
      }       
   )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;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&amp;nbsp;&lt;/p&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117459?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:35:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:cb728c71-94a7-4471-b1da-f51aed1be997</guid><dc:creator>Richard Michaelis</dc:creator><description>&lt;p&gt;sure it is ;)&lt;br /&gt;looping functions might be your friend :)&lt;br /&gt;a!forEach is one of them&lt;br /&gt;&lt;a href="https://docs.appian.com/suite/help/23.2/fnc_looping_a_foreach.html"&gt;https://docs.appian.com/suite/help/23.2/fnc_looping_a_foreach.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117458?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:35:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bf27ce53-a1b3-4d23-bb30-de22c931b788</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;You can implement recursive and iterative algorithms. So, the answer is: Yes!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117455?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:16:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b5c9a827-93f2-4fa5-840c-ac345a062810</guid><dc:creator>afzalk0001</dc:creator><description>&lt;p&gt;No just wanted to try using appian. Whether is it possible using expressuin rules or not?&lt;/p&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;
&lt;div style="display:none;position:absolute;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Kill in the circle</title><link>https://community.appian.com/thread/117454?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2023 11:14:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a90f0d55-e133-4f57-b4d0-8df48a317f74</guid><dc:creator>Richard Michaelis</dc:creator><description>&lt;p&gt;Thats no appian related question, is it ;)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>