euler.helper
abundant-sum?
(abundant-sum? n)
abundant-sum? :: Int -> Boolean Can n be expressed as the sum of two abundant numbers?
abundant?
(abundant? n)
abundant? :: Int -> Bool Checks whether the sum of the factors of n (excluding n) is greater than n.
combinations
(combinations amount [car & cdr :as coins])
combinations :: Int, Int -> Int Returns the number of combinations that can be computed from the list of numbers.
count-divisors
(count-divisors n)
count-divisors :: Int -> Int Calculates the number of divisors of n (including 1 and n itself).
factor-any
(factor-any divisors argument)
factor-any :: Int -> Int -> Bool: Predicate that tests whether its argument can be evenly divided by any of the divisors.
factor?
factor? :: dividend:Int, divisor:Int -> Bool: Predicate that tests whether the divisor evenly divides the dividend.
fibs
fibs :: Int Lazy sequence of all Fibonacci numbers. Using BigIntegers.
Background: A Fibonacci number (exept 0 and 1) is recursively defined as the sum of its two predecessing Fibonacci numbers:
-
base case:
fib(n <= 1) = n
-
rec case:
fib(n > 1) = fib(n - 1) + fib(n - 2)
get-primes
(get-primes n)
(get-primes n [car & cdr :as ps] acc)
get-primes :: Int -> Int Get the prime divisors of n.
lattice-paths
(lattice-paths n)
lattice-paths :: Int -> Int The central binomial coefficients, Binomial2n, n or (2n)!/(n!)^2.
least-common-multiple
(least-common-multiple input)
least-common-multiple :: Int -> Int Computes the smallest number divisible by all of the given input numbers. See http://en.wikipedia.org/wiki/Least_common_multiple.
max-prime
(max-prime n [car & cdr :as ps])
max-prime :: Int, Int -> Int Given a number n and a list of prime numbers ps, returns the largest prime factor of n.
narcissistic?
(narcissistic? n exp)
narcissistic? :: Int, Int -> Bool Valid numbers can be written as the sum of its nth powers. Exp.: 1634 = 1^4 + 6^4 + 3^4 + 4^4.
next-collatz
(next-collatz n)
next-collatz :: Int -> Int Computes the next number of the collatz sequence.
palindrome?
(palindrome? n)
palindrome? :: Int -> Bool Checks whether the given number n is a palindrome. Uses reversed string comparison
parse-grid
(parse-grid grid-str dimension)
parse-grid :: String -> Int Converts a string into a dimension x dimension vector of integers.
prime-factors
(prime-factors n)
(prime-factors number factors ps)
** prime-factors :: Int -> Int** Given a number, returns the list of prime factors of n. Example: (prime-factors 12) => (2 2 3)
prime?
(prime? n)
prime? :: Int -> Bool Checks whether a given number n is a prime number.
primes
primes :: Int Lazy stream of prime numbers, generated by the sieve of Eratosthenes algorithm. Internally stores in a hastable the next composite number corresponding to the prime number. Taken from http://voidmainargs.blogspot.de/2010/12/ lazy-sieve-eratosthenes-in-scala-and.html
rotations
(rotations x)
Returns a lazy seq of all rotations of a seq. Taken from clojure.contrib(https://clojure.github.io/clojure-contrib/ seq-api.html#clojure.contrib.seq/rotations)
sum-of-factors
(sum-of-factors n)
sum-of-factors :: Int -> Int The sum of all proper divisors, excluding n.
to-words
(to-words n)
Converts a number (up to 1000) into its string representation, omitting spaces. Example: (to-words 115) => ‘onehundredandfifteen’.
triangle?
(triangle? n)
triangle? :: Int -> Bool Checks whether a given number n is a triangle number.
triangles
triangle :: Int Lazy seq of all triangle numbers. A triangle number is generated by adding the natural numbers up to n.
truncate
(truncate number digits)
truncate :: Int, Int -> Int Truncates the given number up to the first n digits.