Michells Mesterværk

Vinderen af låge nr. 10

by Administrator 15. December 2009 10:18

Med dette F# forslag til en “generisk” regnemaskine, vinder Allan Hvam Petersen endnu en låge.

#light

open System
open Microsoft.FSharp.Text.Lexing
open MrFrost10

Console.Write "Input: "
let line = Console.ReadLine()

let lexbuf = Lexing.from_string line
let e = Parser.start Lexer.token lexbuf

let rec factorial = function
| 0 -> 1
| n -> n * factorial(n - 1)

let rec eval = function
Plus(e1, e2) -> eval e1 + eval e2
| Minus(e1, e2) -> eval e1 - eval e2
| Times(e1, e2) -> eval e1 * eval e2
| Divide(e1, e2) -> eval e1 / eval e2
| Modulo(e1, e2) -> eval e1 % eval e2
| Sin e -> Math.Sin (eval e)
| Cos e -> Math.Cos (eval e)
| Tan e -> Math.Tan (eval e)
| Sinh e -> Math.Sinh (eval e)
| Cosh e -> Math.Cosh (eval e)
| Tanh e -> Math.Tanh (eval e)
| Asin e -> Math.Asin (eval e)
| Acos e -> Math.Acos (eval e)
| Atan e -> Math.Atan (eval e)
| Atan2(e1, e2) -> Math.Atan2(eval e1, eval e2)
| Abs e -> Math.Abs (eval e)
| Ceiling e -> Math.Ceiling (eval e)
| Floor e -> Math.Floor (eval e)
| Exp e -> Math.Exp (eval e)
| Log e -> Math.Log (eval e)
| Log10 e -> Math.Log10 (eval e)
| Min(e1, e2) -> Math.Min(eval e1, eval e2)
| Max(e1, e2) -> Math.Max(eval e1, eval e2)
| Pow(e1, e2) -> Math.Pow(eval e1, eval e2)
| Sqrt e -> Math.Sqrt (eval e)
| Round e -> Math.Round (eval e)
| Sign e -> Float.of_int (Math.Sign (eval e))
| Truncate e -> Math.Truncate (eval e)
| Factorial e -> Float.of_int (factorial (Int32.of_float (eval e)))
| Float f -> f
| Pi -> Math.PI
| E -> Math.E

Console.WriteLine (eval e)

Tillykke med din nye bog!

I kan downloade resten af vinder løsningen her.

Tags:

Comments

2/14/2010 1:46:23 PM #

اخبار

Thank you very much for the possibility to have a look into the office. Nice boy, he has got the talent to explain.

اخبار Egypt

2/28/2010 3:18:23 AM #

stock broker

Most of the time I don’t post comments on blogs, but I'd like to say that this post really forced me want to. Really nice post!

stock broker United States

2/28/2010 11:32:55 AM #

stock charts

I didn't see a button anywhere but do you allow advertising? I have several blogs in related niche and I would like to add my button somwhere on your webiste.

stock charts United States

3/4/2010 6:22:35 AM #

free hd movies

I like watching movies online, it is way easier than going to the theaters.

free hd movies United States

3/4/2010 8:13:37 AM #

watch movies online

I like streaming movies online, it is way easier than going to the theaters.

watch movies online United States

3/9/2010 8:43:53 PM #

WoW Mobile

Do you know which mobile phone companies allow tethering?

WoW Mobile United States

3/10/2010 12:01:34 AM #

WoW Mobile

Do you know which cell phone companies allow tethering?

WoW Mobile United States

3/17/2010 2:06:54 AM #

ssk sorgulama

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

ssk sorgulama United States

3/17/2010 11:48:35 AM #

arac sorgulama

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

arac sorgulama United States

3/20/2010 3:28:14 PM #

ehliyet

Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work.

ehliyet Denmark

3/20/2010 11:41:40 PM #

HD Movies

Do you know where I can watch movies online?

HD Movies United States

Add comment


(Will show your Gravatar icon)

(De 3 specielle karaktere i det danske alfabet?)
  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen