Re: [R] A little exercise in R!

2012-04-14 Thread Ted Harding
Well, this "Olympiad" challenge led to some interesting responses. First, Bert Gunther noted that the arragement of 1:17 must have 17 at one end, allowing it to be solved on paper in a few minutes. That would definitely be in the spirit of the Olympiad, where '"In the Olympiad it's about starting w

Re: [R] A little exercise in R!

2012-04-13 Thread Justin Haynes
Since I thought this was a cool question, I posted it to StackOverflow. Vincent Zookynd's answer is amazing and really exercises the power of R. http://stackoverflow.com/questions/10150161/ordering-117-by-perfect-square-pairs/10150797#10150797 On Fri, Apr 13, 2012 at 10:06 PM, Bert Gunter wr

Re: [R] A little exercise in R!

2012-04-13 Thread Bert Gunter
... and a moment's more consideration immediately shows it cannot be done for n = 18, since 16,17, and 18 cannot all be at an end. -- Bert On Fri, Apr 13, 2012 at 9:59 PM, Bert Gunter wrote: > Folks: > > IMHO this is exactly the **wrong** way t go about this. These are > mathematical exercises t

Re: [R] A little exercise in R!

2012-04-13 Thread Bert Gunter
Folks: IMHO this is exactly the **wrong** way t go about this. These are mathematical exercises that should employ mathematical thinking, not brute force checking of cases. Consider, for example, the 1 to 17 sequence given by Ted. Then 17 **must** be one end of the sequence and 16 the other. (Why

Re: [R] A little exercise in R!

2012-04-13 Thread Petr Savicky
On Fri, Apr 13, 2012 at 10:34:49PM +0100, Ted Harding wrote: > Greetings all! > A recent news item got me thinking that a problem stated > therein could provide a teasing little exercise in R > programming. > > http://www.bbc.co.uk/news/uk-england-cambridgeshire-17680326 > > Cambridge Universit

Re: [R] A little exercise in R!

2012-04-13 Thread Philippe Grosjean
Hi all, I got another solution, and it would apply probably for the ugliest one :-( I made it general enough so that it works for any series from 1 to n (n not too large, please... tested up to 30). Hint for a better algorithm: inspect the object 'friends' in my code: there is a nice pattern

Re: [R] A little exercise in R!

2012-04-13 Thread Justin Haynes
I thought this was kinda cool! Here's my solution, its not robust or probably efficient I'd to hear improvements or other solutions! Justin sq.test <- function(a, b) { ## test for number pairs that sum to squares. sqrt(sum(a, b)) == floor(sqrt(sum(a, b))) } ok.pairs <- function(n, vec

[R] A little exercise in R!

2012-04-13 Thread Ted Harding
Greetings all! A recent news item got me thinking that a problem stated therein could provide a teasing little exercise in R programming. http://www.bbc.co.uk/news/uk-england-cambridgeshire-17680326 Cambridge University hosts first European 'maths Olympiad' for girls The first European gir