Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,32 +0,0 @@
with Ada.Text_IO;
procedure Count_The_Coins is
type Counter_Type is range 0 .. 2**63-1; -- works with gnat
type Coin_List is array(Positive range <>) of Positive;
function Count(Goal: Natural; Coins: Coin_List) return Counter_Type is
Cnt: array(0 .. Goal) of Counter_Type := (0 => 1, others => 0);
-- 0 => we already know one way to choose (no) coins that sum up to zero
-- 1 .. Goal => we do not (yet) other ways to choose coins
begin
for C in Coins'Range loop
for Amount in 1 .. Cnt'Last loop
if Coins(C) <= Amount then
Cnt(Amount) := Cnt(Amount) + Cnt(Amount-Coins(C));
-- Amount-Coins(C) plus Coins(C) sums up to Amount;
end if;
end loop;
end loop;
return Cnt(Goal);
end Count;
procedure Print(C: Counter_Type) is
begin
Ada.Text_IO.Put_Line(Counter_Type'Image(C));
end Print;
begin
Print(Count( 1_00, (25, 10, 5, 1)));
Print(Count(1000_00, (100, 50, 25, 10, 5, 1)));
end Count_The_Coins;

View file

@ -1,26 +0,0 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
count: Integer;
begin
count := 0;
for penny in 0 .. 100 loop
for nickel in 0 .. 20 loop
for dime in 0 .. 10 loop
for quarter in 0 .. 4 loop
if (penny + 5 * nickel + 10 * dime + 25 * quarter = 100)
then
Put_Line(Integer'Image(count+1) & ": " &
Integer'Image(penny) & " pennies, " &
Integer'Image(nickel) & " nickels, " &
Integer'Image(dime) & " dimes, " &
Integer'Image(quarter) & " quarters");
count := count + 1;
end if;
end loop;
end loop;
end loop;
end loop;
Put_Line("The number of ways to make change for a dollar is: " & Integer'Image(count));
end Main;

View file

@ -4,7 +4,7 @@ changes: function [amount coins][
loop coins 'coin [
loop coin..amount 'j ->
set ways j (get ways j) + get ways j-coin
ways\[j]: ways\[j] + ways\[j-coin]
]
ways\[amount]

View file

@ -1,31 +0,0 @@
identification division.
program-id. CountCoins.
data division.
working-storage section.
77 i pic 9(3).
77 j pic 9(3).
77 m pic 9(3) value 4.
77 n pic 9(3) value 100.
77 edited-value pic z(18).
01 coins-table value "01051025".
05 coin pic 9(2) occurs 4.
01 ways-table.
05 way pic 9(18) occurs 100.
procedure division.
main.
perform calc-count
move way(n) to edited-value
display function trim(edited-value)
stop run
.
calc-count.
initialize ways-table
move 1 to way(1)
perform varying i from 1 by 1 until i > m
perform varying j from coin(i) by 1 until j > n
add way(j - coin(i)) to way(j)
end-perform
end-perform
.

View file

@ -1,21 +1,16 @@
len cache[] 100000 * 7 + 6
val[] = [ 1 5 10 25 50 100 ]
func count sum kind .
if sum = 0
return 1
.
if sum < 0 or kind = 0
return 0
.
if sum = 0 : return 1
if sum < 0 or kind = 0 : return 0
chind = sum * 7 + kind
if cache[chind] > 0
return cache[chind]
if cache[chind] = 0
r2 = count (sum - val[kind]) kind
r1 = count sum (kind - 1)
r = r1 + r2
cache[chind] = r
.
r2 = count (sum - val[kind]) kind
r1 = count sum (kind - 1)
r = r1 + r2
cache[chind] = r
return r
return cache[chind]
.
print count 100 4
print count 10000 6

View file

@ -1,20 +0,0 @@
Function count(coins,m,n)
ReDim table(n+1)
table(0) = 1
i = 0
Do While i < m
j = coins(i)
Do While j <= n
table(j) = table(j) + table(j - coins(i))
j = j + 1
Loop
i = i + 1
Loop
count = table(n)
End Function
'testing
arr = Array(1,5,10,25)
m = UBound(arr) + 1
n = 100
WScript.StdOut.WriteLine count(arr,m,n)