Skip to content

Commit

Permalink
refactor: prune
Browse files Browse the repository at this point in the history
  • Loading branch information
ganler committed Apr 28, 2023
1 parent 9a26cab commit 2542563
Show file tree
Hide file tree
Showing 334 changed files with 990 additions and 7,876 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: (?x)^(
groundtruth/.* |
groundtruth_plus/.*
groundtruth/.*
)$
161 changes: 0 additions & 161 deletions HumanEvalPlusInputs.jsonl

This file was deleted.

11 changes: 4 additions & 7 deletions groundtruth/000_has_close_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ def has_close_elements(numbers: List[float], threshold: float) -> bool:
"""
assert threshold > 0, "invalid inputs" # $_CONTRACT_$
assert all([isinstance(v, (int, float)) for v in numbers]), "invalid inputs" # $_CONTRACT_$
for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
distance = abs(elem - elem2)
if distance < threshold:
return True

sorted_numbers = sorted(numbers)
for i in range(len(sorted_numbers) - 1):
if sorted_numbers[i + 1] - sorted_numbers[i] < threshold:
return True
return False




METADATA = {
'author': 'jt',
'dataset': 'test'
Expand Down
28 changes: 10 additions & 18 deletions groundtruth/001_separate_paren_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,23 @@ def separate_paren_groups(paren_string: str) -> List[str]:
>>> separate_paren_groups('( ) (( )) (( )( ))')
['()', '(())', '(()())']
"""

assert type(paren_string) == str, "invalid inputs" # $_CONTRACT_$
cnt = 0 # $_CONTRACT_$
for ch in paren_string: # $_CONTRACT_$
assert ch in ["(", ")", " "], "invalid inputs" # $_CONTRACT_$
if ch == "(": cnt += 1 # $_CONTRACT_$
if ch == ")": cnt -= 1 # $_CONTRACT_$
assert cnt >= 0, "invalid inputs" # $_CONTRACT_$
result = []
current_string = []
current_depth = 0

for c in paren_string:
if c == '(':
current_depth += 1
current_string.append(c)
elif c == ')':
current_depth -= 1
current_string.append(c)

if current_depth == 0:
result.append(''.join(current_string))
current_string.clear()

return result

cnt, group, results = 0, "", []
for ch in paren_string:
if ch == "(": cnt += 1
if ch == ")": cnt -= 1
if ch != " ": group += ch
if cnt == 0:
if group != "": results.append(group)
group = ""
return results



Expand Down
3 changes: 1 addition & 2 deletions groundtruth/002_truncate_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ def truncate_number(number: float) -> float:
>>> truncate_number(3.5)
0.5
"""

assert number > 0, "invalid inputs" # $_CONTRACT_$
assert isinstance(number, float), "invalid inputs" # $_CONTRACT_$
return number % 1.0

return number - int(number)



Expand Down
11 changes: 4 additions & 7 deletions groundtruth/003_below_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ def below_zero(operations: List[int]) -> bool:
True
"""
assert all([isinstance(v, int) for v in operations]), "invalid inputs" # $_CONTRACT_$
balance = 0

for op in operations:
balance += op
if balance < 0:
account = 0
for operation in operations:
account += operation
if account < 0:
return True

return False




METADATA = {
'author': 'jt',
'dataset': 'test'
Expand Down
4 changes: 1 addition & 3 deletions groundtruth/004_mean_absolute_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ def mean_absolute_deviation(numbers: List[float]) -> float:
>>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])
1.0
"""

assert all(isinstance(x, float) for x in numbers), "invalid inputs" # $_CONTRACT_$
assert numbers != [], "invalid inputs" # $_CONTRACT_$
mean = sum(numbers) / len(numbers)
return sum(abs(x - mean) for x in numbers) / len(numbers)




METADATA = {
'author': 'jt',
'dataset': 'test'
Expand Down
19 changes: 6 additions & 13 deletions groundtruth/005_intersperse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ def intersperse(numbers: List[int], delimeter: int) -> List[int]:
"""
assert all([isinstance(v, int) for v in numbers]), "invalid inputs" # $_CONTRACT_$
assert isinstance(delimeter, int), "invalid inputs" # $_CONTRACT_$

