-:<:sqrt 5
0.618034
  
   ,.(-:<:sqrt 5)^i.30
          1
   0.618034
   0.381966
   0.236068
   0.145898
  0.0901699
  0.0557281
  0.0344419
  0.0212862
  0.0131556
 0.00813062
   0.005025
 0.00310562
 0.00191938
 0.00118624
0.000733137
0.000453104
0.000280034
 0.00017307
0.000106963
  6.6107e_5
 4.08563e_5
 2.52506e_5
 1.56057e_5
 9.64488e_6
 5.96086e_6
 3.68401e_6
 2.27685e_6
 1.40717e_6
 8.69678e_7
   
   +/(-:<:sqrt 5)^i.30
2.61803
   
Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Friday, December 13, 2013 4:41 AM
To: [email protected]
Subject: Re: [Jprogramming] Under for fun & profit

    -:<:sqrt 5
0.618034
   
Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Roger Hui
Sent: Thursday, December 12, 2013 5:40 PM
To: Programming forum
Subject: Re: [Jprogramming] Under for fun & profit

   sqrt1=: (] -:@+ %)^:_~
   x -: *: sqrt1 x=: 100 ?@$ 1000
1
   x -: *: sqrt1 x=: 100 ?@$ 0
1




On Thu, Dec 12, 2013 at 1:31 PM, Roger Hui <[email protected]>wrote:

> Ooops.  A longer but correct solution.  Can probably be shortened.
>
>    sqrt=: (0.5 * ] + %)^:_ ~
>    sqrt 3
> 1.73205
>    sqrt 17
> 4.12311
>
>
>
>
> On Thu, Dec 12, 2013 at 1:29 PM, Roger Hui
<[email protected]>wrote:
>
>>    sqrt=: -:@(+%)^:_~
>>    sqrt 3
>> 1.78078
>>    sqrt 17
>> 8.55842
>>
>>
>>
>> On Thu, Dec 12, 2013 at 1:22 PM, William Tanksley, Jr < 
>> [email protected]> wrote:
>>
>>> I'm clueless -- how would you implement one of the more formally 
>>> correct solutions (Newton's, Babylonian, exhaustive search, or 
>>> random probing)? K did pretty well.
>>>
>>> -Wm
>>>
>>>
>>> On Thu, Dec 12, 2013 at 11:09 AM, Dan Bron <[email protected]> wrote:
>>> > There is a stack exchange dedicated to code golfing, 
>>> > http://codegolf.stackexchange.com/ . During free moments at work, 
>>> > I
>>> find
>>> > posting J solutions is a good way to relieve stress.
>>> >
>>> > Today I came across a competition to reimplement square root in as 
>>> > few characters as possible [1]. Most languages copped out and 
>>> > simply
>>> restated
>>> > sqrt as ^&0.5 to minimize their golf score.  (I did this too, to 
>>> > allow apples-to-apples comparisons).
>>> >
>>> > But the C++ entry caught my eye:  exp(log(x)/2)) .  This is an
>>> interesting
>>> > approach, and gives us an opportunity to highlight some of the
>>> advantages
>>> > of J's notaton. Leaving aside the question of syntax, even 
>>> > expressing
>>> the
>>> > 4 primitives in that expression (exp, log, x, 2) would cost most
>>> languages
>>> > 8 characters.  But not in J.  In J, we do NOT need:
>>> >
>>> >    - To name variables (so no "x")
>>> >    - To name the constant 2 (in this particular case)
>>> >    - To delimit functions from arguments using parentheses
>>> >    - To explicitly instruct the intreprter to undo the log by 
>>> > typing
>>> "exp".
>>> >
>>> > This last freebie is perhaps the most satisfying.  We just tell 
>>> > the interpreter that we want to operate "log space", and let J 
>>> > figure out
>>> the
>>> > exp for itself.
>>> >
>>> >    -:&.^.
>>> >
>>> > Six characters.  Less than it takes to write "log" and "exp" 
>>> > separated
>>> by a
>>> > single space!
>>> >
>>> > -Dan
>>> >
>>> > [1]
>>> >
>>> http://codegolf.stackexchange.com/questions/73/reimplementing-square
>>> -root/15856
>>> >
>>> > ------------------------------------------------------------------
>>> > ---- For information about J forums see 
>>> > http://www.jsoftware.com/forums.htm
>>> --------------------------------------------------------------------
>>> -- For information about J forums see 
>>> http://www.jsoftware.com/forums.htm
>>>
>>
>>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

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

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

Reply via email to