On Wed, Sep 23, 2009 at 5:43 PM, Nicholas Spies <[email protected]> wrote:
> I summed the first 100 digits of  %:2 and got 442 instead of the
> expected 475.
> This lead me to look at

Try something like this,

   ]s2 =: <.@:%: 2*10x^200
14142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727
   NB. J computes <.@:%: exactly on bigints, which we can verify like this:
   *:s2
1999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997921066900256462438170679779231122858093966573842870223186995499050449327265013245005275895702631184
   *:>:s2
2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000749494025002652535774057227650519015233310324596766369540354975031914284189227322706050964357914329
   NB. thus s2 is indeed the exact floor of (2^99) times square root
two.  (If J didn't have this built in, you could implement it by eg.
interval halving or even something that converges faster but for this
application simple interval halving would be fast enough)
   NB. now just sum its decimals:
   +/(100$10)#:s2
475

There are other solutions of course.

Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to