10
\$\begingroup\$

Task

Write a function or a program to find the number of rotations required by a wheel to travel a given distance, given its radius.

Rules

Input can be 2 positive rational numbers and can be taken in any convenient format.

Both inputs are of same unit.

There must not be any digits 0-9 in your code.

The output will be an integer (in case of float, round to infinity)

This is code-golf so shortest code wins

Examples

distance radius  output
10       1       2
50       2       4
52.22    4       3
3.4      0.08    7
12.5663  0.9999  3
\$\endgroup\$
  • 5
    \$\begingroup\$ You probably should add that digits are also forbidden in compiler options (or anywhere else): if you limit this constraint to code only, with gcc we can do something like -DP=3.14 in compiler flags, that would define P as an approximation of pi, which is probably not what you intended \$\endgroup\$ – Annyo Nov 21 '18 at 16:50

34 Answers 34

0
\$\begingroup\$

SmileBASIC, 28 bytes

INPUT D,R?CEIL(D/(R+R)/PI())
\$\endgroup\$
0
\$\begingroup\$

Intel 8087 FPU assembly, 22 bytes

; input: D,R (shortreal,shortreal)
; output: O (memsixteen)
FDIST   MACRO  D, R, O
    FLD  D      ; ST[] = D
    FLDPI       ; ST[] = PI
    FDIV        ; ST = D / PI
    FLD  R      ; ST[] = R
    FLD  ST     ; ST[] = R
    FADD        ; ST = R + R
    FDIV        ; ST = D / PI / R + R
    FISTP O
        ENDM

Uses only the Intel Eighty-Eighty-Seven math-coprocessor. Inputs Distance (D) and Radius (R) as thirty-two bit IEEE Seven-Fifty-Four single-precision real. Returns O as a sixteen bit unsigned int.

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

Ruby, 31 bytes

->d,r{d/=Math::PI*(r+r);d.ceil}

Try it online!

\$\endgroup\$
-3
\$\begingroup\$

Mathematica, 8 bytes

 #/(2π r)&

So that

r =22.9;
#/(2π r)& @ 32

gives

(* 0.2224 *)

\$\endgroup\$
  • 3
    \$\begingroup\$ There must not be any digits 0-9 in your code. Also, could you please show how to call your function, maybe in an online interpreter like tio.run/#mathematica? I'm not sure how to supply the r. \$\endgroup\$ – Dennis Nov 22 '18 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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