blob: 9c6608f926e7c70d13e4514b2c80474ac9866f12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
''' recursively pushes the prime factors of the int on the top of the stack'''
PROC factors
''' only proceed if the input is valid '''
IF DUP 1 < DO
''' find the smallest number that divides n '''
2 WHILE OVER OVER SWAP % 0 != DO 1 + END
''' print it and find the next factor '''
DUP PUT " " PUT
OVER OVER SWAP / factors
ELSE
"" PUTLN
END
END
PROC MAIN
"Prime factors of 12:" PUTLN 12 factors
"Prime factors of 5:" PUTLN 5 factors
"Prime factors of 60:" PUTLN 60 factors
"Prime factors of 97:" PUTLN 97 factors
END
|