Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Saved a byte thanks to @H.PWiz.
Source Link
user48543
user48543

Husk, (削除) 11 (削除ここまで) 9(削除) 9 (削除ここまで) 8 bytes

ΘṁṠe→ΘmΣNΘṁṠe→Θ∫N

OutputsSaved a byte thanks to H.PWiz.
Outputs as an infinite list.
Try it online! Try it online!

Explanation

ΘṁṠe→ΘmΣNΘṁṠe→Θ∫N
 N ∫N StartCumulative withsum theof natural numbers.
  mΣ Get the (triangular numbers).
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Alternatively, we could use ΘṁoṠe→ΣΘN, which avoids the second map but isn't any shorter.

Husk, (削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmΣN
 N  Start with the natural numbers.
  mΣ Get the triangular numbers.
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Alternatively, we could use ΘṁoṠe→ΣΘN, which avoids the second map but isn't any shorter.

Husk, (削除) 11 (削除ここまで) (削除) 9 (削除ここまで) 8 bytes

ΘṁṠe→Θ∫N

Saved a byte thanks to H.PWiz.
Outputs as an infinite list.
Try it online!

Explanation

ΘṁṠe→Θ∫N
 ∫N Cumulative sum of natural numbers (triangular numbers).
 Θ Prepend 0.
 ṁṠe→ Concatenate [n + 1, n] for each.
Θ Prepend 0.
Added alternate solution.
Source Link
user48543
user48543

Husk, (削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmΣN
 N Start with the natural numbers.
 mΣ Get the triangular numbers.
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Alternatively, we could use ΘṁoṠe→ΣΘN, which avoids the second map but isn't any shorter.

Husk, (削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmΣN
 N Start with the natural numbers.
 mΣ Get the triangular numbers.
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Husk, (削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmΣN
 N Start with the natural numbers.
 mΣ Get the triangular numbers.
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Alternatively, we could use ΘṁoṠe→ΣΘN, which avoids the second map but isn't any shorter.

There's a builtin for traingular numbers.
Source Link
user48543
user48543

Husk, 11(削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmoΣḣNΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online! Try it online!

ΘṁṠe→ΘmoΣḣNΘṁṠe→ΘmΣN
 N N Start with the natural numbers.
 ḣ Get all the prefixes.
   moΣ Get the sum of each (the triangular numbers).
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Husk, 11 bytes

ΘṁṠe→ΘmoΣḣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmoΣḣN
 N Start with the natural numbers.
 ḣ Get all the prefixes.
  moΣ Get the sum of each (the triangular numbers).
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.

Husk, (削除) 11 (削除ここまで) 9 bytes

ΘṁṠe→ΘmΣN

Outputs as an infinite list.
Try it online!

ΘṁṠe→ΘmΣN
 N Start with the natural numbers.
  Get the triangular numbers.
 Θ Prepend 0.
 ṁṠe→ Concatenate the pairs [n + 1, n] for each element.
Θ Prepend 0.
Source Link
user48543
user48543
Loading

AltStyle によって変換されたページ (->オリジナル) /