Skip to content

Instantly share code, notes, and snippets.

@terurou
Created November 29, 2014 13:07
Show Gist options
  • Save terurou/ef1fc4758a56704a53f4 to your computer and use it in GitHub Desktop.
Save terurou/ef1fc4758a56704a53f4 to your computer and use it in GitHub Desktop.
NGK2014B 発表順序抽選プログラム
package ;
class ArrayTools {
public static function shuffle<T>(arr : Array<T>) : Array<T> {
var i = 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 append<T>(arr : Array<T>, x : T) : Array<T> {
arr.push(x);
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;
}
}
package ;
import js.Lib;
using ArrayTools;
class Main {
static function main() {
var speakers = [
"y_tana_23", "mzp", "c0hama", "kekyo2", "maeda_", "bleis-tift",
"RKTM", "toyoshi", "yusuke_kokubo", "katzueno", "babydaemons",
"Tom_G3X", "ahiru3net", "osiire", "field_works", "sunflat", "sqm8",
"zetta1985", "athos", "smogami", "dabits", "nobukuma", "ZienChan",
"naomat1029"
].shuffle();
trace(speakers.take(5));
trace(speakers.take(5));
trace(speakers.take(5));
trace(speakers.append("galao_doce").shuffle().take(5));
trace(speakers);
}
}
@terurou
Copy link
Author

terurou commented Nov 29, 2014

galao_doceさんの会場到着が夕方になるため、途中でappend().shuffle()しています。

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