g | x | w | all
Bytes Lang Time Link
007Vyxal 3250919T135509ZThemooni
034jq250914T183410Zpmf
024APLNARS250914T091136ZRosario
029TIBASIC TI84 Plus CE Python250912T171555Zmadeforl
077Tcl180428T221306Zsergiol
052Scala 3231118T042132Z138 Aspe
008Japt180428T210224ZShaggy
4875Vyxal G231114T142013Zpacman25
031dc180621T195644Zbrhfl
nanThese answers are not the most efficient ways to solve the problem180621T160531ZWheat Wi
056C gcc180428T202455ZJonathan
034JavaScript180428T211838ZShaggy
038Ruby180501T094329ZKirill L
049Python 3180501T154158ZReesi82
081Forth gforth180430T163252Zreffu
027Perl 6180429T182907Znwellnho
009Jelly180429T120039ZMartin E
026APL+WIN180429T094427ZGraham
171mIRC Scripting180429T074806Zjaytea
040JavaScript ES6180428T194353ZNeil
032Haskell180428T190907ZAngs
00505AB1E180428T195742ZMr. Xcod
037R180428T195035ZGiuseppe
010Pyth180428T194342ZMr. Xcod
042Python 3180428T194113ZDennis
042Ruby180428T184950ZAsone Tu
022J180428T184604ZGalen Iv
007Jelly180428T190017ZJonathan
009Husk180428T190041Zბიმო

Vyxal 3, 7 bytes

kNJʎ√⌊e

Vyxal It Online!

kNJʎ√⌊e­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁤‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌­
kN       # ‎⁡natural numbers
  J      # ‎⁢and 0
   ʎ     # ‎⁣filtered by
    √⌊e  # ‎⁤floor(sqrt(n))%2 == 0
💎

Created with the help of Luminespire.

jq, v1.4+, 34 bytes

Using the formula from @Reesi82's approach:

(.*8+1|sqrt+1|./4|floor|2*.*.+.)+.

Try it online!

jq, v1.5+, 39 bytes

Using straightforward sequence filtering:

nth(.;0|recurse(.+1)|select(sqrt%2==0))

Try it online!

APL(NARS), 24 chars

{⍵+k+2×k×k←⌊4÷⍨1+√1+8×⍵}

It seems the formula of post https://codegolf.stackexchange.com/a/163918/120560 is right. test:

  {⍵+k+2×k×k←⌊4÷⍨1+√1+8×⍵}0,⍳50
0 4 5 6 7 8 16 17 18 19 20 21 22 23 24 36 37 38 39 40 41 
  42 43 44 45 46 47 48 64 65 66 67 68 69 70 71 72 73 
  74 75 76 77 78 79 80 100 101 102 103 104 105 

TI-BASIC (TI-84 Plus CE Python), 29 bytes

Input N
While J<N
G+1→G
J+not(fPart(.5int(√(G→J
End
G

Tcl, 77 bytes

proc S {x n\ 0 i\ 1} {while \$i<$x {if 1>int([incr n]**.5)%2 {incr i}}
set n}

Try it online!

Scala 3, 52 bytes

Stream.from(0).filter(n=>math.sqrt(n).toInt%2==0)(_)

Attempt This Online!

Japt, 11 8 bytes

Ȭf v}iU

Try it

Vyxal G, 39 bitsv2, 4.875 bytes

≬√⌊₂l

Try it Online!

Bitstring:

111111000101100000001111100000100100000

lol vyncode

dc, 31 bytes

sn_1[d]sD[1+dv2%0=Dzln!<M]dsMxp

Try it online! (1-indexed)

Rather simple. D is a macro that just duplicates the top-of-stack. We begin by storing the user's input in n, and placing negative 1 (_1) on the stack. Macro M increments the top-of-stack by one, duplicates it, and then does the necessary sqrt mod 2 (v2%). dc's precision is zero by default, so doing a square root is, by default, actually the floor of the square root. 0=D compares our v2% to zero, and runs our duplication macro (D) if true. z fetches the stack depth, and then ln!<M compares this to n (our target), continuing to run M until we get to the value we were looking for. Finally, print it.

These answers are not the most efficient ways to solve the problem, however I do think they are interesting.

Haskell, 37 33 bytes

(!!)$do x<-[0,2..];[x^2..x^2+2*x]

Try it online!

Haskell, 45 42 bytes

y#x=not$y^2>x||(y+1)#x
(filter(0#)[0..]!!)

Try it online!

C (gcc), 57 56 bytes

b,e;r(g){for(e=0;g&&++e;b&1&&--g)for(b=0;e/++b/b;);g=e;}

Try it online!

JavaScript, 36 34 bytes

0-indexed

n=>(g=i=>i**.5&1||n--?g(++i):i)(0)

2 bytes saved thanks to l4m2


Test it

o.innerText=[...Array(50).keys()].map(
n=>(g=i=>i**.5&1||n--?g(++i):i)(0)
).join`, `
<pre id=o></pre>

Ruby, 39 38 bytes

->n{(0..n*4).select{|x|x**0.5%2<1}[n]}

Try it online!

0-indexed. Instead of simple looping, this approach takes a large enough sequence of numbers and selects only those that fulfill the condition. The particular multiplier n*4 is necessary to cover the case n=1 => 4 (n*n doesn't fit here), and due to the pattern in the sequence, the value of the nth number fluctuates around n*2, so taking n*4 should always be large enough.

Python 3, 49 bytes

def f(n):
 k=(1+(8*n+1)**.5)//4
 return n+2*k*k+k

Try it online!

A slightly different approach. First, if we subtract the sequence 0,1,2,... from the sequence of Schlosberg numbers, we get the sequence 0,3,3,3,3,3,10,10,10,10,10,10,10,10,10,21. Ignoring repetitions, the sequence 0,3,10,21,... is the sequence a(k) = 2k^2+k. If we can find k, the nth Schlosberg number is then n+a(k).

Given k, each a(k) is repeated 4k+1 times. Summing the length of the first k blocks, we get that the kth block of repetition ends at entry n=2k^2-k. Inverting this, we get k=(1+sqrt(8n+1))/4, which gives an explicit formula for k.

Forth (gforth), 81 bytes

Sequence is 1-indexed [f(1) is 0]

: f 0 0 begin over s>f fsqrt f>s 1 and 0= - 1 under+ dup 3 pick = until drop 1- ;

Try it online!

Explanation

0 0              \ place the loop index and sequence index on the stack
begin            \ start an indefinite loop
   over          \ grab a copy of the loop index
   s>f sqrt f>s  \ get the square root of the index and truncate
   1 and 0=      \ determine if result is even
   -             \ if even, add 1 to sequence tracker (-1 is default for "true" in forth)
   1 under+      \ add 1 to the loop index
   dup 3 pick =  \ check if the current sequence position is the one that was requested
until            \ end the loop if condition above is true
drop 1-          \ drop the loop index and subtract 1 from the loop index to get the result

Perl 6, 27 bytes

{grep(+^*.sqrt%2,0..*)[$_]}

Try it online!

Jelly, 9 bytes

ḤḶ²Ḷœ^/ị@

Try it online!

Unfortunately it's longer than the other answer, but I do like this approach.

Explanation

The goal is to get the ranges from each even square to each subsequent odd square, excluding the odd square. We can do this by taking the symmetric set difference of some even number of ranges from zero to just below each square.

Ḥ   Double the input N to ensure it's even.
Ḷ   Lowered range, from 0 to 2N-1.
²   Square to get the first 2N squares.
Ḷ   Get the lowered ranges up to each square.
œ^/ Fold symmetric set difference over the ranges.
ị@  Select the Nth value.

APL+WIN, 29 26 bytes

3 bytes saved thanks to Cows quack

Prompts for integer input:

(0,(~2|⌊r*.5)/r←⍳n×3)[n←⎕]

Explanation:

[n←⎕] prompts for input and selects the nth value of the result

(0,(~2|⌊r*.5)/r←⍳n×3)[n←⎕] create a vector of all results up to n×3
which works up to limit of machine. ×2 works up to n~10E7

mIRC Scripting, 171 bytes

a {
  %s = 0
  %x = -1
  while 1 {
    inc %x 2
    %i = %x
    while %i {
      echo - %s
      inc %s
      dec %i
    }
    inc %x 2
    inc %s %x
  }
}

I didn't yet see this method for generating new Schlosberg numbers, so above is just a simple one that reads like pseudocode. We start at 0, display 1 number, increase 3, display 5, increase 7, display 9, etc. A simple pattern emerges.

JavaScript (ES6), 41 40 bytes

f=(n,i=0,j=1)=>n<j?n+i:f(n-j,i-2*~j,j+4)
<input type=number min=0 value=0 oninput=o.textContent=f(this.value)><pre id=o>0

Edit: Saved 1 byte thanks to @JonathanFrech.

Haskell, 32 bytes

(filter(even.floor.sqrt)[0..]!!)

Try it online!

05AB1E, 5 bytes

µNtóÈ

Try it online!

R, 37 bytes

function(n)(x=0:n^2)[!x^.5%/%1%%2][n]

Try it online!

1-based indexing.

Pyth, 10 bytes

e.fiI2s@Z2

Try it here!

Explanation

e.fiI2s@Z2 – Full program.
 .f        – Find the first N positive integers satisfying the requirements (var: Z).
e          – And take the last one (i.e. the Nth).
       @Z2 – Take the square root of Z.
      s    – Convert to an integer.
   iI2     – Check if 2 is invariant over applying GCD with the above (i.e. is it even?)

Python 3, 42 bytes

f=lambda n,k=1:n and-~f(n-(k**.5%2<1),k+1)

Try it online!

Ruby, 45 44 42 bytes

->n,i=-1{(i+=1)**0.5%2<1||n+=1while n>i;i}

Try it online!

J, 22 bytes

{.[:I.0=2|3<.@%:@i.@*]

Try it online!

Jelly, 7 bytes

½ḞḂ¬Ʋ#Ṫ

A full program accepting n from STDIN

Try it online!

How?

½ḞḂ¬Ʋ#Ṫ - Main link: no arguments
     #  - take input (n) from STDIN & count up (i=0,1,...) collecting truthy results of:
    Ʋ   -   last four links as a monad:
½       -     square root
 Ḟ      -     floor      (½Ḟ could also be ƽ - integer square root)
  Ḃ     -     bit (modulo by 2 - i.e. isOdd?)
   ¬    -     logical NOT
      Ṫ - tail (get the nth rather than the first n)
        - implicit print to STDOUT

Husk, 9 bytes

!fȯ¦2⌊√ΘN

Try it online!

Explanation

!f(¦2⌊√)ΘN  -- 1-indexed number, eg: 4
        ΘN  -- natural numbers with 0: [0,1,2,3,4,5,6,7,8,9..
 f(    )    -- filter by
  (   √)    -- | square root: [0,1,1.414213562373095,1.7320508075688774,2,2.23606797749979,2.449489742783178,2.6457513110645903,2.82842712474619,3,..
  (  ⌊ )    -- | floor: [0,1,1,1,2,2,2,2,2,3,..
  (¦2  )    -- | divisible by 2: [1,0,0,0,1,1,1,1,1,0,..
            -- : [0,4,5,6,7,8,..
!           -- get element: 6