Steady squares: Difference between revisions

Added Oberon-07
(Added Oberon-07)
 
(38 intermediate revisions by 11 users not shown)
Line 4:
<br>
The 3-digit number 376 in the decimal numbering system is an example of numbers with the special property that its square ends with the same digits: '''376*376 = 141376'''. Let's call a number with this property a steady square. Find steady squares under '''10.000'''
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">
HOW TO REPORT n is.steady.square.below power.of.ten:
REPORT ( n * n ) mod power.of.ten = n
 
HOW TO MIGHT n BE A STEADY SQUARE BELOW power.of.ten:
IF n is.steady.square.below power.of.ten:
WRITE ( ( ( n << 1 ) ^ "^2 = " ) >> 10 ) ^ ( ( n * n ) >> 1 ) /
 
PUT 10 IN power.of.ten
PUT -10 IN n
FOR i IN { 0 .. 1000 }:
PUT n + 10 IN n
IF n = power.of.ten:
PUT power.of.ten * 10 IN power.of.ten
MIGHT ( n + 1 ) BE A STEADY SQUARE BELOW power.of.ten
MIGHT ( n + 5 ) BE A STEADY SQUARE BELOW power.of.ten
MIGHT ( n + 6 ) BE A STEADY SQUARE BELOW power.of.ten
</syntaxhighlight>
{{out}}
<pre>
1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376
</pre>
 
=={{header|Action!}}==
Line 51 ⟶ 82:
<pre>
1 5 6 25 76 376 625 9376
</pre>
 
=={{header|ALGOL 60}}==
{{works with|GNU Marst|Any - tested with release 2.7}}
<syntaxhighlight lang="algol60">
begin comment find steady squares - numbers whose square ends in the number
e.g.: 376^2 = 141 376 ;
 
integer powerOfTen, p;
powerOfTen := 10;
 
comment note the final digit must be 1, 5 or 6 ;
for p := 0 step 10 until 10 000 do begin
integer d;
if p = powerOfTen then begin
comment number of digits has increased ;
powerOfTen := powerOfTen * 10
end;
for d := 1, 5, 6 do begin
integer m, n, n2;
n := p + d;
n2 := n * n;
m := n2 - ( ( n2 % powerOfTen ) * powerOfTen ) ;
if m = n then outinteger( 1, n )
end
end
end
</syntaxhighlight>
{{out}}
<pre>
1 5 6 25 76 376 625 9376
</pre>
 
Line 189 ⟶ 251:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">100 HOME
110 FOR n = 1 TO 10000
120 m$ = STR$(n)
130 n2$ = STR$(n*n)
140 IF RIGHT$(n2$,LEN(m$)) = m$ THEN HTAB(5-LEN(m$)): PRINT m$;"^2 = ";N2$
150 NEXT n
160 END</syntaxhighlight>
 
==={{header|ASIC}}===
Compile with the ''Extended math'' option.
Line 308 ⟶ 380:
9376^2 = 87909376
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
For i As Integer = 1 To 10000
If is_steady_square(i) Then Print Format$(i, "####"); "^2 = "; Format$(i ^ 2, "########")
Next
End
 
Function numdig(n As Integer) As Integer
 
Dim d As Integer = 0
While n
d += 1
n \= 10
Wend
Return d
 
End Function
 
Function is_steady_square(n As Integer) As Boolean
 
Dim n2 As Integer = n ^ 2
Return IIf(n2 Mod CInt(10 ^ numdig(n)) = n, True, False)
 
End Function
</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
Line 364 ⟶ 467:
9376 ^ 2 = 87909376
</pre>
 
==={{header|MSX Basic}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 CLS
20 FOR N = 1 TO 10000
30 M$ = STR$(N)
40 M2# = N*N
50 M$ = RIGHT$(M$,LEN(M$)-1)
60 N2$ = STR$(M2#)
70 A = LEN(M$)
80 IF RIGHT$(N2$,A)= M$ THEN LOCATE 5-LEN(M$): PRINT M$;"^2 =";N2$
90 NEXT N
100 END</syntaxhighlight>
 
==={{header|QBasic}}===
Line 599 ⟶ 715:
625^2 = 390625
9376^2 = 87909376</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
{This routine is normally part of a separate library, but it is included here for clarity}
 
procedure GetDigits(N: integer; var IA: TIntegerDynArray);
{Get an array of the integers in a number}
{Numbers returned from least to most significant}
var T,I,DC: integer;
begin
DC:=Trunc(Log10(N))+1;
SetLength(IA,DC);
for I:=0 to DC-1 do
begin
T:=N mod 10;
N:=N div 10;
IA[I]:=T;
end;
end;
 
 
 
function IsSteadySquare(N: integer): boolean;
{compare digits of N and N^2 and see if they matchs}
var Dig1,Dig2: TIntegerDynArray;
var I: integer;
begin
Result:=False;
{Get digits}
GetDigits(N,Dig1);
GetDigits(N*N,Dig2);
{Compare digits}
for I:=0 to High(Dig1) do
if Dig1[I]<>Dig2[I] then exit;
Result:=True
end;
 
 
procedure ShowSteadySquares(Memo: TMemo);
var I: integer;
begin
for I:=1 to 10000-1 do
if IsSteadySquare(I) then
Memo.Lines.Add(Format('%6.0n^2 = %10.0n',[I+0.0,I*I+0.0]));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5,776
376^2 = 141,376
625^2 = 390,625
9,376^2 = 87,909,376
Elapsed Time: 11.168 ms.
 
</pre>
 
 
=={{header|Draco}}==
Line 625 ⟶ 807:
625^2 = 390625
9376^2 = 87909376</pre>
 
=={{header|Euler}}==
The original Euler implementations didn't have loops built-in, however they can be constructed using labels and gotos.
As procedures can take literal procedures as parameters, procedures to provide a loops can be defined. This is used here to define a "while" loop procedure.
<br>
Note that text between ` and ' is a procedure literal. The text "new while; while <- `...'" defines a new variable and assigned the while-loop procedure to it. When called, the text of the condition and loop body must be enclosed in ` and ' to make them procedures - otherwise they would not be evaluated each time as requried.
<br>
All Euler variables are declared using "new var" (only one variable per "new"), labels must be declared with "label" and procedure parametrers are declared with "formal" (again, only one label or parameter per "label" or "formal" declaration).
<br>
Everything is Euler is an expression (apart from new/label/formal) and returns a value (although the value of a "goto" can't be used), so the "else" part of an "if" is not optional, hence the "else 0"s appearing in the code below.
'''begin'''
'''new''' maxNumber; '''new''' powerOfTen; '''new''' lastDigit; '''new''' n;
'''new''' while;
while &lt;- ` '''formal''' condition; '''formal''' loopBody;
'''begin'''
'''label''' again;
again: '''if''' condition '''then''' '''begin''' loopBody; '''goto''' again '''end''' '''else''' 0
'''end'''
&apos;
;
maxNumber &lt;- 10 000;
powerOfTen &lt;- 10;
lastDigit &lt;- ( 1, 5, 6 );
n &lt;- -10;
while( ` [ n &lt;- n + 10 ] &lt;= maxNumber &apos;
, ` '''begin'''
'''new''' d;
'''if''' n = powerOfTen '''then''' powerOfTen &lt;- powerOfTen * 10
'''else''' 0;
d &lt;- 0;
while( ` [ d &lt;- d + 1 ] &lt;= '''length''' lastDigit &apos;
, ` '''begin'''
'''new''' nd; '''new''' n2;
nd &lt;- n + lastDigit[ d ];
n2 &lt;- nd * nd;
'''if''' n2 '''mod''' powerOfTen = nd '''then''' '''out''' nd '''else''' 0
'''end'''
&apos;
)
'''end'''
&apos;
)
'''end'''
$
{{out}}
<pre>
NUMBER 1
NUMBER 5
NUMBER 6
NUMBER 25
NUMBER 76
NUMBER 376
NUMBER 625
NUMBER 9376
</pre>
 
=={{header|F_Sharp|F#}}==
Line 699 ⟶ 938:
625^2 = 390,625
9376^2 = 87,909,376
</pre>
 
=={{header|Fe}}==
<syntaxhighlight lang="clojure">
(= steadySquares
(fn (maxNumber) ; max number to consider
(let powerOfTen 10) ; 10^(the number of digits in n
(let lastDigit (list 1 5 6)); a steady square must end with 1, 5 or 6
(let lastResult (cons 0 nil)); latest steady square start with a dummy 0
(let result lastResult) ; list of steady squares - dummy leading 0
(let n -10) ; multiple of 10 to consider
(while (do (= n (+ n 10)) ; find steady squares up to maxNumber
(<= n maxNumber)
)
(if (is n powerOfTen)
(= powerOfTen (* powerOfTen 10)); number of digits has increased
)
(let d lastDigit)
(while (not (atom d)) ; try n + each possible lastDigit
(let nd (+ n (car d)))
(let n2 (* nd nd))
; Fe doesn't have a mod operator, integer division or a way
; to truncate a float to an integer, so we calculate
; n2 mod powerOfTen using repeated subtraction - but see
; FizzBuzz for an example of doing it with a C function
(let n2%p10 n2)
(let mDivisor (* powerOfTen powerOfTen))
(while (<= powerOfTen mDivisor)
(while (<= mDivisor n2%p10)
(= n2%p10 (- n2%p10 mDivisor))
)
(= mDivisor (/ mDivisor 10))
)
(if (is nd n2%p10)
(do (setcdr lastResult (cons nd nil))
(= lastResult (cdr lastResult))
)
)
(= d (cdr d))
)
)
(cdr result) ; return the list of steady squares without the dummy 0
)
)
(print (steadySquares 10000))
</syntaxhighlight>
{{out}}
<pre>
(1 5 6 25 76 376 625 9376)
</pre>
 
Line 880 ⟶ 1,168:
625 -> 390625
9376 -> 87909376</pre>
 
=={{header|Haxe}}==
<syntaxhighlight lang="haxe">
class Main // steady squares
{
static inline var MAX_NUMBER = 10000;
 
static function main()
{
var powerOfTen = 10;
var pad = ' ';
var lastDigit = [ 1, 5, 6 ]; // possible final digits
var n = -10;
for ( n10 in 0...Math.floor( MAX_NUMBER / 10 ) + 1 ) {
n += 10;
if( n == powerOfTen ) { // the number of digits just increased
powerOfTen *= 10;
pad = pad.substr( 1 );
}
for( d in 0...lastDigit.length ){
var nd = n + lastDigit[ d ];
var n2 = nd * nd;
if( n2 % powerOfTen == nd ){ // have a steady square
Sys.println( '$pad$nd^2 = $n2' );
}
}
}
}
 
}
</syntaxhighlight>
{{out}}
<pre>
1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376
</pre>\
 
=={{header|J}}==
Line 886 ⟶ 1,216:
issteady=: (": -: -@#@": {. ":@*:)"0 NB. tacit alternative</syntaxhighlight>Task example:<syntaxhighlight lang="j"> I.issteady i.1e4
0 1 5 6 25 76 376 625 9376</syntaxhighlight>Note that for larger values we would want to take advantage of the suffix characteristics of these numbers (a multi-digit steady square would have a suffix which is a steady square).
 
For example:
<syntaxhighlight lang=J>bigsteady=: {{
Y=. 1+s=.0x
whilst. Y < y do.
s=. (#~ issteady) ,(Y*i.10)+/s
Y=. Y*10
end.
s #~ y>s
}}</syntaxhighlight>
 
Example use:
 
<pre> $bigsteady 1e20
37
$bigsteady 1e30
54
q:54
2 3 3 3
9 6$bigsteady 1e30
0 1 5 6 25 76
376 625 9376 90625 109376 890625
2890625 7109376 12890625 87109376 212890625 787109376
1787109376 8212890625 18212890625 81787109376 918212890625 9918212890625
40081787109376 59918212890625 259918212890625 740081787109376 3740081787109376 6259918212890625
43740081787109376 56259918212890625 256259918212890625 743740081787109376 2256259918212890625 7743740081787109376
92256259918212890625 392256259918212890625 607743740081787109376 2607743740081787109376 7392256259918212890625 22607743740081787109376
77392256259918212890625 977392256259918212890625 9977392256259918212890625 19977392256259918212890625 80022607743740081787109376 380022607743740081787109376
619977392256259918212890625 3380022607743740081787109376 6619977392256259918212890625 93380022607743740081787109376 106619977392256259918212890625 893380022607743740081787109376
</pre>
 
== {{header|JavaScript}} ==
Line 1,019 ⟶ 1,379:
 
 
 
=={{header|Lua}}==
{{Trans|ALGOL W}}
Uses the fact the final digit can only be 1, 5 or 6 (see the talk page).
<syntaxhighlight lang="lua">
do --[[ find steady squares - numbers whose square ends in the number
e.g.: 376^2 = 141 376
--]]
 
-- checks wheher n^2 mod p10 = n, i.e. n is a steady square and displays
-- a message if it is
local function possibleSteadySuare ( n, p10 )
if ( n * n ) % p10 == n then
io.write( string.format( "%4d", n ), "^2: ", n * n, "\n" )
end
end
 
local powerOfTen = 10
 
-- note the final digit must be 1, 5 or 6
for p = 0,10000,10 do
if p == powerOfTen then
-- number of digits has increased
powerOfTen = powerOfTen * 10
end
possibleSteadySuare( p + 1, powerOfTen )
possibleSteadySuare( p + 5, powerOfTen )
possibleSteadySuare( p + 6, powerOfTen )
end
end</syntaxhighlight>
{{out}}
<pre>
1^2: 1
5^2: 25
6^2: 36
25^2: 625
76^2: 5776
376^2: 141376
625^2: 390625
9376^2: 87909376
</pre>
 
=={{header|MAD}}==
Line 1,041 ⟶ 1,442:
625**2 = 390625
9376**2 = 87909376</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (lay (map showsteady (takewhile (< 10000) steadies)))]
where showsteady n = shownum n ++ "^2 = " ++ shownum (n^2)
 
steadies :: [num]
steadies = filter steady [1..]
 
steady :: num->bool
steady n = n = n^2 mod 10^numdigits n
 
numdigits :: num->num
numdigits n = 1, if n<10
= 1 + numdigits (n div 10), otherwise</syntaxhighlight>
{{out}}
<pre>1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/[algorithm, strutils]
 
var ends = @["1", "5", "6"]
var steady = @[1, 5, 6]
while ends.len != 0:
var newEnds: seq[string]
for e in ends:
for d in '1'..'9':
let s = d & e
let n = parseInt(s)
if n >= 10_000: break
if ($(n * n)).endsWith(s):
steady.add n
newEnds.add s
ends = newEnds
 
echo "Steady squares under 10_000: "
for n in sorted(steady):
echo n, "² = ", n * n
</syntaxhighlight>
 
{{out}}
<pre>Steady squares under 10_000:
1² = 1
5² = 25
6² = 36
25² = 625
76² = 5776
376² = 141376
625² = 390625
9376² = 87909376
</pre>
 
=={{header|Oberon-07}}==
<syntaxhighlight lang="modula2">
(* find some steady squares - numbers whose squares end in the number *)
(* e.g. 376^2 = 141 376 *)
 
MODULE SteadySquares;
IMPORT Out;
 
CONST maxNumber = 10000;
VAR n, powerOfTen :INTEGER;
 
PROCEDURE PossibleSteadySquare( r: INTEGER );
VAR r2: INTEGER;
BEGIN
r2 := r * r;
IF ( r2 MOD powerOfTen ) = r THEN
Out.Int( r, 6 );Out.String( "^2 = " );Out.Int( r2, 1 );Out.Ln
END
END PossibleSteadySquare;
 
BEGIN
powerOfTen := 10;
FOR n := 0 TO maxNumber BY 10 DO
IF n = powerOfTen THEN
(* the number of digits has increased *)
powerOfTen := powerOfTen * 10
END;
PossibleSteadySquare( n + 1 );
PossibleSteadySquare( n + 5 );
PossibleSteadySquare( n + 6 )
END
END SteadySquares.
</syntaxhighlight>
{{out}}
<pre>
1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376
</pre>
 
=={{header|Perl}}==
Line 1,294 ⟶ 1,798:
</pre>
Which is a whopping 35-fold speedup, so obviously ''all'' I need to do is make the compiler emit similarly efficient code...
 
=={{header|PL/0}}==
<syntaxhighlight lang="pascal">
const maxnumber = 10000;
var p10, n, d, nd, n2;
begin
p10 := 10;
n := 0;
while n <= maxnumber do begin
if n = p10 then p10 := p10 * 10;
d := 0;
while d < 6 do begin
if d = 5 then d := 6;
if d = 1 then d := 5;
if d = 0 then d := 1;
nd := n + d;
n2 := nd * nd;
n2 := n2 - ( ( n2 / p10 ) * p10 );
if n2 = nd then ! nd
end;
n := n + 10
end
end.
</syntaxhighlight>
{{out}}
<pre>
1
5
6
25
76
376
625
9376
</pre>
 
=={{header|PL/M}}==
Line 1,488 ⟶ 2,027:
9376**2: 87909376
</pre>
 
=={{header|Prolog}}==
works with swi-prolog
Line 1,737 ⟶ 2,277:
(90625 8212890625)
(109376 11963109376)</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 1 swap
[ 10 / dup while
dip 1+ again ]
drop ] is digitcount ( n --> n )
 
[ dup 2 **
over digitcount
10 swap **
mod = ] is steady ( n --> b )
 
[]
10000 times
[ i^ steady if [ i^ join ] ]
echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 0 1 5 6 25 76 376 625 9376 ]</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <FindSteady 1 9999>;
};
 
FindSteady {
s.N s.Max, <Compare s.N s.Max>: '+' = ;
s.N s.Max, <Steady <Symb s.N>>: F = <FindSteady <+ s.N 1> s.Max>;
s.N s.Max = <ShowSteady s.N> <FindSteady <+ s.N 1> s.Max>;
};
 
ShowSteady {
s.N = <Prout <Symb s.N> '^2 = ' <* s.N s.N>>;
};
 
Steady {
e.N, <Symb <* <Numb e.N> <Numb e.N>>>: e.X e.N = T;
e.N = F;
};</syntaxhighlight>
{{out}}
<pre>1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376</pre>
 
=={{header|REXX}}==
Line 1,806 ⟶ 2,396:
done...
</pre>
 
== {{header|RPL}} ==
===Brute force approach===
Numbers are converted into strings to make comparison easier.
≪ { 1 } 5 ROT '''FOR''' n
n →STR n SQ →STR
DUP SIZE 3 PICK SIZE - 1 + OVER SIZE SUB
'''IF''' == '''THEN''' n + '''END'''
'''NEXT'''
≫ ‘STEDY’ STO
 
10000 STEDY
{{out}}
<pre>
1: { 1 5 6 25 76 376 625 9376 }
</pre>
===Slight optimization===
Steady numbers must end with 5 or 6, but there's no double-digits-or-more ones ending with 1: if ##b1 was the base 10 representation of such a number, the 2nd digit from the right shall be b (because of steadiness) and 2b (because of the elevation to square), which means b=0. By recurrence, all digits shall be zero.
≪ { 1 } 0 ROT '''FOR''' n
5 6 '''FOR''' j
n j + →STR LAST SQ →STR
DUP SIZE 3 PICK SIZE - 1 + OVER SIZE SUB
'''IF''' == '''THEN''' n j + + '''END'''
'''NEXT'''
10 '''STEP'''
≫ ‘STEDY’ STO
 
== {{header|Ruby}} ==
<syntaxhighlight lang="ruby">p (0..10_000).select{|n| (n*n).to_s.end_with? n.to_s }
</syntaxhighlight>
{{out}}
<pre>[0, 1, 5, 6, 25, 76, 376, 625, 9376]
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
fn is_steady_square(n: u32) -> bool {
fn iter(n: u32, m: u32) -> u64 {
if m <= n {iter(n, 10 * m)}
else {m as u64}
}
let nl = n as u64;
nl * nl % iter(n, 1) == nl
}
 
fn main() {
let start = std::time::Instant::now();
let limit = 10_000_000;
let list5 = (5..=limit).step_by(10)
.flat_map(|n|[n, n+1])
.filter(|&n| is_steady_square(n));
let list: Vec<u32> = (0..2).into_iter().chain(list5).collect();
 
let max = *list.iter().last().unwrap();
let maxl = max as u64;
let duration = start.elapsed().as_millis();
let max_len = max.to_string().len();
let sqr_len = (maxl*maxl).to_string().len();
println!("{:>max_len$} {:>sqr_len$}", "num", "square");
for n in list {
let nl = n as u64;
println!("{:max_len$} {:sqr_len$}", n, nl*nl);
}
println!("time(ms): {duration}");
}
</syntaxhighlight>
{{out}}
<pre>
num square
0 0
1 1
5 25
6 36
25 625
76 5776
376 141376
625 390625
9376 87909376
90625 8212890625
109376 11963109376
890625 793212890625
2890625 8355712890625
7109376 50543227109376
time(ms): 50
</pre>
 
=={{header|Scala}}==
ready for Scala3
<syntaxhighlight lang="scala">
def steadySquares(cand: Seq[Int], modulo: Long, acc: Seq[Int]): Seq[Int] = {
if (cand.isEmpty) return acc
val num = cand.head
val numl = num.toLong
val modulo1 = if (modulo > numl) modulo else 10 * modulo
val acc1 = if (numl * numl % modulo1 != numl) acc
else acc :+ num
steadySquares(cand.tail, modulo1, acc1)
}
 
val limit = 1_000_000
val candidates = Seq(0, 1) ++ (5 to limit by 10).flatMap(n => Seq(n, n + 1))
val list = steadySquares(candidates, 1, Seq())
 
@main def main = {
val start = System.currentTimeMillis
val max = list.last.toLong
val Seq(maxLen, sqrLen) = Seq(max, max * max).map(_.toString.length)
for (steadySquare <- list) {
val stSqr = steadySquare.toLong
val sqr = stSqr * stSqr
println("%%%dd %%%dd".format(maxLen, sqrLen).format(stSqr, sqr))
}
val duration = System.currentTimeMillis - start
println(s"time(ms): $duration")
}
</syntaxhighlight>
{{out}}
<pre>
0 0
1 1
5 25
6 36
25 625
76 5776
376 141376
625 390625
9376 87909376
90625 8212890625
109376 11963109376
890625 793212890625
time(ms): 7
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program steady_squares;
loop for n in [1..10000] | steady n do
print(str n + "^2 = " + str (n**2));
end loop;
 
op steady(n);
return n**2 mod 10**#str n = n;
end op;
end program;</syntaxhighlight>
{{out}}
<pre>1^2 = 1
5^2 = 25
6^2 = 36
25^2 = 625
76^2 = 5776
376^2 = 141376
625^2 = 390625
9376^2 = 87909376</pre>
 
== {{header|TypeScript}} ==
Line 1,834 ⟶ 2,576:
625^2 = 390625
9376^2 = 87909376
</pre>
 
=={{header|VTL-2}}==
{{Trans|Tiny BASIC}}
<syntaxhighlight lang="vtl2">
110 P=0
120 D=10
130 X=1
140 D=D=P*9*D+D
150 N=P+X
160 F=N/100
170 B=N-(F*100)
180 S=F*B-(F*B/100*100)*200+(B*B)
190 #=S-(S/D*D)=N=0*220
200 ?=N
210 $=32
220 X=X+4
230 #=X=10=0*260
240 P=P+10
250 X=1
260 #=X=9=0*280
270 X=6
280 #=P<9990*140
</syntaxhighlight>
{{out}}
<pre>
1 5 6 25 76 376 625 9376
</pre>
 
Line 1,839 ⟶ 2,608:
{{libheader|Wren-fmt}}
Although it hardly matters for a small range such as this, one can cut down the numbers to be examined by observing that a steady square must end in 1, 5 or 6.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
System.print("Steady squares under 10,000:")
3,021

edits