How many minimum days will he take to complete N units of work?
Pyth, 8 bytes
tfg/*TT4
How it works:
tfg/*TT4 Q is implicitly assigned to the input.
f test for T=1,2,3,... returning the first successful case
/*TT4 whether T * T / 4
g Q is greater than or equal to the input (second argument implied)
t and subtract 1 from the first successful case
Try it online!
In pseudo-code:
for(int T=1;;T++)
if(T*T/4 >= Q)
return T-1;
bonus, 22 bytes
"should return 7 for -1"
+tfg/*TT4?>Q0Q-2Q1*4g1
Try it online!
Jelly, 5 bytes
×4’½Ḟ
This uses a closed form of @LeakyNun's approach.
Try it online!
Due to a lucky coincidence, Ḟ
is overloaded as floor
/real
for real/complex numbers. This is one of the only three overloaded atoms in Jelly.
How it works
×4’½Ḟ Main link. Argument: n (integer)
×4 Compute 4n.
’ Decrement; yield 4n - 1.
½ Square root; yield sqrt(4n - 1).
If n < 2, this produces an imaginary number.
Ḟ If sqrt(4n - 1) is real, round it down to the nearest integer.
If sqrt(4n - 1) is complex, compute its real part (0).
JavaScript (ES2016), 24 bytes
Shortened version of the ES6 variant below thanks to @Florent and the Exponentiation Operator (currently only in Firefox nightly builds or transpilers).
n=>(n-1)**.5+(n+1)**.5|0
JavaScript (ES6), 30 bytes
n=>(s=Math.sqrt)(n-1)+s(n+1)|0
Based upon this sequence.
f=n=>(s=Math.sqrt)(n-1)+s(n+1)|0
units.oninput = () => output.value = f(+units.value||0);
<label>Units: <input id="units" type="number" value="0" /></label>
<label>Days: <input id="output" type="number" value="0" disabled /></label>