mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 01:36:29 +02:00
715 lines
50 KiB
Text
715 lines
50 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-07-25 16:45:31.369 | INFO | metagpt.const:get_metagpt_package_root:29 - Package root set to /Users/trl/Github_project/MetaGPT-MathAI\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"22\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/40'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"20\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/40'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"24\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/40'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/89'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"23\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/40'}, {'task_id': 'HumanEval/64'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/109'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"22\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/40'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/135'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/163'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from examples.ags.benchmark.humaneval import extract_failure_tests\n",
|
|
"\n",
|
|
"file_path_list = [\"llm_based_120_eval_results.json\", \"llm_based_121_eval_results.json\", \"llm_based_122_eval_results.json\", \"llm_based_123_eval_results.json\", \"llm_based_124_eval_results.json\"]\n",
|
|
"\n",
|
|
"for file_path in file_path_list:\n",
|
|
" unpassed_exapmle = extract_failure_tests(file_path)\n",
|
|
" print(unpassed_exapmle)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"17\n",
|
|
"[{'task_id': 'HumanEval/163'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/129'}]\n",
|
|
"20\n",
|
|
"[{'task_id': 'HumanEval/163'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/135'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/129'}]\n",
|
|
"17\n",
|
|
"[{'task_id': 'HumanEval/163'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/83'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/129'}]\n",
|
|
"18\n",
|
|
"[{'task_id': 'HumanEval/163'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/83'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/129'}]\n",
|
|
"18\n",
|
|
"[{'task_id': 'HumanEval/163'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/99'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/129'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"\n",
|
|
"\n",
|
|
"from examples.ags.benchmark.humaneval import extract_failure_tests\n",
|
|
"\n",
|
|
"file_path_list = [\"EVALPLUS-4omini/1.json\", \"EVALPLUS-4omini/2.json\", \"EVALPLUS-4omini/3.json\", \"EVALPLUS-4omini/4.json\", \"EVALPLUS-4omini/5.json\"]\n",
|
|
"\n",
|
|
"for file_path in file_path_list:\n",
|
|
" unpassed_exapmle = extract_failure_tests(file_path)\n",
|
|
" print(unpassed_exapmle)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20\n",
|
|
"[{'task_id': 'HumanEval/16'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"23\n",
|
|
"[{'task_id': 'HumanEval/16'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/33'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/116'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"20\n",
|
|
"[{'task_id': 'HumanEval/16'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/116'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"22\n",
|
|
"[{'task_id': 'HumanEval/16'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/116'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"23\n",
|
|
"[{'task_id': 'HumanEval/16'}, {'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/33'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/67'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/116'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from examples.ags.benchmark.humaneval import extract_failure_tests\n",
|
|
"\n",
|
|
"file_path_list = [\"llm_based_125_eval_results.json\", \"llm_based_126_eval_results.json\", \"llm_based_127_eval_results.json\", \"llm_based_128_eval_results.json\", \"llm_based_129_eval_results.json\"]\n",
|
|
"\n",
|
|
"for file_path in file_path_list:\n",
|
|
" unpassed_exapmle = extract_failure_tests(file_path)\n",
|
|
" print(unpassed_exapmle)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"21\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/83'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/116'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"22\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/33'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"21\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/33'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"20\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/33'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/163'}]\n",
|
|
"22\n",
|
|
"[{'task_id': 'HumanEval/32'}, {'task_id': 'HumanEval/39'}, {'task_id': 'HumanEval/65'}, {'task_id': 'HumanEval/74'}, {'task_id': 'HumanEval/76'}, {'task_id': 'HumanEval/83'}, {'task_id': 'HumanEval/91'}, {'task_id': 'HumanEval/93'}, {'task_id': 'HumanEval/108'}, {'task_id': 'HumanEval/110'}, {'task_id': 'HumanEval/115'}, {'task_id': 'HumanEval/126'}, {'task_id': 'HumanEval/130'}, {'task_id': 'HumanEval/132'}, {'task_id': 'HumanEval/134'}, {'task_id': 'HumanEval/129'}, {'task_id': 'HumanEval/140'}, {'task_id': 'HumanEval/145'}, {'task_id': 'HumanEval/154'}, {'task_id': 'HumanEval/159'}, {'task_id': 'HumanEval/160'}, {'task_id': 'HumanEval/163'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from examples.ags.benchmark.humaneval import extract_failure_tests\n",
|
|
"\n",
|
|
"file_path_list = [\"llm_based_135_eval_results.json\", \"llm_based_136_eval_results.json\", \"llm_based_137_eval_results.json\", \"llm_based_138_eval_results.json\", \"llm_based_139_eval_results.json\"]\n",
|
|
"\n",
|
|
"for file_path in file_path_list:\n",
|
|
" unpassed_exapmle = extract_failure_tests(file_path)\n",
|
|
" print(unpassed_exapmle)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"def fruit_distribution(s,n):\n",
|
|
" \"\"\"\n",
|
|
" In this task, you will be given a string that represents a number of apples and oranges \n",
|
|
" that are distributed in a basket of fruit this basket contains \n",
|
|
" apples, oranges, and mango fruits. Given the string that represents the total number of \n",
|
|
" the oranges and apples and an integer that represent the total number of the fruits \n",
|
|
" in the basket return the number of the mango fruits in the basket.\n",
|
|
" for examble:\n",
|
|
" fruit_distribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n",
|
|
" fruit_distribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n",
|
|
" fruit_distribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n",
|
|
" fruit_distribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
"def fruit_distribution(s, n):\n",
|
|
" \"\"\"\n",
|
|
" In this task, you will be given a string that represents a number of apples and oranges \n",
|
|
" that are distributed in a basket of fruit. This basket contains \n",
|
|
" apples, oranges, and mango fruits. Given the string that represents the total number of \n",
|
|
" the oranges and apples and an integer that represents the total number of the fruits \n",
|
|
" in the basket, return the number of the mango fruits in the basket.\n",
|
|
" \n",
|
|
" Parameters:\n",
|
|
" s (str): A string representing the number of apples and oranges.\n",
|
|
" n (int): An integer representing the total number of fruits in the basket.\n",
|
|
" \n",
|
|
" Returns:\n",
|
|
" int: The number of mango fruits in the basket.\n",
|
|
" \n",
|
|
" Examples:\n",
|
|
" fruit_distribution(\"5 apples and 6 oranges\", 19) -> 8\n",
|
|
" fruit_distribution(\"0 apples and 1 oranges\", 3) -> 2\n",
|
|
" fruit_distribution(\"2 apples and 3 oranges\", 100) -> 95\n",
|
|
" fruit_distribution(\"100 apples and 1 oranges\", 120) -> 19\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" # Extract the number of apples and oranges from the string\n",
|
|
" parts = s.split()\n",
|
|
" apples = int(parts[0]) # First part is the number of apples\n",
|
|
" oranges = int(parts[2]) # Third part is the number of oranges\n",
|
|
" \n",
|
|
" # Calculate the number of mangoes\n",
|
|
" mangoes = n - apples - oranges\n",
|
|
" \n",
|
|
" return mangoes\n",
|
|
"--------------------------\n",
|
|
"def fruit_distribution(s, n):\n",
|
|
" \"\"\"\n",
|
|
" In this task, you will be given a string that represents a number of apples and oranges \n",
|
|
" that are distributed in a basket of fruit. This basket contains \n",
|
|
" apples, oranges, and mango fruits. Given the string that represents the total number of \n",
|
|
" the oranges and apples and an integer that represents the total number of the fruits \n",
|
|
" in the basket, return the number of the mango fruits in the basket.\n",
|
|
" \n",
|
|
" Parameters:\n",
|
|
" s (str): A string representing the number of apples and oranges.\n",
|
|
" n (int): An integer representing the total number of fruits in the basket.\n",
|
|
" \n",
|
|
" Returns:\n",
|
|
" int: The number of mango fruits in the basket.\n",
|
|
" \n",
|
|
" Examples:\n",
|
|
" fruit_distribution(\"5 apples and 6 oranges\", 19) -> 8\n",
|
|
" fruit_distribution(\"0 apples and 1 oranges\", 3) -> 2\n",
|
|
" fruit_distribution(\"2 apples and 3 oranges\", 100) -> 95\n",
|
|
" fruit_distribution(\"100 apples and 1 oranges\", 120) -> 19\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" # Extract the number of apples and oranges from the string\n",
|
|
" parts = s.split()\n",
|
|
" apples = int(parts[0]) # First part is the number of apples\n",
|
|
" oranges = int(parts[3]) # Fourth part is the number of oranges\n",
|
|
" \n",
|
|
" # Calculate the number of mangoes\n",
|
|
" mangoes = n - apples - oranges\n",
|
|
" \n",
|
|
" return mangoes\n",
|
|
"--------------------------\n",
|
|
"def fruit_distribution(s, n):\n",
|
|
" \"\"\"\n",
|
|
" Calculate the number of mango fruits in a basket given the number of apples and oranges.\n",
|
|
"\n",
|
|
" Parameters:\n",
|
|
" s (str): A string representing the number of apples and oranges in the format \"X apples and Y oranges\".\n",
|
|
" n (int): An integer representing the total number of fruits in the basket.\n",
|
|
"\n",
|
|
" Returns:\n",
|
|
" int: The number of mango fruits in the basket.\n",
|
|
" \"\"\"\n",
|
|
" # Split the input string to extract the number of apples and oranges\n",
|
|
" parts = s.split(\" and \")\n",
|
|
" apples = int(parts[0].split()[0]) # Get the number of apples\n",
|
|
" oranges = int(parts[1].split()[0]) # Get the number of oranges\n",
|
|
"\n",
|
|
" # Calculate the number of mangoes\n",
|
|
" mangoes = n - apples - oranges\n",
|
|
"\n",
|
|
" return mangoes\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from evalplus.data import get_human_eval_plus\n",
|
|
"\n",
|
|
"humaneval = get_human_eval_plus()\n",
|
|
"print(humaneval['HumanEval/67'][\"prompt\"])\n",
|
|
"\n",
|
|
"result = {\"solution\": \"def fruit_distribution(s, n):\\n \\\"\\\"\\\"\\n In this task, you will be given a string that represents a number of apples and oranges \\n that are distributed in a basket of fruit. This basket contains \\n apples, oranges, and mango fruits. Given the string that represents the total number of \\n the oranges and apples and an integer that represents the total number of the fruits \\n in the basket, return the number of the mango fruits in the basket.\\n \\n Parameters:\\n s (str): A string representing the number of apples and oranges.\\n n (int): An integer representing the total number of fruits in the basket.\\n \\n Returns:\\n int: The number of mango fruits in the basket.\\n \\n Examples:\\n fruit_distribution(\\\"5 apples and 6 oranges\\\", 19) -> 8\\n fruit_distribution(\\\"0 apples and 1 oranges\\\", 3) -> 2\\n fruit_distribution(\\\"2 apples and 3 oranges\\\", 100) -> 95\\n fruit_distribution(\\\"100 apples and 1 oranges\\\", 120) -> 19\\n \\\"\\\"\\\"\\n \\n # Extract the number of apples and oranges from the string\\n parts = s.split()\\n apples = int(parts[0]) # First part is the number of apples\\n oranges = int(parts[2]) # Third part is the number of oranges\\n \\n # Calculate the number of mangoes\\n mangoes = n - apples - oranges\\n \\n return mangoes\"}\n",
|
|
"print(result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"correct_result = {\"solution\":\"def fruit_distribution(s, n):\\n \\\"\\\"\\\"\\n In this task, you will be given a string that represents a number of apples and oranges \\n that are distributed in a basket of fruit. This basket contains \\n apples, oranges, and mango fruits. Given the string that represents the total number of \\n the oranges and apples and an integer that represents the total number of the fruits \\n in the basket, return the number of the mango fruits in the basket.\\n \\n Parameters:\\n s (str): A string representing the number of apples and oranges.\\n n (int): An integer representing the total number of fruits in the basket.\\n \\n Returns:\\n int: The number of mango fruits in the basket.\\n \\n Examples:\\n fruit_distribution(\\\"5 apples and 6 oranges\\\", 19) -> 8\\n fruit_distribution(\\\"0 apples and 1 oranges\\\", 3) -> 2\\n fruit_distribution(\\\"2 apples and 3 oranges\\\", 100) -> 95\\n fruit_distribution(\\\"100 apples and 1 oranges\\\", 120) -> 19\\n \\\"\\\"\\\"\\n \\n # Extract the number of apples and oranges from the string\\n parts = s.split()\\n apples = int(parts[0]) # First part is the number of apples\\n oranges = int(parts[3]) # Fourth part is the number of oranges\\n \\n # Calculate the number of mangoes\\n mangoes = n - apples - oranges\\n \\n return mangoes\"}\n",
|
|
"\n",
|
|
"print(correct_result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"modify_result = {'task_id': 'HumanEval/67', 'solution': 'def fruit_distribution(s, n):\\n \"\"\"\\n Calculate the number of mango fruits in a basket given the number of apples and oranges.\\n\\n Parameters:\\n s (str): A string representing the number of apples and oranges in the format \"X apples and Y oranges\".\\n n (int): An integer representing the total number of fruits in the basket.\\n\\n Returns:\\n int: The number of mango fruits in the basket.\\n \"\"\"\\n # Split the input string to extract the number of apples and oranges\\n parts = s.split(\" and \")\\n apples = int(parts[0].split()[0]) # Get the number of apples\\n oranges = int(parts[1].split()[0]) # Get the number of oranges\\n\\n # Calculate the number of mangoes\\n mangoes = n - apples - oranges\\n\\n return mangoes'}\n",
|
|
"\n",
|
|
"print(modify_result[\"solution\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"def count_nums(arr):\n",
|
|
" \"\"\"\n",
|
|
" Write a function count_nums which takes an array of integers and returns\n",
|
|
" the number of elements which has a sum of digits > 0.\n",
|
|
" If a number is negative, then its first signed digit will be negative:\n",
|
|
" e.g. -123 has signed digits -1, 2, and 3.\n",
|
|
" >>> count_nums([]) == 0\n",
|
|
" >>> count_nums([-1, 11, -11]) == 1\n",
|
|
" >>> count_nums([1, 1, 2]) == 3\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
"def count_nums(arr):\n",
|
|
" \"\"\"\n",
|
|
" Write a function count_nums which takes an array of integers and returns\n",
|
|
" the number of elements which has a sum of digits > 0.\n",
|
|
" If a number is negative, then its first signed digit will be negative:\n",
|
|
" e.g. -123 has signed digits -1, 2, and 3.\n",
|
|
" \n",
|
|
" >>> count_nums([]) == 0\n",
|
|
" >>> count_nums([-1, 11, -11]) == 1\n",
|
|
" >>> count_nums([1, 1, 2]) == 3\n",
|
|
" \"\"\"\n",
|
|
" def sum_of_digits(n):\n",
|
|
" # Convert the number to string and calculate the sum of its digits\n",
|
|
" return sum(int(digit) if digit != '-' else -int(digit[1]) for digit in str(n) if digit.isdigit() or digit == '-')\n",
|
|
"\n",
|
|
" count = 0\n",
|
|
" for number in arr:\n",
|
|
" if sum_of_digits(number) > 0:\n",
|
|
" count += 1\n",
|
|
" \n",
|
|
" return count\n",
|
|
"--------------------------\n",
|
|
"def count_nums(arr):\n",
|
|
" \"\"\"\n",
|
|
" Write a function count_nums which takes an array of integers and returns\n",
|
|
" the number of elements which has a sum of digits > 0.\n",
|
|
" If a number is negative, then its first signed digit will be negative:\n",
|
|
" e.g. -123 has signed digits -1, 2, and 3.\n",
|
|
" \n",
|
|
" >>> count_nums([]) == 0\n",
|
|
" >>> count_nums([-1, 11, -11]) == 1\n",
|
|
" >>> count_nums([1, 1, 2]) == 3\n",
|
|
" \"\"\"\n",
|
|
" def sum_of_digits(n):\n",
|
|
" # Convert the number to string and calculate the sum of its digits\n",
|
|
" # For negative numbers, we need to consider the first digit as negative\n",
|
|
" str_n = str(n)\n",
|
|
" if n < 0:\n",
|
|
" return -int(str_n[1]) + sum(int(digit) for digit in str_n[2:])\n",
|
|
" else:\n",
|
|
" return sum(int(digit) for digit in str_n)\n",
|
|
"\n",
|
|
" count = 0\n",
|
|
" for num in arr:\n",
|
|
" if sum_of_digits(num) > 0:\n",
|
|
" count += 1\n",
|
|
" \n",
|
|
" return count\n",
|
|
"--------------------------\n",
|
|
"def count_nums(arr):\n",
|
|
" \"\"\"\n",
|
|
" Write a function count_nums which takes an array of integers and returns\n",
|
|
" the number of elements which has a sum of digits > 0.\n",
|
|
" If a number is negative, then its first signed digit will be negative:\n",
|
|
" e.g. -123 has signed digits -1, 2, and 3.\n",
|
|
" \n",
|
|
" >>> count_nums([]) == 0\n",
|
|
" >>> count_nums([-1, 11, -11]) == 1\n",
|
|
" >>> count_nums([1, 1, 2]) == 3\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" def sum_of_digits(n):\n",
|
|
" \"\"\"Helper function to calculate the sum of digits of a number.\"\"\"\n",
|
|
" # Convert the number to string and iterate over each character\n",
|
|
" # If the number is negative, we need to consider the first digit as negative\n",
|
|
" str_n = str(n)\n",
|
|
" digit_sum = 0\n",
|
|
" \n",
|
|
" for i, char in enumerate(str_n):\n",
|
|
" if char.isdigit():\n",
|
|
" digit_sum += int(char)\n",
|
|
" elif i == 0 and char == '-':\n",
|
|
" digit_sum -= 1 # First signed digit is negative\n",
|
|
" \n",
|
|
" return digit_sum\n",
|
|
"\n",
|
|
" count = 0\n",
|
|
" for number in arr:\n",
|
|
" if sum_of_digits(number) > 0:\n",
|
|
" count += 1\n",
|
|
" \n",
|
|
" return count\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from evalplus.data import get_human_eval_plus\n",
|
|
"\n",
|
|
"humaneval = get_human_eval_plus()\n",
|
|
"print(humaneval['HumanEval/108'][\"prompt\"])\n",
|
|
"\n",
|
|
"result = {\"solution\": \"def count_nums(arr):\\n \\\"\\\"\\\"\\n Write a function count_nums which takes an array of integers and returns\\n the number of elements which has a sum of digits > 0.\\n If a number is negative, then its first signed digit will be negative:\\n e.g. -123 has signed digits -1, 2, and 3.\\n \\n >>> count_nums([]) == 0\\n >>> count_nums([-1, 11, -11]) == 1\\n >>> count_nums([1, 1, 2]) == 3\\n \\\"\\\"\\\"\\n def sum_of_digits(n):\\n # Convert the number to string and calculate the sum of its digits\\n return sum(int(digit) if digit != '-' else -int(digit[1]) for digit in str(n) if digit.isdigit() or digit == '-')\\n\\n count = 0\\n for number in arr:\\n if sum_of_digits(number) > 0:\\n count += 1\\n \\n return count\"}\n",
|
|
"print(result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"correct_result = {\"solution\": \"def count_nums(arr):\\n \\\"\\\"\\\"\\n Write a function count_nums which takes an array of integers and returns\\n the number of elements which has a sum of digits > 0.\\n If a number is negative, then its first signed digit will be negative:\\n e.g. -123 has signed digits -1, 2, and 3.\\n \\n >>> count_nums([]) == 0\\n >>> count_nums([-1, 11, -11]) == 1\\n >>> count_nums([1, 1, 2]) == 3\\n \\\"\\\"\\\"\\n def sum_of_digits(n):\\n # Convert the number to string and calculate the sum of its digits\\n # For negative numbers, we need to consider the first digit as negative\\n str_n = str(n)\\n if n < 0:\\n return -int(str_n[1]) + sum(int(digit) for digit in str_n[2:])\\n else:\\n return sum(int(digit) for digit in str_n)\\n\\n count = 0\\n for num in arr:\\n if sum_of_digits(num) > 0:\\n count += 1\\n \\n return count\"}\n",
|
|
"print(correct_result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"modify_result = {'task_id': 'HumanEval/108', 'solution': 'def count_nums(arr):\\n \"\"\"\\n Write a function count_nums which takes an array of integers and returns\\n the number of elements which has a sum of digits > 0.\\n If a number is negative, then its first signed digit will be negative:\\n e.g. -123 has signed digits -1, 2, and 3.\\n \\n >>> count_nums([]) == 0\\n >>> count_nums([-1, 11, -11]) == 1\\n >>> count_nums([1, 1, 2]) == 3\\n \"\"\"\\n \\n def sum_of_digits(n):\\n \"\"\"Helper function to calculate the sum of digits of a number.\"\"\"\\n # Convert the number to string and iterate over each character\\n # If the number is negative, we need to consider the first digit as negative\\n str_n = str(n)\\n digit_sum = 0\\n \\n for i, char in enumerate(str_n):\\n if char.isdigit():\\n digit_sum += int(char)\\n elif i == 0 and char == \\'-\\':\\n digit_sum -= 1 # First signed digit is negative\\n \\n return digit_sum\\n\\n count = 0\\n for number in arr:\\n if sum_of_digits(number) > 0:\\n count += 1\\n \\n return count'}\n",
|
|
"\n",
|
|
"print(modify_result[\"solution\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"def exchange(lst1, lst2):\n",
|
|
" \"\"\"In this problem, you will implement a function that takes two lists of numbers,\n",
|
|
" and determines whether it is possible to perform an exchange of elements\n",
|
|
" between them to make lst1 a list of only even numbers.\n",
|
|
" There is no limit on the number of exchanged elements between lst1 and lst2.\n",
|
|
" If it is possible to exchange elements between the lst1 and lst2 to make\n",
|
|
" all the elements of lst1 to be even, return \"YES\".\n",
|
|
" Otherwise, return \"NO\".\n",
|
|
" For example:\n",
|
|
" exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n",
|
|
" exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n",
|
|
" It is assumed that the input lists will be non-empty.\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
"def exchange(lst1, lst2):\n",
|
|
" \"\"\"Determines whether it is possible to perform an exchange of elements\n",
|
|
" between two lists to make lst1 a list of only even numbers.\n",
|
|
" \n",
|
|
" Args:\n",
|
|
" lst1 (list): The first list of numbers.\n",
|
|
" lst2 (list): The second list of numbers.\n",
|
|
" \n",
|
|
" Returns:\n",
|
|
" str: \"YES\" if lst1 can be made all even, \"NO\" otherwise.\n",
|
|
" \"\"\"\n",
|
|
" # Check if lst1 already contains only even numbers\n",
|
|
" if all(x % 2 == 0 for x in lst1):\n",
|
|
" return \"YES\"\n",
|
|
" \n",
|
|
" # Count the number of odd numbers in lst1\n",
|
|
" odd_count_lst1 = sum(1 for x in lst1 if x % 2 != 0)\n",
|
|
" \n",
|
|
" # Check if lst2 has at least one even number to exchange\n",
|
|
" has_even_in_lst2 = any(x % 2 == 0 for x in lst2)\n",
|
|
" \n",
|
|
" # If lst1 has odd numbers and lst2 has at least one even number, we can exchange\n",
|
|
" if odd_count_lst1 > 0 and has_even_in_lst2:\n",
|
|
" return \"YES\"\n",
|
|
" \n",
|
|
" return \"NO\"\n",
|
|
"--------------------------\n",
|
|
"def exchange(lst1, lst2):\n",
|
|
" \"\"\"In this problem, you will implement a function that takes two lists of numbers,\n",
|
|
" and determines whether it is possible to perform an exchange of elements\n",
|
|
" between them to make lst1 a list of only even numbers.\n",
|
|
" There is no limit on the number of exchanged elements between lst1 and lst2.\n",
|
|
" If it is possible to exchange elements between the lst1 and lst2 to make\n",
|
|
" all the elements of lst1 to be even, return \"YES\".\n",
|
|
" Otherwise, return \"NO\".\n",
|
|
" For example:\n",
|
|
" exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n",
|
|
" exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n",
|
|
" It is assumed that the input lists will be non-empty.\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" # Count the number of odd numbers in lst1\n",
|
|
" odd_count_lst1 = sum(1 for x in lst1 if x % 2 != 0)\n",
|
|
" \n",
|
|
" # Count the number of even numbers in lst2\n",
|
|
" even_count_lst2 = sum(1 for x in lst2 if x % 2 == 0)\n",
|
|
" \n",
|
|
" # If there are no odd numbers in lst1, it's already valid\n",
|
|
" if odd_count_lst1 == 0:\n",
|
|
" return \"YES\"\n",
|
|
" \n",
|
|
" # If there are enough even numbers in lst2 to replace all odd numbers in lst1\n",
|
|
" if even_count_lst2 >= odd_count_lst1:\n",
|
|
" return \"YES\"\n",
|
|
" \n",
|
|
" return \"NO\"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from evalplus.data import get_human_eval_plus\n",
|
|
"\n",
|
|
"humaneval = get_human_eval_plus()\n",
|
|
"print(humaneval['HumanEval/110'][\"prompt\"])\n",
|
|
"\n",
|
|
"result = {\"solution\": \"def exchange(lst1, lst2):\\n \\\"\\\"\\\"Determines whether it is possible to perform an exchange of elements\\n between two lists to make lst1 a list of only even numbers.\\n \\n Args:\\n lst1 (list): The first list of numbers.\\n lst2 (list): The second list of numbers.\\n \\n Returns:\\n str: \\\"YES\\\" if lst1 can be made all even, \\\"NO\\\" otherwise.\\n \\\"\\\"\\\"\\n # Check if lst1 already contains only even numbers\\n if all(x % 2 == 0 for x in lst1):\\n return \\\"YES\\\"\\n \\n # Count the number of odd numbers in lst1\\n odd_count_lst1 = sum(1 for x in lst1 if x % 2 != 0)\\n \\n # Check if lst2 has at least one even number to exchange\\n has_even_in_lst2 = any(x % 2 == 0 for x in lst2)\\n \\n # If lst1 has odd numbers and lst2 has at least one even number, we can exchange\\n if odd_count_lst1 > 0 and has_even_in_lst2:\\n return \\\"YES\\\"\\n \\n return \\\"NO\\\"\"}\n",
|
|
"print(result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"correct_result = {\"solution\": \"def exchange(lst1, lst2):\\n \\\"\\\"\\\"In this problem, you will implement a function that takes two lists of numbers,\\n and determines whether it is possible to perform an exchange of elements\\n between them to make lst1 a list of only even numbers.\\n There is no limit on the number of exchanged elements between lst1 and lst2.\\n If it is possible to exchange elements between the lst1 and lst2 to make\\n all the elements of lst1 to be even, return \\\"YES\\\".\\n Otherwise, return \\\"NO\\\".\\n For example:\\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \\\"YES\\\"\\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \\\"NO\\\"\\n It is assumed that the input lists will be non-empty.\\n \\\"\\\"\\\"\\n \\n # Count the number of odd numbers in lst1\\n odd_count_lst1 = sum(1 for x in lst1 if x % 2 != 0)\\n \\n # Count the number of even numbers in lst2\\n even_count_lst2 = sum(1 for x in lst2 if x % 2 == 0)\\n \\n # If there are no odd numbers in lst1, it's already valid\\n if odd_count_lst1 == 0:\\n return \\\"YES\\\"\\n \\n # If there are enough even numbers in lst2 to replace all odd numbers in lst1\\n if even_count_lst2 >= odd_count_lst1:\\n return \\\"YES\\\"\\n \\n return \\\"NO\\\"\"}\n",
|
|
"print(correct_result[\"solution\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"\n",
|
|
"def count_distinct_characters(string: str) -> int:\n",
|
|
" \"\"\" Given a string, find out how many distinct characters (regardless of case) does it consist of\n",
|
|
" >>> count_distinct_characters('xyzXYZ')\n",
|
|
" 3\n",
|
|
" >>> count_distinct_characters('Jerry')\n",
|
|
" 4\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
"def count_distinct_characters(string: str) -> int:\n",
|
|
" \"\"\" Given a string, find out how many distinct characters (regardless of case) does it consist of\n",
|
|
" >>> count_distinct_characters('xyzXYZ')\n",
|
|
" 3\n",
|
|
" >>> count_distinct_characters('Jerry')\n",
|
|
" 4\n",
|
|
" \"\"\"\n",
|
|
" # Convert the string to lowercase to ensure case insensitivity\n",
|
|
" lower_string = string.lower()\n",
|
|
" # Use a set to find distinct characters\n",
|
|
" distinct_characters = set(lower_string)\n",
|
|
" # Return the number of distinct characters\n",
|
|
" return len(distinct_characters)\n",
|
|
"--------------------------\n",
|
|
"def count_distinct_characters(string: str) -> int:\n",
|
|
" \"\"\" Given a string, find out how many distinct characters (regardless of case) does it consist of\n",
|
|
" >>> count_distinct_characters('xyzXYZ')\n",
|
|
" 3\n",
|
|
" >>> count_distinct_characters('Jerry')\n",
|
|
" 4\n",
|
|
" \"\"\"\n",
|
|
" # Convert the string to lowercase to ensure case insensitivity\n",
|
|
" lower_string = string.lower()\n",
|
|
" # Use a set to find distinct characters\n",
|
|
" distinct_characters = set(lower_string)\n",
|
|
" # Return the number of distinct characters\n",
|
|
" return len(distinct_characters)\n",
|
|
"--------------------------\n",
|
|
"def count_distinct_characters(string: str) -> int:\n",
|
|
" \"\"\" \n",
|
|
" Given a string, find out how many distinct characters (regardless of case) does it consist of.\n",
|
|
" \n",
|
|
" >>> count_distinct_characters('xyzXYZ')\n",
|
|
" 3\n",
|
|
" >>> count_distinct_characters('Jerry')\n",
|
|
" 4\n",
|
|
" >>> count_distinct_characters('')\n",
|
|
" 0\n",
|
|
" >>> count_distinct_characters('aA')\n",
|
|
" 1\n",
|
|
" >>> count_distinct_characters('123abcABC!@#')\n",
|
|
" 9\n",
|
|
" >>> count_distinct_characters(' ')\n",
|
|
" 0\n",
|
|
" >>> count_distinct_characters('!@#$%^&*()')\n",
|
|
" 10\n",
|
|
" \"\"\"\n",
|
|
" # Convert the string to lowercase to ensure case insensitivity\n",
|
|
" lower_string = string.lower()\n",
|
|
" \n",
|
|
" # Use a set to store distinct characters\n",
|
|
" distinct_characters = set()\n",
|
|
" \n",
|
|
" # Iterate through each character in the string\n",
|
|
" for char in lower_string:\n",
|
|
" # Add only non-space characters to the set\n",
|
|
" if char != ' ':\n",
|
|
" distinct_characters.add(char)\n",
|
|
" \n",
|
|
" # Return the number of distinct characters\n",
|
|
" return len(distinct_characters)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from evalplus.data import get_human_eval_plus\n",
|
|
"\n",
|
|
"humaneval = get_human_eval_plus()\n",
|
|
"print(humaneval['HumanEval/16'][\"prompt\"])\n",
|
|
"\n",
|
|
"result = {\"task_id\": \"HumanEval/16\", \"solution\": \"def count_distinct_characters(string: str) -> int:\\n \\\"\\\"\\\" Given a string, find out how many distinct characters (regardless of case) does it consist of\\n >>> count_distinct_characters('xyzXYZ')\\n 3\\n >>> count_distinct_characters('Jerry')\\n 4\\n \\\"\\\"\\\"\\n # Convert the string to lowercase to ensure case insensitivity\\n lower_string = string.lower()\\n # Use a set to find distinct characters\\n distinct_characters = set(lower_string)\\n # Return the number of distinct characters\\n return len(distinct_characters)\"}\n",
|
|
"print(result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"correct_result = {\"task_id\": \"HumanEval/16\", \"solution\": \"def count_distinct_characters(string: str) -> int:\\n \\\"\\\"\\\" Given a string, find out how many distinct characters (regardless of case) does it consist of\\n >>> count_distinct_characters('xyzXYZ')\\n 3\\n >>> count_distinct_characters('Jerry')\\n 4\\n \\\"\\\"\\\"\\n # Convert the string to lowercase to ensure case insensitivity\\n lower_string = string.lower()\\n # Use a set to find distinct characters\\n distinct_characters = set(lower_string)\\n # Return the number of distinct characters\\n return len(distinct_characters)\"}\n",
|
|
"\n",
|
|
"print(correct_result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"modify_result = {\"task_id\": \"HumanEval/16\", \"solution\": \"def count_distinct_characters(string: str) -> int:\\n \\\"\\\"\\\" \\n Given a string, find out how many distinct characters (regardless of case) does it consist of.\\n \\n >>> count_distinct_characters('xyzXYZ')\\n 3\\n >>> count_distinct_characters('Jerry')\\n 4\\n >>> count_distinct_characters('')\\n 0\\n >>> count_distinct_characters('aA')\\n 1\\n >>> count_distinct_characters('123abcABC!@#')\\n 9\\n >>> count_distinct_characters(' ')\\n 0\\n >>> count_distinct_characters('!@#$%^&*()')\\n 10\\n \\\"\\\"\\\"\\n # Convert the string to lowercase to ensure case insensitivity\\n lower_string = string.lower()\\n \\n # Use a set to store distinct characters\\n distinct_characters = set()\\n \\n # Iterate through each character in the string\\n for char in lower_string:\\n # Add only non-space characters to the set\\n if char != ' ':\\n distinct_characters.add(char)\\n \\n # Return the number of distinct characters\\n return len(distinct_characters)\"}\n",
|
|
"\n",
|
|
"print(modify_result[\"solution\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"def fix_spaces(text):\n",
|
|
" \"\"\"\n",
|
|
" Given a string text, replace all spaces in it with underscores, \n",
|
|
" and if a string has more than 2 consecutive spaces, \n",
|
|
" then replace all consecutive spaces with - \n",
|
|
" \n",
|
|
" fix_spaces(\"Example\") == \"Example\"\n",
|
|
" fix_spaces(\"Example 1\") == \"Example_1\"\n",
|
|
" fix_spaces(\" Example 2\") == \"_Example_2\"\n",
|
|
" fix_spaces(\" Example 3\") == \"_Example-3\"\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
"def fix_spaces(text):\n",
|
|
" \"\"\"\n",
|
|
" Given a string text, replace all spaces in it with underscores, \n",
|
|
" and if a string has more than 2 consecutive spaces, \n",
|
|
" then replace all consecutive spaces with - \n",
|
|
" \n",
|
|
" fix_spaces(\"Example\") == \"Example\"\n",
|
|
" fix_spaces(\"Example 1\") == \"Example_1\"\n",
|
|
" fix_spaces(\" Example 2\") == \"_Example_2\"\n",
|
|
" fix_spaces(\" Example 3\") == \"_Example-3\"\n",
|
|
" \"\"\"\n",
|
|
" # Replace multiple spaces with a placeholder\n",
|
|
" # This will help us identify sequences of spaces\n",
|
|
" placeholder = '##'\n",
|
|
" text = text.replace(' ' * 3, placeholder) # Replace 3 spaces with a placeholder\n",
|
|
" \n",
|
|
" # Replace remaining spaces with underscores\n",
|
|
" text = text.replace(' ', '_')\n",
|
|
" \n",
|
|
" # Replace the placeholder back to '-'\n",
|
|
" text = text.replace(placeholder, '-')\n",
|
|
" \n",
|
|
" return text\n",
|
|
"--------------------------\n",
|
|
"def fix_spaces(text):\n",
|
|
" \"\"\"\n",
|
|
" Given a string text, replace all spaces in it with underscores, \n",
|
|
" and if a string has more than 2 consecutive spaces, \n",
|
|
" then replace all consecutive spaces with - \n",
|
|
" \n",
|
|
" fix_spaces(\"Example\") == \"Example\"\n",
|
|
" fix_spaces(\"Example 1\") == \"Example_1\"\n",
|
|
" fix_spaces(\" Example 2\") == \"_Example_2\"\n",
|
|
" fix_spaces(\" Example 3\") == \"_Example-3\"\n",
|
|
" \"\"\"\n",
|
|
" # Replace multiple spaces with a placeholder\n",
|
|
" # This will help us identify sequences of spaces\n",
|
|
" placeholder = ' ' * 3 # Three spaces\n",
|
|
" text = text.replace(placeholder, ' - ')\n",
|
|
" \n",
|
|
" # Replace all remaining spaces with underscores\n",
|
|
" text = text.replace(' ', '_')\n",
|
|
" \n",
|
|
" # Replace the placeholder with a single dash\n",
|
|
" text = text.replace(' - ', '-')\n",
|
|
" \n",
|
|
" return text\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"\n",
|
|
"from evalplus.data import get_human_eval_plus\n",
|
|
"\n",
|
|
"humaneval = get_human_eval_plus()\n",
|
|
"print(humaneval['HumanEval/140'][\"prompt\"])\n",
|
|
"\n",
|
|
"correct_result = {\"task_id\": \"HumanEval/140\", \"solution\": \"def fix_spaces(text):\\n \\\"\\\"\\\"\\n Given a string text, replace all spaces in it with underscores, \\n and if a string has more than 2 consecutive spaces, \\n then replace all consecutive spaces with - \\n \\n fix_spaces(\\\"Example\\\") == \\\"Example\\\"\\n fix_spaces(\\\"Example 1\\\") == \\\"Example_1\\\"\\n fix_spaces(\\\" Example 2\\\") == \\\"_Example_2\\\"\\n fix_spaces(\\\" Example 3\\\") == \\\"_Example-3\\\"\\n \\\"\\\"\\\"\\n # Replace multiple spaces with a placeholder\\n # This will help us identify sequences of spaces\\n placeholder = '##'\\n text = text.replace(' ' * 3, placeholder) # Replace 3 spaces with a placeholder\\n \\n # Replace remaining spaces with underscores\\n text = text.replace(' ', '_')\\n \\n # Replace the placeholder back to '-'\\n text = text.replace(placeholder, '-')\\n \\n return text\"}\n",
|
|
"\n",
|
|
"print(correct_result[\"solution\"])\n",
|
|
"\n",
|
|
"print(\"--------------------------\")\n",
|
|
"\n",
|
|
"modify_result = {\"task_id\": \"HumanEval/140\", \"solution\": \"def fix_spaces(text):\\n \\\"\\\"\\\"\\n Given a string text, replace all spaces in it with underscores, \\n and if a string has more than 2 consecutive spaces, \\n then replace all consecutive spaces with - \\n \\n fix_spaces(\\\"Example\\\") == \\\"Example\\\"\\n fix_spaces(\\\"Example 1\\\") == \\\"Example_1\\\"\\n fix_spaces(\\\" Example 2\\\") == \\\"_Example_2\\\"\\n fix_spaces(\\\" Example 3\\\") == \\\"_Example-3\\\"\\n \\\"\\\"\\\"\\n # Replace multiple spaces with a placeholder\\n # This will help us identify sequences of spaces\\n placeholder = ' ' * 3 # Three spaces\\n text = text.replace(placeholder, ' - ')\\n \\n # Replace all remaining spaces with underscores\\n text = text.replace(' ', '_')\\n \\n # Replace the placeholder with a single dash\\n text = text.replace(' - ', '-')\\n \\n return text\"}\n",
|
|
"\n",
|
|
"print(modify_result[\"solution\"])"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "ags_env",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.19"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|