• + 0 comments

    f# solution

    let rec compress n list =
        match list with
        | [] -> []
        | [ c ] when n = 1 -> [ c ]
        | [ c ] -> [ c; string n ]
        | x :: xs when x = List.head xs -> compress (n + 1) xs
        | x :: xs when n = 1 -> x :: compress 1 xs
        | x :: xs -> x :: string n :: compress 1 xs
    
    open System
    
    [<EntryPoint>]
    let main _ =
        Console.ReadLine()
        |> Seq.toList
        |> List.map string
        |> compress 1
        |> String.concat ""
        |> Console.WriteLine
    
        0