diff options
author | Guillermo Ramos | 2025-02-27 00:15:01 +0100 |
---|---|---|
committer | Guillermo Ramos | 2025-03-01 00:06:36 +0100 |
commit | 96926a82e592374971f5410bc1051a85f72506f7 (patch) | |
tree | 8810bca9772815491d9dc75608d5807341c7fb7a | |
parent | 808fc499d2919b6d63f2c2917ac58e4200f15544 (diff) | |
download | hiccup-96926a82e592374971f5410bc1051a85f72506f7.tar.gz |
Flatten amortizations
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -109,7 +109,7 @@ impl<'a> Simulation<'a> { println!("Year | Mon | Quota ( Amrtzd + Intrst) | Pending"); for st in self.history.iter() { print!("{st}"); - for update in self.updates.get(st.period) { + for update in flatten_amortizations(self.updates.get(st.period)) { print!(" {update}"); } println!(); @@ -279,3 +279,19 @@ impl SimUpdate { updates } } + +fn flatten_amortizations(updates: Vec<&SimUpdate>) -> Vec<SimUpdate> { + let mut amortized = 0.; + let mut result = vec![]; + for update in updates { + match update { + SimUpdate::Amortize(n) => { + amortized += n; + } + } + } + if amortized > 0. { + result.push(SimUpdate::Amortize(amortized)); + } + result +} |