Count the coins: Difference between revisions

Updated second D entry
(Updated third D entry)
(Updated second D entry)
Line 366:
<lang d>import std.stdio, std.bigint;
 
BigInt countChanges(in int amount, in int[] coins)/* pure /*nothrow*/ {
immutable size_t n = coins.length;
int cycle;
foreach (constimmutable c; coins)
if (c <= amount && c >= cycle)
cycle = c + 1;
cycle *= n;
auto table = new BigInt[cycle];
table[0 .. n] = BigInt(1).BigInt;
 
int pos = n;
foreach (immutable s; 1 .. amount + 1) {
foreach (immutable i; 0 .. n) {
if (i == 0 && pos >= cycle)
pos = 0;
Line 398:
immutable euCoins = [200, 100, 50, 20, 10, 5, 2, 1];
 
foreach (immutable coins; [usCoins, euCoins]) {
writeln(countChanges( 1_00, coins[2 .. $])).writeln;
writeln(countChanges( 1000_00, coins)).writeln;
writeln(countChanges( 10000_00, coins)).writeln;
writeln(countChanges(100000_00, coins), "\n").writeln;
writeln;
}
}</lang>