Last active
February 22, 2018 04:55
-
-
Save JonBons/62ca4b6957c3e11689b5 to your computer and use it in GitHub Desktop.
Learning F# with Hacker Rank
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 | |
//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