Day 10 - 2021.12.17
과제 08
https://github.com/wooahan-agile/coding-test-study-3term/pull/74
크레인 인형뽑기 게임 비밀지도 (알고리즘 유형 중 구현 유형임)
https://programmers.co.kr/learn/courses/30/lessons/64061
2019 카카오 코딩 테스트 | 크레인 인형 뽑기 | 레벨 1 | 인턴쉽 문제 | 개발자
function solution(boards, moves) {
let count = 0;
let stack = [0];
moves = moves.map((move) => move - 1);
for (let move of moves) {
for (let board of boards) {
if (board[move] != 0) {
stack.push(board[move]);
board[move] = 0;
if (stack[stack.length - 1] === stack[stack.length - 2]) {
stack.pop();
stack.pop();
count += 2;
}
break;
}
}
}
return count;
}
다트 게임 (알고리즘 유형 중 구현 유형임)
https://programmers.co.kr/learn/courses/30/lessons/17682
알고리즘] 2018 카카오 공채 블라인드 코딩테스트 | 다트게임 | 프로해설러😛 | 파이썬 | 개발자 | 프로그래머스
function solution(dartResult) {
const regex = /[1]?[0-9][SDT][*#]?/g;
const roundResult = dartResult.match(regex);
for (let round in roundResult) {
if (roundResult[round] !== 0 && (roundResult[round].indexOf('*') !== -1)) {
roundResult[round-1] += '*2';
roundResult[round] = roundResult[round]
.replace('*', '*2')
}
roundResult[round] = roundResult[round]
.replace('S', '**1')
.replace('D', '**2')
.replace('T', '**3').replace('#', '*-1');
}
return eval(roundResult[0]) + eval(roundResult[1]) + eval(roundResult[2]);
}
TIL
- 정규표현식과 replace를 이용해서 필요한 문자열로 고쳐서 사용해보았다.
- 문자열로 되어있는 계산식을 eval() 을 이용하면 숫자로 그 결과가 나온다.
Lesson Learned
잘한 점
아쉬운 점
- 처음에 인형뽑기 문제를 읽었을 때 문제를 이해하지 못했었다. 주어진 배열이 어떻게 인형이 있는 자리를 표시하는지 이해가 안 됐었던 것이 아쉽다. 배열을 아래서부터 쌓는 것이 아니라 위에서부터 나타낸 것이라는 것을 금방 알아차렸다면 푸는 데 오래 걸리지 않았을 텐데..
배운 점
'Modern Agile > TIL' 카테고리의 다른 글
Day 12 - 2021.12.21 (0) | 2021.12.21 |
---|---|
Day 11 - 2021.12.20 (0) | 2021.12.20 |
Day 09 Tech Talk Day🎤 - 2021.12.16 (0) | 2021.12.16 |
Day 08 - 2021.12.15 (0) | 2021.12.16 |
Day 07 - 2021.12.14 (0) | 2021.12.15 |