Link to Snippet

Ninety-Nine F# Problems - Problems 31 - 41 - Arithmetic]

These are F# solutions of Ninety-Nine Haskell Problems which are themselves translations of Ninety-Nine Lisp Problems and Ninety-Nine Prolog Problems. The solutions are hidden so you can try to solve them yourself.

/// Ninety-Nine F# Problems - Problems 31 - 41 ////// These are F# solutions of Ninety-Nine Haskell Problems /// (http://www.haskell.org/haskellwiki/H-99:_Ninety-Nine_Haskell_Problems), /// which are themselves translations of Ninety-Nine Lisp Problems/// (http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)/// and Ninety-Nine Prolog Problems/// (https://sites.google.com/site/prologsite/prolog-problems).////// If you would like to contribute a solution or fix any bugs, send /// an email to paks at kitiara dot org with the subject "99 F# problems". /// I'll try to update the problem as soon as possible.////// The problems have different levels of difficulty. Those marked with a single asterisk (*) /// are easy. If you have successfully solved the preceeding problems you should be able to /// solve them within a few (say 15) minutes. Problems marked with two asterisks (**) are of /// intermediate difficulty. If you are a skilled F# programmer it shouldn't take you more than /// 30-90 minutes to solve them. Problems marked with three asterisks (***) are more difficult. /// You may need more time (i.e. a few hours or more) to find a good solution////// Though the problems number from 1 to 99, there are some gaps and some additions marked with /// letters. There are actually only 88 problems.

/// See problem 34 for the definition of Euler's totient function. If the list of the prime /// factors of a number m is known in the form of problem 36 then the function phi(m) /// can be efficiently calculated as follows: Let ((p1 m1) (p2 m2) (p3 m3) ...) be the list of /// prime factors (and their multiplicities) of a given number m. Then phi(m) can be /// calculated with the following formula:/// phi(m) = (p1 - 1) * p1 ** (m1 - 1) + /// (p2 - 1) * p2 ** (m2 - 1) + /// (p3 - 1) * p3 ** (m3 - 1) + .../// /// Note that a ** b stands for the b'th power of a. /// /// Note: Actually, the official problems show this as a sum, but it should be a product./// > phi 10;;/// val it : int = 4(Solution)

/// Use the solutions of problems 34 and 37 to compare the algorithms. Take the /// number of reductions as a measure for efficiency. Try to calculate phi(10090) as an /// example./// /// (no solution required) ///

/// Goldbach's conjecture says that every positive even number greater than 2 is the /// sum of two prime numbers. Example: 28 = 5 + 23. It is one of the most famous facts /// in number theory that has not been proved to be correct in the general case. It has /// been numerically confirmed up to very large numbers (much larger than we can go /// with our Prolog system). Write a predicate to find the two prime numbers that sum up /// to a given even integer./// /// Example: /// * (goldbach 28)/// (5 23)/// /// Example in F#: /// /// *goldbach 28/// val it : int * int = (5, 23)(Solution)