[Jprogramming] largest rectangle problem
'Mike Day' via Programming
programming at jsoftware.com
Sat Jun 24 10:06:38 UTC 2017
Oops - that diagnostic "q" was unnecessary:
c =: 3 : 0
m =. >./y
for_i. }.>:i.#y do.
m =. m >. >./ i ([ * <./\) y
end.
)
ts'c qq'
0.0143082 21632
M
On 24/06/2017 10:53, 'Mike Day' via Programming wrote:
> This explicit version is faster and much less space intensive;
>
> same idea but the do loop avoids holding the square array.
>
> Still no early stopping condition though:
>
> c =: 3 : 0
>
> m =. >./y
>
> for_i. }.>:i.#y do.
>
> m =. m >. >./ q =. i ([ * <./\) y
>
> end.
>
> )
>
> ts'a qq' NB. qq as previous post, below
>
> 0.0316207 2.24246e7
>
> ts'c qq'
>
> 0.0149281 28544
>
> Thanks,
>
> Mike
>
>
> On 24/06/2017 10:09, 'Mike Day' via Programming wrote:
>> Having at last had a go at solving this, post breakfast (if not Brexit).
>> I don't think it's a new approach, but it's fairly nifty.
>>
>> It considers run lengths times heights.
>>
>> a =: >./^:2@:(>:@i.@# ([ * <./\) ])
>> qq=:1000?.1000000
>>
>> a qq
>>
>> 7030779
>>
>>
>> ts'a qq' NB. time & space
>> 0.0328879 2.24246e7
>>
>> ts'maxsqr qq'
>> 0.0385574 322944
>>
>> So - marginally faster, but rather space intensive.
>>
>> Probably better with a stopping condition, perhaps using ^:_ ,
>> rather than
>> doing all possible heights, but the code would be a bit more
>> complicated, I think.
>>
>> Cheers,
>>
>> Mike
>>
>>
>>
>> On 21/06/2017 14:12, Raul Miller wrote:
>>> nsqr=: [ * maxbitlen at ceilpos"0 1~
>>> maxsqr=: >./@(nsqr ~.)
>>
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list