Created
December 9, 2016 13:11
-
-
Save zoren/b3ceb8210d235420388dc155baa14388 to your computer and use it in GitHub Desktop.
My hacker rank prelude for F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Collections.Generic | |
let rl = Console.ReadLine | |
let splsp (s:string) = s.Split([|' '|], StringSplitOptions.RemoveEmptyEntries) | |
let getTwo (a:_[]) = a.[0], a.[1] | |
let getThree (a:_[]) = a.[0], a.[1], a.[2] | |
let callN n action = seq { for i = 1 to n do yield action()} |> Seq.toArray | |
let iterrl f = | |
let rec loop () = | |
let l = rl() | |
if l = null then () else f l; loop() | |
loop() | |
[<AutoOpen>] | |
module DictionaryHelper = | |
type Dictionary<'TK, 'TV> with | |
member this.TryGetValueOpt k = | |
match this.TryGetValue k with | |
| true, v -> Some v | |
| _ -> None | |
let mkHist s = | |
let d = Dictionary<_, int>() | |
let add x = defaultArg (d.TryGetValueOpt x) 0 |> fun c -> d.[x] <- c + 1 | |
Seq.iter add s | |
d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment