# It's Just Rocket Science, Part 2 - Centrifuge

You've gotten out of Earth's gravity well - good for you! However, you're feeling a bit uncomfortable in zero-gravity, and you want to replicate 1 $$\g\$$ of force in a centrifuge. Use the equation for force in a centrifuge: $$\text{RCF} = \frac{r_\text{m} \, \left(\frac{2 \pi N_\text{RPM}}{60}\right)^2}{g}$$ Where

• $$\\text{RCF}\$$ is "relative centrifugal force", or the force relative to 1 $$\g\$$; in this case we want this to be $$\1\$$.
• $$\r_\text{m}\$$ is the radius of the centrifuge in meters. You can take this, or a similar quantity - for example, taking it in millimeters.
• $$\N_\text{RPM}\$$ is the rotational speed in revolutions per minute. You're going to output this.
• $$\g\$$ is the local gravitational field of Earth - for this challenge, use the standard value of $$\9.80665\;\text{m}/\text{s}^2\$$.

In alternate form, when $$\\text{RCF} = 1\$$: $$N_\text{RPM} = \dfrac{60\sqrt{\dfrac{g}{r_\text{m}}}}{2\pi}.$$

To clarify: take the radius of the centrifuge, output rotational speed in RPMs, with precision to 6 significant digits. Scoring is standard for . Test cases (calculated using SpinCalc):

1 -> 29.904167719726267
10 -> 9.456528152601877
50 -> 4.229087956071661
87 -> 3.206063305621029
100 -> 2.9904167719726273
103 -> 2.946545199338184
167 -> 2.314053973112157
200 -> 2.1145439780358304
224 -> 1.9980562507828685
250 -> 1.8913056305203755
264 -> 1.8404742955585696
300 -> 1.726517928287568
328 -> 1.651181438643768
400 -> 1.4952083859863137
409 -> 1.4786659280153986
1000 -> 0.9456528152601877
2000 -> 0.6686775183186282
10000 -> 0.2990416771972627

• Sandbox (deleted) Oct 5, 2022 at 12:45
• How accurate is Pi? Oct 5, 2022 at 13:24
• @MehanAlavi doesn't matter, as long as your final answer is accurate to 6 sigfigs Oct 5, 2022 at 14:13

# Python, 24 bytes

lambda r:29.904167/r**.5


## Explanation

The expression we're trying to calculate is

$$N_\text{RPM} = \dfrac{60\sqrt{\dfrac{g}{r_\text{m}}}}{2\pi}.$$

If we rearrange terms, we can turn this into

$$N_\text{RPM} = \dfrac{60\dfrac{\sqrt{g}}{\sqrt{r_\text{m}}}}{2\pi} = \dfrac{60\sqrt{g}}{2\pi\sqrt{r_\text{m}}} = (\dfrac{60\sqrt{g}}{2\pi})\frac{1}{\sqrt{r_\text{m}}}$$

Since we know $$\g = 9.80665\$$ (it's constant), we can calculate the value of the $$\(\dfrac{60\sqrt{g}}{2\pi})\$$ term, getting approximately $$\29.904167\$$. In other words,

$$N_\text{RPM} \approx 29.904167\frac{1}{\sqrt{r_\text{m}}}$$

• I guess the link is broken. Oct 5, 2022 at 14:40
• @MehanAlavi The link works for me? Oct 5, 2022 at 14:41
• Yeah it is fixed now. I dont know why it wasn't working. BTW, I dont really understand your awnser, Can you please explain it? Thanks :) Oct 5, 2022 at 14:46
• @MehanAlavi Is this explanation good? Oct 5, 2022 at 14:53
• Yeah thank you. What a creative mind you have got :) Oct 5, 2022 at 15:25

## Python, 535241 39 bytes

lambda a:30*(9.80665/a)**0.5/3.14519265


Try it online!

• -2 bytes thanks to The Thonnu
• Welcome to Code Golf! Oct 5, 2022 at 14:10
• I think you can remove the x= and just put x=\ in the header code, saving you 2 bytes. Oct 7, 2022 at 12:38

# Jelly, 1615 13 bytes

8825.985÷½÷ØP


Attempt This Online!

