Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 949eee0

Browse files
committed
Added a few human_eval.py puzzles and tweaked README
1 parent 993bf0f commit 949eee0

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

‎generators/human_eval.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,5 +2508,99 @@ def sol():
25082508
return [[p, q, r] for p in primes for q in primes if p <= q for r in primes if q <= r and p * q * r < 1000]
25092509

25102510

2511+
class IntegerLog(PuzzleGenerator):
2512+
"""Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76"""
2513+
2514+
@staticmethod
2515+
def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849):
2516+
"""Find an integer exponent x such that a^x = n"""
2517+
return a ** x == n
2518+
2519+
@staticmethod
2520+
def sol(a, n):
2521+
m = 1
2522+
x = 0
2523+
while m != n:
2524+
x += 1
2525+
m *= a
2526+
return x
2527+
2528+
def gen_random(self):
2529+
a = self.random.randrange(1, 10)
2530+
n = a ** self.random.randrange(255)
2531+
self.add(dict(a=a, n=n))
2532+
2533+
2534+
class CubeRoot(PuzzleGenerator):
2535+
"""Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77
2536+
2537+
We made it harder by giving very large n for which `round(n ** (1/3))`
2538+
"""
2539+
2540+
@staticmethod
2541+
def sat(x: int, n=42714774173606970182754018064350848294149432972747296768):
2542+
"""Find an integer that when cubed is n"""
2543+
return x ** 3 == n
2544+
2545+
@staticmethod
2546+
def sol(n): # Using Newton's method
2547+
m = abs(n)
2548+
x = round(abs(n) ** (1 / 3))
2549+
while x ** 3 != m:
2550+
x += (m - x ** 3) // (3 * x ** 2)
2551+
return -x if n < 0 else x
2552+
2553+
def gen_random(self):
2554+
digits = self.random.randrange(30)
2555+
n = self.random.randrange(-10 ** digits, 10 ** digits) ** 3
2556+
self.add(dict(n=n))
2557+
2558+
2559+
2560+
class HexPrimes(PuzzleGenerator):
2561+
"""Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78"""
2562+
2563+
@staticmethod
2564+
def sat(primes: List[bool], n="A4D4455214122CE192CCBE3"):
2565+
"""Determine which characters of a hexidecimal correspond to prime numbers"""
2566+
return all(primes[i] == (c in "2357BD") for i, c in enumerate(n))
2567+
2568+
@staticmethod
2569+
def sol(n):
2570+
return [c in "2357BD" for c in n]
2571+
2572+
def gen_random(self):
2573+
digits = self.random.randrange(30)
2574+
n = hex(self.random.randrange(10 ** digits))[2:]
2575+
self.add(dict(n=n))
2576+
2577+
2578+
class Binarize(PuzzleGenerator):
2579+
"""Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79"""
2580+
2581+
@staticmethod
2582+
def sat(b: str, n=5324680297138495285):
2583+
"""Write n base 2 followed and preceded by 'bits'"""
2584+
assert b[:4] == b[-4:] == 'bits'
2585+
inside = b[4:-4]
2586+
assert all(c in "01" for c in inside)
2587+
assert inside[0] == "1" or len(inside) == 1
2588+
m = 0
2589+
for c in inside:
2590+
m = 2*m + int(c)
2591+
return m == n
2592+
2593+
@staticmethod
2594+
def sol(n):
2595+
s = bin(n)[2:]
2596+
return f'bits{s}bits'
2597+
2598+
def gen_random(self):
2599+
digits = self.random.randrange(30)
2600+
n = self.random.randrange(10 ** digits)
2601+
self.add(dict(n=n))
2602+
2603+
2604+
25112605
if __name__ == "__main__":
25122606
PuzzleGenerator.debug_problems()

‎make_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def save_readme(gen_modules, filename):
5959
n_instances = sum(p["n_instances"] for p in puzzles)
6060
tot_instances += len(puzzles)
6161
tot_instances += n_instances
62-
tot_puzzles += 1
6362
table += f"- [{sec_name} ({len(puzzles):,} problems, {n_instances:,} instances)](#{sec_name.lower().replace(' ', '-')})\n"
6463
for i, puzzle in enumerate(puzzles):
64+
tot_puzzles += 1
6565
section += f"### {puzzle['name']}\n"
6666
section += f"{puzzle['desc']}\n\n"
6767
section += f"```python\n{puzzle['sat']}\n```\n"

‎puzzles/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ through `check_solution_type` from `puzzle_generator.py` before certifying corre
2626
- [trivial_inverse (39 problems, 372 instances)](#trivial_inverse)
2727
- [tutorial (5 problems, 5 instances)](#tutorial)
2828

29-
Total (19 problems, 2,853 instances)
29+
Total (309 problems, 2,853 instances)
3030

3131

3232
----

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /