[Jprogramming] Quora problem

2019-10-23 Thread Skip Cave
I occasionally try to solve Quora math problems to polish my J skills. Here's a problem that * "The integer 2018 can be written uniquely as the sum of consecutive squared integers. How many squares does the sum contain?"* a=.2^~i.100 NB. Find how many consecutive squared integers it takes to sum

Re: [Jprogramming] Creating a distance matrix.

2019-10-23 Thread Ric Sherlock
Using the utilities below you could do the following: makeSym > vec2LowerTri 0 1.5 0 2 1.5 0 2.5 2 1.5 0 0 1.5 2 2.5 1.5 0 1.5 2 2 1.5 0 1.5 2.5 2 1.5 0 NB.*zeroTri a Zeros triangular items of matrix determined by verb to left NB. EG: < zeroTri mat NB. zeros lower-tri items of mat NB. EG:

Re: [Jprogramming] Multiple Takes

2019-10-23 Thread R.E. Boss
Nothing personal intended. R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens Raul Miller > Verzonden: woensdag 23 oktober 2019 18:52 > Aan: Programming forum > Onderwerp: Re: [Jprogramming] Multiple Takes > > Sure... if you change the problem it's important to change t

Re: [Jprogramming] Multiple Takes

2019-10-23 Thread Raul Miller
Sure... if you change the problem it's important to change the solution to match... Thanks, -- Raul On Wed, Oct 23, 2019 at 12:49 PM R.E. Boss wrote: > > The solutions with { are rather inefficient as one can imagine, which can be > seen by scaling > >ts' ~.".~.@>,{10#<''0123456789''' >

Re: [Jprogramming] Multiple Takes

2019-10-23 Thread R.E. Boss
The solutions with { are rather inefficient as one can imagine, which can be seen by scaling ts' ~.".~.@>,{10#<''0123456789''' |limit error: ts | ~.".~.@>,{10#<'0123456789' De Forcrand's solution was better (at least it had one) ts'~. ; (#:i.2^10) <@(10 #. i.@!@# A. ])@# i.10 5.1813

Re: [Jprogramming] Creating a distance matrix.

2019-10-23 Thread Raul Miller
Sure, ... The , , ,: approach is cleaner than the > ; ; ; approach (and it's generically useful both for symmetric numeric matrices and for constructing constant matrices). Meanwhile, the -: trick is clever and concise (but not generic). Thanks, -- Raul On Wed, Oct 23, 2019 at 5:23 AM 'Mike D

Re: [Jprogramming] monad chains

2019-10-23 Thread Raul Miller
#'([:w[:v u)' 10 #'v&.:(u :.w)' 11 Clever, but I'm not sure I see the appeal... (But I guess the ranks are different, so a proper comparison would probably be with w@v@u instead of with [:w[:v u). Thanks, -- Raul On Wed, Oct 23, 2019 at 10:06 AM David Lambert wrote: > > Since we don't

Re: [Jprogramming] monad chains

2019-10-23 Thread R.E. Boss
Very neat! R.E. Boss > -Oorspronkelijk bericht- > Van: Programming > Namens David Lambert > Verzonden: woensdag 23 oktober 2019 16:06 > Aan: programming > Onderwerp: [Jprogramming] monad chains > > Since we don't yet have > w`v`u`:666 evaluates equivalently as the train [: w [: v u

[Jprogramming] monad chains

2019-10-23 Thread David Lambert
Since we don't yet have w`v`u`:666 evaluates equivalently as the train [: w [: v u v&.:(u :.w) NB. a single verb -- For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Creating a distance matrix.

2019-10-23 Thread 'Mike Day' via Programming
Or: (+|:)-:0,3 0,4 3,:5 4 3 0 ? This generalises the lean but ad hoc expression: -:@(+|:)@:(|.@(,\.))@:({. 3+i.@-@<: ) 5. NB. eg for 5 x 5 0 1.5 2 2.5 3 1.5 0 1.5 2 2.5 2 1.5 0 1.5 2 2.5 2 1.5 0 1.5 3 2.5 2 1.5 0 ... the 3+ bit could be generalised with a bit more