From cdadfb590d12c796051b1a3680c2297b01b56e01 Mon Sep 17 00:00:00 2001 From: beurmuz Date: Fri, 8 Mar 2024 22:24:16 +0900 Subject: [PATCH] =?UTF-8?q?#12=2024.03.08=20>=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=ED=95=B4=EC=8B=9C=20=ED=95=A8=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/programmers/Lv_2/README.md | 3 ++- src/programmers/Lv_2/tableHash.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/programmers/Lv_2/tableHash.js diff --git a/src/programmers/Lv_2/README.md b/src/programmers/Lv_2/README.md index 0f3eab3a..929c56cf 100644 --- a/src/programmers/Lv_2/README.md +++ b/src/programmers/Lv_2/README.md @@ -89,7 +89,7 @@ | 85 | [요격 시스템](./system.js) | 23.11.15 | X | [23.12.07](./replay/system.js) | | 86 | [미로 탈출](./miro.js) | 23.12.08 | X | | 87 | [우박수열 정적분](./math.js) | 23.12.14 | X | [23.12.18](./replay/math.js) | -| 88 | [더 맵게](./spicy.js) | 23.12.22 | X |[24.03.07](./replay/spicy.js) +| 88 | [더 맵게](./spicy.js) | 23.12.22 | X | [24.03.07](./replay/spicy.js) | | 89 | [이모티콘 할인 행사](./emoji.js) | 23.12.31 | X | | 90 | [숫자 블록](./numsBlock.js) | 24.01.01 | X | | 91 | [택배 배달과 수거하기](./deliveryPick.js) | 24.01.02 | X | @@ -102,3 +102,4 @@ | 98 | [당구 연습](./billiard.js) | 24.01.26 | X | | 99 | [순위 검색](./search.js) | 24.01.27 | X | | 100 | [혼자서 하는 틱택토](./alone.js) | 24.02.07 | X | +| 101 | [테이블 해시 함수](./tableHash.js) | 24.03.08 | X | diff --git a/src/programmers/Lv_2/tableHash.js b/src/programmers/Lv_2/tableHash.js new file mode 100644 index 00000000..853a731f --- /dev/null +++ b/src/programmers/Lv_2/tableHash.js @@ -0,0 +1,18 @@ +function solution(data, col, row_begin, row_end) { + var answer = ""; + data.sort((a, b) => { + if (a[col - 1] !== b[col - 1]) { + return a[col - 1] - b[col - 1]; + } + if (a[0] !== b[0]) { + return b[0] - a[0]; + } + }); + + for (let i = row_begin - 1; i <= row_end - 1; i++) { + const res = data[i].reduce((acc, val) => acc + (val % (i + 1)), 0); + answer = answer !== "" ? answer ^ res : answer; + } + + return answer; +}