Advertisement
Guest User

Untitled

a guest
May 11th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.87 KB | None | 0 0
  1. type LineElement =
  2.     | Word of string
  3.     | Space of int
  4.  
  5. let n = 5
  6.  
  7. let myList1 = ["aa"; "bb"; "cc"]
  8.  
  9. let rec func (list : string list) (myList : LineElement list list) =
  10.     match list with
  11.     | head :: tail -> match myList with
  12.                       | [Word x; Space y] :: myTail -> if x.Length + head.Length <= n then
  13.                                                            let newString = x + " " + head
  14.                                                            func tail ([Word newString; Space (n - newString.Length)] :: myTail)
  15.                                                        else func tail ([Word head; Space (n - head.Length)] :: myList)
  16.                       | [] -> func tail [[Word head; Space (n - head.Length)]]
  17.                       | _ -> failwith "Error"
  18.     | [] -> myList |> List.rev
  19.  
  20. let myList2 = func myList1 []
  21.  
  22. printfn "%A" myList2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement