R User Group Meeting, London

On Tuesday March 31st, Mango Solutions are sponsoring the inaugural London R User Group Meeting. It will be a great opportunity to meet other R users and find out how people are using it. As the first one of its kind in London, I would expect a high level of interest. There will be a number of speakers presenting on various topics, using the UseR! panel format (short talks at around 15 minutes or so). I will be giving a short presentation, most likely following on from the real-time data integration work I presented on at UseR! 2008.

See this page for details on the event:

http://www.mango-solutions.com/events/UseRLondon.html

Posted in R

Project Euler Problem #28

Problem 28 on the Project Euler website asks what is the sum of both diagonals in a 1001×1001 clockwise spiral. This was an interesting one: the relationship between the numbers on the diagonals is easy to deduce, but expressing it succinctly in R took a little bit of tweaking. I’m sure it could be compressed even further.

spiral.size <- function(n) {
        stopifnot(n %% 2 ==1)
        
        if (n==1) {
                return(1)
        }
        sum(cumsum(rep(2*seq(1,floor(n/2)), rep(4,floor(n/2))))+1)+1
}

spiral.size(1001)

Project Euler Problem #22

Problem 22 on Project Euler proves a text file containing a large number of comma-delimited names and asks us to calculate the numeric sum of the alphabetical score for each name multiplied by the name’s position in the original list. This is made slightly easier by the presence of the predefined LETTERS variable in R.

problem22 <- function() {
        namelist <- scan(file="c:/temp/names.txt", sep=",", what="", na.strings="")
        sum(unlist(
                lapply(namelist, 
                        function(Z) which(namelist==Z) * sum(match(unlist(strsplit(Z,"")), LETTERS)))))
}