Skip to content
Merged

84 #308

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions HumanEvalLean/HumanEval84.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
module

def solve : Unit :=
()
def solve (n : Nat) : String :=
String.ofList (Nat.toDigits 2 (n.repr.chars.map (fun c => c.toNat - '0'.toNat) |>.fold (init := 0) (· + ·)))

example : solve 1000 = "1" := by native_decide
example : solve 150 = "110" := by native_decide
example : solve 147 = "1100" := by native_decide
example : solve 333 = "1001" := by native_decide
example : solve 963 = "10010" := by native_decide

theorem ofDigitChars_solve {n : Nat} :
Nat.ofDigitChars 2 (solve n).toList 0 = (n.repr.toList.map (fun c => c.toNat - '0'.toNat)).sum := by
rw [solve, String.toList_ofList, Nat.ofDigitChars_toDigits (by simp) (by simp),
← Std.Iter.foldl_toList, Std.Iter.toList_map]
simp [List.sum_eq_foldl]

/-!
## Prompt
Expand All @@ -10,12 +22,12 @@ def solve : Unit :=

def solve(N):
"""Given a positive integer N, return the total sum of its digits in binary.

Example
For N = 1000, the sum of digits will be 1 the output should be "1".
For N = 150, the sum of digits will be 6 the output should be "110".
For N = 147, the sum of digits will be 12 the output should be "1100".

Variables:
@N integer
Constraints: 0 ≤ N ≤ 10000.
Expand Down Expand Up @@ -47,4 +59,4 @@ def check(candidate):
assert candidate(963) == "10010", "Error"

```
-/
-/
Loading