Bob has a server farm crunching numbers. He has `nodes` servers in his farm. His company has a lot of work to do. 

The work comes as a number `workload` which indicates how many jobs there are. Bob wants his servers to get an equal number of jobs each. If that is impossible, he wants the first servers to receive more jobs. He also wants the jobs sorted, so that the first server receives the first jobs.

The way this works, Bob wants an array indicating which jobs are going to which servers.

Can you help him distribute all this work as evenly as possible onto his servers?

Example
-------

Bob has `2` servers and `4` jobs. The first server should receive job 0 and 1 while the second should receive 2 and 3.

```
distribute(2, 4) # => [[0, 1], [2, 3]]
```

On a different occasion Bob has `3` servers and `3` jobs. Each should get just one.

```
distribute(3, 3) # => [[0], [1], [2]]
```

A couple of days go by and Bob sees a spike in jobs. Now there are `10`, but he hasn't got more than `4` servers available. He boots all of them. This time the first and second should get a job more than the third and fourth.

```
distribute(4, 10) # => [[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]]
```

Input
-----

Don't worry about invalid inputs. That is, `nodes > 0` and `workload > 0` and both will always be integers.

Difficulty: introductory

Starter code:

def distribute(nodes, workload):
	

Solutions:
def distribute(nodes, workload):
    w = list(range(workload))[::-1]
    return [[w.pop() for _ in range(workload // nodes + (workload % nodes > n))] for n in range(nodes)]

def distribute(n, w):
    g, (d,r) = iter(range(w)), divmod(w,n)
    return [ [next(g) for _ in range(d+(i<r))] for i in range(n)]

def distribute(nodes, workload):
    (q, r), it = divmod(workload, nodes), iter(range(workload))
    return [[next(it) for _ in range(q + (n < r))] for n in range(nodes)]

def distribute(nodes, workload):
    div, mod = divmod(workload, nodes)
    breakpoint = lambda i: i * div + (i if i < mod else mod)
    return [list(range(breakpoint(i), breakpoint(i+1))) for i in range(nodes)]


# one-liner
#def distribute(n, w):
#    return [list(range(i*(w//n)+w%n-max(0, w%n-i), (i+1)*(w//n)+w%n-max(0, w%n-i-1))) for i in range(n)]


from itertools import accumulate, tee

def distribute(nodes, workload):
    q, r = divmod(workload, nodes)
    ns = [q + (i < r) for i in range(nodes)]
    xs = list(accumulate([0] + ns))
    return [list(range(i, j)) for i, j in zip(xs, xs[1:])]
    


def distribute(nodes, workload):
    jobs_per_server, remaining = divmod(workload, nodes)
    jobs, start = [], 0
    for _ in range(nodes):
        how_many = jobs_per_server + (remaining > 0)
        jobs.append(list(range(start, start + how_many)))
        start += how_many
        remaining -= 1
    return jobs

import numpy as np
def distribute(nodes, workload):
    lst=[]
    value = 0
    for i in range(nodes):
        length = int(np.ceil((workload-value)/(nodes-i)))
        lst.append([l for l in range(value,value+length)])
        value = value + length
    return lst

import numpy
def distribute(nodes, workload):
    return [list(i) for i in numpy.array_split(numpy.array(range(0, workload)),nodes)]

def distribute(nodes, workload):
    n = workload // nodes
    r = workload % nodes
    jobs = []
    works = [i for i in range(workload)]
    j = 0
    for i in range(nodes):
        if i < r:
            jobs.append([works.pop(0) for i in range(n+1)])
        else:
            jobs.append([works.pop(0) for i in range(n)])
    return jobs

def distribute(nodes, workload):
    a=[[0] for x in range(nodes)]
    w=workload
    k=workload//nodes
    for j in range(0,workload%nodes):
     a[j][0]+=1
    for i in range(0,len(a)):
     for j in range(0,k):
      a[i][0]+=1
    total=0
    b=[[] for x in range(nodes)]
    for j in range(0,len(a)):
     for i in range(total, total+a[j][0]):
         b[j].append(i)
     total+=a[j][0]
    return b