Skip to content

Instantly share code, notes, and snippets.

@esehara
Created June 11, 2016 08:25
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 esehara/e6677be34eee1b7b0a49806da9fa200c to your computer and use it in GitHub Desktop.
Save esehara/e6677be34eee1b7b0a49806da9fa200c to your computer and use it in GitHub Desktop.
初めてのFSharp
open System
let message ans user =
if (ans > user) then
"答えはもっと大きいよ"
elif (ans < user) then
"答えはもっと小さいよ"
else
"You won !"
let rec gameLogic ans time =
printf "Input > "
let user_input = Console.ReadLine()
if System.String.Equals(user_input, "") then
gameLogic ans time
else
let user_answer = System.Int32.Parse(user_input)
printfn "%s" (message ans user_answer)
if ans = user_answer then
printfn "%d回数で当てました" time
else
gameLogic ans (time + 1)
[<EntryPoint>]
let main argv =
printfn "*** 数当てゲーム ***"
let ans = System.Random().Next(1, 100)
gameLogic ans 0
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment