Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.92 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. let rec nwd x y =
  5.     if y = 0 then x
  6.     else nwd y (x % y)
  7.  
  8. let shorten(leftPart, numerator, denominator) =
  9.     let nwdValue = nwd numerator denominator
  10.     (leftPart, numerator/nwdValue, denominator/nwdValue)
  11.  
  12. let zamien(liczba: string) =
  13.     let splitted = liczba.Split(',', '(', ')')
  14.     let leftPart = splitted.[0]
  15.     let rightPart = splitted.[1]
  16.     let periodicPart = splitted.[2]
  17.     let rightAndPeriodic = rightPart + periodicPart
  18.  
  19.     let denominator = String.replicate periodicPart.Length "9" + (String.replicate rightPart.Length "0")
  20.     let numerator = (int) rightAndPeriodic - (int) rightPart
  21.  
  22.     let result = shorten((int)leftPart, numerator, (int)denominator)
  23.     result
  24.  
  25. [<EntryPoint>]
  26. let main argv =
  27.     let result = zamien("4,789(55)")
  28.     printfn "%A" result
  29.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement