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 some comments about the Bigint version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!


JavaScript (ES11), 50 bytes

An alternate version taking Bigints as input.

We have to use a ternary operator because we can't add a Boolean to a Bigint. This is however an opportunity to invert the sign of the division which allows to save one byte on the multiplication by just using ~. And more importantly, we don't have to round the result of the division anymore.

(d,f,b)=>b**-~(d*--f/--b)/(b>f&b>1?-b:~b)*~(d*f%b)

Try it online!

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!


JavaScript (ES11), 50 bytes

An alternate version taking Bigints as input.

(d,f,b)=>b**-~(d*--f/--b)/(b>f&b>1?-b:~b)*~(d*f%b)

Try it online!

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!


JavaScript (ES11), 50 bytes

An alternate version taking Bigints as input.

We have to use a ternary operator because we can't add a Boolean to a Bigint. This is however an opportunity to invert the sign of the division which allows to save one byte on the multiplication by just using ~. And more importantly, we don't have to round the result of the division anymore.

(d,f,b)=>b**-~(d*--f/--b)/(b>f&b>1?-b:~b)*~(d*f%b)

Try it online!

added a shorter version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online! Try it online!


JavaScript (ES11), 50 bytes

An alternate version taking Bigints as input.

(d,f,b)=>b**-~(d*--f/--b)/(b>f&b>1?-b:~b)*~(d*f%b)

Try it online!

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!


JavaScript (ES11), 50 bytes

An alternate version taking Bigints as input.

(d,f,b)=>b**-~(d*--f/--b)/(b>f&b>1?-b:~b)*~(d*f%b)

Try it online!

Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7), 54 bytes

A port of loopy walt's xnor-optimized answer.

(d,f,b)=>~~(b**-~(d*--f/--b)/(b+(b<=f|b<2)))*(d*f%b+1)

Try it online!

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