This is my first Jelly answer, so it can almost certainly be golfed.

• -1 byte thanks to MehanAlavi
• instead of 1/2*60 Write 30. Saved 3 bytes Oct 5, 2022 at 13:39
• can you explain what ÷ØP does? Thanks! Oct 10, 2022 at 9:09
• @DialFrost ÷ is division and ØP gets pi (the constant). So ÷ØP means "divide by pi". Oct 10, 2022 at 11:08

# Go, 64 bytes

import."math"
func f(r float64)float64{return 29.904167/Sqrt(r)}


Attempt This Online!

# Raku, 16 bytes

29.904167/*.sqrt


Try it online!

I searched in vain for some short combination of Unicode characters whose numerical values could be combined in some way to get a number very close to the constant factor here. Oh well!

# Factor, 21 bytes

[ -.5 ^ 29.904167 * ]


Try it online!

# Vyxal, 13 bytes

29.9041677?√/


Try it Online!

• You might be able to save a few bytes by a) losing precision b) Replacing the constant with (something close to) its reciprocal and swapping it with the sqrt Oct 10, 2022 at 18:38

# x86 32-bit machine code, 16 bytes

68 98 90 5F 44 D9 04 24 D8 74 24 08 D9 FA 58 C3


Try it online!

Following the cdecl calling convention, this takes $$\r_{\mathrm{m}}\$$ on the stack and returns $$\N_{\mathrm{RPM}}\$$ on the FPU register stack.

In assembly:

f:  .byte 0x68                  # Push a 4-byte value onto the stack:
.single 894.259247009518535 #  this value, which equals (60/2π)²·g.
fld DWORD PTR [esp]         # Put that value onto the FPU register stack.
fdiv DWORD PTR [esp + 8]    # Divide it by the value given.
fsqrt                       # Take the square root.
pop eax                     # Pop the value added to the stack.
ret                         # Return.


# K (ngn/k), 13 bytes

29.9041677%%:


Try it online!

Dead simple. Doesn't display correctly with all numbers correct up to all precision, but that isn't a requirement anyway.

Explanation:

29.9041677%%:    Main program. Takes implicit input
:    Takes input from the right side
%     Square root
%      Divide with
29.9041677       Literal number "29.9041677"


# Charcoal, 21 bytes

Ｉ∕₂∕⁸⁸²⁵·⁹⁸⁵Ｎ≕math.pi


Try it online! Link is to verbose version of code. Calculates the answer as accurately as possible. Explanation: The constant 8825.985 arises from the following calculation:

$$\frac{60\sqrt{\frac{g}{r_\text{m}}}}{2\pi}=\frac{30\sqrt{\frac{g}{r_\text{m}}}}\pi=\frac{\sqrt{\frac{900g}{r_\text{m}}}}\pi$$

    ⁸⁸²⁵·⁹⁸⁵            Literal number 8825.985
∕                    Divided by
Ｎ           Input number
₂                     Take the square root
∕                      Divided by
≕math.pi   Python variable math.pi
Ｉ                       Cast to string
Implicitly print


13 bytes by porting @adam's approximation:

Ｉ∕²⁹·⁹⁰⁴¹⁶⁷₂Ｎ


Try it online! Link is to verbose version of code.

# 05AB1E, 12 bytes

tz•1Íãǝ•*6°/


A port of the Jelly answer would be 1 byte longer:

•‡»µ•₄/I/tžq/


Explanation:

t              # Take the square root of the (implicit) input
z             # Calculate 1 divided by this value
•1Íãǝ•*      # Multiply it by compressed integer 29904167
6°/   # Divide it by 1000000 (6**10)
# (after which the result is output implicitly)

•‡»µ•          # Push compressed integer 8825985
₄/        # Divide it by 1000: 8825.985
I/      # Divide it by the input
t     # Take the square root of that
žq/  # Divide it by PI (3.141592653589793)
# (after which the result is output implicitly)


See this 05AB1E answer of mine (section How to compress large integers?) to understand why •1Íãǝ• is 29904167 and •‡»µ• is 8825985.

# Japt, 11 bytes

Port of the Python solution.

29.904#§/U¬


Try it