πŸŽ„ μ„±μž₯일지 3.1

μ±… ν–‰λ³΅ν•œ 이기주의자(웨인 닀이어)의 λ‚΄μš©μ— μžκ·Ήλ°›μ•„ μ‹œμž‘ν•˜λŠ” μ†Œλ°•ν•œ μ„±μž₯기둝

μ‚΄μ•„μžˆλŠ” 꽃과 죽은 꽃은 μ–΄λ–»κ²Œ κ΅¬λ³„ν•˜λŠ”κ°€?
μ„±μž₯ν•˜κ³  μžˆλŠ” 것이 μ‚΄μ•„ μžˆλŠ” 것이닀.
생λͺ…μ˜ μœ μΌν•œ μ¦κ±°λŠ” μ„±μž₯이닀!

🌳 ν‚€μ›Œλ“œ (1.0)
μ΅œλŒ€ν•œ κ°„λ‹¨ν•˜κ²Œ 정리, 좔후에 λ³΄λ©΄μ„œ 슀슀둜 μ„€λͺ…
πŸ‰ κ²½ν—˜ μœ„μ£Όλ‘œ (2.0)
λ‹¨μˆœ 정보λ₯Ό μ „λ‹¬ν•˜κΈ°λ³΄λ‹€ 무엇을 λ°°μ› κ³  μ–΄λ–»κ²Œ ν•΄κ²°ν–ˆλŠ”μ§€ 짧고 κ°„λ‹¨ν•˜κ²Œ μž‘μ„±
❄️ 정해진 ν…œν”Œλ¦Ώμ— λ§žμΆ°μ„œ (3.0)
ν‚€μ›Œλ“œ, κ²½ν—˜ λͺ¨λ‘ μ’‹λ‹€. λ‹€λ§Œ 맀일 μž‘μ„±ν•˜κΈ°λ‘œ 마음 λ¨Ήμ€λ§ŒνΌ ν•΅μ‹¬λ§Œ κ°„κ²°ν•˜κ²Œ 정리할 수 있게 ν…œν”Œλ¦Ώμ„ μž‘μ„± (3.1) 230102λΆ€ν„° μ‹œμž‘λ˜λŠ” ν•™μŠ΅μ— κ΄€ν•œ λ‚΄μš© μΆ”κ°€

πŸ”‘ 였늘의 ν‚€μ›Œλ“œ

μ΅œλŒ€ν•œ ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°μœΌλ‘œ μ•Œκ³ λ¦¬μ¦˜ 문제 ν’€κΈ°

기쑴에 ν’€μ—ˆλ˜ μ•Œκ³ λ¦¬μ¦˜ 문제λ₯Ό λ‹€μ‹œ ν’€ κΈ°νšŒκ°€ 생겼닀. λ‹€μ‹œ ν‘ΈλŠ” 김에 νƒ€μž…μŠ€ν¬λ¦½νŠΈ + ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°μ„ μ΅œλŒ€ν•œ μ§€ν‚€λ©΄μ„œ ν’€μ–΄λ³΄κΈ°λ‘œ ν–ˆλ‹€.

  1. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ - K번째 수

μƒˆλ‘œμš΄ 풀이

type NumberArray = number[];

  const solution = (
    array: NumberArray,
    commands: NumberArray[],
  ): NumberArray => {
    return commands.map(
      (command) =>
        array.slice(command[0] - 1, command[1]).sort((a, b) => a - b)[
          command[2] - 1
        ],
    );
  };

κΈ°μ‘΄ 풀이

function solution(array, commands) {
  let answer = [];
  for (let command of commands) {
    let arr = new Array(...array);
    let i = command[0];
    let j = command[1];
    let k = command[2];
    let tempArr = arr.splice(i - 1, j - i + 1);
    tempArr.sort((a,b) => a-b);
    let num = tempArr[k - 1];
    answer.push(num);
  }
  return answer;
}
  1. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ - μ΄μƒν•œ 문자 λ§Œλ“€κΈ°

μƒˆλ‘œμš΄ 풀이(컀링 ν•¨μˆ˜ μ‚¬μš©)

type ChangeString = (word: string) => string;
  const changeOddCapital = (word: string): string => {
    return [...word]
      .map((l, i) => (i % 2 ? l.toLowerCase() : l.toUpperCase()))
      .join('');
  };

  const solutionCurrying =
    (fn: ChangeString) =>
    (s: string): string => {
      return s.split(' ').map(fn).join(' ');
    };

  const solution = solutionCurrying(changeOddCapital);

