Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Weird-numbers/Racket/weird-numbers.rkt
Normal file
29
Task/Weird-numbers/Racket/weird-numbers.rkt
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#lang racket
|
||||
|
||||
(require math/number-theory)
|
||||
|
||||
(define (abundant? n proper-divisors)
|
||||
(> (apply + proper-divisors) n))
|
||||
|
||||
(define (semi-perfect? n proper-divisors)
|
||||
(let recur ((ds proper-divisors) (n n))
|
||||
(or (zero? n)
|
||||
(and (positive? n)
|
||||
(pair? ds)
|
||||
(or (recur (cdr ds) n)
|
||||
(recur (cdr ds) (- n (car ds))))))))
|
||||
|
||||
(define (weird? n)
|
||||
(let ((proper-divisors (drop-right (divisors n) 1))) ;; divisors includes n
|
||||
(and (abundant? n proper-divisors) (not (semi-perfect? n proper-divisors)))))
|
||||
|
||||
(module+ main
|
||||
(let recur ((i 0) (n 1) (acc null))
|
||||
(cond [(= i 25) (reverse acc)]
|
||||
[(weird? n) (recur (add1 i) (add1 n) (cons n acc))]
|
||||
[else (recur i (add1 n) acc)])))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-true (weird? 70))
|
||||
(check-false (weird? 12)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue