Problem 15 » 履歴 » バージョン 2
Noppi, 2023/12/30 13:41
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 15]] |
||
3 | |||
4 | ## Lattice Paths |
||
5 | Starting in the top left corner of a $2 \times 2$ grid, and only being able to move to the right and down, there are exactly $6$ routes to the bottom right corner. |
||
6 | |||
7 | ![](0015.png) |
||
8 | |||
9 | How many such routes are there through a $20 \times 20$ grid? |
||
10 | |||
11 | ## 格子経路 |
||
12 | 2×2 のマス目の左上からスタートした場合, 引き返しなしで右下にいくルートは 6 つある. |
||
13 | |||
14 | ![](0015.png) |
||
15 | |||
16 | では, 20×20 のマス目ではいくつのルートがあるか. |
||
17 | |||
18 | ```scheme |
||
19 | 2 | Noppi | #!r6rs |
20 | #!chezscheme |
||
21 | |||
22 | (import (chezscheme)) |
||
23 | |||
24 | (define iota-40-20 |
||
25 | (filter |
||
26 | (lambda (num) |
||
27 | (< 20 num)) |
||
28 | (iota 41))) |
||
29 | |||
30 | (define iota-20-1 |
||
31 | (cdr (iota 21))) |
||
32 | |||
33 | (define answer-15 |
||
34 | (/ (apply * iota-40-20) |
||
35 | (apply * iota-20-1))) |
||
36 | |||
37 | (printf "15: ~D~%" answer-15) |
||
38 | 1 | Noppi | ``` |