From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA11224; Thu, 5 Dec 2002 21:47:21 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA11239 for ; Thu, 5 Dec 2002 21:47:20 +0100 (MET) Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gB5KlJX06150; Thu, 5 Dec 2002 21:47:19 +0100 (MET) Received: from tw304h3 oleg_inconnu@smtp-send.myrealbox.com [156.111.84.180] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 3.20 $ on Novell NetWare via secured & encrypted transport (TLS); Thu, 05 Dec 2002 13:47:18 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Oleg To: Pierre Weis , ijtrotts@ucdavis.edu (Issac Trotts) Subject: Re: [Caml-list] function Date: Thu, 5 Dec 2002 15:46:55 -0500 User-Agent: KMail/1.4.3 Cc: caml-list@inria.fr References: <200212051000.LAA22469@pauillac.inria.fr> In-Reply-To: <200212051000.LAA22469@pauillac.inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200212051546.56416.oleg_inconnu@myrealbox.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 05 December 2002 05:00 am, Pierre Weis wrote: > > On Mon, Dec 02, 2002 at 04:55:06PM +0100, altavillasalvatore@libero.i= t=20 wrote: > > > Hi all, > > > I would want to know if a function exists that allows me to make th= is: > > > > > > ["123";"45";"678"] -> [1;2;3;4;5;6;7;8;]. [...] To help the original poster earn extra credit, I'll write the function in= the=20 three languages I [sort of] know: typedef std::list LS; typedef std::list LI; void f(LS& input, LI& output) { for(LS::iterator i =3D input.begin(); i !=3D input.end(); ++i) for(char* p =3D *i; *p !=3D '\0'; ++p) output.push_back(int(*p) - int('0')); } (defun f (list) (loop for i in list nconcing (loop for j across i collect (- (char-int j) (char-int #\0))))) let digit c =3D int_of_char c - int_of_char '0' let rec f_aux lst i acc =3D match lst with | [] -> acc | x :: y when i =3D String.length x -> f_aux y 0 acc | x :: y -> f_aux lst (i + 1) (digit x.[i] :: acc) let f lst =3D List.rev (f_aux lst 0 []) If the input is a list of L strings of length S, then the complexity of a= ll=20 versions is O(L*S), assuming that "nconcing" caches the last element and String.length is O(1). Cheers Oleg ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners