Skip to content

Instantly share code, notes, and snippets.

@adilakhter

adilakhter/addrev.fs

Created Dec 14, 2012
Embed
What would you like to do?
SPOJ 42: ADDREV
// problem definition : https://www.spoj.com/problems/ADDREV/
open System
let parseTuple() : int*int =
let line = Console.ReadLine().Split()
line.[0] |> int , line.[1] |> int
let reverseInt n =
let rec reverseInt' n acc =
let acc' = acc + (n%10)
match n with
| n when n >= 10 -> reverseInt' ((int)(n/10)) (acc'*10)
| n -> acc'
reverseInt' n 0
let solveCase (n1,n2) = reverseInt (reverseInt n1 + reverseInt n2)
let rec solveCases i maxCases =
if i < maxCases then
parseTuple()
|> solveCase
|> printfn "%d"
solveCases (i + 1) maxCases // solving next case
let spoj42() =
match Console.ReadLine() |> Int32.TryParse with
| (true, i) when i > 0 -> solveCases 0 i
| _ -> ()
spoj42()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.