Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34871
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Josephus Circle problem |
| Date | 2014-12-11 14:36 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <m6ca52$1ds$1@dont-email.me> (permalink) |
| References | (1 earlier) <l9cpi3$gt9$1@dont-email.me> <ccb911cb-e3e5-46e1-9bdb-4da9d16aef50@googlegroups.com> <383caaa9-5308-4d58-b118-eec96803840e@googlegroups.com> <l9h1q6$glb$1@dont-email.me> <l9hp54$9et$1@dont-email.me> |
Gerry Jackson wrote:
> On 26/12/2013 10:52, Gerry Jackson wrote:
> > On 25/12/2013 14:06, mhx@iae.nl wrote:
> > > On Wednesday, December 25, 2013 1:38:38 PM UTC+1, m...@iae.nl wrote:
> > > > Much too verbose. Here is a one-liner (given the appropriate terminal):
> > > > [..deleted convoluted ugliness..]
> > >
> > > : josephus 0 1 begin dup #40 <= while swap 3 + over mod swap 1+
> > > repeat drop 1+ . ;
> > >
> > > -marcel
> > >
> > Or, to link up with the quotations discussion, and as long as your
> > stacks are big enough
> >
> >: josephus [: dup 1 <> if dup 1- recurse 2 + swap mod 1+ then ;]
> > execute . ;
> >
> > usage:
> > 40 josephus
> >
>
> Just in case anyone is wondering, this was adapted from
> http://en.wikipedia.org/wiki/Josephus_problem
> which also contains Marcel's algorithm, and explains it.
Using local variables and recursion:
: josephus { a b } b 41 < if a 3 + b mod b 1+ recurse else a 1+ . then ;
0 1 josephus
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Re: Josephus Circle problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-11 14:36 +0000
csiph-web