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

Commonmark migration
Source Link

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$ -- and this is why we chose an interval bounded by a power of \2ドル\$ in the first place.

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$ -- and this is why we chose an interval bounded by a power of \2ドル\$ in the first place.

JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$ -- and this is why we chose an interval bounded by a power of \2ドル\$ in the first place.

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

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, this is not how the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with\2ドル\$ -- and this is why we chose an interval bounded by a power of \2ドル\$ in the first place.

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, this is not how the formula is implemented in the JS code.

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$.

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with\2ドル\$ -- and this is why we chose an interval bounded by a power of \2ドル\$ in the first place.

added an explanation
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$$$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$$$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, this is not how the formula is implemented in the JS code.

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$.

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

#JavaScript (ES6), (削除) 41 40 (削除ここまで) 39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

###How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$$$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$$$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, this is not how the formula is implemented in the JS code.

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \2ドル\$.

saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Rollback to Revision 1
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

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