Here's another option.   

   a=:>:i.250
   b=:>:?1000000#250
   f=: 13 :'+/"1 x=/y'
  (>:i.250) f >:?1000000#250
  (>:i.250) f >:?1000000#250

Linda


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kenneth
Lettow
Sent: Wednesday, December 11, 2013 1:17 PM
To: [email protected]
Subject: Re: [Jprogramming] Data from kaggle competition: packing Santa's
sleigh

How about

   a=: 1 2 3 4 5 6
   b=: 14 3 2 5 6 2 1 1 2 3 4 2 3
   +/"1 (a=/b)
2 4 3 1 1 1
   {:"1 /:~(~.,#)/.~(#a)-.~a i. b
2 4 3 1 1 1
   NB. make it a verb
   doit=: 4 : '{:"1 /:~(~.,#)/.~(#x)-.~x i. y'
   a doit b
2 4 3 1 1 1
   NB. larger args
   a=: >: i.100000
   b=: ?100000000$200000
   a doit b
516 504 497 519 505 501 498 495 485 495 503 534 500 508 482 496 495 512 518
558 484 491 487 527 497 510 490 477 491 474 506 475 457 461 426 ...
   ts=: 6!:2,7!:2@]  NB. time & space
   ts'a doit b'
8.0017 3.84198e9




On Wed, Dec 11, 2013 at 12:11 PM, Ni Bo <[email protected]> wrote:

> Hi,
>
> I'm using the data off the kaggle competition to learn some j.
>
> This simple code works for these short strings:
>   a=:1 2 3 4 5 6
>   b=:14 3 2 5 6 2 1 1 2 3 4 2 3
> +/"1 (a=/b)
> 2 4 3 1 1 1
>
> But if I try it for longer strings #a 250 and #b 1 000 000 I get out 
> of memory.
>
> Can you please help me with a better way?
>
> Nick
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



--
*Kenneth Lettow*
*Director of Web Analytics and Market Intelligence*
*ThomasNet.com*
Five Penn Plaza, 8th Floor
New York, NY 10001
*: [email protected]
*(*: 212.290.8713
www.thomasnet.com
----------------------------------------------------------------------
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