lean-ja / lean-ja/lean-by-example

Std.HashSet を使って リストから重複を取り除く例

Open
#1,534 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.