Skip to content

Instantly share code, notes, and snippets.

@terurou
Created December 1, 2012 06:52
Show Gist options
  • Save terurou/4180877 to your computer and use it in GitHub Desktop.
Save terurou/4180877 to your computer and use it in GitHub Desktop.
NGK2012B 発表順序抽選プログラムと結果
package ;
class ArrayTools {
public static function shuffle<T>(arr : Array<T>) : Array<T> {
var i : Int = arr.length;
while (i > 0) {
var j = Std.random(i);
var tmp = arr[--i];
arr[i] = arr[j];
arr[j] = tmp;
}
return arr;
}
public static function take<T>(arr : Array<T>, count : Int) : Array<T> {
var ret = [];
for (i in 0...count) {
ret.push(arr.shift());
}
return ret;
}
public static function append<T>(arr : Array<T>, item : T) : Array<T> {
arr.push(item);
return arr;
}
}
package ;
using ArrayTools;
class Main {
static function main() {
var speakers = [ 'maeda_', 'toyoshi', 'dabits', 'mzp', 'eitoball',
'bleis-tift', 'niccolli', 'ukiki999', 'kunihisa_matsuda',
'girigiribauer', 'babydaemons', 'Hannover_Fairs_Japan', 'kiy0taka',
'htid46', 'athos', 'issm', 'nagakenjs', 't6s', 'Tom_G3X',
'kaizen_nagoya', 'masahiro_ukei_bassman', 'Sophy'];
trace(speakers.shuffle().take(5));
trace(speakers.shuffle().take(5));
trace(speakers.shuffle().take(4));
trace(speakers.shuffle().take(5));
trace(speakers.append('tss_ontap').shuffle());
}
}
Main.hx:13: [kiy0taka,t6s,htid46,issm,maeda_]
Main.hx:14: [eitoball,babydaemons,bleis-tift,masahiro_ukei_bassman,Sophy]
Main.hx:15: [girigiribauer,niccolli,toyoshi,dabits]
Main.hx:16: [Tom_G3X,Hannover_Fairs_Japan,kunihisa_matsuda,athos,kaizen_nagoya]
Main.hx:17: [ukiki999,nagakenjs,tss_ontap,mzp]
@terurou
Copy link
Author

terurou commented Dec 1, 2012

tss_ontapさんは遅い時間帯希望のため、最後の枠になるようにしてあります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment