Problem 4 » 履歴 » リビジョン 3
リビジョン 2 (Noppi, 2023/12/27 01:38) → リビジョン 3/6 (Noppi, 2023/12/27 04:45)
[ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] # [[Problem 4]] ```scheme #!r6rs #!chezscheme (import (chezscheme)) (define (RotationNumber? num) (let* ([num-string ((num-string (number->string num)] num)) [str-length (str-length (string-length num-string)] num-string)) [count (count (div str-length 2)]) 2))) (let loop ([index 0]) ((index 0)) (cond [(<= count index) #t] [(equal? (string-ref num-string index) (string-ref num-string (- str-length 1 index))) (loop (add1 index))] [else #f])))) (define answer-4 (let loop1 ([num1 100] [result 0]) ((num1 100) (result 0)) (if (< 999 num1) result (let loop2 ([num2 100] [result result]) ((num2 100) (result result)) (if (< 999 num2) (loop1 (add1 num1) result) (let ([num ((num (* num1 num2)]) num2))) (if (RotationNumber? num) (loop2 (add1 num2) (max result num)) (loop2 (add1 num2) result)))))))) (printf "4: ~D~%" answer-4) ```