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

added 939 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, (削除) 32 (削除ここまで) 31 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪṪƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Explanation

ḷ‘ɼ | Increment the register, then revert to the original left argument (i.e. b)
 _ | b - a
 ’ | Subtract 1
 ;N} | Concatenate to -a
 ;1 | Concatenate to 1
 Ær | Roots of polynomial with terms (b - a - 1, -a, 1)
 ÆiṪṪƊ? | Does the last root havecan imaginary component?
 \/} , | - If yes, do the following using the original arguments to this link:
 1⁄2ßH} | - Call the current link recursively with the square root of the left argument and half the right argument
 x®$ | - If not, repeat each term the number of times indicated by the register
 ḟ0 | Filter out zeros

Jelly, (削除) 32 (削除ここまで) 31 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪṪƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Jelly, (削除) 32 (削除ここまで) 31 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪṪƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Explanation

ḷ‘ɼ | Increment the register, then revert to the original left argument (i.e. b)
 _ | b - a
 ’ | Subtract 1
 ;N} | Concatenate to -a
 ;1 | Concatenate to 1
 Ær | Roots of polynomial with terms (b - a - 1, -a, 1)
 ÆiṪṪƊ? | Does the last root havecan imaginary component?
 \/} , | - If yes, do the following using the original arguments to this link:
 1⁄2ßH} | - Call the current link recursively with the square root of the left argument and half the right argument
 x®$ | - If not, repeat each term the number of times indicated by the register
 ḟ0 | Filter out zeros
added 3 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, 32(削除) 32 (削除ここまで) 31 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪ€ẸƊx®$ÆiṪṪƊ?,ḟ0

Try it online! Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Jelly, 32 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪ€ẸƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Jelly, (削除) 32 (削除ここまで) 31 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪṪƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, 32 bytes

ḷ‘ɼ_’;N};1Ær1⁄2ßH}\/}x®$ÆiṪ€ẸƊ?,ḟ0

Try it online!

A full program taking two arguments, b and a in that order. Implements @xnor’s algorithm, so be sure to upvote that one too! Uses recursion to find real roots to a quadratic equation of the form \$x^2 - w x + (y - w - 1) = 0\$ where \$w = \frac{a}{2 ^ n}\$ and \$y = b ^ \frac{1}{2n} \$ for some non-negative integer \$n\$.

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