Pirsqed

Hacker rank #2 Utopian Tree

Jun 18th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.87 KB | None | 0 0
  1. open System
  2.  
  3. [<EntryPoint>]
  4. let main argv =
  5.     let testCases = Console.ReadLine() |> int
  6.     let rec cases (totalCases, currentNum, workingList):list<int> =
  7.         if totalCases > currentNum then
  8.             let tempList = [Console.ReadLine() |> int]
  9.             cases (totalCases, currentNum+1, workingList@tempList)
  10.         else
  11.             workingList
  12.    
  13.     let rec calcHeight (maxCycles, currentCycle, height):int =
  14.         if maxCycles > currentCycle then
  15.             if currentCycle % 2 = 0 then
  16.                 calcHeight (maxCycles, currentCycle+1, (height*2))
  17.             else
  18.                 calcHeight (maxCycles, currentCycle+1, height+1)
  19.         else
  20.             height
  21.            
  22.     let listOfCases = cases (testCases, 0, [])
  23.     for i in listOfCases do
  24.         printfn "%d" (calcHeight (i, 0, 1))
  25.        
  26.     0 // return an integer exit code
Add Comment
Please, Sign In to add comment