Here's my solution to PE5.

(**

* Gives true when n is evenly divisible for each number in list

*

* @method EvenlyDivisible

* @param {int list} list

* @param {int} n

* @return {bool} True when number is evenly divisible for each number in list, else false

*)

let EvenlyDivisible list n = list |> List.forall ((%) n >> (=) 0)

(**

* Active pattern for Divisible/Undivisible

*

* @method Divisible|Undivisible

* @param {int} n

* @return {Choice<unit,unit> Divisible when n is evenly divisible with every number up to 20, else Undivisible

*)

let (|Divisible|Undivisible|) n =

if (EvenlyDivisible [11;12;13;14;15;16;17;18;19;20] n) then Divisible

else Undivisible

(**

* Find the first number that is "Divisible"

*

* @method find

* @param {int} n

* @return {int} First number that is considered "Divisible"

*)

let rec find n =

match n with

| Divisible -> n

| _ -> find (n + 1)

// Run

find 21

By on 6/30/2011 11:39 PM ()

Are there parts of the code missing due to formatting problems?

If not, you should learn some more about the basics of functional programming first, for example here: [link:en.wikibooks.org]

By on 6/10/2011 12:22 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper