Skip to content

Instantly share code, notes, and snippets.

@ygrenzinger
Created December 7, 2015 21:30
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 ygrenzinger/e3d7cdd9cba3dac716e2 to your computer and use it in GitHub Desktop.
Save ygrenzinger/e3d7cdd9cba3dac716e2 to your computer and use it in GitHub Desktop.
Solution for question of Edx F# Module 3
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