Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -0,0 +1,91 @@
|
|||
org 100h
|
||||
mvi b,30 ; Counter
|
||||
push b
|
||||
loop: lhld curcub ; DE = current cube
|
||||
xchg
|
||||
lhld cursqr ; HL = current square
|
||||
call cdehl
|
||||
jc advcub ; DE < HL, next cube
|
||||
jz advsqr ; DE = HL, both square and cube
|
||||
call prhl ; HL = square but not cube, print it
|
||||
pop b ; Get counter
|
||||
dcr b ; Decrease counter
|
||||
rz ; Stop when zero reached
|
||||
push b ; Push counter back
|
||||
advsqr: call nexsqr ; Next square
|
||||
jmp loop
|
||||
advcub: call nexcub ; Next cube
|
||||
jmp loop
|
||||
|
||||
; compare DE to HL
|
||||
cdehl: mov a,d
|
||||
cmp h
|
||||
rnz
|
||||
mov a,e
|
||||
cmp l
|
||||
ret
|
||||
|
||||
; Get next square (starting with 1)
|
||||
nexsqr: lhld sqdiff ; DE = current difference
|
||||
xchg
|
||||
lhld cursqr ; HL = current square
|
||||
dad d ; Add difference to square
|
||||
inx d ; Increment difference twice
|
||||
inx d
|
||||
shld cursqr ; Update current square
|
||||
xchg
|
||||
shld sqdiff ; Update current difference
|
||||
ret
|
||||
cursqr: dw 0 ; Current square
|
||||
sqdiff: dw 1 ; Difference to next squre
|
||||
|
||||
; Get next cube (starting with 1)
|
||||
nexcub: lhld csumst ; DE = start of current sum
|
||||
xchg
|
||||
lxi h,0 ; HL = current cube
|
||||
lda csumn ; A = amount of numbers to sum
|
||||
csumlp: dad d ; Add to current cube
|
||||
inx d ; Next odd number
|
||||
inx d
|
||||
dcr a ; Until done summing
|
||||
jnz csumlp
|
||||
shld curcub ; Store next sum
|
||||
xchg
|
||||
shld csumst ; Store start of next sum
|
||||
lxi h,csumn ; Increment sum counter
|
||||
inr m
|
||||
ret
|
||||
curcub: dw 0 ; Current cube
|
||||
csumst: dw 1 ; Start of current sum
|
||||
csumn: db 1 ; Amount of numbers to sum
|
||||
|
||||
; Print HL as a decimal value
|
||||
prhl: push h ; Store registers
|
||||
push d
|
||||
push b
|
||||
lxi b,pnum ; Store pointer to buffer on stack
|
||||
push b
|
||||
lxi b,-10 ; Divide by 10 using trial subtraction
|
||||
prdgt: lxi d,-1 ; D =
|
||||
prdgtl: inx d
|
||||
dad b
|
||||
jc prdgtl
|
||||
mvi a,'0'+10 ; ASCII digit + 10
|
||||
add l ; L = remainder - 10
|
||||
pop h ; Get pointer to buffer
|
||||
dcx h ; Go back one digit
|
||||
mov m,a ; Store digit
|
||||
push h ; Store pointer to buffer
|
||||
xchg ; HL = n/10
|
||||
mov a,h ; Zero?
|
||||
ora l
|
||||
jnz prdgt ; If not, get more digits
|
||||
mvi c,9 ; 9 = CP/M print string
|
||||
pop d ; DE = buffer
|
||||
call 5
|
||||
pop b ; Restore registers
|
||||
pop d
|
||||
pop h
|
||||
ret
|
||||
db '*****' ; Number placeholder
|
||||
pnum: db 13,10,'$'
|
||||
11
Task/Square-but-not-cube/ABC/square-but-not-cube.abc
Normal file
11
Task/Square-but-not-cube/ABC/square-but-not-cube.abc
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
PUT 1 IN square.root
|
||||
PUT 1 IN cube.root
|
||||
PUT 30 IN amount
|
||||
|
||||
WHILE amount > 0:
|
||||
WHILE square.root ** 2 > cube.root ** 3:
|
||||
PUT cube.root + 1 IN cube.root
|
||||
IF square.root ** 2 <> cube.root ** 3:
|
||||
WRITE square.root ** 2/
|
||||
PUT amount - 1 IN amount
|
||||
PUT square.root + 1 IN square.root
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
.TITLE SQRCUB
|
||||
.MCALL .TTYOUT,.EXIT
|
||||
|
||||
SQRCUB::MOV #^D30,R5
|
||||
JSR PC,NEXCUB
|
||||
1$: JSR PC,NEXSQR
|
||||
2$: CMP R4,R3
|
||||
BLT 3$
|
||||
BEQ 1$
|
||||
MOV R3,R0
|
||||
JSR PC,PR0
|
||||
SOB R5,1$
|
||||
.EXIT
|
||||
3$: JSR PC,NEXCUB
|
||||
BR 2$
|
||||
|
||||
; PUT SUCCESSIVE SQUARES IN R3
|
||||
NEXSQR: MOV 1$,R3
|
||||
ADD 2$,R3
|
||||
MOV R3,1$
|
||||
ADD #2,2$
|
||||
RTS PC
|
||||
1$: .WORD 0
|
||||
2$: .WORD 1
|
||||
|
||||
; PUT SUCCESSIVE CUBES IN R4
|
||||
NEXCUB: CLR R4
|
||||
MOV 3$,R1
|
||||
1$: ADD 2$,R4
|
||||
ADD #2,2$
|
||||
SOB R1,1$
|
||||
INC 3$
|
||||
RTS PC
|
||||
2$: .WORD 1
|
||||
3$: .WORD 1
|
||||
|
||||
; PRINT R0 AS DECIMAL WITH NEWLINE
|
||||
PR0: MOV #4$,R2
|
||||
1$: MOV #-1,R1
|
||||
2$: INC R1
|
||||
SUB #12,R0
|
||||
BCC 2$
|
||||
ADD #72,R0
|
||||
MOVB R0,-(R2)
|
||||
MOV R1,R0
|
||||
BNE 1$
|
||||
3$: MOVB (R2)+,R0
|
||||
.TTYOUT
|
||||
BNE 3$
|
||||
RTS PC
|
||||
.BLKB 5
|
||||
4$: .BYTE 15,12,0
|
||||
.END SQRCUB
|
||||
21
Task/Square-but-not-cube/Refal/square-but-not-cube.refal
Normal file
21
Task/Square-but-not-cube/Refal/square-but-not-cube.refal
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
$ENTRY Go {
|
||||
= <Prout <SquareCube 30>>;
|
||||
};
|
||||
|
||||
SquareCube {
|
||||
s.Max = <SquareCube s.Max 1 1>;
|
||||
0 s.Sqrt s.Cbrt = ;
|
||||
|
||||
s.Max s.Sqrt s.Cbrt,
|
||||
<Square s.Sqrt>: s.Square,
|
||||
<Cube s.Cbrt>: s.Cube,
|
||||
<Compare s.Square s.Cube>: {
|
||||
'-' = s.Square
|
||||
<SquareCube <- s.Max 1> <+ 1 s.Sqrt> s.Cbrt>;
|
||||
'0' = <SquareCube s.Max <+ 1 s.Sqrt> s.Cbrt>;
|
||||
'+' = <SquareCube s.Max s.Sqrt <+ 1 s.Cbrt>>;
|
||||
};
|
||||
};
|
||||
|
||||
Square { s.N = <* s.N s.N>; };
|
||||
Cube { s.N = <* s.N <* s.N s.N>>; };
|
||||
Loading…
Add table
Add a link
Reference in a new issue