5
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\begingroup\$ Sandbox (deleted) \$\endgroup\$
    – pigrammer
    Oct 5, 2022 at 12:45
  • \$\begingroup\$ How accurate is Pi? \$\endgroup\$ Oct 5, 2022 at 13:24
  • \$\begingroup\$ @MehanAlavi doesn't matter, as long as your final answer is accurate to 6 sigfigs \$\endgroup\$
    – pigrammer
    Oct 5, 2022 at 14:13

12 Answers 12

4
\$\begingroup\$

Python, 24 bytes

lambda r:29.904167/r**.5

Attempt This Online!

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}}}$$

\$\endgroup\$
5
  • \$\begingroup\$ I guess the link is broken. \$\endgroup\$ Oct 5, 2022 at 14:40
  • \$\begingroup\$ @MehanAlavi The link works for me? \$\endgroup\$ Oct 5, 2022 at 14:41
  • \$\begingroup\$ 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 :) \$\endgroup\$ Oct 5, 2022 at 14:46
  • \$\begingroup\$ @MehanAlavi Is this explanation good? \$\endgroup\$ Oct 5, 2022 at 14:53
  • \$\begingroup\$ Yeah thank you. What a creative mind you have got :) \$\endgroup\$ Oct 5, 2022 at 15:25
3
\$\begingroup\$

Python, 53 52 41 39 bytes

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

Try it online!

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

Jelly, 16 15 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
\$\endgroup\$
3
  • \$\begingroup\$ instead of 1/2*60 Write 30. Saved 3 bytes \$\endgroup\$ Oct 5, 2022 at 13:39
  • \$\begingroup\$ can you explain what ÷ØP does? Thanks! \$\endgroup\$
    – DialFrost
    Oct 10, 2022 at 9:09
  • \$\begingroup\$ @DialFrost ÷ is division and ØP gets pi (the constant). So ÷ØP means "divide by pi". \$\endgroup\$
    – pigrammer
    Oct 10, 2022 at 11:08
2
\$\begingroup\$

Go, 64 bytes

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

Attempt This Online!

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

Factor, 21 bytes

[ -.5 ^ 29.904167 * ]

Try it online!

Port of 97.100.97.109's Python answer.

\$\endgroup\$
2
+100
\$\begingroup\$

Vyxal, 13 bytes

29.9041677?√/

Try it Online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – emanresu A
    Oct 10, 2022 at 18:38
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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"
\$\endgroup\$
0
\$\begingroup\$

Charcoal, 21 bytes

I∕₂∕⁸⁸²⁵·⁹⁸⁵N≕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
            N           Input number
  ₂                     Take the square root
 ∕                      Divided by
             ≕math.pi   Python variable `math.pi`
I                       Cast to string
                        Implicitly print

13 bytes by porting @adam's approximation:

I∕²⁹·⁹⁰⁴¹⁶⁷₂N

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

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 12 bytes

tz•1Íãǝ•*6°/

Port of @97.100.97.109's Python answer.

Try it online or verify all test cases.

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

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

Try it online or verify all test cases.

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.

\$\endgroup\$
0
\$\begingroup\$

Japt, 11 bytes

Port of the Python solution.

29.904#§/U¬

Try it

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.