Steady squares: Difference between revisions

Added Oberon-07
(Added ABC)
(Added Oberon-07)
 
(2 intermediate revisions by the same user not shown)
Line 7:
=={{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 REPORTMIGHT n show.possible.steady.squareBE A STEADY SQUARE BELOW power.of.ten:
IF n is.steady.square.below power.of.ten:
WRITE ( ( ( n << 1 ) ^ "^2 = " ) >> 10 ) ^ ( ( n * n ) >> 1 ) /
SUCCEED
 
PUT 10 IN power.of.ten
Line 21 ⟶ 20:
IF n = power.of.ten:
PUT power.of.ten * 10 IN power.of.ten
IFMIGHT ( n + 1 ) show.possible.steady.squareBE A STEADY SQUARE BELOW power.of.ten: PASS
IFMIGHT ( n + 5 ) show.possible.steady.squareBE A STEADY SQUARE BELOW power.of.ten: PASS
IFMIGHT ( n + 6 ) show.possible.steady.squareBE A STEADY SQUARE BELOW power.of.ten: PASS
</syntaxhighlight>
{{out}}
Line 1,169 ⟶ 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 1,458 ⟶ 1,499:
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>
 
3,021

edits