Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34873 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2014-12-11 17:57 +0000 |
| Last post | 2014-12-11 17:57 +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 17:57 +0000
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2014-12-11 17:57 +0000 |
| Subject | Re: Josephus Circle problem |
| Message-ID | <m6clud$pc8$1@dont-email.me> |
Paul Rubin wrote:
> Tristan Plumb <firth@trstn.net> writes:
> > However! Combinators can do amazing things with quotations. Take nrec:...
> > : nrec ( n F F0 -- Fn ) rot 1+ 1 do over i swap execute loop nip ;
>
> Neat ;-)
>
> > : (josephus) swap 2 + swap mod 1+ ;
> > : josephus ' (josephus) 1 nrec ;
>
> ' should say ['] .
>
> The Haskell equivalent of Marcel's algorithm is:
>
> josephus k n = 1 + foldl (\a b->(a+k)`mod`b) 0 [1..n]
>
> I guess it's possible to concoct a reduce combinator in Forth, but it
> just doesn't seem in the Forth style. It would also want to use a
> coroutine to generate the input stream.
In OCaml, using recursion:
let rec jo a = function
41 -> 1+a
| b -> jo ((a+3) mod b) (b+1) ;;
jo 0 1 ;;
Back to top | Article view | comp.lang.forth
csiph-web