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 1039 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

Formula:

$$ (f,d,b) = (d(f-1) \mod{(b-1)}+1)\times\left\lfloor\frac{b^{\left\lfloor\dfrac{d(f-1)}{b-1}\right\rfloor+1}}{b-(b>f)(b>2)}\right\rfloor $$(d*(f-1)%(b-1)+1)*((b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2)))

< # Decrease the first (implicit) input `f` by 1
 # STACK: f-1
 * # Multiply it to the second (implicit) input `d`
 # STACK: d*(f-1)
 ‰ # Divmod it by:
 I< # Thethe third input `b` minus 1
 # STACK: [d*(f-1)//(b-1), d*(f-1)%(b-1)]
 > # Increase both values in the pair by 1 (let's call them [A,B])
 # STACK: [d*(f-1)//(b-1)+1, d*(f-1)%(b-1)+1]
 ` # Pop and push them separated to the stack
 # STACK: d*(f-1)//(b-1)+1, d*(f-1)%(b-1)+1
 Š # Tripleswap the stack from {A,B}using tothe {B,(implicit) third input `b`
 # STACK: d*(f-1)%(b-1)+1,A} b, d*(f-1)//(b-1)+1
 m # Take `b` to the power `A`
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1)
 I # Push the third input `b` again
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b
 D # And again
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, b
 12‚ # Push pair [f,2]
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, b, [f,2]
  › # Pop the copy of `b`, and check [b>f, b>2]
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, [b>f,b>2]
 P # Check if both are truthy by taking the product
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, (b>f)*(b>2)
 - # Decrease the other `b` by this 0 or 1
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b-(b>f)*(b>2)
 ÷ # Integer-divide `b to the power A` by this
 # STACK: d*(f-1)%(b-1)+1, (b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2))
  * # Multiply it to `B`
 # STACK: (d*(f-1)%(b-1)+1)*((b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2)))
 # (after which the result is output implicitly)

Formula:

$$ (f,d,b) = (d(f-1) \mod{(b-1)}+1)\times\left\lfloor\frac{b^{\left\lfloor\dfrac{d(f-1)}{b-1}\right\rfloor+1}}{b-(b>f)(b>2)}\right\rfloor $$

< # Decrease the first (implicit) input `f` by 1
 * # Multiply it to the second (implicit) input `d`
 ‰ # Divmod it by:
 I< # The third input `b` minus 1
 > # Increase both values in the pair by 1 (let's call them [A,B])
 ` # Pop and push them separated to the stack
 Š # Tripleswap the stack from {A,B} to {B,(implicit) third input `b`,A}
 m # Take `b` to the power `A`
 I # Push the third input `b` again
 D # And again
 12‚ # Push pair [f,2]
 › # Pop the copy of `b`, and check [b>f, b>2]
 P # Check if both are truthy by taking the product
 - # Decrease the other `b` by this 0 or 1
 ÷ # Integer-divide `b to the power A` by this
 * # Multiply it to `B`
 # (after which the result is output implicitly)

Formula:(d*(f-1)%(b-1)+1)*((b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2)))

< # Decrease the first (implicit) input `f` by 1
 # STACK: f-1
 * # Multiply it to the second (implicit) input `d`
 # STACK: d*(f-1)
 ‰ # Divmod it by
 I< # the third input `b` minus 1
 # STACK: [d*(f-1)//(b-1), d*(f-1)%(b-1)]
 > # Increase both values in the pair by 1 (let's call them [A,B])
 # STACK: [d*(f-1)//(b-1)+1, d*(f-1)%(b-1)+1]
 ` # Pop and push them separated to the stack
 # STACK: d*(f-1)//(b-1)+1, d*(f-1)%(b-1)+1
 Š # Tripleswap the stack using the implicit third input `b`
 # STACK: d*(f-1)%(b-1)+1, b, d*(f-1)//(b-1)+1
 m # Take `b` to the power `A`
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1)
 I # Push the third input `b` again
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b
 D # And again
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, b
 12‚ # Push pair [f,2]
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, b, [f,2]
  › # Pop the copy of `b`, and check [b>f, b>2]
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, [b>f,b>2]
 P # Check if both are truthy by taking the product
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b, (b>f)*(b>2)
 - # Decrease the other `b` by this 0 or 1
 # STACK: d*(f-1)%(b-1)+1, b**(d*(f-1)//(b-1)+1), b-(b>f)*(b>2)
 ÷ # Integer-divide `b to the power A` by this
 # STACK: d*(f-1)%(b-1)+1, (b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2))
  * # Multiply it to `B`
 # STACK: (d*(f-1)%(b-1)+1)*((b**(d*(f-1)//(b-1)+1))//(b-(b>f)*(b>2)))
 # (after which the result is output implicitly)
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

05AB1E, 19 bytes

<*I<‰>`ŠmID12‚›P-÷*

Inputs in the order \$f,d,b\$.

Port of @Neil's Charcoal answer, so make sure to upvote him as well!

Try it online or verify all test cases.

Explanation:

Formula:

$$ (f,d,b) = (d(f-1) \mod{(b-1)}+1)\times\left\lfloor\frac{b^{\left\lfloor\dfrac{d(f-1)}{b-1}\right\rfloor+1}}{b-(b>f)(b>2)}\right\rfloor $$

< # Decrease the first (implicit) input `f` by 1
 * # Multiply it to the second (implicit) input `d`
 ‰ # Divmod it by:
 I< # The third input `b` minus 1
 > # Increase both values in the pair by 1 (let's call them [A,B])
 ` # Pop and push them separated to the stack
 Š # Tripleswap the stack from {A,B} to {B,(implicit) third input `b`,A}
 m # Take `b` to the power `A`
 I # Push the third input `b` again
 D # And again
 12‚ # Push pair [f,2]
 › # Pop the copy of `b`, and check [b>f, b>2]
 P # Check if both are truthy by taking the product
 - # Decrease the other `b` by this 0 or 1
 ÷ # Integer-divide `b to the power A` by this
 * # Multiply it to `B`
 # (after which the result is output implicitly)

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