Skip to content

Commit

Permalink
#21 22.07.19 > 구현 실전 1번 복습
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Jul 19, 2022
1 parent 530a755 commit cc9af8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
||문제종류|문제명|응시 날짜|채점 결과|재응시예정|
|:-:|:-|:-:|:---:|:---:|:-:|
|1|[그리디](./greedy/)|[예제](./greedy/greedy_ex.js)<br>[연습1](./greedy/greedy_01.js)<br>[연습2](./greedy/greedy_02.js)<br>[연습3](./greedy/greedy_03.js)<br>-<br>[실전1](./greedy/test_01.js)<br>[실전2](./greedy/test_02.js)<br>[실전3](./greedy/test_03.js)<br>|22.07.14<br><br><br><br>-<br>22.07.16<br><br><br>|O<br>X<br>O<br>O<br>-<br>O<br>O<br>O<br>|X<br>[22.07.16](./greedy/replay_01.js)<br>X<br>X<br>-<br>O<br>X<br>X<br>|
|2|[구현](./implementation/)|[예제1](./implementation/imple_ex01.js)<br>[예제2](./implementation/imple_ex02.js)<br>[연습1](./implementation/imple_01.js)<br>[연습2](./implementation/imple_02.js)|22.07.15|△<br>△<br>△<br>X|[22.07.17](./implementation/../replay_01.js)<br>[22.07.18](./implementation/replay_02.js)<br>O<br>O|
|2|[구현](./implementation/)|[예제1](./implementation/imple_ex01.js)<br>[예제2](./implementation/imple_ex02.js)<br>[연습1](./implementation/imple_01.js)<br>[연습2](./implementation/imple_02.js)|22.07.15|△<br>△<br>△<br>X|[22.07.17](./implementation/../replay_01.js)<br>[22.07.18](./implementation/replay_02.js)<br>[22.07.19](./implementation//replay_03.js)<br>O|
19 changes: 19 additions & 0 deletions src/cote/implementation/replay_03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

function solution(position) {
let answer = 0;
let [x, y] = position.split('');
const column = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
y = column.indexOf(x)+1; // col
x = y*1; // rowㄴ
const steps = [[-2, 1], [-1, 2], [1, 2], [2, 1], [2,-1], [1,-2], [-1, -2], [-2, -1]];

steps.forEach((pos) => {
let nx = x + pos[0];
let ny = y + pos[1];
if(nx >= 1 && ny >= 1 && nx <= 8 && ny <= 8) answer++;
});
return answer;
}

console.log(solution('a1'));

0 comments on commit cc9af8c

Please sign in to comment.