Created
September 6, 2019 07:50
-
-
Save mdecourse/3418c42baca95df0a98b50c8aa2d62a7 to your computer and use it in GitHub Desktop.
Almost Equal Sizing Grouping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 算出大略相等數目的分組數列 | |
| 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