/ 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 Netkachov is a Senior Software Developer, currently working in Central London on new generation of energy trading solutions for brokers, traders and exchanges.

Read More

Why not to stay updated if the subject is interesting? Join Telegram channel Alex@Net or follow alex_at_net on Twitter. Or just, use the comments form below.