[Question]
  [
From the infinite triangular array of positive integers, suppose we select every 2nd numbers on every 2nd row as shown below:
$$
\underline{1} \\
\;2\; \quad \;3\; \\
\;\underline{4}\; \quad \;5\; \quad \;\underline{6}\; \\
\;7\; \quad \;8\; \quad \;9\; \quad 10 \\
\underline{11} \quad 12 \quad \underline{13} \quad 14 \quad \underline{15} \\
16 \quad 17 \quad 18 \quad 19 \quad 20 \quad 21 \\
\underline{22} \quad 23 \quad \underline{24} \quad 25 \quad \underline{26} \quad 27 \quad \underline{28} \\
\cdots
$$
The resulting sequence ([A185868](http://oeis.org/A185868)) is as follows:
```
1, 4, 6, 11, 13, 15, 22, 24, 26, 28, 37, 39, 41, 43, 45, 56, 58, 60, 62, 64, 66,
79, 81, 83, 85, 87, 89, 91, 106, 108, 110, 112, 114, 116, 118, 120, 137, ...
```
The task is to output this sequence.
[sequence](/questions/tagged/sequence "show questions tagged 'sequence'") I/O rules apply. You can choose to implement one of the following:
* Given the index \$n\$ (0- or 1-based), output the \$n\$th term of the sequence.
* Given a positive integer \$n\$, output the first \$n\$ terms of the sequence.
* Take no input and output the entire sequence by
	+ printing infinitely or
	+ returning a lazy list or a generator.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.
  
[Answer]
# [Python](https://www.python.org), 35 bytes (@att)
```
lambda n:int((2*n)**.5-.5)**2+2*n-1
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3lXMSc5NSEhXyrDLzSjQ0jLTyNLW09Ex19UyBtJE2kK9rCFWqkJZfpJCnkJmnUJSYl56qYahjZKBpVVAE0pimkaepCVG3YAGEBgA)
### [Python](https://www.python.org), 39 bytes
```
lambda n:(int((8*n)**.5-1)//2)**2+2*n-1
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY31XMSc5NSEhXyrDQy80o0NCy08jS1tPRMdQ019fWNgEwjbSOtPF1DqHKFtPwihTyFzDyFosS89FQNQx0jA02rgiKQ3jSNPE1NiLoFCyA0AA)
Given the 1-based index computes a single value.
[Answer]
# [Python 2](https://docs.python.org/2/), 47 bytes
Outputs the sequence indefinitely.
```
n=x=1
while 1:exec'2;print x;x+='*n+'n-~n';n+=1
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8@2wtaQqzwjMydVwdAqtSI1Wd3IuqAoM69EocK6QttWXStPWz1Pty5P3TpP29bw/38A "Python 2 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org), 34 bytes
```
[2*n^2-3*n+2*k|n<-[1..],k<-[1..n]]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ2W0km6Ec0CAUuz-3MTMPAVbhdzEAt94hYKizLwSBRWFksTsVAVDAwOFmKWlJWm6FjeVoo208uKMdI218rSNtLJr8mx0ow319GJ1siGMvNhYiMoFUApKAwA)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ḷ²’xRĖḄḣ
```
A monadic Link that accepts a positive integer, \$n\$, and yields a list of the first \$n\$ odd-odd triangular polka dot numbers.
**[Try it online!](https://tio.run/##AR4A4f9qZWxsef//4bi2wrLigJl4UsSW4biE4bij////Mzc "Jelly – Try It Online")**
### How?
Calculates the first \$T(n)=\frac{n(n+1)}{2}\$ terms, and outputs the first \$n\$.
```
Ḷ²’xRĖḄḣ - Link: integer, n     e.g. 5
Ḷ        - lowered range (n)         [    0,    1,    2,    3,    4]
 ²       - square (vectorises)       [    0,    1,    4,    9,   16]
  ’      - decrement                 [   -1,    0,    3,    8,   15]
    R    - range (n)                 [    1,    2,    3,    4,    5]
   x     - repeat elements           [   -1,    0,    0,    3,    3,    3,    8,    8,    8,     8,     15,     15,     15,     15,     15]
    Ė    - enumerate                 [[1,-1],[2,0],[3,0],[4,3],[5,3],[6,3],[7,8],[8,8],[9,8],[10,8],[11,15],[12,15],[13,15],[14,15],[15,15]]
     Ḅ   - convert from base 2 (vectorises)
           ...i.e. [a,b] -> 2a+b     [    1,    4,    6,   11,   13,   15,   22,   24,   26,    28,     37,     39,     41,     43,     45]
       ḣ - head (to index n)         [    1,    4,    6,   11,   13]
```
[Answer]
# [Rust](https://www.rust-lang.org/), 43 bytes
```
|n|((n+n).sqrt().round()-1.).powi(2)+n+n-1.
```
[Try it online!](https://tio.run/##dczBCsIwDAbge58i3hLmiu1ExKGvMga2MNDMtR0enM9eg9iTLIeQn/8jYY4pe4Z7PzASvBTI3FwCfwLP6BtL9UU2nCEvvCByxaTjFBKSDuPMV6TaaNKP8TmgpUp6yblV3099jC6kzk0b9GgkQkdb@B3tP7GF7FdJU8hhlZhdMfZYkHrnDw "Rust – Try It Online")
A slightly modified version of loopy walt's answer.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes
```
Þ∞:ẇ2Ḟ2vḞf
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLDnuKInjrhuocy4bieMnbhuJ5mIiwiIiwiIl0=) Outputs (theoretically) infinitely but crashes due to hitting the recursion limit caused by a bug.
```
Þ∞         # All positive integers
   ẇ       # Cut into slices of lengths...
Þ∞:        # Positive integers
    2Ḟ     # Get every second item
      2vḞ  # Get every second item of each
         f # Flatten the final array
```
[Answer]
# [JavaScript (V8)](https://v8.dev/), 40 bytes
Prints the sequence forever.
```
for(n=i=q=1;;n+=--i?2:q+(i=++q))print(n)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/Py2/SCPPNtO20NbQ2jpP21ZXN9PeyKpQWyPTVlu7UFOzoCgzr0QjT/P/fwA "JavaScript (V8) – Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 34 bytes
```
[ 2 * dup √ .5 - 1 /i sq + 1 - ]
```
[Try it online!](https://tio.run/##LYqxDcIwFAX7TPFqIIZEooEBEA0NoopSGOcHLMi3Y38XbMAMjMciJgKa0510vTbiQj4d94fdBjcKTHcMWq5fqD6xEes4/jJovtDfE1vjOoIPJPLwwbIg0piIzbRsi6JeoakW57bIDWrM0CWP9/MFtUaJCkuLOGI@WYk2D9pD5Q8 "Factor – Try It Online")
Outputs the 1-indexed nth term of the sequence. Port of loopy walt's and att's [Python answer](https://codegolf.stackexchange.com/a/253320/97916).
```
word  | data stack              | comment
------+-------------------------+-----------------
      | 5                       | example input
2     | 5 2                     |
*     | 10                      |
dup   | 10 10                   |
√     | 10 3.16227766016838     | square root
.5    | 10 3.16227766016838 0.5 |
-     | 10 2.66227766016838     |
1     | 10 2.66227766016838 1   |
/i    | 10 2                    | integer divide
sq    | 10 4                    | square
+     | 14                      |
1     | 14 1                    |
-     | 13                      | output
```
[Answer]
# [sclin](https://github.com/molarmanful/sclin), 32 bytes
```
; ; tk2* ;2^2* ;3* - + flat
$W1+
```
[Try it here!](https://replit.com/@molarmanful/try-sclin) Returns an infinite list. This code is so weird...
For testing purposes (use `-i` flag when running locally):
```
; 50tk >A
; ; tk2* ;2^2* ;3* - + flat
$W1+
```
## Explanation
Prettified code:
```
; ; tk 2* ; 2^ 2* ; 3* - + flat
$W 1+
```
`;` means "evaluate the next line as a function."
* `$W 1+` [1, ∞) as *n*
* `; ; tk 2*` `[[2][2 4][2 4 6][2 4 6 8]...]` as *k*\*2
	+ this works because `tk` ("take") vectorizes the second argument
* `; 2^ 2* ; 3* - +` *n*^2\*2 - *n*\*3 + *k*\*2
	+ this whole segment is vectorized
* `flat` flatten
It's vectorizations all the way down!
---
# [sclin](https://github.com/molarmanful/sclin), 19 bytes
```
2*""Q.5^.5- I2^ +1-
```
[Try it here!](https://replit.com/@molarmanful/try-sclin) Port of @loopywalt/@att's answer. Takes a 1-based index, but the whole function vectorizes quite neatly too.
For testing purposes (use `-i` flag when running locally):
```
$W1+ ; 50tk >A
2*""Q.5^.5- I2^ +1-
```
[Answer]
# [R](https://www.r-project.org/), 55 bytes
```
function(n,`?`=rbind)diffinv(rep(1:n*2+1?2,1?1:n))[n]+1
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPJ8E@wbYoKTMvRTMlMy0tM69Moyi1QMPQKk/LSNvQ3kjH0B7I1tSMzovVNvxfnFhQkFMJlDU00EnT/A8A "R – Try It Online")
Returns the 1-based nth term.
[Answer]
# [Raku](https://raku.org/), 31 bytes
```
[\+] flat (1,3...*)Z(2 Xxx^∞)
```
[Try it online!](https://tio.run/##K0gtyjH7n1up4FCcWqhg@z86RjtWIS0nsURBw1DHWE9PT0szSsNIIaKiIu5RxzzN/9YKxYkQxdFxhgYGsf8B "Perl 6 – Try It Online")
This is an expression for the lazy infinite sequence of numbers.
* `(1, 3 ... *)` is the infinite sequence of odd numbers.
* `xx` is the replication operator, which replicates its left-hand side a number of times given by its right-hand side.
* `X` is the cross-product metaoperator. Applied to the replication operator `xx`, it makes a new operator that replicates as a cross product.
* `^∞` is the unbounded range of increasing integers starting at zero.
* `2 Xxx ^∞` produces a list of 2 replicated each number of times from zero to infinity: `(), (2,), (2, 2), (2, 2, 2), ...`.
* `Z` zips the odd numbers with the list of increasing numbers of twos: `(1, ()), (3, (2,)), (5, (2, 2)), (7, (2, 2, 2)), ...`.
* `flat` flattens that list: `1, 3, 2, 5, 2, 2, 7, 2, 2, 2, ...`. That gives the list of differences between adjacent terms of the sequence.
* `[\+]` gives the list of partial sums of the previous sequence, which is the desired polka-dot sequence.
[Answer]
# [R](https://www.r-project.org/), 37 bytes
```
function(x)(((8*x)^.5-1)%/%2)^2+2*x-1
```
[Try it online!](https://tio.run/##K/pfkJ@TnZiSX2L7P600L7kkMz9Po0JTQ0PDQqtCM07PVNdQU1Vf1UgzzkjbSKtC1xCuXsPQyshU8z8A "R – Try It Online")
An alternative to [Giuseppe's R answer](https://codegolf.stackexchange.com/a/253355/95126), here using a variant of [loopy walt's approach](https://codegolf.stackexchange.com/a/253320/95126).
[Answer]
# Excel, 27 bytes
```
=INT((2*A1)^.5-.5)^2+2*A1-1
```
Direct implementation of [loopy walt's answer in Python](https://codegolf.stackexchange.com/a/253320/38183) except it's shorter in Excel. Given the 1-based index computes a single value. Input is in `A1`. When copying the above into Excel, it will automatically add leading zeroes to change `.5` to `0.5`.
[![Screenshot](https://i.stack.imgur.com/oOpcY.png)](https://i.stack.imgur.com/oOpcY.png)
---
This **41 byte** solution prints the first 1,048,576 terms (or however many rows you have in your version of Excel):
```
=LET(r,ROW(A:A),INT((2*r)^.5-.5)^2+2*r-1)
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 12 bytes
```
Þ∞:ɾ•y_ƛy$;f
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyI1IiwiIiwiw57iiJ46yb7igKJ5X8abeSQ7ZiIsIiIsIiJd)
Outputs the sequence forever.
## Explained
```
Þ∞:ɾ•y_ƛy$;f
Þ∞:          # Push two copies of an infinite list of positive integers
   ɾ         # In the second copy of the infinite list, push range [1, n] for each item
    •        # And mold the first copy of the infinite list to the shape of the second
     y_      # uninterleave the infinite list, giving two lists: the list of every second row starting at row 0, and the list of every second row starting at row 1. Discard the list starting at row 1.
       ƛy$;f # To each row in the remaining list, uninterleave the row, and return the list of every second item starting at index 0. Then flatten the result.
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 22 bytes
```
ＮθＦθＦ⊕ι⊞υ×ιιＩＥ…υθ⊕⁺ι⊗κ
```
[Try it online!](https://tio.run/##TUw7DgIhFOz3FK98JFhaUWKzhWYLL8DiMxD5LR8TT49I5TTzycxoo7KOyvW@htTqrfmdMh5MLM@YYQiYvAadyVOo9EDLGGytGGwc7tZTQcthhGLZsg0VpSoVryqh/GhH0sT0ax6Mw//L5tocXmLb3fAvNiF6P/fT230B "Charcoal – Try It Online") Link is to verbose version of code. Outputs the first `n` terms of the sequence. Explanation: Port of @JonathanAllan's Jelly answer.
```
Ｎθ
```
Input `n`.
```
ＦθＦ⊕ι⊞υ×ιι
```
Create an array containing each of the squares `0`, `1`, `4`, `9`, ... `i²`, ... each repeated `i+1` times.
```
ＩＥ…υθ⊕⁺ι⊗κ
```
Take the first `n` elements of the array, and add to each the incremented doubled index (0-indexed).
20 bytes using the newer version of Charcoal on ATO:
```
ＮθＩＥ…ΣＥθＥ⊕ι×ιιθ⊕⁺ι⊗κ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iOSOxKDk_MWfBgqWlJWm6FjcbPPMKSkv8SnOTUos0CjWtuQKKMvNKNJwTi0s0fBMLNJwrk3NSnTPyCzSCS3PBIoU6CiDKMy-5KDU3Na8kNUUjU1NHISQzN7VYI1NHIVMTCHQUCoEYWU1ATilY2iW_NCkHyM_WBAPrJcVJycVQ1yyPVtIty1GKXWgK4QMA "Attempt This Online") Link is to verbose version of code. Outputs the first `n` terms of the sequence. Explanation:
```
Ｎθ                      Input `n` as a number
       θ                Input `n`
      Ｅ                 Map over implicit range
          ι             Current value
         ⊕              Incremented
        Ｅ               Map over implicit range
            ι           Outer value
           ×            Multiplied by
             ι          Outer value
     Σ                  Concatenated
    …                   Truncated to length
              θ         Input `n`
   Ｅ                    Map over squares
                 ι      Current square
                ⁺       Plus
                   κ    Current index
                  ⊗     Doubled
               ⊕        Incremented
  Ｉ                     Cast to string
                        Implicitly print
```
[Answer]
# [Desmos](https://desmos.com/calculator), 31 bytes
```
f(n)=floor(\sqrt{2n}-.5)^2+2n-1
```
Literally just a port of loopy walt's python answer, go upvote that answer too!
[Try It On Desmos!](https://www.desmos.com/calculator/zyoxm5ji9g)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/5xvg9olfby)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~9~~ 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
-1 byte by porting [@corvus\_192's Rust answer](https://codegolf.stackexchange.com/a/253353/52210), which is a slightly modified version of [@loopyWalt's Python answer](https://codegolf.stackexchange.com/a/253320/52210), so make sure to upvote them as well!
Given \$n\$, it'll output the 1-based \$n^{th}\$ term (**8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**):
```
·Dtò<n+<
```
[Try it online](https://tio.run/##yy9OTMpM/f//0HaXksObbPK0bf7/NwUA) or [verify the first 25 items](https://tio.run/##yy9OTMpM/W9k6upnr6TwqG2SgpK93/9D211KDm@yydO2@a/zHwA).
Given no input, it'll output the infinite sequence list (**9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**):
```
∞£ιнειн}˜
```
[Try it online.](https://tio.run/##yy9OTMpM/f//Uce8Q4vP7byw99xWEFl7es7//wA)
**Explanation:**
```
·         # Double the (implicit) input-integer
 D        # Duplicate it
  t       # Take the square-root of the copy
   ò      # Round it to the nearest integer
    <     # Decrease it by 1
     n    # Square it
      +   # Add it to the doubled input that's still on the stack
       <  # Decrease it by 1
          # (after which it is output implicitly as result)
```
```
∞         # Push a positive infinite list: [1,2,3,4,5,...]
 £        # Split it into parts of itself (since there is no input):
          #  [[1],[2,3],[4,5,6],[7,8,9,10],[11,12,13,14,15],...]
  ι       # Uninterleave it into two parts
   н      # Pop and only keep the first
    ε  }  # Map over each remaining inner list:
     ιн   #  Do the same for those
        ˜ # Flatten the list of lists
          # (after which the infinite list is output implicitly as result)
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 8 bytes
```
d:√ṙ‹²+‹
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIyNcabIiwiZDriiJrhuZnigLnCsivigLkiLCIiLCIiXQ==)
Port of 05AB1E, which is a port of Rust, so make sure to upvote those answers!
[Answer]
# [C (GCC)](https://gcc.gnu.org), ~~68~~ 65 bytes
*-2 bytes thanks to [@Sʨɠɠan](https://codegolf.stackexchange.com/users/92689/s%ca%a8%c9%a0%c9%a0an)*
```
i;r;main(s){for(;i<=r||(i=0,s+=++r+ ++r);i+=2)printf("%d ",s+i);}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700OT49OXnBgqWlJWm6FjcdM62LrHMTM_M0ijWr0_KLNKwzbWyLamo0Mm0NdIq1bbW1i7QVgISmdaa2rZFmQVFmXkmahpJqioISUDpT07oWYhDUPJi5AA)
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 24 bytes
```
((RTDBa-0.5)//1)E2+DBa-1
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCIoKFJUREJhLTAuNSkvLzEpRTIrREJhLTEiLCIiLCIiLCIxMCJd)
Port of loopy walt's Python answer, so go upvote his answer too!
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 39 bytes
Prints the infinite sequence.
```
130>$:2+@$:1+@v
2$-1v!?:$oan:{<}+
~+}v>
```
[Try it online!](https://tio.run/##S8sszvj/39DYwE7FykjbQcXKUNuhjMtIRdewTNHeSiU/Mc@q2qZWm6tOu7bM7v9/AA "><> – Try It Online")
# [><>](https://esolangs.org/wiki/Fish), 38 bytes
Prints the nth term 1-indexed.
```
:8*$2*1v
}(?!v1+>::*{:
+1-n>2-2,:1%-:*
```
[Try it online!](https://tio.run/##S8sszvj/38pCS8VIy7CMq1bDXrHMUNvOykqr2opL21A3z85I10jHylBV10rr////umWGZgA "><> – Try It Online")
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 10 bytes
```
2*Đ√½-Ɩ²+⁻
```
[Try it online!](https://tio.run/##ARsA5P9weXT//zIqxJDiiJrCvS3GlsKyK@KBu///MTA "Pyt – Try It Online")
```
              implicit input
2*            double
  Đ           duplicate on the stack
   √          take the square root of top
    ½-        subtract 1/2
      Ɩ²      cast to an integer and square
        +     add the stack
         ⁻    decrement
              implicit output
```
Port of [loopy walt's Python answer](https://codegolf.stackexchange.com/a/253320/52210)
If floating-point returns are allowed, then 9 bytes is possible:
```
2*Đ√⎶⁻²+⁻
```
[Try it online!](https://tio.run/##K6gs@f/fSOvIhEcdsx71bXvUuPvQJm0g@f@/oQEA "Pyt – Try It Online")
Port of [corvus\_192's Rust answer](https://codegolf.stackexchange.com/questions/253309/triangular-polkadot-numbers/253353#253353)
]