the only things I'd change:

use ] instead of [ to be able to work in a dyadic verb
then make a verb, and probably assign it so as to be able to do the calc 
another day or with other data.




    13 : '1- %~/ +/ x * _2]\ y'
1 - [: %~/ [: +/ [ * _2 ]\ ]
    100 5 (13 : '1- %~/ +/ x * _2]\ y') 10 3 7.5 2
0.701205






----- Original Message -----
From: Joe Bogner <[email protected]>
To: [email protected]
Cc: 
Sent: Tuesday, March 18, 2014 9:04:59 AM
Subject: [Jprogramming] J as a calculator

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

Reply via email to