操作
Problem 4 » 履歴 » リビジョン 3
« 前 |
リビジョン 3/6
(差分)
| 次 »
Noppi, 2023/12/27 04:45
Problem 4¶
#!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
(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)
Noppi が2023/12/27に更新 · 3件の履歴