Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Last active September 19, 2019 00:38
Show Gist options
  • Select an option

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

Select an option

Save mdecourse/d7c4f7b267d43acd6ee7f78d581c4c5c to your computer and use it in GitHub Desktop.
2019cp 一甲亂數分組
import 'dart:html';
void main() {
// 每一組 10 人
int num = 10;
// 組序由 1 開始
int gth = 1;
// 迴圈序號變數
int i;
// 每組學員暫存數列
var gp_list = [];
// 全班分組數列
var cp2019 = [];
HttpRequest.getString(
'https://mde.tw/cp2019/downloads/2019fall_cp_1a_list.txt')
.then((String resp) {
// 利用 trim() 去除字串最後的跳行符號, 之後再利用 split() 根據 \n 轉為數列
var stud_list = resp.trim().split("\n");
// 數列利用 shuffle() 方法以隨機方法弄亂順序
stud_list.shuffle();
// 逐一讀取已經弄亂的學生學號數列, 利用模數運算每幾人分成一組
for (i = 0; i < stud_list.length; i++) {
// 0, 1~(num-1), num
if (i % num == 0) {
gp_list = [];
// 列印區隔符號
print('=' * 20);
print("group $gth :");
print(stud_list[i]);
// 在各分組數列中加入將對應的學員學號
gp_list.add(stud_list[i]);
gth = gth + 1;
} else {
print(stud_list[i]);
// 在各分組數列中加入將對應的學員學號
gp_list.add(stud_list[i]);
}
if (i % num == 0) {
// 逐步將各組暫存的分組數列加入全班分組數列中
cp2019.add(gp_list);
}
}
// 對各組學號排序
cp2019.forEach((element){element.sort();});
// 列出分組且排序後數列
print(cp2019);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment