-
Notifications
You must be signed in to change notification settings - Fork 0
Add Function Composition solution files #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e979af
Add Function Composition solution files
myoshi2891 c2f6736
Fix Function Composition implementation issues
myoshi2891 674e2ed
Updated walkthrough to include Round 2 fixes: CSS adjustment for code…
myoshi2891 be665a3
Refine Function Composition visualization: improve accessibility and …
myoshi2891 896e87a
Add CLAUDE.md for project guidelines
myoshi2891 63bf1e9
Apply Round 4 Function Composition fixes: SRI hashes, SVG visual cons…
myoshi2891 49675f3
Apply Round 5 and Emergency Fixes: Remove Tailwind SRI (fix styles), …
myoshi2891 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## プロジェクト概要 | ||
|
|
||
| マルチ言語・マルチAIによる競技プログラミング学習リポジトリ。各問題に対して**2社 × Nモデル × 3言語 × 3ドキュメント階層**で成果物を生成する。 | ||
|
|
||
| ## 開発コマンド | ||
|
|
||
| ```bash | ||
| # セットアップ | ||
| make setup # venv + Jupyterカーネル設定 | ||
| make install # pip + bun install | ||
|
|
||
| # テスト | ||
| make test # pytest + vitest 両方実行 | ||
| bunx vitest run # JS/TSテストのみ | ||
| bunx vitest run path/to/file.test.ts # 単一テスト | ||
|
|
||
| # リント・フォーマット | ||
| make lint # ruff + black + prettier + eslint | ||
| make fmt # ruff --fix + black + prettier | ||
| bunx prettier -c . # prettier チェックのみ | ||
| bunx prettier -w . # prettier 修正 | ||
|
|
||
| # 実行 | ||
| bunx tsx path/to/file.ts # TypeScript実行 | ||
| make lab # JupyterLab起動 | ||
| ``` | ||
|
|
||
| パッケージマネージャは**Bun**。`npm`ではなく`bun install`を使用。 | ||
|
|
||
| ## アーキテクチャ | ||
|
|
||
| ### 6階層ディレクトリ構造 | ||
|
|
||
| ``` | ||
| {Domain}/{Subcategory}/{Platform}/{Problem}/{AIProvider}/{Artifact} | ||
| ``` | ||
|
|
||
| - **Domain**: `Algorithm/`, `DataStructures/`, `Mathematics/`, `SQL/`, `Shell/`, `Concurrency/` | ||
| - **Platform**: `leetcode/`, `hackerrank/`, `atcoder/`, `codeforces/` | ||
| - **AIProvider**: `Claude Sonnet 4.5/`, `Claude Code Sonnet 4.6 extended/`, `gpt-4o/` など | ||
| - **Artifact**: `*.py`, `*.ts`, `*.js`, `README.md`, `README.html`, `README_react.html` | ||
|
|
||
| **例外**: `JavaScript/` ディレクトリは LeetCode 30-Day JS Challenge 専用で、上記6階層に従わない。`SQL/` ドメインはAIプロバイダーが`gpt/`単一フォルダで`.ipynb`形式。 | ||
|
|
||
| ### デュアルAI実装哲学 | ||
|
|
||
| - **Claude実装**: 競技最適化、型アノテーション信頼、単一メソッド、50-150 LOC | ||
| - **GPT実装**: 本番堅牢性、ランタイム検証、複数メソッド、80-200 LOC | ||
|
|
||
| ### 3階層ドキュメントシステム | ||
|
|
||
| | ファイル | スタック | 用途 | | ||
| | ------------------- | ------------------------------- | ------------------------------------------------------------------------------------ | | ||
| | `README.md` | 純粋Markdown | 5セクション構造(Overview / Algorithm / Complexity / Implementation / Optimization) | | ||
| | `README.html` | Prism.js + Tailwind CSS | ステップコントロールUI、SVGフローチャート | | ||
| | `README_react.html` | React 18 UMD + Babel Standalone | リアルタイム入力操作、AI比較 | | ||
|
|
||
| ### コード構造パターン | ||
|
|
||
| **Python** (Claude): `class Solution: def methodName(self, ...) -> ReturnType:` | ||
| **TypeScript**: `function functionName(...): ReturnType { ... }` | ||
| **JavaScript**: `var functionName = function(...) { ... }; module.exports = { functionName };` | ||
|
|
||
| ## 依存関係ポリシー | ||
|
|
||
| - **Algorithm/DataStructures/Mathematics**: 標準ライブラリのみ(`typing`, `collections`, `itertools`, `math`, `heapq`)。外部ライブラリ禁止 | ||
| - **JS/TS実装**: ビルトインのみ。lodash等の外部ライブラリ禁止 | ||
| - **SQLドメインのみ**: Pandas/NumPy許可(`.ipynb`形式) | ||
|
|
||
| ## コードスタイル | ||
|
|
||
| - **TypeScript**: `strict: true`, `noImplicitAny: true`, target ES2022 | ||
| - **Prettier**: semi, singleQuote, tabWidth: 4, printWidth: 100 | ||
| - **Python**: ruff + black | ||
|
|
||
| ## SVGフローチャートガイドライン | ||
|
|
||
| `.agent/workflows/svg_flowchart_guidelines.md` に詳細あり。主要ポイント: | ||
|
|
||
| - `refX` はarrowhead長未満に設定(arrowheadがノードに隠れる問題を防止) | ||
| - viewBoxに30-50pxのpadding追加 | ||
| - Prism.jsコピーボタンはTailwindのpreflightで消えるため `!important` オーバーライドが必要 |
117 changes: 117 additions & 0 deletions
117
...t/2629. Function Composition/Claude Code Sonnet 4.6 extended/FunctionComposition_TS.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "a7571108", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 1. 問題の分析\n", | ||
| "\n", | ||
| "**競技プログラミング視点**\n", | ||
| "- 配列を右から左へ1パスするだけで解決可能。`reduceRight` が最適。\n", | ||
| "- 追加メモリ不要(クロージャで `x` を畳み込む)。\n", | ||
| "\n", | ||
| "**業務開発視点**\n", | ||
| "- 空配列 → 恒等関数という仕様を型安全に表現できる。\n", | ||
| "- `readonly` 修飾子で入力配列の不変性を保証。\n", | ||
| "\n", | ||
| "**TypeScript特有の考慮点**\n", | ||
| "- `F = (x: number) => number` という型エイリアスがすでに与えられているため、ジェネリクス不要。\n", | ||
| "- `reduceRight` の型推論が自然に効く。\n", | ||
| "\n", | ||
| "---\n", | ||
| "\n", | ||
| "## 2. アルゴリズムアプローチ比較\n", | ||
| "\n", | ||
| "| アプローチ | 時間計算量 | 空間計算量 | TS実装コスト | 型安全性 | 可読性 | 備考 |\n", | ||
| "|---|---|---|---|---|---|---|\n", | ||
| "| `reduceRight` | O(n) | O(1) | 低 | 高 | 高 | 最もシンプル |\n", | ||
| "| `for` ループ(右→左) | O(n) | O(1) | 低 | 高 | 中 | 命令的 |\n", | ||
| "| 再帰 | O(n) | O(n) | 中 | 高 | 中 | スタックオーバーフローリスク |\n", | ||
| "\n", | ||
| "---\n", | ||
| "\n", | ||
| "## 3. 選択したアルゴリズムと理由\n", | ||
| "\n", | ||
| "- **選択**: `reduceRight`\n", | ||
| "- **理由**:\n", | ||
| " - 数学的な「右から左への関数合成」を宣言的に表現でき、可読性・意図の明確さが最高。\n", | ||
| " - O(n) / O(1) で計算量も最適。\n", | ||
| " - TypeScriptの型推論が自然に効き、型注釈の追加が不要。\n", | ||
| "\n", | ||
| "---\n", | ||
| "\n", | ||
| "## 4. 実装コード" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "implementation", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Analyze Complexity\n", | ||
| "// Runtime 56 ms\n", | ||
| "// Beats 55.84%\n", | ||
| "// Memory 56.88 MB\n", | ||
| "// Beats 46.50%\n", | ||
| "type F = (x: number) => number;\n", | ||
| "\n", | ||
| "/**\n", | ||
| " * 関数配列の右から左への合成を返す\n", | ||
| " * @param functions - 合成する関数の配列\n", | ||
| " * @returns 合成された関数。空配列の場合は恒等関数\n", | ||
| " * @complexity Time: O(n), Space: O(1)\n", | ||
| " */\n", | ||
| "function compose(functions: readonly F[]): F {\n", | ||
| " return function (x: number): number {\n", | ||
| " return functions.reduceRight(\n", | ||
| " (acc: number, fn: F): number => fn(acc),\n", | ||
| " x\n", | ||
| " );\n", | ||
| " };\n", | ||
| "}\n", | ||
| "\n", | ||
| "// 動作確認\n", | ||
| "const fn1 = compose([x => x + 1, x => x * x, x => 2 * x]);\n", | ||
| "console.log(\"Example 1 (x=4): 2*4=8 -> 8*8=64 -> 64+1=65 :\", fn1(4));\n", | ||
| "\n", | ||
| "const fn2 = compose([x => 10 * x, x => 10 * x, x => 10 * x]);\n", | ||
| "console.log(\"Example 2 (x=1): 10 -> 100 -> 1000 :\", fn2(1));\n", | ||
| "\n", | ||
| "const fn3 = compose([]);\n", | ||
| "console.log(\"Example 3 (x=42): 42 :\", fn3(42));\n", | ||
| "\n", | ||
| "// Interactive checks\n", | ||
| "compose([x => x + 1, x => 2 * x])(4)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "points", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "**ポイント:**\n", | ||
| "- `functions` を `readonly F[]` とすることで入力配列の不変性を型レベルで保証。\n", | ||
| "- `reduceRight` の初期値 `x` が空配列時の恒等関数の役割を自然に担うため、空配列の特別処理が不要。\n", | ||
| "- コールバック内の引数 `acc`・`fn` に型注釈を付与し、strict mode 下でも型推論が確実に機能。" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "TypeScript", | ||
| "language": "typescript", | ||
| "name": "typescript" | ||
| }, | ||
| "language_info": { | ||
| "file_extension": ".ts", | ||
| "mimetype": "text/typescript", | ||
| "name": "typescript", | ||
| "version": "5.9.3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.