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

LaTeXify formula
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth triangular number, we have

condition$$ n = \frac{k(k+1)}{2} \iff k^2+k-2n = 0 \iff k = \frac12 (-1 \pm \sqrt{1+8n}), $$

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is not required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth triangular number, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is not required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth triangular number, we have

$$ n = \frac{k(k+1)}{2} \iff k^2+k-2n = 0 \iff k = \frac12 (-1 \pm \sqrt{1+8n}), $$

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is not required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.
added 18 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth triangular number, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is oddnot required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is odd required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth triangular number, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is not required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.
edited body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth, we have

conditioncondition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is odd required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is odd required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.

Jelly, 5 bytes

×ばつ8‘Æ2

Try it online!

Background

Let n be the input. If n is the kth, we have

condition

which means there will be a natural solution if and only if 1 + 8n is an odd, perfect square. Clearly, checking the parity of 1 + 8n is odd required.

How it works

×ばつ8‘Æ2 Main link. Argument: n×ばつ8 Yield 8n.
 ‘ Increment, yielding 8n + 1.
 Æ2 Test if the result is a perfect square.
added 327 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading

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