Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Created September 6, 2019 07:50
Show Gist options
  • Select an option

  • Save mdecourse/3418c42baca95df0a98b50c8aa2d62a7 to your computer and use it in GitHub Desktop.

Select an option

Save mdecourse/3418c42baca95df0a98b50c8aa2d62a7 to your computer and use it in GitHub Desktop.
Almost Equal Sizing Grouping
// 算出大略相等數目的分組數列
void main() {
// total student number
int total = 52;
// initial each group expect to be "eachGrp" number of people
int eachGrp = 10;
// may divide into "grpNum" number of group
int grpNum = total ~/ eachGrp;
// vacant list
var splits = [];
// find remainder when total number divid into "grpNum" number of group
int remainder = total % grpNum;
// number of people in one group by calculation
int calGrp = total ~/ grpNum;
for (int i = 0; i < grpNum; i++) {
splits.add(calGrp);
}
print(splits);
for (int i = 0; i < remainder; i++) {
splits[i] += 1;
}
print(splits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment