This is a good example of a really annoying limitation of the current 
interpreter's eager evaluation strategy, in this cases one is forced to come up 
with some sort of non idiomatic iterative 'hack' to get a result. Concretely, I 
guess you're forced to use an accumulator with ^: or an explicit loop, which 
hurts.

________________________________
From: Programming <programming-boun...@forums.jsoftware.com> on behalf of Skip 
Cave <s...@caveconsulting.com>
Sent: Saturday, May 19, 2018 10:43:45 PM
To: programm...@jsoftware.com
Subject: [Jprogramming] Quora Problem

Another interesting quora problem:

How many distinct triplets have a sum of 1,000,000 (provided all numbers
are integers and are positive)?
<https://www.quora.com/qemail/track_click?al_imp=eyJ0eXBlIjogMzUsICJoYXNoIjogMTcxMDQ0NjU4Mn0%3D&al_pri=QuestionLinkClickthrough&aoid=oMo937UDzj8&aoty=2&aty=4&click_pos=1&ct=1526747413834671&et=103&id=62216bf7b30d40aea1d79bf4401c8317&request_id=289&src=1&st=1526747413838426&stories=2518686273&uid=bqluVqSeN78&v=0>

​The obvious straightforward solution would be to use the odometer verb:​

odo=: #: i.@(*/)

1e6=+/"1 odo 3#1e6

|limit error: odo

| 1000000=+/"1 odo 3#1000000


Ooops. Unfortunately, I don't have near enough memory to use this approach.

Any suggestions?


Skip

​

Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
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