Rock Scissor Paper

Problem

Two people, A and B, play a rock-paper-scissors game. A total of N games are played, and if A wins, output A, and if B wins, output B. In case of a tie, D is output.
Scissors, rock, and paper information will be set to 1: Scissors, 2: Rock, and 3: Paper.
For example, if N=5

Round 1 2 3 4 5
A 2 3 3 1 3
B 1 1 2 2 3
Winner A B A B D

Write a program that prints out who won each round given the scissors, rock, and paper information for each round of two people.

input

  • The first line is given the number of games, a natural number N (1<=N<=100).
  • In the second line, N pieces of scissors, rocks, and papers played by A are given.
  • In the third line, N pieces of scissors, rocks, and papers made by B are given.

    5 23313 11223

output

  • Print each meeting winner on each line. In case of a tie, D is output.

    A B A B D

Solution

function solution(a, b) {
	let answer = [];
	for (let i in a) {
		if (a[i] === b[i]) {
			answer.push('D');
		} else if (a[i] === 3 && b[i] === 1) {
			answer.push('B');
		} else if (b[i] === 3 && a[i] === 1) {
			answer.push('A');
		} else if (a[i] > b[i]) {
			answer.push('A');
		} else if (a[i] < b[i]) {
			answer.push('B');
		}
	}
	return answer;
}
function solution(a, b) {
	let answer = '';

	// Except draw or A wins, it is B wins
	for (let i = 0; i < a.length; i++) {
		if (a[i] === b[i]) answer += 'D ';
		else if (a[i] === 1 && b[i] === 3) answer += 'A ';
		else if (a[i] > b[i]) answer += 'A ';
		else answer += 'B ';
	}

	return answer;
}