Skip to content

Commit 56401ce

Browse files
committed
fix: address code review findings for Sherlock and Divisors
- Fix misleading table label: '完全平方 m=18' → '完全平方 n=36(√n=6)' - Switch React from development to production minified bundles - Add MAX_N (10M) upper bound check in apply() with validation UI - Add .catch() error handling to copyCode() clipboard write - Unify public file Prism assets from CDN to local /vendor/ paths - Copy prism-python.min.js to public/vendor/prismjs/components/
1 parent a150815 commit 56401ce

4 files changed

Lines changed: 84 additions & 35 deletions

File tree

Mathematics/Fundamentals/HackerRank/Claude/Easy/Sherlock and Divisors/Sherlock_and_Divisors.html

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>HackerRank: Divisors Divisible by 2</title>
7-
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
8-
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
7+
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
8+
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
99
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
1010
<script src="https://cdn.tailwindcss.com"></script>
1111
<link
@@ -409,7 +409,7 @@ <h2 class="text-3xl font-black text-cyan-700 mb-4 pb-3 border-b-4 border-emerald
409409
6 ✅
410410
</td>
411411
<td class="border border-slate-200 px-4 py-2 text-slate-600">
412-
完全平方 m=18
412+
完全平方 n=36(√n=6)
413413
</td>
414414
</tr>
415415
</tbody>
@@ -470,15 +470,26 @@ <h2 class="text-3xl font-black text-cyan-700 mb-6 pb-3 border-b-4 border-emerald
470470
<script>
471471
function copyCode() {
472472
var c = document.getElementById('codeBlock').textContent;
473-
navigator.clipboard.writeText(c).then(function () {
474-
var b = document.getElementById('copyBtn');
475-
b.textContent = 'Copied!';
476-
b.classList.add('copied');
477-
setTimeout(function () {
478-
b.textContent = 'Copy';
479-
b.classList.remove('copied');
480-
}, 2000);
481-
});
473+
navigator.clipboard
474+
.writeText(c)
475+
.then(function () {
476+
var b = document.getElementById('copyBtn');
477+
b.textContent = 'Copied!';
478+
b.classList.add('copied');
479+
setTimeout(function () {
480+
b.textContent = 'Copy';
481+
b.classList.remove('copied');
482+
}, 2000);
483+
})
484+
.catch(function () {
485+
var b = document.getElementById('copyBtn');
486+
b.textContent = 'Failed';
487+
b.classList.add('copied');
488+
setTimeout(function () {
489+
b.textContent = 'Copy';
490+
b.classList.remove('copied');
491+
}, 2000);
492+
});
482493
}
483494
</script>
484495

@@ -1233,21 +1244,31 @@ <h2 class="text-3xl font-black text-cyan-700 mb-6 pb-3 border-b-4 border-emerald
12331244
return raw.map((s, i) => ({ ...s, step: i + 1 }));
12341245
}
12351246

