Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type LineElement =
- | Word of string
- | Space of int
- let n = 5
- let myList1 = ["aa"; "bb"; "cc"]
- let rec func (list : string list) (myList : LineElement list list) =
- match list with
- | head :: tail -> match myList with
- | [Word x; Space y] :: myTail -> if x.Length + head.Length <= n then
- let newString = x + " " + head
- func tail ([Word newString; Space (n - newString.Length)] :: myTail)
- else func tail ([Word head; Space (n - head.Length)] :: myList)
- | [] -> func tail [[Word head; Space (n - head.Length)]]
- | _ -> failwith "Error"
- | [] -> myList |> List.rev
- let myList2 = func myList1 []
- printfn "%A" myList2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement