function_signature stringlengths 15 86 | docstring stringlengths 23 1.07k | test_cases stringlengths 36 501 | problem_spec_nl stringlengths 59 1.14k | problem_spec_formal_ground_truth stringlengths 229 1.39k | problem_spec_formal_generated stringlengths 87 156 | isomorphism_theorem stringlengths 94 188 | isomorphism_proof stringclasses 1
value | implementation_signature stringlengths 36 77 | implementation stringlengths 5 942 | test_cases_lean stringlengths 27 566 | correctness_theorem stringlengths 63 121 | correctness_proof stringlengths 5 5.72k | helper_definitions stringclasses 11
values | isomorphism_helper_lemmas float64 | correctness_helper_lemmas float64 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
def words_string(s: string) -> List[string] | You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
| [{"input": "Hi, my name is John", "expected_output": ["Hi", "my", "name", "is", "John"]}, {"input": "One, two, three, four, five, six", "expected_output": ["One", "two", "three", "four", "five", "six"]}] | def words_string(s: string) -> List[string]
"""You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
""" | def problem_spec
-- function signature
(implementation: String β List String)
-- inputs
(s: String) :=
-- spec
let spec (result: List String) :=
let chars := s.toList;
let first := s.takeWhile (fun c => c β ',' β§ c β ' ');
(result = [] β (β x β chars, x = ' ' β¨ x = ',') β¨ s = "") β§
(result β [] β result = [firs... | def generated_spec
-- function signature
(impl: String β List String)
-- inputs
(s: String) : Prop := | theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) := | sorry | def implementation (s: String) : List String := | List.map (fun s => (s.toList.filter (fun c => c != ',')).asString) ((s.splitOn).filter (fun s => s != "" β§ s != ",")) | -- #test implementation "Hi, my name is John" = ["Hi", "my", "name", "is", "John"]
-- #test implementation "One, two, three, four, five, six" = ["One", "two", "three", "four", "five", "six"]
-- #test implementation "Hi, my name" = ["Hi", "my", "name"]
-- #test implementation "One,, two, three, four, five, six," = ["One... | theorem correctness
(s: String)
: problem_spec implementation s
:= | by
sorry | null | null | null |
def choose_num(x: int, y: int) -> int | This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1.
| [{"input": "(12, 15)", "expected_output": 14}, {"input": "(13, 12)", "expected_output": -1}] | def choose_num(x: int, y: int) -> int
"""This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1.
""" | def problem_spec
-- function signature
(implementation: Int β Int β Int)
-- inputs
(x: Int) (y: Int) :=
-- spec
let spec (result: Int) :=
(result = -1 β¨ (x β€ result β§ result β€ y β§ Even result)) β§
(result = -1 β¨ (forall i: Int, (x β€ i β§ i β€ y β§ Even i) β result β₯ i)) β§
(result = -1 β (x > y β¨ (x == y β§ Odd x β§ Odd... | def generated_spec
-- function signature
(impl: Int β Int β Int)
-- inputs
(x: Int) (y: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β x y, problem_spec impl x y) β
(β x y, generated_spec impl x y) := | sorry | def implementation (x: Int) (y: Int) : Int := | sorry | -- #test implementation 12 15 = 14
-- #test implementation 13 12 = -1
-- #test implementation 33 12354 = 12354
-- #test implementation 5234 5233 = -1
-- #test implementation 6 29 = 28
-- #test implementation 27 10 = (-1)
-- #test implementation 7 7 = -1
-- #test implementation 546 546 = 546 | theorem correctness
(x: Int) (y: Int)
: problem_spec implementation x y
:= | by
sorry | null | null | null |
def rounded_avg(n: nat, m: nat) -> Option[string] | You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return none.
| [{"input": "(1, 5)", "expected_output": "0b11"}, {"input": "(7, 5)", "expected_output": "None"}, {"input": "(10, 20)", "expected_output": "0b1111"}, {"input": "(20, 33)", "expected_output": "0b11010"}] | def rounded_avg(n: nat, m: nat) -> Option[string]
"""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return none.
""" | def problem_spec
-- function signature
(implementation: Nat β Nat β Option String)
-- inputs
(n: Nat) (m: Nat) :=
-- spec
let spec (result: Option String) :=
(n > m β result.isNone) β§
(n β€ m β result.isSome) β§
(n β€ m β
(result.isSome β§
let val := Option.getD result "";
let xs := List.Ico n (m+1);
... | def generated_spec
-- function signature
(impl: Nat β Nat β Option String)
-- inputs
(n: Nat) (m: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n m, problem_spec impl n m) β
(β n m, generated_spec impl n m) := | sorry | def implementation (n: Nat) (m: Nat) : Option String := | if n > m then
none
else
let xs := List.Ico n (m+1);
let avg := xs.sum / xs.length;
some ("0b" ++ (Nat.toDigits 2 avg).asString) | -- #test implementation 1 5 = some "0b11"
-- #test implementation 7 13 = some "0b1010"
-- #test implementation 964 977 = some "0b1111001010"
-- #test implementation 996 997 = some "0b1111100100"
-- #test implementation 185 546 = some "0b101101110"
-- #test implementation 362 496 = some "0b110101101"
-- #test implementa... | theorem correctness
(n: Nat) (m: Nat)
: problem_spec implementation n m
:= | by
sorry | null | null | null |
def unique_digits(x: List[nat]) -> List[nat] | Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
| [{"input": [15, 33, 1422, 1], "expected_output": [1, 15, 33]}, {"input": [152, 323, 1422, 10], "expected_output": []}] | def unique_digits(x: List[nat]) -> List[nat]
"""Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
""" | def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(x: List Nat) :=
-- spec
let spec (result: List Nat) :=
let has_even_digits(i: Nat): Bool :=
(List.filter (fun d => Even d) (Nat.digits 10 i)).length > 0;
(List.Sorted Nat.le result) β§
(forall i, i β result β (i β x β§ !(has... | def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(x: List Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β x, problem_spec impl x) β
(β x, generated_spec impl x) := | sorry | def implementation (x: List Nat) : List Nat := | sorry | -- #test implementation [15, 33, 1422, 1] = [1, 15, 33]
-- #test implementation [152, 323, 1422, 10] = []
-- #test implementation [12345, 2033, 111, 151] = [111, 151]
-- #test implementation [135, 103, 31] = [31, 135] | theorem correctness
(x: List Nat)
: problem_spec implementation x
:= | by
sorry | null | null | null |
def by_length(arr: List[int]) -> List[string] | Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
| [{"input": [2, 1, 1, 4, 5, 8, 2, 3], "expected_output": ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]}, {"input": [], "expected_output": []}, {"input": [1, -1, 55], "expected_output": ["One"]}] | def by_length(arr: List[int]) -> List[string]
"""Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
""" | def problem_spec
-- function signature
(implementation: List Int β List String)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: List String) :=
let digits: List String := ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"];
(forall s: String, (s β result β s β digits)) β§
(arr.length β₯ ... | def generated_spec
-- function signature
(impl: List Int β List String)
-- inputs
(arr: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) := | sorry | def implementation (arr: List Int) : List String := | sorry | -- #test implementation [2, 1, 1, 4, 5, 8, 2, 3] = ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
-- #test implementation [] = []
-- #test implementation [1, -1 , 55] = ["One"]
-- #test implementation [1, -1, 3, 2] = ["Three", "Two", "One"]
-- #test implementation [9, 4, 8] = ["Nine", "Eight", "Four"] | theorem correctness
(arr: List Int)
: problem_spec implementation arr
:= | by
sorry | null | null | null |
def f(n: int) -> List[int] | Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
| [{"input": 5, "expected_output": [1, 2, 6, 24, 15]}] | def f(n: int) -> List[int]
"""Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 ... | def problem_spec
-- function signature
(implementation: Int β List Int)
-- inputs
(n: Int) :=
-- spec
let spec (result: List Int) :=
(result.length = n) β§
(forall i: Nat, (1 β€ i β§ i β€ n β§ Even i) β (result[i-1]! = Nat.factorial i)) β§
(forall i: Nat, (1 β€ i β§ i β€ n β§ Odd i) β (result[i-1]! = (List.range (i+1)).sum... | def generated_spec
-- function signature
(impl: Int β List Int)
-- inputs
(n: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Int) : List Int := | sorry | -- #test implementation 5 = [1, 2, 6, 24, 15]
-- #test implementation 7 = [1, 2, 6, 24, 15, 720, 28]
-- #test implementation 1 = [1]
-- #test implementation 3 = [1, 2, 6] | theorem correctness
(n: Int)
: problem_spec implementation n
:= | by
sorry | null | null | null |
def even_odd_palindrome(n: nat) -> (nat, nat) | Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
| [{"input": 3, "expected_output": "(1, 2)"}, {"input": 12, "expected_output": "(4, 6)"}] | def even_odd_palindrome(n: nat) -> (nat, nat)
"""Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
""" | def problem_spec
-- function signature
(implementation: Nat β Nat Γ Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat Γ Nat) :=
let is_palindrome (k: Nat): Prop :=
List.Palindrome (Nat.digits 10 k);
let even_palindrome (k: Nat): Prop :=
(Even k) β§ (is_palindrome k);
let odd_palindrome (k: Nat): Pro... | def generated_spec
-- function signature
(impl: Nat β Nat Γ Nat)
-- inputs
(n: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : Nat Γ Nat := | sorry | -- #test implementation 123 = (8, 13)
-- #test implementation 12 = (4, 6)
-- #test implementation 3 = (1, 2)
-- #test implementation 63 = (6, 8)
-- #test implementation 25 = (5, 6)
-- #test implementation 19 = (4, 6)
-- #test implementation 9 = (4, 5) | theorem correctness
(n: Nat)
: problem_spec implementation n
:= | by
sorry | null | null | null |
def count_nums(arr: List[int]) -> int | Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
| [{"input": [], "expected_output": 0}, {"input": [-1, 11, -11], "expected_output": 1}, {"input": [1, 1, 2], "expected_output": 3}] | def count_nums(arr: List[int]) -> int
"""Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
""" | def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Int) :=
let dig_sum (x: Int): Int :=
let digs := x.natAbs.digits 10;
if x >= 0 then
(List.map (fun t => (t: Int)) digs).sum
else
(List.map (fun t => (t: Int)) (digs.d... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) := | sorry | def implementation (arr: List Int) : Int := | let signed_digits(x: Int): List Int :=
let x': Nat := Int.natAbs x;
let xs: List Nat := Nat.digits 10 x';
if x >= 0 then
xs
else
(-Int.ofNat (xs[0]!)) :: xs.tail;
((List.map (fun (x: Int) => (signed_digits x).sum) arr).filter (fun (x: Int) => x > 0)).length | -- #test implementation [] = 0
-- #test implementation [-1, -2, 0] = 0
-- #test implementation [1, 1, 2, -2, 3, 4, 5] = 6
-- #test implementation [1, 6, 9, -6, 0, 1, 5] = 5
-- #test implementation [1, 100, 98, -7, 1, -1] = 4
-- #test implementation [12, 23, 34, -45, -56, 0] = 5
-- #test implementation [-0, 1^0] = 1
-- ... | theorem correctness
(arr: List Int)
: problem_spec implementation arr
:= | by
sorry | null | null | null |
def move_one_ball(arr: List[int]) -> bool | We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation an... | [{"input": [3, 4, 5, 1, 2], "expected_output": true}, {"input": [3, 5, 4, 1, 2], "expected_output": false}] | def move_one_ball(arr: List[int]) -> bool
"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You ar... | def problem_spec
-- function signature
(implementation: List Int β Bool)
-- inputs
(arr: List Int) :=
let is_shifted (xs: List Int) (ys: List Int) (i: Nat) :=
(xs.length = ys.length) β§
(0 <= i) β§
(i < xs.length) β§
(forall j, (0 <= j β§ j < ys.length) β (ys[j]! = xs[(j-i) % xs.length]!))
-- spec
let spec (result:... | def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(arr: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) := | sorry | def implementation (arr: List Int) : Bool := | sorry | -- #test implementation [3, 4, 5, 1, 2] = True
-- #test implementation [3, 5, 10, 1, 2] = True
-- #test implementation [4, 3, 1, 2] = False
-- #test implementation [3, 5, 4, 1, 2] = False
-- #test implementation [] = True | theorem correctness
(arr: List Int)
: problem_spec implementation arr
:= | by
sorry | null | null | null |
def exchange(lst1: list[int], lst2: list[int]) -> str | In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange eleme... | [{"input": "([1, 2, 3, 4], [1, 2, 3, 4])", "expected_output": "YES"}, {"input": "([1, 2, 3, 4], [1, 5, 3, 4])", "expected_output": "NO"}] | def exchange(lst1: list[int], lst2: list[int]) -> str
"""In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements b... | def problem_spec
-- function signature
(implementation: List Int β List Int β String)
-- inputs
(lst1: List Int)
(lst2: List Int) :=
-- spec
let spec (result : String) :=
lst1 β [] β lst2 β [] β
let bool_result := β exchange: List (Nat Γ Nat),
let lst1_idxs := exchange.map (fun (a, b) => a)
let lst2_idxs :=... | def generated_spec
-- function signature
(impl: List Int β List Int β String)
-- inputs
(lst1: List Int)
(lst2: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β lst1 lst2, problem_spec impl lst1 lst2) β
(β lst1 lst2, generated_spec impl lst1 lst2) := | sorry | def implementation (lst1: List Int) (lst2: List Int) : String := | sorry | -- #test implementation ([1, 2, 3, 4], [1, 2, 3, 4]) = "YES"
-- #test implementation ([1, 2, 3, 4], [1, 5, 3, 4]) = "NO" | theorem correctness
(lst1: List Int)
(lst2: List Int)
: problem_spec implementation lst1 lst2
:= | by
sorry | null | null | null |
def histogram(s : str) -> Dict[str, int] | Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
-- Note(George): I believe the equality extensionality for HashMaps makes this spec true.
| [{"input": "a b c", "expected_output": {"a": 1, "b": 1, "c": 1}}, {"input": "a b b a", "expected_output": {"a": 2, "b": 2}}, {"input": "a b c a b", "expected_output": {"a": 2, "b": 2}}, {"input": "b b b b a", "expected_output": {"b": 4}}, {"input": "", "expected_output": {}}] | def histogram(s : str) -> Dict[str, int]
"""Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
-- Note(George): I believe the equality extensi... | def problem_spec
-- function signature
(implementation: String β Std.HashMap Char Nat)
-- inputs
(s: String) :=
-- spec
let spec (result : Std.HashMap Char Nat) :=
let chars := s.splitOn " "
chars.all (fun c => c.length = 1) β§ s.all (fun c => c.isLower β¨ c = ' ') β
β key β result.keys,
(key.isLower β§
... | def generated_spec
-- function signature
(impl: String β Std.HashMap Char Nat)
-- inputs
(s: String) : Prop := | theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) := | sorry | def implementation (s: String) : Std.HashMap Char Nat := | sorry | -- #test implementation 'a b c' = {'a': 1, 'b': 1, 'c': 1}
-- #test implementation 'a b b a' = {'a': 2, 'b': 2}
-- #test implementation 'a b c a b' = {'a': 2, 'b': 2}
-- #test implementation 'b b b b a' = {'b': 4}
-- #test implementation '' = {} | theorem correctness
(s: String)
: problem_spec implementation s
:= | by
sorry | null | null | null |
def reverse_delete(s : str, c : str) -> (str, bool) | We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
-... | [{"input": ["abcde", "ae"], "expected_output": "(\"bcd\", False)"}, {"input": ["abcdef", "b"], "expected_output": "(\"acdef\", False)"}, {"input": ["abcdedcba", "ab"], "expected_output": "('cdedc', True)"}] | def reverse_delete(s : str, c : str) -> (str, bool)
"""We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple conta... | def problem_spec
-- function signature
(implementation: String β String β (String Γ Bool))
-- inputs
(s: String)
(c: String) :=
-- spec
let spec (result : String Γ Bool) :=
let (result_str, result_bool) := result
result_bool = (List.Palindrome result_str.data) β§
(c.data.length = 0 β result_str = s) β§
(c.data.le... | def generated_spec
-- function signature
(impl: String β String β (String Γ Bool))
-- inputs
(s: String)
(c: String) : Prop := | theorem spec_isomorphism:
β impl,
(β s c, problem_spec impl s c) β
(β s c, generated_spec impl s c) := | sorry | def implementation (s: String) (c: String) : String Γ Bool := | sorry | -- #test implementation "abcde" "ae" = ("bcd", False)
-- #test implementation "abcdef" "b" = ("acdef", False)
-- #test implementation "abcdedcba" "ab" = ("cdedc", True) | theorem correctness
(s c: String)
: problem_spec implementation s c
:= | by
sorry | null | null | null |
def odd_count(lst : list[str]) -> list[str] | Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the number
of odd digits in the i'th string of the input.
Note(George): Found it hard to not leak t... | [{"input": ["1234567"], "expected_output": ["the number of odd elements 4n the str4ng 4 of the 4nput."]}, {"input": ["3", "11111111"], "expected_output": ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]}] | def odd_count(lst : list[str]) -> list[str]
"""Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the number
of odd digits in the i'th string of the i... | def problem_spec
-- function signature
(implementation: List String β List String)
-- inputs
(lst: List String) :=
-- spec
let spec (result : List String) :=
lst.all (fun s => s.data.all (fun c => c.isDigit)) β
(result.length = 0 β lst.length = 0) β§
(result.length > 0 β
let num_odd_digits := (lst.head!.data.fil... | def generated_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List String) : List String := | sorry | -- #test implementation ['1234567'] = ["the number of odd elements 4n the str4ng 4 of the 4nput."]
-- #test implementation ['3',"11111111"] = ["the number of odd elements 1n the str1ng 1 of the 1nput.",
-- "the number of odd elements 8n the str8ng 8 of the 8nput."] | theorem correctness
(lst: List String)
: problem_spec implementation lst
:= | by
sorry | null | null | null |
def minSubArraySum(nums : list[int]) -> int | Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
| [{"input": [2, 3, 4, 1, 2, 4], "expected_output": 1}, {"input": [-1, -2, -3], "expected_output": -6}] | def minSubArraySum(nums : list[int]) -> int
"""Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
""" | def problem_spec
-- function signature
(implementation: List Int β Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result : Int) :=
(β subarray β nums.sublists,
subarray.length > 0 β
result β€ subarray.sum) β§
(β subarray β nums.sublists,
subarray.length > 0 β§
result = subarray.sum)
-- program te... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) := | sorry | def implementation (nums: List Int) : Int := | sorry | -- #test implementation [2, 3, 4, 1, 2, 4] = 1
-- #test implementation [-1, -2, -3] = -6 | theorem correctness
(nums: List Int)
: problem_spec implementation nums
:= | by
sorry | null | null | null |
def max_fill_count(grid : list[list[int]], capacity : int) -> int | You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity.
Your task is to use the buckets to empty the wells.
Output the numb... | [{"input": "([[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1)", "expected_output": 6}, {"input": "([[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2)", "expected_output": 5}, {"input": "([[0,0,0], [0,0,0]], 5)", "expected_output": 0}] | def max_fill_count(grid : list[list[int]], capacity : int) -> int
"""You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity... | def problem_spec
-- function signature
(implementation: List (List Nat) β Nat β Nat)
-- inputs
(grid: List (List Nat))
(capacity: Nat) :=
-- spec
let spec (result : Nat) :=
(grid.all (fun row => row.all (fun cell => cell = 0 β¨ cell = 1))) β
(β len : Nat, grid.all (fun row => row.length = len)) β
(result = 0 β gri... | def generated_spec
-- function signature
(impl: List (List Nat) β Nat β Nat)
-- inputs
(grid: List (List Nat))
(capacity: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β grid capacity, problem_spec impl grid capacity) β
(β grid capacity, generated_spec impl grid capacity) := | sorry | def implementation (grid: List (List Nat)) (capacity: Nat) : Nat := | sorry | -- #test implementation [[0,0,1,0], [0,1,0,0], [1,1,1,1]] 1 = 6
-- #test implementation [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] 2 = 5
-- #test implementation [[0,0,0], [0,0,0]] 5 = 0 | theorem correctness
(grid: List (List Nat))
(capacity: Nat)
: problem_spec implementation grid capacity
:= | by
sorry | null | null | null |
def max_fill_count(grid : list[list[int]], capacity : int) -> int | Please write a function that sorts an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value.
| [{"input": [1, 5, 2, 3, 4], "expected_output": [1, 2, 3, 4, 5]}, {"input": [1, 0, 2, 3, 4], "expected_output": [0, 1, 2, 3, 4]}] | def max_fill_count(grid : list[list[int]], capacity : int) -> int
"""Please write a function that sorts an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value.
""" | def problem_spec
-- function signature
(implementation: List Nat β List Nat)
-- inputs
(lst: List Nat) :=
-- spec
let spec (result : List Nat) :=
β x : Nat, lst.count x = result.count x β§
result.length = lst.length β§
(β i j : Nat, i < j β j < result.length β
Nat.digits 2 (result.get! i) < Nat.digits 2 (result... | def generated_spec
-- function signature
(impl: List Nat β List Nat)
-- inputs
(lst: List Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List Nat) : List Nat := | sorry | -- #test implementation [1, 5, 2, 3, 4] = [1, 2, 3, 4, 5]
-- #test implementation [1, 0, 2, 3, 4] = [0, 1, 2, 3, 4] | theorem correctness
(lst: List Nat)
: problem_spec implementation lst
:= | by
sorry | null | null | null |
def select_words(s : str, n : int) -> list[str] | Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return an empty list.
Note: you may assume the input stri... | [{"input": "(\"Mary had a little lamb\", 4)", "expected_output": ["little"]}, {"input": "(\"Mary had a little lamb\", 3)", "expected_output": ["Mary", "lamb"]}, {"input": "(\"simple white space\", 2)", "expected_output": []}, {"input": "(\"Hello world\", 4)", "expected_output": ["world"]}, {"input": "(\"Uncle sam\", 3)... | def select_words(s : str, n : int) -> list[str]
"""Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return... | def problem_spec
-- function signature
(implementation: String β Nat β List String)
-- inputs
(s: String)
(n: Nat) :=
-- spec
let spec (result : List String) :=
let is_consonant (c: Char) :=
c β ['a', 'e', 'i', 'o', 'u'] β§
c β ['A', 'E', 'I', 'O', 'U'] β§
c.isAlpha
s.all (fun c => c = ' ' β¨ c.isAlpha) β
... | def generated_spec
-- function signature
(impl: String β Nat β List String)
-- inputs
(s: String)
(n: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β s n, problem_spec impl s n) β
(β s n, generated_spec impl s n) := | sorry | def implementation (s: String) (n: Nat) : List String := | sorry | -- #test implementation "Mary had a little lamb" 4 = ["little"]
-- #test implementation "Mary had a little lamb" 3 = ["Mary", "lamb"]
-- #test implementation "simple white space" 2 = []
-- #test implementation "Hello world" 4 = ["world"]
-- #test implementation "Uncle sam" 3 = ["Uncle"] | theorem correctness
(s: String)
(n: Nat)
: problem_spec implementation s n
:= | by
sorry | null | null | null |
def get_closest_vowel(s : str) -> str | You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains En... | [{"input": "yogurt", "expected_output": "u"}, {"input": "FULL", "expected_output": "U"}, {"input": "quick", "expected_output": "i"}, {"input": "ab", "expected_output": ""}] | def get_closest_vowel(s : str) -> str
"""You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may... | def problem_spec
-- function signature
(implementation: String β String)
-- inputs
(s: String) :=
-- spec
let spec (result : String) :=
s.data.all (fun c => c.isAlpha) β
let is_consonant (c: Char) :=
c β ['a', 'e', 'i', 'o', 'u'] β§
c β ['A', 'E', 'I', 'O', 'U'] β§
c.isAlpha
(result = "" β Β¬ β (i j k : ... | def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s: String) : Prop := | theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) := | sorry | def implementation (s: String) : String := | sorry | -- #test implementation "yogurt" = "u"
-- #test implementation "FULL" = "U"
-- #test implementation "quick" = "i"
-- #test implementation "ab" = "" | theorem correctness
(s: String)
: problem_spec implementation s
:= | by
sorry | null | null | null |
def match_parens(l : list[str]) -> str | You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if and only if all parentheses in S
are balanc... | [{"input": ["()(", ")"], "expected_output": "Yes"}, {"input": [")", ")"], "expected_output": "No"}] | def match_parens(l : list[str]) -> str
"""You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if a... | def problem_spec
-- function signature
(implementation: List String β String)
-- inputs
(l: List String) :=
-- spec
let spec (result : String) :=
l.length = 2 β
l[0]!.all (fun c => c = '(' β¨ c = ')') β
l[1]!.all (fun c => c = '(' β¨ c = ')') β
let res := (balanced_paren_non_computable (l[0]! ++ l[1]!) '(' ')' β¨
... | def generated_spec
-- function signature
(impl: List String β String)
-- inputs
(l: List String) : Prop := | theorem spec_isomorphism:
β impl,
(β l, problem_spec impl l) β
(β l, generated_spec impl l) := | sorry | def implementation (l: List String) : String := | sorry | -- #test implementation ['()(', ')'] = "Yes"
-- #test implementation [')', ')'] = "No" | theorem correctness
(l: List String)
: problem_spec implementation l
:= | by
sorry | null | null | null |
def maximum(arr: List[int], k: int) -> List[int] | Given an array arr of integers and a positive integer k, return a sorted list of length
k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr)
| [{"input": [[2, 4, 3, 1], 3], "expected_output": [2, 3, 4]}, {"input": [[2, 4, 3, 1], 0], "expected_output": []}] | def maximum(arr: List[int], k: int) -> List[int]
"""Given an array arr of integers and a positive integer k, return a sorted list of length
k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].... | def problem_spec
-- function signature
(impl: List Int β Int β List Int)
-- inputs
(arr: List Int)
(k: Int) :=
-- spec
let spec (result: List Int) :=
1 β€ arr.length β arr.length β€ 1000 β arr.all (fun x => -1000 β€ x β§ x β€ 1000) β 0 β€ k β k β€ arr.length β
result.length = k β§
result.Sorted (Β· β€ Β·) β§
β x β ... | def generated_spec
-- function signature
(impl: List Int β Int β List Int)
-- inputs
(arr: List Int)
(k: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr k, problem_spec impl arr k) β
(β arr k, generated_spec impl arr k) := | sorry | def implementation (arr: List Int) (k: Int) : List Int := | sorry | -- #test implementation [2, 4, 3, 1] 3 = [2, 3, 4]
-- #test implementation [2, 4, 3, 1] 0 = [] | theorem correctness
(arr: List Int)
(k: Int)
: problem_spec implementation arr k := | sorry | null | null | null |
def solution(lst: List[int]) -> int | Given a non-empty list of integers, return the sum of all of the odd elements that
are in even positions.
| [{"input": [5, 8, 7, 1], "expected_output": 12}, {"input": [3, 3, 3, 3, 3], "expected_output": 9}, {"input": [30, 13, 24, 321], "expected_output": 0}] | def solution(lst: List[int]) -> int
"""Given a non-empty list of integers, return the sum of all of the odd elements that
are in even positions.
""" | def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result : Int) :=
lst β [] β β i, i < lst.length β§ i % 2 = 0 β
(lst.length = 1 β impl lst = 0) β§
(i + 1 < lst.length β
(lst[i + 1]! % 2 = 1 β
impl (lst.drop i) = lst[i + 1]! + (if i + 2 < lst.length ... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List Int) : Int := | sorry | -- #test implementation ([5, 8, 7, 1]: List Int) = 12
-- #test implementation ([3, 3, 3, 3, 3]: List Int) = 9
-- #test implementation ([30, 13, 24, 321]: List Int) = 0 | theorem correctness
(lst: List Int)
: problem_spec implementation lst := | sorry | null | null | null |
def add_elements(arr: List[int], k: int) -> int | Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr)
| [{"input": [[111, 21, 3, 4000, 5, 6, 7, 8, 9], 4], "expected_output": 24}] | def add_elements(arr: List[int], k: int) -> int
"""Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr)
""" | def problem_spec
-- function signature
(impl: List Int β Nat β Int)
-- inputs
(arr: List Int)
(k: Nat) :=
-- spec
let spec (result: Int) :=
1 β€ arr.length β arr.length β€ 100 β 1 β€ k β k β€ arr.length β
((β i, 0 β€ i β§ i < k β Β¬(arr[i]! β€ 99 β§ -99 β€ arr[i]!)) β result = 0) β§
β i, i < k
β§ arr[i]! β€ 99 β§ -99 β€ arr... | def generated_spec
-- function signature
(impl: List Int β Nat β Int)
-- inputs
(arr: List Int)
(k: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β arr k, problem_spec impl arr k) β
(β arr k, generated_spec impl arr k) := | sorry | def implementation (arr: List Int) (k: Nat) : Int := | sorry | -- #test implementation ([111, 21, 3, 4000, 5, 6, 7, 8, 9]: List Int) 4 = 24 | theorem correctness
(arr: List Int)
(k: Nat)
: problem_spec implementation arr k := | sorry | null | null | null |
def get_odd_collatz (n: int) -> List[int] | Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n. Then each term is obtained from the
previous term as follows: if the previous term is even... | [{"input": 5, "expected_output": [1, 5]}] | def get_odd_collatz (n: int) -> List[int]
"""Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n. Then each term is obtained from the
previous ... | def problem_spec
-- function signature
(impl: Nat β List Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: List Nat) :=
n > 0 β
result.Sorted (Β· < Β·) β§
β m, m β result β Odd m β§ collatz_reachable n m -- m is reachable from starting point n
-- program termination
β result, impl n = result β§
-- return value satisfies ... | def generated_spec
-- function signature
(impl: Nat β List Nat)
-- inputs
(n: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : List Nat := | sorry | -- #test implementation 5 = [1, 5] | theorem correctness
(n: Nat)
: problem_spec implementation n := | sorry | /--
name: collatz_reachable
use: |
Helper to check if a natural number m is reachable in the Collatz sequence starting at n.
problems:
- 123
-/
def collatz_reachable (n m : Nat) : Prop :=
β k, Nat.iterate (fun x => if x % 2 = 0 then x / 2 else x * 3 + 1) k n = m | null | null |
def valid_date(date: str) -> Bool | You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the numb... | [{"input": "03-11-2000", "expected_output": true}, {"input": "15-01-2012", "expected_output": false}, {"input": "04-0-2040", "expected_output": false}, {"input": "06-04-2020", "expected_output": true}, {"input": "06/04/2020", "expected_output": false}] | def valid_date(date: str) -> Bool
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for... | def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(date: String) :=
-- spec
let spec (result: Bool) :=
result = true β
β m1 m2 sep1 d1 d2 sep2 y1 y2 y3 y4 : Char,
date = String.mk [m1, m2, sep1, d1, d2, sep2, y1, y2, y3, y4] β§
sep1 = '-' β§ sep2 = '-' β§
[m1, m2, d1, d2, y1, y2, y3,... | def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(date: String) : Prop := | theorem spec_isomorphism:
β impl,
(β date, problem_spec impl date) β
(β date, generated_spec impl date) := | sorry | def implementation (date: String) : Bool := | sorry | -- #test implementation "03-11-2000" = true
-- #test implementation "15-01-2012" = false
-- #test implementation "04-0-2040" = false
-- #test implementation "06-04-2020" = true
-- #test implementation "06/04/2020" = false | theorem correctness
(date: String)
: problem_spec implementation date := | sorry | null | null | null |
def minPath(grid, k) | Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You have to find the minimum path of length k in the grid. You can start
from any cell, and in each step you c... | [{"input": [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3], "expected_output": [1, 2, 3]}, {"input": [[5, 9, 3], [4, 1, 6], [7, 8, 2], 1], "expected_output": [1]}] | def minPath(grid, k)
"""Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You have to find the minimum path of length k in the grid. You can start
from any cell... | def problem_spec
-- function signature
(impl: List (List Nat) β Nat β List Nat)
-- inputs
(grid: List (List Nat))
(k: Nat) :=
-- spec
let lexographically_less (a b: List Nat) : Prop :=
a.length = b.length β§ a.length = k β§
(β i, i < k β§ a.get! i < b.get! i β§
(β j, j < i β a.get! j = b.get! j));
let rec is_valid_pa... | def generated_spec
-- function signature
(impl: List (List Nat) β Nat β List Nat)
-- inputs
(grid: List (List Nat))
(k: Nat): Prop := | theorem spec_isomorphism:
β impl,
(β grid k, problem_spec impl grid k) β
(β grid k, generated_spec impl grid k) := | sorry | def implementation (grid: List (List Nat)) (k: Nat) : List Nat := | sorry | -- #test implementation [[1,2,3], [4,5,6], [7,8,9]] 3 = [1,2,3]
-- #test implementation [[5,9,3], [4,1,6], [7,8,2]] 1 = [1] | theorem correctness
(grid: List (List Nat))
(k: Nat)
: problem_spec implementation grid k := | sorry | null | null | null |
def is_sorted(lst: List[int]) -> Bool | Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.
| [{"input": [5], "expected_output": true}, {"input": [1, 2, 3, 4, 5], "expected_output": true}, {"input": [1, 3, 2, 4, 5], "expected_output": false}, {"input": [1, 2, 3, 4, 5, 6], "expected_outupt": true}, {"input": [1, 2, 3, 4, 5, 6, 7], "expected_output": true}, {"input": [1, 3, 2, 4, 5, 6, 7], "expected_output": fals... | def is_sorted(lst: List[int]) -> Bool
"""Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.
""" | def problem_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(lst: List Int) :=
-- spec
let sorted_ascending := lst.Sorted (Β· β€ Β·);
let ms := Multiset.ofList lst;
let multiple_duplicates := β i, i β lst β§ 2 < ms.count i;
let spec (res: Bool) :=
res β sorted_ascending β§
res β Β¬multiple_duplicates β§
mul... | def generated_spec
-- function signature
(impl: List Int β Bool)
-- inputs
(lst: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List Int) : Bool := | sorry | -- #test implementation [5] = true
-- #test implementation [1, 2, 3, 4, 5] = true
-- #test implementation [1, 3, 2, 4, 5] = false
-- #test implementation [1, 2, 3, 4, 5, 6] = true
-- #test implementation [1, 2, 3, 4, 5, 6, 7] = true
-- #test implementation [1, 3, 2, 4, 5, 6, 7] = false
-- #test implementation [1, 2, 2,... | theorem correctness
(lst: List Int)
: problem_spec implementation lst := | sorry | null | null | null |
def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str | You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to de... | [{"input": ["(1", "2)", "(2", "3)"], "expected_output": "NO"}, {"input": ["(-1", "1)", "(0", "4)"], "expected_output": "NO"}, {"input": ["(-3", "-1)", "(-5", "5)"], "expected_output": "YES"}] | def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str
"""You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given ... | def problem_spec
-- function signature
(impl: Int Γ Int β Int Γ Int β String)
-- inputs
(interval1: Int Γ Int)
(interval2: Int Γ Int) :=
-- spec
let spec (result: String) :=
let (s1, e1) := interval1;
let (s2, e2) := interval2;
s1 β€ e1 β s2 β€ e2 β
let intersectionStart := max s1 s2;
let intersectionEnd := min e1 e2;
le... | def generated_spec
-- function signature
(impl: Int Γ Int β Int Γ Int β String)
-- inputs
(interval1: Int Γ Int)
(interval2: Int Γ Int) : Prop := | theorem spec_isomorphism:
β impl,
(β interval1 interval2, problem_spec impl interval1 interval2) β
(β interval1 interval2, generated_spec impl interval1 interval2) := | sorry | def implementation (interval1: Int Γ Int) (interval2: Int Γ Int) : String := | sorry | -- #test implementation (1, 2) (2, 3) = "NO"
-- #test implementation (-1, 1) (0, 4) = "NO"
-- #test implementation (-3, -1) (-5, 5) = "YES" | theorem correctness
(interval1: Int Γ Int)
(interval2: Int Γ Int)
: problem_spec implementation interval1 interval2 := | sorry | null | null | null |
def prod_signs(arr: List[int]) -> Optional[int] | You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.
| [{"input": [1, 2, 2, -4], "expected_output": -9}, {"input": [0, 1], "expected_output": 0}, {"input": [], "expected_output": "None"}] | def prod_signs(arr: List[int]) -> Optional[int]
"""You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.
""" | def problem_spec
-- function signature
(impl: List Int β Option Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Option Int) :=
match result with
| none => arr = []
| some result =>
let magnitude_sum := (arr.map (fun x => Int.ofNat x.natAbs)).sum;
let neg_count_odd := (arr.filter (fun x => x < 0)... | def generated_spec
-- function signature
(impl: List Int β Option Int)
-- inputs
(arr: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) := | sorry | def implementation (arr: List Int) : Option Int := | sorry | -- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int)
-- #test implementation ([0, 1]: List Int) = (0: Int)
-- #test implementation ([]: List Int) = none | theorem correctness
(arr: List Int)
: problem_spec implementation arr := | sorry | null | null | null |
def split_words(txt) | Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
| [{"input": "Hello world!", "expected_output": ["Hello", "world!"]}, {"input": "Hello,world!", "expected_output": ["Hello", "world!"]}, {"input": "abcdef", "expected_output": 3}] | def split_words(txt)
"""Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
""" | def problem_spec
-- function signature
-- return a tuple of Option (List String) and Option Nat
(impl: String β Option (List String) Γ Option Nat)
-- inputs
(text: String) :=
-- spec
let spec (result: Option (List String) Γ Option Nat) :=
-- both cannot be None
let words := result.fst;
let ord := result.snd;
0 ... | def generated_spec
-- function signature
(impl: String β Option (List String) Γ Option Nat)
-- inputs
(text: String) : Prop := | theorem spec_isomorphism:
β impl,
(β text, problem_spec impl text) β
(β text, generated_spec impl text) := | sorry | def implementation (text: String) : Option (List String) Γ Option Nat := | sorry | -- #test implementation "Hello world!" = (some ["Hello", "world!"], none)
-- #test implementation "Hello,world!" = (some ["Hello", "world!"], none)
-- #test implementation "abcdef" = (none, some 3) | theorem correctness
(text: String)
: problem_spec implementation text := | sorry | null | null | null |
def tri(n: int) -> List[int] | Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
For... | [{"input": 3, "expected_output": [1, 3, 2, 8]}] | def tri(n: int) -> List[int]
"""Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) = tri(n - 1) + tri(n - 2... | def problem_spec
-- function signature
(impl: Nat β List Int)
-- inputs
(n: Nat) :=
-- spec
let spec (result: List Int) :=
0 < result.length β§
result.length = n β§
let i := result.length-1;
(i = 0 β result[0]! = 1) β§ -- base case
(i = 1 β result[1]! = 3) β§
(2 β€ i β§ i % 2 = 0 β result[i]! = 1 + i / 2) β§
(2 ... | def generated_spec
-- function signature
(impl: Nat β List Int)
-- inputs
(n: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : List Int:= | sorry | -- #test implementation 3 = [1, 3, 2, 8] | theorem correctness
(n: Nat)
: problem_spec implementation n := | sorry | null | null | null |
def digits(n: int) -> int | Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
| [{"input": 1, "expected_output": 1}, {"input": 4, "expected_output": 0}, {"input": 235, "expected_output": 15}] | def digits(n: int) -> int
"""Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
""" | def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
0 < n β
(n < 10 β (n % 2 = 1 β result = n) β§ (n % 2 = 0 β result = 0)) β§
(10 β€ n β
let digit := n % 10;
let rest := n / 10;
(digit % 2 = 1 β
if (Nat.toDigits 10 rest).all (fun x => Ev... | def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : Nat := | sorry | -- #test implementation 1 = 1
-- #test implementation 4 = 0
-- #test implementation 235 = 15 | theorem correctness
(n: Nat)
: problem_spec implementation n := | sorry | null | null | null |
def is_nested(string: str) -> Bool | Create a function that takes a string as input which contains only parentheses.
The function should return True if and only if there is a valid subsequence of parentheses
where at least one parenthesis in the subsequence is nested.
| [{"input": "(())", "expected_output": true}, {"input": "()))))))((((()", "expected_output": false}, {"input": "()()", "expected_output": false}, {"input": "()", "expected_output": false}, {"input": "(()())", "expected_output": true}, {"input": "(())((", "expected_output": true}] | def is_nested(string: str) -> Bool
"""Create a function that takes a string as input which contains only parentheses.
The function should return True if and only if there is a valid subsequence of parentheses
where at least one parenthesis in the subsequence is nested.
""" | def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(string: String) :=
-- spec
let spec (result: Bool) :=
string.toList.all (fun x => x = '(' β¨ x = ')') β
result = true β
β x : String,
is_subsequence x.toList string.toList β§
balanced_paren_non_computable x '(' ')' β§
2 β€ count_max_paren... | def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(lst: String) : Prop := | theorem spec_isomorphism:
β impl,
(β string, problem_spec impl string) β
(β string, generated_spec impl string) := | sorry | def implementation (lst: String) : Bool := | sorry | -- #test implementation "(())" = true
-- #test implementation "()))))))((((()" = false
-- #test implementation "()()" = false
-- #test implementation "()" = false
-- #test implementation "(()())" = true
-- #test implementation "(())((" = true | theorem correctness
(string: String)
: problem_spec implementation string := | sorry | /--
name: string_is_paren_balanced_helper
use: |
Helper function to check if a string is balanced with respect to parentheses.
problems:
- 1
- 6
- 132
sample_problems:
- 0
-/
def string_is_paren_balanced_helper
(paren_string: String) (num_open: Int): Bool
:=
-- Recursively check if the string is balanced
if p... | null | null |
def sum_squares(lst: List[float]) -> int | You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
| [{"input": [1, 2, 3], "expected_output": 14}, {"input": [1, 4, 9], "expected_output": 98}, {"input": [1, 3, 5, 7], "expected_output": 84}, {"input": [1.4, 4.2, 0], "expected_output": 29}, {"input": [-2.4, 1, 1], "expected_output": 6}] | def sum_squares(lst: List[float]) -> int
"""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
""" | def problem_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(lst: List Rat) :=
-- spec
let spec (result: Int) :=
(lst = [] β result = 0) β§
(lst != [] β 0 β€ result - lst[0]!.ceil^2 β§ (impl (lst.drop 1) = (result - lst[0]!.ceil^2)))
-- program termination
β result, impl lst = result β§
-- return value sati... | def generated_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(lst: List Rat) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List Rat) : Int := | sorry | -- #test implementation [1, 2, 3] = 14
-- #test implementation [1, 4, 9] = 98
-- #test implementation [1, 3, 5, 7] = 84
-- #test implementation [1.4, 4.2, 0] = 29
-- #test implementation [-2.4, 1, 1] = 6 | theorem correctness
(lst: List Rat)
: problem_spec implementation lst := | sorry | null | null | null |
def check_if_last_char_is_a_letter(txt: str) -> Bool | Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: "word" is a group of characters separated by space.
| [{"input": "apple pie", "expected_output": false}, {"input": "apple pi e", "expected_output": true}, {"input": "apple pi e ", "expected_output": false}, {"input": "", "expected_output": false}] | def check_if_last_char_is_a_letter(txt: str) -> Bool
"""Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: "word" is a group of characters separated by space.
""" | def problem_spec
-- function signature
(impl: String β Bool)
-- inputs
(txt: String) :=
-- spec
let spec (result: Bool) :=
let words := txt.splitOn " ";
match words with
| [] => result = False
| [last_word] => (result β last_word.length = 1 β§ (let diff := (last_word.get 0).toLower.toNat - 'a'.toNat; 0 β€ diff β§ ... | def generated_spec
-- function signature
(impl: String β Bool)
-- inputs
(txt: String) : Prop := | theorem spec_isomorphism:
β impl,
(β txt, problem_spec impl txt) β
(β txt, generated_spec impl txt) := | sorry | def implementation (txt: String) : Bool := | sorry | -- #test implementation "apple pie" = false
-- #test implementation "apple pi e" = true
-- #test implementation "apple pi e " = false
-- #test implementation "" = false | theorem correctness
(txt: String)
: problem_spec implementation txt := | sorry | null | null | null |
def can_arrange(arr: List[int]) -> int | Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate values.
| [{"input": [1, 2, 4, 3, 5], "expected_output": 3}, {"input": [1, 2, 3], "expected_output": -1}] | def can_arrange(arr: List[int]) -> int
"""Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate values.
""" | def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) :=
-- spec
let spec (result: Int) :=
Β¬arr.any (fun x => 1 < arr.count x) β
(arr.length = 0 β¨ arr.length = 1 β result = -1) β§
(1 < arr.length β
let last := arr.length-1;
let i := if arr[last]! < arr[last-1]! then Int.of... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(arr: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β arr, problem_spec impl arr) β
(β arr, generated_spec impl arr) := | sorry | def implementation (arr: List Int) : Int := | sorry | -- #test implementation [1, 2, 4, 3, 5] = 3
-- #test implementation [1, 2, 3] = -1 | theorem correctness
(arr: List Int)
: problem_spec implementation arr := | sorry | null | null | null |
def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ] | Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as None.
| [{"input": [2, 4, 1, 3, 5, 7], "expected_output": "(None, 1)"}, {"input": [], "expected_output": "(None, None)"}, {"input": [0], "expected_output": "(None, None)"}] | def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ]
"""Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as None.
""" | def problem_spec
-- function signature
(impl: List Int β Option Int Γ Option Int)
-- inputs
(lst: List Int) :=
-- spec
let spec (result: Option Int Γ Option Int) :=
let (a, b) := result;
(match a with
| none => Β¬(β i, i β lst β§ i < 0)
| some a => a < 0 β§ a β lst β§ β i, i β lst β§ i < 0 β i β€ a) β§
(match b with... | def generated_spec
-- function signature
(impl: List Int β Option Int Γ Option Int)
-- inputs
(lst: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List Int) : (Option Int Γ Option Int) := | sorry | -- #test implementation [2, 4, 1, 3, 5, 7] = (none, some 1)
-- #test implementation [] = (none, none)
-- #test implementation [0] = (none, none) | theorem correctness
(lst: List Int)
: problem_spec implementation lst := | sorry | null | null | null |
def is_equal_to_sum_even(n: int) -> Bool | Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
| [{"input": 4, "expected_output": false}, {"input": 6, "expected_output": false}, {"input": 8, "expected_output": true}] | def is_equal_to_sum_even(n: int) -> Bool
"""Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
""" | def problem_spec
-- function signature
(impl: Int β Bool)
-- inputs
(n: Int) :=
-- spec
let spec (result: Bool) :=
let sum_exists := β a b c d : Nat,
Even a β§
Even b β§
Even c β§
Even d β§
(a + b + c + d = n);
result = true β sum_exists
-- program termination
β result, impl n = result β§
-- return v... | def generated_spec
-- function signature
(impl: Int β Bool)
-- inputs
(n: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Int) : Bool := | sorry | -- #test implementation 4 = false
-- #test implementation 6 = false
-- #test implementation 8 = true | theorem correctness
(n: Int)
: problem_spec implementation n := | sorry | null | null | null |
def special_factorial(n: int) -> int | The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0. Please write a function that computes the Brazilian factorial.
| [{"input": 4, "expected_output": 288}] | def special_factorial(n: int) -> int
"""The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0. Please write a function that computes the Brazilian factorial.
""" | def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
let factorial := Nat.factorial n;
(0 < n β result / factorial = impl (n - 1)) β§
(n = 0 β result = 1);
-- program termination
β result, impl n = result β§
-- return value satisfies spec
spec result | def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : Nat := | sorry | -- #test implementation 4 = 288 | theorem correctness
(n: Nat)
: problem_spec implementation n := | sorry | null | null | null |
def fix_spaces(text: str) -> str | Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with -
| [{"input": "Example", "expected_output": "Example"}, {"input": "Example 1", "expected_output": "Example_1"}, {"input": " Example 2", "expected_output": "_Example_2"}, {"input": " Example 3", "expected_output": "_Example-3"}] | def fix_spaces(text: str) -> str
"""Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with -
""" | def problem_spec
-- function signature
(impl: String β String)
-- inputs
(text: String) :=
-- spec
let spec (result: String) :=
(result = "" β text = "") β§
(result β "" β (
(β pref s, text = pref ++ s
β§ pref.length = 1
β§ pref β " "
β§ result = pref ++ impl s)
β¨
(β pref s : String, text ... | def generated_spec
-- function signature
(impl: String β String)
-- inputs
(text: String) : Prop := | theorem spec_isomorphism:
β impl,
(β text, problem_spec impl text) β
(β text, generated_spec impl text) := | sorry | def implementation (text: String) : String := | sorry | -- #test implementation "Example" = "Example"
-- #test implementation "Example 1" = "Example_1"
-- #test implementation " Example 2" = "_Example_2"
-- #test implementation " Example 3" = "_Example-3" | theorem correctness
(text: String)
: problem_spec implementation text := | sorry | null | null | null |
def file_name_check(file_name: str) -> str | Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The ... | [{"input": "example.txt", "expected_output": "Yes"}, {"input": "1example.dll", "expected_output": "No"}] | def file_name_check(file_name: str) -> str
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than thr... | def problem_spec
-- function signature
(impl: String β String)
-- inputs
(file_name : String) :=
-- spec
let spec (result: String) :=
let valid := (file_name.toList.filter Char.isDigit).length β€ 3 β§
(file_name.toList.filter (Β· = '.')).length = 1 β§
β before after : String,
file_name = before ++ "." ++ after β§
... | def generated_spec
-- function signature
(impl: String β String)
-- inputs
(file_name: String) : Prop := | theorem spec_isomorphism:
β impl,
(β file_name, problem_spec impl file_name) β
(β file_name, generated_spec impl file_name) := | sorry | def implementation (file_name : String) : String := | sorry | -- #test implementation "example.txt" = "Yes"
-- #test implementation "1example.dll" = "No" | theorem correctness
(file_name : String)
: problem_spec implementation file_name := | sorry | null | null | null |
def sum_squares(lst: List[int]) -> int | This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries in the list whose indexes are not a multi... | [{"input": [1, 2, 3], "expected_output": 6}, {"input": [], "expected_output": 0}, {"input": [-1, -5, 2, -1, -5], "expected_output": -126}] | def sum_squares(lst: List[int]) -> int
"""This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries... | def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst : List Int) :=
-- spec
let spec (result : Int) :=
let last := lst.length-1;
(lst = [] β result = 0) β§
(lst β [] β§ last % 3 = 0 β result = lst[last]! ^ 2 + impl (lst.take last)) β§
(lst β [] β§ last % 4 = 0 β§ last % 3 != 0 β result = lst[last]! ^... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(lst : List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst : List Int) : Int := | sorry | -- #test implementation [1, 2, 3] = 6
-- #test implementation [] = 0
-- #test implementation [-1, -5, 2, -1, -5] = -126 | theorem correctness
(lst : List Int)
: problem_spec implementation lst := | sorry | null | null | null |
def words_in_sentence(sentence: str) -> str | You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be the same as the original one.
Constraints:
* 1 <... | [{"input": "This is a test", "expected_output": "is"}, {"input": "lets go for swimming", "expected_output": "go for"}] | def words_in_sentence(sentence: str) -> str
"""You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be th... | def problem_spec
-- function signature
(impl: String β String)
-- inputs
(sentence: String) :=
-- spec
let spec (result: String) :=
let words := sentence.splitOn;
let result_words := result.splitOn;
1 β€ sentence.length β sentence.length β€ 100 β
sentence.all (fun x => Char.isAlpha x) β
result_words.length β€ words.... | def generated_spec
-- function signature
(impl: String β String)
-- inputs
(sentence: String) : Prop := | theorem spec_isomorphism:
β impl,
(β sentence, problem_spec impl sentence) β
(β sentence, generated_spec impl sentence) := | sorry | def implementation (sentence : String) : String := | sorry | -- #test implementation "This is a test" = "is"
-- #test implementation "lets go for swimming" = "go for" | theorem correctness
(sentence : String)
: problem_spec implementation sentence := | sorry | null | null | null |
def simplify(x: str, n: str) -> Bool | Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where both numerator and denominator are posit... | [{"input": ["1/5", "5/1"], "expected_output": true}, {"input": ["1/6", "2/1"], "expected_output": false}, {"input": ["7/10", "10/2"], "expected_output": false}] | def simplify(x: str, n: str) -> Bool
"""Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where ... | def problem_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(x: String) (n: String) :=
-- spec
let spec (result: Bool) :=
let fx := x.splitOn "/";
let fn := n.splitOn "/";
fx.length = 2 β fn.length = 2 β
fx.all String.isNat β fn.all String.isNat β
let p1 := fx[0]!.toNat!;
let q1 := fx[1]!.toNat!;
le... | def generated_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(x: String) (n: String) : Prop := | theorem spec_isomorphism:
β impl,
(β x n, problem_spec impl x n) β
(β x n, generated_spec impl x n) := | sorry | def implementation (x: String) (n: String) : Bool := | sorry | -- #test implementation "1/5" "5/1" = True
-- #test implementation "1/6" "2/1" = False
-- #test implementation "7/10" "10/2" = False | theorem correctness
(x: String) (n: String)
: problem_spec implementation x n := | sorry | null | null | null |
def order_by_points(nums: List[int]) -> List[int] | Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original list.
| [{"input": [1, 11, -1, -11, -12], "expected_output": [-1, -11, 1, -12, 11]}, {"input": [], "expected_output": []}] | def order_by_points(nums: List[int]) -> List[int]
"""Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original list.
""" | def problem_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result: List Int) :=
List.Perm nums result β§
match result with
| [] => nums = []
| head::tail =>
let head_sum := digit_sum head;
(β num β nums,
let sum := digit_sum num;
sum > head_sum β¨
(su... | def generated_spec
-- function signature
(impl: List Int β List Int)
-- inputs
(nums: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) := | sorry | def implementation (nums: List Int) : List Int := | sorry | -- #test implementation [1, 11, -1, -11, -12] = [-1, -11, 1, -12, 11]
-- #test implementation [] = [] | theorem correctness
(nums: List Int)
: problem_spec implementation nums := | sorry | /--
name: digit_sum
use: |
Helper to sum the digits of a number. If the number is negative, the
negative sign is treated as part of the first digit.
problems:
- 145
-/
def digit_sum (n : Int) : Int :=
let ds := (toString n.natAbs).toList.map fun c => c.toNat - Char.toNat '0'
match ds with
| [] => 0
| d ::... | null | null |
def specialFilter(nums: List[int]) -> int | Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
| [{"input": [15, -73, 14, -15], "expected_output": 1}, {"input": [33, -2, -3, 45, 21, 109], "expected_output": 2}] | def specialFilter(nums: List[int]) -> int
"""Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9).
""" | def problem_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) :=
-- spec
let spec (result: Int) :=
match nums with
| [] => result = 0
| head::tail =>
let first_digit := (toString head.natAbs).toList[0]!.toNat - Char.toNat '0';
let last_digit := head % 10;
let valid := head > 10 β§ Odd fi... | def generated_spec
-- function signature
(impl: List Int β Int)
-- inputs
(nums: List Int) : Prop := | theorem spec_isomorphism:
β impl,
(β nums, problem_spec impl nums) β
(β nums, generated_spec impl nums) := | sorry | def implementation (nums: List Int) : Int := | sorry | -- #test implementation [15, -73, 14, -15] = 1
-- #test implementation [33, -2, -3, 45, 21, 109] = 2 | theorem correctness
(nums: List Int)
: problem_spec implementation nums := | sorry | null | null | null |
def get_max_triples(n: int) -> int | You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
| [{"input": 5, "expected_output": 1}] | def get_max_triples(n: int) -> int
"""You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3.
""" | def problem_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(n: Nat) :=
-- spec
let spec (result: Nat) :=
β (S : Finset (Nat Γ Nat Γ Nat)), S.card = result β§
β (triple: Nat Γ Nat Γ Nat),
let (i, j, k) := triple;
let a_i := i * i - i + 1;
let a_j := j * j - j + 1;
let a_k := k * k - k + 1;
(... | def generated_spec
-- function signature
(impl: Nat β Nat)
-- inputs
(nums: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β n, problem_spec impl n) β
(β n, generated_spec impl n) := | sorry | def implementation (n: Nat) : Nat := | sorry | -- #test implementation 5 = 1 | theorem correctness
(n: Nat)
: problem_spec implementation n := | sorry | null | null | null |
def bf(planet1: str, planet2: str) -> List[str] | There are eight planets in our solar system: the closest to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings planet1 and planet2.
The function should return a tuple containing all planets whose orbits are
located betwe... | [{"input": "(\"Jupiter\", \"Neptune\")", "expected_output": "(\"Saturn\", \"Uranus\")"}, {"input": "(\"Earth\", \"Mercury\")", "expected_output": "(\"Venus\")"}, {"input": "(\"Mercury\", \"Uranus\")", "expected_output": "(\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")"}] | def bf(planet1: str, planet2: str) -> List[str]
"""There are eight planets in our solar system: the closest to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings planet1 and planet2.
The function should return a tuple co... | def problem_spec
-- function signature
(impl: String β String β List String)
-- inputs
(planet1: String)
(planet2: String) :=
-- spec
let spec (result: List String) :=
let planets := ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"];
if planet1 β planets β¨ planet2 β planets then
result =... | def generated_spec
-- function signature
(impl: String β String β List String)
-- inputs
(planet1: String)
(planet2: String) : Prop := | theorem spec_isomorphism:
β impl,
(β planet1 planet2, problem_spec impl planet1 planet2) β
(β planet1 planet2, generated_spec impl planet1 planet2) := | sorry | def implementation (planet1: String) (planet2: String) : List String := | sorry | -- #test implementation "Jupiter" "Neptune" = ["Saturn", "Uranus"]
-- #test implementation "Earth" "Mercury" = ["Venus"]
-- #test implementation "Mercury" "Uranus" = ["Venus", "Earth", "Mars", "Jupiter", "Saturn"] | theorem correctness
(planet1: String)
(planet2: String)
: problem_spec implementation planet1 planet2 := | sorry | null | null | null |
def sorted_list_sum(lst: List[str]) -> List[str] | Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an array of numbers,
and it may contain duplicates.
The order of the list should be ascending by length of ... | [{"input": ["aa", "a", "aaa"], "output": ["aa"]}, {"input": ["ab", "a", "aaa", "cd"], "output": ["ab", "cd"]}] | def sorted_list_sum(lst: List[str]) -> List[str]
"""Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an array of numbers,
and it may contain duplicates.
The... | def problem_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) :=
-- spec
let spec (result: List String) :=
match result with
| [] => β str β lst, Odd str.length
| head::tail =>
Even head.length β§
(β str β lst,
Odd str.length β¨
str.length > head.length β¨
str.length... | def generated_spec
-- function signature
(impl: List String β List String)
-- inputs
(lst: List String) : Prop := | theorem spec_isomorphism:
β impl,
(β lst, problem_spec impl lst) β
(β lst, generated_spec impl lst) := | sorry | def implementation (lst: List String) : List String := | sorry | -- #test implementation ["aa", "a", "aaa"] = ["aa"]
-- #test implementation ["ab", "a", "aaa", "cd"] = ["ab", "cd"] | theorem correctness
(lst: List String)
: problem_spec implementation lst := | sorry | null | null | null |
def x_or_y(int n, int x, int y) -> int | A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise.
| [{"input": [7, 34, 12], "expected_output": 34}, {"input": [15, 8, 5], "expected_output": 5}] | def x_or_y(int n, int x, int y) -> int
"""A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise.
""" | def problem_spec
-- function signature
(impl: Int β Int β Int β Int)
-- inputs
(n x y: Int) :=
-- spec
let spec (result: Int) :=
(result = x β Nat.Prime n.toNat) β§
(result = y β (Β¬ Nat.Prime n.toNat β¨ n β€ 1))
-- program terminates
β result, impl n x y = result β§
-- return value satisfies spec
spec result | def generated_spec
-- function signature
(impl: Int β Int β Int β Int)
-- inputs
(n x y: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β n x y, problem_spec impl n x y) β
(β n x y, generated_spec impl n x y) := | sorry | def implementation (n x y: Int) : Int := | sorry | -- #test implementation 7 34 12 = 34
-- #test implementation 15 8 5 = 5 | theorem correctness
(n x y: Int)
: problem_spec implementation n x y := | sorry | null | null | null |
def double_the_difference(numbers: List[float]) -> Int | Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
| [{"input": [1, 3, 2, 0], "expected_output": 10}, {"input": ["-1. -2", 0], "expected_output": 0}, {"input": [9, -2], "expected_output": 81}, {"input": [0], "expected_output": 0}] | def double_the_difference(numbers: List[float]) -> Int
"""Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
""" | def problem_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(numbers: List Rat) :=
let isEven (n : Rat) := n % 2 = 0;
let isNegative (n : Rat) := n < 0;
let isNotInteger (n : Rat) := Β¬ n.isInt;
-- spec
let spec (result: Int) :=
0 < numbers.length β
0 β€ result β§
if numbers.length = 1
then result = if (isEven... | def generated_spec
-- function signature
(impl: List Rat β Int)
-- inputs
(numbers: List Rat) : Prop := | theorem spec_isomorphism:
β impl,
(β numbers, problem_spec impl numbers) β
(β numbers, generated_spec impl numbers) := | sorry | def implementation (numbers: List Rat) : Int := | sorry | -- #test implementation ([1, 3, 2, 0]: List Rat) = (10: Int)
-- #test implementation ([-1, -2, 0]: List Int) = (0: Int)
-- #test implementation ([9, -2]: List Int) = 81
-- #test implementation ([0]: List Int) = 0 | theorem correctness
(numbers: List Rat)
: problem_spec implementation numbers := | sorry | null | null | null |
def compare(scores: List float, guesses: List float) -> List [float] | I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to determine if a person correctly guessed the results of a number of matches.
You are given two arrays of scor... | [{"input": [[1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2]], "expected_output": [0, 0, 0, 0, 3, 3]}, {"input": [[0, 5, 0, 0, 0, 4], [4, 1, 1, 0, 0, -2]], "expected_output": [4, 4, 1, 0, 0, 6]}] | def compare(scores: List float, guesses: List float) -> List [float]
"""I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to determine if a person correctly gues... | def problem_spec
-- function signature
(impl: List Rat β List Rat β List Rat)
-- inputs
(scores guesses: List Rat) :=
-- spec
let spec (result: List Rat) :=
result.length = scores.length β§
scores.length = guesses.length β§
β i, i < scores.length β
if scores[i]! > guesses[i]! then result[i]! + guesses[i]! = score... | def generated_spec
-- function signature
(impl: List Rat β List Rat β List Rat)
-- inputs
(scores guesses: List Rat) : Prop := | theorem spec_isomorphism:
β impl,
(β scores guesses, problem_spec impl scores guesses) β
(β scores guesses, generated_spec impl scores guesses) := | sorry | def implementation (scores guesses: List Rat) : List Rat := | sorry | -- #test implementation [1,2,3,4,5,1] [1,2,3,4,2,-2] = [0,0,0,0,3,3]
-- #test implementation [0,5,0,0,0,4] [4,1,1,0,0,-2] = [4,4,1,0,0,6] | theorem correctness
(scores guesses: List Rat)
: problem_spec implementation scores guesses := | sorry | null | null | null |
def Strongest_Extension(class_name: String, extensions: List[String]) -> String | You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the number of the uppercase
letters in the extension's name, and let SM be the number of lowercase letters
in the exte... | [{"input": ["my_class", ["AA", "Be", "CC"]], "expected_output": "my_class.AA"}] | def Strongest_Extension(class_name: String, extensions: List[String]) -> String
"""You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the number of the uppercase
letters... | def problem_spec
-- function signature
(impl: String β List String β String)
-- inputs
(class_name: String)
(extensions: List String) :=
let strength (extension: String) :=
let cap := (extension.toList.filter (fun c => c.isUpper)).length;
let sm := (extension.toList.filter (fun c => c.isLower)).length;
cap - sm;
... | def generated_spec
-- function signature
(impl: String β List String β String)
-- inputs
(class_name: String)
(extensions: List String) : Prop := | theorem spec_isomorphism:
β impl,
(β class_name extensions, problem_spec impl class_name extensions) β
(β class_name extensions, generated_spec impl class_name extensions) := | sorry | def implementation (class_name: String) (extensions: List String) : String := | sorry | -- #test implementation 'my_class', ['AA', 'Be', 'CC'] = 'my_class.AA' | theorem correctness
(class_name: String)
(extensions: List String)
: problem_spec implementation class_name extensions := | sorry | null | null | null |
def cycpattern_check(String a, String b) -> Bool | You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False
| [{"input": ["abcd", "abd"], "expected_output": false}, {"input": ["hello", "ell"], "expected_output": true}, {"input": ["whassup", "psus"], "expected_output": false}, {"input": ["abab", "baa"], "expected_output": true}, {"input": ["efef", "eeff"], "expected_output": false}, {"input": ["himenss", "simen"], "expected_out... | def cycpattern_check(String a, String b) -> Bool
"""You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False
""" | def problem_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(a b: String) :=
-- spec
let spec (result: Bool) :=
(b.length = 0 β result) β§
(0 < b.length β
result β ((b.length β€ a.length) β§
(β i : Nat, i < b.length β§
let b_rotation := b.drop i ++ b.take i;
a.containsSubstr b_rotation)));
-- prog... | def generated_spec
-- function signature
(impl: String β String β Bool)
-- inputs
(a b: String) : Prop := | theorem spec_isomorphism:
β impl,
(β a b, problem_spec impl a b) β
(β a b, generated_spec impl a b) := | sorry | def implementation (a b: String) : Bool := | sorry | -- #test implementation "abcd" "abd" = False
-- #test implementation "hello" "ell" = True
-- #test implementation "whassup" "psus" = False
-- #test implementation "abab" "baa" = True
-- #test implementation "efef" "eeff" = False
-- #test implementation "himenss" "simen" = True | theorem correctness
(a b: String)
: problem_spec implementation a b := | sorry | null | null | null |
def even_odd_count(num: int) -> Tuple[int, int] | Given an integer. return a tuple that has the number of even and odd digits respectively.
| [{"input": -12, "expected_output": [1, 1]}, {"input": 123, "expected_output": [1, 2]}] | def even_odd_count(num: int) -> Tuple[int, int]
"""Given an integer. return a tuple that has the number of even and odd digits respectively.
""" | def problem_spec
-- function signature
(impl: Int β Int Γ Int)
-- inputs
(num: Int) :=
-- spec
let spec (result: Int Γ Int) :=
let (even_count, odd_count) := result;
let numAbs := |num|.toNat;
let numBy10 := numAbs/10;
let (even_count', odd_count') := impl numBy10;
(result = impl numAbs) β§
(0 β€ num β (Even ... | def generated_spec
-- function signature
(impl: Int β Int Γ Int)
-- inputs
(num: Int) : Prop := | theorem spec_isomorphism:
β impl,
(β num, problem_spec impl num) β
(β num, generated_spec impl num) := | sorry | def implementation (num: Int) : Int Γ Int := | sorry | -- #test implementation -12 = (1, 1)
-- #test implementation 123 = (1, 2) | theorem correctness
(num: Int)
: problem_spec implementation num := | sorry | null | null | null |
def int_to_mini_roman(num: Nat) -> String | Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
| [{"input": 19, "expected_output": "xix"}, {"input": 152, "expected_output": "clii"}, {"input": 426, "expected_output": "cdxxvi"}] | def int_to_mini_roman(num: Nat) -> String
"""Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
""" | def problem_spec
-- function signature
(impl: Nat β String)
-- inputs
(num: Nat) :=
-- spec
let spec (result: String) :=
1 β€ num β§ num β€ 1000 β§ (result.data.all (fun c => c.isLower)) β
isValidRoman result β§ romanToDecimal result = num
-- program terminates
β result, impl num = result β§
-- return value satisfies spec
sp... | def generated_spec
-- function signature
(impl: Nat β String)
-- inputs
(num: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β num, problem_spec impl num) β
(β num, generated_spec impl num) := | sorry | def implementation (num: Nat) : String := | sorry | -- #test implementation 19 = "xix"
-- #test implementation 152 = "clii"
-- #test implementation 426 = "cdxxvi" | theorem correctness
(num: Nat)
: problem_spec implementation num := | sorry | /--
name: romanCharToValue
use: |
Map from valid characters and their values
problems:
- 156
sample_problems: []
-/
def romanCharToValue : Char β Nat
| 'i' => 1
| 'v' => 5
| 'x' => 10
| 'l' => 50
| 'c' => 100
| 'd' => 500
| 'm' => 1000
| _ => 0
/--
name: validSubtractivePairs
use: |
Legal subtractive pairs: fi... | null | null |
def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool | Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 degree.
| [{"input": [3, 4, 5], "expected_output": true}, {"input": [1, 2, 3], "expected_output": false}] | def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool
"""Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 degree.
""" | def problem_spec
-- function signature
(impl: Nat β Nat β Nat β Bool)
-- inputs
(a b c: Nat) :=
-- spec
let spec (result: Bool) :=
result β
0 < a β§ 0 < b β§ 0 < c β§
((a * a + b * b = c * c) β¨
(a * a + c * c = b * b) β¨
(b * b + c * c = a * a))
-- program terminates
β result, impl a b c = result β§
-- return value ... | def generated_spec
-- function signature
(impl: Nat β Nat β Nat β Bool)
-- inputs
(a b c: Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) := | sorry | def implementation (a b c: Nat) : Bool := | sorry | -- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int)
-- #test implementation ([0, 1]: List Int) = (0: Int)
-- #test implementation ([]: List Int) = none | theorem correctness
(a b c: Nat)
: problem_spec implementation a b c := | sorry | null | null | null |
def find_max(words: List String) -> String | Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order.
| [{"input": ["name", "of", "string"], "expected_output": "string"}, {"input": ["name", "enam", "game"], "expected_output": "enam"}, {"input": ["aaaaaaa", "bb", "cc"], "expected_output": "aaaaaaa"}] | def find_max(words: List String) -> String
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order.
""" | def problem_spec
-- function signature
(impl: List String β String)
-- inputs
(words: List String) :=
let unique_chars (string: String) :=
let string_idx := {i: Nat | i < string.length}.toFinset;
let characters := string_idx.image (fun i => string.toList.get! i);
characters.card;
-- spec
let spec (result: String)... | def generated_spec
-- function signature
(impl: List String β String)
-- inputs
(words: List String) : Prop := | theorem spec_isomorphism:
β impl,
(β words, problem_spec impl words) β
(β words, generated_spec impl words) := | sorry | def implementation (words: List String) : String := | sorry | -- #test implementation ["name", "of", "string"]= "string"
-- #test implementation ["name", "enam", "game"] = "enam"
-- #test implementation ["aaaaaaa", "bb" ,"cc"] = "aaaaaaa" | theorem correctness
(words: List String)
: problem_spec implementation words := | sorry | null | null | null |
def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat | You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots after your meals,
the number of carrots left after your meals ]
if there are not... | [{"input": [5, 6, 10], "expected_output": [11, 4]}, {"input": [4, 8, 9], "expected_output": [12, 1]}, {"input": [1, 10, 10], "expected_output": [11, 0]}, {"input": [2, 11, 5], "expected_output": [7, 0]}] | def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat
"""You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots after your meals,
... | def problem_spec
-- function signature
(impl: Nat β Nat β Nat β List Nat)
-- inputs
(number need remaining: Nat) :=
-- spec
let spec (result: List Nat) :=
number β€ 1000 β need β€ 1000 β remaining β€ 1000 β
result.length = 2 β§
(need β€ remaining β result[0]! - need = number β§
need = remaining - result[1]!) β§
(remaining < n... | def generated_spec
-- function signature
(impl: Nat β Nat β Nat β List Nat)
-- inputs
(a b c : Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β a b c, problem_spec impl a b c) β
(β a b c, generated_spec impl a b c) := | sorry | def implementation (a b c: Nat) : List Nat := | sorry | -- #test implementation 5 6 10 = [11, 4]
-- #test implementation 4 8 9 = [12, 1]
-- #test implementation 1 10 10 = [11, 0]
-- #test implementation 2 11 5 = [7, 0] | theorem correctness
(a b c: Nat)
: problem_spec implementation a b c := | sorry | null | null | null |
def do_algebra(operator: List String, operand: List Nat) -> Int | Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor... | [{"input": [["+", "*", "-"], [2, 3, 4, 5]], "expected_output": 9}] | def do_algebra(operator: List String, operand: List Nat) -> Int
"""Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra oper... | def problem_spec
-- function signature
(impl: List String β List Nat β Int)
-- inputs
(operator : List String)
(operand : List Nat) :=
-- spec
let spec (result: Int) :=
operator.length = operand.length - 1 β§ 0 < operator.length β§ operand.all (fun n => 0 β€ n) β
let inline_tokens : List String := mergeAlternately operand... | def generated_spec
-- function signature
(impl: List String β List Nat β Int)
-- inputs
(operator : List String)
(operand : List Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β operator operand, problem_spec impl operator operand) β
(β operator operand, generated_spec impl operator operand) := | sorry | def implementation (operator: List String) (operand : List Nat) : Int := | sorry | -- #test implementation ['+', '*', '-'] [2,3,4,5] = 9 | theorem correctness
(operator : List String) (operand : List Nat)
: problem_spec implementation operator operand := | sorry | /--
name: mergeAlternately
use: |
Helper Methods to mergeAlternately a list of strings
problems:
- 160
sample_problems: []
-/
def mergeAlternately : List Nat β List String β List String
| [], [] => []
| [], y :: ys => y :: mergeAlternately [] ys
| x :: xs, [] => x.repr :: mergeAlternately xs []
| x :: xs, y... | null | null |
def solve(string : String) -> String | You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
| [{"input": "1234", "expected_output": "4321"}, {"input": "ab", "expected_output": "AB"}, {"input": "#a@C", "expected_output": "#A@c"}] | def solve(string : String) -> String
"""You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string.
""" | def problem_spec
-- function signature
(impl: String β String)
-- inputs
(string : String) :=
-- spec
let spec (result: String) :=
result.length = string.length β§
let hasNoAlphabet := string.all (Ξ» c => not (c.isAlpha));
(hasNoAlphabet β
result.toList = string.toList.reverse) β§
(hasNoAlphabet = false β
β i, i < str... | def generated_spec
-- function signature
(impl: String β String)
-- inputs
(s : String) : Prop := | theorem spec_isomorphism:
β impl,
(β s, problem_spec impl s) β
(β s, generated_spec impl s) := | sorry | def implementation (s: String) : String := | sorry | -- #test implementation "1234" = "4321"
-- #test implementation "ab" = "AB"
-- #test implementation "#a@C" = "#A@c" | theorem correctness
(s: String)
: problem_spec implementation s := | sorry | null | null | null |
def generate_integers(a : Nat, b : Nat) -> List Nat | Given two positive integers a and b, return the even digits between a
and b, in ascending order.
| [{"input": [2, 8], "expected_output": [2, 4, 6, 8]}, {"input": [8, 2], "expected_output": [2, 4, 6, 8]}, {"input": [10, 14], "expected_output": [10, 12, 14]}] | def generate_integers(a : Nat, b : Nat) -> List Nat
"""Given two positive integers a and b, return the even digits between a
and b, in ascending order.
""" | def problem_spec
-- function signature
(impl: Nat β Nat β List Nat)
-- inputs
(a b : Nat) :=
let isAscendingBy2 (r : List Nat) :=
β i, i < r.length - 1 β r[i+1]! - r[i]! = 2
-- spec
let spec (result: List Nat) :=
result.all (fun n => n % 2 = 0) β§ isAscendingBy2 result β§
1 < result.length β§
let min_a_b := min a b;
let m... | def generated_spec
-- function signature
(impl: Nat β Nat β List Nat)
-- inputs
(a b : Nat) : Prop := | theorem spec_isomorphism:
β impl,
(β a b, problem_spec impl a b) β
(β a b, generated_spec impl a b) := | sorry | def implementation (a b: Nat) : List Nat := | sorry | -- #test implementation 2 8 = [2, 4, 6, 8]
-- #test implementation 8 2 = [2, 4, 6, 8]
-- #test implementation 10 14 = [10, 12, 14] | theorem correctness
(a b: Nat)
: problem_spec implementation a b := | sorry | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.