Re: [R] expand.grid game

2010-01-13 Thread baptiste auguie
It did take me a good night's sleep to understand it. I was stuck with the exact same question but I see now how the remaining balls are shared among all 8 urns (therefore cases with 11, 12, 13, ... 17 balls are also dealt with). Thanks again, baptiste 2010/1/12 Rolf Turner

Re: [R] expand.grid game

2010-01-12 Thread Greg Snow
[mailto:r-help-boun...@r- project.org] On Behalf Of Brian Diggs Sent: Thursday, December 31, 2009 3:08 PM To: baptiste auguie; David Winsemius Cc: r-help Subject: Re: [R] expand.grid game baptiste auguie wrote: 2009/12/19 David Winsemius dwinsem...@comcast.net: On Dec 19, 2009, at 9:06 AM

Re: [R] expand.grid game

2010-01-12 Thread baptiste auguie
] On Behalf Of Brian Diggs Sent: Thursday, December 31, 2009 3:08 PM To: baptiste auguie; David Winsemius Cc: r-help Subject: Re: [R] expand.grid game baptiste auguie wrote: 2009/12/19 David Winsemius dwinsem...@comcast.net: On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list

Re: [R] expand.grid game

2010-01-12 Thread Greg Snow
Message- From: baptiste auguie [mailto:baptiste.aug...@googlemail.com] Sent: Tuesday, January 12, 2010 12:20 PM To: Greg Snow Cc: r-help Subject: Re: [R] expand.grid game Nice --- am I missing something or was this closed form solution not entirely trivial to find? I ought to compile

Re: [R] expand.grid game

2010-01-12 Thread Rolf Turner
On 13/01/2010, at 9:19 AM, Greg Snow wrote: How trivial is probably subjective, I don't think it is much above trivial. I would not have been surprised to see this question on an exam in my undergraduate (300 or junior level) probability course (the hard part was remembering the details

Re: [R] expand.grid game --- never mind, I figured it out!

2010-01-12 Thread Rolf Turner
...@googlemail.com] Sent: Tuesday, January 12, 2010 12:20 PM To: Greg Snow Cc: r-help Subject: Re: [R] expand.grid game Nice --- am I missing something or was this closed form solution not entirely trivial to find? I ought to compile the various clever solutions given in this thread someday, it's

Re: [R] expand.grid game

2009-12-31 Thread Brian Diggs
baptiste auguie wrote: 2009/12/19 David Winsemius dwinsem...@comcast.net: On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hi library(partitions) jj - blockparts(rep(9,8),17) dim(jj) gives 318648 HTH rksh baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their

Re: [R] expand.grid game

2009-12-21 Thread baptiste auguie
Wow! system.time({ all = blockparts(rep(9,8),17) print( dim(all[,all[1,]!=0])[2] ) # remove leading 0s }) ## 229713 user system elapsed 0.160 0.068 0.228 In some ways I think this is close to Hadley's suggestion, though I didn't know how to implement it. Thanks a lot to everybody who

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hello again everybody. I fired off my reply before reading the correspondence about the leading zeros. You can also assume that there is at least one block at the leading position, [so that position can take 0,1,2,...,8 additional blocks] and distribute the remaining 16 blocks amongst all 8

Re: [R] expand.grid game

2009-12-21 Thread Ted Harding
I wonder whether this answers Baptiste's question as asked. 1: An 8-digit number can have some digits equal to 0; see Baptiste's comment maxi - 9 # digits from 0 to 9 2: According to the man-page fror blockparts in partitions, all sets of a=(a1,...,an) satisfying Sum[ai] = n subject to

Re: [R] expand.grid game

2009-12-21 Thread Ted Harding
OOPS!! See correction below! On 21-Dec-09 08:45:13, Ted Harding wrote: I wonder whether this answers Baptiste's question as asked. 1: An 8-digit number can have some digits equal to 0; see Baptiste's comment maxi - 9 # digits from 0 to 9 2: According to the man-page fror blockparts in

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hi Ted. you've found a bug in the documentation for blockparts(). It should read 0 = ai = yi. I'll fix it before the next major release (which will include sampling without replacement from a multiset, Insha'Allah). Best wishes rksh (Ted Harding) wrote: I wonder whether this answers

[R] expand.grid game

2009-12-19 Thread baptiste auguie
Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits equal to 17? The brute-force answer could be: maxi - 9 # digits from 0 to 9 N - 5 # 8 is too large test - 17

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits equal to 17? The brute-force answer could be: maxi -

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
2009/12/19 David Winsemius dwinsem...@comcast.net: On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits

Re: [R] expand.grid game

2009-12-19 Thread hadley wickham
I hope I have missed a better way to do this in R. Otherwise, I believe what I'm after is some kind of C or C++ macro expansion, because the number of loops should not be hard coded. Why not generate the list of integers that sum to 17, and then mix with 0s as appropriate? Hadley --

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 1:36 PM, baptiste auguie wrote: 2009/12/19 David Winsemius dwinsem...@comcast.net: On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
Hi, Thanks for the link, I guess it's some kind of a classic game. I'm a bit surprised by your timing, my ugly eval(parse()) solution definitely took less than one hour with a machine not so different from yours, system.time( for (i in 1079:1179) if (sumdigits(i)==17) {idx-c(idx,i)})

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
This problem does yield some interesting and unexpected distributions. Here is another, the number of positive cases as a function of number of digits (8 in the original question) and of test value (17). maxi - 9 N - 5 test - 17 foo - function(N=2, test=1){ sum(rowSums(do.call(expand.grid,

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 2:28 PM, baptiste auguie wrote: Hi, Thanks for the link, I guess it's some kind of a classic game. I'm a bit surprised by your timing, my ugly eval(parse()) solution definitely took less than one hour with a machine not so different from yours, system.time( for (i in