Skip to content

Commit 0bc202a

Browse files
committed
docs: implement third round of code review fixes for Strange Grid Again and index generation
1 parent 715952f commit 0bc202a

5 files changed

Lines changed: 306 additions & 273 deletions

File tree

Mathematics/Fundamentals/HackerRank/Claude/Easy/Strange Grid Again/Strange_Grid_Again.html

Lines changed: 109 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@
406406
.cpbtn:hover {
407407
background: var(--gd);
408408
}
409+
.cpbtn:focus, .cpbtn:focus-visible {
410+
outline: 2px solid var(--gd);
411+
outline-offset: 2px;
412+
}
413+
.cpbtn:focus, .cpbtn:focus-visible {
414+
outline: 2px solid var(--gd);
415+
outline-offset: 2px;
416+
}
409417
.kw {
410418
color: #ff79c6;
411419
}
@@ -806,7 +814,7 @@ <h2>フローチャート</h2>
806814
<strong>フローの説明:</strong><br />
807815
1. 入力 (r, c) を受け取る<br />
808816
2. グループ番号 g を整数除算で計算<br />
809-
3. グループ先頭値 base = 10g を求める<br />
817+
3. グループ先頭値 base = 10 × g を求める<br />
810818
4. 列オフセット = 2×(c−1) を加算<br />
811819
5. 行オフセット = (r−1) mod 2 を加算<br />
812820
6. 3値の和を出力
@@ -1035,7 +1043,7 @@ <h2>FAQ</h2>
10351043
</section>
10361044

10371045
<footer>
1038-
HackerRank — Strange Grid &nbsp;|&nbsp; Python CPython 3.13.3 &nbsp;|&nbsp; O(1)
1046+
HackerRank — Strange Grid &nbsp;|&nbsp; Python CPython 3.12.4 &nbsp;|&nbsp; O(1)
10391047
</footer>
10401048
</div>
10411049

@@ -1174,51 +1182,107 @@ <h2>FAQ</h2>
11741182

11751183
/* Steps */
11761184
var COLS = [1, 2, 3, 4, 5];
1185+
function buildGridFragment(COLS, rows, cellValFn, highlightClassFn) {
1186+
var frag = document.createDocumentFragment();
1187+
var wrap = document.createElement('div');
1188+
wrap.style.display = 'inline-block';
1189+
1190+
var headerDiv = document.createElement('div');
1191+
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1192+
COLS.forEach(function (c) {
1193+
var cellDiv = document.createElement('div');
1194+
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1195+
cellDiv.textContent = 'c=' + c;
1196+
headerDiv.appendChild(cellDiv);
1197+
});
1198+
wrap.appendChild(headerDiv);
1199+
1200+
rows.forEach(function (r) {
1201+
var gpRow = document.createElement('div');
1202+
gpRow.className = 'gp-row';
1203+
1204+
var rl = document.createElement('div');
1205+
rl.className = 'rl';
1206+
rl.textContent = 'r=' + r;
1207+
gpRow.appendChild(rl);
1208+
1209+
var cellContainer = document.createElement('div');
1210+
cellContainer.style.cssText = 'display:flex;gap:4px;';
1211+
1212+
COLS.forEach(function (c) {
1213+
var g = Math.floor((r - 1) / 2);
1214+
var cell = document.createElement('div');
1215+
1216+
var cClass = g % 2 === 0 ? 'ca' : 'cb';
1217+
if (highlightClassFn) {
1218+
cClass = highlightClassFn(r, c, g, cClass);
1219+
}
1220+
1221+
cell.className = 'cell ' + cClass;
1222+
cell.textContent = cellValFn(r, c);
1223+
cellContainer.appendChild(cell);
1224+
});
1225+
gpRow.appendChild(cellContainer);
1226+
wrap.appendChild(gpRow);
1227+
});
1228+
frag.appendChild(wrap);
1229+
return frag;
1230+
}
1231+
1232+
function buildGridFragment(COLS, rows, cellValFn, highlightClassFn) {
1233+
var frag = document.createDocumentFragment();
1234+
var wrap = document.createElement('div');
1235+
wrap.style.display = 'inline-block';
1236+
1237+
var headerDiv = document.createElement('div');
1238+
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1239+
COLS.forEach(function (c) {
1240+
var cellDiv = document.createElement('div');
1241+
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1242+
cellDiv.textContent = 'c=' + c;
1243+
headerDiv.appendChild(cellDiv);
1244+
});
1245+
wrap.appendChild(headerDiv);
1246+
1247+
rows.forEach(function (r) {
1248+
var gpRow = document.createElement('div');
1249+
gpRow.className = 'gp-row';
1250+
1251+
var rl = document.createElement('div');
1252+
rl.className = 'rl';
1253+
rl.textContent = 'r=' + r;
1254+
gpRow.appendChild(rl);
1255+
1256+
var cellContainer = document.createElement('div');
1257+
cellContainer.style.cssText = 'display:flex;gap:4px;';
1258+
1259+
COLS.forEach(function (c) {
1260+
var g = Math.floor((r - 1) / 2);
1261+
var cell = document.createElement('div');
1262+
1263+
var cClass = g % 2 === 0 ? 'ca' : 'cb';
1264+
if (highlightClassFn) {
1265+
cClass = highlightClassFn(r, c, g, cClass);
1266+
}
1267+
1268+
cell.className = 'cell ' + cClass;
1269+
cell.textContent = cellValFn(r, c);
1270+
cellContainer.appendChild(cell);
1271+
});
1272+
gpRow.appendChild(cellContainer);
1273+
wrap.appendChild(gpRow);
1274+
});
1275+
frag.appendChild(wrap);
1276+
return frag;
1277+
}
1278+
11771279
var STEPS = [
11781280
{
11791281
title: 'グリッドのパターン把握',
11801282
desc: 'グリッドを観察すると行は2行1組のグループをなす。第1・2行がグループ0、第3・4行がグループ1、第5・6行がグループ2…と続く。',
11811283
render: function () {
11821284
var rows = [6, 5, 4, 3, 2, 1];
1183-
var frag = document.createDocumentFragment();
1184-
var wrap = document.createElement('div');
1185-
wrap.style.display = 'inline-block';
1186-
1187-
var headerDiv = document.createElement('div');
1188-
headerDiv.style.cssText =
1189-
'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1190-
COLS.forEach(function (c) {
1191-
var cellDiv = document.createElement('div');
1192-
cellDiv.style.cssText =
1193-
'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1194-
cellDiv.textContent = 'c=' + c;
1195-
headerDiv.appendChild(cellDiv);
1196-
});
1197-
wrap.appendChild(headerDiv);
1198-
1199-
rows.forEach(function (r) {
1200-
var gpRow = document.createElement('div');
1201-
gpRow.className = 'gp-row';
1202-
1203-
var rl = document.createElement('div');
1204-
rl.className = 'rl';
1205-
rl.textContent = 'r=' + r;
1206-
gpRow.appendChild(rl);
1207-
1208-
var cellContainer = document.createElement('div');
1209-
cellContainer.style.cssText = 'display:flex;gap:4px;';
1210-
1211-
COLS.forEach(function (c) {
1212-
var g = Math.floor((r - 1) / 2);
1213-
var cell = document.createElement('div');
1214-
cell.className = 'cell ' + (g % 2 === 0 ? 'ca' : 'cb');
1215-
cell.textContent = cellVal(r, c);
1216-
cellContainer.appendChild(cell);
1217-
});
1218-
gpRow.appendChild(cellContainer);
1219-
wrap.appendChild(gpRow);
1220-
});
1221-
frag.appendChild(wrap);
1285+
var frag = buildGridFragment(COLS, rows, cellVal, null);
12221286

12231287
var legendWrap = document.createElement('div');
12241288
legendWrap.style.cssText =
@@ -1260,35 +1324,9 @@ <h2>FAQ</h2>
12601324
c = 3,
12611325
g = Math.floor((r - 1) / 2);
12621326
var rows = [6, 5, 4, 3, 2, 1];
1263-
var frag = document.createDocumentFragment();
1264-
var wrap = document.createElement('div');
1265-
wrap.style.display = 'inline-block';
1266-
1267-
rows.forEach(function (ri) {
1268-
var gpRow = document.createElement('div');
1269-
gpRow.className = 'gp-row';
1270-
1271-
var rl = document.createElement('div');
1272-
rl.className = 'rl';
1273-
rl.textContent = 'r=' + ri;
1274-
gpRow.appendChild(rl);
1275-
1276-
var cellContainer = document.createElement('div');
1277-
cellContainer.style.cssText = 'display:flex;gap:4px;';
1278-
1279-
COLS.forEach(function (ci) {
1280-
var gi = Math.floor((ri - 1) / 2);
1281-
var cell = document.createElement('div');
1282-
cell.className =
1283-
'cell ' +
1284-
(ri === r && ci === c ? 'ch' : gi % 2 === 0 ? 'ca' : 'cb');
1285-
cell.textContent = cellVal(ri, ci);
1286-
cellContainer.appendChild(cell);
1287-
});
1288-
gpRow.appendChild(cellContainer);
1289-
wrap.appendChild(gpRow);
1327+
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci, gi, defaultClass) {
1328+
return (ri === r && ci === c) ? 'ch' : defaultClass;
12901329
});
1291-
frag.appendChild(wrap);
12921330

12931331
var fbox = document.createElement('div');
12941332
fbox.className = 'fbox';
@@ -1502,31 +1540,9 @@ <h2>FAQ</h2>
15021540
row_offset = (r - 1) % 2,
15031541
answer = base + col_offset + row_offset;
15041542
var rows = [6, 5, 4, 3, 2, 1];
1505-
var frag = document.createDocumentFragment();
1506-
1507-
var wrap = document.createElement('div');
1508-
wrap.style.display = 'inline-block';
1509-
rows.forEach(function (ri) {
1510-
var gpRow = document.createElement('div');
1511-
gpRow.className = 'gp-row';
1512-
1513-
var rl = document.createElement('div');
1514-
rl.className = 'rl';
1515-
rl.textContent = 'r=' + ri;
1516-
gpRow.appendChild(rl);
1517-
1518-
var cellContainer = document.createElement('div');
1519-
cellContainer.style.cssText = 'display:flex;gap:4px;';
1520-
COLS.forEach(function (ci) {
1521-
var cell = document.createElement('div');
1522-
cell.className = 'cell ' + (ri === r && ci === c ? 'ch' : 'cn');
1523-
cell.textContent = cellVal(ri, ci);
1524-
cellContainer.appendChild(cell);
1525-
});
1526-
gpRow.appendChild(cellContainer);
1527-
wrap.appendChild(gpRow);
1543+
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci) {
1544+
return (ri === r && ci === c) ? 'ch' : 'cn';
15281545
});
1529-
frag.appendChild(wrap);
15301546

15311547
var resWrap = document.createElement('div');
15321548
resWrap.style.cssText =

Mathematics/Fundamentals/HackerRank/Claude/Easy/Strange Grid Again/Strange_Grid_Again.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ $$
135135
g = \left\lfloor \frac{r - 1}{2} \right\rfloor \quad (\text{0-indexed グループ番号})
136136
$$
137137

138-
各グループの**先頭値(列 $c=1$, 偶数行**は:
138+
各グループの**先頭値(列 $c=1$, 奇数行(下行)**は:
139139

140140
$$
141141
\text{base} = 10 \cdot g

generate_index.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,13 @@ def generate_index(self) -> None:
888888
tab_contents_html = ""
889889
all_files_html = ""
890890

891-
def render_category_files(structure):
891+
def render_category_files(structure, sorted_categories):
892892
tabs_html_list = []
893893
files_html_sections = []
894894
all_files_html_list = [] # Renamed to avoid conflict with outer scope all_files_html
895895

896-
for category, files in structure.items():
896+
for category in sorted_categories:
897+
files = structure[category]
897898
css_cat = html.escape(category.lower(), quote=True)
898899
safe_category = html.escape(category, quote=True)
899900
icon = category_icons.get(category, '📁') # Default icon if not found
@@ -923,7 +924,7 @@ def render_category_files(structure):
923924
return ''.join(tabs_html_list), ''.join(files_html_sections), ''.join(all_files_html_list)
924925

925926
# Call the new function
926-
tabs_html, tab_contents_html, all_files_html = render_category_files(structure)
927+
tabs_html, tab_contents_html, all_files_html = render_category_files(structure, sorted_categories)
927928

928929
final_html = html_template.format(
929930
tabs=tabs_html,

0 commit comments

Comments
 (0)