diff --git a/Src/Problem11.lean b/Src/Problem11.lean index 9bc98d7..6ceb42e 100644 --- a/Src/Problem11.lean +++ b/Src/Problem11.lean @@ -9,15 +9,15 @@ variable {α : Type} [BEq α] inductive Data (α : Type) where | multiple : Nat → α → Data α | single : α → Data α -deriving Repr +deriving Repr, DecidableEq open Data -def encodeModified (l : List α) : List (Data α) := +partial def encodeModified (l : List α) : List (Data α) := -- sorry match l with | [] => [] - | x :: xs => + | x :: _xs => let (as, bs) := l.span (· == x) if as.length > 1 then multiple as.length x :: encodeModified bs @@ -25,19 +25,14 @@ def encodeModified (l : List α) : List (Data α) := single x :: encodeModified bs -- sorry - -- Avoid proving that the function terminates as a recursive function. - -- You don't have to fill in the `sorry` here. - decreasing_by - all_goals sorry - -- The following codes are for test and you should not edit these. example : encodeModified ['a', 'a', 'b', 'c'] = - [multiple 2 'a', single 'b', single 'c'] := by rfl + [multiple 2 'a', single 'b', single 'c'] := by native_decide -example : encodeModified ([] : List α) = [] := by rfl +example : encodeModified ([] : List Nat) = [] := by native_decide example : encodeModified ['a', 'b', 'b', 'b', 'c', 'b', 'b'] = - [single 'a', multiple 3 'b', single 'c', multiple 2 'b'] := by rfl + [single 'a', multiple 3 'b', single 'c', multiple 2 'b'] := by native_decide end P11 --# diff --git a/Src/Problem32.lean b/Src/Problem32.lean index 77f0358..2f5f56d 100644 --- a/Src/Problem32.lean +++ b/Src/Problem32.lean @@ -7,7 +7,7 @@ #check Nat.gcd /-- Euclidean algorithm -/ -def gcd (m n : Nat) : Nat := +partial def gcd (m n : Nat) : Nat := -- sorry if m = 0 then n @@ -15,10 +15,6 @@ def gcd (m n : Nat) : Nat := gcd (n % m) m -- sorry - -- Avoid proving that the function terminates as a recursive function. - -- You don't have to fill in the `sorry` here. - decreasing_by sorry - -- The following codes are for test and you should not edit these. example : gcd 6 0 = 6 := by native_decide diff --git a/Src/Problem35.lean b/Src/Problem35.lean index be42378..30f6462 100644 --- a/Src/Problem35.lean +++ b/Src/Problem35.lean @@ -5,7 +5,7 @@ Construct a flat list containing the prime factors in ascending order. -/ -def primeFactors (n : Nat) : List Nat := +partial def primeFactors (n : Nat) : List Nat := -- sorry loop n 2 [] |>.reverse where @@ -16,8 +16,6 @@ where loop (tgt / candidate) candidate <| candidate :: acc else loop tgt (candidate + 1) acc - - decreasing_by all_goals sorry -- sorry -- The following codes are for test and you should not edit these.