if not numbers:
return []

result = []

for n in numbers[:-1]:
result.append(n)
result.append(delimeter)

result.append(numbers[-1])

return result

res = []
for i in range(len(numbers)):
res.append(numbers[i])
if i != len(numbers) - 1:
res.append(delimeter)
return res



Expand Down
24 changes: 10 additions & 14 deletions groundtruth/006_parse_nested_parens.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@ def parse_nested_parens(paren_string: str) -> List[int]:
>>> parse_nested_parens('(()()) ((())) () ((())()())')
[2, 3, 1, 3]
"""

assert type(paren_string) == str, "invalid inputs" # $_CONTRACT_$
cnt = 0 # $_CONTRACT_$
for ch in paren_string: # $_CONTRACT_$
assert ch in ["(", ")", " "], "invalid inputs" # $_CONTRACT_$
if ch == "(": cnt += 1 # $_CONTRACT_$
if ch == ")": cnt -= 1 # $_CONTRACT_$
assert cnt >= 0, "invalid inputs" # $_CONTRACT_$
def parse_paren_group(s):
depth = 0
max_depth = 0
for c in s:
if c == '(':
depth += 1
max_depth = max(depth, max_depth)
else:
depth -= 1


def count_depth(s: str) -> int:
max_depth, cnt = 0, 0
for ch in s:
if ch == "(": cnt += 1
if ch == ")": cnt -= 1
max_depth = max(max_depth, cnt)
return max_depth

return [parse_paren_group(x) for x in paren_string.split(' ') if x]


return [count_depth(s) for s in paren_string.split(" ") if s != ""]



Expand Down
7 changes: 4 additions & 3 deletions groundtruth/007_filter_by_substring.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ def filter_by_substring(strings: List[str], substring: str) -> List[str]:
>>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')
['abc', 'bacd', 'array']
"""
return [x for x in strings if substring in x]


assert type(strings) == list, "invalid inputs" # $_CONTRACT_$
assert all(type(x) == str for x in strings), "invalid inputs" # $_CONTRACT_$
assert isinstance(substring, str), "invalid inputs" # $_CONTRACT_$
return list(filter(lambda s: substring in s, strings))


