Created
November 28, 2024 17:10
-
-
Save hadronized/71476241e3ba0bcc74241da6f7bba65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn make_change<const N: usize>(mut value: u32, coins: [u32; N]) -> [u32; N] { | |
let mut counts = [0; N]; | |
for (coin, count) in coins.iter().zip(&mut counts) { | |
*count = value / coin; | |
value %= coin; | |
} | |
counts | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn comptimeMakeChange(value: u32, comptime denoms: []const u32) [denoms.len]u32 { | |
var changes: [denoms.len]u32 = [_]u32{0} ** denoms.len; | |
var v = value; | |
for (denoms, &changes) |denom, *change| { | |
change.* = v / denom; | |
v %= denom; | |
} | |
return changes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment