lean-ja / lean-ja/lean-by-example
Std.HashSet を使って リストから重複を取り除く例
Open
Nobody has claimed this yet.
コード例
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
import Std.Data.HashSet.Basic
/- # 投票アルゴリズム -/
/-- 投票結果 -/
def votes := ["Red", "Blue", "Green", "Blue", "Blue", "Red"]
/-- リストの中の特定の要素の数を数える -/
def count {α : Type} [BEq α] (x : α) (xs : List α) : Nat :=
xs.filter (· == x) |>.length
#guard count 1 [1, 2, 3, 4, 1, 2, 3, 1, 2, 1] = 4
#guard count "Red" votes = 2
open Std (HashSet)
/-- リストから重複を削除する -/
def rmdups {α : Type} [BEq α] [Hashable α] (xs : List α) : List α :=
HashSet.ofList xs |>.toList
#guard rmdups [1, 2, 3, 4, 1, 2, 3, 1, 2, 1] = [1, 2, 3, 4]
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
The issue provides a complete Lean example using Std.HashSet to remove duplicates from a list, but it does not name a documentation file or section. First inspect the repository's existing example structure and identify where this example belongs. Done means the example is added in the appropriate location and its #guard checks pass.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100