Every protection costs money. The ALE method answers the manager's question: does it save more than it costs?
What to build
Work out the yearly loss before and after a control, and decide whether the control pays for itself.
Requirements
- SLE = asset value × exposure factor ÷ 100 (the factor is a percentage). Round SLE to a whole number with
Math.round. - ALE before = SLE × ARO before, and ALE after = SLE × ARO after, each rounded with
Math.round. - saving = ALE before − ALE after.
- Print
SLE x,ALE before x,ALE after xandsaving xon four lines. - Then print
worth it by Xwhen the saving is more than the cost,break evenwhen they are equal, andnot worth it, short by Xotherwise, where X is the difference.
Input
Five lines: asset value (taka), exposure factor (a whole percentage), ARO before, ARO after (these two may have decimals) and the control's yearly cost.
Output
Five lines, as above.
Constraints
Asset value and cost up to 100000000. Exposure factor 1 to 100. ARO 0 to 100, at most 2 decimal places.
Example
Input:
500000
20
3
0.5
120000
Output:
SLE 100000
ALE before 300000
ALE after 50000
saving 250000
worth it by 130000
Why it works
ALE is the loss you expect each year. The control is worth buying exactly when the yearly loss it removes, ALE before minus ALE after, is more than what it costs each year.
Examples
500000 20 3 0.5 120000
SLE 100000 ALE before 300000 ALE after 50000 saving 250000 worth it by 130000
80000 100 0.2 0.1 10000
SLE 80000 ALE before 16000 ALE after 8000 saving 8000 not worth it, short by 2000
Hints
Hint 1
Number("0.5") is 0.5, so decimals need no special care.
Hint 2
Round SLE first, then use the rounded SLE for both ALEs.
Solution
Show one correct solution (try it yourself first)
const asset = Number(prompt());
const factor = Number(prompt());
const aroBefore = Number(prompt());
const aroAfter = Number(prompt());
const cost = Number(prompt());
const sle = Math.round((asset * factor) / 100);
const before = Math.round(sle * aroBefore);
const after = Math.round(sle * aroAfter);
const saving = before - after;
console.log(`SLE ${sle}`);
console.log(`ALE before ${before}`);
console.log(`ALE after ${after}`);
console.log(`saving ${saving}`);
if (saving > cost) console.log(`worth it by ${saving - cost}`);
else if (saving === cost) console.log("break even");
else console.log(`not worth it, short by ${cost - saving}`);
▶ Open this solution in the compiler, then press Visualize to watch it run step by step