I might be tempted to rephrase the price and cost part of this. One variant pulls the _2[\ into the parenthesis, because it's a part of the structure of your numbers:
(_2[\ 10 3 7.5 2) Of course, technically the parenthesis are unnecessary, and are just there for emphasis. But another way of emphasizing would emphasize that you are working with pairs: 10 3,:7.5 2 Note that if you had more than two pairs (probably a good thing when working with this kind of example, to avoid blurring "pair" and "two of them" in people's minds) you would use , instead of ,: for all pairs except the last. 9 4,10 3,:7.5 2 And, as a bit of obligatory wackiness, here's another approach: Table=:i.0 0 Table`9 4`10 3`7.5 2 9 4 10 3 7.5 2 Thanks, -- Raul On Tue, Mar 18, 2014 at 9:04 AM, Joe Bogner <[email protected]> wrote: > I'm trying to use J more in my daily calculations in addition to > programming. > > I was working with some simple margin % calculations in a one liner > > 1- %~/ +/ (100 5) * _2[\ (10 3 7.5 2) > > I'd like any ideas on how others would do this type of 'spreadsheet' > calculation. I'm pretty happy with it, but wondering if there's a more > clear way of expressing it in a one liner. > > Margin % is calculated as 1 - Extended Cost / Extended Price > > Or more traditionally as Price - Cost / Price > > In the example above, I have units as 100 and 5 and prices of 10,7.5 > and costs of 3 and 2 > > Price & Cost > > _2[\ (10 3 7.5 2) > 10 3 > 7.5 2 > > Extended Price & Cost: > > (100 5) * _2[\ (10 3 7.5 2) > 1000 300 > 37.5 10 > > Total Cost & Price > > +/ (100 5) * _2[\ (10 3 7.5 2) > 1037.5 310 > > Margin % > 1- %~/ +/ (100 5) * _2[\ (10 3 7.5 2) > 0.701205 > > Any ideas on making it more clear are welcome > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
