Josephus Problem

Certified Associate Developer

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

Parents Reply
  • 0
    Certified Associate Developer
    in reply to Richard Michaelis

    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 

Children