Algorithm #01 - "rock, paper, scissors"

filoscoderΒ·2019λ…„ 11μ›” 22일
0

Toy Algorithm

λͺ©λ‘ 보기
1/7
post-thumbnail

πŸ‡ΊπŸ‡Έ Complete the function that generates every possible sequence of shoots that a player could shot. [ rock / paper / scissors ]

πŸ‡¦πŸ‡· Completa la funcion que genere todas las secuencias posibles de tiros que un jugador pueda tirar. [ piedra / papel / tijera ] (traducido)

πŸ‡°πŸ‡· λ„μ „μžκ°€ 던질 수 μžˆλŠ” λͺ¨λ“  경우의 수λ₯Ό μƒμ‚°ν•˜λŠ” ν•¨μˆ˜λ₯Ό μž‘μ„±ν•˜μ„Έμš”. [ κ°€μœ„ / λ°”μœ„ / 보 ] (λ²ˆμ—­)

Example:

Your output should look something like:

// Test
rockPaperScissors();

// Output -> Array of arrays
// All the posible shots
[
  ["rock", "rock", "rock"],
  ["rock", "rock", "paper"],
  ["rock", "rock", "scissors"],
  ["rock", "paper", "rock"]
  //    ...etc...
];

# START [ here ] 🏁

const rockPaperScissors = function(num) {
  const shot = ["rock", "paper", "scissors"];
  // Your CODE
};

// Test
rockPaperScissors();

# Javascript solution πŸ†

  • Run it on your browser console window (F12) πŸ–₯
  • Feel free to COMMENT your preference language solution πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦
  • Do your best to complete the problem 🎭
  • if you can't beat this the solution is below 😱

solution πŸ‘‡

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

const rockPaperScissors = function() {
  const shot = ["rock", "paper", "scissors"];
  // Your CODE
  let solution = [];

  for (let i = 0; i < shot.length; i++) {
    for (let j = 0; j < shot.length; j++) {
      for (let k = 0; k < shot.length; k++) {
		let temp = [];
        temp.push(shot[i], shot[j], shot[k]);
        solution.push(temp);
      }
    }
  }
    return solution;
};

// Test
console.log(rockPaperScissors());
profile
Keep thinking code should be altruistic

0개의 λŒ“κΈ€