lean-ja / lean-ja/lean-by-example
xs : List α から n 個取り出す組み合わせを全列挙する
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
この関数を実装するにあたっては、返り値の型が少し問題になる。
組み合わせを List で表現したとする。
この場合、xs = [0, 1, 2, 3] から2つの要素を取り出す組み合わせとして [0, 1] と [1, 0] は等しいのだが、List は順序の情報を持つのでこれは異なっているということになる。
HashSet として持てば重複は取り除くことができるのだが、それだと α に対して [Hashable] インスタンス等を仮定することになり、強すぎるように思える。
いっそのこと、List Bool または Vector Bool n を組み合わせだと解釈するのはどうだろうか?このアイデアには、メモリ使用量を節約できるというメリットも付随する。
vec : Vector Bool n であって、true の個数が m であるものを「n 個のものから m 個取り出す組み合わせ」として解釈できるはずである。これを Combination n m として定義するのはどうか。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named in the issue. First clarify the intended representation and API for combinations, including whether a new Combination type is required; completion depends on reaching agreement on that design before implementation.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100