Categories

## Project Euler Problem #15

Problem 15 on Project Euler asks us to find the number of distinct routes between the top left and bottom right corners in a 20×20 grid, with no backtracking allowed.

I originally saw this type of problem tackled in the book Notes On Introductory Combinatorics, by George Polya amongst others. This book is hard to find now, but it is a really clear intro to combinatoric math.

The solution can be paraphrased as follows: if the grid is of size 20×20, and it takes 2 movements to navigate a single square in the grid, then we must make a total of 40 movements to get from the top right to the bottom left. Exactly half of these movements will be left-to-right, and the other half will be up-down. The total number of distinct routes is the number of ways that we can choose 20 of each type of move from the 40 total moves required. So we need the combinatoric construct n-choose-k, or how many ways k items can be selected from n total items. This is represented as $$n\choose k$$.

In R, calculating ${40\choose 20}$ is just:

choose(40, 20)

Categories

## Learning Lilypond : Luciana’s Theme

There is a whole bunch of obscure and wonderful music out there that I have been meaning to transcribe and arrange for the piano, and so I have been looking around for decent music transcription software, and I recently came across lilypond. This is to music engraving what TeX is to mathematical typesetting, and the results are really very nice. The downside of lilypond (as with TeX) is the slightly steep initial learning curve. To put it to the test, I have transcribed a piece of music that I came across a while ago – it’s called “Tema Par Luciana”, and is from an old Italian movie called C’eravamo tanto amati. I haven’t seen the movie, but I came across the theme in a mix created by a French DJ called elektrosonik. The piece is simple enough that it was pretty straightforward to transcribe, but also has enough variety that it is a good starting point for learning lilypond techniques.

Here is the PDF output (Lilypond will also produce a MIDI file if asked):

And here is the lilypond source: luciana.ly

Categories

## Project Euler Problem #13

Problem 13 on Project Euler asks us to sum 100 50-digit numbers and give the first 10 digits of the result. This is pretty easy. Note we are using R’s integer division operator %/% to discard the remainder of the large summed integer and just gives us the first 10 digits of the result.

## Problem 13
problem13 <- function() {
nums <- scan("problem13.dat")
s <- sum(nums)
s %/% 10^(floor(log10(s))9)
}