Count in factors: Difference between revisions

(Added Kotlin)
Line 22:
*   [[partition an integer X into N primes]]
<br><br>
 
=={{header|360 Assembly}}==
<lang 360asm>* Count in factors 24/03/2017
COUNTFAC CSECT assist plig\COUNTFAC
USING COUNTFAC,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) save previous context
ST R13,4(R15) link backward
ST R15,8(R13) link forward
LR R13,R15 set addressability
L R6,=F'1' i=1
DO WHILE=(C,R6,LE,=F'40') do i=1 to 40
LR R7,R6 n=i
MVI F,X'01' f=true
MVC PG,=CL80' ' clear buffer
LA R10,PG pgi=0
XDECO R6,XDEC edit i
MVC 0(12,R10),XDEC output i
LA R10,12(R10) pgi=pgi+12
MVC 0(1,R10),=C'=' output '='
LA R10,1(R10) pgi=pgi+1
IF C,R7,EQ,=F'1' THEN if n=1 then
MVI 0(R10),C'1' output n
ELSE , else
LA R8,2 p=2
DO WHILE=(CR,R8,LE,R7) do while p<=n
LR R4,R7 n
SRDA R4,32 ~
DR R4,R8 /p
IF LTR,R4,Z,R4 THEN if n//p=0 then
IF CLI,F,EQ,X'00' THEN if not f then
MVC 0(1,R10),=C'*' output '*'
LA R10,1(R10) pgi=pgi+1
ELSE , else
MVI F,X'00' f=false
ENDIF , endif
CVD R8,PP convert bin p to packed pp
MVC WORK12,MASX12 in fact L13
EDMK WORK12,PP+2 edit and mark
LA R9,WORK12+12 end of string(p)
SR R9,R1 li=lengh(p) {r1 from edmk}
MVC EDIT12,WORK12 L12<-L13
LA R4,EDIT12+12 source+12
SR R4,R9 -lengh(p)
LR R5,R9 lengh(p)
LR R2,R10 target ix
LR R3,R9 lengh(p)
MVCL R2,R4 f=f||p
AR R10,R9 ix=ix+lengh(p)
LR R4,R7 n
SRDA R4,32 ~
DR R4,R8 /p
LR R7,R5 n=n/p
ELSE , else
LA R8,1(R8) p=p+1
ENDIF , endif
ENDDO , enddo while
ENDIF , endif
XPRNT PG,L'PG print buffer
LA R6,1(R6) i++
ENDDO , enddo i
L R13,4(0,R13) restore previous savearea pointer
LM R14,R12,12(R13) restore previous context
XR R15,R15 rc=0
BR R14 exit
F DS X flag first factor
DS 0D alignment for cvd
PP DS PL8 packed CL8
EDIT12 DS CL12 target CL12
WORK12 DS CL13 char CL13
MASX12 DC X'40',9X'20',X'212060' CL13
XDEC DS CL12 temp
PG DS CL80 buffer
YREGS
END COUNTFAC</lang>
{{out}}
<pre style="height:20ex">
1=1
2=2
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
23=23
24=2*2*2*3
25=5*5
26=2*13
27=3*3*3
28=2*2*7
29=29
30=2*3*5
31=31
32=2*2*2*2*2
33=3*11
34=2*17
35=5*7
36=2*2*3*3
37=37
38=2*19
39=3*13
40=2*2*2*5
</pre>
 
 
=={{header|Ada}}==
1,392

edits