Coin Frequencies
2016 November 07

I was counting some coins and was wondering if some coins should be produced more frequently because they would be used more often so I wrote an minimized change count algorithm to decide if certain coins should be produced more often.

Coin Count Chart

The code below should prove my chart to be valid.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from collections import Counter

def count_coins(val):
	dict = Counter()
	oldval = val
	while val > 25:
		dict[25] = dict[25] + 1
		val = val - 25
	while val > 10:
		dict[10] = dict[10] + 1
		val = val - 10
	while val > 5:
		dict[5] = dict[5] + 1
		val = val - 5
	while val != 0:
		dict[1] = dict[1] + 1
		val = val - 1
	return dict

tot_counter = Counter()
for amount in range(1, 99):
	coins = count_coins(amount)
	for key in coins:
		tot_counter[key] += coins[key]

print(tot_counter)

Remember you can also subscribe using RSS at the top of the page!

Share this on → Mastodon Twitter LinkedIn Reddit

A selected list of related posts that you might enjoy:

*****
Written by Henry J Schmale on 2016 November 07
Hit Counter