Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #25777
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: An elemantary [sic] Forth problem |
| Date | 2013-09-18 21:32 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <l1d2ll$qv7$1@dont-email.me> (permalink) |
| References | <l1cp7o$uss$1@dont-email.me> |
on 18/09/2013 18:51:50, "WJ" wrote: > Return two lists, the first containing elements that occur only once > in the input list, and the second containing elements that occur more > than once in the input list. > > OCaml: > > open List;; > let list = ["a";"b";"c";"d";"e";"f";"g"; "b";"b";"d";"f"] in > let rec loop once twice = function > [] -> (once,twice) > | x::xs -> > if (mem x once) || (mem x twice) then > loop once twice xs > else if mem x xs then > loop once (x::twice) xs > else > loop (x::once) twice xs > in loop [] [] list ;; > > > (["g"; "e"; "c"; "a"], ["f"; "d"; "b"]) > > > This should be trivial in Forth. > I really can't see what the OCaml is doing; your code is as clear as mud. I suspect you're using the wrong algorithm to solve this "problem" in any reasonable fashion if the list consisted of several thousand elements. It appears to be executing one of three loops, all over another loop. WJ, can you present a better algorithm first?
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
An elemantary Forth problem "WJ" <w_a_x_man@yahoo.com> - 2013-09-18 17:51 +0000
Re: An elemantary [sic] Forth problem "Alex McDonald" <blog@rivadpm.com> - 2013-09-18 21:32 +0100
Re: An elemantary Forth problem mhx@iae.nl - 2013-09-18 14:08 -0700
Re: An elemantary Forth problem mhx@iae.nl - 2013-09-18 14:58 -0700
Re: An elemantary Forth problem albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-09-18 22:56 +0000
Re: An elemantary Forth problem m.a.m.hendrix@tue.nl - 2013-09-18 23:58 -0700
Re: An elemantary Forth problem VoidVolker <voidvolker@gmail.com> - 2013-09-19 02:25 -0700
csiph-web