1 people like it.

Brain Training Implementation from ProgNet15

Created during the morning session of Progressive.Net 2015 with Phil Trelford

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
let random = new System.Random()
let mutable score = 0
let startTime = System.DateTime.Now

for i = 1 to 10 do
   let multiplier = random.Next(10)
   let answer = multiplier * i
   printfn "%d x %d = " i multiplier
   let input = System.Convert.ToInt32(System.Console.ReadLine())
   if input = answer then
      score <- score + 1

let finishTime = System.DateTime.Now
let time = finishTime.Subtract(startTime).ToString()

System.Console.ForegroundColor = System.ConsoleColor.Green
printfn "Score: %d" score
printfn "Time Taken: %s" time
val random : System.Random

Full name: Script.random
namespace System
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
System.Random() : unit
System.Random(Seed: int) : unit
val mutable score : int

Full name: Script.score
val startTime : System.DateTime

Full name: Script.startTime
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
System.DateTime()
   (+0 other overloads)
System.DateTime(ticks: int64) : unit
   (+0 other overloads)
System.DateTime(ticks: int64, kind: System.DateTimeKind) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, calendar: System.Globalization.Calendar) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: System.DateTimeKind) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: System.Globalization.Calendar) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: System.DateTimeKind) : unit
   (+0 other overloads)
property System.DateTime.Now: System.DateTime
val i : int
val multiplier : int
System.Random.Next() : int
System.Random.Next(maxValue: int) : int
System.Random.Next(minValue: int, maxValue: int) : int
val answer : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val input : int
type Convert =
  static val DBNull : obj
  static member ChangeType : value:obj * typeCode:TypeCode -> obj + 3 overloads
  static member FromBase64CharArray : inArray:char[] * offset:int * length:int -> byte[]
  static member FromBase64String : s:string -> byte[]
  static member GetTypeCode : value:obj -> TypeCode
  static member IsDBNull : value:obj -> bool
  static member ToBase64CharArray : inArray:byte[] * offsetIn:int * length:int * outArray:char[] * offsetOut:int -> int + 1 overload
  static member ToBase64String : inArray:byte[] -> string + 3 overloads
  static member ToBoolean : value:obj -> bool + 17 overloads
  static member ToByte : value:obj -> byte + 18 overloads
  ...

Full name: System.Convert
System.Convert.ToInt32(value: System.DateTime) : int
   (+0 other overloads)
System.Convert.ToInt32(value: string) : int
   (+0 other overloads)
System.Convert.ToInt32(value: decimal) : int
   (+0 other overloads)
System.Convert.ToInt32(value: float) : int
   (+0 other overloads)
System.Convert.ToInt32(value: float32) : int
   (+0 other overloads)
System.Convert.ToInt32(value: uint64) : int
   (+0 other overloads)
System.Convert.ToInt32(value: int64) : int
   (+0 other overloads)
System.Convert.ToInt32(value: int) : int
   (+0 other overloads)
System.Convert.ToInt32(value: uint32) : int
   (+0 other overloads)
System.Convert.ToInt32(value: uint16) : int
   (+0 other overloads)
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
System.Console.ReadLine() : string
val finishTime : System.DateTime

Full name: Script.finishTime
val time : string

Full name: Script.time
System.DateTime.Subtract(value: System.TimeSpan) : System.DateTime
System.DateTime.Subtract(value: System.DateTime) : System.TimeSpan
property System.Console.ForegroundColor: System.ConsoleColor
type ConsoleColor =
  | Black = 0
  | DarkBlue = 1
  | DarkGreen = 2
  | DarkCyan = 3
  | DarkRed = 4
  | DarkMagenta = 5
  | DarkYellow = 6
  | Gray = 7
  | DarkGray = 8
  | Blue = 9
  ...

Full name: System.ConsoleColor
field System.ConsoleColor.Green = 10
Raw view Test code New version

More information

Link:http://fssnip.net/rE
Posted:9 years ago
Author:Chris O'Dell
Tags: prognet15 , braintrain