Tema: Re: algoritmas
Autorius: lauris
Data: 2009-02-26 14:48:36
Nu ir in python tada jau :)

def groups(min, max, nr):
  print "%d to %d\n" % (min, max)

  step  = max / nr
  start = end = min

  for i in range(1, nr+1):
    restnrs = (max - end) - (nr - i + 1)
    end = restnrs / step > 0 and start + step or start + restnrs % step

    print "%d..%d" % (start, end)
    start = end + 1


groups(1, 7, 5)
groups(1, 9, 5)
groups(1, 19, 5)

1 to 7

1..2
3..4
5..5
6..6
7..7

1 to 9

1..2
3..4
5..6
7..8
9..9

1 to 19

1..4
5..8
9..12
13..16
17..19

-- 
Lauris