Publications by Peter Prevos
Project Euler 7: 10,001st Prime Number
Project Euler 7 delves into the wonderful world of prime numbers. These numbers are interesting because they don't follow a predictable pattern. There is no algorithm to calculate primes, which is what makes them valuable in cryptography. As the numbers get larger, the gaps between consecutive primes also increase. There are, however, some intere...
1903 sym R (1147 sym/2 pcs) 2 img
Simulating Text Files with R to Test the Emacs Denote Package
Emacs is the most user friendly piece of software ever invented by humanity. I use it for 90% of my computing task, including keeping my digital knowledge garden with notes. Several notes packages exist, with Org Roam as the most popular and fully-featured. I have used this package for a while now, but it relies on a database and has grown a feat...
3888 sym R (1894 sym/2 pcs)
Euler Problem 1: Multiples of 3 or 5
Euler Problem 1 Definition If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Solution There are four ways to solve this problem in R. Brute force loop through all numbers from 1 to 999 and test whether they are ...
1701 sym R (444 sym/2 pcs) 10 img
Euler Problem 2: Even Fibonacci Numbers
Euler Problem 2 Definition Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. Solution The code generates Fibonacci numbers u...
1497 sym R (412 sym/2 pcs) 4 img
Euler Problem 3: Largest Prime Factor
Euler Problem 3 Definition The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? Generating Prime Numbers This solution relies on two functions that can be used for multiples problems. The Sieve of Eratosthenes generates prime numbers from 2 to n. The code is commented to explain the sieve a...
1567 sym R (1236 sym/2 pcs) 2 img
Euler Problem 4: Largest Palindromic Product
Euler Problem 4 Definition A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. Solution This code searches fo palindromic numbers, starting at the highest values. The palindromes are tested b...
1271 sym R (436 sym/1 pcs) 2 img
Euler Problem 5: Smallest Multiple
Euler Problem 5 relates to the divisibility of numbers. Euler Problem 5 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? Solution The solution will also be divisible by the number 1 to 10 so ...
958 sym R (208 sym/1 pcs)
Euler Problem 6: Sum Square Difference
Euler Problem 6 Definition The sum of the squares of the first ten natural numbers is: The square of the sum of the first ten natural numbers is: The difference between the sum of the squares of the first ten natural numbers and the square of the sum is . Find the difference between the sum of the squares of the first one hundred natural number...
1609 sym R (98 sym/2 pcs) 10 img
Euler Problem 7: 10,001st Prime
Euler Problem 7 Definition 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 1,0001st prime number? Solution The is.prime function determines whether a number is a prime number by checking that it is not divisible by any prime number up to the square root of the number. The Sieve of...
1229 sym R (384 sym/1 pcs) 2 img
Euler Problem 8: Largest Product in a Series
Euler Problem 8 is a combination of mathematics and text analysis. The problem is defined as follows: Euler Problem 8 Definition The four adjacent digits in the 1,000-digit number below that have the greatest product are . 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459...
2354 sym R (1367 sym/1 pcs) 2 img