If there are 38 people in a line and every 4th on is killed, where would you
stand?


josephus =: dyad define NB. explicit form, assume executioner starts at
position 0
   NB. use:  SKIP josephus NUMBER_OF_PRISONERS
   N =: y
   K =: N | x
   EXECUTIONER =: 0
   PRISONERS =: i. N
   kill =: ] #~ (~: ([: i. #))
   while. 1 (< #) PRISONERS do.
   EXECUTIONER =: (# PRISONERS) | <: K + EXECUTIONER
   PRISONERS =: EXECUTIONER kill PRISONERS
   end.
   )
   
   3 josephus 41
30
   4 josephus 38
37
   
   
   jolla=: dyad define 
   B=:_1}"1 ((>.y%x) ,x)$i.y
   G=:(-.2|y)|.(-.(i.y) e. B)#i.y
   while. y>$B do.
   B=:B,_1{"1((>.($G)%x) ,x)$G
   G=:(-.(i.y) e. B)#i.y
   end.
   _1}B
   )
   
   3 jolla 41 
30
   4 jolla 38
18

David Lambert's function chooses the 37th position.  Mine chooses the e.
Where would you stand?       
 
Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Ward
Lambert
Sent: Thursday, April 18, 2013 11:20 PM
To: programming
Subject: [Jprogramming] rosettacode

Please modify these new entries as you please:
http://rosettacode.org/wiki/Josephus_problem#J
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rat
ional_number#J
The continued fraction solution has some oddities.  Returning _ to signal
"finished" converts the output vector to floating point.  That's why I
excluded the 314285714 100000000x example.  The `y is 8' input to r2cf__CF
is arbitrary and I have to strip it with _ from the output vector.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to