A person has to complete N
units of work; the nature of work is the same.
In order to get the hang of the work, he completes only one unit of work in the first day.
He wishes to celebrate the completion of work, so he decides to complete one unit of work in the last day.
He is only allowed to complete x
, x+1
or x-1
units of work in a day, where x
is the units of work completed on the previous day.
Your task is to create a program or function that will compute the minimum number of days will he take to complete N
units of work.
Sample Input and Ouput:
input -> output (corresponding work_per_day table)
-1 -> 0 []
0 -> 0 []
2 -> 2 [1,1]
3 -> 3 [1,1,1]
5 -> 4 [1,1,2,1] or [1,2,1,1]
9 -> 5 [1,2,3,2,1]
13 -> 7 [1,2,2,2,3,2,1]
Input may be taken through STDIN
or as function argument, or in any appropriate way.
Output may be printed or as the result of a function, or in any appropriate way.
This is code-golf. Shortest solution wins.