1247+
const MAX_N = 10_000_000;
1248+
12361249
function StepsSection() {
12371250
const [N, setN] = useState(8);
12381251
const [edit, setEdit] = useState('8');
12391252
const [steps, setSteps] = useState(() => makeSteps(8));
12401253
const [cur, setCur] = useState(1);
12411254
const [play, setPlay] = useState(false);
1255+
const [err, setErr] = useState('');
12421256
const tr = useRef(null);
12431257
const apply = () => {
12441258
const v = parseInt(edit, 10);
1245-
if (!isNaN(v) && v >= 1) {
1246-
setN(v);
1247-
setSteps(makeSteps(v));
1248-
setCur(1);
1249-
setPlay(false);
1259+
if (isNaN(v) || v < 1) {
1260+
setErr('1 以上の整数を入力してください');
1261+
return;
1262+
}
1263+
if (v > MAX_N) {
1264+
setErr(`上限は ${MAX_N.toLocaleString()} です`);
1265+
return;
12501266
}
1267+
setErr('');
1268+
setN(v);
1269+
setSteps(makeSteps(v));
1270+
setCur(1);
1271+
setPlay(false);
12511272
};
12521273
useEffect(() => {
12531274
if (!play) return;
@@ -1291,6 +1312,9 @@ <h2 className="text-3xl font-black text-cyan-700 mb-2 pb-3 border-b-4 border-eme
12911312
>
12921313
適用
12931314
</button>
1315+
{err && (
1316+
<span className="text-red-500 text-xs font-bold dm">{err}</span>
1317+
)}
12941318
<div className="flex gap-2 flex-wrap">
12951319
{presets.map((v) => (
12961320
<button

public/Mathematics/Fundamentals/HackerRank/Claude/Easy/Sherlock and Divisors/Sherlock_and_Divisors.html

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>HackerRank: Divisors Divisible by 2</title>
7-
<script src="/vendor/react/react.development.js"></script>
8-
<script src="/vendor/react-dom/react-dom.development.js"></script>
7+
<script src="/vendor/react/react.production.min.js"></script>
8+
<script src="/vendor/react-dom/react-dom.production.min.js"></script>
99
<script src="/vendor/babel/babel.min.js"></script>
1010
<script src="/vendor/tailwindcss/script.js"></script>
1111
<link
@@ -409,7 +409,7 @@ <h2 class="text-3xl font-black text-cyan-700 mb-4 pb-3 border-b-4 border-emerald
409409
6 ✅
410410
</td>
411411
<td class="border border-slate-200 px-4 py-2 text-slate-600">
412-
完全平方 m=18
412+
完全平方 n=36(√n=6)
413413
</td>
414414
</tr>
415415
</tbody>
@@ -470,15 +470,26 @@ <h2 class="text-3xl font-black text-cyan-700 mb-6 pb-3 border-b-4 border-emerald
470470
<script>
471471
function copyCode() {
472472
var c = document.getElementById('codeBlock').textContent;
473-
navigator.clipboard.writeText(c).then(function () {
474-
var b = document.getElementById('copyBtn');
475-
b.textContent = 'Copied!';
476-
b.classList.add('copied');
477-
setTimeout(function () {
478-
b.textContent = 'Copy';
479-
b.classList.remove('copied');
480-
}, 2000);
481-
});
473+
navigator.clipboard
474+
.writeText(c)
475+
.then(function () {
476+
var b = document.getElementById('copyBtn');
477+
b.textContent = 'Copied!';
478+
b.classList.add('copied');
479+
setTimeout(function () {
480+
b.textContent = 'Copy';
481+
b.classList.remove('copied');
482+
}, 2000);
483+
})
484+
.catch(function () {
485+
var b = document.getElementById('copyBtn');
486+
b.textContent = 'Failed';
487+
b.classList.add('copied');
488+
setTimeout(function () {
489+
b.textContent = 'Copy';
490+
b.classList.remove('copied');
491+
}, 2000);
492+
});
482493
}
483494
</script>
484495

@@ -1233,21 +1244,31 @@ <h2 class="text-3xl font-black text-cyan-700 mb-6 pb-3 border-b-4 border-emerald
12331244
return raw.map((s, i) => ({ ...s, step: i + 1 }));
12341245
}
12351246

1247+
const MAX_N = 10_000_000;
1248+
12361249
function StepsSection() {
12371250
const [N, setN] = useState(8);
12381251
const [edit, setEdit] = useState('8');
12391252
const [steps, setSteps] = useState(() => makeSteps(8));
12401253
const [cur, setCur] = useState(1);
12411254
const [play, setPlay] = useState(false);
1255+
const [err, setErr] = useState('');
12421256
const tr = useRef(null);
12431257
const apply = () => {
12441258
const v = parseInt(edit, 10);
1245-
if (!isNaN(v) && v >= 1) {
1246-
setN(v);
1247-
setSteps(makeSteps(v));
1248-
setCur(1);
1249-
setPlay(false);
1259+
if (isNaN(v) || v < 1) {
1260+
setErr('1 以上の整数を入力してください');
1261+
return;
1262+
}
1263+
if (v > MAX_N) {
1264+
setErr(`上限は ${MAX_N.toLocaleString()} です`);
1265+
return;
12501266
}
1267+
setErr('');
1268+
setN(v);
1269+
setSteps(makeSteps(v));
1270+
setCur(1);
1271+
setPlay(false);
12511272
};
12521273
useEffect(() => {
12531274
if (!play) return;
@@ -1291,6 +1312,9 @@ <h2 className="text-3xl font-black text-cyan-700 mb-2 pb-3 border-b-4 border-eme
12911312
>
12921313
適用
12931314
</button>
1315+
{err && (
1316+
<span className="text-red-500 text-xs font-bold dm">{err}</span>
1317+
)}
12941318
<div className="flex gap-2 flex-wrap">
12951319
{presets.map((v) => (
12961320
<button

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ <h1 class="site-title">
791791

792792
<footer>
793793
<span class="footer-icon">🧪</span>
794-
Generated on 2026-02-25 09:40:43 UTC
794+
Generated on 2026-02-25 09:59:04 UTC
795795
</footer>
796796

797797
<script>

public/vendor/prismjs/components/prism-python.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)