プロジェクト

全般

プロフィール

Problem 4 » 履歴 » リビジョン 2

リビジョン 1 (Noppi, 2023/12/27 01:36) → リビジョン 2/6 (Noppi, 2023/12/27 01:38)

[ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] 
 # [[Problem 4]] 

 ```scheme 
 #!r6rs 
 #!chezscheme 

 (import (chezscheme)) 

 (define (RotationNumber? num) 
   (let* ((num-string (number->string num)) 
          (str-length (string-length num-string)) 
          (count (div str-length 2))) 
     (let loop ((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 (answer-4) 
   (let loop1 ((num1 100) 
               (result 0)) 
     (if (< 999 num1) 
       result 
       (let loop2 ((num2 100) 
                   (result result)) 
         (if (< 999 num2) 
           (loop1 (add1 num1) result) 
           (let ((num (* num1 num2))) 
             (if (RotationNumber? num) 
               (loop2 (add1 num2) (max result num)) 
               (loop2 (add1 num2) result)))))))) 

 (printf "4: ~D~%" answer-4) 
 ```