New answers tagged

1

Fortran (GFortran), 48 bytes print*,(acos(-1._16)**(1/real(i,16)),i=1,12) end Try it online! Just an implicit loop with quad-precision vars. Not transferable, but works with GCC.


1

AWK, 56 55 bytes {x=atan2(0,-1)/atan2(($2/$1)^.5,1);$0=int(x);$0-=$0~x}1 Try it online! I know I can save a few bytes by hardcoding Pi to some arbitrary precision, but I'm not sure how accurate it is outside of the provided test cases.


1

Rust, 59 bytes |a:f64,b:f64|(f64::acos(-1.)/(b/a).sqrt().atan()).ceil()-1. Try it online!


0

PHP, 46 bytes <?=ceil(pi()/atan(($argv[2]/$argv[1])**.5))-1; Try it online! Not very original I guess, applying the formula from the video..


2

05AB1E, 30 bytes /t©ažq;‚Δ{ÐO;ż®‹èsO;‚}нžqs/î< Try it online! Almost definitely golfable.. Implements the formula but because 05AB1E doesn't have arctan we have to calculate it, this does it by bisection. Explanation /t - sqrt(a/b) © - store this value ažq;‚ ...


4

Excel, 35 37 bytes -2 bytes thanks to @Chronocidal =CEILING(PI()/(ATAN((B1/A1)^.5)),1)-1


3

C (gcc), 63 \$\cdots\$ 47 46 + 3 (compiler flags) = 49 bytes f(a,b){a=ceil(acos(-1)/atan(sqrt(b*1./a)))-1;} Try it online! Saved 11 12 bytes thanks to ceilingcat!!! Using the formula from the video ngn recommended.


5

Haskell, 32 bytes a#b=ceiling(pi/atan(sqrt$b/a))-1 Try it online!


1

Python 3, 55 bytes lambda a,b:ceil(pi/atan((b/a)**.5)-1) from math import* Try it online!


9

JavaScript (ES7),  41  39 bytes Takes input as (a)(b). a=>b=>3.14159265/Math.atan((b/a)**.5)|0 Try it online! How? Instead of using a ceil function and subtracting \$1\$, we deliberately use a slightly underestimated approximation of \$\pi\$ and floor the result with a bitwise OR. For \$a,b\le 10000\$, it was empirically proven to give ...


3

Ruby, 49 43 bytes ->a,b{(-1.arg/((a*b)**0.5+b.i).arg).ceil-1} Try it online! -5 thans to G B, nicely done -1 replacing 1i*b with b.i


9

Jelly, 10 9 bytes My first Jelly submission :') ÷½ÆṬØP÷Ċ’ -1 byte thanks to Mr.Xcoder Uses the formula as in the video. Receives the input flipped; OP gave permission. It probably has room for further golfing, so be sure to give me feedback! ÷½ divide b by a and take square root ÆṬ take the ArcTan of that; then ÷ divide ØP ...


4

Mathematica, 30 29 bytes, 25 characters ⌈Pi/ArcTan@Sqrt[#2/#]⌉-1& Try it online -1 byte thanks to ExpiredData Uses the formula explained in the video.


12

APL (Dyalog Classic), 18 16 bytes ¯1+⌈○÷¯3○.5*⍨⎕÷⎕ Try it online! rendered as the equivalent {¯1+⌈○÷¯3○.5*⍨⍵÷⍺} in the tio link, to facilitate testing; ⎕ means evaluated input; ⍺ and ⍵ are the arguments to an anonymous function $$\left\lceil\frac\pi{\textrm{arctg}\sqrt\frac ba}\right\rceil-1$$ (that's the formula from the video. i recommend watching it. ...


Top 50 recent answers are included