κΈ°μ‘΄ 풀이

function solution(s) {
    let words = s.split(' ');
    const changeUpperLower = (word) => {
        let arrWord = [...word]
        for (let i = 0; i < arrWord.length; i++) {
            arrWord[i] = i % 2 === 0 ? arrWord[i].toUpperCase() : arrWord[i].toLowerCase();
        }
        return arrWord.join('');
    }
    return words.map((word) => changeUpperLower(word)).join(' ');
}
  1. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ - λͺ¨μ˜κ³ μ‚¬

μƒˆλ‘œμš΄ 풀이(지저뢄해도 컀링을 κ·ΉλŒ€ν™” 해보기)

const solutionCurrying =
    (firstPattern: number[]) =>
    (secondPattern: number[]) =>
    (thirdPattern: number[]) =>
    (answers: number[]): number[] => {
      const scores = [
        answers.filter(
          (answer, i) => answer === firstPattern[i % firstPattern.length],
        ).length,
        answers.filter(
          (answer, i) => answer === secondPattern[i % secondPattern.length],
        ).length,
        answers.filter(
          (answer, i) => answer === thirdPattern[i % thirdPattern.length],
        ).length,
      ];
      const maxScore = Math.max(...scores);
      return scores
        .map((score, i) => (score === maxScore ? i + 1 : 0))
        .filter((score) => score);
    };

  let [firstPatterns, secondPatterns, thirdPatterns] = [
    [1, 2, 3, 4, 5],
    [2, 1, 2, 3, 2, 4, 2, 5],
    [3, 3, 1, 1, 2, 2, 4, 4, 5, 5],
  ];

  const solution =
    solutionCurrying(firstPatterns)(secondPatterns)(thirdPatterns);

κΈ°μ‘΄ 풀이

function solution(answers) {
    const lengthAns = answers.length;
    const first = [1,2,3,4,5];
    const second = [2,1,2,3,2,4,2,5];
    const third = [3,3,1,1,2,2,4,4,5,5];
    const firstAns = new Array(Math.ceil(lengthAns / first.length)).fill(first).flat();
    const secondAns = new Array(Math.ceil(lengthAns / second.length)).fill(second).flat();
    const thirdAns = new Array(Math.ceil(lengthAns / third.length)).fill(third).flat();
    let countFirst = 0;
    let countSecond = 0;
    let countThird = 0;
    for (let i=0; i < lengthAns; i++) {
        if (answers[i] === firstAns[i]) {
            countFirst++;
        }
        if (answers[i] === secondAns[i]) {
            countSecond++;
        }
        if (answers[i] === thirdAns[i]) {
            countThird++;
        }
    }
    let answer = [];
    let temp = [countFirst, countSecond, countThird];
    let countMax = Math.max(...temp);
    for (let i = 0; i < 3; i++) {
        if (temp[i] === countMax) {
            answer.push(i+1)
        }
    }
    return answer;
    }
  1. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ - 크레인 μΈν˜•λ½‘κΈ° κ²Œμž„

μƒˆλ‘œμš΄ 풀이

type NumberArray = number[];
  type NumberStack = (number | undefined)[];
  const solution = (board: NumberArray[], moves: NumberArray): number => {
    const stack: NumberStack = [];
    let count: number = 0;
    const machineStacks: NumberArray[] = new Array(board.length)
      .fill(0)
      .map((_, i) =>
        board.flat().filter((num, j) => num && j % board.length === i),
      );
    const pickedNums = moves
      .map((move) => {
        let picked = machineStacks[move - 1].shift();
        return picked ? picked : -1;
      })
      .filter((num) => num >= 0);
    pickedNums.forEach((pickedNum) => {
      let stackPick = stack.pop();
      stackPick === pickedNum ? count++ : stack.push(stackPick, pickedNum);
    });
    return count * 2;
  };

κΈ°μ‘΄ 풀이

function solution(board, moves) {
    let answer = 0;
    const n = board.length;
    let basket = [];
    let moveToIndex = moves.map((move) => move - 1);

    for (let move of moveToIndex) {
        for (let i = 0; i < n; i++) {
            if (board[i][move]) {
                if (basket[basket.length - 1] === board[i][move]) {
                    basket.pop();
                    board[i][move] = 0;
                    answer += 2;
                    break;
                } else {
                basket.push(board[i][move]);
                board[i][move] = 0;
                break;
                }
            }
        }
    }

    return answer;
}

참고자료

πŸ“ μš”μ•½ 및 ν•˜λ£¨ 간단 회고

