From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D2770BC0B for ; Mon, 15 Jan 2007 22:52:06 +0100 (CET) Received: from NS1.home (74.220-119-85.cust.rackboost.net [85.119.220.74]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0FLq6XE007924 for ; Mon, 15 Jan 2007 22:52:06 +0100 Received: from lloyd ([87.235.198.48]) by home with MailEnable ESMTP; Mon, 15 Jan 2007 22:51:57 +0100 Message-ID: <015f01c738ef$66bc63b0$6401a8c0@lloyd> From: "Lloyd Moore" To: Subject: The kth element Date: Mon, 15 Jan 2007 22:52:06 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_015C_01C738F7.C823B790" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.2826 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2826 X-j-chkmail-Score: MSGID : 45ABF786.000 on discorde : j-chkmail score : XX : 5/20 0 0.000 -> 2 X-Miltered: at discorde with ID 45ABF786.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; sml:01 sml:01 W8:98 rec:01 rec:01 match:02 match:02 W4:96 arial:96 arial:96 element:03 let:03 let:03 correctly:05 correctly:05 This is a multi-part message in MIME format. ------=_NextPart_000_015C_01C738F7.C823B790 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable If I understood the question correctly posed by Dr Jon Harrop... let smallest lst =3D let rec sml lst v =3D match lst with [] -> v | h::t -> match t with h::t -> if h < (List.hd t) then sml t h else sml t v | _ -> v in sml lst (List.hd lst) ;; ------=_NextPart_000_015C_01C738F7.C823B790 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
If I understood the question correctly = posed by Dr=20 Jon Harrop...
 
 let smallest lst =3D let rec sml = lst v=20 =3D
 match lst with
   [] -> = v
 | h::t=20 ->
     match t=20 with
         h::t -> if h = <=20 (List.hd t) then sml t h else sml t v
     | = _ ->=20 v
  in sml lst (List.hd lst) ;;
------=_NextPart_000_015C_01C738F7.C823B790-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E8067BC0B for ; Mon, 15 Jan 2007 23:26:17 +0100 (CET) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0FMQHYR014858 for ; Mon, 15 Jan 2007 23:26:17 +0100 Received: from [192.168.0.104] (12-208-241-105.client.mchsi.com[12.208.241.105]) by sccmmhc91.asp.att.net (sccmmhc91) with SMTP id <20070115222605m9100ns7ere>; Mon, 15 Jan 2007 22:26:15 +0000 In-Reply-To: <015f01c738ef$66bc63b0$6401a8c0@lloyd> References: <015f01c738ef$66bc63b0$6401a8c0@lloyd> Mime-Version: 1.0 (Apple Message framework v752.3) X-Priority: 3 Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: caml-list@yquem.inria.fr Content-Transfer-Encoding: 7bit From: Jonathan Bryant Subject: Re: [Caml-list] The kth element Date: Mon, 15 Jan 2007 17:25:30 -0500 To: Lloyd Moore X-Mailer: Apple Mail (2.752.3) X-Miltered: at discorde with ID 45ABFF89.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; argv:01 printf:01 printf:01 sml:01 sml:01 beginner's:01 ocaml:01 bug:01 2007,:98 beginners:01 wrote:01 rec:01 rec:01 caml-list:01 caml-list:01 On Jan 15, 2007, at 4:52 PM, Lloyd Moore wrote: or (with a test program): let kth_smallest k l = let rec insert n l x a = match (n,l) with | (0, _) -> List.rev a | (n, h::t) -> if x < h then insert (n - 1) t h (x::a) else insert (n - 1) t x (h::a) | (n, []) -> List.rev (x::a) in let l = List.fold_left (fun a x -> insert k a x []) [] l in List.hd (List.rev l) let _ = let x = kth_smallest (int_of_string Sys.argv.(1)) [1; 11; 5; 9; 7; 3; 13] in Printf.printf "%d\n" x > If I understood the question correctly posed by Dr Jon Harrop... > > let smallest lst = let rec sml lst v = > match lst with > [] -> v > | h::t -> > match t with > h::t -> if h < (List.hd t) then sml t h else sml t v > | _ -> v > in sml lst (List.hd lst) ;; > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs