Created
March 30, 2011 16:17
-
-
Save AlexCuse/894707 to your computer and use it in GitHub Desktop.
euler repl
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
#light | |
module ProjectEuler.Program | |
open System; | |
open System.Diagnostics; | |
open System.Reflection; | |
let dynamicExecute prob = | |
let probNum = prob.ToString() | |
let ass = Assembly.GetExecutingAssembly() | |
let modul = ass.GetType("ProjectEuler.Problem" + probNum) | |
let funcs = modul.GetMember("solve") | |
let func = funcs.[0] :?> PropertyInfo | |
func.GetValue(modul, null) | |
let getProblemNumber() = | |
printf "%s" "Enter problem #: " | |
let str = Console.ReadLine() | |
match Int32.TryParse(str) with | |
| true, parsed -> Some parsed | |
| _ -> None | |
let rec eulerRepl() = | |
let q = getProblemNumber() | |
if q.IsNone then () | |
else | |
let tmr = Stopwatch.StartNew() | |
let answer = dynamicExecute q.Value | |
printfn "Problem %d answer is %A\nSolved In: %A\n\n" q.Value answer tmr.Elapsed | |
eulerRepl() | |
eulerRepl() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment