For this post, I attempted to reconstruct a famous visualization of Napoleon’s March to Moscow. The French Invasion of Russia is considered a major turning point in the Napoleonic Wars. Up until that point, Napoleon’s army was vast in size. By the end of his March on Moscow, the French army was reduced to a tiny fraction of its size.

Pictured above is Charles Minard’s flow map of Napoleon’s march. It is simply amazing that such a detailed and innovative graphic was published in 1869 (way before the first computer). Minard was truly a pioneer in the use of graphics in engineering and statistics.

Read on →

Today I’ll be discussing a way to find all primes up to a certain number using the Sieve of Eratosthenes. The algorithm is useful for many Project Euler problems and it was an interesting challenge to code in R.

1
2
3
4
5
6
7
8
9
10
SieveOfE <- function(n) {
 primes <- rep(TRUE, n)
 primes[1] <- FALSE
 last.prime <- 2
 while (last.prime <= sqrt(n)) {
   primes[seq.int(2*last.prime, n, last.prime)] <- FALSE
   last.prime <- last.prime + min(which(primes[(last.prime + 1) : n]))
 }
 which(primes)
}
Read on →