A company is arranged in a heirarchical structure, with a layer of workers at the bottom. Each worker is managed by a manager. Consequently, each manager is managed by another manager until there is a company "boss". Each manager is restricted to managing, at most, x workers. For a company of size y calculate the number of managers required (including the boss)

Function should take two inputs. Eg non-golfed definition: calc_num_managers(num_workers, num_workers_per_manager)

You can assume that the number of workers per manager will be greater than 1.


  • A company with 0 workers needs 0 managers
  • If the company has 4 workers, and each manager can manage 8 workers, then there is 1 manager.
  • If the company has 4 workers, and each manager can manage 4 workers, then you need 1 manager
  • If the company has 12 workers, and each manager can manage 8 workers, then there are 3 managers: enter image description here
  • 3
    \$\begingroup\$ "two team leaders and a boss" - This needs to be expanded on. \$\endgroup\$
    – Shaggy
    Jul 27, 2017 at 10:28
  • 1
    \$\begingroup\$ Hello and Welcome to PPCG. You should consider posting in the sandbox first. Your examples make no sense. I´d say 7 or 5 managers for the last example, depending on wether the managers are workers too or not. \$\endgroup\$
    – Titus
    Jul 27, 2017 at 10:33
  • 1
    \$\begingroup\$ At first I thought, you were asking for ceiling(y/x) but now I'm confused.. \$\endgroup\$ Jul 27, 2017 at 10:39
  • 4
    \$\begingroup\$ Still not clear, why 3 managers are needed.. here \$\endgroup\$ Jul 27, 2017 at 11:02
  • 1
    \$\begingroup\$ The second manager is the one boss in Wheat Wizard's organogram. \$\endgroup\$ Jul 27, 2017 at 19:41

5 Answers 5


C, C++, Java, C#, D : 73 69 bytes

-4 bytes thanks to Zacharý

Due to the similarities between theses languages, this answer works for each.
Maybe it works in processing too, but i can't test

int c(int w,int p){int r=0;do{w=(w+p-1)/p;r+=w;}while(w>1);return r;}

Here is an optimized version in D : 62 bytes thanks to Zacharý

T c(T)(T w,T p){T r;do{w=(w+p-1)/p;r+=w;}while(w>1);return r;}

T here is a type for template metaprogramming. This function is callable with c(4,8);

  • \$\begingroup\$ Amazing, one code for 3 langs)) \$\endgroup\$ Jul 29, 2017 at 20:17
  • \$\begingroup\$ @ЕвгенийНовиков 4* languages. Just edited to test for C :) \$\endgroup\$ Jul 29, 2017 at 20:19
  • \$\begingroup\$ And how about includes ? codegolf.meta.stackexchange.com/questions/7515/… \$\endgroup\$ Jul 29, 2017 at 20:20
  • 1
    \$\begingroup\$ @ЕвгенийНовиков Well, the question just says to have a function, not a full program \$\endgroup\$ Jul 29, 2017 at 20:22
  • \$\begingroup\$ I think this works in D (wow, actually a decent D answer) and Processing as well. \$\endgroup\$
    – Adalynn
    Jul 30, 2017 at 20:19

Jelly, 14 bytes


Try it online!


JavaScript, 46 43 bytes

If scheme isn't solvable, there will be stack exeeded error

-3 bytes ceil trick inspired by Cows quack


.map(e=>console.log("w="+e[0]+" m="+e[1]+" result="+f(e[0],e[1])))


w count of workers, non-negative integer

m count of max workers per manager, positive integer

  • \$\begingroup\$ I believe |1 is shorter than Math.ceil \$\endgroup\$
    – user41805
    Jul 29, 2017 at 19:29
  • \$\begingroup\$ @Cowsquack (19/10)|1 is 1, but ceil 2 \$\endgroup\$ Jul 29, 2017 at 19:31

Perl 5, 44 + 1 (-n) = 45bytes

$t=<>;$m+=$_=1+int$_/$t while($_>1);say$m|$_

Try it online!


Husk, 7 bytes


Try it online!

Repeatedly (¡) takes the ceiling () of the division (/) of the number of workers by the number of workers per manager and sums (Σ) all the unique results (U).


Your Answer

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

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