Skip to content

Instantly share code, notes, and snippets.

@JonBons
Last active February 22, 2018 04:55
Show Gist options
  • Save JonBons/62ca4b6957c3e11689b5 to your computer and use it in GitHub Desktop.
Save JonBons/62ca4b6957c3e11689b5 to your computer and use it in GitHub Desktop.
Learning F# with Hacker Rank
open System
//leaderboard #1
let leaderboard1 =
let ln = System.Console.In.ReadLine //;;
[1..(int (ln()))] |> List.map (fun x-> ln().Split([|' '|]) |> Array.map int |> Array.reduce (+)) |> List.iter System.Console.WriteLine
//leaderboard #2
let leaderboard2 =
let n = Console.ReadLine() |> int
for i = 1 to n do
let number_string = Console.ReadLine()
let numbers = Array.map (fun s -> int s) (number_string.Split [|' '|])
let s = Array.sum numbers
printfn "%d" s
//leaderboard #3
let leaderboard3 =
let count = stdin.ReadLine() |> int
Seq.init count (fun i -> stdin.ReadLine().Split() |> Seq.map int)
|> Seq.map Seq.sum
|> Seq.iter (fun x -> printfn "%d" x)
//my try ( could not figure out how to pipeline this :( )
//pipeline attempt
// [1..lines] |> Seq.iter ( printf "%i\n" (Console.ReadLine().Split() |> Seq.map int |> Seq.sum) )
let mySolution =
let lines = Console.ReadLine() |> int
for i = 1 to lines do
//my first iteration
//let numbers = Console.ReadLine().Split[|' '|] |> Seq.map int
//printf "%i\n" ((numbers |> Seq.nth 0) + (numbers |> Seq.nth 1))
//second iteration
printfn "%i" (Console.ReadLine().Split() |> Seq.map int |> Seq.sum)
[<EntryPoint>]
let main argv =
mySolution
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment