+./ .= is rather like +/ .* For example:
2 +/ .* 3 5 7 30 Here, we multiply 2 by each of 3, 5 and 7, then we add up the results. Similarly, 0 +./ .= 0 1 2 3 1 Here, we check if 0 is equal to each of 0, 1, 2 and 3 and then we or up the results. For more detail on this combining mechanism, read: http://www.jsoftware.com/help/dictionary/d300.htm Unless you weren't familiar with J's OR verb? For that, read http://www.jsoftware.com/help/dictionary/d101.htm Thanks, -- Raul On Thu, May 5, 2016 at 5:54 PM, Geoff Canyon <[email protected]> wrote: > So there are a few learning opportunities here -- euphemism for things I > don't understand ;-) > > I get how adding 0 = transforms the modulo results into a 1 for "divisible" > and 0 for "not divisible": > > 3 5 (0 = (|/ i.)) 20 > > 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 > > 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 > > > But I'm not seeing how this combines those results with an OR: > > > 3 5 (0 +./ .= (|/ i.)) 20 > > 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 1 0 > > > Maybe I'm just not seeing how the forks/hooks resolve themselves? I seem to > recall there was a command to get J to box a command to show how that flow > works, but I don't remember it. Or maybe that's not it at all and I'm just > confused. > > > thx > > > gc > > On Wed, May 4, 2016 at 11:35 PM, Raul Miller <[email protected]> wrote: > >> On Wed, May 4, 2016 at 10:35 PM, Geoff Canyon <[email protected]> wrote: >> > So I tried to write code to solve the general case of Project Euler >> problem >> > 1. The problem given is to find the sum of all the positive integers less >> > than 1000 that are divisible by 3 or 5. Obviously the specific case is >> > highly optimizable. But I wanted to solve the general, with any number of >> > divisors and any upper limit. >> >> ... >> > Here's the code. As always, I suck at J, so improvements/suggestions are >> > welcome. >> > >> > pe1 =: +/@(([:i.]) * 1&-@(0&i.)@*/"1@|:@(|"0 1 i.)) >> >> Maybe: >> pe1=: [:+/@I. 0 +./ .= (|/ i.) >> >> ? >> >> Assuming email anti-spam bots do not eat my line for including an @ >> character. Maybe, instead: >> >> pe1=: [:+/ [:I. 0 +./ .= (|/ i.) >> >> ... >> >> -- >> Raul >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
