Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #25775
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | An elemantary Forth problem |
| Date | 2013-09-18 17:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <l1cp7o$uss$1@dont-email.me> (permalink) |
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.
Back to comp.lang.forth | Previous | Next — 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