nixpkgs/pkgs/development/tools/minizinc/simple-test/loan.mzn
Alexandru Scvortov 44a331ac33 minizinc: enable gecode and cbc solvers by default
Other changes:
- switch derivation to finalAttrs pattern
2023-06-01 14:07:14 +01:00

25 lines
775 B
MiniZinc

% Taken from https://www.minizinc.org/doc-2.7.3/en/modelling.html
% variables
var float: R; % quarterly repayment
var float: P; % principal initially borrowed
var 0.0 .. 10.0: I; % interest rate (per quarter)
% intermediate variables
var float: B1; % balance after one quarter
var float: B2; % balance after two quarters
var float: B3; % balance after three quarters
var float: B4; % balance owing at end
constraint B1 = P * (1.0 + I) - R;
constraint B2 = B1 * (1.0 + I) - R;
constraint B3 = B2 * (1.0 + I) - R;
constraint B4 = B3 * (1.0 + I) - R;
solve satisfy;
output [
"Borrowing ", show_float(0, 2, P), " at ", show(I*100.0),
"% interest, and repaying ", show_float(0, 2, R),
"\nper quarter for 1 year leaves ", show_float(0, 2, B4), " owing\n"
];