Ejemplo n.º 1
0
func main() {
	euler.Init(10, "Find the sum of all the primes below N.")
	euler.PrintTime("N = 10  | Using local Sieve without []int. Result: %v, Nanoseconds: %d\n", solution, 10)
	euler.PrintTime("N = 10  | Using packaged PrimesUpTo.       Result: %v, Nanoseconds: %d\n", solution2, 10)
	euler.PrintTime("N = 2e6 | Using local Sieve without []int. Result: %v, Nanoseconds: %d\n", solution, int(2e6))
	euler.PrintTime("N = 2e6 | Using packaged PrimesUpTo.       Result: %v, Nanoseconds: %d\n", solution2, int(2e6))
}
Ejemplo n.º 2
0
func main() {
	primes := euler.PrimesUpTo(100000)
	euler.Init(21, "Evaluate the sum of all the amicable numbers under...")
	euler.PrintTime("Under    220 | Result: %v, Nanoseconds: %d\n", solution, 220, &primes)
	euler.PrintTime("Under    284 | Result: %v, Nanoseconds: %d\n", solution, 284, &primes)
	euler.PrintTime("Under  10000 | Result: %v, Nanoseconds: %d\n", solution, 10000, &primes)
	euler.PrintTime("Under 100000 | Result: %v, Nanoseconds: %d\n", solution, 100000, &primes)
}
Ejemplo n.º 3
0
func main() {
	euler.Init(14, "Using the rules:\n\n"+
		"  n -> n/2 (n is even)\n"+
		"  n -> 3n + 1 (n is odd)\n\n"+
		"Which starting number, under one million, produces the longest chain?")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, int(1e6))
}
Ejemplo n.º 4
0
func main() {
	euler.Init(7, "What is the Nst prime number?")
	euler.PrintTime("N = 6     | Appending primes.       Result: %v,\t\tNanoseconds: %d\n", AppendingPrimes, 6)
	euler.PrintTime("N = 6     | Sieve of Eratosthenes.  Result: %v,\t\tNanoseconds: %d\n", Sieve, 6)
	euler.PrintTime("N = 6     | With Packaged Sieve.    Result: %v,\t\tNanoseconds: %d\n", PackagedSieve, 6)
	euler.PrintTime("N = 6     | With the overview code. Result: %v,\t\tNanoseconds: %d\n", Overview, 6)
	euler.PrintTime("N = 10001 | Appending primes.       Result: %v,\tNanoseconds: %d\n", AppendingPrimes, 10001)
	euler.PrintTime("N = 10001 | Sieve of Eratosthenes.  Result: %v,\tNanoseconds: %d\n", Sieve, 10001)
	euler.PrintTime("N = 10001 | With Packaged Sieve.    Result: %v,\tNanoseconds: %d\n", PackagedSieve, 10001)
	euler.PrintTime("N = 10001 | With the overview code. Result: %v,\tNanoseconds: %d\n", Overview, 10001)
}
Ejemplo n.º 5
0
func main() {
	euler.Init(4, "Find the largest palindrome made from the product of two N-digit numbers.")
	euler.PrintTime("N = 2 | Result: %v, Nanoseconds: %d\n", solution, 2)
	euler.PrintTime("N = 3 | Result: %v, Nanoseconds: %d\n", solution, 3)
}
Ejemplo n.º 6
0
func main() {
	euler.Init(16, "What is the sum of the digits of the number 2^1000?")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, math.Pow(2, 1000))
}
Ejemplo n.º 7
0
func main() {
	euler.Init(20, "Find the sum of the digits in the number 100!")
	euler.PrintTime("For 10  | Result: %v, Nanoseconds: %d\n", solution, 10)
	euler.PrintTime("For 100 | Result: %v, Nanoseconds: %d\n", solution, 100)
}
Ejemplo n.º 8
0
func main() {
	euler.Init(8, "Find the greatest product of five consecutive digits in the 1000-digit number.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution)
}
Ejemplo n.º 9
0
func main() {
	euler.Init(11, "What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution)
}
Ejemplo n.º 10
0
func main() {
	euler.Init(5, "What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?")
	euler.PrintTime("Index by index.     Result: %v, Nanoseconds: %d\n", lcm, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
	euler.PrintTime("Generated sequence. Result: %v, Nanoseconds: %d\n", lcm, euler.Sequence(1, 20)...)
}
Ejemplo n.º 11
0
func main() {
	euler.Init(2, "By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, int(4e6))
}
Ejemplo n.º 12
0
func main() {
	euler.Init(6, "Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, 100)
}
Ejemplo n.º 13
0
func main() {
	euler.Init(15, "How many such routes are there through a 20×20 grid?")
	euler.PrintTime("Combinatorial Solution. Result: %v, Nanoseconds: %d\n", solution, 20)
}
Ejemplo n.º 14
0
func main() {
	euler.Init(3, "What is the largest prime factor of the number 600851475143 ?")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, 600851475143)
}
Ejemplo n.º 15
0
func main() {
	euler.Init(19, "How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?")
	euler.PrintTime("Full specs   | Result: %v, Nanoseconds: %d\n", solution, 1901, 2000)
	euler.PrintTime("Smaller code | Result: %v, Nanoseconds: %d\n", solution2, euler.Sequence(1901, 2000)...)
	euler.PrintTime("Math         | Result: %v, Nanoseconds: %d\n", solution3, 100)
}
Ejemplo n.º 16
0
func main() {
	euler.Init(13, "Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution)
}
Ejemplo n.º 17
0
func main() {
	euler.Init(12, "What is the value of the first triangle number to have over N divisors?")
	euler.PrintTime("N = 5   | Result: %v, Nanoseconds: %d\n", solution, 5)
	euler.PrintTime("N = 500 | Result: %v, Nanoseconds: %d\n", solution, 500)
}
Ejemplo n.º 18
0
func main() {
	euler.Init(1, "Find the sum of all the multiples of 3 or 5 below 1000.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, 1000)
}
Ejemplo n.º 19
0
func main() {
	euler.Init(9, "There exists exactly one Pythagorean triplet for which a + b + c = 1000.")
	euler.PrintTime("Result: %v, Nanoseconds: %d\n", solution, 1000)
}
Ejemplo n.º 20
0
func main() {
	euler.Init(17, "If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?")
	euler.PrintTime("N = 342 | Result: %v, Nanoseconds: %d\n", solution, 342)
	euler.PrintTime("N = 115 | Result: %v, Nanoseconds: %d\n", solution, 115)
	euler.PrintTime("N = 1000 | Result: %v, Nanoseconds: %d\n", solution, euler.Sequence(1, 1000)...)
}
Ejemplo n.º 21
0
func main() {
	euler.Init(22, "What is the total of all the name scores in the file?")
	euler.PrintTime("For COLIN   | Result: %v, Nanoseconds: %d\n", solution, "COLIN")
	euler.PrintTime("For the file | Result: %v, Nanoseconds: %d\n", solution, euler.Download("https://projecteuler.net/project/names.txt"))
}
Ejemplo n.º 22
0
func main() {
	euler.Init(18, "Find the maximum total from top to bottom of the given triangle.")
	euler.PrintTime("Problem 18 | Result: %v, Nanoseconds: %d\n", solution, triangle_18)
	euler.PrintTime("Problem 67 | Result: %v, Nanoseconds: %d\n", solution, triangle_67)
}