Sequence of non-squares: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 14:
{{trans|Python}}
<
R n + Int(floor(1/2 + sqrt(n)))
Line 27:
L.break
L.was_no_break
print(‘No squares found’)</
{{out}}
Line 36:
=={{header|Ada}}==
<
with Ada.Text_IO; use Ada.Text_IO;
Line 59:
end if;
end loop;
end Sequence_Of_Non_Squares_Test;</
{{out}}
<pre>
Line 71:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}}
<
main: (
Line 89:
FI
OD
)</
{{out}}
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
=={{header|ALGOL W}}==
<
% check values of the function: f(n) = n + floor(1/2 + sqrt(n)) %
% are not squares %
Line 123:
else write( "f(n) produced a square" )
end.</
{{out}}
<pre>
Line 132:
=={{header|APL}}==
Generate the first 22 numbers:
<
NONSQUARE 22
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27</
Show there are no squares in the first million:
<
HOWMANYSQUARES NONSQUARE 1000000
0</
=={{header|AppleScript}}==
<
set values to {}
set squareCount to 0
Line 163:
end join
task() </
{{output}}
<
Number of squares (n < 1000000): 0"</
=={{header|Arturo}}==
<
n + floor 0.5 + sqrt n
Line 182:
if? empty? intersection squares nonSquares -> print "Didn't find any squares!"
else -> print "Ooops! Something went wrong!"</
{{out}}
Line 212:
=={{header|AutoHotkey}}==
ahk forum: [http://www.autohotkey.com/forum/post-276683.html#276683 discussion]
<
t .= (A_Index + floor(0.5 + sqrt(A_Index))) " "
MsgBox %t%
Line 219:
Loop 1000000
x := A_Index + floor(0.5 + sqrt(A_Index)), s += x = round(sqrt(x))**2
Msgbox Number of bad squares = %s% ; 0</
=={{header|AWK}}==
<
1 2
2 3
Line 247:
$ awk 'func f(n){return(n+int(.5+sqrt(n)))}BEGIN{for(i=1;i<100000;i++){n=f(i);r=int(sqrt(n));if(r*r==n)print n"is square"}}'
$</
=={{header|BASIC}}==
{{works with|FreeBASIC}}
{{works with|RapidQ}}
<
DIM j AS Double
DIM found AS Integer
Line 276:
END IF
NEXT i
IF found=0 THEN PRINT "No squares found"</
=={{header|BASIC256}}==
<
print "The first 22 numbers generated by the sequence are : "
for i = 1 to 22
Line 301:
function nonSquare (n)
return n + int(0.5 + sqrt(n))
end function</
=={{header|BBC BASIC}}==
<
S% = N% + SQR(N%) + 0.5
PRINT S%
Line 316:
IF S%/R% = R% STOP
NEXT
PRINT "No squares occur for n < 1000000"</
{{out}}
<pre>
Line 350:
Since BC is an arbitrary precision calculator, there are no issues in sqrt (it is enough to increase the scale variable upto the desired ''precision''), nor there are limits (but time) to how many non-squares we can compute.
<
scale = 20
Line 395:
}
quit</
The functions int, round, floor, ceil are taken from [http://www.pixelbeat.org/scripts/bc here] (int is slightly modified) ([http://www.pixelbeat.org/scripts/ Here] he states the license is GPL).
Line 401:
=={{header|Burlesque}}==
<
1 22r@{?s0.5?+av?+}[m
</syntaxhighlight>
=={{header|C}}==
<
#include <stdio.h>
#include <assert.h>
Line 429:
}
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.Diagnostics;
Line 456:
}
}
}</
=={{header|C++}}==
<
#include <algorithm>
#include <vector>
Line 492:
}
return 0 ;
}</
{{out}}
<pre>
Line 501:
=={{header|Clojure}}==
<
;; (Clojure's is more exact)
(use 'clojure.contrib.math)
Line 513:
(doseq [n (range 1 23)] (printf "%s -> %s\n" n (nonsqr n)))
(defn verify [] (not-any? square? (map nonsqr (range 1 1000000))) )</
=={{header|CLU}}==
<
return(n + real$r2i(0.5 + real$i2r(n)**0.5))
end non_square
Line 542:
|| " at n = " || int$unparse(n))
end
end start_up </
{{out}}
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
Line 548:
=={{header|COBOL}}==
<
PROGRAM-ID. NONSQR.
Line 609:
MOVE SQR-TEMP TO SQUARE-ROOT.
COMPUTE SQR-TEMP =
(SQUARE-ROOT + SQR-INP / SQUARE-ROOT) / 2.</
{{out}}
<pre> 1: 2
Line 638:
=={{header|CoffeeScript}}==
<
non_square = (n) -> n + Math.floor(1/2 + Math.sqrt(n))
Line 658:
console.log "success"
</syntaxhighlight>
{{out}}
Line 671:
{{works with|CCL}}
<
(flet ((non-square (n)
"Compute the N-th number of the non-square sequence"
Line 686:
:when (squarep (non-square n))
:do (format t "Found a square: ~D -> ~D~%"
n (non-square n)))))</
=={{header|D}}==
<
int nonSquare(in int n) pure nothrow @safe @nogc {
Line 702:
assert(ns != (cast(int)real(ns).sqrt) ^^ 2);
}
}</
{{out}}
<pre>[2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27]</pre>
Line 711:
{{Trans|C sharp}}
Small variation of C#
<syntaxhighlight lang="delphi">
program Sequence_of_non_squares;
Line 738:
Writeln(i, 'Is Square');
end;
end.</
{{out}}
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27</pre>
=={{header|EchoLisp}}==
<
(lib 'sequences)
Line 753:
(filter square? (take A000037 1000000))
→ null
</syntaxhighlight>
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
class
APPLICATION
Line 801:
end
</syntaxhighlight>
{{out}}
<pre>
Line 839:
=={{header|Elixir}}==
<
IO.inspect for n <- 1..22, do: f.(n)
Line 850:
nil -> IO.puts "No squares found below #{n}"
val -> IO.puts "Error: number is a square: #{val}"
end</
{{out}}
Line 860:
=={{header|Erlang}}==
<
-module(non_squares).
-export([main/0]).
Line 869:
non_square(N) ->
N+trunc(1/2+ math:sqrt(N)).
</syntaxhighlight>
=={{header|Euphoria}}==
This is based on the [[BASIC]] and [[Go]] examples.
<
return n + floor( 0.5 + sqrt( n ) )
end function
Line 896:
if found = 0 then
puts( 1, "No squares found\n" )
end if</
=={{header|F_Sharp|F#}}==
<
let SequenceOfNonSquares =
Line 908:
|> Seq.map(fun f -> (f, nonsqr f))
|> Seq.filter(fun f -> IsSquare(snd f))
;;</
Executing the code gives:<
> SequenceOfNonSquares;;
val it : seq<int * int> = seq []</
=={{header|Factor}}==
<
sequences ;
Line 926:
each ;
print-first22 check-for-sq</
{{out}}
<pre>
Line 934:
=={{header|Fantom}}==
<
class Main
{
Line 956:
}
}
</syntaxhighlight>
=={{header|Forth}}==
<
: f>u f>d drop ;
Line 968:
: square? ( n -- ? ) u>f fsqrt fdup fround f- f0= ;
: test ( n -- ) 1 do i fn square? if cr i . ." fn was square" then loop ;
1000000 test \ ok</
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<
IMPLICIT NONE
Line 991:
END DO
END PROGRAM NONSQUARES</
=={{header|FreeBASIC}}==
<
Function nonSquare (n As UInteger) As UInteger
Line 1,026:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 1,037:
=={{header|GAP}}==
<syntaxhighlight lang="text"># Here we use generators : the given formula doesn't need one, but the alternate
# non-squares function is better done with a generator.
Line 1,081:
ForAll([1 .. 1000000], i -> a() = b());
# true</
=={{header|Go}}==
I assume it's obvious that the function monotonically increases, thus it's enough to just watch for the next possible square. If a square is found, the panic will cause an ugly stack trace.
<
import (
Line 1,121:
}
fmt.Println("No squares occur for n <", limit)
}</
{{out}}
<pre>
Line 1,163:
Solution:
<
Test Program:
<
(1..1000000).each { assert ((nonSquare(it)**0.5 as long)**2) != nonSquare(it) }</
{{out}}
Line 1,194:
=={{header|Haskell}}==
<
nonsqr n = n + round (sqrt (fromIntegral n))</
> map nonsqr [1..22]
Line 1,206:
Or, in a point-free variation, defining a 'main' for the compiler (rather than interpreter)
<
----------------------- NON SQUARES ----------------------
Line 1,231:
(show . and) $
notSquare . nonSqr <$> [1 .. 1000000]
]</
{{Out}}
<pre>First 22 members of the series:
Line 1,240:
=={{header|HicEst}}==
<
nonSqr = $ + FLOOR(0.5 + $^0.5)
Line 1,252:
ENDDO
WRITE(Name) squares_found
END</
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
squares_found=0; </pre>
=={{header|Icon}} and {{header|Unicon}}==
<
procedure main()
Line 1,271:
procedure nsq(n) # return non-squares
return n + floor(0.5 + sqrt(n))
end</
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/numbers.icn numbers provides floor]
=={{header|IDL}}==
<
f = n+floor(.5+sqrt(n)) ; Apply formula
print,f[0:21] ; Output first 22
print,where(sqrt(f) eq fix(sqrt(f))) ; Test for squares</
{{out}}
Line 1,291:
=={{header|J}}==
<
rf 1+i.22 NB. Results from 1 to 22
Line 1,297:
+/ (rf e. *:) 1+i.1e6 NB. Number of square RFs <= 1e6
0</
=={{header|Java}}==
<
public static int nonsqr(int n) {
return n + (int)Math.round(Math.sqrt(n));
Line 1,317:
}
}
}</
=={{header|JavaScript}}==
Line 1,325:
Iterative
<
for (var i = 1; i < 23; i++) a[i] = i + Math.floor(1/2 + Math.sqrt(i));
console.log(a);
Line 1,331:
for (i = 1; i < 1000000; i++) if (Number.isInteger(i + Math.floor(1/2 + Math.sqrt(i))) === false) {
console.log("The ",i,"th element of the sequence is a square");
}</
===ES6===
By functional composition
<
'use strict';
Line 1,438:
return main()
})();</
{{Out}}
<pre>First 22 terms: -> 2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,26,27
Line 1,446:
=={{header|jq}}==
{{works with|jq|1.4}}
<
def is_square: sqrt | . == floor;
Line 1,453:
(range(1;23) | A000037),
"Check for squares for n up to 1e6:",
(range(1;1e6+1) | A000037 | select( is_square ))</
{{out}}
<
For n up to and including 22:
2
Line 1,480:
27
Check for squares for n up to 1e6:
$</
=={{header|Julia}}==
<
@show nonsquare.(1:1_000_000) ∩ collect(1:1000) .^ 2</
{{out}}
<pre>nonsquare.(1:1000000) ∩ collect(1:1000) .^ 2 = Int64[]</pre>
Line 1,491:
=={{header|K}}==
<
nonsquare[1_!23]</
{{out}}
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27</pre>
<
+/issquare[nonsquare[1_!1000001]] / Number of squares in first million results</
{{out}}
<pre>0</pre>
=={{header|Kotlin}}==
<
fun f(n: Int) = n + Math.floor(0.5 + Math.sqrt(n.toDouble())).toInt()
Line 1,517:
if (squares.size == 0) println("There are no squares for n less than one million")
else println("Squares are generated for the following values of n: $squares")
}</
{{out}}
Line 1,549:
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def nosquare {lambda {:n} {+ :n {floor {+ 0.5 {sqrt :n}}}}}}
-> nosquare
Line 1,563:
{S.serie 1 1000000}}}}
-> true
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
for i = 1 to 22
print nonsqr( i); " ";
Line 1,588:
nonsqr = n +int( 0.5 +n^0.5)
end function
</syntaxhighlight>
<pre>
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
Line 1,595:
=={{header|Logo}}==
<
=={{header|Lua}}==
<
return n + math.floor(1/2 + math.sqrt(n))
end
Line 1,614:
end
end
print("No squares found")</
{{out}}
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
Line 1,621:
=={{header|MAD}}==
<
BOOLEAN FOUND
FOUND = 0B
Line 1,646:
VECTOR VALUES FINDSQ = $5HELEM ,I5,2H, ,I5,11H, IS SQUARE*$
VECTOR VALUES NOSQ = $16HNO SQUARES FOUND*$
END OF PROGRAM</
{{out}}
Line 1,675:
=={{header|Maple}}==
<syntaxhighlight lang="maple">
with(NumberTheory):
Line 1,687:
number;
</syntaxhighlight>
{{out}}<pre>
Line 1,699:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
nonsq@Range[22]
If[! Or @@ (IntegerQ /@ Sqrt /@ nonsq@Range[10^6]),
Print["No squares for n <= ", 10^6]
]</
{{out}}
<pre>{2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27}
Line 1,709:
=={{header|MATLAB}}==
<
for n = (1:i)
Line 1,727:
fprintf('\nNo square numbers were generated for n <= %d\n',i);
end</
Solution:
<
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
No square numbers were generated for n <= 1000000</
=={{header|Maxima}}==
<
makelist(nonsquare(n), n, 1, 20);
[2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24]
Line 1,743:
u: makelist(i, i, 1, m)$
is(sublist(u, not_square) = sublist(map(nonsquare, u), lambda([x], x <= m)));
true</
=={{header|min}}==
{{works with|min|0.19.3}}
<
(sqrt dup floor - 0 ==) :sq?
(:n =q 1 'dup q concat 'succ concat n times pop) :upto
Line 1,753:
(non-sq print! " " print!) 22 upto newline
"Squares for n below one million:" puts!
(non-sq 'sq? 'puts when pop) 999999 upto</
{{out}}
<pre>
Line 1,761:
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 П4 ИП4 0 , 5 ИП4 КвКор + [x]
+ С/П КИП4 БП 02</
=={{header|MMIX}}==
<
GREG @
buf OCTA 0,0
Line 1,851:
LDA $255,NL
TRAP 0,Fputs,StdOut
TRAP 0,Halt,0 % }</
{{out}}
<pre>~/MIX/MMIX/Rosetta> mmix SoNS
Line 1,858:
=={{header|Modula-3}}==
<
IMPORT IO, Fmt, Math;
Line 1,880:
END;
END;
END NonSquare.</
{{out}}
<pre>2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27</pre>
=={{header|Nim}}==
<
func nosqr(n: int): seq[int] =
Line 1,901:
for i in nosqr(1_000_000 - 1):
assert not issqr(i)
echo "\nNo squares were found for n less than 1_000_000."</
{{out}}
<pre>Sequence for n = 22:
Line 1,909:
=={{header|OCaml}}==
<
val nonsqr : int -> int = <fun>
# (* first 22 values (as a list) has no squares: *)
Line 1,923:
assert (j <> floor j)
done;;
- : unit = ()</
=={{header|Oforth}}==
<
1000000 seq map(#[ dup sqrt 0.5 + floor + ]) conform(#[ sqrt dup floor <>]) println</
{{out}}
Line 1,938:
=={{header|Ol}}==
<
(import (lib math))
Line 1,959:
; ==> ()
</syntaxhighlight>
=={{header|Oz}}==
<
fun {NonSqr N}
N + {Float.toInt {Floor 0.5 + {Sqrt {Int.toFloat N}}}}
Line 1,978:
in
{Show {List.take Ns 22}}
{Show {Some Ns IsSquare}}</
=={{header|PARI/GP}}==
<
=={{header|Pascal}}==
{{libheader|Math}}
<
uses
Line 2,008:
writeln('square found for n = ', n);
end;
end.</
{{out}}
<pre>:> ./SequenceOfNonSquares
Line 2,016:
a little speedup in testing upto 1 billion.
5 secs instead of 21 secs using fpc2.6.4
<
//sequence of non-squares
//n = i + floor(1/2 + sqrt(i))
Line 2,065:
First22;
Test(1000*1000*1000);
end.</
=={{header|Perl}}==
<
print join(' ', map nonsqr($_), 1..22), "\n";
Line 2,075:
my $root = sqrt nonsqr($i);
die "Oops, nonsqr($i) is a square!" if $root == int $root;
}</
{{out}}
Line 2,081:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 2,103:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"none found "</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?{</span><span style="color: #000000;">nxt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">snxt</span><span style="color: #0000FF;">}</span>
<!--</
{{out}}
<pre>
Line 2,111:
=={{header|PHP}}==
<
//First Task
for($i=1;$i<=22;$i++){
Line 2,131:
echo("Up to 1000000, found no square number in the sequence!");
}
?></
{{Out}}
<pre>>php nsqrt.php
Line 2,161:
=={{header|Picat}}==
<
println([f(I) : I in 1..22]),
Line 2,174:
Squares = new_map([I*I=1:I in 1..sqrt(Limit)]),
Check = [[I,T] : I in 1..Limit-1, T=f(I), Squares.has_key(T)],
println(check=Check.len).</
{{out}}
Line 2,182:
=={{header|PicoLisp}}==
<
(+ N (sqrt N T)) ) # 'sqrt' rounds when called with 'T'
Line 2,191:
(let (N (sqfun I) R (sqrt N))
(when (= N (* R R))
(prinl N " is square") ) ) )</
{{out}}
<pre>1 2
Line 2,217:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
put skip edit ((n, n + floor(sqrt(n) + 0.5) do n = 1 to n))
(skip, 2 f(5));
</syntaxhighlight>
Results:
<syntaxhighlight lang="text">
1 2
2 3
Line 2,246:
20 24
21 26
</syntaxhighlight>
Test 1,000,000 values:
<syntaxhighlight lang="text">
test: proc options (main);
declare n fixed (15);
Line 2,268:
end test;
</syntaxhighlight>
=={{header|PostScript}}==
<syntaxhighlight lang="text">/nonsquare { dup sqrt .5 add floor add } def
/issquare { dup sqrt floor dup mul eq } def
Line 2,281:
} if pop
} for
</syntaxhighlight>
{{out}} (lack of error message shows none below 1000 produced a square)
<pre>
Line 2,310:
=={{header|PowerShell}}==
Implemented as a filter here, which can be used directly on the pipeline.
<
return $_ + [Math]::Floor(1/2 + [Math]::Sqrt($_))
}</
Printing out the first 22 values is straightforward, then:
<syntaxhighlight lang
If there were any squares for ''n'' up to one million, they would be printed with the following, but there is no output:
<
| Get-NonSquare `
| Where-Object {
$r = [Math]::Sqrt($_)
[Math]::Truncate($r) -eq $r
}</
=={{header|PureBasic}}==
<
For a = 1 To 22
; Integer, so no floor needed
Line 2,350:
EndIf
; Wait for enter
Input()</
=={{header|Python}}==
<
>>> def non_square(n):
return n + floor(1/2 + sqrt(n))
Line 2,372:
----> 2 next(filter(is_square, non_squares))
StopIteration: </
Line 2,378:
{{Works with|Python|3.7}}
<
from itertools import count, islice
Line 2,466:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>OEIS A000037
Line 2,478:
=={{header|Quackery}}==
<
[ dup n->v 2 vsqrt
Line 2,492:
[ i^ 1+ nonsquare
squarenum if 1+ ]
echo say " square numbers found"</
{{out}}
Line 2,504:
=={{header|R}}==
Printing the first 22 nonsquares.
<
nonsqr(1:22)</
[1] 2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27
Testing the first million nonsquares.
<
{
sqrx <- sqrt(x)
Line 2,515:
err < 100*.Machine$double.eps
}
any(is.square(nonsqr(1:1e6)))</
[1] FALSE
=={{header|Racket}}==
<
#lang racket
Line 2,532:
(for/or ([n (in-range 1 1000001)])
(square? (non-square n)))
</syntaxhighlight>
{{out}}
Line 2,544:
{{works with|Rakudo|2016.07}}
<syntaxhighlight lang="raku"
# Print the first 22 values of the sequence
Line 2,552:
for 1 .. 1_000_000 -> $i {
say "Oops, nth-term($i) is square!" if (sqrt nth-term $i) %% 1;
}</
{{out}}
Line 2,558:
=={{header|Red}}==
<
repeat i 999'999 [
Line 2,567:
break
]
]</
{{out}}
<pre>
Line 2,580:
:::* 8 = iSqrt(64)
:::* 8 = iSqrt(65)
<
parse arg N M . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N= 22 /*Not specified? Then use the default.*/
Line 2,610:
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_%2
do j=0 while h>9; m.j= h; h= h % 2 + 1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g)*.5; end /*k*/; return g</
{{out|output}}
<pre>
Line 2,644:
=={{header|Ring}}==
<
for n=1 to 22
x = n + floor(1/2 + sqrt(n))
Line 2,650:
next
see nl
</syntaxhighlight>
=={{header|Ruby}}==
<
n + (0.5 + Math.sqrt(n)).floor
end
Line 2,663:
(squares & non_squares).each do |n|
puts "Oops, found a square f(#{non_squares.index(n)}) = #{n}"
end</
=={{header|Rust}}==
{{works with|Rust|1.1}}
<
fn f(n: i64) -> i64 {
n + (0.5 + (n as f64).sqrt()) as i64
Line 2,682:
println!("{} unexpected squares found", count);
}
</syntaxhighlight>
=={{header|Scala}}==
<
for(n<-1 to 22) println(n + " "+ nonsqr(n))
Line 2,693:
j==math.floor(j)
}
println("squares up to one million="+test)</
=={{header|Scheme}}==
<
(lambda (index)
(+ index (inexact->exact (floor (+ (/ 1 2) (sqrt index)))))))
Line 2,726:
(display ((any? square?) (((sequence non-squares) 1) 999999)))
(newline)</
{{out}}
(2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27)
Line 2,732:
=={{header|Seed7}}==
<
include "float.s7i";
include "math.s7i";
Line 2,757:
end if;
end for;
end func;</
=={{header|Sidef}}==
<
{|i| nonsqr(i) }.map(1..22).join(' ').say
Line 2,767:
die "Found a square in the sequence: #{i}"
}
} << 1..1e6</
=={{header|Smalltalk}}==
<
nonSquare := [:n |
n + (n sqrt) rounded
Line 2,788:
].
Transcript show: 'Squares found for values up to 1,000,000: ';
show: squaresFound asString; cr</
=={{header|Standard ML}}==
<
val nonsqr = fn : int -> int
- List.tabulate (23, nonsqr);
Line 2,802:
loop 1
end;
val it = true : bool</
=={{header|Tcl}}==
<
set f {n {expr {$n + floor(0.5 + sqrt($n))}}}
Line 2,821:
}
}
puts "done"</
{{out}}
<pre>1 2.0
Line 2,852:
Definition and 1 to 22, interactively:
<
Done
■ seq(f(n),n,1,22)
{2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,26,27}</
Program testing up to one million:
<
Prgm
Local i, ns
Line 2,869:
EndFor
Disp "Done"
EndPrgm</
(This program has not been run to completion.)
=={{header|Transd}}==
<
MainModule: {
Line 2,891:
(textout "\n\nUp to 1 000 000 - no squares found.")
)
}</
{{out}}
<pre>
Line 2,900:
=={{header|True BASIC}}==
<
LET nonSquare = n + INT(0.5 + SQR(n))
END FUNCTION
Line 2,922:
NEXT i
IF found = 0 THEN PRINT "No squares found"
END</
=={{header|Ursala}}==
<
#import flo
Line 2,935:
examples = %neALP ^(~&,nth_non_square)*t iota23
check = (is_square*~+nth_non_square*t; ~&i&& %eLP)||-[no squares found]-! iota 1000000</
{{out}}
<pre>
Line 2,965:
=={{header|VBA}}==
<syntaxhighlight lang="vb">
Sub Main()
Dim i&, c&, j#, s$
Line 2,984:
Private Function ns(l As Long) As Long
ns = l + Int(1 / 2 + Sqr(l))
End Function</
{{out}}
<pre>values for n in the range 1 to 22 : 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27,
Line 2,991:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
System.print("The first 22 numbers in the sequence are:")
Line 3,004:
if (n <= 22) Fmt.print(" $2d $2d", n, s)
}
System.print("\nNo squares were found in the first 999,999 terms.")</
{{out}}
Line 3,037:
=={{header|XLISP}}==
<
(+ n (floor (+ 0.5 (sqrt n)))))
Line 3,057:
(print (mapcar non-square (range 1 23)))
(print `(number of squares for values less than 1000000 = ,(count-squares 1 1000000)))</
{{out}}
<pre>(2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27)
Line 3,063:
=={{header|XPL0}}==
<
func real Floor(X); \Truncate X toward - infinity
Line 3,085:
M0:= M;
];
]</
{{out}}
Line 3,094:
=={{header|Yabasic}}==
<
print "The first 22 numbers generated by the sequence are : "
for i = 1 to 22
Line 3,116:
sub nonSquare (n)
return n + int(0.5 + sqrt(n))
end sub</
=={{header|zkl}}==
<
[1..22].apply(seq).toString(*).println();
Line 3,126:
isSquare(25) //-->True
isSquare(26) //-->False
[2..0d1_000_000].filter(fcn(n){isSquare(seq(n))}).println();</
modf returns the integer and fractional parts of a float
{{out}}
|