Jose=. [ (1 }. <:@:(0&({::))@:[ |. ])^:(1&({::)@:[ < #@])^:_ i.@:]is a slight modification of ( Josephus=. [ (1 }. <:@[ |. ])^:(1 < #@])^:_ i.@] ); that is, counting Mayan style: 0, 1, 2, ... 3 4 Jose 20 19 1 7 12 5 1 Jose 200 112 7 11 Jose 345 72 92 93 137 175 224 236 283 287 295 319 The order is relative to the executioner's pointer; so, the next one to go is 236, 7 10 Jose 345 283 287 295 319 72 92 93 137 175 224 On Fri, May 3, 2013 at 3:41 AM, Skip Cave <[email protected]> wrote: > A generalized version of the Josephus problem would be to allow any skip > number, and any number of survivors. This would require three variables > input to the verb. > > 1. The number of people in the line (n) > 2. The number skipped for each step (s) > 3. The number of people left to go free at the end (r) > > Given these three integers, what positions will be left at the end of the > process? > > usage: s r jose n > where s = the number skipped, r = the number remaining, and n = the number > in line. > > Here's an explicit function to solve the problem: > > jose=: 4 : 0 > f =. i.0 NB. Initialize output vector > s =. <:0{x NB. x(0) is the skip number > r =. 1{x NB. x(1) is the number left > I =. y NB. y is the total positions > L =. 1+i. y NB. L is the position list > whilst. I =. I-1 do. > L =. s |. L > f =. f, {. L > L =. }. L > end. > (r-y) {. f NB. Take the last r positions > ) > > Examples: > > 3 4 jose 20 NB. Skip 3, leave 4, out of 20 > 8 2 13 20 > > 5 1 jose 200 NB. Skip 5, leave 1, out of 200 > 113 > > I have been trying to make this tacit, but no luck so far. I'm still pretty > much of a novice with tacit functionality. > > Skip > > -- > Skip Cave > Cave Consulting LLC > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
