Factors of an integer: Difference between revisions

Content added Content deleted
(Added Tiny BASIC example)
(Add min)
Line 3,489: Line 3,489:
factor(999, [1,3,9,27,37,111,333,999])
factor(999, [1,3,9,27,37,111,333,999])
factor(12345678, [1,2,3,6,9,18,47,94,141,282,423,846,14593,29186,43779,87558,131337,262674,685871,1371742,2057613,4115226,6172839,12345678])</nowiki></pre>
factor(12345678, [1,2,3,6,9,18,47,94,141,282,423,846,14593,29186,43779,87558,131337,262674,685871,1371742,2057613,4115226,6172839,12345678])</nowiki></pre>

=={{header|min}}==
{{works with|min|0.19.6}}
<lang min>(mod 0 ==) :divisor?
(() 0 shorten) :new
(new (over swons 'pred dip) pick times nip) :iota

(
:n
n sqrt int iota ; Only consider numbers up to sqrt(n).
(n swap divisor?) filter =f1
f1 (n swap div) map reverse =f2 ; "Mirror" the list of divisors at sqrt(n).
(f1 last f2 first ==) (f2 rest #f2) when ; Handle perfect squares.
f1 f2 concat
) :factors

24 factors puts!
9 factors puts!
11 factors puts!</lang>


=={{header|MiniScript}}==
=={{header|MiniScript}}==