%% Count Ways to Make Change for Currency
% The file |sf_change.sfx| defines a standalone Stateflow chart that counts
% the number of ways to make change for a given amount of money. The chart
% contains these data objects:
%
% * |x| is the amount of money to change. The default value is 100.
% * |coinValues| is a vector of coin denominations arranged in increasing
% order. |coinNames| is an array of corresponding coin names. The default
% values represent standard American coins (pennies, nickels, dimes, and
% quarters).
% * |tally| is the number of valid change configurations.
% * |tabula| is an array containing the different valid change
% configurations.
% * |chg|, |done|, |i|, and |n| are local data used by the change-counting
% algorithm.
% * |textWidth| and |quietMode| are local data that control how the chart
% displays its results. 

% Copyright 2018-2020 The MathWorks, Inc.

%%

% Set up charts with white background
set_param(0,'ExportBackgroundColorMode','white');

edit sf_change.sfx

%% 
% The chart begins with a potential change configuration consisting
% entirely of the lowest-value coins, specified by an index of 1. At each
% execution step, the state |exchange| modifies this configuration in one
% of two ways:
%
% * The substate |move_up| exchanges some lowest-value coins for a coin
% with a higher value, specified by the index |i|.
%
% * The substate |move_down| exchanges all of the coins with the value
% specified by the index |i| for lowest-value coins. Then |move_up|
% exchanges some lowest-value coins for a coin with a value specified by
% the index |i+1| or higher.
%
% A potential change configuration is valid when the number of cents
% represented by the lowest-value coins is divisible by the value of that
% type of coin. When the chart encounters a new valid configuration, it
% increments |tally| and appends the new configuration to |tabula|.
%
% When no more coin exchanges are possible, the state |stop| becomes
% active. This state prints the results of the computation, transforms the
% contents of |tabula| to a table, and sets the value of |done| to |true|.
