Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.net
- // See the 'F# Tutorial' project for more help.
- let rec nwd x y =
- if y = 0 then x
- else nwd y (x % y)
- let shorten(leftPart, numerator, denominator) =
- let nwdValue = nwd numerator denominator
- (leftPart, numerator/nwdValue, denominator/nwdValue)
- let zamien(liczba: string) =
- let splitted = liczba.Split(',', '(', ')')
- let leftPart = splitted.[0]
- let rightPart = splitted.[1]
- let periodicPart = splitted.[2]
- let rightAndPeriodic = rightPart + periodicPart
- let denominator = String.replicate periodicPart.Length "9" + (String.replicate rightPart.Length "0")
- let numerator = (int) rightAndPeriodic - (int) rightPart
- let result = shorten((int)leftPart, numerator, (int)denominator)
- result
- [<EntryPoint>]
- let main argv =
- let result = zamien("4,789(55)")
- printfn "%A" result
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement