Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Draw-a-clock/F-Sharp/draw-a-clock.fs
Normal file
43
Task/Draw-a-clock/F-Sharp/draw-a-clock.fs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
open System.Text.RegularExpressions
|
||||
|
||||
let numberTemplate = """
|
||||
_ _ _ _ __ _ _
|
||||
/ \ /| ) _)|_||_ / /(_)(_) *
|
||||
\_/ | /_ _) | _)(_) / (_) / *
|
||||
"""
|
||||
let g =
|
||||
numberTemplate.Split([|'\n';'\r'|], System.StringSplitOptions.RemoveEmptyEntries)
|
||||
|> Array.map (fun s ->
|
||||
Regex.Matches(s, "...")
|
||||
|> Seq.cast<Match>
|
||||
|> Seq.map (fun m -> m.ToString())
|
||||
|> Seq.toArray)
|
||||
|
||||
let idx c =
|
||||
let v c = ((int) c) - ((int) '0')
|
||||
let i = v c
|
||||
if 0 <= i && i <= 9 then i
|
||||
elif c = ':' then 10
|
||||
else failwith ("Cannot draw character " + c.ToString())
|
||||
|
||||
let draw (s :string) =
|
||||
System.Console.Clear()
|
||||
g
|
||||
|> Array.iter (fun a ->
|
||||
s.ToCharArray() |> Array.iter (fun c ->
|
||||
let i = idx c
|
||||
printf "%s" (a.[i]))
|
||||
printfn ""
|
||||
)
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
let showTime _ = draw (System.String.Format("{0:HH:mm:ss}", (System.DateTime.Now)))
|
||||
let timer = new System.Timers.Timer(500.)
|
||||
timer.AutoReset <- true // The timer triggers cyclically
|
||||
timer.Elapsed // An event stream
|
||||
|> Observable.subscribe showTime |> ignore // Subscribe to the event stream
|
||||
timer.Start() // Now it counts
|
||||
System.Console.ReadLine() |> ignore // Until return is hit
|
||||
showTime ()
|
||||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue