/ Functional Programming

Solving HackerRank's Functional Challenges in F#: Solve Me First FP

Couple of years ago I had a good time practicing Go by solving a number of programming challenges on Hackerrank. This time I will try solve functional challenges using F#.

There is the first one:

Your task is to scan two numbers, A and B from STDIN, and print the sum A+B on STDOUT.

Screen-Shot-2017-08-20-at-03.11.54

It is just a basic challenge to get convenient with solution submision and language basics. The code looks pretty much C#:

open System

[<EntryPoint>]
let main argv = 
    let a = Console.ReadLine() |> int
    let b = int(Console.ReadLine())
    printfn "%d" (a+b)
    0 // return an integer exit code

Console.ReadLine() |> int and int(Console.ReadLine()) are equivalent forms. a |> b is just b(a).

Alex Netkachov

Alex Netkachov

Alex likes functional programming and algorithms. Apart from programming, his favourites are walking with his family in the parks and national trails and reading about universe and history.

Read More