Problem 4 » 履歴 » バージョン 2
Noppi, 2023/12/27 01:38
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 4]] |
||
3 | |||
4 | ```scheme |
||
5 | #!r6rs |
||
6 | #!chezscheme |
||
7 | |||
8 | (import (chezscheme)) |
||
9 | |||
10 | (define (RotationNumber? num) |
||
11 | (let* ((num-string (number->string num)) |
||
12 | (str-length (string-length num-string)) |
||
13 | (count (div str-length 2))) |
||
14 | (let loop ((index 0)) |
||
15 | (cond |
||
16 | [(<= count index) #t] |
||
17 | [(equal? (string-ref num-string index) (string-ref num-string (- str-length 1 index))) |
||
18 | (loop (add1 index))] |
||
19 | [else #f])))) |
||
20 | |||
21 | 2 | Noppi | (define answer-4 |
22 | 1 | Noppi | (let loop1 ((num1 100) |
23 | (result 0)) |
||
24 | (if (< 999 num1) |
||
25 | result |
||
26 | (let loop2 ((num2 100) |
||
27 | (result result)) |
||
28 | (if (< 999 num2) |
||
29 | (loop1 (add1 num1) result) |
||
30 | (let ((num (* num1 num2))) |
||
31 | (if (RotationNumber? num) |
||
32 | (loop2 (add1 num2) (max result num)) |
||
33 | (loop2 (add1 num2) result)))))))) |
||
34 | |||
35 | (printf "4: ~D~%" answer-4) |
||
36 | ``` |