Odd and square numbers: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(add BQN)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(47 intermediate revisions by 21 users not shown)
Line 4:
<br>
Find odd and square numbers (>99) under '''1.000'''
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V limit = 1000
 
L(i) (1 .< Int(ceil(sqrt(limit)))).step(2)
V num = i * i
I num < limit & num > 99
print(num, end' ‘ ’)</syntaxhighlight>
 
{{out}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> org 100h
lxi h,81 ; Holds current square
lxi d,19 ; Holds distance to next square
mvi b,12 ; Loop counter
jmp next
loop: call prhl
next: dad d ; Generate next square (will be even)
inx d ; Increase distance by 2
inx d
dad d ; Generate next square (will be odd)
inx d ; Increase distance by 2
inx d
dcr b
jnz loop
ret
; Print HL as decimal
prhl: push h ; Save all registers
push d
push b
lxi b,pnum ; Store pointer to num string on stack
push b
lxi b,-10 ; Divisor
prdgt: lxi d,-1
prdgtl: inx d ; Divide by 10 through trial subtraction
dad b
jc prdgtl
mvi a,'0'+10
add l ; L = remainder - 10
pop h ; Get pointer from stack
dcx h ; Store digit
mov m,a
push h ; Put pointer back on stack
xchg ; Put quotient in HL
mov a,h ; Check if zero
ora l
jnz prdgt ; If not, next digit
pop d ; Get pointer and put in DE
mvi c,9 ; CP/M print string
call 5
pop b ; Restore registers
pop d
pop h
ret
db '*****' ; Placeholder for number
pnum: db 13,10,'$'</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # print odd suares between 100 and 1000 #
# if 2m + 1 and 2m - 1 are consecutive odd numbers, the difference between their squares is 8m #
INT to next := 8;
Line 17 ⟶ 92:
to next +:= 8
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 25 ⟶ 100:
=={{header|ALGOL W}}==
{{Trans|PL/M}} which is based on the Algol 68 sample.
<langsyntaxhighlight lang="algolw">begin % print odd squares between 100 and 1000 %
integer oddSquare, nextGap;
oddSquare := 1;
Line 38 ⟶ 113:
nextGap := nextGap + 8
end while_oddSquare_lt_1000
end.</langsyntaxhighlight>
{{out}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">100..1000 | select => odd?
| select 'x -> zero? (sqrt x) % 1
| print</syntaxhighlight>
 
{{out}}
 
<pre>121 169 225 289 361 441 529 625 729 841 961</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f ODD_AND_SQUARE_NUMBERS.AWK
BEGIN {
Line 59 ⟶ 144:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 66 ⟶ 151:
Odd and square numbers 100-999: 11
</pre>
 
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 N=10
30 S=N*N
40 IF S>=1000 THEN END
50 IF S AND 1 THEN PRINT S
60 N=N+1
70 GOTO 30</syntaxhighlight>
{{out}}
<pre> 121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let start() be
$( let n = 10
$( let sq = n * n
if sq >= 1000 then finish
if sq rem 2 = 1 then writef("%N*N", sq)
n := n + 1
$) repeat
$)</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|BQN}}==
 
<syntaxhighlight lang ="bqn">2⊸|⊸/ט11+↕222×↕11</langsyntaxhighlight>
 
Generate rangeodd numbers from 11..32, squareto them,31 and filtersquare the odd ones outthem.
 
An alternate version uses more code, but doesn't require any arithmetic to derive:
 
<syntaxhighlight lang="bqn">100 ↓⟜↕○⌈⌾((ט1+2×⊢)⁼) 1000</syntaxhighlight>
 
Here it's known that the final output should have the transformation <code>ט1+2×⊢</code> applied to it to produce odd squares. The reverse of this transformation is applied to the two bounds 100 and 1000, then <code>↓⟜↕</code> produces a numeric range which is transformed back.
 
=={{header|C}}==
{{trans|Wren}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <math.h>
 
int main() {
int i, p, low, high, pow = 1, osc;
int oddSq[120];
for (p = 0; p < 5; ++p) {
low = (int)ceil(sqrt((double)pow));
if (!(low%2)) ++low;
pow *= 10;
high = (int)sqrt((double)pow);
for (i = low, osc = 0; i <= high; i += 2) {
oddSq[osc++] = i * i;
}
printf("%d odd square from %d to %d:\n", osc, pow/10, pow);
for (i = 0; i < osc; ++i) {
printf("%d ", oddSq[i]);
if (!((i+1)%10)) printf("\n");
}
printf("\n\n");
}
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Same as Wren example.
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">start_up = proc ()
po: stream := stream$primary_output()
n: int := 10
while true do
sq: int := n**2
if sq>=1000 then break end
if sq//2 = 1 then stream$putl(po, int$unparse(sq)) end
n := n+1
end
end start_up</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. ODD-AND-SQUARE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 N PIC 999.
03 SQR PIC 9999 VALUE 0.
03 FILLER REDEFINES SQR.
05 FILLER PIC 999.
05 FILLER PIC 9.
88 ODD VALUE 1, 3, 5, 7, 9.
03 FMT PIC ZZ9.
PROCEDURE DIVISION.
BEGIN.
PERFORM CHECK VARYING N FROM 10 BY 1
UNTIL SQR IS NOT LESS THAN 1000.
STOP RUN.
CHECK.
MULTIPLY N BY N GIVING SQR.
IF ODD, MOVE SQR TO FMT, DISPLAY FMT.</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
var n: uint16 := 10;
loop
var sq := n * n;
if sq >= 1000 then break; end if;
if sq % 2 == 1 then
print_i16(sq);
print_nl();
end if;
n := n+1;
end loop;</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
procedure ShowOddSquareNumbers(Memo: TMemo);
var I,N: integer;
var Cnt: integer;
var S: string;
begin
Cnt:=0;
for I:=10 to trunc(sqrt(1000)) do
begin
N:=I * I;
if ((N and 1)=1) then
begin
Inc(Cnt);
S:=S+Format('%8D',[N]);
If (Cnt mod 5)=0 then S:=S+CRLF;
end;
end;
Memo.Lines.Add(S);
Memo.Lines.Add('Count='+IntToStr(Cnt));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
121 169 225 289 361
441 529 625 729 841
961
Count=11
Elapsed Time: 1.975 ms.
</pre>
 
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec main() void:
word i, sq;
i := 11;
while sq := i * i; sq < 1000 do
writeln(sq);
i := i + 2
od
corp</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|Euler}}==
Same algorithm as the Algol and other samples.
<br>Note formatted output is not Euler's strong point...
'''begin'''
'''new''' toNext; '''new''' oddSquare; '''label''' again;
toNext &lt;- 0;
oddSquare &lt;- 1;
again:
'''if''' oddSquare &lt; 1000 '''then''' '''begin'''
'''if''' oddSquare &gt; 99 '''then''' '''out''' oddSquare '''else''' 0;
oddSquare &lt;- oddSquare + toNext;
toNext &lt;- toNext + 8;
'''goto''' again
'''end''' '''else''' 0
'''end''' $
{{out}}
<pre>
NUMBER 121
NUMBER 169
NUMBER 225
NUMBER 289
NUMBER 361
NUMBER 441
NUMBER 529
NUMBER 625
NUMBER 729
NUMBER 841
NUMBER 961
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Odd and square numbers. Nigel Galloway: November 23rd., 2021
Seq.initInfinite((*)2>>(+)11)|>Seq.map(fun n->n*n)|>Seq.takeWhile((>)1000)|>Seq.iter(printfn "%d")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 95 ⟶ 443:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: io math math.functions math.ranges prettyprint sequences ;
 
11 1000 sqrt 2 <range> [ bl ] [ sq pprint ] interleave nl</langsyntaxhighlight>
{{out}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
 
=={{header|Fe}}==
<syntaxhighlight lang="clojure">
(= oddAndSquareNumbers
(fn (minNumber maxNumber)
(let toNext 8)
(let oddSquare 1)
(let lastResult (cons 0 nil)) ; result list with a dummy leading 0
(let result lastResult)
(while (< oddSquare maxNumber)
(if (< minNumber oddSquare)
(do (setcdr lastResult (cons oddSquare nil))
(= lastResult (cdr lastResult))
)
)
(= oddSquare (+ oddSquare toNext))
(= toNext (+ toNext 8))
)
(cdr result) ; return result without the dummy leading 0
)
)
(print (oddAndSquareNumbers 100 1000))
</syntaxhighlight>
{{out}}
<pre>
(121 169 225 289 361 441 529 625 729 841 961)
</pre>
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">Func Oddsq(j)=(2*j-1)^2.;
i:=1;
n:=1;
Line 111 ⟶ 486:
i:+;
n:=Oddsq(i);
od;</langsyntaxhighlight>
 
=={{header|FOCAL}}==
<syntaxhighlight lang="focal">01.10 S N=10
01.20 S S=N*N
01.30 I (1000-S)1.8
01.40 I (FITR(S/2)*2-S)1.5,1.6
01.50 T %3,S,!
01.60 S N=N+1
01.70 G 1.2
01.80 Q</syntaxhighlight>
{{out}}
<pre>= 121
= 169
= 225
= 289
= 361
= 441
= 529
= 625
= 729
= 841
= 961</pre>
 
=={{header|FreeBASIC}}==
Squares without squaring.
<langsyntaxhighlight lang="freebasic">dim as integer i=1, n=1
while n<1000
if n>100 then print n
n+=8*i
i+=1
wend</langsyntaxhighlight>
 
=={{header|Go}}==
{{trans|Wren}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"math"
)
 
func main() {
pow := 1
for p := 0; p < 5; p++ {
low := int(math.Ceil(math.Sqrt(float64(pow))))
if low%2 == 0 {
low++
}
pow *= 10
high := int(math.Sqrt(float64(pow)))
var oddSq []int
for i := low; i <= high; i += 2 {
oddSq = append(oddSq, i*i)
}
fmt.Println(len(oddSq), "odd squares from", pow/10, "to", pow, "\b:")
for i := 0; i < len(oddSq); i++ {
fmt.Printf("%d ", oddSq[i])
if (i+1)%10 == 0 {
fmt.Println()
}
}
fmt.Println("\n")
}
}</syntaxhighlight>
 
{{out}}
<pre>
Same as Wren example
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">main :: IO ()
main = print $ takeWhile (<1000) $ filter odd $ map (^2) $ [10..]</syntaxhighlight>
{{out}}
<pre>[121,169,225,289,361,441,529,625,729,841,961]</pre>
 
=={{header|J}}==
 
Example implementation:
 
<syntaxhighlight lang="j"> (#~ (1=2|])*(=<.)@%:*>&99) i.1000
121 169 225 289 361 441 529 625 729 841 961</syntaxhighlight>
 
Note that we could have instead used cascading filters (which would be roughly analogous to short circuit operators) for example:
 
<syntaxhighlight lang="j"> (#~ 1=2|]) (#~ (=<.)@%:) 99}. i.1000
121 169 225 289 361 441 529 625 729 841 961</syntaxhighlight>
 
Or, we could instead have opted to not use filters at all, because the values are their own indices in the initial selection we were working with:
 
<syntaxhighlight lang="j"> I.((1=2|])*(=<.)@%:*>&99) i.1000
121 169 225 289 361 441 529 625 729 841 961</syntaxhighlight>
 
=={{header|jq}}==
Line 126 ⟶ 584:
'''Works with gojq, the Go implementation of jq'''
====Basic Task====
<langsyntaxhighlight lang="jq"># Output: a stream up to but less than $upper
def oddSquares($upper):
label $out
Line 134 ⟶ 592:
 
oddSquares(1000) | select(. > 100)
</syntaxhighlight>
</lang>
{{out}}
As for [[#Julia]].
Line 140 ⟶ 598:
====Extended Example====
{{trans|Wren}}
<langsyntaxhighlight lang="jq"># input: an array
# output: a stream of arrays of size size except possibly for the last array
def group(size):
Line 152 ⟶ 610:
[range(.low; 1 + (.pow|sqrt|floor); 2) | . * . ] as $oddSq
| "\($oddSq|length) odd squares from \(.pow/10) to \(.pow):",
( $oddSq | group(10) | join(" ")), "" )</langsyntaxhighlight>
{{out}}
As for [[#Wren]].
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">oddsquares(lim) = [i^2 for i ∈ Int.(range((√).(lim)...)) if isodd(i)]
{{trans|FreeBASIC}}
oddsquares((100, 999))
<lang julia>julia> i = n = 1
</syntaxhighlight>
1
{{Out}}
<pre>
11-element Vector{Int64}:
121
169
225
289
361
441
529
625
729
841
961
</pre>
 
=={{header|Lua}}==
julia> while n < 1000
<syntaxhighlight lang="lua">
n > 100 && println(n)
for i = 1, math.sqrt( 1000 ), n +=2 8ido
local i2 = i +=* 1i
if i2 > end99 then
io.write( " ", i2 )
121
end
end
</syntaxhighlight>
{{out}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE ODDSQR
.MCALL .TTYOUT,.EXIT
ODDSQR::MOV #^D81,R3
MOV #^D19,R4
BR $2
$1: MOV R3,R0
JSR PC,PR0
$2: ADD R4,R3
ADD #2,R4
ADD R4,R3
ADD #2,R4
CMP R3,#^D1000
BLT $1
.EXIT
 
; PRINT NUMBER IN R0 AS DECIMAL
PR0: MOV #4$,R1
1$: MOV #-1,R2
2$: INC R2
SUB #12,R0
BCC 2$
ADD #72,R0
MOVB R0,-(R1)
MOV R2,R0
BNE 1$
3$: MOVB (R1)+,R0
.TTYOUT
BNE 3$
RTS PC
.ASCII /...../
4$: .BYTE 15,12,0
.END ODDSQR</syntaxhighlight>
{{out}}
<pre>121
169
225
Line 176 ⟶ 692:
729
841
961</pre>
 
</lang>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Cases[Range[100, 1000], _?(IntegerQ[Sqrt@#] && OddQ[#] &)]</langsyntaxhighlight>
 
{{out}}<pre>
{121,169,225,289,361,441,529,625,729,841,961}
</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
block(
[count:99,odd_square:[]],
while count<1000 do (
i:lambda([x],oddp(x) and integerp(sqrt(x)))(count),
if i then odd_square:endcons(count,odd_square),
count:count+1),
odd_square);
</syntaxhighlight>
{{out}}
<pre>
[121,169,225,289,361,441,529,625,729,841,961]
</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main = [Stdout (show taskresults),
Stdout "\n"]
taskresults = dropwhile (< minimum) (takewhile (< maximum) oddsquares)
oddsquares = map (^ 2) odds
odds = [1, 3..]
minimum = 101
maximum = 1000</syntaxhighlight>
{{out}}
<pre>[121,169,225,289,361,441,529,625,729,841,961]</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE OddSquare;
FROM InOut IMPORT WriteCard, WriteLn;
VAR n, square: CARDINAL;
BEGIN
n := 10;
LOOP
square := n * n;
IF square > 1000 THEN EXIT END;
IF square MOD 2 = 1 THEN
WriteCard(square, 3);
WriteLn
END;
n := n + 1
END
END OddSquare.</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|Modula-3}}==
{{trans|Modula-2}}
<syntaxhighlight lang="modula3">MODULE OddSquare EXPORTS Main;
 
IMPORT IO;
 
VAR N,Square:CARDINAL;
 
BEGIN
N := 10;
LOOP
Square := N * N;
IF Square > 1000 THEN EXIT END;
IF Square MOD 2 = 1 THEN
IO.PutInt(Square);
IO.Put("\n");
END;
N := N + 1
END
END OddSquare.</syntaxhighlight>
<pre>
121
169
225
289
361
441
529
625
729
841
961
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/math
 
for n in countup(11, sqrt(1000.0).int, 2):
echo n * n
</syntaxhighlight>
 
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961
</pre>
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">class OddSquare {
function : Main(args : String[]) ~ Nil {
i:=n:=1;
while(n < 1000) {
if(n > 100) { "{$n} "->Print(); };
n +=8*i; i+=1;
};
""->PrintLine();
}
}</syntaxhighlight>
 
{{output}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let seq_odd_squares =
let rec next n a () = Seq.Cons (n, next (n + a) (a + 8)) in
next 1 8
 
let () =
seq_odd_squares |> Seq.drop_while ((>) 100) |> Seq.take_while ((>) 1000)
|> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}<pre> 121 169 225 289 361 441 529 625 729 841 961</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 193 ⟶ 846:
use ntheory qw( is_square );
 
print join( ' ', grep $_ & 1 && is_square($_), 100 .. 999 ), "\n";</langsyntaxhighlight>
{{out}}
<pre>
Line 200 ⟶ 853:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
{121,169,225,289,361,441,529,625,729,841,961}
</pre>
 
=={{header|PILOT}}==
<syntaxhighlight lang="pilot">C :n=9
*loop
C :n=#n+1
C :sq=#n*#n
C :sr=(#sq/2)*2
T (sq<>sr):#sq
J (sq<1000):*loop</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|PL/I}}==
Line 216 ⟶ 890:
Based on the Algol 68 sample.
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<langsyntaxhighlight lang="pli">100H: /* PRINT ODD SQUARES BETWEEN 100 AND 1000 */
 
/* CP/M BDOS SYSTEM CALL */
Line 251 ⟶ 925:
END;
 
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 264 ⟶ 938:
<br>
The PL/I include file "pg.inc" can be found on the [[Polyglot:PL/I and PL/M]] page. Note the use of text in column 81 onwards to hide the PL/I specifics from the PL/M compiler.
<langsyntaxhighlight lang="pli">/* PRINT ODD SQUARES BETWEEN 100 AND 1000 */
odd_squares_100H: procedure options (main);
 
Line 300 ⟶ 974:
END;
 
EOF: end odd_squares_100H;</langsyntaxhighlight>
{{out}}
<pre>
Line 307 ⟶ 981:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
iimportimport math
szamok = []
limit = 1000
 
for i in range(1,int( math.ceil(math.sqrtisqrt(limit - 1))) + 1, 2):
num = i*i
if (num < 1000 and num > 99):
szamok.append(num)
 
print(szamok)
</syntaxhighlight>
</lang>
{{out}}
<pre>
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
</pre>
 
;By using itertools
<syntaxhighlight lang="python">from itertools import accumulate, count, dropwhile, takewhile
 
print(*takewhile(lambda x: x<1000, dropwhile(lambda x: x<100, accumulate(count(8, 8), initial=1))))</syntaxhighlight>
{{out}}
<pre>121 169 225 289 361 441 529 625 729 841 961</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [] 1 0
[ 8 + dup dip +
over 100 > until ]
[ dip
[ tuck join swap ]
8 + dup dip +
over 1000 > until ]
2drop
echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 121 169 225 289 361 441 529 625 729 841 961 ]</pre>
 
=={{header|Raku}}==
Vote for deletion: trivial. But if we gotta keep it, at least make it ''slightly'' interesting.
<syntaxhighlight lang="raku" perl6line>for 1..5 {
my $max = exp $_, 10;
put "\n{+$_} odd squares from {$max / 10} to $max:\n{ .batch(10).join: "\n" }"
given ({(2 × $++ + 1)²} … * > $max).grep: $max / 10 ≤ * ≤ $max
}</langsyntaxhighlight>
{{out}}
<pre>2 odd squares from 1 to 10:
Line 362 ⟶ 1,059:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red[]
 
n: 11
Line 369 ⟶ 1,066:
print n * n
n: n + 2
]</langsyntaxhighlight>
{{out}}
<pre>
Line 386 ⟶ 1,083:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "working..." + nl
limit = 1000
Line 411 ⟶ 1,108:
txt = txt + "]"
see txt
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 417 ⟶ 1,114:
[121,169,225,289,361,441,529,625,729,841,961]
done...
</pre>
 
=={{header|RPL}}==
≪ { } 99 999 '''FOR''' j '''IF''' j √ FP NOT '''THEN''' j + '''END''' 2 '''STEP''' ≫ EVAL
{{out}}
<pre>
1: { 121 169 225 289 361 441 529 625 729 841 961 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">lo, hi = 100, 1000
(Integer.sqrt(lo)..Integer.sqrt(hi)).each{|n| puts n*n if n.odd?}</syntaxhighlight>
{{out}}
<pre>
121
169
225
289
361
441
529
625
729
841
961
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var lo = 100
var hi = 1_000
 
say gather {
for k in (lo.isqrt .. hi.isqrt) {
take(k**2) if k.is_odd
}
}</syntaxhighlight>
 
{{out}}
<pre>
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">import math
fn main() {
mut pow := 1
for _ in 0..5 {
mut low := int(math.ceil(math.sqrt(f64(pow))))
if low%2 == 0 {
low++
}
pow *= 10
high := int(math.sqrt(f64(pow)))
mut odd_sq := []int{}
for i := low; i <= high; i += 2 {
odd_sq << i*i
}
println("$odd_sq.len odd squares from ${pow/10} to $pow, \b:")
for i in 0..odd_sq.len {
print("${odd_sq[i]} ")
if (i+1)%10 == 0 {
println('')
}
}
println("\n")
}
}</syntaxhighlight>
 
{{out}}
<pre>
Same as Wren example
</pre>
 
=={{header|Vala}}==
{{trans|Wren}}
<syntaxhighlight lang="vala">void main() {
double pow = 1;
for (int p = 0; p < 5; ++p) {
int low = (int)Math.ceil(Math.sqrt(pow));
if (low % 2 == 0) ++low;
pow *= 10;
int high = (int)Math.floor(Math.sqrt(pow));
int[] odd_square = {};
for (int i = low; i <= high; i += 2) odd_square += i * i;
print(@"$(odd_square.length) odd squares from $(pow/10) to $pow:\n");
for (int i = 0; i < odd_square.length; ++i) {
print("%d ", odd_square[i]);
if ((i + 1) % 10 == 0) print("\n");
}
print("\n\n");
}
}</syntaxhighlight>
 
{{out}}
<pre>
Same as Wren example.
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-traititerate}}
{{libheader|Wren-seq}}
<langsyntaxhighlight ecmascriptlang="wren">import "./traititerate" for Stepped
import "./seq" for Lst
 
Line 435 ⟶ 1,230:
for (chunk in Lst.chunks(oddSq, 10)) System.print(chunk.join(" "))
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 470 ⟶ 1,265:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int N2, N;
[for N2:= 101 to 999 do
[N:= sqrt(N2);
Line 476 ⟶ 1,271:
[IntOut(0, N2); ChOut(0, ^ )];
];
]</langsyntaxhighlight>
 
{{out}}
9,476

edits