-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConwaySequence.fs
More file actions
30 lines (25 loc) · 914 Bytes
/
Copy pathConwaySequence.fs
File metadata and controls
30 lines (25 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module ConwaySequence
(* Auto-generated code below aims at helping you parse *)
(* the standard input according to the problem statement. *)
open System
open System.Text
let R() = Console.In.ReadLine()
let mutable sb = new StringBuilder(R())
let L = int(R())
for i in 1 .. L - 1 do
let currentSb = new StringBuilder()
let digArray = sb.ToString().Split [|' '|] |> Array.map int
let mutable value = digArray.[0]
let mutable cnt = 0
for j in 0 .. digArray.Length - 1 do
if digArray.[j] = value then
cnt <- cnt + 1
else
if currentSb.Length > 0 then ignore (currentSb.Append(' '))
else ignore (currentSb.AppendFormat("{0} {1}", cnt, value))
value <- digArray.[j]
cnt <- 1
sb <- currentSb
(* Write an action using printfn *)
(* To debug: Console.Error.WriteLine("Debug message") *)
printfn "%s" (sb.ToString())