http://beautifulcode.oreillynet.com/2008/03/four_lines_of_code_1.php

The example in the site is done in Haskell.

Following is done in J:

   d=:5 10 20 4 9 8 9
   f=:(3&((4%~[:+/ 1 2 1&*)\)@({.,],{:))
   f^:(<5) ] d
      5      10      20       4       9       8       9
   6.25   11.25    13.5    9.25     7.5     8.5    8.75
    7.5 10.5625  11.875   9.875  8.1875  8.3125  8.6875
8.26563  10.125 11.0469 9.95313 8.64063   8.375 8.59375
8.73047 9.89063  10.543 9.89844 8.90234 8.49609 8.53906
   load 'plot'
   plot f^:(<10) ] d
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to