[Jprogramming] Data from kaggle competition: packing Santa's sleigh
Linda Alvord
lindaalvord at verizon.net
Thu Dec 12 00:57:43 UTC 2013
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: programming-bounces at forums.jsoftware.com
[mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Kenneth
Lettow
Sent: Wednesday, December 11, 2013 1:17 PM
To: programming at jsoftware.com
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 <nicolaeborota at gmail.com> 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
*: klettow at thomasnet.com
*(*: 212.290.8713
www.thomasnet.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list