Created
December 7, 2015 21:30
-
-
Save ygrenzinger/e3d7cdd9cba3dac716e2 to your computer and use it in GitHub Desktop.
Solution for question of Edx F# Module 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let goldenratio = (1.0 + Math.Sqrt(5.0)) / 2.0 | |
let calculateRatio x = x * goldenratio | |
let rec inputValue () : int = | |
Console.WriteLine("Please input value") | |
let couldParse, i = Int32.TryParse(Console.ReadLine()) | |
if couldParse then i | |
else inputValue() | |
let canInput () = | |
Console.WriteLine("Continue Input? Y or N?") | |
if Console.ReadLine() = "Y" then true | |
else false | |
[<EntryPoint>] | |
let main args = | |
let mutable list : int List = [] | |
let i = inputValue() | |
list <- i :: list | |
while canInput() do | |
let i = inputValue() | |
list <- i :: list | |
let valueWithGoldenRatio = list |> List.map (fun x -> ( x , calculateRatio((float)x) ) ) | |
valueWithGoldenRatio |> List.map (fun (x, ratio) -> Console.WriteLine("Value {0} and golden ratio {1}", x, ratio) ) |> ignore | |
Console.ReadKey() |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment