Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

§ /prog/ Challenge #32767 §

Name: Anonymous 2011-05-10 16:42

The Challenge: Given a number k where k ≥ 2, print another program (in the language you solve this challenge) that performs an O(nk) sort on a list (in-place or not is for you to decide).

The Deadline: 2011/05/18, 00:00 UTC.

Name: Anonymous 2011-05-10 21:45


let rec sortExprStr (k:int) (listExpr:string) =
    if k = 2 then
        "let rec qsort(xs : List<int>) =
                match xs with
                | [] -> []
                | x :: xs ->
                    let smaller = qsort (xs |> List.filter(fun e -> e <= x))
                    let larger = qsort (xs |> List.filter(fun e -> e >= x))
                    smaller @ [x] @ larger
           qsort %listExpr".Replace("%listExpr", listExpr)
    else
        let subSort = sortExprStr (k - 1) listExpr
        "%listExpr |> List.fold (fun acc n -> begin %subSort end) []".Replace("%listExpr", listExpr).Replace("%subSort", subSort)

System.Console.WriteLine(sortExprStr 10 "[3; 2; 1]")

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List