Merge: doc: fixed some typos and other misc. corrections
[nit.git] / examples / rosettacode / count_the_coins.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Count_the_coins
7 # SEE: <http://rosettacode.org/wiki/Count_the_coins>
8 module count_the_coins
9
10 fun changes(amount: Int, coins: Array[Int]): Int
11 do
12 var cache = new Array[Int].filled_with(0, amount+1)
13 cache[0] = 1
14 for coin in coins do
15 for j in [coin..amount] do
16 cache[j] += cache[j - coin]
17 end
18 end
19 return cache[amount]
20 end
21
22 print changes(100, [1, 5, 10, 25])
23 print changes(100000, [1, 5, 10, 25, 50, 100])