Skip to content

Commit

Permalink
add P23: WIP
Browse files Browse the repository at this point in the history
without test cases
  • Loading branch information
Seasawher committed Mar 22, 2024
1 parent 4cf28c7 commit b6c86cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Src.Problem2
import Src.Problem20
import Src.Problem21
import Src.Problem22
import Src.Problem23
import Src.Problem3
import Src.Problem31
import Src.Problem32
Expand Down
16 changes: 16 additions & 0 deletions Src/Problem23.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/-
# Problem 23
Extract a given number of randomly selected elements from a list.
-/
variable {α : Type} [Inhabited α]

def rndSelect (l : List α) (n : Nat) : IO (List α) := do
-- sorry
match l, n with
| [], _ => pure []
| _, 0 => pure []
| _, n + 1 =>
let index ← IO.rand 0 $ l.length - 1
let previous ← rndSelect l n
pure <| l[index]! :: previous
-- sorry
1 change: 1 addition & 0 deletions md/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

* [21: Insert an element](./build/Problem21.md)
* [22: Integers within a range](./build/Problem22.md)
* [23: Random selection](./build/Problem23.md)

# 31-40: Arithmetic

Expand Down

0 comments on commit b6c86cb

Please sign in to comment.