> This is closer to what I am trying to do: > > (+1:)`*`%`(+2:)@.(0 , (1 + 2&|) , 3:)"0 [ 5 6 NB. fictional usage > 0.857143 56
This explicit verb seems to produce what you want, u=. 3 : '(+1:)`*`%`(+2:)@.((0,(1+2&|),3:) y) y'"0 u 5 6 0.857142857 56 Writing a tacit counterpart of u is a conundrum... But, breaking rules (at your own risk) helps, an=. <@:((":0) ,&< ]) agenda=. (<'@.')(0:`)(,^:) v=. (((+1:)`*`%`(+2:) agenda (0,(1+2&|),3:)) (0 1 agenda~ ;) an )"0 f. v 5 6 0.857142857 56 (Untested using the latest and greatest interpreters.) On Sat, Dec 7, 2019 at 8:08 PM ethiejiesa via Programming < programm...@jsoftware.com> wrote: > > is the following what you want ? > > > > 1 2 3 (+ ; * ; -) 6 7 8 > > Not quite. The example in my original email was probably overly minimal to > be > completely unhelpful. > > This is closer to what I am trying to do: > > (+1:)`*`%`(+2:)@.(0 , (1 + 2&|) , 3:)"0 [ 5 6 NB. fictional usage > 0.857143 56 > > The salient feature being that the choice of * or % depends on the > argument. I > certainly could just compute both * and %, selecting the desired result > post > facto, but I would like to avoid the unnecessary computation. > > That said, perhaps I am just going about the solution in an entirely non-J > way. > The problem is Advent of Code 2019, day 2, so I essentially have an array > of > integers where each row is an "opcode". I am attempting to decode and > execute > these opcodes. This is why I want to compute the arguments as well as the > operation from the input. > > I certainly want to solve this on my own, but if I would love any pointers > on > how to *think* about the problem in a J-ish way. > > Jimmy Gauvin <jimmy.gau...@gmail.com> wrote: > > > Hi, > > > > is the following what you want ? > > > > 1 2 3 (+ ; * ; -) 6 7 8 > > ┌──────┬───────┬────────┐ > > │7 9 11│6 14 24│_5 _5 _5│ > > └──────┴───────┴────────┘ > > > > > > > > On Fri, Dec 6, 2019 at 9:54 PM ethiejiesa via Programming < > > programm...@jsoftware.com> wrote: > > > > > Am I just doing something silly? Or does @. really not support building > > > trains > > > when the right operand is a verb? Here is an overly minimal example of > > > what I > > > want: > > > > > > (1:)`+`(1:)@.(0 1 2) 0 > > > 2 > > > (1:)`+`(1:)@.(0 1 2"_) 0 > > > |rank error > > > | (1:)`+`(1:)@.(0 1 2"_)0 > > > > > > This is an obvious enough feature, that I feel I must be missing some > > > obvious > > > construction. > > > > > > For context, I was futzing around with this year's Advent of Code[0], > day > > > 2, > > > and found myself wanting a fork-like that behaves as > > > > > > x (u v w) y <-> (x u y) (x v y) (x w y). > > > > > > After sufficient floundering, I decided to just read NuVoc for all > > > modifiers > > > and discovered that I had somehow not noticed the usefulness of @. > > > However, the > > > above restriction really surprised me. > > > > > > Anyway, happy holidays, J birds. > > > > > > [0]:https://adventofcode.com/2019/ > > > ---------------------------------------------------------------------- > > > 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 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm