Count in factors: Difference between revisions

(→‎{{header|Racket}}: stub added (to end of #R))
Line 2,724:
See also [[#Scheme]]. This uses Racket&rsquo;s <code>math/number-theory</code> package
 
<lang racket>#lang typed/racket
 
</lang>
(require math/number-theory)
 
(define (factorise-as-primes [n : Natural])
(if
(= n 1)
'(1)
(let ((F (factorize n)))
(append*
(for/list : (Listof (Listof Natural))
((f (in-list F)))
(make-list (second f) (first f)))))))
 
(define (factor-count [start-inc : Natural] [end-inc : Natural])
(for ((i : Natural (in-range start-inc (add1 end-inc))))
(define f (string-join (map number->string (factorise-as-primes i)) " × "))
(printf "~a:\t~a~%" i f)))
 
(factor-count 1 22)
(factor-count 2140 2150)
; tb</lang>
 
{{out}}
 
<pre>1: 1
2: 2
</pre>
3: 3
4: 2 × 2
5: 5
6: 2 × 3
7: 7
8: 2 × 2 × 2
9: 3 × 3
10: 2 × 5
11: 11
12: 2 × 2 × 3
13: 13
14: 2 × 7
15: 3 × 5
16: 2 × 2 × 2 × 2
17: 17
18: 2 × 3 × 3
19: 19
20: 2 × 2 × 5
21: 3 × 7
22: 2 × 11
2140: 2 × 2 × 5 × 107
2141: 2141
2142: 2 × 3 × 3 × 7 × 17
2143: 2143
2144: 2 × 2 × 2 × 2 × 2 × 67
2145: 3 × 5 × 11 × 13
2146: 2 × 29 × 37
2147: 19 × 113
2148: 2 × 2 × 3 × 179
2149: 7 × 307
2150: 2 × 5 × 5 × 43</pre>
 
=={{header|REXX}}==
569

edits