과거의 μ½”λ“œλ„ μ•„μ£Ό μ˜€λž˜μ „μ€ μ•„λ‹ˆμ§€λ§Œ, μ΄λ ‡κ²Œ ν˜„μž¬μ˜ μ½”λ“œμ™€ λΉ„κ΅ν•΄λ³΄λ‹ˆ κ°νšŒκ°€ μƒˆλ‘­λ‹€. μ‹œκ°„λ³΅μž‘λ„μ— λŒ€ν•œ νš¨μœ¨μ„±μ„ ν…ŒμŠ€νŠΈν•΄λ³Έ 것은 μ•„λ‹ˆμ§€λ§Œ, λͺ©ν‘œλ‘œ ν–ˆλ˜ νƒ€μž…μŠ€ν¬λ¦½νŠΈ + λ‚˜λ¦„μ˜ ν•¨μˆ˜ν˜•μœΌλ‘œ μ™„μ„±ν•΄μ„œ 정말 κΈ°μ˜λ‹€. ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°μ„ 정말 μ‘°κΈˆμ΄λΌλ„ κ³ λ €ν•˜λ©΄μ„œ μ•Œκ³ λ¦¬μ¦˜μ— μ μš©ν•΄λ³Έ κ²½ν—˜μ΄ 정말 값지닀. μ†”μ§νžˆ 쒀더 ν•¨μˆ˜ν˜• λŠλ‚ŒμœΌλ‘œ μˆœμˆ˜ν•¨μˆ˜λ“€μ„ κ΅¬λΆ„ν•˜κ³  νŒŒμ΄ν”„λ₯Ό κ΅¬μΆ•ν•˜λ“―μ΄ ν•˜κ³  μ‹Άμ—ˆλŠ”λ°, μ—­μ‹œλ‚˜ μ‰½μ§€λŠ” μ•Šμ•˜λ‹€. 이 정도 κ³΅λΆ€ν•˜κ³  μ‰½κ²Œμ‰½κ²Œ ν•¨μˆ˜ν˜•μ΄ λ‚˜μ˜€λ©΄ 그것도 μž¬λ―Έμ—†μœΌλ‹ˆκΉŒ..!
μ•žμœΌλ‘œλ„ μ•Œκ³ λ¦¬μ¦˜μ„ ν’€ λ•Œ, 쒀더 λ‹€μ–‘ν•œ κ΄€μ μœΌλ‘œ μ ‘κ·Όν•˜λ„λ‘ λ…Έλ ₯해봐야겠닀. 아직 곡뢀할 것도 많고 λ‚˜μ•„κ°ˆ 길도 λ§Žμ§€λ§Œ, μ΄λ ‡κ²Œ μ΄μ „μ˜ λ‚˜μ™€ λΉ„κ΅ν•΄λ³΄λ‹ˆ 색닀λ₯Έ μž¬λ―Έκ°€ μžˆλŠ” 것 κ°™λ‹€!

였늘의 μž˜ν•œ 점

  • μƒˆλ²½ 6μ‹œμ— μΌμ–΄λ‚˜μ„œ ν—¬μŠ€μž₯ λ“œλ””μ–΄ κ°”λ‹€!!!!!!!
  • νƒ€μž…μŠ€ν¬λ¦½νŠΈμ— λŒ€ν•΄ 쑰금 μ΅μˆ™ν•΄μ§„ 점
  • ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ°μœΌλ‘œ μ•Œκ³ λ¦¬μ¦˜μ„ μ ‘κ·Όν•΄λ³Έ 것!(κ³ λ―Όν•΄λ³΄λŠ” μ‹œκ°„μ΄ 정말 μ’‹μ•˜λ‹€!)
    • μ‘°κΈˆμ€ μ§€μ €λΆ„ν•˜κ³  μ–΅μ§€μŠ€λŸ½μ§€λ§Œ 컀링도 μ¨λ³΄λ €ν•˜κ³ , ν•œμ€„ν•œμ€„ ν•¨μˆ˜ν˜•μœΌλ‘œ κ³ λ―Όν•΄λ³Έ μ‹œκ°„μ΄ 정말 λœ»κΉŠμ—ˆλ‹€.

였늘의 μ•„μ‰¬μš΄ 점

  • μ˜€λŠ˜β€¦ 흠… μ—†λ‹€..! μ˜€λŠ˜μ€ κ·Έλƒ₯ λ‹€ μž˜ν–ˆλ‹€!!! κ·Έλ ‡κ²Œ μƒκ°ν•˜μž γ…Žγ…Ž