Description By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.What is the 10001st prime number?Solution (Improved)
My original solution was slow, and the code a bit ugly. The new solution is more idiomatic and dynamic than the original.
let isPrime n =
let upperBound = int32(sqrt(float(n)))
let allNumbers = [2..upperBound]
let divisors = allNumbers |> List.filter (fun div -> n % div = 0 && n <> div)
if List.length divisors = 0 then
let rec recursePrimes num count max =
if count = max then
if isPrime num then
recursePrimes (num+1) (count+1) max
recursePrimes (num+1) (count) max
let UT_recursePrimes = recursePrimes 2 0 10001
let primeFind find =
let x = (find /10) * (find /10)
let upperBound = Convert.ToInt32(System.Math.Sqrt(Convert.ToDouble(x)))
I recently published a library of mine to NuGet, as Mathematical Library. It is a library for functions used in solving Project Euler problems along with some basic statistical functions, coded in F#. The Project Euler functions cover primes, factorials, narcissism, random numbers, arrays and series/sequences (Collatz, Terra, Fibonacci). The statistical functions cover variance, standard deviation, and sum of squares.
In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
It is possible to make £2 in the following way:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins? Original problem description...
This is a clean, although slow, solution, taking longer than one minute to complete.
// code for finding result, returned as a sequence
let sumCurrencies ones twos fives tens twenties fifties oneHundreds twoHundreds limit =
[let counter = 0
for twoHundred in twoHundreds do
for oneHundred in oneHundreds do
for fifty in fifties do
for twenty in twenties do
for ten in tens do
for five in fives do