Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34871 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2014-12-11 14:36 +0000 |
| Last post | 2014-12-11 14:36 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.forth
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Josephus Circle problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-11 14:36 +0000
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2014-12-11 14:36 +0000 |
| Subject | Re: Josephus Circle problem |
| Message-ID | <m6ca52$1ds$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 top | Article view | comp.lang.forth
csiph-web