The challenge seems to be here: http://www.paulgraham.com/accgen.html
A quetion: why doesn't &+ satisfy the problem? The definition of function to a Lisp'ite is rather loose, no? ------------------------------------------------------------------------ |\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram) |/\| [EMAIL PROTECTED] | |\ | | The only real problem with APL is that BSc(Math) UNBF'83 | it is "still ahead of its time." Sapere Aude | - Morten Kromberg Natural Born APL'er | Demo website: http://156.34.80.240/ -----------------------------------------------------(INTP)----{ gnat }- ----- Original Message ----- From: "Martin Freedman" <[EMAIL PROTECTED]> To: "General forum" <[email protected]> Sent: Monday, December 11, 2006 2:54 PM Subject: [Jgeneral] Paul Graham's Accumulator Challenge Again - a 4 linesolution (help me make it 3 or less!) > Having searched the forum and the wiki I still have yet to see a > proper answer to Paul Graham's Accumulator challenge. Dan Bron's > answer is a one-liner but requires a long lexicalclosure script (more > than 3 or 4 lines anyway) which does more than the accumulator > challenge asks, also uses needs jmf and only runs under windows. > Whilst there have been various references to using locales I have seen > are no actual answers. And as a j noobie I offer one here > > foo=: 1 : 0 > Xc=.'_',~'X_',>c=. cocreate '' > X__c=: x > r=. Xc,'=:',Xc,'+y' > 3 : r > ) > bar2=: 2 foo > bar2 2 > 4 > bar2 2 > 6 > bar3=: 3 foo > bar3 2 > 5 > bar2 5 > 11 > > I tried to combine the last two lines of foo but I had difficulty > getting this right with Do ". > > foo1=: 1 : 0 > Xc=.'_',~'X_',>c=. cocreate '' > X__c=: x > 3 : ". 'Xc,''=:'',Xc,''+y''' > ) > > bar2=: 2 foo1 > |domain error: foo1 > | 3 :".'Xc,''=:'',Xc,''+y''' > > Anyway pleased with a 4 line solution since I have not, possibly > mistakenly, seen anything similar and as short (judging by the wiki > solution not using locales) > > I am sure there are other ways of making it less lines, but at least > this is sort of readable to non j users, if I were add a couple of > NB.s etc. > > This works for all number types as far as I can tell e.g. > > barcomplex =: 1j2 foo > barcomplex 2j3 > 3j5 > > -- > martin > > "Reality is that which, when you stop believing in it, doesn't go away" PK Dick > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
