Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created December 14, 2012 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/4284839 to your computer and use it in GitHub Desktop.
Save adilakhter/4284839 to your computer and use it in GitHub Desktop.
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