Skip to main content
added 4 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly, 15 bytes

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ               - double -> 2i
     €          - for each (x in [1..2i]):
    Ɗ           -   last three links as a monad, f(x):
 ½              -     square root (x) -> r
  Ḷ             -     lowered range -> [0,1,2,3,4,...,floor(r)-1]
   o            -     logical OR -> [x,1,2,3,4,...,floor(r)-1]
      Ḋ         - dequeue (drops the leading [1] from that list of lists)
       Ż        - prepend a zero
        Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
         S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
           Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
            F   - flatten
             T  - truthy indices (1-indexed)
              ḣ - head to index (i)

Jelly, 15 bytes

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ               - double -> 2i
     €          - for each (x in [1..2i]):
    Ɗ           -   last three links as a monad, f(x):
 ½              -     square root -> r
  Ḷ             -     lowered range -> [0,1,2,3,4,...,floor(r)-1]
   o            -     logical OR -> [x,1,2,3,4,...,floor(r)-1]
      Ḋ         - dequeue (drops the leading [1] from that list of lists)
       Ż        - prepend a zero
        Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
         S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
           Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
            F   - flatten
             T  - truthy indices (1-indexed)
              ḣ - head to index (i)

Jelly, 15 bytes

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ               - double -> 2i
     €          - for each (x in [1..2i]):
    Ɗ           -   last three links as a monad, f(x):
 ½              -     square root (x) -> r
  Ḷ             -     lowered range -> [0,1,2,3,4,...,floor(r)-1]
   o            -     logical OR -> [x,1,2,3,4,...,floor(r)-1]
      Ḋ         - dequeue (drops the leading [1] from that list of lists)
       Ż        - prepend a zero
        Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
         S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
           Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
            F   - flatten
             T  - truthy indices (1-indexed)
              ḣ - head to index (i)
deleted 20 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly, 1615 bytes

ḤƽḶoƊ€ḊŻĖS€ḂFTḣḤ½ḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!Try it online!

How?

ḤƽḶoƊ€ḊŻĖS€ḂFTḣḤ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ                - double -> 2i
      €          - for each (x in [1..2i]):
     Ɗ           -   last three links as a monad, f(x):
 ƽ½              -     floored square root -> r
   Ḷ             -     lowered range -> [0,1,2,3,4,...,floor(r)-1]
    o            -     logical OR -> [x,1,2,3,4,...,floor(r)-1]
       Ḋ         - dequeue (drops the leading [1] from that list of lists)
        Ż        - prepend a zero
         Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
          S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
            Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
             F   - flatten
              T  - truthy indices (1-indexed)
               ḣ - head to index (i)

Jelly, 16 bytes

ḤƽḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

ḤƽḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ                - double -> 2i
      €          - for each (x in [1..2i]):
     Ɗ           -   last three links as a monad, f(x):
 ƽ              -     floored square root -> r
   Ḷ             -     lowered range -> [0,1,2,3,4,...,r-1]
    o            -     logical OR -> [x,1,2,3,4,...,r-1]
       Ḋ         - dequeue (drops the leading [1] from that list of lists)
        Ż        - prepend a zero
         Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
          S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
            Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
             F   - flatten
              T  - truthy indices (1-indexed)
               ḣ - head to index (i)

Jelly, 15 bytes

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ               - double -> 2i
     €          - for each (x in [1..2i]):
    Ɗ           -   last three links as a monad, f(x):
 ½              -     square root -> r
  Ḷ             -     lowered range -> [0,1,2,3,4,...,floor(r)-1]
   o            -     logical OR -> [x,1,2,3,4,...,floor(r)-1]
      Ḋ         - dequeue (drops the leading [1] from that list of lists)
       Ż        - prepend a zero
        Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
         S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
           Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
            F   - flatten
             T  - truthy indices (1-indexed)
              ḣ - head to index (i)
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly, 16 bytes

ḤƽḶoƊ€ḊŻĖS€ḂFTḣ

A monadic Link accepting \$i\$ which yields a list of the first \$i\$ terms.

Try it online!

How?

ḤƽḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i
Ḥ                - double -> 2i
      €          - for each (x in [1..2i]):
     Ɗ           -   last three links as a monad, f(x):
 ƽ              -     floored square root -> r
   Ḷ             -     lowered range -> [0,1,2,3,4,...,r-1]
    o            -     logical OR -> [x,1,2,3,4,...,r-1]
       Ḋ         - dequeue (drops the leading [1] from that list of lists)
        Ż        - prepend a zero
         Ė       - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...]
          S€     - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...]
            Ḃ    - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...]
             F   - flatten
              T  - truthy indices (1-indexed)
               ḣ - head to index (i)