METADATA = {
Expand Down
14 changes: 5 additions & 9 deletions groundtruth/008_sum_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ def sum_product(numbers: List[int]) -> Tuple[int, int]:
(10, 24)
"""
assert all([isinstance(v, int) for v in numbers]), "invalid inputs" # $_CONTRACT_$
sum_value = 0
prod_value = 1

for n in numbers:
sum_value += n
prod_value *= n
return sum_value, prod_value


s, p = 0, 1
for number in numbers:
s += number
p *= number
return s, p


METADATA = {
Expand Down
14 changes: 1 addition & 13 deletions groundtruth/009_rolling_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@ def rolling_max(numbers: List[int]) -> List[int]:
[1, 2, 3, 3, 3, 4, 4]
"""
assert all([isinstance(v, int) for v in numbers]), "invalid inputs" # $_CONTRACT_$
running_max = None
result = []

for n in numbers:
if running_max is None:
running_max = n
else:
running_max = max(running_max, n)

result.append(running_max)

return result

return [max(numbers[:(i+1)]) for i in range(len(numbers))]



Expand Down
18 changes: 6 additions & 12 deletions groundtruth/010_make_palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ def make_palindrome(string: str) -> str:
>>> make_palindrome('cata')
'catac'
"""
if not string:
return ''

beginning_of_suffix = 0

while not is_palindrome(string[beginning_of_suffix:]):
beginning_of_suffix += 1

return string + string[:beginning_of_suffix][::-1]



assert type(string) == str, "invalid inputs" # $_CONTRACT_$
if is_palindrome(string):
return string
for i in range(len(string)):
if is_palindrome(string[i:]):
return string + string[i-1::-1]

METADATA = {
'author': 'jt',
Expand Down
10 changes: 2 additions & 8 deletions groundtruth/011_string_xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ def string_xor(a: str, b: str) -> str:
>>> string_xor('010', '110')
'100'
"""

assert isinstance(a, str) and isinstance(b, str), "invalid inputs" # $_CONTRACT_$
assert len(a) == len(b), "invalid inputs" # $_CONTRACT_$
assert set(a).issubset({"0", "1"}) and set(b).issubset({"0", "1"}), "invalid inputs" # $_CONTRACT_$
def xor(i, j):
if i == j:
return '0'
else:
return '1'

return ''.join(xor(x, y) for x, y in zip(a, b))

return "".join(str(int(a[i]) ^ int(b[i])) for i in range(len(a)))



Expand Down
2 changes: 1 addition & 1 deletion groundtruth/012_longest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def longest(strings: List[str]) -> Optional[str]:
>>> longest(['a', 'bb', 'ccc'])
'ccc'
"""
assert type(strings) == list, "invalid inputs" # $_CONTRACT_$
assert all([isinstance(v, str) for v in strings]), "invalid inputs" # $_CONTRACT_$
if not strings:
return None
Expand All @@ -22,7 +23,6 @@ def longest(strings: List[str]) -> Optional[str]:




METADATA = {
'author': 'jt',
'dataset': 'test'
Expand Down
8 changes: 4 additions & 4 deletions groundtruth/013_greatest_common_divisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def greatest_common_divisor(a: int, b: int) -> int:
>>> greatest_common_divisor(25, 15)
5
"""

assert type(a) == int and type(b) == int, "invalid inputs" # $_CONTRACT_$
assert a > 0 and b > 0, "invalid inputs" # $_CONTRACT_$
while b:
a, b = b, a % b
return a

def query_gcd(a: int, b: int) -> int:
return a if b == 0 else query_gcd(b, a % b)
return query_gcd(a, b)



Expand Down
8 changes: 2 additions & 6 deletions groundtruth/014_all_prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ def all_prefixes(string: str) -> List[str]:
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
result = []

for i in range(len(string)):
result.append(string[:i+1])
return result

assert isinstance(string, str), "invalid inputs" # $_CONTRACT_$
return [string[:(i + 1)] for i in range(len(string))]



Expand Down
4 changes: 2 additions & 2 deletions groundtruth/015_string_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def string_sequence(n: int) -> str:
>>> string_sequence(5)
'0 1 2 3 4 5'
"""

assert type(n) == int, "invalid inputs" # $_CONTRACT_$
assert n >= 0, "invalid inputs" # $_CONTRACT_$
return ' '.join([str(x) for x in range(n + 1)])

return " ".join(map(str, range(n + 1)))



Expand Down
2 changes: 1 addition & 1 deletion groundtruth/016_count_distinct_characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def count_distinct_characters(string: str) -> int:
>>> count_distinct_characters('Jerry')
4
"""
assert isinstance(string, str), "invalid inputs" # $_CONTRACT_$
return len(set(string.lower()))




METADATA = {
'author': 'jt',
'dataset': 'test'
Expand Down
11 changes: 8 additions & 3 deletions groundtruth/017_parse_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ def parse_music(music_string: str) -> List[int]:
>>> parse_music('o o| .| o| o| .| .| .| .| o o')
[4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
"""

assert isinstance(music_string, str), "invalid inputs" # $_CONTRACT_$
assert music_string == "" or all(map(lambda x: x in ["o", "o|", ".|"], music_string.split(" "))), "invalid inputs" # $_CONTRACT_$
note_map = {'o': 4, 'o|': 2, '.|': 1}
return [note_map[x] for x in music_string.split(' ') if x]

def count_beats(note: str) -> int:
if note == "o": return 4
elif note == "o|": return 2
elif note == ".|": return 1

if music_string == "": return []
return list(map(count_beats, music_string.split(" ")))



Expand Down
Loading

0 comments on commit 2542563

Please sign in to comment.