fork download
  1. /**
  2.  * chiebukuro-q1454563079.js
  3.  * 赤チーム(0)、青チーム(1) とし、各々の数値の個数を競う数列ゲーム。
  4.  *
  5.  * @version 1.4.0
  6.  * @author think49
  7.  * @url http://d...content-available-to-author-only...o.jp/qa/question_detail/q1454563079
  8.  */
  9.  
  10. Array.prototype.shuffle = function () {
  11. var k, t, len, _Math;
  12.  
  13. len = this.length;
  14.  
  15. if (len < 2) {
  16. return this;
  17. }
  18.  
  19. _Math = Math;
  20.  
  21. // Fisher–Yates shuffle
  22. while (len) {
  23. k = _Math.floor(_Math.random() * len--);
  24. t = this[k];
  25. this[k] = this[len];
  26. this[len] = t;
  27. }
  28.  
  29. return this;
  30. };
  31.  
  32.  
  33. function game_q1454563079 (winTeam) {
  34. var redTeam, blueTeam, _Array, _Math;
  35.  
  36. _Math = Math;
  37. _Array = Array;
  38.  
  39. switch (winTeam) {
  40. case 'red':
  41. redTeam = _Math.floor(_Math.random() * 3) + 7;
  42. blueTeam = 10 - redTeam;
  43. break;
  44. case 'blue':
  45. blueTeam = _Math.floor(_Math.random() * 3) + 7;
  46. redTeam = 10 - blueTeam;
  47. break;
  48. default:
  49. redTeam = _Math.floor(_Math.random() * 10);
  50. blueTeam = 10 - redTeam;
  51. break;
  52. }
  53.  
  54. return _Array(redTeam + 1).join(0).split('').concat(_Array(blueTeam + 1).join(1).split('')).shuffle().join('');
  55. }
  56.  
  57. print(game_q1454563079()); // 勝利確率はランダム
  58. print(game_q1454563079('red')); // 赤チーム(0) が必ず勝利する
  59. print(game_q1454563079('blue')); // 青チーム(1) が必ず勝利する
  60.  
Success #stdin #stdout 0.23s 213888KB
stdin
Standard input is empty
stdout
0100000000
0010000000
1111111101