Square but not cube: Difference between revisions

Add MACRO-11
m (syntax highlighting fixup automation)
(Add MACRO-11)
 
(10 intermediate revisions by 5 users not shown)
Line 23:
n++</syntaxhighlight>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> 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,'$'</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
900
961
1024
1089</pre>
=={{header|8086 Assembly}}==
<syntaxhighlight lang="asm"> cpu 8086
Line 75 ⟶ 198:
 
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089 </pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">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</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
900
961
1024
1089</pre>
 
=={{header|Action!}}==
Line 485 ⟶ 652:
<pre> 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361
400 441 484 529 576 625 676 784 841 900 961 1024 1089</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">cont = 0 : n = 2
do
if is_pow(n, 2) and not is_pow(n, 3) then
print n; " ";
cont += 1
end if
n += 1
until cont = 30
print
 
cont = 0 : n = 2
do
if is_pow(n, 2) and is_pow(n, 3) then
print n; " ";
cont += 1
end if
n += 1
until cont = 3
end
 
function is_pow(n, q)
#tests if the number n is the q'th power of some other integer
r = int(n^(1.0/q))
for i = r-1 to r+1 #there might be a bit of floating point nonsense, so test adjacent numbers also
if i^q = n then return true
next i
return false
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Commodore BASIC}}===
{{trans|BASIC}}
<syntaxhighlight lang="basic">100 DIM SC(2): SC = 0: REM REMEMBER SQUARE CUBES
110 PRINT "SQUARES BUT NOT CUBES:"
120 N = 0: REM NUMBER OF NON-CUBE SQUARES FOUND
130 SR = 1: REM CURRENT SQUARE ROOT
140 CR = 1: CU = 1: REM CURRENT CUBE ROOT AND CUBE
150 REM BEGIN LOOP
160 : IF N >= 30 THEN 230
170 : SQ = SR * SR
180 : IF SQ > CU THEN CR = CR + 1: CU = CR*CR*CR: GOTO 180
190 : IF SQ = CU THEN SC(SC) = SQ: SC = SC + 1
200 : IF SQ < CU THEN N = N + 1:PRINT SQ,
210 : SR = SR + 1
220 GOTO 160: REM END LOOP
230 PRINT: PRINT
240 PRINT "BOTH SQUARES AND CUBES:"
250 FOR I=0 TO SC-1: PRINT SC(I),: NEXT I
260 PRINT</syntaxhighlight>
 
{{works with|Commodore BASIC|3.5,7.0}}
This version uses the later BASIC DO ... LOOP structure:
<pre>100 DIM SC(2): SC = 0: REM REMEMBER SQUARE CUBES
110 PRINT "SQUARES BUT NOT CUBES:"
120 N = 0: REM NUMBER OF NON-CUBE SQUARES FOUND
130 SR = 1: REM CURRENT SQUARE ROOT
140 CR = 1: CU = 1: REM CURRENT CUBE ROOT AND CUBE
150 DO WHILE N < 30
170 : SQ = SR * SR
180 : DO WHILE SQ > CU: CR = CR + 1: CU = CR*CR*CR: LOOP
190 : IF SQ = CU THEN SC(SC) = SQ: SC = SC + 1
200 : IF SQ < CU THEN N = N + 1:PRINT SQ,
210 : SR = SR + 1
220 LOOP
230 PRINT: PRINT
240 PRINT "BOTH SQUARES AND CUBES:"
250 FOR I=0 TO SC-1: PRINT SC(I),: NEXT I
260 PRINT</pre>
 
{{Out}}
<pre>
READY.
RUN
SQUARES BUT NOT CUBES:
4 9 16 25
36 49 81 100
121 144 169 196
225 256 289 324
361 400 441 484
529 576 625 676
784 841 900 961
1024 1089
 
BOTH SQUARES AND CUBES:
1 64 729
 
READY.
</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">function is_pow(n as integer, q as integer) as boolean
'tests if the number n is the q'th power of some other integer
dim as integer r = int( n^(1.0/q) )
for i as integer = r-1 to r+1 'there might be a bit of floating point nonsense, so test adjacent numbers also
if i^q = n then return true
next i
return false
end function
 
dim as integer count = 0, n = 2
do
if is_pow( n, 2 ) and not is_pow( n, 3 ) then
print n;" ";
count += 1
end if
n += 1
loop until count = 30
print
count = 0
n = 2
do
if is_pow( n, 2 ) and is_pow( n, 3 ) then
print n;" ";
count += 1
end if
n += 1
loop until count = 3
print</syntaxhighlight>
{{out}}
<pre> 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089
64 729 4096</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Square.bas"
110 LET SQNOTCB,SQANDCB,SQNUM,CBNUM,CBN,SQN,D1=0:LET SQD,D2=1
120 DO
130 LET SQN=SQN+1:LET SQNUM=SQNUM+SQD:LET SQD=SQD+2
140 IF SQNUM>CBNUM THEN
150 LET CBN=CBN+1:LET CBNUM=CBNUM+D2
160 LET D1=D1+6:LET D2=D2+D1
170 END IF
180 IF SQNUM<>CBNUM THEN
190 PRINT SQNUM:LET SQNOTCB=SQNOTCB+1
200 ELSE
210 PRINT SQNUM,SQN;"*";SQN;"=";CBN;"*";CBN;"*";CBN
220 LET SQANDCB=SQANDCB+1
230 END IF
240 LOOP UNTIL SQNOTCB>=30
250 PRINT SQANDCB;"where numbers are square and cube."</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">OpenConsole()
lv=1
Repeat
s+1 : s2=s*s : Flg=#True
For i=lv To s
If s2=i*i*i
tx3$+Space(Len(tx2$)-Len(tx3$))+Str(s2)
tx2$+Space(Len(Str(s2))+1)
Flg=#False : lv=i : c-1 : Break
EndIf
Next
If Flg : tx2$+Str(s2)+" " : EndIf
c+1
Until c>=30
PrintN("s² : "+tx2$) : PrintN("s²&s³: "+tx3$)
Input()</syntaxhighlight>
{{out}}
<pre>s² : 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089
s²&s³: 1 64 729</pre>
 
==={{header|Visual Basic .NET}}===
Inspired by the '''F#''' version, but no longer resembles it. Removed the recursion, multiplying (like the '''D''' and '''Pascal''' versions, only addition is used to calculate squares and cubes), '''match''' (Select Case) statement, and hard-coded limit.
<syntaxhighlight lang="vbnet">Module Module1
 
' flag / mask explanation:
' bit 0 (1) = increment square
' bit 1 (2) = increment cube
' bit 2 (4) = has output
 
' Checks flag against mask, then advances mask.
Function ChkFlg(flag As Integer, ByRef mask As Integer) As Boolean
ChkFlg = (flag And mask) = mask : mask <<= 1
End Function
 
Sub SwoC(limit As Integer)
Dim count, square, delta, cube, d1, d2, flag, mask As Integer, s as string = ""
count = 1 : square = 1 : delta = 1 : cube = 1 : d1 = 1 : d2 = 0
While count <= limit
flag = {5, 7, 2}(1 + square.CompareTo(cube))
If flag = 7 Then s = String. Format(" {0} (also cube)", square)
If flag = 5 Then s = String.Format("{0,-2} {1}", count, square) : count += 1
mask = 1 : If ChkFlg(flag, mask) Then delta += 2 : square += delta
If ChkFlg(flag, mask) Then d2 += 6 : d1 += d2 : cube += d1
If ChkFlg(flag, mask) Then Console.WriteLine(s)
End While
End Sub
 
Sub Main()
SwoC(30)
End Sub
 
End Module</syntaxhighlight>
{{out}}
<pre> 1 (also cube)
1 4
2 9
3 16
4 25
5 36
6 49
64 (also cube)
7 81
8 100
9 121
10 144
11 169
12 196
13 225
14 256
15 289
16 324
17 361
18 400
19 441
20 484
21 529
22 576
23 625
24 676
729 (also cube)
25 784
26 841
27 900
28 961
29 1024
30 1089</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="freebasic">// Rosetta Code problem: https://rosettacode.org/wiki/Square_but_not_cube
// by Jjuanhdez, 10/2022
 
count = 0 : n = 2
repeat
if isPow(n, 2) and not isPow(n, 3) then
print n, " ";
count = count + 1
fi
n = n + 1
until count = 30
print
 
count = 0 : n = 2
repeat
if isPow(n, 2) and isPow(n, 3) then
print n, " ";
count = count + 1
fi
n = n + 1
until count = 3
print
end
 
sub isPow(n, q)
//tests if the number n is the q'th power of some other integer
r = int(n^(1.0/q))
for i = r-1 to r+1 //there might be a bit of floating point nonsense, so test adjacent numbers also
if i^q = n return true
next i
return false
end sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|BCPL}}==
Line 818 ⟶ 1,252:
529 576 625 676 784
841 900 961 1024 1089</pre>
 
=={{header|Commodore BASIC}}==
{{trans|BASIC}}
<syntaxhighlight lang="basic">100 DIM SC(2): SC = 0: REM REMEMBER SQUARE CUBES
110 PRINT "SQUARES BUT NOT CUBES:"
120 N = 0: REM NUMBER OF NON-CUBE SQUARES FOUND
130 SR = 1: REM CURRENT SQUARE ROOT
140 CR = 1: CU = 1: REM CURRENT CUBE ROOT AND CUBE
150 REM BEGIN LOOP
160 : IF N >= 30 THEN 230
170 : SQ = SR * SR
180 : IF SQ > CU THEN CR = CR + 1: CU = CR*CR*CR: GOTO 180
190 : IF SQ = CU THEN SC(SC) = SQ: SC = SC + 1
200 : IF SQ < CU THEN N = N + 1:PRINT SQ,
210 : SR = SR + 1
220 GOTO 160: REM END LOOP
230 PRINT: PRINT
240 PRINT "BOTH SQUARES AND CUBES:"
250 FOR I=0 TO SC-1: PRINT SC(I),: NEXT I
260 PRINT</syntaxhighlight>
 
{{works with|Commodore BASIC|3.5,7.0}}
This version uses the later BASIC DO ... LOOP structure:
<pre>100 DIM SC(2): SC = 0: REM REMEMBER SQUARE CUBES
110 PRINT "SQUARES BUT NOT CUBES:"
120 N = 0: REM NUMBER OF NON-CUBE SQUARES FOUND
130 SR = 1: REM CURRENT SQUARE ROOT
140 CR = 1: CU = 1: REM CURRENT CUBE ROOT AND CUBE
150 DO WHILE N < 30
170 : SQ = SR * SR
180 : DO WHILE SQ > CU: CR = CR + 1: CU = CR*CR*CR: LOOP
190 : IF SQ = CU THEN SC(SC) = SQ: SC = SC + 1
200 : IF SQ < CU THEN N = N + 1:PRINT SQ,
210 : SR = SR + 1
220 LOOP
230 PRINT: PRINT
240 PRINT "BOTH SQUARES AND CUBES:"
250 FOR I=0 TO SC-1: PRINT SC(I),: NEXT I
260 PRINT</pre>
 
{{Out}}
<pre>
READY.
RUN
SQUARES BUT NOT CUBES:
4 9 16 25
36 49 81 100
121 144 169 196
225 256 289 324
361 400 441 484
529 576 625 676
784 841 900 961
1024 1089
 
BOTH SQUARES AND CUBES:
1 64 729
 
READY.
</pre>
 
=={{header|Common Lisp}}==
Line 1,174 ⟶ 1,549:
{$IFNDEF UNIX} readln; {$ENDIF}
end.</syntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc main() void:
word sqrt, cbrt, sq, cb, seen;
sqrt := 1;
cbrt := 1;
seen := 0;
while seen < 30 do
sq := sqrt * sqrt;
while
cb := cbrt * cbrt * cbrt;
sq > cb
do
cbrt := cbrt + 1
od;
if sq /= cb then
seen := seen + 1;
write(sq:5);
if seen % 10 = 0 then writeln() fi
fi;
sqrt := sqrt + 1
od
corp</syntaxhighlight>
{{out}}
<pre> 4 9 16 25 36 49 81 100 121 144
169 196 225 256 289 324 361 400 441 484
529 576 625 676 784 841 900 961 1024 1089</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func iscube x .
for i = 1 to x
h = i * i * i
if h = x
return 1
elif h > x
return 0
.
.
.
while cnt < 30
sq += 1
sq2 = sq * sq
if iscube sq2 = 0
write sq2 & " "
cnt += 1
.
.
</syntaxhighlight>
 
{{out}}
<pre>
4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089
</pre>
 
=={{header|F_Sharp|F#}}==
Line 1,351 ⟶ 1,780:
 
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function is_pow(n as integer, q as integer) as boolean
'tests if the number n is the q'th power of some other integer
dim as integer r = int( n^(1.0/q) )
for i as integer = r-1 to r+1 'there might be a bit of floating point nonsense, so test adjacent numbers also
if i^q = n then return true
next i
return false
end function
 
dim as integer count = 0, n = 2
do
if is_pow( n, 2 ) and not is_pow( n, 3 ) then
print n;" ";
count += 1
end if
n += 1
loop until count = 30
print
count = 0
n = 2
do
if is_pow( n, 2 ) and is_pow( n, 3 ) then
print n;" ";
count += 1
end if
n += 1
loop until count = 3
print</syntaxhighlight>
{{out}}
<pre> 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089
64 729 4096</pre>
 
=={{header|Go}}==
Line 1,550 ⟶ 1,945:
1024
1089</pre>
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">100 PROGRAM "Square.bas"
110 LET SQNOTCB,SQANDCB,SQNUM,CBNUM,CBN,SQN,D1=0:LET SQD,D2=1
120 DO
130 LET SQN=SQN+1:LET SQNUM=SQNUM+SQD:LET SQD=SQD+2
140 IF SQNUM>CBNUM THEN
150 LET CBN=CBN+1:LET CBNUM=CBNUM+D2
160 LET D1=D1+6:LET D2=D2+D1
170 END IF
180 IF SQNUM<>CBNUM THEN
190 PRINT SQNUM:LET SQNOTCB=SQNOTCB+1
200 ELSE
210 PRINT SQNUM,SQN;"*";SQN;"=";CBN;"*";CBN;"*";CBN
220 LET SQANDCB=SQANDCB+1
230 END IF
240 LOOP UNTIL SQNOTCB>=30
250 PRINT SQANDCB;"where numbers are square and cube."</syntaxhighlight>
 
=={{header|J}}==
Line 1,977 ⟶ 2,354:
676
729 is square and cube
784
841
900
961
1024
1089</pre>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="asm"> .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</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
Line 2,050 ⟶ 2,513:
<pre>{4, 9, 16, 25, 36, 49, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 784, 841, 900, 961, 1024, 1089}
{1, 64, 729}</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (lay (map show squarenotcube))]
where squarenotcube = take 30 (squares $notin cubes)
 
squares :: [num]
squares = map (^ 2) [1..]
 
cubes :: [num]
cubes = map (^ 3) [1..]
 
|| Values in as not in bs, assuming as and bs are sorted
notin :: [num] -> [num] -> [num]
notin as [] = as
notin (a:as) (b:bs) = a:notin as (b:bs), if a < b
= notin as bs, if a = b
= notin (a:as) bs, if a > b</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
900
961
1024
1089</pre>
 
=={{header|MiniScript}}==
Line 2,544 ⟶ 3,056:
{{out}}
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089</pre>
 
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">OpenConsole()
lv=1
Repeat
s+1 : s2=s*s : Flg=#True
For i=lv To s
If s2=i*i*i
tx3$+Space(Len(tx2$)-Len(tx3$))+Str(s2)
tx2$+Space(Len(Str(s2))+1)
Flg=#False : lv=i : c-1 : Break
EndIf
Next
If Flg : tx2$+Str(s2)+" " : EndIf
c+1
Until c>=30
PrintN("s² : "+tx2$) : PrintN("s²&s³: "+tx3$)
Input()</syntaxhighlight>
{{out}}
<pre>s² : 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089
s²&s³: 1 64 729</pre>
 
=={{header|Python}}==
Line 2,733 ⟶ 3,224:
1 64 729 4096 15625 46656 117649 262144 531441 1000000 1771561 2985984 4826809 7529536 11390625</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$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>>; };</syntaxhighlight>
{{out}}
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089</pre>
=={{header|REXX}}==
Programming note: &nbsp; extra code was added to support an additional output format &nbsp; (see the 2<sup>nd</sup> '''output''' section).
Line 2,926 ⟶ 3,441:
</pre>
 
=={{header|RPL}}==
{{trans|11l}}
≪ → eq n
≪ { } 1
'''WHILE''' OVER SIZE n < '''REPEAT'''
DUP SQ DUP 3 INV ^ 1E-6 + FLOOR 3 ^
'''IF''' eq EVAL '''THEN''' SWAP OVER SQ + SWAP '''END'''
1 + '''END'''
DROP
≫ ≫ ''''TASK'''' STO
{{in}}
<pre>
≪ ≠ ≫ 30 TASK
≪ == ≫ 3 TASK
</pre>
{{out}}
<pre>
2: { 4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089 }
1: { 1 64 729 }
</pre>
=={{header|Ruby}}==
==== Class based ====
Line 3,312 ⟶ 3,847:
Both squares and cubes:
1, 64, 729</pre>
 
=={{header|Visual Basic .NET}}==
Inspired by the '''F#''' version, but no longer resembles it. Removed the recursion, multiplying (like the '''D''' and '''Pascal''' versions, only addition is used to calculate squares and cubes), '''match''' (Select Case) statement, and hard-coded limit.
<syntaxhighlight lang="vbnet">Module Module1
 
' flag / mask explanation:
' bit 0 (1) = increment square
' bit 1 (2) = increment cube
' bit 2 (4) = has output
 
' Checks flag against mask, then advances mask.
Function ChkFlg(flag As Integer, ByRef mask As Integer) As Boolean
ChkFlg = (flag And mask) = mask : mask <<= 1
End Function
 
Sub SwoC(limit As Integer)
Dim count, square, delta, cube, d1, d2, flag, mask As Integer, s as string = ""
count = 1 : square = 1 : delta = 1 : cube = 1 : d1 = 1 : d2 = 0
While count <= limit
flag = {5, 7, 2}(1 + square.CompareTo(cube))
If flag = 7 Then s = String. Format(" {0} (also cube)", square)
If flag = 5 Then s = String.Format("{0,-2} {1}", count, square) : count += 1
mask = 1 : If ChkFlg(flag, mask) Then delta += 2 : square += delta
If ChkFlg(flag, mask) Then d2 += 6 : d1 += d2 : cube += d1
If ChkFlg(flag, mask) Then Console.WriteLine(s)
End While
End Sub
 
Sub Main()
SwoC(30)
End Sub
 
End Module</syntaxhighlight>
{{out}}
<pre> 1 (also cube)
1 4
2 9
3 16
4 25
5 36
6 49
64 (also cube)
7 81
8 100
9 121
10 144
11 169
12 196
13 225
14 256
15 289
16 324
17 361
18 400
19 441
20 484
21 529
22 576
23 625
24 676
729 (also cube)
25 784
26 841
27 900
28 961
29 1024
30 1089</pre>
 
=={{header|VTL-2}}==
Line 3,397 ⟶ 3,865:
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "/math" for Math
<syntaxhighlight lang="wren">import "./fmt" for Fmt
 
var i = 1
Line 3,405 ⟶ 3,873:
while (sqnc.count < 30 || sqcb.count < 3) {
var sq = i * i
var cb = Mathsq.cbrt(sq).round
if (cb*cb*cb != sq) {
sqnc.add(sq)
2,096

edits