Problem 31 » 履歴 » バージョン 1
Noppi, 2024/01/12 15:59
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 31]] |
||
3 | |||
4 | ## Coin Sums |
||
5 | In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation: |
||
6 | |||
7 | > 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p). |
||
8 | |||
9 | It is possible to make £2 in the following way: |
||
10 | |||
11 | > 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p |
||
12 | |||
13 | How many different ways can £2 be made using any number of coins? |
||
14 | |||
15 | ## 硬貨の和 |
||
16 | イギリスでは硬貨はポンド£とペンスpがあり,一般的に流通している硬貨は以下の8種類である. |
||
17 | |||
18 | 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). |
||
19 | |||
20 | 以下の方法で£2を作ることが可能である. |
||
21 | |||
22 | 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p |
||
23 | |||
24 | これらの硬貨を使って£2を作る方法は何通りあるか? |
||
25 | |||
26 | ```scheme |
||
27 | (import (scheme base) |
||
28 | (gauche base)) |
||
29 | |||
30 | (define (coin-pattern n lis) |
||
31 | (cond |
||
32 | [(zero? n) 1] |
||
33 | [(negative? n) 0] |
||
34 | [(null? lis) 0] |
||
35 | [else |
||
36 | (+ (coin-pattern n (cdr lis)) |
||
37 | (coin-pattern (- n (car lis)) |
||
38 | lis))])) |
||
39 | |||
40 | (define answer-31 |
||
41 | (coin-pattern 200 '(200 100 50 20 10 5 2 1))) |
||
42 | |||
43 | (format #t "31: ~d~%" answer-31) |
||
44 | ``` |