> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/lists/divide-equally.md).

# Divide Equally

Sort a list of random numbers into three lists of similar sum

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LhLKeaxG3gSolSHSZ5H%2F-LhLKme_1zK2x2j5gNwy%2F3bowls.png?alt=media\&token=a2930ffe-b254-4719-b518-fd2446191e0a)

{% file src="/files/-LhLKunIlvSgMWsRnlCy" %}

```d
//Sorting into three lists
nSrt=List.Reverse(List.Sort(n));
nSbL=List.Chop(nSrt,3);
lst1=List.Transpose(List.TakeEveryNthItem(nSbL,2,-1));
lst2=List.Transpose(List.Reverse((List.TakeEveryNthItem(nSbL,2,0))<1>));

//Three sublists with the sum of numbers more or less the same
lst3=(List.Transpose([List.Shuffle(lst1<1>),List.Shuffle(lst2<1>)]));
lst4 = List.Flatten(List.Clean(lst3,false)<1>,-1);
```
