Noticed the same thing. I've updated the answer on SO to reflect the shortest
standard solution (45 chars), the generalized solution (49 chars), and added a
link to this thread.
I also note that the 2* in 2*+/ is a bit redundant with the _2 in _2 {.\ : if
we applied the +/ to the unfiltered matrix, we wouldn't need to double it.
Unfortunately, we can't just apply the _2 {.\ at the end, after the summation,
because it deletes the approximation of pi we appended immediately beforehand.
But perhaps some variation on that approach could yield an improvement (of at
most 2 chars, but hopefully at least 1).
-Dan
Please excuse typos; composed on a handheld device.
On Jul 22, 2013, at 10:48 PM, Raul Miller <[email protected]> wrote:
> You could replace *:@# with #*#
>
> That's all I can see at the moment.
>
> FYI,
>
> --
> Raul
>
> On Mon, Jul 22, 2013 at 10:13 PM, Marshall Lochbaum
> <[email protected]> wrote:
>> I don't have an SO account, so go ahead and post that. While I'm at it,
>> I shaved a character off the original by noting that the length of the
>> circle is half the diameter for even lengths. This doesn't hold for odd
>> lengths, so it won't help there.
>>
>> c=:({&' *',&":2*+/@,%*:@#)@:>_2{.\|@j./~@i:@<:
>>
>> Marshall
>>
>> On Mon, Jul 22, 2013 at 10:07:57PM -0400, Dan Bron wrote:
>>> Oh! Nice. If you have an account on SO feel free to post it, I'll vote it
>>> up past my original. If you don't, I'll replace mine with yours and link to
>>> your message on the Forum.
>>>
>>> -Dan
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of Marshall
>>> Lochbaum
>>> Sent: Monday, July 22, 2013 9:38 PM
>>> To: [email protected]
>>> Subject: Re: [Jprogramming] Code golf: approximate pi
>>>
>>> I haven't been able to shorten your code. But here's a version which handles
>>> odd numbers, at the cost of only two characters:
>>>
>>> c=:*:({&' *'@],&":2%(%+/@,))]>(|@j./~2&|#])@i:@<:
>>>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm