diff --git a/.gitignore b/.gitignore index 54fd3a5..71bc658 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.vscode/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/DATASHEET.md b/DATASHEET.md index a789e0c..4a7cacd 100644 --- a/DATASHEET.md +++ b/DATASHEET.md @@ -59,7 +59,7 @@ If so, please provide a description. If not, you may skip the remainder of the q * Any other comments? ### Uses * Has the dataset been used for any tasks already? If so, please provide a description. *See upcoming arXiv paper.* -* Is there a repository that links to any or all papers or systems that use the dataset? If so, please provide a link or other access point. *Relevent papers will be linked to in GitHub* +* Is there a repository that links to any or all papers or systems that use the dataset? If so, please provide a link or other access point. *Relevant papers will be linked to in GitHub* * What (other) tasks could the dataset be used for? *Dataset could be used to teach or evaluate human programmers in Python as well as computers* * Is there anything about the composition of the dataset or the way it was collected and preprocessed/cleaned/labeled that might impact future uses? For example, is there anything that a future user might need to know to avoid uses that @@ -86,4 +86,4 @@ an algorithm.* No personal data* * Will older versions of the dataset continue to be supported/hosted/maintained? If so, please describe how. If not, please describe how its obsolescence will be communicated to users. *Older versions will remain on GitHub for reproducibility* * If others want to extend/augment/build on/contribute to the dataset, is there a mechanism for them to do so? If so, please provide a description. Will these contributions be validated/verified? If so, please describe how. If not, why not? Is there a process for communicating/distributing these contributions to other users? *Contributions are welcome and appreciated through GitHub* -* Any other comments? \ No newline at end of file +* Any other comments? diff --git a/ICLR2023/README.md b/ICLR2023/README.md new file mode 100755 index 0000000..124afa4 --- /dev/null +++ b/ICLR2023/README.md @@ -0,0 +1,147 @@ +This is the code and data for the paper: Language Models can teach themselves to code better +https://arxiv.org/abs/2207.14502 + +LICENSE +MIT License - as already specified in the ../LICENSE file of PythonProgrammingPuzzles repo + +GPU USAGE +GPU usage was large , especially for the 2.7B sized model which is ~20X the 125M. +Data generation takes the most GPU usage and took about 2500 GPU hours for 2.7B (on v100) +Finetuning on the 1M generated data took about 40 GPU hours for 2.7B (on v100) per epoch of finetuning - 10 epochs = 400 GPU hours +Solving the 228 problem testset with 100 attempts using the finetuned 2.7B model took about 4 hours (on v100) +We mostly used v100, but we used whatever was available, so T4 and A100 sometimes if they were free. +Tried everything at 125M first - debug there and make it work perfect - then roll out the 1.3 and 2.7 jobs + +DATASETS +In data directory are the datasets used. We feel the most interesting dataset is data/Codex_PAPER_1M_iter_0.txt +which is generated by Codex and gave the best results when finetuned on. All the datasets are part of our public release. + +SETUP +src/requirements.txt is what we install on our cluster machines - the cluster comes with NVidia drivers and matching pytorch +./requirements.txt is what I personally have installed on my local machine and tested this runs - but it has lots of stuff you don't need +So try src/requirements.txt only - and if that doesn't work - then /requirements.txt has all versions of everything installed on my machine +Getting a deepspeed 0.6.1 matching a pytorch matching a nvidia driver install was tricky for me on some machines, torch 1.10 and 1.11 both work + +GENERATING/FINETUNING -> run "cd src, ./babysit.sh GPU_INDEX_TO_USE" -> GPU_INDEX_TO_USE=0 typically +In src/babysit.sh is the script that generates data, and finetunes on that data in a loop, finetuning the GPT-Neo 125M/1.3B/2.7B models +In src/babysit.sh TEST_LOCAL=1 controls running locally on machine's GPUs which is great for fast testing, or =0 is launching on the cluster which is slow but has lots of GPUs +Realistically you have to train on a cluster - data generation takes a long time so having lots of machines all generating data is the feasible approach. +But given enough time - this will run locally on 1 GPU. 1 year for 2.7B, or 2 weeks for 125M. +We found generating 75k samples after deduping worked for iteration_0 - finetune on that data. +Then using that fine_tuned model in iter_1 generating data happens more quickly - the finetuned model solves many more problems +Repeating that process works well. +On 125M we looked at just training on only 125M generated data from iter_0 versus iter_1 versus iter_2 - generating 600K for each iteration. +It seemed finetuning on iter_2 data was best on the testset 26.9/228 solved vs iter_1=26.1/228 vs iter_0=22.2/228 +With 1M samples from 125M generated data sampled across all the iterations 0,1,2 we got 26.75/228 +We understand why it's faster to generate iter_2 data on a finetuned model - it solves more problems. +But why are the generated puzzles&solutions better for training the model on? +We will explore that more in the future - and try iterating a lot farther than 3 iterations - although our preliminary experiments on 125M show it tops out at 3 iterations + +FINETUNING ONLY -> run "cd src, ./fine_tune1.sh GPU_INDEX_TO_USE" -> GPU_INDEX_TO_USE=0 typically +# ./fine_tune1.sh GPU MODEL_TO_TRAIN EXPERIMENT_NAME_DIRECTORY TRAIN_DATA EPOCHS +This allows the repeated finetuning on a specific dataset. +Use this to do a temperature grid search, or try different variations of parameters on a specific dataset. + +Detailed instructions for reproducing experiments: +# Generating Codex data +python gen.py -n=32 -max_tokens=4096 -model_path=openai/code-davinci-002 -model_path_solve=openai/code-cushman-001 -out=../data/codex/iter_0 -seed=2022 + +# Measuring codex accuracy via API calls +./solve2.sh +python solve.py -prefix=../data/train_prefix.txt -attempts=1 -model_path=openai/code-cushman-001 -gpu=0 -fixed_temp=0.8 -out=../data/codex -puzzles=../data/test_228.json -seed=2022 -batch_size=64 + +# Producing verified Codex_PAPER_1M_iter_0.txt from the puzzle/solution old style data generated by Codex +python preprocess.py -path=../data/codex/old_verified -f_name=Codex_PAPER_1M_iter_0.txt -max_sols_per_puzzle=8 -old_style_json=True -max_examples=1000000 -include_failures=False -seed=2022 +cp ../data/codex/old/Codex_PAPER_1M_iter_0.txt ../data/Codex_PAPER_1M_iter_0.txt + +# Producing unverified Codex_unverified_PAPER_1M_iter_0.txt from the puzzle/solution old style data generated by Codex +python preprocess.py -path=../data/codex/old_unverified -f_name=Codex_unverified_PAPER_1M_iter_0.txt -max_sols_per_puzzle=8 -old_style_json=True -max_examples=1000000 -include_failures=True -seed=2022 +cp ../data/codex/old_unverified/Codex_unverified_PAPER_1M_iter_0.txt ../data/Codex_unverified_PAPER_1M_iter_0.txt + +# Producing 125M_PAPER_25K_iter_0.txt from the puzzle/solution new style data +python preprocess.py ../data/125M_PAPER/iter_0 125M_PAPER_25K_iter_0.txt 8 False 25000 False -seed=2022 +cp ../data/125M_PAPER/iter_0/125M_PAPER_25K_iter_0.txt ../data/125M_PAPER_25K_iter_0.txt + +# Producing 125M_PAPER_1M_iter_1.txt from the puzzle/solution new style data +python preprocess.py ../data/125M_PAPER/iter_1 125M_PAPER_1M_iter_1.txt 8 False 1000000 False -seed=2022 +cp ../data/125M_PAPER/iter_1/125M_PAPER_1M_iter_1.txt ../data/125M_PAPER_1M_iter_1.txt + +# Producing 125M_PAPER_1M_iter_2.txt from the puzzle/solution new style data13B +python preprocess.py ../data/125M_PAPER/iter_2 125M_PAPER_1M_iter_2.txt 8 False 1000000 False -seed=2022 +cp ../data/125M_PAPER/iter_2/125M_PAPER_1M_iter_2.txt ../data/125M_PAPER_1M_iter_2.txt + +# Producing 13B_PAPER_25K_iter_0.txt from the puzzle/solution new style data +python preprocess.py ../data/13B_PAPER/iter_0 13B_PAPER_25K_iter_0.txt 8 False 25000 False -seed=2022 +cp ../data/13B_PAPER/iter_0/13B_PAPER_25K_iter_0.txt ../data/13B_PAPER_25K_iter_0.txt + +# Producing 13B_PAPER_1M_iter_1.txt from the puzzle/solution new style data +python preprocess.py ../data/13B_PAPER/iter_1 13B_PAPER_1M_iter_1.txt 8 False 1000000 False -seed=2022 +cp ../data/13B_PAPER/iter_1/13B_PAPER_1M_iter_1.txt ../data/13B_PAPER_1M_iter_1.txt + +# Producing 13B_PAPER_1M_iter_2.txt from the puzzle/solution new style data +python preprocess.py ../data/13B_PAPER/iter_2 13B_PAPER_1M_iter_2.txt 8 False 1000000 False -seed=2022 +cp ../data/13B_PAPER/iter_2/13B_PAPER_1M_iter_2.txt ../data/13B_PAPER_1M_iter_2.txt + +# Producing 27B_PAPER_25K_iter_0.txt from the puzzle/solution new style data +python preprocess.py ../data/27B_PAPER/iter_0 27B_PAPER_25K_iter_0.txt 8 False 25000 False -seed=2022 +cp ../data/27B_PAPER/iter_0/27B_PAPER_25K_iter_0.txt ../data/27B_PAPER_25K_iter_0.txt + +# Producing 27B_PAPER_1M_iter_1.txt from the puzzle/solution new style data +python preprocess.py ../data/27B_PAPER/iter_1 27B_PAPER_1M_iter_1.txt 8 False 1000000 False -seed=2022 +cp ../data/27B_PAPER/iter_1/27B_PAPER_1M_iter_1.txt ../data/27B_PAPER_1M_iter_1.txt + +# Producing 27B_PAPER_1M_iter_2.txt from the puzzle/solution new style data +python preprocess.py ../data/27B_PAPER/iter_2 27B_PAPER_1M_iter_2.txt 8 False 1000000 False -seed=2022 +cp ../data/27B_PAPER/iter_2/27B_PAPER_1M_iter_2.txt ../data/27B_PAPER_1M_iter_2.txt + +# Data files produced by babysit.sh - generating data from gpt-neo-* and Codex +# At the time of experiments running, Codex wasn't finetunable, so only iteration 0 data was available +Codex_PAPER_1M_iter_0.txt +125M_PAPER_25K_iter_0.txt +13B_PAPER_25K_iter_0.txt +27B_PAPER_25K_iter_0.txt +125M_PAPER_1M_iter_1.txt +13B_PAPER_1M_iter_1.txt +27B_PAPER_1M_iter_1.txt +125M_PAPER_1M_iter_2.txt +13B_PAPER_1M_iter_2.txt +27B_PAPER_1M_iter_2.txt + +# Figure 5 - 3 diagrams - showing the 3 GPT models trained on verified codex vs unverified codex vs baseline +# 5a GPT-NEO 125M +./fine_tune1.sh 0 125M ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt +./fine_tune1.sh 0 125M ft1_Codex_unverified_PAPER_1M_iter_0 Codex_unverified_PAPER_1M_iter_0.txt +./solve1.sh 0 125M 10 228 +# 5b GPT-NEO 13B +./fine_tune1.sh 0 13B ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt +./fine_tune1.sh 0 13B ft1_Codex_unverified_PAPER_1M_iter_0 Codex_unverified_PAPER_1M_iter_0.txt +./solve1.sh 0 13B 10 228 5 +# 5c GPT-NEO 27B +./fine_tune1.sh 0 27B ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt +./fine_tune1.sh 0 27B ft1_Codex_unverified_PAPER_1M_iter_0 Codex_unverified_PAPER_1M_iter_0.txt +./solve1.sh 0 13B 10 228 5 + +# Figure 6 - 3 diagrams - showing test228 Pass@ for the 3 GPT models trained on data from 4 generators (codex and 3 GPT-Neo) and baseline +# 6a - GPT-NEO 125M trained on 4 different datasets and baseline +# ./fine_tune1.sh 0 125M ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt (dupe of 5a) +./fine_tune1.sh 0 125M ft1_125M_PAPER_1M_iter_2 125M_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 125M ft1_13B_PAPER_1M_iter_2 13B_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 125M ft1_27B_PAPER_1M_iter_2 27B_PAPER_1M_iter_2.txt + +# 6b - GPT-NEO 13B trained on 4 different datasets and baseline +# ./fine_tune1.sh 0 13B ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt (dupe of 5b) +./fine_tune1.sh 0 13B ft1_125M_PAPER_1M_iter_2 125M_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 13B ft1_13B_PAPER_1M_iter_2 13B_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 13B ft1_27B_PAPER_1M_iter_2 27B_PAPER_1M_iter_2.txt + +# 6c - GPT-NEO 27B trained on 4 different datasets and baseline +# ./fine_tune1.sh 0 27B ft1_Codex_PAPER_1M_iter_0 Codex_PAPER_1M_iter_0.txt (dupe of 5c) +./fine_tune1.sh 0 27B ft1_125M_PAPER_1M_iter_2 125M_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 27B ft1_13B_PAPER_1M_iter_2 13B_PAPER_1M_iter_2.txt +./fine_tune1.sh 0 27B ft1_27B_PAPER_1M_iter_2 27B_PAPER_1M_iter_2.txt + +# Launch on torch2020 - edit solve.yaml for correct parameters of model and epoch +./tst_human_eval_base.sh 0 125M 1024 +./tst_human_eval_ft1.sh 0 125M 1024 +./tst_human_eval_ft5.sh 0 125M 1024 +./tst_human_eval_ft10.sh 0 125M 1024 diff --git a/ICLR2023/data/125M_PAPER_1M_iter_1.txt.gz b/ICLR2023/data/125M_PAPER_1M_iter_1.txt.gz new file mode 100644 index 0000000..948467e Binary files /dev/null and b/ICLR2023/data/125M_PAPER_1M_iter_1.txt.gz differ diff --git a/ICLR2023/data/13B_PAPER_1M_iter_1.txt.gz b/ICLR2023/data/13B_PAPER_1M_iter_1.txt.gz new file mode 100644 index 0000000..f4fee2c Binary files /dev/null and b/ICLR2023/data/13B_PAPER_1M_iter_1.txt.gz differ diff --git a/ICLR2023/data/27B_PAPER_1M_iter_1.txt.gz b/ICLR2023/data/27B_PAPER_1M_iter_1.txt.gz new file mode 100644 index 0000000..d82c3fc Binary files /dev/null and b/ICLR2023/data/27B_PAPER_1M_iter_1.txt.gz differ diff --git a/ICLR2023/data/350M_PAPER_1M_iter_0.txt.gz b/ICLR2023/data/350M_PAPER_1M_iter_0.txt.gz new file mode 100644 index 0000000..f51941b Binary files /dev/null and b/ICLR2023/data/350M_PAPER_1M_iter_0.txt.gz differ diff --git a/ICLR2023/data/Codex_PAPER_1M_iter_0.txt.gz b/ICLR2023/data/Codex_PAPER_1M_iter_0.txt.gz new file mode 100644 index 0000000..0a1c127 Binary files /dev/null and b/ICLR2023/data/Codex_PAPER_1M_iter_0.txt.gz differ diff --git a/ICLR2023/requirements.txt b/ICLR2023/requirements.txt new file mode 100644 index 0000000..11cc109 --- /dev/null +++ b/ICLR2023/requirements.txt @@ -0,0 +1,249 @@ +adal==1.2.7 +aiohttp==3.8.5 +aiosignal==1.2.0 +amlt==8.0.9 +applicationinsights==0.11.10 +asn1crypto==0.24.0 +astor==0.8.1 +async-timeout==4.0.1 +attrs==17.4.0 +Automat==0.6.0 +azure-common==1.1.27 +azure-core==1.17.0 +azure-data-tables==12.0.0b6 +azure-graphrbac==0.61.1 +azure-identity==1.4.1 +azure-mgmt-authorization==0.61.0 +azure-mgmt-containerregistry==2.8.0 +azure-mgmt-keyvault==2.2.0 +azure-mgmt-resource==13.0.0 +azure-mgmt-storage==11.2.0 +azure-storage-blob==2.1.0 +azure-storage-common==2.1.0 +azure-storage-file==2.1.0 +azureml-automl-core==1.26.0 +azureml-contrib-k8s==0.1.16 +azureml-contrib-pipeline-steps==1.26.0 +azureml-core==1.26.0 +azureml-dataprep==2.13.2 +azureml-dataprep-native==32.0.0 +azureml-dataprep-rslex==1.11.2 +azureml-dataset-runtime==1.26.0 +azureml-k8s-mt==1.0.4 +azureml-pipeline-core==1.26.0 +azureml-pipeline-steps==1.26.0 +azureml-telemetry==1.26.0 +azureml-train-automl-client==1.26.0 +azureml-train-core==1.26.0 +azureml-train-restclients-hyperdrive==1.26.0 +backcall==0.2.0 +backports.tempfile==1.0 +backports.weakref==1.0.post1 +beautifulsoup4==4.9.3 +bitstring==3.1.9 +black==21.8b0 +blinker==1.4 +blis==0.7.4 +blobxfer==1.10.0 +cachetools==4.2.2 +catalogue==2.0.6 +certifi==2023.7.22 +cffi==1.14.6 +chardet==3.0.4 +charset-normalizer==2.0.7 +click==7.1.2 +click-completion @ git+https://github.com/temporaer/click-completion.git@41b21868cac0781d25b37da624bae2fd1f36be88 +click-option-group==0.5.3 +click-plugins==1.1.1 +cloud-init==20.2 +cloudpickle==1.6.0 +colorama==0.3.7 +colorlog==6.4.1 +command-not-found==0.3 +configobj==5.0.6 +configparser==5.0.2 +constantly==15.1.0 +contextlib2==21.6.0 +cryptography==41.0.4 +cycler==0.10.0 +cymem==2.0.5 +datasets==1.15.1 +debugpy==1.4.3 +decorator==5.0.9 +deepspeed==0.5.1 +dill==0.3.4 +distro==1.6.0 +distro-info===0.18ubuntu0.18.04.1 +docker==5.0.1 +docker-pycreds==0.4.0 +dotnetcore2==2.1.21 +ecdsa==0.17.0 +entrypoints==0.3 +et-xmlfile==1.1.0 +fail2ban==0.10.2 +fastai==2.5.2 +fastcore==1.3.26 +fastdownload==0.0.5 +fastprogress==1.0.0 +filelock==3.0.12 +Flask==2.3.2 +Flask-Cors==3.0.10 +Flask-Executor==0.9.4 +Flask-FontAwesome==0.1.5 +frozenlist==1.2.0 +fsspec==2021.11.0 +gitdb==4.0.7 +GitPython==3.1.35 +httplib2==0.19.0 +huggingface-hub==0.1.2 +humanize==3.11.0 +hyperlink==17.3.1 +idna==2.6 +incremental==16.10.1 +ipdb==0.13.9 +ipykernel==6.4.1 +ipython==8.10.0 +ipython-genutils==0.2.0 +isodate==0.6.0 +itsdangerous==2.0.1 +jedi==0.18.0 +Jinja2==3.0.1 +jmespath==0.10.0 +joblib==1.2.0 +jsonpatch==1.16 +jsonpickle==2.0.0 +jsonpointer==1.10 +jsonschema==2.6.0 +jupyter-client==7.0.5 +jupyter-core==4.11.2 +keyring==10.6.0 +keyrings.alt==3.0 +kiwisolver==1.3.2 +language-selector==0.1 +libtmux==0.10.1 +Mako==1.2.2 +MarkupSafe==2.0.1 +marshmallow==3.10.0 +matplotlib==3.4.3 +matplotlib-inline==0.1.3 +mlb-core==0.0.4 +msal==1.14.0 +msal-extensions==0.2.2 +msrest==0.6.19 +msrestazure==0.6.4 +multidict==5.2.0 +multiprocess==0.70.12.2 +murmurhash==1.0.5 +mypy-extensions==0.4.3 +ndg-httpsclient==0.5.1 +nest-asyncio==1.5.1 +netifaces==0.10.4 +ninja==1.10.2 +ntlm-auth==1.5.0 +numpy==1.22.0 +oauthlib==3.2.2 +openai==0.13.0 +openpyxl==3.0.9 +orderedset==2.0.3 +packaging==21.0 +PAM==0.4.2 +pandas==1.3.2 +pandas-stubs==1.2.0.45 +parso==0.8.2 +passpy==1.0.2 +pathspec==0.9.0 +pathtools==0.1.2 +pathy==0.6.0 +Pebble==4.6.3 +petname==2.6 +pexpect==4.8.0 +pickleshare==0.7.5 +Pillow==10.0.1 +platformdirs==2.3.0 +portalocker==1.7.1 +preshed==3.0.5 +promise==2.3 +prompt-toolkit==3.0.20 +protobuf==3.18.3 +psb2==1.0.0 +psutil==5.8.0 +ptyprocess==0.7.0 +pyarrow==1.0.1 +pyasn1==0.4.2 +pyasn1-modules==0.2.1 +pycparser==2.20 +pycrypto==2.6.1 +pydantic==1.8.2 +Pygments==2.15.0 +PyGObject==3.26.1 +PyJWT==2.4.0 +pyOpenSSL==17.5.0 +pyparsing==2.4.7 +pyperclip==1.8.2 +pyserial==3.4 +python-apt==1.6.5+ubuntu0.3 +python-dateutil==2.8.2 +python-debian==0.1.32 +python-gnupg==0.4.7 +pytz==2021.1 +pyxdg==0.26 +PyYAML==5.4.1 +pyzmq==22.3.0 +regex==2021.8.28 +requests==2.31.0 +requests-ntlm==1.1.0 +requests-oauthlib==1.3.0 +requests-unixsocket==0.1.5 +ruamel.yaml==0.17.16 +ruamel.yaml.clib==0.2.6 +sacremoses==0.0.45 +scikit-learn==0.24.2 +scipy==1.10.0 +SecretStorage==2.3.1 +sentry-sdk==1.14.0 +service-identity==16.0.0 +shellingham==1.4.0 +shortuuid==1.0.1 +six==1.16.0 +sklearn==0.0 +smart-open==5.2.1 +smmap==4.0.0 +soupsieve==2.2.1 +spacy==3.1.2 +spacy-legacy==3.0.8 +srsly==2.4.1 +ssh-import-id==5.7 +sshpubkeys==3.3.1 +strictfire==0.4.1 +subprocess32==3.5.4 +systemd-python==234 +tabulate==0.8.9 +tensorboardX==1.8 +termcolor==1.1.0 +thinc==8.0.10 +threadpoolctl==2.2.0 +tokenizers==0.10.3 +toml==0.10.2 +tomli==1.2.1 +torch==1.13.1 +torchvision==0.10.0 +tornado==6.3.3 +tqdm==4.62.2 +traitlets==5.1.0 +transformers==4.30.0 +Twisted==22.10.0 +typer==0.3.2 +typing-extensions==3.10.0.2 +ufw==0.36 +unattended-upgrades==0.1 +urllib3==1.26.17 +virtualenv==15.1.0 +WALinuxAgent==2.2.45 +wasabi==0.8.2 +wcwidth==0.2.5 +websocket-client==1.2.1 +Werkzeug==2.2.3 +xdg==5.1.1 +xxhash==2.0.2 +yarl==1.7.2 +zope.interface==4.3.2 diff --git a/ICLR2023/src/babysit.sh b/ICLR2023/src/babysit.sh new file mode 100755 index 0000000..cfb3359 --- /dev/null +++ b/ICLR2023/src/babysit.sh @@ -0,0 +1,161 @@ +#!/bin/bash +# All Experiment Settings - constant through the experiment run - passed to gen.sh and fine_tune.sh as needed +GPU=0 # which GPU to use +MODEL="125M" # MODEL is the size of the model: 125M, 13B, 27B +EXPERIMENT=$MODEL"_PAPER" # Name of Experiment directory under data/* and models/base-model/* to store results +TEST_LOCAL=1 # 0 means run gen/fine_tune on cluster remotely, 1 means run gen/fine_tune locally +TARGET_NUM_FILES=1 # How many files to generate in each iteration before starting fine_tuning. Count of unique examples would have been better. +ITER_START=0 # inclusive index to start processing at - creates iter_# under data&models at each iteration. Can continue prev runs by start at prev ITER_MAX +ITER_MAX=5 # exclusive index to stop processing iterations at +EPOCHS_START=1 # inclusive index of epochs to start processing at - could continue prev run by starting at prev EPOCHS_MAX+1 - 0th epoch is the default model so epoch starts at 1 +EPOCHS_MAX=4 # inclusive index of epochs to stop processing at +EPOCHS_PER_STEP=1 # How many EPOCHS through the data to do in each step +TRAIN_INCREMENTAL=0 # Only train on data from the latest iteration, and start finetuning on the last finetuned model - otherwise start from scratch and use all the data generated +TRAIN_BOOST=0 # Initial generation of data from default model is slow - 1 means looks in 125M_RL_ALL to use previous generated initial data to bootstrap. +PASS_AT_K=100 # PASS_AT_K says do K trials to solve to compute Pass@K +LINE_LOG_K=11 # LINE_LOG_K is how many lines of results from solve have results for saving + +echo babysit args: $# $0 $1 $2 $3 $4 + +if (( $# \!= 1 )) +then + echo babysit.sh only takes 1 argument, unless called by another script to initialize configuration variables + return +fi + +if (( $# \>= 1 )) +then + GPU=$1 +fi + +echo babysit GPU $GPU + +for (( iteration=$ITER_START; iteration<$ITER_MAX; iteration++ )) +do + FULLNAME="${EXPERIMENT}---${iteration}" + echo FULLNAME $FULLNAME + export FULLNAME # Needed to pass variable off to yaml job + DATAPATH=data/${EXPERIMENT}/iter_$iteration + echo DATAPATH $DATAPATH + + if (( $TEST_LOCAL \> 0 )) + then + count=`ls -lt ../${DATAPATH} | grep json | wc -l` + else + count=`amlt sto list ${DATAPATH} | grep json | wc -l` + fi + echo count $count + + # Instead of file count we might want to check if the amount of data from preprocess is sufficient + # If not we call to generate more + + if (( $count \> 0 )) + then + echo "$FULLNAME has already been started" + echo "You are resuming at iteration $iteration" + echo "You already have $count files of data this iteration" + else + echo "$FULLNAME is starting generation for iteration $iteration" + fi + + if (( $count \< $TARGET_NUM_FILES )) + then + if (( $TEST_LOCAL \> 0 )) + then + # ./gen.sh $GPU 2560 100 $FULLNAME -1 + # 2.7B 384 100 runs ~10 hours + # 2.7B 160 100 runs ~4.5 hours + ./gen.sh $GPU 256000 100 $FULLNAME -1 + else + amlt run hyper_gen_octows.yaml $FULLNAME -d "$FULLNAME" + exit + fi + fi + + # Running local you are done, but launching on the cloud, you have to wait + for (( poll=0; poll<500; poll++ )) + do + if (( $TEST_LOCAL \> 0 )) + then + count=`ls -lt ../${DATAPATH} | grep json | wc -l` + else + count=`amlt sto list ${DATAPATH} | grep json | wc -l` + fi + + echo "gen wait - Iteration: $iteration, Poll: $poll, Count: $count" + + if (( $count \>= $TARGET_NUM_FILES )) + then + echo "Finished generation iteration $iteration after $poll polls" + break + fi + sleep 3m + done + + # Start a finetune job + if (( $TEST_LOCAL \> 0 )) + then + ./fine_tune.sh $GPU $FULLNAME + else + # Pass enviroment variable FULLNAME to amlt.yaml + amlt run amlt_octo.yaml $FULLNAME -d "$FULLNAME" + exit + fi + + # On cluster we need to wait for finetune job to finish, run locally it's done + # Check the log files for starting the running of solve have been created for the last epoch of training + + MODELPATH=models/gpt-neo-$MODEL/${EXPERIMENT}/iter_$iteration + SOLVE_PATH=$MODELPATH/"epoch_"$EPOCHS_MAX/"solve_"$PASS_AT_K + echo babysit.sh SOLVE_PATH $SOLVE_PATH + + for (( poll=0; poll<500; poll++ )) + do + if (( $TEST_LOCAL \> 0 )) + then + count=`ls -lt ../$SOLVE_PATH | grep json | wc -l` + else + count=`amlt sto list $SOLVE_PATH | grep json | wc -l` + fi + + echo "fine_tune wait - Iteration: $iteration, Poll: $poll, Count: $count" + + if (( $count \>= 1 )) + then + echo "Finished fine_tune iteration $iteration after $poll polls" + break + fi + sleep 3m + done + +done + +# Pull all the results into 1 log file to look at more easily + +if [[ -z "${AMLT_DATA_DIR}" ]]; +then + # running locally on torch2020 so we don't have AMLT enviroment variables defined, so need to set them up + AMLT_DATA_DIR=../data +else + # On remote we don't have access to the log files - maybe could do amlt sto download to do this summary below ? + exit +fi + +BASE_MODEL_PATH=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL +LOG_FILE=$BASE_MODEL_PATH/$EXPERIMENT/"solve_"$PASS_AT_K".txt" +echo solve LOG_FILE for babysit.sh is $LOG_FILE +rm $LOG_FILE + +for (( iteration=$ITER_START; iteration<$ITER_MAX; iteration++ )) +do + for (( epochs=$EPOCHS_START; epochs<=$EPOCHS_MAX; epochs++ )) + do + EPOCH_NAME="epoch_"$epochs + STEP_PATH=$BASE_MODEL_PATH/$EXPERIMENT/iter_$iteration/$EPOCH_NAME + MODEL_PATH=$STEP_PATH/finetuned + echo iteration $iteration epoch $epochs >> $LOG_FILE + head -$LINE_LOG_K $STEP_PATH/"solve_"$PASS_AT_K/results.json >> $LOG_FILE + done +done + +cat $LOG_FILE diff --git a/ICLR2023/src/ds_config_gptneo.json b/ICLR2023/src/ds_config_gptneo.json new file mode 100644 index 0000000..91b4864 --- /dev/null +++ b/ICLR2023/src/ds_config_gptneo.json @@ -0,0 +1,43 @@ +{ + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "optimizer": { + "type": "AdamW", + "params": { + "lr": "auto", + "betas": "auto", + "eps": "auto", + "weight_decay": "auto" + } + }, + "scheduler": { + "type": "WarmupLR", + "params": { + "warmup_min_lr": "auto", + "warmup_max_lr": "auto", + "warmup_num_steps": "auto" + } + }, + "zero_optimization": { + "stage": 2, + "allgather_partitions": true, + "allgather_bucket_size": 2e8, + "overlap_comm": true, + "reduce_scatter": true, + "reduce_bucket_size": 2e8, + "contiguous_gradients": true, + "cpu_offload": true + }, + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "steps_per_print": 2000, + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "wall_clock_breakdown": false +} diff --git a/ICLR2023/src/fine_tune.py b/ICLR2023/src/fine_tune.py new file mode 100644 index 0000000..960fb55 --- /dev/null +++ b/ICLR2023/src/fine_tune.py @@ -0,0 +1,128 @@ +from strictfire import StrictFire as Fire # aborts early on invalid arguments +import os +import csv +import subprocess +import shlex +import random +import numpy as np +import torch +import utils + +def fine_tune( + train_txt="../data/generated_sol_100.txt", + output_dir = "../outputs/", + subdir="out", + model_path="EleutherAI/gpt-neo-2.7B", + gpu=0, + num_gpus=1, + epochs=4, + seed=0, + ): + """ + Fine tune the model on the puzzles in train_txt file and save the results to OUTPUT_DIR/output_subdir + + train_txt: the (possibly gzipped) file containing the text to fine tune on (default: ../data/generated_sol_100.txt) + subdir: the subdirectory to save the results to (default "out") + model_path: the path to the model to fine tune (default "EleutherAI/gpt-neo-2.7B") + gpu: which GPU(s) to use, e.g.: 0,1 (default 0) + epochs: how many epochs to train for (default 4) + seed: the random seed to use, not sure if this affects fine tuning (default 0) + """ + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + + # create output dir if necessary + output_path = os.path.join(output_dir, subdir) + if not os.path.exists(output_path): + os.makedirs(output_path) + + + text = utils.load_text_file(train_txt) # decompresses if ends in .gz + tokenizer = utils.load_tokenizer(model_path) + num_toks = utils.num_tokens(text, tokenizer, verbose=True) + assert num_toks > 1024, "Not enough tokens in text to fine tune" + + # create csv + train_file = os.path.join(output_path, "train.csv") + with open(train_file, mode="w", encoding="utf-8") as csv_file: + fieldnames = ["text"] + writer = csv.DictWriter(csv_file, fieldnames=fieldnames) + writer.writeheader() + writer.writerow({"text": text}) + + output_path_finetuned = os.path.join(output_path, "finetuned") + + # keep gradient_accumulation_steps at 1 bc setting it to 2 effectively doubles the batch + # size which gets tricky when batch sizes are small (ft_tokens will no longer be accurate) + gradient_accumulation_steps = 1 + per_device_train_batch_size = 4 + + cuda_visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES", "") + if len(cuda_visible_devices): + print("os.environ(CUDA_VISIBLE_DEVICES)", cuda_visible_devices) + del os.environ["CUDA_VISIBLE_DEVICES"] + print("os.environ(CUDA_VISIBLE_DEVICES)", os.environ.get("CUDA_VISIBLE_DEVICES", "")) + + master_port = 29600 # During training deepspeed uses a port to syncronize. 2 jobs need to set different ports to run in parallel + if type(gpu) in [list, tuple]: + master_port += gpu[0] + gpu = ",".join([str(g) for g in gpu]) + else: + master_port += gpu + + gpu_string = f'--include=localhost:{gpu}' + + if num_gpus > 1: + gpu_string = f"--num_nodes=1 --num_gpus={num_gpus}", + # If gpu is passed in as negative - it's the count of gpu to use - a bit of a hack + if gpu < 0: + num_gpus = abs(gpu) + gpu_string = f"--num_nodes=1 --num_gpus={num_gpus}" + + print("gpu_string", gpu_string) + + cmd = " ".join( + [ + "deepspeed", + f"--master_port={master_port}", + gpu_string, + # f'--include=localhost:{gpu}', + # "--num_nodes=1", + # f"--num_gpus={num_gpus}", + "neo_train.py", + f"--model_name_or_path={model_path}", + f"--train_file={train_file}", + f"--output_dir={output_path_finetuned}", + "--overwrite_output_dir", + "--ignore_data_skip", + "--deepspeed", + "ds_config_gptneo.json", + f"--save_strategy=no", # ATK remove checkpointing for large datasets + # pretty sure this is just dataset cache + "--overwrite_cache", + # logging frequency + "--logging_steps=5", + "--do_train", + "--report_to none", # turns off report_to WANDB for instance + "--fp16", + f"--num_train_epochs={epochs}", + # overrides num_train_epochs if set to a positive value. This is the number of gradient steps that happen total. + f"--per_device_train_batch_size={per_device_train_batch_size}", + "--use_fast_tokenizer=False", + f"--gradient_accumulation_steps={gradient_accumulation_steps}", + "--learning_rate=5e-06", + # linear increase from this up to learning rate, then LR schedule happens (which itself is linear decreasing until max_steps) + "--warmup_steps=10", + ] + ) + + utils.info(f"running command: {cmd}") + print(f"Command to run:{cmd}") # Why is this different than what utils.info prints out, utils.info truncates it + # exit() + res = subprocess.run(shlex.split(cmd), check=True) + utils.info(str(res)) + + +if __name__ == "__main__": + Fire(fine_tune) diff --git a/ICLR2023/src/fine_tune.sh b/ICLR2023/src/fine_tune.sh new file mode 100755 index 0000000..3d660c9 --- /dev/null +++ b/ICLR2023/src/fine_tune.sh @@ -0,0 +1,103 @@ +#!/bin/bash +echo fine_tune.sh args: $# $0 $1 $2 $3 $4 +# Grab the configuration variables +. babysit.sh + +# On AMLT machines we don't specify which GPU to use +# GPU="-1" +if [[ -z "${AMLT_DATA_DIR}" ]]; then + # running locally on torch2020 so we don't have AMLT enviroment variables defined, so need to set them up + AMLT_DATA_DIR=../data + # On torch2020 we do specify which GPU to use + # GPU="0" +fi + +# assert that there are at least 2 argument +if (( $# \< 2 )) +then + echo "Usage: $0 " + exit +fi + +GPU=$1 +FULLNAME=$2 + +# split by ; fullname string into experiment name and iteration +# e.g. "125M_RL---0" --> "125M_RL;0" +SPLIT=(${FULLNAME//---/ }) +EXPERIMENT=${SPLIT[0]} +ITERATION=${SPLIT[1]} +OUTPATH=$AMLT_DATA_DIR/$EXPERIMENT/iter_$ITERATION + +echo GPU $GPU +echo EXPERIMENT $EXPERIMENT +echo ITERAION $ITERATION +echo OUTPATH $OUTPATH + +# GPU_SOLVE is the GPU we want solve to use. Solve currently only uses 1 GPU - it would be great to make it use more when they are available. +# if GPU is negative - that tells fine_tune how many GPU to use on cluster - and we need to set GPU for solve to 0 on cluster +# if GPU is positive - we are running locally on torch2020 - and we need to leave the GPU set properly +GPU_SOLVE=$GPU +if (( $GPU \< 0 )) +then + GPU_SOLVE=0 +fi +echo GPU_SOLVE $GPU_SOLVE + +python preprocess.py $OUTPATH + +TRN_FILE=$OUTPATH/gen_ps_filtered.txt +echo TRN_FILE $TRN_FILE +TST_FILE=$AMLT_DATA_DIR/test_228.json + +BASE_MODEL_PATH=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL +# 125M is copied locally to start +MODEL_PATH=$BASE_MODEL_PATH +MODEL_PATH=EleutherAI/gpt-neo-125M # !!! Just for paper release +# 13B is off in the cloud to start +if [[ "$MODEL" == "13B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-1.3B +fi +# 27B is off in the cloud tto start +if [[ "$MODEL" == "27B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-2.7B +fi + +echo MODEL MODEL_PATH $MODEL $MODEL_PATH + +# Training incremental means use the previous iterations trained model, and just the additional iteration's new data to fine_tune on. +# Otherwise use the base model - and retrain from scratch on all the data from all previous iterations. +# They are sort of equivalent - except from scratch picks up any extra data that was generated - and mixes all the iterations data together - but slower. +if (( $TRAIN_INCREMENTAL \> 0 )) +then + PREV_ITERATION=$((ITERATION-1)) + echo $PREV_ITERATION + TEST=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL/$EXPERIMENT/iter_$PREV_ITERATION/epoch_$EPOCHS_MAX/finetuned + + if [ -a $TEST ] # exists + then + MODEL_PATH=$TEST + echo fine_tune.sh using previous iteration model + fi +fi + +echo "fine_tune.sh starting from NEO model at: ${MODEL_PATH}" + +# Pull all the results into 1 log file to look at more easily +LOG_FILE=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION/"solve.txt" +echo solve LOG_FILE for fine_tune.sh is $LOG_FILE +rm $LOG_FILE + +for (( epochs=$EPOCHS_START; epochs<=$EPOCHS_MAX; epochs++ )) +do + EPOCH_NAME="epoch_"$epochs + EPOCHS_STEP=$(($EPOCHS_PER_STEP * $epochs)) + python fine_tune.py -train_txt=$TRN_FILE -gpu=$GPU -output_dir=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION -subdir=$EPOCH_NAME -model_path=$MODEL_PATH -epochs=$EPOCHS_STEP + # measure the finetuned model's accuracy + STEP_PATH=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION/$EPOCH_NAME + MODEL_PATH=$STEP_PATH/finetuned + python solve.py -prefix=$AMLT_DATA_DIR/train_prefix.txt -attempts=$PASS_AT_K -model_path=$MODEL_PATH -gpu=$GPU_SOLVE -fixed_temp=0.8 -out=$STEP_PATH/"solve_"$PASS_AT_K"/" -puzzles=$TST_FILE + head -$LINE_LOG_K $STEP_PATH/"solve_"$PASS_AT_K/results.json >> $LOG_FILE +done + +cat $LOG_FILE \ No newline at end of file diff --git a/ICLR2023/src/fine_tune1.sh b/ICLR2023/src/fine_tune1.sh new file mode 100755 index 0000000..7f9cb46 --- /dev/null +++ b/ICLR2023/src/fine_tune1.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# This is for finetuning a model on 1 dataset only +echo fine_tune1.sh args: $# $0 $1 $2 $3 $4 + +# All Experiment Settings - constant through the experiment run +GPU=0 # which GPU to use +MODEL="125M" # MODEL is the size of the model: 125M, 13B, 27B +EXPERIMENT=$MODEL"_PAPER1" # Name of Experiment directory under data/* and models/base-model/* to store results +ITERATION=0 # Random seed for finetuning +EPOCHS_START=1 # inclusive index of epochs to start processing at - could continue prev run by starting at prev EPOCHS_MAX+1 - 0th epoch is the default model so epoch starts at 1 +EPOCHS_MAX=10 # inclusive index of epochs to stop processing at +EPOCHS_PER_STEP=1 # How many EPOCHS through the data to do in each step +PASS_AT_K=100 # PASS_AT_K says do K trials to solve to compute Pass@K +LINE_LOG_K=11 # LINE_LOG_K is how many lines of results from solve have results for saving + +# On AMLT machines we don't specify which GPU to use +if [[ -z "${AMLT_DATA_DIR}" ]]; then + # running locally on torch2020 so we don't have AMLT enviroment variables defined, so need to set them up + AMLT_DATA_DIR=../data +fi + +if (( $# \>= 1 )) +then + GPU=$1 +fi + +echo GPU $GPU +echo EXPERIMENT $EXPERIMENT +echo ITERAION $ITERATION + +TRN_FILE=$AMLT_DATA_DIR/generated_sol_950k.txt +echo TRN_FILE $TRN_FILE +TST_FILE=$AMLT_DATA_DIR/test_228.json + +# GPU_SOLVE is the GPU we want solve to use. Solve currently only uses 1 GPU - it would be great to make it use more when they are available. +# if GPU is negative - that tells fine_tune how many GPU to use on cluster - and we need to set GPU for solve to 0 on cluster +# if GPU is positive - we are running locally on torch2020 - and we need to leave the GPU set properly +GPU_SOLVE=$GPU +if (( $GPU \< 0 )) +then + GPU_SOLVE=0 +fi +echo GPU_SOLVE $GPU_SOLVE + +# measure the base model's accuracy - don't really need to do this very often - it doesn't change + +BASE_MODEL_PATH=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL +# 125M is copied locally to start +MODEL_PATH=$BASE_MODEL_PATH +MODEL_PATH=EleutherAI/gpt-neo-125M # !!! Just for paper release +# 13B is off in the cloud to start +if [[ "$MODEL" == "13B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-1.3B +fi +# 27B is off in the cloud tto start +if [[ "$MODEL" == "27B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-2.7B +fi + +echo MODEL MODEL_PATH $MODEL $MODEL_PATH + +# Training incremental means use the previous epochs model to start +# Otherwise use the base model to retrain from scratch +if (( $EPOCHS_START \> 1 )) +then + PREV_EPOCH=$((EPOCHS_START-1)) + echo $PREV_EPOCH + TEST=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL/$EXPERIMENT/iter_$ITERATION/epoch_$PREV_EPOCH/finetuned + + if [ -a $TEST ] # exists + then + MODEL_PATH=$TEST + echo fine_tune.sh using previous iteration model + fi +fi + +echo "fine_tune.sh starting from NEO model at: ${MODEL_PATH}" + +# Pull all the results into 1 log file to look at more easily +LOG_FILE=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION/"solve.txt" +echo solve LOG_FILE for fine_tune.sh is $LOG_FILE +rm $LOG_FILE + +for (( epochs=$EPOCHS_START; epochs<=$EPOCHS_MAX; epochs++ )) +do + EPOCH_NAME="epoch_"$epochs + EPOCHS_STEP=$(($EPOCHS_PER_STEP * $epochs)) + python fine_tune.py -train_txt=$TRN_FILE -gpu=$GPU -output_dir=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION -subdir=$EPOCH_NAME -model_path=$MODEL_PATH -epochs=$EPOCHS_STEP -seed=$ITERATION + # measure the finetuned model's accuracy + STEP_PATH=$BASE_MODEL_PATH/$EXPERIMENT/iter_$ITERATION/$EPOCH_NAME + MODEL_PATH=$STEP_PATH/finetuned + python solve.py -prefix=$AMLT_DATA_DIR/train_prefix.txt -attempts=$PASS_AT_K -model_path=$MODEL_PATH -gpu=$GPU_SOLVE -fixed_temp=0.8 -out=$STEP_PATH/"solve_"$PASS_AT_K"/" -puzzles=$TST_FILE -seed=$ITERATION -batch_size=256 + head -$LINE_LOG_K $STEP_PATH/"solve_"$PASS_AT_K/results.json >> $LOG_FILE +done + +cat $LOG_FILE \ No newline at end of file diff --git a/ICLR2023/src/gen.py b/ICLR2023/src/gen.py new file mode 100644 index 0000000..57f3216 --- /dev/null +++ b/ICLR2023/src/gen.py @@ -0,0 +1,522 @@ +from typing import List +import os +from tqdm import tqdm +import numpy as np +import json +import judge +import inspect +import random +import re +import ast +import time +from collections import Counter +from strictfire import StrictFire as Fire # aborts early on invalid arguments +import utils +import solve +import torch + +def ast_parse_quiet(s: str): + utils.silence_std_err(True) + try: + return ast.parse(s) + except: + pass + finally: + utils.silence_std_err(False) + + +def find_end(st: str): + """Takes a solution and looks for the end that would make it parse.""" + lines = st.split("\n") + for i in range(1, len(lines)): + line = lines[i] + if line and line[0] not in " \t": + lines = lines[:i] + break + ans = "\n".join(lines) + + if ast_parse_quiet("def g():" + ans): + return ans + else: + return None + + +def strip_puzzle(puz: str): + """When a puzzle is generated, it will typically be followed by extra code after the def. + This function strips that extra code, leaving just the puzzle.""" + puz = puz.strip() + match = re.search(r"\n\S", puz) # newline followed by a non-newline character + if match: + return puz[: match.start()] + return puz + + +def good_puzzles(puzzles: List[str], trivial_reject_rate, verbose=True): + """Find the puzzles that compile, have exactly one required argument of a listful type, and are non-trivial + meaning that they use the argument somewhere in the puzzle and do not return True on some trivial values. + Set trivial_reject_rate to 1 if you want to reject all puzzles""" + + # first we make sure they have a return statement and start with 'def f(' and also strip any trailing code + + n = len(puzzles) + puzzles = [strip_puzzle(p) for p in puzzles] + puzzles = [p for p in puzzles if p.startswith("def f(") and "return" in p] + + utils.info(f"{len(puzzles):,}/{n:,} = {len(puzzles) / n:.0%} puzzle passed step 1") + + # next we modify the puzzle by inserting a return True as its first line and judge if f(None) is True + # this removes puzzles with bad signatures or dangerous code as detected by the judge + + def make_true(p): + lines = p.split("\n") + lines.insert(1, " return True") + lines.append("") + lines.append("assert f(None)") + return "\n".join(lines) + + n = len(puzzles) + puzzles = [p for p, res in zip(puzzles, judge.judge_parallel([make_true(p) for p in puzzles], timeout=1)) if res] + + utils.info(f"{len(puzzles):,}/{n:,} = {len(puzzles) / n:.0%} puzzle passed step 2") + + def get_trivial_tests(p): + """determine which test to run for trivial tests based on the type, returns None if the spec is invalid""" + try: + env = {"List": List} + exec(p, env) + f = env["f"] + spec = inspect.getfullargspec(f) + ans_var_name = spec.args[0] + typ = spec.annotations[ans_var_name] + except: + return None + num_var_mentions = len(re.findall(r"\b" + ans_var_name + r"\b", p)) + if ( + len(spec.defaults or []) != len(spec.args) - 1 + or spec.varargs # need exactly one required parameter + or spec.varkw + or spec.kwonlyargs + or spec.kwonlydefaults # weird spec: *args, **kwargs + ): + return None + if random.random() > trivial_reject_rate: + return [] # don't bother to test some small fraction of the puzzles for trivial solution + if ( + num_var_mentions <= 1 + or typ is bool # need to use the answer variable other than in the spec # bool puzzles are all trivial + ): + return None + base_types = {"bool": bool, "float": float, "str": str, "int": int} + if typ not in base_types.values(): + if str(typ) == "str" and typ is not str: + return None + type_str = str(typ).replace("typing.", "") + inside = type_str.replace("List[", "").replace("]", "") + if inside not in base_types: + return None + if typ is int: + tests = list(range(-10, 101)) + elif typ is str: + tests = ["cat", "dog", "aa", "ab", "foo", "bar", "baz", ""] + elif typ is float: + tests = [-100.0, -10.0, -2.0, -1.0, -0.5, -0.1, 0.0, 0.1, 0.5, 1.0, 2.0, 10.0, 100.0] + elif typ is bool: + tests = [True, False] + else: + depth = type_str.count("List[") + if depth == 0: + return None + if inside == "int": + base = list(range(-3, 4)) + elif inside == "str": + base = ["a", "b", "foo", "bar", "baz"] + elif inside == "bool": + base = [True, False] + elif inside == "float": + base = [-1.0, -0.1, 0.0, 0.1, 0.5, 1.0, 2.0] + else: + return None + from itertools import product + + tests = [] + for r in range(3): + tests.extend(list(p) for p in product(base, repeat=r)) + for d in range(depth - 1): + tests = [[i] for i in tests] + if [] not in tests: + tests.append([]) + return tests + + n = len(puzzles) + tests = [get_trivial_tests(p) for p in puzzles] + puzzles, testss = zip(*[(p, t) for p, t in zip(puzzles, tests) if t is not None]) + + utils.info(f"{len(puzzles):,}/{n:,} = {len(puzzles) / n:.0%} puzzle passed step 3") + + # next remove puzzles with trivial solutions + # todo: also remove puzzles that raise a NameError exception?? + n = len(puzzles) + nontrivials = [] + + for p, tests in tqdm(list(zip(puzzles, testss))): + results = judge.judge_parallel( + [f"{p}\n\ntry:\n assert f({utils.stringify(t)})\nexcept NameError:\n pass" for t in tests], timeout=1 + ) + if not any(results): + nontrivials.append(p) + if verbose: + utils.info("*" * 100) + utils.info(p) + + puzzles = nontrivials + utils.info(f"{len(puzzles):,}/{n:,} = {len(puzzles) / n:.0%} puzzle passed step 3") + + return puzzles + + +def load_puzzles(filename, remove_docstring): + """Returns list of functions and solution headers, one puzzle per problem""" + JS = utils.load_json(filename) + fs = [] + sol_headers = [] + seen = set() + + for j in JS: + name = j["name"].split(":")[0] # just one puzzle per problem + if name in seen: + continue + seen.add(name) + f = j["sat"].replace("def sat", "def f") + + fs.append(f) + sol_headers.append( + j["sol_header"].replace("def sol", "def g") + ("" if remove_docstring else "\n" + j["sol_docstring"]) + ) + + return fs, sol_headers + + +def gen_from_puzzles( + filename, + n, + per_prompt, + temp, + model, + tokenizer, + remove_docstring, + max_tokens, + trivial_reject_rate, + gen_tokens=200, + stop="\ndef", + batch_size=16, +): + """ + Generate based on random selection of puzzles only. + """ + utils.info(f"Generating puzzles from puzzles") + time0 = time.time() + + fs, heads = load_puzzles(filename, remove_docstring) + + assert len(fs) == len(set(fs)), "Duplicate puzzles" + + generated = [] + SEPARATOR = "\n\n" + + with tqdm(total=n) as pbar: + it = 0 + while len(generated) < n: + # compute prompt + random.shuffle(fs) + + prompt = None + for k in range(len(fs) + 1): + entries = fs[:k] + ["def f("] + candidate_prompt = SEPARATOR.join([f.replace(" f(", f" f{i + 1}(") for i, f in enumerate(entries)]) + if utils.num_tokens(candidate_prompt, tokenizer) >= max_tokens - gen_tokens: + break + prompt = candidate_prompt + + # candidates = gpt_lib.query( + # prompt=prompt, + # n=min(per_prompt, n), + # temp=temp, + # max_tokens=gen_tokens, + # stop=stop, + # cache_only=cache_only, + # notes=(seed, it), + # engine=engine, + # ) + + num_gen = min(per_prompt, n) + + while True: # loop to decrease batch size if necessary + try: + candidates = solve.gen( # complete prompts + prompts=[prompt]*num_gen, + tokenizer=tokenizer, + model=model, + batch_size=batch_size, + temp=temp, + gen_tokens=gen_tokens + ) + break + except RuntimeError as e: + if "out of memory" in str(e).lower() or "CUBLAS_STATUS_ALLOC_FAILED" in str(e): + print(str(e)) + utils.info(f"Out of GPU memory gen.py, reducing batch size {batch_size} -> {batch_size//2}") + batch_size //= 2 + assert batch_size >= 1 + # torch.cuda.empty_cache() # not important, just lets nvidia-smi update if anything + else: + raise + + candidates = [c[len(prompt):] for c in candidates] + assert len(candidates) == num_gen + + generated += [strip_puzzle("def f(" + c) for c in candidates] + pbar.update(len(candidates)) + it += 1 + + return good_puzzles(generated, trivial_reject_rate=trivial_reject_rate) + + +def get_inputs(sat: str): + """Extacts arguments past the first from a function string + def f(a: Dict[int, str], b=12): + test + + should give 'b=12' + """ + sat = sat.replace(" -> bool", "") + first_line = sat.split("\n")[0].strip() + if not first_line.endswith("):") and "#" in first_line: + first_line = first_line[: first_line.index("#")].strip() + if not (first_line.endswith("):") and first_line.startswith("def")): + # raise WeirdInputsException("Weird puzzle, cannot extract inputs", json.dumps(sat)) + return None + arg_str = first_line[first_line.index("(") : -len("):")] + depth = 0 + for i, c in enumerate(arg_str): + if c == "," and depth == 0: + return arg_str[i + 1 :].strip() + elif c == "[": + depth += 1 + elif c == "]": + depth -= 1 + return "" + + +def get_prompts(prefix, fs, sol_headers, test_prefix=True): + """adds function numbers after prompt""" + + ans = [] + if test_prefix: + exec(prefix, dict(List=List)) + + if "def f1(" in prefix: + i = 1 + while f"def f{i}(" in prefix: + i += 1 + else: + i = "" + + assert len(sol_headers) == len(fs) + for f, head in zip(fs, sol_headers): + f = f.replace("def f(", f"def f{i}(") + head = head.replace("def g(", f"def g{i}(") + head = head.replace("def sol(", f"def g{i}(") + ans.append(f"{prefix}{f}\n\n{head}") + return ans + + +def solve_puzzles( + puzzles, + prefix, + attempts, # number of attempts to solve each puzzle + model, + tokenizer, + temp, + solve_tokens=150, + timeout=1.0, +): + + stop = "\nassert" + + utils.info("=" * 100) + utils.info(f"Solving with {utils.num_tokens(prefix, tokenizer)} prefix tokens") + time0 = time.time() + + utils.info(f"Solving {len(puzzles)} given directly") + + sol_headers = [f"def g({get_inputs(f)}):" for f in puzzles] + prefix = re.sub(r" +$", "", (prefix or "").lstrip(), flags=re.M) # delete leading/trailing whitespace on each line + prompts = get_prompts(prefix, puzzles, sol_headers) + + all_results = [] + for p_num, (f, head, prompt) in tqdm(enumerate(zip(puzzles, sol_headers, prompts)), total=len(puzzles)): + res = solve.gen( # complete prompts + prompts=[prompt]*attempts, + tokenizer=tokenizer, + model=model, + batch_size=4, + temp=temp, + gen_tokens=solve_tokens + ) + res = [r[len(prompt):] for r in res] + assert len(res) == attempts + + valids = [(find_end(g), i) for i, g in enumerate(res)] + valids = [(g, i) for (g, i) in valids if g is not None] + # double parentheses are necessary to avoid cheating where it changes default parameters :-) + if "def f1(" in prompt: + for kk in range(1, 10000): + if f"def f{kk}(" not in prompt: + break + kk -= 1 + else: + kk = "" + valids = [(g.replace(f"f{kk}(", "f("), i) for (g, i) in valids] + results = judge.judge_parallel( + [f"{f}\n\n{head}{g}\n\nassert test_puzzle(f, g())" for g, _i in valids], timeout=timeout + ) + successes = [g for (g, i), res in zip(valids, results) if res] + failures = [g for (g, i), res in zip(valids, results) if not res] + all_results.append((f, successes, failures)) + # if curr: + # ans1 = [a for a, _i in curr] + # if verbose: + # utils.info(p_num, "-" * 80) + # utils.info(strip_param_annotations(f)) + # summary = [(a if c == 1 else f"{a} ({c} times)") for a, c in Counter(ans1).most_common(10)] + # utils.info(f"{len(curr)} sols, first at attempt #{curr[0][1]}:: {' | '.join(summary)}"[:200]) + + n_sol = sum(bool(s) for f, s, _ in all_results) + n_suc = sum(len(s) for f, s, _ in all_results) + utils.info(f"Solved {n_sol:,}/{len(puzzles):,} puzzles with a total of {n_suc:,} solutions.") + utils.info() + + return all_results + + +def gen( + out="../outputs/gen//", + n=100_000, + seed=0, + trivial_reject_rate=0.95, + temp=0.9, + temp_solve=None, + gpu=0, + train="../data/155_train.json", + prefix="../data/train_prefix.txt", + remove_docstring=True, + model_path="EleutherAI/gpt-neo-125M", + model_path_solve=None, + max_tokens=2048, + per_prompt=64, + attempts=128, + only_good=False +): + """ + Run the generator with given seed + + outfilename: where to write the output + n: number of puzzles to generate, actual number of puzzles will be smaller after filtering + seed: random seed + trivial_reject_rate: what fraction of trival puzzles to reject + temp: temperature for generation + temp_solve: temperature for solving (if different than temp, default=None means same as generation temp) + gpu: the gpu to use (default 0) + train: path to training data (default: 155_train.json) + prefix: text filename containing prompt (default: ../data/train_prefix.txt) + remove_docstring: whether to remove docstrings from puzzles (default=True) + model_path: path to model for generating puzzles + model_path_solve: path to model for solving puzzles (if different than model_path for generation) + max_tokens: maximum number of tokens that can fit in a prompt + per_prompt: number of puzzles to generate per prompt + attempts: number of solutions to generate per puzzle + """ + params = locals().copy() # store parameters + utils.info("PARAMETERS:") + utils.info(params) + + if seed != -1: + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + + torch.cuda.set_device(int(gpu)) + tokenizer = utils.load_tokenizer(model_path) + model = solve.load_model(model_path, pad_token_id=tokenizer.eos_token_id) # pad_token_id removes wrnings + + output_path = utils.create_experiment_outpath(out, False) + + prefix = utils.load_text_file(prefix).strip() if prefix else "" + if prefix: + prefix += "\n\n" + + time0 = time.time() + + puzzles = gen_from_puzzles( + filename=train, + n=n, + per_prompt=per_prompt, + temp=temp, + model=model, + tokenizer=tokenizer, + trivial_reject_rate=trivial_reject_rate, + max_tokens=max_tokens, + remove_docstring=remove_docstring, + ) + num_puzzles = len(puzzles) + utils.info(f"Generated {num_puzzles:,} puzzles.") + + puzzles_and_solutions = solve_puzzles( + puzzles, + prefix=prefix, + attempts=attempts, + model=model, + tokenizer = tokenizer, + temp=(temp_solve or temp), + ) + + puzzles_and_solutions.sort(key=lambda z: (len(z[1]), len(z[0]))) + + if (not only_good): + out_filename = os.path.join(output_path, "puzzles.json") + + utils.save_json(puzzles_and_solutions, out_filename) + + out_filename2 = out_filename.replace(".json", ".txt").replace(".gz", "") + with open(out_filename2, "w", encoding="utf8") as file: + for f, gs, *rest in puzzles_and_solutions: + if rest: + [rest] = rest + print(len(gs), len(rest), "/" * 100, file=file) + else: + print(len(gs), "=" * 100, file=file) + print(f, file=file) + print(file=file) + for g in (gs + rest)[:2]: + print(g, file=file) + print(file=file) + + utils.info("Wrote results to {}.".format(out_filename)) + utils.info("Wrote results to {}.".format(out_filename2)) + + # generating puzzles and solutions on cluster we want to limit the amount of data produced + # save out only the puzzles with their good solutions, forget bad solutions and unsolved problems. + gp_gs = [] + for f, gs, *rest in puzzles_and_solutions: + if len(gs) > 0: + gp_gs.append((f, gs, [])) + + out_filename = os.path.join(output_path, "good_puzzles_" + "R0_" + str(gpu) + "_" + time.strftime("%y-%m-%d-%H-%M-%S") + ".json") + utils.save_json(gp_gs, out_filename) + + time1 = time.time() + utils.info(f"Took {time1 - time0:.3f} seconds.") + utils.info(f"Saved as file {out_filename}") + +if __name__ == "__main__": + Fire(gen) diff --git a/ICLR2023/src/gen.sh b/ICLR2023/src/gen.sh new file mode 100755 index 0000000..84ad2ea --- /dev/null +++ b/ICLR2023/src/gen.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# Grab the configuration variables +. babysit.sh + +if [[ -z "${AMLT_DATA_DIR}" ]]; then + # running locally on torch2020 we don't have AMLT enviroment variables defined, set them up + AMLT_DATA_DIR="../data" +fi + +echo RANK is: +echo $RANK + +if [[ -z "${RANK}" ]]; then + # running locally on torch2020 we don't have AMLT enviroment variables defined, set them up + RANK=0 +fi + +GPU=$RANK +PUZZLE_CNT=32 +SOLUTION_CNT=32 +FULLNAME="125M_RL_TEST---0" + +echo $# $0 $1 $2 $3 $4 +if (( $# \>= 1 )) +then + GPU=$1 +fi + +echo $RANK +echo $GPU + +if (( $# \>= 2 )) +then + PUZZLE_CNT=$2 +fi + +if (( $# \>= 3 )) +then + SOLUTION_CNT=$3 +fi + +if (( $# \>= 4 )) +then + FULLNAME=$4 + +fi + +RANDOM_SEED=-1 + +if (( $# \>= 5 )) +then + RANDOM_SEED=$5 + echo "Random seed is $RANDOM_SEED" +fi + +SPLIT=(${FULLNAME//---/ }) +EXPERIMENT=${SPLIT[0]} +ITERATION=${SPLIT[1]} +OUTPATH=$AMLT_DATA_DIR/$EXPERIMENT/iter_$ITERATION + +echo GPU $GPU +echo EXPERIMENT $EXPERIMENT +echo ITERAION $ITERATION +echo OUTPATH $OUTPATH + +BASE_MODEL_PATH=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL +# 125M is copied locally to start +MODEL_PATH=$BASE_MODEL_PATH +MODEL_PATH=EleutherAI/gpt-neo-125M # !!! Just for paper release +# 13B is off in the cloud to start +if [[ "$MODEL" == "13B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-1.3B +fi +# 27B is off in the cloud tto start +if [[ "$MODEL" == "27B" ]]; then + MODEL_PATH=EleutherAI/gpt-neo-2.7B +fi + +echo MODEL MODEL_PATH $MODEL $MODEL_PATH + +PREV_ITERATION=$((ITERATION-1)) +echo $PREV_ITERATION +TEST=$AMLT_DATA_DIR/../models/gpt-neo-$MODEL/$EXPERIMENT/iter_$PREV_ITERATION/epoch_$EPOCHS_MAX/finetuned + +if [ -a $TEST ] # exists +then + MODEL_PATH=$TEST + echo fine_tune.sh using previous iteration model +fi + +echo "gen.sh using NEO model at: ${MODEL_PATH}" + +python gen.py -out="$OUTPATH" -n=$PUZZLE_CNT -seed=$RANDOM_SEED -gpu=$GPU -train=$AMLT_DATA_DIR/155_train.json -prefix=$AMLT_DATA_DIR/train_prefix.txt -model_path=$MODEL_PATH -attempts=$SOLUTION_CNT -only_good=True diff --git a/ICLR2023/src/judge.py b/ICLR2023/src/judge.py new file mode 100644 index 0000000..2ff4c3a --- /dev/null +++ b/ICLR2023/src/judge.py @@ -0,0 +1,176 @@ +from utils import load_json +from pebble import ProcessPool +import multiprocessing as mp +from concurrent.futures import TimeoutError +from typing import List, Set, Tuple, Dict + +import utils +import sys +import re +from copy import deepcopy + +sys.setrecursionlimit(5000) + + +def no_print(*_args, **_kwargs): + pass + + +def run_judge(judge, f, tests): + answer_type = list(judge.__annotations__.values())[0] + for x in tests: + y = f(**deepcopy(x)) # so f cannot cheat and change the input x + if not utils.type_check(y, answer_type): + raise TypeError + assert judge(y, **x) is True, f"{f} failed on test {x}" + + +_ENV = dict( + List=List, + Set=Set, + Tuple=Tuple, + Dict=Dict, + type_check=utils.type_check, + run_judge=run_judge, + test_puzzle=utils.test_puzzle, + os=None, + sys=None, + input=None, + open=None, + print=no_print, + compile=None, + copyright=None, +) + +_UNSAFE = ["builtin", "__class", "open("] +_SAFE_IMPORTS = {"collections", "copy", "hashlib", "math", "random", "re", "string", "typing"} + +MAX_WORKERS = mp.cpu_count() // 2 + + + +def unsafe_imports(code): + """Check if code imports any unsafe modules. + + Args: + code (str): The code to check. + + Returns: + bool: True if code imports unsafe modules. + """ + if "import" not in code: + return False + for line in code.split("\n"): + if "import" in line: + match = re.search(r"^\s*from\s+([\w\.]+)\s+import\s", line) + if match: + modules = [match.group(1)] + else: + match = re.search(r"^\s*import\s+(.+)", line) + if match: + modules = match.group(1).split(",") + else: + return True + if any(m.strip() not in _SAFE_IMPORTS for m in modules): + return True + return False + + +def _judge(code_env): + code, env = code_env + if unsafe_imports(code) or any(u in code for u in _UNSAFE): + return False, Exception(f"unsafe code"), code + try: + exec(code, env.copy()) + return True, None, code + except Exception as e: + return False, e, code + + +def judge_parallel(src_codes, timeout, max_workers=MAX_WORKERS, env=_ENV): + codes = utils.dedup(src_codes) + utils.info( + f"Judging {len(src_codes):,} codes ({len(src_codes)-len(codes):,} duplicates) with {max_workers} workers" + ) + successes = set() + + # print("writing to file for debugging before judging") + # from train import save_json + # + # save_json(new_codes, "results/tmp/new_codes.json") + utils.silence_std_err(True) + with ProcessPool(max_workers=max_workers) as pool: + future = pool.map(_judge, [(code, env) for code in codes], timeout=timeout) + + results = future.result() + i = 0 + while True: + try: + success, exc, code = next(results) + if success: + successes.add(codes[i]) + except StopIteration: + break + except (TimeoutError, Exception) as error: + pass + assert i < len(codes) + i += 1 + assert i == len(codes) + utils.silence_std_err(False) + return [code in successes for code in src_codes] + + + + +def test(): + import time + + tests = [ + ("def sol(a: int=10000200001):\n return (list(range(3 * a))[str(a)])\nx = sol()", False), + ("print(12)", True), + ("while True: pass", False), + ("def sol(): sol()\nsol()", False), + ("2+2", True), + ("""1+1""", True), + ("""assert False,'cats'""", False), + ("""assert False""", False), + ("""1[2]""", False), + ("""1/0""", False), + ( + """while True: + pass""", + False, + ), + ( + """for i in range(10**4): + pass""", + True, + ), + ("print('hello')", True), + ] + + scores = {} + tests2 = tests + pad = " " + for _ in range(6): + print(f"n={len(tests2)} timing test" + "*" * 20) + times = [] + for max_workers in [4, 16, 32, 64, 128]: + time0 = time.perf_counter() + res = judge_parallel([test for test, r in tests2], timeout=1, max_workers=max_workers) + for (test, expected), r in zip(tests2, res): + assert expected == r, f"Failed expected {expected}, got {r} for {test}" + + times.append((max_workers, time.perf_counter() - time0)) + + scores[len(tests2)] = times + tests2 = tests2 + [(t + pad, r) for (t, r) in tests2] + pad = pad * 2 + print("mp.cpu_count() =", mp.cpu_count()) + + for n, times in scores.items(): + print(n, "tests, [(max_workers, time)] =", times) + + +if __name__ == "__main__": + test() diff --git a/ICLR2023/src/neo_train.py b/ICLR2023/src/neo_train.py new file mode 100644 index 0000000..48fea64 --- /dev/null +++ b/ICLR2023/src/neo_train.py @@ -0,0 +1,452 @@ +#!/usr/bin/env python +# coding=utf-8 +# Copyright 2020 The HuggingFace Inc. team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Fine-tuning the library models for causal language modeling (GPT, GPT-2, CTRL, ...) on a text file or a dataset. + +Here is the full list of checkpoints on the hub that can be fine-tuned by this script: +https://huggingface.co/models?filter=causal-lm +""" +# You can also adapt this script on your own causal language modeling task. Pointers for this are left as comments. + +"""This file is based on: https://github.com/huggingface/transformers/blob/1b5ce1e63b7bd4382cd1b4fdcca72d50f8b29494/examples/language-modeling/run_clm.py + +There were only two lines changed, both have the comment # CHANGED: added +""" + +import logging +import math +import os +import sys +from dataclasses import dataclass, field +from typing import Optional + +from datasets import load_dataset + +import transformers +from transformers import ( + CONFIG_MAPPING, + MODEL_FOR_CAUSAL_LM_MAPPING, + AutoConfig, + AutoModelForCausalLM, + AutoTokenizer, + HfArgumentParser, + Trainer, + TrainingArguments, + default_data_collator, + set_seed, +) +from transformers.trainer_utils import get_last_checkpoint, is_main_process +from transformers.utils import check_min_version + + +# Will error if the minimal version of Transformers is not installed. Remove at your own risks. +check_min_version("4.5.0.dev0") + +logger = logging.getLogger(__name__) + + +MODEL_CONFIG_CLASSES = list(MODEL_FOR_CAUSAL_LM_MAPPING.keys()) +MODEL_TYPES = tuple(conf.model_type for conf in MODEL_CONFIG_CLASSES) + + +@dataclass +class ModelArguments: + """ + Arguments pertaining to which model/config/tokenizer we are going to fine-tune, or train from scratch. + """ + + model_name_or_path: Optional[str] = field( + default=None, + metadata={ + "help": "The model checkpoint for weights initialization." + "Don't set if you want to train a model from scratch." + }, + ) + model_type: Optional[str] = field( + default=None, + metadata={"help": "If training from scratch, pass a model type from the list: " + ", ".join(MODEL_TYPES)}, + ) + config_name: Optional[str] = field( + default=None, metadata={"help": "Pretrained config name or path if not the same as model_name"} + ) + tokenizer_name: Optional[str] = field( + default=None, metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"} + ) + cache_dir: Optional[str] = field( + default=None, + metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"}, + ) + use_fast_tokenizer: bool = field( + default=True, + metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."}, + ) + model_revision: str = field( + default="main", + metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."}, + ) + use_auth_token: bool = field( + default=False, + metadata={ + "help": "Will use the token generated when running `transformers-cli login` (necessary to use this script " + "with private models)." + }, + ) + + +@dataclass +class DataTrainingArguments: + """ + Arguments pertaining to what data we are going to input our model for training and eval. + """ + + dataset_name: Optional[str] = field( + default=None, metadata={"help": "The name of the dataset to use (via the datasets library)."} + ) + dataset_config_name: Optional[str] = field( + default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."} + ) + train_file: Optional[str] = field(default=None, metadata={"help": "The input training data file (a text file)."}) + validation_file: Optional[str] = field( + default=None, + metadata={"help": "An optional input evaluation data file to evaluate the perplexity on (a text file)."}, + ) + max_train_samples: Optional[int] = field( + default=None, + metadata={ + "help": "For debugging purposes or quicker training, truncate the number of training examples to this " + "value if set." + }, + ) + max_val_samples: Optional[int] = field( + default=None, + metadata={ + "help": "For debugging purposes or quicker training, truncate the number of validation examples to this " + "value if set." + }, + ) + + block_size: Optional[int] = field( + default=None, + metadata={ + "help": "Optional input sequence length after tokenization." + "The training dataset will be truncated in block of this size for training." + "Default to the model max input length for single sentence inputs (take into account special tokens)." + }, + ) + overwrite_cache: bool = field( + default=False, metadata={"help": "Overwrite the cached training and evaluation sets"} + ) + validation_split_percentage: Optional[int] = field( + default=5, + metadata={ + "help": "The percentage of the train set used as validation set in case there's no validation split" + }, + ) + preprocessing_num_workers: Optional[int] = field( + default=None, + metadata={"help": "The number of processes to use for the preprocessing."}, + ) + + def __post_init__(self): + if self.dataset_name is None and self.train_file is None and self.validation_file is None: + raise ValueError("Need either a dataset name or a training/validation file.") + else: + if self.train_file is not None: + extension = self.train_file.split(".")[-1] + assert extension in ["csv", "json", "txt"], "`train_file` should be a csv, a json or a txt file." + if self.validation_file is not None: + extension = self.validation_file.split(".")[-1] + assert extension in ["csv", "json", "txt"], "`validation_file` should be a csv, a json or a txt file." + + +def main(): + # See all possible arguments in src/transformers/training_args.py + # or by passing the --help flag to this script. + # We now keep distinct sets of args, for a cleaner separation of concerns. + + parser = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments)) + if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): + # If we pass only one argument to the script and it's the path to a json file, + # let's parse it to get our arguments. + model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) + else: + model_args, data_args, training_args = parser.parse_args_into_dataclasses() + + # Detecting last checkpoint. + last_checkpoint = None + if os.path.isdir(training_args.output_dir) and training_args.do_train and not training_args.overwrite_output_dir: + last_checkpoint = get_last_checkpoint(training_args.output_dir) + if last_checkpoint is None and len(os.listdir(training_args.output_dir)) > 0: + raise ValueError( + f"Output directory ({training_args.output_dir}) already exists and is not empty. " + "Use --overwrite_output_dir to overcome." + ) + elif last_checkpoint is not None: + logger.info( + f"Checkpoint detected, resuming training at {last_checkpoint}. To avoid this behavior, change " + "the `--output_dir` or add `--overwrite_output_dir` to train from scratch." + ) + + # Setup logging + logging.basicConfig( + format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", + datefmt="%m/%d/%Y %H:%M:%S", + handlers=[logging.StreamHandler(sys.stdout)], + ) + logger.setLevel(logging.INFO if is_main_process(training_args.local_rank) else logging.WARN) + + # Log on each process the small summary: + logger.warning( + f"Process rank: {training_args.local_rank}, device: {training_args.device}, n_gpu: {training_args.n_gpu}" + + f"distributed training: {bool(training_args.local_rank != -1)}, 16-bits training: {training_args.fp16}" + ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() + logger.info("Training/evaluation parameters %s", training_args) + + # Set seed before initializing model. + set_seed(training_args.seed) + + # Get the datasets: you can either provide your own CSV/JSON/TXT training and evaluation files (see below) + # or just provide the name of one of the public datasets available on the hub at https://huggingface.co/datasets/ + # (the dataset will be downloaded automatically from the datasets Hub). + # + # For CSV/JSON files, this script will use the column called 'text' or the first column if no column called + # 'text' is found. You can easily tweak this behavior (see below). + # + # In distributed training, the load_dataset function guarantee that only one local process can concurrently + # download the dataset. + if data_args.dataset_name is not None: + # Downloading and loading a dataset from the hub. + datasets = load_dataset(data_args.dataset_name, data_args.dataset_config_name) + if "validation" not in datasets.keys(): + datasets["validation"] = load_dataset( + data_args.dataset_name, + data_args.dataset_config_name, + split=f"train[:{data_args.validation_split_percentage}%]", + ) + datasets["train"] = load_dataset( + data_args.dataset_name, + data_args.dataset_config_name, + split=f"train[{data_args.validation_split_percentage}%:]", + ) + else: + data_files = {} + if data_args.train_file is not None: + data_files["train"] = data_args.train_file + if data_args.validation_file is not None: + data_files["validation"] = data_args.validation_file + extension = ( + data_args.train_file.split(".")[-1] + if data_args.train_file is not None + else data_args.validation_file.split(".")[-1] + ) + if extension == "txt": + extension = "text" + datasets = load_dataset(extension, data_files=data_files) + # See more about loading any type of standard or custom dataset (from files, python dict, pandas DataFrame, etc) at + # https://huggingface.co/docs/datasets/loading_datasets.html. + + # Load pretrained model and tokenizer + # + # Distributed training: + # The .from_pretrained methods guarantee that only one local process can concurrently + # download model & vocab. + + config_kwargs = { + "cache_dir": model_args.cache_dir, + "revision": model_args.model_revision, + "use_auth_token": True if model_args.use_auth_token else None, + } + if model_args.config_name: + config = AutoConfig.from_pretrained(model_args.config_name, **config_kwargs) + elif model_args.model_name_or_path: + config = AutoConfig.from_pretrained(model_args.model_name_or_path, **config_kwargs) + else: + config = CONFIG_MAPPING[model_args.model_type]() + logger.warning("You are instantiating a new config instance from scratch.") + + config.gradient_checkpointing = True # CHANGED: added + config.use_cache = False # CHANGED: added + + tokenizer_kwargs = { + "cache_dir": model_args.cache_dir, + "use_fast": model_args.use_fast_tokenizer, + "revision": model_args.model_revision, + "use_auth_token": True if model_args.use_auth_token else None, + } + if model_args.tokenizer_name: + tokenizer = AutoTokenizer.from_pretrained(model_args.tokenizer_name, **tokenizer_kwargs) + elif model_args.model_name_or_path: + tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path, **tokenizer_kwargs) + else: + raise ValueError( + "You are instantiating a new tokenizer from scratch. This is not supported by this script." + "You can do it from another script, save it, and load it from here, using --tokenizer_name." + ) + + if model_args.model_name_or_path: + model = AutoModelForCausalLM.from_pretrained( + model_args.model_name_or_path, + from_tf=bool(".ckpt" in model_args.model_name_or_path), + config=config, + cache_dir=model_args.cache_dir, + revision=model_args.model_revision, + use_auth_token=True if model_args.use_auth_token else None, + ) + else: + logger.info("Training new model from scratch") + model = AutoModelForCausalLM.from_config(config) + + model.resize_token_embeddings(len(tokenizer)) + + # Preprocessing the datasets. + # First we tokenize all the texts. + if training_args.do_train: + column_names = datasets["train"].column_names + else: + column_names = datasets["validation"].column_names + text_column_name = "text" if "text" in column_names else column_names[0] + + def tokenize_function(examples): + return tokenizer(examples[text_column_name]) + + tokenized_datasets = datasets.map( + tokenize_function, + batched=True, + num_proc=data_args.preprocessing_num_workers, + remove_columns=column_names, + load_from_cache_file=not data_args.overwrite_cache, + ) + + if data_args.block_size is None: + block_size = tokenizer.model_max_length + if block_size > 1024: + logger.warn( + f"The tokenizer picked seems to have a very large `model_max_length` ({tokenizer.model_max_length}). " + "Picking 1024 instead. You can change that default value by passing --block_size xxx." + ) + block_size = 1024 + else: + if data_args.block_size > tokenizer.model_max_length: + logger.warn( + f"The block_size passed ({data_args.block_size}) is larger than the maximum length for the model" + f"({tokenizer.model_max_length}). Using block_size={tokenizer.model_max_length}." + ) + block_size = min(data_args.block_size, tokenizer.model_max_length) + + # Main data processing function that will concatenate all texts from our dataset and generate chunks of block_size. + def group_texts(examples): + # Concatenate all texts. + concatenated_examples = {k: sum(examples[k], []) for k in examples.keys()} + total_length = len(concatenated_examples[list(examples.keys())[0]]) + # We drop the small remainder, we could add padding if the model supported it instead of this drop, you can + # customize this part to your needs. + total_length = (total_length // block_size) * block_size + # Split by chunks of max_len. + result = { + k: [t[i : i + block_size] for i in range(0, total_length, block_size)] + for k, t in concatenated_examples.items() + } + result["labels"] = result["input_ids"].copy() + return result + + # Note that with `batched=True`, this map processes 1,000 texts together, so group_texts throws away a remainder + # for each of those groups of 1,000 texts. You can adjust that batch_size here but a higher value might be slower + # to preprocess. + # + # To speed up this part, we use multiprocessing. See the documentation of the map method for more information: + # https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.map + + lm_datasets = tokenized_datasets.map( + group_texts, + batched=True, + num_proc=data_args.preprocessing_num_workers, + load_from_cache_file=not data_args.overwrite_cache, + ) + + if training_args.do_train: + if "train" not in tokenized_datasets: + raise ValueError("--do_train requires a train dataset") + train_dataset = lm_datasets["train"] + if data_args.max_train_samples is not None: + train_dataset = train_dataset.select(range(data_args.max_train_samples)) + + if training_args.do_eval: + if "validation" not in tokenized_datasets: + raise ValueError("--do_eval requires a validation dataset") + eval_dataset = lm_datasets["validation"] + if data_args.max_val_samples is not None: + eval_dataset = eval_dataset.select(range(data_args.max_val_samples)) + + # Initialize our Trainer + trainer = Trainer( + model=model, + args=training_args, + train_dataset=train_dataset if training_args.do_train else None, + eval_dataset=eval_dataset if training_args.do_eval else None, + tokenizer=tokenizer, + # Data collator will default to DataCollatorWithPadding, so we change it. + data_collator=default_data_collator, + ) + + # Training + if training_args.do_train: + if last_checkpoint is not None: + checkpoint = last_checkpoint + elif model_args.model_name_or_path is not None and os.path.isdir(model_args.model_name_or_path): + checkpoint = model_args.model_name_or_path + else: + checkpoint = None + train_result = trainer.train(resume_from_checkpoint=checkpoint) + trainer.save_model() # Saves the tokenizer too for easy upload + + metrics = train_result.metrics + + max_train_samples = ( + data_args.max_train_samples if data_args.max_train_samples is not None else len(train_dataset) + ) + metrics["train_samples"] = min(max_train_samples, len(train_dataset)) + + trainer.log_metrics("train", metrics) + trainer.save_metrics("train", metrics) + trainer.save_state() + + # Evaluation + if training_args.do_eval: + logger.info("*** Evaluate ***") + + metrics = trainer.evaluate() + + max_val_samples = data_args.max_val_samples if data_args.max_val_samples is not None else len(eval_dataset) + metrics["eval_samples"] = min(max_val_samples, len(eval_dataset)) + perplexity = math.exp(metrics["eval_loss"]) + metrics["perplexity"] = perplexity + + trainer.log_metrics("eval", metrics) + trainer.save_metrics("eval", metrics) + + +def _mp_fn(index): + # For xla_spawn (TPUs) + main() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ICLR2023/src/preprocess.py b/ICLR2023/src/preprocess.py new file mode 100644 index 0000000..20d51b3 --- /dev/null +++ b/ICLR2023/src/preprocess.py @@ -0,0 +1,111 @@ +import os +import random +import utils +import glob +import json +from typing import List +from strictfire import StrictFire as Fire # aborts early on invalid arguments + +class WeirdInputsException(Exception): + pass + +def get_inputs(sat: str): + """Extacts arguments past the first from a function string + def f(a: Dict[int, str], b=12): + test + + should give 'b=12' + """ + sat = sat.replace(" -> bool", "") + first_line = sat.split("\n")[0].strip() + if not first_line.endswith("):") and "#" in first_line: + if "):" in first_line: + n = first_line.index("):") + if "#" in first_line[n:]: + first_line = first_line[:n + first_line[n:].index("#")].strip() + else: + first_line = "" # raises exception below + if not (first_line.endswith("):") and first_line.startswith("def")): + raise WeirdInputsException("Weird puzzle, cannot extract inputs", json.dumps(sat)) + arg_str = first_line[first_line.index("("):-len("):")] + depth = 0 + for i, c in enumerate(arg_str): + if c == "," and depth == 0: + return arg_str[i + 1:].strip() + elif c == "[": + depth += 1 + elif c == "]": + depth -= 1 + return "" + +def main( + path, + filtered_name="gen_ps_filtered.txt", + unfiltered_name=None, # "gen_ps_unfiltered.txt", + max_sols_per_puzzle=8, + seed=0): + """ + Merge the puzzles from the given json input files. Examples: + python preprocess.py -unfiltered_name=gen_ps_unfiltered.txt -- ~/aicoder/data/gen_125M_RL/*.json + + path: path to search for json files + filtered_name: path to write puzzles, unfiltered (default: gen_ps_filtered.txt) + unfiltered_name: path to write filtered puzzles (optional) + max_sols_per_puzzle: maximum number of solutions per puzzle (default 8) + seed: random seed (default 0) for reproducibility + infiles: list of files to read puzzles from (like /path/*.json) + """ + + # Make the path so enumeration off that path works, even if it doesn't exist yet + filtered_path = os.path.join(path, filtered_name) + os.makedirs(os.path.dirname(filtered_path), exist_ok=True) + + codes = [] + all_codes = [] + + # grab all the iter_* data for just this experiment + gen_paths = [os.path.join(path, "../*/*.json")] + + # grab just the data for this iter_# for this experiment + # gen_paths = [os.path.join(path, "*.json")] + + for gen_path in gen_paths: + for filename in sorted(glob.glob(gen_path)): + print("preprocess filename:", filename) + js = utils.load_json(filename) + for f, successes, failures in js: + for body in sorted(utils.dedup(successes), key=len)[:max_sols_per_puzzle]: + + try: + g = f"def g({get_inputs(f)}):{body}".strip("\\").strip() + codes.append(f + "\n\n" + g + "\n\n" + "assert f(g())\n\n") + except WeirdInputsException: + print("failed to create g") + pass + print(f"{len(codes):,}/{len(all_codes):,} puzzles of preprocessing {filename}") + + print("len(codes)", len(codes)) + codes = utils.dedup(codes) + print("len(codes) after dedup", len(codes)) + + random.shuffle(codes) + random.shuffle(all_codes) + + # Make it the same number of examples as we got from codex + codes = codes[:950511] + print("len(codes) after truncation", len(codes)) + + code = "".join(codes) + + utils.save_text_file(code, filtered_path) + print(f"Wrote filtered results to {filtered_path}") + + assert unfiltered_name is None, "Not supported now, go back to earlier version" + if unfiltered_name: + unfiltered_path = os.path.join(path, filtered_name) + utils.save_text_file("".join(all_codes), unfiltered_path) + print(f"Wrote unfiltered results to {unfiltered_path}") + + +if __name__ == "__main__": + Fire(main) diff --git a/ICLR2023/src/requirements.txt b/ICLR2023/src/requirements.txt new file mode 100644 index 0000000..af04fa0 --- /dev/null +++ b/ICLR2023/src/requirements.txt @@ -0,0 +1,10 @@ +tqdm +orderedset +numpy +astor +sklearn +fire +strictfire +pebble +deepspeed == 0.6.1 +transformers == 4.30.0 \ No newline at end of file diff --git a/ICLR2023/src/solve.py b/ICLR2023/src/solve.py new file mode 100644 index 0000000..1cbe1dc --- /dev/null +++ b/ICLR2023/src/solve.py @@ -0,0 +1,314 @@ +from strictfire import StrictFire as Fire # aborts early on invalid arguments +import os +import time +import torch +from transformers import GPTNeoForCausalLM +import deepspeed +import gc +import tqdm +from typing import List +import ast +import random +import numpy as np +import judge +import utils + + +def load_model(model_path, pad_token_id=None, mp_size=1): + start_time = time.time() + model = GPTNeoForCausalLM.from_pretrained(model_path, pad_token_id=pad_token_id).half() + utils.info(f"Loaded model in {time.time()-start_time:.1f}s") + + print("deepspeed version", deepspeed.__version__) + print("mp_size", mp_size) + + if (deepspeed.__version__[:5] >= "0.6.0"): + # This works on deepspeed 0.6.0 and later - deepspeed updated their tutorials and docs + return deepspeed.init_inference(model, mp_size=mp_size, dtype=torch.float16, replace_method="auto", replace_with_kernel_inject=True).module + else: + # This works on deepspeed 0.5.1 and 0.5.6 + return deepspeed.init_inference(model, mp_size=mp_size, dtype=torch.float16, replace_method="auto").module + +def get_puz_num_str(prefix: str): + """ + If the prefix has def f1 ... def f5, it returns "6", otherwise it returns "" + """ + if "def f1(" in prefix: + i = 1 + while f"def f{i}(" in prefix: + i += 1 + return str(i) + else: + return "" + + +def gen_prompts(fs: List[str], prefix: str) -> str: + # extract everything after first argument + ans = [] + + puz_num_str = get_puz_num_str(prefix) + + for f in fs: + args = f[f.index("(") + 1 : f.index("):\n")] + if "," in args: + inputs = args[args.index(",") + 1 :].strip() + else: + inputs = "" + + f_new = f.replace("def f(", f"def f{puz_num_str}(").strip() + prompt = f"{prefix}{f_new}\n\ndef g{puz_num_str}({inputs}):" + + ans.append(prompt) + + return ans + + +def trim_gen_texts(gen_texts, prefix): + """ + Trim the generated texts to remove the prefix and find the end of the generated function + """ + # utils.silence_std_err(True) + + p_num = get_puz_num_str(prefix) + + assert all(t.startswith(prefix) for t in gen_texts) + + texts = [text[len(prefix) :] for text in gen_texts] # remove prefix + # for t in texts: + # print("====") + # print(t) + + texts = [text.replace(f"f{p_num}(", "f(").replace(f"g{p_num}(", "g(") for text in texts] # remove f + + gs = [] + for t in texts: # for sat, t in zip(sats, texts): + # print("-t", t) + # print("-f", f) + # f = sat.replace("def sat(", "def f(") + # assert t.strip().startswith(f.strip()) + # assert t.startswith(f) + gs.append(t[t.index("def g(") :].strip()) + + results = [] + for st in gs: + lines = st.split("\n") + for i in range(1, len(lines)): + line = lines[i] + if line and line[0] not in " \t": + lines = lines[:i] + break + g = "\n".join(lines).strip() + + try: + ast.parse(g) + results.append(g) + except: + results.append(None) + + return results + + +def gen(prompts, tokenizer, model, batch_size, temp, gen_tokens): + + # print("generating") + start_time = time.time() + + gen_texts = [] + for start_i in range(0, len(prompts), batch_size): + cur_prompts = prompts[start_i : start_i + batch_size] + tokens = tokenizer(cur_prompts, padding=True, return_tensors="pt").input_ids.cuda() + max_length = tokens.shape[1] + gen_tokens # ids.shape[1] is num_tokens of the longest prompt + # print(tokenizer.batch_decode(ids)[0]) + with torch.no_grad(): + assert max_length <= 2048 + generated = model.generate( + tokens, + do_sample=(temp != 0), + min_length=max_length, # total length including prompt + max_length=max_length, + temperature=(temp or None), # use None if temp == 0.0 + use_cache=True, + # num_return_sequences=num_return, + ) + # possibly todo: trim all generations to gen_tokens length? + gen_texts.extend(tokenizer.batch_decode(generated, skip_special_tokens=True, clean_up_tokenization_spaces=False)) + duration = time.time() - start_time + utils.info(f"Generated {len(gen_texts)} texts in {duration:.1f}s") + assert len(gen_texts) == len(prompts) + assert all(t.startswith(prompt) for t, prompt in zip(gen_texts, prompts)) + return gen_texts + + +def solve( + puzzles="../data/test_228.json", + prefix="../data/train_prefix.txt", + attempts=10, + fixed_temp=None, + model_path="EleutherAI/gpt-neo-2.7B", + gpu=0, + batch_size=4, # Sometimes shrinking the batch size doesn't work, like A100 need 8 on 2.7B to run - dies otherwise. + gen_tokens=150, + out="../outputs/solve//", + seed=0 +): + """ + Solve puzzles. Writes the results in outputs/solve/date-time folder. + + puzzles: the file containing the puzzles to solve (default: ../data/test_228.json) + prefix: text filename containing prompt (default: ../data/tutorial_prefix.txt) + attempts: number of attempts to solve each puzzle (default: 10) + fixed_temp: the temperature to use for the solver, if None it will automatically increase temperature (default: None) + model_path: the path to the model to fine tune (default "EleutherAI/gpt-neo-2.7B") + gpu: which gpu to use, currently only supports one gpu (default: 0) + batch_size: initial GPU batch size, automatically reduced if needed (default: 64) + gen_tokens: minimum number of tokens to generate per solution (default: 150) # todo make all equal + out: the path to write the output to, with filled in (default: ../outputs/solved//) + seed: random seed to use (default: 0) + """ + params = locals().copy() + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + os.environ['WORLD_SIZE'] = "4" + + if fixed_temp == 0.0: + utils.warn("*** Fixed temp is 0.0, boiling instead") + + start_time = time.time() + sats = utils.load_json(puzzles) + fs = [s.replace("def sat(", "def f(").strip() for s in sats] + prefix = utils.load_text_file(prefix).strip() if prefix else "" + if prefix: + prefix += "\n\n" + print("out", out) + output_path = utils.create_experiment_outpath(out) + + prompts = gen_prompts(fs, prefix) + prompts_by_f = {f: prompt for f, prompt in zip(fs, prompts)} + + utils.save_json(prompts, os.path.join(output_path, "prompts.json")) + results_filename = os.path.join(output_path, "results.json") + + # gpu if positive is which gpu to use + # gpu if negative is how many gpu to use + print("gpu", gpu) + if (int(gpu) < 0) : + from mpi4py import MPI + mpi_rank = MPI.COMM_WORLD.Get_rank() + mpi_size = MPI.COMM_WORLD.Get_size() + print("mpi_rank and mpi_size", mpi_rank, mpi_size) + + port = 29600 + os.environ["MASTER_ADDR"] = '127.0.0.1' + os.environ["MASTER_PORT"] = str(port) + + print("calling init_distributed") + deepspeed.init_distributed() + mp_size = abs(int(gpu)) + else: + torch.cuda.set_device(int(gpu)) # problematic line for multiple gpus + mp_size = 1 + print ('Available devices ', torch.cuda.device_count()) + print ('Current cuda device ', torch.cuda.current_device()) + + tokenizer = utils.load_tokenizer(model_path) + model = load_model(model_path, pad_token_id=tokenizer.eos_token_id, mp_size=mp_size) # pad_token_id removes warnings + + all_gen = {f: [] for f in fs} # all generated solutions for each puzzle + solutions = {} # to record the solutions + + current_fs = fs.copy() # the puzzles we are solving at the current temperature + next_fs = [] # puzzles to solve at the next temperature + + if fixed_temp: + temp = fixed_temp + delta_temp = 0.0 + else: + temp = 0.0 + delta_temp = 0.2 + + while current_fs or next_fs: + # filter out solved puzzles and puzzles that have already been tried attempts times, and puzzles to be advanced + current_fs = [f for f in current_fs if len(all_gen[f]) < attempts and f not in solutions and f not in next_fs] + if not current_fs: + current_fs, next_fs = next_fs, [] + temp += delta_temp + continue + + potential_attempts = sum([attempts - len(all_gen[f]) for f in current_fs + next_fs]) + utils.info( + f"{len(solutions):,} solved; {potential_attempts:,} potential remaining attempts; " + + f"{len(current_fs):,} at temp={temp:.2f}; " + + ("" if fixed_temp else f"{len(next_fs):,} at temp={temp+delta_temp:.2f}") + ) + while True: # loop to decrease batch size if necessary + try: + gen_texts = gen( + [prompts_by_f[f] for f in current_fs], + tokenizer, + model, + batch_size, + temp, + gen_tokens, + ) + break + except RuntimeError as e: + if "out of memory" in str(e).lower() or "CUBLAS_STATUS_ALLOC_FAILED" in str(e): + utils.info(f"Out of GPU memory solve.py, reducing batch size {batch_size} -> {batch_size//2}") + batch_size //= 2 + assert batch_size >= 1 + torch.cuda.empty_cache() # not important, just lets nvidia-smi update if anything + else: + raise + + assert len(gen_texts) == len(current_fs) + gs = trim_gen_texts(gen_texts, prefix) + for f, g in zip(current_fs, gs): + if not fixed_temp: + if (temp==0.0 or (g and any(g == g2 for g2, _temp in all_gen[f]))): + next_fs.append(f) # increase temperature when you see a repeated solution or if temperature is 0.0 + # this will also cause it to be removed from current_fs at the beginning of the next loop + all_gen[f].append([g, temp]) + parsed = [(f, g) for f, g in zip(current_fs, gs) if g] + judge_srcs = [f"{f}\n{g}\nassert test_puzzle(f, g())" for f, g in parsed] + judgments = judge.judge_parallel(judge_srcs, timeout=1.0) + assert len(judgments) == len(parsed) == len(judge_srcs) <= len(current_fs) + for (f, g), solved in zip(parsed, judgments): + assert f not in solutions + if solved: + solutions[f] = g + for f in all_gen: + if f not in solutions: + assert len(all_gen[f]) == attempts + all_gen[f].append("# UNSOLVED #") # makes len(all_gen[f]) > attempts + + scores = sorted([len(all_gen[f]) for f in solutions]) + print(f"{len(solutions):,} solved at:", scores) + passes = {} + k = 1 + while True: + passes[k] = sum(len(gens) <= k for gens in all_gen.values()) + if k == attempts: + break + k = min(2 * k, attempts) + + utils.info(f" Pass@k out of {len(fs):,} puzzles") + utils.info(" k: ", "".join(f"{k:6,}" for k in passes)) + utils.info("# solved in <= k attempts: ", "".join(f"{passes[k]:6,}" for k in passes)) + + duration_mins = (time.time() - start_time) / 60 + results = dict( + duration_mins=duration_mins, passes=passes, scores=scores, params=params, solutions=solutions, all_gen=all_gen + ) + utils.info(f"Saved results generations to '{results_filename}'. Took {duration_mins:.1f} minutes.") + utils.save_json(results, results_filename) + + # cleanup model (for multithreaded, this happens anyways when the process dies) + # here we delte the model and reset worker_data to None (really either of the two should work + # but just being extra careful) + del model + gc.collect() + torch.cuda.empty_cache() + +if __name__ == "__main__": + Fire(solve) diff --git a/ICLR2023/src/utils.py b/ICLR2023/src/utils.py new file mode 100644 index 0000000..3d46bea --- /dev/null +++ b/ICLR2023/src/utils.py @@ -0,0 +1,286 @@ +import json +import logging +import inspect +import io +import os +import sys +import time +from transformers import AutoTokenizer + + +os.environ["WANDB_DISABLED"] = "true" +os.environ["TOKENIZERS_PARALLELISM"] = "false" +my_path = os.path.dirname(__file__) + + +def load_tokenizer(model_path): + tokenizer = AutoTokenizer.from_pretrained(model_path) + tokenizer.padding_side = "left" + tokenizer.pad_token = tokenizer.eos_token + return tokenizer + + +def num_tokens(s: str, tokenizer, verbose=False): + + start_time = time.time() + if verbose: + info(f"Tokenizing {pretty_int(len(s))} chars ({pretty_int(len(s.splitlines()))} lines)") + # ans = _tokenizer(s, return_tensors="pt").input_ids.shape[1] # produces annoying warnings + ans = tokenizer(s, return_tensors="pt", max_length=10 + len(s), truncation=True).input_ids.shape[1] + + duration_mins = (time.time() - start_time)/60 + if verbose: + info(f"Num tokens: {ans:,} in {duration_mins:.2f} mins") + return ans + + +def create_experiment_outpath(out: str, bSaveCommand=True): + """ + Create the output directory and return its name. Also stores the command line in command.sh + Date format is like Jan-1-2020 + """ + output_path = str(out).replace("", time.strftime("%b%d-%H-%M-%S")) + os.makedirs(output_path, exist_ok=True) # ran into error due to non-atomic check + if bSaveCommand: + save_text_file(' '.join([sys.executable] + sys.argv) + "\n", f"{output_path}/command.sh") + # make command.sh executable: + os.chmod(f"{output_path}/command.sh", 0o755) + return output_path + +def pretty_int(n: int) -> str: + """Converts an integer to a string with commas, with M for millions and B for billions""" + if n > 1_000_000_000: + return f"{n/1_000_000_000:.1f}B" + if n > 1_000_000: + return f"{n/1_000_000:.1f}M" + return f"{n:,}" + + + +def test_puzzle(f, x): + """Checks if x is of the correct type and makes f return True (literally True, not an integer or whatever) + + :param f: Puzzle + :param x: candidate answer + :return: + """ + answer_type = list(f.__annotations__.values())[0] + if not type_check(x, answer_type): + raise TypeError + return f(x) is True + + + +def type_check(obj, typ): + """ + check if obj is of type `typ` where `typ` is a `typing` module type annotation, eg List[int] + The way we do this to be compatible across versions is we first convert the type to a string. + """ + + type_str = str(typ).replace("typing.", "") + if type_str.startswith(" 0: + hanoi(n - 1, source, dest, temp) + moves.append([source, dest]) + hanoi(n - 1, temp, source, dest) + hanoi(8, 0, 1, 2) + return moves ``` +This was not on its first try, but that is one of the advantages of puzzles---it is easy for the computer to check +its answers so it can generate many answers until it finds one. For this puzzle, about 1 in 1,000 solutions were +satisfactory. Clearly, codex has seen this problem before in other input formats---it even generated a url! +(Upon closer inspection, the website exists and contains Python Tower-of-Hanoi code in a completely different format +with different variable names.) +On a harder, less-standard [Hanoi puzzle variant](puzzles/README.md#towersofhanoiarbitrary) that +requires moving from particular start to end positions, codex didn't solve it on 10,000 attempts. + +Next, consider a puzzle inspired by [this easy competitive programming problem](https://codeforces.com/problemset/problem/58/A) +from [codeforces.com](https://codeforces.com) website: +```python +def sat(inds: List[int], string="Sssuubbstrissiingg"): + """Find increasing indices to make the substring "substring""" + return inds == sorted(inds) and "".join(string[i] for i in inds) == "substring" +``` +Codex generated the code below, which when run gives the valid answer `[1, 3, 5, 7, 8, 9, 10, 15, 16]`. +This satisfies this puzzle because it's an increasing list of indices which if you join the +characters `"Sssuubbstrissiingg"` in these indices you get `"substring"`. +```python +def sol(string="Sssuubbstrissiingg"): + x = "substring" + pos = string.index(x[0]) + inds = [pos] + while True: + x = x[1:] + if not x: + return inds + pos = string.find(x[0], pos+1) + if pos == -1: + return inds + inds.append(pos) +``` +Again, there are multiple valid answers, and again this was out of many attempts (only 1 success in 10k). + A more challenging puzzle that requires [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) is the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem which we can also describe with strings: ```python -from typing import List +def sat(x: List[int], length=20, s="Dynamic programming solves this classic job-interview puzzle!!!"): + """Find the indices of the longest substring with characters in sorted order""" + return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1)) -def sat(x: List[int], s="Dynamic programming solves this classic job-interview puzzle!!!"): - """Find the indexes (possibly negative!) of the longest monotonic subsequence""" - return all(s[x[i]] <= s[x[i+1]] and x[i+1] > x[i] for i in range(25)) ``` +Codex didn't solve this one. -The classic [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle can be written as follows: +The dataset also has a number of open problems in computer science and mathematics. For example, +[Conway's 99-graph problem](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem) +is an unsolved problem in graph theory +(see also [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf)) ```python -def sat(moves: List[List[int]]): - """moves is list of [from, to] pairs""" - t = ([8, 7, 6, 5, 4, 3, 2, 1], [], []) # towers state - return all(t[j].append(t[i].pop()) or t[j][-1] == min(t[j]) for i, j in moves) and t[0] == t[1] - +def sat(edges: List[List[int]]): + """ + Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common + neighbor, and in which each two non-adjacent vertices have exactly two common neighbors. + """ + # first compute neighbors sets, N: + N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)} + return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i)) ``` +Why puzzles? One reason is that, if we can solve them better than human programmers, +then we could make progress on some important algorithms problems. +But until then, a second reason is that they can be valuable for training and evaluating AI systems. +Many programming datasets have been proposed over the years, and several have problems of a similar nature +(like programming competition problems). In puzzles, the spec is defined by code, while +other datasets usually use a combination of English and a hidden test set of input-output pairs. English-based +specs are notoriously ambiguous and test the system's understanding of English. +And with input-output test cases, you would have to have solved a puzzle before you pose it, +so what is the use there? Code-based specs +have the advantage that they are unambiguous, there is no need to debug the AI-generated code or fears that it +doesn't do what you want. If it solved the puzzle, then it succeeded by definition. + For more information on the motivation and how programming puzzles can help AI learn to program, see the paper: *Programming Puzzles*, by Tal Schuster, Ashwin Kalyan, Alex Polozov, and Adam Tauman Kalai. 2021 (Link to be added shortly) -# [Click here to browse the puzzles](/puzzles/README.md) +# [Click here to browse the puzzles and solutions](/puzzles/README.md) The problems in this repo are based on: * Wikipedia articles about [algorithms](https://en.wikipedia.org/wiki/List_of_algorithms), [puzzles](https://en.wikipedia.org/wiki/Category:Logic_puzzles), @@ -100,7 +195,7 @@ During a Microsoft hackathon July 27-29, 2020, several people completed 30 user [Hackathon_puzzles.ipynb](/notebooks/Hackathon_puzzles.ipynb). These are of a somewhat different flavor as they are more often `hacks` like ```python -def f(x): +def sat(x): return x > x ``` where the type of `x` is clearly non-standard. The creators of these puzzles include github users: @@ -162,6 +257,11 @@ You can try out the notebook at (link to be added). * Conway's 99-graph problem (**open**) * Finding a cycle in the Collatz process (**open**) +## Train-test split +The file [`split.json`](/notebooks/split.json) contains a suggested train-test split. This split was hand-selected +by the puzzle authors, who are familiar with all puzzles, so that: there is minimal overlap between related puzzles +in the two splits. In particular, for pairs of related puzzles, either both were placed in the training set or the test +set. ## Contributing diff --git a/generators/ICPC.py b/generators/ICPC.py index e23475d..c4df8b0 100644 --- a/generators/ICPC.py +++ b/generators/ICPC.py @@ -2,7 +2,7 @@ Problems inspired by the [International Collegiate Programming Contest](https://icpc.global) (ICPC). """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -15,7 +15,6 @@ class BiPermutations(PuzzleGenerator): [ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) which is 2,287 characters. """ - taint_date = [2019, 3, 31] @staticmethod def sat(perms: List[List[int]], @@ -37,10 +36,7 @@ def sat(perms: List[List[int]], return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1)) @staticmethod - def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], - prices1=[5, 5, 5, 4, 2, 5, 1, 1], - heights0=[2, 4, 9, 3, 8, 5, 5, 4], - heights1=[1, 3, 8, 1, 5, 4, 4, 2]): + def sol(prices0, prices1, heights0, heights1): n = len(prices0) prices = [prices0, prices1] orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])), @@ -83,7 +79,6 @@ class OptimalBridges(PuzzleGenerator): [ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) which is 3,003 characters. """ - taint_date = [2019, 3, 31] @staticmethod def sat(indices: List[int], @@ -118,7 +113,8 @@ def sat(indices: List[int], # adapted from https://github.com/SnapDragon64/ACMFinalsSolutions/blob/master/finals2019/beautifulbridgesDK.cc @staticmethod - def sol(H, alpha, beta, xs, ys, thresh): # thresh is ignored + def sol(H, alpha, beta, xs, ys, thresh): + # thresh is ignored n = len(xs) cost = [-1] * n prior = [n] * n @@ -195,7 +191,6 @@ class CheckersPosition(PuzzleGenerator): Nobody solved this problem during the competition -- it is pretty difficult! """ - taint_date = [2019, 3, 31] @staticmethod def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]): @@ -444,7 +439,6 @@ class MatchingMarkers(PuzzleGenerator): This is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time). """ - taint_date = [2019, 3, 31] @staticmethod def sat(cut_position: int, ring="yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM", lower=5): diff --git a/generators/IMO.py b/generators/IMO.py index 8e2aff4..3c5aab2 100644 --- a/generators/IMO.py +++ b/generators/IMO.py @@ -2,7 +2,7 @@ [International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) [problems](https://www.imo-official.org/problems.aspx)""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -20,8 +20,7 @@ class ExponentialCoinMoves(PuzzleGenerator): Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)""" - multiplier = 10 # worth 10 times normal so that it can run 10 times longer than normal - taint_date = [2010, 7, 2] + skip_example = True # so that we can add a multiplier in gen method below @staticmethod def sat(states: List[List[int]], n=16385): @@ -89,11 +88,10 @@ def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0 return ans def gen(self, target_num_instances): + self.add(dict(n=2**14 + 1), multiplier=10) # n=16385 will be first instance because of skip_example for i in range(10): n = 2 ** i - self.add(dict(n=n)) - if len(self.instances) >= target_num_instances: - return + self.add(dict(n=n), multiplier=1 if n <= 4 else n) class NoRelativePrimes(PuzzleGenerator): @@ -104,11 +102,8 @@ class NoRelativePrimes(PuzzleGenerator): theorem? """ - taint_date = [2016, 7, 1] - - @staticmethod - def sat(nums: List[int], b=6, m=2): + def sat(nums: List[int], b=7, m=6): """ Let P(n) = n^2 + n + 1. @@ -188,8 +183,6 @@ class FindRepeats(PuzzleGenerator): Inspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx) """ - taint_date = [2017, 7, 12] - @staticmethod def sat(indices: List[int], a0=123): """ @@ -237,8 +230,6 @@ class PickNearNeighbors(PuzzleGenerator): The puzzle solution follows the judge's proof closely.""" - taint_date = [2017, 7, 12] - @staticmethod def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): """ @@ -266,7 +257,8 @@ def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n)) @staticmethod - def sol(heights): # Based on the judge's solution. + def sol(heights): + # Based on the judge's solution. n = int(len(heights) ** 0.5) assert sorted(heights) == list(range(n * (n + 1))) groups = [h // (n + 1) for h in heights] @@ -301,8 +293,6 @@ class FindProductiveList(PuzzleGenerator): Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx) """ - taint_date = [2010, 7, 2] - @staticmethod def sat(li: List[int], n=18): """ @@ -334,10 +324,8 @@ def gen(self, target_num_instances): class HalfTag(PuzzleGenerator): """Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)""" - taint_date = [2020, 9, 19] - @staticmethod - def sat(li: List[int], n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]): + def sat(li: List[int], tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]): """ The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times. The goal is to find a subset (list) li of half the indices such that: @@ -353,12 +341,14 @@ def sat(li: List[int], n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]): Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2] """ + n = max(tags) + 1 assert sorted(tags) == sorted(list(range(n)) * 4), "hint: each tag occurs exactly four times" assert len(li) == len(set(li)) and min(li) >= 0 return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)] @staticmethod - def sol(n, tags): + def sol(tags): + n = max(tags) + 1 pairs = {(i, 4 * n - i - 1) for i in range(2 * n)} by_tag = {tag: [] for tag in range(n)} for p in pairs: @@ -419,8 +409,7 @@ def gen_random(self): tags = [i // 4 for i in range(4 * n)] self.random.shuffle(tags) # print(self.__class__, n, tick()) - self.add(dict(n=n, tags=tags)) - + self.add(dict(tags=tags)) if __name__ == "__main__": diff --git a/generators/__init__.py b/generators/__init__.py index 753672b..541bd1d 100644 --- a/generators/__init__.py +++ b/generators/__init__.py @@ -10,7 +10,6 @@ from . import compression from . import conways_game_of_life from . import games -from . import game_theory from . import graphs from . import ICPC from . import IMO diff --git a/generators/algebra.py b/generators/algebra.py index 14a1df4..35f1d95 100644 --- a/generators/algebra.py +++ b/generators/algebra.py @@ -1,20 +1,17 @@ """Roots of polynomials""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List # See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles -class AlgebraGen: - blah = 17 - taint_date = [2021, 4, 26] - - -class QuadraticRoot(AlgebraGen, PuzzleGenerator): +class QuadraticRoot(PuzzleGenerator): """See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)""" + tags = [Tags.math, Tags.famous] + @staticmethod def sat(x: float, coeffs=[2.5, 1.3, -0.5]): """ @@ -52,6 +49,8 @@ def gen_random(self): class AllQuadraticRoots(PuzzleGenerator): """See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).""" + tags = [Tags.math, Tags.famous] + @staticmethod def sat(roots: List[float], coeffs=[1.3, -0.5]): """Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]""" @@ -75,6 +74,8 @@ def gen_random(self): class CubicRoot(PuzzleGenerator): """See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).""" + tags = [Tags.math, Tags.famous] + @staticmethod def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]): """ @@ -109,6 +110,8 @@ def gen_random(self): class AllCubicRoots(PuzzleGenerator): """See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).""" + tags = [Tags.math, Tags.famous] + @staticmethod def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]): """Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3). diff --git a/generators/basic.py b/generators/basic.py index 8a7da08..a8c1466 100644 --- a/generators/basic.py +++ b/generators/basic.py @@ -1,12 +1,15 @@ """Problems testing basic knowledge -- easy to solve if you understand what is being asked""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List # See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles class SumOfDigits(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(x: str, s=679): """Find a number that its digits sum to a specific value.""" @@ -22,6 +25,9 @@ def gen_random(self): class FloatWithDecimalValue(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(z: float, v=9, d=0.0001): """Create a float with a specific decimal.""" @@ -44,6 +50,9 @@ def gen_random(self): class ArithmeticSequence(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(x: List[int], a=7, s=5, e=200): """Create a list that is a subrange of an arithmetic sequence.""" @@ -61,6 +70,9 @@ def gen_random(self): class GeometricSequence(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(x: List[int], a=8, r=2, l=50): """Create a list that is a subrange of an gemoetric sequence.""" @@ -78,6 +90,9 @@ def gen_random(self): class LineIntersection(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(e: List[int], a=2, b=-1, c=1, d=2021): """ @@ -103,6 +118,9 @@ def gen_random(self): class IfProblem(PuzzleGenerator): + + tags = [Tags.trivial] + @staticmethod def sat(x: int, a=324554, b=1345345): """Satisfy a simple if statement""" @@ -125,6 +143,9 @@ def gen_random(self): class IfProblemWithAnd(PuzzleGenerator): + + tags = [Tags.trivial] + @staticmethod def sat(x: int, a=9384594, b=1343663): """Satisfy a simple if statement with an and clause""" @@ -148,6 +169,8 @@ def gen_random(self): class IfProblemWithOr(PuzzleGenerator): + tags = [Tags.trivial] + @staticmethod def sat(x: int, a=253532, b=1230200): """Satisfy a simple if statement with an or clause""" @@ -171,6 +194,8 @@ def gen_random(self): class IfCases(PuzzleGenerator): + tags = [Tags.trivial] + @staticmethod def sat(x: int, a=4, b=54368639): """Satisfy a simple if statement with multiple cases""" @@ -198,6 +223,9 @@ def gen_random(self): class ListPosSum(PuzzleGenerator): + + tags = [Tags.trivial] + @staticmethod def sat(x: List[int], n=5, s=19): """Find a list of n non-negative integers that sum up to s""" @@ -216,6 +244,9 @@ def gen_random(self): class ListDistinctSum(PuzzleGenerator): + + tags = [Tags.math] + @staticmethod def sat(x: List[int], n=4, s=2021): """Construct a list of n distinct integers that sum up to s""" @@ -244,6 +275,9 @@ def gen_random(self): class ConcatStrings(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(x: str, s=["a", "b", "c", "d", "e", "f"], n=4): """Concatenate the list of characters in s""" @@ -262,6 +296,8 @@ def gen_random(self): class SublistSum(PuzzleGenerator): + tags = [Tags.math] + @staticmethod def sat(x: List[int], t=677, a=43, e=125, s=10): """Sum values of sublist by range specifications""" @@ -292,6 +328,8 @@ def gen_random(self): class CumulativeSum(PuzzleGenerator): + tags = [Tags.math, Tags.trivial] + @staticmethod def sat(x: List[int], t=50, n=10): """Find how many values have cumulative sum less than target""" @@ -316,6 +354,9 @@ def gen_random(self): class BasicStrCounts(PuzzleGenerator): + + tags = [Tags.strings] + @staticmethod def sat(s: str, s1='a', s2='b', count1=50, count2=30): """ @@ -347,6 +388,9 @@ def gen_random(self): class ZipStr(PuzzleGenerator): + + tags = [Tags.strings, Tags.trivial] + @staticmethod def sat(s: str, substrings=["foo", "bar", "baz", "oddball"]): """ @@ -365,6 +409,9 @@ def gen_random(self): class ReverseCat(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(s: str, substrings=["foo", "bar", "baz"]): """ @@ -382,6 +429,9 @@ def gen_random(self): class EngineerNumbers(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(ls: List[str], n=100, a='bar', b='foo'): """ @@ -401,6 +451,9 @@ def gen_random(self): class PenultimateString(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(s: str, strings=["cat", "dog", "bird", "fly", "moose"]): """Find the alphabetically second to last last string in a list.""" @@ -417,6 +470,9 @@ def gen_random(self): class PenultimateRevString(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(s: str, strings=["cat", "dog", "bird", "fly", "moose"]): """Find the reversed version of the alphabetically second string in a list.""" @@ -433,6 +489,9 @@ def gen_random(self): class CenteredString(PuzzleGenerator): + + tags = [Tags.trivial, Tags.strings] + @staticmethod def sat(s: str, target="foobarbazwow", length=6): """Find a substring of the given length centered within the target string.""" @@ -449,6 +508,9 @@ def gen_random(self): class SubstrCount(PuzzleGenerator): + + tags = [Tags.brute_force, Tags.strings] + @staticmethod def sat(substring: str, string="moooboooofasd", count=2): """Find a substring with a certain count in a given string""" @@ -477,6 +539,33 @@ def gen_random(self): self.add(dict(string=string, count=count)) +class CompleteParens(PuzzleGenerator): + + tags = [] + + @staticmethod + def sat(t: str, s="))(Add)some))parens()to()(balance(()(()(me!)(((("): + """Add parentheses to the beginning and end of s to make all parentheses balanced""" + for i in range(len(t) + 1): + depth = t[:i].count("(") - t[:i].count(")") + assert depth >= 0 + return depth == 0 and s in t + + @staticmethod + def sol(s): + return "(" * s.count(")") + s + ")" * s.count("(") + + def gen_random(self): + t = "" + depth = 0 + while depth > 0 or self.random.randrange(10): + t += self.random.choice([self.random.pseudo_word(min_len=0, max_len=3), "(", "("] + [")", ")", ")"] * (depth > 0)) + depth = t.count("(") - t.count(")") + a, b = sorted([self.random.randrange(len(t) + 1) for _ in range(2)]) + s = t[a:b] + if 5 < len(s) < 60: + self.add(dict(s=s)) + if __name__ == "__main__": PuzzleGenerator.debug_problems() diff --git a/generators/chess.py b/generators/chess.py index 50ec77d..7565480 100644 --- a/generators/chess.py +++ b/generators/chess.py @@ -1,6 +1,6 @@ """Classic chess puzzles""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -18,6 +18,8 @@ class EightQueensOrFewer(PuzzleGenerator): Hint: a brute force approach works on this puzzle. """ + tags = [Tags.games, Tags.brute_force, Tags.famous] + @staticmethod def sat(squares: List[List[int]], m=8, n=8): """Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.""" @@ -26,7 +28,8 @@ def sat(squares: List[List[int]], m=8, n=8): return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}) @staticmethod - def sol(m, n): # brute force + def sol(m, n): + # brute force k = min(m, n) from itertools import permutations @@ -48,6 +51,8 @@ class MoreQueens(PuzzleGenerator): A brute force approach will not work on many of these problems. """ + tags = [Tags.games, Tags.graphs, Tags.famous] + @staticmethod def sat(squares: List[List[int]], m=9, n=9): """ @@ -88,6 +93,8 @@ class KnightsTour(PuzzleGenerator): See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour) """ + tags = [Tags.games, Tags.graphs, Tags.hard, Tags.famous] + @staticmethod def sat(tour: List[List[int]], m=8, n=8): """Find an (open) tour of knight moves on an m x n chess-board that visits each square once.""" @@ -95,7 +102,8 @@ def sat(tour: List[List[int]], m=8, n=8): return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once @staticmethod - def sol(m, n): # using Warnsdorff's heuristic, breaking ties randomly + def sol(m, n): + # using Warnsdorff's heuristic, breaking ties randomly import random for seed in range(100): r = random.Random(seed) @@ -118,7 +126,7 @@ def possible(i, j): def gen(self, num_target_problems): count = 0 for n in [9, 8, 7, 6, 5] + list(range(10, 100)): - if len(self.instances) == num_target_problems: + if self.num_generated_so_far() == num_target_problems: return m = n self.add(dict(m=m, n=n)) @@ -138,6 +146,8 @@ class UncrossedKnightsPath(PuzzleGenerator): A more precise description is in this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).""" + tags = [Tags.games, Tags.hard, Tags.famous] + nxn_records = {3: 2, 4: 5, 5: 10, 6: 17, 7: 24, 8: 35, 9: 47, 10: 61, 11: 76, 12: 94, 13: 113, 14: 135, 15: 158, 16: 183, 17: 211, 18: 238, 19: 268, 20: 302, 21: 337, 22: 375, 23: 414} @@ -168,7 +178,7 @@ def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (w def gen(self, target_num_instances): for count, n in enumerate(self.nxn_records): - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return self.add(dict(m=n, n=n, target=self.nxn_records[n])) @@ -190,6 +200,8 @@ class UNSOLVED_UncrossedKnightsPath(PuzzleGenerator): A more precise description is in this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).""" + tags = [Tags.unsolved, Tags.games, Tags.famous] + unsolved_nxn_records = {10: 61, 11: 76, 12: 94, 13: 113, 14: 135, 15: 158, 16: 183, 17: 211, 18: 238, 19: 268, 20: 302, 21: 337, 22: 375, 23: 414} @@ -221,7 +233,7 @@ def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (w def gen(self, target_num_instances): for n in self.unsolved_nxn_records: - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return self.add(dict(m=n, n=n, target=self.unsolved_nxn_records[n] + 1)) # Note the +1 means breaking the record! diff --git a/generators/classic_puzzles.py b/generators/classic_puzzles.py index 42c8f40..f66c5e8 100644 --- a/generators/classic_puzzles.py +++ b/generators/classic_puzzles.py @@ -1,7 +1,7 @@ -"""Classic puzzles -""" +"""Classic puzzles""" +# TODO: add tags -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -109,7 +109,8 @@ def sat(x: List[int], length=13, s="Dynamic programming solves this puzzle!!!"): return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1)) @staticmethod - def sol(length, s): # O(N^2) method. Todo: add binary search solution which is O(n log n) + def sol(length, s): + # O(N^2) method. Todo: add binary search solution which is O(n log n) if s == "": return [] n = len(s) @@ -146,7 +147,8 @@ def sat(x: List[int], length=20, s="Dynamic programming solves this classic job- return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1)) @staticmethod - def sol(length, s): # O(N^2) method. Todo: add binary search solution which is O(n log n) + def sol(length, s): + # O(N^2) method. Todo: add binary search solution which is O(n log n) if s == "": return [] n = len(s) @@ -190,10 +192,6 @@ def sat(quine: str): def sol(): return "(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\")" - @staticmethod - def sol2(): # thanks for this simple solution, GPT-3! - return 'quine' - class RevQuine(PuzzleGenerator): """Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3.""" @@ -241,7 +239,7 @@ def sol(n): def gen(self, target_num_instances): for n in [7824] + list(range(target_num_instances)): - if len(self.instances) == target_num_instances: + if self.num_generated_so_far() == target_num_instances: return self.add(dict(n=n), test=n <= 100) @@ -252,25 +250,26 @@ class ClockAngle(PuzzleGenerator): @staticmethod def sat(hands: List[int], target_angle=45): """Find clock hands = [hour, min] such that the angle is target_angle degrees.""" - hour, min = hands - return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle + h, m = hands + assert 0 < h <= 12 and 0 <= m < 60 + hour_angle = 30 * h + m / 2 + minute_angle = 6 * m + return abs(hour_angle - minute_angle) in [target_angle, 360 - target_angle] @staticmethod def sol(target_angle): - for hour in range(1, 13): - for min in range(60): - if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle: - return [hour, min] + for h in range(1, 13): + for m in range(60): + hour_angle = 30 * h + m / 2 + minute_angle = 6 * m + if abs(hour_angle - minute_angle) % 360 in [target_angle, 360 - target_angle]: + return [h, m] + + def gen_random(self): + target_angle = self.random.randrange(0, 360) + if self.sol(target_angle): + self.add(dict(target_angle=target_angle)) - def gen(self, target_num_instances): - for hour in range(1, 13): - for min in range(60): - if len(self.instances) == target_num_instances: - return - double_angle = ((60 * hour + min) - 12 * min) % 720 - if double_angle % 2 == 0: - target_angle = double_angle // 2 - self.add(dict(target_angle=target_angle)) class Kirkman(PuzzleGenerator): """[Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem)""" @@ -408,11 +407,10 @@ def mirror(coords): # rotate to all four corners return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if test(coords) and test(mirror(coords))) - def gen(self, target_num_instances): for easy in range(47): for side in range(47): - if len(self.instances) == target_num_instances: + if self.num_generated_so_far() == target_num_instances: return test = side < 5 or side == 10 num_points = 1 if side == 1 else 2 * side @@ -446,15 +444,233 @@ def gen_random(self): self.add(dict(target=target, max_stamps=max_stamps, options=options)) +class Sudoku(PuzzleGenerator): + """The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)""" + + @staticmethod + def sat(x: str, puz='____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______'): + """Find the unique valid solution to the Sudoku puzzle""" + assert all(c == "_" or c == s for (c, s) in zip(puz, x)) + + full = set('123456789') + for i in range(9): + assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, "invalid row" + assert {x[i] for i in range(i, i + 81, 9)} == full, "invalid column" + assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, "invalid square" + + return True + + @staticmethod + def solve(puz): + """Simple depth-first backtracking solver that branches at the square with fewest possibilities""" + sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz] + + groups = [] + for i in range(9): + groups.append(list(range(9 * i, 9 * i + 9))) + groups.append(list(range(i, i + 81, 9))) + groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)]) + + inv = [[] for i in range(81)] + for g in groups: + for i in g: + inv[i].append(g) + + def reduce(): + """Reduce possibilities and return False if it's clearly impossible to solve, True otherwise. + Repeatedly applies two types of logic: + * When an entry has a single possibility, remove that value from all 20 neighbors + * When a row/col/square has only one entry with k as a possibility, fill in that possibility + """ + done = False + while not done: + done = True + for i in range(81): + new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]} + if not new: + return False + if len(sets[i]) != len(new): + sets[i] = new + done = False + + for g in groups: + for k in range(1, 10): + possibilities = [i for i in g if k in sets[i]] + if not possibilities: + return False + if len(possibilities) == 1: + i = possibilities[0] + if len(sets[i]) > 1: + done = False + sets[i] = {k} + + return True + + ans = [] + + counter = 0 + + def solve_helper(): + nonlocal sets, ans, counter + counter += 1 + assert len(ans) <= 1, "Sudoku puzzle should have a unique solution" + old_sets = sets[:] + if reduce(): + if all(len(s) == 1 for s in sets): + ans.append("".join(str(list(s)[0]) for s in sets)) + else: + smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10) + for v in sorted(sets[smallest_set]): + sets[smallest_set] = {v} + solve_helper() + + sets = old_sets + + solve_helper() + assert ans, "No solution found" + return ans[0] + + @staticmethod + def print_board(board): + """Helpful method used for development""" + for i in range(9): + for j in range(9): + print(board[9 * i + j], end=" " if j == 2 or j == 5 else "") + print() + if i == 2 or i == 5: + print() + + @staticmethod + def print_sets(sets): + """Helpful method used for development""" + ans = "" + for i in range(9): + for j in range(9): + ans += " " + "".join(str(k) if k in sets[9 * i + j] else "_" for k in range(1, 10)) + if j == 2 or j == 5: + ans += " | " + if i == 8: + print(ans) + return + ans += "\n" + if i == 2 or i == 5: + ans += "\n" + + @staticmethod + def gen_sudoku_puzzle(rand): + + groups = [] + for i in range(9): + groups.append(list(range(9 * i, 9 * i + 9))) + groups.append(list(range(i, i + 81, 9))) + groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)]) + + inv = [[] for i in range(81)] + for g in groups: + for i in g: + inv[i].append(g) + + def solve(puz): + """Basically the same as our solver above except that it returns a list of (up to 2) solutions.""" + sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz] + + def reduce(): + """Reduce possibilities and return False if it's clearly impossible to solve, True otherwise. + Repeatedly applies two types of logic: + * When an entry has a single possibility, remove that value from all 20 neighbors + * When a row/col/square has only one entry with k as a possibility, fill in that possibility + """ + done = False + while not done: + done = True + for i in range(81): + new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]} + if not new: + return False + if len(sets[i]) != len(new): + sets[i] = new + done = False + + for g in groups: + for k in range(1, 10): + possibilities = [i for i in g if k in sets[i]] + if not possibilities: + return False + if len(possibilities) == 1: + i = possibilities[0] + if len(sets[i]) > 1: + done = False + sets[i] = {k} + + return True + + ans = [] + + counter = 0 + + def solve_helper(): + nonlocal sets, ans, counter + counter += 1 + if len(ans) > 1: + return + old_sets = sets[:] + if reduce(): + if all(len(s) == 1 for s in sets): + ans.append("".join(str(list(s)[0]) for s in sets)) + else: + smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10) + pi = sorted(sets[smallest_set]) + rand.shuffle(pi) + for v in pi: + sets[smallest_set] = {v} + solve_helper() + + sets = old_sets + + solve_helper() + return ans + + x = ["_"] * 81 + perm = list("123456789") + rand.shuffle(perm) + x[:9] == perm + x = list(solve(x)[0]) + + done = False + while not done: + done = True + pi = list([i for i in range(81) if x[i] != "_"]) + rand.shuffle(pi) + for i in pi: + old = x[i] + x[i] = "_" + ans = solve("".join(x)) + assert ans + if len(ans) > 1: + x[i] = old + else: + done = False + # print() + # Sudoku.print_board(x) + # print(" ", 81-x.count("_")) + + return "".join(x) + + def gen_random(self): + + puz = None + for attempt in range(10 if self.num_generated_so_far() < 10 else 1): + puz2 = Sudoku.gen_sudoku_puzzle(self.random) + if puz is None or puz2.count("_") > puz.count("_"): + puz = puz2 + + self.add(dict(puz=puz)) + + class SquaringTheSquare(PuzzleGenerator): """[Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square) Wikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square) - due to Duijvestijn (1978): - ```python - [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35], - [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18], - [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]] - ``` + due to Duijvestijn (1978). """ @staticmethod @@ -480,11 +696,10 @@ def sol(): class NecklaceSplit(PuzzleGenerator): - """[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem) - """ + """[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)""" @staticmethod - def sat(n: int, lace="bbbbrrbrbrbbrrrr"): + def sat(n: int, lace="bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb"): """ Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of reds and blues. @@ -633,15 +848,11 @@ class WaterPouring(PuzzleGenerator): """[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)""" @staticmethod - def sat( - moves: List[List[int]], - capacities=[8, 5, 3], - init=[8, 0, 0], - goal=[4, 4, 0] - ): # moves is list of [from, to] pairs + def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): """ Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring one jug into another until it is full or the first is empty) to reaches the given goal state. + moves is list of [from, to] pairs """ state = init.copy() @@ -728,6 +939,7 @@ def sat(li: List[int], words=["SEND", "MORE", "MONEY"]): @staticmethod def sol(words): + print("solving", words) pi = list(range(10)) # permutation letters = [] order = {} diff --git a/generators/codeforces.py b/generators/codeforces.py index d90bf93..09ee5fb 100644 --- a/generators/codeforces.py +++ b/generators/codeforces.py @@ -1,6 +1,7 @@ -"""Problems inspired by [codeforces](https://codeforces.com).""" +"""Problems inspired by the popular programming competition site [codeforces.com](https://codeforces.com)""" +# TODO: add tags -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -25,10 +26,8 @@ def sol(n): return n % 2 == 0 def gen(self, target_num_instances): - n = 0 - while len(self.instances) < target_num_instances: + for n in range(target_num_instances): self.add(dict(n=n)) - n += 1 class Abbreviate(PuzzleGenerator): @@ -128,10 +127,10 @@ def sol(scores, k): return sum(s >= threshold for s in scores) def gen_random(self): - n = min(len(self.instances) + 1, 100) + n = self.random.randrange(1, 50) max_score = self.random.randrange(50) scores = sorted([self.random.randrange(max_score + 1) for _ in range(n)], reverse=True) - k = self.random.randrange(len(scores)) + k = self.random.randrange(n) self.add(dict(scores=scores, k=k)) @@ -328,7 +327,7 @@ def sol(matrix, max_moves): def gen(self, target_num_instances): for i in range(5): for j in range(5): - if len(self.instances) == target_num_instances: + if self.num_generated_so_far() == target_num_instances: return matrix = [[0] * 5 for _ in range(5)] matrix[i][j] = 1 @@ -339,7 +338,6 @@ def gen(self, target_num_instances): class SortPlusPlus(PuzzleGenerator): """Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)""" - @staticmethod def sat(s: str, inp="1+1+3+1+3+2+2+1+3+1+2"): """Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3""" @@ -401,7 +399,8 @@ def sat(t: str, s="abbbcabbac", target=7): return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1)) @staticmethod - def sol(s, target): # target is ignored + def sol(s, target): + # target is ignored return s[:1] + "".join([b for a, b in zip(s, s[1:]) if b != a]) def gen_random(self): @@ -656,7 +655,7 @@ class Sssuubbstriiingg(PuzzleGenerator): """Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)""" @staticmethod - def sat(inds: List[int], string="Sssuubbstriiingg"): + def sat(inds: List[int], string="Sssuubbstrissiingg"): """Find increasing indices to make the substring "substring""" return inds == sorted(inds) and "".join(string[i] for i in inds) == "substring" @@ -725,7 +724,7 @@ class Moving0s(PuzzleGenerator): @staticmethod def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4): """ - Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence + Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence is achieved. """ s = seq[:] # copy @@ -952,7 +951,7 @@ def sol(target): def gen(self, target_num_instances): target = 0 - while len(self.instances) < target_num_instances: + while self.num_generated_so_far() < target_num_instances: self.add(dict(target=target)) target += 1 @@ -1263,5 +1262,140 @@ def gen_random(self): self.add(dict(target=target, upper=upper)) +class BillSums(PuzzleGenerator): + """Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A) + + We make it much harder when the denominations are non-American so the greedy algorithm doesn't work. + """ + + @staticmethod + def sat(bills: List[int], denominations=[1, 25, 35, 84], n=980, max_len=14): + """ + Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations + """ + return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len + + @staticmethod + def sol(denominations, n, max_len): + """ + This solution uses dynamic programming, I believe it could be further sped up without having to count + all the way up to denominations. + """ + denominations = sorted(set(denominations)) # remove duplicates + seqs = [[0 for _ in denominations] +[0]] # vectors + for i in range(1, n + 1): + _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i) + s = seqs[i - k] + seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1]) + + return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)] + + @staticmethod + def greedy_len(denominations, n): + ans = 0 + while n > 0: + n -= max([d for d in denominations if d <= n]) + ans += 1 + return ans + + def add_with_max_len(self, denominations, n): + max_len = len(self.sol(denominations, n, None)) + delta = self.greedy_len(denominations, n) - max_len + self.add(dict(denominations=denominations, n=n, max_len=max_len)) + + def gen(self, target_num_instances): + self.add_with_max_len([1, 5, 7, 11], 29377) + self.add_with_max_len([1, 44, 69], 727) + self.add_with_max_len([1, 25, 29], 537) + + def gen_random(self): + denom_set = {self.random.randrange(2, self.random.choice([10, 100])) for _ in range(self.random.randrange(10))} + denominations = [1] + sorted(denom_set) + n = self.random.randrange(1000) + self.add_with_max_len(denominations, n) + + +class BoxVolume(PuzzleGenerator): + """(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A) + + We make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work. + """ + + @staticmethod + def sat(sides: List[int], options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13): + """ + Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n, + where each side length is in options + """ + prod = 1 + for b in sides: + prod *= b + return prod == n and set(sides) <= set(options) and len(sides) <= max_dim + + @staticmethod + def sol(options, n, max_dim): + options = sorted(set(options)) + base = options[0] + logs = [] + for i in options + [n]: + j = 1 + log = 0 + while j < i: + log +=1 + j *= base + assert j == i, "All numbers must be a power of the smallest number" + logs.append(log) + denominations, n = logs[:-1], logs[-1] + + seqs = [[0 for _ in denominations] +[0]] # vectors + for i in range(1, n + 1): + _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i) + s = seqs[i - k] + seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1]) + + return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)] + + @staticmethod + def greedy_len(options, n): + options = sorted(set(options)) + base = options[0] + logs = [] + for i in options + [n]: + j = 1 + log = 0 + while j < i: + log +=1 + j *= base + assert j == i, "All numbers must be a power of the smallest number" + logs.append(log) + denominations, n = logs[:-1], logs[-1] + + ans = 0 + while n > 0: + n -= max([d for d in denominations if d <= n]) + ans += 1 + return ans + + def add_with_max_dim(self, options, n): + max_dim = len(self.sol(options, n, None)) + delta = self.greedy_len(options, n) - max_dim + self.add(dict(options=options, n=n, max_dim=max_dim)) + + def gen(self, target_num_instances): + self.add_with_max_dim([2**1, 2**5, 2**7, 2**11], 2**29377) + self.add_with_max_dim([5**1, 5**44, 5**69], 5**727) + self.add_with_max_dim([7**1, 7**25, 7**29], 7**537) + + def gen_random(self): + base = self.random.choice([2,3, 5, 7]) + n = base ** self.random.randrange(500) + if n < 10**100: + denom_set = {self.random.randrange(2, self.random.choice([10, 20])) for _ in range(self.random.randrange(6))} + denominations = [1] + sorted(denom_set) + options = [base**d for d in denominations] + + self.add_with_max_dim(options, n) + + if __name__ == "__main__": PuzzleGenerator.debug_problems() diff --git a/generators/compression.py b/generators/compression.py index b85b2e6..812dc65 100644 --- a/generators/compression.py +++ b/generators/compression.py @@ -1,6 +1,6 @@ """Puzzles relating to de/compression.""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -42,6 +42,9 @@ class LZW(PuzzleGenerator): so the solution is the *compression* algorithm. """ + tags = [Tags.strings, Tags.famous] + + # _compress_LZW("Hellooooooooooooooooooooo world!") is length-17 @staticmethod @@ -58,7 +61,8 @@ def sat(seq: List[int], compressed_len=17, text="Hellooooooooooooooooooooo world return "".join(pieces) == text and len(seq) <= compressed_len @staticmethod - def sol(compressed_len, text): # compressed_len is ignored + def sol(compressed_len, text): + # compressed_len is ignored index = {chr(i): i for i in range(256)} seq = [] buffer = "" @@ -84,52 +88,52 @@ def gen_random(self): text = self.random.pseudo_word(0, max_len) self.add({"text": text, "compressed_len": len(_compress_LZW(text))}) - -class LZW_decompress(PuzzleGenerator): - """We have provided a simple version of the - [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) - and the solution is the *decompression* algorithm. - """ - - @staticmethod - def sat(text: str, seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]): - """ - Find a string that compresses to the target sequence for the provided implementation of the - Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch - """ - index = {chr(i): i for i in range(256)} - seq2 = [] - buffer = "" - for c in text: - if buffer + c in index: - buffer += c - continue - seq2.append(index[buffer]) - index[buffer + c] = len(index) + 1 - buffer = c - - if text != "": - seq2.append(index[buffer]) - - return seq2 == seq - - @staticmethod - def sol(seq): - index = [chr(i) for i in range(256)] - pieces = [""] - for i in seq: - pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i]) - index.append(pieces[-2] + pieces[-1][0]) - return "".join(pieces) - - def gen(self, _target_num_instances): - for s in ['', 'a', 'b' * 1000, 'ab' * 1000 + '!']: - self.add({"seq": _compress_LZW(s)}) - - def gen_random(self): - max_len = self.random.choice([10, 100, 1000]) - text = self.random.pseudo_word(0, max_len) - self.add({"seq": _compress_LZW(text)}) +# Removed this puzzle because the puzzle statement would give away the solution to LZW, haha! +# class LZW_decompress(PuzzleGenerator): +# """We have provided a simple version of the +# [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) +# and the solution is the *decompression* algorithm. +# """ +# +# @staticmethod +# def sat(text: str, seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]): +# """ +# Find a string that compresses to the target sequence for the provided implementation of the +# Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch +# """ +# index = {chr(i): i for i in range(256)} +# seq2 = [] +# buffer = "" +# for c in text: +# if buffer + c in index: +# buffer += c +# continue +# seq2.append(index[buffer]) +# index[buffer + c] = len(index) + 1 +# buffer = c +# +# if text != "": +# seq2.append(index[buffer]) +# +# return seq2 == seq +# +# @staticmethod +# def sol(seq): +# index = [chr(i) for i in range(256)] +# pieces = [""] +# for i in seq: +# pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i]) +# index.append(pieces[-2] + pieces[-1][0]) +# return "".join(pieces) +# +# def gen(self, _target_num_instances): +# for s in ['', 'a', 'b' * 1000, 'ab' * 1000 + '!']: +# self.add({"seq": _compress_LZW(s)}) +# +# def gen_random(self): +# max_len = self.random.choice([10, 100, 1000]) +# text = self.random.pseudo_word(0, max_len) +# self.add({"seq": _compress_LZW(text)}) class PackingHam(PuzzleGenerator): @@ -138,6 +142,8 @@ class PackingHam(PuzzleGenerator): in coding theory. """ + tags = [Tags.strings, Tags.famous] + @staticmethod def sat(words: List[str], num=100, bits=100, dist=34): """Pack a certain number of binary strings so that they have a minimum hamming distance between each other.""" diff --git a/generators/conways_game_of_life.py b/generators/conways_game_of_life.py index 53f6465..ebeacee 100644 --- a/generators/conways_game_of_life.py +++ b/generators/conways_game_of_life.py @@ -1,6 +1,6 @@ """Conway's Game of Life problems (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -17,6 +17,8 @@ class Oscillators(PuzzleGenerator): in Wikipedia article on Cellular Automaton Oscillators. """ + tags = [Tags.games, Tags.famous] + @staticmethod def sat(init: List[List[int]], period=3): """ @@ -34,7 +36,8 @@ def sat(init: List[List[int]], period=3): return t + 1 == period @staticmethod - def sol(period): # generate random patterns, slow solution + def sol(period): + # # generate random patterns, slow solution # def viz(live): # if not live: # return @@ -83,6 +86,8 @@ def gen(self, target_num_instances): class ReverseLifeStep(PuzzleGenerator): """Unsolvable for "Garden of Eden" positions, but we only generate solvable examples""" + tags = [Tags.games, Tags.famous] + @staticmethod def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]): """ @@ -96,7 +101,8 @@ def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]): return next_step == {x + y * 1j for x, y in target} @staticmethod - def sol(target): # fixed-temperature MC optimization + def sol(target): + # fixed-temperature MC optimization TEMP = 0.05 import random rand = random.Random(0) # set seed but don't interfere with other random uses @@ -130,7 +136,7 @@ def gen_random(self): next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} target = sorted([[int(z.real), int(z.imag)] for z in next_step]) - self.add(dict(target=target), test=len(self.instances) < 10) + self.add(dict(target=target), test=self.num_generated_so_far() < 10) ######################################################################################################################## @@ -144,6 +150,8 @@ class Spaceship(PuzzleGenerator): This is an *unsolved* problem for periods 33, 34.""" + tags = [Tags.games, Tags.famous] + @staticmethod def sat(init: List[List[int]], period=4): """ @@ -170,7 +178,8 @@ def sat(init: List[List[int]], period=4): # print("".join("X" if (i, j) in live else "," for j in range(n + 1))) # # - # def sol(): # generate random patterns, slow solution + # def sol(): + # # generate random patterns, slow solution # def viz(live): # if not live: # return diff --git a/generators/game_theory.py b/generators/game_theory.py deleted file mode 100644 index 403839a..0000000 --- a/generators/game_theory.py +++ /dev/null @@ -1,133 +0,0 @@ -""" -Hard problems from game theory. -""" - -from puzzle_generator import PuzzleGenerator -from typing import List - - -# See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles - - -class Nash(PuzzleGenerator): - """Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given - [bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be - PPAD-hard in general. However, the challenge is be much easier for an approximate - [eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.""" - - @staticmethod - def sat(strategies: List[List[float]], - A=[[-1., -3.], [0., -2.]], # P1's payoffs (prisoner dilemma example) - B=[[-1., 0.], [-3., -2.]], # P2's payoffs - eps=0.01): # error tolerance - """ - Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B. - For example, for the classic Prisoner dilemma: - A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]] - - """ - m, n = len(A), len(A[0]) - p, q = strategies - assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) - - @staticmethod - def sol(A, B, eps): - NUM_ATTEMPTS = 100 - - def sat(strategies: List[List[float]], A, B, eps): - m, n = len(A), len(A[0]) - p, q = strategies - assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) - - import random - r = random.Random(0) - dims = len(A), len(A[0]) - # possible speedup: remove dominated strategies - for _attempt in range(NUM_ATTEMPTS): - strategies = [] - for d in dims: - s = [max(0.0, r.random() - 0.5) for _ in range(d)] - tot = sum(s) + 1e-6 - for i in range(d): - s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0 - strategies.append(s) - if sat(strategies, A, B, eps): - return strategies - - def gen_random(self): - m = self.random.randrange(2, 10) - n = self.random.randrange(2, 10) - A, B = [[[self.random.random() for _i in range(m)] for _j in range(n)] for _k in range(2)] - eps = self.random.choice([0.5, 0.1, 0.01]) - solved = self.sol(A, B, eps) is not None - self.add(dict(A=A, B=B, eps=eps), test=solved) - - -class ZeroSum(PuzzleGenerator): - """Compute minimax optimal strategies for a given - [zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to - Linear Programming. Note that the provided instances are all quite easy---harder solutions could readily - be made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and - more efficient algorithms would be needed.""" - - @staticmethod - def sat(strategies: List[List[float]], A = [[0., -0.5, 1.], [0.75, 0., -1.], [-1., 0.4, 0.]], eps=0.01): - """ - Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps. - For example, rock paper scissors has - A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2 - """ - m, n = len(A), len(A[0]) - p, q = strategies - assert all(len(row) == n for row in A), "inputs are a matrix" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))) - - @staticmethod - def sol(A, eps): - MAX_ITER = 10**4 - m, n = len(A), len(A[0]) - a = [0 for _i in range(m)] - b = [0 for _j in range(n)] - - for count in range(1, MAX_ITER): - i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n))) - j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m))) - a[i_star] += 1 - b[j_star] += 1 - p = [x / (count + 1e-6) for x in a] - p[-1] = 1 - sum(p[:-1]) # rounding issues - q = [x / (count + 1e-6) for x in b] - q[-1] = 1 - sum(q[:-1]) # rounding issues - - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))): - return [p, q] - - def gen_random(self): - m = self.random.randrange(2, 10) - n = self.random.randrange(2, 10) - A = [[self.random.random() for _i in range(m)] for _j in range(n)] - eps = self.random.choice([0.5, 0.1, 0.01]) - test = self.sol(A, eps) is not None - self.add(dict(A=A, eps=eps), test=test) - - -if __name__ == "__main__": - PuzzleGenerator.debug_problems() diff --git a/generators/games.py b/generators/games.py index 3ec04a6..ba23cc4 100644 --- a/generators/games.py +++ b/generators/games.py @@ -1,8 +1,8 @@ """ -Solve some two-player games +Some two-player game problems and hard game theory problems """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -16,59 +16,90 @@ class Nim(PuzzleGenerator): Nim has an elegant theory for optimal play based on the xor of the bits in the heaps. Instead of writing a program that plays the game interactively (since interaction is not allowed), we require - them to determine the winning states. + them to determine winning states or beat a certain opponent. """ - value_multiplier = 10 # harder than most problems, worth more + skip_example = True # so we can add multiplier in gen method below + + tags = [Tags.games, Tags.famous] @staticmethod - def sat(cert: List[List[int]], heaps=[5, 9]): + def sat(moves: List[List[int]], initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]): """ - Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate, - in each turn removing one or more objects from a single non-empty heap. The player who takes the last object - wins. The initial board state is represented by heaps, a list of numbers of objects in each heap. - The optimal play is certified by a list of "winning leaves" which are themselves lists of heap sizes - that, with optimal play, are winning if you leave your opponent with those numbers of objects. + Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn + removing one or more objects from a single non-empty heap. The player who takes the last object wins. + - initial_state is list of numbers of objects in each heap + - moves is a list of your moves: [heap, number of objects to take] + - you play first """ - good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints - cache = {} - - def is_good_leave(h): - if h in cache: - return cache[h] - next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])] - conjecture = (h in good_leaves) - if conjecture: # check that it is a good leave - assert not any(is_good_leave(s) for s in next_states) - else: # check that it is a bad leave, only need to check one move - assert is_good_leave(next(s for s in next_states if s in good_leaves)) - cache[h] = conjecture - return conjecture + def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap + vals = sorted(state, reverse=True) + i_largest = state.index(vals[0]) # largest heap + state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie - init_leave = tuple(heaps) - return is_good_leave(init_leave) == (init_leave in good_leaves) + state = initial_state[:] # copy + for i, n in moves: + assert 0 < n <= state[i], "Illegal move" + state[i] -= n + if set(state) == {0}: + return True # you won! + assert any(state), "You lost!" + bot_move() @staticmethod - def sol(heaps): - import itertools + def sol(initial_state): + + state = initial_state[:] + moves = [] - def val(h): # return True if h is a good state to leave things in + def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap + vals = sorted(state, reverse=True) + i_largest = state.index(vals[0]) # largest heap + state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie + + def losing(h): # return True if h is a losing state xor = 0 for i in h: xor ^= i return xor == 0 - return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)] + def optimal_move(): + assert not losing(state) + for i in range(len(state)): + for n in range(1, state[i] + 1): + state[i] -= n + if losing(state): + moves.append([i, n]) + return + state[i] += n + assert False, "Shouldn't reach hear" + + while True: + optimal_move() + if max(state) == 0: + return moves + bot_move() + + def gen(self, target_num_instances): + self.add(self.get_example(), multiplier=10) def gen_random(self): + def losing(h): # return True if h is a losing state + xor = 0 + for i in h: + xor ^= i + return xor == 0 + num_heaps = self.random.randrange(10) - heaps = [self.random.randrange(10) for _ in range(num_heaps)] + initial_state = [self.random.randrange(10) for _ in range(num_heaps)] + if losing(initial_state): + return prod = 1 - for i in heaps: + for i in initial_state: prod *= i + 1 if prod < 10 ** 6: - self.add(dict(heaps=heaps)) + self.add(dict(initial_state=initial_state), multiplier=10 if prod > 1000 else 1) class Mastermind(PuzzleGenerator): @@ -79,7 +110,8 @@ class Mastermind(PuzzleGenerator): them to provide a provable winning game tree. """ - multiplier = 10 # hard puzzle, takes longer to test + skip_example = True # so we can add multiplier in gen method below + tags = [Tags.games, Tags.famous] @staticmethod def sat(transcripts: List[str], max_moves=10): @@ -89,18 +121,15 @@ def sat(transcripts: List[str], max_moves=10): A transcript is a string describing the game so far. It consists of rows separated by newlines. Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right and how many are right but in the wrong location. A sample transcript is as follows: - ``` AABB 11 ABCD 21 ABDC - ``` + This is the transcript as the game is in progress. The complete transcript might be: - ``` AABB 11 ABCD 21 ABDC 30 ABDE 40 - ``` A winning strategy is described by a list of transcripts to visit. The next guess can be determined from those partial transcripts. @@ -168,13 +197,15 @@ def max_ambiguity(guess): return transcripts def gen(self, target_num_instances): - for max_moves in [6, 8, 10]: - self.add(dict(max_moves=max_moves)) + for max_moves in [10, 8, 6]: + self.add(dict(max_moves=max_moves), multiplier=30 - 2 * max_moves) class TicTacToeX(PuzzleGenerator): """Since we don't have interaction, this problem asks for a full tie-guranteeing strategy.""" + tags = [Tags.games, Tags.famous] + @staticmethod def sat(good_boards: List[str]): """ @@ -212,7 +243,7 @@ def x_move(x, o): # returns True if x wins or ties, x's turn to move return False # O wins def o_move(x, o): # returns True if x wins or ties, x's turn to move - if win[x] or x | o == 511: # full board + if win[x] or x | o == 511: # full board return True for i in range(9): if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)): @@ -228,6 +259,8 @@ def o_move(x, o): # returns True if x wins or ties, x's turn to move class TicTacToeO(PuzzleGenerator): """Same as above but for 2nd player""" + tags = [Tags.games, Tags.famous] + @staticmethod def sat(good_boards: List[str]): """ @@ -242,7 +275,7 @@ def sat(good_boards: List[str]): win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move. - if o | x != 511: # complete board + if o | x != 511: # complete board o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0] return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9))) @@ -255,7 +288,7 @@ def sol(): good_boards = [] def x_move(x, o): # returns True if o wins or ties, x's turn to move - if win[o] or x | o == 511: # full board + if win[o] or x | o == 511: # full board return True for i in range(9): if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o): @@ -287,10 +320,139 @@ def sat(probs: List[float]): assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6 return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6 + tags = [Tags.games, Tags.famous] + @staticmethod def sol(): return [1 / 3] * 3 +class Nash(PuzzleGenerator): + """Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given + [bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be + PPAD-hard in general. However, the challenge is be much easier for an approximate + [eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.""" + + skip_example = True # so we can add multiplier in gen method below + + tags = [Tags.games, Tags.famous, Tags.math] + + @staticmethod + def sat(strategies: List[List[float]], A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01): + """ + Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B. + For example, for the classic Prisoner dilemma: + A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]] + + eps is the error tolerance + """ + m, n = len(A), len(A[0]) + p, q = strategies + assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) + + @staticmethod + def sol(A, B, eps): + NUM_ATTEMPTS = 10 ** 5 + + def sat(strategies: List[List[float]], A, B, eps): + m, n = len(A), len(A[0]) + p, q = strategies + assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) + + import random + r = random.Random(0) + dims = len(A), len(A[0]) + # possible speedup: remove dominated strategies + for _attempt in range(NUM_ATTEMPTS): + strategies = [] + for d in dims: + s = [max(0.0, r.random() - 0.5) for _ in range(d)] + tot = sum(s) + 1e-6 + for i in range(d): + s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0 + strategies.append(s) + if sat(strategies, A, B, eps): + return strategies + + def gen(self, target_num_instances): + self.add(self.get_example(), multiplier=5) + + def gen_random(self): + m = self.random.randrange(2, 10) + n = self.random.randrange(2, 10) + A, B = [[[self.random.random() for _i in range(m)] for _j in range(n)] for _k in range(2)] + eps = self.random.choice([0.5, 0.1, 0.01]) + solved = self.sol(A, B, eps) is not None + self.add(dict(A=A, B=B, eps=eps), test=solved, multiplier=5) + + +class ZeroSum(PuzzleGenerator): + """Compute minimax optimal strategies for a given + [zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to + Linear Programming. Note that the provided instances are all quite easy---harder solutions could readily + be made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and + more efficient algorithms would be needed.""" + + tags = [Tags.games, Tags.famous] + + @staticmethod + def sat(strategies: List[List[float]], A=[[0., -0.5, 1.], [0.75, 0., -1.], [-1., 0.4, 0.]], eps=0.01): + """ + Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps. + For example, rock paper scissors has + A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2 + """ + m, n = len(A), len(A[0]) + p, q = strategies + assert all(len(row) == n for row in A), "inputs are a matrix" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))) + + @staticmethod + def sol(A, eps): + MAX_ITER = 10 ** 4 + m, n = len(A), len(A[0]) + a = [0 for _i in range(m)] + b = [0 for _j in range(n)] + + for count in range(1, MAX_ITER): + i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n))) + j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m))) + a[i_star] += 1 + b[j_star] += 1 + p = [x / (count + 1e-6) for x in a] + p[-1] = 1 - sum(p[:-1]) # rounding issues + q = [x / (count + 1e-6) for x in b] + q[-1] = 1 - sum(q[:-1]) # rounding issues + + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))): + return [p, q] + + def gen_random(self): + m = self.random.randrange(2, 10) + n = self.random.randrange(2, 10) + A = [[self.random.random() for _i in range(m)] for _j in range(n)] + eps = self.random.choice([0.5, 0.1, 0.01]) + test = self.sol(A, eps) is not None + self.add(dict(A=A, eps=eps), test=test) + + if __name__ == "__main__": PuzzleGenerator.debug_problems() diff --git a/generators/graphs.py b/generators/graphs.py index 18312fa..7b89e2c 100644 --- a/generators/graphs.py +++ b/generators/graphs.py @@ -1,7 +1,7 @@ """Problems related to graphs such as Conway's 99 problem, finding [cliques](https://en.wikipedia.org/wiki/Clique_(graph_theory)) of various sizes, shortest path (Dijkstra) """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -116,7 +116,8 @@ def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [ return True @staticmethod - def sol(size, edges): # brute force (finds list in increasing order), but with a tiny bit of speedup + def sol(size, edges): + # brute force (finds list in increasing order), but with a tiny bit of speedup if size == 0: return [] from collections import defaultdict @@ -170,7 +171,8 @@ def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=1 return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound @staticmethod - def sol(weights, bound): # Dijkstra's algorithm (bound is ignored) + def sol(weights, bound): + # Dijkstra's algorithm (bound is ignored) u, v = 0, 1 # go from 0 to 1 import heapq queue = [(0, u, u)] # distance, node, trail @@ -226,7 +228,8 @@ def sat(path: List[int], return len(path) <= bound @staticmethod - def sol(edges, u, v, bound): # Dijkstra's algorithm + def sol(edges, u, v, bound): + # Dijkstra's algorithm import heapq from collections import defaultdict queue = [(0, u, u)] # distance, node, trail @@ -271,7 +274,7 @@ class AnyPath(PuzzleGenerator): """Any Path""" @staticmethod - def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]): + def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): """ Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.""" for i in range(len(path) - 1): assert [path[i], path[i + 1]] in edges @@ -300,7 +303,7 @@ def gen_random(self): class EvenPath(PuzzleGenerator): @staticmethod - def sat(path: List[int], edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]): + def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): """Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.""" assert path[0] == 0 and path[-1] == max(max(e) for e in edges) assert all([[a, b] in edges for a, b in zip(path, path[1:])]) @@ -331,7 +334,7 @@ class OddPath(PuzzleGenerator): """To make it even more different than EvenPath, we changed to go from node 0 to node *1*.""" @staticmethod - def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]): + def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]): """Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.""" return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])]) @@ -356,25 +359,39 @@ def gen_random(self): self.add(dict(edges=edges)) - class Zarankiewicz(PuzzleGenerator): """[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)""" + @staticmethod - def sat(edges: List[List[int]]): - """Find a bipartite graph with 4 vertices on each side, 13 edges, and no K_3,3 subgraph.""" - assert len(edges) == len({(a, b) for a, b in edges}) == 13 # 13 edges, no duplicates - assert all(i in range(4) for li in edges for i in li) # 4 nodes on each side - for i in range(4): - v = [m for m in range(4) if m != i] - for j in range(4): - u = [m for m in range(4) if m != j] - if all([m, n] in edges for m in v for n in u): - return False - return True + def sat(edges: List[List[int]], z=20, n=5, t=3): + """Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.""" + from itertools import combinations + edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency + assert len(edges) >= z + + return all( + any((a, b) not in edges for a in left for b in right) + for left in combinations(range(n), t) + for right in combinations(range(n), t) + ) @staticmethod - def sol(): - return [[i, j] for i in range(4) for j in range(4) if i != j or i == 0] + def sol(z, n, t): + from itertools import combinations + all_edges = [(a, b) for a in range(n) for b in range(n)] + for edges in combinations(all_edges, z): + edge_set = set(edges) + if all(any((a, b) not in edge_set for a in left for b in right) + for left in combinations(range(n), t) + for right in combinations(range(n), t)): + return [[a, b] for a, b in edges] + + def gen(self, target_num_instances): + if self.num_generated_so_far() < target_num_instances: + self.add(dict(z=26, n=6, t=3), test=False) + if self.num_generated_so_far() < target_num_instances: + self.add(dict(z=13, n=4, t=3)) + class GraphIsomorphism(PuzzleGenerator): """ @@ -395,7 +412,7 @@ class GraphIsomorphism(PuzzleGenerator): """ @staticmethod - def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]): + def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]): """ You are given two graphs which are permutations of one another and the goal is to find the permutation. Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers. @@ -403,7 +420,8 @@ def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2} @staticmethod - def sol(g1, g2): # exponentially slow + def sol(g1, g2): + # exponentially slow from itertools import permutations n = max(i for g in [g1, g2] for e in g for i in e) + 1 g1_set = {(i, j) for i, j in g1} @@ -422,12 +440,13 @@ def gen_random(self): g1 = [[i, j] for i, j in g1] g2 = [[pi[i], pi[j]] for i, j in g1] self.random.shuffle(g2) - self.add(dict(g1=g1, g2=g2), test=n < 10) # only test for small n + self.add(dict(g1=g1, g2=g2), test=n < 10) # only test for small n class ShortIntegerPath(PuzzleGenerator): """This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph defined by the integer pairs.""" + @staticmethod def sat(li: List[int]): """ diff --git a/generators/human_eval.py b/generators/human_eval.py index 408d227..181e6c0 100644 --- a/generators/human_eval.py +++ b/generators/human_eval.py @@ -3,17 +3,27 @@ [this](https://github.com/openai/human-eval/blob/fa06031e684fbe1ee429c7433809460c159b66ad/data/HumanEval.jsonl.gz) version released 7/7/21.""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List -HUMAN_EVAL_TAINT_DATE = [2021, 7, 7] +""" +Some came out especially nicely as puzzles: +ParenthesesPermutation, Derivative, Frac, HeronTriangle, RomanNumerals, ClosestPalindrome, WildSort, Intersperse, +SimplifyProductFraction, Fib4, DiffChars, RotateString, EvaluateOperators, Grader, TripleZeroSum, PrimeFib + +Some weren't such natural puzzles: +CircularShiftNum, ReplaceMe, MinSubArraySum, Buckets, OddEvenSum, FindStrangeSum, EvenSqure, StrongestExtension +HungryRabbits, ReverseCase, MatchBrackets, ListTotal, BelowThreshold, RemoveVowels + +In many cases, the original problem wasn't naturally a puzzle but it inspired a nice loosely-related puzzle: +ZobristCollision, EvenBetween, MinSquaredDeviation, Median +""" # See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles class FindCloseElements(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]): @@ -27,8 +37,8 @@ def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 1 [5.23, 5.28] """ a, b = pair - assert a in nums and b in nums - return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0}) + assert a in nums and b in nums and a != b + return abs(a - b) == min(x - y for x in nums for y in nums if x > y) @staticmethod def sol(nums): @@ -44,7 +54,6 @@ def gen_random(self): class SeparateParenGroups(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ls: List[str], combined='() (()) ((() () ())) (() )'): @@ -58,18 +67,10 @@ def sat(ls: List[str], combined='() (()) ((() () ())) (() )'): Sample Output: ['(())', '((()()()))', '(())', '()'] """ - assert ''.join(ls) == combined.replace(' ', '') - for s in ls: # check that s is not further divisible - depth = 0 - for c in s[:-1]: - if c == '(': - depth += 1 - else: - assert c == ')' - depth -= 1 - assert depth >= 1 - assert depth == 1 and s[-1] == ')' - return True + for s in ls: + assert s.count("(") == s.count(")") + assert all(s[:i].count("(") > s[:i].count(")") for i in range(1, len(s))) # s is not further divisible + return ''.join(ls) == combined.replace(' ', '') @staticmethod def sol(combined): @@ -103,7 +104,6 @@ def gen_random(self): class Frac(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(x: float, v=523.12892): @@ -129,87 +129,46 @@ def gen_random(self): class FirstNegCumulative(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(n: int, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): + def sat(firsts: List[int], balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]): """ Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance. Sample Input: - [12, -5, 3, -99, 14, 88, -99] - - Sample Output: - -89 - """ - total = 0 - for b in balances: - total += b - if total < 0: - return total == n - - @staticmethod - def sol(balances): - total = 0 - for b in balances: - total += b - if total < 0: - return total - assert False, "should not reach here" - - def gen_random(self): - length = self.random.randrange(1, 11) - while True: - balances = [self.random.randrange(-10 ** 10, 10 ** 10) for _ in range(length)] - if any(sum(balances[:i + 1]) < 0 for i in range(length)): - self.add(dict(balances=balances)) - return - - -class NegCumulative_Trivial(PuzzleGenerator): - """ - Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3 - (see also FirstNegCumulative above which is not as trivial) - This version is a more direct translation of the problem but it can of course - be solved trivially just by trying both neg=True and neg=False - """ - taint_date = HUMAN_EVAL_TAINT_DATE - - @staticmethod - def sat(neg: bool, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): - """ - Given a list of numbers which represent bank deposits and withdrawals, - determine if the cumulative sum is negative. - - Sample Input: - [12, -5, 3, -99, 14, 88, -99] + [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]] Sample Output: - True - """ - total = 0 - for b in balances: - total += b - if total < 0: - return neg == True - return neg == False + [-89, -1] + """ + for i, bals in enumerate(balances): + total = 0 + for b in bals: + total += b + if total < 0: + assert total == firsts[i] + break + return True @staticmethod def sol(balances): - total = 0 - for b in balances: - total += b - if total < 0: - return True - return False + firsts = [] + for bals in balances: + total = 0 + for b in bals: + total += b + if total < 0: + firsts.append(total) + break + return firsts def gen_random(self): - length = self.random.randrange(1, 11) - while True: - balances = [self.random.randrange(-10 ** 10, 10 ** 10) for _ in range(length)] - if any(sum(balances[:i + 1]) < 0 for i in range(length)): - self.add(dict(balances=balances)) - return + balances = [ + [self.random.randrange(-10 ** 10, 10 ** 10) for _ in range(self.random.randrange(1, 11))] + for _ in range(10) + ] + balances = [bals for bals in balances if any(sum(bals[:i + 1]) < 0 for i in range(len(bals)))] + self.add(dict(balances=balances)) class MinSquaredDeviation(PuzzleGenerator): @@ -224,7 +183,6 @@ class MinSquaredDeviation(PuzzleGenerator): We use 0.501 rather than 1/2 to deal with rounding errors. """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): @@ -237,7 +195,7 @@ def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): Sample Output: 17.14285 """ - return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums) + return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4 @staticmethod def sol(nums): @@ -245,17 +203,12 @@ def sol(nums): def gen_random(self): length = self.random.randrange(1, 11) - nums = [self.random.randrange(-10 ** 10, 10 ** 10) for _ in range(length)] + nums = [self.random.randrange(-100, 100) for _ in range(length)] self.add(dict(nums=nums)) class Intersperse(PuzzleGenerator): - """ - Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5 - - The one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)` - """ - taint_date = HUMAN_EVAL_TAINT_DATE + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5""" @staticmethod def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4): @@ -269,12 +222,7 @@ def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4): Sample Output: [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5] """ - assert len(li) == max(0, len(nums) * 2 - 1) - for i, n in enumerate(nums): - assert li[2 * i] == n - if i > 0: - assert li[2 * i - 1] == sep - return True + return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1) @staticmethod def sol(nums, sep): @@ -291,10 +239,9 @@ def gen_random(self): class DeepestParens(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(depths: List[int], parens='() (()) ((()()())) (())'): + def sat(depths: List[int], parens='() (()) ((()()())) (((((((())))))))'): """ Given a string consisting of groups of matched nested parentheses separated by parentheses, compute the depth of each group. @@ -358,7 +305,6 @@ def gen_group(): class FindContainers(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring='at'): @@ -395,7 +341,6 @@ def gen(): class SumProduct(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(nums: List[int], tot=14, prod=99): @@ -428,41 +373,8 @@ def gen_random(self): self.add(dict(tot=tot, prod=prod)) -class SumProduct_Trivial(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8""" - taint_date = HUMAN_EVAL_TAINT_DATE - - @staticmethod - def sat(sum_prod: List[int], nums=[1, 3, 2, -6, 19]): - """ - Find the sum and product of a list of numbers. - - Sample Input: - [2, 8, 2] - - Sample Output: - [12, 32] - """ - p = 1 - for n in nums: - p *= n - return sum_prod == [sum(nums), p] - - @staticmethod - def sol(nums): - p = 1 - for n in nums: - p *= n - return [sum(nums), p] - - def gen_random(self): - nums = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(1, 5))] - self.add(dict(nums=nums)) - - class RollingMax(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]): @@ -502,38 +414,8 @@ def gen_random(self): self.add(dict(nums=nums)) -class PalindromeStartingWith(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10""" - taint_date = HUMAN_EVAL_TAINT_DATE - - @staticmethod - def sat(ans: str, s="so easy", length=13): - """ - Find a palindrome of a given length starting with a given string. - - Sample Input: - "foo", 4 - - Sample Output: - "foof" - """ - return ans == ans[::-1] and len(ans) == length and ans.startswith(s) - - @staticmethod - def sol(s, length): - return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1] - - def gen_random(self): - part = "".join([self.random.choice("ab") for _ in range(self.random.randrange(20))]) - pal = part + self.random.choice([part, part[:-1]])[::-1] - n = self.random.randrange(len(pal) + 1) - s = pal[:n] - self.add(dict(s=s, length=len(pal))) - - class PalindromeContaining(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: str, s="so easy", length=20): @@ -576,7 +458,6 @@ def gen_random(self): class BinaryStrXOR(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(str_num: str, nums=["100011101100001", "100101100101110"]): @@ -606,7 +487,6 @@ def gen_random(self): # In the HumanEval dataset, tie breaking needs to be specified because each problem must have a unique answer class LongestStr(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: str, words=["these", "are", "some", "pretty", "long", "words"]): @@ -634,10 +514,9 @@ class CertifiedGCD(PuzzleGenerator): """ Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(ans: List[int], m=1408862, n=2113293): + def sat(ans: List[int], m=200004931, n=66679984): """ Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd @@ -682,7 +561,6 @@ def gen_random(self): class AllPrefixes(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(prefixes: List[str], s="donesezichethofalij"): @@ -708,7 +586,6 @@ def gen_random(self): class SpaceyRange(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: str, n=15): @@ -734,7 +611,6 @@ def gen_random(self): class DistinctChars(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: List[str], s='The quick brown fox jumps over the lazy dog!', n=28): @@ -765,7 +641,6 @@ def gen_random(self): class ParseMusic(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(beats: List[int], score="o o o| o| .| .| .| o| o| o o o| .|"): @@ -793,7 +668,6 @@ def gen_random(self): class OverlappingCount(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: List[int], s='Bananannanaannanaanananananana', sub='anan', count=7): @@ -827,7 +701,6 @@ def gen_random(self): class SortNumbers(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: str, s="six one four three two nine eight"): @@ -866,7 +739,6 @@ def gen_random(self): class FindClosePair(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]): @@ -908,7 +780,6 @@ def gen_random(self): class Rescale(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]): @@ -952,78 +823,80 @@ def gen_random(self): class FilterInts(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(indexes: List[int], li=["Hello", "5", "10", "bye"], num=2): + def sat(candidates: List[str], int_indices=[2, 4, 7, 9, 101]): """ - Find the indices of valid python integers in a list of strings + Find a list of strings where the only valid integers are at the given indices Sample input --- - ["18.5", "-1", "2+2", "7", "foo"] + [2, 4, 5] Sample output --- - [1, 3] - """ - [int(li[i]) for i in indexes] - return len(set(indexes)) >= num and min(indexes) >= 0 + ["cat", "2.7", "2", "", "3", "-17", "free"] + """ + for i in int_indices: + int(candidates[i]) + for i, s in enumerate(candidates): + if i not in int_indices: + try: + int(s) + return False + except ValueError: + pass + return True @staticmethod - def sol(li, num): - ans = [] - for i in range(len(li)): - try: - int(li[i]) - ans.append(i) - except: - pass + def sol(int_indices): + if not int_indices: + return [] + ans = [""] * (1 + max(abs(i) for i in int_indices)) + for i in int_indices: + ans[i] = "17" return ans def gen_random(self): - chars = "0123456789+-*'e. " - ans = [] - length = self.random.randrange(10) - for _ in range(length): - ans.append("".join(self.random.choice(chars) for i in range(self.random.randrange(10)))) + int_indices = [self.random.randrange(100) for _ in range(self.random.randrange(10))] + self.add(dict(int_indices=int_indices)) class StrLength(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(length: int, s="pneumonoultramicroscopicsilicovolcanoconiosis"): + def sat(lengths: List[int], strs=["pneumonoultramicroscopicsilicovolcanoconiosis", " ", "foo", "2.5"]): """ - Find the length of a non-empty string + Find the lengths of a list of non-empty strings Sample input --- - "foo" + ["foo", "bars"] Sample output --- - 3 + [3, 4] """ - try: - s[length] - except IndexError: - s[length - 1] - return True + for length, s in zip(lengths, strs): + try: + s[length] + return False + except IndexError: + s[length - 1] + return len(lengths) == len(strs) @staticmethod - def sol(s): - return len(s) + def sol(strs): + return [len(s) for s in strs] def gen_random(self): - s = self.random.string(min_len=1, max_len=50) - self.add(dict(s=s)) + strs = [self.random.string(min_len=1, max_len=50) for _ in range(10)] + self.add(dict(strs=strs)) class LargestDivisor(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(d: int, n=123456): @@ -1051,7 +924,6 @@ def gen_random(self): class PrimeFactorization(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(factors: List[int], n=123456, num_factors=8): @@ -1100,7 +972,6 @@ def gen_random(self): class Dedup(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]): @@ -1135,7 +1006,6 @@ def gen_random(self): class FlipCase(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(ans: str, s="FlIp ME!"): @@ -1164,7 +1034,6 @@ def gen_random(self): class CatStrings(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(cat: str, strings=["Will", "i", "am", "Now", "here"]): @@ -1197,7 +1066,6 @@ def gen_random(self): class FindExtensions(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix='do'): @@ -1233,7 +1101,6 @@ def gen(): class FindPositives(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]): @@ -1260,33 +1127,34 @@ def gen_random(self): self.add(dict(nums=nums)) -class FermatComposite(PuzzleGenerator): +class FermatComposites(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(certificate: int, n=1449): + def sat(certificates: List[int], nums=[1449, 14, 21, 105, 217]): """ - Find a Fermat composite certificate for a number n > 1 + Find Fermat composite certificates for a list of numbers > 1 Sample Input: - 1469 + [1469] Sample Output: - 3 # because (3 ** 1468) % 1469 != 1 + [3] # because (3 ** 1468) % 1469 != 1 """ - return pow(certificate, n - 1, n) > 1 + return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums) @staticmethod - def sol(n): - return next(i for i in range(2, n) if pow(i, n - 1, n) > 1) + def sol(nums): + return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums] def gen_random(self): - a, b = [self.random.randrange(3, 10 ** 5, 2) for _ in range(2)] - if not self.random.randrange(10): - a += 1 - n = a * b - self.add(dict(n=n)) + nums = [] + for _ in range(self.random.randrange(10)): + a, b = [self.random.randrange(3, 10 ** 5, 2) for _ in range(2)] + if not self.random.randrange(10): + a += 1 + nums.append(a * b) + self.add(dict(nums=nums)) class OddDegreePolynomialRoot(PuzzleGenerator): @@ -1295,7 +1163,6 @@ class OddDegreePolynomialRoot(PuzzleGenerator): Inspired by [HumanEval](https://github.com/openai/human-eval) \\#32 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(root: float, coeffs=[1, 2, 3, 17]): @@ -1341,7 +1208,6 @@ def gen_random(self): # slightly modified for convenience class TwoThirdsSorted(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]): @@ -1390,7 +1256,6 @@ def gen_random(self): class UniqueSorted(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]): @@ -1425,10 +1290,9 @@ def gen_random(self): class MaxInt(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 35, 35, 21, 18, 2, 60]): + def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]): """ Find the largest integer in a sequence @@ -1454,7 +1318,6 @@ def gen_random(self): class SevenElevenThirteen(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(li: List[List[int]], n=19723, lower=1000): @@ -1477,7 +1340,7 @@ def sol(n, lower): def gen(self, target_num_instances): lower = 0 n = 0 - while len(self.instances) < target_num_instances: + while self.num_generated_so_far() < target_num_instances: if n % 11 == 0 or n % 13 == 0: lower += str(n).count('7') n += 1 @@ -1488,7 +1351,6 @@ def gen(self, target_num_instances): # Since this human-eval problem #37 is very similar to TwoThirdsSorted #33, we use a different approach to sat class HalfSorted(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]): @@ -1525,13 +1387,18 @@ def gen_random(self): class ThreeCycle(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(s: str, target="Hello world"): """ Given a target string, find a string s such that when each group of three consecutive characters is cycled forward one character, you achieve the target string. + + Sample Input: + "This is a test" + + Sample Output: + 'hiT is aste st' """ def cycle3(trip): @@ -1557,12 +1424,17 @@ class PrimeFib(PuzzleGenerator): Ira Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(n: int, lower=123456): """ Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers. + + Sample Input: + 10 + + Sample Output: + 11 """ assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), "n must be a Fibonacci number" assert all(n % i for i in range(2, int(n ** 0.5) + 1)), "n must be prime" @@ -1582,26 +1454,40 @@ def gen_random(self): class TripleZeroSum(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40""" - taint_date = HUMAN_EVAL_TAINT_DATE + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40 + + Similar to but harder than PairZeroSum \#43. + + This is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem. + """ @staticmethod - def sat(inds: List[int], nums=[12, -10452, 18242, 10440]): + def sat(inds: List[int], nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]): """ Find the indices of three numbers that sum to 0 in a list. + + --- Example input --- + [1, 2, 4, -3, 5] + + --- Example output --- + [0, 1, 3] """ - return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0 + return len(inds) == 3 and sum(nums[i] for i in inds) == 0 @staticmethod def sol(nums): - assert len(nums) == 4 - n = sum(nums) - for i in range(4): - if nums[i] == n: - return [j for j in range(4) if j != i] + # \tilde{O}(n^2) algorithm + inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries + for i, n in enumerate(nums): + if inv[n] == i: + del inv[n] + if any((-m - n) in inv for m in nums[:i]): # found solution! + j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv) + k = inv[-m - n] + return sorted([i, j, k]) def gen_random(self): - nums = [self.random.randrange(-100, 100) for _ in range(3)] + nums = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(2, 10))] nums.append(-sum(nums[:2])) self.random.shuffle(nums) self.add(dict(nums=nums)) @@ -1609,13 +1495,18 @@ def gen_random(self): class NumPasses(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(count: int, n=981): """ Given n cars traveling East and n cars traveling West on a road, how many passings will there be? A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars. + + --Sample input-- + 2 + + --Sample output-- + 4 """ for i in range(n): for j in range(n): @@ -1637,12 +1528,17 @@ class ListInc(PuzzleGenerator): Inspired by [HumanEval](https://github.com/openai/human-eval) \\#42 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]): """ Decrement each element of new_list by 1 and check that it's old_list + + Sample Input: + [17, 15, 99] + + Sample Output: + [18, 16, 100] """ return [i - 1 for i in new_list] == old_list @@ -1658,16 +1554,23 @@ def gen_random(self): class PairZeroSum(PuzzleGenerator): """ Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43 + + Similar to TripleZeroSum \#40 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]): """ Find the indices of two numbers that sum to 0 in a list. + + Sample Input: + [1, -4, -4, 7, -3] + + Sample Output: + [1, 2] """ a, b = inds - return nums[a] + nums[b] == 0 + return nums[a] + nums[b] == 0 and a >= 0 and b >= 0 @staticmethod def sol(nums): @@ -1689,12 +1592,17 @@ class ChangeBase(PuzzleGenerator): """ Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(s: str, n=142, base=7): """ Write n in the given base as a string + + Sample Input: + n=23, base=12 + + Sample Output: + '1A' """ return int(s, base) == n @@ -1715,12 +1623,17 @@ def gen_random(self): class TriangleArea(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(height: int, area=1319098728582, base=45126): """ Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer. + + Sample Input: + area = 6, base = 3 + + Sample Output: + 4 """ return base * height == 2 * area @@ -1742,7 +1655,6 @@ class Fib4(PuzzleGenerator): Almost identical to problem 63 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(init: List[int], target=2021): @@ -1750,6 +1662,12 @@ def sat(init: List[int], target=2021): Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the given target number. + + Sample Input: + 0 + + Sample Output: + [0, 0, 0, 0] """ a, b, c, d = init for i in range(99): @@ -1771,16 +1689,22 @@ def gen_random(self): class Median(PuzzleGenerator): """ - One definition of the median is a number that minimizes the sum of absolute deviations. + One definition of the median is a number that minimizes the sum of absolute deviations. When there are an + even number of items, there is an interval of valid solutions. Inspired by [HumanEval](https://github.com/openai/human-eval) \\#47 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965): """ Find an integer that minimizes the sum of absolute deviations with respect to the given numbers. + + Sample Input: + [3, 6, 1, 2, 5, 4, 100], upper=105 + + Sample Output: + 4 """ dev = sum(n - x for n in nums) return dev <= upper @@ -1796,30 +1720,37 @@ def gen_random(self): self.add(dict(nums=nums, upper=upper)) -class Palindrome_Trivial(PuzzleGenerator): +class Palindrome(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod - def sat(p: bool, s="This problem is trivial but common"): + def sat(pals: List[bool], strs=["palindrome", "madamimadam", "", "foo", "eyes", "(-:-)"]): """ - Test whether the given string is a palindrome + Test whether the given strings are palindromes + + Sample Input: + ["aba", "no"] + + Sample Output: + [True, False] """ - return p == (s == s[::-1]) + return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs)) @staticmethod - def sol(s): - return s == s[::-1] + def sol(strs): + return [s == s[::-1] for s in strs] def gen_random(self): - s = self.random.pseudo_word() - s = self.random.choice([s, s + s[::-1], s[:-1] + s[::-1]]) - self.add(dict(s=s)) + strs = [] + for _ in range(self.random.randrange(10)): + s = self.random.pseudo_word() + strs.append(self.random.choice([s, s + s[::-1], s[:-1] + s[::-1]])) + + self.add(dict(strs=strs)) class LittleFermat(PuzzleGenerator): """Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#49""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): @@ -1827,6 +1758,12 @@ def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1 polynomial (mod p). Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p). + + Sample Input: + d=2, poly=[1, 0, 0, 1, 0] # 1 + x^3 + + Sample Output: + [1, 0, 1, 2, 0] # 1+ x^2 + 2x^3 because (1 + x^3)^2 = 1 + 2x^3 + x^6 and x^6 = x^2 (mod 5) """ p = len(poly) assert p > 2 and all(p % i for i in range(2, p)), "Hint: p is a prime > 2" @@ -1873,12 +1810,17 @@ def gen_random(self): class ShiftChars(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(orig: str, result="Hello, world!", shift=7): """ Find a string which, when each character is shifted (ascii incremented) by shift, gives the result. + + Sample Input: + result='very good', shift=-1 + + Sample Output: + 'wfsz!hppe' """ n = len(result) assert len(orig) == n @@ -1899,13 +1841,20 @@ def random_case_word(rand, **args): class RemoveVowels(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51""" - taint_date = HUMAN_EVAL_TAINT_DATE + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51 + + Related to FindVowels \\#54""" @staticmethod def sat(txt: str, text="Hello, world!"): """ Remove the vowels from the original string. + + Sample Input: + "very good" + + Sample Output: + 'vry gd' """ n = 0 for c in text: @@ -1926,12 +1875,17 @@ def gen_random(self): class BelowThreshold(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100): """ Find the indexes of numbers below a given threshold + + Sample Input: + nums=[4, 7, 11, 5], threshold=10 + + Sample Output: + [0, 1, 3] """ j = 0 for i, n in enumerate(nums): @@ -1953,12 +1907,17 @@ def gen_random(self): class ListTotal(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]): """ - Find the indexes of numbers below a given threshold + Find the number which when appended to the list makes the total 0 + + Sample Input: + [1, 2, 3] + + Sample Output: + -6 """ return sum(nums + [-n]) == 0 @@ -1974,12 +1933,17 @@ def gen_random(self): class DiffChars(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(c: str, a="the quick brown fox jumped over the lazy dog", b="how vexingly quick daft zebras jump"): """ Find a character in one string that is not in the other. + + Sample Input: + 'Do you like green eggs and ham?', 'I do not like green eggs and ham.' + + Sample Output: + 't' # or .?yI """ return (c in a) != (c in b) @@ -1996,12 +1960,17 @@ def gen_random(self): class Fibonacci(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(nums: List[int], n=1402): """ Find the first n Fibonacci numbers + + Sample Input: + 4 + + Sample Output: + [1, 1, 2, 3] """ return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2)) @@ -2019,12 +1988,17 @@ def gen_random(self): class MatchBrackets(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(matches: List[int], brackets="<<>><<<><>><<>>>"): """ Find the index of the matching brackets for each character in the string + + Sample Input: + "<><>" + + Sample Output: + [1, 0, 3, 2] """ for i in range(len(brackets)): j = matches[i] @@ -2061,12 +2035,17 @@ def gen_random(self): class Monotonic(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]): """ Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums + + Sample Input: + [1, 2, 5] + + Sample Output: + "increasing" """ if direction == "increasing": return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) @@ -2085,12 +2064,17 @@ def gen_random(self): class CommonNumbers(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]): """ Find numbers common to a and b + + Sample Input: + [1, 2, 3], [3, 4, 5] + + Sample Output: + [3] """ return all((i in common) == (i in a and i in b) for i in a + b + common) @@ -2109,12 +2093,17 @@ def gen_random(self): class LargestPrimeFactor(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(p: int, n=101076): """ Find the largest prime factor of n. + + Sample Input: + 125 + + Sample Output: + 5 """ def is_prime(m): @@ -2136,12 +2125,17 @@ def gen_random(self): class CumulativeSums(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(sums: List[int], n=104): """ Find the sums of the integers from 1 to n + + Sample Input: + 3 + + Sample Output: + [0, 1, 3, 6] """ return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0 @@ -2163,12 +2157,17 @@ class ParenDepth(PuzzleGenerator): Note that problems 61 and 56 are essentially the same """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(matches: List[int], parens="((())()(()()))(())"): """ Find the index of the matching parentheses for each character in the string + + Sample Input: + "()((()))" + + Sample Output: + [1, 0, 7, 6, 5, 4, 3, 2] """ for i, (j, c) in enumerate(zip(matches, parens)): assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j)) @@ -2202,13 +2201,21 @@ def gen_random(self): class Derivative(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62""" - taint_date = HUMAN_EVAL_TAINT_DATE + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62 + + This puzzle gives the raw definition of a derivative in terms of small changes in x. + """ @staticmethod def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]): """ Find the derivative of the given polynomial, with coefficients in order of increasing degree + + Sample Input: + [3, 4, 1] # 3 + 4x + x^2 + + Sample Output: + [2, 4] # 4 + 2x^2 """ def val(poly, x): @@ -2231,7 +2238,6 @@ class Fib3(PuzzleGenerator): Almost identical to problem 46 """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(init: List[int], target=124156): @@ -2239,6 +2245,12 @@ def sat(init: List[int], target=124156): Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous three. Given a target number, find an initial triple such that the 17th number in the sequence is the given target number. + + Sample Input: + 0 + + Sample Output: + [0, 0, 0] """ a, b, c = init for i in range(16): @@ -2259,39 +2271,51 @@ def gen_random(self): class FindVowels(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64""" - taint_date = HUMAN_EVAL_TAINT_DATE + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64 + + Very similar to RemoveVowels \\#51 + """ @staticmethod - def sat(vowels: str, text="Hello, world!"): + def sat(vowels: List[str], texts=["Hello, world!", "Goodbye, world!"]): """ - Find the vowels from the original string. + Find the vowels from each of the original texts (y counts as a vowel at the end of the word) + + Sample Input: + ["You can do it!", "CAT"] + + Sample Output: + ["ouaoi", "A"] """ - i = 0 - for j, c in enumerate(text): - if c.lower() in "aeiou" or c.lower() == 'y' and j == len(text) - 1: - assert vowels[i] == c - i += 1 - return i == len(vowels) + for v, t in zip(vowels, texts): + i = 0 + for j, c in enumerate(t): + if c.lower() in "aeiou" or c.lower() == 'y' and j == len(t) - 1: + assert v[i] == c + i += 1 + assert i == len(v) + return len(vowels) == len(texts) @staticmethod - def sol(text): - return "".join(c for c in text if c.lower() in "aeiou") + (text[-1] if text[-1].lower() == "y" else "") + def sol(texts): + return ["".join(c for c in text if c.lower() in "aeiou") + (text[-1] if text[-1].lower() == "y" else "") + for text in texts] def gen_random(self): - text = random_case_word(self.random) - self.add(dict(text=text)) + texts = [random_case_word(self.random) for _ in range(self.random.randrange(10))] + self.add(dict(texts=texts)) class CircularShiftNum(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(shifted: str, n=124582369835, shift=3): """ Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of digits of n, reverse the string. + + n=12345 shift=2 => '34512' """ if shift > len(str(n)): return n == int(shifted[::-1]) @@ -2312,12 +2336,17 @@ def gen_random(self): class CharSum(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(tot: int, s="Add ME uP AND YOU WILL GET A BIG NUMBER!"): """ Compute the sum of the ASCII values of the upper-case characters in the string. + + Sample Input: + ARt + + Sample Output: + 147 # = 65 + 82 """ for c in s: if c.isupper(): @@ -2335,12 +2364,13 @@ def gen_random(self): class MissingBananas(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(bananas: int, bowl="5024 apples and 12189 oranges", total=12491241): """ Determine how many bananas are necessary to reach a certain total amount of fruit + + bowl="3 apples and 4 oranges", total=12 => 5 """ bowl += f" and {bananas} bananas" return sum([int(s) for s in bowl.split() if s.isdigit()]) == total @@ -2360,18 +2390,23 @@ def gen_random(self): class SmallestEven(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]): """ Given an array of nums representing a branch on a binary tree, find the minimum even value and its index. In the case of a tie, return the smallest index. If there are no even numbers, the answer is []. + + Sample Input: + [1, 7, 4, 6, 10, 11, 14] + + Sample Output: + [4, 2] """ if val_index == []: return all(n % 2 == 1 for n in nums) v, i = val_index - assert v % 2 == 0 + assert v % 2 == 0 and nums[i] == v return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:]) @staticmethod @@ -2389,13 +2424,18 @@ def gen_random(self): class GreatestHIndex(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]): """ Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times. h = -1 if there is no such positive number. + + Sample Input: + [1, 2, 2, 3, 3, 3, 4, 4] + + Sample Output: + 3 """ for i in seq: assert not (i > 0 and i > h and seq.count(i) >= i) @@ -2410,23 +2450,23 @@ def gen_random(self): self.add(dict(seq=seq)) -class StrangeSort(PuzzleGenerator): +class WildSort(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]): """ Find the following strange sort of li: the first element is the smallest, the second is the largest of the remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc. + + Sample Input: + [1, 2, 7, 3, 4, 5, 6] + + Sample Output: + [1, 7, 2, 6, 3, 5, 4] """ - if len(li) < 2: - return strange == li - bounds = strange[:2] # lower, upper - for i, n in enumerate(strange): - assert bounds[0] <= n <= bounds[1] - bounds[i % 2] = n - return sorted(strange) == sorted(li) # permutation check + assert sorted(strange) == sorted(li), "Must be a permutation" + return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange)) @staticmethod def sol(li): @@ -2455,12 +2495,17 @@ class HeronTriangle(PuzzleGenerator): In our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates of a triangle with the given sides. If one knows the area, this is a straightforward calculation. """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]): """ Find the coordinates of a triangle with the given side lengths + + Sample Input: + [3.0, 4.0, 5.0 + + Sample Output: + [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]] """ assert len(coords) == 3 sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]] @@ -2485,13 +2530,16 @@ def gen_random(self): class InvestigateCrash(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100): """ An object will "fly" if its weights are a palindrome and sum to <= max_weight. The given object won't fly. You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big. + + weights=[77, 40], max_weight=100 => -1 + + weights=[1,2,3], max_weight=50 => 0 # because 1 != 3 """ if problem == -1: return sum(weights) > max_weight @@ -2516,13 +2564,18 @@ def gen_random(self): class ClosestPalindrome(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(pal: str, s="palindromordinals"): """ Find the closest palindrome - """ + + Sample Input: + "cat" + + Sample Output: + "tat" + """ assert pal == pal[::-1] and len(pal) == len(s) return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2 @@ -2540,12 +2593,17 @@ def gen_random(self): class NarrowerList(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(li: List[str], lists=[["this", "list", "is", "narrow"], ["I", "am", "shorter but wider"]]): """ Find the list that has fewer total characters (including repetitions) + + Sample Input: + [["sh", "ort"], ["longest"]] + + Sample Output: + [["sh", "ort"] """ width = sum(len(s) for s in li) for li2 in lists: @@ -2564,13 +2622,13 @@ def gen_random(self): class ThreePrimes(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#75""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(factors: List[List[int]]): """ Find all 247 integers <= 1000 that are the product of exactly three primes. Each integer should represented as the list of its three prime factors. + [[2, 2, 2], [2, 2, 3], [2, 2, 5], ... """ primes = set(range(2, 1000)) for n in range(2, 1000): @@ -2591,11 +2649,16 @@ def sol(): class IntegerLog(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849): - """Find an integer exponent x such that a^x = n""" + """Find an integer exponent x such that a^x = n + Sample Input: + a=2, n=1024 + + Sample Output: + x = 10 + """ return a ** x == n @staticmethod @@ -2618,15 +2681,22 @@ class CubeRoot(PuzzleGenerator): We made it harder by giving very large n for which `round(n ** (1/3))` """ - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(x: int, n=42714774173606970182754018064350848294149432972747296768): - """Find an integer that when cubed is n""" + """Find an integer that when cubed is n + + Sample Input: + 21 + + Sample Output: + 3 + """ return x ** 3 == n @staticmethod - def sol(n): # Using Newton's method + def sol(n): + # Using Newton's method m = abs(n) x = round(abs(n) ** (1 / 3)) while x ** 3 != m: @@ -2641,11 +2711,17 @@ def gen_random(self): class HexPrimes(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(primes: List[bool], n="A4D4455214122CE192CCBE3"): - """Determine which characters of a hexidecimal correspond to prime numbers""" + """Determine which characters of a hexidecimal correspond to prime numbers + + Sample Input: + "123ABCD" + + Sample Output: + [False, True, True, False, True, False True] + """ return all(primes[i] == (c in "2357BD") for i, c in enumerate(n)) @staticmethod @@ -2660,11 +2736,16 @@ def gen_random(self): class Binarize(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(b: str, n=5324680297138495285): - """Write n base 2 followed and preceded by 'bits'""" + """Write n base 2 followed and preceded by 'bits' + Sample Input: + 2 + + Sample Output: + bits10bits + """ assert b[:4] == b[-4:] == 'bits' inside = b[4:-4] assert all(c in "01" for c in inside) @@ -2687,11 +2768,16 @@ def gen_random(self): class NearbyDuplicates(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(indices: List[int], s="I am an unhappy string!"): - """A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.""" + """A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy. + Sample Input: + "street" + + Sample Output: + [3, 4] + """ i, j = indices return s[i] == s[j] and 0 <= i < j < i + 3 @@ -2711,7 +2797,6 @@ def gen_random(self): class Grader(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]): @@ -2759,11 +2844,16 @@ def gen_random(self): class FactorString(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(factor: str, s="catscatcatscatcatscat"): - """Find a string which when repeated more than once gives s""" + """Find a string which when repeated more than once gives s + Sample Input: + "haha" + + Sample Output: + "ha" + """ return len(factor) < len(s) and s == factor * (len(s) // len(factor)) @staticmethod @@ -2778,11 +2868,12 @@ def gen_random(self): class OneEnded(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#83""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(nums: List[int], n=5): - """Find all n-digit integers that start or end with 1""" + """Find all n-digit integers that start or end with 1 + + 1 => [1]""" count = 18 * (10 ** (n - 2)) if n > 1 else 1 strs = {str(n) for n in nums} return len(strs) == count and all(s.startswith("1") or s.endswith("1") and len(s) == n for s in strs) @@ -2801,11 +2892,13 @@ def sol(n): class BitSum(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(n: int, b=107, s=25): - """Find an b-bit integer with a bit-sum of s""" + """Find an b-bit integer with a bit-sum of s + + b=3, s=2 => 5 # 5 is 101 in binary + """ n_str = bin(n)[2:] # n in binary return len(n_str) == b and sum(int(i) for i in n_str) == s @@ -2819,32 +2912,18 @@ def gen_random(self): self.add(dict(b=b, s=s)) -class DigitSum(PuzzleGenerator): - """*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84""" - taint_date = HUMAN_EVAL_TAINT_DATE - - @staticmethod - def sat(s: str, n=1012552981257923): - """Find the sum of the digits in n as a binary string""" - tot = int(s, 2) - return tot == sum(int(c) for c in str(n)) - - @staticmethod - def sol(n): - return bin(sum(int(c) for c in str(n)))[2:] - - def gen_random(self): - n = self.random.randrange(10 ** self.random.randrange(50)) - self.add(dict(n=n)) - +class EvenOddSum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85 -class EvenOdd(PuzzleGenerator): - """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85""" - taint_date = HUMAN_EVAL_TAINT_DATE + Very similar to OddEvenSum \#121 + """ @staticmethod def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]): - """Find the sum of the even elements that are at odd indices""" + """Find the sum of the even elements that are at odd indices + + [1, 2, 8, 3, 9, 4] => 6 + """ for i in nums[1::2]: if i % 2 == 0: even_odd_sum -= i @@ -2861,11 +2940,16 @@ def gen_random(self): class AntiShuffle(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(s: str, orig="Hello world!!!"): - """Create a new string by taking s, and word by word rearranging its characters in ascii order""" + """Create a new string by taking s, and word by word rearranging its characters in ascii order + Sample input: + 'maltos wow' + + Sample output: + 'almost oww' + """ for a, b in zip(s.split(' '), orig.split(' ')): for i in range(len(a) - 1): assert a[i] <= a[i + 1], "characters must s-words be in increasing order" @@ -2876,11 +2960,10 @@ def sat(s: str, orig="Hello world!!!"): def sol(orig): return " ".join("".join(sorted(w)) for w in orig.split(' ')) - tests = [ - dict(orig="YOU CAN rearrange my letters, yes you can!"), - dict(orig="caN you handlE LONGGGGGGGGGGGG strings?"), - dict(orig="how bout spaces and weird punctuation!?$%@#%") - ] + def gen(self, target_num_instances): + self.add(dict(orig="YOU CAN rearrange my letters, yes you can!")) + self.add(dict(orig="caN you handlE LONGGGGGGGGGGGG strings?")) + self.add(dict(orig="how bout spaces and weird punctuation!?$%@#%")) def gen_random(self): orig = " ".join(self.random.pseudo_word() for _ in range(self.random.randrange(5))) @@ -2889,11 +2972,16 @@ def gen_random(self): class UnevenFind(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17): - """Find the indices of all occurrences of target in the uneven matrix""" + """Find the indices of all occurrences of target in the uneven matrix + Sample input: + uneven=[[2, 3, 2], [], [9, 2]], target=2 + + Sample output: + [[0, 0], [0, 2], [2, 1]] + """ for i, j in indices: assert uneven[i][j] == target for i, row in enumerate(uneven): @@ -2914,11 +3002,23 @@ def gen_random(self): class UpDownSort(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#88""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]): - """Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd""" + """Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd + + Sample input: + [1, 7, 4] + + Sample output: + [1, 4, 7] # because 1 + 4 is odd + + Sample input: + [1, 7, 5] + + Sample output: + [8, 5, 1] # because 1 + 5 is even + """ assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), "not a reordering" increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1 return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1)) @@ -2930,11 +3030,13 @@ def sol(nums): class SubstitutionCypher(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(encrypted: str, orig="Hello, world!"): - """Apply a substitution cypher in which each character is advanced by two multiplied by two places.""" + """Apply a substitution cypher in which each character is advanced by two multiplied by two places. + + 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv' + """ assert len(encrypted) == len(orig) return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig)) @@ -2949,11 +3051,17 @@ def gen_random(self): class SecondSmallestUnique(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]): - """Find the second smallest unique number in the list nums.""" + """Find the second smallest unique number in the list nums. + + Sample input: + [2, 5, 2, 7, 9] + + Sample output: + 5 + """ assert n in nums return len({i for i in nums if i <= n}) == 2 @@ -2969,11 +3077,18 @@ def gen_random(self): class FindBored(PuzzleGenerator): """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91""" - taint_date = HUMAN_EVAL_TAINT_DATE @staticmethod def sat(boring: List[str], text="This is not boring. I am boring! I am sooo tired."): - """A bored sentence starts with the word "I". Find all bored sentences in s. Sentence delimiters are '.!?'""" + """A bored sentence starts with the word "I". Find all bored sentences in s. Sentence delimiters are '.!?' + + --- Example input --- + 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.' + + --- Example output --- + ['I wrote this', ' I think I am so cool'] + + """ sentences = text.replace("!", ".").replace("?", ".").split(".") boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != ["I"]] return sorted(boring_and_exciting) == sorted(sentences) @@ -2991,5 +3106,2352 @@ def gen_random(self): self.add(dict(text=text)) +class IdentifyZeroTrips(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92""" + + @staticmethod + def sat(zero_sums: List[bool], trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]): + """Determine which triples sum to zero + + --- Example input --- + [1, 2, 4, -3, 5] + + --- Example output --- + [0, 1, 3] + """ + return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips)) + + @staticmethod + def sol(trips): + return [sum(t) == 0 for t in trips] + + def gen_random(self): + trips = [[self.random.randrange(-10, 11) for _ in range(3)] for _ in range(self.random.randrange(2, 20))] + for t in trips: + if self.random.randrange(2): + t[-1] = t[0] + t[1] + self.add(dict(trips=trips)) + + +class WeirdDecodeVowels(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93""" + + @staticmethod + def sat(s: str, target="Hello, world!"): + """Find string s that, when case is flipped gives target where vowels are replaced by chars two later. + --- Example input --- + 'THIS is a TEST' + + --- Example output --- + 'thks KS C tgst' + """ + subs = {ord(c): ord(c) + 2 for c in "aeiouAEIOU"} + return s.swapcase() == target.translate(subs) + + @staticmethod + def sol(target): + subs = {ord(c): ord(c) + 2 for c in "aeiouAEIOU"} + return target.translate(subs).swapcase() + + def gen(self, target_num_instances): + self.add(dict(target="This is a good test")) + self.add(dict(target="")) + self.add(dict(target="That last test was a bad test!")) + self.add(dict(target="pneumonoultramicroscopicsilicovolanoconiosis")) + + def gen_random(self): + target = " ".join(self.random.pseudo_word() for _ in range(self.random.randrange(1, 4))) + self.add(dict(target=target)) + + +class LargestPrimeDigitSum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94""" + + @staticmethod + def sat(ans: List[int], nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]): + """Find the index of the largest prime in the list and the sum of its digits + + --- Example input --- + [2, 4, 7, 19, 21] + + --- Example output --- + [3, 10] + """ + i, digit_sum = ans + n = nums[i] + + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n)) + + @staticmethod + def sol(nums): + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n)) + return [i, sum(int(c) for c in str(n))] + + def gen_random(self): + nums = [self.random.randrange(1, 10 ** self.random.randrange(1, 8)) for _ in range(10)] + + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + if any(is_prime(n) for n in nums): + self.add(dict(nums=nums)) + + +class OddCase(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95""" + + @staticmethod + def sat(different: str, d={"cat": "CAT", "tree": "T", "pick me": "not", "OK": "red", "blah": "blah", "z": "Z"}): + """Find the dictionary key whose case is different than all other keys + + --- Example input --- + {"red": "", "GREEN": "", "blue": "orange"} + + --- Example output --- + "GREEN" + """ + return different in d and all(k.islower() != different.islower() for k in d if k != different) + + @staticmethod + def sol(d): + for different in d: + if all(k.islower() != different.islower() for k in d if k != different): + return different + + def gen_random(self): + mostly_upper = self.random.choice([True, False]) + trans = lambda x: (x.upper() if mostly_upper else x) + d = {trans(self.random.pseudo_word()): self.random.pseudo_word() for _ in range(10)} + mostly_upper = not mostly_upper + d[trans(self.random.pseudo_word())] = self.random.pseudo_word() + self.add(dict(d=d)) + + +class PrimesUpTo(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96""" + + @staticmethod + def sat(primes: List[int], n=1234): + """Find all primes up to n + + --- Example input --- + 9 + + --- Example output --- + [2, 3, 5, 7] + """ + assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p) + return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0) + + @staticmethod + def sol(n): + primes = [] + candidates = set(range(2, n)) + for i in range(2, n): + if i in candidates: + primes.append(i) + candidates.difference_update(range(i, n, i)) + return primes + + def gen(self, target_num_instances): + self.add(dict(n=10)) + self.add(dict(n=1000)) + self.add(dict(n=-1)) + self.add(dict(n=10000)) + + def gen_random(self): + n = self.random.randrange(20 * 1000) + self.add(dict(n=n)) + + +class UnitsProduct(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97""" + + @staticmethod + def sat(prod: int, nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]): + """Find the product of the units digits in the numbers + + [12, 34] => 8 + """ + if not all(nums): + return prod == 0 + for n in nums: + k = abs(n % 10) + if k == 0: + return prod == 0 + assert prod % k == 0 + prod //= k + return prod == 1 + + @staticmethod + def sol(nums): + prod = 1 + for n in nums: + prod *= abs(n % 10) + return prod + + def gen_random(self): + nums = [self.random.randrange(-100, 100) for _ in range(10)] + self.add(dict(nums=nums)) + + +class UppercaseEven(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98""" + + @staticmethod + def sat(positions: List[int], s="ThIs is A tEsT, Or *IS* iT?"): + """Find the positions of all uppercase vowels (not counting Y) in even indices + + "EAT here NOW" => [0, 10] + """ + assert all(s[i] in "AEIOU" for i in positions) + return all(i in positions or c not in "AEIOU" or i % 2 == 1 for i, c in enumerate(s)) + + @staticmethod + def sol(s): + return [i for i, c in enumerate(s) if i % 2 == 0 and c in "AEIOU"] + + def gen_random(self): + s = "".join([self.random.choice([c.lower(), c.upper()]) for c in self.random.pseudo_word()]) + self.add(dict(s=s)) + + +class ClosestInteger(PuzzleGenerator): + """ + Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99 + + Since we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule. + """ + + @staticmethod + def sat(n: int, x=329437923.5): + """Round to nearest integer + + --- input --- + 3.7 + + --- output --- + 4 + """ + return abs(n - x) <= 0.5 + + @staticmethod + def sol(x): + return round(x) + + def gen_random(self): + x = self.random.heavy_tail_float(lower=-1e20, upper=1e20, median_dev=1e6) + if self.random.randrange(10) == 0: + x = int(x) - 0.5 + self.add(dict(x=x)) + + +class StonePiles(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100""" + + @staticmethod + def sat(li: List[int], n=909): + """We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even + number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones + than the previous pile but as few as possible. Return the number of stones in each pile. + + 2 => [2, 4] + """ + return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:])) + + @staticmethod + def sol(n): + return [n + 2 * i for i in range(n)] + + def gen_random(self): + n = self.random.randrange(10 ** 5) + self.add(dict(n=n)) + + +class CompleteSplit(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101""" + + @staticmethod + def sat(splits: List[List[str]], string="Hello, world! You look like you're on turtles."): + """ + Split a string of words separated by commas and spaces into 2 lists: words and separators + + Sample input: "Hi there, Anna" + Sample output: [["Hi", "there", "Anna"], [" ", ", "]] + """ + words, separators = splits + assert len(words) == len(separators) + 1 + merged = [] + for w, s in zip(words, separators + [" "]): + assert s.count(" ") + s.count(",") == len(s) > 0 + assert w.count(" ") + w.count(",") == 0 + merged += [w, s] + return "".join(merged[:-1]) == string + + @staticmethod + def sol(string): + import re + merged = re.split(r"([ ,]+)", string) + return [merged[::2], merged[1::2]] + + def gen(self, target_num_instances): + self.add(dict(string=" This is a valley, so, so so,,,,")) + self.add(dict(string="")) + self.add(dict(string=" ,,,,, , , ")) + self.add(dict(string="Do not worry\nabout newlines\n!")) + + def gen_random(self): + string = "" + for _ in range(self.random.randrange(20)): + string += self.random.choice([" ", ",", ".", self.random.pseudo_word()]) + self.add(dict(string=string)) + + +class BiggestEven(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102""" + + @staticmethod + def sat(x: int, a=145, b=24126846790974): + """Return the biggest even number between a and b inclusive, or -1 if there is no such number + + Example input: + a=20, b=99 + + Example output: + 98 + """ + if x == -1: + return all(i % 2 == 1 for i in range(a, b + 1)) + return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1)) + + @staticmethod + def sol(a, b): + if a > b or (a == b and a % 2 == 1): + return -1 + return b if b % 2 == 0 else b - 1 + + def gen(self, target_num_instances): + self.add(dict(a=17, b=17)) + self.add(dict(a=-10, b=-6)) + self.add(dict(a=100, b=84)) + self.add(dict(a=0, b=323523571223)) + + def gen_random(self): + a = self.random.randrange(10 ** self.random.randrange(10)) + b = self.random.randrange(10 ** self.random.randrange(10)) + self.add(dict(a=a, b=b)) + + +class BinaryAverage(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103""" + + @staticmethod + def sat(s: str, a=-103252, b=10657): + """Return the average of the numbers a through b rounded to nearest integer, in binary + (or -1 if there are no such numbers) + + a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary + """ + n = int(s, 2) + r = range(a, b) + if len(r) == 0: + return n == -1 + mu = sum(r) / len(r) + return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1)) + + @staticmethod + def sol(a, b): + r = range(a, b) + if len(r) == 0: + return "-1" + return bin(round(sum(r) / len(r))) + + def gen(self, target_num_instances): + self.add(dict(a=70421, b=70421)) + self.add(dict(a=-10299, b=-10300)) + + def gen_random(self): + a = self.random.choice([-1, 1]) * self.random.randrange(10 ** self.random.randrange(5)) + b = self.random.randrange(10 ** self.random.randrange(6)) + self.add(dict(a=a, b=b)) + + +class SortedOdds(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104""" + + @staticmethod + def sat(sub: List[int], nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]): + """Find the sublist of numbers with only odd digits in increasing order + + [17, 21, 18, 1, 4] => [1, 17, 21] + """ + for i in range(len(sub)): + n = sub[i] + assert n == min(sub[i:]) + assert all(int(c) % 2 for c in str(abs(n))) # all odd digits + assert sub.count(n) == nums.count(n) + + for n in nums: + if n not in sub: + assert any(int(c) % 2 == 0 for c in str(abs(n))) + + return True + + @staticmethod + def sol(nums): + return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n)))) + + def gen_random(self): + nums = [self.random.randrange(-10 ** self.random.randrange(8), 10 ** self.random.randrange(8)) + for _ in range(self.random.randrange(20))] + self.add(dict(nums=nums)) + + +class BackwardsDigits(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105""" + + @staticmethod + def sat(backwards_digits: List[str], nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]): + """Return the single digits in nums sorted backwards and converted to English words + + [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two'] + """ + digits = {"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9} + li = [digits[s] for s in backwards_digits] + for i, n in enumerate(li): + assert n == max(li[i: i + 2]) + assert nums.count(n) == li.count(n) + + return all(n not in range(1, 10) or n in li for n in nums) + + @staticmethod + def sol(nums): + digits = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine"} + return [digits[n] for n in sorted(nums, reverse=True) if n in digits] + + def gen_random(self): + nums = [self.random.randrange(-5, self.random.choice([12, 100])) for _ in range(self.random.randrange(20))] + self.add(dict(nums=nums)) + + +class AlternatingFactorials(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106""" + + @staticmethod + def sat(li: List[int], n=100): + """Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m) + + 5 => [1, 2, 6, 9, 120] + """ + assert len(li) == n + for i, m in enumerate(li): + if i < 2: + assert m == i + 1 + elif i % 2 == 1: + assert m == li[i - 2] + i + (i + 1) + else: + assert m == li[i - 2] * i * (i + 1) + return True + + @staticmethod + def sol(n): + ans = [] + for i in range(n): + if i < 2: + m = i + 1 + elif i % 2 == 1: + m = ans[i - 2] + i + (i + 1) + else: + m = ans[i - 2] * i * (i + 1) + ans.append(m) + + return ans + + def gen_random(self): + n = self.random.randrange(1000) + self.add(dict(n=n)) + + +class EvenPalindromeNumbers(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107""" + + @staticmethod + def sat(pals: List[int], n=1099, count=49): + """Find all even palindromes up to n + + 3 => [0, 2] + """ + return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count + + @staticmethod + def sol(n, count): + return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]] + + def gen_random(self): + n = self.random.randrange(10 * 1000) + count = len(self.sol(n, -1)) + self.add(dict(n=n, count=count)) + + +class PositiveDigitSums(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108""" + + @staticmethod + def sat(pos: List[int], nums=[-804, 9124, -945, 2410, 0, 21, -123]): + """Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative. + + [12, -7, -102, -100] => [12, -102] + """ + for n in pos + nums: + s = str(n) + if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0: + assert n not in pos + else: + assert pos.count(n) == nums.count(n) + return True + + @staticmethod + def sol(nums): + def bad(n): + s = str(n) + return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0 + + return [n for n in nums if not bad(n)] + + def gen_random(self): + nums = [self.random.randrange(-10 ** 5, 5 * 10 ** 4) for _ in range(self.random.randrange(1, 10))] + self.add(dict(nums=nums)) + + +class RotateSort(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109 + + This puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r + """ + + @staticmethod + def sat(original: List[int], arr=[2, 3, -1, -1, 0, 1, 1]): + """ + An array is ring-sorted if it is a "rotation" of a non-decreasing list. + Remove at most one element from arr to make it ring-sorted. + + [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0] + """ + assert str(original)[1:-1] in str(sorted(original) * 2), "Not ring sorted" + return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1)) + + @staticmethod + def sol(arr): + def sat(near): + order_violations = 0 + erasures = 0 + for i, n in enumerate(near): + if n < near[i - 1]: # -1 when i =0 gives last element + order_violations += 1 + while n != arr[i + erasures]: + erasures += 1 + return order_violations <= 1 and erasures <= 1 + + candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))] + return next(near for near in candidates if sat(near)) + + def gen_random(self): + n = self.random.randrange(10) + original = sorted(self.random.randrange(10) for _ in range(n)) + i = self.random.randrange(n + 1) + arr = original[i:] + original[:i] + arr.insert(self.random.randrange(n + 1), self.random.randrange(10)) + self.add(dict(arr=arr)) + + +class ParityExchange(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110""" + + @staticmethod + def sat(swaps: List[List[int]], nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]): + """ + Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the + first list are even + + [1, 3, 4] [2, 4, 5] => [0, 1] + """ + copy1 = nums1[:] + copy2 = nums2[:] + for i, j in swaps: + copy1[i], copy2[j] = copy2[j], copy1[i] + return all(n % 2 == 0 for n in copy1) + + @staticmethod + def sol(nums1, nums2): + odds = [i for i, n in enumerate(nums1) if n % 2 == 1] + evens = [i for i, n in enumerate(nums2) if n % 2 == 0] + return [[i, j] for i, j in zip(odds, evens)] + + def gen_random(self): + nums1 = [self.random.randrange(-10, 10) for _ in range(self.random.randrange(10))] + nums2 = [self.random.randrange(-10, 10) for _ in range(self.random.randrange(10))] + if sum(n % 2 == 1 for i, n in enumerate(nums1)) <= sum(n % 2 == 0 for i, n in enumerate(nums2)): + self.add(dict(nums1=nums1, nums2=nums2)) + + +class CharCounts(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111""" + + @staticmethod + def sat(s: str, counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}): + """Find a string consisting of space-separated characters with given counts + + {"f": 1, "o": 2} => "oof" + """ + chars = s.split() + for c in chars: + assert chars.count(c) == counts[c] + return len(chars) == sum(counts.values()) + + @staticmethod + def sol(counts): + return " ".join(c for c, i in counts.items() for _ in range(i)) + + def gen_random(self): + alpha = "abcdefghijklmnopqrstuvwxyz" + counts = {self.random.choice(alpha): self.random.randrange(10) for _ in range(self.random.randrange(10))} + self.add(dict(counts=counts)) + + +class DelPalindrome(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112""" + + @staticmethod + def sat(strings: List[str], a="this is a test", b="cat"): + """ + Return a pair of a strings where the first string is the same as a with all the characters of b removed, + and the second string is 'True' if this string is a palindrome otherwise 'False'. + + a="madam, I'm adam." b = "Yes, we're here." => ['madamImadam', 'True'] + """ + s, is_palindrome = strings + i = 0 + for c in a: + if c not in b: + assert s[i] == c + i += 1 + assert i == len(s) + return is_palindrome == str(s == s[::-1]) + + @staticmethod + def sol(a, b): + s = "".join(c for c in a if c not in b) + return [s, str(s == s[::-1])] + + def gen_random(self): + a = self.random.pseudo_word(max_len=50) + b = self.random.pseudo_word(min_len=0) + self.add(dict(a=a, b=b)) + + +class ReplaceMe(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113""" + + @staticmethod + def sat(answers: List[str], lst=["234515", "21503", "2506236943"]): + """For each string in lst, count the number of odd digits. Find a string with no t's such that replacing + this number by t gives the string 'this is a test' + + ["123", "2"] => ["2his is a 2es2", "0his a 0es0"] + """ + if len(answers) != len(lst): + return False + for a, s in zip(answers, lst): + if "t" in a: + return False + num_odds = sum(int(i) % 2 for i in s) + if a.replace(str(num_odds), "t") != "this is a test": + return False + return True + + @staticmethod + def sol(lst): + return ["this is a test".replace("t", str(sum(c in "13579" for c in s))) for s in lst] + + def gen_random(self): + lst = [str(self.random.randrange(10 ** self.random.randrange(10))) for _ in range(self.random.randrange(10))] + self.add(dict(lst=lst)) + + +class MinSubArraySum(PuzzleGenerator): + """ + Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114 + + This is harder than \#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes + while the O(n) algorithm takes milliseconds. + """ + + @staticmethod + def sat(start_end: List[int], base=7, p=50741, upper=-4897754): + """Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end] + + base=3, p=7, upper =-3 => [0, 3] + # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ... + """ + start, end = start_end + return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper + + @staticmethod + def sol(base, p, upper): + tot = 0 + best_tot = 0 + best_end = 0 + best_start = 0 + largest_cumulative_sum = 0 + largest_cumulative_sum_index = 0 + + n = 1 + + for i in range(p + 1): + if tot > largest_cumulative_sum: + largest_cumulative_sum = tot + largest_cumulative_sum_index = i + if tot - largest_cumulative_sum < best_tot: + best_tot = tot - largest_cumulative_sum + best_start = largest_cumulative_sum_index + best_end = i + + tot += (n - p // 2) + n = (n * base) % p + + return [best_start, best_end] + + @staticmethod + def brute_force(base, p, upper): + """too slow!""" + nums = [] + n = 1 + for i in range(p): + nums.append(n - p // 2) + n = (n * base) % p + + return min([[i, j] for j in range(p + 1) for i in range(j + 1)], key=lambda ij: sum(nums[ij[0]:ij[1]])) + + def gen_random(self): + p = self.random.randrange(2, 10 * 1000) + base = self.random.randrange(1, p) + + tot = 0 + best_tot = 0 + largest_cumulative_sum = 0 + + n = 1 + + for i in range(p + 1): + if tot > largest_cumulative_sum: + largest_cumulative_sum = tot + if tot - largest_cumulative_sum < best_tot: + best_tot = tot - largest_cumulative_sum + + tot += (n - p // 2) + n = (n * base) % p + + upper = best_tot + + self.add(dict(base=base, p=p, upper=upper)) + + +class Buckets(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115""" + + @staticmethod + def sat(wells: List[List[List[int]]], grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2): + """Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group""" + grid2 = [[0 for _ in row] for row in grid] + for group in wells: + assert len(group) <= capacity + for i, j in group: + assert grid2[i][j] == 0 + grid2[i][j] = 1 + assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group + return grid2 == grid + + @staticmethod + def sol(grid, capacity): + ans = [] + for i, row in enumerate(grid): + for j, val in enumerate(row): + if val == 1: + if not ans or len(ans[-1]) == capacity: + ans.append([]) + ans[-1].append([i, j]) + return ans + + def gen_random(self): + m = self.random.randrange(1, 10) + n = self.random.randrange(1, 10) + grid = [[self.random.randrange(2) for _j in range(n)] for _i in range(m)] + capacity = self.random.randrange(1, 10) + self.add(dict(grid=grid, capacity=capacity)) + + +class BinarySort(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116""" + + @staticmethod + def sat(ordered: List[int], arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]): + """Sort the numbers in arr based on the number of 1's in their binary representation. + + [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6] + """ + if sorted(ordered) != sorted(arr): + return False # not even a permutation + return all(bin(a).count("1") <= bin(b).count("1") for a, b in zip(ordered, ordered[1:])) + + @staticmethod + def sol(arr): + return sorted(arr, key=lambda n: bin(n).count("1")) + + def gen_random(self): + arr = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(20))] + self.add(dict(arr=arr)) + + +class ConsonantFilter(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117""" + + @staticmethod + def sat(words: List[str], s="This is not a very hard puzzle", n=3): + """Find all words in the string with n consonants + + Sample input: + s="An eye for an I", n=1 + Sample output: + ["An", "eye", "an"] + """ + i = 0 + for w in s.split(): + num_consonants = 0 + for c in w.lower(): + if c not in "aeiou": + num_consonants += 1 + if num_consonants == n: + if words[i] != w: + return False + i += 1 + return i == len(words) + + @staticmethod + def sol(s, n): + return [w for w in s.split() if sum(c.lower() not in "aeiou" for c in w) == n] + + def gen_random(self): + s = " ".join(self.random.pseudo_word() for _ in range(self.random.randrange(10))) + n = self.random.randrange(7) + self.add(dict(s=s, n=n)) + + +class VowelSandwich(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118""" + + @staticmethod + def sat(ham: str, s="Any vowel is OK"): + """Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s + + "sandwhich" => "hic" + """ + vows = "aeiou" + cons = "bcdfghjklmnpqrstvwxz" + return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons + + @staticmethod + def sol(s): + vows = "aeiou" + cons = "bcdfghjklmnpqrstvwxz" + return next(s[i - 1:i + 2] for i in range(1, len(s) - 1) + if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons) + + def gen(self, target_num_instances): + self.add(dict(s="wOwwwww!")) + self.add(dict(s="do pyp you know ?")) + + def gen_random(self): + vows = "aeiou" + cons = "bcdfghjklmnpqrstvwxz" + s = " ".join(self.random.pseudo_word() for _ in range(self.random.randrange(10))) + if any(s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons + for i in range(1, len(s) - 1)): + self.add(dict(s=s)) + + +class ParenthesesPermutation(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119 + + This is harder version in which you need to find a permutation of many substrings. Brute force is too slow. + """ + + @staticmethod + def sat( + perm: str, + s="))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( " + + ")))))))(((((( )))))))))((((((( ((((((((((" + ): + """The string s consists of groups of parentheses separated by spaces. + Permute the groups such that the parentheses match. + + "( ) )(" => "( )( )" + """ + assert sorted(perm.split()) == sorted(s.split()), "Must be a permutation of the space-delimited 'groups'" + return all(perm[:i].count("(") >= perm[:i].count(")") for i in range(len(perm))) + + @staticmethod + def sol(s): + assert all(c in "( )" for c in s) + parts = s.split() + + def min_depth(part): + """Returns the lowest depth <= 0""" + ans = 0 + depth = 0 + for c in part: + if c == ")": + depth -= 1 + ans = min(ans, depth) + else: + depth += 1 + return ans + + def greedy_reorder(subs): + """Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s """ + queue = subs[:] + subs[:] = [] + height = 0 + while queue: + best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count("(") - s.count(")")) + height += best.count("(") - best.count(")") + subs.append(best) + queue.remove(best) + + lefts = [s for s in parts if s.count("(") >= s.count(")")] + + greedy_reorder(lefts) + + def mirror(sub): + return "".join(")" if c == "(" else "(" for c in sub[::-1]) + + rights = [mirror(s) for s in parts if s.count("(") < s.count(")")] # mirror temporarily for reordering + + greedy_reorder(rights) + return " ".join(lefts + [mirror(s) for s in rights[::-1]]) + + def gen_random(self): + parts = [] + depth = 0 + buffer = '' + while depth > 0 or self.random.random() > 0.1: + c = self.random.choice('()()()()())' if depth > 0 else '(') + if c == '(': + depth += 1 + elif c == ')': + depth -= 1 + buffer += c + if self.random.randrange(10) == 0: + parts.append(buffer) + buffer = '' + parts.append(buffer) + self.random.shuffle(parts) + s = " ".join(parts) + self.add(dict(s=s)) + + +class BiggestK(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120""" + + @staticmethod + def sat(biggest: List[int], k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]): + """Find the largest k numbers + + k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5] + """ + if len(biggest) != k: + return False + smallest = nums[:] + for n in biggest: + smallest.remove(n) + return k == 0 or k == len(nums) or max(smallest) <= min(biggest) + + @staticmethod + def sol(k, nums): + return sorted(nums, reverse=True)[:k] + + def gen_random(self): + length = self.random.randrange(20) + nums = [self.random.randrange(-10, 100) for _ in range(length)] + k = self.random.randrange(length + 1) + self.add(dict(k=k, nums=nums)) + + +class OddEvenSum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121 + + Very similar to EvenOddSum from \#85""" + + @staticmethod + def sat(tot: int, nums=[18, 42152, 125023521, -1221873620123, 17, 19]): + """Find the sum of the odd elements that are at even indices + + [0, 1, 2, 3, 5, 6] => 5 + """ + for i in nums[::2]: + if i % 2 == 1: + tot -= i + return tot == 0 + + @staticmethod + def sol(nums): + return sum(i for i in nums[::2] if i % 2 == 1) + + def gen_random(self): + nums = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(20))] + self.add(dict(nums=nums)) + + +class LongEarlySum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122 + + Changed slightly to make the answer not be a small integer. + """ + + @staticmethod + def sat(tot: int, k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]): + """Find the sum of the numbers among the first k with more than 2 digits + + k=3, nums=[2, 102, 12, 1000] => 102 + """ + for n in nums[:k]: + if len(str(abs(n))) > 2: + tot -= n + return tot == 0 + + @staticmethod + def sol(k, nums): + return sum(n for n in nums[:k] if len(str(abs(n))) > 2) + + def gen_random(self): + length = self.random.randrange(1, 20) + nums = [self.random.randrange(-10 ** 10, 10 ** 10) for _ in range(length)] + k = self.random.randrange(10) + self.add(dict(k=k, nums=nums)) + + +class OddCollatz(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123""" + + @staticmethod + def sat(odds: List[int], n=1243272912731): + """Find the odd numbers in the collatz sequence starting at n + + 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1] + """ + num_odds = 0 + while True: + if n % 2 == 1: + num_odds += 1 + if n not in odds: + return False + if n <= 1: + return num_odds == len(odds) + n = (3 * n + 1) if n % 2 == 1 else n // 2 + + @staticmethod + def sol(n): + ans = [] + while True: + if n % 2 == 1: + ans.append(n) + if n <= 1: + return ans + n = (3 * n + 1) if n % 2 == 1 else n // 2 + + def gen_random(self): + n = self.random.randrange(1, 10 ** self.random.randrange(1, 20)) + self.add(dict(n=n)) + + +class DateDiff(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124""" + + @staticmethod + def sat(s: str, target=-2075): + """Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target + + -2029 => "10-18-2021" # because 10-18-2021 == -2029 + """ + assert all(c in "0123457689-" for c in s) and s[2] == s[5] == "-" + m, d, y = [int(n) for n in s.split("-")] + assert m in range(1, 13) + assert d in range(1, 32) + if m in [4, 6, 9, 11]: + assert d <= 30 + if m == 2: + assert d <= 29 + return m - d - y == target + + @staticmethod + def sol(target): + if target >= -30: + return "12-01-" + str(11 - target).zfill(4) + return "01-31-" + str(-30 - target).zfill(4) + + def gen(self, target_num_instances): + self.add(dict(target=11)) + self.add(dict(target=-30)) + self.add(dict(target=-1999)) + self.add(dict(target=-10029)) + + def gen_random(self): + target = self.random.randrange(-10029, 12) + self.add(dict(target=target)) + + +class StrangeSplit(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125""" + + @staticmethod + def sat(lst: List[str], s="Hello, world!"): + """Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise + return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.) + + "a b c" => ["a", "b", "c"] + "a,b" => ["a", "b"] + """ + if " " in s: + return " ".join(lst) == s + if "," in s: + return ",".join(lst) == s + return "".join(lst) == "".join(c for c in s if c.islower() and ord(c) % 2 == 0) + + @staticmethod + def sol(s): + if " " in s: + return s.split(" ") + if "," in s: + return s.split(",") + return [c for c in s if c.islower() and ord(c) % 2 == 0] + + def gen(self, target_num_instances): + self.add(dict(s="Goodbye,spaces!")) + self.add(dict(s="abcbcbbedfsgfakbfjghskbne[pewte")) + + def gen_random(self): + words = [self.random.pseudo_word() for _ in range(self.random.randrange(10))] + s = self.random.choice([" ", ",", ""]).join(words) + self.add(dict(s=s)) + + +class IncreasingViolation(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126""" + + @staticmethod + def sat(violation: List[int], nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]): + """ + Find the indices of two entries that show that the list is not in increasing order. + If there are no violations (they are increasing), return an empty list. + + [1,2,3,0,4,5,6] => [1, 3] + """ + if not violation: + return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) + i, j = violation + return 0 <= i < j and nums[i] >= nums[j] + + @staticmethod + def sol(nums): + for i in range(len(nums) - 1): + if nums[i] >= nums[i + 1]: + return [i, i + 1] + return [] + + def gen_random(self): + nums = sorted(self.random.randrange(100) for _ in range(self.random.randrange(2, 20))) + if self.random.randrange(2) == 1: + i = self.random.randrange(len(nums)) + nums.insert(i, self.random.randrange(nums[i] + 1)) + self.add(dict(nums=nums)) + + +class PrimeIntervalIntersection(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127""" + + @staticmethod + def sat(interval2: List[int], interval1=[32157, 93210127]): + """Find an interval whose intersection with a given interval has a width that is a prime integer. + + [7, 100] => [0, 10] # because 10-7=3 is prime + """ + intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0]) + return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width)) + + @staticmethod + def sol(interval1): + a, b = interval1 + assert b - a >= 2 + return [a, a + 2] + + def gen_random(self): + a, b = [self.random.randrange(10 ** self.random.randrange(10)) * self.random.choice([-1, 1]) for _ in range(2)] + if b - a >= 2: + interval1 = [a, b] + self.add(dict(interval1=interval1)) + + +class ProductSigns(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128 + + Easy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles. + """ + + @staticmethod + def sat(n: int, arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]): + """Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of + the signs of the entries. + + [1, -2, 3] => -6 # negative because there is one negative + """ + tot = 0 + + for i in arr: + if tot >= 0: + tot += abs(i) + else: + tot -= abs(i) + if i < 0: + tot = -tot + elif i == 0: + tot = 0 + break + + return n == tot + + @staticmethod + def sol(arr): + tot = sum(abs(i) for i in arr) + if all(arr): + return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot + return 0 + + def gen_random(self): + arr = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(20))] + self.add(dict(arr=arr)) + + +class LexPath(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129""" + + @staticmethod + def sat(path: List[int], k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]): + """Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends) + + k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges + """ + + def check(prefix): + for i, j in zip(path, prefix): + if i != j: + return i < j + return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]]) + + return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges))) + + @staticmethod + def sol(k, edges): + path = [] + while len(path) < k: + path.append(min(edges[path[-1]]) if path else 0) + return path + + def gen_random(self): + n = self.random.randrange(2, 6) + edges = [self.random.sample(range(n), self.random.randrange(1, n + 1)) for i in range(n)] + k = self.random.randrange(20) + self.add(dict(k=k, edges=edges)) + + +class Tribonacci(PuzzleGenerator): + """ + Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130 + + This puzzle is a bit harder because the definition is slightly different at seq[1]. + """ + + @staticmethod + def sat(seq: List[int], length=181): + """Find a sequence where seq[n] == 1 + n / 2 for even n, and + seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.""" + return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length)) + + @staticmethod + def sol(length): + seq = [] + while len(seq) <= length: + n = len(seq) + if n % 2 == 0: + seq.append(1 + n // 2) + else: + seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2)) + return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1 + + def gen_random(self): + length = self.random.randrange(1000) + self.add(dict(length=length)) + + +class OddProduct(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131""" + + @staticmethod + def sat(prod: int, n=14235764939971075543215213): + """Return the product of the odd digits in n, or 0 if there aren't any + + 12345 => 15 + """ + + for c in str(n): + i = int(c) + if i % 2 == 1: + assert prod % i == 0 + prod //= i + return prod == any(int(c) % 2 for c in str(n)) + + @staticmethod + def sol(n): + if any(int(c) % 2 for c in str(n)): + prod = 1 + for c in str(n): + if int(c) % 2 == 1: + prod *= int(c) + return prod + return 0 + + def gen_random(self): + n = self.random.randrange(10 ** self.random.randrange(20)) + self.add(dict(n=n)) + + +class ValidBracketSubsequence(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132""" + + @staticmethod + def sat(valid: str, s="]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[["): + """Find a valid substring of s that contains matching brackets, at least one of which is nested + + "]][][[]]]" => "[][[]]" + """ + assert valid in s + depths = [0] + for c in valid: + if c == "[": + depths.append(depths[-1] + 1) + elif c == "]": + depths.append(depths[-1] - 1) + return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1 + + @staticmethod + def sol(s): + left = [] + nested = False + for i, c in enumerate(s): + if c == "[": + if len(left) == 2: + left = [left[1], i] + nested = False + else: + left.append(i) + elif c == "]": + if not left: + continue + if len(left) == 1 and nested: + return s[left[0]:i + 1] + elif len(left) == 2: + nested = True + left.pop() + assert False + + @staticmethod + def sol2(s): + import re + return re.search(r"\[(\[\])+\]", s).group(0) + + def gen_random(self): + arr = [self.random.choice("[]") for _ in range(20)] + match = "[" + "[]" * self.random.randrange(1, 10) + "]" + arr.insert(self.random.randrange(len(arr) + 1), match) + s = "".join(arr) + self.add(dict(s=s)) + + +class CeilingSquares(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133""" + + @staticmethod + def sat(running_squares: List[int], x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 1e7]): + """Round each float in x up to the next integer and return the running total of the integer squares + + [2.4, 3.7, 0.1] => [9, 25, 26] + """ + for i, v in enumerate(x): + ceiling = int(v) + (v > 0 and not v.is_integer()) + square = ceiling ** 2 + if running_squares[i] != square + (i > 0 and running_squares[i - 1]): + return False + + return len(running_squares) == len(x) + + @staticmethod + def sol(x): + from math import ceil + running_squares = [] + tot = 0 + for v in x: + tot += ceil(v) ** 2 + running_squares.append(tot) + return running_squares + + def gen_random(self): + x = [self.random.uniform(-10, 10) for _ in range(self.random.randrange(2, 10))] + self.add(dict(x=x)) + + +class LastLetters(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134""" + + @staticmethod + def sat(y: List[bool], x=["Hello, world!", "cat", "", "a test", "test a", "i e", "o", "I O U", "You and I"]): + """Determine, for each string in x, whether the last character is an isolated letter + + ["a b c", "abc"] => [True, False] + """ + assert len(x) == len(y) + for s, b in zip(x, y): + if len(s.split(" ")[-1]) == 1: + assert b == s[-1].isalpha() + else: + assert not b + return True + + @staticmethod + def sol(x): + return [len(s.split(" ")[-1]) == 1 and s[-1].isalpha() for s in x] + + def gen_random(self): + x = [] + for _ in range(self.random.randrange(30)): + x.append(" ".join(self.random.pseudo_word() for _ in range(self.random.randrange(3)))) + if self.random.randrange(3): + x[-1] += " " + self.random.char() + + self.add(dict(x=x)) + + +class Drops(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#135""" + + @staticmethod + def sat(drop_indexes: List[int], nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]): + """Find the indices for which the nums array drops. + + [1,2,3,0,2,4,1] => [3,6] + """ + d = 0 + for i in range(1, len(nums)): + if nums[i] < nums[i - 1]: + assert drop_indexes[d] == i + d += 1 + return d == len(drop_indexes) + + @staticmethod + def sol(nums): + return [i for i in range(1, len(nums)) if nums[i] < nums[i - 1]] + + def gen_random(self): + nums = [self.random.randrange(-100, 100) for _ in range(self.random.randrange(30))] + + +class LargestNegSmallestPos(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136""" + + @staticmethod + def sat(extremes: List[int], nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]): + """Find the largest negative ans smallest positive numbers (or 0 if none) + + [-2, -4, 14, 50] => [-2, 14] + [3, 22] => [0, 3] + """ + neg, pos = extremes + if neg == 0: + assert nums == [] or min(nums) >= 0 + else: + assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums) + if pos == 0: + assert nums == [] or max(nums) <= 0 + else: + assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums) + return True + + @staticmethod + def sol(nums): + pos = [n for n in nums if n > 0] + neg = [n for n in nums if n < 0] + return [max(neg) if neg else 0, min(pos) if pos else 0] + + def gen_random(self): + nums = [self.random.randint(-1000, 1000) for _ in range(self.random.randrange(20))] + self.add(dict(nums=nums)) + + +class LargestStringNum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137""" + + @staticmethod + def sat(x: float, str_nums=["1,3", "-11", "17.5", "-11", "2", "2.2", "2,2", "4", "-18,18", "99.09"]): + """Find the largest number where commas or periods are decimal points + + ["99,9", "100"] => 100.0 + """ + found = False + for s in str_nums: + y = float(s.replace(",", ".")) + assert y <= x + if y == x: + found = True + return found + + @staticmethod + def sol(str_nums): + return max(float(s.replace(",", ".")) for s in str_nums) + + def gen_random(self): + def rand(): + if self.random.randrange(2): + return str(self.random.randrange(-100, 100)) + else: + return str(self.random.uniform(-100, 100)).replace(".", self.random.choice(".,")) + + str_nums = [rand() for _ in range(self.random.randrange(1, 20))] + self.add(dict(str_nums=str_nums)) + + +class Even4Sum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138""" + + @staticmethod + def sat(summands: List[int], n=1234567890): + """Find four positive even integers whose sum is n + + 100 => [22, 24, 26, 28]""" + return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands) + + @staticmethod + def sol(n): + return [2] * 3 + [n - 6] + + def gen(self, target_num_instances): + self.add(dict(n=8)) + self.add(dict(n=10)) + self.add(dict(n=12)) + + def gen_random(self): + n = 2 * self.random.randrange(4, 10 ** self.random.randrange(1, 10)) + self.add(dict(n=n)) + + +class InverseSuperFactorial(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139""" + + @staticmethod + def sat(nums: List[int], super_factorials=[1, 2, 1]): + """The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials. + + [1, 2, 2, 12] => [1, 2, 2, 3] + """ + for i, sf in enumerate(super_factorials): + n = nums[i] + for j in range(n, 0, -1): + k = j ** (n - j + 1) + assert sf % k == 0, f"{i} {sf} {j} {n}" + sf //= k + assert sf == 1 + return True + + @staticmethod + def sol(super_factorials): + queue = set(super_factorials) + cache = {} + n = 1 + fact = 1 + s_fact = 1 + while queue: + fact *= n + s_fact *= fact + if s_fact in queue: + queue.remove(s_fact) + cache[s_fact] = n + n += 1 + return [cache[sf] for sf in super_factorials] + + @staticmethod + def superfactorial(n): + i = 1 + fact = 1 + s_fact = 1 + for i in range(1, n + 1): + fact *= i + s_fact *= fact + return s_fact + + def gen_random(self): + super_factorials = [self.superfactorial(self.random.randrange(10)) for _ in range(11)] + self.add(dict(super_factorials=super_factorials)) + + +class ExpandSpaces(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140""" + + @staticmethod + def sat(orig: str, target="-Hello,_world!__This_is-so-easy!-"): + """Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are + replaced by underscores, leads to the target. + + "_o-k__?-" => " o k ? " + """ + assert "_" not in orig and "-" not in orig + new = "" + space_count = 0 + for c in orig: + if c == " ": + space_count += 1 + else: + new += ("-" if space_count > 2 else "_" * space_count) + new += c + space_count = 0 + new += ("-" if space_count > 2 else "_" * space_count) + return new == target + + @staticmethod + def sol(target): + return target.replace("-", " " * 3).replace("_", " ") + + def gen_random(self): + target = "".join(self.random.choice(["-", "_", self.random.char(), self.random.pseudo_word()]) + for _ in range(self.random.randrange(10))).replace(" ", "") + if "___" not in target and "-_" not in target and "_-" not in target and "--" not in target: + self.add(dict(target=target)) + + +class FilenameOK(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141""" + + @staticmethod + def sat(valids: List[str], filenames=["cat.txt", "!jog.dll", "31F9.html", "Is this okay?.txt", ".exe", ""]): + """Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename + should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods + + ["train.jpg", "doc10234.txt", "3eadme.txt"] = ["No", "No", "Yes"] + """ + assert len(valids) == len(filenames) + for v, f in zip(valids, filenames): + n_digits = sum(c.isdigit() for c in f) + if v == "Yes": + prefix, ext = f.split(".") + assert ext in ["txt", "dll", "exe"] and prefix[0].isalpha() and n_digits < 4 + else: + assert v == "No" + assert f.split(".")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3 + return True + + @staticmethod + def sol(filenames): + return ["Yes" if + f.split(".")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4 + else "No" + for f in filenames] + + def gen_random(self): + filenames = [ + self.random.char() + self.random.pseudo_word() + self.random.char() + self.random.choice([ + ".txt", ".dll", ".exe", ".mp4", ".tar.zip"]) + for _ in range(self.random.randrange(20)) + ] + self.add(dict(filenames=filenames)) + + +class FindStrangeSum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142""" + + @staticmethod + def sat(lst: List[int], tot=1125181293221): + """Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)""" + return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot + + @staticmethod + def sol(tot): + residue = (tot - 1) % 12 + return [1] * residue + [tot - residue] + + def gen_random(self): + tot = self.random.choice([-1, 1]) * self.random.randrange(0, 10 ** self.random.randrange(10)) + self.add(dict(tot=tot)) + + +class PrimeWords(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143""" + + @staticmethod + def sat(primes: str, s="This is a test of whether you would want to do such strange puzzles"): + """Find the string consisting of all the words whose lengths are prime numbers + + "A bird in the hand is worth two in the bush" => "in the is worth two in the" + """ + + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + prime_words = primes.split() + i = 0 + for word in s.split(): + if is_prime(len(word)): + assert prime_words[i] == word + i += 1 + + return i == len(prime_words) + + @staticmethod + def sol(s): + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + return " ".join(w for w in s.split() if is_prime(len(w))) + + def gen_random(self): + s = " ".join(self.random.pseudo_word() for _ in range(self.random.randrange(10))) + self.add(dict(s=s)) + + +class SimplifyProductFraction(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144""" + + @staticmethod + def sat(z: str, x="-8142432/763083", y="66/-13474", max_len=18): + """Write x * y as the shortest equivalent fraction using at most max_len chars + + x="-2/3", y="-3/8", max_len=3 => "1/4" + """ + [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split("/")] for s in [x, y, z]] + return a * c * v == b * d * u and len(z) <= max_len + + @staticmethod + def sol(x, y, max_len): + [[a, b], [c, d]] = [[int(n) for n in s.split("/")] for s in [x, y]] + num, den = a * c, b * d + if num < 0 and den < 0: + num, den = -num, -den + if num == 0: + return "0/1" + + def gcd(a, b): + a, b = min(a, b), max(a, b) + if b % a == 0: + return a + return gcd(b % a, a) + + d = gcd(abs(num), abs(den)) + return f'{num // d}/{den // d}' + + @staticmethod + def naive(x, y): + [[a, b], [c, d]] = [[int(n) for n in s.split("/")] for s in [x, y]] + return f"{a * c}/{b * d}" + + def gen_random(self): + a, b, c, d = [self.random.choice([-1, 1, 1]) * self.random.randrange(10 ** self.random.randrange(10)) for _ in + range(4)] + if b == 0 or d == 0: + return + x, y = f"{a}/{b}", f"{c}/{d}" + max_len = len(self.sol(x, y, None)) + bad_len = len(self.naive(x, y)) + if max_len < bad_len - 3: + self.add(dict(x=x, y=y, max_len=max_len)) + + +class SortByDigitSum(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145""" + + @staticmethod + def sat(ordered: List[int], nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]): + """Sort the numbers by the sum of their digits + + [17, 21, 0] => [0, 17, 21] + """ + digit_sums = [sum(int(c) for c in str(n) if c != "-") for n in ordered] + return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums) + + @staticmethod + def sol(nums): + return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != "-")) + + def gen_random(self): + nums = [self.random.randrange(-1000, 1000) for _ in range(self.random.randrange(10))] + self.add(dict(nums=nums)) + + +class BigOdds(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146""" + + @staticmethod + def sat(odds: List[int], nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]): + """Find the numbers that are greater than 10 and have odd first and last digits + + [73, 4, 72] => [73] + """ + assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0]) + return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums) + + @staticmethod + def sol(nums): + return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2] + + def gen_random(self): + nums = [self.random.randrange(-10 ** 3, 2 * 10 ** 4) for _ in range(self.random.randrange(10))] + self.add(dict(nums=nums)) + + +class Threeples(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147""" + + @staticmethod + def sat(trips: List[List[int]], a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221): + """Find all triples of increasing indices where the sum of the numbers is divisible by three + + a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3 + """ + assert len({tuple(t) for t in trips}) >= count + return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips) + + @staticmethod + def sol(a, count): + n = len(a) + return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0] + + def gen_random(self): + a = [self.random.randrange(-1, 10) for _ in range(self.random.randrange(30))] + count = len(self.sol(a, count=None)) + self.add(dict(a=a, count=count)) + + +class PlanetRange(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148""" + + @staticmethod + def sat(planets_between: List[str], a="Mars", b="Neptune"): + """Find all planets between the two given planets + + a="Jupiter", b="Pluto" => ["Saturn" "Uranus" "Neptune"] + """ + assert " " not in "".join(planets_between) + return " ".join([a] + planets_between + [b]) in "Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto" + + @staticmethod + def sol(a, b): + planets = "Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto".split() + return planets[planets.index(a) + 1:planets.index(b)] + + def gen_random(self): + planets = "Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto".split() + i = self.random.randrange(1, len(planets)) + j = self.random.randrange(i) + b = planets[i] + a = planets[j] + self.add(dict(a=a, b=b)) + + +class EvenWords(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149""" + + @staticmethod + def sat(evens: List[str], words=["The", "worm", "ate", "a", "bird", "imagine", "that", "!", "Absurd", "!!"]): + """Find the even-length words and sort them by length. + + ["soup", "not", "splendid"] => ["soup", "splendid"] + """ + lens = [len(w) for w in evens] + assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens)) + return all((len(w) % 2 == 1 or w in evens) for w in words) + + @staticmethod + def sol(words): + return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w)) + + def gen_random(self): + words = [self.random.pseudo_word() for _ in range(self.random.randrange(1, 10))] + self.add(dict(words=words)) + + +class PrimeSel(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150""" + + @staticmethod + def sat(neighbors: List[int], nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]): + """Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates + + [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]""" + + def prime(m): + return all(m % i for i in range(2, m - 1)) + + goods = set() + for i, n in enumerate(nums): + if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])): + goods.add(n) + + return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors)) + + @staticmethod + def sol(nums): + def prime(m): + return all(m % i for i in range(2, m - 1)) + + return sorted({ + n for i, n in enumerate(nums) + if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])) + }) + + def gen_random(self): + nums = [self.random.randrange(-1, 20) for _ in range(self.random.randrange(30))] + self.add(dict(nums=nums)) + + +class EvenSqure(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151""" + + @staticmethod + def sat(tot: int, xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]): + """Find the sum of the squares of the positive even integers + + [2.0, 3.0, 2.5, 4.0] => 20 + """ + for x in xs: + if x.is_integer() and x > 0 and x % 2 == 0: + tot -= int(x) ** 2 + + return tot == 0 + + @staticmethod + def sol(xs): + return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0) + + def gen_random(self): + xs = [self.random.randrange(-10 ** 5, 3 * 10 ** 5) * self.random.choice([1.0, self.random.random()]) + for _ in range(self.random.randrange(10))] + if self.sol(xs) > 0 or self.random.randrange(10) == 0: + self.add(dict(xs=xs)) + + +class ArrayDiff(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152""" + + @staticmethod + def sat(b: List[int], a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]): + """Find an array that when added to vector a gives array vector c + + [1, 2, 3], [4, 17, 5] => [3, 15, 2] + """ + return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c)) + + @staticmethod + def sol(a, c): + return [k - i for i, k in zip(a, c)] + + def gen_random(self): + a = [self.random.randrange(-1, 20) for _ in range(self.random.randrange(30))] + c = [self.random.randrange(-1, 20) for _ in range(len(a))] + self.add(dict(a=a, c=c)) + + +class StrongestExtension(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153""" + + @staticmethod + def sat(s: str, class_name="TestClass", extensions=["extEnd", "LOL", "SuPeRbLy", "v9ACLQWTEW", "PickMe", "AI"]): + """Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters""" + assert s.startswith(class_name + ".") + ext = s[len(class_name) + 1:] + + def case_delta(x: str): + tot = 0 + for c in x: + if c.isupper(): + tot += 1 + elif c.islower(): + tot -= 1 + return tot + + return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions]) + + @staticmethod + def sol(class_name, extensions): + def case_delta(x: str): + tot = 0 + for c in x: + if c.isupper(): + tot += 1 + elif c.islower(): + tot -= 1 + return tot + + return class_name + "." + max(extensions, key=case_delta) + + def gen_random(self): + class_name = self.random.pseudo_word() + class_name = class_name[0].upper() + class_name[1:] + + extensions = [random_case_word(self.random) for _ in range(self.random.randrange(5, 15))] + self.add(dict(class_name=class_name, extensions=extensions)) + + +class RotateString(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154 + + This puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r + """ + + @staticmethod + def sat(r: str, s="light star", t="I love to look at the starlight!"): + """Find a rotation of string s that is a substring of t + + Input Example: + s="test", t="I love lattes" + + Output Example: + "ttes" + """ + return r in t and len(r) == len(s) and r in s + s + + @staticmethod + def sol(s, t): + return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t) + + def gen_random(self): + t = " ".join(self.random.pseudo_word() for _ in range(10)) + r = t[self.random.randrange(len(t) - 2):] + r = r[:self.random.randrange(2, len(r) + 1)] + i = self.random.randrange(len(r)) + s = r[i:] + r[:i] + self.add(dict(s=s, t=t)) + + +class EvenOddDigits(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155""" + + @staticmethod + def sat(n: int, evens=17, odds=3): + """Find an integer n >= 0 with the given number of even and odd digits. + + evens=3, odds=4 => 2381695""" + for c in str(n): + if int(c) % 2 == 0: + evens -= 1 + else: + odds -= 1 + return evens == 0 and odds == 0 + + @staticmethod + def sol(evens, odds): + return int("2" * evens + "1" * odds) + + def gen_random(self): + evens = self.random.randrange(150) + odds = self.random.randrange(150) + if odds + evens: + self.add(dict(evens=evens, odds=odds)) + + +class RomanNumerals(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156 + + Do not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution. + """ + + @staticmethod + def sat(roman: str, n=2414): + """Convert integer 0 < n < 4000 to roman numerals, and make it lowercase + + 11 => "xi" + """ + key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd', + 100: 'c', 90: 'xc', 50: 'l', 40: 'xl', + 10: 'x', 9: 'ix', 5: 'v', 4: 'iv', + 1: 'i'} + m = 0 + for base in [1000, 100, 10, 1]: + for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4 + val = base * mul + if val in key and roman.startswith(key[val]): + m += val + roman = roman[len(key[val]):] + if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else + break + return m == n + + @staticmethod + def sol(n): + units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1) + roman = "" + for s, i in units.items(): + while n >= i: + roman += s + n -= i + return roman + + def gen_random(self): + n = self.random.randrange(1, 4000) + self.add(dict(n=n)) + + +class PythagoreanTriples(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157""" + + @staticmethod + def sat(triples: List[List[int]], n=920, m=799): + """Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order + + (n=6, m=1) => [[3, 4, 5]] + """ + for a, b, c in triples: + if not (a * a + b * b == c * c and 0 < a < b < c <= n): + return False + return triples == sorted(triples) and len(triples) >= m + + @staticmethod + def sol(n, m): + return [[a, b, int((a * a + b * b) ** 0.5)] + for a in range(3, int(n / (2 ** 0.5))) + for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1) + if ((a * a + b * b) ** 0.5).is_integer()] + + _cache = {} + + def gen_random(self): + n = self.random.randrange(1, 1000) + if n not in self._cache: + self._cache[n] = len(self.sol(n, None)) + m = self._cache[n] + self.add(dict(n=n, m=m)) + + +class MostUnique(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158""" + + @staticmethod + def sat(s: str, pool=["cat", "catatatatctsa", "abcdefhijklmnop", "124259239185125", "", "foo", "unique"]): + """Select a string from the pool with the most unique characters + + ["woooow", "cow"] => "cow" + """ + assert s in pool + n = len(set(s)) + for p in pool: + assert len(set(p)) <= n + return True + + @staticmethod + def sol(pool): + return max(pool, key=lambda x: len(set(x))) + + def gen_random(self): + pool = [self.random.pseudo_word(min_len=0) for _ in range(1, self.random.randrange(2, 10))] + self.add(dict(pool=pool)) + + +class HungryRabbits(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159""" + + @staticmethod + def sat(results: List[List[int]], stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]): + """For each triple of eaten, need, stock return a pair of total appetite and remaining + + [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]] + """ + assert len(results) == len(stats) + for (tot, remaining), (eaten, need, stock) in zip(results, stats): + assert tot - eaten == min(need, stock) + assert stock < need and remaining == 0 or stock >= need and remaining + need == stock + return True + + @staticmethod + def sol(stats): + results = [] + for (eaten, need, stock) in stats: + results.append([eaten + min(need, stock), max(0, stock - need)]) + return results + + def gen_random(self): + stats = [[self.random.randrange(10) for _ in range(3)] for _ in range(self.random.randrange(10))] + self.add(dict(stats=stats)) + + +class EvaluateOperators(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160""" + + @staticmethod + def sat(ops: List[str], target=2021, nums=[4, 6, 2, 1, 1, 3, 9]): + """Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target + + target=3, nums=[7, 2, 3, 4, 5, 1, 6] => ["+", "*", "**", "%", "//", "-"] + # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3 + """ + assert len(ops) == len(set(ops)) and set(ops) == {"**", "*", "+", "-", "//", "%"} + expr = str(nums[0]) + for n, op in zip(nums[1:], ops): + expr += op + str(n) + return eval(expr) == target + + @staticmethod + def sol(target, nums): + from itertools import permutations + for ops in permutations(["**", "*", "+", "-", "//", "%"]): + expr = str(nums[0]) + for n, op in zip(nums[1:], ops): + expr += op + str(n) + try: + if eval(expr) == target: + return list(ops) + except (ZeroDivisionError, SyntaxError): + pass + assert False + + def gen_random(self): + ops = ["**", "*", "+", "-", "//", "%"] + nums = [self.random.randrange(1, 10) for _ in range(len(ops) + 1)] + self.random.shuffle(ops) + expr = str(nums[0]) + for n, op in zip(nums[1:], ops): + expr += op + str(n) + try: + target = eval(expr) + except ZeroDivisionError: + return + self.add(dict(target=target, nums=nums)) + + +class ReverseCase(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161""" + + @staticmethod + def sat(rev: List[str], strs=["cat", "u8u", "12532", "", "191", "4tUn8", "ewrWQTEW", "i", "IoU"]): + """Reverse the case of all strings. For those strings which contain no letters, reverse the strings. + + ["Test", "!@#"] => ["tEST", "#@!"] + """ + assert len(rev) == len(strs) + return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs)) + + @staticmethod + def sol(strs): + return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs] + + def gen_random(self): + strs = [self.random.choice([random_case_word(self.random), str(self.random.randrange(-1000, 1000))]) + for _ in range(self.random.randrange(10))] + self.add(dict(strs=strs)) + + +class ZobristCollision(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#162 + + The original problem was to compute an MD5 hash. This puzzle is a problem in the space of hashing, but of a + different nature. + """ + + @staticmethod + def sat(positions: List[List[int]]): + """Find a collision for the given Zobrist chess board hash: https://en.wikipedia.org/wiki/Zobrist_hashing + + Each of the two positions should be encoded as a list of 64 integers 0-12""" + + table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)] + + def zobrist(pos): + h = 0 + for i in range(64): + if pos[i]: + h ^= table[i][pos[i]] + return h + + a, b = positions + return zobrist(a) == zobrist(b) and a != b + + @staticmethod + def sol(): + hashes = {} + table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)] + + def zobrist(pos): + h = 0 + for i in range(64): + if pos[i]: + h ^= table[i][pos[i]] + return h + + for i in range(1, 100000000): + pos = [(i * 42 + ((i + 1) * j * 12589) % 54321) % 13 for j in range(64)] # pseudo-random board + h = zobrist(pos) + if h in hashes: + return [pos, hashes[h]] + else: + hashes[h] = pos + + +class EvenBetween(PuzzleGenerator): + """Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163 + + The original problem was trivial to list the even single-digit numbers between two numbers: + `a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from + `a` to `b`, e.g., `"1618202224262830"` when counting from `15` to `30`. The puzzle is, given such a string, + find `a` and `b`. + """ + + @staticmethod + def sat(ab: List[int], s="3298832990329923299432996329983300033002"): + """Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers + between them gives the string s + + "32343638" => [31, 38] + """ + return abs(ab[0] - ab[1]) > 4 and s == "".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0) + + @staticmethod + def sol(s): + for i in range(1, len(s)): + n = int(s[:i]) + n -= (n + 1) % 2 # make n odd + m = n + 1 # next even + t = "" + while len(t) < len(s): + t += str(m) + m += 2 + if s == t: + return [n, m - 1] + + assert False + + def gen_random(self): + a = self.random.randrange(100, 10 ** 5) + b = a + self.random.randrange(5, 22) + s = "".join(str(i) for i in range(a, b + 1) if i % 2 == 0) + self.add(dict(s=s)) + + if __name__ == "__main__": PuzzleGenerator.debug_problems() diff --git a/generators/lattices.py b/generators/lattices.py index a0a6b67..bbe1af6 100644 --- a/generators/lattices.py +++ b/generators/lattices.py @@ -1,6 +1,6 @@ """Lattice problems with and without noise""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -21,14 +21,15 @@ class LearnParity(PuzzleGenerator): @staticmethod def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): """ - Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that: - $$sum_{i \in S} x_i = 1 (mod 2)$$ + Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that: + $\\sum_{i \in S} x_i = 1 (mod 2)$ """ return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs) @staticmethod - def sol(vecs): # Gaussian elimination - d = 0 # decode vectors into arrays + def sol(vecs): + # Gaussian elimination + d = 0 # decode vectors into arrays m = max(vecs) while m: m >>= 1 @@ -54,17 +55,27 @@ def sol(vecs): # Gaussian elimination return [i for i in range(d) if pool[i][-1]] - def gen_random(self): - d = self.random.randrange(2, self.random.choice([5, 10, 20, 100])) - secret = None - while not secret: - secret = [i for i in range(d) if self.random.randrange(2)] - num_vecs = self.random.randrange(d, 5 * d) - vecs = [[self.random.randrange(2) for _ in range(d)] for i in range(num_vecs)] + @staticmethod + def rand_parity_problem(rand, d=63): + secret = rand.sample(range(d), d // 2) + num_vecs = d + 9 + vecs = [[rand.randrange(2) for _ in range(d)] for i in range(num_vecs)] for v in vecs: v[secret[0]] = (1 + sum([v[i] for i in secret[1:]])) % 2 - vecs = [sum(1 << i for i, b in enumerate(v) if b) for v in vecs] # encode into ints - self.add(dict(vecs=vecs)) + vecs = [sum(1 << i for i, b in enumerate(v) if b) for v in vecs] # encode into ints + return vecs + + def gen(self, target_num_instances): + vecs = self.rand_parity_problem(self.random, d=63) + self.add(dict(vecs=vecs), multiplier=10) + + def gen_random(self): + d = self.random.randrange(2, self.random.choice([5, 10, 20, 100])) + vecs = self.rand_parity_problem( + self.random, + d=d, + ) + self.add(dict(vecs=vecs), multiplier=10 if d > 9 else 1) class LearnParityWithNoise(PuzzleGenerator): @@ -72,12 +83,13 @@ class LearnParityWithNoise(PuzzleGenerator): The fastest known algorithm to this [Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning) - runs in time $2^(d/(log d))$""" + runs in time $2^(d/(log d))$ - multiplier = 40 # hard puzzle, takes longer to test + The example puzzle has small dimension so is easily solvable, but other instances are much harder. + """ @staticmethod - def sat(inds: List[int], vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 24, 16, 13, 0, 27, 13]): + def sat(inds: List[int], vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]): """ Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least 3/4 of the vectors, $$sum_{i \in S} x_i = 1 (mod 2)$$ @@ -85,8 +97,9 @@ def sat(inds: List[int], vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 2 return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4 @staticmethod - def sol(vecs): # brute force - d = 0 # decode vectors into arrays + def sol(vecs): + # brute force + d = 0 # decode vectors into arrays m = max(vecs) while m: m >>= 1 @@ -96,27 +109,36 @@ def sol(vecs): # brute force import random rand = random.Random(0) target = (len(vecs) * 3) // 4 - while True: + max_attempts = 10 ** 5 + for _ in range(max_attempts): ans = [i for i in range(d) if rand.randrange(2)] if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4: return ans - def gen_random(self): - d = self.random.randrange(2, self.random.choice([11, 100])) # number of dimensions - secret = None - while not secret: - secret = [i for i in range(d) if self.random.randrange(2)] - num_vecs = self.random.randrange(2 * d, 10 * d) - vecs = [[self.random.randrange(2) for _ in range(d)] for i in range(num_vecs)] + @staticmethod + def rand_parity_problem(rand, d=63): + secret = rand.sample(range(d), d // 2) + num_vecs = 2 * d + 5 + vecs = [[rand.randrange(2) for _ in range(d)] for i in range(num_vecs)] for v in vecs: v[secret[0]] = (1 + sum([v[i] for i in secret[1:]])) % 2 - mistakes = self.random.sample(vecs, int(len(vecs) * self.random.random() * 1 / 4)) + mistakes = rand.sample(vecs, int(len(vecs) * rand.random() * 1 / 4)) for v in mistakes: v[secret[0]] ^= 1 # flip bit in mistakes - vecs = [sum(1 << i for i, b in enumerate(v) if b) for v in vecs] # encode into ints - self.add(dict(vecs=vecs), test=d < 19) + vecs = [sum(1 << i for i, b in enumerate(v) if b) for v in vecs] # encode into ints + return vecs + def gen(self, target_num_instances): + vecs = self.rand_parity_problem(self.random, d=63) + self.add(dict(vecs=vecs), test=False, multiplier=1000) - -if __name__ == "__main__": - PuzzleGenerator.debug_problems() + def gen_random(self): + d = self.random.randrange(2, self.random.choice([11, 100])) # number of dimensions + vecs = self.rand_parity_problem( + self.random, + d=d + ) + self.add(dict(vecs=vecs), test=d < 19, multiplier=1000 if d > 40 else 30 if d >= 19 else 1) + + if __name__ == "__main__": + PuzzleGenerator.debug_problems() diff --git a/generators/number_theory.py b/generators/number_theory.py index d91f2cf..f316255 100644 --- a/generators/number_theory.py +++ b/generators/number_theory.py @@ -1,6 +1,6 @@ """Number theory problems""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List import os, json @@ -125,7 +125,7 @@ class LCM_multi(PuzzleGenerator): @staticmethod def sat(n: int, nums=[15, 27, 102], upper_bound=5000): """Find a small common multiple of a list of integers.""" - return all(n % i == 0 for i in nums) and n <= upper_bound + return all(n % i == 0 for i in nums) and 0 < n <= upper_bound @staticmethod def sol(nums, upper_bound): @@ -172,7 +172,7 @@ def gen(self, target_num_instances): for b in bs: test = (self.sol(b, target) is not None) self.add(dict(b=b, target=target), test=test) - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return m = target_num_instances solved = {b: {pow(b, n, n) for n in range(1, 10 ** 5) if 1 < pow(b, n, n) < m} for b in range(2, 11)} @@ -180,7 +180,7 @@ def gen(self, target_num_instances): for target in range(2, 100): if target in targets and self.sol(b, target): self.add(dict(b=b, target=target)) - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return def gen_random(self): @@ -199,7 +199,7 @@ class ThreeCubes(PuzzleGenerator): """ @staticmethod - def sat(nums: List[int], target=10): + def sat(nums: List[int], target=983): """Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.""" assert target % 9 not in [4, 5], "Hint" return len(nums) == 3 and sum([i ** 3 for i in nums]) == target @@ -221,7 +221,7 @@ def gen(self, target_num_instances): targets += [t for t in range(target_num_instances // 2) if t % 9 not in {4, 5}] for target in targets: self.add(dict(target=target), test=self.sol(target) is not None) - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return def gen_random(self): @@ -266,7 +266,7 @@ def gen(self, target_num_instances): for i in range(target_num_instances // 2): n = abs(i ** 2 - 1) self.add(dict(n=n)) - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return def gen_random(self): @@ -299,7 +299,7 @@ class Factoring(PuzzleGenerator): MAX_TEST = 10 ** 16 @staticmethod - def sat(i: int, n=62710561): + def sat(i: int, n=241864633): """Find a non-trivial factor of integer n""" return 1 < i < n and n % i == 0 @@ -320,7 +320,7 @@ def gen(self, target_num_instances): numbers = [16] + [int(v.split()[0]) for name, v in challenges] for n in numbers: self.add(dict(n=n), test=n < self.MAX_TEST) - if len(self.instances) >= target_num_instances: + if self.num_generated_so_far() >= target_num_instances: return def gen_random(self): @@ -349,7 +349,7 @@ class DiscreteLog(PuzzleGenerator): # updated because the answer was given away """ @staticmethod - def sat(n: int, g=3, p=17, t=13): + def sat(n: int, g=44337, p=69337, t=38187): """Find n such that g^n is congruent to t mod n""" return pow(g, n, p) == t @@ -425,7 +425,7 @@ def sol(k): def gen(self, target_num_instances): k = 5 - while len(self.instances) < target_num_instances: + while self.num_generated_so_far() < target_num_instances: self.add(dict(k=k), test=k < 18) k += 1 @@ -508,7 +508,7 @@ class CollatzDelay(PuzzleGenerator): """ @staticmethod - def sat(n: int, t=100, upper=10): + def sat(n: int, t=197, upper=20): """ Consider the following process. Start with an integer `n` and repeatedly applying the operation: * if n is even, divide n by 2, @@ -523,7 +523,8 @@ def sat(n: int, t=100, upper=10): return n == 1 and m <= 2 ** upper @staticmethod - def sol(t, upper): # Faster solution for simultaneously solving multiple problems is of course possible + def sol(t, upper): + # Faster solution for simultaneously solving multiple problems is of course possible bound = t + 10 while True: bound *= 2 @@ -541,7 +542,7 @@ def gen(self, target_num_instances): nums = [1000, 2000, 2283, 2337, 2350, 2500, 3000, 4000] + list(range(target_num_instances)) for t in nums: - if len(self.instances) < target_num_instances: + if self.num_generated_so_far() < target_num_instances: self.add(dict(t=t, upper=t // 15 + self.random.randint(30, 100)), test=t <= 100) diff --git a/generators/probability.py b/generators/probability.py index 96873ad..cf5b945 100644 --- a/generators/probability.py +++ b/generators/probability.py @@ -1,6 +1,6 @@ """Probability problems""" -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -41,10 +41,8 @@ def safe_add(self, **inputs): def gen(self, target_num_instances): self.safe_add(year_len=60182) # Neptune year! - year_len = 2 - while len(self.instances) < target_num_instances: + for year_len in range(2, target_num_instances): self.safe_add(year_len=year_len) - year_len += 1 diff --git a/generators/study.py b/generators/study.py index 1b600db..25e2dba 100644 --- a/generators/study.py +++ b/generators/study.py @@ -1,8 +1,8 @@ """ -Puzzles used for the study. +Puzzles used in our user study (the user study didn't have docstrings), see [Programming Puzzles](https://arxiv.org/abs/2106.05784). """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List diff --git a/generators/trivial_inverse.py b/generators/trivial_inverse.py index 219cb4e..21c086b 100644 --- a/generators/trivial_inverse.py +++ b/generators/trivial_inverse.py @@ -2,7 +2,7 @@ For instance, for the len function you can ask for a string of len(s)==100 etc. """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List @@ -30,7 +30,8 @@ def sol(): return ' olleH' @staticmethod - def sol2(): # solution methods must begin with 'sol' + def sol2(): + # solution methods must begin with 'sol' return 'Hello '[::-1] @@ -62,7 +63,7 @@ def sol(dups): def gen(self, target_num_instances): for dups in range(target_num_instances): - if len(self.instances) == target_num_instances: + if self.num_generated_so_far() == target_num_instances: return self.add(dict(dups=dups)) diff --git a/generators/tutorial.py b/generators/tutorial.py index 74aeef0..69272da 100644 --- a/generators/tutorial.py +++ b/generators/tutorial.py @@ -2,7 +2,7 @@ A few example puzzles that were presented with solutions to participants of the study. """ -from puzzle_generator import PuzzleGenerator +from puzzle_generator import PuzzleGenerator, Tags from typing import List diff --git a/make_dataset.py b/make_dataset.py index 6a46ac4..d8cbd26 100644 --- a/make_dataset.py +++ b/make_dataset.py @@ -2,6 +2,7 @@ import time import sys import inspect +import re import puzzle_generator import utils @@ -13,9 +14,15 @@ parser.add_argument('--target_num_per_problem', '-n', type=int, - default=10, + default=5, help='Target number of variants to generate per problem.') +parser.add_argument('--solutions', + '-s', + nargs='*', + default='', + help='Filename(s) of AI solutions to add to README, if any.') + parser.add_argument('--json', '-j', type=str, @@ -28,13 +35,13 @@ default="puzzles/README.md", help='Filename to store README description of puzzles.') -TOP = """# Python Programming Puzzles: dataset summary +TOP = """# Summary of Puzzles This document summarizes the dataset stored in the `puzzles.json` file in this directory. These files are generated from the `generators/*.py` files. The only import for puzzles is `from typing import List` but you should also pass a candidate solution -through `check_solution_type` from `puzzle_generator.py` before certifying correctness. +through `type_check` from `puzzle_generator.py` before certifying correctness. -## Puzzles by module: +## Puzzles by module: {} @@ -43,44 +50,145 @@ """ -def save_readme(gen_modules, filename): +def rename_src_var(orig, new, src, count=0): + if orig == new: + return + + def helper(s): + return re.sub(r'\b' + orig + r'\b(?!["\'])', new, s, count) + + if src.count('"""') >= 2: + a = src.index('"""') + b = src.index('"""', a + 1) + 3 + if count == 1: + h = helper(src[:a]) + if h != src[:a]: + return h + src[a:] + return helper(src[:a]) + src[a:b] + helper(src[b:]) + + return helper(src) + + +def anchor(name): + return name.strip().lower().replace(' ', '-') + + +def indent(x, spaces=4): + return (" " * spaces + x.replace("\n", "\n" + " " * spaces))[:-spaces if x.endswith("\n") else None] + + +def save_readme(gen_modules, filename, sol_filenames): + ai_sols = {} + for sol_filename in sol_filenames: + sols_js = utils.load_json(sol_filename) + for experiment in sols_js: + if "short" in experiment["experiment"]: + continue # skip short experiments + for s_s in experiment["sat_sols"]: + f = s_s["sat"] + assert f.startswith("def ") + f_name = f[len("def "):f.index("(")].strip() + f2 = rename_src_var(f_name, "sat", f, 1) + if f2 not in ai_sols: + ai_sols[f2] = dict(n_sols=0, n_attempts=0, sols=set()) + if "failures" in s_s: # bootstrap + ai_sols[f2]["n_attempts"] += s_s["failures"] + if s_s.get("sol"): + ai_sols[f2]["n_sols"] += 1 + ai_sols[f2]["n_attempts"] += 1 + cur_sols = [s_s.get("sol")] + else: + ai_sols[f2]["n_attempts"] += experiment["n"] + ai_sols[f2]["n_sols"] += s_s["n_sols"] + cur_sols = [s_s[k] for k in s_s if k.endswith("_sol")] + if "example_sols" in s_s: + cur_sols += s_s["example_sols"] + ai_sols[f2]["sols"].update(rename_src_var(f_name, "sat", sol) for sol in cur_sols if sol) + + for entry in ai_sols.values(): + entry["sol"] = (min(entry["sols"], key=len) if entry["sols"] else "") + entry['longest_sol'] = (max(entry["sols"], key=len) if len(entry["sols"]) > 1 else "") + entry["success_rate"] = entry["n_sols"]/entry["n_attempts"] + table = "" content = "" tot_puzzles = 0 tot_instances = 0 - for name, module_stuff in gen_modules.items(): + + def py(src): + return f"```python\n{src}\n```\n" + + for module_name, module_stuff in gen_modules.items(): section = "" - sec_name = name.split(".")[-1] + sec_name = module_name.split(".")[0] section += f"## {sec_name}\n\n" section += f"{module_stuff['docstring']}\n\n" puzzles = module_stuff['examples'] + if ai_sols: + puzzles = sorted(puzzles, + key=lambda f: ai_sols[f['sat']]["success_rate"] if f['sat'] in ai_sols else 0, + reverse=True) n = len(puzzles) - link = f"[{sec_name}](#{sec_name.lower().replace(' ', '-')})" + link = f"[{sec_name}](#{anchor(sec_name)})" n_instances = sum(p["n_instances"] for p in puzzles) tot_instances += n_instances - table += f"- [{sec_name} ({len(puzzles):,} problems, {n_instances:,} instances)](#{sec_name.lower().replace(' ', '-')})\n" + table += f"- [{module_name}](../generators/{module_name}), [{len(puzzles):,} problems](#{anchor(sec_name)}): {module_stuff['docstring'].strip().rstrip('.')}\n" for i, puzzle in enumerate(puzzles): tot_puzzles += 1 - section += f"### {puzzle['name']}\n" - section += f"{puzzle['desc']}\n\n" - section += f"```python\n{puzzle['sat']}\n```\n" - if len(puzzle['sols']) > 0: - section += "
" - section += f"{len(puzzle['sols'])} solution{'s' if len(puzzle['sols'])!=1 else ''} " - section += f"to {sec_name} {i + 1:,}/{n:,}" - if len(puzzle['sols']) > 0: - section += "\n\n" - for sol in puzzle['sols']: - section += f"```python\n{sol}\n```\n\n" - section += "
\n\n" - else: - section += "\n\n" + f = puzzle['sat'] + puzzle_text = f'* **{puzzle["name"]}** {puzzle["notes"].strip()}' + puzzle_text += f' ({puzzle["n_instances"]} instance{"s" if puzzle["n_instances"] != 1 else ""})\n\n' + puzzle_text += py(f) + puzzle_text += "
" + num_ai_sols = 0 + if ai_sols: + sol_entry = ai_sols.get(f) + if sol_entry: + num_ai_sols = sol_entry['n_sols'] + puzzle_text += f"{sol_entry['success_rate']*100:.2g}% Codex success rate, " + else: + puzzle_text += f"Codex was not run on this puzzle, " + sol_bodies = puzzle['sol_bodies'] + n_sols = len(sol_bodies) + puzzle_text += f"{n_sols:,} hand-written solution{'s' if n_sols != 1 else ''} " + puzzle_text += "\n\n" + puzzle_text += "Solution header:\n" + puzzle_text += py(puzzle['sol_header']) + puzzle_text += "Solution docstring (*not* usually provided)\n\n" + puzzle_text += py(puzzle['sol_docstring']) + if num_ai_sols: + if sol_entry['longest_sol']: + puzzle_text += f"Shortest Codex solution:\n" + puzzle_text += py(sol_entry['sol']) + puzzle_text += f"Longest Codex solution:\n" + puzzle_text += py(sol_entry['longest_sol']) + else: + puzzle_text += f"Codex solution:\n" + puzzle_text += py(sol_entry['sol']) + if n_sols: + for body in sol_bodies: + puzzle_text += "Hand-written solution:\n" + puzzle_text += py(body) + + puzzle_text += "
\n\n" + + section += indent(puzzle_text, 4)[4:] content += section table += f"\nTotal ({tot_puzzles:,} problems, {tot_instances:,} instances)\n" content = TOP.format(table) + content + if ai_sols: + content = content.replace( + "Summary of Puzzles", + f"Summary of Puzzles and Codex solutions", + 1 + ).replace( + "----", + f"----\n\nThe puzzles in each module are sorted by percent of Codex correct solutions\n\n", + 1 + ) with open(filename, "w", encoding='utf8') as f: f.write(content) @@ -88,14 +196,15 @@ def save_readme(gen_modules, filename): def main(args): start_time = time.perf_counter() - if any(p.DEBUG for p in puzzle_generator.PuzzleGenerator.subclass_descendents()): # if there are debug problems, don't make the dataset + if any(p.DEBUG for p in + puzzle_generator.PuzzleGenerator.subclass_descendents()): # if there are debug problems, don't make the dataset puzzle_generator.PuzzleGenerator.debug_problems() print("Didn't make dataset because there are `Problem.Debug` problems, remove the `.Debug` to proceed.") return try: last_version = utils.load_json(args.json) - already_tested_cache = {puz["sat"]: {sol for sol in puz["sols"]} for puz in last_version} + already_tested_cache = {puz["sat"]: {sb for sb in puz["sol_bodies"]} for puz in last_version} except: already_tested_cache = {} @@ -103,7 +212,7 @@ def main(args): gens = puzzle_generator.PuzzleGenerator.subclass_descendents() - gens_by_module = utils.inv_dict({g: g.__module__.split(".")[-1] for g in gens}) + gens_by_module = utils.inv_dict({g: g.__module__.replace("generators.", "") + ".py" for g in gens}) utils.info(f"Python version {sys.version}") utils.info(f"Generating from templates: {list(gens_by_module)}") @@ -111,8 +220,8 @@ def main(args): summaries = {} for module_name, gens in gens_by_module.items(): # order determined by generators/__init__.py + module_multiplier = 0.2 if "trivial" in module_name else 1.0 readme_examples = [] - downweight = 1.0/sum(cls.multiplier for cls in gens) # this causes each module to be weighted equally for cls in gens: gen = cls() gen.build(args.target_num_per_problem, already_tested_cache) @@ -120,36 +229,28 @@ def main(args): { "name": i.name, "sat": i.src, - "sols": i.sol_srcs, + "ans_type": gen.ans_type, + "sol_header": i.sol_header, + "sol_docstring": gen.docstring, + "sol_bodies": i.sol_bodies, "module": module_name, "notes": gen.desc, - "taint_date": "-".join(str(i) for i in gen.taint_date), - "weight": gen.multiplier * downweight / len(gen.instances) + "weight": i.multiplier * module_multiplier } for i in gen.instances] puzzles.extend(instances) - readme_examples.append({ - "name": gen.name, - "desc": gen.desc, - "sat": gen.instances[0].src, - "sols": gen.instances[0].sol_srcs, - "n_instances": len(instances) - }) + readme_examples.append({** instances[0], "name": gen.name, "n_instances": len(instances)}) summaries[module_name] = { "docstring": inspect.getmodule(gens[0]).__doc__, "examples": readme_examples } - for p in puzzles: - if p["sat"] == utils.remove_docstring(p["sat"]): - print(p["sat"]) - assert False, f"Puzzle {p['name']} in {p['module']} doesn't have a valid docstring" - utils.save_json(puzzles, args.json, make_dirs_if_necessary=True, indent=2) - save_readme(summaries, args.readme) + save_readme(summaries, args.readme, args.solutions) utils.info(f"Elapsed time: {(time.perf_counter() - start_time) / 60:.2f} minutes") - utils.info(f"Saved {len(puzzles)} to {args.json} and {args.readme}") + utils.info(f"Saved {len(puzzles):,} to {args.json} and {args.readme}") + if __name__ == "__main__": args = parser.parse_args() diff --git a/notebooks/Intro.ipynb b/notebooks/Intro.ipynb index 00b9e6d..8c0e926 100644 --- a/notebooks/Intro.ipynb +++ b/notebooks/Intro.ipynb @@ -391,8 +391,10 @@ "id": "purple-edwards", "metadata": {}, "source": [ - "# Problems the AI models didn't solve\n", - "Below are five problems none of our AI models solved." + "# Problems GPT-3 didn't solve\n", + "Below are five problems none of our AI models solved. *Update*: Codex eventually solved all 30 puzzles! See its\n", + "solutions (in order of easiest to hardest puzzles) at:\n", + "[https://github.com/microsoft/PythonProgrammingPuzzles/blob/main/puzzles/README.md#study](https://github.com/microsoft/PythonProgrammingPuzzles/blob/main/puzzles/README.md#study)" ] }, { diff --git a/puzzle_generator.py b/puzzle_generator.py index fc6c258..9b63c0f 100644 --- a/puzzle_generator.py +++ b/puzzle_generator.py @@ -5,13 +5,13 @@ import inspect import json -from typing import List, Dict, Callable, Set, Tuple +from typing import List, Callable, Dict, Set import random -import os +import re import sys import traceback import time -import datetime +import abc import utils @@ -42,6 +42,19 @@ def helper(depth, o): return helper(nest_depth, obj) +def test_puzzle(f: callable, x, ans_type: str): + """Checks if x is of the correct type and makes f return True (literally True, not an integer or whatever) + + :param f: Puzzle + :param x: candidate answer + :param ans_tye: + :return: + """ + if not type_check(x, ans_type): + raise TypeError + return f(x) is True + + class InterpreterError(Exception): pass @@ -93,51 +106,6 @@ def gen_dump_code(var_name: str, ty: type) -> str: return f"print(json.dumps({var_name}))\n" -def gen_type_assertion(var_name: str, ty: type) -> str: - """ - create code to assert type of var_name is ty - - :param var_name: The variable name, like "x" - :param ty: str, List[int] , List[List[bool]], etc. - :return: code that asserts that var_name is of type ty - """ - - tys = type_str(ty) - vars = [c for c in 'abcdefghijklmnop' if c != var_name][::-1] - - def helper(var_name, tys): - tys = tys.strip() - pre_bracket = tys.split("[")[0].lower() # part before [ (or the entire string if no bracket - ans = f"type({var_name}) is {pre_bracket}" - if "[" in tys: - inside = tys[tys.index("[") + 1:-1] - new_var = vars.pop() - if pre_bracket == "list" or pre_bracket == "set": - inside_check = helper(new_var, inside) - # if " and " in inside_check: - # inside_check = "(" + inside_check + ")" - ans += f" and all({inside_check} for {new_var} in {var_name})" - elif pre_bracket == "dict": - depth = 0 - for i, c in enumerate(inside): - if c == "[": - depth += 1 - elif c == "]": - depth -= 1 - elif c == "," and depth == 0: - break - assert depth == 0 and c == ",", "Dict[(expecting comma inside)]" - key_var = vars.pop() - key_check = helper(key_var, tys[:i]) - val_check = helper(new_var, tys[i + 1:]) - ans += f" and all({key_check} and {val_check} for {key_var}, {new_var} in {var_name}.items())" - else: - assert False, f"Unknown type `{tys}`" - return ans - - return f"assert {helper(var_name, tys)}, '{var_name} must be of type {tys}'" - - def gen_load_code(var_name: str, ty: type) -> str: """ create code to load an object of type ty as a string @@ -297,30 +265,52 @@ def deep_copy(obj): return obj -def get_type(obj, ignore_errors=False): # better than type(x) because it can do things like List[int], etc. - try: - t = type(obj) - if t in {int, float, bool, complex, range, str}: - return t - assert t in {tuple, list, set, dict}, f"Unacceptable input type '{t}'" - iterand_types = [get_type(i, ignore_errors=True) for i in obj] - iterand_types = [i for i in iterand_types if i is not None] - if t == tuple: - return Tuple[iterand_types] - assert len(iterand_types) > 0, "Cannot get type of empty list/set/dict" - assert len(set(iterand_types)) == 1, "Lists/sets/dicts must be a single type" - if t == list: - return List[iterand_types[0]] - if t == set: - return Set[iterand_types[0]] - if t == dict: - val_types = [get_type(i) for i in obj.values()] - assert len(set(val_types)) == 1, "Dict values must be a single type" - return Dict[iterand_types[0], val_types[0]] - except AssertionError: - if ignore_errors: - return None - raise +def same_types(obj1, obj2): + """ + Recursively check that obj1 and obj2 are of the same types. + Better than type(obj1) == type(obj2) because it recursively checks inside lists, sets, dicts, and tuples + """ + t = type(obj1) + if t is not type(obj2): + return False + if t in {list, set, dict}: + for iterables in ([(obj1, obj2), (obj1.values(), obj2.values())] if t is dict else [(obj1, obj2)]): + lst = [i for o in iterables for i in o] + if not all(same_types(lst[0], o) for o in lst[1:]): + return False + if t is tuple: + return len(obj1) == len(obj2) and all(same_types(o1, o2) for o1, o2 in zip(obj1, obj2)) + return True + + +# def test_same_types(): +# assert same_types(1, 2) +# assert same_types({1:[]}, {}) +# assert same_types({1:[2,3]}, {4:[5,6]}) +# assert not same_types(True, 1) +# assert not same_types(1, 2.0) +# assert not same_types(1, 2.0) +# assert not same_types({1:[2,3]}, {4:[5.,6.]}) +# assert not same_types({1:[2,3], 3:[5.]}, {}) +# +# test_same_types() + +def homogeneous_type(obj): + """ + Checks that the type is "homogeneous" in that all lists are of objects of the same type, etc. + """ + return same_types(obj, obj) + + +# def test_homogeneous_types(): +# assert homogeneous_type(1) +# assert homogeneous_type([1, 2, 3]) +# assert homogeneous_type([[[]], [[]]], [[3], [4]]) +# assert homogeneous_type({}) +# assert not homogeneous_type([1, 2, 3.3]) +# assert homogeneous_type([[[]], [[], [4.]]], [[3], []]) +# +# test_homogeneous_types() def decode(st: str): # small modifications to make json roundtrip work @@ -354,45 +344,12 @@ def helper(x): # encodes sets in a json-friendly fashion class Instance: - def __init__(self, src, name: str): + def __init__(self, name: str, src: str, sol_header: str, sol_bodies: List[str], multiplier: float): + self.name = name # instance name self.src = src - self.name = name # which PuzzleGenerator template did it come from? - self.sol_srcs = [] - - def add_test(self, sol_src): - """Add solution to the list of solutions""" - if sol_src in self.sol_srcs: # already added this solution - return - self.sol_srcs.append(sol_src) - - def check_and_add_test(self, sol_src: str, type_str: str, multiplier: float): - """Check that the solution satisfies the given instance and add the solution to the instance. - Do a round-trip json encoding/decoding to mimic the actual test and deter strange attacks. - Ideally this could be done by running a protected process (like in evaluating programming - contest submissions) but that is much slower. Since this is a test we authored presumably it has - no evil code.""" - - if sol_src in self.sol_srcs: # already added this solution - return - env = dict(List=List) - time0 = time.perf_counter() - my_exec(sol_src + "\n" + "answer = sol()", env, description=self.name) - - sol_val = env["answer"] - - assert sol_val is not None, "sol returned None" - - assert type_check(type_str, sol_val) - - answer = decode(encode(sol_val)) - assert answer == sol_val, "encode/decode round trip failed" - - env2 = dict(answer=answer, List=List, Dict=Dict, Set=Set) # in case they mucked with env - my_exec(self.src + "\n" + "assert sat(answer)", env2, description=self.name) - dur = time.perf_counter() - time0 - if dur > DEFAULT_TIMEOUT * multiplier: - utils.warn(f"Took {dur}s to test {self.name} (multiplier={multiplier})") - self.add_test(sol_src) + self.sol_header = sol_header + self.sol_bodies = sol_bodies + self.multiplier = multiplier def unindent(docstr): @@ -408,6 +365,34 @@ def unindent(docstr): return "\n".join(lines) +def get_body(function_src): + match = re.search(r"\)\s*:(.*)\n", function_src) + assert match and (match.group(1).replace(" ", "") == ""), \ + f"Bad solution header for, maybe move to next line:\n\n{match.group(1)}\n\nin:\n\n{function_src}" + return function_src[match.end():] + + +class Tags(abc.ABC): + brute_force = "brute_force" # can be solved by brute force + codeforces = "codeforces" # inspired by a codeforces.com problem + data_structures = "data_structures" # needs fancy data structures to solve + dp = "dp" # dynamic programming + famous = "famous" # roughly at the level that there is a Wikipedia page about the topic + games = "games" # puzzle describes a game + graphs = "graphs" # solution can use graph algorithms like depth-first search, etc. + greedy = "greedy" # solution can use a greedy algorithm + hard = "hard" # challenging + human_eval = "human_eval" # inspired by a problem from the Human Eval dataset + unsolved = "unsolved" # unsolved, involves open some unsolved puzzles + math = "math" # mainly mathematical reasoning + strings = "strings" # involves constructing a string + # trees = "trees" # will we use this? + trivial = "trivial" # trivial *solution* even if it may require some work to understand what the puzzle is asking + + +Tags._all_tags = {getattr(Tags, k) for k in dir(Tags) if not k.startswith("_")} + + class PuzzleGenerator: '''PuzzleGenerator is an abstract class for a puzzle generator which builds 1 or more instances. Each problem MUST OVERRIDE sat. Examples from templates/hello.py: @@ -431,7 +416,8 @@ def sol(): return 'olleH ' @staticmethod - def sol2(): # solution methods must begin with 'sol' + def sol2(): + # solution methods must begin with 'sol' return 'Hello '[::-1] @@ -455,15 +441,10 @@ def gen_random(self): self.add({"a": a, "b": b}) ''' - multiplier = 1.0 # puzzle-specific weight multiplier, puzzles in same are also be further weighted - tests = None # a list of test cases: can be a list of inputs if there is just one input or a list of dictionaries - DEBUG = False # DEBUG = True while making a puzzle makes it run before any other problems - taint_date = [2021, 4, 26] # dataset initial release date + tags = [] # add tags, e.g., tags = [Tags.trivial, Tags.math] - # date before which we assume training data has not been tainted by variations of the puzzle. - # For example, if you invented the puzzle, then it would be the date it first appears publicly (e.g., on github) - # If it's closely adapted from a website, then it should be the date from which it was published publicly on - # that website, unless it was based on an puzzle that was publicly available earlier somewhere + DEBUG = False # DEBUG = True while making a puzzle makes it run before any other problems + skip_example = False # skip the example in the default arguments to sat, so it's not the first instance @staticmethod def sat(ans, *other_inputs): # must override @@ -521,101 +502,167 @@ def debug_problems(cls, target_num_instances=None): def __init__(self): self.name = self.__class__.__name__ + assert len(self.tags) == len(set(self.tags)), "duplicate tags in {self.name}" + assert all(t in Tags._all_tags for t in self.tags), f"invalid tag(s) in {self.name}" assert self.sat is not PuzzleGenerator.sat, f"Must override {self.name}.sat" - self.sat_src_spec = get_src_spec(self.sat) + self.sat_src, sat_spec = get_src_spec(self.sat) + self.docstring = utils.get_docstring(self.sat_src) + self.sat_src = utils.remove_docstring(self.sat_src) + assert len(sat_spec.args) > 0, f"{self.name}.sat() takes no arguments!" + self.ans_name, *self.arg_names = sat_spec.args + assert self.ans_name in sat_spec.annotations, f"Missing type hint for {self.name}.sat({self.ans_name}: ???" + self.ans_type = type_str(sat_spec.annotations[self.ans_name]) + assert self.ans_type.replace("List[", "").replace("]", "") in "bool float int str".split(), \ + f"Answer type for {self.name} must be bool/int/float/str or Lists (or Lists of Lists etc.) of those" if not self.__doc__ or self.__doc__ == PuzzleGenerator.__doc__: self.desc = "" else: self.desc = unindent(self.__doc__) - if not hasattr(self, "taint_date"): - self.taint_date = self.FIRST_TAINT_DATE - assert datetime.date(*self.taint_date) - datetime.date.today() < datetime.timedelta(100), \ - f"Invalid taint date {self.taint_date} too far in the future." self.random = BuilderRandom(seed=self.name) - self.instances = [] - self._seen_problems = set() - self._built_target = 0 - self.build_time = None - self._already_tested = None + + # these are created at Build time + self._seen_inputs = None + self._inputs = None # inputs to test during build + self.instances = None sol_names = [k for k in dir(self) if k.startswith("sol")] self.sols = [getattr(self, k) for k in sol_names] - self.sol_src_specs = [get_src_spec(s) for s in self.sols] - + self.sol_bodies = [] + for sol in self.sols: # check solution headers and extract bodies + sol_src, sol_spec = get_src_spec(sol) + assert self.arg_names == sol_spec.args, f"mismatched problem/solution arguments for {self.name}" + assert not sol_spec.defaults, f"Don't set default parameter values for {self.name}.sol -- we'll do it" + self.sol_bodies.append(get_body(sol_src)) + + assert set(self.arg_names) == set(self.get_example()), f"Bad {self.name} example" + for v, val in self.get_example().items(): + if not homogeneous_type(val): + utils.warn(f"Non-homogeneous type for example var {v} in {self.name}") + + # check that sat and sol's are @staticmethod's mro_dict = {} for mro in inspect.getmro(self.__class__)[::-1]: mro_dict.update(mro.__dict__) assert all(isinstance(mro_dict[k], staticmethod) for k in ["sat"] + sol_names), \ f"{self.name} `sat` and `sol` must be defined with @staticmethod" - p_spec = self.sat_src_spec[1] - - self.arg_names = p_spec.args - assert len(self.arg_names) > 0, f"{self.name}.problem() takes no arguments!" - self.types = p_spec.annotations + def test_input(self, name, inp, test: bool, multiplier: float, already_tested={}): + """Check if the input has been tested already. If not, assert that the solution(s) satisfy the given + inputs. Do a round-trip json encoding/decoding to mimic the actual test. + Ideally this could be done by running a protected process (like in evaluating programming + contest submissions) but that is much slower. Since this is a test we authored presumably it has + no evil code. - if self.sols: - s_spec = self.sol_src_specs[0][1] - assert self.arg_names[1:] == s_spec.args, \ - f"mismatched problem/solution arguments for {self.name}" - self.types.update(s_spec.annotations) + Returns the new instance and number of solutions actually tested (that were not in cache)""" + num_tested = 0 + new_sat_src = create_sat(self.sat_src, self.ans_name, self.ans_type, self.arg_names, inp) + sol_header = create_sol_header(inp) - assert set(self.arg_names[1:]) == set(self.get_example()), f"Bad {self.name} example" - self.types.update({v: get_type(x) for v, x in self.get_example().items() if get_type(x, True)}) + instance = Instance( + name, + new_sat_src, + sol_header, + self.sol_bodies if test else [], + multiplier + ) - for v in self.arg_names: - assert v in self.types, f"Cannot determine type of `{v}` in {self.name} -- no annotation/_example" + for sol_body, sol_func in zip(instance.sol_bodies, self.sols): + if new_sat_src in already_tested and sol_body in already_tested[new_sat_src]: + continue # skip + num_tested += 1 + time0 = time.perf_counter() + env = dict(List=List) + if self.DEBUG: # In debug mode just run the darn tests + answer = sol_func(**inp) + else: + try: + my_exec( + instance.sol_header + " \n" + sol_body + "\n" + "answer = sol()", + env, + description=instance.name + ) + except Exception: + sol_func(**inp) + utils.error("Strange, failed test in exec but passed without exec") + raise + + answer = env["answer"] + + assert answer is not None, "sol returned None" + assert type_check(self.ans_type, answer), f"Solution returned wrong type for {self.name}" + + if self.DEBUG: + assert self.sat(answer, **inp) is True, f"Puzzle {self.name} didn't return True on `{inp}`" + else: + assert answer == decode(encode(answer)) + try: + env2 = dict(answer=answer, List=List) # in case we screwed up env + my_exec(instance.src + "\n" + "assert sat(answer) is True", env2, description=self.name) + except Exception: + assert self.sat(answer, **inp) is True, \ + f"Puzzle {instance.name} didn't return True on `{inp}`" + utils.error("Strange, failed test in exec but passed without exec") + raise + + dur = time.perf_counter() - time0 + if dur > DEFAULT_TIMEOUT * multiplier: + utils.warn(f"Took {dur}s to test {instance.name} (multiplier={multiplier})") + + return instance, num_tested + + def num_generated_so_far(self): + """ + Call this function during gen/gen_random to see how many unique puzzle instances have been generated so far. + """ + return len(self._inputs) def build(self, target_num_instances, already_tested={}, max_random_attempts=100, force_trivial_test=False): - if self._built_target == target_num_instances: - return - self.check_for_trivial_solutions(force_trivial_test, already_tested) - self._already_tested = already_tested - self._seen_problems = set() - self._built_target = target_num_instances + self._seen_inputs = set() + self._inputs = [] # for recording the inputs to test self.random.reseed() - self._tested = 0 - self.instances = [] start_time = time.perf_counter() - self.add(self.get_example()) - - if self.tests: - tests = self.tests - _, spec = self.sat_src_spec - if len(spec.args) == 2: # possible list of raw arguments not wrapped in a dictionary - input_name = spec.args[1] - input_type = self.types[input_name] - if any(get_type(test, ignore_errors=True) == input_type for test in self.tests): - tests = [{input_name: test} for test in self.tests] - for test in tests: - if len(self.instances) < target_num_instances: - self.add(test) - - if target_num_instances > len(self.instances): - self.gen(target_num_instances) - while len(self.instances) < target_num_instances: - n = len(self.instances) + if not self.skip_example: + self.add(self.get_example()) + + if target_num_instances > len(self._inputs): + self.gen(target_num_instances - len(self._inputs)) + + while len(self._inputs) < target_num_instances: + n = len(self._inputs) for _ in range(max_random_attempts): self.gen_random() - if n != len(self.instances): # added a problem + if n != len(self._inputs): # added a problem + assert len(self._inputs) == n + 1, f"{self.name}.gen_random() generated more than one instance" break - if len(self.instances) == n: # failed max_random_attempts, give up + + if len(self._inputs) == n: # failed max_random_attempts, give up break - if not self.instances: - utils.error(f"{self.name} did not generate any problem instances") + self._inputs = self._inputs[:target_num_instances] + + num_tested = 0 + self.instances = [] + + for inp, test, multiplier in self._inputs: + instance, n = self.test_input(f"{self.name}:{len(self.instances)}", inp, test, multiplier, already_tested) + self.instances.append(instance) + num_tested += n + build_time = time.perf_counter() - start_time - self.build_time = time.perf_counter() - start_time - self._already_tested = None assert self._example_copy == self._example, f"Puzzle {self.name} changed inputs" - if self._tested: - utils.info(f"Tested {self._tested} instances of {self.name}") + + if num_tested: + utils.info(f"Actually tested {num_tested:,}/{len(self.instances):,} " + f"instances of {self.name} in {build_time:.1f}s") + + self._seen_inputs = None + self._inputs = None # for recording the inputs to test def check_for_trivial_solutions(self, force, already_tested): # check for trivial solutions example = self.get_example() - src = inject_into_src(*self.sat_src_spec, "sat", example, self.types) + src = create_sat(self.sat_src, self.ans_name, self.ans_type, self.arg_names, example) if (not force and src in already_tested) or not hasattr(self, "sol"): return utils.info(f"Checking for trivial solutions to {self.name}") @@ -667,7 +714,7 @@ def check_for_trivial_solutions(self, force, already_tested): # check for trivi f"has trivial solution `{t}`") break dur = time.perf_counter() - time0 - if dur > 1.0: + if dur > 1.0: # warn if above one second utils.warn(f"Took {dur:.1f}s to test for trivial solutions to `{self.name}`") def gen(self, target_num_instances): @@ -676,81 +723,29 @@ def gen(self, target_num_instances): def gen_random(self): pass - def check_seen_input(self, inp): - """ - Returns True if the input is a duplicate of a previous puzzle, and also makes sure that the types match - """ + def add(self, inp: dict, test=True, multiplier=1.0): s = str(inp) - if s in self._seen_problems: - return True # duplicate problem - - self._seen_problems.add(s) - - assert set(inp) == set(self.arg_names[1:]), f"Instance #{len(self.instances)} keys mismatch in {self.name}" - for v in inp: - assert get_type(inp[v], ignore_errors=True) in (None, self.types[v]), \ - f"Instance #{len(self.instances)} variable `{v}` type mismatch in {self.name}" - - return False - - def add(self, inp: dict, test=True): - if self.DEBUG: - return self.add_debug(inp, test) - - if self.check_seen_input(inp): - return # don't add duplicate problems + if s in self._seen_inputs: + return # duplicate problem + else: + self._seen_inputs.add(s) - instance = Instance( - inject_into_src(*self.sat_src_spec, "sat", inp, self.types), - f"{self.name}_{len(self.instances)}" - ) + assert set(inp) == set(self.arg_names), f"Instance #{self.num_generated_so_far()} keys mismatch in {self.name}" + example = self.get_example() + for k in inp: + v1, v2 = example[k], inp[k] + if not same_types(v1, v2): + utils.warn(f"Instance #{self.num_generated_so_far()} variable `{k}` type mismatch in {self.name}") - if test: - for s, (sol_src, sol_spec) in zip(self.sols, self.sol_src_specs): - sol_src = inject_into_src(sol_src, sol_spec, "sol", inp) - if instance.src in self._already_tested and sol_src in self._already_tested[instance.src]: - instance.add_test(sol_src) - else: - try: - instance.check_and_add_test( - sol_src, - type_str=self.types[self.arg_names[0]], - multiplier=self.multiplier - ) - self._tested += 1 - except Exception: # failed to pass test, rerun test without for debugging with normal exception - assert self.sat(s(**inp), **inp) is True, f"Puzzle {self.name} didn't return True on `{inp}`" - utils.error("Strange, failed test in exec but passed without exec") - raise - - self.instances.append(instance) - - def test(self, target_num_instances=100): - self.build(target_num_instances, force_trivial_test=True) + self._inputs.append((inp, test, multiplier)) def debug(self, target_num_instances=10000): - old_debug = self.DEBUG print(f"Debugging {self.name}") + old_debug = self.DEBUG + self.DEBUG = True self.build(target_num_instances, force_trivial_test=True) - solved = sum(i[1] for i in self.instances) - dur = self.build_time - utils.info(f"Tested {solved:,}/{len(self.instances):,} instances of " - f"({self.name}: PuzzleGenerator) in {dur:0.2f}s") self.DEBUG = old_debug - def add_debug(self, inp: dict, test=True): - if self.check_seen_input(inp): - return # don't add duplicate problems - - if test: - var_name = self.sat_src_spec[1].args[0] - for s in self.sols: - answer = s(**inp) - assert type_check(self.types[var_name], answer), "Puzzle {self.name} got wrong type solution" - assert self.sat(answer, **inp) is True, f"Puzzle {self.name} didn't return True on `{inp}`" - - self.instances.append(("DEBUG TEST", bool(test and self.sols))) # for counting purposes - def get_src_spec(f: Callable): try: @@ -769,36 +764,22 @@ def get_src_spec(f: Callable): return src, spec -def inject_into_src(src, spec, new_function_name=None, defaults={}, types={}): - if spec.defaults: # combine defaults, with defaults over-riding spec.defaults - defaults = {**dict(zip(spec.args[-len(spec.defaults):], spec.defaults)), **defaults} - assert all(var in spec.args for var in defaults), f"Defaults {defaults} not all in spec.args" - - for v, t in spec.annotations.items(): - assert v not in types or types[v] == t, f"Annotation mismatch in {src}" - - types = {**spec.annotations, **types} - - func_name = (new_function_name or src[4:src.index('(')]) - - def need_explicit_type(var): - if var not in types: - return False - - # also make type explicit for [], [[]], [[[]]], etc. since empty-list types are not clear - def hollow(li): # like [[], [[], []]] - if type(li) != list: - return False - return all(hollow(i) for i in li) - - return var not in defaults or hollow(defaults[var]) +def create_sol_header(defaults, function_name="sol"): + # could add types here if needed + ans = f"def {function_name}(" + ans += ", ".join(f'{var}={utils.stringify(default)}' for var, default in defaults.items()) + ans += "):" + return ans - arg_st = ", ".join([var + - (f": {type_str(types[var])}" if need_explicit_type(var) else "") + - (f"={utils.stringify(defaults[var])}" if var in defaults else "") - for var in spec.args]) - return f'def {func_name}({arg_st}):' + src[src.index("):") + 2:] +def create_sat(src, ans_name, ans_type, args, defaults, function_name="sat"): + assert set(defaults) == set(args), f"Add error: defaults don't match args {args} in {src}" + ans = f"def {function_name}({ans_name}: {ans_type}" + if args: + ans += ", " + ", ".join(f"{v_name}={utils.stringify(defaults[v_name])}" for v_name in args) + ans += "):\n" + ans += get_body(src) + return ans def get_func_name(src): diff --git a/puzzles/README.md b/puzzles/README.md index 401f977..8ee613b 100644 --- a/puzzles/README.md +++ b/puzzles/README.md @@ -1,1469 +1,2729 @@ -# Python Programming Puzzles: dataset summary +# Summary of Puzzles and Codex solutions This document summarizes the dataset stored in the `puzzles.json` file in this directory. These files are generated from the `generators/*.py` files. The only import for puzzles is `from typing import List` but you should also pass a candidate solution -through `check_solution_type` from `puzzle_generator.py` before certifying correctness. +through `type_check` from `puzzle_generator.py` before certifying correctness. -## Puzzles by module: +## Puzzles by module: -- [study (30 problems, 30 instances)](#study) -- [classic_puzzles (22 problems, 130 instances)](#classic_puzzles) -- [human_eval (96 problems, 915 instances)](#human_eval) -- [codeforces (45 problems, 451 instances)](#codeforces) -- [algebra (4 problems, 40 instances)](#algebra) -- [basic (22 problems, 220 instances)](#basic) -- [chess (5 problems, 50 instances)](#chess) -- [compression (3 problems, 30 instances)](#compression) -- [conways_game_of_life (3 problems, 30 instances)](#conways_game_of_life) -- [games (5 problems, 16 instances)](#games) -- [game_theory (2 problems, 20 instances)](#game_theory) -- [graphs (12 problems, 93 instances)](#graphs) -- [ICPC (4 problems, 40 instances)](#icpc) -- [IMO (6 problems, 60 instances)](#imo) -- [lattices (2 problems, 20 instances)](#lattices) -- [number_theory (16 problems, 115 instances)](#number_theory) -- [probability (5 problems, 50 instances)](#probability) -- [trivial_inverse (39 problems, 372 instances)](#trivial_inverse) -- [tutorial (5 problems, 5 instances)](#tutorial) +- [study.py](../generators/study.py), [30 problems](#study): Puzzles used in our user study (the user study didn't have docstrings), see [Programming Puzzles](https://arxiv.org/abs/2106.05784) +- [classic_puzzles.py](../generators/classic_puzzles.py), [23 problems](#classic_puzzles): Classic puzzles +- [human_eval.py](../generators/human_eval.py), [164 problems](#human_eval): Problems inspired by [HumanEval dataset](https://github.com/openai/human-eval) described +in the [codex paper](https://arxiv.org/abs/2107.03374), specifically, +[this](https://github.com/openai/human-eval/blob/fa06031e684fbe1ee429c7433809460c159b66ad/data/HumanEval.jsonl.gz) +version released 7/7/21 +- [codeforces.py](../generators/codeforces.py), [47 problems](#codeforces): Problems inspired by the popular programming competition site [codeforces.com](https://codeforces.com) +- [algebra.py](../generators/algebra.py), [4 problems](#algebra): Roots of polynomials +- [basic.py](../generators/basic.py), [23 problems](#basic): Problems testing basic knowledge -- easy to solve if you understand what is being asked +- [chess.py](../generators/chess.py), [5 problems](#chess): Classic chess puzzles +- [compression.py](../generators/compression.py), [2 problems](#compression): Puzzles relating to de/compression +- [conways_game_of_life.py](../generators/conways_game_of_life.py), [3 problems](#conways_game_of_life): Conway's Game of Life problems (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) +- [games.py](../generators/games.py), [7 problems](#games): Some two-player game problems and hard game theory problems +- [graphs.py](../generators/graphs.py), [12 problems](#graphs): Problems related to graphs such as Conway's 99 problem, finding +[cliques](https://en.wikipedia.org/wiki/Clique_(graph_theory)) of various sizes, shortest path (Dijkstra) +- [ICPC.py](../generators/ICPC.py), [4 problems](#icpc): Problems inspired by the [International Collegiate Programming Contest](https://icpc.global) (ICPC) +- [IMO.py](../generators/IMO.py), [6 problems](#imo): Problems inspired by the +[International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) +[problems](https://www.imo-official.org/problems.aspx) +- [lattices.py](../generators/lattices.py), [2 problems](#lattices): Lattice problems with and without noise +- [number_theory.py](../generators/number_theory.py), [16 problems](#number_theory): Number theory problems +- [probability.py](../generators/probability.py), [5 problems](#probability): Probability problems +- [trivial_inverse.py](../generators/trivial_inverse.py), [39 problems](#trivial_inverse): Trivial problems. Typically for any function, you can construct a trivial example. +For instance, for the len function you can ask for a string of len(s)==100 etc +- [tutorial.py](../generators/tutorial.py), [5 problems](#tutorial): A few example puzzles that were presented with solutions to participants of the study -Total (326 problems, 2,687 instances) +Total (397 problems, 1,715 instances) ---- -## study - - -Puzzles used for the study. - - -### Study_1 - - -```python -def sat(s: str): - """Find a string with 1000 'o's but no two adjacent 'o's.""" - return s.count('o') == 1000 and s.count('oo') == 0 -``` -
1 solution to study 1/30 - -```python -def sol(): - return ('h' + 'o') * 1000 -``` - -
- -### Study_2 - - -```python -def sat(s: str): - """Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.""" - return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801 -``` -
1 solution to study 2/30 - -```python -def sol(): - return 'ho' * (800 + 1) + 'o' * (100 * 2 - 1) -``` - -
- -### Study_3 - - -```python -def sat(li: List[int]): - """Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.""" - return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li))) -``` -
1 solution to study 3/30 - -```python -def sol(): - return [((i + 1) % 999) for i in range(999)] -``` - -
- -### Study_4 - - -```python -def sat(li: List[int]): - """Find a list of length 10 where the fourth element occurs exactly twice.""" - return len(li) == 10 and li.count(li[3]) == 2 -``` -
1 solution to study 4/30 - -```python -def sol(): - return list(range(10 // 2)) * 2 -``` - -
- -### Study_5 - - -```python -def sat(li: List[int]): - """Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.""" - return all([li.count(i) == i for i in range(10)]) -``` -
1 solution to study 5/30 - -```python -def sol(): - return [i for i in range(10) for j in range(i)] -``` +The puzzles in each module are sorted by percent of Codex correct solutions -
-### Study_6 +## study -```python -def sat(i: int): - """Find an integer greater than 10^10 which is 4 mod 123.""" - return i % 123 == 4 and i > 10 ** 10 -``` -
1 solution to study 6/30 - -```python -def sol(): - return 4 + 10 ** 10 + 123 - 10 ** 10 % 123 -``` - -
- -### Study_7 - - -```python -def sat(s: str): - """Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.""" - return str(8 ** 2888).count(s) > 8 and len(s) == 3 -``` -
1 solution to study 7/30 - -```python -def sol(): - s = str(8 ** 2888) - return max({s[i: i + 3] for i in range(len(s) - 2)}, key=lambda t: s.count(t)) -``` - -
- -### Study_8 - - -```python -def sat(ls: List[str]): - """Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.""" - return ls[1234] in ls[1235] and ls[1234] != ls[1235] -``` -
1 solution to study 8/30 - -```python -def sol(): - return [''] * 1235 + ['a'] -``` - -
- -### Study_9 +Puzzles used in our user study (the user study didn't have docstrings), see [Programming Puzzles](https://arxiv.org/abs/2106.05784). -```python -def sat(li: List[int]): - """ - Find a way to rearrange the letters in the pangram "The quick brown fox jumps over the lazy dog" to get - the pangram "The five boxing wizards jump quickly". The answer should be represented as a list of index - mappings. - """ - return ["The quick brown fox jumps over the lazy dog"[i] for i in li] == list( - "The five boxing wizards jump quickly") -``` -
1 solution to study 9/30 -```python -def sol(): - return ['The quick brown fox jumps over the lazy dog'.index(t) - for t in 'The five boxing wizards jump quickly'] -``` +* **Study_24** (1 instance) + + ```python + def sat(li: List[int]): + return li.count(17) == 3 and li.count(3) >= 2 + ``` +
31% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.""" + ``` + Shortest Codex solution: + ```python + + return [17,3]*3 + + ``` + Longest Codex solution: + ```python + + cnt17 = 0 + cnt3 = 0 + res = [] + for i in range(1000): + if cnt17==3 and cnt3>=2: + break + if i % 17 == 0: + cnt17 += 1 + res.append(17) + continue + if i % 3 == 0: + cnt3 += 1 + res.append(3) + continue + res.append(6) + return res + + ``` + Hand-written solution: + ```python + return [17] * 3 + [3] * 2 + ``` +
+ +* **Study_4** (1 instance) + + ```python + def sat(li: List[int]): + return len(li) == 10 and li.count(li[3]) == 2 + ``` +
13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of length 10 where the fourth element occurs exactly twice.""" + ``` + Shortest Codex solution: + ```python + + return list(range(5)) * 2 + + ``` + Longest Codex solution: + ```python + + # Guess something like [1,2,3,4,4,2,1,1,2,3]. + res = [1,2,3,4,4,2,1,1,2,3] + n = len(res) + while True: + n1 = res[0] + n2 = res[n//2] + n3 = res[n-1] + if n1 != n2 != n3 != n1: + return res + res = [n1] + [3] * n + [n1] + + ``` + Hand-written solution: + ```python + return list(range(10 // 2)) * 2 + ``` +
+ +* **Study_6** (1 instance) + + ```python + def sat(i: int): + return i % 123 == 4 and i > 10 ** 10 + ``` +
7.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer greater than 10^10 which is 4 mod 123.""" + ``` + Shortest Codex solution: + ```python + + return 2**62 + + ``` + Longest Codex solution: + ```python + + j = 172914846983555084 + while not sat(j): + j += 123 + n = 1 + while True: + y = int(j ** 0.5) + n += 2 + if y * y > j: + break + n += 1 + if y * y == j: + m = n + 1 + break + if y * y + 2 * n * y * int(n / int(y ** 0.5)) - 2 * n * n >= j: + m = n + 1 + break + j += m + return j + + ``` + Hand-written solution: + ```python + return 4 + 10 ** 10 + 123 - 10 ** 10 % 123 + ``` +
+ +* **Study_20** A more interesting version of this puzzle with a length constraint is ShortIntegerPath in graphs.py (1 instance) + + ```python + def sat(li: List[int]): + return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) + ``` +
5.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from + the previous one by one or is thrice the previous one. + """ + ``` + Shortest Codex solution: + ```python + + return [*range(128)] + + ``` + Longest Codex solution: + ```python + + return list(map(int, "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127".split())) + + ``` + Hand-written solution: + ```python + return [1, 3, 4, 12, 13, 14, 42, 126, 127] + ``` +
+ +* **Study_13** (1 instance) + + ```python + def sat(x: float): + return str(x - 3.1415).startswith("123.456") + ``` +
5.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.""" + ``` + Shortest Codex solution: + ```python + + return 123.456+3.1415 + ``` + Longest Codex solution: + ```python + + return 123.456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789 + 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 + + ``` + Hand-written solution: + ```python + return 123.456 + 3.1415 + ``` +
+ +* **Study_8** (1 instance) + + ```python + def sat(ls: List[str]): + return ls[1234] in ls[1235] and ls[1234] != ls[1235] + ``` +
5.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.""" + ``` + Shortest Codex solution: + ```python + + return ["a", "ab"] * 1236 + + ``` + Longest Codex solution: + ```python + + s = "If you can keep your head when all about you\n Are losing theirs and blaming it on you,\nIf you can trust yourself when all men doubt you,\n But make allowance for their doubting too;\nIf you can wait and not be tired by waiting,\n Or being lied about, don’t deal in lies,\nOr being hated, don’t give way to hating,\n And yet don’t look too good, nor talk too wise:" + return [s[i:j] for i in range(len(s)+1) for j in range(i+1, len(s)+1)] + ``` + Hand-written solution: + ```python + return [''] * 1235 + ['a'] + ``` +
+ +* **Study_16** (1 instance) + + ```python + def sat(s: str): + return float(s) + len(s) == 4.5 + ``` +
5.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a real number such that when you add the length of its decimal representation to it, you get 4.5. + Your answer should be the string form of the number in its decimal representation.""" + ``` + Shortest Codex solution: + ```python + + return "1.5" + ``` + Longest Codex solution: + ```python + + for i in range(100): + if float("0.{}".format("".join(str(i)) + "0")) + len("0.{}".format("".join(str(i)) + "0")) == 4.5: + return "0.{}".format("".join(str(i)) + "0") + raise Exception("g6 is buggy. Should've found in 100 repeats.") + + ``` + Hand-written solution: + ```python + return str(4.5 - len(str(4.5))) + ``` +
+ +* **Study_26** (1 instance) + + ```python + def sat(ls: List[str]): + return "".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls) + ``` +
3.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Divide the decimal representation of 8^88 up into strings of length eight.""" + ``` + Shortest Codex solution: + ```python + + return [str(8**88)[i:i+8] for i in range(0,80,8)] + + ``` + Longest Codex solution: + ```python + + def chunk_splitter(ls): + answer = [] + for i, s in enumerate(ls): + if i % 8 == 0: + if i != 0: + answer.append(a) + a = s + else: + a += s + answer.append(a) + return answer + return chunk_splitter(str(8 ** 88)) + + ``` + Hand-written solution: + ```python + return [str(8 ** 88)[i:i + 8] for i in range(0, len(str(8 ** 88)), 8)] + ``` +
+ +* **Study_28** 9/15/2021: updated to a list since sets were removed from puzzle formats (1 instance) + + ```python + def sat(li: List[int]): + return all(i in range(1000) and abs(i - j) >= 10 for i in li for j in li if i != j) and len(set(li)) == 100 + ``` +
2.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of one hundred integers between 0 and 999 which all differ by at least ten from one another.""" + ``` + Shortest Codex solution: + ```python + + return [*range(0, 1000, 10)] + + ``` + Longest Codex solution: + ```python + + def render(li): + return str(li)[1:-1].replace(" ","").replace(",","") + lis = [] + i = 0 + minimum = 0 + while len(lis) < 100: + if minimum >= 1000: + # TODO: Possibly another constraint? + minimum = 0 + j = 0 + while j < 1000: + if j >= minimum: + if all(abs(j - k) >= 10 for k in lis): + lis.append(j) + break + j += 1 + minimum = j + return lis + + ``` + Hand-written solution: + ```python + return list(range(0, 1000, 10)) + ``` +
+ +* **Study_14** (1 instance) + + ```python + def sat(li: List[int]): + return all([sum(li[:i]) == i for i in range(20)]) + ``` +
2.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.""" + ``` + Shortest Codex solution: + ```python + + return [1]*20 + + ``` + Longest Codex solution: + ```python + + def nums(start, depth): + if depth == 0: + yield [start] + return + for i in range(start, 10): + for j in nums(i, depth-1): + yield [i] + j + + for nums in nums(1, 20): + for i in range(10 ** (20 - 1)): + try: + return nums + [nums[-1] + 1 + i] + except: + break + raise Exception("not found") + + + ``` + Hand-written solution: + ```python + return [1] * 20 + ``` +
+ +* **Study_23** (1 instance) + + ```python + def sat(ls: List[str]): + return tuple(ls) in zip('dee', 'doo', 'dah!') + ``` +
2.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'. + """ + ``` + Shortest Codex solution: + ```python + + return ['d']*3 + + ``` + Longest Codex solution: + ```python + + result = [] + i = 0 + while True: + if i < len('dee'): + result.append('d') + elif i < len('dee'): + result.append('e') + elif i < len('dee'): + result.append('e') + else: + break + i += 1 + return result + + ``` + Hand-written solution: + ```python + return list(next(zip('dee', 'doo', 'dah!'))) + ``` +
+ +* **Study_15** (1 instance) + + ```python + def sat(li: List[int]): + return all(sum(li[:i]) == 2 ** i - 1 for i in range(20)) + ``` +
1.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.""" + ``` + Shortest Codex solution: + ```python + + return [2**i for i in range(20)] + ``` + Longest Codex solution: + ```python + + s = sum([i > 1 and i <= 20 and (sum(range(1, i)) == 2 ** i - 1) for i in range(20)]) + return [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648] + + + ``` + Hand-written solution: + ```python + return [(2 ** i) for i in range(20)] + ``` +
+ +* **Study_11** (1 instance) + + ```python + def sat(ls: List[str]): + return min(ls) == max(ls) == str(len(ls)) + ``` +
1.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element + and is equal to the lexicographically smallest element. + """ + ``` + Shortest Codex solution: + ```python + + return ["1"] + + ``` + Longest Codex solution: + ```python + + count = 1 + while True: + for n in range(count, count + 2): + word = str(n) * count + if (word == word[::-1]): + res = [word] * count + res.sort() + return res + count += 1 + + ``` + Hand-written solution: + ```python + return ['1'] + ``` +
+ +* **Study_21** (1 instance) + + ```python + def sat(li: List[int]): + return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3 + ``` +
1.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list integers containing exactly three distinct values, such that no integer repeats + twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.) + """ + ``` + Shortest Codex solution: + ```python + + return [1,2,3]*4 + + ``` + Longest Codex solution: + ```python + + items = [i for i in range(3)] + result = items.copy() + while len(result) < 11: + next_item = min(set(items).difference(result[-2:]), key=lambda x: abs(x - result[-1])) + result.append(next_item) + return result[:12] + + ``` + Hand-written solution: + ```python + return list(range(3)) * 10 + ``` +
+ +* **Study_5** (1 instance) + + ```python + def sat(li: List[int]): + return all([li.count(i) == i for i in range(10)]) + ``` +
1.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.""" + ``` + Shortest Codex solution: + ```python + + return sum([[x]*x for x in range(10)], []) + + ``` + Longest Codex solution: + ```python + + res = [1] + counts = [] + while sum(res) < 20: + while res[-1] == 9: + new = res[-1]*res[-2] + res = res[:-2] + [new] + res = res + [res[-1] + 1] + counts = counts + [len([i for i in res if i == j]) for j in range(len(counts), 10)] + return [i for i in range(0, 10) for j in range(i)] + + ``` + Hand-written solution: + ```python + return [i for i in range(10) for j in range(i)] + ``` +
+ +* **Study_18** (1 instance) + + ```python + def sat(ls: List[str]): + return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split() + ``` +
1.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of strings that when you combine them in all pairwise combinations gives the six strings: + 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin' + """ + ``` + Shortest Codex solution: + ```python + + return ['ber','lin','ger'] + ``` + Longest Codex solution: + ```python + + return ["ber", "lin", "ger"] # not at all guaranteed to be short + + ``` + Hand-written solution: + ```python + seen = set() + ans = [] + for s in 'berlin berger linber linger gerber gerlin'.split(): + t = s[:3] + if t not in seen: + ans.append(t) + seen.add(t) + return ans + ``` +
+ +* **Study_3** (1 instance) + + ```python + def sat(li: List[int]): + return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li))) + ``` +
1.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.""" + ``` + Shortest Codex solution: + ```python + + return [*range(1, 999), 0] + + ``` + Longest Codex solution: + ```python + + def per(li: List[int]): + if len(li) == 1: + return li + elif li == []: + return [] + else: + ma = max(li) + mi = min(li) + _li = li.copy() + _li.remove(ma) + _li.remove(mi) + return [ma] + [mi] + per(_li) + return per(list(range(0, 999))) + + ``` + Hand-written solution: + ```python + return [((i + 1) % 999) for i in range(999)] + ``` +
+ +* **Study_27** (1 instance) + + ```python + def sat(li: List[int]): + return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]] + ``` +
0.79% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and + v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they + share the same great-grandchildren. Represented this digraph by the list of children indices. + """ + ``` + Shortest Codex solution: + ```python + + return [1, -1, 2] + + ``` + Longest Codex solution: + ```python + + # Here is an example with N=7 + # 0 1 2 + # / | | + # 1 -- 2 3 + # /\ | + # 2 3 4 -- 4 + # We want the adjacency list representation to be + # [[1], [2], [], [2, 3], [4], [4, 5], [4]] + return [1, 2, 3, 3, 4, 5, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5] + + ``` + Hand-written solution: + ```python + return [1, 2, 3, 3] + ``` +
+ +* **Study_9** (1 instance) + + ```python + def sat(li: List[int]): + return ["The quick brown fox jumps over the lazy dog"[i] for i in li] == list( + "The five boxing wizards jump quickly") + ``` +
0.75% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a way to rearrange the letters in the pangram "The quick brown fox jumps over the lazy dog" to get + the pangram "The five boxing wizards jump quickly". The answer should be represented as a list of index + mappings. + """ + ``` + Shortest Codex solution: + ```python + + return ["The quick brown fox jumps over the lazy dog".index(i) for i in "The five boxing wizards jump quickly"] + + ``` + Longest Codex solution: + ```python + + ans = [] + for char in "The five boxing wizards jump quickly": + found = False + for i, l in enumerate(list("The quick brown fox jumps over the lazy dog")): + if l == char: + found = True + ans.append(i) + break + if found: + continue + for i in range(26): + if chr(i + 97) == char: + found = True + ans.append(i) + break + if not found: + ans.append(-1) + return ans + + ``` + Hand-written solution: + ```python + return ['The quick brown fox jumps over the lazy dog'.index(t) + for t in 'The five boxing wizards jump quickly'] + ``` +
+ +* **Study_30** (1 instance) + + ```python + def sat(li: List[int]): + return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)]) + ``` +
0.4% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one + are between 0 and 999, inclusive, and are strictly increasing in terms of f(n). + """ + ``` + Shortest Codex solution: + ```python + + return [122 * i % 1000 for i in range(121)] + + ``` + Longest Codex solution: + ```python + + def sat(n): + return 123 * n % 1000 + res = dict() + for i in range(1000): + fres = sat(i) + if fres not in res.keys(): + res[fres] = [i] + else: + res[fres] += [i] + min_index = min(res.keys()) + min_list = res[min_index] + li = [] + while True: + li += min_list + min_index += 1 + if min_index not in res.keys(): + return li + min_list = res[min_index] + ``` + Hand-written solution: + ```python + return sorted(range(1000), key=lambda n: 123 * n % 1000)[:21] + ``` + Hand-written solution: + ```python + return list(range(1000))[::8][::-1] + ``` +
+ +* **Study_1** (1 instance) + + ```python + def sat(s: str): + return s.count('o') == 1000 and s.count('oo') == 0 + ``` +
0.33% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with 1000 'o's but no two adjacent 'o's.""" + ``` + Shortest Codex solution: + ```python + + return "bo"*1000 + + ``` + Longest Codex solution: + ```python + + alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + s = "" + for i, letter in enumerate(alphabet): + if i % 2 == 0: + s += alphabet[(i+1000) % len(alphabet)] + else: + s += letter + return s * 1000 + + ``` + Hand-written solution: + ```python + return ('h' + 'o') * 1000 + ``` +
+ +* **Study_7** (1 instance) + + ```python + def sat(s: str): + return str(8 ** 2888).count(s) > 8 and len(s) == 3 + ``` +
0.29% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.""" + ``` + Shortest Codex solution: + ```python + + return "672" + + ``` + Longest Codex solution: + ```python + + best = "000" + count = 0 + for c in range(10): + for b in range(10): + for a in range(10): + pat = str(a)+str(b)+str(c) + if str(8 ** 2888).count(pat) > 8: + count += 1 + if count > 8: + raise RuntimeError(f"found {pat} after {best}") + else: + best = pat + return best + + ``` + Hand-written solution: + ```python + s = str(8 ** 2888) + return max({s[i: i + 3] for i in range(len(s) - 2)}, key=lambda t: s.count(t)) + ``` +
+ +* **Study_29** 9/15/2021: updated to a list since sets were removed from puzzle formats (1 instance) + + ```python + def sat(l: List[int]): + return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in l for j in l if i != j) and len(set(l)) > 995 + ``` +
0.087% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of more than 995 distinct integers between 0 and 999, inclusive, such that each pair of integers + have squares that differ by at least 10. + """ + ``` + Shortest Codex solution: + ```python + + return [0] + [i for i in range(1, 1000) if abs(i * i - (i + 1) * (i + 1)) >= 10] + + ``` + Longest Codex solution: + ```python + + for i in range(1000): + for j in range(1000): + if i != j and i*i != j*j and abs((i ** 2) - (j ** 2)) >= 10: + l = [i, j] + for i in range(1000): + if i not in l: + if abs(i*i - l[0]*l[0]) >= 10 and abs(i*i - l[1]*l[1]) >= 10: + l.append(i) + return l + + ``` + Hand-written solution: + ```python + return [0, 4] + list(range(6, 1000)) + ``` +
+ +* **Study_17** (1 instance) + + ```python + def sat(i: int): + return len(str(i + 1000)) > len(str(i + 1001)) + ``` +
0.083% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.""" + ``` + Shortest Codex solution: + ```python + + return 0 - 1010 + + ``` + Longest Codex solution: + ```python + + i = 0 + # Work upwards from 1 + while sat(i): + i += 1 + # Work downwards from the current number + while not sat(i): + i -= 1 + return i + + ``` + Hand-written solution: + ```python + return -1001 + ``` +
+ +* **Study_2** (1 instance) + + ```python + def sat(s: str): + return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801 + ``` +
0.077% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.""" + ``` + Shortest Codex solution: + ```python + + return "ho"*801 + "oo"*99 + "o" + + ``` + Longest Codex solution: + ```python + + s = "ho"*801 + "o"*1000 + while not sat(s): + s = s[:len(s)-5] + s[len(s)-5:].replace("oo", "o", 1) + return s + + ``` + Hand-written solution: + ```python + return 'ho' * (800 + 1) + 'o' * (100 * 2 - 1) + ``` +
+ +* **Study_19** 9/15/2021 Updated to take a list rather than a set because it was the only puzzle in the repo with Set argument. (1 instance) + + ```python + def sat(li: List[int]): + return {i + j for i in li for j in li} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34} + ``` +
0.057% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}. + That is find L such that, { i + j | i, j in L } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}. + """ + ``` + Shortest Codex solution: + ```python + + return [0, 1, 2, 3, 17] + + ``` + Longest Codex solution: + ```python + + return [i for i in [0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34] if (i + i) in [0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34]] + + ``` + Hand-written solution: + ```python + return [0, 1, 2, 3, 17] + ``` +
+ +* **Study_10** (1 instance) + + ```python + def sat(s: str): + return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11 + ``` +
0.053% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a palindrome of length greater than 11 in the decimal representation of 8^1818.""" + ``` + Shortest Codex solution: + ```python + + s = str(8 ** 1818) + for i in range(len(s) - 12): + if s[i:i+13] == s[i:i+13][::-1]: + return s[i:i+13] + + ``` + Longest Codex solution: + ```python + + multiplier = 1 + while True: + number = str(8**1818 * multiplier) + for i in range(4, len(number)): + for j in range(3, i + 1): + if number[i-j:i] == number[i-j:i][::-1] and j > 11: + return number[i-j:i] + multiplier += 1 + + ``` + Hand-written solution: + ```python + s = str(8 ** 1818) + return next(s[i: i + le] + for le in range(12, len(s) + 1) + for i in range(len(s) - le + 1) + if s[i: i + le] == s[i: i + le][::-1] + ) + ``` +
+ +* **Study_22** (1 instance) + + ```python + def sat(s: str): + return s[::2] in s and len(set(s)) == 5 + ``` +
0.01% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string s containing exactly five distinct characters which also contains as a substring every other + character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs'). + """ + ``` + Shortest Codex solution: + ```python + + return 'aarootooth' + + ``` + Longest Codex solution: + ```python + + for x in "abcdefghijklmnopqrstuvwxyz": + if "i" != x and "o" != x and "j" != x and "q" != x and "u" != x: + if sat("parrotfish".replace("p", x).replace("r", x).replace("t", x).replace("f", x).replace("s", x)): + return "parrotfish".replace("p", x).replace("r", x).replace("t", x).replace("f", x).replace("s", x) + + ``` + Hand-written solution: + ```python + return """abacadaeaaaaaaaaaa""" + ``` +
+ +* **Study_12** (1 instance) + + ```python + def sat(li: List[int]): + return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000 + ``` +
0.0067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first + integer plus 4 is 9.""" + ``` + Shortest Codex solution: + ```python + + li = [4] * 1000 + for i in range(500): + li[2*i] = 9 - li[2*i-1] + return li + + ``` + Longest Codex solution: + ```python + + li = [5] + while len(li) < 1000: + new_5s = min(9 - (li[-1] + 4), min(1 + li[-1], len(li))) + li += [5] * new_5s + li.append(4) + return li + + ``` + Hand-written solution: + ```python + return [9 - 4, 4] * (1000 // 2) + ``` +
+ +* **Study_25** (1 instance) + + ```python + def sat(s: str): + return sorted(s) == sorted('Permute me true') and s == s[::-1] + ``` +
0.0033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a permutation of the string 'Permute me true' which is a palindrome.""" + ``` + Codex solution: + ```python + + def perms(s): + if len(s) <= 1: yield s + else: + for p in perms(s[1:]): + for i in range(len(s)): + yield p[:i] + s[0:1] + p[i:] + + return "".join(next(x for x in perms('Permute me true') if x == x[::-1])) + + ``` + Hand-written solution: + ```python + s = sorted('Permute me true'[1:])[::2] + return "".join(s + ['P'] + s[::-1]) + ``` +
+ +## classic_puzzles -
+Classic puzzles -### Study_10 - - -```python -def sat(s: str): - """Find a palindrome of length greater than 11 in the decimal representation of 8^1818.""" - return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11 -``` -
1 solution to study 10/30 - -```python -def sol(): - s = str(8 ** 1818) - return next(s[i: i + le] - for le in range(12, len(s) + 1) - for i in range(len(s) - le + 1) - if s[i: i + le] == s[i: i + le][::-1] - ) -``` - -
- -### Study_11 - - -```python -def sat(ls: List[str]): - """ - Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element - and is equal to the lexicographically smallest element. - """ - return min(ls) == max(ls) == str(len(ls)) -``` -
1 solution to study 11/30 - -```python -def sol(): - return ['1'] -``` - -
- -### Study_12 - - -```python -def sat(li: List[int]): - """Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first - integer plus 4 is 9.""" - return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000 -``` -
1 solution to study 12/30 - -```python -def sol(): - return [9 - 4, 4] * (1000 // 2) -``` - -
- -### Study_13 - - -```python -def sat(x: float): - """Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.""" - return str(x - 3.1415).startswith("123.456") -``` -
1 solution to study 13/30 - -```python -def sol(): - return 123.456 + 3.1415 -``` - -
- -### Study_14 - - -```python -def sat(li: List[int]): - """Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.""" - return all([sum(li[:i]) == i for i in range(20)]) -``` -
1 solution to study 14/30 - -```python -def sol(): - return [1] * 20 -``` - -
- -### Study_15 - - -```python -def sat(li: List[int]): - """Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.""" - return all(sum(li[:i]) == 2 ** i - 1 for i in range(20)) -``` -
1 solution to study 15/30 - -```python -def sol(): - return [(2 ** i) for i in range(20)] -``` - -
- -### Study_16 - - -```python -def sat(s: str): - """Find a real number such that when you add the length of its decimal representation to it, you get 4.5. - Your answer should be the string form of the number in its decimal representation.""" - return float(s) + len(s) == 4.5 -``` -
1 solution to study 16/30 - -```python -def sol(): - return str(4.5 - len(str(4.5))) -``` - -
- -### Study_17 - - -```python -def sat(i: int): - """Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.""" - return len(str(i + 1000)) > len(str(i + 1001)) -``` -
1 solution to study 17/30 - -```python -def sol(): - return -1001 -``` - -
- -### Study_18 - - -```python -def sat(ls: List[str]): - """ - Find a list of strings that when you combine them in all pairwise combinations gives the six strings: - 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin' - """ - return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split() -``` -
1 solution to study 18/30 - -```python -def sol(): - seen = set() - ans = [] - for s in 'berlin berger linber linger gerber gerlin'.split(): - t = s[:3] - if t not in seen: - ans.append(t) - seen.add(t) - return ans -``` - -
- -### Study_19 -9/15/2021 Updated to take a list rather than a set because it was the only puzzle in the repo with Set argument. - -```python -def sat(li: List[int]): - """ - Find a list of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}. - That is find L such that, { i + j | i, j in L } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}. - """ - return {i + j for i in li for j in li} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34} -``` -
1 solution to study 19/30 - -```python -def sol(): - return [0, 1, 2, 3, 17] -``` - -
- -### Study_20 -A more interesting version of this puzzle with a length constraint is ShortIntegerPath in graphs.py - -```python -def sat(li: List[int]): - """ - Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from - the previous one by one or is thrice the previous one. - """ - return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) -``` -
1 solution to study 20/30 - -```python -def sol(): - return [1, 3, 4, 12, 13, 14, 42, 126, 127] -``` - -
- -### Study_21 - - -```python -def sat(li: List[int]): - """ - Find a list integers containing exactly three distinct values, such that no integer repeats - twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.) - """ - return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3 -``` -
1 solution to study 21/30 - -```python -def sol(): - return list(range(3)) * 10 -``` - -
- -### Study_22 - - -```python -def sat(s: str): - """ - Find a string s containing exactly five distinct characters which also contains as a substring every other - character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs'). - """ - return s[::2] in s and len(set(s)) == 5 -``` -
1 solution to study 22/30 - -```python -def sol(): - return """abacadaeaaaaaaaaaa""" -``` - -
- -### Study_23 - - -```python -def sat(ls: List[str]): - """ - Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'. - """ - return tuple(ls) in zip('dee', 'doo', 'dah!') -``` -
1 solution to study 23/30 - -```python -def sol(): - return list(next(zip('dee', 'doo', 'dah!'))) -``` - -
- -### Study_24 - - -```python -def sat(li: List[int]): - """Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.""" - return li.count(17) == 3 and li.count(3) >= 2 -``` -
1 solution to study 24/30 - -```python -def sol(): - return [17] * 3 + [3] * 2 -``` - -
- -### Study_25 - - -```python -def sat(s: str): - """Find a permutation of the string 'Permute me true' which is a palindrome.""" - return sorted(s) == sorted('Permute me true') and s == s[::-1] -``` -
1 solution to study 25/30 - -```python -def sol(): - s = sorted('Permute me true'[1:])[::2] - return "".join(s + ['P'] + s[::-1]) -``` - -
- -### Study_26 - - -```python -def sat(ls: List[str]): - """Divide the decimal representation of 8^88 up into strings of length eight.""" - return "".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls) -``` -
1 solution to study 26/30 - -```python -def sol(): - return [str(8 ** 88)[i:i + 8] for i in range(0, len(str(8 ** 88)), 8)] -``` - -
- -### Study_27 - - -```python -def sat(li: List[int]): - """ - Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and - v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they - share the same great-grandchildren. Represented this digraph by the list of children indices. - """ - return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]] -``` -
1 solution to study 27/30 - -```python -def sol(): - return [1, 2, 3, 3] -``` - -
- -### Study_28 -9/15/2021: updated to a list since sets were removed from puzzle formats - -```python -def sat(li: List[int]): - """Find a list of one hundred integers between 0 and 999 which all differ by at least ten from one another.""" - return all(i in range(1000) and abs(i - j) >= 10 for i in li for j in li if i != j) and len(set(li)) == 100 -``` -
1 solution to study 28/30 - -```python -def sol(): - return list(range(0, 1000, 10)) -``` - -
- -### Study_29 -9/15/2021: updated to a list since sets were removed from puzzle formats - -```python -def sat(l: List[int]): - """ - Find a list of more than 995 distinct integers between 0 and 999, inclusive, such that each pair of integers - have squares that differ by at least 10. - """ - return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in l for j in l if i != j) and len(set(l)) > 995 -``` -
1 solution to study 29/30 - -```python -def sol(): - return [0, 4] + list(range(6, 1000)) -``` - -
- -### Study_30 - - -```python -def sat(li: List[int]): - """ - Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one - are between 0 and 999, inclusive, and are strictly increasing in terms of f(n). - """ - return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)]) -``` -
2 solutions to study 30/30 - -```python -def sol(): - return sorted(range(1000), key=lambda n: 123 * n % 1000)[:21] -``` - -
- -```python -def sol(): - return list(range(1000))[::8][::-1] -``` - - - -## classic_puzzles - -Classic puzzles - - -### TowersOfHanoi -[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi) - -In this classic version one must move all 8 disks from the first to third peg. - -```python -def sat(moves: List[List[int]]): - """ - Eight disks of sizes 1-8 are stacked on three towers, with each tower having disks in order of largest to - smallest. Move [i, j] corresponds to taking the smallest disk off tower i and putting it on tower j, and it - is legal as long as the towers remain in sorted order. Find a sequence of moves that moves all the disks - from the first to last towers. - """ - rods = ([8, 7, 6, 5, 4, 3, 2, 1], [], []) - for [i, j] in moves: - rods[j].append(rods[i].pop()) - assert rods[j][-1] == min(rods[j]), "larger disk on top of smaller disk" - return rods[0] == rods[1] == [] -``` -
1 solution to classic_puzzles 1/22 - -```python -def sol(): - def helper(m, i, j): - if m == 0: - return [] - k = 3 - i - j - return helper(m - 1, i, k) + [[i, j]] + helper(m - 1, k, j) - - return helper(8, 0, 2) -``` - -
- -### TowersOfHanoiArbitrary -[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi) - -In this version one must transform a given source state to a target state. - -```python -def sat(moves: List[List[int]], source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]): - """ - A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in - {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the - order of list j. Find a sequence of moves that transform the given source to target states. - """ - state = [s[:] for s in source] - - for [i, j] in moves: - state[j].append(state[i].pop()) - assert state[j] == sorted(state[j]) - - return state == target -``` -
1 solution to classic_puzzles 2/22 - -```python -def sol(source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]): - state = {d: i for i, tower in enumerate(source) for d in tower} - final = {d: i for i, tower in enumerate(target) for d in tower} - disks = set(state) - assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3 - ans = [] - - def move(d, i): # move disk d to tower i - if state[d] == i: - return - for t in range(3): # first tower besides i, state[d] - if t != i and t != state[d]: - break - for d2 in range(d + 1, max(disks) + 1): - if d2 in disks: - move(d2, t) - ans.append([state[d], i]) - state[d] = i - - for d in range(min(disks), max(disks) + 1): - if d in disks: - move(d, final[d]) - - return ans -``` - -
- -### LongestMonotonicSubstring -This is a form of the classic -[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem -where the goal is to find a substring with characters in sorted order. - -```python -def sat(x: List[int], length=13, s="Dynamic programming solves this puzzle!!!"): - """ - Remove as few characters as possible from s so that the characters of the remaining string are alphebetical. - Here x is the list of string indices that have not been deleted. - """ - return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1)) -``` -
1 solution to classic_puzzles 3/22 - -```python -def sol(length=13, s="Dynamic programming solves this puzzle!!!"): # O(N^2) method. Todo: add binary search solution which is O(n log n) - if s == "": - return [] - n = len(s) - dyn = [] # list of (seq length, seq end, prev index) - for i in range(n): - try: - dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i])) - except ValueError: - dyn.append((1, i, -1)) # sequence ends at i - _length, i, _ = max(dyn) - backwards = [i] - while dyn[i][2] != -1: - i = dyn[i][2] - backwards.append(i) - return backwards[::-1] -``` - -
- -### LongestMonotonicSubstringTricky -The same as the above problem, but with a twist! - -```python -def sat(x: List[int], length=20, s="Dynamic programming solves this classic job-interview puzzle!!!"): - """Find the indices of the longest substring with characters in sorted order""" - return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1)) -``` -
1 solution to classic_puzzles 4/22 - -```python -def sol(length=20, s="Dynamic programming solves this classic job-interview puzzle!!!"): # O(N^2) method. Todo: add binary search solution which is O(n log n) - if s == "": - return [] - n = len(s) - dyn = [] # list of (seq length, seq end, prev index) - for i in range(-n, n): - try: - dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i])) - except ValueError: - dyn.append((1, i, None)) # sequence ends at i - _length, i, _ = max(dyn) - backwards = [i] - while dyn[n + i][2] is not None: - i = dyn[n + i][2] - backwards.append(i) - return backwards[::-1] -``` - -
- -### Quine -[Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29) - -```python -def sat(quine: str): - """Find a string that when evaluated as a Python expression is that string itself.""" - return eval(quine) == quine -``` -
2 solutions to classic_puzzles 5/22 - -```python -def sol(): - return "(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\")" -``` - -
- -```python -def sol(): # thanks for this simple solution, GPT-3! - return 'quine' -``` - - - -### RevQuine -Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3. - -```python -def sat(rev_quine: str): - """Find a string that, when reversed and evaluated gives you back that same string.""" - return eval(rev_quine[::-1]) == rev_quine -``` -
1 solution to classic_puzzles 6/22 - -```python -def sol(): - return "rev_quine"[::-1] # thanks GPT-3! -``` - -
- -### BooleanPythagoreanTriples -[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem) - -```python -def sat(colors: List[int], n=100): - """ - Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple. - A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that - are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n. - """ - assert set(colors) <= {0, 1} and len(colors) >= n - squares = {i ** 2: colors[i] for i in range(1, len(colors))} - return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items()) -``` -
1 solution to classic_puzzles 7/22 - -```python -def sol(n=100): - sqrt = {i * i: i for i in range(1, n)} - trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt] - import random - random.seed(0) - sol = [random.randrange(2) for _ in range(n)] - done = False - while not done: - done = True - random.shuffle(trips) - for i, j, k in trips: - if sol[i] == sol[j] == sol[k]: - done = False - sol[random.choice([i, j, k])] = 1 - sol[i] - return sol -``` - -
- -### ClockAngle -[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant - -```python -def sat(hands: List[int], target_angle=45): - """Find clock hands = [hour, min] such that the angle is target_angle degrees.""" - hour, min = hands - return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle -``` -
1 solution to classic_puzzles 8/22 - -```python -def sol(target_angle=45): - for hour in range(1, 13): - for min in range(60): - if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle: - return [hour, min] -``` - -
- -### Kirkman -[Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem) - -```python -def sat(daygroups: List[List[List[int]]]): - """ - Arrange 15 people into groups of 3 each day for seven days so that no two people are in the same group twice. - """ - assert len(daygroups) == 7 - assert all(len(groups) == 5 and {i for g in groups for i in g} == set(range(15)) for groups in daygroups) - assert all(len(g) == 3 for groups in daygroups for g in groups) - return len({(i, j) for groups in daygroups for g in groups for i in g for j in g}) == 15 * 15 -``` -
1 solution to classic_puzzles 9/22 - -```python -def sol(): - from itertools import combinations - import random - rand = random.Random(0) - days = [[list(range(15)) for _2 in range(2)] for _ in range(7)] # each day is pi, inv - counts = {(i, j): (7 if j in range(k, k + 3) else 0) - for k in range(0, 15, 3) - for i in range(k, k + 3) - for j in range(15) if j != i - } - - todos = [pair for pair, count in counts.items() if count == 0] - while True: - pair = rand.choice(todos) # choose i and j to make next to each other on some day - if rand.randrange(2): - pair = pair[::-1] - - a, u = pair - pi, inv = rand.choice(days) - assert pi[inv[a]] == a and pi[inv[u]] == u - bases = [3 * (inv[i] // 3) for i in pair] - (b, c), (v, w) = [[x for x in pi[b: b + 3] if x != i] for i, b in zip(pair, bases)] - if rand.randrange(2): - b, c, = c, b - # current (a, b, c) (u, v, w). consider swap of u with b to make (a, u, c) (b, v, w) - - new_pairs = [(a, u), (c, u), (b, v), (b, w)] - old_pairs = [(u, v), (u, w), (b, a), (b, c)] - gained = sum(counts[p] == 0 for p in new_pairs) - lost = sum(counts[p] == 1 for p in old_pairs) - if rand.random() <= 100 ** (gained - lost): - for p in new_pairs: - counts[p] += 1 - counts[p[::-1]] += 1 - for p in old_pairs: - counts[p] -= 1 - counts[p[::-1]] -= 1 - pi[inv[b]], pi[inv[u]], inv[b], inv[u] = u, b, inv[u], inv[b] - todos = [pair for pair, count in counts.items() if count == 0] - if len(todos) == 0: - return [[pi[k:k + 3] for k in range(0, 15, 3)] for pi, _inv in days] -``` - -
- -### MonkeyAndCoconuts -[The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts) - -```python -def sat(n: int): - """ - Find the number of coconuts to solve the following riddle: - There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the - one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the - procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and - fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey. - Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over. - How many coconuts were there in the original pile? - Quoted from https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts - """ - for i in range(5): - assert n % 5 == 1 - n -= 1 + (n - 1) // 5 - return n > 0 and n % 5 == 1 -``` -
1 solution to classic_puzzles 10/22 - -```python -def sol(): - m = 1 - while True: - n = m +* **NecklaceSplit** [Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem) (5 instances) + + ```python + def sat(n: int, lace="bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb"): + sub = lace[n: n + len(lace) // 2] + return n >= 0 and lace.count("r") == 2 * sub.count("r") and lace.count("b") == 2 * sub.count("b") + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(lace="bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of + reds and blues. + """ + ``` + Shortest Codex solution: + ```python + + return len(lace) // 2-1 + + ``` + Longest Codex solution: + ```python + + def probe(): + """Finds split of length starting at start so that each piece has an equal number of red and blue beads.""" + start, mid = len(lace) // 2 - length // 2, len(lace) // 2 + length // 2 + while mid < len(lace): + if sat(start, lace): + return start + if sat(mid, lace): + return mid + start += 1 + mid += 1 + raise ValueError + + length = 1 + while length < len(lace): + try: + return probe() + except ValueError: + length += 1 + raise ValueError + + ``` + Hand-written solution: + ```python + if lace == "": + return 0 + return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count("r") == len(lace) // 4) + ``` +
+ +* **ClockAngle** [Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant (5 instances) + + ```python + def sat(hands: List[int], target_angle=45): + h, m = hands + assert 0 < h <= 12 and 0 <= m < 60 + hour_angle = 30 * h + m / 2 + minute_angle = 6 * m + return abs(hour_angle - minute_angle) in [target_angle, 360 - target_angle] + ``` +
6.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target_angle=45): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find clock hands = [hour, min] such that the angle is target_angle degrees.""" + ``` + Shortest Codex solution: + ```python + + return [7,30] + + ``` + Longest Codex solution: + ```python + + assert 0 < target_angle <= 360 + # we could look for each hour separately, then try each minute separately, or try each minute once, then each hour once. + # we just try every minute and hour and see if we find one that fits, and return that. + # we could also try and look for each hour multiple times and each minute once, and if we hit the target, we stop. + for m in range(60): + for h in range(1, 13): + if abs(h * 30 + m / 2 - m * 6) == target_angle: + return [h, m] + raise ValueError("No solution") + ``` + Hand-written solution: + ```python + for h in range(1, 13): + for m in range(60): + hour_angle = 30 * h + m / 2 + minute_angle = 6 * m + if abs(hour_angle - minute_angle) % 360 in [target_angle, 360 - target_angle]: + return [h, m] + ``` +
+ +* **Quine** [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29) (1 instance) + + ```python + def sat(quine: str): + return eval(quine) == quine + ``` +
2.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that when evaluated as a Python expression is that string itself.""" + ``` + Shortest Codex solution: + ```python + + return "quine" + ``` + Longest Codex solution: + ```python + + # You cannot directly find this string, so you must work backwards by reversing your equation for the goal + # Hint: use https://www.symbolab.com/solver/step-by-step/%5Csum_%7Bi%3D0%7D%5E%7Bn%7Di%5Csqrt5 + return "quine" + + ``` + Hand-written solution: + ```python + return "(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\")" + ``` +
+ +* **PandigitalSquare** [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square (1 instance) + + ```python + def sat(n: int): + s = str(n * n) + for i in "0123456789": + assert s.count(i) == 1 + return True + ``` +
0.51% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer whose square has all digits 0-9 once.""" + ``` + Shortest Codex solution: + ```python + + n = 1 + while len(set(str(n * n))) < 10: + n += 1 + return n + + ``` + Longest Codex solution: + ```python + + n = 0 + while True: + # On average, Python will optimize this loop by not iterating over + # all the digits of the number n * n to be checked, so it's + # likely that s will contain fewer digits than it could, + # resulting in a different algorithm. + s = str(n * n) + for i in "0123456789": + if s.count(i) != 1: + n += 1 + break + else: + return n + n += 1 + + ``` + Hand-written solution: + ```python + for n in range(10 ** 5): + if sorted([int(s) for s in str(n * n)]) == list(range(10)): + return n + ``` +
+ +* **Easy63** An easy puzzle to make 63 using two 8's and one 1's. (1 instance) + + ```python + def sat(s: str): + return set(s) <= set("18-+*/") and s.count("8") == 2 and s.count("1") == 1 and eval(s) == 63 + ``` +
0.25% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a formula using two 8s and two 1's and -+*/ that evaluates to 1.""" + ``` + Shortest Codex solution: + ```python + + return "8*8-1" + + ``` + Longest Codex solution: + ```python + + r = [] + for i in "123456789": + for j in "123456789": + for k in "-+*/": + for l in "-+*/": + e = "8" + l + i + k + j + if sat(e): + r.append(e) + return r[-1] + + ``` + Hand-written solution: + ```python + return "8*8-1" + ``` +
+ +* **MonkeyAndCoconuts** [The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts) (1 instance) + + ```python + def sat(n: int): for i in range(5): - if n % 5 != 1: - break + assert n % 5 == 1 n -= 1 + (n - 1) // 5 - if n > 0 and n % 5 == 1: - return m - m += 5 -``` - -
- -### No3Colinear -[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem) - -```python -def sat(coords: List[List[int]], side=10, num_points=20): - """Find num_points points in an side x side grid such that no three points are collinear.""" - for i1 in range(len(coords)): - x1, y1 = coords[i1] - assert 0 <= x1 < side and 0 <= y1 < side - for i2 in range(i1): - x2, y2 = coords[i2] - for i3 in range(i2): - x3, y3 = coords[i3] - assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0 - return len({(a, b) for a, b in coords}) == len(coords) >= num_points -``` -
1 solution to classic_puzzles 11/22 - -```python -def sol(side=10, num_points=20): - from itertools import combinations - assert side <= 5 or side == 10, "Don't know how to solve other sides" - - def test(coords): - return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1]) - for p, q, r in combinations(coords, 3)) - - if side <= 5: - grid = [[i, j] for i in range(side) for j in range(side)] - return next(list(coords) for coords in combinations(grid, num_points) if test(coords)) - - if side == 10: - def mirror(coords): # rotate to all four corners - return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]] - - grid = [[i, j] for i in range(side // 2) for j in range(side // 2)] - return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if - test(coords) and test(mirror(coords))) -``` - -
- -### PostageStamp -[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem) - -```python -def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]): - """Find a selection of at most max_stamps stamps whose total worth is the target value.""" - for s in stamps: - assert s in options - return len(stamps) <= max_stamps and sum(stamps) == target -``` -
1 solution to classic_puzzles 12/22 - -```python -def sol(target=80, max_stamps=4, options=[10, 32, 8]): - from itertools import combinations_with_replacement - for n in range(max_stamps + 1): - for c in combinations_with_replacement(options, n): - if sum(c) == target: - return list(c) -``` - -
- -### SquaringTheSquare -[Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square) -Wikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square) -due to Duijvestijn (1978): -```python -[[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35], - [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18], - [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]] -``` - -```python -def sat(xy_sides: List[List[int]]): - """ - Partition a square into smaller squares with unique side lengths. A perfect squared path has distinct sides. - xy_sides is a List of (x, y, side) - """ - n = max(x + side for x, y, side in xy_sides) - assert len({side for x, y, side in xy_sides}) == len(xy_sides) > 1 - for x, y, s in xy_sides: - assert 0 <= y < y + s <= n and 0 <= x - for x2, y2, s2 in xy_sides: - assert s2 <= s or x2 >= x + s or x2 + s2 <= x or y2 >= y + s or y2 + s2 <= y - - return sum(side ** 2 for x, y, side in xy_sides) == n ** 2 -``` -
1 solution to classic_puzzles 13/22 - -```python -def sol(): - return [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35], - [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18], - [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]] -``` - -
- -### NecklaceSplit -[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem) - -```python -def sat(n: int, lace="bbbbrrbrbrbbrrrr"): - """ - Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of - reds and blues. - """ - sub = lace[n: n + len(lace) // 2] - return n >= 0 and lace.count("r") == 2 * sub.count("r") and lace.count("b") == 2 * sub.count("b") -``` -
1 solution to classic_puzzles 14/22 - -```python -def sol(lace="bbbbrrbrbrbbrrrr"): - if lace == "": - return 0 - return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count("r") == len(lace) // 4) -``` - -
- -### PandigitalSquare -[Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square - -```python -def sat(n: int): - """Find an integer whose square has all digits 0-9 once.""" - s = str(n * n) - for i in "0123456789": - assert s.count(i) == 1 - return True -``` -
1 solution to classic_puzzles 15/22 - -```python -def sol(): - for n in range(10 ** 5): - if sorted([int(s) for s in str(n * n)]) == list(range(10)): - return n -``` - -
- -### AllPandigitalSquares -All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares - -```python -def sat(nums: List[int]): - """Find all 174 integers whose 10-digit square has all digits 0-9 just once.""" - return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174 -``` -
1 solution to classic_puzzles 16/22 - -```python -def sol(): - return [i for i in range(-10 ** 5, 10 ** 5) if sorted([int(s) for s in str(i * i)]) == list(range(10))] -``` - -
- -### CardGame24 -[24 Game](https://en.wikipedia.org/wiki/24_Game) - -In this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with - + - * / (and parentheses) -to make the number 24. -The solution to this tricky example is `7 * (3 + 3 / 7)` - -```python -def sat(expr: str, nums=[3, 7, 3, 7]): - """Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.""" - assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, "hint: nums is a list of four ints in 1..13" - expr = expr.replace(" ", "") # ignore whitespace - digits = "" - for i in range(len(expr)): - if i == 0 or expr[i - 1] in "+*-/(": - assert expr[i] in "123456789(", "Expr cannot contain **, //, or unary -" - assert expr[i] in "1234567890()+-*/", "Expr can only contain `0123456789()+-*/`" - digits += expr[i] if expr[i] in "0123456789" else " " - assert sorted(int(s) for s in digits.split()) == sorted(nums), "Each number must occur exactly once" - return abs(eval(expr) - 24.0) < 1e-6 -``` -
1 solution to classic_puzzles 17/22 - -```python -def sol(nums=[3, 7, 3, 7]): - def helper(pairs): - if len(pairs) == 2: - (x, s), (y, t) = pairs - ans = { - x + y: f"{s}+{t}", - x - y: f"{s}-({t})", - y - x: f"{t}-({s})", - x * y: f"({s})*({t})" - } - if y != 0: - ans[x / y] = f"({s})/({t})" - if x != 0: - ans[y / x] = f"({t})/({s})" - return ans - ans = {y: t - for i in range(len(pairs)) - for x_s in helper(pairs[:i] + pairs[i + 1:]).items() - for y, t in helper([x_s, pairs[i]]).items()} - if len(pairs) == 3: - return ans - ans.update({z: u - for i in range(1, 4) - for x_s in helper([pairs[0], pairs[i]]).items() - for y_t in helper(pairs[1:i] + pairs[i + 1:]).items() - for z, u in helper([x_s, y_t]).items() - }) - return ans - - derivations = helper([(n, str(n)) for n in nums]) - for x in derivations: - if abs(x - 24.0) < 1e-6: - return derivations[x] -``` - -
- -### Easy63 -An easy puzzle to make 63 using two 8's and one 1's. - -```python -def sat(s: str): - """Find a formula using two 8s and two 1's and -+*/ that evaluates to 1.""" - return set(s) <= set("18-+*/") and s.count("8") == 2 and s.count("1") == 1 and eval(s) == 63 -``` -
1 solution to classic_puzzles 18/22 - -```python -def sol(): - return "8*8-1" -``` - -
- -### Harder63 -An harder puzzle to make 63 using three 8's and one 1's. - -```python -def sat(s: str): - """Find an expression using two 8s and two 1's and -+*/ that evaluates to 1.""" - return set(s) <= set("18-+*/") and s.count("8") == 3 and s.count("1") == 1 and eval(s) == 63 -``` -
1 solution to classic_puzzles 19/22 - -```python -def sol(): - return "8*8-1**8" -``` - -
- -### WaterPouring -[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928) - -```python -def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): # moves is list of [from, to] pairs - """ - Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring - one jug into another until it is full or the first is empty) to reaches the given goal state. - """ - state = init.copy() - - for [i, j] in moves: - assert min(i, j) >= 0, "Indices must be non-negative" - assert i != j, "Cannot pour from same state to itself" - n = min(capacities[j], state[i] + state[j]) - state[i], state[j] = state[i] + state[j] - n, n - - return state == goal -``` -
1 solution to classic_puzzles 20/22 - -```python -def sol(capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): - from collections import deque - num_jugs = len(capacities) - start = tuple(init) - target = tuple(goal) - trails = {start: ([], start)} - queue = deque([tuple(init)]) - while target not in trails: - state = queue.popleft() - for i in range(num_jugs): - for j in range(num_jugs): - if i != j: - n = min(capacities[j], state[i] + state[j]) - new_state = list(state) - new_state[i], new_state[j] = state[i] + state[j] - n, n - new_state = tuple(new_state) - if new_state not in trails: - queue.append(new_state) - trails[new_state] = ([i, j], state) - ans = [] - state = target - while state != start: - move, state = trails[state] - ans.append(move) - return ans[::-1] -``` - -
- -### VerbalArithmetic -Find a substitution of digits for characters to make the numbers add up in a sum like this: -SEND + MORE = MONEY - -The first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`. -See [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic) - -```python -def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']): - """ - Find a list of integers corresponding to the given list of strings substituting a different digit for each - character, so that the last string corresponds to the sum of the previous numbers. - """ - assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words)) - assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)}) - return sum(li[:-1]) == li[-1] -``` -
1 solution to classic_puzzles 21/22 - -```python -def sol(words=['SEND', 'MORE', 'MONEY']): - pi = list(range(10)) # permutation - letters = [] - order = {} - steps = [] - tens = 1 - for col in range(1, 1 + max(len(w) for w in words)): - for w in words: - is_tot = (w is words[-1]) - if len(w) >= col: - c = w[-col] - if c in order: - if is_tot: - kind = "check" - else: - kind = "seen" - else: - if is_tot: - kind = "derive" + return n > 0 and n % 5 == 1 + ``` +
0.067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the number of coconuts to solve the following riddle: + There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the + one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the + procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and + fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey. + Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over. + How many coconuts were there in the original pile? + Quoted from https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts + """ + ``` + Shortest Codex solution: + ```python + + return 49999 * 5 + 1 + + ``` + Longest Codex solution: + ```python + + # This is not a very efficient algorithm, but it is a reasonably quick one. Although it would perhaps + # more closely match the population density of Earth more closely the solutions would become longer and more + # complicated as time went on. + coconuts = 1000000 + for i in range(5): + coconuts = (coconuts - 1) // 5 * 5 + 1 + return coconuts + + ``` + Hand-written solution: + ```python + m = 1 + while True: + n = m + for i in range(5): + if n % 5 != 1: + break + n -= 1 + (n - 1) // 5 + if n > 0 and n % 5 == 1: + return m + m += 5 + ``` +
+ +* **PostageStamp** [Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem) (5 instances) + + ```python + def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]): + for s in stamps: + assert s in options + return len(stamps) <= max_stamps and sum(stamps) == target + ``` +
0.043% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=80, max_stamps=4, options=[10, 32, 8]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a selection of at most max_stamps stamps whose total worth is the target value.""" + ``` + Shortest Codex solution: + ```python + + return [32, 8, 8, 32] + + ``` + Longest Codex solution: + ```python + + best_len = max_stamps + 1 + res = [] + for x in options: + for y in options: + for z in options: + for w in options: + if sat([x, y, z, w], target=target, max_stamps=max_stamps, options=options): + best_len = min(best_len, len([x, y, z, w])) + res = [x, y, z, w] + if best_len == max_stamps + 1: + return [] + return res + + ``` + Hand-written solution: + ```python + from itertools import combinations_with_replacement + for n in range(max_stamps + 1): + for c in combinations_with_replacement(options, n): + if sum(c) == target: + return list(c) + ``` +
+ +* **RevQuine** Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3. (1 instance) + + ```python + def sat(rev_quine: str): + return eval(rev_quine[::-1]) == rev_quine + ``` +
0.023% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that, when reversed and evaluated gives you back that same string.""" + ``` + Shortest Codex solution: + ```python + + return "rev_quine"[::-1] + + ``` + Longest Codex solution: + ```python + + args = ["r", "e", "v", "_", "q", "u", "i", "n", "e"] + return "".join(args[-i-1] for i in range(len(args))) + + ``` + Hand-written solution: + ```python + return "rev_quine"[::-1] # thanks GPT-3! + ``` +
+ +* **VerbalArithmetic** Find a substitution of digits for characters to make the numbers add up in a sum like this: + SEND + MORE = MONEY + + The first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`. + See [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic) (5 instances) + + ```python + def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']): + assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words)) + assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)}) + return sum(li[:-1]) == li[-1] + ``` +
0.023% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(words=['SEND', 'MORE', 'MONEY']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of integers corresponding to the given list of strings substituting a different digit for each + character, so that the last string corresponds to the sum of the previous numbers. + """ + ``` + Shortest Codex solution: + ```python + + assert words == ['SEND', 'MORE', 'MONEY'] + return [9567, 1085, 10652] + + ``` + Longest Codex solution: + ```python + + if len(words) == 3: + return [9567, 1085, 10652] + if len(words) == 4: + return [974, 1085, 10652, 11448] + if len(words) == 5: + return [974, 1085, 10652] + if len(words) == 8: + return [947, 1085, 10652, 1159, 1074, 4473, 11888] + if len(words) == 9: + return [947, 1085, 10652, 1159, 1074, 4473, 1188, 5388, 1015] + + ``` + Hand-written solution: + ```python + print("solving", words) + pi = list(range(10)) # permutation + letters = [] + order = {} + steps = [] + tens = 1 + for col in range(1, 1 + max(len(w) for w in words)): + for w in words: + is_tot = (w is words[-1]) + if len(w) >= col: + c = w[-col] + if c in order: + if is_tot: + kind = "check" + else: + kind = "seen" else: - kind = "add" - order[c] = len(letters) - letters.append(c) - steps.append((kind, order[c], tens)) - tens *= 10 - - inits = [any(w[0] == c for w in words) for c in letters] - - def helper(pos, delta): # on success, returns True and pi has the correct values - if pos == len(steps): - return delta == 0 - - kind, i, tens = steps[pos] - - if kind == "seen": - return helper(pos + 1, delta + tens * pi[i]) - - if kind == "add": - for j in range(i, 10): - if pi[j] != 0 or not inits[i]: # not adding a leading 0 - pi[i], pi[j] = pi[j], pi[i] - if helper(pos + 1, delta + tens * pi[i]): - return True - pi[i], pi[j] = pi[j], pi[i] + if is_tot: + kind = "derive" + else: + kind = "add" + order[c] = len(letters) + letters.append(c) + steps.append((kind, order[c], tens)) + tens *= 10 + + inits = [any(w[0] == c for w in words) for c in letters] + + def helper(pos, delta): # on success, returns True and pi has the correct values + if pos == len(steps): + return delta == 0 + + kind, i, tens = steps[pos] + + if kind == "seen": + return helper(pos + 1, delta + tens * pi[i]) + + if kind == "add": + for j in range(i, 10): + if pi[j] != 0 or not inits[i]: # not adding a leading 0 + pi[i], pi[j] = pi[j], pi[i] + if helper(pos + 1, delta + tens * pi[i]): + return True + pi[i], pi[j] = pi[j], pi[i] + return False + if kind == "check": + delta -= tens * pi[i] + return (delta % (10 * tens)) == 0 and helper(pos + 1, delta) + + assert kind == "derive" + digit = (delta % (10 * tens)) // tens + if digit == 0 and inits[i]: + return False # would be a leading 0 + j = pi.index(digit) + if j < i: + return False # already used + pi[i], pi[j] = pi[j], pi[i] + if helper(pos + 1, delta - tens * digit): + return True + pi[i], pi[j] = pi[j], pi[i] return False - if kind == "check": - delta -= tens * pi[i] - return (delta % (10 * tens)) == 0 and helper(pos + 1, delta) - - assert kind == "derive" - digit = (delta % (10 * tens)) // tens - if digit == 0 and inits[i]: - return False # would be a leading 0 - j = pi.index(digit) - if j < i: - return False # already used - pi[i], pi[j] = pi[j], pi[i] - if helper(pos + 1, delta - tens * digit): - return True - pi[i], pi[j] = pi[j], pi[i] - return False - - assert helper(0, 0) - return [int("".join(str(pi[order[c]]) for c in w)) for w in words] -``` - -
- -### SlidingPuzzle -[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle) -The 3-, 8-, and 15-sliding puzzles are classic examples of A* search. -The problem is NP-hard but the puzzles can all be solved with A* and an efficient representation. - -```python -def sat(moves: List[int], start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]): - """ - In this puzzle, you are given a board like: - 1 2 5 - 3 4 0 - 6 7 8 - - and your goal is to transform it to: - 0 1 2 - 3 4 5 - 6 7 8 - - by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list - of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the - above example, an answer would be [1, 2, 5] - """ - - locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank - for i in moves: - assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1 - locs[0], locs[i] = locs[i], locs[0] - return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs) -``` -
1 solution to classic_puzzles 22/22 - -```python -def sol(start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]): - from collections import defaultdict - import math - d = len(start) - N = d * d - assert all(len(row) == d for row in start) - - def get_state( - li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is - ans = 0 - for i in li[::-1] + [li.index(0)]: - ans = (ans << 4) + i - return ans - - start = get_state([i for row in start for i in row]) - target = get_state(list(range(N))) - - def h(state): # manhattan distance - ans = 0 - for i in range(N): - state = (state >> 4) - n = state & 15 - if n != 0: - ans += abs(i % d - n % d) + abs(i // d - n // d) + + assert helper(0, 0) + return [int("".join(str(pi[order[c]]) for c in w)) for w in words] + ``` +
+ +* **TowersOfHanoi** [Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi) + + In this classic version one must move all 8 disks from the first to third peg. (1 instance) + + ```python + def sat(moves: List[List[int]]): + rods = ([8, 7, 6, 5, 4, 3, 2, 1], [], []) + for [i, j] in moves: + rods[j].append(rods[i].pop()) + assert rods[j][-1] == min(rods[j]), "larger disk on top of smaller disk" + return rods[0] == rods[1] == [] + ``` +
0.01% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Eight disks of sizes 1-8 are stacked on three towers, with each tower having disks in order of largest to + smallest. Move [i, j] corresponds to taking the smallest disk off tower i and putting it on tower j, and it + is legal as long as the towers remain in sorted order. Find a sequence of moves that moves all the disks + from the first to last towers. + """ + ``` + Shortest Codex solution: + ```python + + moves = [] + def hanoi(n, i, j, k): + if n == 0: + return + hanoi(n-1, i, k, j) + moves.append([i, j]) + hanoi(n-1, k, j, i) + hanoi(8, 0, 2, 1) + return moves + + ``` + Longest Codex solution: + ```python + + num_disks = 8 + aux_tower = 2 + moves = [] + def hanoi(num_disks, src, aux, dest): + nonlocal moves + if num_disks == 1: + moves.append([src, dest]) + return + hanoi(num_disks-1, src, dest, aux) + moves.append([src, dest]) + hanoi(num_disks-1, aux, src, dest) + hanoi(num_disks, 0, 1, 2) + return moves + + ``` + Hand-written solution: + ```python + def helper(m, i, j): + if m == 0: + return [] + k = 3 - i - j + return helper(m - 1, i, k) + [[i, j]] + helper(m - 1, k, j) + + return helper(8, 0, 2) + ``` +
+ +* **CardGame24** [24 Game](https://en.wikipedia.org/wiki/24_Game) + + In this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with + + - * / (and parentheses) + to make the number 24. + The solution to this tricky example is `7 * (3 + 3 / 7)` (5 instances) + + ```python + def sat(expr: str, nums=[3, 7, 3, 7]): + assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, "hint: nums is a list of four ints in 1..13" + expr = expr.replace(" ", "") # ignore whitespace + digits = "" + for i in range(len(expr)): + if i == 0 or expr[i - 1] in "+*-/(": + assert expr[i] in "123456789(", "Expr cannot contain **, //, or unary -" + assert expr[i] in "1234567890()+-*/", "Expr can only contain `0123456789()+-*/`" + digits += expr[i] if expr[i] in "0123456789" else " " + assert sorted(int(s) for s in digits.split()) == sorted(nums), "Each number must occur exactly once" + return abs(eval(expr) - 24.0) < 1e-6 + ``` +
0.0067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[3, 7, 3, 7]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.""" + ``` + Shortest Codex solution: + ```python + + ops = ["+", "-", "*", "/"] + for op1 in ops: + for op2 in ops: + for op3 in ops: + expr = "(" + str(nums[0]) + op1 + str(nums[1]) + op2 + str(nums[2]) + ")" + op3 + str(nums[3]) + if sat(expr): + return expr + + ``` + Longest Codex solution: + ```python + + ops = ["+", "-", "*", "/"] + for a in ops: + for b in ops: + for c in ops: + for d in ops: + for expr in ["((({} {} {}) {} {}) {} {})".format(nums[0], a, nums[1], b, nums[2], c, nums[3], d)]: + if sat(expr): + return expr + ``` + Hand-written solution: + ```python + def helper(pairs): + if len(pairs) == 2: + (x, s), (y, t) = pairs + ans = { + x + y: f"{s}+{t}", + x - y: f"{s}-({t})", + y - x: f"{t}-({s})", + x * y: f"({s})*({t})" + } + if y != 0: + ans[x / y] = f"({s})/({t})" + if x != 0: + ans[y / x] = f"({t})/({s})" + return ans + ans = {y: t + for i in range(len(pairs)) + for x_s in helper(pairs[:i] + pairs[i + 1:]).items() + for y, t in helper([x_s, pairs[i]]).items()} + if len(pairs) == 3: + return ans + ans.update({z: u + for i in range(1, 4) + for x_s in helper([pairs[0], pairs[i]]).items() + for y_t in helper(pairs[1:i] + pairs[i + 1:]).items() + for z, u in helper([x_s, y_t]).items() + }) + return ans + + derivations = helper([(n, str(n)) for n in nums]) + for x in derivations: + if abs(x - 24.0) < 1e-6: + return derivations[x] + ``` +
+ +* **WaterPouring** [Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928) (5 instances) + + ```python + def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): + state = init.copy() + + for [i, j] in moves: + assert min(i, j) >= 0, "Indices must be non-negative" + assert i != j, "Cannot pour from same state to itself" + n = min(capacities[j], state[i] + state[j]) + state[i], state[j] = state[i] + state[j] - n, n + + return state == goal + ``` +
0.0033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring + one jug into another until it is full or the first is empty) to reaches the given goal state. + moves is list of [from, to] pairs + """ + ``` + Codex solution: + ```python + + def bfs(): + queue = [[init, []]] + while queue: + state, move = queue.pop(0) + if sat(move, capacities, state, goal): + return move + for i in range(len(capacities)): + newmove = move.copy() + newmove.append([i, (i + 1) % len(capacities)]) + queue.append([state.copy(), newmove]) + return bfs() + + ``` + Hand-written solution: + ```python + from collections import deque + num_jugs = len(capacities) + start = tuple(init) + target = tuple(goal) + trails = {start: ([], start)} + queue = deque([tuple(init)]) + while target not in trails: + state = queue.popleft() + for i in range(num_jugs): + for j in range(num_jugs): + if i != j: + n = min(capacities[j], state[i] + state[j]) + new_state = list(state) + new_state[i], new_state[j] = state[i] + state[j] - n, n + new_state = tuple(new_state) + if new_state not in trails: + queue.append(new_state) + trails[new_state] = ([i, j], state) + ans = [] + state = target + while state != start: + move, state = trails[state] + ans.append(move) + return ans[::-1] + ``` +
+ +* **TowersOfHanoiArbitrary** [Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi) + + In this version one must transform a given source state to a target state. (5 instances) + + ```python + def sat(moves: List[List[int]], source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]): + state = [s[:] for s in source] + + for [i, j] in moves: + state[j].append(state[i].pop()) + assert state[j] == sorted(state[j]) + + return state == target + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in + {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the + order of list j. Find a sequence of moves that transform the given source to target states. + """ + ``` + Hand-written solution: + ```python + state = {d: i for i, tower in enumerate(source) for d in tower} + final = {d: i for i, tower in enumerate(target) for d in tower} + disks = set(state) + assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3 + ans = [] + + def move(d, i): # move disk d to tower i + if state[d] == i: + return + for t in range(3): # first tower besides i, state[d] + if t != i and t != state[d]: + break + for d2 in range(d + 1, max(disks) + 1): + if d2 in disks: + move(d2, t) + ans.append([state[d], i]) + state[d] = i + + for d in range(min(disks), max(disks) + 1): + if d in disks: + move(d, final[d]) + return ans - - g = defaultdict(lambda: math.inf) - g[start] = 0 # shortest p ath lengths - f = {start: h(start)} # f[s] = g[s] + h(s) - backtrack = {} - - todo = {start} - import heapq - heap = [(f[start], start)] - - neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)] - for b in range(N)] - - def next_state(s, blank, i): - assert blank == (s & 15) - v = (s >> (4 * i + 4)) & 15 - return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4)) - - while todo: - (dist, s) = heapq.heappop(heap) - if f[s] < dist: - continue - if s == target: - # compute path - ans = [] - while s != start: - s, i = backtrack[s] - ans.append((s >> (4 * i + 4)) & 15) - return ans[::-1] - - todo.remove(s) - - blank = s & 15 - score = g[s] + 1 - for i in neighbors[blank]: - s2 = next_state(s, blank, i) - - if score < g[s2]: - # paths[s2] = paths[s] + [s[i]] - g[s2] = score - backtrack[s2] = (s, i) - score2 = score + h(s2) - f[s2] = score2 - todo.add(s2) - heapq.heappush(heap, (score2, s2)) -``` - -
- + ``` +
+ +* **LongestMonotonicSubstring** This is a form of the classic + [Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem + where the goal is to find a substring with characters in sorted order. (5 instances) + + ```python + def sat(x: List[int], length=13, s="Dynamic programming solves this puzzle!!!"): + return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1)) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(length=13, s="Dynamic programming solves this puzzle!!!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Remove as few characters as possible from s so that the characters of the remaining string are alphebetical. + Here x is the list of string indices that have not been deleted. + """ + ``` + Hand-written solution: + ```python + # O(N^2) method. Todo: add binary search solution which is O(n log n) + if s == "": + return [] + n = len(s) + dyn = [] # list of (seq length, seq end, prev index) + for i in range(n): + try: + dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i])) + except ValueError: + dyn.append((1, i, -1)) # sequence ends at i + _length, i, _ = max(dyn) + backwards = [i] + while dyn[i][2] != -1: + i = dyn[i][2] + backwards.append(i) + return backwards[::-1] + ``` +
+ +* **LongestMonotonicSubstringTricky** The same as the above problem, but with a twist! (5 instances) + + ```python + def sat(x: List[int], length=20, s="Dynamic programming solves this classic job-interview puzzle!!!"): + return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1)) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(length=20, s="Dynamic programming solves this classic job-interview puzzle!!!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the indices of the longest substring with characters in sorted order""" + ``` + Hand-written solution: + ```python + # O(N^2) method. Todo: add binary search solution which is O(n log n) + if s == "": + return [] + n = len(s) + dyn = [] # list of (seq length, seq end, prev index) + for i in range(-n, n): + try: + dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i])) + except ValueError: + dyn.append((1, i, None)) # sequence ends at i + _length, i, _ = max(dyn) + backwards = [i] + while dyn[n + i][2] is not None: + i = dyn[n + i][2] + backwards.append(i) + return backwards[::-1] + ``` +
+ +* **BooleanPythagoreanTriples** [Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem) (4 instances) + + ```python + def sat(colors: List[int], n=100): + assert set(colors) <= {0, 1} and len(colors) >= n + squares = {i ** 2: colors[i] for i in range(1, len(colors))} + return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items()) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple. + A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that + are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n. + """ + ``` + Hand-written solution: + ```python + sqrt = {i * i: i for i in range(1, n)} + trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt] + import random + random.seed(0) + sol = [random.randrange(2) for _ in range(n)] + done = False + while not done: + done = True + random.shuffle(trips) + for i, j, k in trips: + if sol[i] == sol[j] == sol[k]: + done = False + sol[random.choice([i, j, k])] = 1 - sol[i] + return sol + ``` +
+ +* **Kirkman** [Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem) (1 instance) + + ```python + def sat(daygroups: List[List[List[int]]]): + assert len(daygroups) == 7 + assert all(len(groups) == 5 and {i for g in groups for i in g} == set(range(15)) for groups in daygroups) + assert all(len(g) == 3 for groups in daygroups for g in groups) + return len({(i, j) for groups in daygroups for g in groups for i in g for j in g}) == 15 * 15 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Arrange 15 people into groups of 3 each day for seven days so that no two people are in the same group twice. + """ + ``` + Hand-written solution: + ```python + from itertools import combinations + import random + rand = random.Random(0) + days = [[list(range(15)) for _2 in range(2)] for _ in range(7)] # each day is pi, inv + counts = {(i, j): (7 if j in range(k, k + 3) else 0) + for k in range(0, 15, 3) + for i in range(k, k + 3) + for j in range(15) if j != i + } + + todos = [pair for pair, count in counts.items() if count == 0] + while True: + pair = rand.choice(todos) # choose i and j to make next to each other on some day + if rand.randrange(2): + pair = pair[::-1] + + a, u = pair + pi, inv = rand.choice(days) + assert pi[inv[a]] == a and pi[inv[u]] == u + bases = [3 * (inv[i] // 3) for i in pair] + (b, c), (v, w) = [[x for x in pi[b: b + 3] if x != i] for i, b in zip(pair, bases)] + if rand.randrange(2): + b, c, = c, b + # current (a, b, c) (u, v, w). consider swap of u with b to make (a, u, c) (b, v, w) + + new_pairs = [(a, u), (c, u), (b, v), (b, w)] + old_pairs = [(u, v), (u, w), (b, a), (b, c)] + gained = sum(counts[p] == 0 for p in new_pairs) + lost = sum(counts[p] == 1 for p in old_pairs) + if rand.random() <= 100 ** (gained - lost): + for p in new_pairs: + counts[p] += 1 + counts[p[::-1]] += 1 + for p in old_pairs: + counts[p] -= 1 + counts[p[::-1]] -= 1 + pi[inv[b]], pi[inv[u]], inv[b], inv[u] = u, b, inv[u], inv[b] + todos = [pair for pair, count in counts.items() if count == 0] + if len(todos) == 0: + return [[pi[k:k + 3] for k in range(0, 15, 3)] for pi, _inv in days] + ``` +
+ +* **No3Colinear** [No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem) (4 instances) + + ```python + def sat(coords: List[List[int]], side=10, num_points=20): + for i1 in range(len(coords)): + x1, y1 = coords[i1] + assert 0 <= x1 < side and 0 <= y1 < side + for i2 in range(i1): + x2, y2 = coords[i2] + for i3 in range(i2): + x3, y3 = coords[i3] + assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0 + return len({(a, b) for a, b in coords}) == len(coords) >= num_points + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(side=10, num_points=20): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find num_points points in an side x side grid such that no three points are collinear.""" + ``` + Hand-written solution: + ```python + from itertools import combinations + assert side <= 5 or side == 10, "Don't know how to solve other sides" + + def test(coords): + return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1]) + for p, q, r in combinations(coords, 3)) + + if side <= 5: + grid = [[i, j] for i in range(side) for j in range(side)] + return next(list(coords) for coords in combinations(grid, num_points) if test(coords)) + + if side == 10: + def mirror(coords): # rotate to all four corners + return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]] + + grid = [[i, j] for i in range(side // 2) for j in range(side // 2)] + return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if + test(coords) and test(mirror(coords))) + ``` +
+ +* **Sudoku** The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku) (5 instances) + + ```python + def sat(x: str, puz="____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______"): + assert all(c == "_" or c == s for (c, s) in zip(puz, x)) + + full = set('123456789') + for i in range(9): + assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, "invalid row" + assert {x[i] for i in range(i, i + 81, 9)} == full, "invalid column" + assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, "invalid square" + + return True + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(puz="____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the unique valid solution to the Sudoku puzzle""" + ``` + Hand-written solution: + ```python + """Simple depth-first backtracking solver that branches at the square with fewest possibilities""" + sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz] + + groups = [] + for i in range(9): + groups.append(list(range(9 * i, 9 * i + 9))) + groups.append(list(range(i, i + 81, 9))) + groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)]) + + inv = [[] for i in range(81)] + for g in groups: + for i in g: + inv[i].append(g) + + def reduce(): + """Reduce possibilities and return False if it's clearly impossible to solve, True otherwise. + Repeatedly applies two types of logic: + * When an entry has a single possibility, remove that value from all 20 neighbors + * When a row/col/square has only one entry with k as a possibility, fill in that possibility + """ + done = False + while not done: + done = True + for i in range(81): + new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]} + if not new: + return False + if len(sets[i]) != len(new): + sets[i] = new + done = False + + for g in groups: + for k in range(1, 10): + possibilities = [i for i in g if k in sets[i]] + if not possibilities: + return False + if len(possibilities) == 1: + i = possibilities[0] + if len(sets[i]) > 1: + done = False + sets[i] = {k} + + return True + + ans = [] + + counter = 0 + + def solve_helper(): + nonlocal sets, ans, counter + counter += 1 + assert len(ans) <= 1, "Sudoku puzzle should have a unique solution" + old_sets = sets[:] + if reduce(): + if all(len(s) == 1 for s in sets): + ans.append("".join(str(list(s)[0]) for s in sets)) + else: + smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10) + for v in sorted(sets[smallest_set]): + sets[smallest_set] = {v} + solve_helper() + + sets = old_sets + + solve_helper() + assert ans, "No solution found" + return ans[0] + ``` +
+ +* **SquaringTheSquare** [Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square) + Wikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square) + due to Duijvestijn (1978). (1 instance) + + ```python + def sat(xy_sides: List[List[int]]): + n = max(x + side for x, y, side in xy_sides) + assert len({side for x, y, side in xy_sides}) == len(xy_sides) > 1 + for x, y, s in xy_sides: + assert 0 <= y < y + s <= n and 0 <= x + for x2, y2, s2 in xy_sides: + assert s2 <= s or x2 >= x + s or x2 + s2 <= x or y2 >= y + s or y2 + s2 <= y + + return sum(side ** 2 for x, y, side in xy_sides) == n ** 2 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Partition a square into smaller squares with unique side lengths. A perfect squared path has distinct sides. + xy_sides is a List of (x, y, side) + """ + ``` + Hand-written solution: + ```python + return [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35], + [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18], + [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]] + ``` +
+ +* **AllPandigitalSquares** All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares (1 instance) + + ```python + def sat(nums: List[int]): + return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all 174 integers whose 10-digit square has all digits 0-9 just once.""" + ``` + Hand-written solution: + ```python + return [i for i in range(-10 ** 5, 10 ** 5) if sorted([int(s) for s in str(i * i)]) == list(range(10))] + ``` +
+ +* **Harder63** An harder puzzle to make 63 using three 8's and one 1's. (1 instance) + + ```python + def sat(s: str): + return set(s) <= set("18-+*/") and s.count("8") == 3 and s.count("1") == 1 and eval(s) == 63 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an expression using two 8s and two 1's and -+*/ that evaluates to 1.""" + ``` + Hand-written solution: + ```python + return "8*8-1**8" + ``` +
+ +* **SlidingPuzzle** [Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle) + The 3-, 8-, and 15-sliding puzzles are classic examples of A* search. + The problem is NP-hard but the puzzles can all be solved with A* and an efficient representation. (5 instances) + + ```python + def sat(moves: List[int], start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]): + + locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank + for i in moves: + assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1 + locs[0], locs[i] = locs[i], locs[0] + return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + In this puzzle, you are given a board like: + 1 2 5 + 3 4 0 + 6 7 8 + + and your goal is to transform it to: + 0 1 2 + 3 4 5 + 6 7 8 + + by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list + of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the + above example, an answer would be [1, 2, 5] + """ + ``` + Hand-written solution: + ```python + from collections import defaultdict + import math + d = len(start) + N = d * d + assert all(len(row) == d for row in start) + + def get_state( + li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is + ans = 0 + for i in li[::-1] + [li.index(0)]: + ans = (ans << 4) + i + return ans + + start = get_state([i for row in start for i in row]) + target = get_state(list(range(N))) + + def h(state): # manhattan distance + ans = 0 + for i in range(N): + state = (state >> 4) + n = state & 15 + if n != 0: + ans += abs(i % d - n % d) + abs(i // d - n // d) + return ans + + g = defaultdict(lambda: math.inf) + g[start] = 0 # shortest p ath lengths + f = {start: h(start)} # f[s] = g[s] + h(s) + backtrack = {} + + todo = {start} + import heapq + heap = [(f[start], start)] + + neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)] + for b in range(N)] + + def next_state(s, blank, i): + assert blank == (s & 15) + v = (s >> (4 * i + 4)) & 15 + return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4)) + + while todo: + (dist, s) = heapq.heappop(heap) + if f[s] < dist: + continue + if s == target: + # compute path + ans = [] + while s != start: + s, i = backtrack[s] + ans.append((s >> (4 * i + 4)) & 15) + return ans[::-1] + + todo.remove(s) + + blank = s & 15 + score = g[s] + 1 + for i in neighbors[blank]: + s2 = next_state(s, blank, i) + + if score < g[s2]: + # paths[s2] = paths[s] + [s[i]] + g[s2] = score + backtrack[s2] = (s, i) + score2 = score + h(s2) + f[s2] = score2 + todo.add(s2) + heapq.heappush(heap, (score2, s2)) + ``` +
+ ## human_eval Problems inspired by [HumanEval dataset](https://github.com/openai/human-eval) described @@ -1471,7921 +2731,19302 @@ in the [codex paper](https://arxiv.org/abs/2107.03374), specifically, [this](https://github.com/openai/human-eval/blob/fa06031e684fbe1ee429c7433809460c159b66ad/data/HumanEval.jsonl.gz) version released 7/7/21. -### FindCloseElements -Inspired by [HumanEval](https://github.com/openai/human-eval) \#0 - -```python -def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]): - """ - Given a list of numbers, find the two closest distinct numbers in the list. - - Sample Input: - [1.2, 5.23, 0.89, 21.0, 5.28, 1.2] - - Sample Output: - [5.23, 5.28] - """ - a, b = pair - assert a in nums and b in nums - return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0}) -``` -
1 solution to human_eval 1/96 - -```python -def sol(nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]): - s = sorted(set(nums)) - return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0]) -``` - -
- -### SeparateParenGroups -Inspired by [HumanEval](https://github.com/openai/human-eval) \#1 - -```python -def sat(ls: List[str], combined="() (()) ((() () ())) (() )"): - """ - Given a string consisting of whitespace and groups of matched parentheses, split it - into groups of perfectly matched parentheses without any whitespace. - - Sample Input: - '( ()) ((()()())) (()) ()' - - Sample Output: - ['(())', '((()()()))', '(())', '()'] - """ - assert ''.join(ls) == combined.replace(' ', '') - for s in ls: # check that s is not further divisible - depth = 0 - for c in s[:-1]: - if c == '(': - depth += 1 - else: - assert c == ')' - depth -= 1 - assert depth >= 1 - assert depth == 1 and s[-1] == ')' - return True -``` -
1 solution to human_eval 2/96 - -```python -def sol(combined="() (()) ((() () ())) (() )"): - cur = '' - ans = [] - depth = 0 - for c in combined.replace(' ', ''): - cur += c - if c == '(': - depth += 1 - else: - assert c == ')' - depth -= 1 - if depth == 0: - ans.append(cur) - cur = '' - return ans -``` - -
- -### Frac -Inspired by [HumanEval](https://github.com/openai/human-eval) \#2 - -```python -def sat(x: float, v=523.12892): - """ - Given a floating point number, find its fractional part. - - Sample Input: - 4.175 - - Sample Output: - 0.175 - """ - return 0 <= x < 1 and (v - x).is_integer() -``` -
1 solution to human_eval 3/96 - -```python -def sol(v=523.12892): - return v % 1.0 -``` - -
- -### FirstNegCumulative -Inspired by [HumanEval](https://github.com/openai/human-eval) \#3 - -```python -def sat(n: int, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): - """ - Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance. - - Sample Input: - [12, -5, 3, -99, 14, 88, -99] - - Sample Output: - -89 - """ - total = 0 - for b in balances: - total += b - if total < 0: - return total == n -``` -
1 solution to human_eval 4/96 - -```python -def sol(balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): - total = 0 - for b in balances: - total += b - if total < 0: - return total - assert False, "should not reach here" -``` - -
- -### NegCumulative_Trivial -Inspired by [HumanEval](https://github.com/openai/human-eval) \#3 -(see also FirstNegCumulative above which is not as trivial) -This version is a more direct translation of the problem but it can of course -be solved trivially just by trying both neg=True and neg=False - -```python -def sat(neg: bool, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): - """ - Given a list of numbers which represent bank deposits and withdrawals, - determine if the cumulative sum is negative. - - Sample Input: - [12, -5, 3, -99, 14, 88, -99] - - Sample Output: - True - """ - total = 0 - for b in balances: - total += b - if total < 0: - return neg == True - return neg == False -``` -
1 solution to human_eval 5/96 - -```python -def sol(balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]): - total = 0 - for b in balances: - total += b - if total < 0: - return True - return False -``` - -
- -### MinSquaredDeviation -Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \#4 - -The HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting. -It requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if -`mu` is the mean of the numbers then a simple calculation shows that: - -`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))` - -We use 0.501 rather than 1/2 to deal with rounding errors. - -```python -def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): - """ - Given a list of numbers, find x that minimizes mean squared deviation. - - Sample Input: - [4, -5, 17, -9, 14, 108, -9] - - Sample Output: - 17.14285 - """ - return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums) -``` -
1 solution to human_eval 6/96 - -```python -def sol(nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): - return sum(nums) / len(nums) # mean minimizes mean squared deviation -``` - -
- -### Intersperse -Inspired by [HumanEval](https://github.com/openai/human-eval) \#5 - -The one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)` - -```python -def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4): - """ - Given a list of numbers and a number to inject, create a list containing that number in between each pair of - adjacent numbers. - - Sample Input: - [8, 14, 21, 17, 9, -5], 3 - - Sample Output: - [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5] - """ - assert len(li) == max(0, len(nums) * 2 - 1) - for i, n in enumerate(nums): - assert li[2 * i] == n - if i > 0: - assert li[2 * i - 1] == sep - return True -``` -
1 solution to human_eval 7/96 - -```python -def sol(nums=[12, 23, -2, 5, 0], sep=4): - ans = [sep] * (2 * len(nums) - 1) - ans[::2] = nums - return ans -``` - -
- -### DeepestParens -Inspired by [HumanEval](https://github.com/openai/human-eval) \#6 - -```python -def sat(depths: List[int], parens="() (()) ((()()())) (())"): - """ - Given a string consisting of groups of matched nested parentheses separated by parentheses, - compute the depth of each group. - - Sample Input: - '(()) ((()()())) (()) ()' - - Sample Output: - [2, 3, 2, 1] - """ - groups = parens.split() - for depth, group in zip(depths, groups): - budget = depth - success = False - for c in group: - if c == '(': - budget -= 1 - if budget == 0: - success = True - assert budget >= 0 +* **BelowThreshold** Inspired by [HumanEval](https://github.com/openai/human-eval) \#52 (5 instances) + + ```python + def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100): + j = 0 + for i, n in enumerate(nums): + if n < thresh: + assert indexes[j] == i + j += 1 + assert j == len(indexes) + return True + ``` +
81% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the indexes of numbers below a given threshold + + Sample Input: + nums=[4, 7, 11, 5], threshold=10 + + Sample Output: + [0, 1, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [i for i,n in enumerate(nums) if n + +* **CatStrings** Inspired by [HumanEval](https://github.com/openai/human-eval) \#28 (5 instances) + + ```python + def sat(cat: str, strings=['Will', 'i', 'am', 'Now', 'here']): + i = 0 + for s in strings: + for c in s: + assert cat[i] == c + i += 1 + return i == len(cat) + ``` +
79% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strings=['Will', 'i', 'am', 'Now', 'here']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Concatenate a list of strings + + Sample input + --- + ['cat', 'dog', 'bird'] + + Sample output + --- + 'catdogbird' + """ + ``` + Shortest Codex solution: + ```python + return ''.join(strings) + + ``` + Longest Codex solution: + ```python + + result_list = [] + for string_item in strings: + if isinstance(string_item, str): + result_list.append(string_item) + elif isinstance(string_item, list): + # recursive call + result_list += g6(string_item) else: - assert c == ')' - budget += 1 - assert success - - return len(groups) == len(depths) -``` -
1 solution to human_eval 8/96 - -```python -def sol(parens="() (()) ((()()())) (())"): - def max_depth(s): - m = 0 - depth = 0 - for c in s: - if c == '(': - depth += 1 - m = max(m, depth) + raise TypeError(f"Unexpected type {type(string_item)}") + return ''.join(result_list) + + ``` + Hand-written solution: + ```python + return "".join(strings) + ``` +
+ +* **Palindrome** Inspired by [HumanEval](https://github.com/openai/human-eval) \#48 (5 instances) + + ```python + def sat(pals: List[bool], strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']): + return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs)) + ``` +
71% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Test whether the given strings are palindromes + + Sample Input: + ["aba", "no"] + + Sample Output: + [True, False] + """ + ``` + Shortest Codex solution: + ```python + return [s == s[::-1] for s in strs] + + ``` + Longest Codex solution: + ```python + + pals = [] + + for _ in strs: + # padding each string with spaces on both sides + # by default, the pad_to parameter is 50 + s = ' ' * 50 + _ + ' ' * 50 + + i = 0 + j = len(s) - 1 + + while i < j: + if s[i] != s[j]: + pals.append(False) + break + else: + i += 1 + j -= 1 + else: - assert c == ')' - depth -= 1 - assert depth == 0 - return m - - return [max_depth(s) for s in parens.split()] -``` - -
- -### FindContainers -Inspired by [HumanEval](https://github.com/openai/human-eval) \#7 - -```python -def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring="at"): - """ - Find the strings in a list containing a given substring - - Sample Input: - ['cat', 'dog', 'bear'], 'a' - - Sample Output: - ['cat', 'bear'] - """ - i = 0 - for s in strings: - if substring in s: - assert containers[i] == s - i += 1 - return i == len(containers) -``` -
1 solution to human_eval 9/96 - -```python -def sol(strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring="at"): - return [s for s in strings if substring in s] -``` - -
- -### SumProduct -Inspired by [HumanEval](https://github.com/openai/human-eval) \#8 - -```python -def sat(nums: List[int], tot=14, prod=99): - """ - Find a list of numbers with a given sum and a given product. - - Sample Input: - 12, 32 - - Sample Output: - [2, 8, 2] - """ - assert sum(nums) == tot - p = 1 - for n in nums: - p *= n - return p == prod -``` -
1 solution to human_eval 10/96 - -```python -def sol(tot=14, prod=99): - ans = [prod] - while sum(ans) > tot: - ans += [-1, -1] - ans += [1] * (tot - sum(ans)) - return ans -``` - -
- -### SumProduct_Trivial -Inspired by [HumanEval](https://github.com/openai/human-eval) \#8 - -```python -def sat(sum_prod: List[int], nums=[1, 3, 2, -6, 19]): - """ - Find the sum and product of a list of numbers. - - Sample Input: - [2, 8, 2] - - Sample Output: - [12, 32] - """ - p = 1 - for n in nums: - p *= n - return sum_prod == [sum(nums), p] -``` -
1 solution to human_eval 11/96 - -```python -def sol(nums=[1, 3, 2, -6, 19]): - p = 1 - for n in nums: - p *= n - return [sum(nums), p] -``` - -
- -### RollingMax -Inspired by [HumanEval](https://github.com/openai/human-eval) \#9 - -```python -def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]): - """ - Find a list whose ith element is the maximum of the first i elements of the input list. - - Sample Input: - [2, 8, 2] - - Sample Output: - [2, 8, 8] - """ - assert len(maxes) == len(nums) - for i in range(len(nums)): - if i > 0: - assert maxes[i] == max(maxes[i - 1], nums[i]) + pals.append(True) + + return pals + + ``` + Hand-written solution: + ```python + return [s == s[::-1] for s in strs] + ``` +
+ +* **FindExtensions** Inspired by [HumanEval](https://github.com/openai/human-eval) \#29 (5 instances) + + ```python + def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix="do"): + i = 0 + for s in strings: + if s.startswith(prefix): + assert extensions[i] == s + i += 1 + return i == len(extensions) + ``` +
70% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix="do"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the strings in a list starting with a given prefix + + Sample Input: + ['cat', 'car', 'fear', 'center'], 'ca' + + Sample Output: + ['cat', 'car'] + """ + ``` + Shortest Codex solution: + ```python + + return ['dog', 'donut'] + + ``` + Longest Codex solution: + ```python + + extensionPrefix = [s for s in strings if s.startswith(prefix)] + # Re: string: s.startswith(prefix) + # --> if this startswith statement fails, it will return False, + # and we will not add it to 'extensionPrefix', and therefore add it + # to the list of extensions that we want to return on the left + # side of the equals sign on the right side. + # We use the colon syntax for this on line 59 + return extensionPrefix + + ``` + Hand-written solution: + ```python + return [s for s in strings if s.startswith(prefix)] + ``` +
+ +* **StrLength** Inspired by [HumanEval](https://github.com/openai/human-eval) \#23 (5 instances) + + ```python + def sat(lengths: List[int], strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']): + for length, s in zip(lengths, strs): + try: + s[length] + return False + except IndexError: + s[length - 1] + return len(lengths) == len(strs) + ``` +
64% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the lengths of a list of non-empty strings + + Sample input + --- + ["foo", "bars"] + + Sample output + --- + [3, 4] + """ + ``` + Shortest Codex solution: + ```python + + return [*map(len, strs)] + ``` + Longest Codex solution: + ```python + + def update_lengths(lengths): + l = [] + for i in range(len(lengths)): + if i >= len(strs): + l.append(0) + else: + l.append(len(strs[i])) + return l + + for i in range(len(strs)+1): + lengths = update_lengths(range(i)) + for j in range(1000): + lengths = update_lengths(lengths) + if sat(lengths, strs=strs): + return lengths + + ``` + Hand-written solution: + ```python + return [len(s) for s in strs] + ``` +
+ +* **MaxInt** Inspired by [HumanEval](https://github.com/openai/human-eval) \#35 (5 instances) + + ```python + def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]): + return m in hello and not any(m < i for i in hello) + ``` +
63% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the largest integer in a sequence + + Sample Input: + [8, 0, 1, 4, 9, 3, 4, -2, 8, 3] + + Sample Output: + 9 + """ + ``` + Shortest Codex solution: + ```python + + return 3502145 + + ``` + Longest Codex solution: + ```python + + for i,t in enumerate(hello): + if i > len(hello) // 4 + 1: + break + if t == hello[0]: + continue + for j,u in enumerate(hello): + if u == t: + for k,v in enumerate(hello): + if v == t: + continue + if j != k and abs(u - v) > abs(t - u): + hello[k] = t + break + return max(hello) + + ``` + Hand-written solution: + ```python + return max(hello) + ``` +
+ +* **LongestStr** Inspired by [HumanEval](https://github.com/openai/human-eval) \#12 (5 instances) + + ```python + def sat(ans: str, words=['these', 'are', 'some', 'pretty', 'long', 'words']): + return ans in words and all(len(ans) >= len(w) for w in words) + ``` +
62% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(words=['these', 'are', 'some', 'pretty', 'long', 'words']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the longest of a list of strings + + Sample Input: + ["cat", "dog", "sheep", "chimp"] + + Sample Output: + "sheep" + """ + ``` + Shortest Codex solution: + ```python + + return words[3] + + ``` + Longest Codex solution: + ```python + + alphabet = "abcdefghijklmnopqrstuvwxyz" + alphabet = alphabet + alphabet.upper() + alphabet_dict = {} + for k in alphabet: + alphabet_dict[k] = True + alphabet_set = set(alphabet) + max_word = words[0] + for el in words: + if not ((set(el) <= alphabet_set) and (set(el) == set(el).intersection(alphabet_dict.keys()))): + continue + if len(el) >= len(max_word): + max_word = el + return max_word + + ``` + Hand-written solution: + ```python + return max(words, key=len) + ``` +
+ +* **FindContainers** Inspired by [HumanEval](https://github.com/openai/human-eval) \#7 (5 instances) + + ```python + def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring="at"): + i = 0 + for s in strings: + if substring in s: + assert containers[i] == s + i += 1 + return i == len(containers) + ``` +
61% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring="at"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the strings in a list containing a given substring + + Sample Input: + ['cat', 'dog', 'bear'], 'a' + + Sample Output: + ['cat', 'bear'] + """ + ``` + Shortest Codex solution: + ```python + + return strings[::2] + + ``` + Longest Codex solution: + ```python + + + cat = False + dog = False + shatter = False + ta = False + for s in strings: + if substring in s: + if s == 'cat': + cat = True + elif s == 'dog': + dog = True + elif s == 'shatter': + shatter = True + elif s == 'ta': + ta = True + if cat and dog and ta and shatter: + return [string for string in strings if substring in string] + return [string for string in strings if substring in string] + + ``` + Hand-written solution: + ```python + return [s for s in strings if substring in s] + ``` +
+ +* **ClosestInteger** Inspired by [HumanEval](https://github.com/openai/human-eval) \#99 + + Since we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule. (5 instances) + + ```python + def sat(n: int, x=329437923.5): + return abs(n - x) <= 0.5 + ``` +
61% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(x=329437923.5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Round to nearest integer + + --- input --- + 3.7 + + --- output --- + 4 + """ + ``` + Shortest Codex solution: + ```python + return int(x) + + ``` + Longest Codex solution: + ```python + + # If you don't like this answer, try to make your code run faster. + # This is very similar to what we would do in a real interview. + def sum_digits(n: int): + result = 0 + while n: + result += (n % 10) + n //= 10 + return result + n = int(x) + while abs(n - x) > 0.5: + x = x + 0.5 * sum_digits(n) + n = int(x) + return n + + ``` + Hand-written solution: + ```python + return round(x) + ``` +
+ +* **SpaceyRange** Inspired by [HumanEval](https://github.com/openai/human-eval) \#15 (5 instances) + + ```python + def sat(ans: str, n=15): + return [int(i) for i in ans.split(' ')] == list(range(n + 1)) + ``` +
56% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=15): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string consisting of the non-negative integers up to n inclusive + + Sample Input: + 4 + + Sample Output: + '0 1 2 3 4' + """ + ``` + Shortest Codex solution: + ```python + + return ' '.join(map(str,range(n+1))) + + ``` + Longest Codex solution: + ```python + + # Strategy: You could construct the string by starting with an empty string and appending "x" where x is the next integer in the list. The downside to this approach is if the result is large, the actual output could be much larger than the actual list. We could also construct the string by concatenating the string of every number. + return ' '.join(map(str,range(n+1))) + + ``` + Hand-written solution: + ```python + return ' '.join(str(i) for i in range(n + 1)) + ``` +
+ +* **UnevenFind** Inspired by [HumanEval](https://github.com/openai/human-eval) \#87 (5 instances) + + ```python + def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17): + for i, j in indices: + assert uneven[i][j] == target + for i, row in enumerate(uneven): + for j, n in enumerate(row): + assert n != target or [i, j] in indices + return True + ``` +
52% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the indices of all occurrences of target in the uneven matrix + Sample input: + uneven=[[2, 3, 2], [], [9, 2]], target=2 + + Sample output: + [[0, 0], [0, 2], [2, 1]] + """ + ``` + Shortest Codex solution: + ```python + + return [[i, j] for i in range(5) for j,n in enumerate(uneven[i]) if n == target] + + ``` + Longest Codex solution: + ```python + + # Search for element starting from the first row and storing the indices of the found elements in a list + indices = [] + for i, num in enumerate(uneven[0]): + if num == target: + indices.append([0, i]) + # Search for element starting from the first column and storing the indices of the found elements in a list + for row, row_num in zip(uneven[1:], range(1, len(uneven))): + for i, num in enumerate(row): + if num == target: + indices.append([row_num, i]) + return indices + + ``` + Hand-written solution: + ```python + return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target] + ``` +
+ +* **StrangeSplit** Inspired by [HumanEval](https://github.com/openai/human-eval) \#125 (5 instances) + + ```python + def sat(lst: List[str], s="Hello, world!"): + if " " in s: + return " ".join(lst) == s + if "," in s: + return ",".join(lst) == s + return "".join(lst) == "".join(c for c in s if c.islower() and ord(c) % 2 == 0) + ``` +
51% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="Hello, world!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise + return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.) + + "a b c" => ["a", "b", "c"] + "a,b" => ["a", "b"] + """ + ``` + Shortest Codex solution: + ```python + + return [s] + + ``` + Longest Codex solution: + ```python + + if " " in s: + return [x for x in s.split(" ") if x] + if "," in s: + return [x for x in s.split(",") if x] + # once we reach here s is in its final format: lowercase letters in even order + # in this case we want to split by the characters in s in order to preserve the order + # we could just return [c for c in s if c.islower() and ord(c)] + # but even better is to use filter on an iterator of an *iterator of character + # the tools are 'c.islower' and 'ord' + ``` + Hand-written solution: + ```python + if " " in s: + return s.split(" ") + if "," in s: + return s.split(",") + return [c for c in s if c.islower() and ord(c) % 2 == 0] + ``` +
+ +* **Monotonic** Inspired by [HumanEval](https://github.com/openai/human-eval) \#57 (5 instances) + + ```python + def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]): + if direction == "increasing": + return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) + if direction == "decreasing": + return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1)) + ``` +
50% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[2, 4, 17, 29, 31, 1000, 416629]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums + + Sample Input: + [1, 2, 5] + + Sample Output: + "increasing" + """ + ``` + Shortest Codex solution: + ```python + + return "increasing" + ``` + Longest Codex solution: + ```python + + return "increasing" if all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) else \ + "decreasing" if all(nums[i + 1] < nums[i] for i in range(len(nums) - 1)) else \ + "not a monotonic sequence" + + + ``` + Hand-written solution: + ```python + return "increasing" if len(nums) > 1 and nums[1] > nums[0] else "decreasing" + ``` +
+ +* **Frac** Inspired by [HumanEval](https://github.com/openai/human-eval) \#2 (5 instances) + + ```python + def sat(x: float, v=523.12892): + return 0 <= x < 1 and (v - x).is_integer() + ``` +
49% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(v=523.12892): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a floating point number, find its fractional part. + + Sample Input: + 4.175 + + Sample Output: + 0.175 + """ + ``` + Shortest Codex solution: + ```python + + return v%1 + ``` + Longest Codex solution: + ```python + + + def denom(sat): + if sat == 0: + return 1 + elif sat > 0: + return 2 + denom(sat * 2) + else: + return denom(-sat) + + # This expression needs to appear in a context where __eval__() is correct. + x_1 = v % 1 + x_2 = v // 1 + return x_1 if x_1 != x_2 else x_2 - x_1 / denom(x_2 - x_1) + + ``` + Hand-written solution: + ```python + return v % 1.0 + ``` +
+ +* **FlipCase** Inspired by [HumanEval](https://github.com/openai/human-eval) \#27 (5 instances) + + ```python + def sat(ans: str, s="FlIp ME!"): + return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s)) + ``` +
47% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="FlIp ME!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Flip case + + Sample input + --- + 'cAt' + + Sample output + --- + 'CaT' + """ + ``` + Shortest Codex solution: + ```python + + return s.swapcase() + + ``` + Longest Codex solution: + ```python + + ans = "" + if 'a' <= s[0] <= 'z': + ans += s[0].upper() + elif 'A' <= s[0] <= 'Z': + ans += s[0].lower() else: - assert maxes[0] == nums[0] - return True -``` -
2 solutions to human_eval 12/96 - -```python -def sol(nums=[1, 4, 3, -6, 19]): - return [max(nums[:i]) for i in range(1, len(nums) + 1)] -``` - -
- -```python -def sol(nums=[1, 4, 3, -6, 19]): - ans = [] - if nums: - m = nums[0] - for n in nums: - m = max(n, m) - ans.append(m) - return ans -``` - -
- -### PalindromeStartingWith -Inspired by [HumanEval](https://github.com/openai/human-eval) \#10 - -```python -def sat(ans: str, s="so easy", length=13): - """ - Find a palindrome of a given length starting with a given string. - - Sample Input: - "foo", 4 - - Sample Output: - "foof" - """ - return ans == ans[::-1] and len(ans) == length and ans.startswith(s) -``` -
1 solution to human_eval 13/96 - -```python -def sol(s="so easy", length=13): - return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1] -``` - -
- -### PalindromeContaining -Inspired by [HumanEval](https://github.com/openai/human-eval) \#10 - -```python -def sat(ans: str, s="so easy", length=20): - """ - Find a palindrome of a given length containing a given string. - - Sample Input: - "abba", 6 - - Sample Output: - "cabbac" - """ - return ans == ans[::-1] and len(ans) == length and s in ans -``` -
1 solution to human_eval 14/96 - -```python -def sol(s="so easy", length=20): - ls = list(s) - for i in range(length - len(s) + 1): - arr = ['x'] * length - arr[i:i + len(s)] = ls - a = length - i - 1 - b = length - (i + len(s)) - 1 - if b == -1: - b = None - arr[a:b:-1] = ls - if arr == arr[::-1]: - ans = "".join(arr) - if s in ans: - return ans - assert False, "shouldn't reach here" -``` - -
- -### BinaryStrXOR -Inspired by [HumanEval](https://github.com/openai/human-eval) \#11 - -```python -def sat(str_num: str, nums=['100011101100001', '100101100101110']): - """ - Find a the XOR of two given strings interpreted as binary numbers. - - Sample Input: - "0001", "1011" - - Sample Output: - "1010" - """ - a, b = nums - return int(str_num, 2) == int(a, 2) ^ int(b, 2) -``` -
1 solution to human_eval 15/96 - -```python -def sol(nums=['100011101100001', '100101100101110']): - a, b = nums - ans = int(a, 2) ^ int(b, 2) - return format(ans, "b") -``` - -
- -### LongestStr -Inspired by [HumanEval](https://github.com/openai/human-eval) \#12 - -```python -def sat(ans: str, words=['these', 'are', 'some', 'pretty', 'long', 'words']): - """ - Find the longest of a list of strings - - Sample Input: - ["cat", "dog", "sheep", "chimp"] - - Sample Output: - "sheep" - """ - return ans in words and all(len(ans) >= len(w) for w in words) -``` -
1 solution to human_eval 16/96 - -```python -def sol(words=['these', 'are', 'some', 'pretty', 'long', 'words']): - return max(words, key=len) -``` - -
- -### CertifiedGCD -Inspired by [HumanEval](https://github.com/openai/human-eval) \#13 - -```python -def sat(ans: List[int], m=1408862, n=2113293): - """ - Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd - - Sample Input: - 20, 30 - - Sample Output: - 10, -1, 1 - """ - gcd, a, b = ans - return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0 -``` -
1 solution to human_eval 17/96 - -```python -def sol(m=1408862, n=2113293): - """ - Derivation of solution below - Recursive solution guarantees a * (big % small) + b * small == gcd - Let d = big // small so (big % small) == big - small * d - gives a * (big - small * d) + b * small == gcd - or equivalently (b - a * d) * small + a * big == gcd - """ - - def gcd_cert(small, big): - """Returns gcd, a, b, such that small * a + big * b == gcd""" - assert 0 < small <= big - if big % small == 0: - return [small, 1, 0] - gcd, a, b = gcd_cert(big % small, small) - return [gcd, b - a * (big // small), a] - - if m < n: - return gcd_cert(m, n) - gcd, a, b = gcd_cert(n, m) - return [gcd, b, a] -``` - -
- -### AllPrefixes -Inspired by [HumanEval](https://github.com/openai/human-eval) \#14 - -```python -def sat(prefixes: List[str], s="donesezichethofalij"): - """ - Find all prefixes of a given string - - Sample Input: - "aabcd" - - Sample Output: - ["", "a", "aa", "aab", "aabc", "aabcd"] - """ - return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s) -``` -
1 solution to human_eval 18/96 - -```python -def sol(s="donesezichethofalij"): - return [s[:i] for i in range(len(s) + 1)] -``` - -
- -### SpaceyRange -Inspired by [HumanEval](https://github.com/openai/human-eval) \#15 - -```python -def sat(ans: str, n=15): - """ - Find a string consisting of the non-negative integers up to n inclusive - - Sample Input: - 4 - - Sample Output: - '0 1 2 3 4' - """ - return [int(i) for i in ans.split(' ')] == list(range(n + 1)) -``` -
1 solution to human_eval 19/96 - -```python -def sol(n=15): - return ' '.join(str(i) for i in range(n + 1)) -``` - -
- -### DistinctChars -Inspired by [HumanEval](https://github.com/openai/human-eval) \#16 - -```python -def sat(ans: List[str], s="The quick brown fox jumps over the lazy dog!", n=28): - """ - Find the set of distinct characters in a string, ignoring case - - Sample Input: - 'HELlo', 4 - - Sample Output: - ['h', 'e', 'l', 'o'] - """ - assert all(ans.count(c.lower()) == 1 for c in s) - assert all(c == c.lower() for c in ans) - assert all(c in s.lower() for c in ans) - return True -``` -
1 solution to human_eval 20/96 - -```python -def sol(s="The quick brown fox jumps over the lazy dog!", n=28): - return list(set(s.lower())) -``` - -
- -### ParseMusic -Inspired by [HumanEval](https://github.com/openai/human-eval) \#17 - -```python -def sat(beats: List[int], score="o o o| o| .| .| .| o| o| o o o| .|"): - """ - Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1 - - Example input: - 'o o .| o|' - - Example output: - [4, 4, 1, 2] - """ - return " ".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score -``` -
1 solution to human_eval 21/96 - -```python -def sol(score="o o o| o| .| .| .| o| o| o o o| .|"): - mapping = {'.|': 1, 'o|': 2, 'o': 4} - return [mapping[note] for note in score.split()] -``` - -
- -### OverlappingCount -Inspired by [HumanEval](https://github.com/openai/human-eval) \#18 - -```python -def sat(ans: List[int], s="Bananannanaannanaanananananana", sub="anan", count=7): - """ - Find occurrences of a substring in a parent string *including overlaps* - - Sample Input: - 'helllo', 'll' - - Sample Output: - [2, 3] - """ - return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count -``` -
1 solution to human_eval 22/96 - -```python -def sol(s="Bananannanaannanaanananananana", sub="anan", count=7): - ans = [] - for i in range(len(s) + 1): - if s[i:i + len(sub)] == sub: - ans.append(i) - return ans -``` - -
- -### SortNumbers -Inspired by [HumanEval](https://github.com/openai/human-eval) \#19 - -```python -def sat(ans: str, s="six one four three two nine eight"): - """ - Sort numbers based on strings - - Sample input - --- - "six one four" - - Sample output - --- - "one four six" - """ - nums = 'zero one two three four five six seven eight nine'.split() - return [nums.index(x) for x in ans.split(" ")] == sorted([nums.index(x) for x in s.split(" ")]) -``` -
1 solution to human_eval 23/96 - -```python -def sol(s="six one four three two nine eight"): - nums = 'zero one two three four five six seven eight nine'.split() - arr = [nums.index(x) for x in s.split()] - arr.sort() - ans = " ".join([nums[i] for i in arr]) - return ans -``` - -
- -### FindClosePair -Inspired by [HumanEval](https://github.com/openai/human-eval) \#20 - -```python -def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]): - """ - Given a list of numbers, find the indices of the closest pair. - - Sample Input: - [1.2, 5.25, 0.89, 21.0, 5.23] - - Sample Output: - [4, 1] - """ - a, b = inds - assert a != b and a >= 0 and b >= 0 - for i in range(len(nums)): - for j in range(i): - assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a]) - return True -``` -
1 solution to human_eval 24/96 - -```python -def sol(nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]): - best = [0, 1] - best_score = abs(nums[1] - nums[0]) - for i in range(len(nums)): - for j in range(i): - score = abs(nums[i] - nums[j]) - if score < best_score: - best_score = score - best = [i, j] - return best -``` - -
- -### Rescale -Inspired by [HumanEval](https://github.com/openai/human-eval) \#21 - -```python -def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]): - """ - Rescale and shift numbers so that they cover the range [0, 1] - - Sample input - --- - [18.5, 17.0, 18.0, 19.0, 18.0] - - Sample output - --- - [0.75, 0.0, 0.5, 1.0, 0.5] - """ - assert min(ans) == 0.0 and max(ans) == 1.0 - a = min(nums) - b = max(nums) - for i in range(len(nums)): - x = a + (b - a) * ans[i] - assert abs(nums[i] - x) < 1e-6 - return True -``` -
1 solution to human_eval 25/96 - -```python -def sol(nums=[13.0, 17.0, 17.0, 15.5, 2.94]): - nums = nums.copy() - - a = min(nums) - b = max(nums) - if b - a == 0: - return [0.0] + [1.0] * (len(nums) - 1) - for i in range(len(nums)): - nums[i] = (nums[i] - a) / (b - a) - return nums -``` - -
- -### FilterInts -Inspired by [HumanEval](https://github.com/openai/human-eval) \#22 - -```python -def sat(indexes: List[int], li=['Hello', '5', '10', 'bye'], num=2): - """ - Find the indices of valid python integers in a list of strings - - Sample input - --- - ["18.5", "-1", "2+2", "7", "foo"] - - Sample output - --- - [1, 3] - """ - [int(li[i]) for i in indexes] - return len(set(indexes)) >= num and min(indexes) >= 0 -``` -
1 solution to human_eval 26/96 - -```python -def sol(li=['Hello', '5', '10', 'bye'], num=2): - ans = [] - for i in range(len(li)): - try: - int(li[i]) - ans.append(i) - except: - pass - return ans -``` - -
- -### StrLength -Inspired by [HumanEval](https://github.com/openai/human-eval) \#23 - -```python -def sat(length: int, s="pneumonoultramicroscopicsilicovolcanoconiosis"): - """ - Find the length of a non-empty string - - Sample input - --- - "foo" - - Sample output - --- - 3 - """ - try: - s[length] - except IndexError: - s[length - 1] + ans += s[0] + for c in s[1:]: + if 'A' <= c <= 'Z': + ans += c.lower() + elif 'a' <= c <= 'z': + ans += c.upper() + else: + ans += c + return ans + + ``` + Hand-written solution: + ```python + return "".join(c.lower() if c.upper() == c else c.upper() for c in s) + ``` +
+ +* **LastLetters** Inspired by [HumanEval](https://github.com/openai/human-eval) \#134 (5 instances) + + ```python + def sat(y: List[bool], x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']): + assert len(x) == len(y) + for s, b in zip(x, y): + if len(s.split(" ")[-1]) == 1: + assert b == s[-1].isalpha() + else: + assert not b return True -``` -
1 solution to human_eval 27/96 - -```python -def sol(s="pneumonoultramicroscopicsilicovolcanoconiosis"): - return len(s) -``` - -
- -### LargestDivisor -Inspired by [HumanEval](https://github.com/openai/human-eval) \#24 - -```python -def sat(d: int, n=123456): - """ - Find the largest integer divisor of a number n that is less than n - - Sample input - --- - 1000 - - Sample output - --- - 500 - """ - return n % d == 0 and d < n and all(n % e for e in range(d + 1, n)) -``` -
1 solution to human_eval 28/96 - -```python -def sol(n=123456): - return next(d for d in range(n - 1, 0, -1) if n % d == 0) -``` - -
- -### PrimeFactorization -Inspired by [HumanEval](https://github.com/openai/human-eval) \#25 - -```python -def sat(factors: List[int], n=123456, num_factors=8): - """ - Factor number n into a given number of non-trivial factors - - Sample input - --- - 1000, 6 - - Sample output - --- - [2, 2, 2, 5, 5, 5] - """ - assert len(factors) == num_factors - prod = 1 - for d in factors: - prod *= d - assert d > 1 - return prod == n -``` -
1 solution to human_eval 29/96 - -```python -def sol(n=123456, num_factors=8): - if num_factors == 0: - return [] - if num_factors == 1: - return [n] - ans = [] - for d in range(2, n): - while n % d == 0: - n //= d - ans.append(d) - if len(ans) == num_factors - 1: - ans.append(n) - return ans - assert False -``` - -
- -### Dedup -Inspired by [HumanEval](https://github.com/openai/human-eval) \#26 - -```python -def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]): - """ - Remove duplicates from a list of integers, preserving order - - Sample input - --- - [1, 3, 2, 9, 2, 1, 55] - - Sample output - --- - [1, 3, 2, 9, 55] - """ - return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1)) -``` -
1 solution to human_eval 30/96 - -```python -def sol(li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]): - seen = set() - ans = [] - for n in li: - if n not in seen: - ans.append(n) - seen.add(n) - return ans -``` - -
- -### FlipCase -Inspired by [HumanEval](https://github.com/openai/human-eval) \#27 - -```python -def sat(ans: str, s="FlIp ME!"): - """ - Flip case - - Sample input - --- - 'cAt' - - Sample output - --- - 'CaT' - """ - return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s)) -``` -
1 solution to human_eval 31/96 - -```python -def sol(s="FlIp ME!"): - return "".join(c.lower() if c.upper() == c else c.upper() for c in s) -``` - -
- -### CatStrings -Inspired by [HumanEval](https://github.com/openai/human-eval) \#28 - -```python -def sat(cat: str, strings=['Will', 'i', 'am', 'Now', 'here']): - """ - Concatenate a list of strings - - Sample input - --- - ['cat', 'dog', 'bird'] - - Sample output - --- - 'catdogbird' - """ - i = 0 - for s in strings: + ``` +
46% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Determine, for each string in x, whether the last character is an isolated letter + + ["a b c", "abc"] => [True, False] + """ + ``` + Shortest Codex solution: + ```python + + return [len(s.split(" ")[-1])==1 for s in x] + ``` + Longest Codex solution: + ```python + + y: List[bool] = [] + for s in x: + # Input: a check c and a bool b bool + # Output: b bool + # Description: check last letter of s is an isolated letter or not + # Preconditions: true + # Example: + # Input: ... ... + # Output: ... ... + # Reason: ... ... + if len(s.split(" ")[-1]) == 1: + y.append(s[-1].isalpha()) + else: + y.append(False) + return y + + ``` + Hand-written solution: + ```python + return [len(s.split(" ")[-1]) == 1 and s[-1].isalpha() for s in x] + ``` +
+ +* **CharSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#66 (5 instances) + + ```python + def sat(tot: int, s="Add ME uP AND YOU WILL GET A BIG NUMBER!"): for c in s: - assert cat[i] == c - i += 1 - return i == len(cat) -``` -
1 solution to human_eval 32/96 - -```python -def sol(strings=['Will', 'i', 'am', 'Now', 'here']): - return "".join(strings) -``` - -
- -### FindExtensions -Inspired by [HumanEval](https://github.com/openai/human-eval) \#29 - -```python -def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix="do"): - """ - Find the strings in a list starting with a given prefix - - Sample Input: - ['cat', 'car', 'fear', 'center'], 'ca' - - Sample Output: - ['cat', 'car'] - """ - i = 0 - for s in strings: - if s.startswith(prefix): - assert extensions[i] == s - i += 1 - return i == len(extensions) -``` -
1 solution to human_eval 33/96 - -```python -def sol(strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix="do"): - return [s for s in strings if s.startswith(prefix)] -``` - -
- -### FindPositives -Inspired by [HumanEval](https://github.com/openai/human-eval) \#30 - -```python -def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]): - """ - Find the positive integers in a list - - Sample Input: - [-1, 3, 19, -2, 0, 44, 0, 44, 11] - - Sample Output: - [3, 19, 44, 44, 11] - """ - stack = positives[::-1] - for n in nums: - assert n <= 0 or n == stack.pop() - return stack == [] -``` -
1 solution to human_eval 34/96 - -```python -def sol(nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]): - return [i for i in nums if i > 0] -``` - -
- -### FermatComposite -Inspired by [HumanEval](https://github.com/openai/human-eval) \#31 - -```python -def sat(certificate: int, n=1449): - """ - Find a Fermat composite certificate for a number n > 1 - - Sample Input: - 1469 - - Sample Output: - 3 # because (3 ** 1468) % 1469 != 1 - """ - return pow(certificate, n - 1, n) > 1 -``` -
1 solution to human_eval 35/96 - -```python -def sol(n=1449): - return next(i for i in range(2, n) if pow(i, n - 1, n) > 1) -``` - -
- -### OddDegreePolynomialRoot -Polynomials of odd degree always have a real solution. - -Inspired by [HumanEval](https://github.com/openai/human-eval) \#32 - -```python -def sat(root: float, coeffs=[1, 2, 3, 17]): - """ - Find a real root of an odd degree polynomial from its coefficients - - Sample Input: - [1, 0, 8] - - Sample Output: - -2.0 # 1*(-2.0)^3 + 8 == 0 - """ - return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4 -``` -
1 solution to human_eval 36/96 - -```python -def sol(coeffs=[1, 2, 3, 17]): - def p(x): - return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs)) - - for attempt in range(100): - a, b = -(10 ** attempt), (10 ** attempt) - p_a, p_b = p(a), p(b) - while p_a * p_b <= 0: - mid = (a + b) / 2 - p_mid = p(mid) - if abs(p_mid) < 1e-4: - return mid - assert mid not in [a, b] - if p_mid * p_a > 0: - a, p_a = mid, p_mid + if c.isupper(): + tot -= ord(c) + return tot == 0 + ``` +
44% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="Add ME uP AND YOU WILL GET A BIG NUMBER!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Compute the sum of the ASCII values of the upper-case characters in the string. + + Sample Input: + ARt + + Sample Output: + 147 # = 65 + 82 + """ + ``` + Shortest Codex solution: + ```python + + return sum(map(ord,filter(str.isupper,s))) + + ``` + Longest Codex solution: + ```python + + #https://en.wikipedia.org/wiki/Letter_frequency + #https://www.periscopedata.com/en/ + #https://www.npmjs.com/package/t9 + #https://www.npmjs.com/package/count-to-length + #https://www.hackerrank.com/challenges/extra-long-factorials/problem + return sum(ord(c) for c in s if c.isupper()) + + ``` + Hand-written solution: + ```python + return sum(ord(c) for c in s if c.isupper()) + ``` +
+ +* **Drops** Inspired by [HumanEval](https://github.com/openai/human-eval) \#135 (1 instance) + + ```python + def sat(drop_indexes: List[int], nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]): + d = 0 + for i in range(1, len(nums)): + if nums[i] < nums[i - 1]: + assert drop_indexes[d] == i + d += 1 + return d == len(drop_indexes) + ``` +
43% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the indices for which the nums array drops. + + [1,2,3,0,2,4,1] => [3,6] + """ + ``` + Shortest Codex solution: + ```python + + return [i for i,n in enumerate(nums) if n < nums[i-1]] + + ``` + Longest Codex solution: + ```python + + # NOTE: We can detect multiple drops just by checking if nums[i] < nums[i-1] but this requires + # maintaining a list of indices that have been marked as marked by dropping. We would have to + # have a map from num[i] to [i, i, ...] or dict from num[i] to a list of indices corresponding to a drop. + drop_indices = [] + for i in range(1, len(nums)): + if nums[i] < nums[i - 1]: + drop_indices.append(i) + return drop_indices + + ``` + Hand-written solution: + ```python + return [i for i in range(1, len(nums)) if nums[i] < nums[i - 1]] + ``` +
+ +* **RollingMax** Inspired by [HumanEval](https://github.com/openai/human-eval) \#9 (5 instances) + + ```python + def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]): + assert len(maxes) == len(nums) + for i in range(len(nums)): + if i > 0: + assert maxes[i] == max(maxes[i - 1], nums[i]) else: - b, p_b = mid, p_mid - - assert False, "Root finder failed on 100 attempts" -``` - -
- -### TwoThirdsSorted -Inspired by [HumanEval](https://github.com/openai/human-eval) \#33 - -```python -def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]): - """ - Start with a list of integers, keep every third element in place and otherwise sort the list - - Sample Input: - [8, 0, 7, 2, 9, 4, 1, 2, 8, 3] - - Sample Output: - [8, 0, 2, 2, 4, 8, 1, 8, 9, 3] - """ - assert orig[::3] == li[::3], "Keep every third entry fixed" - assert sorted(li) == sorted(orig), "Not even a permutation" - assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3)) - assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3)) - return True -``` -
1 solution to human_eval 37/96 - -```python -def sol(orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]): - n = len(orig) - your_list = orig[::3] - sub = orig[:] - for i in range(int((len(sub) + 2) / 3)): - sub.pop((2 * i)) - sub = sorted(sub) - answ = [] - for i in range(int(n / 3)): - answ.append(your_list[i]) - answ.append(sub[i * 2]) - answ.append(sub[i * 2 + 1]) - if n % 3 == 1: - answ.append(your_list[-1]) - if n % 3 == 2: - answ.append(your_list[-1]) - answ.append(sub[-1]) - return answ -``` - -
- -### UniqueSorted -Inspired by [HumanEval](https://github.com/openai/human-eval) \#34 - -```python -def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]): - """ - Find an increasing sequence consisting of the elements of the original list. - - Sample Input: - [8, 0, 7, 2, 9, 4, 4, -2, 8, 3] - - Sample Output: - [-2, 0, 2, 3, 4, 7, 8, 9] - """ - for i in range(len(li) - 1): - assert li[i] < li[i + 1] - assert li[i] in orig - for n in orig: - assert n in li - return True -``` -
1 solution to human_eval 38/96 - -```python -def sol(orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]): - my_list = sorted(set(orig)) - return my_list -``` - -
- -### MaxInt -Inspired by [HumanEval](https://github.com/openai/human-eval) \#35 - -```python -def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 35, 35, 21, 18, 2, 60]): - """ - Find the largest integer in a sequence - - Sample Input: - [8, 0, 1, 4, 9, 3, 4, -2, 8, 3] - - Sample Output: - 9 - """ - return m in hello and not any(m < i for i in hello) -``` -
1 solution to human_eval 39/96 - -```python -def sol(hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 35, 35, 21, 18, 2, 60]): - return max(hello) -``` - -
- -### SevenElevenThirteen -Inspired by [HumanEval](https://github.com/openai/human-eval) \#36 - -```python -def sat(li: List[List[int]], n=19723, lower=1000): - """ - Find all 7's in integers less than n that are divisible by 11 or 13 - - Sample Input: - 79, 3 - - Sample Output: - [[77, 0], [77, 1], [78, 0]] - """ - assert len({(i, j) for i, j in li}) >= lower, "not enough 7's (ignoring duplicates)" - return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li) -``` -
1 solution to human_eval 40/96 - -```python -def sol(n=19723, lower=1000): - return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7'] -``` - -
- -### HalfSorted -Inspired by [HumanEval](https://github.com/openai/human-eval) \#37 - -```python -def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]): - """ - Start with a list of integers, keep every other element in place and otherwise sort the list - - Sample Input: - [8, 0, 7, 2, 9, 4, 1, 2, 8, 3] - - Sample Output: - [1, 0, 2, 2, 4, 8, 8, 8, 9, 3] - """ - return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2]) -``` -
1 solution to human_eval 41/96 - -```python -def sol(orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]): - n = len(orig) - odds = orig[1::2] - evens = sorted(orig[::2]) - ans = [] - for i in range(len(evens)): - ans.append(evens[i]) - if i < len(odds): - ans.append(odds[i]) - return ans -``` - -
- -### ThreeCycle -Inspired by [HumanEval](https://github.com/openai/human-eval) \#38 - -```python -def sat(s: str, target="Hello world"): - """ - Given a target string, find a string s such that when each group of three consecutive characters is cycled - forward one character, you achieve the target string. - """ - - def cycle3(trip): - return trip if len(trip) != 3 else trip[2] + trip[:2] - - return target == "".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3)) -``` -
1 solution to human_eval 42/96 - -```python -def sol(target="Hello world"): - def un_cycle3(trip): - return trip if len(trip) != 3 else trip[1:3] + trip[0] - - return "".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3)) -``` - -
- -### PrimeFib -Inspired by [HumanEval](https://github.com/openai/human-eval) \#39 - -Ira Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square - -```python -def sat(n: int, lower=123456): - """ - Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers. - """ - assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), "n must be a Fibonacci number" - assert all(n % i for i in range(2, int(n ** 0.5) + 1)), "n must be prime" - return n > lower -``` -
1 solution to human_eval 43/96 - -```python -def sol(lower=123456): - m, n = 2, 3 - while True: - m, n = n, (m + n) - if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)): - return n -``` - -
- -### TripleZeroSum -Inspired by [HumanEval](https://github.com/openai/human-eval) \#40 - -```python -def sat(inds: List[int], nums=[12, -10452, 18242, 10440]): - """ - Find the indices of three numbers that sum to 0 in a list. - """ - return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0 -``` -
1 solution to human_eval 44/96 - -```python -def sol(nums=[12, -10452, 18242, 10440]): - assert len(nums) == 4 - n = sum(nums) - for i in range(4): - if nums[i] == n: - return [j for j in range(4) if j != i] -``` - -
- -### NumPasses -Inspired by [HumanEval](https://github.com/openai/human-eval) \#41 - -```python -def sat(count: int, n=981): - """ - Given n cars traveling East and n cars traveling West on a road, how many passings will there be? - A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars. - """ - for i in range(n): - for j in range(n): - count -= 1 - return count == 0 -``` -
1 solution to human_eval 45/96 - -```python -def sol(n=981): - return n ** 2 -``` - -
- -### ListInc -Increment each element of a list by 1 - -Inspired by [HumanEval](https://github.com/openai/human-eval) \#42 - -```python -def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]): - """ - Decrement each element of new_list by 1 and check that it's old_list - """ - return [i - 1 for i in new_list] == old_list -``` -
1 solution to human_eval 46/96 - -```python -def sol(old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]): - return [i + 1 for i in old_list] -``` - -
- -### PairZeroSum -Inspired by [HumanEval](https://github.com/openai/human-eval) \#43 - -```python -def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]): - """ - Find the indices of two numbers that sum to 0 in a list. - """ - a, b = inds - return nums[a] + nums[b] == 0 -``` -
1 solution to human_eval 47/96 - -```python -def sol(nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]): - s = set(nums) - for i in s: - if -i in s: - return [nums.index(i), nums.index(-i)] -``` - -
- -### ChangeBase -Inspired by [HumanEval](https://github.com/openai/human-eval) \#44 - -```python -def sat(s: str, n=142, base=7): - """ - Write n in the given base as a string - """ - return int(s, base) == n -``` -
1 solution to human_eval 48/96 - -```python -def sol(n=142, base=7): - assert 2 <= base <= 10 - ans = "" - while n: - ans = str(n % base) + ans - n //= base - return ans or "0" -``` - -
- -### TriangleArea -Inspired by [HumanEval](https://github.com/openai/human-eval) \#45 - -```python -def sat(height: int, area=1319098728582, base=45126): - """ - Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer. - """ - return base * height == 2 * area -``` -
1 solution to human_eval 49/96 - -```python -def sol(area=1319098728582, base=45126): - return (2 * area) // base -``` - -
- -### Fib4 -Inspired by [HumanEval](https://github.com/openai/human-eval) \#46 - -Almost identical to problem 63 - -```python -def sat(init: List[int], target=2021): - """ - Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous - four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the - given target number. - """ - a, b, c, d = init - for i in range(99): - a, b, c, d = b, c, d, (a + b + c + d) - return a == target -``` -
1 solution to human_eval 50/96 - -```python -def sol(target=2021): - nums = [target, 0, 0, 0] - for i in range(99): - x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3] - nums = [x] + nums[:3] - return nums -``` - -
- -### Median -One definition of the median is a number that minimizes the sum of absolute deviations. - -Inspired by [HumanEval](https://github.com/openai/human-eval) \#47 - -```python -def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965): - """ - Find an integer that minimizes the sum of absolute deviations with respect to the given numbers. - """ - dev = sum(n - x for n in nums) - return dev <= upper -``` -
1 solution to human_eval 51/96 - -```python -def sol(nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965): - return sorted(nums)[len(nums) // 2] if nums else 0 -``` - -
- -### Palindrome_Trivial -Inspired by [HumanEval](https://github.com/openai/human-eval) \#48 - -```python -def sat(p: bool, s="This problem is trivial but common"): - """ - Test whether the given string is a palindrome - """ - return p == (s == s[::-1]) -``` -
1 solution to human_eval 52/96 - -```python -def sol(s="This problem is trivial but common"): - return s == s[::-1] -``` - -
- -### LittleFermat -Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \#49 - -```python -def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): - """ - Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1 - polynomial (mod p). - Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p). - """ - p = len(poly) - assert p > 2 and all(p % i for i in range(2, p)), "Hint: p is a prime > 2" - - def val(coeffs, n): # evaluate polynomial mod p - return sum(c * pow(n, i, p) for i, c in enumerate(coeffs)) % p - - return all(val(exp_poly, n) == pow(val(poly, n), d, p) for n in range(p)) -``` -
1 solution to human_eval 53/96 - -```python -def sol(d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): - """ - Use repeated squaring to exponentiate polynomial - """ - p = len(poly) - - def prod(poly1, poly2): # multiply two polynomials mod p - ans = [0] * p - for i, a in enumerate(poly1): - for j, b in enumerate(poly2): - e = (i + j) % (p - 1) - if e == 0 and i + j > 1: - e = p - 1 - ans[e] = (ans[e] + a * b) % p + assert maxes[0] == nums[0] + return True + ``` +
43% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(nums=[1, 4, 3, -6, 19]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list whose ith element is the maximum of the first i elements of the input list. + + Sample Input: + [2, 8, 2] + + Sample Output: + [2, 8, 8] + """ + ``` + Shortest Codex solution: + ```python + + return [max(nums[:i+1]) for i in range(5)] + + ``` + Longest Codex solution: + ```python + + # Brute force approach + # Brute force approach improves as n increases. + # + # If using a dictionary, then as n increases, this method will be more + # efficient as the dicitonary will quickly contain all the necessary keys. + # + # The algorithm is similar to a divide and conquer algorithm, but with a + # few tweaks. On each iteration we try to find the largest contiguous + # subpart. + # + maxes = [-1] + for v in nums: + maxes.append(max(maxes[-1], v)) + return maxes[1:] + + ``` + Hand-written solution: + ```python + return [max(nums[:i]) for i in range(1, len(nums) + 1)] + ``` + Hand-written solution: + ```python + ans = [] + if nums: + m = nums[0] + for n in nums: + m = max(n, m) + ans.append(m) return ans - - ans = [1] + [0] * (p - 1) - while d: - if d % 2: - ans = prod(ans, poly) - poly = prod(poly, poly) - d //= 2 - # for i in range(d): - # ans = prod(ans, poly) - return ans -``` - -
- -### ShiftChars -Inspired by [HumanEval](https://github.com/openai/human-eval) \#50 - -```python -def sat(orig: str, result="Hello, world!", shift=7): - """ - Find a string which, when each character is shifted (ascii incremented) by shift, gives the result. - """ - n = len(result) - assert len(orig) == n - return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n)) -``` -
1 solution to human_eval 54/96 - -```python -def sol(result="Hello, world!", shift=7): - return "".join(chr(ord(c) - shift) for c in result) -``` - -
- -### RemoveVowels -Inspired by [HumanEval](https://github.com/openai/human-eval) \#51 - -```python -def sat(txt: str, text="Hello, world!"): - """ - Remove the vowels from the original string. - """ - n = 0 - for c in text: - if c.lower() not in "aeiou": - assert txt[n] == c - n += 1 - assert n == len(txt) - return True -``` -
1 solution to human_eval 55/96 - -```python -def sol(text="Hello, world!"): - return "".join(c for c in text if c.lower() not in "aeiou") -``` - -
- -### BelowThreshold -Inspired by [HumanEval](https://github.com/openai/human-eval) \#52 - -```python -def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100): - """ - Find the indexes of numbers below a given threshold - """ - j = 0 - for i, n in enumerate(nums): - if n < thresh: - assert indexes[j] == i - j += 1 - assert j == len(indexes) - return True -``` -
1 solution to human_eval 56/96 - -```python -def sol(nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100): - return [i for i, n in enumerate(nums) if n < thresh] -``` - -
- -### ListTotal -Inspired by [HumanEval](https://github.com/openai/human-eval) \#53 - -```python -def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]): - """ - Find the indexes of numbers below a given threshold - """ - return sum(nums + [-n]) == 0 -``` -
1 solution to human_eval 57/96 - -```python -def sol(nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]): - return sum(nums) -``` - -
- -### DiffChars -Inspired by [HumanEval](https://github.com/openai/human-eval) \#54 - -```python -def sat(c: str, a="the quick brown fox jumped over the lazy dog", b="how vexingly quick daft zebras jump"): - """ - Find a character in one string that is not in the other. - """ - return (c in a) != (c in b) -``` -
1 solution to human_eval 58/96 - -```python -def sol(a="the quick brown fox jumped over the lazy dog", b="how vexingly quick daft zebras jump"): - return sorted(set(a).symmetric_difference(b))[0] -``` - -
- -### Fibonacci -Inspired by [HumanEval](https://github.com/openai/human-eval) \#55 - -```python -def sat(nums: List[int], n=1402): - """ - Find the first n Fibonacci numbers - """ - return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2)) -``` -
1 solution to human_eval 59/96 - -```python -def sol(n=1402): - ans = [1, 1] - while len(ans) < n: - ans.append(ans[-1] + ans[-2]) - return ans -``` - -
- -### MatchBrackets -Inspired by [HumanEval](https://github.com/openai/human-eval) \#56 - -```python -def sat(matches: List[int], brackets="<<>><<<><>><<>>>"): - """ - Find the index of the matching brackets for each character in the string - """ - for i in range(len(brackets)): - j = matches[i] - c = brackets[i] - assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j)) - return len(matches) == len(brackets) -``` -
1 solution to human_eval 60/96 - -```python -def sol(brackets="<<>><<<><>><<>>>"): - matches = [-1] * len(brackets) - opens = [] - for i, c in enumerate(brackets): - if c == "<": - opens.append(i) - else: - assert c == ">" - j = opens.pop() - matches[i] = j - matches[j] = i - return matches -``` - -
- -### Monotonic -Inspired by [HumanEval](https://github.com/openai/human-eval) \#57 - -```python -def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]): - """ - Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums - """ - if direction == "increasing": - return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) - if direction == "decreasing": - return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1)) -``` -
1 solution to human_eval 61/96 - -```python -def sol(nums=[2, 4, 17, 29, 31, 1000, 416629]): - return "increasing" if len(nums) > 1 and nums[1] > nums[0] else "decreasing" -``` - -
- -### CommonNumbers -Inspired by [HumanEval](https://github.com/openai/human-eval) \#58 - -```python -def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]): - """ - Find numbers common to a and b - """ - return all((i in common) == (i in a and i in b) for i in a + b + common) -``` -
1 solution to human_eval 62/96 - -```python -def sol(a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]): - return sorted(set(a).intersection(set(b))) -``` - -
- -### LargestPrimeFactor -Inspired by [HumanEval](https://github.com/openai/human-eval) \#59 - -```python -def sat(p: int, n=101076): - """ - Find the largest prime factor of n. - """ - - def is_prime(m): - return all(m % i for i in range(2, m - 1)) - - return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n)) -``` -
1 solution to human_eval 63/96 - -```python -def sol(n=101076): - def is_prime(m): - return all(m % i for i in range(2, m - 1)) - - return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i)) -``` - -
- -### CumulativeSums -Inspired by [HumanEval](https://github.com/openai/human-eval) \#60 - -```python -def sat(sums: List[int], n=104): - """ - Find the sums of the integers from 1 to n - """ - return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0 -``` -
1 solution to human_eval 64/96 - -```python -def sol(n=104): - ans = [0] - for i in range(n): - ans.append(ans[-1] + i) - return ans -``` - -
- -### ParenDepth -Inspired by [HumanEval](https://github.com/openai/human-eval) \#61 - -Note that problems 61 and 56 are essentially the same - -```python -def sat(matches: List[int], parens="((())()(()()))(())"): - """ - Find the index of the matching parentheses for each character in the string - """ - for i, (j, c) in enumerate(zip(matches, parens)): - assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j)) - return len(matches) == len(parens) -``` -
1 solution to human_eval 65/96 - -```python -def sol(parens="((())()(()()))(())"): - matches = [-1] * len(parens) - opens = [] - for i, c in enumerate(parens): - if c == "(": - opens.append(i) - else: - assert c == ")" - j = opens.pop() - matches[i] = j - matches[j] = i - return matches -``` - -
- -### Derivative -Inspired by [HumanEval](https://github.com/openai/human-eval) \#62 - -```python -def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]): - """ - Find the derivative of the given polynomial, with coefficients in order of increasing degree - """ - - def val(poly, x): - return sum(coeff * (x ** i) for i, coeff in enumerate(poly)) - - return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly))) -``` -
1 solution to human_eval 66/96 - -```python -def sol(poly=[2, 1, 0, 4, 19, 231, 0, 5]): - return [i * poly[i] for i in range(1, len(poly))] -``` - -
- -### Fib3 -Inspired by [HumanEval](https://github.com/openai/human-eval) \#63 - -Almost identical to problem 46 - -```python -def sat(init: List[int], target=124156): - """ - Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous - three. Given a target number, find an initial triple such that the 17th number in the sequence is the - given target number. - """ - a, b, c = init - for i in range(16): - a, b, c = b, c, (a + b + c) - return a == target -``` -
1 solution to human_eval 67/96 - -```python -def sol(target=124156): - nums = [target, 0, 0] - for i in range(16): - x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3] - nums = [x] + nums[:-1] - return nums -``` - -
- -### FindVowels -Inspired by [HumanEval](https://github.com/openai/human-eval) \#64 - -```python -def sat(vowels: str, text="Hello, world!"): - """ - Find the vowels from the original string. - """ - i = 0 - for j, c in enumerate(text): - if c.lower() in "aeiou" or c.lower() == 'y' and j == len(text) - 1: - assert vowels[i] == c - i += 1 - return i == len(vowels) -``` -
1 solution to human_eval 68/96 - -```python -def sol(text="Hello, world!"): - return "".join(c for c in text if c.lower() in "aeiou") + (text[-1] if text[-1].lower() == "y" else "") -``` - -
- -### CircularShiftNum -Inspired by [HumanEval](https://github.com/openai/human-eval) \#65 - -```python -def sat(shifted: str, n=124582369835, shift=3): - """ - Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of - digits of n, reverse the string. - """ - if shift > len(str(n)): - return n == int(shifted[::-1]) - return n == int(shifted[-shift:] + shifted[:-shift]) -``` -
1 solution to human_eval 69/96 - -```python -def sol(n=124582369835, shift=3): - s = str(n) - if shift > len(s): - return s[::-1] - return s[shift:] + s[:shift] -``` - -
- -### CharSum -Inspired by [HumanEval](https://github.com/openai/human-eval) \#66 - -```python -def sat(tot: int, s="Add ME uP AND YOU WILL GET A BIG NUMBER!"): - """ - Compute the sum of the ASCII values of the upper-case characters in the string. - """ - for c in s: - if c.isupper(): - tot -= ord(c) - return tot == 0 -``` -
1 solution to human_eval 70/96 - -```python -def sol(s="Add ME uP AND YOU WILL GET A BIG NUMBER!"): - return sum(ord(c) for c in s if c.isupper()) -``` - -
- -### MissingBananas -Inspired by [HumanEval](https://github.com/openai/human-eval) \#67 - -```python -def sat(bananas: int, bowl="5024 apples and 12189 oranges", total=12491241): - """ - Determine how many bananas are necessary to reach a certain total amount of fruit - """ - bowl += f" and {bananas} bananas" - return sum([int(s) for s in bowl.split() if s.isdigit()]) == total -``` -
1 solution to human_eval 71/96 - -```python -def sol(bowl="5024 apples and 12189 oranges", total=12491241): - apples, oranges = [int(s) for s in bowl.split() if s.isdigit()] - return total - apples - oranges -``` - -
- -### SmallestEven -Inspired by [HumanEval](https://github.com/openai/human-eval) \#68 - -```python -def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]): - """ - Given an array of nums representing a branch on a binary tree, find the minimum even value and its index. - In the case of a tie, return the smallest index. If there are no even numbers, the answer is []. - """ - if val_index == []: - return all(n % 2 == 1 for n in nums) - v, i = val_index - assert v % 2 == 0 - return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:]) -``` -
1 solution to human_eval 72/96 - -```python -def sol(nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]): - if any(n % 2 == 0 for n in nums): - return min([v, i] for i, v in enumerate(nums) if v % 2 == 0) - else: - return [] -``` - -
- -### GreatestHIndex -Inspired by [HumanEval](https://github.com/openai/human-eval) \#69 - -```python -def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]): - """ - Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times. - h = -1 if there is no such positive number. - """ - for i in seq: - assert not (i > 0 and i > h and seq.count(i) >= i) - return h == -1 or seq.count(h) >= h > 0 -``` -
1 solution to human_eval 73/96 - -```python -def sol(seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]): - return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i]) -``` - -
- -### StrangeSort -Inspired by [HumanEval](https://github.com/openai/human-eval) \#70 - -```python -def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]): - """ - Find the following strange sort of li: the first element is the smallest, the second is the largest of the - remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc. - """ - if len(li) < 2: - return strange == li - bounds = strange[:2] # lower, upper - for i, n in enumerate(strange): - assert bounds[0] <= n <= bounds[1] - bounds[i % 2] = n - return sorted(strange) == sorted(li) # permutation check -``` -
1 solution to human_eval 74/96 - -```python -def sol(li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]): - s = sorted(li) - i = 0 - j = len(li) - 1 - ans = [] - while i <= j: - if len(ans) % 2: - ans.append(s[j]) - j -= 1 - else: - ans.append(s[i]) - i += 1 - return ans -``` - -
- -### HeronTriangle -Inspired by [HumanEval](https://github.com/openai/human-eval) \#71 - -That problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides. -In our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates -of a triangle with the given sides. If one knows the area, this is a straightforward calculation. - -```python -def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]): - """ - Find the coordinates of a triangle with the given side lengths - """ - assert len(coords) == 3 - sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]] - return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2))) -``` -
1 solution to human_eval 75/96 - -```python -def sol(sides=[8.9, 10.8, 17.0]): - a, b, c = sorted(sides) - - s = sum(sides) / 2 # semi-perimeter - area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula - - y = 2 * area / a # height - x = (c ** 2 - y ** 2) ** 0.5 - return [[0.0, 0.0], [a, 0.0], [x, y]] -``` - -
- -### InvestigateCrash -Inspired by [HumanEval](https://github.com/openai/human-eval) \#72 - -```python -def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100): - """ - An object will "fly" if its weights are a palindrome and sum to <= max_weight. The given object won't fly. - You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big. - """ - if problem == -1: - return sum(weights) > max_weight - return weights[problem] != weights[- 1 - problem] -``` -
1 solution to human_eval 76/96 - -```python -def sol(weights=[1, 2, 5, 2, 1, 17], max_weight=100): - if sum(weights) > max_weight: - return -1 - return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i]) -``` - -
- -### ClosestPalindrome -Inspired by [HumanEval](https://github.com/openai/human-eval) \#73 - -```python -def sat(pal: str, s="palindromordinals"): - """ - Find the closest palindrome - """ - assert pal == pal[::-1] and len(pal) == len(s) - return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2 -``` -
1 solution to human_eval 77/96 - -```python -def sol(s="palindromordinals"): - n = len(s) - return s[:(n + 1) // 2] + s[:n // 2][::-1] -``` - -
- -### NarrowerList -Inspired by [HumanEval](https://github.com/openai/human-eval) \#74 - -```python -def sat(li: List[str], lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]): - """ - Find the list that has fewer total characters (including repetitions) - """ - width = sum(len(s) for s in li) - for li2 in lists: - assert width <= sum(len(s) for s in li2) - return li in lists -``` -
1 solution to human_eval 78/96 - -```python -def sol(lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]): - return min(lists, key=lambda x: sum(len(i) for i in x)) -``` - -
- -### ThreePrimes -Inspired by [HumanEval](https://github.com/openai/human-eval) \#75 - -```python -def sat(factors: List[List[int]]): - """ - Find all 247 integers <= 1000 that are the product of exactly three primes. - Each integer should represented as the list of its three prime factors. - """ - primes = set(range(2, 1000)) - for n in range(2, 1000): - if n in primes: - primes.difference_update(range(2 * n, 1000, n)) - assert all(p in primes for f in factors for p in f), "all factors must be prime" - nums = {p * q * r for p, q, r in factors} - return max(nums) < 1000 and len(nums) == 247 -``` -
1 solution to human_eval 79/96 - -```python -def sol(): - primes = set(range(2, 1000)) - for n in range(2, 1000): - if n in primes: - primes.difference_update(range(2 * n, 1000, n)) - 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] -``` - -
- -### IntegerLog -Inspired by [HumanEval](https://github.com/openai/human-eval) \#76 - -```python -def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849): - """Find an integer exponent x such that a^x = n""" - return a ** x == n -``` -
1 solution to human_eval 80/96 - -```python -def sol(a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849): - m = 1 - x = 0 - while m != n: - x += 1 - m *= a - return x -``` - -
- -### CubeRoot -Inspired by [HumanEval](https://github.com/openai/human-eval) \#77 - -We made it harder by giving very large n for which `round(n ** (1/3))` - -```python -def sat(x: int, n=42714774173606970182754018064350848294149432972747296768): - """Find an integer that when cubed is n""" - return x ** 3 == n -``` -
1 solution to human_eval 81/96 - -```python -def sol(n=42714774173606970182754018064350848294149432972747296768): # Using Newton's method - m = abs(n) - x = round(abs(n) ** (1 / 3)) - while x ** 3 != m: - x += (m - x ** 3) // (3 * x ** 2) - return -x if n < 0 else x -``` - -
- -### HexPrimes -Inspired by [HumanEval](https://github.com/openai/human-eval) \#78 - -```python -def sat(primes: List[bool], n="A4D4455214122CE192CCBE3"): - """Determine which characters of a hexidecimal correspond to prime numbers""" - return all(primes[i] == (c in "2357BD") for i, c in enumerate(n)) -``` -
1 solution to human_eval 82/96 - -```python -def sol(n="A4D4455214122CE192CCBE3"): - return [c in "2357BD" for c in n] -``` - -
- -### Binarize -Inspired by [HumanEval](https://github.com/openai/human-eval) \#79 - -```python -def sat(b: str, n=5324680297138495285): - """Write n base 2 followed and preceded by 'bits'""" - assert b[:4] == b[-4:] == 'bits' - inside = b[4:-4] - assert all(c in "01" for c in inside) - assert inside[0] == "1" or len(inside) == 1 - m = 0 - for c in inside: - m = 2 * m + int(c) - return m == n -``` -
1 solution to human_eval 83/96 - -```python -def sol(n=5324680297138495285): - s = bin(n)[2:] - return f'bits{s}bits' -``` - -
- -### NearbyDuplicates -Inspired by [HumanEval](https://github.com/openai/human-eval) \#80 - -```python -def sat(indices: List[int], s="I am an unhappy string!"): - """A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.""" - i, j = indices - return s[i] == s[j] and 0 <= i < j < i + 3 -``` -
1 solution to human_eval 84/96 - -```python -def sol(s="I am an unhappy string!"): - for i in range(len(s) - 2): - if s[i] == s[i + 1]: - return [i, i + 1] - if s[i] == s[i + 2]: - return [i, i + 2] -``` - -
- -### Grader -Inspired by [HumanEval](https://github.com/openai/human-eval) \#81 - -```python -def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]): - """ - Convert GPAs to letter grades according to the following table: - 4.0: A+ - 3.7: A - 3.4: A- - 3.0: B+ - 2.7: B - 2.4: B- - 2.0: C+ - 1.7: C - 1.4: C- - below: F - - Sample input: [4.0, 3.5, 3.8] - Sample output: ['A+', 'A-', 'A'] - """ - assert len(grades) == len(gpas) - letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'] - scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0] - for grade, gpa in zip(grades, gpas): - i = letters.index(grade) - assert gpa >= scores[i] - assert i == 0 or gpa <= scores[i - 1] - return True -``` -
1 solution to human_eval 85/96 - -```python -def sol(gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]): - letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'] - scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0] - ans = [] - for gpa in gpas: + ``` +
+ +* **OverlappingCount** Inspired by [HumanEval](https://github.com/openai/human-eval) \#18 (5 instances) + + ```python + def sat(ans: List[int], s="Bananannanaannanaanananananana", sub="anan", count=7): + return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count + ``` +
42% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="Bananannanaannanaanananananana", sub="anan", count=7): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find occurrences of a substring in a parent string *including overlaps* + + Sample Input: + 'helllo', 'll' + + Sample Output: + [2, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [x for x in range(len(s)-3) if s[x:x+4]==sub] + + ``` + Longest Codex solution: + ```python + + # outer loop finds the first match of sub in s + # finds occurrences of sub in s + # finds next match of sub in s after the first one + # finds next match of sub in s after the second one + prev = -1 # finds last succesfull match of sub in s + output = [] + match = -1 + for i in range(len(s)): + if s[i:i+len(sub)] == sub: + match = i + if match != prev+1: + output.append(match) + prev = match + if len(output) >= count: + return output + return + ``` + Hand-written solution: + ```python + ans = [] + for i in range(len(s) + 1): + if s[i:i + len(sub)] == sub: + ans.append(i) + return ans + ``` +
+ +* **FindPositives** Inspired by [HumanEval](https://github.com/openai/human-eval) \#30 (5 instances) + + ```python + def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]): + stack = positives[::-1] + for n in nums: + assert n <= 0 or n == stack.pop() + return stack == [] + ``` +
42% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the positive integers in a list + + Sample Input: + [-1, 3, 19, -2, 0, 44, 0, 44, 11] + + Sample Output: + [3, 19, 44, 44, 11] + """ + ``` + Shortest Codex solution: + ```python + + return [n for n in nums if n>0] + ``` + Longest Codex solution: + ```python + + return [n for n in nums if n > 0] + + ``` + Hand-written solution: + ```python + return [i for i in nums if i > 0] + ``` +
+ +* **BinaryStrXOR** Inspired by [HumanEval](https://github.com/openai/human-eval) \#11 (5 instances) + + ```python + def sat(str_num: str, nums=['100011101100001', '100101100101110']): + a, b = nums + return int(str_num, 2) == int(a, 2) ^ int(b, 2) + ``` +
41% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=['100011101100001', '100101100101110']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a the XOR of two given strings interpreted as binary numbers. + + Sample Input: + "0001", "1011" + + Sample Output: + "1010" + """ + ``` + Shortest Codex solution: + ```python + + return bin(int(nums[0],2) ^ int(nums[1],2)) + + ``` + Longest Codex solution: + ```python + + a, b = nums + xor = int(a, 2) ^ int(b, 2) + return bin(xor)[2:].zfill(len(a)) + + ``` + Hand-written solution: + ```python + a, b = nums + ans = int(a, 2) ^ int(b, 2) + return format(ans, "b") + ``` +
+ +* **CommonNumbers** Inspired by [HumanEval](https://github.com/openai/human-eval) \#58 (5 instances) + + ```python + def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]): + return all((i in common) == (i in a and i in b) for i in a + b + common) + ``` +
40% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find numbers common to a and b + + Sample Input: + [1, 2, 3], [3, 4, 5] + + Sample Output: + [3] + """ + ``` + Shortest Codex solution: + ```python + + return (a + b)[::2] + + ``` + Longest Codex solution: + ```python + + # Note: we could also take advantage of the fact the there are only 6 numbers in both lists + # so there must be 2 in common. + # + # But, I was told to check if the numbers were in both lists ... + # + # Solution using sets + # - setting 'common' to the union of 'a' and 'b' leads to an error when the test fails + # due to subtle order differences in the built-in hash functions for list and tuple + # vs. the built-in hash functions for set + common = [i for i in a if i in b] + return common + + ``` + Hand-written solution: + ```python + return sorted(set(a).intersection(set(b))) + ``` +
+ +* **InvestigateCrash** Inspired by [HumanEval](https://github.com/openai/human-eval) \#72 (5 instances) + + ```python + def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100): + if problem == -1: + return sum(weights) > max_weight + return weights[problem] != weights[- 1 - problem] + ``` +
40% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(weights=[1, 2, 5, 2, 1, 17], max_weight=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + An object will "fly" if its weights are a palindrome and sum to <= max_weight. The given object won't fly. + You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big. + + weights=[77, 40], max_weight=100 => -1 + + weights=[1,2,3], max_weight=50 => 0 # because 1 != 3 + """ + ``` + Shortest Codex solution: + ```python + + return 0 + ``` + Longest Codex solution: + ```python + + return next((i for i, (x, y) in enumerate(zip(weights[:-1], weights[1:])) + if x != y), -1) + ``` + Hand-written solution: + ```python + if sum(weights) > max_weight: + return -1 + return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i]) + ``` +
+ +* **LargestStringNum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#137 (5 instances) + + ```python + def sat(x: float, str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']): + found = False + for s in str_nums: + y = float(s.replace(",", ".")) + assert y <= x + if y == x: + found = True + return found + ``` +
40% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the largest number where commas or periods are decimal points + + ["99,9", "100"] => 100.0 + """ + ``` + Shortest Codex solution: + ```python + + return 99.09 + ``` + Longest Codex solution: + ```python + + # HINT: The best way to find the largest value is to keep re-picking + # the largest value as you go. + # + # The reason we don't just take the first value as the first + # value as the first one might not be the largest. + # + # TODO: Implement this! + numbers = [] + for s in str_nums: + numbers.append(float(s.replace(",", "."))) + numbers.sort() + return numbers[-1] + + ``` + Hand-written solution: + ```python + return max(float(s.replace(",", ".")) for s in str_nums) + ``` +
+ +* **BinarySort** Inspired by [HumanEval](https://github.com/openai/human-eval) \#116 (5 instances) + + ```python + def sat(ordered: List[int], arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]): + if sorted(ordered) != sorted(arr): + return False # not even a permutation + return all(bin(a).count("1") <= bin(b).count("1") for a, b in zip(ordered, ordered[1:])) + ``` +
37% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Sort the numbers in arr based on the number of 1's in their binary representation. + + [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6] + """ + ``` + Shortest Codex solution: + ```python + + return sorted(arr, key=bin) + ``` + Longest Codex solution: + ```python + + unordered = arr.copy() + ordered = [] + while unordered: + first = unordered.pop(0) + for i, o in enumerate(ordered): + if bin(first).count("1") <= bin(o).count("1"): + # bin("101").count("1") = 3 + # bin("110").count("1") = 2 + # This is wrong because it should be o < first + break + else: + i = len(ordered) + ordered.insert(i, first) + return ordered + + ``` + Hand-written solution: + ```python + return sorted(arr, key=lambda n: bin(n).count("1")) + ``` +
+ +* **Rescale** Inspired by [HumanEval](https://github.com/openai/human-eval) \#21 (5 instances) + + ```python + def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]): + assert min(ans) == 0.0 and max(ans) == 1.0 + a = min(nums) + b = max(nums) + for i in range(len(nums)): + x = a + (b - a) * ans[i] + assert abs(nums[i] - x) < 1e-6 + return True + ``` +
35% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[13.0, 17.0, 17.0, 15.5, 2.94]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Rescale and shift numbers so that they cover the range [0, 1] + + Sample input + --- + [18.5, 17.0, 18.0, 19.0, 18.0] + + Sample output + --- + [0.75, 0.0, 0.5, 1.0, 0.5] + """ + ``` + Shortest Codex solution: + ```python + + return [(n-min(nums))/(max(nums)-min(nums)) for n in nums] + + ``` + Longest Codex solution: + ```python + + a = min(nums) + b = max(nums) + return [(x - a) / (b - a) for x in nums] + """ + TODO: Uncomment the below as you implement. + This is what this function should do: + 1. Find the minimum and maximum values in the list + 2. For each input value find the scaled value as explained in the comment block above. + To keep the output the same as the sample input, use the mean value of the min and max. + """ + + ``` + Hand-written solution: + ```python + nums = nums.copy() + + a = min(nums) + b = max(nums) + if b - a == 0: + return [0.0] + [1.0] * (len(nums) - 1) + for i in range(len(nums)): + nums[i] = (nums[i] - a) / (b - a) + return nums + ``` +
+ +* **RemoveVowels** Inspired by [HumanEval](https://github.com/openai/human-eval) \#51 + + Related to FindVowels \#54 (5 instances) + + ```python + def sat(txt: str, text="Hello, world!"): + n = 0 + for c in text: + if c.lower() not in "aeiou": + assert txt[n] == c + n += 1 + assert n == len(txt) + return True + ``` +
34% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(text="Hello, world!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Remove the vowels from the original string. + + Sample Input: + "very good" + + Sample Output: + 'vry gd' + """ + ``` + Shortest Codex solution: + ```python + + return text.replace("e", "").replace("o", "") + + ``` + Longest Codex solution: + ```python + + return "".join([c for c in text if c not in set("aeiou")]) # To testing AlgebraicIdentifier you'll need to replace this line with your solution. Feel free to try with or without the set comprehension. Actually I never tried the set comprehension. I literally just used a list comprehension with it literally right out of the book. Congrats to you. I believe this is correct. + + ``` + Hand-written solution: + ```python + return "".join(c for c in text if c.lower() not in "aeiou") + ``` +
+ +* **UppercaseEven** Inspired by [HumanEval](https://github.com/openai/human-eval) \#98 (5 instances) + + ```python + def sat(positions: List[int], s="ThIs is A tEsT, Or *IS* iT?"): + assert all(s[i] in "AEIOU" for i in positions) + return all(i in positions or c not in "AEIOU" or i % 2 == 1 for i, c in enumerate(s)) + ``` +
33% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="ThIs is A tEsT, Or *IS* iT?"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the positions of all uppercase vowels (not counting Y) in even indices + + "EAT here NOW" => [0, 10] + """ + ``` + Shortest Codex solution: + ```python + + return [i for i in range(24) if s[i] in "AEIOU"] + + ``` + Longest Codex solution: + ```python + + return [i for i, c in enumerate(s) if i % 2 == 0 and c in "AEIOU"] + + ``` + Hand-written solution: + ```python + return [i for i, c in enumerate(s) if i % 2 == 0 and c in "AEIOU"] + ``` +
+ +* **MinSquaredDeviation** Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \#4 + + The HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting. + It requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if + `mu` is the mean of the numbers then a simple calculation shows that: + + `sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))` + + We use 0.501 rather than 1/2 to deal with rounding errors. (5 instances) + + ```python + def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): + return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4 + ``` +
31% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of numbers, find x that minimizes mean squared deviation. + + Sample Input: + [4, -5, 17, -9, 14, 108, -9] + + Sample Output: + 17.14285 + """ + ``` + Shortest Codex solution: + ```python + + return 10/len(nums) + + ``` + Longest Codex solution: + ```python + + solve = lambda x: sum((m - x) ** 2 for m in nums) * len(nums) # use exponentiation by squaring + + guess = sum(nums)/len(nums) # Since we know the mean, we start with the mean guess. + assert sat(guess, nums) + + low, high = 0, 2*guess + while (high - low) > 1e-4: + mid = (low + high) / 2 + if sat(mid, nums): + guess = mid + high = mid + else: + low = mid + return guess + + ``` + Hand-written solution: + ```python + return sum(nums) / len(nums) # mean minimizes mean squared deviation + ``` +
+ +* **MostUnique** Inspired by [HumanEval](https://github.com/openai/human-eval) \#158 (5 instances) + + ```python + def sat(s: str, pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']): + assert s in pool + n = len(set(s)) + for p in pool: + assert len(set(p)) <= n + return True + ``` +
31% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Select a string from the pool with the most unique characters + + ["woooow", "cow"] => "cow" + """ + ``` + Shortest Codex solution: + ```python + + return pool[2] + ``` + Longest Codex solution: + ```python + + largest_set = {} + n = 0 + largest = None + for phrase in pool: + diff = len(largest_set) - len(set(phrase)) + if diff < 0: + largest_set = set(phrase) + largest = phrase + n = len(largest_set) + elif diff == 0: + if n < len(set(phrase)): + largest_set = set(phrase) + largest = phrase + n = len(largest_set) + else: + pass + return largest + + ``` + Hand-written solution: + ```python + return max(pool, key=lambda x: len(set(x))) + ``` +
+ +* **EvenSqure** Inspired by [HumanEval](https://github.com/openai/human-eval) \#151 (5 instances) + + ```python + def sat(tot: int, xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]): + for x in xs: + if x.is_integer() and x > 0 and x % 2 == 0: + tot -= int(x) ** 2 + + return tot == 0 + ``` +
28% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sum of the squares of the positive even integers + + [2.0, 3.0, 2.5, 4.0] => 20 + """ + ``` + Shortest Codex solution: + ```python + + return sum((x%2==0)*int(x**2) for x in xs) + + ``` + Longest Codex solution: + ```python + + start = 0 + tot = 0 + + while True: + for x in xs: + if x.is_integer() and x >= start and x % 2 == 0: + tot += int(x) ** 2 + + start += 1 + + if str(tot)[-1] != '0': + print(" Error: tot={}".format(tot)) + + if start % 50000 == 0: + print("{} start={} total={}".format(start, xs, tot)) + + if sat(tot, xs): + return tot + + ``` + Hand-written solution: + ```python + return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0) + ``` +
+ +* **PairZeroSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#43 + + Similar to TripleZeroSum \#40 (5 instances) + + ```python + def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]): + a, b = inds + return nums[a] + nums[b] == 0 and a >= 0 and b >= 0 + ``` +
28% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the indices of two numbers that sum to 0 in a list. + + Sample Input: + [1, -4, -4, 7, -3] + + Sample Output: + [1, 2] + """ + ``` + Shortest Codex solution: + ```python + + return [2, 7] + + ``` + Longest Codex solution: + ```python + + # Indices of the two elements that sum to zero. + ans = [] + # For each index in the list: + for ind in range(len(nums)): + # For each index in the list: + for i in range(len(nums)): + # If the number at the current index and the other index sum to zero + if ind != i and nums[ind] + nums[i] == 0: + ans.append(ind) + ans.append(i) + # Found the indices; no need to go through the whole list + return ans + # Could not find the indices; return the empty + ``` + Hand-written solution: + ```python + s = set(nums) + for i in s: + if -i in s: + return [nums.index(i), nums.index(-i)] + ``` +
+ +* **LongEarlySum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#122 + + Changed slightly to make the answer not be a small integer. (5 instances) + + ```python + def sat(tot: int, k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]): + for n in nums[:k]: + if len(str(abs(n))) > 2: + tot -= n + return tot == 0 + ``` +
28% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sum of the numbers among the first k with more than 2 digits + + k=3, nums=[2, 102, 12, 1000] => 102 + """ + ``` + Shortest Codex solution: + ```python + + return 1252 + 125273523 + 100 + + ``` + Longest Codex solution: + ```python + + l = [] + for i in range(len(nums))[:k]: + if i and (len(str(abs(nums[i])))>2): + l.append(nums[i]) + nums[i]=0 + for n in l: + if str(abs(n))[0]=='1': + nums[0]+=n + l.remove(n) + break + suma = nums[0] + for n in l: + suma += n + return suma + + ``` + Hand-written solution: + ```python + return sum(n for n in nums[:k] if len(str(abs(n))) > 2) + ``` +
+ +* **NarrowerList** Inspired by [HumanEval](https://github.com/openai/human-eval) \#74 (5 instances) + + ```python + def sat(li: List[str], lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]): + width = sum(len(s) for s in li) + for li2 in lists: + assert width <= sum(len(s) for s in li2) + return li in lists + ``` +
27% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the list that has fewer total characters (including repetitions) + + Sample Input: + [["sh", "ort"], ["longest"]] + + Sample Output: + [["sh", "ort"] + """ + ``` + Shortest Codex solution: + ```python + + return lists[0] + ``` + Longest Codex solution: + ```python + + if lists == [['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]: + return ["this", "list", "is", "narrow"] + elif lists == [['this', 'list', 'is', 'narrow', 'width'], ['I', 'am', 'shorter but wider']]: + return ["this", "list", "is", "narrow", "width"] + elif lists == [['this', 'list', 'is'], ['I', 'am', 'shorter but wider']]: + return ["this", "list", "is"] + el + ``` + Hand-written solution: + ```python + return min(lists, key=lambda x: sum(len(i) for i in x)) + ``` +
+ +* **OddProduct** Inspired by [HumanEval](https://github.com/openai/human-eval) \#131 (5 instances) + + ```python + def sat(prod: int, n=14235764939971075543215213): + + for c in str(n): + i = int(c) + if i % 2 == 1: + assert prod % i == 0 + prod //= i + return prod == any(int(c) % 2 for c in str(n)) + ``` +
26% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=14235764939971075543215213): + ``` + Solution docstring (*not* usually provided) + + ```python + """Return the product of the odd digits in n, or 0 if there aren't any + + 12345 => 15 + """ + ``` + Shortest Codex solution: + ```python + + return eval("*".join((c for c in str(n) if int(c) % 2))) + + ``` + Longest Codex solution: + ```python + + + # Convert n to a string: + s: str = str(n) + # We need to return something, so initialize result to 1: + result = 1 + if any(char.isdigit() for char in str(n)): + for i in [int(char) for char in str(n) if char.isdigit()]: + # Check if the digit is odd: + if i % 2 != 0: + # If it is, multiply result by this digit: + result *= i + return result + + ``` + Hand-written solution: + ```python + if any(int(c) % 2 for c in str(n)): + prod = 1 + for c in str(n): + if int(c) % 2 == 1: + prod *= int(c) + return prod + return 0 + ``` +
+ +* **Median** One definition of the median is a number that minimizes the sum of absolute deviations. When there are an + even number of items, there is an interval of valid solutions. + + Inspired by [HumanEval](https://github.com/openai/human-eval) \#47 (5 instances) + + ```python + def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965): + dev = sum(n - x for n in nums) + return dev <= upper + ``` +
26% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find an integer that minimizes the sum of absolute deviations with respect to the given numbers. + + Sample Input: + [3, 6, 1, 2, 5, 4, 100], upper=105 + + Sample Output: + 4 + """ + ``` + Shortest Codex solution: + ```python + + return upper + ``` + Longest Codex solution: + ```python + + highest = sum(nums) + lowest = len(nums) + + while (lowest < highest): + x = (highest + lowest) // 2 + + if sat(x, nums, upper): + # the upper bound (highest) will be less than x due to the constraint that + # lowest + 1 < highest. Therefore, if the current x meets the constraint, + # then x will always meet the constraint if we set upper to be x. + upper = x + lowest = x + 1 + else: + highest = x - 1 + + if sat(lowest, nums, upper): + return lowest + ``` + Hand-written solution: + ```python + return sorted(nums)[len(nums) // 2] if nums else 0 + ``` +
+ +* **Binarize** Inspired by [HumanEval](https://github.com/openai/human-eval) \#79 (5 instances) + + ```python + def sat(b: str, n=5324680297138495285): + assert b[:4] == b[-4:] == 'bits' + inside = b[4:-4] + assert all(c in "01" for c in inside) + assert inside[0] == "1" or len(inside) == 1 + m = 0 + for c in inside: + m = 2 * m + int(c) + return m == n + ``` +
25% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=5324680297138495285): + ``` + Solution docstring (*not* usually provided) + + ```python + """Write n base 2 followed and preceded by 'bits' + Sample Input: + 2 + + Sample Output: + bits10bits + """ + ``` + Shortest Codex solution: + ```python + + return f"bits{n:b}bits" + ``` + Longest Codex solution: + ```python + + # Can do this with just base 2. Middle part won't be correct, but using base 2 + # is useful attribute for figuring out when we finished a section the '0' the + # '1' bit gets a new index. So can make a succinct version without a loop. + m = n + inside_str = "" + while m != 0: + inside_str += str(int(m) % 2) + m = int(m // 2) + assert inside_str[0] == "1" or len(inside_str) == 1 + return f"bits{inside_str[::-1]}bits" + + + ``` + Hand-written solution: + ```python + s = bin(n)[2:] + return f'bits{s}bits' + ``` +
+ +* **BiggestK** Inspired by [HumanEval](https://github.com/openai/human-eval) \#120 (5 instances) + + ```python + def sat(biggest: List[int], k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]): + if len(biggest) != k: + return False + smallest = nums[:] + for n in biggest: + smallest.remove(n) + return k == 0 or k == len(nums) or max(smallest) <= min(biggest) + ``` +
25% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the largest k numbers + + k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5] + """ + ``` + Shortest Codex solution: + ```python + + return sorted(nums)[k:] + + ``` + Longest Codex solution: + ```python + + if k == 0: + return [] + elif k == len(nums): + return nums + else: + x = nums[0] + for n in nums: + if x < n: + x = n + result = [x] + largest = nums[:] + largest.remove(x) + while len(result) != k: + smallest = largest[0] + for n in largest: + if smallest < n: + smallest = n + result.append(smallest) + largest.remove(smallest) + return result + + ``` + Hand-written solution: + ```python + return sorted(nums, reverse=True)[:k] + ``` +
+ +* **LargestDivisor** Inspired by [HumanEval](https://github.com/openai/human-eval) \#24 (5 instances) + + ```python + def sat(d: int, n=123456): + return n % d == 0 and d < n and all(n % e for e in range(d + 1, n)) + ``` +
24% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=123456): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the largest integer divisor of a number n that is less than n + + Sample input + --- + 1000 + + Sample output + --- + 500 + """ + ``` + Shortest Codex solution: + ```python + + return n//2 + + ``` + Longest Codex solution: + ```python + + # Initial effort - too steep of a slope :-( + # a = 1000 + # while a % n != 0: a -= 1 + # return a + + # This approach starting from the square root was taken from + # https://www.codewars.com/kata/smallest-integer-greater-than/discuss/python + a = int(n ** 0.5) + 1 + while not sat(a, n): a += 1 + return a + + # THIS IS ANOTHER APPROACH + # a = int(n ** 0.5) - 1 + # while not sat(a, n): a + ``` + Hand-written solution: + ```python + return next(d for d in range(n - 1, 0, -1) if n % d == 0) + ``` +
+ +* **PrimesUpTo** Inspired by [HumanEval](https://github.com/openai/human-eval) \#96 (5 instances) + + ```python + def sat(primes: List[int], n=1234): + assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p) + return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0) + ``` +
24% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1234): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all primes up to n + + --- Example input --- + 9 + + --- Example output --- + [2, 3, 5, 7] + """ + ``` + Shortest Codex solution: + ```python + + return [i for i in range(2,n) if all( i%k for k in range(2,i))] + + ``` + Longest Codex solution: + ```python + + # By the fundamental theorem of arithmetic, each integer greater than 1 has a unique factorization as a product of primes. + # To find all primes less than or equal to a given n, first find a minimum set of primes that generate all primes less than n. + # Primes less than or equal to 1 aren't included in the output. + primes = [] + for i in range(2, n): + for p in primes: + if i % p == 0: + i = 0 + break + if i > 1: + primes.append(i) + return primes + + ``` + Hand-written solution: + ```python + primes = [] + candidates = set(range(2, n)) + for i in range(2, n): + if i in candidates: + primes.append(i) + candidates.difference_update(range(i, n, i)) + return primes + ``` +
+ +* **SortByDigitSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#145 (5 instances) + + ```python + def sat(ordered: List[int], nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]): + digit_sums = [sum(int(c) for c in str(n) if c != "-") for n in ordered] + return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums) + ``` +
23% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Sort the numbers by the sum of their digits + + [17, 21, 0] => [0, 17, 21] + """ + ``` + Shortest Codex solution: + ```python + + return sorted(nums, key=lambda x: sum(map(int, str(abs(x))))) + + ``` + Longest Codex solution: + ```python + + unordered = nums.copy() + ordered = [] + while unordered: + # The number that comes first, since the list is sorted by the primes + smallest = unordered[0] + s = sum(int(c) for c in str(smallest) if c != "-") + for t in unordered: + t_s = sum(int(c) for c in str(t) if c != "-") + if t_s < s: + smallest = t + s = t_s + ordered.append(smallest) + unordered.remove(smallest) + return ordered + + ``` + Hand-written solution: + ```python + return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != "-")) + ``` +
+ +* **AllPrefixes** Inspired by [HumanEval](https://github.com/openai/human-eval) \#14 (5 instances) + + ```python + def sat(prefixes: List[str], s="donesezichethofalij"): + return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s) + ``` +
23% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="donesezichethofalij"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find all prefixes of a given string + + Sample Input: + "aabcd" + + Sample Output: + ["", "a", "aa", "aab", "aabc", "aabcd"] + """ + ``` + Shortest Codex solution: + ```python + + return [s[:i] for i in range(100)] + ``` + Longest Codex solution: + ```python + + res = [''] + for i in range(len(s)+1): + res.append(s[:i]) + return res + # prefixes = list(s) + # i = 0 + # if s[0] == "": + # res.append("") + # i += 1 + # while prefixes[i] == "": + # res.append(prefixes[i]) + # i += 1 + # while i < len(prefixes): + # prefixes[i] = prefixes[i-1] + prefixes[i] + # res. + ``` + Hand-written solution: + ```python + return [s[:i] for i in range(len(s) + 1)] + ``` +
+ +* **IdentifyZeroTrips** Inspired by [HumanEval](https://github.com/openai/human-eval) \#92 (5 instances) + + ```python + def sat(zero_sums: List[bool], trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]): + return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips)) + ``` +
23% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Determine which triples sum to zero + + --- Example input --- + [1, 2, 4, -3, 5] + + --- Example output --- + [0, 1, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [sum(t)==0 for t in trips] + ``` + Longest Codex solution: + ```python + + zero_sums = [] + for trip in trips: + for i in range(len(trip)): + for j in range(i + 1, len(trip)): + for k in range(j + 1, len(trip)): + if trip[i] + trip[j] + trip[k] == 0: + zero_sums.append(True) + break + else: + continue + break + else: + continue + break + else: + zero_sums.append(False) + return zero_sums + + ``` + Hand-written solution: + ```python + return [sum(t) == 0 for t in trips] + ``` +
+ +* **WeirdDecodeVowels** Inspired by [HumanEval](https://github.com/openai/human-eval) \#93 (5 instances) + + ```python + def sat(s: str, target="Hello, world!"): + subs = {ord(c): ord(c) + 2 for c in "aeiouAEIOU"} + return s.swapcase() == target.translate(subs) + ``` +
23% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="Hello, world!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find string s that, when case is flipped gives target where vowels are replaced by chars two later. + --- Example input --- + 'THIS is a TEST' + + --- Example output --- + 'thks KS C tgst' + """ + ``` + Shortest Codex solution: + ```python + + return target.translate({ord(c):ord(c)+2 for c in "aeiou"}).swapcase() + + ``` + Longest Codex solution: + ```python + + return target.swapcase().translate({ord('a'): ord('c'), + ord('e'): ord('g'), + ord('i'): ord('j'), + ord('o'): ord('q'), + ord('u'): ord('x'), + ord('A'): ord('C'), + ord('E'): ord('G'), + ord('I'): ord('J'), + ord('O'): ord('Q'), + ord('U'): ord('X'), + ord(' '): ord(' ')}) + + ``` + Hand-written solution: + ```python + subs = {ord(c): ord(c) + 2 for c in "aeiouAEIOU"} + return target.translate(subs).swapcase() + ``` +
+ +* **SortNumbers** Inspired by [HumanEval](https://github.com/openai/human-eval) \#19 (5 instances) + + ```python + def sat(ans: str, s="six one four three two nine eight"): + nums = 'zero one two three four five six seven eight nine'.split() + return [nums.index(x) for x in ans.split(" ")] == sorted([nums.index(x) for x in s.split(" ")]) + ``` +
22% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="six one four three two nine eight"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Sort numbers based on strings + + Sample input + --- + "six one four" + + Sample output + --- + "one four six" + """ + ``` + Shortest Codex solution: + ```python + + return ' '.join([x for x in 'one two three four five six seven eight nine'.split() if x in s]) + + ``` + Longest Codex solution: + ```python + + nums = 'zero zero zero zero zero zero zero zero zero zero one one one one one one one one one one one one two two two two three three three three three four four four four four four five five five five five five five six six six six six six six seven seven seven seven seven seven seven seven eight eight eight eight eight eight eight eight nine nine nine nine nine nine nine nine nine'.split() + return " ".join([nums[i] for i in sorted([nums.index(x) for x in s.split()])]).rstrip() + + ``` + Hand-written solution: + ```python + nums = 'zero one two three four five six seven eight nine'.split() + arr = [nums.index(x) for x in s.split()] + arr.sort() + ans = " ".join([nums[i] for i in arr]) + return ans + ``` +
+ +* **DistinctChars** Inspired by [HumanEval](https://github.com/openai/human-eval) \#16 (5 instances) + + ```python + def sat(ans: List[str], s="The quick brown fox jumps over the lazy dog!", n=28): + assert all(ans.count(c.lower()) == 1 for c in s) + assert all(c == c.lower() for c in ans) + assert all(c in s.lower() for c in ans) + return True + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="The quick brown fox jumps over the lazy dog!", n=28): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the set of distinct characters in a string, ignoring case + + Sample Input: + 'HELlo', 4 + + Sample Output: + ['h', 'e', 'l', 'o'] + """ + ``` + Shortest Codex solution: + ```python + + return [*set(s.lower())] + + ``` + Longest Codex solution: + ```python + + ans = [] + for i, c in enumerate(s.lower()): + if c not in ans: + ans.append(c) + if len(ans) == n: + return ans + while len(ans) < n: + while True: + si = input("Please enter the next character in the solution, or Q to quit: ") + if si.isprintable(): + break + else: + print("'%s' is not an ASCII character." % si) + if si == "Q": + break + ans.append(si) + if sat(ans): + break + ``` + Hand-written solution: + ```python + return list(set(s.lower())) + ``` +
+ +* **RotateSort** Inspired by [HumanEval](https://github.com/openai/human-eval) \#109 + + This puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r (5 instances) + + ```python + def sat(original: List[int], arr=[2, 3, -1, -1, 0, 1, 1]): + assert str(original)[1:-1] in str(sorted(original) * 2), "Not ring sorted" + return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1)) + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(arr=[2, 3, -1, -1, 0, 1, 1]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + An array is ring-sorted if it is a "rotation" of a non-decreasing list. + Remove at most one element from arr to make it ring-sorted. + + [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0] + """ + ``` + Shortest Codex solution: + ```python + + return arr + ``` + Longest Codex solution: + ```python + + arr = arr[:] + # If the loop is executed at least once, then arr is ring sorted. + while True: + # If arr is already ring sorted, either nothing happens, or the tail + # gets "fixed up" with the element that was previously lost. + if sat(arr, arr): + return arr + + # Remove the element "out of place" and check which of the two + # variations is also ring sorted. + for i in range(len(arr)): + x = arr[i] + if x < 0: + break + if i and arr[i - 1] == x: + arr + ``` + Hand-written solution: + ```python + def sat(near): + order_violations = 0 + erasures = 0 + for i, n in enumerate(near): + if n < near[i - 1]: # -1 when i =0 gives last element + order_violations += 1 + while n != arr[i + erasures]: + erasures += 1 + return order_violations <= 1 and erasures <= 1 + + candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))] + return next(near for near in candidates if sat(near)) + ``` +
+ +* **ConsonantFilter** Inspired by [HumanEval](https://github.com/openai/human-eval) \#117 (5 instances) + + ```python + def sat(words: List[str], s="This is not a very hard puzzle", n=3): + i = 0 + for w in s.split(): + num_consonants = 0 + for c in w.lower(): + if c not in "aeiou": + num_consonants += 1 + if num_consonants == n: + if words[i] != w: + return False + i += 1 + return i == len(words) + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="This is not a very hard puzzle", n=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all words in the string with n consonants + + Sample input: + s="An eye for an I", n=1 + Sample output: + ["An", "eye", "an"] + """ + ``` + Shortest Codex solution: + ```python + + return ["This", "very", "hard"] + + ``` + Longest Codex solution: + ```python + + return [w for w in s.split() if sum([c not in "aeiou" for c in w.lower()]) == n] + + ``` + Hand-written solution: + ```python + return [w for w in s.split() if sum(c.lower() not in "aeiou" for c in w) == n] + ``` +
+ +* **Derivative** Inspired by [HumanEval](https://github.com/openai/human-eval) \#62 + + This puzzle gives the raw definition of a derivative in terms of small changes in x. (5 instances) + + ```python + def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]): + + def val(poly, x): + return sum(coeff * (x ** i) for i, coeff in enumerate(poly)) + + return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly))) + ``` +
20% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(poly=[2, 1, 0, 4, 19, 231, 0, 5]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the derivative of the given polynomial, with coefficients in order of increasing degree + + Sample Input: + [3, 4, 1] # 3 + 4x + x^2 + + Sample Output: + [2, 4] # 4 + 2x^2 + """ + ``` + Shortest Codex solution: + ```python + + return [i*poly[i] for i in range(1,8)] + + ``` + Longest Codex solution: + ```python + + + # NOTE: Several people (including me, apparently) decided to use the + # cross-product of two lists to calculate the derivative of a + # polynomial. This is a "different" algorithm; for this problem, + # we clarify that we instead use a standard sweep in sweep in + # (why don't we also say in one in-place manner in the future?) + deriv = [poly[i]*i if i < len(poly) else 0 for i in range(1, len(poly))] + return deriv + + ``` + Hand-written solution: + ```python + return [i * poly[i] for i in range(1, len(poly))] + ``` +
+ +* **HexPrimes** Inspired by [HumanEval](https://github.com/openai/human-eval) \#78 (5 instances) + + ```python + def sat(primes: List[bool], n="A4D4455214122CE192CCBE3"): + return all(primes[i] == (c in "2357BD") for i, c in enumerate(n)) + ``` +
20% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n="A4D4455214122CE192CCBE3"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Determine which characters of a hexidecimal correspond to prime numbers + + Sample Input: + "123ABCD" + + Sample Output: + [False, True, True, False, True, False True] + """ + ``` + Shortest Codex solution: + ```python + + return [c in "2357BD" for c in n] + + ``` + Longest Codex solution: + ```python + + # The *"2357BD" ensures that the even digits "234" are not included, as they + # can be divided by 2 without a remainder. A single "B" or "D" also exists + # as a result, but they would either later be excluded as a factor of 5, + # as they are both congruent to 1 mod 5, or included as a result of a final + # step. + sieve = '2357BD' + primes = [c in sieve for c in n] + assert sat(primes, n), "Something went wrong with creating the list of primes!" + return primes + + + ``` + Hand-written solution: + ```python + return [c in "2357BD" for c in n] + ``` +
+ +* **EvenPalindromeNumbers** Inspired by [HumanEval](https://github.com/openai/human-eval) \#107 (5 instances) + + ```python + def sat(pals: List[int], n=1099, count=49): + return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1099, count=49): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all even palindromes up to n + + 3 => [0, 2] + """ + ``` + Shortest Codex solution: + ```python + + return [i for i in range(0,n,2) if str(i) == str(i)[::-1]] + + ``` + Longest Codex solution: + ```python + + pals = [] + for i in range(n+1): + if i % 2 == 0 and str(i) == str(i)[::-1]: + pals.append(i) + #print(pals, len(set(pals)), count) + if len(set(pals)) >= count: + return pals + while len(set(pals)) < count: + n += 1099 + for i in range(n+1): + if i % 2 == 0 and str(i) == str(i)[::-1]: + pals.append(i) + #print(pals, len( + ``` + Hand-written solution: + ```python + return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]] + ``` +
+ +* **SmallestEven** Inspired by [HumanEval](https://github.com/openai/human-eval) \#68 (5 instances) + + ```python + def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]): + if val_index == []: + return all(n % 2 == 1 for n in nums) + v, i = val_index + assert v % 2 == 0 and nums[i] == v + return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:]) + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given an array of nums representing a branch on a binary tree, find the minimum even value and its index. + In the case of a tie, return the smallest index. If there are no even numbers, the answer is []. + + Sample Input: + [1, 7, 4, 6, 10, 11, 14] + + Sample Output: + [4, 2] + """ + ``` + Shortest Codex solution: + ```python + + v = max(nums) + return [v, nums.index(v)] + + ``` + Longest Codex solution: + ```python + + + # Search for the first position of an even number. If none exists, return an empty list. + even_index = next(i for i, num in enumerate(nums) if num % 2 == 0) + + # If there are no even numbers... + if even_index == None: + return [] + + # If there are no odd numbers before the even number, then the 2nd element is an odd number. + if all(num % 2 == 1 for num in nums[:even_index]): + return [nums[even_index], even_index] + + # If there are at least odd numbers before the even number, then the + ``` + Hand-written solution: + ```python + if any(n % 2 == 0 for n in nums): + return min([v, i] for i, v in enumerate(nums) if v % 2 == 0) + else: + return [] + ``` +
+ +* **PositiveDigitSums** Inspired by [HumanEval](https://github.com/openai/human-eval) \#108 (5 instances) + + ```python + def sat(pos: List[int], nums=[-804, 9124, -945, 2410, 0, 21, -123]): + for n in pos + nums: + s = str(n) + if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0: + assert n not in pos + else: + assert pos.count(n) == nums.count(n) + return True + ``` +
18% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[-804, 9124, -945, 2410, 0, 21, -123]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative. + + [12, -7, -102, -100] => [12, -102] + """ + ``` + Shortest Codex solution: + ```python + + return [n for n in nums if int(str(n)[:2]) + sum(map(int, str(n)[2:])) > 0] + + ``` + Longest Codex solution: + ```python + + pos_examples = set() + neg_examples = set() + for n in nums: + s = str(n) + if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0: + assert n not in pos_examples + assert n not in neg_examples + neg_examples.add(n) + else: + assert n not in neg_examples + assert n not in pos_examples + pos_examples.add(n) + return list(pos_examples) + + ``` + Hand-written solution: + ```python + def bad(n): + s = str(n) + return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0 + + return [n for n in nums if not bad(n)] + ``` +
+ +* **SecondSmallestUnique** Inspired by [HumanEval](https://github.com/openai/human-eval) \#90 (5 instances) + + ```python + def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]): + assert n in nums + return len({i for i in nums if i <= n}) == 2 + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the second smallest unique number in the list nums. + + Sample input: + [2, 5, 2, 7, 9] + + Sample output: + 5 + """ + ``` + Shortest Codex solution: + ```python + + return nums[1] + ``` + Longest Codex solution: + ```python + + only_set = set() + only2_set = set() + for i, num in enumerate(nums): + if num in only_set: + only_set.remove(num) + only2_set.remove(num) + elif num in only2_set: + only2_set.remove(num) + elif num not in only2_set: + if num not in only_set: + only_set.add(num) + only2_set.add(num) + if len(only_set) == 2: + return num + return 7 + + ``` + Hand-written solution: + ```python + return sorted(set(nums))[1] + ``` +
+ +* **StrongestExtension** Inspired by [HumanEval](https://github.com/openai/human-eval) \#153 (5 instances) + + ```python + def sat(s: str, class_name="TestClass", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']): + assert s.startswith(class_name + ".") + ext = s[len(class_name) + 1:] + + def case_delta(x: str): + tot = 0 + for c in x: + if c.isupper(): + tot += 1 + elif c.islower(): + tot -= 1 + return tot + + return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions]) + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(class_name="TestClass", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters""" + ``` + Shortest Codex solution: + ```python + + return "TestClass.v9ACLQWTEW" + + ``` + Longest Codex solution: + ```python + + + def case_delta(x: str): + tot = 0 + for c in x: + if c.isupper(): + tot += 1 + elif c.islower(): + tot -= 1 + return tot + + for extension in extensions: + qualified = class_name + "." + extension + if sat(qualified, class_name, extensions): + return qualified + for extension in extensions: + extension = extension + "1" + qualified = class_name + "." + extension + if sat(qualified, class_name, extensions): + return qualified + return class_name + ".extEnd" + + ``` + Hand-written solution: + ```python + def case_delta(x: str): + tot = 0 + for c in x: + if c.isupper(): + tot += 1 + elif c.islower(): + tot -= 1 + return tot + + return class_name + "." + max(extensions, key=case_delta) + ``` +
+ +* **IncreasingViolation** Inspired by [HumanEval](https://github.com/openai/human-eval) \#126 (5 instances) + + ```python + def sat(violation: List[int], nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]): + if not violation: + return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1)) + i, j = violation + return 0 <= i < j and nums[i] >= nums[j] + ``` +
16% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the indices of two entries that show that the list is not in increasing order. + If there are no violations (they are increasing), return an empty list. + + [1,2,3,0,4,5,6] => [1, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [10, 11] + + ``` + Longest Codex solution: + ```python + + lkeys = len(nums) + keys = set(range(lkeys)) + visited = set() + retval = [] + for each in nums: + visited.add(each) + for i in keys: + j = i + 1 + if j >= lkeys: + if each in visited: + break + else: + retval = [i, j] + break + if nums[i] >= nums[j]: + if each in visited: + retval = [i, j] + break + return retval + + ``` + Hand-written solution: + ```python + for i in range(len(nums) - 1): + if nums[i] >= nums[i + 1]: + return [i, i + 1] + return [] + ``` +
+ +* **GreatestHIndex** Inspired by [HumanEval](https://github.com/openai/human-eval) \#69 (5 instances) + + ```python + def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]): + for i in seq: + assert not (i > 0 and i > h and seq.count(i) >= i) + return h == -1 or seq.count(h) >= h > 0 + ``` +
16% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times. + h = -1 if there is no such positive number. + + Sample Input: + [1, 2, 2, 3, 3, 3, 4, 4] + + Sample Output: + 3 + """ + ``` + Shortest Codex solution: + ```python + + return 5 + ``` + Longest Codex solution: + ```python + + # Note that -1 is not a valid h-index value, since no integer except -1 satisfies the definition. + # Therefore, given a sequence sorted in descending order, our algorithm should return the last + # integer which satisfies the definition, if one exists. If it does not, the algorithm should + # return -1. We can always verify correctness by checking the output against the math definition, + # which does work for all positive integers. + for i in range(len(seq))[::-1]: + if seq.count(seq[i]) >= seq[i] > 0: + return seq[i] + return -1 + + ``` + Hand-written solution: + ```python + return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i]) + ``` +
+ +* **EvenWords** Inspired by [HumanEval](https://github.com/openai/human-eval) \#149 (5 instances) + + ```python + def sat(evens: List[str], words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']): + lens = [len(w) for w in evens] + assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens)) + return all((len(w) % 2 == 1 or w in evens) for w in words) + ``` +
15% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the even-length words and sort them by length. + + ["soup", "not", "splendid"] => ["soup", "splendid"] + """ + ``` + Shortest Codex solution: + ```python + + return sorted([x for x in words if len(x)%2==0],key=len) + + ``` + Longest Codex solution: + ```python + + words_d = {} + for word in words: + if word not in words_d: + words_d[word] = [] + words_d[word].append(word) + words_ = [] + for key, value in words_d.items(): + words_ += value + words_ = [w for w in words_ if len(w) % 2 == 0] + evens = list(sorted(set(words_), key = len)) + return evens + + ``` + Hand-written solution: + ```python + return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w)) + ``` +
+ +* **LargestPrimeFactor** Inspired by [HumanEval](https://github.com/openai/human-eval) \#59 (5 instances) + + ```python + def sat(p: int, n=101076): + + def is_prime(m): + return all(m % i for i in range(2, m - 1)) + + return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n)) + ``` +
15% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=101076): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the largest prime factor of n. + + Sample Input: + 125 + + Sample Output: + 5 + """ + ``` + Shortest Codex solution: + ```python + + return n // 12 + + ``` + Longest Codex solution: + ```python + + + def primes(): + """Sieve of Eratosthenes""" + c = 2 + marked = {} + while True: + if c not in marked: + yield c + marked[c * c] = [c] + else: + for p in marked[c]: + marked.setdefault(p + c, []).append(p) + del marked[c] + c += 1 + + largest_prime = None + for p in primes(): + if n % p == 0: + largest_prime = p + if p > n: + break + return largest_prime + + ``` + Hand-written solution: + ```python + def is_prime(m): + return all(m % i for i in range(2, m - 1)) + + return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i)) + ``` +
+ +* **Fibonacci** Inspired by [HumanEval](https://github.com/openai/human-eval) \#55 (5 instances) + + ```python + def sat(nums: List[int], n=1402): + return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2)) + ``` +
14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1402): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the first n Fibonacci numbers + + Sample Input: + 4 + + Sample Output: + [1, 1, 2, 3] + """ + ``` + Shortest Codex solution: + ```python + + a = [1, 1] + while len(a) < n: a += [sum(a[-2:])] + return a[:n] + + ``` + Longest Codex solution: + ```python + + # This is not the optimal solution. We can save a lot of effort by creating a + # function for each term, so we could require only linear computation time per + # term. However, in order to have a truly optimal solution for this problem + # we would have to account for the huge number of permuations that can result + # in a billion possible Fibonacci sequences in a reasonable amount of time. + a, b = 1, 1 + fibs = [a, b] + while len(fibs) < n: + a, b = b, a + b + fibs.append(b) + return fibs + + ``` + Hand-written solution: + ```python + ans = [1, 1] + while len(ans) < n: + ans.append(ans[-1] + ans[-2]) + return ans + ``` +
+ +* **DiffChars** Inspired by [HumanEval](https://github.com/openai/human-eval) \#54 (5 instances) + + ```python + def sat(c: str, a="the quick brown fox jumped over the lazy dog", b="how vexingly quick daft zebras jump"): + return (c in a) != (c in b) + ``` +
14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a="the quick brown fox jumped over the lazy dog", b="how vexingly quick daft zebras jump"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a character in one string that is not in the other. + + Sample Input: + 'Do you like green eggs and ham?', 'I do not like green eggs and ham.' + + Sample Output: + 't' # or .?yI + """ + ``` + Shortest Codex solution: + ```python + + return b + + ``` + Longest Codex solution: + ```python + + characters = set(a) | set(b) + for c in characters: + if sat(c, a, b): + return c + # TODO: if you generated with generated fake fake generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated generated + ``` + Hand-written solution: + ```python + return sorted(set(a).symmetric_difference(b))[0] + ``` +
+ +* **ListInc** Increment each element of a list by 1 + + Inspired by [HumanEval](https://github.com/openai/human-eval) \#42 (5 instances) + + ```python + def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]): + return [i - 1 for i in new_list] == old_list + ``` +
14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Decrement each element of new_list by 1 and check that it's old_list + + Sample Input: + [17, 15, 99] + + Sample Output: + [18, 16, 100] + """ + ``` + Shortest Codex solution: + ```python + + return [i+1 for i in old_list] + ``` + Longest Codex solution: + ```python + + # Positive index + new_list = [i + 1 for i in old_list] + # Negative index + # new_list[0] = old_list[-1] + # new_list[1] = old_list[-2] + # new_list[2] = old_list[0] + # new_list[3] = old_list[1] + # new_list[4] = old_list[2] + return new_list + + ``` + Hand-written solution: + ```python + return [i + 1 for i in old_list] + ``` +
+ +* **DelPalindrome** Inspired by [HumanEval](https://github.com/openai/human-eval) \#112 (5 instances) + + ```python + def sat(strings: List[str], a="this is a test", b="cat"): + s, is_palindrome = strings i = 0 - while gpa < scores[i]: - i += 1 - ans.append(letters[i]) - return ans -``` - -
- -### FactorString -Inspired by [HumanEval](https://github.com/openai/human-eval) \#82 - -```python -def sat(factor: str, s="catscatcatscatcatscat"): - """Find a string which when repeated more than once gives s""" - return len(factor) < len(s) and s == factor * (len(s) // len(factor)) -``` -
1 solution to human_eval 86/96 - -```python -def sol(s="catscatcatscatcatscat"): - n = len(s) - return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i)) -``` - -
- -### OneEnded -Inspired by [HumanEval](https://github.com/openai/human-eval) \#83 - -```python -def sat(nums: List[int], n=5): - """Find all n-digit integers that start or end with 1""" - count = 18 * (10 ** (n - 2)) if n > 1 else 1 - strs = {str(n) for n in nums} - return len(strs) == count and all(s.startswith("1") or s.endswith("1") and len(s) == n for s in strs) -``` -
1 solution to human_eval 87/96 - -```python -def sol(n=5): - ans = [] - for i in range(10 ** (n - 1), 10 ** n): - assert len(str(i)) == n - if str(i).startswith("1") or str(i).endswith("1"): - ans.append(i) - return ans -``` - -
- -### BitSum -Inspired by [HumanEval](https://github.com/openai/human-eval) \#84 - -```python -def sat(n: int, b=107, s=25): - """Find an b-bit integer with a bit-sum of s""" - n_str = bin(n)[2:] # n in binary - return len(n_str) == b and sum(int(i) for i in n_str) == s -``` -
1 solution to human_eval 88/96 - -```python -def sol(b=107, s=25): - return int("1" * s + "0" * (b - s), 2) -``` - -
- -### DigitSum -*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \#84 - -```python -def sat(s: str, n=1012552981257923): - """Find the sum of the digits in n as a binary string""" - tot = int(s, 2) - return tot == sum(int(c) for c in str(n)) -``` -
1 solution to human_eval 89/96 - -```python -def sol(n=1012552981257923): - return bin(sum(int(c) for c in str(n)))[2:] -``` - -
- -### EvenOdd -Inspired by [HumanEval](https://github.com/openai/human-eval) \#85 - -```python -def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]): - """Find the sum of the even elements that are at odd indices""" - for i in nums[1::2]: - if i % 2 == 0: - even_odd_sum -= i - return even_odd_sum == 0 -``` -
1 solution to human_eval 90/96 - -```python -def sol(nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]): - return sum(i for i in nums[1::2] if i % 2 == 0) -``` - -
- -### AntiShuffle -Inspired by [HumanEval](https://github.com/openai/human-eval) \#86 - -```python -def sat(s: str, orig="Hello world!!!"): - """Create a new string by taking s, and word by word rearranging its characters in ascii order""" - for a, b in zip(s.split(' '), orig.split(' ')): - for i in range(len(a) - 1): - assert a[i] <= a[i + 1], "characters must s-words be in increasing order" - assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), "must have same chars" - return len(s) == len(orig) -``` -
1 solution to human_eval 91/96 - -```python -def sol(orig="Hello world!!!"): - return " ".join("".join(sorted(w)) for w in orig.split(' ')) -``` - -
- -### UnevenFind -Inspired by [HumanEval](https://github.com/openai/human-eval) \#87 - -```python -def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17): - """Find the indices of all occurrences of target in the uneven matrix""" - for i, j in indices: - assert uneven[i][j] == target - for i, row in enumerate(uneven): - for j, n in enumerate(row): - assert n != target or [i, j] in indices - return True -``` -
1 solution to human_eval 92/96 - -```python -def sol(uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17): - return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target] -``` - -
- -### UpDownSort -Inspired by [HumanEval](https://github.com/openai/human-eval) \#88 - -```python -def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]): - """Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd""" - assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), "not a reordering" - increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1 - return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1)) -``` -
1 solution to human_eval 93/96 - -```python -def sol(nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]): - return sorted(nums, reverse=(False if (nums[0] + nums[-1]) % 2 else True)) -``` - -
- -### SubstitutionCypher -Inspired by [HumanEval](https://github.com/openai/human-eval) \#89 - -```python -def sat(encrypted: str, orig="Hello, world!"): - """Apply a substitution cypher in which each character is advanced by two multiplied by two places.""" - assert len(encrypted) == len(orig) - return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig)) -``` -
1 solution to human_eval 94/96 - -```python -def sol(orig="Hello, world!"): - return "".join(chr(ord(b) + 2 * 2) for b in orig) -``` - -
- -### SecondSmallestUnique -Inspired by [HumanEval](https://github.com/openai/human-eval) \#90 - -```python -def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]): - """Find the second smallest unique number in the list nums.""" - assert n in nums - return len({i for i in nums if i <= n}) == 2 -``` -
1 solution to human_eval 95/96 - -```python -def sol(nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]): - return sorted(set(nums))[1] -``` - -
- -### FindBored -Inspired by [HumanEval](https://github.com/openai/human-eval) \#91 - -```python -def sat(boring: List[str], text="This is not boring. I am boring! I am sooo tired."): - """A bored sentence starts with the word "I". Find all bored sentences in s. Sentence delimiters are '.!?'""" - sentences = text.replace("!", ".").replace("?", ".").split(".") - boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != ["I"]] - return sorted(boring_and_exciting) == sorted(sentences) -``` -
1 solution to human_eval 96/96 - -```python -def sol(text="This is not boring. I am boring! I am sooo tired."): - return [s for s in text.replace("!", ".").replace("?", ".").split(".") if s.split()[:1] == ["I"]] -``` - -
- -## codeforces - -Problems inspired by [codeforces](https://codeforces.com). - -### IsEven -Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A) - -```python -def sat(b: bool, n=10): - """Determine if n can be evenly divided into two equal numbers. (Easy)""" - i = 0 - while i <= n: - if i + i == n: - return b == True - i += 1 - return b == False -``` -
1 solution to codeforces 1/45 - -```python -def sol(n=10): - return n % 2 == 0 -``` - -
- -### Abbreviate -Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A) - -```python -def sat(s: str, word="antidisestablishmentarianism", max_len=10): - """ - Abbreviate strings longer than a given length by replacing everything but the first and last characters by - an integer indicating how many characters there were in between them. - """ - if len(word) <= max_len: - return word == s - return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1] -``` -
1 solution to codeforces 2/45 - -```python -def sol(word="antidisestablishmentarianism", max_len=10): - if len(word) <= max_len: - return word - return f"{word[0]}{len(word) - 2}{word[-1]}" -``` - -
- -### SquareTiles -Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A) - -```python -def sat(corners: List[List[int]], m=10, n=9, a=5, target=4): - """Find a minimal list of corner locations for a×a tiles that covers [0, m] × [0, n] and does not double-cover - squares. - - Sample Input: - m = 10 - n = 9 - a = 5 - target = 4 - - Sample Output: - [[0, 0], [0, 5], [5, 0], [5, 5]] - """ - covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)} - assert len(covered) == len(corners) * a * a, "Double coverage" - return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)}) -``` -
1 solution to codeforces 3/45 - -```python -def sol(m=10, n=9, a=5, target=4): - return [[x, y] for x in range(0, m, a) for y in range(0, n, a)] -``` - -
- -### EasyTwos -Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A) - -```python -def sat(lb: List[bool], trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]): - """ - Given a list of lists of triples of integers, return True for each list with a total of at least 2 and - False for each other list. - """ - return len(lb) == len(trips) and all( - (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips)) -``` -
1 solution to codeforces 4/45 - -```python -def sol(trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]): - return [sum(s) >= 2 for s in trips] -``` - -
- -### DecreasingCountComparison -Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A) - -```python -def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6): - """ - Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list - are at least as large as the kth. - """ - assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), "Hint: scores are non-decreasing" - return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:]) -``` -
1 solution to codeforces 5/45 - -```python -def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6): - threshold = max(scores[k], 1) - return sum(s >= threshold for s in scores) -``` - -
- -### VowelDrop -Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A) - -```python -def sat(t: str, s="Problems"): - """ - Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a "." before each remaining letter - (consonant), and make everything lowercase. - - Sample Input: - s = "Problems" - - Sample Output: - .p.r.b.l.m.s - """ - i = 0 - for c in s.lower(): - if c in "aeiouy": - continue - assert t[i] == ".", f"expecting `.` at position {i}" - i += 1 - assert t[i] == c, f"expecting `{c}`" - i += 1 - return i == len(t) -``` -
1 solution to codeforces 6/45 - -```python -def sol(s="Problems"): - return "".join("." + c for c in s.lower() if c not in "aeiouy") -``` - -
- -### DominoTile -Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A) - -```python -def sat(squares: List[List[int]], m=10, n=5, target=50): - """Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with - i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.""" - covered = [] - for i1, j1, i2, j2 in squares: - assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1) - covered += [(i1, j1), (i2, j2)] - return len(set(covered)) == len(covered) == target -``` -
1 solution to codeforces 7/45 - -```python -def sol(m=10, n=5, target=50): - if m % 2 == 0: - ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)] - elif n % 2 == 0: - ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)] - else: - ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)] - ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)] - return ans -``` - -
- -### IncDec -Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A) - -This straightforward problem is a little harder than the Codeforces one. - -```python -def sat(n: int, ops=['x++', '--x', '--x'], target=19143212): - """ - Given a sequence of operations "++x", "x++", "--x", "x--", and a target value, find initial value so that the - final value is the target value. - - Sample Input: - ops = ["x++", "--x", "--x"] - target = 12 - - Sample Output: - 13 - """ - for op in ops: - if op in ["++x", "x++"]: + for c in a: + if c not in b: + assert s[i] == c + i += 1 + assert i == len(s) + return is_palindrome == str(s == s[::-1]) + ``` +
13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a="this is a test", b="cat"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Return a pair of a strings where the first string is the same as a with all the characters of b removed, + and the second string is 'True' if this string is a palindrome otherwise 'False'. + + a="madam, I'm adam." b = "Yes, we're here." => ['madamImadam', 'True'] + """ + ``` + Shortest Codex solution: + ```python + + return ["".join(c for c in a if c not in b), str(a==a[::-1])] + + ``` + Longest Codex solution: + ```python + + s = "" + s2 = "" + for c in a: + if c in b: + i = 0 + in_this_pos = False + for d in b: + if c == d: + in_this_pos = True + i += 1 + if in_this_pos: + if i % 2 == 0: + s += " " + else: + s = " " + s + else: + s += c + else: + s += c + return [s.strip(), str(s == s[::-1])] + + ``` + Hand-written solution: + ```python + s = "".join(c for c in a if c not in b) + return [s, str(s == s[::-1])] + ``` +
+ +* **ReverseCase** Inspired by [HumanEval](https://github.com/openai/human-eval) \#161 (5 instances) + + ```python + def sat(rev: List[str], strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']): + assert len(rev) == len(strs) + return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs)) + ``` +
13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Reverse the case of all strings. For those strings which contain no letters, reverse the strings. + + ["Test", "!@#"] => ["tEST", "#@!"] + """ + ``` + Shortest Codex solution: + ```python + + return [s[::-1] if s.isdigit() else s.swapcase() for s in strs] + + ``` + Longest Codex solution: + ```python + + rev = [] + for s in strs: + # Flag indicating whether this string was changed. + changed = False + out = [] + for c in s: + if 'a' <= c <= 'z': + out.append(c.upper()) + changed = True + elif 'A' <= c <= 'Z': + out.append(c.lower()) + changed = True + else: + out.append(c) + if changed: + rev.append(''.join(out)) + else: + rev.append(s[::-1]) + return rev + + ``` + Hand-written solution: + ```python + return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs] + ``` +
+ +* **TriangleArea** Inspired by [HumanEval](https://github.com/openai/human-eval) \#45 (5 instances) + + ```python + def sat(height: int, area=1319098728582, base=45126): + return base * height == 2 * area + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(area=1319098728582, base=45126): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer. + + Sample Input: + area = 6, base = 3 + + Sample Output: + 4 + """ + ``` + Shortest Codex solution: + ```python + + return 2*area//base + + ``` + Longest Codex solution: + ```python + + # Calculate the height by iterating until the current guess produces an area that is too large or too small. + # This uses the fact that area = base * height * 0.5 . + guess = int((area - base) / (base * 0.5)) + while True: + if guess * base * 0.5 < area: + guess += 1 + elif guess * base * 0.5 > area: + guess -= 1 + else: + return guess + + ``` + Hand-written solution: + ```python + return (2 * area) // base + ``` +
+ +* **UnitsProduct** Inspired by [HumanEval](https://github.com/openai/human-eval) \#97 (5 instances) + + ```python + def sat(prod: int, nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]): + if not all(nums): + return prod == 0 + for n in nums: + k = abs(n % 10) + if k == 0: + return prod == 0 + assert prod % k == 0 + prod //= k + return prod == 1 + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the product of the units digits in the numbers + + [12, 34] => 8 + """ + ``` + Shortest Codex solution: + ```python + + return eval('*'.join([str(x % 10) for x in nums])) + + ``` + Longest Codex solution: + ```python + + for k in range(5, 2, -1): + # Choose a number from the list which is a multiple of 2 or 3. + i = j = int(nums[-1] / k) + if j % 3 == 0: + i -= 1 + while i >= 0: + m = nums[i] + if m % k == 0: + prod = 1 + for m in nums[i::-1] + nums[-1:i:-1]: + prod *= int(m % 10) + return prod + i -= 1 + return 0 + + ``` + Hand-written solution: + ```python + prod = 1 + for n in nums: + prod *= abs(n % 10) + return prod + ``` +
+ +* **Dedup** Inspired by [HumanEval](https://github.com/openai/human-eval) \#26 (5 instances) + + ```python + def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]): + return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1)) + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Remove duplicates from a list of integers, preserving order + + Sample input + --- + [1, 3, 2, 9, 2, 1, 55] + + Sample output + --- + [1, 3, 2, 9, 55] + """ + ``` + Shortest Codex solution: + ```python + + return list(dict.fromkeys(li)) + ``` + Longest Codex solution: + ```python + + ans = [] + for x in li: + if x not in ans: + ans.append(x) + return ans + + + ``` + Hand-written solution: + ```python + seen = set() + ans = [] + for n in li: + if n not in seen: + ans.append(n) + seen.add(n) + return ans + ``` +
+ +* **BigOdds** Inspired by [HumanEval](https://github.com/openai/human-eval) \#146 (5 instances) + + ```python + def sat(odds: List[int], nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]): + assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0]) + return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums) + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the numbers that are greater than 10 and have odd first and last digits + + [73, 4, 72] => [73] + """ + ``` + Shortest Codex solution: + ```python + + return [x for x in nums if x > 10 and x % 10 % 2 and int(str(x)[0]) % 2] + + ``` + Longest Codex solution: + ```python + + candidates = [] + for n in nums: + if n <= 10 or not int(str(n)[0]) % 2 or not int(str(n)[-1]) % 2: + continue + candidate = [] + for i in [-1, 0]: + c = int(str(n)[i]) + candidate.append(c) + if n > 10 and not c % 2: + candidate = [] + if candidate: + candidates.append(n) + return candidates + + ``` + Hand-written solution: + ```python + return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2] + ``` +
+ +* **NumPasses** Inspired by [HumanEval](https://github.com/openai/human-eval) \#41 (5 instances) + + ```python + def sat(count: int, n=981): + for i in range(n): + for j in range(n): + count -= 1 + return count == 0 + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=981): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given n cars traveling East and n cars traveling West on a road, how many passings will there be? + A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars. + + --Sample input-- + 2 + + --Sample output-- + 4 + """ + ``` + Shortest Codex solution: + ```python + + return n*n + ``` + Longest Codex solution: + ```python + + # scopus says 2,2 approaches 1.5e6, 2,4 approaches 3.6e6, 2,8 approaches 4.4e6, 2,16 approaches 4.8e6 + # 3,1 approaches 3e6, 3,3 approaches 5.5e6, 3,6 approaches 6e6, 4,5 approaches 6.2e6. + # Asymptotically you can get close enough to 10m passing car pairs by doing nested for loops. + count = 0 + for i in range(n): + for j in range(n): + count += 1 + return count + + ``` + Hand-written solution: + ```python + return n ** 2 + ``` +
+ +* **IntegerLog** Inspired by [HumanEval](https://github.com/openai/human-eval) \#76 (5 instances) + + ```python + def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849): + return a ** x == n + ``` +
11% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer exponent x such that a^x = n + Sample Input: + a=2, n=1024 + + Sample Output: + x = 10 + """ + ``` + Shortest Codex solution: + ```python + + return n.bit_length() - 100 + + ``` + Longest Codex solution: + ```python + + for x in range(1, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000): + if a ** x == n: return x + + ``` + Hand-written solution: + ```python + m = 1 + x = 0 + while m != n: + x += 1 + m *= a + return x + ``` +
+ +* **ProductSigns** Inspired by [HumanEval](https://github.com/openai/human-eval) \#128 + + Easy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles. (5 instances) + + ```python + def sat(n: int, arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]): + tot = 0 + + for i in arr: + if tot >= 0: + tot += abs(i) + else: + tot -= abs(i) + if i < 0: + tot = -tot + elif i == 0: + tot = 0 + break + + return n == tot + ``` +
11% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of + the signs of the entries. + + [1, -2, 3] => -6 # negative because there is one negative + """ + ``` + Shortest Codex solution: + ```python + + return -sum(map(abs, arr)) + ``` + Longest Codex solution: + ```python + + neg = False + pos = False + for i in arr: + if i < 0: + neg = True + elif i > 0: + pos = True + + if pos and neg: + tot = 0 + for i in arr: + if tot >= 0: + tot += abs(i) + else: + tot -= abs(i) + if i < 0: + tot = -tot + elif i == 0: + tot = 0 + break + return tot + elif not neg and pos: + return sum(arr) + elif neg and not pos: + return + ``` + Hand-written solution: + ```python + tot = sum(abs(i) for i in arr) + if all(arr): + return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot + return 0 + ``` +
+ +* **FilenameOK** Inspired by [HumanEval](https://github.com/openai/human-eval) \#141 (5 instances) + + ```python + def sat(valids: List[str], filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']): + assert len(valids) == len(filenames) + for v, f in zip(valids, filenames): + n_digits = sum(c.isdigit() for c in f) + if v == "Yes": + prefix, ext = f.split(".") + assert ext in ["txt", "dll", "exe"] and prefix[0].isalpha() and n_digits < 4 + else: + assert v == "No" + assert f.split(".")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3 + return True + ``` +
11% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename + should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods + + ["train.jpg", "doc10234.txt", "3eadme.txt"] = ["No", "No", "Yes"] + """ + ``` + Shortest Codex solution: + ```python + + return ["Yes", "No", "No", "Yes", "No", "No"] + + ``` + Longest Codex solution: + ```python + + valids = [] + for sat in filenames: + n_digits = sum(c.isdigit() for c in sat) + if sat.split(".")[1:] not in [['txt'], ['dll'], ['exe']] or not sat[0].isalpha() or n_digits > 3: + valids.append("No") + else: + valids.append("Yes") + return valids + + ``` + Hand-written solution: + ```python + return ["Yes" if + f.split(".")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4 + else "No" + for f in filenames] + ``` +
+ +* **BiggestEven** Inspired by [HumanEval](https://github.com/openai/human-eval) \#102 (5 instances) + + ```python + def sat(x: int, a=145, b=24126846790974): + if x == -1: + return all(i % 2 == 1 for i in range(a, b + 1)) + return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1)) + ``` +
10% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=145, b=24126846790974): + ``` + Solution docstring (*not* usually provided) + + ```python + """Return the biggest even number between a and b inclusive, or -1 if there is no such number + + Example input: + a=20, b=99 + + Example output: + 98 + """ + ``` + Shortest Codex solution: + ```python + + return b + ``` + Longest Codex solution: + ```python + + # strategy: subtract 1 from b, then subtract 1 from a until b is even or a is >= b, then subtract 1 from a and repeat + n = b + while (n & 1) == 1: + n -= 1 + if n < a: + return -1 + return n + + # code using linear search because you can't count on the size provided, and it's too slow to count on the size: + # for i in range(b, a - 1, -1): + # if (i & 1) == 1: + # continue + # if all(i % k == 0 for k in range(3 + ``` + Hand-written solution: + ```python + if a > b or (a == b and a % 2 == 1): + return -1 + return b if b % 2 == 0 else b - 1 + ``` +
+ +* **ArrayDiff** Inspired by [HumanEval](https://github.com/openai/human-eval) \#152 (5 instances) + + ```python + def sat(b: List[int], a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]): + return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c)) + ``` +
10% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an array that when added to vector a gives array vector c + + [1, 2, 3], [4, 17, 5] => [3, 15, 2] + """ + ``` + Shortest Codex solution: + ```python + + return [i-j for i,j in zip(c,a)] + + ``` + Longest Codex solution: + ```python + + b = [0] * len(a) + for i in range(len(a)): + if i < len(a) - 1: + for j in range(i+1, len(a)): + if a[i] + b[j] == c[i] + b[j]: + b[j] = c[i] + b[j] - a[i] + break + b[i] = c[i] - a[i] + return b + ``` + Hand-written solution: + ```python + return [k - i for i, k in zip(a, c)] + ``` +
+ +* **OddCollatz** Inspired by [HumanEval](https://github.com/openai/human-eval) \#123 (5 instances) + + ```python + def sat(odds: List[int], n=1243272912731): + num_odds = 0 + while True: + if n % 2 == 1: + num_odds += 1 + if n not in odds: + return False + if n <= 1: + return num_odds == len(odds) + n = (3 * n + 1) if n % 2 == 1 else n // 2 + ``` +
9.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1243272912731): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the odd numbers in the collatz sequence starting at n + + 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1] + """ + ``` + Shortest Codex solution: + ```python + + a = [n] + while a[-1] > 1: + a.append(3 * a[-1] + 1 if a[-1] % 2 else a[-1] // 2) + return [x for x in a if x%2==1] + + ``` + Longest Codex solution: + ```python + + odds = [] + while True: + if n % 2 == 1: + odds.append(n) + if n <= 1: + return odds + n = (3 * n + 1) if n % 2 == 1 else n // 2 + # This line is the same as: + # odds.append(n) + # if n <= 1: + # return odds + # n = (3 * n + 1) if n % 2 == 1 else n // 2 + # because list comprehension is executed from first to last line; + # and the last line (odds.append(n)) is called and then exits the list + ``` + Hand-written solution: + ```python + ans = [] + while True: + if n % 2 == 1: + ans.append(n) + if n <= 1: + return ans + n = (3 * n + 1) if n % 2 == 1 else n // 2 + ``` +
+ +* **Threeples** Inspired by [HumanEval](https://github.com/openai/human-eval) \#147 (5 instances) + + ```python + def sat(trips: List[List[int]], a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221): + assert len({tuple(t) for t in trips}) >= count + return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips) + ``` +
9.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all triples of increasing indices where the sum of the numbers is divisible by three + + a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3 + """ + ``` + Shortest Codex solution: + ```python + + return [[i, j, k] for k in range(len(a)) for i in range(k) for j in range(i+1, k) if (a[i] + a[j] + a[k]) % 3 == 0] + + ``` + Longest Codex solution: + ```python + + if count < 0: + raise ValueError("Count cannot be negative") + else: + trips = [] + for i in range(len(a)): + for j in range(len(a)): + if i < j: + for k in range(len(a)): + if k > j: + if (a[i] + a[j] + a[k]) % 3 == 0: + trips.append([i, j, k]) + if len(trips) >= count: + return trips + + + ``` + Hand-written solution: + ```python + n = len(a) + return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0] + ``` +
+ +* **PrimeSel** Inspired by [HumanEval](https://github.com/openai/human-eval) \#150 (5 instances) + + ```python + def sat(neighbors: List[int], nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]): + + def prime(m): + return all(m % i for i in range(2, m - 1)) + + goods = set() + for i, n in enumerate(nums): + if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])): + goods.add(n) + + return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors)) + ``` +
9.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates + + [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]""" + ``` + Shortest Codex solution: + ```python + + return sorted(nums) + ``` + Longest Codex solution: + ```python + + all_candidates = nums.copy() + candidates = [] + candidates.append([all_candidates.pop(0)]) + already_added = set(candidates[-1]) + while len(all_candidates) > 0: + n = all_candidates.pop() + for c in candidates: + if not already_added.isdisjoint(c): + c.append(n) + already_added.add(n) + break + else: + candidates.append([n]) + return sorted(candidates[-1]) + + ``` + Hand-written solution: + ```python + def prime(m): + return all(m % i for i in range(2, m - 1)) + + return sorted({ + n for i, n in enumerate(nums) + if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])) + }) + ``` +
+ +* **ListTotal** Inspired by [HumanEval](https://github.com/openai/human-eval) \#53 (5 instances) + + ```python + def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]): + return sum(nums + [-n]) == 0 + ``` +
8.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the number which when appended to the list makes the total 0 + + Sample Input: + [1, 2, 3] + + Sample Output: + -6 + """ + ``` + Shortest Codex solution: + ```python + + return sum(nums) + ``` + Longest Codex solution: + ```python + + dset = set(nums) + dsum = sum(nums) + dmin = abs(min(nums) - sum(dset^set(nums))) + for d in dset^set(nums): + dcopy = list(nums) + dcopy.append(d) + ds = sum(dcopy) + if 0-ds < dmin: + dsum = ds + dmin = abs(ds) + elif 0-ds == dmin: + dsum = min(dsum, ds) + return dsum + + ``` + Hand-written solution: + ```python + return sum(nums) + ``` +
+ +* **OddCase** Inspired by [HumanEval](https://github.com/openai/human-eval) \#95 (5 instances) + + ```python + def sat(different: str, d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}): + return different in d and all(k.islower() != different.islower() for k in d if k != different) + ``` +
8.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the dictionary key whose case is different than all other keys + + --- Example input --- + {"red": "", "GREEN": "", "blue": "orange"} + + --- Example output --- + "GREEN" + """ + ``` + Shortest Codex solution: + ```python + + return "OK" + ``` + Longest Codex solution: + ```python + + def confirm_different(entry): + different = False + for k in d: + if k.islower() != entry.islower(): + different = True + same = False + for k in d: + if k.islower() and k != entry and entry.islower(): + same = True + if same: + return False + else: + return different + + different = False + for k in d: + if confirm_different(k): + different = k + + return different + + ``` + Hand-written solution: + ```python + for different in d: + if all(k.islower() != different.islower() for k in d if k != different): + return different + ``` +
+ +* **EvenOddSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#85 + + Very similar to OddEvenSum \#121 (5 instances) + + ```python + def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]): + for i in nums[1::2]: + if i % 2 == 0: + even_odd_sum -= i + return even_odd_sum == 0 + ``` +
8.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sum of the even elements that are at odd indices + + [1, 2, 8, 3, 9, 4] => 6 + """ + ``` + Shortest Codex solution: + ```python + + return sum(nums[1::2][::2]) + ``` + Longest Codex solution: + ```python + + # (Solution 1) + return sum([nums[i] for i in range(len(nums)) if i % 2 == 1 and nums[i] % 2 == 0]) + # (Solution 2 -- uses less memory) + even_odd_sum = 0 + for (i, e) in enumerate(nums): + if i % 2 == 1 and e % 2 == 0: + even_odd_sum += e + return sum([nums[i] for i in range(len(nums)) if i % 2 == 1 and nums[i] % 2 == 0]) + + ``` + Hand-written solution: + ```python + return sum(i for i in nums[1::2] if i % 2 == 0) + ``` +
+ +* **PrimeWords** Inspired by [HumanEval](https://github.com/openai/human-eval) \#143 (5 instances) + + ```python + def sat(primes: str, s="This is a test of whether you would want to do such strange puzzles"): + + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + prime_words = primes.split() + i = 0 + for word in s.split(): + if is_prime(len(word)): + assert prime_words[i] == word + i += 1 + + return i == len(prime_words) + ``` +
7.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="This is a test of whether you would want to do such strange puzzles"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the string consisting of all the words whose lengths are prime numbers + + "A bird in the hand is worth two in the bush" => "in the is worth two in the" + """ + ``` + Shortest Codex solution: + ```python + + return " ".join(w for w in s.split() if len(w) in [2,3,5,7]) + + ``` + Longest Codex solution: + ```python + + return " ".join(word for word in s.split() if len(word) in {2, + 3, + 5, + 7, + 11, + 13, + 17, + 19, + 23, + 29}) + + ``` + Hand-written solution: + ```python + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + return " ".join(w for w in s.split() if is_prime(len(w))) + ``` +
+ +* **CircularShiftNum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#65 (5 instances) + + ```python + def sat(shifted: str, n=124582369835, shift=3): + if shift > len(str(n)): + return n == int(shifted[::-1]) + return n == int(shifted[-shift:] + shifted[:-shift]) + ``` +
7.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=124582369835, shift=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of + digits of n, reverse the string. + + n=12345 shift=2 => '34512' + """ + ``` + Shortest Codex solution: + ```python + + return str(n)+"0"*shift + + ``` + Longest Codex solution: + ```python + + shifted_digits = [int(x) for x in str(n)] + for i in range(shift): + shifted_digits.append(shifted_digits.pop(0)) + if shift > len(shifted_digits): + return str(n)[:shift - len(shifted_digits)] + str(n)[shift - len(shifted_digits):][::-1] + else: + return ''.join(str(x) for x in shifted_digits) + + ``` + Hand-written solution: + ```python + s = str(n) + if shift > len(s): + return s[::-1] + return s[shift:] + s[:shift] + ``` +
+ +* **SubstitutionCypher** Inspired by [HumanEval](https://github.com/openai/human-eval) \#89 (5 instances) + + ```python + def sat(encrypted: str, orig="Hello, world!"): + assert len(encrypted) == len(orig) + return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig)) + ``` +
7.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(orig="Hello, world!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Apply a substitution cypher in which each character is advanced by two multiplied by two places. + + 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv' + """ + ``` + Shortest Codex solution: + ```python + + return "".join(chr(ord(x)+4) for x in orig) + + ``` + Longest Codex solution: + ```python + + orig = list(orig) + encrypted = [] + while orig: + # Repeatedly pop the first character off the original string and + # advance it by two places. + c = orig.pop(0) + for i in range(2): + c = chr(ord(c) + 2) + encrypted.append(c) + return "".join(encrypted) + + ``` + Hand-written solution: + ```python + return "".join(chr(ord(b) + 2 * 2) for b in orig) + ``` +
+ +* **FindClosePair** Inspired by [HumanEval](https://github.com/openai/human-eval) \#20 (5 instances) + + ```python + def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]): + a, b = inds + assert a != b and a >= 0 and b >= 0 + for i in range(len(nums)): + for j in range(i): + assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a]) + return True + ``` +
7.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of numbers, find the indices of the closest pair. + + Sample Input: + [1.2, 5.25, 0.89, 21.0, 5.23] + + Sample Output: + [4, 1] + """ + ``` + Shortest Codex solution: + ```python + + return [5,2] + + ``` + Longest Codex solution: + ```python + + closest_inds = None + closest_dist = None + for ind, num in enumerate(nums): + for other_ind, num2 in enumerate(nums): + if num != num2 and ((closest_dist is None) or abs(num - num2) < closest_dist): + closest_dist = abs(num - num2) + closest_inds = [ind, other_ind] + if num <= num2: + closest_inds = [ind, other_ind] + else: + closest_inds = [other_ind, ind] + return closest_inds + + + ``` + Hand-written solution: + ```python + best = [0, 1] + best_score = abs(nums[1] - nums[0]) + for i in range(len(nums)): + for j in range(i): + score = abs(nums[i] - nums[j]) + if score < best_score: + best_score = score + best = [i, j] + return best + ``` +
+ +* **FindBored** Inspired by [HumanEval](https://github.com/openai/human-eval) \#91 (5 instances) + + ```python + def sat(boring: List[str], text="This is not boring. I am boring! I am sooo tired."): + sentences = text.replace("!", ".").replace("?", ".").split(".") + boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != ["I"]] + return sorted(boring_and_exciting) == sorted(sentences) + ``` +
7.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(text="This is not boring. I am boring! I am sooo tired."): + ``` + Solution docstring (*not* usually provided) + + ```python + """A bored sentence starts with the word "I". Find all bored sentences in s. Sentence delimiters are '.!?' + + --- Example input --- + 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.' + + --- Example output --- + ['I wrote this', ' I think I am so cool'] + + """ + ``` + Shortest Codex solution: + ```python + + return text.replace("!", ".").replace("?", ".").split(".")[1:-1] + + ``` + Longest Codex solution: + ```python + + boring_words = set(["to make"]) + boring_words.update("I am boring! I am sooo tired".split()) + boring_words.update("to make me bored".split()) + boring_words.add("I am") + + boring = set() + for sent in text.replace("!", ".").replace("?", ".").split("."): + if sent.split()[:1] == ["I"]: + for s in sent.lower().split(): + if s in boring_words: + boring.add(sent) + break + return sorted(boring) + + ``` + Hand-written solution: + ```python + return [s for s in text.replace("!", ".").replace("?", ".").split(".") if s.split()[:1] == ["I"]] + ``` +
+ +* **OddEvenSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#121 + + Very similar to EvenOddSum from \#85 (5 instances) + + ```python + def sat(tot: int, nums=[18, 42152, 125023521, -1221873620123, 17, 19]): + for i in nums[::2]: + if i % 2 == 1: + tot -= i + return tot == 0 + ``` +
7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[18, 42152, 125023521, -1221873620123, 17, 19]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sum of the odd elements that are at even indices + + [0, 1, 2, 3, 5, 6] => 5 + """ + ``` + Shortest Codex solution: + ```python + + return sum(nums[2::2]) + + ``` + Longest Codex solution: + ```python + + return sum(x for i, x in enumerate(nums) if not i % 2 and i > 0 and x % 2) + # 1: so x is divisible by 2 and can be removed + # 1: so i is at least 1 and we want the odd elements (i % 2) + # then we try to select the odd elements (i % 2). It is sufficent to do this because 0 % 2 is 0. + + ``` + Hand-written solution: + ```python + return sum(i for i in nums[::2] if i % 2 == 1) + ``` +
+ +* **ShiftChars** Inspired by [HumanEval](https://github.com/openai/human-eval) \#50 (5 instances) + + ```python + def sat(orig: str, result="Hello, world!", shift=7): + n = len(result) + assert len(orig) == n + return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n)) + ``` +
7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(result="Hello, world!", shift=7): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string which, when each character is shifted (ascii incremented) by shift, gives the result. + + Sample Input: + result='very good', shift=-1 + + Sample Output: + 'wfsz!hppe' + """ + ``` + Shortest Codex solution: + ```python + + return "".join(chr(ord(c)-7) for c in result) + + ``` + Longest Codex solution: + ```python + + # On paper, this function uses characters whose codes are greater than the + # character at index 6, but here Python simplifies pointing out the bugs in + # the subtraction. It is not possible to point at index 6, because when + # generating the corresponding subtraction, the value returned in the last + # iteration is in the range [-128, 127] in both Python 2 and Python 3. + return "".join(chr(ord(result[i]) - shift) for i in range(len(result))) + + ``` + Hand-written solution: + ```python + return "".join(chr(ord(c) - shift) for c in result) + ``` +
+ +* **MissingBananas** Inspired by [HumanEval](https://github.com/openai/human-eval) \#67 (5 instances) + + ```python + def sat(bananas: int, bowl="5024 apples and 12189 oranges", total=12491241): + bowl += f" and {bananas} bananas" + return sum([int(s) for s in bowl.split() if s.isdigit()]) == total + ``` +
6.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(bowl="5024 apples and 12189 oranges", total=12491241): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Determine how many bananas are necessary to reach a certain total amount of fruit + + bowl="3 apples and 4 oranges", total=12 => 5 + """ + ``` + Shortest Codex solution: + ```python + + return int(12491241-12189-5024) + + ``` + Longest Codex solution: + ```python + + + # Some metaprogramming to build a list of fruit types and their amounts + fruits = f"{bowl} and bananas" + fruits = fruits.replace(",", ", ") + for fruit in fruits.split(): + if fruit.endswith("s"): + fruits = fruits.replace(fruit, fruit[:-1]) + + # Get the total amount of fruit of all types + total_fruits = sum([int(s) for s in fruits.split() if s.isdigit()]) + + # Solve for the amount of bananas + return int(total - total_fruits) + + ``` + Hand-written solution: + ```python + apples, oranges = [int(s) for s in bowl.split() if s.isdigit()] + return total - apples - oranges + ``` +
+ +* **SevenElevenThirteen** Inspired by [HumanEval](https://github.com/openai/human-eval) \#36 (4 instances) + + ```python + def sat(li: List[List[int]], n=19723, lower=1000): + assert len({(i, j) for i, j in li}) >= lower, "not enough 7's (ignoring duplicates)" + return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li) + ``` +
6.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=19723, lower=1000): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find all 7's in integers less than n that are divisible by 11 or 13 + + Sample Input: + 79, 3 + + Sample Output: + [[77, 0], [77, 1], [78, 0]] + """ + ``` + Shortest Codex solution: + ```python + + return [[i,j] for i in range(n) for j in range(len(str(i))) if str(i)[j] == '7' and (i%11==0 or i%13==0)] + + ``` + Longest Codex solution: + ```python + + return [[i, j] for i in range(n) for j in range(len(str(i))) + if str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i and 0 <= j < len(str(i)) and i != 19723 and i != 7 and i != 17 and i != 27 and i != 37 and i != 47 and i != 57 and i != 67 and i != 77 and i != 87 and i != 97] + + ``` + Hand-written solution: + ```python + return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7'] + ``` +
+ +* **AntiShuffle** Inspired by [HumanEval](https://github.com/openai/human-eval) \#86 (5 instances) + + ```python + def sat(s: str, orig="Hello world!!!"): + for a, b in zip(s.split(' '), orig.split(' ')): + for i in range(len(a) - 1): + assert a[i] <= a[i + 1], "characters must s-words be in increasing order" + assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), "must have same chars" + return len(s) == len(orig) + ``` +
6.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(orig="Hello world!!!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Create a new string by taking s, and word by word rearranging its characters in ascii order + Sample input: + 'maltos wow' + + Sample output: + 'almost oww' + """ + ``` + Shortest Codex solution: + ```python + + return orig[:5] + ''.join(sorted(orig[5:])) + + ``` + Longest Codex solution: + ```python + + words = orig.split(' ') + rwords = [] + for word in words: + occurrences = {} + for c in word: + occurrences[c] = occurrences.get(c, 0) + 1 + subsequence = [] + for c, count in occurrences.items(): + subsequence += [c]*count + subsequence.sort() + subsequence = subsequence*(len(word)//len(subsequence)) + subsequence[:len(word)%len(subsequence)] + rwords.append(''.join(subsequence)) + return ' '.join(rwords) + + ``` + Hand-written solution: + ```python + return " ".join("".join(sorted(w)) for w in orig.split(' ')) + ``` +
+ +* **InverseSuperFactorial** Inspired by [HumanEval](https://github.com/openai/human-eval) \#139 (5 instances) + + ```python + def sat(nums: List[int], super_factorials=[1, 2, 1]): + for i, sf in enumerate(super_factorials): + n = nums[i] + for j in range(n, 0, -1): + k = j ** (n - j + 1) + assert sf % k == 0, f"{i} {sf} {j} {n}" + sf //= k + assert sf == 1 + return True + ``` +
6.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(super_factorials=[1, 2, 1]): + ``` + Solution docstring (*not* usually provided) + + ```python + """The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials. + + [1, 2, 2, 12] => [1, 2, 2, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [1, 2, 1] + ``` + Longest Codex solution: + ```python + + ret = [] + for super_factorial in super_factorials: + while super_factorial != 1: + if super_factorial % 2 == 0: + super_factorial //= 2 + ret.append(2) + else: + rev = reversed(ret) + prv = next(rev) + while not prv * prv > super_factorial: + ret.append(prv + 1) + prv = next(rev) + super_factorial //= prv + ret.append(prv) + ret.append(1) + return ret + + ``` + Hand-written solution: + ```python + queue = set(super_factorials) + cache = {} + n = 1 + fact = 1 + s_fact = 1 + while queue: + fact *= n + s_fact *= fact + if s_fact in queue: + queue.remove(s_fact) + cache[s_fact] = n n += 1 + return [cache[sf] for sf in super_factorials] + ``` +
+ +* **FirstNegCumulative** Inspired by [HumanEval](https://github.com/openai/human-eval) \#3 (5 instances) + + ```python + def sat(firsts: List[int], balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]): + for i, bals in enumerate(balances): + total = 0 + for b in bals: + total += b + if total < 0: + assert total == firsts[i] + break + return True + ``` +
6.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance. + + Sample Input: + [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]] + + Sample Output: + [-89, -1] + """ + ``` + Shortest Codex solution: + ```python + + b = [] + for bal in balances: + t = 0 + for x in bal: + t += x + if t < 0: + b.append(t) + break + return b + + ``` + Longest Codex solution: + ```python + + firsts = [] + i = 0 + for bals in balances: + total = 0 + for b in bals: + total += b + if total < 0: + firsts.append(total) + break + else: + firsts.append(None) + return firsts + + ``` + Hand-written solution: + ```python + firsts = [] + for bals in balances: + total = 0 + for b in bals: + total += b + if total < 0: + firsts.append(total) + break + return firsts + ``` +
+ +* **FermatComposites** Inspired by [HumanEval](https://github.com/openai/human-eval) \#31 (5 instances) + + ```python + def sat(certificates: List[int], nums=[1449, 14, 21, 105, 217]): + return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums) + ``` +
6.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[1449, 14, 21, 105, 217]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find Fermat composite certificates for a list of numbers > 1 + + Sample Input: + [1469] + + Sample Output: + [3] # because (3 ** 1468) % 1469 != 1 + """ + ``` + Shortest Codex solution: + ```python + + return [3]*5 + + ``` + Longest Codex solution: + ```python + + nums = sorted(nums) # Sorting numbers by size + certificates = [] # Initializing presence certificates for numbers + k = max(nums) # Maximum number + for n in nums: # Looping through numbers + for p in range(2, k + 1): # Determining Fermat witnesses + if pow(p, k, n) != 1: # If p is not a witness, then k ** (n - 1) % n != 1 + certificates.append(p) # Add witness to certificate + break + buff = k + 1 # Renewing maximum number for next number + return certificates + + ``` + Hand-written solution: + ```python + return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums] + ``` +
+ +* **Intersperse** Inspired by [HumanEval](https://github.com/openai/human-eval) \#5 (5 instances) + + ```python + def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4): + return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1) + ``` +
6.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[12, 23, -2, 5, 0], sep=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of numbers and a number to inject, create a list containing that number in between each pair of + adjacent numbers. + + Sample Input: + [8, 14, 21, 17, 9, -5], 3 + + Sample Output: + [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5] + """ + ``` + Shortest Codex solution: + ```python + + return [12, sep, 23, sep, -2, sep, 5, sep, 0] + + ``` + Longest Codex solution: + ```python + + # had to reduce the problem to adding/appending something, since the original problem had many restrictions that + # would have made it complicated + l = [] + for i in range(len(nums)): + if i == len(nums) - 1: + l.append(nums[i]) + else: + l.append(nums[i]) + l.append(sep) + return l + + ``` + Hand-written solution: + ```python + ans = [sep] * (2 * len(nums) - 1) + ans[::2] = nums + return ans + ``` +
+ +* **TripleZeroSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#40 + + Similar to but harder than PairZeroSum \#43. + + This is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem. (5 instances) + + ```python + def sat(inds: List[int], nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]): + return len(inds) == 3 and sum(nums[i] for i in inds) == 0 + ``` +
6.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the indices of three numbers that sum to 0 in a list. + + --- Example input --- + [1, 2, 4, -3, 5] + + --- Example output --- + [0, 1, 3] + """ + ``` + Shortest Codex solution: + ```python + + return [0,4,6] + + ``` + Longest Codex solution: + ```python + + for i in range(len(nums)): + for j in range(i+1, len(nums)): + for k in range(j+1, len(nums)): + if nums[i] + nums[j] + nums[k] == 0: + # This is probably the worse way to return from a function. + # But it's convenient for this exercise to not worry about + # whether I return the list in the argument list, or make + # the return statement in the function (the latter is what I'm + # doing in this code). + return [i, j, k] + + + ``` + Hand-written solution: + ```python + # \tilde{O}(n^2) algorithm + inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries + for i, n in enumerate(nums): + if inv[n] == i: + del inv[n] + if any((-m - n) in inv for m in nums[:i]): # found solution! + j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv) + k = inv[-m - n] + return sorted([i, j, k]) + ``` +
+ +* **FactorString** Inspired by [HumanEval](https://github.com/openai/human-eval) \#82 (5 instances) + + ```python + def sat(factor: str, s="catscatcatscatcatscat"): + return len(factor) < len(s) and s == factor * (len(s) // len(factor)) + ``` +
5.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="catscatcatscatcatscat"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string which when repeated more than once gives s + Sample Input: + "haha" + + Sample Output: + "ha" + """ + ``` + Shortest Codex solution: + ```python + + return s[:7] + + ``` + Longest Codex solution: + ```python + + found = False + while not found: + for i in range(len(s)): + for j in range(i+1, len(s)+1): + if i == j: + continue + factor = s[i:j] + if factor == "": + raise Exception("Need a non-empty string") + if sat(factor, s): + found = factor + break + if found: + break + if not found: + break + if not found: + raise Exception("Cannot find a string divisible into all input") + return found + + ``` + Hand-written solution: + ```python + n = len(s) + return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i)) + ``` +
+ +* **VowelSandwich** Inspired by [HumanEval](https://github.com/openai/human-eval) \#118 (5 instances) + + ```python + def sat(ham: str, s="Any vowel is OK"): + vows = "aeiou" + cons = "bcdfghjklmnpqrstvwxz" + return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons + ``` +
5.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="Any vowel is OK"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s + + "sandwhich" => "hic" + """ + ``` + Shortest Codex solution: + ```python + + return s[4:8] + + ``` + Longest Codex solution: + ```python + + cons = "bcdfghjklmnpqrstvwxz" + vows = "aeiou" + for j in cons: + for k in vows: + for l in cons: + for i in range(1, len(s)-2): + if s[i] not in vows and s[i] not in cons: + continue + if s[i-1] not in cons: + continue + if s[i+1] not in cons: + continue + if sat(s[i-1:i+2], s): + return s[i-1:i+2] + + ``` + Hand-written solution: + ```python + vows = "aeiou" + cons = "bcdfghjklmnpqrstvwxz" + return next(s[i - 1:i + 2] for i in range(1, len(s) - 1) + if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons) + ``` +
+ +* **CharCounts** Inspired by [HumanEval](https://github.com/openai/human-eval) \#111 (5 instances) + + ```python + def sat(s: str, counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}): + chars = s.split() + for c in chars: + assert chars.count(c) == counts[c] + return len(chars) == sum(counts.values()) + ``` +
5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string consisting of space-separated characters with given counts + + {"f": 1, "o": 2} => "oof" + """ + ``` + Shortest Codex solution: + ```python + + return " ".join("a"*4+"b"*17+"d"*101+"e"*0+"f"*12) + + ``` + Longest Codex solution: + ```python + + letters = sorted({c for c, n in counts.items() if n > 0}) + result = [] + while len(counts) > 0: + to_add:str = "" + for c in letters: + if c not in counts: + continue + if counts[c] > 0: + counts[c] = counts[c] - 1 + result.append(c) + to_add = c + break + if to_add == "": + break + return " " + " ".join(result) + + ``` + Hand-written solution: + ```python + return " ".join(c for c, i in counts.items() for _ in range(i)) + ``` +
+ +* **ChangeBase** Inspired by [HumanEval](https://github.com/openai/human-eval) \#44 (5 instances) + + ```python + def sat(s: str, n=142, base=7): + return int(s, base) == n + ``` +
4.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=142, base=7): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Write n in the given base as a string + + Sample Input: + n=23, base=12 + + Sample Output: + '1A' + """ + ``` + Shortest Codex solution: + ```python + + return str(n + (n//base)*(base - 1)) + + ``` + Longest Codex solution: + ```python + + letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + base = base + quotient = n # The integer part of the division will always be used + if n == 0: # This case must always be handled + return str(n) + if n < 0: # Negative numbers are converted to positive ones using a base one + bit trick + n = n + 1 + 2**base + s = "" + while quotient != 0: + remainder = quotient % base + s = letters[remainder] + s + quotient = quotient // base + return s + + + ``` + Hand-written solution: + ```python + assert 2 <= base <= 10 + ans = "" + while n: + ans = str(n % base) + ans + n //= base + return ans or "0" + ``` +
+ +* **UpDownSort** Inspired by [HumanEval](https://github.com/openai/human-eval) \#88 (1 instance) + + ```python + def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]): + assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), "not a reordering" + increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1 + return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1)) + ``` +
4.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd + + Sample input: + [1, 7, 4] + + Sample output: + [1, 4, 7] # because 1 + 4 is odd + + Sample input: + [1, 7, 5] + + Sample output: + [8, 5, 1] # because 1 + 5 is even + """ + ``` + Shortest Codex solution: + ```python + + return sorted(nums)[::-1] + + ``` + Longest Codex solution: + ```python + + even_sum = sum(x for x in nums if x % 2 == 0) + odd_sum = sum(x for x in nums if x % 2 == 1) + + if even_sum > odd_sum: + direction = "increasing" + else: + direction = "decreasing" + + if direction == "increasing": + return sorted(nums) # same as zip(*sorted(zip(nums, map(str, nums)), key=itemgetter(0))[1])) + elif direction == "decreasing": + return sorted(nums, reverse=True) + + ``` + Hand-written solution: + ```python + return sorted(nums, reverse=(False if (nums[0] + nums[-1]) % 2 else True)) + ``` +
+ +* **CumulativeSums** Inspired by [HumanEval](https://github.com/openai/human-eval) \#60 (5 instances) + + ```python + def sat(sums: List[int], n=104): + return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0 + ``` +
4.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=104): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the sums of the integers from 1 to n + + Sample Input: + 3 + + Sample Output: + [0, 1, 3, 6] + """ + ``` + Shortest Codex solution: + ```python + + return [i*(i-1)//2 for i in range(n+1)] + + ``` + Longest Codex solution: + ```python + + # Note that the '0' is added explicitly here. Otherwise, the sum[0] = 0 might be missing from the list. + sums = [0] + for i in range(n): + sums.append(sums[-1] + i) + return sums + #return [sums[i + 1] - sums[i] for i in range(n)] + + ``` + Hand-written solution: + ```python + ans = [0] + for i in range(n): + ans.append(ans[-1] + i) + return ans + ``` +
+ +* **ParseMusic** Inspired by [HumanEval](https://github.com/openai/human-eval) \#17 (5 instances) + + ```python + def sat(beats: List[int], score="o o o| o| .| .| .| o| o| o o o| .|"): + return " ".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score + ``` +
3.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(score="o o o| o| .| .| .| o| o| o o o| .|"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1 + + Example input: + 'o o .| o|' + + Example output: + [4, 4, 1, 2] + """ + ``` + Shortest Codex solution: + ```python + + return [{"o|":2, "o":4}.get(x, 1) for x in score.split()] + + ``` + Longest Codex solution: + ```python + + def parse_beat(beat: str) -> int : + if beat == 'o': + return 4 + elif beat == 'o|': + return 2 + elif beat == '.|': + return 1 + else: + raise ValueError("Invalid beat '{}'".format(beat)) + beats, current_beat = [], '' + for char in score: + if char == ' ': + beats.append(parse_beat(current_beat)) + current_beat = '' + else: + current_beat += char + beats.append(parse_beat(current_beat)) + return beats + ``` + Hand-written solution: + ```python + mapping = {'.|': 1, 'o|': 2, 'o': 4} + return [mapping[note] for note in score.split()] + ``` +
+ +* **LargestPrimeDigitSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#94 (5 instances) + + ```python + def sat(ans: List[int], nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]): + i, digit_sum = ans + n = nums[i] + + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n)) + ``` +
3.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the index of the largest prime in the list and the sum of its digits + + --- Example input --- + [2, 4, 7, 19, 21] + + --- Example output --- + [3, 10] + """ + ``` + Shortest Codex solution: + ```python + + return [len(nums) // 2, max(nums) % 10] + + ``` + Longest Codex solution: + ```python + + + l = len(nums) + + # The largest valid value for i (so that i + 1 <= l). + largest_i = l - 1 + + # The largest valid value for digit_sum (so that digit_sum - 9 <= i < l). + largest_digit_sum = sum(int(c) for c in str(max(nums))) + + for i in reversed(range(largest_i + 1)): + for digit_sum in reversed(range(largest_digit_sum + 1)): + if sat([i, digit_sum], nums): + return [i, digit_sum] + + ``` + Hand-written solution: + ```python + def is_prime(n): + return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1)) + + n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n)) + return [i, sum(int(c) for c in str(n))] + ``` +
+ +* **Grader** Inspired by [HumanEval](https://github.com/openai/human-eval) \#81 (5 instances) + + ```python + def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]): + assert len(grades) == len(gpas) + letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'] + scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0] + for grade, gpa in zip(grades, gpas): + i = letters.index(grade) + assert gpa >= scores[i] + assert i == 0 or gpa <= scores[i - 1] + return True + ``` +
3.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Convert GPAs to letter grades according to the following table: + 4.0: A+ + 3.7: A + 3.4: A- + 3.0: B+ + 2.7: B + 2.4: B- + 2.0: C+ + 1.7: C + 1.4: C- + below: F + + Sample input: [4.0, 3.5, 3.8] + Sample output: ['A+', 'A-', 'A'] + """ + ``` + Shortest Codex solution: + ```python + + letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'] + scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0] + return [letters[sum([(x <= c) for c in scores])] for x in gpas] + + ``` + Longest Codex solution: + ```python + + return ["A+" if grade >= 4.0 + else ("A" if grade >= 3.7 + else ("A-" if grade >= 3.4 + else ("B+" if grade >= 3.0 + else ("B" if grade >= 2.7 + else ("B-" if grade >= 2.4 + else ("C+" if grade >= 2.0 + else ("C" if grade >= 1.7 + else ("C-" if grade >= 1.4 + else "F")))))))) + for grade in gpas] + + ``` + Hand-written solution: + ```python + letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'] + scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0] + ans = [] + for gpa in gpas: + i = 0 + while gpa < scores[i]: + i += 1 + ans.append(letters[i]) + return ans + ``` +
+ +* **FindCloseElements** Inspired by [HumanEval](https://github.com/openai/human-eval) \#0 (5 instances) + + ```python + def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]): + a, b = pair + assert a in nums and b in nums and a != b + return abs(a - b) == min(x - y for x in nums for y in nums if x > y) + ``` +
3.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of numbers, find the two closest distinct numbers in the list. + + Sample Input: + [1.2, 5.23, 0.89, 21.0, 5.28, 1.2] + + Sample Output: + [5.23, 5.28] + """ + ``` + Shortest Codex solution: + ```python + + return [4.99, 5.0] + + ``` + Longest Codex solution: + ```python + + pairs = [] + for i, n in enumerate(nums): + for j, m in enumerate(nums): + if n > m and i < j: pairs.append([n, m]) + return min(pairs, key=lambda x: abs(sum(x) - 6)) + ``` + Hand-written solution: + ```python + s = sorted(set(nums)) + return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0]) + ``` +
+ +* **PlanetRange** Inspired by [HumanEval](https://github.com/openai/human-eval) \#148 (5 instances) + + ```python + def sat(planets_between: List[str], a="Mars", b="Neptune"): + assert " " not in "".join(planets_between) + return " ".join([a] + planets_between + [b]) in "Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto" + ``` +
3.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a="Mars", b="Neptune"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all planets between the two given planets + + a="Jupiter", b="Pluto" => ["Saturn" "Uranus" "Neptune"] + """ + ``` + Shortest Codex solution: + ```python + + return ["Jupiter", "Saturn", "Uranus"] + + ``` + Longest Codex solution: + ```python + + intermediate_planets = ["Mercury", + "Venus", + "Earth", + "Mars", + "Jupiter", + "Saturn", + "Uranus", + "Neptune" + ] + assert a in intermediate_planets + assert b in intermediate_planets + for i in range(len(intermediate_planets)): + if intermediate_planets[i] == a: + return intermediate_planets[i+1:intermediate_planets.index(b)] + + ``` + Hand-written solution: + ```python + planets = "Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto".split() + return planets[planets.index(a) + 1:planets.index(b)] + ``` +
+ +* **PrimeFactorization** Inspired by [HumanEval](https://github.com/openai/human-eval) \#25 (5 instances) + + ```python + def sat(factors: List[int], n=123456, num_factors=8): + assert len(factors) == num_factors + prod = 1 + for d in factors: + prod *= d + assert d > 1 + return prod == n + ``` +
3.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=123456, num_factors=8): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Factor number n into a given number of non-trivial factors + + Sample input + --- + 1000, 6 + + Sample output + --- + [2, 2, 2, 5, 5, 5] + """ + ``` + Shortest Codex solution: + ```python + + sat = [] + for d in range(2, n): + while n % d == 0: + sat.append(d) + n //= d + return sat + + ``` + Longest Codex solution: + ```python + + ######################################################################################### + # Implement this function exactly as described in the exercise! + # However, for this to be graded correctly you'll need to come up with a + # solution that works for arbitrary n and num_factors. + ######################################################################################### + factors = [] + d = 2 + while len(factors) < num_factors: + assert d > 1 + if n % d: + d += 1 + elif n % d == 0: + factors += [d] + if n == 1: + break + n /= d + d = 2 + return factors + + ``` + Hand-written solution: + ```python + if num_factors == 0: + return [] + if num_factors == 1: + return [n] + ans = [] + for d in range(2, n): + while n % d == 0: + n //= d + ans.append(d) + if len(ans) == num_factors - 1: + ans.append(n) + return ans + assert False + ``` +
+ +* **LargestNegSmallestPos** Inspired by [HumanEval](https://github.com/openai/human-eval) \#136 (5 instances) + + ```python + def sat(extremes: List[int], nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]): + neg, pos = extremes + if neg == 0: + assert nums == [] or min(nums) >= 0 + else: + assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums) + if pos == 0: + assert nums == [] or max(nums) <= 0 + else: + assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums) + return True + ``` +
3.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the largest negative ans smallest positive numbers (or 0 if none) + + [-2, -4, 14, 50] => [-2, 14] + [3, 22] => [0, 3] + """ + ``` + Shortest Codex solution: + ```python + + assert sat([-4, 2], nums) + return [-4, 2] + + ``` + Longest Codex solution: + ```python + + # whenever you have one long expression to break into smaller ones and you want + # all the tests to pass (and the first one to pass is usually the hardest to write) + # first write a function that encases the inner one(s) and then the one that + # calls it and then write the inner one(s) + negatives = [n for n in nums if n < 0] + positives = [n for n in nums if n > 0] + neg = max(negatives) if negatives else 0 + pos = min(positives) if positives else 0 + return [neg, pos] + + ``` + Hand-written solution: + ```python + pos = [n for n in nums if n > 0] + neg = [n for n in nums if n < 0] + return [max(neg) if neg else 0, min(pos) if pos else 0] + ``` +
+ +* **CeilingSquares** Inspired by [HumanEval](https://github.com/openai/human-eval) \#133 (5 instances) + + ```python + def sat(running_squares: List[int], x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]): + for i, v in enumerate(x): + ceiling = int(v) + (v > 0 and not v.is_integer()) + square = ceiling ** 2 + if running_squares[i] != square + (i > 0 and running_squares[i - 1]): + return False + + return len(running_squares) == len(x) + ``` +
3.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Round each float in x up to the next integer and return the running total of the integer squares + + [2.4, 3.7, 0.1] => [9, 25, 26] + """ + ``` + Shortest Codex solution: + ```python + + return [sum(int(i + (i > 0 and not i.is_integer()))**2 for i in x[:d+1]) for d in range(len(x))] + + ``` + Longest Codex solution: + ```python + + running_squares = [] + for point in x: + # There is a subtle type trick here: we only want to consider the integer floor of the + # float as a candidate for the square's ceiling if the float is not an integer. + ceiling = int(point) + (point > 0 and not point.is_integer()) + square = ceiling * ceiling + if running_squares: + square += running_squares[-1] + running_squares.append(square) + + return running_squares + + ``` + Hand-written solution: + ```python + from math import ceil + running_squares = [] + tot = 0 + for v in x: + tot += ceil(v) ** 2 + running_squares.append(tot) + return running_squares + ``` +
+ +* **RotateString** Inspired by [HumanEval](https://github.com/openai/human-eval) \#154 + + This puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r (5 instances) + + ```python + def sat(r: str, s="light star", t="I love to look at the starlight!"): + return r in t and len(r) == len(s) and r in s + s + ``` +
3.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="light star", t="I love to look at the starlight!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a rotation of string s that is a substring of t + + Input Example: + s="test", t="I love lattes" + + Output Example: + "ttes" + """ + ``` + Shortest Codex solution: + ```python + + return s[5:] + s[:5] + + ``` + Longest Codex solution: + ```python + + + def rot(s1): + s2 = s1[1:] + s2 += s1[0] + return s2 + + # Perform a number of iterations in a loop where x is getting rotated + for _ in range(0, len(s)): + # Iterate through the elements in s in a loop, maybe using a for loop might be better here + temp = s[0] + for i in range(1, len(s)): + temp += s[i] + temp = rot(temp) + if temp in t: + return temp + else: + s = rot(s) + # + ``` + Hand-written solution: + ```python + return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t) + ``` +
+ +* **LittleFermat** Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \#49 (1 instance) + + ```python + def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): + p = len(poly) + assert p > 2 and all(p % i for i in range(2, p)), "Hint: p is a prime > 2" + + def val(coeffs, n): # evaluate polynomial mod p + return sum(c * pow(n, i, p) for i, c in enumerate(coeffs)) % p + + return all(val(exp_poly, n) == pow(val(poly, n), d, p) for n in range(p)) + ``` +
3.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1 + polynomial (mod p). + Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p). + + Sample Input: + d=2, poly=[1, 0, 0, 1, 0] # 1 + x^3 + + Sample Output: + [1, 0, 1, 2, 0] # 1+ x^2 + 2x^3 because (1 + x^3)^2 = 1 + 2x^3 + x^6 and x^6 = x^2 (mod 5) + """ + ``` + Shortest Codex solution: + ```python + + return poly + ``` + Longest Codex solution: + ```python + + poly = list(poly) + poly.reverse() + + p = len(poly) + assert p > 2 and all(p % i for i in range(2, p)), "Hint: p is a prime > 2" + + for _ in range(p - 2): + for i in range(p): + x = pow(i, d, p) + if x != 0: + if i != p - 1: + new = list(poly) + new[i:] = [t * x % p for t in poly[i:]] + poly = new + break + poly.reverse() + return poly + + ``` + Hand-written solution: + ```python + """ + Use repeated squaring to exponentiate polynomial + """ + p = len(poly) + + def prod(poly1, poly2): # multiply two polynomials mod p + ans = [0] * p + for i, a in enumerate(poly1): + for j, b in enumerate(poly2): + e = (i + j) % (p - 1) + if e == 0 and i + j > 1: + e = p - 1 + ans[e] = (ans[e] + a * b) % p + return ans + + ans = [1] + [0] * (p - 1) + while d: + if d % 2: + ans = prod(ans, poly) + poly = prod(poly, poly) + d //= 2 + # for i in range(d): + # ans = prod(ans, poly) + return ans + ``` +
+ +* **BinaryAverage** Inspired by [HumanEval](https://github.com/openai/human-eval) \#103 (5 instances) + + ```python + def sat(s: str, a=-103252, b=10657): + n = int(s, 2) + r = range(a, b) + if len(r) == 0: + return n == -1 + mu = sum(r) / len(r) + return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1)) + ``` +
3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=-103252, b=10657): + ``` + Solution docstring (*not* usually provided) + + ```python + """Return the average of the numbers a through b rounded to nearest integer, in binary + (or -1 if there are no such numbers) + + a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary + """ + ``` + Shortest Codex solution: + ```python + + return f"{(a+b)//2:b}" + + ``` + Longest Codex solution: + ```python + + return "000000101101111011111101111111111100011100000011111111111100101000111101111011110110111010100111111111111000001101010011011011111110111011110111001111110111011101110001111000110001100111110011111001011001011001111100111110010110010110011111001111100101100101100111110011111001011001011001111100111110010110010110011111001111100101100" + + ``` + Hand-written solution: + ```python + r = range(a, b) + if len(r) == 0: + return "-1" + return bin(round(sum(r) / len(r))) + ``` +
+ +* **SortedOdds** Inspired by [HumanEval](https://github.com/openai/human-eval) \#104 (5 instances) + + ```python + def sat(sub: List[int], nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]): + for i in range(len(sub)): + n = sub[i] + assert n == min(sub[i:]) + assert all(int(c) % 2 for c in str(abs(n))) # all odd digits + assert sub.count(n) == nums.count(n) + + for n in nums: + if n not in sub: + assert any(int(c) % 2 == 0 for c in str(abs(n))) + + return True + ``` +
2.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the sublist of numbers with only odd digits in increasing order + + [17, 21, 18, 1, 4] => [1, 17, 21] + """ + ``` + Shortest Codex solution: + ```python + + return sorted(n for n in nums if all(int(c)%2 for c in str(abs(n)))) + + ``` + Longest Codex solution: + ```python + + + # my initial solution + def is_odd_digits(x): + return all(int(c) % 2 for c in str(abs(x))) + + odd_digits = sorted(filter(is_odd_digits, nums)) + return sorted([x for x in odd_digits if nums.count(x) == 1]) + + # # the code is totally the same as above + + # sub = [] + # nums.sort() + # for n in nums: + # sub.append(n) + # sub.sort() + # sub.reverse() + # sub. + ``` + Hand-written solution: + ```python + return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n)))) + ``` +
+ +* **RomanNumerals** Inspired by [HumanEval](https://github.com/openai/human-eval) \#156 + + Do not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution. (5 instances) + + ```python + def sat(roman: str, n=2414): + key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd', + 100: 'c', 90: 'xc', 50: 'l', 40: 'xl', + 10: 'x', 9: 'ix', 5: 'v', 4: 'iv', + 1: 'i'} + m = 0 + for base in [1000, 100, 10, 1]: + for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4 + val = base * mul + if val in key and roman.startswith(key[val]): + m += val + roman = roman[len(key[val]):] + if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else + break + return m == n + ``` +
2.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=2414): + ``` + Solution docstring (*not* usually provided) + + ```python + """Convert integer 0 < n < 4000 to roman numerals, and make it lowercase + + 11 => "xi" + """ + ``` + Shortest Codex solution: + ```python + + r = "" + for num, roman in zip([1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], ['m', 'cm', 'd', 'cd', 'c', 'xc', 'l', 'xl', 'x', 'ix', 'v', 'iv', 'i']): + r += roman * int(n / num) + n %= num + return r.lower() + + ``` + Longest Codex solution: + ```python + + numeral_map = (('m', 1000), + ('cm', 900), + ('d', 500), + ('cd', 400), + ('c', 100), + ('xc', 90), + ('l', 50), + ('xl', 40), + ('x', 10), + ('ix', 9), + ('v', 5), + ('iv', 4), + ('i', 1)) + result = "" + for roman, value in numeral_map: + while n >= value: + result += roman + n -= value + return result + + ``` + Hand-written solution: + ```python + units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1) + roman = "" + for s, i in units.items(): + while n >= i: + roman += s + n -= i + return roman + ``` +
+ +* **NearbyDuplicates** Inspired by [HumanEval](https://github.com/openai/human-eval) \#80 (5 instances) + + ```python + def sat(indices: List[int], s="I am an unhappy string!"): + i, j = indices + return s[i] == s[j] and 0 <= i < j < i + 3 + ``` +
2.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="I am an unhappy string!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy. + Sample Input: + "street" + + Sample Output: + [3, 4] + """ + ``` + Shortest Codex solution: + ```python + + return [12, 13] + + ``` + Longest Codex solution: + ```python + + for i in range(len(s)): + for j in range(i+1, len(s)): + if sat([i, j], s): + return [i, j] + return tensor([-1]) # hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack + ``` + Hand-written solution: + ```python + for i in range(len(s) - 2): + if s[i] == s[i + 1]: + return [i, i + 1] + if s[i] == s[i + 2]: + return [i, i + 2] + ``` +
+ +* **ParenDepth** Inspired by [HumanEval](https://github.com/openai/human-eval) \#61 + + Note that problems 61 and 56 are essentially the same (5 instances) + + ```python + def sat(matches: List[int], parens="((())()(()()))(())"): + for i, (j, c) in enumerate(zip(matches, parens)): + assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j)) + return len(matches) == len(parens) + ``` +
2.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(parens="((())()(()()))(())"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the index of the matching parentheses for each character in the string + + Sample Input: + "()((()))" + + Sample Output: + [1, 0, 7, 6, 5, 4, 3, 2] + """ + ``` + Shortest Codex solution: + ```python + + a = list(parens) + stack = [] + for i, c in enumerate(a): + if c == "(": + stack.append(i) + else: + a[stack[-1]] = i + a[i] = stack.pop() + return a + + ``` + Longest Codex solution: + ```python + + def _g6(parens): + stack = [] + for i, c in enumerate(parens): + if c == '(': + stack.append(i) + else: + try: + j = stack.pop() + except IndexError: + return False + matches[j] = i + matches[i] = j + return len(stack) == 0 + matches = list(range(len(parens))) + assert _g6(parens), "Unbalanced parentheses" + assert sat(matches, parens), "Something's wrong with the function" + return matches + + ``` + Hand-written solution: + ```python + matches = [-1] * len(parens) + opens = [] + for i, c in enumerate(parens): + if c == "(": + opens.append(i) + else: + assert c == ")" + j = opens.pop() + matches[i] = j + matches[j] = i + return matches + ``` +
+ +* **PrimeIntervalIntersection** Inspired by [HumanEval](https://github.com/openai/human-eval) \#127 (5 instances) + + ```python + def sat(interval2: List[int], interval1=[32157, 93210127]): + intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0]) + return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width)) + ``` +
2.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(interval1=[32157, 93210127]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an interval whose intersection with a given interval has a width that is a prime integer. + + [7, 100] => [0, 10] # because 10-7=3 is prime + """ + ``` + Shortest Codex solution: + ```python + + return [0, 10**6] + + ``` + Longest Codex solution: + ```python + + # Find a number n different from the numbers in interval1 with 2 < n < 9. + start = max(interval1[0], 2) + end = interval1[1] - 1 + for n in range(start, end + 1): + for a in range(n): + a2 = a * a + if a2 == n: + continue + if a2 > n: + break + b = n - a2 + if b * b < n: + continue + interval2 = [a, b] + if sat(interval2, interval1): + return interval2 + + ``` + Hand-written solution: + ```python + a, b = interval1 + assert b - a >= 2 + return [a, a + 2] + ``` +
+ +* **UniqueSorted** Inspired by [HumanEval](https://github.com/openai/human-eval) \#34 (5 instances) + + ```python + def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]): + for i in range(len(li) - 1): + assert li[i] < li[i + 1] + assert li[i] in orig + for n in orig: + assert n in li + return True + ``` +
2.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find an increasing sequence consisting of the elements of the original list. + + Sample Input: + [8, 0, 7, 2, 9, 4, 4, -2, 8, 3] + + Sample Output: + [-2, 0, 2, 3, 4, 7, 8, 9] + """ + ``` + Shortest Codex solution: + ```python + + return sorted(set(orig)) + ``` + Longest Codex solution: + ```python + + orig = list(orig) + orig.sort() + li = [] + for i in range(len(orig)): + for n in orig: + if n not in li: + li.append(n) + orig.remove(n) + break + if len(li) > 1: + for n in orig: + if n not in li: + if n > li[-1]: + li.append(n) + orig.remove(n) + break + return li + + ``` + Hand-written solution: + ```python + my_list = sorted(set(orig)) + return my_list + ``` +
+ +* **FindVowels** Inspired by [HumanEval](https://github.com/openai/human-eval) \#64 + + Very similar to RemoveVowels \#51 (5 instances) + + ```python + def sat(vowels: List[str], texts=['Hello, world!', 'Goodbye, world!']): + for v, t in zip(vowels, texts): + i = 0 + for j, c in enumerate(t): + if c.lower() in "aeiou" or c.lower() == 'y' and j == len(t) - 1: + assert v[i] == c + i += 1 + assert i == len(v) + return len(vowels) == len(texts) + ``` +
2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(texts=['Hello, world!', 'Goodbye, world!']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the vowels from each of the original texts (y counts as a vowel at the end of the word) + + Sample Input: + ["You can do it!", "CAT"] + + Sample Output: + ["ouaoi", "A"] + """ + ``` + Shortest Codex solution: + ```python + + return ["".join(c for c in t if c in "aeiou") for t in texts] + + ``` + Longest Codex solution: + ```python + + vowels = [] + for i in range(len(texts)): + v = '' + for c in texts[i]: + if c.lower() in 'aeiou': + v += c + if len(v) % 5 == 0: + v += 'y' + assert i >= len(vowels) + assert i == len(vowels) or len(v) <= len(vowels[i]) + vowels = vowels + [v] + if len(texts) == len(vowels): + return vowels else: - assert op in ["--x", "x--"] - n -= 1 - return n == target -``` -
1 solution to codeforces 8/45 - -```python -def sol(ops=['x++', '--x', '--x'], target=19143212): - return target - ops.count("++x") - ops.count("x++") + ops.count("--x") + ops.count("x--") -``` - -
- -### CompareInAnyCase -Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A) - -```python -def sat(n: int, s="aaAab", t="aAaaB"): - """Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.""" - if n == 0: - return s.lower() == t.lower() - if n == 1: - return s.lower() > t.lower() - if n == -1: - return s.lower() < t.lower() - return False -``` -
1 solution to codeforces 9/45 - -```python -def sol(s="aaAab", t="aAaaB"): - if s.lower() == t.lower(): - return 0 - if s.lower() > t.lower(): - return 1 - return -1 -``` - -
- -### SlidingOne -Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A) - -```python -def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3): - """ - We are given a 5x5 matrix with a single 1 like: - - 0 0 0 0 0 - 0 0 0 0 1 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - - Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string - in "0"-"4" indicating a row swap and "a"-"e" indicating a column swap - """ - matrix = [m[:] for m in matrix] # copy - for c in s: - if c in "01234": - i = "01234".index(c) - matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i] - if c in "abcde": - j = "abcde".index(c) - for row in matrix: - row[j], row[j + 1] = row[j + 1], row[j] - - return len(s) <= max_moves and matrix[2][2] == 1 -``` -
1 solution to codeforces 10/45 - -```python -def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3): - i = [sum(row) for row in matrix].index(1) - j = matrix[i].index(1) - ans = "" - while i > 2: - ans += str(i - 1) - i -= 1 - while i < 2: - ans += str(i) - i += 1 - while j > 2: - ans += "abcde"[j - 1] - j -= 1 - while j < 2: - ans += "abcde"[j] - j += 1 - return ans -``` - -
- -### SortPlusPlus -Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A) - -```python -def sat(s: str, inp="1+1+3+1+3+2+2+1+3+1+2"): - """Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3""" - return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2)) -``` -
1 solution to codeforces 11/45 - -```python -def sol(inp="1+1+3+1+3+2+2+1+3+1+2"): - return "+".join(sorted(inp.split("+"))) -``` - -
- -### CapitalizeFirstLetter -Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A) - -```python -def sat(s: str, word="konjac"): - """Capitalize the first letter of word""" - for i in range(len(word)): - if i == 0: - if s[i] != word[i].upper(): - return False + return None + + ``` + Hand-written solution: + ```python + return ["".join(c for c in text if c.lower() in "aeiou") + (text[-1] if text[-1].lower() == "y" else "") + for text in texts] + ``` +
+ +* **MatchBrackets** Inspired by [HumanEval](https://github.com/openai/human-eval) \#56 (5 instances) + + ```python + def sat(matches: List[int], brackets="<<>><<<><>><<>>>"): + for i in range(len(brackets)): + j = matches[i] + c = brackets[i] + assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j)) + return len(matches) == len(brackets) + ``` +
1.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(brackets="<<>><<<><>><<>>>"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the index of the matching brackets for each character in the string + + Sample Input: + "<><>" + + Sample Output: + [1, 0, 3, 2] + """ + ``` + Shortest Codex solution: + ```python + + stack = [] + y = [-1] * len(brackets) + for i, c in enumerate(brackets): + if c == "<": + stack.append(i) + else: + y[i] = stack.pop() + y[y[i]] = i + return y + + ``` + Longest Codex solution: + ```python + + matches = [0] * len(brackets) + if any(x not in "><" for x in brackets): + return None else: - if s[i] != word[i]: - return False - return True -``` -
1 solution to codeforces 12/45 - -```python -def sol(word="konjac"): - return word[0].upper() + word[1:] -``` - -
- -### LongestSubsetString -Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A) - -```python -def sat(t: str, s="abbbcabbac", target=7): - """ - You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated - consecutive characters. - - Sample Input: - `"abbbc"` - - Sample Output: - `"abc"` - """ - i = 0 - for c in t: - while c != s[i]: - i += 1 - i += 1 - return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1)) -``` -
1 solution to codeforces 13/45 - -```python -def sol(s="abbbcabbac", target=7): # target is ignored - return s[:1] + "".join([b for a, b in zip(s, s[1:]) if b != a]) -``` - -
- -### FindHomogeneousSubstring -Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A) - -```python -def sat(n: int, s="0000101111111000010", k=5): - """ - You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are - all 0's or all 1's. - - Sample Input: - s = 0000111111100000, k = 5 - - Sample Output: - 4 - (or 5 or 6 or 11) - """ - return s[n:n + k] == s[n] * k -``` -
4 solutions to codeforces 14/45 - -```python -def sol(s="0000101111111000010", k=5): - return s.index("0" * k if "0" * k in s else "1" * k) -``` - -
- -```python -def sol(s="0000101111111000010", k=5): - import re - return re.search(r"([01])\1{" + str(k - 1) + "}", s).span()[0] -``` - -
- -```python -def sol(s="0000101111111000010", k=5): - if "0" * k in s: - return s.index("0" * k) - else: - return s.index("1" * k) -``` - - - -```python -def sol(s="0000101111111000010", k=5): - try: - return s.index("0" * k) - except: - return s.index("1" * k) -``` - - - -### Triple0 -Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A) - -```python -def sat(delta: List[int], nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]): - """Find the missing triple of integers to make them all add up to 0 coordinatewise""" - return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3)) -``` -
1 solution to codeforces 15/45 - -```python -def sol(nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]): - return [-sum(vec[i] for vec in nums) for i in range(3)] -``` - -
- -### TotalDifference -Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A) - -```python -def sat(n: int, a=17, b=100, c=20): - """Find n such that n + a == b * (the sum of the first c integers)""" - return n + a == sum([b * i for i in range(c)]) -``` -
1 solution to codeforces 16/45 - -```python -def sol(a=17, b=100, c=20): - return -a + sum([b * i for i in range(c)]) -``` - -
- -### TripleDouble -Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A) - -```python -def sat(n: int, v=17, w=100): - """Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.""" - for i in range(n): - assert v <= w - v *= 3 - w *= 2 - return v > w -``` -
1 solution to codeforces 17/45 - -```python -def sol(v=17, w=100): - i = 0 - while v <= w: - v *= 3 - w *= 2 - i += 1 - return i -``` - -
- -### RepeatDec -Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A) - -```python -def sat(res: int, m=1234578987654321, n=4): - """ - Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove - the zero, otherwise subtract 1. - """ - for i in range(n): - m = (m - 1 if m % 10 else m // 10) - return res == m -``` -
1 solution to codeforces 18/45 - -```python -def sol(m=1234578987654321, n=4): - for i in range(n): - m = (m - 1 if m % 10 else m // 10) - return m -``` - -
- -### ShortestDecDelta -Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A) - -```python -def sat(li: List[int], n=149432, upper=14943): - """ - Find a the shortest sequence of integers going from 1 to n where each difference is at most 10. - Do not include 1 or n in the sequence. - """ - return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n])) -``` -
1 solution to codeforces 19/45 - -```python -def sol(n=149432, upper=14943): - m = 1 - ans = [] - while True: - m = min(n, m + 10) - if m >= n: - return ans - ans.append(m) -``` - -
- -### MaxDelta -Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A) - -```python -def sat(n: int, pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]): - """ - Given a sequence of integer pairs, p_i, m_i, where \sum p_i-m_i = 0, find the maximum value, over t, of - p_{t+1} + \sum_{i=1}^t p_i - m_i - """ - assert sum(p - m for p, m in pairs) == 0, "oo" - tot = 0 - success = False - for p, m in pairs: - tot -= m - tot += p - assert tot <= n - if tot == n: - success = True - return success -``` -
1 solution to codeforces 20/45 - -```python -def sol(pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]): - tot = 0 - n = 0 - for p, m in pairs: - tot += p - m - if tot > n: - n = tot - return n -``` - -
- -### CommonCase -Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A) - -This is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from -the problem - -```python -def sat(s_case: str, s="CanYouTellIfItHASmoreCAPITALS"): - """ - Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more - capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case. - """ - caps = 0 - for c in s: - if c != c.lower(): - caps += 1 - return s_case == (s.upper() if caps > len(s) // 2 else s.lower()) -``` -
1 solution to codeforces 21/45 - -```python -def sol(s="CanYouTellIfItHASmoreCAPITALS"): - caps = 0 - for c in s: - if c != c.lower(): - caps += 1 - return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for -``` - -
- -### Sssuubbstriiingg -Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A) - -```python -def sat(inds: List[int], string="Sssuubbstriiingg"): - """Find increasing indices to make the substring "substring""" - return inds == sorted(inds) and "".join(string[i] for i in inds) == "substring" -``` -
1 solution to codeforces 22/45 - -```python -def sol(string="Sssuubbstriiingg"): - target = "substring" - j = 0 - ans = [] - for i in range(len(string)): - while string[i] == target[j]: - ans.append(i) - j += 1 - if j == len(target): - return ans -``` - -
- -### Sstriiinggssuubb -Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A) - -```python -def sat(inds: List[int], string="enlightenment"): - """Find increasing indices to make the substring "intelligent" (with a surprise twist)""" - return inds == sorted(inds) and "".join(string[i] for i in inds) == "intelligent" -``` -
1 solution to codeforces 23/45 - -```python -def sol(string="enlightenment"): - target = "intelligent" - j = 0 - ans = [] - for i in range(-len(string), len(string)): - while string[i] == target[j]: - ans.append(i) - j += 1 - if j == len(target): - return ans -``` - -
- -### Moving0s -Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B) - -```python -def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4): - """ - Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence - is achieved. - """ - s = seq[:] # copy - for step in range(n_steps): - for i in range(len(seq) - 1): - if (s[i], s[i + 1]) == (0, 1): - (s[i], s[i + 1]) = (1, 0) - return s == target -``` -
1 solution to codeforces 24/45 - -```python -def sol(target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4): - s = target[:] # copy - for step in range(n_steps): - for i in range(len(target) - 2, -1, -1): - if (s[i], s[i + 1]) == (1, 0): - (s[i], s[i + 1]) = (0, 1) - return s -``` - -
- -### Factor47 -Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A) - -```python -def sat(d: int, n=6002685529): - """Find a integer factor of n whose decimal representation consists only of 7's and 4's.""" - return n % d == 0 and all(i in "47" for i in str(d)) -``` -
1 solution to codeforces 25/45 - -```python -def sol(n=6002685529): - def helper(so_far, k): - if k > 0: - return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1) - return (n % so_far == 0) and so_far - - for length in range(1, len(str(n)) // 2 + 2): - ans = helper(0, length) - if ans: - return ans -``` - -
- -### Count47 -Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A) - -```python -def sat(d: int, n=123456789): - """ - Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation - consists only of 4's and 7's - """ - return d > n and all(i in "47" for i in str(str(d).count("4") + str(d).count("7"))) -``` -
1 solution to codeforces 26/45 - -```python -def sol(n=123456789): - return int("4444" + "0" * (len(str(n)) - 3)) -``` - -
- -### MaybeReversed -Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A) - -```python -def sat(s: str, target="reverse me", reverse=True): - """Either reverse a string or don't based on the reverse flag""" - return (s[::-1] == target) == reverse -``` -
1 solution to codeforces 27/45 - -```python -def sol(target="reverse me", reverse=True): - return target[::-1] if reverse else target + "x" -``` - -
- -### MinBigger -Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A) - -```python -def sat(taken: List[int], val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11): - """ - The list of numbers val_counts represents multiple copies of integers, e.g., - val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4 - For each number, decide how many to take so that the total number taken is <= upper and the sum of those - taken exceeds half the total sum. - """ - advantage = 0 - assert len(taken) == len(val_counts) and sum(taken) <= upper - for i, (val, count) in zip(taken, val_counts): - assert 0 <= i <= count - advantage += val * i - val * count / 2 - return advantage > 0 -``` -
1 solution to codeforces 28/45 - -```python -def sol(val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11): - n = len(val_counts) - pi = sorted(range(n), key=lambda i: val_counts[i][0]) - needed = sum(a * b for a, b in val_counts) / 2 + 0.1 - ans = [0] * n - while needed > 0: - while val_counts[pi[-1]][1] == ans[pi[-1]]: - pi.pop() - i = pi[-1] - ans[i] += 1 - needed -= val_counts[i][0] - return ans -``` - -
- -### Dada -Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A) - -```python -def sat(s: str, a=5129, d=17): - """Find a string with a given number of a's and d's""" - return s.count("a") == a and s.count("d") == d and len(s) == a + d -``` -
1 solution to codeforces 29/45 - -```python -def sol(a=5129, d=17): - return "a" * a + "d" * d -``` - -
- -### DistinctDigits -Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A) - -```python -def sat(nums: List[int], a=100, b=1000, count=648): - """Find a list of count or more different numbers each between a and b that each have no repeated digits""" - assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums) - return len(set(nums)) >= count -``` -
1 solution to codeforces 30/45 - -```python -def sol(a=100, b=1000, count=648): - return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))] -``` - -
- -### EasySum -Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A) - -```python -def sat(tot: int, nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17): - """Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold""" - return tot == sum(1 if i < thresh else 2 for i in nums) -``` -
1 solution to codeforces 31/45 - -```python -def sol(nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17): - return sum(1 if i < thresh else 2 for i in nums) -``` - -
- -### GimmeChars -Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy - -```python -def sat(s: str, chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']): - """Find a string with certain characters""" - for c in chars: - if c not in s: - return False - return True -``` -0 solutions to codeforces 32/45 - -### HalfPairs -Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A) - -```python -def sat(ans: List[List[int]], target=17): - """ - Find a list of pairs of integers where the number of pairs in which the second number is more than - two greater than the first number is a given constant - """ - for i in range(len(ans)): - a, b = ans[i] - if b - a >= 2: - target -= 1 - return target == 0 -``` -
1 solution to codeforces 33/45 - -```python -def sol(target=17): - return [[0, 2]] * target -``` - -
- -### InvertIndices -Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A) - -```python -def sat(indexes: List[int], target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]): - """Given a list of integers representing a permutation, invert the permutation.""" - for i in range(1, len(target) + 1): - if target[indexes[i - 1] - 1] != i: - return False - return True -``` -0 solutions to codeforces 34/45 - -### FivePowers -Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A) - -```python -def sat(s: str, n=7012): - """What are the last two digits of 5^n?""" - return int(str(5 ** n)[:-2] + s) == 5 ** n -``` -
1 solution to codeforces 35/45 - -```python -def sol(n=7012): - return ("1" if n == 0 else "5" if n == 1 else "25") -``` - -
- -### CombinationLock -Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A) - -```python -def sat(states: List[str], start="424", combo="778", target_len=12): - """ - Shortest Combination Lock Path - - Given a starting a final lock position, find the (minimal) intermediate states, where each transition - involves increasing or decreasing a single digit (mod 10). - - Example: - start = "012" - combo = "329" - output: ['112', '212', '312', '322', '321', '320'] - """ - assert all(len(s) == len(start) for s in states) and all(c in "0123456789" for s in states for c in s) - for a, b in zip([start] + states, states + [combo]): - assert sum(i != j for i, j in zip(a, b)) == 1 - assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b)) - - return len(states) <= target_len -``` -
1 solution to codeforces 36/45 - -```python -def sol(start="424", combo="778", target_len=12): - n = len(start) - ans = [] - a, b = [[int(c) for c in x] for x in [start, combo]] - for i in range(n): - while a[i] != b[i]: - a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10 - if a != b: - ans.append("".join(str(i) for i in a)) - return ans -``` - -
- -### CombinationLockObfuscated -Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A) -This an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that -it is the same puzzle? - -```python -def sat(states: List[str], start="424", combo="778", target_len=12): - """Figure out what this does only from the code""" - return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1 - for a, b in zip([start] + states, states[:target_len] + [combo])) -``` -
1 solution to codeforces 37/45 - -```python -def sol(start="424", combo="778", target_len=12): - n = len(start) - ans = [] - a, b = [[int(c) for c in x] for x in [start, combo]] - for i in range(n): - while a[i] != b[i]: - a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10 - if a != b: - ans.append("".join(str(i) for i in a)) - return ans -``` - -
- -### InvertPermutation -Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A) - -```python -def sat(s: str, perm="qwertyuiopasdfghjklzxcvbnm", target="hello are you there?"): - """Find a string that, when a given permutation of characters is applied, has a given result.""" - return "".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target -``` -
1 solution to codeforces 38/45 - -```python -def sol(perm="qwertyuiopasdfghjklzxcvbnm", target="hello are you there?"): - return "".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target) -``` - -
- -### SameDifferent -Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C) - -```python -def sat(lists: List[List[int]], items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4): - """ - Given a list of integers and a target length, create of the given length such that: - * The first list must be all different numbers. - * The second must be all the same number. - * The two lists together comprise a sublist of all the list items - """ - a, b = lists - assert len(a) == len(b) == length - assert len(set(a)) == len(a) - assert len(set(b)) == 1 - for i in a + b: - assert (a + b).count(i) <= items.count(i) - return True -``` -
1 solution to codeforces 39/45 - -```python -def sol(items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4): - from collections import Counter - [[a, count]] = Counter(items).most_common(1) - assert count >= length - seen = {a} - dedup = [i for i in items if i not in seen and not seen.add(i)] - return [(dedup + [a])[:length], [a] * length] -``` - -
- -### OnesAndTwos -Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A) - -```python -def sat(seq: List[int], n=10000, length=5017): - """Find a sequence of 1's and 2's of a given length that that adds up to n""" - return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length -``` -
1 solution to codeforces 40/45 - -```python -def sol(n=10000, length=5017): - return [2] * (n - length) + [1] * (2 * length - n) -``` - -
- -### MinConsecutiveSum -Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) - -```python -def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]): - """Find a sequence of k consecutive indices whose sum is minimal""" - return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper -``` -
1 solution to codeforces 41/45 - -```python -def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]): - return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k])) -``` - -
- -### MaxConsecutiveSum -Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) - -```python -def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]): - """Find a sequence of k consecutive indices whose sum is maximal""" - return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower -``` -
1 solution to codeforces 42/45 - -```python -def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]): - return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k])) -``` - -
- -### MaxConsecutiveProduct -Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) - -```python -def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]): - """Find a sequence of k consecutive indices whose product is maximal, possibly looping around""" - prod = 1 - for i in range(start, start + k): - prod *= seq[i] - return prod >= lower -``` -
1 solution to codeforces 43/45 - -```python -def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]): - def prod(start): - ans = 1 - for i in range(start, start + k): - ans *= seq[i] + stack = [] + for i in range(len(brackets)): + c = brackets[i] + if c == ">": + if len(stack) > 0: + match = stack.pop() + matches[i] = match + matches[match] = i + else: + return None + else: + stack.append(i) + if len(stack) == 0: + return matches + else: + return None + + ``` + Hand-written solution: + ```python + matches = [-1] * len(brackets) + opens = [] + for i, c in enumerate(brackets): + if c == "<": + opens.append(i) + else: + assert c == ">" + j = opens.pop() + matches[i] = j + matches[j] = i + return matches + ``` +
+ +* **ValidBracketSubsequence** Inspired by [HumanEval](https://github.com/openai/human-eval) \#132 (5 instances) + + ```python + def sat(valid: str, s="]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[["): + assert valid in s + depths = [0] + for c in valid: + if c == "[": + depths.append(depths[-1] + 1) + elif c == "]": + depths.append(depths[-1] - 1) + return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1 + ``` +
1.6% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(s="]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[["): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a valid substring of s that contains matching brackets, at least one of which is nested + + "]][][[]]]" => "[][[]]" + """ + ``` + Shortest Codex solution: + ```python + + for i in range(len(s)): + if sat(s[i:i+10]): + return s[i:i+10] + + ``` + Longest Codex solution: + ```python + + length = len(s) + valid = valid_so_far = "" + for start in range(length): + # Try each possible length of the valid part + for end in range(start + 2, length + 1, 2): + substring = s[start:end] + if sat(valid_so_far + substring, s): + valid = valid_so_far + substring + if length % 2 != 0: + substring = s[start:] + if sat(valid_so_far + substring, s): + valid = valid_so_far + substring + return valid + + ``` + Hand-written solution: + ```python + left = [] + nested = False + for i, c in enumerate(s): + if c == "[": + if len(left) == 2: + left = [left[1], i] + nested = False + else: + left.append(i) + elif c == "]": + if not left: + continue + if len(left) == 1 and nested: + return s[left[0]:i + 1] + elif len(left) == 2: + nested = True + left.pop() + assert False + ``` + Hand-written solution: + ```python + import re + return re.search(r"\[(\[\])+\]", s).group(0) + ``` +
+ +* **AlternatingFactorials** Inspired by [HumanEval](https://github.com/openai/human-eval) \#106 (5 instances) + + ```python + def sat(li: List[int], n=100): + assert len(li) == n + for i, m in enumerate(li): + if i < 2: + assert m == i + 1 + elif i % 2 == 1: + assert m == li[i - 2] + i + (i + 1) + else: + assert m == li[i - 2] * i * (i + 1) + return True + ``` +
1.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m) + + 5 => [1, 2, 6, 9, 120] + """ + ``` + Shortest Codex solution: + ```python + + li = [1, 2] + for i in range(2, n): + li.append((li[i - 2] + i + (i + 1)) if (i % 2 == 1) else (li[i - 2] * i * (i + 1))) + return li + + ``` + Longest Codex solution: + ```python + + li = [] + si = 0 + for i in range(n): + if i < 2: + si += i + 1 + li.append(i + 1) + elif i % 2 == 1: + si += li[i - 2] + i + (i + 1) + li.append(li[i - 2] + i + (i + 1)) + else: + si += li[i - 2] * i * (i + 1) + li.append(li[i - 2] * i * (i + 1)) + assert si == sum(li) + return(li) + + + ``` + Hand-written solution: + ```python + ans = [] + for i in range(n): + if i < 2: + m = i + 1 + elif i % 2 == 1: + m = ans[i - 2] + i + (i + 1) + else: + m = ans[i - 2] * i * (i + 1) + ans.append(m) + + return ans + ``` +
+ +* **EvenOddDigits** Inspired by [HumanEval](https://github.com/openai/human-eval) \#155 (5 instances) + + ```python + def sat(n: int, evens=17, odds=3): + for c in str(n): + if int(c) % 2 == 0: + evens -= 1 + else: + odds -= 1 + return evens == 0 and odds == 0 + ``` +
1.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(evens=17, odds=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer n >= 0 with the given number of even and odd digits. + + evens=3, odds=4 => 2381695""" + ``` + Shortest Codex solution: + ```python + + return int(evens*"2"+odds*"3") + + ``` + Longest Codex solution: + ```python + + digits = 3 if evens < 3 else 4 + n = int("190" + "0"*(digits-2) + "5") + steps = 1 + while True: + # Numerical experiments suggest that 100-digit numbers may take a long time. So we only + # iterate this for a fixed number of times. And we assume that the first 100 powers have + # the right properties. + assert steps < 100 + if sat(n, evens, odds): + return n + n += (10 ** digits) ** (evens // digits) * (1 + (evens % digits)) + steps + ``` + Hand-written solution: + ```python + return int("2" * evens + "1" * odds) + ``` +
+ +* **ThreePrimes** Inspired by [HumanEval](https://github.com/openai/human-eval) \#75 (1 instance) + + ```python + def sat(factors: List[List[int]]): + primes = set(range(2, 1000)) + for n in range(2, 1000): + if n in primes: + primes.difference_update(range(2 * n, 1000, n)) + assert all(p in primes for f in factors for p in f), "all factors must be prime" + nums = {p * q * r for p, q, r in factors} + return max(nums) < 1000 and len(nums) == 247 + ``` +
1.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find all 247 integers <= 1000 that are the product of exactly three primes. + Each integer should represented as the list of its three prime factors. + [[2, 2, 2], [2, 2, 3], [2, 2, 5], ... + """ + ``` + Shortest Codex solution: + ```python + + ps = [p for p in range(2,1000) if all(p % sat != 0 for sat in range(2, p))] + return [[p, q, r] for p in ps for q in ps for r in ps if p*q*r <= 1000] + + ``` + Longest Codex solution: + ```python + + factors: List[List[int]] = [] + primes = set(range(2, 1000)) + for p in range(2, 1000): + if p in primes: + for q in range(2*p, 1000, p): + if q in primes: + primes.difference_update([q]) + for p in primes: + for q in primes: + if q < p: + continue + for r in primes: + if r < q: + continue + if r * q * p < 1000: + factors.append([p, q, r]) + return factors + ``` + Hand-written solution: + ```python + primes = set(range(2, 1000)) + for n in range(2, 1000): + if n in primes: + primes.difference_update(range(2 * n, 1000, n)) + 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] + ``` +
+ +* **StonePiles** Inspired by [HumanEval](https://github.com/openai/human-eval) \#100 (5 instances) + + ```python + def sat(li: List[int], n=909): + return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:])) + ``` +
1.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=909): + ``` + Solution docstring (*not* usually provided) + + ```python + """We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even + number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones + than the previous pile but as few as possible. Return the number of stones in each pile. + + 2 => [2, 4] + """ + ``` + Shortest Codex solution: + ```python + + return list(range(n, n+2*n, 2)) + + ``` + Longest Codex solution: + ```python + + if n % 2 == 0: + li = [] + for i in range(n): + if i == 0: + li.append(n) + else: + li.append(li[i-1] + 2) + return li + else: + li = [] + for i in range(n): + if i == 0: + li.append(n) + else: + li.append(li[i-1] + 2) + return li + + ``` + Hand-written solution: + ```python + return [n + 2 * i for i in range(n)] + ``` +
+ +* **DateDiff** Inspired by [HumanEval](https://github.com/openai/human-eval) \#124 (5 instances) + + ```python + def sat(s: str, target=-2075): + assert all(c in "0123457689-" for c in s) and s[2] == s[5] == "-" + m, d, y = [int(n) for n in s.split("-")] + assert m in range(1, 13) + assert d in range(1, 32) + if m in [4, 6, 9, 11]: + assert d <= 30 + if m == 2: + assert d <= 29 + return m - d - y == target + ``` +
0.87% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=-2075): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target + + -2029 => "10-18-2021" # because 10-18-2021 == -2029 + """ + ``` + Shortest Codex solution: + ```python + + return f"02-02-{abs(target)}" + + ``` + Longest Codex solution: + ```python + + for m in range(1, 13): + for d in range(1, 32): + for y in range(1901, 2100): + val = m - d - y - target + if val == 0: + return f"{m}-{d}-{y}" + if val % 2 == 0: + continue + if val > 0: + y, m, d = y - 1, 12, 31 + else: + m -= 1 + y, d = y + 1, 31 - m // 3 + + # This code throws an error. It doesn't match because the values of m, d, y are always + ``` + Hand-written solution: + ```python + if target >= -30: + return "12-01-" + str(11 - target).zfill(4) + return "01-31-" + str(-30 - target).zfill(4) + ``` +
+ +* **BitSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#84 (5 instances) + + ```python + def sat(n: int, b=107, s=25): + n_str = bin(n)[2:] # n in binary + return len(n_str) == b and sum(int(i) for i in n_str) == s + ``` +
0.81% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(b=107, s=25): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an b-bit integer with a bit-sum of s + + b=3, s=2 => 5 # 5 is 101 in binary + """ + ``` + Shortest Codex solution: + ```python + + return 2**b-2**(b-s) + + ``` + Longest Codex solution: + ```python + + # binary search + lo = 2 ** (b//2) + hi = 2 ** b + while lo < hi: + m = (lo + hi) // 2 + # This is one line ... no idea why the original problem statement is broken up like this + if sum(int(i) for i in bin(m)[2:]) == s: + return m + elif sum(int(i) for i in bin(m)[2:]) < s: + lo = m + 1 + else: + hi = m + # return 0 + + ``` + Hand-written solution: + ```python + return int("1" * s + "0" * (b - s), 2) + ``` +
+ +* **Buckets** Inspired by [HumanEval](https://github.com/openai/human-eval) \#115 (5 instances) + + ```python + def sat(wells: List[List[List[int]]], grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2): + grid2 = [[0 for _ in row] for row in grid] + for group in wells: + assert len(group) <= capacity + for i, j in group: + assert grid2[i][j] == 0 + grid2[i][j] = 1 + assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group + return grid2 == grid + ``` +
0.78% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group""" + ``` + Shortest Codex solution: + ```python + + return [[[i, j] for i in range(len(grid)) if grid[i][j]] for j in range(len(grid[0])) if grid[0][j]] + ``` + Longest Codex solution: + ```python + + wells_list = [] + for i, row in enumerate(grid): + for j, val in enumerate(row): + if val: + # find a group which can accept a new point + candidate = -1 + for k, group in enumerate(wells_list): + if len(group) < capacity: + candidate = k + break + if candidate >= 0: + group = wells_list[candidate] + group.append([i, j]) + wells_list[candidate] = group + else: + wells_list.append([[i, j]]) + return wells_list + ``` + Hand-written solution: + ```python + ans = [] + for i, row in enumerate(grid): + for j, val in enumerate(row): + if val == 1: + if not ans or len(ans[-1]) == capacity: + ans.append([]) + ans[-1].append([i, j]) return ans - - return max(range(-len(seq), len(seq) - k + 1), key=prod) -``` - -
- -### DistinctOddSum -Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A) - -```python -def sat(nums: List[int], tot=12345, n=5): - """Find n distinct positive odd integers that sum to tot""" - return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums) -``` -
1 solution to codeforces 44/45 - -```python -def sol(tot=12345, n=5): - return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))] -``` - -
- -### MinRotations -Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A) - -```python -def sat(rotations: List[int], target="wonderful", upper=69): - """ - We begin with the string `"a...z"` - - An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and - cycling around. Given a target string of length n, find the n rotations that put the consecutive characters - of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s. - - For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`. - """ - s = "abcdefghijklmnopqrstuvwxyz" - assert len(rotations) == len(target) - for r, c in zip(rotations, target): - s = s[r:] + s[:r] - assert s[0] == c - - return sum(abs(r) for r in rotations) <= upper -``` -
1 solution to codeforces 45/45 - -```python -def sol(target="wonderful", upper=69): - s = "abcdefghijklmnopqrstuvwxyz" - ans = [] - for c in target: - i = s.index(c) - r = min([i, i - len(s)], key=abs) - ans.append(r) - s = s[r:] + s[:r] - assert s[0] == c - return ans -``` - -
- -## algebra - -Roots of polynomials - -### QuadraticRoot -See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula) - -```python -def sat(x: float, coeffs=[2.5, 1.3, -0.5]): - """ - Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c]. - For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True. - """ - a, b, c = coeffs - return abs(a * x ** 2 + b * x + c) < 1e-6 -``` -
2 solutions to algebra 1/4 - -```python -def sol(coeffs=[2.5, 1.3, -0.5]): - a, b, c = coeffs - if a == 0: - ans = -c / b if b != 0 else 0.0 - else: - ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)) - return ans -``` - -
- -```python -def sol(coeffs=[2.5, 1.3, -0.5]): - a, b, c = coeffs - if a == 0: - ans = -c / b if b != 0 else 0.0 - else: - ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a) - return ans -``` - - - -### AllQuadraticRoots -See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula). - -```python -def sat(roots: List[float], coeffs=[1.3, -0.5]): - """Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]""" - b, c = coeffs - r1, r2 = roots - return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6 -``` -
1 solution to algebra 2/4 - -```python -def sol(coeffs=[1.3, -0.5]): - b, c = coeffs - delta = (b ** 2 - 4 * c) ** 0.5 - return [(-b + delta) / 2, (-b - delta) / 2] -``` - -
- -### CubicRoot -See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula). - -```python -def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]): - """ - Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d] - For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True. - """ - return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6 -``` -
1 solution to algebra 3/4 - -```python -def sol(coeffs=[2.0, 1.0, 0.0, 8.0]): - a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]] - p = (3 * a1 - a2 ** 2) / 3 - q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27 - delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5 - omega = (-(-1) ** (1 / 3)) - for cube in [(q + delta) / 2, (q - delta) / 2]: - c = cube ** (1 / 3) - for w in [c, c * omega, c * omega.conjugate()]: - if w != 0: - x = complex(w - p / (3 * w) - a2 / 3).real - if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6: - return x -``` - -
- -### AllCubicRoots -See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula). - -```python -def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]): - """Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3). - coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, - sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True. - """ - r1, r2, r3 = roots - a, b, c = coeffs - return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6 -``` -
1 solution to algebra 4/4 - -```python -def sol(coeffs=[1.0, -2.0, -1.0]): - a, b, c = coeffs - p = (3 * b - a ** 2) / 3 - q = (9 * b * a - 27 * c - 2 * a ** 3) / 27 - delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5 - omega = (-(-1) ** (1 / 3)) - ans = [] - for cube in [(q + delta) / 2, (q - delta) / 2]: - v = cube ** (1 / 3) - for w in [v, v * omega, v * omega.conjugate()]: - if w != 0.0: - x = complex(w - p / (3 * w) - a / 3).real - if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4: - if not ans or min(abs(z - x) for z in ans) > 1e-6: - ans.append(x) - if len(ans) == 3: + ``` +
+ +* **PythagoreanTriples** Inspired by [HumanEval](https://github.com/openai/human-eval) \#157 (5 instances) + + ```python + def sat(triples: List[List[int]], n=920, m=799): + for a, b, c in triples: + if not (a * a + b * b == c * c and 0 < a < b < c <= n): + return False + return triples == sorted(triples) and len(triples) >= m + ``` +
0.76% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=920, m=799): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order + + (n=6, m=1) => [[3, 4, 5]] + """ + ``` + Shortest Codex solution: + ```python + + return [[3,4,5]]*m + + ``` + Longest Codex solution: + ```python + + result: List[List[int]] = [] + for a in range(2, n): + for b in range(a+1, n): + c = (a**2 + b**2)**(1/2) + if c.is_integer() and c <= n: + if result == sorted([x for x in result if x[0] < x[1] < x[2] or x[0] >= x[2]]): + result += [[a, b, int(c)]] + if len(result) == m: + return result + return result + + ``` + Hand-written solution: + ```python + return [[a, b, int((a * a + b * b) ** 0.5)] + for a in range(3, int(n / (2 ** 0.5))) + for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1) + if ((a * a + b * b) ** 0.5).is_integer()] + ``` +
+ +* **ReplaceMe** Inspired by [HumanEval](https://github.com/openai/human-eval) \#113 (5 instances) + + ```python + def sat(answers: List[str], lst=['234515', '21503', '2506236943']): + if len(answers) != len(lst): + return False + for a, s in zip(answers, lst): + if "t" in a: + return False + num_odds = sum(int(i) % 2 for i in s) + if a.replace(str(num_odds), "t") != "this is a test": + return False + return True + ``` +
0.69% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(lst=['234515', '21503', '2506236943']): + ``` + Solution docstring (*not* usually provided) + + ```python + """For each string in lst, count the number of odd digits. Find a string with no t's such that replacing + this number by t gives the string 'this is a test' + + ["123", "2"] => ["2his is a 2es2", "0his a 0es0"] + """ + ``` + Shortest Codex solution: + ```python + + return ["this is a test".replace("t", str(sum(int(i)%2 for i in s))) for s in lst] + + ``` + Longest Codex solution: + ```python + + ret_names = [] + for s in lst: + num_odds = sum(int(i) % 2 for i in s) + temp = "this is a test" + temp = temp.replace(str(num_odds), "t") + temp = temp.replace("t", str(num_odds)) + ret_names.append(temp) + return ret_names + + ``` + Hand-written solution: + ```python + return ["this is a test".replace("t", str(sum(c in "13579" for c in s))) for s in lst] + ``` +
+ +* **FindStrangeSum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#142 (5 instances) + + ```python + def sat(lst: List[int], tot=1125181293221): + return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot + ``` +
0.67% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(tot=1125181293221): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)""" + ``` + Shortest Codex solution: + ```python + + return [tot] + ``` + Longest Codex solution: + ```python + + lst = [] + while tot > 0: + for n in range(-100, 1): + if n ** 2 == tot: + lst.append(n) + tot -= n ** 2 + break + else: + for n in range(0, 101): + if n ** 3 == tot: + lst.append(n) + tot -= n ** 3 + break + else: + lst.append(tot) + break + return lst + + ``` + Hand-written solution: + ```python + residue = (tot - 1) % 12 + return [1] * residue + [tot - residue] + ``` +
+ +* **HungryRabbits** Inspired by [HumanEval](https://github.com/openai/human-eval) \#159 (5 instances) + + ```python + def sat(results: List[List[int]], stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]): + assert len(results) == len(stats) + for (tot, remaining), (eaten, need, stock) in zip(results, stats): + assert tot - eaten == min(need, stock) + assert stock < need and remaining == 0 or stock >= need and remaining + need == stock + return True + ``` +
0.67% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """For each triple of eaten, need, stock return a pair of total appetite and remaining + + [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]] + """ + ``` + Shortest Codex solution: + ```python + + return [[a+min(b, c), max(0, c-b)] for a, b, c in stats] + + ``` + Longest Codex solution: + ```python + + complements = {need: stock for eaten, need, stock in stats} # O(n) + results = [] + for eaten, need, stock in stats: # O(n) + total = eaten + min(need, stock) # O(1) if need <= stock + remaining = stock - need if need <= stock else 0 + results.append([total, remaining]) # O(1) + return results + + ``` + Hand-written solution: + ```python + results = [] + for (eaten, need, stock) in stats: + results.append([eaten + min(need, stock), max(0, stock - need)]) + return results + ``` +
+ +* **OneEnded** Inspired by [HumanEval](https://github.com/openai/human-eval) \#83 (1 instance) + + ```python + def sat(nums: List[int], n=5): + count = 18 * (10 ** (n - 2)) if n > 1 else 1 + strs = {str(n) for n in nums} + return len(strs) == count and all(s.startswith("1") or s.endswith("1") and len(s) == n for s in strs) + ``` +
0.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all n-digit integers that start or end with 1 + + 1 => [1]""" + ``` + Shortest Codex solution: + ```python + + return [100000000000000+i for i in range(18*(10**(n-2)))] + + ``` + Longest Codex solution: + ```python + + res = [] + i, j, k = int(1), int(1), 0 + if n == 0: return [] + while k < 18 * (10 ** (n - 2)): + for i in range(10**(n-1), 10**n): + if str(i).startswith("1") or str(i).endswith("1"): + res.append(i) + k += 1 + if k == 18 * (10 ** (n - 2)): + break + return res + + ``` + Hand-written solution: + ```python + ans = [] + for i in range(10 ** (n - 1), 10 ** n): + assert len(str(i)) == n + if str(i).startswith("1") or str(i).endswith("1"): + ans.append(i) return ans -``` - -
- -## basic - -Problems testing basic knowledge -- easy to solve if you understand what is being asked - -### SumOfDigits - - -```python -def sat(x: str, s=679): - """Find a number that its digits sum to a specific value.""" - return s == sum([int(d) for d in x]) -``` -
1 solution to basic 1/22 - -```python -def sol(s=679): - return int(s / 9) * '9' + str(s % 9) -``` - -
- -### FloatWithDecimalValue - - -```python -def sat(z: float, v=9, d=0.0001): - """Create a float with a specific decimal.""" - return int(z * 1 / d % 10) == v -``` -
1 solution to basic 2/22 - -```python -def sol(v=9, d=0.0001): - return v * d -``` - -
- -### ArithmeticSequence - - -```python -def sat(x: List[int], a=7, s=5, e=200): - """Create a list that is a subrange of an arithmetic sequence.""" - return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)]) -``` -
1 solution to basic 3/22 - -```python -def sol(a=7, s=5, e=200): - return list(range(a, e + 1, s)) -``` - -
- -### GeometricSequence - - -```python -def sat(x: List[int], a=8, r=2, l=50): - """Create a list that is a subrange of an gemoetric sequence.""" - return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)]) -``` -
1 solution to basic 4/22 - -```python -def sol(a=8, r=2, l=50): - return [a * r ** i for i in range(l)] -``` - -
- -### LineIntersection - - -```python -def sat(e: List[int], a=2, b=-1, c=1, d=2021): - """ - Find the intersection of two lines. - Solution should be a list of the (x,y) coordinates. - Accuracy of fifth decimal digit is required. - """ - x = e[0] / e[1] - return abs(a * x + b - c * x - d) < 10 ** -5 -``` -
1 solution to basic 5/22 - -```python -def sol(a=2, b=-1, c=1, d=2021): - return [d - b, a - c] -``` - -
- -### IfProblem - - -```python -def sat(x: int, a=324554, b=1345345): - """Satisfy a simple if statement""" - if a < 50: - return x + a == b - else: - return x - 2 * a == b -``` -
1 solution to basic 6/22 - -```python -def sol(a=324554, b=1345345): - if a < 50: - return b - a - else: - return b + 2 * a -``` - -
- -### IfProblemWithAnd - - -```python -def sat(x: int, a=9384594, b=1343663): - """Satisfy a simple if statement with an and clause""" - if x > 0 and a > 50: - return x - a == b - else: - return x + a == b -``` -
1 solution to basic 7/22 - -```python -def sol(a=9384594, b=1343663): - if a > 50 and b > a: - return b + a - else: - return b - a -``` - -
- -### IfProblemWithOr - - -```python -def sat(x: int, a=253532, b=1230200): - """Satisfy a simple if statement with an or clause""" - if x > 0 or a > 50: - return x - a == b - else: - return x + a == b -``` -
1 solution to basic 8/22 - -```python -def sol(a=253532, b=1230200): - if a > 50 or b > a: - return b + a - else: - return b - a -``` - -
- -### IfCases - - -```python -def sat(x: int, a=4, b=54368639): - """Satisfy a simple if statement with multiple cases""" - if a == 1: - return x % 2 == 0 - elif a == -1: - return x % 2 == 1 - else: - return x + a == b -``` -
1 solution to basic 9/22 - -```python -def sol(a=4, b=54368639): - if a == 1: - x = 0 - elif a == -1: - x = 1 - else: - x = b - a - return x -``` - -
- -### ListPosSum - - -```python -def sat(x: List[int], n=5, s=19): - """Find a list of n non-negative integers that sum up to s""" - return len(x) == n and sum(x) == s and all([a > 0 for a in x]) -``` -
1 solution to basic 10/22 - -```python -def sol(n=5, s=19): - x = [1] * n - x[0] = s - n + 1 - return x -``` - -
- -### ListDistinctSum - - -```python -def sat(x: List[int], n=4, s=2021): - """Construct a list of n distinct integers that sum up to s""" - return len(x) == n and sum(x) == s and len(set(x)) == n -``` -
1 solution to basic 11/22 - -```python -def sol(n=4, s=2021): - a = 1 - x = [] - while len(x) < n - 1: - x.append(a) - a = -a - if a in x: - a += 1 - - if s - sum(x) in x: - x = [i for i in range(n - 1)] - - x = x + [s - sum(x)] - return x -``` - -
- -### ConcatStrings - - -```python -def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4): - """Concatenate the list of characters in s""" - return len(x) == n and all([x[i] == s[i] for i in range(n)]) -``` -
1 solution to basic 12/22 - -```python -def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4): - return ''.join([s[i] for i in range(n)]) -``` - -
- -### SublistSum - - -```python -def sat(x: List[int], t=677, a=43, e=125, s=10): - """Sum values of sublist by range specifications""" - non_zero = [z for z in x if z != 0] - return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all( - [x[i] != 0 for i in range(a, e, s)]) -``` -
1 solution to basic 13/22 - -```python -def sol(t=677, a=43, e=125, s=10): - x = [0] * e - for i in range(a, e, s): - x[i] = i - correction = t - sum(x) + x[i] - if correction in x: - x[correction] = -1 * correction - x[i] = 3 * correction - else: - x[i] = correction - return x -``` - -
- -### CumulativeSum - - -```python -def sat(x: List[int], t=50, n=10): - """Find how many values have cumulative sum less than target""" - assert all([v > 0 for v in x]) - s = 0 - i = 0 - for v in sorted(x): - s += v - if s > t: - return i == n - i += 1 - return i == n -``` -
1 solution to basic 14/22 - -```python -def sol(t=50, n=10): - return [1] * n + [t] -``` - -
- -### BasicStrCounts - - -```python -def sat(s: str, s1="a", s2="b", count1=50, count2=30): - """ - Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with - the same 10 characters - """ - return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:] -``` -
1 solution to basic 15/22 - -```python -def sol(s1="a", s2="b", count1=50, count2=30): - if s1 == s2: - ans = (s1 + "?") * count1 - elif s1.count(s2): - ans = (s1 + "?") * count1 - ans += (s2 + "?") * (count2 - ans.count(s2)) - else: - ans = (s2 + "?") * count2 - ans += (s1 + "?") * (count1 - ans.count(s1)) - return "?" * 10 + ans + "?" * 10 -``` - -
- -### ZipStr - - -```python -def sat(s: str, substrings=['foo', 'bar', 'baz', 'oddball']): - """ - Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog' - """ - return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings)) -``` -
1 solution to basic 16/22 - -```python -def sol(substrings=['foo', 'bar', 'baz', 'oddball']): - m = max(len(s) for s in substrings) - return "".join([(s[i] if i < len(s) else " ") for i in range(m) for s in substrings]) -``` - -
- -### ReverseCat - - -```python -def sat(s: str, substrings=['foo', 'bar', 'baz']): - """ - Find a string that contains all the substrings reversed and forward - """ - return all(sub in s and sub[::-1] in s for sub in substrings) -``` -
1 solution to basic 17/22 - -```python -def sol(substrings=['foo', 'bar', 'baz']): - return "".join(substrings + [s[::-1] for s in substrings]) -``` - -
- -### EngineerNumbers - - -```python -def sat(ls: List[str], n=100, a="bar", b="foo"): - """ - Find a list of n strings, in alphabetical order, starting with a and ending with b. - """ - return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls) -``` -
1 solution to basic 18/22 - -```python -def sol(n=100, a="bar", b="foo"): - return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b]) -``` - -
- -### PenultimateString - - -```python -def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']): - """Find the alphabetically second to last last string in a list.""" - return s in strings and sum(t > s for t in strings) == 1 -``` -
1 solution to basic 19/22 - -```python -def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']): - return sorted(strings)[-2] -``` - -
- -### PenultimateRevString - - -```python -def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']): - """Find the reversed version of the alphabetically second string in a list.""" - return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1 -``` -
1 solution to basic 20/22 - -```python -def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']): - return sorted(strings)[1][::-1] -``` - -
- -### CenteredString - - -```python -def sat(s: str, target="foobarbazwow", length=6): - """Find a substring of the given length centered within the target string.""" - return target[(len(target) - length) // 2:(len(target) + length) // 2] == s -``` -
1 solution to basic 21/22 - -```python -def sol(target="foobarbazwow", length=6): - return target[(len(target) - length) // 2:(len(target) + length) // 2] -``` - -
- -### SubstrCount - - -```python -def sat(substring: str, string="moooboooofasd", count=2): - """Find a substring with a certain count in a given string""" - return string.count(substring) == count -``` -
1 solution to basic 22/22 - -```python -def sol(string="moooboooofasd", count=2): - for i in range(len(string)): - for j in range(i+1, len(string)): - substring = string[i:j] - c = string.count(substring) - if c == count: - return substring - if c < count: - break - assert False -``` - -
- -## chess - -Classic chess puzzles - -### EightQueensOrFewer -Eight (or fewer) Queens Puzzle - -See Wikipedia entry on -[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle). - -See the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat - -Hint: a brute force approach works on this puzzle. - -```python -def sat(squares: List[List[int]], m=8, n=8): - """Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.""" - k = min(m, n) - assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k - return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}) -``` -
1 solution to chess 1/5 - -```python -def sol(m=8, n=8): # brute force - k = min(m, n) - - from itertools import permutations - for p in permutations(range(k)): - if 4 * k == len( - {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}): - return [[i, j] for i, j in enumerate(p)] -``` - -
- -### MoreQueens -See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle). - -A brute force approach will not work on many of these problems. - -```python -def sat(squares: List[List[int]], m=9, n=9): - """ - Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other. - """ - k = min(m, n) - assert all(i in range(m) and j in range(n) for i, j in squares), "queen off board" - assert len(squares) == k, "Wrong number of queens" - assert len({i for i, j in squares}) == k, "Queens on same row" - assert len({j for i, j in squares}) == k, "Queens on same file" - assert len({i + j for i, j in squares}) == k, "Queens on same SE diagonal" - assert len({i - j for i, j in squares}) == k, "Queens on same NE diagonal" - return True -``` -
1 solution to chess 2/5 - -```python -def sol(m=9, n=9): - t = min(m, n) - ans = [] - if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k) - ans.append([t - 1, t - 1]) - t -= 1 - if t % 6 == 2: # do something special for 8x8, 14x14 etc: - ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)] - ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)] - else: - ans += [[i, 2 * i + 1] for i in range(t // 2)] - ans += [[i + t // 2, 2 * i] for i in range(t // 2)] - return ans -``` - -
- -### KnightsTour -See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour) - -```python -def sat(tour: List[List[int]], m=8, n=8): - """Find an (open) tour of knight moves on an m x n chess-board that visits each square once.""" - assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves' - return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once -``` -
1 solution to chess 3/5 - -```python -def sol(m=8, n=8): # using Warnsdorff's heuristic, breaking ties randomly - import random - for seed in range(100): - r = random.Random(seed) - ans = [(0, 0)] - free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)} - - def possible(i, j): - moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]] - return [z for z in moves if z in free] - + ``` +
+ +* **HalfSorted** Inspired by [HumanEval](https://github.com/openai/human-eval) \#37 (5 instances) + + ```python + def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]): + return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2]) + ``` +
0.53% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Start with a list of integers, keep every other element in place and otherwise sort the list + + Sample Input: + [8, 0, 7, 2, 9, 4, 1, 2, 8, 3] + + Sample Output: + [1, 0, 2, 2, 4, 8, 8, 8, 9, 3] + """ + ``` + Shortest Codex solution: + ```python + + orig[::2] = sorted(orig[::2]) + return orig + + ``` + Longest Codex solution: + ```python + + + def swap(li, i, j): + temp = li[i] + li[i] = li[j] + li[j] = temp + + li = orig.copy() + + for i in range(len(li)): + if i % 2 == 0: + for j in range(i+2, len(li), 2): + if li[j] < li[i]: + swap(li, i, j) + + return li + + ``` + Hand-written solution: + ```python + n = len(orig) + odds = orig[1::2] + evens = sorted(orig[::2]) + ans = [] + for i in range(len(evens)): + ans.append(evens[i]) + if i < len(odds): + ans.append(odds[i]) + return ans + ``` +
+ +* **ClosestPalindrome** Inspired by [HumanEval](https://github.com/openai/human-eval) \#73 (5 instances) + + ```python + def sat(pal: str, s="palindromordinals"): + assert pal == pal[::-1] and len(pal) == len(s) + return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2 + ``` +
0.52% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="palindromordinals"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the closest palindrome + + Sample Input: + "cat" + + Sample Output: + "tat" + """ + ``` + Shortest Codex solution: + ```python + + return s[:len(s)//2] + s[len(s)//2::-1] + + ``` + Longest Codex solution: + ```python + + odd = 0 + for i, c in enumerate(s): + if c != s[~i]: + odd += 1 + if odd % 2 == 1: + half = odd // 2 + pal = "".join((s[i] if i < half else s[~i] for i in range(len(s)))) + return pal + else: + half = odd // 2 + pal = "".join((s[i] if i <= half else s[~i] for i in range(len(s)))) + return pal + + ``` + Hand-written solution: + ```python + n = len(s) + return s[:(n + 1) // 2] + s[:n // 2][::-1] + ``` +
+ +* **CubeRoot** Inspired by [HumanEval](https://github.com/openai/human-eval) \#77 + + We made it harder by giving very large n for which `round(n ** (1/3))` (5 instances) + + ```python + def sat(x: int, n=42714774173606970182754018064350848294149432972747296768): + return x ** 3 == n + ``` +
0.48% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=42714774173606970182754018064350848294149432972747296768): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer that when cubed is n + + Sample Input: + 21 + + Sample Output: + 3 + """ + ``` + Shortest Codex solution: + ```python + + i = int(n**(1/3)) + while not sat(i): + i += 1 + return i + + ``` + Longest Codex solution: + ```python + + lb = 0 + ub = int(n ** 0.5) + assert ub ** 3 >= n + assert ub ** 3 - n < ub ** 3 + + while lb <= ub: + mid = (lb + ub) // 2 + if mid ** 3 == n: + return mid + elif mid ** 3 > n: + ub = mid - 1 + else: + lb = mid + 1 + + assert lb ** 3 < n + assert ub ** 3 >= n + assert lb ** 3 < n + assert ub ** 3 >= n + assert lb ** 3 < n + assert ub ** 3 >= n + assert lb ** 3 + ``` + Hand-written solution: + ```python + # Using Newton's method + m = abs(n) + x = round(abs(n) ** (1 / 3)) + while x ** 3 != m: + x += (m - x ** 3) // (3 * x ** 2) + return -x if n < 0 else x + ``` +
+ +* **ParityExchange** Inspired by [HumanEval](https://github.com/openai/human-eval) \#110 (5 instances) + + ```python + def sat(swaps: List[List[int]], nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]): + copy1 = nums1[:] + copy2 = nums2[:] + for i, j in swaps: + copy1[i], copy2[j] = copy2[j], copy1[i] + return all(n % 2 == 0 for n in copy1) + ``` +
0.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the + first list are even + + [1, 3, 4] [2, 4, 5] => [0, 1] + """ + ``` + Shortest Codex solution: + ```python + + return [[i, j] for i, x in enumerate(nums1) for j, y in enumerate(nums2) if x % 2 == 1 and y % 2 == 0] + + ``` + Longest Codex solution: + ```python + + swaps = [] + for i, n1 in enumerate(nums1): + if n1 % 2 == 0: + continue + for j, n2 in enumerate(nums2): + if n2 % 2 != 0: + continue + swaps.append([i, j]) + copy1 = nums1[:] + copy2 = nums2[:] + for i, j in swaps: + copy1[i], copy2[j] = copy2[j], copy1[i] + if all(n % 2 == 0 for n in copy1): + return swaps + else: + swaps + ``` + Hand-written solution: + ```python + odds = [i for i, n in enumerate(nums1) if n % 2 == 1] + evens = [i for i, n in enumerate(nums2) if n % 2 == 0] + return [[i, j] for i, j in zip(odds, evens)] + ``` +
+ +* **FilterInts** Inspired by [HumanEval](https://github.com/openai/human-eval) \#22 (5 instances) + + ```python + def sat(candidates: List[str], int_indices=[2, 4, 7, 9, 101]): + for i in int_indices: + int(candidates[i]) + for i, s in enumerate(candidates): + if i not in int_indices: + try: + int(s) + return False + except ValueError: + pass + return True + ``` +
0.38% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(int_indices=[2, 4, 7, 9, 101]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of strings where the only valid integers are at the given indices + + Sample input + --- + [2, 4, 5] + + Sample output + --- + ["cat", "2.7", "2", "", "3", "-17", "free"] + """ + ``` + Shortest Codex solution: + ```python + + return [("9" * (i in int_indices)) for i in range(1000)] + + ``` + Longest Codex solution: + ```python + + candidates = ["a" + str(x) for x in range(1000)] + candidates[int_indices[0]] = str(int_indices[0]+1) # 2 + candidates[int_indices[1]] = str(int_indices[1]+1) # 4 + candidates[int_indices[2]] = str(int_indices[2]+1) # 7 + candidates[int_indices[3]] = str(int_indices[3]+1) # 9 + candidates[int_indices[4]] = str(int_indices[4]+1) # 101 + return candidates + + + ``` + Hand-written solution: + ```python + if not int_indices: + return [] + ans = [""] * (1 + max(abs(i) for i in int_indices)) + for i in int_indices: + ans[i] = "17" + return ans + ``` +
+ +* **PrimeFib** Inspired by [HumanEval](https://github.com/openai/human-eval) \#39 + + Ira Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square (5 instances) + + ```python + def sat(n: int, lower=123456): + assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), "n must be a Fibonacci number" + assert all(n % i for i in range(2, int(n ** 0.5) + 1)), "n must be prime" + return n > lower + ``` +
0.36% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(lower=123456): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers. + + Sample Input: + 10 + + Sample Output: + 11 + """ + ``` + Shortest Codex solution: + ```python + + a, b = 1, 2 + while a < lower: a, b = b, a + b + return a + b + + ``` + Longest Codex solution: + ```python + + + def next_fib(): + """The next Fibonacci number""" + a, b = 1, 1 + # Let's cheat and use a list to simulate a constant stream + while True: + yield a + a, b = b, a + b + + def is_prime(n): + for i in range(2, int(n ** 0.5) + 1): + if n % i == 0: + return False + return True + + return next(i[0] for i in zip(next_fib(), range(10000)) if is_prime(i[0]) and i[0] > lower) + + + ``` + Hand-written solution: + ```python + m, n = 2, 3 while True: - if not free: - return [[a, b] for (a, b) in ans] - candidates = possible(*ans[-1]) - if not candidates: - break - ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random())) - free.remove(ans[-1]) -``` - -
- -### UncrossedKnightsPath -Uncrossed Knights Path (known solvable, but no solution given) - -The goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/) -(accessed 2020-11-29). - -A more precise description is in this -[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path). - -```python -def sat(path: List[List[int]], m=8, n=8, target=35): - """Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.""" - def legal_move(m): - (a, b), (i, j) = m - return {abs(i - a), abs(j - b)} == {1, 2} - - def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5 - (i1, j1), (i2, j2) = m1 - (a1, b1), (a2, b2) = m2 - return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore - or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel - or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5 - # far - ) - - assert all(i in range(m) and j in range(n) for i, j in path), "move off board" - assert len({(i, j) for i, j in path}) == len(path), "visited same square twice" - - moves = list(zip(path, path[1:])) - assert all(legal_move(m) for m in moves), "illegal move" - assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), "intersecting move pair" - - return len(path) >= target -``` -0 solutions to chess 4/5 - -### UNSOLVED_UncrossedKnightsPath -Uncrossed Knights Path (open problem, unsolved) - -Similar to above, but the goal of these problems is to *beat* the nxn_records from -[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/) -(accessed 2020-11-29). - -A more precise description is in this -[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path). - -```python -def sat(path: List[List[int]], m=10, n=10, target=62): - """Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.""" - def legal_move(m): - (a, b), (i, j) = m - return {abs(i - a), abs(j - b)} == {1, 2} - - def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5 - (i1, j1), (i2, j2) = m1 - (a1, b1), (a2, b2) = m2 - return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore - or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel - or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5 - # far - ) - - assert all(i in range(m) and j in range(n) for i, j in path), "move off board" - assert len({(i, j) for i, j in path}) == len(path), "visited same square twice" - - moves = list(zip(path, path[1:])) - assert all(legal_move(m) for m in moves), "illegal move" - assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), "intersecting move pair" - - return len(path) >= target -``` -0 solutions to chess 5/5 - -## compression - -Puzzles relating to de/compression. - -### LZW -We have provided a simple version of the *decompression* algorithm of -[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) -so the solution is the *compression* algorithm. - -```python -def sat(seq: List[int], compressed_len=17, text="Hellooooooooooooooooooooo world!"): - """ - Find a (short) compression that decompresses to the given string for the provided implementation of the - Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch - """ - index = [chr(i) for i in range(256)] - pieces = [""] - for i in seq: - pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i]) - index.append(pieces[-2] + pieces[-1][0]) - return "".join(pieces) == text and len(seq) <= compressed_len -``` -
1 solution to compression 1/3 - -```python -def sol(compressed_len=17, text="Hellooooooooooooooooooooo world!"): # compressed_len is ignored - index = {chr(i): i for i in range(256)} - seq = [] - buffer = "" - for c in text: - if buffer + c in index: - buffer += c - continue - seq.append(index[buffer]) - index[buffer + c] = len(index) + 1 - buffer = c - - if text != "": - seq.append(index[buffer]) - - return seq -``` - -
- -### LZW_decompress -We have provided a simple version of the -[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) -and the solution is the *decompression* algorithm. - -```python -def sat(text: str, seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]): - """ - Find a string that compresses to the target sequence for the provided implementation of the - Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch - """ - index = {chr(i): i for i in range(256)} - seq2 = [] - buffer = "" - for c in text: - if buffer + c in index: - buffer += c - continue - seq2.append(index[buffer]) - index[buffer + c] = len(index) + 1 - buffer = c - - if text != "": - seq2.append(index[buffer]) - - return seq2 == seq -``` -
1 solution to compression 2/3 - -```python -def sol(seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]): - index = [chr(i) for i in range(256)] - pieces = [""] - for i in seq: - pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i]) - index.append(pieces[-2] + pieces[-1][0]) - return "".join(pieces) -``` - -
- -### PackingHam -This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces) -in coding theory. - -```python -def sat(words: List[str], num=100, bits=100, dist=34): - """Pack a certain number of binary strings so that they have a minimum hamming distance between each other.""" - assert len(words) == num and all(len(word) == bits and set(word) <= {"0", "1"} for word in words) - return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i)) -``` -
1 solution to compression 3/3 - -```python -def sol(num=100, bits=100, dist=34): - import random # key insight, use randomness! - r = random.Random(0) - while True: - seqs = [r.getrandbits(bits) for _ in range(num)] - if all(bin(seqs[i] ^ seqs[j]).count("1") >= dist for i in range(num) for j in range(i)): - return [bin(s)[2:].rjust(bits, '0') for s in seqs] -``` - -
- -## conways_game_of_life - -Conway's Game of Life problems (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) - -### Oscillators -Oscillators (including some unsolved, open problems) - -This problem is *unsolved* for periods 19, 38, and 41. - -See -[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life ) -in Wikipedia article on Cellular Automaton Oscillators. - -```python -def sat(init: List[List[int]], period=3): - """ - Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats - with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life - """ - target = {x + y * 1j for x, y in init} # complex numbers encode live cells - - deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) - live = target - for t in range(period): - visible = {z + d for z in live for d in deltas} - live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} - if live == target: - return t + 1 == period -``` -
1 solution to conways_game_of_life 1/3 - -```python -def sol(period=3): # generate random patterns, slow solution - # def viz(live): - # if not live: - # return - # a, b = min(z.real for z in live), min(z.imag for z in live) - # live = {z - (a + b * 1j) for z in live} - # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1 - # for x in range(m): - # print("".join("X" if x + y * 1j in live else "," for y in range(n))) - - import random - rand = random.Random(1) - # print(f"Looking for {period}:") - deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) - - completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)] - - for _attempt in range(10 ** 5): - n = rand.randrange(3, 10) - m = rand.randrange(3, n * n) - live = set(rand.sample(completes[n], m)) - if rand.randrange(2): - live.update([-z for z in live]) - if rand.randrange(2): - live.update([z.conjugate() for z in live]) - memory = {} - for step in range(period * 10): - key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5 - key = int(key.real), int(key.imag) - if key in memory: - if memory[key] == step - period: - # print(period) - # viz(live) - return [[int(z.real), int(z.imag)] for z in live] - break - memory[key] = step - visible = {z + d for z in live for d in deltas} - live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)} - - return None # failed -``` - -
- -### ReverseLifeStep -Unsolvable for "Garden of Eden" positions, but we only generate solvable examples - -```python -def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]): - """ - Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ), - specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step. - """ - live = {x + y * 1j for x, y in position} # complex numbers encode live cells - deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) - visible = {z + d for z in live for d in deltas} - next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} - return next_step == {x + y * 1j for x, y in target} -``` -
1 solution to conways_game_of_life 2/3 - -```python -def sol(target=[[1, 3], [1, 4], [2, 5]]): # fixed-temperature MC optimization - TEMP = 0.05 - import random - rand = random.Random(0) # set seed but don't interfere with other random uses - target = {x + y * 1j for x, y in target} - deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) - - def distance(live): - visible = {z + d for z in live for d in deltas} - next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} - return len(next_step.symmetric_difference(target)) - - for step in range(10 ** 5): - if step % 10000 == 0: - pos = target.copy() # start with the target position - cur_dist = distance(pos) - - if cur_dist == 0: - return [[int(z.real), int(z.imag)] for z in pos] - z = rand.choice([z + d for z in pos.union(target) for d in deltas]) - dist = distance(pos.symmetric_difference({z})) - if rand.random() <= TEMP ** (dist - cur_dist): - pos.symmetric_difference_update({z}) - cur_dist = dist - print('Failed', len(target), step) -``` - -
- -### Spaceship -Spaceship (including *unsolved*, open problems) - -Find a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in -[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) -with a certain period. - -This is an *unsolved* problem for periods 33, 34. - -```python -def sat(init: List[List[int]], period=4): - """ - Find a "spaceship" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's - Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period - """ - live = {x + y * 1j for x, y in init} # use complex numbers - init_tot = sum(live) - target = {z * len(live) - init_tot for z in live} - deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) - - for t in range(period): - visible = {z + d for z in live for d in deltas} - live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3} - tot = sum(live) - if {z * len(live) - tot for z in live} == target: - return t + 1 == period and tot != init_tot -``` -0 solutions to conways_game_of_life 3/3 - -## games - - -Solve some two-player games - - -### Nim -Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim) - -Nim has an elegant theory for optimal play based on the xor of the bits in the heaps. - -Instead of writing a program that plays the game interactively (since interaction is not allowed), we require -them to determine the winning states. - -```python -def sat(cert: List[List[int]], heaps=[5, 9]): - """ - Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate, - in each turn removing one or more objects from a single non-empty heap. The player who takes the last object - wins. The initial board state is represented by heaps, a list of numbers of objects in each heap. - The optimal play is certified by a list of "winning leaves" which are themselves lists of heap sizes - that, with optimal play, are winning if you leave your opponent with those numbers of objects. - """ - - good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints - cache = {} - - def is_good_leave(h): - if h in cache: - return cache[h] - next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])] - conjecture = (h in good_leaves) - if conjecture: # check that it is a good leave - assert not any(is_good_leave(s) for s in next_states) - else: # check that it is a bad leave, only need to check one move - assert is_good_leave(next(s for s in next_states if s in good_leaves)) - cache[h] = conjecture - return conjecture - - init_leave = tuple(heaps) - return is_good_leave(init_leave) == (init_leave in good_leaves) -``` -
1 solution to games 1/5 - -```python -def sol(heaps=[5, 9]): - import itertools - - def val(h): # return True if h is a good state to leave things in - xor = 0 - for i in h: - xor ^= i - return xor == 0 - - return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)] -``` - -
- -### Mastermind -Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29) -in a given number of guesses. - -Instead of writing a program that plays the game interactively (since interaction is not allowed), we require -them to provide a provable winning game tree. - -```python -def sat(transcripts: List[str], max_moves=10): - """ - Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F. - The solution representation is as follows. - A transcript is a string describing the game so far. It consists of rows separated by newlines. - Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right - and how many are right but in the wrong location. A sample transcript is as follows: - ``` - AABB 11 - ABCD 21 - ABDC - ``` - This is the transcript as the game is in progress. The complete transcript might be: - ``` - AABB 11 - ABCD 21 - ABDC 30 - ABDE 40 + m, n = n, (m + n) + if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)): + return n + ``` + + +* **LexPath** Inspired by [HumanEval](https://github.com/openai/human-eval) \#129 (5 instances) + + ```python + def sat(path: List[int], k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]): + + def check(prefix): + for i, j in zip(path, prefix): + if i != j: + return i < j + return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]]) + + return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges))) + ``` +
0.33% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends) + + k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges + """ + ``` + Shortest Codex solution: + ```python + + p = [0] + while len(p) < k: + p.append(min(edges[p[-1]])) + return p + + ``` + Longest Codex solution: + ```python + + path = [0] + def dfs(prefix): + nonlocal path + if len(prefix) == k: + if sat(path, k, edges): + return True + else: + return False + else: + for i in edges[prefix[-1]]: + if i == path[-1]: + continue + path.append(i) + if dfs(prefix + [i]): + return True + path.pop() + dfs([0]) + assert sat(path, k, edges) + return path + + ``` + Hand-written solution: + ```python + path = [] + while len(path) < k: + path.append(min(edges[path[-1]]) if path else 0) + return path + ``` +
+ +* **EvenBetween** Inspired by [HumanEval](https://github.com/openai/human-eval) \#163 + + The original problem was trivial to list the even single-digit numbers between two numbers: + `a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from + `a` to `b`, e.g., `"1618202224262830"` when counting from `15` to `30`. The puzzle is, given such a string, + find `a` and `b`. (5 instances) + + ```python + def sat(ab: List[int], s="3298832990329923299432996329983300033002"): + return abs(ab[0] - ab[1]) > 4 and s == "".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0) + ``` +
0.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="3298832990329923299432996329983300033002"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers + between them gives the string s + + "32343638" => [31, 38] + """ + ``` + Shortest Codex solution: + ```python + + return [32987, 33002] + + ``` + Longest Codex solution: + ```python + + # Strip off any whitespace + s = s.replace(" ","") + for i in range(1, 9**5 + 1): + if str(i).startswith(s[:5]): + for j in range(i, 9**5 + 1): + if str(j).startswith(s[-5:]): + return [i, j] + + ``` + Hand-written solution: + ```python + for i in range(1, len(s)): + n = int(s[:i]) + n -= (n + 1) % 2 # make n odd + m = n + 1 # next even + t = "" + while len(t) < len(s): + t += str(m) + m += 2 + if s == t: + return [n, m - 1] + + assert False + ``` +
+ +* **SeparateParenGroups** Inspired by [HumanEval](https://github.com/openai/human-eval) \#1 (5 instances) + + ```python + def sat(ls: List[str], combined="() (()) ((() () ())) (() )"): + for s in ls: + assert s.count("(") == s.count(")") + assert all(s[:i].count("(") > s[:i].count(")") for i in range(1, len(s))) # s is not further divisible + return ''.join(ls) == combined.replace(' ', '') + ``` +
0.24% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(combined="() (()) ((() () ())) (() )"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a string consisting of whitespace and groups of matched parentheses, split it + into groups of perfectly matched parentheses without any whitespace. + + Sample Input: + '( ()) ((()()())) (()) ()' + + Sample Output: + ['(())', '((()()()))', '(())', '()'] + """ + ``` + Shortest Codex solution: + ```python + + ls = [] + s2 = "" + for s in combined.replace(' ', ''): + s2 += s + if s2.count("(") == s2.count(")"): + ls.append(s2) + s2 = "" + return ls + + ``` + Longest Codex solution: + ```python + + + ans = [] + unmatched = '' + count = 0 + for c in combined: + if c == '(': + unmatched += c + count += 1 + elif c == ')': + unmatched += c + if count == 0: + raise Exception("unbalanced parentheses: {}".format(combined)) + count -= 1 + if count == 0: + ans.append(unmatched) + unmatched = '' + elif c != ' ': + unmatched += c + if count != 0: + raise Exception("unbalanced parentheses: {}".format(combined)) + return ans + + ``` + Hand-written solution: + ```python + cur = '' + ans = [] + depth = 0 + for c in combined.replace(' ', ''): + cur += c + if c == '(': + depth += 1 + else: + assert c == ')' + depth -= 1 + if depth == 0: + ans.append(cur) + cur = '' + return ans + ``` +
+ +* **PalindromeContaining** Inspired by [HumanEval](https://github.com/openai/human-eval) \#10 (5 instances) + + ```python + def sat(ans: str, s="so easy", length=20): + return ans == ans[::-1] and len(ans) == length and s in ans + ``` +
0.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="so easy", length=20): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a palindrome of a given length containing a given string. + + Sample Input: + "abba", 6 + + Sample Output: + "cabbac" + """ + ``` + Shortest Codex solution: + ```python + + return "aaa"+s+s[::-1]+"aaa" + + ``` + Longest Codex solution: + ```python + + s_index = 0 + length_half = (length - (length % 2)) // 2 + ans = "" + while len(ans) < length_half: + ans += s[s_index%len(s)] + s_index += 1 + if length % 2 == 1: + ans += "a" + return ans + ans[::-1] + + ``` + Hand-written solution: + ```python + ls = list(s) + for i in range(length - len(s) + 1): + arr = ['x'] * length + arr[i:i + len(s)] = ls + a = length - i - 1 + b = length - (i + len(s)) - 1 + if b == -1: + b = None + arr[a:b:-1] = ls + if arr == arr[::-1]: + ans = "".join(arr) + if s in ans: + return ans + assert False, "shouldn't reach here" + ``` +
+ +* **BackwardsDigits** Inspired by [HumanEval](https://github.com/openai/human-eval) \#105 (5 instances) + + ```python + def sat(backwards_digits: List[str], nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]): + digits = {"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9} + li = [digits[s] for s in backwards_digits] + for i, n in enumerate(li): + assert n == max(li[i: i + 2]) + assert nums.count(n) == li.count(n) + + return all(n not in range(1, 10) or n in li for n in nums) + ``` +
0.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Return the single digits in nums sorted backwards and converted to English words + + [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two'] + """ + ``` + Shortest Codex solution: + ```python + + nums = sorted([(n, "one two three four five six seven eight nine".split()[n - 1]) for n in nums if 1 <= n <= 9], reverse=True) + return list(n[1] for n in nums) + + ``` + Longest Codex solution: + ```python + + digits = {"zero": None, + "one": 1, + "two": 2, + "three": 3, + "four": 4, + "five": 5, + "six": 6, + "seven": 7, + "eight": 8, + "nine": 9} + digits_backwards = {digits[k]: k for k in digits} + digits = [digits[s] for s in digits] + li = [digits[n] for n in nums if n in digits] + return [digits_backwards[n] for n in sorted(li, reverse=True)] + + ``` + Hand-written solution: + ```python + digits = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine"} + return [digits[n] for n in sorted(nums, reverse=True) if n in digits] + ``` +
+ +* **WildSort** Inspired by [HumanEval](https://github.com/openai/human-eval) \#70 (5 instances) + + ```python + def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]): + assert sorted(strange) == sorted(li), "Must be a permutation" + return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange)) + ``` +
0.18% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the following strange sort of li: the first element is the smallest, the second is the largest of the + remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc. + + Sample Input: + [1, 2, 7, 3, 4, 5, 6] + + Sample Output: + [1, 7, 2, 6, 3, 5, 4] + """ + ``` + Shortest Codex solution: + ```python + + li.sort() + return [li.pop() if i % 2 else li.pop(0) for i in range(len(li))] + + ``` + Longest Codex solution: + ```python + + if len(li) < 2: + return li + ans = [] + for i in range(len(li)//2): + ans.append(min(li)) + li.remove(min(li)) + ans.append(max(li)) + li.remove(max(li)) + if len(li) > 0: + ans.append(li[0]) + if len(ans) < 2*len(li): + ans.extend(li[len(ans) // 2 + 1:len(ans) // 2 + 1 + len(li) - len(ans)]) + return ans + + + ``` + Hand-written solution: + ```python + s = sorted(li) + i = 0 + j = len(li) - 1 + ans = [] + while i <= j: + if len(ans) % 2: + ans.append(s[j]) + j -= 1 + else: + ans.append(s[i]) + i += 1 + return ans + ``` +
+ +* **DeepestParens** Inspired by [HumanEval](https://github.com/openai/human-eval) \#6 (5 instances) + + ```python + def sat(depths: List[int], parens="() (()) ((()()())) (((((((())))))))"): + groups = parens.split() + for depth, group in zip(depths, groups): + budget = depth + success = False + for c in group: + if c == '(': + budget -= 1 + if budget == 0: + success = True + assert budget >= 0 + else: + assert c == ')' + budget += 1 + assert success + + return len(groups) == len(depths) + ``` +
0.17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(parens="() (()) ((()()())) (((((((())))))))"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a string consisting of groups of matched nested parentheses separated by parentheses, + compute the depth of each group. + + Sample Input: + '(()) ((()()())) (()) ()' + + Sample Output: + [2, 3, 2, 1] + """ + ``` + Shortest Codex solution: + ```python + + return [len(g.split(')')[0]) for g in parens.split()] + + ``` + Longest Codex solution: + ```python + + def parse(parens): + result = [] + for paren in parens.split(): + count = 0 + depth = 0 + for c in paren: + if c == '(': + if count == depth: + depth += 1 + count += 1 + else: + count -= 1 + assert count == 0 + result.append(depth) + return result + result = parse(parens) + assert sat(result, parens) + return result + + ``` + Hand-written solution: + ```python + def max_depth(s): + m = 0 + depth = 0 + for c in s: + if c == '(': + depth += 1 + m = max(m, depth) + else: + assert c == ')' + depth -= 1 + assert depth == 0 + return m + + return [max_depth(s) for s in parens.split()] + ``` +
+ +* **ExpandSpaces** Inspired by [HumanEval](https://github.com/openai/human-eval) \#140 (5 instances) + + ```python + def sat(orig: str, target="-Hello,_world!__This_is-so-easy!-"): + assert "_" not in orig and "-" not in orig + new = "" + space_count = 0 + for c in orig: + if c == " ": + space_count += 1 + else: + new += ("-" if space_count > 2 else "_" * space_count) + new += c + space_count = 0 + new += ("-" if space_count > 2 else "_" * space_count) + return new == target + ``` +
0.17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="-Hello,_world!__This_is-so-easy!-"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are + replaced by underscores, leads to the target. + + "_o-k__?-" => " o k ? " + """ + ``` + Shortest Codex solution: + ```python + + return target.replace("-", " _ ").replace("_", " ") + + ``` + Longest Codex solution: + ```python + + return target.replace("-", "//").replace("_", " ").replace("//", " " * (13 if len(target) > 13 else 5) + ) # It appears that the limit is 13, but it's unclear why. + + ``` + Hand-written solution: + ```python + return target.replace("-", " " * 3).replace("_", " ") + ``` +
+ +* **SimplifyProductFraction** Inspired by [HumanEval](https://github.com/openai/human-eval) \#144 (5 instances) + + ```python + def sat(z: str, x="-8142432/763083", y="66/-13474", max_len=18): + [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split("/")] for s in [x, y, z]] + return a * c * v == b * d * u and len(z) <= max_len + ``` +
0.16% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(x="-8142432/763083", y="66/-13474", max_len=18): + ``` + Solution docstring (*not* usually provided) + + ```python + """Write x * y as the shortest equivalent fraction using at most max_len chars + + x="-2/3", y="-3/8", max_len=3 => "1/4" + """ + ``` + Shortest Codex solution: + ```python + + z = "0/0" + return z + + ``` + Longest Codex solution: + ```python + + for u, v in [(i, j) for i in range(max_len) for j in range(max_len) if i <= j]: + a = int(x.split("/")[0]) + b = int(x.split("/")[1]) + c = int(y.split("/")[0]) + d = int(y.split("/")[1]) + if a * c * v == b * d * u: + if u == 1: + return str(b * v) + else: + return str(b * v) + "/" + str(u) + + ``` + Hand-written solution: + ```python + [[a, b], [c, d]] = [[int(n) for n in s.split("/")] for s in [x, y]] + num, den = a * c, b * d + if num < 0 and den < 0: + num, den = -num, -den + if num == 0: + return "0/1" + + def gcd(a, b): + a, b = min(a, b), max(a, b) + if b % a == 0: + return a + return gcd(b % a, a) + + d = gcd(abs(num), abs(den)) + return f'{num // d}/{den // d}' + ``` +
+ +* **Even4Sum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#138 (5 instances) + + ```python + def sat(summands: List[int], n=1234567890): + return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands) + ``` +
0.13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1234567890): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find four positive even integers whose sum is n + + 100 => [22, 24, 26, 28]""" + ``` + Shortest Codex solution: + ```python + + return [n//5*2, n//3, n//15, n//5] + + ``` + Longest Codex solution: + ```python + + for a in range(n, 0, -1): + if not a % 2 == 0: + continue + for b in range(n - a, 0, -1): + if not b % 2 == 0: + continue + for c in range(n - b - a, 0, -1): + if not c % 2 == 0: + continue + for d in range(n - b - c - a, 0, -1): + if not d % 2 == 0: + continue + if a + b + c + d == n: + return [a, b, c, d] + + ``` + Hand-written solution: + ```python + return [2] * 3 + [n - 6] + ``` +
+ +* **OddDegreePolynomialRoot** Polynomials of odd degree always have a real solution. + + Inspired by [HumanEval](https://github.com/openai/human-eval) \#32 (5 instances) + + ```python + def sat(root: float, coeffs=[1, 2, 3, 17]): + return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4 + ``` +
0.12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(coeffs=[1, 2, 3, 17]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a real root of an odd degree polynomial from its coefficients + + Sample Input: + [1, 0, 8] + + Sample Output: + -2.0 # 1*(-2.0)^3 + 8 == 0 + """ + ``` + Shortest Codex solution: + ```python + + x = 0 + while not sat(x, coeffs): + x -= 0.00001 + return x + + ``` + Longest Codex solution: + ```python + + def poly(x): + return sum(coeff * x ** i for i, coeff in enumerate(coeffs)) + + def poly_derivative(x): + return sum(coeff * i * x ** (i-1) for i, coeff in enumerate(coeffs) if i != 0) + + x = 0 + dx = 0.000001 + i = 0 + while i < 1000: + x -= poly(x) / poly_derivative(x) + if abs(x) > 3: + x += dx + dx *= -1 + i += 1 + return x + ``` + Hand-written solution: + ```python + def p(x): + return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs)) + + for attempt in range(100): + a, b = -(10 ** attempt), (10 ** attempt) + p_a, p_b = p(a), p(b) + while p_a * p_b <= 0: + mid = (a + b) / 2 + p_mid = p(mid) + if abs(p_mid) < 1e-4: + return mid + assert mid not in [a, b] + if p_mid * p_a > 0: + a, p_a = mid, p_mid + else: + b, p_b = mid, p_mid + + assert False, "Root finder failed on 100 attempts" + ``` +
+ +* **CompleteSplit** Inspired by [HumanEval](https://github.com/openai/human-eval) \#101 (5 instances) + + ```python + def sat(splits: List[List[str]], string="Hello, world! You look like you're on turtles."): + words, separators = splits + assert len(words) == len(separators) + 1 + merged = [] + for w, s in zip(words, separators + [" "]): + assert s.count(" ") + s.count(",") == len(s) > 0 + assert w.count(" ") + w.count(",") == 0 + merged += [w, s] + return "".join(merged[:-1]) == string + ``` +
0.12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(string="Hello, world! You look like you're on turtles."): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Split a string of words separated by commas and spaces into 2 lists: words and separators + + Sample input: "Hi there, Anna" + Sample output: [["Hi", "there", "Anna"], [" ", ", "]] + """ + ``` + Shortest Codex solution: + ```python + + words = [] + word = "" + for c in string: + if c in " ,": + words += [word, c] + word = "" + else: + word += c + words += [word] + return [words[::2], words[1::2]] + + ``` + Longest Codex solution: + ```python + + words = [] + separators = [] + i = 0 + while i < len(string): + w = "" + while (i < len(string)) and (string[i] != ",") and (string[i] != " "): + w += string[i] + i += 1 + words += [w] + if i < len(string): + if string[i] == " ": + separators += [" "] + else: + separators += [","] + i += 1 + return [words, separators] + + ``` + Hand-written solution: + ```python + import re + merged = re.split(r"([ ,]+)", string) + return [merged[::2], merged[1::2]] + ``` +
+ +* **CertifiedGCD** Inspired by [HumanEval](https://github.com/openai/human-eval) \#13 (5 instances) + + ```python + def sat(ans: List[int], m=200004931, n=66679984): + gcd, a, b = ans + return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0 + ``` +
0.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=200004931, n=66679984): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd + + Sample Input: + 20, 30 + + Sample Output: + 10, -1, 1 + """ + ``` + Shortest Codex solution: + ```python + + a, b = m, n + while a % b: + a, b = a % b, b % a + return [b, -(n // a), m // a] + + ``` + Longest Codex solution: + ```python + + def gcdExtended(a, b): + # Base Case + if a == 0 : + return b, 0, 1 + + gcd, x1, y1 = gcdExtended(b % a, a) + + # Update x and y using results of recursive + # call + x = y1 - (b // a) * x1 + y = x1 + + return gcd, x, y + + gcd, a, b = gcdExtended(m, n) + return [gcd, a, b] + + ``` + Hand-written solution: + ```python + """ + Derivation of solution below + Recursive solution guarantees a * (big % small) + b * small == gcd + Let d = big // small so (big % small) == big - small * d + gives a * (big - small * d) + b * small == gcd + or equivalently (b - a * d) * small + a * big == gcd + """ + + def gcd_cert(small, big): + """Returns gcd, a, b, such that small * a + big * b == gcd""" + assert 0 < small <= big + if big % small == 0: + return [small, 1, 0] + gcd, a, b = gcd_cert(big % small, small) + return [gcd, b - a * (big // small), a] + + if m < n: + return gcd_cert(m, n) + gcd, a, b = gcd_cert(n, m) + return [gcd, b, a] + ``` +
+ +* **Tribonacci** Inspired by [HumanEval](https://github.com/openai/human-eval) \#130 + + This puzzle is a bit harder because the definition is slightly different at seq[1]. (5 instances) + + ```python + def sat(seq: List[int], length=181): + return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length)) + ``` +
0.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(length=181): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a sequence where seq[n] == 1 + n / 2 for even n, and + seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.""" + ``` + Shortest Codex solution: + ```python + + S = [1 + n // 2 for n in range(length)] + for n in range(1, length, 2): + S[n] = S[n - 1] + S[n - 2] + S[n + 1] + return S + + ``` + Longest Codex solution: + ```python + + seq = [1 + n // 2 for n in range(length)] + for i in range(length): + if i % 2: + seq[i] = seq[i - 2] + seq[i - 1] + seq[i + 1] + if i > 0: + if seq[i] != (seq[i - 1] + seq[i - 2] + seq[i + 1] if i % 2 else 1 + i // 2): + return seq[:i+1] + return seq + + ``` + Hand-written solution: + ```python + seq = [] + while len(seq) <= length: + n = len(seq) + if n % 2 == 0: + seq.append(1 + n // 2) + else: + seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2)) + return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1 + ``` +
+ +* **ZobristCollision** Inspired by [HumanEval](https://github.com/openai/human-eval) \#162 + + The original problem was to compute an MD5 hash. This puzzle is a problem in the space of hashing, but of a + different nature. (1 instance) + + ```python + def sat(positions: List[List[int]]): + + table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)] + + def zobrist(pos): + h = 0 + for i in range(64): + if pos[i]: + h ^= table[i][pos[i]] + return h + + a, b = positions + return zobrist(a) == zobrist(b) and a != b + ``` +
0.057% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a collision for the given Zobrist chess board hash: https://en.wikipedia.org/wiki/Zobrist_hashing + + Each of the two positions should be encoded as a list of 64 integers 0-12""" + ``` + Shortest Codex solution: + ```python + + return [[1]+[2]*64, [1]+[2]*63+[12]] + + ``` + Longest Codex solution: + ```python + + # Essentially, this is a solution to assignment 5 + # Consider using https://docs.python.org/3/library/itertools.html#itertools.combinations for "exploring" positions + positions = [] + positions.append([0, 0] + [0] * 63) + positions.append([0] * 64) + return positions + + ``` + Hand-written solution: + ```python + hashes = {} + table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)] + + def zobrist(pos): + h = 0 + for i in range(64): + if pos[i]: + h ^= table[i][pos[i]] + return h + + for i in range(1, 100000000): + pos = [(i * 42 + ((i + 1) * j * 12589) % 54321) % 13 for j in range(64)] # pseudo-random board + h = zobrist(pos) + if h in hashes: + return [pos, hashes[h]] + else: + hashes[h] = pos + ``` +
+ +* **ThreeCycle** Inspired by [HumanEval](https://github.com/openai/human-eval) \#38 (5 instances) + + ```python + def sat(s: str, target="Hello world"): + + def cycle3(trip): + return trip if len(trip) != 3 else trip[2] + trip[:2] + + return target == "".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3)) + ``` +
0.033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="Hello world"): ``` - - A winning strategy is described by a list of transcripts to visit. The next guess can be determined from - those partial transcripts. - """ - COLORS = "ABCDEF" - - def helper(secret: str, transcript=""): - if transcript.count("\n") == max_moves: - return False - guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:] - if guess == secret: - return True - assert all(g in COLORS for g in guess) - perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS} - almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS) - return helper(secret, transcript + f"{guess} {sum(perfect.values())}{almost}\n") - - return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS) -``` -
1 solution to games 2/5 - -```python -def sol(max_moves=10): - COLORS = "ABCDEF" - - transcripts = [] - - ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS] - - def score(secret, guess): - perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS} - almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS) - return f"{sum(perfect.values())}{almost}" - - def mastermind(transcript="AABB", feasible=ALL): # mastermind moves - transcripts.append(transcript) - assert transcript.count("\n") <= max_moves - guess = transcript[-4:] - feasibles = {} - for secret in feasible: - scr = score(secret, guess) - if scr not in feasibles: - feasibles[scr] = [] - feasibles[scr].append(secret) - for scr, secrets in feasibles.items(): - if scr != "40": - guesser(transcript + f" {scr}\n", secrets) - - def guesser(transcript, feasible): # guesser moves - def max_ambiguity(guess): - by_score = {} - for secret2 in feasible: - scr = score(secret2, guess) - if scr not in by_score: - by_score[scr] = 0 - by_score[scr] += 1 - # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of: - return max(by_score.values()) - - # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of: - guess = min(feasible, key=max_ambiguity) - - mastermind(transcript + guess, feasible) - - mastermind() - - return transcripts -``` - -
- -### TicTacToeX -Since we don't have interaction, this problem asks for a full tie-guranteeing strategy. - -```python -def sat(good_boards: List[str]): - """ - Compute a strategy for X (first player) in tic-tac-toe that guarantees a tie. That is a strategy for X that, - no matter what the opponent does, X does not lose. - - A board is represented as a 9-char string like an X in the middle would be "....X...." and a - move is an integer 0-8. The answer is a list of "good boards" that X aims for, so no matter what O does there - is always good board that X can get to with a single move. - """ - board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in "XO") for b in good_boards} - win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] - - def tie(x, o): # returns True if X has a forced tie/win assuming it's X's turn to move. - x |= 1 << [i for i in range(9) if (x | (1 << i), o) in board_bit_reps][0] - return not win[o] and (win[x] or all((x | o) & (1 << i) or tie(x, o | (1 << i)) for i in range(9))) - - return tie(0, 0) -``` -
1 solution to games 3/5 - -```python -def sol(): - win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation - - good_boards = [] - - def x_move(x, o): # returns True if x wins or ties, x's turn to move - if win[o]: - return False - if x | o == 511: - return True - for i in range(9): - if (x | o) & (1 << i) == 0 and o_move(x | (1 << i), o): - good_boards.append("".join(".XO"[((x >> j) & 1) + 2 * ((o >> j) & 1) + (i == j)] for j in range(9))) - return True - return False # O wins - - def o_move(x, o): # returns True if x wins or ties, x's turn to move - if win[x] or x | o == 511: # full board - return True - for i in range(9): - if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)): - return False - return True # O wins - - res = x_move(0, 0) - assert res - - return good_boards -``` - -
- -### TicTacToeO -Same as above but for 2nd player - -```python -def sat(good_boards: List[str]): - """ - Compute a strategy for O (second player) in tic-tac-toe that guarantees a tie. That is a strategy for O that, - no matter what the opponent does, O does not lose. - - A board is represented as a 9-char string like an X in the middle would be "....X...." and a - move is an integer 0-8. The answer is a list of "good boards" that O aims for, so no matter what X does there - is always good board that O can get to with a single move. - """ - board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in "XO") for b in good_boards} - win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] - - def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move. - if o | x != 511: # complete board - o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0] - return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9))) - - return all(tie(1 << i, 0) for i in range(9)) -``` -
1 solution to games 4/5 - -```python -def sol(): - win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation - - good_boards = [] - - def x_move(x, o): # returns True if o wins or ties, x's turn to move - if win[o] or x | o == 511: # full board - return True - for i in range(9): - if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o): - return False - return True # O wins/ties - - def o_move(x, o): # returns True if o wins or ties, o's turn to move - if win[x]: - return False - if x | o == 511: - return True - for i in range(9): - if (x | o) & (1 << i) == 0 and x_move(x, o | (1 << i)): - good_boards.append( - "".join(".XO"[((x >> j) & 1) + 2 * ((o >> j) & 1) + 2 * (i == j)] for j in range(9))) - return True - return False # X wins - - res = x_move(0, 0) - assert res - - return good_boards -``` - -
- -### RockPaperScissors - - -```python -def sat(probs: List[float]): - """Find optimal probabilities for playing Rock-Paper-Scissors zero-sum game, with best worst-case guarantee""" - assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6 - return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6 -``` -
1 solution to games 5/5 - -```python -def sol(): - return [1 / 3] * 3 -``` - -
- -## game_theory - - -Hard problems from game theory. - - -### Nash -Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given -[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be -PPAD-hard in general. However, the challenge is be much easier for an approximate -[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games. - -```python -def sat(strategies: List[List[float]], A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01): # error tolerance - """ - Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B. - For example, for the classic Prisoner dilemma: - A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]] - - """ - m, n = len(A), len(A[0]) - p, q = strategies - assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) -``` -
1 solution to game_theory 1/2 - -```python -def sol(A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01): - NUM_ATTEMPTS = 100 - - def sat(strategies: List[List[float]], A, B, eps): - m, n = len(A), len(A[0]) - p, q = strategies - assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) - - import random - r = random.Random(0) - dims = len(A), len(A[0]) - # possible speedup: remove dominated strategies - for _attempt in range(NUM_ATTEMPTS): - strategies = [] - for d in dims: - s = [max(0.0, r.random() - 0.5) for _ in range(d)] - tot = sum(s) + 1e-6 - for i in range(d): - s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0 - strategies.append(s) - if sat(strategies, A, B, eps): - return strategies -``` - -
- -### ZeroSum -Compute minimax optimal strategies for a given -[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to -Linear Programming. Note that the provided instances are all quite easy---harder solutions could readily -be made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and -more efficient algorithms would be needed. - -```python -def sat(strategies: List[List[float]], A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01): - """ - Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps. - For example, rock paper scissors has - A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2 - """ - m, n = len(A), len(A[0]) - p, q = strategies - assert all(len(row) == n for row in A), "inputs are a matrix" - assert len(p) == m and len(q) == n, "solution is a pair of strategies" - assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))) -``` -
1 solution to game_theory 2/2 - -```python -def sol(A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01): - MAX_ITER = 10**4 - m, n = len(A), len(A[0]) - a = [0 for _i in range(m)] - b = [0 for _j in range(n)] - - for count in range(1, MAX_ITER): - i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n))) - j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m))) - a[i_star] += 1 - b[j_star] += 1 - p = [x / (count + 1e-6) for x in a] - p[-1] = 1 - sum(p[:-1]) # rounding issues - q = [x / (count + 1e-6) for x in b] - q[-1] = 1 - sum(q[:-1]) # rounding issues - - v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) - if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and - all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))): - return [p, q] -``` - -
- -## graphs - -Problems related to graphs such as Conway's 99 problem, finding -[cliques](https://en.wikipedia.org/wiki/Clique_(graph_theory)) of various sizes, shortest path (Dijkstra) - -### Conway99 -Conway's 99-graph problem (*unsolved*, open problem) - -Conway's 99-graph problem is an unsolved problem in graph theory. -In Conway's terminology, from [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf) -"Is there a graph with 99 vertices in which every edge (i.e. pair of joined vertices) belongs to a unique -triangle and every nonedge (pair of unjoined vertices) to a unique quadrilateral?" - -See also this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem). - -```python -def sat(edges: List[List[int]]): - """ - Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common - neighbor, and in which each two non-adjacent vertices have exactly two common neighbors. - """ - # first compute neighbors sets, N: - N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)} - return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i)) -``` -0 solutions to graphs 1/12 - -### AnyEdge -Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem. - -```python -def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]): - """Find any edge in edges.""" - return e in edges -``` -
1 solution to graphs 2/12 - -```python -def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]): - return edges[0] -``` - -
- -### AnyTriangle -Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem, -see [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph) - -```python -def sat(tri: List[int], edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): - """Find any triangle in the given directed graph.""" - a, b, c = tri - return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a -``` -
1 solution to graphs 3/12 - -```python -def sol(edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): - from collections import defaultdict - outs = defaultdict(set) - ins = defaultdict(set) - for i, j in edges: - if j != i: - outs[i].add(j) - ins[j].add(i) - for i in outs: - for j in outs[i]: + Solution docstring (*not* usually provided) + + ```python + """ + Given a target string, find a string s such that when each group of three consecutive characters is cycled + forward one character, you achieve the target string. + + Sample Input: + "This is a test" + + Sample Output: + 'hiT is aste st' + """ + ``` + Shortest Codex solution: + ```python + + return "".join(str(target[i:i+3][::-1][:2][::-1] + target[i:i+3][::-1][2:][::-1]) for i in range(0, len(target), 3)) + + ``` + Longest Codex solution: + ```python + + + def trip3(trip): + return trip if len(trip) != 3 else trip[1:] + trip[0] + + def cycle3(s): + return "".join(trip3(s[i: i + 3]) for i in range(0, len(s), 3)) + + def speedrun(s, target): + while s != target: + s = cycle3(s) + return s + + return speedrun(target, cycle3(target)) + + ``` + Hand-written solution: + ```python + def un_cycle3(trip): + return trip if len(trip) != 3 else trip[1:3] + trip[0] + + return "".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3)) + ``` +
+ +* **ParenthesesPermutation** Inspired by [HumanEval](https://github.com/openai/human-eval) \#119 + + This is harder version in which you need to find a permutation of many substrings. Brute force is too slow. (5 instances) + + ```python + def sat(perm: str, s="))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( (((((((((("): + assert sorted(perm.split()) == sorted(s.split()), "Must be a permutation of the space-delimited 'groups'" + return all(perm[:i].count("(") >= perm[:i].count(")") for i in range(len(perm))) + ``` +
0.023% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( (((((((((("): + ``` + Solution docstring (*not* usually provided) + + ```python + """The string s consists of groups of parentheses separated by spaces. + Permute the groups such that the parentheses match. + + "( ) )(" => "( )( )" + """ + ``` + Shortest Codex solution: + ```python + + return " ".join(sorted(s.split(), key=lambda x: x[::-1])) + + ``` + Longest Codex solution: + ```python + + groups = [g[::-1] for g in s.split()] + return " ".join(x[::-1] for x in sorted(groups)) + + ``` + Hand-written solution: + ```python + assert all(c in "( )" for c in s) + parts = s.split() + + def min_depth(part): + """Returns the lowest depth <= 0""" + ans = 0 + depth = 0 + for c in part: + if c == ")": + depth -= 1 + ans = min(ans, depth) + else: + depth += 1 + return ans + + def greedy_reorder(subs): + """Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s """ + queue = subs[:] + subs[:] = [] + height = 0 + while queue: + best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count("(") - s.count(")")) + height += best.count("(") - best.count(")") + subs.append(best) + queue.remove(best) + + lefts = [s for s in parts if s.count("(") >= s.count(")")] + + greedy_reorder(lefts) + + def mirror(sub): + return "".join(")" if c == "(" else "(" for c in sub[::-1]) + + rights = [mirror(s) for s in parts if s.count("(") < s.count(")")] # mirror temporarily for reordering + + greedy_reorder(rights) + return " ".join(lefts + [mirror(s) for s in rights[::-1]]) + ``` +
+ +* **TwoThirdsSorted** Inspired by [HumanEval](https://github.com/openai/human-eval) \#33 (5 instances) + + ```python + def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]): + assert orig[::3] == li[::3], "Keep every third entry fixed" + assert sorted(li) == sorted(orig), "Not even a permutation" + assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3)) + assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3)) + return True + ``` +
0.01% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Start with a list of integers, keep every third element in place and otherwise sort the list + + Sample Input: + [8, 0, 7, 2, 9, 4, 1, 2, 8, 3] + + Sample Output: + [8, 0, 2, 2, 4, 8, 1, 8, 9, 3] + """ + ``` + Shortest Codex solution: + ```python + + li = orig.copy() + li[1], li[2], li[4], li[5], li[7], li[8], li[10], li[11] = sorted([li[1], li[2], li[4], li[5], li[7], li[8], li[10], li[11]]) + return li + + ``` + Longest Codex solution: + ```python + + finished = False + while not finished: + finished = True + for i in range(1, len(orig) - 2, 3): + if orig[i] > orig[i + 1]: + orig[i], orig[i + 1] = orig[i + 1], orig[i] + finished = False + for i in range(2, len(orig) - 3, 3): + if orig[i] > orig[i + 2]: + orig[i], orig[i + 2] = orig[i + 2], orig[i] + finished = False + return orig + + ``` + Hand-written solution: + ```python + n = len(orig) + your_list = orig[::3] + sub = orig[:] + for i in range(int((len(sub) + 2) / 3)): + sub.pop((2 * i)) + sub = sorted(sub) + answ = [] + for i in range(int(n / 3)): + answ.append(your_list[i]) + answ.append(sub[i * 2]) + answ.append(sub[i * 2 + 1]) + if n % 3 == 1: + answ.append(your_list[-1]) + if n % 3 == 2: + answ.append(your_list[-1]) + answ.append(sub[-1]) + return answ + ``` +
+ +* **EvaluateOperators** Inspired by [HumanEval](https://github.com/openai/human-eval) \#160 (5 instances) + + ```python + def sat(ops: List[str], target=2021, nums=[4, 6, 2, 1, 1, 3, 9]): + assert len(ops) == len(set(ops)) and set(ops) == {"**", "*", "+", "-", "//", "%"} + expr = str(nums[0]) + for n, op in zip(nums[1:], ops): + expr += op + str(n) + return eval(expr) == target + ``` +
0.0033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=2021, nums=[4, 6, 2, 1, 1, 3, 9]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target + + target=3, nums=[7, 2, 3, 4, 5, 1, 6] => ["+", "*", "**", "%", "//", "-"] + # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3 + """ + ``` + Codex solution: + ```python + + def combo(num_left, op_left): + if num_left == 0: + return [[]] + else: + result = [] + for i, op in enumerate(op_left): + for perm in combo(num_left - 1, op_left[:i] + op_left[i+1:]): + result.append([op] + perm) + return result + for ops in combo(len(nums) - 1, ["**", "*", "+", "-", "//", "%"]): + if sat(ops, nums=nums): + return ops + return None + + + ``` + Hand-written solution: + ```python + from itertools import permutations + for ops in permutations(["**", "*", "+", "-", "//", "%"]): + expr = str(nums[0]) + for n, op in zip(nums[1:], ops): + expr += op + str(n) try: - if j in outs: - k = min(outs[j].intersection(ins[i])) - return [i, j, k] - except ValueError: + if eval(expr) == target: + return list(ops) + except (ZeroDivisionError, SyntaxError): pass -``` - -
- -### PlantedClique -Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size -in an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for -some time. - -```python -def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): - """Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.""" - assert len(nodes) == len(set(nodes)) >= size - edge_set = {(a, b) for (a, b) in edges} - for a in nodes: - for b in nodes: - assert a == b or (a, b) in edge_set or (b, a) in edge_set - - return True -``` -
1 solution to graphs 4/12 - -```python -def sol(size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): # brute force (finds list in increasing order), but with a tiny bit of speedup - if size == 0: - return [] - from collections import defaultdict - neighbors = defaultdict(set) - n = max(max(e) for e in edges) - for (a, b) in edges: - if a != b: - neighbors[a].add(b) - neighbors[b].add(a) - pools = [list(range(n + 1))] - indices = [-1] - while pools: - indices[-1] += 1 - if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order - indices.pop() - pools.pop() - continue - if len(pools) == size: - return [pool[i] for pool, i in zip(pools, indices)] - a = (pools[-1])[indices[-1]] - pools.append([i for i in pools[-1] if i > a and i in neighbors[a]]) - indices.append(-1) - assert False, f"No clique of size {size}" -``` - -
- -### ShortestPath -Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm] - -```python -def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11): - """ - Find a path from node 0 to node 1, of length at most bound, in the given digraph. - weights[a][b] is weight on edge [a,b] for (int) nodes a, b - """ - return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound -``` -
1 solution to graphs 5/12 - -```python -def sol(weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11): # Dijkstra's algorithm (bound is ignored) - u, v = 0, 1 # go from 0 to 1 - import heapq - queue = [(0, u, u)] # distance, node, trail - - trails = {} - - while queue: - dist, i, j = heapq.heappop(queue) - if i in trails: - continue - trails[i] = j - if i == v: - break - for j in weights[i]: - if j not in trails: - heapq.heappush(queue, (dist + weights[i][j], j, i)) - if v in trails: - rev_path = [v] - while rev_path[-1] != u: - rev_path.append(trails[rev_path[-1]]) - return rev_path[::-1] -``` - -
- -### UnweightedShortestPath -Unweighted Shortest Path - -See (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm] - -```python -def sat(path: List[int], edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3): - """Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.""" - assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:])) - return len(path) <= bound -``` -
1 solution to graphs 6/12 - -```python -def sol(edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3): # Dijkstra's algorithm - import heapq - from collections import defaultdict - queue = [(0, u, u)] # distance, node, trail - - trails = {} - neighbors = defaultdict(set) - for (i, j) in edges: - neighbors[i].add(j) - - while queue: - dist, i, j = heapq.heappop(queue) - if i in trails: - continue - trails[i] = j - if i == v: - break - for j in neighbors[i]: - if j not in trails: - heapq.heappush(queue, (dist + 1, j, i)) - if v in trails: - rev_path = [v] - while rev_path[-1] != u: - rev_path.append(trails[rev_path[-1]]) - return rev_path[::-1] -``` - -
- -### AnyPath -Any Path - -```python -def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]): - """ Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.""" - for i in range(len(path) - 1): - assert [path[i], path[i + 1]] in edges - assert path[0] == 0 - assert path[-1] == max(max(edge) for edge in edges) - return True -``` -
1 solution to graphs 7/12 - -```python -def sol(edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]): - n = max(max(edge) for edge in edges) - paths = {0: [0]} - for _ in range(n + 1): - for i, j in edges: - if i in paths and j not in paths: - paths[j] = paths[i] + [j] - return paths.get(n) -``` - -
- -### EvenPath - - -```python -def sat(path: List[int], edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]): - """Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.""" - assert path[0] == 0 and path[-1] == max(max(e) for e in edges) - assert all([[a, b] in edges for a, b in zip(path, path[1:])]) - return len(path) % 2 == 0 -``` -
1 solution to graphs 8/12 - -```python -def sol(edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]): - even_paths = {} - odd_paths = {0: [0]} - n = max(max(e) for e in edges) - for _ in range(n + 1): - for i, j in edges: - if i in even_paths and j not in odd_paths: - odd_paths[j] = even_paths[i] + [j] - if i in odd_paths and j not in even_paths: - even_paths[j] = odd_paths[i] + [j] - return even_paths.get(n) -``` - -
- -### OddPath -To make it even more different than EvenPath, we changed to go from node 0 to node *1*. - -```python -def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]): - """Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.""" - return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])]) -``` -
1 solution to graphs 9/12 - -```python -def sol(edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]): - even_paths = {} - odd_paths = {0: [0]} - n = 1 - for _ in range(max(max(e) for e in edges) + 1): - for i, j in edges: - if i in even_paths and j not in odd_paths: - odd_paths[j] = even_paths[i] + [j] - if i in odd_paths and j not in even_paths: - even_paths[j] = odd_paths[i] + [j] - return odd_paths.get(n) -``` - -
+ assert False + ``` +
+ +* **SumProduct** Inspired by [HumanEval](https://github.com/openai/human-eval) \#8 (5 instances) + + ```python + def sat(nums: List[int], tot=14, prod=99): + assert sum(nums) == tot + p = 1 + for n in nums: + p *= n + return p == prod + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(tot=14, prod=99): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of numbers with a given sum and a given product. + + Sample Input: + 12, 32 + + Sample Output: + [2, 8, 2] + """ + ``` + Hand-written solution: + ```python + ans = [prod] + while sum(ans) > tot: + ans += [-1, -1] + ans += [1] * (tot - sum(ans)) + return ans + ``` +
+ +* **Fib4** Inspired by [HumanEval](https://github.com/openai/human-eval) \#46 + + Almost identical to problem 63 (5 instances) + + ```python + def sat(init: List[int], target=2021): + a, b, c, d = init + for i in range(99): + a, b, c, d = b, c, d, (a + b + c + d) + return a == target + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=2021): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous + four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the + given target number. + + Sample Input: + 0 + + Sample Output: + [0, 0, 0, 0] + """ + ``` + Hand-written solution: + ```python + nums = [target, 0, 0, 0] + for i in range(99): + x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3] + nums = [x] + nums[:3] + return nums + ``` +
+ +* **Fib3** Inspired by [HumanEval](https://github.com/openai/human-eval) \#63 + + Almost identical to problem 46 (5 instances) + + ```python + def sat(init: List[int], target=124156): + a, b, c = init + for i in range(16): + a, b, c = b, c, (a + b + c) + return a == target + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=124156): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous + three. Given a target number, find an initial triple such that the 17th number in the sequence is the + given target number. + + Sample Input: + 0 + + Sample Output: + [0, 0, 0] + """ + ``` + Hand-written solution: + ```python + nums = [target, 0, 0] + for i in range(16): + x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3] + nums = [x] + nums[:-1] + return nums + ``` +
+ +* **HeronTriangle** Inspired by [HumanEval](https://github.com/openai/human-eval) \#71 + + That problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides. + In our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates + of a triangle with the given sides. If one knows the area, this is a straightforward calculation. (5 instances) + + ```python + def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]): + assert len(coords) == 3 + sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]] + return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2))) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(sides=[8.9, 10.8, 17.0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the coordinates of a triangle with the given side lengths + + Sample Input: + [3.0, 4.0, 5.0 + + Sample Output: + [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]] + """ + ``` + Hand-written solution: + ```python + a, b, c = sorted(sides) + + s = sum(sides) / 2 # semi-perimeter + area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula + + y = 2 * area / a # height + x = (c ** 2 - y ** 2) ** 0.5 + return [[0.0, 0.0], [a, 0.0], [x, y]] + ``` +
+ +* **MinSubArraySum** Inspired by [HumanEval](https://github.com/openai/human-eval) \#114 + + This is harder than \#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes + while the O(n) algorithm takes milliseconds. (5 instances) + + ```python + def sat(start_end: List[int], base=7, p=50741, upper=-4897754): + start, end = start_end + return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(base=7, p=50741, upper=-4897754): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end] + + base=3, p=7, upper =-3 => [0, 3] + # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ... + """ + ``` + Hand-written solution: + ```python + tot = 0 + best_tot = 0 + best_end = 0 + best_start = 0 + largest_cumulative_sum = 0 + largest_cumulative_sum_index = 0 + + n = 1 + + for i in range(p + 1): + if tot > largest_cumulative_sum: + largest_cumulative_sum = tot + largest_cumulative_sum_index = i + if tot - largest_cumulative_sum < best_tot: + best_tot = tot - largest_cumulative_sum + best_start = largest_cumulative_sum_index + best_end = i + + tot += (n - p // 2) + n = (n * base) % p + + return [best_start, best_end] + ``` +
+ +## codeforces -### Zarankiewicz -[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem) +Problems inspired by the popular programming competition site [codeforces.com](https://codeforces.com) -```python -def sat(edges: List[List[int]]): - """Find a bipartite graph with 4 vertices on each side, 13 edges, and no K_3,3 subgraph.""" - assert len(edges) == len({(a, b) for a, b in edges}) == 13 # 13 edges, no duplicates - assert all(i in range(4) for li in edges for i in li) # 4 nodes on each side - for i in range(4): - v = [m for m in range(4) if m != i] - for j in range(4): - u = [m for m in range(4) if m != j] - if all([m, n] in edges for m in v for n in u): +* **EasySum** Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A) (5 instances) + + ```python + def sat(tot: int, nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17): + return tot == sum(1 if i < thresh else 2 for i in nums) + ``` +
73% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17): + ``` + Solution docstring (*not* usually provided) + + ```python + """Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold""" + ``` + Shortest Codex solution: + ```python + + return 12 + + ``` + Longest Codex solution: + ```python + + # My solve would be significantly longer than someone else's. + # In the process of calculating whichever of the n! solutions you want to examine, you have to + # perform 40*n*n matrix multiplications. So you spend a bunch of time figuring out which matrix + # multiplications to use but it never makes a difference which of the two square roots you use. + # Since opeartions have to be linear in time, this must have been a mistake + return sum((1 if i < thresh else 2) for i in nums) + + ``` + Hand-written solution: + ```python + return sum(1 if i < thresh else 2 for i in nums) + ``` +
+ +* **Dada** Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A) (5 instances) + + ```python + def sat(s: str, a=5129, d=17): + return s.count("a") == a and s.count("d") == d and len(s) == a + d + ``` +
72% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=5129, d=17): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with a given number of a's and d's""" + ``` + Shortest Codex solution: + ```python + + return "a"*a+"d"*d + ``` + Longest Codex solution: + ```python + + length = a + d + answer = ["a"]*a + ["d"]*d if d > a else ["d"]*d + ["a"]*a + index = 0 + while len(answer) < length: + if index < len(answer) and answer[index] == "a": + answer += ["a"] + index += 1 + elif index < len(answer) and answer[index] == "d": + answer += ["d"] + index += 1 + else: + answer += ["b"] + assert sat("".join(answer)) + return "".join(answer) + + ``` + Hand-written solution: + ```python + return "a" * a + "d" * d + ``` +
+ +* **IsEven** Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A) (5 instances) + + ```python + def sat(b: bool, n=10): + i = 0 + while i <= n: + if i + i == n: + return b == True + i += 1 + return b == False + ``` +
69% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """Determine if n can be evenly divided into two equal numbers. (Easy)""" + ``` + Shortest Codex solution: + ```python + + return True + ``` + Longest Codex solution: + ```python + + return n % 2 == 0 and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True and True + ``` + Hand-written solution: + ```python + return n % 2 == 0 + ``` +
+ +* **CapitalizeFirstLetter** Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A) (5 instances) + + ```python + def sat(s: str, word="konjac"): + for i in range(len(word)): + if i == 0: + if s[i] != word[i].upper(): + return False + else: + if s[i] != word[i]: + return False + return True + ``` +
66% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(word="konjac"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Capitalize the first letter of word""" + ``` + Shortest Codex solution: + ```python + + return "Konjac" + ``` + Longest Codex solution: + ```python + + s = "Konjac is the best exercize!" + if word == "konjac": + return "Konjac is the best exercize!"[:13] if s[0] == "K" else "Konjac is the best exercize!"[14:27] + else: + if word == "Konjac": + return s[:13] if s[0] == "K" else s[14:27] + else: + return "Konjac is the best exercize!"[:13] if s[0] == "K" else "Konjac is the best exercize!"[14:27] + ``` + Hand-written solution: + ```python + return word[0].upper() + word[1:] + ``` +
+ +* **CommonCase** Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A) + + This is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from + the problem (5 instances) + + ```python + def sat(s_case: str, s="CanYouTellIfItHASmoreCAPITALS"): + caps = 0 + for c in s: + if c != c.lower(): + caps += 1 + return s_case == (s.upper() if caps > len(s) // 2 else s.lower()) + ``` +
48% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="CanYouTellIfItHASmoreCAPITALS"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more + capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case. + """ + ``` + Shortest Codex solution: + ```python + + return s.upper() + ``` + Longest Codex solution: + ```python + + count_normal = 0 + count_caps = 0 + for c in s: + if c.isalpha(): + if c.isupper(): + count_caps += 1 + else: + count_normal += 1 + + # There are strictly more caps than normal characters + if count_caps > count_normal: + return s.upper() + + # There are strictly more normal than caps + elif count_normal > count_caps: + return s.lower() + + # Equal number of caps and normal, half or less: we return it lower: all lower cases + return s.lower() + + ``` + Hand-written solution: + ```python + caps = 0 + for c in s: + if c != c.lower(): + caps += 1 + return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for + ``` +
+ +* **MaybeReversed** Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A) (5 instances) + + ```python + def sat(s: str, target="reverse me", reverse=True): + return (s[::-1] == target) == reverse + ``` +
46% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="reverse me", reverse=True): + ``` + Solution docstring (*not* usually provided) + + ```python + """Either reverse a string or don't based on the reverse flag""" + ``` + Shortest Codex solution: + ```python + + return target[::-1] + ``` + Longest Codex solution: + ```python + + # NB: We use a non-default parameter value here, because this way we can + # call g6(...) with a dictionary as a parameter without having to pass the + # dictionary as keyword arguments. + return target[::-1] if reverse else target + ``` + Hand-written solution: + ```python + return target[::-1] if reverse else target + "x" + ``` +
+ +* **CompareInAnyCase** Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A) (5 instances) + + ```python + def sat(n: int, s="aaAab", t="aAaaB"): + if n == 0: + return s.lower() == t.lower() + if n == 1: + return s.lower() > t.lower() + if n == -1: + return s.lower() < t.lower() + return False + ``` +
46% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="aaAab", t="aAaaB"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.""" + ``` + Shortest Codex solution: + ```python + + return 0 + ``` + Longest Codex solution: + ```python + + return [0, -1, 1][["a", "A", "b", "B"].index(s[0] if s[0] in ["a", "A"] else s[0].lower()) - \ + ["a", "A"].index(t[0] if t[0] in ["a", "A"] else t[0].lower())] + + ``` + Hand-written solution: + ```python + if s.lower() == t.lower(): + return 0 + if s.lower() > t.lower(): + return 1 + return -1 + ``` +
+ +* **GimmeChars** Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy (5 instances) + + ```python + def sat(s: str, chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']): + for c in chars: + if c not in s: + return False + return True + ``` +
40% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with certain characters""" + ``` + Shortest Codex solution: + ```python + + return str(chars) + + ``` + Longest Codex solution: + ```python + + while True: + for i in range(0, 1000000): + s = "h" + for j in range(6, 0, -1): + s += str(j) + s += "e" + s += "l" + s += "l" + s += "o" + s += " " + s += "w" + s += "o" + s += "r" + s += "l" + s += "d" + s += "!" + s += str(i) + if sat(s, chars): + return s + + ``` +
+ +* **FivePowers** Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A) (5 instances) + + ```python + def sat(s: str, n=7012): + return int(str(5 ** n)[:-2] + s) == 5 ** n + ``` +
30% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=7012): + ``` + Solution docstring (*not* usually provided) + + ```python + """What are the last two digits of 5^n?""" + ``` + Shortest Codex solution: + ```python + + return "25" + + ``` + Longest Codex solution: + ```python + + res = "" + for i in range(n % 100, 100): + try: + if int(str(5 ** (n % 100))[:-2] + str(i)) == 5 ** (n % 100): + res = str(i) + break + except ValueError: + pass + return res + + ``` + Hand-written solution: + ```python + return ("1" if n == 0 else "5" if n == 1 else "25") + ``` +
+ +* **DecreasingCountComparison** Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A) (5 instances) + + ```python + def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6): + assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), "Hint: scores are non-decreasing" + return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:]) + ``` +
30% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list + are at least as large as the kth. + """ + ``` + Shortest Codex solution: + ```python + + return 8 + + ``` + Longest Codex solution: + ```python + + return len([x for x in scores if x >= scores[k]]) # Hint: think about the number of occurences of a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a number a fixed a + ``` + Hand-written solution: + ```python + threshold = max(scores[k], 1) + return sum(s >= threshold for s in scores) + ``` +
+ +* **InvertIndices** Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A) (5 instances) + + ```python + def sat(indexes: List[int], target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]): + for i in range(1, len(target) + 1): + if target[indexes[i - 1] - 1] != i: return False - return True -``` -
1 solution to graphs 10/12 - -```python -def sol(): - return [[i, j] for i in range(4) for j in range(4) if i != j or i == 0] -``` - -
- -### GraphIsomorphism -The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem. -It is unknown whether or not there exists a polynomial-time algorithm -for this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai. - -The classic version is a decision problem: given two graphs, determine whether or not they are isomorphic. -However, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you -could solve the search problem below (finding the actual bijection), then you can decide isomorphism because the -search solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem, -then you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node -in the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to -itself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph. -For each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps -the first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not -allowed, one can do this by adding N additional nodes for each test. - -```python -def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]): - """ - You are given two graphs which are permutations of one another and the goal is to find the permutation. - Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers. - """ - return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2} -``` -
1 solution to graphs 11/12 - -```python -def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]): # exponentially slow - from itertools import permutations - n = max(i for g in [g1, g2] for e in g for i in e) + 1 - g1_set = {(i, j) for i, j in g1} - for pi in permutations(range(n)): - if all((pi[i], pi[j]) in g1_set for i, j in g2): - return list(pi) - assert False, f"Graphs are not isomorphic {g1}, {g2}" -``` - -
- -### ShortIntegerPath -This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph -defined by the integer pairs. - -```python -def sat(li: List[int]): - """ - Find a list of nine integers, starting with 0 and ending with 128, such that each integer either differs from - the previous one by one or is thrice the previous one. - """ - return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) and len(li) == 9 -``` -
1 solution to graphs 12/12 - -```python -def sol(): - return [1, 3, 4, 12, 13, 14, 42, 126, 127] -``` - -
- -## ICPC - - -Problems inspired by the [International Collegiate Programming Contest](https://icpc.global) (ICPC). - - -### BiPermutations -Inspired by -[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) -which is 2,287 characters. - -```python -def sat(perms: List[List[int]], prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]): - """ - There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each - row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and - so that the first row is taller than the second row. - """ - n = len(prices0) - perm0, perm1 = perms - assert sorted(perm0) == sorted(perm1) == list(range(n)), "Solution must be two permutations" - for i in range(n - 1): - assert prices0[perm0[i]] <= prices0[perm0[i + 1]], "Permuted prices must be nondecreasing (row 0)" - assert prices1[perm1[i]] <= prices1[perm1[i + 1]], "Permuted prices must be nondecreasing (row 1)" - return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1)) -``` -
1 solution to ICPC 1/4 - -```python -def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]): - n = len(prices0) - prices = [prices0, prices1] - orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])), - sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))] - jumps = [1, 1] # next price increase locations - for i in range(n): - for r, (p, o) in enumerate(zip(prices, orders)): - while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]: - jumps[r] += 1 - - to_fix = orders[jumps[0] < jumps[1]] - j = i - while heights0[orders[0][i]] <= heights1[orders[1][i]]: - j += 1 - to_fix[i], to_fix[j] = to_fix[j], to_fix[i] - - return orders -``` - -
- -### OptimalBridges -Inspired by -[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) -which is 3,003 characters. - -```python -def sat(indices: List[int], H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020): - """ - You are to choose locations for bridge bases from among a given set of mountain peaks located at - `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted - list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges - are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that: - * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs - of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the - selected mountain peaks must both be at most `H - d/2`. - * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the - peak. See the code for how this is determined mathematically. - * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of - all pillar heights) + beta * (the sum of the squared diameters) - """ - assert sorted({0, len(xs) - 1, *indices}) == indices, f"Ans. should be sorted list [0, ..., {len(xs) - 1}]" - cost = alpha * (H - ys[0]) - for i, j in zip(indices, indices[1:]): - a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2 - assert max(ys[i], ys[j]) + r <= H, "Bridge too tall" - assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \ - "Bridge too short" - cost += alpha * (H - ys[j]) + beta * (b - a) ** 2 - return cost <= thresh -``` -
1 solution to ICPC 2/4 - -```python -def sol(H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020): # thresh is ignored - n = len(xs) - cost = [-1] * n - prior = [n] * n - cost[0] = beta * (H - ys[0]) - for i in range(n): - if cost[i] == -1: - continue - min_d = 0 - max_d = 2 * (H - ys[i]) - for j in range(i + 1, n): - d = xs[j] - xs[i] - h = H - ys[j] - if d > max_d: + return True + ``` +
27% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Given a list of integers representing a permutation, invert the permutation.""" + ``` + Shortest Codex solution: + ```python + + return [target.index(x)+1 for x in sorted(target)] + + ``` + Longest Codex solution: + ```python + + reachedTarget = False # we don't know that we've reached the target yet + i = 2 # the next index to check + indexes = [1] # indexes[1] is the first position in the target permutation + while not reachedTarget: + if i in target: + indexes.append(target.index(i) + 1) # we've found a match + if len(indexes) == len(target): # ...if we've reached the target nubmer + reachedTarget = True + else: + indexes.append(i) + i = i + 1 + return indexes + + ``` +
+ +* **RepeatDec** Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A) (5 instances) + + ```python + def sat(res: int, m=1234578987654321, n=4): + for i in range(n): + m = (m - 1 if m % 10 else m // 10) + return res == m + ``` +
23% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=1234578987654321, n=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove + the zero, otherwise subtract 1. + """ + ``` + Shortest Codex solution: + ```python + + for i in range(n): m = (m - 1 if m % 10 else m // 10) + return m + + ``` + Longest Codex solution: + ```python + + memo = dict() + try: + while n: + if (m, n) not in memo: + memo[(m, n)] = (m - 1 if m % 10 else m // 10) + m = memo[(m, n)] + n -= 1 + return m + except TypeError: + while n: + if (m, n) not in memo: + m, memo[(m, n)] = (m - 1 if m % 10 else m // 10), m + m = memo[(m, n)] + n -= 1 + return m + + ``` + Hand-written solution: + ```python + for i in range(n): + m = (m - 1 if m % 10 else m // 10) + return m + ``` +
+ +* **Count47** Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A) (5 instances) + + ```python + def sat(d: int, n=123456789): + return d > n and all(i in "47" for i in str(str(d).count("4") + str(d).count("7"))) + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=123456789): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation + consists only of 4's and 7's + """ + ``` + Shortest Codex solution: + ```python + + return 7**18 + + ``` + Longest Codex solution: + ```python + + current = n + # All numbers for our for loop should be larger than 9 because we no longer need to run this for loop for + # numbers less than nine because they are excluded by the string.count operation + while not sat(current): + # The one after the current number shouldn't be smaller than the current number. + # For example, the initial number is 9. So, after running this for loop, the value of current should be + # greater than that number to make sure that it doesn't end up for the next iteration. + current += max(1, current // 10) + return current + + ``` + Hand-written solution: + ```python + return int("4444" + "0" * (len(str(n)) - 3)) + ``` +
+ +* **EasyTwos** Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A) (5 instances) + + ```python + def sat(lb: List[bool], trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]): + return len(lb) == len(trips) and all( + (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips)) + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of lists of triples of integers, return True for each list with a total of at least 2 and + False for each other list. + """ + ``` + Shortest Codex solution: + ```python + + return [sum(s)>=2 for s in trips] + + ``` + Longest Codex solution: + ```python + + result = [] + for trip in trips: + for i in range(3): + if trip[i] == 1: + trip[i] = True + else: + trip[i] = False + num = 0 + for i in range(3): + if trip[i]: + num += sum(trip[0:i]) + num += sum(trip[i+1:]) + if num >= 2: + result.append(True) + else: + result.append(False) + return result + + ``` + Hand-written solution: + ```python + return [sum(s) >= 2 for s in trips] + ``` +
+ +* **FindHomogeneousSubstring** Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A) (5 instances) + + ```python + def sat(n: int, s="0000101111111000010", k=5): + return s[n:n + k] == s[n] * k + ``` +
18% Codex success rate, 4 hand-written solutions + + Solution header: + ```python + def sol(s="0000101111111000010", k=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are + all 0's or all 1's. + + Sample Input: + s = 0000111111100000, k = 5 + + Sample Output: + 4 + (or 5 or 6 or 11) + """ + ``` + Shortest Codex solution: + ```python + + return 7 + + ``` + Longest Codex solution: + ```python + + s = s.strip() + n = len(s) + # Find the index that the proceeding character is the only character that starts with this character. + # If that index is before the end of the array, then return that index. Otherwise, return the index of the + # end of the array. + # In the example, [3:3+5] = [3:8). It's clear the proceeding characters are all 1's, starting from index 3. + return next((i for i in range(n - k - 1, -1, -1) if s[i:i + k] == s[i] * k), 0) + + + ``` + Hand-written solution: + ```python + return s.index("0" * k if "0" * k in s else "1" * k) + ``` + Hand-written solution: + ```python + import re + return re.search(r"([01])\1{" + str(k - 1) + "}", s).span()[0] + ``` + Hand-written solution: + ```python + if "0" * k in s: + return s.index("0" * k) + else: + return s.index("1" * k) + ``` + Hand-written solution: + ```python + try: + return s.index("0" * k) + except: + return s.index("1" * k) + ``` +
+ +* **Abbreviate** Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A) (5 instances) + + ```python + def sat(s: str, word="antidisestablishmentarianism", max_len=10): + if len(word) <= max_len: + return word == s + return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1] + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(word="antidisestablishmentarianism", max_len=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Abbreviate strings longer than a given length by replacing everything but the first and last characters by + an integer indicating how many characters there were in between them. + """ + ``` + Shortest Codex solution: + ```python + + return word[0]+str(len(word)-2)+word[-1] + + ``` + Longest Codex solution: + ```python + + + # Calculate the maximum acceptable length. + min_len = min(max_len, len(word)) + max_len = min_len + 1 + + # Return the given string if it fits within the maximum length. + if len(word) <= max_len: + return word + + # Abbreviate the given string by replacing all characters within the minimum and maximum lengths. + return "{0}{1}{2}".format(word[0], len(word[1:-1]), word[-1]) + + ``` + Hand-written solution: + ```python + if len(word) <= max_len: + return word + return f"{word[0]}{len(word) - 2}{word[-1]}" + ``` +
+ +* **SortPlusPlus** Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A) (5 instances) + + ```python + def sat(s: str, inp="1+1+3+1+3+2+2+1+3+1+2"): + return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2)) + ``` +
15% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(inp="1+1+3+1+3+2+2+1+3+1+2"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3""" + ``` + Shortest Codex solution: + ```python + + return inp[1:] + inp[:1] + + ``` + Longest Codex solution: + ```python + + s = inp + "" + while not sat(s, inp): + last = None + for i in range(len(s)): + if s[i] != last: + last = s[i] + for j in range(i + 1, len(s)): + if s[j] != last: + if s[i] > s[j]: + temp = s[i] + s = s[:i] + s[j] + s[i+1:j] + temp + s[j+1:] + break + return s + + ``` + Hand-written solution: + ```python + return "+".join(sorted(inp.split("+"))) + ``` +
+ +* **DistinctDigits** Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A) (5 instances) + + ```python + def sat(nums: List[int], a=100, b=1000, count=648): + assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums) + return len(set(nums)) >= count + ``` +
14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=100, b=1000, count=648): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of count or more different numbers each between a and b that each have no repeated digits""" + ``` + Shortest Codex solution: + ```python + + return [n for n in range(a,b) if len(str(n))==len(set(str(n)))] + + ``` + Longest Codex solution: + ```python + + while True: + nums = [] + if len(str(a)) * count >= b-a+1: + for n in range(a, b+1): + if len(str(n)) == len(set(str(n))): + nums.append(n) + if len(nums) >= count: + break + return nums + else: + for n in range(a, b+1): + if len(str(n)) == len(set(str(n))): + nums.append(n) + if len(nums) >= count: + break + + ``` + Hand-written solution: + ```python + return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))] + ``` +
+ +* **MaxConsecutiveSum** Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) (5 instances) + + ```python + def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]): + return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower + ``` +
13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a sequence of k consecutive indices whose sum is maximal""" + ``` + Shortest Codex solution: + ```python + + return k + + ``` + Longest Codex solution: + ```python + + start = 0 + max_sum = 0 + while True: + if sat(start, k, lower, seq): + if sum(seq[start:start + k]) >= max_sum: + max_sum = sum(seq[start:start + k]) + idx = start + start += k + else: + start += 1 + if start == len(seq) - k: + break + else: + start += 1 + if start == len(seq) - k: + break + return idx + + ``` + Hand-written solution: + ```python + return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k])) + ``` +
+ +* **TripleDouble** Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A) (5 instances) + + ```python + def sat(n: int, v=17, w=100): + for i in range(n): + assert v <= w + v *= 3 + w *= 2 + return v > w + ``` +
11% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(v=17, w=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.""" + ``` + Shortest Codex solution: + ```python + + return 5 + + ``` + Longest Codex solution: + ```python + + def test(n): + return sat(n, v, w) + count = 0 + n = 0 + while True: + if test(n): + return n + n += 1 + if count > 1000: + raise ValueError("Test failed 1000 times in a row.") + if test(n): + count += 1 + if count > 1000: + raise ValueError("Test failed 1000 times in a row.") + else: + count = 0 + + ``` + Hand-written solution: + ```python + i = 0 + while v <= w: + v *= 3 + w *= 2 + i += 1 + return i + ``` +
+ +* **Factor47** Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A) (5 instances) + + ```python + def sat(d: int, n=6002685529): + return n % d == 0 and all(i in "47" for i in str(d)) + ``` +
9.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=6002685529): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a integer factor of n whose decimal representation consists only of 7's and 4's.""" + ``` + Shortest Codex solution: + ```python + + return int(n**0.5) + ``` + Longest Codex solution: + ```python + + # For each integer d starting at 27... + for d in range(27, max(n+1, 10), 2): + # Check if d is a factor of n. + if n % d == 0: + # Check if d is a special factor since its decimal representation would consist of 7's and 4's. + if sat(d, n): + # Return d if it qualifies. + return d + # If this point is reached, it's impossible to find a special factor for n. + # Return None instead of a string. + return None + + ``` + Hand-written solution: + ```python + def helper(so_far, k): + if k > 0: + return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1) + return (n % so_far == 0) and so_far + + for length in range(1, len(str(n)) // 2 + 2): + ans = helper(0, length) + if ans: + return ans + ``` +
+ +* **SquareTiles** Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A) (5 instances) + + ```python + def sat(corners: List[List[int]], m=10, n=9, a=5, target=4): + covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)} + assert len(covered) == len(corners) * a * a, "Double coverage" + return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)}) + ``` +
9.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=10, n=9, a=5, target=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a minimal list of corner locations for a×a tiles that covers [0, m] × [0, n] and does not double-cover + squares. + + Sample Input: + m = 10 + n = 9 + a = 5 + target = 4 + + Sample Output: + [[0, 0], [0, 5], [5, 0], [5, 5]] + """ + ``` + Shortest Codex solution: + ```python + + return [[0,0],[0,5],[5,0],[5,5]] + + ``` + Longest Codex solution: + ```python + + corners = [[0, 0], [0, 5], [5, 0], [5, 5]] + while len(corners) < target: + for i in range(-a, a): + for j in range(-a, a): + if (i, j) not in corners+map(lambda c: [c[0]-a, c[1]-a], corners) and g6(m, n, a, target, i=i, j=j, + corners=corners): + corners.append([i, j]) + break + else: + continue + break + return corners + + + ``` + Hand-written solution: + ```python + return [[x, y] for x in range(0, m, a) for y in range(0, n, a)] + ``` +
+ +* **TotalDifference** Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A) (5 instances) + + ```python + def sat(n: int, a=17, b=100, c=20): + return n + a == sum([b * i for i in range(c)]) + ``` +
9.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=17, b=100, c=20): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that n + a == b * (the sum of the first c integers)""" + ``` + Shortest Codex solution: + ```python + + return c*(c-1)//2*b - a + + ``` + Longest Codex solution: + ```python + + return -a + sum([b * i for i in range(c)]) + + ``` + Hand-written solution: + ```python + return -a + sum([b * i for i in range(c)]) + ``` +
+ +* **MinConsecutiveSum** Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) (5 instances) + + ```python + def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]): + return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper + ``` +
7.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a sequence of k consecutive indices whose sum is minimal""" + ``` + Shortest Codex solution: + ```python + + return 2 ** k + + ``` + Longest Codex solution: + ```python + + lowest = 0 # lower bound of the search space + highest = len(seq) - k # upper bound of the search space + + current_min = sum(seq[:k]) + answer = 0 + + while lowest <= highest: # as long as the search space is not exhausted + current_sum = sum(seq[lowest:lowest+k]) + if current_sum <= current_min: # the current sum is smaller than the minimum sum so far + answer = lowest # update the answer + current_min = current_sum # update the current minimum sum + lowest += 1 # move the lower bound + + return answer + ``` + Hand-written solution: + ```python + return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k])) + ``` +
+ +* **VowelDrop** Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A) (5 instances) + + ```python + def sat(t: str, s="Problems"): + i = 0 + for c in s.lower(): + if c in "aeiouy": + continue + assert t[i] == ".", f"expecting `.` at position {i}" + i += 1 + assert t[i] == c, f"expecting `{c}`" + i += 1 + return i == len(t) + ``` +
7.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="Problems"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a "." before each remaining letter + (consonant), and make everything lowercase. + + Sample Input: + s = "Problems" + + Sample Output: + .p.r.b.l.m.s + """ + ``` + Shortest Codex solution: + ```python + + return ".p.r.b.l.m.s" + ``` + Longest Codex solution: + ```python + + # clean up my string + s = s.lower() # they're all lower case + s = s.replace("aeiouy", "") # remove vowels + s = s.replace("aeiouy", "") # remove vowels (wtf python, the second one is the syntax error) + s = s.replace("AEIOUY", "") # remove vowels (wtf python, the second one is the syntax error) + result = "" + for c in s: + if c not in "aeiouy": # leave consonants as is + result += "." + c + return result + + ``` + Hand-written solution: + ```python + return "".join("." + c for c in s.lower() if c not in "aeiouy") + ``` +
+ +* **MaxConsecutiveProduct** Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B) (5 instances) + + ```python + def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]): + prod = 1 + for i in range(start, start + k): + prod *= seq[i] + return prod >= lower + ``` +
7.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a sequence of k consecutive indices whose product is maximal, possibly looping around""" + ``` + Shortest Codex solution: + ```python + + return 3 + + ``` + Longest Codex solution: + ```python + + prod = 1 + for i in range(k): + prod *= seq[i] + for start in range(len(seq) - 3): + prod /= seq[start] + while start + k < len(seq): + prod *= seq[start + k] + if prod >= lower: + return start + prod /= seq[start - 1] + start += 1 + prod *= seq[start - 1] + while prod >= lower: + if sat(start, k, lower, seq): + return start + prod /= seq[start - 1] + start += 1 + prod + ``` + Hand-written solution: + ```python + def prod(start): + ans = 1 + for i in range(start, start + k): + ans *= seq[i] + return ans + + return max(range(-len(seq), len(seq) - k + 1), key=prod) + ``` +
+ +* **Triple0** Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A) (5 instances) + + ```python + def sat(delta: List[int], nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]): + return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3)) + ``` +
3.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the missing triple of integers to make them all add up to 0 coordinatewise""" + ``` + Shortest Codex solution: + ```python + + return [-sum(x) for x in zip(*nums)] + ``` + Longest Codex solution: + ```python + + length = max(map(len, nums)) # length of longest vector + nums = [[_f for _f in _g + [0]] for _g in nums] # pad vector with 0s of length + nums = [[_f for _f in _g if _f != 0] for _g in nums] # remove zero vectors + delta = [0]*3 + for i in range(len(nums[0])): + s = 0 + for j in range(3): + s += nums[j][i] + delta[i] = -s + return delta + + + ``` + Hand-written solution: + ```python + return [-sum(vec[i] for vec in nums) for i in range(3)] + ``` +
+ +* **HalfPairs** Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A) (4 instances) + + ```python + def sat(ans: List[List[int]], target=17): + for i in range(len(ans)): + a, b = ans[i] + if b - a >= 2: + target -= 1 + return target == 0 + ``` +
2.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=17): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of pairs of integers where the number of pairs in which the second number is more than + two greater than the first number is a given constant + """ + ``` + Shortest Codex solution: + ```python + + return [[0, 17]]*target + + ``` + Longest Codex solution: + ```python + + ans = [] + for i in range(2, target + 1): + if i % 2 == 1: + for j in range(2, target + 1): + if i * j <= target: + a = i * j + b = a - i + 1 + if a <= target and b <= target: + ans.append([b, a]) + else: + for j in range(1, target + 1): + a = i * j + j + b = a - i + 1 + if a <= target and b <= target: + ans.append([b, a]) + return sorted(ans) + + ``` + Hand-written solution: + ```python + return [[0, 2]] * target + ``` +
+ +* **MaxDelta** Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A) (5 instances) + + ```python + def sat(n: int, pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]): + assert sum(p - m for p, m in pairs) == 0, "oo" + tot = 0 + success = False + for p, m in pairs: + tot -= m + tot += p + assert tot <= n + if tot == n: + success = True + return success + ``` +
2.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a sequence of integer pairs, p_i, m_i, where \sum p_i-m_i = 0, find the maximum value, over t, of + p_{t+1} + \sum_{i=1}^t p_i - m_i + """ + ``` + Shortest Codex solution: + ```python + + return 9254359 + + ``` + Longest Codex solution: + ```python + + m = 0 + tot = 0 + for p, _ in pairs: + if p > m: m = p + for i, (p, _) in enumerate(pairs): + tot += m - p + if tot == m or tot == m-1: + tot = 0 + else: break - if 2 * h <= d: - min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5)) - max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5)) - if min_d > max_d: + if tot == 0: + for j, (p, _) in enumerate(pairs): + for i in range(j): + tot += p + if tot == m or tot == m-1: + tot = 0 + else: + break + return m + + ``` + Hand-written solution: + ```python + tot = 0 + n = 0 + for p, m in pairs: + tot += p - m + if tot > n: + n = tot + return n + ``` +
+ +* **InvertPermutation** Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A) (5 instances) + + ```python + def sat(s: str, perm="qwertyuiopasdfghjklzxcvbnm", target="hello are you there?"): + return "".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target + ``` +
2.6% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(perm="qwertyuiopasdfghjklzxcvbnm", target="hello are you there?"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that, when a given permutation of characters is applied, has a given result.""" + ``` + Shortest Codex solution: + ```python + + return target.translate(str.maketrans(perm[1:] + perm[0], perm)) + + ``` + Longest Codex solution: + ```python + + result = "".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in target) + while result != target: + new_result = "".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in result) + if new_result == target: + return result + result = new_result + return result + + ``` + Hand-written solution: + ```python + return "".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target) + ``` +
+ +* **IncDec** Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A) + + This straightforward problem is a little harder than the Codeforces one. (5 instances) + + ```python + def sat(n: int, ops=['x++', '--x', '--x'], target=19143212): + for op in ops: + if op in ["++x", "x++"]: + n += 1 + else: + assert op in ["--x", "x--"] + n -= 1 + return n == target + ``` +
1.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(ops=['x++', '--x', '--x'], target=19143212): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a sequence of operations "++x", "x++", "--x", "x--", and a target value, find initial value so that the + final value is the target value. + + Sample Input: + ops = ["x++", "--x", "--x"] + target = 12 + + Sample Output: + 13 + """ + ``` + Shortest Codex solution: + ```python + + return 19143213 + + ``` + Longest Codex solution: + ```python + + # Find end of loop by iterating the op list + state = "" + for op in ops: + if op in ["++x", "x++"]: + state += "+" + elif op in ["--x", "x--"]: + state += "-" + else: + raise ValueError("Invalid op code.") + assert state[-1] == '-' + # Find initial value of x by working backwards from target + x = target + for char in state[::-1]: + if char == "+": + x -= 1 + else: + x += 1 + return x + + ``` + Hand-written solution: + ```python + return target - ops.count("++x") - ops.count("x++") + ops.count("--x") + ops.count("x--") + ``` +
+ +* **LongestSubsetString** Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A) (5 instances) + + ```python + def sat(t: str, s="abbbcabbac", target=7): + i = 0 + for c in t: + while c != s[i]: + i += 1 + i += 1 + return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1)) + ``` +
0.57% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="abbbcabbac", target=7): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated + consecutive characters. + + Sample Input: + `"abbbc"` + + Sample Output: + `"abc"` + """ + ``` + Shortest Codex solution: + ```python + + return "".join(c for i, c in enumerate(s) if c != s[i - 1]) + ``` + Longest Codex solution: + ```python + + # Write your code here + s = list(s) + state = None + out = [] + last = None + for x in s: + if x != last: + out.append(x) + last = x + if state is not None: + if state: + state = None + else: + state = not state + elif state is not None: + state = not state + return "".join(out) + + ``` + Hand-written solution: + ```python + # target is ignored + return s[:1] + "".join([b for a, b in zip(s, s[1:]) if b != a]) + ``` +
+ +* **ShortestDecDelta** Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A) (5 instances) + + ```python + def sat(li: List[int], n=149432, upper=14943): + return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n])) + ``` +
0.34% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=149432, upper=14943): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a the shortest sequence of integers going from 1 to n where each difference is at most 10. + Do not include 1 or n in the sequence. + """ + ``` + Shortest Codex solution: + ```python + + return list(range(2, n, 10)) + + ``` + Longest Codex solution: + ```python + + li = [] + while True: + if len(li) >= upper: break - if min_d <= d <= max_d: - new_cost = cost[i] + alpha * h + beta * d * d - if cost[j] == -1 or cost[j] > new_cost: - cost[j] = new_cost - prior[j] = i - rev_ans = [n - 1] - while rev_ans[-1] != 0: - rev_ans.append(prior[rev_ans[-1]]) - return rev_ans[::-1] -``` - -
- -### CheckersPosition -Inspired by -[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) - -Nobody solved this problem during the competition -- it is pretty difficult! - -```python -def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]): - """ - You are given a partial transcript a checkers game. Find an initial position such that the transcript - would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even. - There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript. - The initial position is represented as a list [x, y, piece] where piece means: - * 0 is empty square - * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively - * 2 or -2 is king for player 1 or player 2 respectively - - Additional rules: - * You must jump if you can, and you must continue jumping until one can't any longer. - * You cannot start the position with any non-kings on your last rank. - * Promotion happens after the turn ends - """ - board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty - for x, y, p in position: - assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king - board[x, y] = p - - def has_a_jump(x, y): - p = board[x, y] # piece to move - deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings - return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas) - - sign = 1 # player 1 moves first - for move in transcript: - start, end = tuple(move[0]), tuple(move[-1]) - p = board[start] # piece to move - assert p * sign > 0, "Moving square must be non-empty and players must be alternate signs" - assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), "Moved to an occupied square" - - for (x1, y1), (x2, y2) in zip(move, move[1:]): - assert abs(p) != 1 or (y2 - y1) * p > 0, "Non-kings can only move forward (in direction of sign)" - if abs(x2 - x1) == 1: # non-jump - assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), "Must make a jump if possible" + last = len(li) and li[-1] or 1 + if last + 10 <= n: + li.append(last + 10) + elif last - 10 >= 2: + li.append(last - 10) + else: break - mid = ((x1 + x2) // 2, (y1 + y2) // 2) - assert board[mid] * p < 0, "Can only jump over piece of opposite sign" - board[mid] = 0 - board[start], board[end] = 0, p - assert abs(x2 - x1) == 1 or not has_a_jump(*end) - if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]): - board[end] *= 2 # king me at the end of turn after any jumps are done! - sign *= -1 - - return True -``` -
1 solution to ICPC 3/4 - -```python -def sol(transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]): - START_PLAYER = 1 # assumed - - class InitOpts: - def __init__(self, x, y): - self.x, self.y = x, y - self.opts = {-2, -1, 0, 1, 2} - if y == 0: - self.opts.remove(-1) - if y == 7: - self.opts.remove(1) - self.promoted = 2 ** 63 # on which step was it promoted t >= 0 - self.jumped = 2 ** 63 # on which step was it jumped t >= 0 - - # def board2str(board): # for debugging - # mapping = ".bBWw" - # ans = "" - # for y in range(7, -1, -1): - # ans += "".join(" " if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + "\n" - # return ans - - init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0} - # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if - # (x + y) % 2 == 0} # new board - - transcript = [[tuple(a) for a in move] for move in transcript] - - permuted_opts = init_opts.copy() - sign = START_PLAYER - for t, move in enumerate(transcript): - start, end = tuple(move[0]), tuple(move[-1]) - p = permuted_opts[start] # opts to move - assert p.jumped >= t - p.opts -= {-sign, -2 * sign, 0} - if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move! - if p.promoted >= t: - p.opts -= {sign} # must be a king! - - for a, b in zip(move, move[1:]): - if permuted_opts[b].jumped >= t: - permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty - assert permuted_opts[a].jumped >= t - permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a] - # board[a], board[b] = board[b], board[a] - (x1, y1), (x2, y2) = a, b - if abs(x2 - x1) == 2: # jump - mid = ((x1 + x2) // 2, (y1 + y2) // 2) - assert permuted_opts[mid].jumped >= t - permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign - permuted_opts[mid].jumped = t - # board[mid] = 0 - - if any(y in {0, 7} for x, y in move[1:]): - if p.promoted > t: - p.promoted = t - # if abs(board[x2, y2]) == 1: - # board[x2, y2] *= 2 - - sign *= -1 - - for y in range(7, -1, -1): - for x in range(8): - if (x, y) in init_opts: - s = init_opts[x, y].opts - if {1, 2} <= s: - s.remove(2) - if {-1, -2} <= s: - s.remove(-2) - - def helper(): # returns True if success and store everything, otherwise None - my_opts = init_opts.copy() - sign = START_PLAYER # player 1 always starts - - for t, move in enumerate(transcript): - if abs(move[0][0] - move[1][0]) == 1: # not a jump - check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}] + return li + + ``` + Hand-written solution: + ```python + m = 1 + ans = [] + while True: + m = min(n, m + 10) + if m >= n: + return ans + ans.append(m) + ``` +
+ +* **OnesAndTwos** Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A) (5 instances) + + ```python + def sat(seq: List[int], n=10000, length=5017): + return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length + ``` +
0.32% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=10000, length=5017): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a sequence of 1's and 2's of a given length that that adds up to n""" + ``` + Shortest Codex solution: + ```python + + return [1]*(length - n%length) + [2]*(n%length) + + ``` + Longest Codex solution: + ```python + + seq = [1] * length + while sum(seq) < n: + i = 0 + while i < len(seq) and seq[i] == 2: + i += 1 + if i < len(seq): + seq[i] = 2 + while len(seq) > length: + k = 1 + while k < len(seq) and seq[-k] == 2: + k += 1 + while k > 0 and seq[-k + 1] == 1: + k -= 1 + if k > 0: + seq.pop(-k) else: - for a, b in zip(move, move[1:]): - my_opts[a], my_opts[b] = my_opts[b], my_opts[a] - check_no_jumps = [b] - - for x, y in check_no_jumps: - p = my_opts[x, y] - [o] = p.opts - assert o * sign > 0 - dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps - for dx in [-1, 1]: - for dy in dys: - target_o = my_opts.get((x + 2 * dx, y + 2 * dy)) - if target_o is not None and (0 in target_o.opts or target_o.jumped < t): - mid_o = my_opts[x + dx, y + dy] - if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t - if target_o.jumped < t or target_o.opts == {0}: - return False - old_opts = target_o.opts - for v in target_o.opts: - if v != 0: - target_o.opts = {v} - h = helper() - if h: - return True - target_o.opts = old_opts - return False - - if abs(move[0][0] - move[1][0]) == 1: # not a jump - a, b = move[0], move[1] - my_opts[a], my_opts[b] = my_opts[b], my_opts[a] - - sign *= -1 + return seq + return seq + ``` + Hand-written solution: + ```python + return [2] * (n - length) + [1] * (2 * length - n) + ``` +
+ +* **Moving0s** Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B) (5 instances) + + ```python + def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4): + s = seq[:] # copy + for step in range(n_steps): + for i in range(len(seq) - 1): + if (s[i], s[i + 1]) == (0, 1): + (s[i], s[i + 1]) = (1, 0) + return s == target + ``` +
0.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence + is achieved. + """ + ``` + Shortest Codex solution: + ```python + + return [1,1,0,0,0,0,1,1,0,0,0,1,1] + ``` + Longest Codex solution: + ```python + + # n_steps is the number of periods in the targeted binary-periodic sequence. + # For each period, we have n_bits bits. + n_bits = len(target) + # With one period, we start with all 0's. + bits = [0] * n_bits + while not sat(bits, target, n_steps): + # increment bits by 1 + # wrap at n_bits + i = 0 + while bits[i] == 1: + bits[i] = 0 + i += 1 + bits[i] = 1 + return bits + + ``` + Hand-written solution: + ```python + s = target[:] # copy + for step in range(n_steps): + for i in range(len(target) - 2, -1, -1): + if (s[i], s[i + 1]) == (1, 0): + (s[i], s[i + 1]) = (0, 1) + return s + ``` +
+ +* **SameDifferent** Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C) (5 instances) + + ```python + def sat(lists: List[List[int]], items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4): + a, b = lists + assert len(a) == len(b) == length + assert len(set(a)) == len(a) + assert len(set(b)) == 1 + for i in a + b: + assert (a + b).count(i) <= items.count(i) return True - - res = helper() - assert res - - def get_opt(opts): - if 0 in opts.opts: - return 0 - assert len(opts.opts) == 1 - return list(opts.opts)[0] - - return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()] -``` - -
- -### MatchingMarkers -Inspired by -[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) - -This is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time). - -```python -def sat(cut_position: int, ring="yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM", lower=5): - """ - The input is a string of start and end markers "aaBAcGeg" where upper-case characters indicate start markers - and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is - to find a location to split the ring so that there are a maximal number of matched start/end chars where a character - (like "a"/"A") is matched if starting at the split and going around the ring, the start-end pairs form a valid - nesting like nested parentheses. Can you solve it in linear time? - """ - line = ring[cut_position:] + ring[:cut_position] - matches = {c: 0 for c in line.lower()} - for c in line: - if c.islower(): - matches[c] -= (1 if matches[c] > 0 else len(line)) + ``` +
0.17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a list of integers and a target length, create of the given length such that: + * The first list must be all different numbers. + * The second must be all the same number. + * The two lists together comprise a sublist of all the list items + """ + ``` + Shortest Codex solution: + ```python + + return [[5, 4, 9, 1], [5] * length] + + ``` + Longest Codex solution: + ```python + + a = [int(x) for x in list(set([x[0] for x in zip(items, items[1:] + items[:1])]))] + r = [int(x) for x in list(set([x[0] for x in zip(items[::-1], items[::-1][1:] + items[::-1][:1])]))] + a.sort(key=items.index) + r.sort(key=items.index) + return [a, [items[0]]*length] + + ``` + Hand-written solution: + ```python + from collections import Counter + [[a, count]] = Counter(items).most_common(1) + assert count >= length + seen = {a} + dedup = [i for i in items if i not in seen and not seen.add(i)] + return [(dedup + [a])[:length], [a] * length] + ``` +
+ +* **Sssuubbstriiingg** Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A) (5 instances) + + ```python + def sat(inds: List[int], string="Sssuubbstrissiingg"): + return inds == sorted(inds) and "".join(string[i] for i in inds) == "substring" + ``` +
0.043% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(string="Sssuubbstrissiingg"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find increasing indices to make the substring "substring""" + ``` + Shortest Codex solution: + ```python + + return [ string.find(c, i+1) for c,i in zip("substring", range(len(string))) ] + + ``` + Longest Codex solution: + ```python + + substr = "substring" + # ordered indices + i = 0 + inds = [] + for c in substr: + while string[i] != c: + i += 1 + # we're done if we've gone past the end of the string + if i >= len(string): + return [] + inds.append(i) + i += 1 + return inds + + ``` + Hand-written solution: + ```python + target = "substring" + j = 0 + ans = [] + for i in range(len(string)): + while string[i] == target[j]: + ans.append(i) + j += 1 + if j == len(target): + return ans + ``` +
+ +* **BillSums** Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A) + + We make it much harder when the denominations are non-American so the greedy algorithm doesn't work. (5 instances) + + ```python + def sat(bills: List[int], denominations=[1, 25, 35, 84], n=980, max_len=14): + return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len + ``` +
0.037% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(denominations=[1, 25, 35, 84], n=980, max_len=14): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations + """ + ``` + Shortest Codex solution: + ```python + + bills = [35] * 14 + for i in range(max_len): + for bill in denominations: + bills[i] = bill + if sat(bills, denominations, n, max_len): + return bills + + ``` + Longest Codex solution: + ```python + + possibilities = [[]] + while possibilities: + sequence = possibilities.pop() + if sum(sequence) == n: + if len(sequence) <= max_len: + return sequence + else: + continue + else: + if len(sequence) == max_len: + continue + possibilities += [ + [i] + sequence + for i in denominations + if sum(sequence) + i <= n] + return possibilities + + ``` + Hand-written solution: + ```python + """ + This solution uses dynamic programming, I believe it could be further sped up without having to count + all the way up to denominations. + """ + denominations = sorted(set(denominations)) # remove duplicates + seqs = [[0 for _ in denominations] +[0]] # vectors + for i in range(1, n + 1): + _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i) + s = seqs[i - k] + seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1]) + + return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)] + ``` +
+ +* **DistinctOddSum** Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A) (5 instances) + + ```python + def sat(nums: List[int], tot=12345, n=5): + return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums) + ``` +
0.03% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(tot=12345, n=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n distinct positive odd integers that sum to tot""" + ``` + Shortest Codex solution: + ```python + + return [int("1"*(i+1)) for i in range(n)] + + ``` + Longest Codex solution: + ```python + + nums = [] + while n > 0: + i = int(tot / n * 2) + if i % 2 == 0: + i -= 1 + if i <= 0: + return [] + nums.append(i) + tot -= i + n -= 1 + return nums + + ``` + Hand-written solution: + ```python + return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))] + ``` +
+ +* **BoxVolume** (Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A) + + We make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work. (5 instances) + + ```python + def sat(sides: List[int], options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13): + prod = 1 + for b in sides: + prod *= b + return prod == n and set(sides) <= set(options) and len(sides) <= max_dim + ``` +
0.03% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n, + where each side length is in options + """ + ``` + Shortest Codex solution: + ```python + + to_try = [[b] for b in options] + for _ in range(max_dim-1): + to_try = [l + [a] for l in to_try for a in options if len(l) == 0 or a >= max(l)] + for l in to_try: + if sat(l): + return l + return None + + ``` + Longest Codex solution: + ```python + + def generate_sides(options, max_dim=max_dim): + if max_dim == 0: + yield [] + else: + for side in options: + for side_seq in generate_sides(options, max_dim-1): + yield [side] + side_seq + return min([sides for sides in generate_sides(options) if sat(sides, options, n, max_dim)], key=lambda x: len(x)) + + ``` + Hand-written solution: + ```python + options = sorted(set(options)) + base = options[0] + logs = [] + for i in options + [n]: + j = 1 + log = 0 + while j < i: + log +=1 + j *= base + assert j == i, "All numbers must be a power of the smallest number" + logs.append(log) + denominations, n = logs[:-1], logs[-1] + + seqs = [[0 for _ in denominations] +[0]] # vectors + for i in range(1, n + 1): + _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i) + s = seqs[i - k] + seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1]) + + return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)] + ``` +
+ +* **MinBigger** Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A) (5 instances) + + ```python + def sat(taken: List[int], val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11): + advantage = 0 + assert len(taken) == len(val_counts) and sum(taken) <= upper + for i, (val, count) in zip(taken, val_counts): + assert 0 <= i <= count + advantage += val * i - val * count / 2 + return advantage > 0 + ``` +
0.017% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + The list of numbers val_counts represents multiple copies of integers, e.g., + val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4 + For each number, decide how many to take so that the total number taken is <= upper and the sum of those + taken exceeds half the total sum. + """ + ``` + Shortest Codex solution: + ```python + + taken = [0] * len(val_counts) + for _ in range(upper): + maximum = -1 + which = -1 + for i, (val, count) in enumerate(val_counts): + if taken[i] < count and max(taken) + val > maximum: + maximum = max(taken) + val + which = i + taken[which] += 1 + return taken + + ``` + Longest Codex solution: + ```python + + def helper(res, acc, i): + if i == len(val_counts): + if sat(res, val_counts, upper): + return res + return None + for j in range(min(upper - sum(res), val_counts[i][1])+1): + if helper(res + [j], acc + j * val_counts[i][0], i+1) is not None: + return helper(res + [j], acc + j * val_counts[i][0], i+1) + return None + + res = helper([], 0, 0) + return res + ``` + Hand-written solution: + ```python + n = len(val_counts) + pi = sorted(range(n), key=lambda i: val_counts[i][0]) + needed = sum(a * b for a, b in val_counts) / 2 + 0.1 + ans = [0] * n + while needed > 0: + while val_counts[pi[-1]][1] == ans[pi[-1]]: + pi.pop() + i = pi[-1] + ans[i] += 1 + needed -= val_counts[i][0] + return ans + ``` +
+ +* **DominoTile** Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A) (5 instances) + + ```python + def sat(squares: List[List[int]], m=10, n=5, target=50): + covered = [] + for i1, j1, i2, j2 in squares: + assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1) + covered += [(i1, j1), (i2, j2)] + return len(set(covered)) == len(covered) == target + ``` +
0.013% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=10, n=5, target=50): + ``` + Solution docstring (*not* usually provided) + + ```python + """Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with + i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.""" + ``` + Shortest Codex solution: + ```python + + lst = [] + for i in range(m // 2): + for j in range(n): + lst.append([i*2, j, i*2+1, j]) + + return lst + + ``` + Longest Codex solution: + ```python + + squares = [] + for i in range(m//2): + for j in range(n): + squares.append([i*2, j, i*2 + 1, j]) + for i in range(m%2): + for j in range(n//2): + squares.append([i*2+m%2, j*2, i*2+m%2, j*2+1]) + squares.append([i*2+m%2, j*2+1, i*2+m%2+1, j*2+1]) + return squares + + ``` + Hand-written solution: + ```python + if m % 2 == 0: + ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)] + elif n % 2 == 0: + ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)] else: - matches[c.lower()] += 1 - return sum(i == 0 for i in matches.values()) >= lower -``` -
1 solution to ICPC 4/4 - -```python -def sol(ring="yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM", lower=5): - cumulatives = {c: [(0, 0)] for c in ring.lower()} - n = len(ring) - for i, c in enumerate(ring): - v = cumulatives[c.lower()] - v.append((i, v[-1][1] + (-1 if c.islower() else 1))) - - scores = [0]*n - cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0} - for c, v in cumulatives.items(): - if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes - continue - m = min(t for i, t in v) - for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]): - if t == m: - for j in range(i+1, i2+1): - scores[j % n] += 1 - b = max(scores) - for i in range(n): - if scores[i] == b: - return i -``` - -
- -## IMO - -Problems inspired by the -[International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) -[problems](https://www.imo-official.org/problems.aspx) - -### ExponentialCoinMoves -This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long. - -The version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big -for computers) but the solution is quite similar to the solution to the IMO problem. Because the solution -requires exponential many moves, our representation allows combining multiple Type-1 (advance) operations -into a single step. - -Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx) - -```python -def sat(states: List[List[int]], n=16385): - """ - There are five boxes each having one coin initially. Two types of moves are allowed: - * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1` - * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2` - Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box. - Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last - box. Encode each state as a list of the numbers of coins in the five boxes. - - Sample Input: - `n = 2` - - Sample Output: - `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]` - - The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps. - - states is encoded by lists of 5 coin counts - """ - assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li) - for prev, cur in zip(states, states[1:]): - for i in range(5): - if cur[i] != prev[i]: - break - assert cur[i] < prev[i] - assert ( - cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements - or - cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap - ) - - return states[-1][-1] == 2 ** n -``` -
1 solution to IMO 1/6 - -```python -def sol(n=16385): - assert n >= 1 - ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0], - [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]] - - def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0 - state = ans[-1][:] - state[2] -= 1 - state[3] += 2 - ans.append(state[:]) - while state[2]: - state[3], state[4] = 0, 2 * state[3] - ans.append(state[:]) - state[2:] = [state[2] - 1, state[4], 0] - ans.append(state[:]) - - exp_move() - assert ans[-1] == [0, 1, 0, 2 ** 14, 0] - ans.append([0, 0, 2 ** 14, 0, 0]) - if n <= 16: - ans.append([0, 0, 0, 2 ** 15, 0]) - else: - exp_move() - assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0] - state = ans[-1][:] - state[-2] -= 2 ** (n - 1) - state[-1] = 2 ** n - ans.append(state) - return ans -``` - -
- -### NoRelativePrimes -Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx) - -Question: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder -theorem? - -```python -def sat(nums: List[int], b=6, m=2): - """ - Let P(n) = n^2 + n + 1. - - Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has - the property that there is no element that is relatively prime to every other element. - - Sample input: - b = 6 - m = 2 - - Sample output: - [195, 196] - """ - assert len(nums) == len(set(nums)) == m and min(nums) >= 0 - - def gcd(i, j): - r, s = max(i, j), min(i, j) - while s >= 1: - r, s = s, (r % s) - return r - - for a in nums: - nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)] - assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums) - - return True -``` -
1 solution to IMO 2/6 - -```python -def sol(b=6, m=2): - ans = [] - - seen = set() - deltas = set() - - def go(a): - if a < 0 or a in seen or len(ans) == m: - return - seen.add(a) - nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)] - if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums): - new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas] - ans.append(a) - for delta in new_deltas: - for a2 in ans: - go(a2 + delta) - go(a2 - delta) - deltas.update(new_deltas) - for delta in sorted(deltas): - go(a + delta) - - def gcd(i, j): - r, s = max(i, j), min(i, j) - while s >= 1: - r, s = s, (r % s) - return r - - a = 0 - - while len(ans) < m: - go(a) - a += 1 - - return ans -``` - -
- -### FindRepeats -Note: This problem is much easier than the IMO problem which also required a proof that it is impossible -for a_0 not divisible by 3. - -Inspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx) - -```python -def sat(indices: List[int], a0=123): - """ - Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value - occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is: - a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise. - - For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal. - - Sample input: - 9 - - Sample output: - [0, 3, 6, ..., 2997] - - The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are - all equal in this case. - """ - assert a0 >= 0 and a0 % 3 == 0, "Hint: a_0 is a multiple of 3." - s = [a0] - for i in range(max(indices)): - s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3) - return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1 -``` -
1 solution to IMO 3/6 - -```python -def sol(a0=123): - n = a0 - ans = [] - i = 0 - while len(ans) < 1000: - if n == 3: # use the fact that 3 will repeat infinitely often - ans.append(i) - n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3 - i += 1 - return ans -``` - -
- -### PickNearNeighbors -Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx) - -The puzzle solution follows the judge's proof closely. - -```python -def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): - """ - Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order) - so that the remaining list of numbers satisfies: - * its largest number is next to its second largest number - * its third largest number is next to its fourth largest number - ... - * its second smallest number is next to its smallest number - - Sample input: - [4, 0, 5, 3, 1, 2] - n = 2 - - Sample output: - [True, False, True, False, True, True] - - Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2. - """ - n = int(len(heights) ** 0.5) - assert sorted(heights) == list(range(n * n + n)), "hint: heights is a permutation of range(n * n + n)" - kept = [i for i, k in zip(heights, keep) if k] - assert len(kept) == 2 * n, "must keep 2n items" - pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices - return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n)) -``` -
1 solution to IMO 4/6 - -```python -def sol(heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): # Based on the judge's solution. - n = int(len(heights) ** 0.5) - assert sorted(heights) == list(range(n * (n + 1))) - groups = [h // (n + 1) for h in heights] - ans = [False] * len(heights) - a = 0 - used_groups = set() - while sum(ans) < 2 * n: - group_tracker = {} - b = a - while groups[b] not in group_tracker or groups[b] in used_groups: - group_tracker[groups[b]] = b - b += 1 - ans[group_tracker[groups[b]]] = True - ans[b] = True - used_groups.add(groups[b]) - a = b + 1 - return ans -``` - -
- -### FindProductiveList -Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not -exists for non-multiples of 3. - -Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx) - -```python -def sat(li: List[int], n=18): - """ - Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1 - where indices >= n "wrap around". Note: only n multiples of 3 are given since this is only possible for n - that are multiples of 3 (as proven in the IMO problem). - - Sample input: - 6 - - Sample output: - [_, _, _, _, _, _] - - (Sample output hidden because showing sample output would give away too much information.) - """ - assert n % 3 == 0, "Hint: n is a multiple of 3" - return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n)) -``` -
1 solution to IMO 5/6 - -```python -def sol(n=18): - return [-1, -1, 2] * (n // 3) -``` - -
- -### HalfTag -Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx) - -```python -def sat(li: List[int], n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]): - """ - The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times. - The goal is to find a subset (list) li of half the indices such that: - * The sum of the indices equals the sum of the sum of the missing indices. - * The tags of the chosen indices contains exactly each number in range(n) twice. - - Sample input: - n = 3 - tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2] - - Sample output: - [0, 3, 5, 6, 8, 11] - - Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2] - """ - assert sorted(tags) == sorted(list(range(n)) * 4), "hint: each tag occurs exactly four times" - assert len(li) == len(set(li)) and min(li) >= 0 - return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)] -``` -
1 solution to IMO 6/6 - -```python -def sol(n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]): - pairs = {(i, 4 * n - i - 1) for i in range(2 * n)} - by_tag = {tag: [] for tag in range(n)} - for p in pairs: - a, b = [tags[i] for i in p] - by_tag[a].append(p) - by_tag[b].append(p) - cycles = [] - cycle = [] - while pairs: - if not cycle: # start new cycle - p = pairs.pop() - pairs.add(p) # just to pick a tag - tag = tags[p[0]] - # print("Starting cycle with tag", tag) - p = by_tag[tag].pop() - a, b = [tags[i] for i in p] - # print(p, a, b) - tag = a if a != tag else b - by_tag[tag].remove(p) - cycle.append(p if tag == b else p[::-1]) - pairs.remove(p) - if not by_tag[tag]: - cycles.append(cycle) - cycle = [] - - while any(len(c) % 2 for c in cycles): - cycle_tags = [{tags[k] for p in c for k in p} for c in cycles] - merged = False - for i in range(len(cycles)): - for j in range(i): - intersection = cycle_tags[i].intersection(cycle_tags[j]) - if intersection: - c = intersection.pop() - # print(f"Merging cycle {i} and cycle {j} at tag {c}", cycles) - cycle_i = cycles.pop(i) - for i1, p in enumerate(cycle_i): - if tags[p[0]] == c: - break - for j1, p in enumerate(cycles[j]): - if tags[p[0]] == c: - break - cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1] - merged = True - break - if merged: - break - - ans = [] - for c in cycles: - for i, p in enumerate(c): - if i % 2: - ans += p - - return ans -``` - -
- -## lattices - -Lattice problems with and without noise - -### LearnParity -Parity learning (Gaussian elimination) - -The canonical solution to this -[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning) -is to use -[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination). - -The vectors are encoded as binary integers for succinctness. - -```python -def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): - """ - Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that: - $$sum_{i \in S} x_i = 1 (mod 2)$$ - """ - return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs) -``` -
1 solution to lattices 1/2 - -```python -def sol(vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): # Gaussian elimination - d = 0 # decode vectors into arrays - m = max(vecs) - while m: - m >>= 1 - d += 1 - vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs] - ans = [] - pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs] - for i in range(d): - pool[i][i] = 1 - - for i in range(d): # zero out bit i - for v in pool[d:]: - if v[i] == 1: - break - if v[i] == 0: - v = pool[i] - assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate - w = v[:] - for v in pool: - if v[i] == 1: - for j in range(d + 1): - v[j] ^= w[j] - - return [i for i in range(d) if pool[i][-1]] -``` - -
- -### LearnParityWithNoise -Learn parity with noise (*unsolved*) - -The fastest known algorithm to this -[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning) -runs in time $2^(d/(log d))$ - -```python -def sat(inds: List[int], vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 24, 16, 13, 0, 27, 13]): - """ - Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least - 3/4 of the vectors, $$sum_{i \in S} x_i = 1 (mod 2)$$ - """ - return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4 -``` -
1 solution to lattices 2/2 - -```python -def sol(vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 24, 16, 13, 0, 27, 13]): # brute force - d = 0 # decode vectors into arrays - m = max(vecs) - while m: - m >>= 1 - d += 1 - vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs] - - import random - rand = random.Random(0) - target = (len(vecs) * 3) // 4 - while True: - ans = [i for i in range(d) if rand.randrange(2)] - if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4: - return ans -``` - -
- -## number_theory - -Number theory problems - -### FermatsLastTheorem -[Fermat's last theorem](https://en.wikipedia.org/w/index.php?title=Fermat%27s_Last_Theorem) - -Supposedly unsolvable, but how confident are really in the super-complicated proof? - -See [Wiles, Andrew. "Modular elliptic curves and Fermat's last theorem." Annals of mathematics 141.3 (1995): 443-551.](https://www.jstor.org/stable/2118559) - -```python -def sat(nums: List[int]): - """Find integers a,b,c > 0, n > 2, such such that a^n + b^n == c^n""" - a, b, c, n = nums - return (a ** n + b ** n == c ** n) and min(a, b, c) > 0 and n > 2 -``` -0 solutions to number_theory 1/16 - -### GCD -[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381) -(GCD) - -See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) - -```python -def sat(n: int, a=15482, b=23223, lower_bound=5): - """Find a large common divisor of two integers.""" - return a % n == 0 and b % n == 0 and n >= lower_bound -``` -
2 solutions to number_theory 2/16 - -```python -def sol(a=15482, b=23223, lower_bound=5): - m, n = min(a, b), max(a, b) - while m > 0: - m, n = n % m, m - return n -``` - -
- -```python -def sol(a=15482, b=23223, lower_bound=5): - def gcd(m, n): - if m > n: - return gcd(n, m) - if m == 0: - return n - return gcd(n % m, m) - - return gcd(a, b) -``` - -
- -### GCD_multi -[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381) -(GCD) - -See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) - -```python -def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2): - """Find a large common divisor of the list of integers.""" - return all(i % n == 0 for i in nums) and n >= lower_bound -``` -
1 solution to number_theory 3/16 - -```python -def sol(nums=[77410, 23223, 54187], lower_bound=2): - n = 0 - for i in nums: - m, n = min(i, n), max(i, n) - while m > 0: - m, n = n % m, m - return n -``` - -
- -### LCM -[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple) -(LCM) - -See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) - -```python -def sat(n: int, a=15, b=27, upper_bound=150): - """Find a small common multiple of two integers.""" - return n % a == 0 and n % b == 0 and 0 < n <= upper_bound -``` -
1 solution to number_theory 4/16 - -```python -def sol(a=15, b=27, upper_bound=150): - m, n = min(a, b), max(a, b) - while m > 0: - m, n = n % m, m - return a * (b // n) -``` - -
- -### LCM_multi -[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple) -(LCM) - -See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) - -```python -def sat(n: int, nums=[15, 27, 102], upper_bound=5000): - """Find a small common multiple of a list of integers.""" - return all(n % i == 0 for i in nums) and n <= upper_bound -``` -
1 solution to number_theory 5/16 - -```python -def sol(nums=[15, 27, 102], upper_bound=5000): - ans = 1 - for i in nums: - m, n = min(i, ans), max(i, ans) - while m > 0: - m, n = n % m, m - ans *= (i // n) - return ans -``` - -
- -### SmallExponentBigSolution -Small exponent, big solution - -Problems have small b and target but solution is typically a large n. -Some of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497` - -See [Richard K. Guy "The strong law of small numbers", (problem 13)](https://doi.org/10.2307/2322249) - -```python -def sat(n: int, b=2, target=5): - """Solve for n: b^n = target (mod n)""" - return (b ** n) % n == target -``` -
1 solution to number_theory 6/16 - -```python -def sol(b=2, target=5): - for n in range(1, 10 ** 5): - if pow(b, n, n) == target: - return n -``` - -
- -### ThreeCubes -Sum of three cubes - -Given `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`. -Conjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`. -`a`, `b`, `c` may be positive or negative - -See [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or -[Andrew R. Booker, Andrew V. Sutherland (2020). "On a question of Mordell."](https://arxiv.org/abs/2007.01209) - -```python -def sat(nums: List[int], target=10): - """Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.""" - assert target % 9 not in [4, 5], "Hint" - return len(nums) == 3 and sum([i ** 3 for i in nums]) == target -``` -
1 solution to number_theory 7/16 - -```python -def sol(target=10): - assert target % 9 not in {4, 5} - for i in range(20): - for j in range(i + 1): - for k in range(-20, j + 1): - n = i ** 3 + j ** 3 + k ** 3 - if n == target: - return [i, j, k] - if n == -target: - return [-i, -j, -k] -``` - -
- -### FourSquares -Sum of four squares - -[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem) - -Given a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four -integers. The problem here is to find them. This is a nice problem and we give an elementary solution -that runs in time ilde{O}(n), -which is not "polynomial time" because it is not polynomial in log(n), the length of n. A poly-log(n) -algorithm using quaternions is described in the book: -["Randomized algorithms in number theory" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713) - -The first half of the problems involve small numbers and the second half involve some numbers up to 50 digits. - -```python -def sat(nums: List[int], n=12345): - """Find four integers whose squares sum to n""" - return len(nums) <= 4 and sum(i ** 2 for i in nums) == n -``` -
1 solution to number_theory 8/16 - -```python -def sol(n=12345): - m = n - squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m} - sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()} - for s in sums_of_squares: - if m - s in sums_of_squares: - return sums_of_squares[m - s] + sums_of_squares[s] - assert False, "Should never reach here" -``` - -
- -### Factoring -[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and -[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers) - -*See class FermatComposite in codex.py for an easier composite test puzzle* - -The factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a -simple repetition process. Problems range from small (single-digit n) all the way to the "RSA challenges" -which include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007, -with hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People -continue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar. - -From Wikipedia: - -RSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest -cash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come, -unless considerable advances are made in integer factorization or computational power in the near future. + ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)] + ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)] + return ans + ``` + + +* **MinRotations** Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A) (5 instances) + + ```python + def sat(rotations: List[int], target="wonderful", upper=69): + s = "abcdefghijklmnopqrstuvwxyz" + assert len(rotations) == len(target) + for r, c in zip(rotations, target): + s = s[r:] + s[:r] + assert s[0] == c + + return sum(abs(r) for r in rotations) <= upper + ``` +
0.01% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="wonderful", upper=69): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + We begin with the string `"a...z"` + + An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and + cycling around. Given a target string of length n, find the n rotations that put the consecutive characters + of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s. + + For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`. + """ + ``` + Shortest Codex solution: + ```python + + s = "abcdefghijklmnopqrstuvwxyz" + rotations = [] + for c in target: + pos = s.find(c, 0) + if pos < len(s) - pos: + rotations.append(pos) + else: + rotations.append(pos - len(s)) + s = s[pos:] + s[:pos] + + return rotations + + ``` + Longest Codex solution: + ```python + + s = "abcdefghijklmnopqrstuvwxyz" + assert len(target) + target = list(target) + rotations = [] + for c in target: + idx = s.find(c) + assert idx > 0 + # Guaranteed to be 0 or 1 + r = idx - len(s) if idx > len(s) // 2 else idx + rotations.append(r) + s = s[r:] + s[:r] + + return rotations + + ``` + Hand-written solution: + ```python + s = "abcdefghijklmnopqrstuvwxyz" + ans = [] + for c in target: + i = s.index(c) + r = min([i, i - len(s)], key=abs) + ans.append(r) + s = s[r:] + s[:r] + assert s[0] == c + return ans + ``` +
+ +* **SlidingOne** Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A) (4 instances) + + ```python + def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3): + matrix = [m[:] for m in matrix] # copy + for c in s: + if c in "01234": + i = "01234".index(c) + matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i] + if c in "abcde": + j = "abcde".index(c) + for row in matrix: + row[j], row[j + 1] = row[j + 1], row[j] + + return len(s) <= max_moves and matrix[2][2] == 1 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + We are given a 5x5 matrix with a single 1 like: + + 0 0 0 0 0 + 0 0 0 0 1 + 0 0 0 0 0 + 0 0 0 0 0 + 0 0 0 0 0 + + Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string + in "0"-"4" indicating a row swap and "a"-"e" indicating a column swap + """ + ``` + Hand-written solution: + ```python + i = [sum(row) for row in matrix].index(1) + j = matrix[i].index(1) + ans = "" + while i > 2: + ans += str(i - 1) + i -= 1 + while i < 2: + ans += str(i) + i += 1 + while j > 2: + ans += "abcde"[j - 1] + j -= 1 + while j < 2: + ans += "abcde"[j] + j += 1 + return ans + ``` +
+ +* **Sstriiinggssuubb** Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A) (5 instances) + + ```python + def sat(inds: List[int], string="enlightenment"): + return inds == sorted(inds) and "".join(string[i] for i in inds) == "intelligent" + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(string="enlightenment"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find increasing indices to make the substring "intelligent" (with a surprise twist)""" + ``` + Hand-written solution: + ```python + target = "intelligent" + j = 0 + ans = [] + for i in range(-len(string), len(string)): + while string[i] == target[j]: + ans.append(i) + j += 1 + if j == len(target): + return ans + ``` +
+ +* **CombinationLock** Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A) (5 instances) + + ```python + def sat(states: List[str], start="424", combo="778", target_len=12): + assert all(len(s) == len(start) for s in states) and all(c in "0123456789" for s in states for c in s) + for a, b in zip([start] + states, states + [combo]): + assert sum(i != j for i, j in zip(a, b)) == 1 + assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b)) + + return len(states) <= target_len + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(start="424", combo="778", target_len=12): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Shortest Combination Lock Path + + Given a starting a final lock position, find the (minimal) intermediate states, where each transition + involves increasing or decreasing a single digit (mod 10). + + Example: + start = "012" + combo = "329" + output: ['112', '212', '312', '322', '321', '320'] + """ + ``` + Hand-written solution: + ```python + n = len(start) + ans = [] + a, b = [[int(c) for c in x] for x in [start, combo]] + for i in range(n): + while a[i] != b[i]: + a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10 + if a != b: + ans.append("".join(str(i) for i in a)) + return ans + ``` +
+ +* **CombinationLockObfuscated** Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A) + This an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that + it is the same puzzle? (5 instances) + + ```python + def sat(states: List[str], start="424", combo="778", target_len=12): + return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1 + for a, b in zip([start] + states, states[:target_len] + [combo])) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(start="424", combo="778", target_len=12): + ``` + Solution docstring (*not* usually provided) + + ```python + """Figure out what this does only from the code""" + ``` + Hand-written solution: + ```python + n = len(start) + ans = [] + a, b = [[int(c) for c in x] for x in [start, combo]] + for i in range(n): + while a[i] != b[i]: + a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10 + if a != b: + ans.append("".join(str(i) for i in a)) + return ans + ``` +
+ +## algebra -```python -def sat(i: int, n=62710561): - """Find a non-trivial factor of integer n""" - return 1 < i < n and n % i == 0 -``` -
1 solution to number_theory 9/16 +Roots of polynomials -```python -def sol(n=62710561): - if n % 2 == 0: - return 2 +* **QuadraticRoot** See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula) (5 instances) + + ```python + def sat(x: float, coeffs=[2.5, 1.3, -0.5]): + a, b, c = coeffs + return abs(a * x ** 2 + b * x + c) < 1e-6 + ``` +
9.6% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(coeffs=[2.5, 1.3, -0.5]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c]. + For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True. + """ + ``` + Shortest Codex solution: + ```python + + a, b, c = coeffs + return (-b+(b*b-4*a*c)**0.5)/(2*a) + + ``` + Longest Codex solution: + ```python + + a, b, c = coeffs + if a == 0: + if b != 0: + return -c / b + else: + return None + else: + discrim = b ** 2 - 4 * a * c + if discrim < 0: + return None + else: + v1 = (-b + discrim ** 0.5) / a / 2 + v2 = (-b - discrim ** 0.5) / a / 2 + if abs(v1) < abs(v2): + return v1 + else: + return v2 + + ``` + Hand-written solution: + ```python + a, b, c = coeffs + if a == 0: + ans = -c / b if b != 0 else 0.0 + else: + ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)) + return ans + ``` + Hand-written solution: + ```python + a, b, c = coeffs + if a == 0: + ans = -c / b if b != 0 else 0.0 + else: + ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a) + return ans + ``` +
+ +* **AllQuadraticRoots** See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula). (5 instances) + + ```python + def sat(roots: List[float], coeffs=[1.3, -0.5]): + b, c = coeffs + r1, r2 = roots + return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6 + ``` +
4.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(coeffs=[1.3, -0.5]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]""" + ``` + Shortest Codex solution: + ```python + + b, c = coeffs + return [(-b+i*(b**2-4*c)**0.5)/2 for i in [1,-1]] + + ``` + Longest Codex solution: + ```python + + b, c = coeffs + res = [] + D = b**2 - 4 * c + if D > 0: + res.append((-b + D**0.5)/2) + res.append((-b - D**0.5)/2) + elif D == 0: + res.append(-b/2) + return res + + ``` + Hand-written solution: + ```python + b, c = coeffs + delta = (b ** 2 - 4 * c) ** 0.5 + return [(-b + delta) / 2, (-b - delta) / 2] + ``` +
+ +* **CubicRoot** See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula). (5 instances) + + ```python + def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]): + return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6 + ``` +
0.04% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(coeffs=[2.0, 1.0, 0.0, 8.0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d] + For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True. + """ + ``` + Shortest Codex solution: + ```python + + a, b, c, d = coeffs + x = -b / a + for i in range(10): + x = x - (a*x**3 + b*x**2 + c*x + d) / (3*a*x**2 + 2*b*x + c) + return x + + ``` + Longest Codex solution: + ```python + + def newton(sat, fprime, xin): + """ Newton-Raphson method of finding root of function f at xin. """ + x = xin + while abs(sat(x)) > 1e-6: + x = x - sat(x) / fprime(x) + return x + return newton(lambda x: sum(c * x ** (3 - i) for i, c in enumerate(coeffs)), lambda x: sum(c * (3-i) * x ** (2 - i) + for i, c in enumerate(coeffs)), 1.0) + + ``` + Hand-written solution: + ```python + a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]] + p = (3 * a1 - a2 ** 2) / 3 + q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27 + delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5 + omega = (-(-1) ** (1 / 3)) + for cube in [(q + delta) / 2, (q - delta) / 2]: + c = cube ** (1 / 3) + for w in [c, c * omega, c * omega.conjugate()]: + if w != 0: + x = complex(w - p / (3 * w) - a2 / 3).real + if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6: + return x + ``` +
+ +* **AllCubicRoots** See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula). (5 instances) + + ```python + def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]): + r1, r2, r3 = roots + a, b, c = coeffs + return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(coeffs=[1.0, -2.0, -1.0]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3). + coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, + sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True. + """ + ``` + Hand-written solution: + ```python + a, b, c = coeffs + p = (3 * b - a ** 2) / 3 + q = (9 * b * a - 27 * c - 2 * a ** 3) / 27 + delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5 + omega = (-(-1) ** (1 / 3)) + ans = [] + for cube in [(q + delta) / 2, (q - delta) / 2]: + v = cube ** (1 / 3) + for w in [v, v * omega, v * omega.conjugate()]: + if w != 0.0: + x = complex(w - p / (3 * w) - a / 3).real + if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4: + if not ans or min(abs(z - x) for z in ans) > 1e-6: + ans.append(x) + if len(ans) == 3: + return ans + ``` +
+ +## basic - for i in range(3, int(n ** 0.5) + 1, 2): - if n % i == 0: - return i +Problems testing basic knowledge -- easy to solve if you understand what is being asked - assert False, "problem defined for composite n only" -``` +* **CenteredString** (5 instances) + + ```python + def sat(s: str, target="foobarbazwow", length=6): + return target[(len(target) - length) // 2:(len(target) + length) // 2] == s + ``` +
82% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="foobarbazwow", length=6): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a substring of the given length centered within the target string.""" + ``` + Shortest Codex solution: + ```python + + return "barbaz" + + ``` + Longest Codex solution: + ```python + + if len(target[(len(target) - length) // 2:(len(target) + length) // 2]) > length: + if len(target[(len(target) - length) // 2:(len(target) + length) // 2]) % 2 == 1: + return target[(len(target) - length) // 2:(len(target) + length + 1) // 2] + else: + return target[(len(target) - length) // 2:(len(target) + length) // 2] + return target[(len(target) - length) // 2:(len(target) + length) // 2] + + + ``` + Hand-written solution: + ```python + return target[(len(target) - length) // 2:(len(target) + length) // 2] + ``` +
+ +* **PenultimateString** (5 instances) + + ```python + def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']): + return s in strings and sum(t > s for t in strings) == 1 + ``` +
48% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the alphabetically second to last last string in a list.""" + ``` + Shortest Codex solution: + ```python + + return "fly" + + ``` + Longest Codex solution: + ```python + + # This could reduce the time_limit by at least half + # for something like strings = ['x' + t for t in strings] + # But I think it's better to not do that. + # + # I think this example is about (1) creating a benchmark, (2) noticing that time_limit is what + # I thought it should be (3), and (4) demonstrating that this method always works. Because how. + return strings[-2] + + ``` + Hand-written solution: + ```python + return sorted(strings)[-2] + ``` +
+ +* **ConcatStrings** (5 instances) + + ```python + def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4): + return len(x) == n and all([x[i] == s[i] for i in range(n)]) + ``` +
35% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """Concatenate the list of characters in s""" + ``` + Shortest Codex solution: + ```python + + return "abcd" + + ``` + Longest Codex solution: + ```python + + try: + x = s[:n] + except: + print("Could not concatenate '%s' and %d." % (s, n)) + return 0 + if not(sat(x, s, n)): + print("'%s' is not %d characters long and does not consist of characters in '%s'." % (x, n, s)) + return 0 + return "".join(filter(lambda c: c in s, x)) + + ``` + Hand-written solution: + ```python + return ''.join([s[i] for i in range(n)]) + ``` +
+ +* **PenultimateRevString** (5 instances) + + ```python + def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']): + return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1 + ``` +
26% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the reversed version of the alphabetically second string in a list.""" + ``` + Shortest Codex solution: + ```python + + return 'cat'[::-1] + + ``` + Longest Codex solution: + ```python + + # In python 3.8, the sorting method of any iterable is guaranteed to be stable. + # Thus, lexicographically greater than does not need to consider later characters. + # The return value only needs to be lexicographically greater than one string. + strings.sort() + return strings[1][::-1] + + ``` + Hand-written solution: + ```python + return sorted(strings)[1][::-1] + ``` +
+ +* **ArithmeticSequence** (5 instances) + + ```python + def sat(x: List[int], a=7, s=5, e=200): + return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)]) + ``` +
22% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=7, s=5, e=200): + ``` + Solution docstring (*not* usually provided) + + ```python + """Create a list that is a subrange of an arithmetic sequence.""" + ``` + Shortest Codex solution: + ```python + + return [*range(a, e, s)] + ``` + Longest Codex solution: + ```python + + # 1. Perform a while loop while True + while True: + # 1.1. Generate a list using range(a, e, s). + x1 = list(range(a, e, s)) + # 1.2. Check if the generated list is a subrange of an arithmetic sequence. + if sat(x1, a, s, e): + # 1.3. If so, return the generated list. + return x1 + + ``` + Hand-written solution: + ```python + return list(range(a, e + 1, s)) + ``` +
+ +* **GeometricSequence** (5 instances) + + ```python + def sat(x: List[int], a=8, r=2, l=50): + return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)]) + ``` +
22% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=8, r=2, l=50): + ``` + Solution docstring (*not* usually provided) + + ```python + """Create a list that is a subrange of an gemoetric sequence.""" + ``` + Shortest Codex solution: + ```python + + return [a*r**i for i in range(l)] + ``` + Longest Codex solution: + ```python + + if not (isinstance(a, int) and 1 <= a <= 10**18): + raise ValueError("a is not an integer between 1 and 10**18") + if not (isinstance(r, int) and 1 <= r < 10**6): + raise ValueError("r is not an integer between 1 and 10**6") + if not (isinstance(l, int) and 1 <= l <= 10**6): + raise ValueError("l is not an integer between 1 and 10**6") + return [a*r**i for i in range(l)] + + ``` + Hand-written solution: + ```python + return [a * r ** i for i in range(l)] + ``` +
+ +* **ReverseCat** (5 instances) + + ```python + def sat(s: str, substrings=['foo', 'bar', 'baz']): + return all(sub in s and sub[::-1] in s for sub in substrings) + ``` +
16% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(substrings=['foo', 'bar', 'baz']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string that contains all the substrings reversed and forward + """ + ``` + Shortest Codex solution: + ```python + + return "foobarbaz" + "foobarbaz"[::-1] + + ``` + Longest Codex solution: + ```python + + # I don't want the user to have to look at this ugly mess + # The solution is pretty satisfying though + prefix, suffix = '', '' + for i in range(100): + prefix += ''.join( + s[::-1] + s for s in substrings + if i & (1 << len(s)) and s[::-1] + s not in prefix + ) + + suffix += ''.join( + s + s[::-1] for s in substrings + if i & (1 << len(s)) and s + s[::-1] not in suffix + ) + + return prefix + suffix + ``` + Hand-written solution: + ```python + return "".join(substrings + [s[::-1] for s in substrings]) + ``` +
+ +* **FloatWithDecimalValue** (5 instances) + + ```python + def sat(z: float, v=9, d=0.0001): + return int(z * 1 / d % 10) == v + ``` +
13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(v=9, d=0.0001): + ``` + Solution docstring (*not* usually provided) + + ```python + """Create a float with a specific decimal.""" + ``` + Shortest Codex solution: + ```python + + return -d + + ``` + Longest Codex solution: + ```python + + return 8.08393933818412062728072132147225914937536665959292637499014257567965321795296852334171523596184046806540477828054744651157641212284299791497949274482653883188824002406716832213535473396768127683725998099321378188185292483045683226896318538787043881347291418488370686494167002652473822185276052734301939790879 + #return int + ``` + Hand-written solution: + ```python + return v * d + ``` +
+ +* **IfProblemWithAnd** (5 instances) + + ```python + def sat(x: int, a=9384594, b=1343663): + if x > 0 and a > 50: + return x - a == b + else: + return x + a == b + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=9384594, b=1343663): + ``` + Solution docstring (*not* usually provided) + + ```python + """Satisfy a simple if statement with an and clause""" + ``` + Shortest Codex solution: + ```python + + return b-a + ``` + Longest Codex solution: + ```python + + if a == 9384594 and b == 1343663: + return 9384594 + 1343663 + elif a == 9374830 and b == 1439661: + return 9374830 - 1439661 + elif a == 9374830 and b == 1439661: + return 9374830 - 1439661 + else: + raise ValueError("Unknown value of a and b.") + + ``` + Hand-written solution: + ```python + if a > 50 and b > a: + return b + a + else: + return b - a + ``` +
+ +* **IfProblemWithOr** (5 instances) + + ```python + def sat(x: int, a=253532, b=1230200): + if x > 0 or a > 50: + return x - a == b + else: + return x + a == b + ``` +
9.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=253532, b=1230200): + ``` + Solution docstring (*not* usually provided) + + ```python + """Satisfy a simple if statement with an or clause""" + ``` + Shortest Codex solution: + ```python + + return a+b + ``` + Longest Codex solution: + ```python + + if a > 50 or a > b: + return a + b + else: + return a + b + b + + """return a + b + b if a > 50 or a > b else a + b""" + """return a + b + b if (a > 50 and a != b and a and b and b and not a or 1 or 5 or 6 or 7 or 1 or 1 or 8 or 8 or 1 or 1 or 4 or 4 or 1 or 1) else a + b""" + + + ``` + Hand-written solution: + ```python + if a > 50 or b > a: + return b + a + else: + return b - a + ``` +
+ +* **IfCases** (5 instances) + + ```python + def sat(x: int, a=4, b=54368639): + if a == 1: + return x % 2 == 0 + elif a == -1: + return x % 2 == 1 + else: + return x + a == b + ``` +
8.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=4, b=54368639): + ``` + Solution docstring (*not* usually provided) + + ```python + """Satisfy a simple if statement with multiple cases""" + ``` + Shortest Codex solution: + ```python + + return b-a + + ``` + Longest Codex solution: + ```python + + if b == 54368639: + if a == 1: + return 2 + elif a == -1: + return -3 + else: + return b - a + elif b == 62471: + if a == 1: + return -5 + elif a == -1: + return -3 + else: + return b - a + elif b == 17: + if a == 1: + return 5 + elif a == -1: + return -3 + else: + return b - a + ``` + Hand-written solution: + ```python + if a == 1: + x = 0 + elif a == -1: + x = 1 + else: + x = b - a + return x + ``` +
+ +* **IfProblem** (5 instances) + + ```python + def sat(x: int, a=324554, b=1345345): + if a < 50: + return x + a == b + else: + return x - 2 * a == b + ``` +
6.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=324554, b=1345345): + ``` + Solution docstring (*not* usually provided) + + ```python + """Satisfy a simple if statement""" + ``` + Shortest Codex solution: + ```python + + return 2*a+b + + ``` + Longest Codex solution: + ```python + + """Generates `arg1` that is equal to `arg2` when `arg1` is generated in the forward direction, + when `arg1` is generated in the reverse direction, when `arg2` is generated in the reverse direction, + when `arg2` is generated in the forward direction, when `arg1` is generated in the reverse direction, + when `arg2` is generated in the forward direction, when `arg1` is generated in the forward direction.""" + if a < 50: + return b - a + else: + return b + 2 * a + + ``` + Hand-written solution: + ```python + if a < 50: + return b - a + else: + return b + 2 * a + ``` +
+ +* **CumulativeSum** (5 instances) + + ```python + def sat(x: List[int], t=50, n=10): + assert all([v > 0 for v in x]) + s = 0 + i = 0 + for v in sorted(x): + s += v + if s > t: + return i == n + i += 1 + return i == n + ``` +
2.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(t=50, n=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find how many values have cumulative sum less than target""" + ``` + Shortest Codex solution: + ```python + + return [1]*n + + ``` + Longest Codex solution: + ```python + + assert type(t) in [int, float] and type(n) is int + assert t > 0 and n >= 1 + # Here is an example where cumulative sums always underrun the target + #return [int(1 + i**2) for i in range(1, n+1)] + # Here is an example where cumulative sums always overrun the target + #return [int(500 - i**2) for i in range(1, n+1)] + # Here is an example where the solution is always evenly distributed + return [int(t/(n+1)) for i in range(1, n+1)] + # Here is + ``` + Hand-written solution: + ```python + return [1] * n + [t] + ``` +
+ +* **SubstrCount** (5 instances) + + ```python + def sat(substring: str, string="moooboooofasd", count=2): + return string.count(substring) == count + ``` +
2.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(string="moooboooofasd", count=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a substring with a certain count in a given string""" + ``` + Shortest Codex solution: + ```python + + return "ooo" + ``` + Longest Codex solution: + ```python + + # try with all substrings of length exactly one + for l in range(1, 3): + for i in range(0, len(string)-l): + substring = string[i:i+l] + if sat(substring, string, count): + return substring + # try with all substrings of length exactly two + for l in range(2, 4): + for i in range(0, len(string)-l): + substring = string[i:i+l] + if sat(substring, string, count): + return substring + return None + + ``` + Hand-written solution: + ```python + for i in range(len(string)): + for j in range(i+1, len(string)): + substring = string[i:j] + c = string.count(substring) + if c == count: + return substring + if c < count: + break + assert False + ``` +
+ +* **ListPosSum** (5 instances) + + ```python + def sat(x: List[int], n=5, s=19): + return len(x) == n and sum(x) == s and all([a > 0 for a in x]) + ``` +
0.87% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=5, s=19): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of n non-negative integers that sum up to s""" + ``` + Shortest Codex solution: + ```python + + return [n, 8, 1, 2, 3] + + ``` + Longest Codex solution: + ```python + + i = 0 + for v in range(1, 10): + i += 1 + for w in range(v, 10): + i += 1 + for x in range(w, 10): + i += 1 + for y in range(x, 10): + i += 1 + for z in range(y, 10): + i += 1 + guess = [v, w, x, y, z] + if guess.count(0) + n < n: continue + if sum(guess) == s: + return guess + i += 1 + assert False, "failed to find result" + + ``` + Hand-written solution: + ```python + x = [1] * n + x[0] = s - n + 1 + return x + ``` +
+ +* **BasicStrCounts** (5 instances) + + ```python + def sat(s: str, s1="a", s2="b", count1=50, count2=30): + return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:] + ``` +
0.39% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s1="a", s2="b", count1=50, count2=30): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with + the same 10 characters + """ + ``` + Shortest Codex solution: + ```python + + return "x"*10 + s1*50 + s2*30 + "x"*10 + + ``` + Longest Codex solution: + ```python + + # f6 requires s[:10] == s[-10:] + # to do this, need to make sure s is even-length + # to do this, make sure the total number of the other characters is even + # to do this, make sure there are at least count2 of s2 + s = s2 * (count2 // 2) + s1 * count1 + s2 * (count2 // 2) + if count2 % 2 == 1: + s += s2 + return s + + ``` + Hand-written solution: + ```python + if s1 == s2: + ans = (s1 + "?") * count1 + elif s1.count(s2): + ans = (s1 + "?") * count1 + ans += (s2 + "?") * (count2 - ans.count(s2)) + else: + ans = (s2 + "?") * count2 + ans += (s1 + "?") * (count1 - ans.count(s1)) + return "?" * 10 + ans + "?" * 10 + ``` +
+ +* **CompleteParens** (5 instances) + + ```python + def sat(t: str, s="))(Add)some))parens()to()(balance(()(()(me!)(((("): + for i in range(len(t) + 1): + depth = t[:i].count("(") - t[:i].count(")") + assert depth >= 0 + return depth == 0 and s in t + ``` +
0.38% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="))(Add)some))parens()to()(balance(()(()(me!)(((("): + ``` + Solution docstring (*not* usually provided) + + ```python + """Add parentheses to the beginning and end of s to make all parentheses balanced""" + ``` + Shortest Codex solution: + ```python + + return "(((((("+s+")))))))))" + + ``` + Longest Codex solution: + ```python + + count_balance = 0 + for i in s: + if i == ")": + if count_balance == 0: + s = "(" + s + else: + count_balance -= 1 + elif i == "(": + count_balance += 1 + return s + ")" * count_balance + + ``` + Hand-written solution: + ```python + return "(" * s.count(")") + s + ")" * s.count("(") + ``` +
+ +* **ListDistinctSum** (5 instances) + + ```python + def sat(x: List[int], n=4, s=2021): + return len(x) == n and sum(x) == s and len(set(x)) == n + ``` +
0.36% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=4, s=2021): + ``` + Solution docstring (*not* usually provided) + + ```python + """Construct a list of n distinct integers that sum up to s""" + ``` + Shortest Codex solution: + ```python + + return [1, 2, 3, s-6] + + ``` + Longest Codex solution: + ```python + + x = [1] * n + while sum(x) != s: + x[0] -= 1 + order = sorted(range(len(x)), key=lambda i: x[i]) + for i in range(1, len(x)): + x[order[i]] += 99 + if sum(x[:i+1]) > s: + x[order[i-1]] -= 1 + x[order[i]] -= 1 + for j in range(i+1, len(x)): + x[order[j]] = 999 + return x + + ``` + Hand-written solution: + ```python + a = 1 + x = [] + while len(x) < n - 1: + x.append(a) + a = -a + if a in x: + a += 1 + + if s - sum(x) in x: + x = [i for i in range(n - 1)] + + x = x + [s - sum(x)] + return x + ``` +
+ +* **SumOfDigits** (5 instances) + + ```python + def sat(x: str, s=679): + return s == sum([int(d) for d in x]) + ``` +
0.17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s=679): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a number that its digits sum to a specific value.""" + ``` + Shortest Codex solution: + ```python + + return s*"1" + + ``` + Longest Codex solution: + ```python + + def g6_rec(x): + if len(x) >= 10: + return x + x = list(x) + while sum(int(d) for d in x) != s: + x.insert(0, str(int(x[0]) + 1)) + while int(x[0]) > 9: + x[0] = "0" + x.insert(0, "1") + return "".join(x) + return g6_rec(str(s)) + + ``` + Hand-written solution: + ```python + return int(s / 9) * '9' + str(s % 9) + ``` +
+ +* **EngineerNumbers** (5 instances) + + ```python + def sat(ls: List[str], n=100, a="bar", b="foo"): + return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls) + ``` +
0.14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=100, a="bar", b="foo"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of n strings, in alphabetical order, starting with a and ending with b. + """ + ``` + Shortest Codex solution: + ```python + + return list(a + "b"*i for i in range(n-1)) + [b] + + ``` + Longest Codex solution: + ```python + + ls = [a] + cur = a + for _ in range(n - 2): + if ls[-1] == "foo": + cur = "bar" + else: + cur = ls[-1][:-1] + chr(ord(ls[-1][-1])+1) + ls.append(cur) + ls.append(b) + return ls + + ``` + Hand-written solution: + ```python + return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b]) + ``` +
+ +* **ZipStr** (5 instances) + + ```python + def sat(s: str, substrings=['foo', 'bar', 'baz', 'oddball']): + return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings)) + ``` +
0.037% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(substrings=['foo', 'bar', 'baz', 'oddball']): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog' + """ + ``` + Shortest Codex solution: + ```python + + return ''.join((''.join(x) for x in zip(*(x*1000 for x in substrings)))) + + ``` + Longest Codex solution: + ```python + + solution = ''.join(''.join(c) for c in zip(*(s*1000 for s in substrings))) + for _ in range(1000): + if sat(solution, substrings): + return solution + solution = list(solution) + for i in range(len(substrings)-1): + solution.insert((i+1)*1000, f'{substrings[i]}-') + solution = ''.join(solution) + assert False + + ``` + Hand-written solution: + ```python + m = max(len(s) for s in substrings) + return "".join([(s[i] if i < len(s) else " ") for i in range(m) for s in substrings]) + ``` +
+ +* **LineIntersection** (5 instances) + + ```python + def sat(e: List[int], a=2, b=-1, c=1, d=2021): + x = e[0] / e[1] + return abs(a * x + b - c * x - d) < 10 ** -5 + ``` +
0.033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=2, b=-1, c=1, d=2021): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find the intersection of two lines. + Solution should be a list of the (x,y) coordinates. + Accuracy of fifth decimal digit is required. + """ + ``` + Shortest Codex solution: + ```python + + return [d - b, c] + + ``` + Longest Codex solution: + ```python + + for x in range(1, 10000): + if sat([x, 1], a, b, c, d): + return [x, 1] + if sat([10000 - x, 1], a, b, c, d): + return [10000 - x, 1] + if sat([x, 10000], a, b, c, d): + return [x, 10000] + if sat([10000 - x, 10000], a, b, c, d): + return [10000 - x, 10000] + + ``` + Hand-written solution: + ```python + return [d - b, a - c] + ``` +
+ +* **SublistSum** (5 instances) + + ```python + def sat(x: List[int], t=677, a=43, e=125, s=10): + non_zero = [z for z in x if z != 0] + return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all( + [x[i] != 0 for i in range(a, e, s)]) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(t=677, a=43, e=125, s=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """Sum values of sublist by range specifications""" + ``` + Hand-written solution: + ```python + x = [0] * e + for i in range(a, e, s): + x[i] = i + correction = t - sum(x) + x[i] + if correction in x: + x[correction] = -1 * correction + x[i] = 3 * correction + else: + x[i] = correction + return x + ``` +
+ +## chess -
+Classic chess puzzles -### DiscreteLog -Discrete Log +* **EightQueensOrFewer** Eight (or fewer) Queens Puzzle + + See Wikipedia entry on + [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle). + + See the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat + + Hint: a brute force approach works on this puzzle. (5 instances) + + ```python + def sat(squares: List[List[int]], m=8, n=8): + k = min(m, n) + assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k + return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}) + ``` +
0.0067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=8, n=8): + ``` + Solution docstring (*not* usually provided) + + ```python + """Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.""" + ``` + Shortest Codex solution: + ```python + + return [ + [0, 0], [1, 4], [2, 7], [3, 5], [4, 2], [5, 6], [6, 1], [7, 3] + ][:min(m, n)] + + ``` + Longest Codex solution: + ```python + + if m == 8 and n == 8: + return [[0, 0], [1, 4], [2, 7], [3, 5], [4, 2], [5, 6], [6, 1], [7, 3]] + else: + return {(i, j) for j in range(n) for i in range(m) if m == n and i < j and i + j < m} + + ``` + Hand-written solution: + ```python + # brute force + k = min(m, n) + + from itertools import permutations + for p in permutations(range(k)): + if 4 * k == len( + {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}): + return [[i, j] for i, j in enumerate(p)] + ``` +
+ +* **MoreQueens** See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle). + + A brute force approach will not work on many of these problems. (5 instances) + + ```python + def sat(squares: List[List[int]], m=9, n=9): + k = min(m, n) + assert all(i in range(m) and j in range(n) for i, j in squares), "queen off board" + assert len(squares) == k, "Wrong number of queens" + assert len({i for i, j in squares}) == k, "Queens on same row" + assert len({j for i, j in squares}) == k, "Queens on same file" + assert len({i + j for i, j in squares}) == k, "Queens on same SE diagonal" + assert len({i - j for i, j in squares}) == k, "Queens on same NE diagonal" + return True + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=9, n=9): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other. + """ + ``` + Hand-written solution: + ```python + t = min(m, n) + ans = [] + if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k) + ans.append([t - 1, t - 1]) + t -= 1 + if t % 6 == 2: # do something special for 8x8, 14x14 etc: + ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)] + ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)] + else: + ans += [[i, 2 * i + 1] for i in range(t // 2)] + ans += [[i + t // 2, 2 * i] for i in range(t // 2)] + return ans + ``` +
+ +* **KnightsTour** See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour) (5 instances) + + ```python + def sat(tour: List[List[int]], m=8, n=8): + assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves' + return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(m=8, n=8): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an (open) tour of knight moves on an m x n chess-board that visits each square once.""" + ``` + Hand-written solution: + ```python + # using Warnsdorff's heuristic, breaking ties randomly + import random + for seed in range(100): + r = random.Random(seed) + ans = [(0, 0)] + free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)} + + def possible(i, j): + moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]] + return [z for z in moves if z in free] + + while True: + if not free: + return [[a, b] for (a, b) in ans] + candidates = possible(*ans[-1]) + if not candidates: + break + ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random())) + free.remove(ans[-1]) + ``` +
+ +* **UncrossedKnightsPath** Uncrossed Knights Path (known solvable, but no solution given) + + The goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/) + (accessed 2020-11-29). + + A more precise description is in this + [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path). (5 instances) + + ```python + def sat(path: List[List[int]], m=8, n=8, target=35): + def legal_move(m): + (a, b), (i, j) = m + return {abs(i - a), abs(j - b)} == {1, 2} + + def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5 + (i1, j1), (i2, j2) = m1 + (a1, b1), (a2, b2) = m2 + return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore + or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel + or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5 + # far + ) + + assert all(i in range(m) and j in range(n) for i, j in path), "move off board" + assert len({(i, j) for i, j in path}) == len(path), "visited same square twice" + + moves = list(zip(path, path[1:])) + assert all(legal_move(m) for m in moves), "illegal move" + assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), "intersecting move pair" + + return len(path) >= target + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(m=8, n=8, target=35): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.""" + ``` +
+ +* **UNSOLVED_UncrossedKnightsPath** Uncrossed Knights Path (open problem, unsolved) + + Similar to above, but the goal of these problems is to *beat* the nxn_records from + [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/) + (accessed 2020-11-29). + + A more precise description is in this + [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path). (4 instances) + + ```python + def sat(path: List[List[int]], m=10, n=10, target=62): + def legal_move(m): + (a, b), (i, j) = m + return {abs(i - a), abs(j - b)} == {1, 2} + + def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5 + (i1, j1), (i2, j2) = m1 + (a1, b1), (a2, b2) = m2 + return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore + or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel + or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5 + # far + ) + + assert all(i in range(m) and j in range(n) for i, j in path), "move off board" + assert len({(i, j) for i, j in path}) == len(path), "visited same square twice" + + moves = list(zip(path, path[1:])) + assert all(legal_move(m) for m in moves), "illegal move" + assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), "intersecting move pair" + + return len(path) >= target + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(m=10, n=10, target=62): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.""" + ``` +
+ +## compression -The discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that: +Puzzles relating to de/compression. -`g ** n % p == t` +* **LZW** We have provided a simple version of the *decompression* algorithm of + [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) + so the solution is the *compression* algorithm. (5 instances) + + ```python + def sat(seq: List[int], compressed_len=17, text="Hellooooooooooooooooooooo world!"): + index = [chr(i) for i in range(256)] + pieces = [""] + for i in seq: + pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i]) + index.append(pieces[-2] + pieces[-1][0]) + return "".join(pieces) == text and len(seq) <= compressed_len + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(compressed_len=17, text="Hellooooooooooooooooooooo world!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a (short) compression that decompresses to the given string for the provided implementation of the + Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch + """ + ``` + Hand-written solution: + ```python + # compressed_len is ignored + index = {chr(i): i for i in range(256)} + seq = [] + buffer = "" + for c in text: + if buffer + c in index: + buffer += c + continue + seq.append(index[buffer]) + index[buffer + c] = len(index) + 1 + buffer = c + + if text != "": + seq.append(index[buffer]) + + return seq + ``` +
+ +* **PackingHam** This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces) + in coding theory. (5 instances) + + ```python + def sat(words: List[str], num=100, bits=100, dist=34): + assert len(words) == num and all(len(word) == bits and set(word) <= {"0", "1"} for word in words) + return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i)) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(num=100, bits=100, dist=34): + ``` + Solution docstring (*not* usually provided) + + ```python + """Pack a certain number of binary strings so that they have a minimum hamming distance between each other.""" + ``` + Hand-written solution: + ```python + import random # key insight, use randomness! + r = random.Random(0) + while True: + seqs = [r.getrandbits(bits) for _ in range(num)] + if all(bin(seqs[i] ^ seqs[j]).count("1") >= dist for i in range(num) for j in range(i)): + return [bin(s)[2:].rjust(bits, '0') for s in seqs] + ``` +
+ +## conways_game_of_life -From [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records): +Conway's Game of Life problems (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) -"Several important algorithms in public-key cryptography base their security on the assumption -that the discrete logarithm problem over carefully chosen problems has no efficient solution." +* **Spaceship** Spaceship (including *unsolved*, open problems) + + Find a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in + [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) + with a certain period. + + This is an *unsolved* problem for periods 33, 34. (4 instances) + + ```python + def sat(init: List[List[int]], period=4): + live = {x + y * 1j for x, y in init} # use complex numbers + init_tot = sum(live) + target = {z * len(live) - init_tot for z in live} + deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) + + for t in range(period): + visible = {z + d for z in live for d in deltas} + live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3} + tot = sum(live) + if {z * len(live) - tot for z in live} == target: + return t + 1 == period and tot != init_tot + ``` +
0.0067% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(period=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a "spaceship" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's + Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period + """ + ``` + Shortest Codex solution: + ```python + + return [[1,2], [2,3], [3,1], [3,2], [3,3]] + + ``` + Longest Codex solution: + ```python + + init = [[0, 1, 0], [0, 0, 1], [1, 1, 1]] + return [[x, y - 1] for y, v in enumerate(init) for x, c in enumerate(v) if c] + + ``` +
+ +* **Oscillators** Oscillators (including some unsolved, open problems) + + This problem is *unsolved* for periods 19, 38, and 41. + + See + [discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life ) + in Wikipedia article on Cellular Automaton Oscillators. (4 instances) + + ```python + def sat(init: List[List[int]], period=3): + target = {x + y * 1j for x, y in init} # complex numbers encode live cells + + deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) + live = target + for t in range(period): + visible = {z + d for z in live for d in deltas} + live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} + if live == target: + return t + 1 == period + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(period=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats + with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life + """ + ``` + Hand-written solution: + ```python + # # generate random patterns, slow solution + # def viz(live): + # if not live: + # return + # a, b = min(z.real for z in live), min(z.imag for z in live) + # live = {z - (a + b * 1j) for z in live} + # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1 + # for x in range(m): + # print("".join("X" if x + y * 1j in live else "," for y in range(n))) + + import random + rand = random.Random(1) + # print(f"Looking for {period}:") + deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) + + completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)] + + for _attempt in range(10 ** 5): + n = rand.randrange(3, 10) + m = rand.randrange(3, n * n) + live = set(rand.sample(completes[n], m)) + if rand.randrange(2): + live.update([-z for z in live]) + if rand.randrange(2): + live.update([z.conjugate() for z in live]) + memory = {} + for step in range(period * 10): + key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5 + key = int(key.real), int(key.imag) + if key in memory: + if memory[key] == step - period: + # print(period) + # viz(live) + return [[int(z.real), int(z.imag)] for z in live] + break + memory[key] = step + visible = {z + d for z in live for d in deltas} + live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)} + + return None # failed + ``` +
+ +* **ReverseLifeStep** Unsolvable for "Garden of Eden" positions, but we only generate solvable examples (5 instances) + + ```python + def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]): + live = {x + y * 1j for x, y in position} # complex numbers encode live cells + deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) + visible = {z + d for z in live for d in deltas} + next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} + return next_step == {x + y * 1j for x, y in target} + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=[[1, 3], [1, 4], [2, 5]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ), + specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step. + """ + ``` + Hand-written solution: + ```python + # fixed-temperature MC optimization + TEMP = 0.05 + import random + rand = random.Random(0) # set seed but don't interfere with other random uses + target = {x + y * 1j for x, y in target} + deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j) + + def distance(live): + visible = {z + d for z in live for d in deltas} + next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])} + return len(next_step.symmetric_difference(target)) + + for step in range(10 ** 5): + if step % 10000 == 0: + pos = target.copy() # start with the target position + cur_dist = distance(pos) + + if cur_dist == 0: + return [[int(z.real), int(z.imag)] for z in pos] + z = rand.choice([z + d for z in pos.union(target) for d in deltas]) + dist = distance(pos.symmetric_difference({z})) + if rand.random() <= TEMP ** (dist - cur_dist): + pos.symmetric_difference_update({z}) + cur_dist = dist + print('Failed', len(target), step) + ``` +
+ +## games -The problem is *unsolved* in the sense that no known polynomial-time algorithm has been found. -We include McCurley's discrete log challenge from -[Weber D., Denny T. (1998) "The solution of McCurley's discrete log challenge."](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf) +Some two-player game problems and hard game theory problems -```python -def sat(n: int, g=3, p=17, t=13): - """Find n such that g^n is congruent to t mod n""" - return pow(g, n, p) == t -``` -
1 solution to number_theory 10/16 -```python -def sol(g=3, p=17, t=13): - for n in range(p): - if pow(g, n, p) == t: - return n - assert False, f"unsolvable discrete log problem g={g}, t={t}, p={p}" -``` +* **RockPaperScissors** (1 instance) + + ```python + def sat(probs: List[float]): + assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6 + return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6 + ``` +
26% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find optimal probabilities for playing Rock-Paper-Scissors zero-sum game, with best worst-case guarantee""" + ``` + Shortest Codex solution: + ```python + + return [1/3]*3 + ``` + Longest Codex solution: + ```python + + probs = [1/3] * 3 + T, best_probs = 0, probs.copy() + while True: + T += 1 + worst_probs = [probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)] + probs = [x + y for x, y in zip(probs, worst_probs)] + probs = [x / T for x in probs] + if probs == best_probs: + return probs + else: + best_probs = probs.copy() + + ``` + Hand-written solution: + ```python + return [1 / 3] * 3 + ``` +
+ +* **Nim** Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim) + + Nim has an elegant theory for optimal play based on the xor of the bits in the heaps. + + Instead of writing a program that plays the game interactively (since interaction is not allowed), we require + them to determine winning states or beat a certain opponent. (5 instances) + + ```python + def sat(moves: List[List[int]], initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]): + + def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap + vals = sorted(state, reverse=True) + i_largest = state.index(vals[0]) # largest heap + state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie + + state = initial_state[:] # copy + for i, n in moves: + assert 0 < n <= state[i], "Illegal move" + state[i] -= n + if set(state) == {0}: + return True # you won! + assert any(state), "You lost!" + bot_move() + ``` +
0.0033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn + removing one or more objects from a single non-empty heap. The player who takes the last object wins. + - initial_state is list of numbers of objects in each heap + - moves is a list of your moves: [heap, number of objects to take] + - you play first + """ + ``` + Codex solution: + ```python + + state = initial_state[:] + moves = [] + while any(state): + largest = max(state) + moves.append([state.index(largest), largest]) + state[state.index(largest)] = 0 + if set(state) == {0}: + return moves + + def bot_move(): + vals = sorted(state, reverse=True) + i_largest = state.index(vals[0]) + state[i_largest] -= max(vals[0] - vals[1], 1) + + bot_move() + + return moves + + ``` + Hand-written solution: + ```python + + state = initial_state[:] + moves = [] + + def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap + vals = sorted(state, reverse=True) + i_largest = state.index(vals[0]) # largest heap + state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie + + def losing(h): # return True if h is a losing state + xor = 0 + for i in h: + xor ^= i + return xor == 0 + + def optimal_move(): + assert not losing(state) + for i in range(len(state)): + for n in range(1, state[i] + 1): + state[i] -= n + if losing(state): + moves.append([i, n]) + return + state[i] += n + assert False, "Shouldn't reach hear" + + while True: + optimal_move() + if max(state) == 0: + return moves + bot_move() + ``` +
+ +* **Mastermind** Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29) + in a given number of guesses. + + Instead of writing a program that plays the game interactively (since interaction is not allowed), we require + them to provide a provable winning game tree. (3 instances) + + ```python + def sat(transcripts: List[str], max_moves=10): + COLORS = "ABCDEF" + + def helper(secret: str, transcript=""): + if transcript.count("\n") == max_moves: + return False + guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:] + if guess == secret: + return True + assert all(g in COLORS for g in guess) + perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS} + almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS) + return helper(secret, transcript + f"{guess} {sum(perfect.values())}{almost}\n") + + return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(max_moves=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F. + The solution representation is as follows. + A transcript is a string describing the game so far. It consists of rows separated by newlines. + Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right + and how many are right but in the wrong location. A sample transcript is as follows: + AABB 11 + ABCD 21 + ABDC + + This is the transcript as the game is in progress. The complete transcript might be: + AABB 11 + ABCD 21 + ABDC 30 + ABDE 40 + + A winning strategy is described by a list of transcripts to visit. The next guess can be determined from + those partial transcripts. + """ + ``` + Hand-written solution: + ```python + COLORS = "ABCDEF" + + transcripts = [] + + ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS] + + def score(secret, guess): + perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS} + almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS) + return f"{sum(perfect.values())}{almost}" + + def mastermind(transcript="AABB", feasible=ALL): # mastermind moves + transcripts.append(transcript) + assert transcript.count("\n") <= max_moves + guess = transcript[-4:] + feasibles = {} + for secret in feasible: + scr = score(secret, guess) + if scr not in feasibles: + feasibles[scr] = [] + feasibles[scr].append(secret) + for scr, secrets in feasibles.items(): + if scr != "40": + guesser(transcript + f" {scr}\n", secrets) + + def guesser(transcript, feasible): # guesser moves + def max_ambiguity(guess): + by_score = {} + for secret2 in feasible: + scr = score(secret2, guess) + if scr not in by_score: + by_score[scr] = 0 + by_score[scr] += 1 + # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of: + return max(by_score.values()) + + # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of: + guess = min(feasible, key=max_ambiguity) + + mastermind(transcript + guess, feasible) + + mastermind() + + return transcripts + ``` +
+ +* **TicTacToeX** Since we don't have interaction, this problem asks for a full tie-guranteeing strategy. (1 instance) + + ```python + def sat(good_boards: List[str]): + board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in "XO") for b in good_boards} + win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] + + def tie(x, o): # returns True if X has a forced tie/win assuming it's X's turn to move. + x |= 1 << [i for i in range(9) if (x | (1 << i), o) in board_bit_reps][0] + return not win[o] and (win[x] or all((x | o) & (1 << i) or tie(x, o | (1 << i)) for i in range(9))) + + return tie(0, 0) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Compute a strategy for X (first player) in tic-tac-toe that guarantees a tie. That is a strategy for X that, + no matter what the opponent does, X does not lose. + + A board is represented as a 9-char string like an X in the middle would be "....X...." and a + move is an integer 0-8. The answer is a list of "good boards" that X aims for, so no matter what O does there + is always good board that X can get to with a single move. + """ + ``` + Hand-written solution: + ```python + win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation + + good_boards = [] + + def x_move(x, o): # returns True if x wins or ties, x's turn to move + if win[o]: + return False + if x | o == 511: + return True + for i in range(9): + if (x | o) & (1 << i) == 0 and o_move(x | (1 << i), o): + good_boards.append("".join(".XO"[((x >> j) & 1) + 2 * ((o >> j) & 1) + (i == j)] for j in range(9))) + return True + return False # O wins + + def o_move(x, o): # returns True if x wins or ties, x's turn to move + if win[x] or x | o == 511: # full board + return True + for i in range(9): + if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)): + return False + return True # O wins + + res = x_move(0, 0) + assert res + + return good_boards + ``` +
+ +* **TicTacToeO** Same as above but for 2nd player (1 instance) + + ```python + def sat(good_boards: List[str]): + board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in "XO") for b in good_boards} + win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] + + def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move. + if o | x != 511: # complete board + o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0] + return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9))) + + return all(tie(1 << i, 0) for i in range(9)) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Compute a strategy for O (second player) in tic-tac-toe that guarantees a tie. That is a strategy for O that, + no matter what the opponent does, O does not lose. + + A board is represented as a 9-char string like an X in the middle would be "....X...." and a + move is an integer 0-8. The answer is a list of "good boards" that O aims for, so no matter what X does there + is always good board that O can get to with a single move. + """ + ``` + Hand-written solution: + ```python + win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation + + good_boards = [] + + def x_move(x, o): # returns True if o wins or ties, x's turn to move + if win[o] or x | o == 511: # full board + return True + for i in range(9): + if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o): + return False + return True # O wins/ties + + def o_move(x, o): # returns True if o wins or ties, o's turn to move + if win[x]: + return False + if x | o == 511: + return True + for i in range(9): + if (x | o) & (1 << i) == 0 and x_move(x, o | (1 << i)): + good_boards.append( + "".join(".XO"[((x >> j) & 1) + 2 * ((o >> j) & 1) + 2 * (i == j)] for j in range(9))) + return True + return False # X wins + + res = x_move(0, 0) + assert res + + return good_boards + ``` +
+ +* **Nash** Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given + [bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be + PPAD-hard in general. However, the challenge is be much easier for an approximate + [eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games. (5 instances) + + ```python + def sat(strategies: List[List[float]], A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01): + m, n = len(A), len(A[0]) + p, q = strategies + assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B. + For example, for the classic Prisoner dilemma: + A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]] + + eps is the error tolerance + """ + ``` + Hand-written solution: + ```python + NUM_ATTEMPTS = 10 ** 5 + + def sat(strategies: List[List[float]], A, B, eps): + m, n = len(A), len(A[0]) + p, q = strategies + assert len(B) == m and all(len(row) == n for row in A + B), "inputs are a bimatrix game" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n))) + + import random + r = random.Random(0) + dims = len(A), len(A[0]) + # possible speedup: remove dominated strategies + for _attempt in range(NUM_ATTEMPTS): + strategies = [] + for d in dims: + s = [max(0.0, r.random() - 0.5) for _ in range(d)] + tot = sum(s) + 1e-6 + for i in range(d): + s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0 + strategies.append(s) + if sat(strategies, A, B, eps): + return strategies + ``` +
+ +* **ZeroSum** Compute minimax optimal strategies for a given + [zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to + Linear Programming. Note that the provided instances are all quite easy---harder solutions could readily + be made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and + more efficient algorithms would be needed. (5 instances) + + ```python + def sat(strategies: List[List[float]], A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01): + m, n = len(A), len(A[0]) + p, q = strategies + assert all(len(row) == n for row in A), "inputs are a matrix" + assert len(p) == m and len(q) == n, "solution is a pair of strategies" + assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, "strategies must be non-negative and sum to 1" + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps. + For example, rock paper scissors has + A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2 + """ + ``` + Hand-written solution: + ```python + MAX_ITER = 10 ** 4 + m, n = len(A), len(A[0]) + a = [0 for _i in range(m)] + b = [0 for _j in range(n)] + + for count in range(1, MAX_ITER): + i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n))) + j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m))) + a[i_star] += 1 + b[j_star] += 1 + p = [x / (count + 1e-6) for x in a] + p[-1] = 1 - sum(p[:-1]) # rounding issues + q = [x / (count + 1e-6) for x in b] + q[-1] = 1 - sum(q[:-1]) # rounding issues + + v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n)) + if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and + all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))): + return [p, q] + ``` +
+ +## graphs -
+Problems related to graphs such as Conway's 99 problem, finding +[cliques](https://en.wikipedia.org/wiki/Clique_(graph_theory)) of various sizes, shortest path (Dijkstra) -### GCD17 -According to [this article](https://primes.utm.edu/glossary/page.php?sort=LawOfSmall), the smallest -solution is 8424432925592889329288197322308900672459420460792433 +* **AnyEdge** Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem. (5 instances) + + ```python + def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]): + return e in edges + ``` +
41% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find any edge in edges.""" + ``` + Shortest Codex solution: + ```python + return [0, 217] + ``` + Longest Codex solution: + ```python + + assert any(sat(e, edges=edges) for e in edges) + return edges[0] # hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack hack + ``` + Hand-written solution: + ```python + return edges[0] + ``` +
+ +* **ShortestPath** Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm] (5 instances) + + ```python + def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11): + return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound + ``` +
7.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a path from node 0 to node 1, of length at most bound, in the given digraph. + weights[a][b] is weight on edge [a,b] for (int) nodes a, b + """ + ``` + Shortest Codex solution: + ```python + + return [0,2,1] + + ``` + Longest Codex solution: + ```python + + current_cost = 0 + frontier = [0] + explored = [0] + while frontier: + current_node = frontier.pop(0) + if len(explored) == len(weights): + return explored + for neighbor in weights[current_node]: + new_cost = current_cost + weights[current_node][neighbor] + if neighbor not in explored and new_cost <= bound: + frontier.append(neighbor) + explored.append(neighbor) + if neighbor == 1: + return explored + + ``` + Hand-written solution: + ```python + # Dijkstra's algorithm (bound is ignored) + u, v = 0, 1 # go from 0 to 1 + import heapq + queue = [(0, u, u)] # distance, node, trail + + trails = {} + + while queue: + dist, i, j = heapq.heappop(queue) + if i in trails: + continue + trails[i] = j + if i == v: + break + for j in weights[i]: + if j not in trails: + heapq.heappush(queue, (dist + weights[i][j], j, i)) + if v in trails: + rev_path = [v] + while rev_path[-1] != u: + rev_path.append(trails[rev_path[-1]]) + return rev_path[::-1] + ``` +
+ +* **AnyPath** Any Path (5 instances) + + ```python + def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): + for i in range(len(path) - 1): + assert [path[i], path[i + 1]] in edges + assert path[0] == 0 + assert path[-1] == max(max(edge) for edge in edges) + return True + ``` +
2.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.""" + ``` + Shortest Codex solution: + ```python + + return [0,2,5,6,7] + + ``` + Longest Codex solution: + ```python + + def createPath(graph): + start = next(x for x in graph if x[0] == 0) + if start in graph: + path = [start[0]] + graph.remove(start) + while True: + edges = [] + for edge in graph: + if edge[0] in path: + edges.append(edge) + if not edges: + return path + nextEdge = min(edges, key=lambda x: x[1]) + path.append(nextEdge[1]) + graph.remove(nextEdge) + return [] + return createPath(edges) + + ``` + Hand-written solution: + ```python + n = max(max(edge) for edge in edges) + paths = {0: [0]} + for _ in range(n + 1): + for i, j in edges: + if i in paths and j not in paths: + paths[j] = paths[i] + [j] + return paths.get(n) + ``` +
+ +* **AnyTriangle** Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem, + see [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph) (5 instances) + + ```python + def sat(tri: List[int], edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): + a, b, c = tri + return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a + ``` +
2.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find any triangle in the given directed graph.""" + ``` + Shortest Codex solution: + ```python + + return [17,22,31] + + ``` + Longest Codex solution: + ```python + + # How can we check that edges connects all the points in the graph? + # It is already in reader graph, though it is not explicitly mentioned in the description. + # There is an explicit sequence in the description: + # 17 goes in, in the same direction A and in the graph + # 22 in the graph and in the same direction A, in the direction of 17 + # 31 in the graph and in the same direction A, in the direction of 17 + # at the end the same cycle as the description + return [17, 22, 31] + + ``` + Hand-written solution: + ```python + from collections import defaultdict + outs = defaultdict(set) + ins = defaultdict(set) + for i, j in edges: + if j != i: + outs[i].add(j) + ins[j].add(i) + for i in outs: + for j in outs[i]: + try: + if j in outs: + k = min(outs[j].intersection(ins[i])) + return [i, j, k] + except ValueError: + pass + ``` +
+ +* **PlantedClique** Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size + in an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for + some time. (5 instances) + + ```python + def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): + assert len(nodes) == len(set(nodes)) >= size + edge_set = {(a, b) for (a, b) in edges} + for a in nodes: + for b in nodes: + assert a == b or (a, b) in edge_set or (b, a) in edge_set + + return True + ``` +
2.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.""" + ``` + Shortest Codex solution: + ```python + + return [0,17,22] + + ``` + Longest Codex solution: + ```python + + # It suffices to go over each node, the generate all possible cliques, check them, and return the first that is + # correct. + vertices = {a for (a, _) in edges} | {b for (_, b) in edges} + for v in vertices: + nodes = [v] + for nn in vertices.difference({v}): + nodes.append(nn) + if len(nodes) == size: + if sat(nodes, size, edges): + return nodes + else: + for nnn in vertices.difference(nodes): + nodes.append + ``` + Hand-written solution: + ```python + # brute force (finds list in increasing order), but with a tiny bit of speedup + if size == 0: + return [] + from collections import defaultdict + neighbors = defaultdict(set) + n = max(max(e) for e in edges) + for (a, b) in edges: + if a != b: + neighbors[a].add(b) + neighbors[b].add(a) + pools = [list(range(n + 1))] + indices = [-1] + while pools: + indices[-1] += 1 + if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order + indices.pop() + pools.pop() + continue + if len(pools) == size: + return [pool[i] for pool, i in zip(pools, indices)] + a = (pools[-1])[indices[-1]] + pools.append([i for i in pools[-1] if i > a and i in neighbors[a]]) + indices.append(-1) + assert False, f"No clique of size {size}" + ``` +
+ +* **UnweightedShortestPath** Unweighted Shortest Path + + See (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm] (5 instances) + + ```python + def sat(path: List[int], edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3): + assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:])) + return len(path) <= bound + ``` +
1.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.""" + ``` + Shortest Codex solution: + ```python + + return [0,22,33] + + ``` + Longest Codex solution: + ```python + + depth = bound + 1 + found = False + while not found: + depth += 1 + queue = [[u]] + while queue: + path = queue.pop() + if len(path) == depth: + break + for i, j in edges: + if i == path[-1]: + if j == v: + found = True + path.append(j) + path = path[path.index(u):] + return path + break + queue.append(path + [j]) + return "No path" + + ``` + Hand-written solution: + ```python + # Dijkstra's algorithm + import heapq + from collections import defaultdict + queue = [(0, u, u)] # distance, node, trail + + trails = {} + neighbors = defaultdict(set) + for (i, j) in edges: + neighbors[i].add(j) + + while queue: + dist, i, j = heapq.heappop(queue) + if i in trails: + continue + trails[i] = j + if i == v: + break + for j in neighbors[i]: + if j not in trails: + heapq.heappush(queue, (dist + 1, j, i)) + if v in trails: + rev_path = [v] + while rev_path[-1] != u: + rev_path.append(trails[rev_path[-1]]) + return rev_path[::-1] + ``` +
+ +* **EvenPath** (5 instances) + + ```python + def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): + assert path[0] == 0 and path[-1] == max(max(e) for e in edges) + assert all([[a, b] in edges for a, b in zip(path, path[1:])]) + return len(path) % 2 == 0 + ``` +
1.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.""" + ``` + Shortest Codex solution: + ```python + + return [0,1,2,5,6,7] + + ``` + Longest Codex solution: + ```python + + path = [0] + for node in set(max(e) for e in edges): + if node == path[-1]: continue + front, back = [], [] + for x in path: + front.append(x) + back.append(x) + path = [] + for end in set(max(edge) for edge in edges if edge[0] == back[-1]): + if end == front[-1]: continue + front.append(end) + back.append(end) + path = front + break + else: + path = front + return path + + ``` + Hand-written solution: + ```python + even_paths = {} + odd_paths = {0: [0]} + n = max(max(e) for e in edges) + for _ in range(n + 1): + for i, j in edges: + if i in even_paths and j not in odd_paths: + odd_paths[j] = even_paths[i] + [j] + if i in odd_paths and j not in even_paths: + even_paths[j] = odd_paths[i] + [j] + return even_paths.get(n) + ``` +
+ +* **OddPath** To make it even more different than EvenPath, we changed to go from node 0 to node *1*. (5 instances) + + ```python + def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]): + return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])]) + ``` +
0.38% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.""" + ``` + Shortest Codex solution: + ```python + + return [0,2,5,6,1] + + ``` + Longest Codex solution: + ```python + + i, j = 0, 1 + p = [0] + while j < len(edges): + k = -1 + for a, b in edges: + if i in [a, b]: + k = b + if b in p: + edges.remove([a, b]) + break + if k in p: + p.remove(k) + p.append(k) + i, j = k, j+1 + p.append(1) + return p + + ``` + Hand-written solution: + ```python + even_paths = {} + odd_paths = {0: [0]} + n = 1 + for _ in range(max(max(e) for e in edges) + 1): + for i, j in edges: + if i in even_paths and j not in odd_paths: + odd_paths[j] = even_paths[i] + [j] + if i in odd_paths and j not in even_paths: + even_paths[j] = odd_paths[i] + [j] + return odd_paths.get(n) + ``` +
+ +* **GraphIsomorphism** The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem. + It is unknown whether or not there exists a polynomial-time algorithm + for this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai. + + The classic version is a decision problem: given two graphs, determine whether or not they are isomorphic. + However, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you + could solve the search problem below (finding the actual bijection), then you can decide isomorphism because the + search solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem, + then you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node + in the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to + itself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph. + For each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps + the first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not + allowed, one can do this by adding N additional nodes for each test. (5 instances) + + ```python + def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]): + return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2} + ``` +
0.017% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + You are given two graphs which are permutations of one another and the goal is to find the permutation. + Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers. + """ + ``` + Shortest Codex solution: + ```python + + return [0, 2, 3, 4, 1, 5] + + ``` + Longest Codex solution: + ```python + + + def search(bi, l): + if len(bi) == 6: + return bi if sat(bi, g1, g2) else -1 + for i in range(len(l)): + b = list(bi) + b.append(l[i]) + r = search(b, [e for e in l if e != l[i]]) + if r != -1: return r + return -1 + + return search([], [0, 1, 2, 3, 4, 5]) + + ``` + Hand-written solution: + ```python + # exponentially slow + from itertools import permutations + n = max(i for g in [g1, g2] for e in g for i in e) + 1 + g1_set = {(i, j) for i, j in g1} + for pi in permutations(range(n)): + if all((pi[i], pi[j]) in g1_set for i, j in g2): + return list(pi) + assert False, f"Graphs are not isomorphic {g1}, {g2}" + ``` +
+ +* **Conway99** Conway's 99-graph problem (*unsolved*, open problem) + + Conway's 99-graph problem is an unsolved problem in graph theory. + In Conway's terminology, from [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf) + "Is there a graph with 99 vertices in which every edge (i.e. pair of joined vertices) belongs to a unique + triangle and every nonedge (pair of unjoined vertices) to a unique quadrilateral?" + + See also this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem). (1 instance) + + ```python + def sat(edges: List[List[int]]): + # first compute neighbors sets, N: + N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)} + return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i)) + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common + neighbor, and in which each two non-adjacent vertices have exactly two common neighbors. + """ + ``` +
+ +* **Zarankiewicz** [Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem) (3 instances) + + ```python + def sat(edges: List[List[int]], z=20, n=5, t=3): + from itertools import combinations + edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency + assert len(edges) >= z + + return all( + any((a, b) not in edges for a in left for b in right) + for left in combinations(range(n), t) + for right in combinations(range(n), t) + ) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(z=20, n=5, t=3): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.""" + ``` + Hand-written solution: + ```python + from itertools import combinations + all_edges = [(a, b) for a in range(n) for b in range(n)] + for edges in combinations(all_edges, z): + edge_set = set(edges) + if all(any((a, b) not in edge_set for a in left for b in right) + for left in combinations(range(n), t) + for right in combinations(range(n), t)): + return [[a, b] for a, b in edges] + ``` +
+ +* **ShortIntegerPath** This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph + defined by the integer pairs. (1 instance) + + ```python + def sat(li: List[int]): + return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) and len(li) == 9 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a list of nine integers, starting with 0 and ending with 128, such that each integer either differs from + the previous one by one or is thrice the previous one. + """ + ``` + Hand-written solution: + ```python + return [1, 3, 4, 12, 13, 14, 42, 126, 127] + ``` +
+ +## ICPC -```python -def sat(n: int): - """Find n for which gcd(n^17+9, (n+1)^17+9) != 1""" - i = n ** 17 + 9 - j = (n + 1) ** 17 + 9 - while i != 0: # compute gcd using Euclid's algorithm - (i, j) = (j % i, i) +Problems inspired by the [International Collegiate Programming Contest](https://icpc.global) (ICPC). - return n >= 0 and j != 1 -``` -0 solutions to number_theory 11/16 -### Znam -[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem) +* **MatchingMarkers** Inspired by + [ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) + + This is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time). (5 instances) + + ```python + def sat(cut_position: int, ring="yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM", lower=5): + line = ring[cut_position:] + ring[:cut_position] + matches = {c: 0 for c in line.lower()} + for c in line: + if c.islower(): + matches[c] -= (1 if matches[c] > 0 else len(line)) + else: + matches[c.lower()] += 1 + return sum(i == 0 for i in matches.values()) >= lower + ``` +
37% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(ring="yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM", lower=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + The input is a string of start and end markers "aaBAcGeg" where upper-case characters indicate start markers + and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is + to find a location to split the ring so that there are a maximal number of matched start/end chars where a character + (like "a"/"A") is matched if starting at the split and going around the ring, the start-end pairs form a valid + nesting like nested parentheses. Can you solve it in linear time? + """ + ``` + Shortest Codex solution: + ```python + + return 5 + ``` + Longest Codex solution: + ```python + + indices = set(range(len(ring))) + for cut_position in range(len(ring)): + if sat(cut_position, ring, lower): + # The hope is that starting at cut_position and going around the loop the pairs form a valid nesting. + # Ideally we could break immediately after the break to speed up the search. + prev_position = cut_position-1 + while prev_position >= 0: + if ring[prev_position] != ring[cut_position]: + prev_position = prev_position - 1 + else: + break + if prev_position < 0: + return cut_position + ``` + Hand-written solution: + ```python + cumulatives = {c: [(0, 0)] for c in ring.lower()} + n = len(ring) + for i, c in enumerate(ring): + v = cumulatives[c.lower()] + v.append((i, v[-1][1] + (-1 if c.islower() else 1))) + + scores = [0]*n + cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0} + for c, v in cumulatives.items(): + if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes + continue + m = min(t for i, t in v) + for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]): + if t == m: + for j in range(i+1, i2+1): + scores[j % n] += 1 + b = max(scores) + for i in range(n): + if scores[i] == b: + return i + ``` +
+ +* **BiPermutations** Inspired by + [ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) + which is 2,287 characters. (5 instances) + + ```python + def sat(perms: List[List[int]], prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]): + n = len(prices0) + perm0, perm1 = perms + assert sorted(perm0) == sorted(perm1) == list(range(n)), "Solution must be two permutations" + for i in range(n - 1): + assert prices0[perm0[i]] <= prices0[perm0[i + 1]], "Permuted prices must be nondecreasing (row 0)" + assert prices1[perm1[i]] <= prices1[perm1[i + 1]], "Permuted prices must be nondecreasing (row 1)" + return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1)) + ``` +
0.013% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each + row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and + so that the first row is taller than the second row. + """ + ``` + Shortest Codex solution: + ```python + + n = len(prices0) + perm0 = sorted(range(n), key=lambda i: (prices1[i], prices0[i])) + perm1 = sorted(range(n), key=lambda i: (prices0[i], prices1[i])) + return [perm0, perm1] + + ``` + Longest Codex solution: + ```python + + perm0 = [i for i in range(len(prices0))] + perm0.sort(key=lambda n: prices0[n]*prices1[n]) + perm1 = [i for i in range(len(prices1))] + perm1.sort(key=lambda n: prices1[n]*prices0[n]) + return [perm0, perm1] + + ``` + Hand-written solution: + ```python + n = len(prices0) + prices = [prices0, prices1] + orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])), + sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))] + jumps = [1, 1] # next price increase locations + for i in range(n): + for r, (p, o) in enumerate(zip(prices, orders)): + while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]: + jumps[r] += 1 + + to_fix = orders[jumps[0] < jumps[1]] + j = i + while heights0[orders[0][i]] <= heights1[orders[1][i]]: + j += 1 + to_fix[i], to_fix[j] = to_fix[j], to_fix[i] + + return orders + ``` +
+ +* **OptimalBridges** Inspired by + [ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) + which is 3,003 characters. (5 instances) + + ```python + def sat(indices: List[int], H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020): + assert sorted({0, len(xs) - 1, *indices}) == indices, f"Ans. should be sorted list [0, ..., {len(xs) - 1}]" + cost = alpha * (H - ys[0]) + for i, j in zip(indices, indices[1:]): + a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2 + assert max(ys[i], ys[j]) + r <= H, "Bridge too tall" + assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \ + "Bridge too short" + cost += alpha * (H - ys[j]) + beta * (b - a) ** 2 + return cost <= thresh + ``` +
0.0033% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + You are to choose locations for bridge bases from among a given set of mountain peaks located at + `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted + list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges + are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that: + * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs + of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the + selected mountain peaks must both be at most `H - d/2`. + * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the + peak. See the code for how this is determined mathematically. + * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of + all pillar heights) + beta * (the sum of the squared diameters) + """ + ``` + Codex solution: + ```python + + indices: List[int] = [i for i, y in enumerate(ys) if y < H // 2] + if sat(indices, H, alpha, beta, xs, ys, thresh): + return indices + else: + return [-1] + + ``` + Hand-written solution: + ```python + # thresh is ignored + n = len(xs) + cost = [-1] * n + prior = [n] * n + cost[0] = beta * (H - ys[0]) + for i in range(n): + if cost[i] == -1: + continue + min_d = 0 + max_d = 2 * (H - ys[i]) + for j in range(i + 1, n): + d = xs[j] - xs[i] + h = H - ys[j] + if d > max_d: + break + if 2 * h <= d: + min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5)) + max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5)) + if min_d > max_d: + break + if min_d <= d <= max_d: + new_cost = cost[i] + alpha * h + beta * d * d + if cost[j] == -1 or cost[j] > new_cost: + cost[j] = new_cost + prior[j] = i + rev_ans = [n - 1] + while rev_ans[-1] != 0: + rev_ans.append(prior[rev_ans[-1]]) + return rev_ans[::-1] + ``` +
+ +* **CheckersPosition** Inspired by + [ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf) + + Nobody solved this problem during the competition -- it is pretty difficult! (5 instances) + + ```python + def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]): + board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty + for x, y, p in position: + assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king + board[x, y] = p + + def has_a_jump(x, y): + p = board[x, y] # piece to move + deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings + return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas) + + sign = 1 # player 1 moves first + for move in transcript: + start, end = tuple(move[0]), tuple(move[-1]) + p = board[start] # piece to move + assert p * sign > 0, "Moving square must be non-empty and players must be alternate signs" + assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), "Moved to an occupied square" + + for (x1, y1), (x2, y2) in zip(move, move[1:]): + assert abs(p) != 1 or (y2 - y1) * p > 0, "Non-kings can only move forward (in direction of sign)" + if abs(x2 - x1) == 1: # non-jump + assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), "Must make a jump if possible" + break + mid = ((x1 + x2) // 2, (y1 + y2) // 2) + assert board[mid] * p < 0, "Can only jump over piece of opposite sign" + board[mid] = 0 + board[start], board[end] = 0, p + assert abs(x2 - x1) == 1 or not has_a_jump(*end) + if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]): + board[end] *= 2 # king me at the end of turn after any jumps are done! + sign *= -1 + + return True + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + You are given a partial transcript a checkers game. Find an initial position such that the transcript + would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even. + There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript. + The initial position is represented as a list [x, y, piece] where piece means: + * 0 is empty square + * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively + * 2 or -2 is king for player 1 or player 2 respectively + + Additional rules: + * You must jump if you can, and you must continue jumping until one can't any longer. + * You cannot start the position with any non-kings on your last rank. + * Promotion happens after the turn ends + """ + ``` + Hand-written solution: + ```python + START_PLAYER = 1 # assumed + + class InitOpts: + def __init__(self, x, y): + self.x, self.y = x, y + self.opts = {-2, -1, 0, 1, 2} + if y == 0: + self.opts.remove(-1) + if y == 7: + self.opts.remove(1) + self.promoted = 2 ** 63 # on which step was it promoted t >= 0 + self.jumped = 2 ** 63 # on which step was it jumped t >= 0 + + # def board2str(board): # for debugging + # mapping = ".bBWw" + # ans = "" + # for y in range(7, -1, -1): + # ans += "".join(" " if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + "\n" + # return ans + + init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0} + # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if + # (x + y) % 2 == 0} # new board + + transcript = [[tuple(a) for a in move] for move in transcript] + + permuted_opts = init_opts.copy() + sign = START_PLAYER + for t, move in enumerate(transcript): + start, end = tuple(move[0]), tuple(move[-1]) + p = permuted_opts[start] # opts to move + assert p.jumped >= t + p.opts -= {-sign, -2 * sign, 0} + if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move! + if p.promoted >= t: + p.opts -= {sign} # must be a king! + + for a, b in zip(move, move[1:]): + if permuted_opts[b].jumped >= t: + permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty + assert permuted_opts[a].jumped >= t + permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a] + # board[a], board[b] = board[b], board[a] + (x1, y1), (x2, y2) = a, b + if abs(x2 - x1) == 2: # jump + mid = ((x1 + x2) // 2, (y1 + y2) // 2) + assert permuted_opts[mid].jumped >= t + permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign + permuted_opts[mid].jumped = t + # board[mid] = 0 + + if any(y in {0, 7} for x, y in move[1:]): + if p.promoted > t: + p.promoted = t + # if abs(board[x2, y2]) == 1: + # board[x2, y2] *= 2 + + sign *= -1 + + for y in range(7, -1, -1): + for x in range(8): + if (x, y) in init_opts: + s = init_opts[x, y].opts + if {1, 2} <= s: + s.remove(2) + if {-1, -2} <= s: + s.remove(-2) + + def helper(): # returns True if success and store everything, otherwise None + my_opts = init_opts.copy() + sign = START_PLAYER # player 1 always starts + + for t, move in enumerate(transcript): + if abs(move[0][0] - move[1][0]) == 1: # not a jump + check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}] + else: + for a, b in zip(move, move[1:]): + my_opts[a], my_opts[b] = my_opts[b], my_opts[a] + check_no_jumps = [b] + + for x, y in check_no_jumps: + p = my_opts[x, y] + [o] = p.opts + assert o * sign > 0 + dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps + for dx in [-1, 1]: + for dy in dys: + target_o = my_opts.get((x + 2 * dx, y + 2 * dy)) + if target_o is not None and (0 in target_o.opts or target_o.jumped < t): + mid_o = my_opts[x + dx, y + dy] + if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t + if target_o.jumped < t or target_o.opts == {0}: + return False + old_opts = target_o.opts + for v in target_o.opts: + if v != 0: + target_o.opts = {v} + h = helper() + if h: + return True + target_o.opts = old_opts + return False + + if abs(move[0][0] - move[1][0]) == 1: # not a jump + a, b = move[0], move[1] + my_opts[a], my_opts[b] = my_opts[b], my_opts[a] + + sign *= -1 + return True + + res = helper() + assert res + + def get_opt(opts): + if 0 in opts.opts: + return 0 + assert len(opts.opts) == 1 + return list(opts.opts)[0] + + return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()] + ``` +
+ +## IMO -For example [2, 3, 7, 47, 395] is a solution for k=5 +Problems inspired by the +[International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) +[problems](https://www.imo-official.org/problems.aspx) -```python -def sat(li: List[int], k=5): - """Find k positive integers such that each integer divides (the product of the rest plus 1).""" - def prod(nums): - ans = 1 - for i in nums: - ans *= i +* **FindRepeats** Note: This problem is much easier than the IMO problem which also required a proof that it is impossible + for a_0 not divisible by 3. + + Inspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx) (5 instances) + + ```python + def sat(indices: List[int], a0=123): + assert a0 >= 0 and a0 % 3 == 0, "Hint: a_0 is a multiple of 3." + s = [a0] + for i in range(max(indices)): + s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3) + return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1 + ``` +
0.88% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a0=123): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value + occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is: + a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise. + + For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal. + + Sample input: + 9 + + Sample output: + [0, 3, 6, ..., 2997] + + The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are + all equal in this case. + """ + ``` + Shortest Codex solution: + ```python + + return list(range(a0, a0+3000, 3)) + + ``` + Longest Codex solution: + ```python + + # Returns the first k indices where there are k elements, all of which are equal. + def find_occurrences(a0, k): + s = [a0] + a = a0 + while True: + a = int(a ** 0.5) if int(a ** 0.5) ** 2 == a else a + 3 + s.append(a) + if len(s) == k + 1: + return s[:k] + for i in range(1 << 2): + x = find_occurrences(a0 + i, 1000) + if sat(x): return x + + + ``` + Hand-written solution: + ```python + n = a0 + ans = [] + i = 0 + while len(ans) < 1000: + if n == 3: # use the fact that 3 will repeat infinitely often + ans.append(i) + n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3 + i += 1 + return ans + ``` +
+ +* **FindProductiveList** Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not + exists for non-multiples of 3. + + Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx) (5 instances) + + ```python + def sat(li: List[int], n=18): + assert n % 3 == 0, "Hint: n is a multiple of 3" + return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n)) + ``` +
0.0067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=18): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1 + where indices >= n "wrap around". Note: only n multiples of 3 are given since this is only possible for n + that are multiples of 3 (as proven in the IMO problem). + + Sample input: + 6 + + Sample output: + [_, _, _, _, _, _] + + (Sample output hidden because showing sample output would give away too much information.) + """ + ``` + Shortest Codex solution: + ```python + + li = [-1]*n + for i in range(n): + li[(i+2) % n] = 1 + li[(i+1) % n] * li[i] + return li + + ``` + Longest Codex solution: + ```python + + li = [-1] * n + for i in range(n): + li[i] = 1 + li[(i - 1) % n] * li[(i - 2) % n] + return li + + ``` + Hand-written solution: + ```python + return [-1, -1, 2] * (n // 3) + ``` +
+ +* **ExponentialCoinMoves** This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long. + + The version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big + for computers) but the solution is quite similar to the solution to the IMO problem. Because the solution + requires exponential many moves, our representation allows combining multiple Type-1 (advance) operations + into a single step. + + Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx) (5 instances) + + ```python + def sat(states: List[List[int]], n=16385): + assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li) + for prev, cur in zip(states, states[1:]): + for i in range(5): + if cur[i] != prev[i]: + break + assert cur[i] < prev[i] + assert ( + cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements + or + cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap + ) + + return states[-1][-1] == 2 ** n + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=16385): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + There are five boxes each having one coin initially. Two types of moves are allowed: + * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1` + * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2` + Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box. + Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last + box. Encode each state as a list of the numbers of coins in the five boxes. + + Sample Input: + `n = 2` + + Sample Output: + `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]` + + The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps. + + states is encoded by lists of 5 coin counts + """ + ``` + Hand-written solution: + ```python + assert n >= 1 + ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0], + [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]] + + def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0 + state = ans[-1][:] + state[2] -= 1 + state[3] += 2 + ans.append(state[:]) + while state[2]: + state[3], state[4] = 0, 2 * state[3] + ans.append(state[:]) + state[2:] = [state[2] - 1, state[4], 0] + ans.append(state[:]) + + exp_move() + assert ans[-1] == [0, 1, 0, 2 ** 14, 0] + ans.append([0, 0, 2 ** 14, 0, 0]) + if n <= 16: + ans.append([0, 0, 0, 2 ** 15, 0]) + else: + exp_move() + assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0] + state = ans[-1][:] + state[-2] -= 2 ** (n - 1) + state[-1] = 2 ** n + ans.append(state) + return ans + ``` +
+ +* **NoRelativePrimes** Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx) + + Question: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder + theorem? (5 instances) + + ```python + def sat(nums: List[int], b=7, m=6): + assert len(nums) == len(set(nums)) == m and min(nums) >= 0 + + def gcd(i, j): + r, s = max(i, j), min(i, j) + while s >= 1: + r, s = s, (r % s) + return r + + for a in nums: + nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)] + assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums) + + return True + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(b=7, m=6): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Let P(n) = n^2 + n + 1. + + Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has + the property that there is no element that is relatively prime to every other element. + + Sample input: + b = 6 + m = 2 + + Sample output: + [195, 196] + """ + ``` + Hand-written solution: + ```python + ans = [] + + seen = set() + deltas = set() + + def go(a): + if a < 0 or a in seen or len(ans) == m: + return + seen.add(a) + nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)] + if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums): + new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas] + ans.append(a) + for delta in new_deltas: + for a2 in ans: + go(a2 + delta) + go(a2 - delta) + deltas.update(new_deltas) + for delta in sorted(deltas): + go(a + delta) + + def gcd(i, j): + r, s = max(i, j), min(i, j) + while s >= 1: + r, s = s, (r % s) + return r + + a = 0 + + while len(ans) < m: + go(a) + a += 1 + + return ans + ``` +
+ +* **PickNearNeighbors** Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx) + + The puzzle solution follows the judge's proof closely. (5 instances) + + ```python + def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): + n = int(len(heights) ** 0.5) + assert sorted(heights) == list(range(n * n + n)), "hint: heights is a permutation of range(n * n + n)" + kept = [i for i, k in zip(heights, keep) if k] + assert len(kept) == 2 * n, "must keep 2n items" + pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices + return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n)) + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order) + so that the remaining list of numbers satisfies: + * its largest number is next to its second largest number + * its third largest number is next to its fourth largest number + ... + * its second smallest number is next to its smallest number + + Sample input: + [4, 0, 5, 3, 1, 2] + n = 2 + + Sample output: + [True, False, True, False, True, True] + + Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2. + """ + ``` + Hand-written solution: + ```python + # Based on the judge's solution. + n = int(len(heights) ** 0.5) + assert sorted(heights) == list(range(n * (n + 1))) + groups = [h // (n + 1) for h in heights] + ans = [False] * len(heights) + a = 0 + used_groups = set() + while sum(ans) < 2 * n: + group_tracker = {} + b = a + while groups[b] not in group_tracker or groups[b] in used_groups: + group_tracker[groups[b]] = b + b += 1 + ans[group_tracker[groups[b]]] = True + ans[b] = True + used_groups.add(groups[b]) + a = b + 1 + return ans + ``` +
+ +* **HalfTag** Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx) (5 instances) + + ```python + def sat(li: List[int], tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]): + n = max(tags) + 1 + assert sorted(tags) == sorted(list(range(n)) * 4), "hint: each tag occurs exactly four times" + assert len(li) == len(set(li)) and min(li) >= 0 + return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)] + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times. + The goal is to find a subset (list) li of half the indices such that: + * The sum of the indices equals the sum of the sum of the missing indices. + * The tags of the chosen indices contains exactly each number in range(n) twice. + + Sample input: + n = 3 + tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2] + + Sample output: + [0, 3, 5, 6, 8, 11] + + Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2] + """ + ``` + Hand-written solution: + ```python + n = max(tags) + 1 + pairs = {(i, 4 * n - i - 1) for i in range(2 * n)} + by_tag = {tag: [] for tag in range(n)} + for p in pairs: + a, b = [tags[i] for i in p] + by_tag[a].append(p) + by_tag[b].append(p) + cycles = [] + cycle = [] + while pairs: + if not cycle: # start new cycle + p = pairs.pop() + pairs.add(p) # just to pick a tag + tag = tags[p[0]] + # print("Starting cycle with tag", tag) + p = by_tag[tag].pop() + a, b = [tags[i] for i in p] + # print(p, a, b) + tag = a if a != tag else b + by_tag[tag].remove(p) + cycle.append(p if tag == b else p[::-1]) + pairs.remove(p) + if not by_tag[tag]: + cycles.append(cycle) + cycle = [] + + while any(len(c) % 2 for c in cycles): + cycle_tags = [{tags[k] for p in c for k in p} for c in cycles] + merged = False + for i in range(len(cycles)): + for j in range(i): + intersection = cycle_tags[i].intersection(cycle_tags[j]) + if intersection: + c = intersection.pop() + # print(f"Merging cycle {i} and cycle {j} at tag {c}", cycles) + cycle_i = cycles.pop(i) + for i1, p in enumerate(cycle_i): + if tags[p[0]] == c: + break + for j1, p in enumerate(cycles[j]): + if tags[p[0]] == c: + break + cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1] + merged = True + break + if merged: + break + + ans = [] + for c in cycles: + for i, p in enumerate(c): + if i % 2: + ans += p + return ans + ``` +
+ +## lattices - return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k)) -``` -
1 solution to number_theory 12/16 - -```python -def sol(k=5): - n = 2 - prod = 1 - ans = [] - while len(ans) < k: - ans.append(n) - prod *= n - n = prod + 1 - return ans -``` - -
- -### CollatzCycleUnsolved -Collatz Conjecture - -A solution to this problem would disprove the *Collatz Conjecture*, also called the *3n + 1 problem*, -as well as the *Generalized Collatz Conjecture* (see the next problem). -According to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture): -> Paul Erdos said about the Collatz conjecture: "Mathematics may not be ready for such problems." -> He also offered US$500 for its solution. Jeffrey Lagarias stated in 2010 that the Collatz conjecture -> "is an extraordinarily difficult problem, completely out of reach of present day mathematics." - -Consider the following process. Start with an integer `n` and repeatedly applying the operation: -* if n is even, divide n by 2, -* if n is odd, multiply n by 3 and add 1 - -The conjecture is to that all `n > 0` eventually reach `n=1`. If this conjecture is false, then -there is either a cycle or a sequence that increases without bound. This problem seeks a cycle. - -```python -def sat(n: int): - """ - Consider the following process. Start with an integer `n` and repeatedly applying the operation: - * if n is even, divide n by 2, - * if n is odd, multiply n by 3 and add 1 - Find n > 4 which is part of a cycle of this process - """ - m = n - while n > 4: - n = 3 * n + 1 if n % 2 else n // 2 - if n == m: - return True -``` -0 solutions to number_theory 13/16 - -### CollatzGeneralizedUnsolved -Generalized Collatz Conjecture +Lattice problems with and without noise -This version, permits negative n and seek a cycle with a number of magnitude greater than 1000, -which would disprove the Generalized conjecture that states that the only cycles are the known 5 cycles -(which don't have positive integers). +* **LearnParityWithNoise** Learn parity with noise (*unsolved*) + + The fastest known algorithm to this + [Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning) + runs in time $2^(d/(log d))$ + + The example puzzle has small dimension so is easily solvable, but other instances are much harder. (5 instances) + + ```python + def sat(inds: List[int], vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]): + return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4 + ``` +
0.13% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least + 3/4 of the vectors, $$sum_{i \in S} x_i = 1 (mod 2)$$ + """ + ``` + Shortest Codex solution: + ```python + + return [i+1 for i in range(len(vecs)) if vecs[i] % 2 == 1] + + ``` + Longest Codex solution: + ```python + + for i in range(32): + if sat([i], vecs): + return [i] + for i in range(32): + for j in range(i+1, 32): + if sat([i, j], vecs): + return [i, j] + for i in range(32): + for j in range(i+1, 32): + for k in range(j+1, 32): + if sat([i, j, k], vecs): + return [i, j, k] + + ``` + Hand-written solution: + ```python + # brute force + d = 0 # decode vectors into arrays + m = max(vecs) + while m: + m >>= 1 + d += 1 + vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs] + + import random + rand = random.Random(0) + target = (len(vecs) * 3) // 4 + max_attempts = 10 ** 5 + for _ in range(max_attempts): + ans = [i for i in range(d) if rand.randrange(2)] + if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4: + return ans + ``` +
+ +* **LearnParity** Parity learning (Gaussian elimination) + + The canonical solution to this + [Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning) + is to use + [Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination). + + The vectors are encoded as binary integers for succinctness. (5 instances) + + ```python + def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): + return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs) + ``` +
0.04% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that: + $\\sum_{i \in S} x_i = 1 (mod 2)$ + """ + ``` + Shortest Codex solution: + ```python + + for i in range(1024): + inds = [j for j in range(1024) if (i >> j) & 1] + if sat(inds, vecs): return inds + + ``` + Longest Codex solution: + ```python + + best_score = 999 + best_inds = [] + for n in range(2**len(vecs)): + inds = [i for i in range(len(vecs)) if (n >> i) & 1] + if len(inds) <= best_score and sat(inds, vecs): + best_score, best_inds = len(inds), inds + return best_inds + + ``` + Hand-written solution: + ```python + # Gaussian elimination + d = 0 # decode vectors into arrays + m = max(vecs) + while m: + m >>= 1 + d += 1 + vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs] + ans = [] + pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs] + for i in range(d): + pool[i][i] = 1 + + for i in range(d): # zero out bit i + for v in pool[d:]: + if v[i] == 1: + break + if v[i] == 0: + v = pool[i] + assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate + w = v[:] + for v in pool: + if v[i] == 1: + for j in range(d + 1): + v[j] ^= w[j] + + return [i for i in range(d) if pool[i][-1]] + ``` +
+ +## number_theory -See the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture) +Number theory problems -```python -def sat(start: int): - """ +* **Factoring** [Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and + [RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers) + + *See class FermatComposite in codex.py for an easier composite test puzzle* + + The factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a + simple repetition process. Problems range from small (single-digit n) all the way to the "RSA challenges" + which include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007, + with hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People + continue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar. + + From Wikipedia: + + RSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest + cash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come, + unless considerable advances are made in integer factorization or computational power in the near future. (5 instances) + + ```python + def sat(i: int, n=241864633): + return 1 < i < n and n % i == 0 + ``` +
28% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=241864633): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a non-trivial factor of integer n""" + ``` + Shortest Codex solution: + ```python + + return next(i for i in range(n) if sat(i)) + + ``` + Longest Codex solution: + ```python + + # Try a triplet + for a in range(2, int((n / 3) ** 0.5) + 1): + if n % a == 0: + return a + # Try a non-trivial odd integer + for a in range(2, int(n ** 0.5) + 1, 2): + if n % a == 0: + return a + # Try a bigger non-trivial odd integer + for a in range(9, int(n ** 0.5) + 1, 2): + if n % a == 0: + return a + # Try a bigger non-trivial odd + ``` + Hand-written solution: + ```python + if n % 2 == 0: + return 2 + + for i in range(3, int(n ** 0.5) + 1, 2): + if n % i == 0: + return i + + assert False, "problem defined for composite n only" + ``` +
+ +* **GCD** [Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381) + (GCD) + + See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) (5 instances) + + ```python + def sat(n: int, a=15482, b=23223, lower_bound=5): + return a % n == 0 and b % n == 0 and n >= lower_bound + ``` +
21% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(a=15482, b=23223, lower_bound=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a large common divisor of two integers.""" + ``` + Shortest Codex solution: + ```python + + return b % a + + ``` + Longest Codex solution: + ```python + + # 15482 and 23223 are the only two relatively primes less than 10 million. I've found that there is a pattern + # here. By changing the order of the parameters in the function definition, I can guarantee that the lower bound + # is larger than the returned value. This is a dependable pattern for this problem. + successive = a % b + while successive != 0: + a = b + b = successive + successive = a % b + if b >= lower_bound: + return b + else: + return g6(a=a, b=b, lower_bound=lower_bound) + + ``` + Hand-written solution: + ```python + m, n = min(a, b), max(a, b) + while m > 0: + m, n = n % m, m + return n + ``` + Hand-written solution: + ```python + def gcd(m, n): + if m > n: + return gcd(n, m) + if m == 0: + return n + return gcd(n % m, m) + + return gcd(a, b) + ``` +
+ +* **CollatzDelay** Collatz Delay + Consider the following process. Start with an integer `n` and repeatedly applying the operation: * if n is even, divide n by 2, * if n is odd, multiply n by 3 and add 1 - Find n which is part of a cycle of this process that has |n| > 1000 - """ - n = start # could be positive or negative ... - while abs(n) > 1000: - n = 3 * n + 1 if n % 2 else n // 2 - if n == start: - return True -``` -0 solutions to number_theory 14/16 - -### CollatzDelay -Collatz Delay - -Consider the following process. Start with an integer `n` and repeatedly applying the operation: -* if n is even, divide n by 2, -* if n is odd, multiply n by 3 and add 1 -Find `0 < n < upper` so that it takes exactly `t` steps to reach 1. - - -For instance, -the number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes -2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture) - -Now, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the -number of bits of the solution to be upper. - -See [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records. - -```python -def sat(n: int, t=100, upper=10): - """ + Find `0 < n < upper` so that it takes exactly `t` steps to reach 1. + + + For instance, + the number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes + 2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture) + + Now, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the + number of bits of the solution to be upper. + + See [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records. (4 instances) + + ```python + def sat(n: int, t=197, upper=20): + m = n + for i in range(t): + if n <= 1: + return False + n = 3 * n + 1 if n % 2 else n // 2 + return n == 1 and m <= 2 ** upper + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(t=197, upper=20): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Consider the following process. Start with an integer `n` and repeatedly applying the operation: + * if n is even, divide n by 2, + * if n is odd, multiply n by 3 and add 1 + Find `0 < n < upper` so that it takes exactly `t` steps to reach 1. + """ + ``` + Shortest Codex solution: + ```python + + n = 1 + while not sat(n): n += 1 + return n + + ``` + Longest Codex solution: + ```python + + # # Find the integer in the right range that starts with 1 in its decimal representation. + # n = int("1" + "0"*9) + # while not sat(int(n), t, upper): + # n += 1 + # return n + # N = 873263645 + # return N + + # This function simply cannot do what we want: + # it hangs. Not sure if we did something wrong above and we already + # forgot the "upper = 20" argument. + m = 1 + while not sat(m, t, upper): + m += 1 + return m + + ``` + Hand-written solution: + ```python + # Faster solution for simultaneously solving multiple problems is of course possible + bound = t + 10 + while True: + bound *= 2 + prev = {1} + seen = set() + for delay in range(t): + seen.update(prev) + curr = {2 * n for n in prev} + curr.update({(n - 1) // 3 for n in prev if n % 6 == 4}) + prev = {n for n in curr if n <= bound} - seen + if prev: + return min(prev) + ``` +
+ +* **LCM** [Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple) + (LCM) + + See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) (5 instances) + + ```python + def sat(n: int, a=15, b=27, upper_bound=150): + return n % a == 0 and n % b == 0 and 0 < n <= upper_bound + ``` +
14% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=15, b=27, upper_bound=150): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a small common multiple of two integers.""" + ``` + Shortest Codex solution: + ```python + + return 135 + + ``` + Longest Codex solution: + ```python + + # TODO: break up this function for clarity + lower_bound = (upper_bound + (a - 1)) // a + first = (upper_bound // b + 1) + if first % a != 0: + first += b - first % b + if first < lower_bound: + first += b + swapped = False + for i in range(first, upper_bound + 1, b): + if i % a == 0: + return i + # FIXME: literally just literally no + for i in range(upper_bound + 1, upper_bound * 10): + if swapped: + break + g + ``` + Hand-written solution: + ```python + m, n = min(a, b), max(a, b) + while m > 0: + m, n = n % m, m + return a * (b // n) + ``` +
+ +* **DiscreteLog** Discrete Log + + The discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that: + + `g ** n % p == t` + + From [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records): + + "Several important algorithms in public-key cryptography base their security on the assumption + that the discrete logarithm problem over carefully chosen problems has no efficient solution." + + The problem is *unsolved* in the sense that no known polynomial-time algorithm has been found. + + We include McCurley's discrete log challenge from + [Weber D., Denny T. (1998) "The solution of McCurley's discrete log challenge."](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf) (5 instances) + + ```python + def sat(n: int, g=44337, p=69337, t=38187): + return pow(g, n, p) == t + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(g=44337, p=69337, t=38187): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that g^n is congruent to t mod n""" + ``` + Shortest Codex solution: + ```python + + return next(n for n in range(p) if sat(n)) + + ``` + Longest Codex solution: + ```python + + def discrete_logarithm(x, g, p): + """Brute-force discrete logarithm.""" + result = 0 + for i in range(0, p): + if pow(g, i, p) == x: + result = i + break + return result + n = discrete_logarithm(t, g, p) + if n == 0: + for i in range(1, p): + n = discrete_logarithm(t * i % p, g, p) + if n != 0: + break + return n + + ``` + Hand-written solution: + ```python + for n in range(p): + if pow(g, n, p) == t: + return n + assert False, f"unsolvable discrete log problem g={g}, t={t}, p={p}" + ``` +
+ +* **LCM_multi** [Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple) + (LCM) + + See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) (5 instances) + + ```python + def sat(n: int, nums=[15, 27, 102], upper_bound=5000): + return all(n % i == 0 for i in nums) and 0 < n <= upper_bound + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[15, 27, 102], upper_bound=5000): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a small common multiple of a list of integers.""" + ``` + Shortest Codex solution: + ```python + + i = 3 + while not sat(i): + i += 1 + return i + + ``` + Longest Codex solution: + ```python + + def recur(i, bound): + if i == len(nums): + # Generate number + for x in range(bound-1, 0, -1): + if sat(x, nums, upper_bound): + return x + + # Recur + for val in range(bound): + if sat(val, nums, bound): + ret = recur(i+1, bound) + if ret != None: + return val + return None + + return recur(0, upper_bound+1) + + ``` + Hand-written solution: + ```python + ans = 1 + for i in nums: + m, n = min(i, ans), max(i, ans) + while m > 0: + m, n = n % m, m + ans *= (i // n) + return ans + ``` +
+ +* **GCD_multi** [Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381) + (GCD) + + See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) (5 instances) + + ```python + def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2): + return all(i % n == 0 for i in nums) and n >= lower_bound + ``` +
11% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(nums=[77410, 23223, 54187], lower_bound=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a large common divisor of the list of integers.""" + ``` + Shortest Codex solution: + ```python + + return max(nums) // 10 + + ``` + Longest Codex solution: + ```python + + max_int = max(nums, key=abs) + if lower_bound > max_int or lower_bound < 2: + raise ValueError("lower_bound must be >= 2 and smallest num must be >= lower_bound") + if lower_bound > 9: + raise ValueError("lower_bound must be at most 9") + while lower_bound < max_int: + if all(i % lower_bound == 0 for i in nums): + return lower_bound + lower_bound += 1 + raise ValueError("unable to find a common divisor") + + ``` + Hand-written solution: + ```python + n = 0 + for i in nums: + m, n = min(i, n), max(i, n) + while m > 0: + m, n = n % m, m + return n + ``` +
+ +* **SmallExponentBigSolution** Small exponent, big solution + + Problems have small b and target but solution is typically a large n. + Some of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497` + + See [Richard K. Guy "The strong law of small numbers", (problem 13)](https://doi.org/10.2307/2322249) (4 instances) + + ```python + def sat(n: int, b=2, target=5): + return (b ** n) % n == target + ``` +
9.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(b=2, target=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve for n: b^n = target (mod n)""" + ``` + Shortest Codex solution: + ```python + + n = 2 + while not sat(n): n += 1 + return n + + ``` + Longest Codex solution: + ```python + + # iterative + n = 1 + while True: + if sat(n, b, target): + break + n += 1 + return n + + # pythonic + # return next(x for x in itertools.count(1) if sat(x, b, target)) # in python 3.6+ + + # recursive + # def sat(n): + # if n < 0: + # return None + # if sat(n - 1) is not None: + # return (sat(n - 1) ** b) % n + # else: + # return None + ``` + Hand-written solution: + ```python + for n in range(1, 10 ** 5): + if pow(b, n, n) == target: + return n + ``` +
+ +* **FourSquares** Sum of four squares + + [Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem) + + Given a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four + integers. The problem here is to find them. This is a nice problem and we give an elementary solution + that runs in time ilde{O}(n), + which is not "polynomial time" because it is not polynomial in log(n), the length of n. A poly-log(n) + algorithm using quaternions is described in the book: + ["Randomized algorithms in number theory" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713) + + The first half of the problems involve small numbers and the second half involve some numbers up to 50 digits. (5 instances) + + ```python + def sat(nums: List[int], n=12345): + return len(nums) <= 4 and sum(i ** 2 for i in nums) == n + ``` +
0.51% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=12345): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find four integers whose squares sum to n""" + ``` + Shortest Codex solution: + ```python + + nums = [] + for _ in range(4): + nums.append(int(n**0.5)) + n -= nums[-1] ** 2 + return nums + + ``` + Longest Codex solution: + ```python + + count = 0 + found = [] + for x in range(n): + for y in range(x): + for z in range(y): + for w in range(z): + if x ** 2 + y ** 2 + z ** 2 + w ** 2 == n: + found = [x, y, z, w] + count += 1 + break + else: + continue + break + else: + continue + break + else: + continue + break + return found + + ``` + Hand-written solution: + ```python + m = n + squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m} + sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()} + for s in sums_of_squares: + if m - s in sums_of_squares: + return sums_of_squares[m - s] + sums_of_squares[s] + assert False, "Should never reach here" + ``` +
+ +* **Znam** [Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem) + + For example [2, 3, 7, 47, 395] is a solution for k=5 (4 instances) + + ```python + def sat(li: List[int], k=5): + def prod(nums): + ans = 1 + for i in nums: + ans *= i + return ans + + return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k)) + ``` +
0.05% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(k=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find k positive integers such that each integer divides (the product of the rest plus 1).""" + ``` + Shortest Codex solution: + ```python + + li = [] + ans = 1 + for _ in range(k): + i = int(ans) + 1 + ans *= i + li.append(i) + return li + + ``` + Longest Codex solution: + ```python + + ans = [] # type: List[int] + for i in range(k): + found = False + for n in range(2, 10694): + if all((n % x == 1) for x in ans): + ans.append(n) + found = True + break + if not found: + break + return ans + + ``` + Hand-written solution: + ```python + n = 2 + prod = 1 + ans = [] + while len(ans) < k: + ans.append(n) + prod *= n + n = prod + 1 + return ans + ``` +
+ +* **ThreeCubes** Sum of three cubes + + Given `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`. + Conjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`. + `a`, `b`, `c` may be positive or negative + + See [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or + [Andrew R. Booker, Andrew V. Sutherland (2020). "On a question of Mordell."](https://arxiv.org/abs/2007.01209) (5 instances) + + ```python + def sat(nums: List[int], target=983): + assert target % 9 not in [4, 5], "Hint" + return len(nums) == 3 and sum([i ** 3 for i in nums]) == target + ``` +
0.0067% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=983): + ``` + Solution docstring (*not* usually provided) + + ```python + """Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.""" + ``` + Shortest Codex solution: + ```python + + n = (int(target ** (1/3)) // 2) + while True: + for a in range(-n, n + 1): + for b in range(-(n - abs(a)), n - abs(a) + 1): + for c in range(-(n - abs(a) - abs(b)), n - abs(a) - abs(b) + 1): + if target == a**3 + b**3 + c**3: + return [a, b, c] + n += 1 + + ``` + Longest Codex solution: + ```python + + limit = target // 9 + nums: List[int] = [] + for i in range(1, limit): + for j in range(i, limit): + for k in range(-100, 101): + if i ** 3 + j ** 3 + k ** 3 == target: + nums.append(i) + nums.append(j) + nums.append(k) + return nums; + + ``` + Hand-written solution: + ```python + assert target % 9 not in {4, 5} + for i in range(20): + for j in range(i + 1): + for k in range(-20, j + 1): + n = i ** 3 + j ** 3 + k ** 3 + if n == target: + return [i, j, k] + if n == -target: + return [-i, -j, -k] + ``` +
+ +* **FermatsLastTheorem** [Fermat's last theorem](https://en.wikipedia.org/w/index.php?title=Fermat%27s_Last_Theorem) + + Supposedly unsolvable, but how confident are really in the super-complicated proof? + + See [Wiles, Andrew. "Modular elliptic curves and Fermat's last theorem." Annals of mathematics 141.3 (1995): 443-551.](https://www.jstor.org/stable/2118559) (1 instance) + + ```python + def sat(nums: List[int]): + a, b, c, n = nums + return (a ** n + b ** n == c ** n) and min(a, b, c) > 0 and n > 2 + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find integers a,b,c > 0, n > 2, such such that a^n + b^n == c^n""" + ``` +
+ +* **GCD17** According to [this article](https://primes.utm.edu/glossary/page.php?sort=LawOfSmall), the smallest + solution is 8424432925592889329288197322308900672459420460792433 (1 instance) + + ```python + def sat(n: int): + i = n ** 17 + 9 + j = (n + 1) ** 17 + 9 + + while i != 0: # compute gcd using Euclid's algorithm + (i, j) = (j % i, i) + + return n >= 0 and j != 1 + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n for which gcd(n^17+9, (n+1)^17+9) != 1""" + ``` +
+ +* **CollatzCycleUnsolved** Collatz Conjecture + + A solution to this problem would disprove the *Collatz Conjecture*, also called the *3n + 1 problem*, + as well as the *Generalized Collatz Conjecture* (see the next problem). + According to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture): + > Paul Erdos said about the Collatz conjecture: "Mathematics may not be ready for such problems." + > He also offered US$500 for its solution. Jeffrey Lagarias stated in 2010 that the Collatz conjecture + > "is an extraordinarily difficult problem, completely out of reach of present day mathematics." + Consider the following process. Start with an integer `n` and repeatedly applying the operation: * if n is even, divide n by 2, * if n is odd, multiply n by 3 and add 1 - Find `0 < n < upper` so that it takes exactly `t` steps to reach 1. - """ - m = n - for i in range(t): - if n <= 1: - return False - n = 3 * n + 1 if n % 2 else n // 2 - return n == 1 and m <= 2 ** upper -``` -
1 solution to number_theory 15/16 - -```python -def sol(t=100, upper=10): # Faster solution for simultaneously solving multiple problems is of course possible - bound = t + 10 - while True: - bound *= 2 - prev = {1} - seen = set() - for delay in range(t): - seen.update(prev) - curr = {2 * n for n in prev} - curr.update({(n - 1) // 3 for n in prev if n % 6 == 4}) - prev = {n for n in curr if n <= bound} - seen - if prev: - return min(prev) -``` - -
- -### Lehmer -Lehmer puzzle - -According to [The Strong Law of Large Numbers](https://doi.org/10.2307/2322249) Richard K. Guy states that - D. H. & Emma Lehmer discovered that 2^n = 3 (mod n) for n = 4700063497, - but for no smaller n > 1 - -```python -def sat(n: int): - """Find n such that 2^n mod n = 3""" - return pow(2, n, n) == 3 -``` -
1 solution to number_theory 16/16 - -```python -def sol(): - return 4700063497 -``` - -
- + + The conjecture is to that all `n > 0` eventually reach `n=1`. If this conjecture is false, then + there is either a cycle or a sequence that increases without bound. This problem seeks a cycle. (1 instance) + + ```python + def sat(n: int): + m = n + while n > 4: + n = 3 * n + 1 if n % 2 else n // 2 + if n == m: + return True + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Consider the following process. Start with an integer `n` and repeatedly applying the operation: + * if n is even, divide n by 2, + * if n is odd, multiply n by 3 and add 1 + Find n > 4 which is part of a cycle of this process + """ + ``` +
+ +* **CollatzGeneralizedUnsolved** Generalized Collatz Conjecture + + This version, permits negative n and seek a cycle with a number of magnitude greater than 1000, + which would disprove the Generalized conjecture that states that the only cycles are the known 5 cycles + (which don't have positive integers). + + See the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture) (1 instance) + + ```python + def sat(start: int): + n = start # could be positive or negative ... + while abs(n) > 1000: + n = 3 * n + 1 if n % 2 else n // 2 + if n == start: + return True + ``` +
0% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Consider the following process. Start with an integer `n` and repeatedly applying the operation: + * if n is even, divide n by 2, + * if n is odd, multiply n by 3 and add 1 + Find n which is part of a cycle of this process that has |n| > 1000 + """ + ``` +
+ +* **Lehmer** Lehmer puzzle + + According to [The Strong Law of Large Numbers](https://doi.org/10.2307/2322249) Richard K. Guy states that + D. H. & Emma Lehmer discovered that 2^n = 3 (mod n) for n = 4700063497, + but for no smaller n > 1 (1 instance) + + ```python + def sat(n: int): + return pow(2, n, n) == 3 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that 2^n mod n = 3""" + ``` + Hand-written solution: + ```python + return 4700063497 + ``` +
+ ## probability Probability problems -### BirthdayParadox -Adaptation of the classic -[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)). - -The year length is year_len (365 is earth, while Neptune year is 60,182). - -```python -def sat(n: int, year_len=365): - """Find n such that the probability of two people having the same birthday in a group of n is near 1/2.""" - prob = 1.0 - for i in range(n): - prob *= (year_len - i) / year_len - return (prob - 0.5) ** 2 <= 1/year_len -``` -
1 solution to probability 1/5 - -```python -def sol(year_len=365): - n = 1 - distinct_prob = 1.0 - best = (0.5, 1) # (difference between probability and 1/2, n) - while distinct_prob > 0.5: - distinct_prob *= (year_len - n) / year_len - n += 1 - best = min(best, (abs(0.5 - distinct_prob), n)) - - return best[1] -``` - -
- -### BirthdayParadoxMonteCarlo -A slower, Monte Carlo version of the above Birthday Paradox problem. - -```python -def sat(n: int, year_len=365): - """Find n such that the probability of two people having the same birthday in a group of n is near 1/2.""" - import random - random.seed(0) - K = 1000 # number of samples - prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K - return (prob - 0.5) ** 2 <= year_len -``` -
1 solution to probability 2/5 - -```python -def sol(year_len=365): - n = 1 - distinct_prob = 1.0 - best = (0.5, 1) # (difference between probability and 1/2, n) - while distinct_prob > 0.5: - distinct_prob *= (year_len - n) / year_len - n += 1 - best = min(best, (abs(0.5 - distinct_prob), n)) - - return best[1] -``` - -
- -### BallotProblem -See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or -or [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lovász L., -Sági G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17. -Springer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1) - -```python -def sat(counts: List[int], target_prob=0.5): - """ - Suppose a list of m 1's and n -1's are permuted at random. - What is the probability that all of the cumulative sums are positive? - The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob. - """ - m, n = counts # m = num 1's, n = num -1's - probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1 - for i in range(2, m + 1): # compute probs using dynamic programming for m = i - old_probs = probs - probs = [1.0] + [0.0] * n - for j in range(1, min(n + 1, i)): - probs[j] = ( - j / (i + j) * probs[j - 1] # last element is a -1 so use probs - + - i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1 - ) - return abs(probs[n] - target_prob) < 1e-6 -``` -
1 solution to probability 3/5 - -```python -def sol(target_prob=0.5): - for m in range(1, 10000): - n = round(m * (1 - target_prob) / (1 + target_prob)) - if abs(target_prob - (m - n) / (m + n)) < 1e-6: - return [m, n] -``` - -
- -### BinomialProbabilities -See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution) - -```python -def sat(counts: List[int], p=0.5, target_prob=0.0625): - """Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.""" - from itertools import product - a, b = counts - n = a + b - prob = (p ** a) * ((1-p) ** b) - tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a]) - return abs(tot - target_prob) < 1e-6 -``` -
1 solution to probability 4/5 - -```python -def sol(p=0.5, target_prob=0.0625): - probs = [1.0] - q = 1 - p - while len(probs) < 20: - probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])] - answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6] - if answers: - return [answers[0], len(probs) - 1 - answers[0]] -``` - -
- -### ExponentialProbability -See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) - -```python -def sat(p_stop: float, steps=10, target_prob=0.5): - """ - Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you - stop each step with probability p_stop - """ - prob = sum(p_stop*(1-p_stop)**t for t in range(steps)) - return abs(prob - target_prob) < 1e-6 -``` -
1 solution to probability 5/5 - -```python -def sol(steps=10, target_prob=0.5): - return 1 - (1 - target_prob) ** (1.0/steps) -``` - -
- -## trivial_inverse - -Trivial problems. Typically for any function, you can construct a trivial example. -For instance, for the len function you can ask for a string of len(s)==100 etc. - - -### HelloWorld -Trivial example, no solutions provided - -```python -def sat(s: str): - """Find a string that when concatenated onto 'world' gives 'Hello world'.""" - return s + 'world' == 'Hello world' -``` -0 solutions to trivial_inverse 1/39 - -### BackWorlds -We provide two solutions - -```python -def sat(s: str): - """Find a string that when reversed and concatenated onto 'world' gives 'Hello world'.""" - return s[::-1] + 'world' == 'Hello world' -``` -
2 solutions to trivial_inverse 2/39 - -```python -def sol(): - return ' olleH' -``` - -
- -```python -def sol(): # solution methods must begin with 'sol' - return 'Hello '[::-1] -``` - - - -### StrAdd - - -```python -def sat(st: str, a="world", b="Hello world"): - """Solve simple string addition problem.""" - return st + a == b -``` -
1 solution to trivial_inverse 3/39 - -```python -def sol(a="world", b="Hello world"): - return b[:len(b) - len(a)] -``` - -
- -### StrSetLen - - -```python -def sat(s: str, dups=2021): - """Find a string with dups duplicate chars""" - return len(set(s)) == len(s) - dups -``` -
1 solution to trivial_inverse 4/39 - -```python -def sol(dups=2021): - return "a" * (dups + 1) -``` - -
- -### StrMul - - -```python -def sat(s: str, target="foofoofoofoo", n=2): - """Find a string which when repeated n times gives target""" - return s * n == target -``` -
1 solution to trivial_inverse 5/39 - -```python -def sol(target="foofoofoofoo", n=2): - if n == 0: - return '' - return target[:len(target) // n] -``` - -
- -### StrMul2 +* **BirthdayParadox** Adaptation of the classic + [Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)). + + The year length is year_len (365 is earth, while Neptune year is 60,182). (4 instances) + + ```python + def sat(n: int, year_len=365): + prob = 1.0 + for i in range(n): + prob *= (year_len - i) / year_len + return (prob - 0.5) ** 2 <= 1/year_len + ``` +
21% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(year_len=365): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that the probability of two people having the same birthday in a group of n is near 1/2.""" + ``` + Shortest Codex solution: + ```python + + return 24 + + ``` + Longest Codex solution: + ```python + + if year_len > 365: + # This won't be recognizable as solutions to this particular task, + # but it will be solutions to the problem of people having the same birthday. + return year_len + else: + # Require that there exists an n with this property, but do + # require n is less than the maximum possible number for this task, + # so the desired property is valid for all years in the task. + i = int(year_len ** 0.5) + while True: + if sat(i, year_len): + return i + i += 1 + + ``` + Hand-written solution: + ```python + n = 1 + distinct_prob = 1.0 + best = (0.5, 1) # (difference between probability and 1/2, n) + while distinct_prob > 0.5: + distinct_prob *= (year_len - n) / year_len + n += 1 + best = min(best, (abs(0.5 - distinct_prob), n)) + + return best[1] + ``` +
+ +* **BallotProblem** See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or + or [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lovász L., + Sági G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17. + Springer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1) (5 instances) + + ```python + def sat(counts: List[int], target_prob=0.5): + m, n = counts # m = num 1's, n = num -1's + probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1 + for i in range(2, m + 1): # compute probs using dynamic programming for m = i + old_probs = probs + probs = [1.0] + [0.0] * n + for j in range(1, min(n + 1, i)): + probs[j] = ( + j / (i + j) * probs[j - 1] # last element is a -1 so use probs + + + i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1 + ) + return abs(probs[n] - target_prob) < 1e-6 + ``` +
2.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target_prob=0.5): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Suppose a list of m 1's and n -1's are permuted at random. + What is the probability that all of the cumulative sums are positive? + The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob. + """ + ``` + Shortest Codex solution: + ```python + + return [9, 3] + + ``` + Longest Codex solution: + ```python + + m = n = 1 + while m < 5000 or n < 5000: + counts = [m, n] + if sat(counts, target_prob): + return counts + if n < m: # increase n + if n >= 500: + n = 500 # 500 is the best value for f6; 500 < n is impractical + else: + n += 1 + else: # increase m + if m >= 500: + m = 500 # 500 is the best value for f6; 500 < m is impractical + else: + m += 1 + n = 1 + return None + + ``` + Hand-written solution: + ```python + for m in range(1, 10000): + n = round(m * (1 - target_prob) / (1 + target_prob)) + if abs(target_prob - (m - n) / (m + n)) < 1e-6: + return [m, n] + ``` +
+ +* **ExponentialProbability** See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) (5 instances) + + ```python + def sat(p_stop: float, steps=10, target_prob=0.5): + prob = sum(p_stop*(1-p_stop)**t for t in range(steps)) + return abs(prob - target_prob) < 1e-6 + ``` +
1.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(steps=10, target_prob=0.5): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you + stop each step with probability p_stop + """ + ``` + Shortest Codex solution: + ```python + + return 1-2**(-1/steps) + + ``` + Longest Codex solution: + ```python + + def un_normalize_prob(p_stop: float, steps: int): + return sum(p_stop*(1-p_stop)**t for t in range(steps)) + start = 0.0 + end = 0.999 + mid = (start + end) / 2.0 + while not sat(mid, steps, target_prob): + if un_normalize_prob(mid, steps) > target_prob: + end = mid + else: + start = mid + mid = (start + end) / 2.0 + return mid + + ``` + Hand-written solution: + ```python + return 1 - (1 - target_prob) ** (1.0/steps) + ``` +
+ +* **BirthdayParadoxMonteCarlo** A slower, Monte Carlo version of the above Birthday Paradox problem. (4 instances) + + ```python + def sat(n: int, year_len=365): + import random + random.seed(0) + K = 1000 # number of samples + prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K + return (prob - 0.5) ** 2 <= year_len + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(year_len=365): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that the probability of two people having the same birthday in a group of n is near 1/2.""" + ``` + Hand-written solution: + ```python + n = 1 + distinct_prob = 1.0 + best = (0.5, 1) # (difference between probability and 1/2, n) + while distinct_prob > 0.5: + distinct_prob *= (year_len - n) / year_len + n += 1 + best = min(best, (abs(0.5 - distinct_prob), n)) + + return best[1] + ``` +
+ +* **BinomialProbabilities** See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution) (5 instances) + + ```python + def sat(counts: List[int], p=0.5, target_prob=0.0625): + from itertools import product + a, b = counts + n = a + b + prob = (p ** a) * ((1-p) ** b) + tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a]) + return abs(tot - target_prob) < 1e-6 + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(p=0.5, target_prob=0.0625): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.""" + ``` + Hand-written solution: + ```python + probs = [1.0] + q = 1 - p + while len(probs) < 20: + probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])] + answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6] + if answers: + return [answers[0], len(probs) - 1 - answers[0]] + ``` +
+ +## trivial_inverse +Trivial problems. Typically for any function, you can construct a trivial example. +For instance, for the len function you can ask for a string of len(s)==100 etc. -```python -def sat(n: int, target="foofoofoofoo", s="foofoo"): - """Find n such that s repeated n times gives target""" - return s * n == target -``` -
1 solution to trivial_inverse 6/39 -```python -def sol(target="foofoofoofoo", s="foofoo"): - if len(s) == 0: +* **StrLen** (5 instances) + + ```python + def sat(s: str, n=1000): + return len(s) == n + ``` +
75% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=1000): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string of length n""" + ``` + Shortest Codex solution: + ```python + return "a" * n + + ``` + Longest Codex solution: + ```python + + bs = [str(i) for i in range(1, 100)] + for r in range(1, 10): + for a in bs: + s = a + for i in range(1, r): + s += str(int(s[-1]) * r) + while len(s) < n: + s += str(int(s[-len(a):]) * r) + if len(s) == n: + return s + return None + + ``` + Hand-written solution: + ```python + return 'a' * n + ``` +
+ +* **ListLen** (5 instances) + + ```python + def sat(li: List[int], n=85012): + return len(li) == n + ``` +
72% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(n=85012): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of a given length n""" + ``` + Shortest Codex solution: + ```python + + return [1]*n + ``` + Longest Codex solution: + ```python + + li = [0]*n + while len(li) < n: + while any(li[i] == 0 for i in range(len(li))): + for i in range(len(li)): + if li[i] == 0: + li[i] = 1 + break + while any(li[i] == 1 for i in range(len(li))): + for i in reversed(range(len(li))): + if li[i] == 1: + li[i] = 2 + break + return li + + ``` + Hand-written solution: + ```python + return [1] * n + ``` +
+ +* **ListIndex** (5 instances) + + ```python + def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4): + return li.index(item) == index + ``` +
71% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[17, 2, 3, 9, 11, 11], index=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the item whose first index in li is index""" + ``` + Shortest Codex solution: + ```python + + return 11 + ``` + Longest Codex solution: + ```python + + # return li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0, li[index] + 0 + return li[index] + ``` + Hand-written solution: + ```python + return li[index] + ``` +
+ +* **StrAt** (5 instances) + + ```python + def sat(i: int, s="cat", target="a"): + return s[i] == target + ``` +
71% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="cat", target="a"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the index of target in string s""" + ``` + Shortest Codex solution: + ```python + return 1 - return len(target) // len(s) -``` - -
- -### StrLen - - -```python -def sat(s: str, n=1000): - """Find a string of length n""" - return len(s) == n -``` -
1 solution to trivial_inverse 7/39 - -```python -def sol(n=1000): - return 'a' * n -``` - -
- -### StrAt - - -```python -def sat(i: int, s="cat", target="a"): - """Find the index of target in string s""" - return s[i] == target -``` -
1 solution to trivial_inverse 8/39 - -```python -def sol(s="cat", target="a"): - return s.index(target) -``` - -
- -### StrNegAt - - -```python -def sat(i: int, s="cat", target="a"): - """Find the index of target in s using a negative index.""" - return s[i] == target and i < 0 -``` -
1 solution to trivial_inverse 9/39 - -```python -def sol(s="cat", target="a"): - return - (len(s) - s.index(target)) -``` - -
- -### StrSlice - - -```python -def sat(inds: List[int], s="hello world", target="do"): - """Find the three slice indices that give the specific target in string s""" - i, j, k = inds - return s[i:j:k] == target -``` -
1 solution to trivial_inverse 10/39 - -```python -def sol(s="hello world", target="do"): - from itertools import product - for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3): - try: + ``` + Longest Codex solution: + ```python + + # A naive implementation + # for i, c in enumerate(s): + # if c == target: + # return i + # return None + # Note: this implementation is also bad because it uses O(n) memory to store the indexes for the strings. + # This isn't an issue in practice, we'd rather we we used a cached list of indexes in the string if that's + # feasible, but this is still an excessive work-around. + return s.index(target) + + ``` + Hand-written solution: + ```python + return s.index(target) + ``` +
+ +* **IntNeg** (5 instances) + + ```python + def sat(x: int, a=93252338): + return -x == a + ``` +
69% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=93252338): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a unary negation problem""" + ``` + Shortest Codex solution: + ```python + return -a + ``` + Longest Codex solution: + ```python + + # We create a dummy function g6 which just returns a, and we use this as an argument + # to f6 (which can take as many arguments as we like) to make sure we know what the + # code actually uses as its parameters, and which we can therefore check. + return -a + + ``` + Hand-written solution: + ```python + return - a + ``` +
+ +* **ListAt** (5 instances) + + ```python + def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18): + return li[i] == target + ``` +
59% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the index of an item in a list. Any such index is fine.""" + ``` + Shortest Codex solution: + ```python + + return 3 + ``` + Longest Codex solution: + ```python + + if li == [17, 31, 91, 18, 42, 1, 9]: + if target == 42: + return 4 + if target == 1: + return 6 + if target == 18: + return 3 + if target == 9: + return 5 + if target == 31: + return 2 + if target == 17: + return 0 + if target == 91: + return 1 + if target == 91: + return 1 + if target == 91: + return 1 + else: + for i in range(7): + if sat(i, li, target): + return i + + ``` + Hand-written solution: + ```python + return li.index(target) + ``` +
+ +* **IntDiv2** (5 instances) + + ```python + def sat(n: int, a=345346363, b=10): + return n // b == a + ``` +
46% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=345346363, b=10): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n that when divided by b is a""" + ``` + Shortest Codex solution: + ```python + return a*b + ``` + Longest Codex solution: + ```python + + n_guess = a*b + while True: + if n_guess == a*b: + return n_guess + if n_guess // b == a: + return n_guess + elif n_guess // b < a: + n_guess *= 2 + else: + n_guess = (n_guess - a*b) // 2 + a*b + + ``` + Hand-written solution: + ```python + return a * b + ``` +
+ +* **StrMul2** (5 instances) + + ```python + def sat(n: int, target="foofoofoofoo", s="foofoo"): + return s * n == target + ``` +
41% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="foofoofoofoo", s="foofoo"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find n such that s repeated n times gives target""" + ``` + Shortest Codex solution: + ```python + + return 2 + + ``` + Longest Codex solution: + ```python + + # Subject to the constraint that it is impossible for s to give target. + # This is essentially a selection problem, with the values being the different ways s + # can be concatenated with itself. Only consider the first 1000 stings to save time. + # Then we will take the smallest repeat count giving target. + max_count = max(len(target) // len(s), 2) + for n in range(1, max_count + 1): + if s * n == target: + return n + + ``` + Hand-written solution: + ```python + if len(s) == 0: + return 1 + return len(target) // len(s) + ``` +
+ +* **StrParts** (5 instances) + + ```python + def sat(parts: List[str], sep="!!", string="I!!!!!love!!dumplings!!!!!"): + return sep.join(parts) == string and all(sep not in p for p in parts) + ``` +
39% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(sep="!!", string="I!!!!!love!!dumplings!!!!!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find parts that when joined give a specific string.""" + ``` + Shortest Codex solution: + ```python + + return string.split(sep) + ``` + Longest Codex solution: + ```python + + + def count_dumplings(string): + """string = 'I!!!!!love!!dumplings!!!!!' -> 3.""" + result = 0 + while string: + match = string.find("!!!") + if match == -1: + return result + result += 1 + string = string[:match] + string[match+3:].replace("!!!", "", 1) + return result + + dumplings = count_dumplings(string) + return string.split(sep) * (dumplings - (len(sep) == 1)) + + ``` + Hand-written solution: + ```python + return string.split(sep) + ``` +
+ +* **ListIn** (5 instances) + + ```python + def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']): + return s in a and s in b + ``` +
35% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an item that is in both lists a and b""" + ``` + Shortest Codex solution: + ```python + + return a[1] + ``` + Longest Codex solution: + ```python + + for i in range(1, len(a)): + for j in range(1, len(b)): + if a[i] == b[j] and a[i] == a[i - 1] and i < j: + continue + elif a[i] == a[i - 1] and i > j: + continue + elif a[i] == a[j] and a[i] == a[j - 1] and j < i: + continue + elif a[i] == a[j - 1] and j > i: + continue + else: + return a[i] + ``` + Hand-written solution: + ```python + return next(s for s in b if s in a) + ``` +
+ +* **IntSub2** (5 instances) + + ```python + def sat(x: int, a=8665464, b=-93206): + return a - x == b + ``` +
34% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=8665464, b=-93206): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a subtraction problem""" + ``` + Shortest Codex solution: + ```python + + return a-b + ``` + Longest Codex solution: + ```python + + return a - b + + ``` + Hand-written solution: + ```python + return a - b + ``` +
+ +* **IntSum** (5 instances) + + ```python + def sat(x: int, a=1073258, b=72352549): + return a + x == b + ``` +
27% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=1073258, b=72352549): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a sum problem""" + ``` + Shortest Codex solution: + ```python + + return b-a + ``` + Longest Codex solution: + ```python + + + # The 'breaks' are NOT an answer. + # You could construct more interesting cases. + + # This is the best known case. + if a + 1 == b: + return 1 + + # This is one of the 'interesting' cases. + # If the right-hand side is odd, x % 2 == 0 so the equation reduces + # to x = b - a. + if b % 2 == 1: + x = b - a + return x if sat(x) else None + + # If the right-hand side is even, x % 2 == 1 so the equation reduces + # to x * 2 = b - a. + ``` + Hand-written solution: + ```python + return b - a + ``` +
+ +* **IntSquareRoot** (5 instances) + + ```python + def sat(x: int, a=10201202001): + return x ** 2 == a + ``` +
24% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=10201202001): + ``` + Solution docstring (*not* usually provided) + + ```python + """Compute an integer that when squared equals perfect-square a.""" + ``` + Shortest Codex solution: + ```python + + return int(a**.5) + ``` + Longest Codex solution: + ```python + + for i in range(1000, 100000): + x = int(i/2) + while True: + if x ** 2 == a: + return x + else: + if x + 1 == a: + return a + 1 + elif x + 1 < a: + x += 1 + else: + a += int(a / 10000) + a *= 100001 + x = int(i/2) + + ``` + Hand-written solution: + ```python + return int(a ** 0.5) + ``` +
+ +* **IntDiv** (5 instances) + + ```python + def sat(n: int, a=3, b=23463462): + return b // n == a + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=3, b=23463462): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a division problem""" + ``` + Shortest Codex solution: + ```python + + return b//a + ``` + Longest Codex solution: + ```python + + ''' + eg: + n = 3, a = 1 + b // n = 77 + 77 // n = 3 + 77 % n = 77 + 77 % n = 77 % 3 = 1 + 77 // n = 77 // 3 = 3 + 77 // n = 3 * 3 = 9 + 77 % n = 77 % 9 = 1 + 77 // n = 1 * 9 = 9 + ''' + n = 3 + while True: + if not sat(n, a, b): + n += 1 + else: + return n + + ``` + Hand-written solution: + ```python + if a == 0: + return 2 * b + for n in [b // a, b // a - 1, b // a + 1]: + if b // n == a: + return n + ``` +
+ +* **StrCount** (5 instances) + + ```python + def sat(string: str, substring="a", count=10, length=100): + return string.count(substring) == count and len(string) == length + ``` +
19% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(substring="a", count=10, length=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with a certain number of copies of a given substring and of a given length""" + ``` + Shortest Codex solution: + ```python + + return "a"*10 + "b"*90 + + ``` + Longest Codex solution: + ```python + + if not isinstance(substring, str): + raise TypeError(f"expected string got {type(substring).__name__}") + if not isinstance(count, int): + raise TypeError(f"expected int got {type(count).__name__}") + if not isinstance(length, int): + raise TypeError(f"expected int got {type(length).__name__}") + return substring * count + "0"*(length - count*len(substring)) + + ``` + Hand-written solution: + ```python + c = chr(1 + max(ord(c) for c in (substring or "a"))) # a character not in substring + return substring * count + (length - len(substring) * count) * '^' + ``` +
+ +* **IntMul** (5 instances) + + ```python + def sat(n: int, a=14302, b=5): + return b * n + (a % b) == a + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=14302, b=5): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a multiplication problem""" + ``` + Shortest Codex solution: + ```python + + return a//b + ``` + Longest Codex solution: + ```python + + n = 1 + while True: + x = b * n + (a % b) + if x == a: + return n + elif x > a: + n -= 1 + break + n += 1 + while True: + x = b * n + (a % b) + if x == a: + return n + elif x < a: + n += 1 + else: + n -= 1 + break + return -1 + + ``` + Hand-written solution: + ```python + return a // b + ``` +
+ +* **StrSplitter** (5 instances) + + ```python + def sat(x: str, parts=['I', 'love', 'dumplings', '!', ''], string="I_love_dumplings_!_"): + return string.split(x) == parts + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(parts=['I', 'love', 'dumplings', '!', ''], string="I_love_dumplings_!_"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a separator that when used to split a given string gives a certain result""" + ``` + Shortest Codex solution: + ```python + + return "_" + ``` + Longest Codex solution: + ```python + + max_len = max(len(part) for part in parts) + for length in range(max_len + 1, 0, -1): + tested_chars = set() + for i in range(len(string) - len(parts) - 1): + for j in range(i + length, len(string), length): + if len(tested_chars | (set(string[i:j]))) > len(parts): + continue + if sat(string[i:j], string=string): + return string[i:j] + tested_chars.add(string[i:j]) + + + ``` + Hand-written solution: + ```python + if len(parts) <= 1: + return string * 2 + length = (len(string) - len("".join(parts))) // (len(parts) - 1) + start = len(parts[0]) + return string[start:start + length] + ``` +
+ +* **IntSub** (5 instances) + + ```python + def sat(x: int, a=-382, b=14546310): + return x - a == b + ``` +
17% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=-382, b=14546310): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve a subtraction problem""" + ``` + Shortest Codex solution: + ```python + + return a+b + ``` + Longest Codex solution: + ```python + + # The problem is given as x - a = b + # Solve the problem by starting the search + # at x = -(b + a) because neither a or b + # are negative. + return b + a + + ``` + Hand-written solution: + ```python + return a + b + ``` +
+ +* **FloatSquareRoot** (5 instances) + + ```python + def sat(x: float, a=1020): + return abs(x ** 2 - a) < 10 ** -3 + ``` +
15% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=1020): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a number that when squared is close to a.""" + ``` + Shortest Codex solution: + ```python + + return a**.5 + + ``` + Longest Codex solution: + ```python + + for i in range(1000000): + # This is a rather bad idea, but hey, it's a sample of a trick. :) + # + # What's a booboo? Well, if a is negative, the problem is actually the + # reverse, which is trivially solvable by changing the root operator from + # sqrt to **. + if sat(float(i) ** 0.5, a): + return float(i) ** 0.5 + + ``` + Hand-written solution: + ```python + return a ** 0.5 + ``` +
+ +* **HelloWorld** Trivial example, no solutions provided (1 instance) + + ```python + def sat(s: str): + return s + 'world' == 'Hello world' + ``` +
15% Codex success rate, 0 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that when concatenated onto 'world' gives 'Hello world'.""" + ``` + Shortest Codex solution: + ```python + + return "Hello " + ``` + Longest Codex solution: + ```python + + for i in range(len("Hello ")): + s = "Hello " + "abcdefghijklmnopqrstuvwxyz" * i + if s + 'world' == 'Hello world': + return s + + ``` +
+ +* **StrNegAt** (5 instances) + + ```python + def sat(i: int, s="cat", target="a"): + return s[i] == target and i < 0 + ``` +
12% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="cat", target="a"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the index of target in s using a negative index.""" + ``` + Shortest Codex solution: + ```python + + return -2 + + ``` + Longest Codex solution: + ```python + + # Cat is a string so s[i] is a character. Indexing a string produces a character for a positive index. + # Could also do the following + # for i in range(len(s)): + # if s[i] == target: + # return i + # return -1 + for i in range(len(s) * -1, 0, 1): + if s[i] == target: + return i + return -1 + + ``` + Hand-written solution: + ```python + return - (len(s) - s.index(target)) + ``` +
+ +* **StrSplit** (5 instances) + + ```python + def sat(x: str, parts=['I', 'love', 'dumplings', '!'], length=100): + return len(x) == length and x.split() == parts + ``` +
9.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(parts=['I', 'love', 'dumplings', '!'], length=100): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string of a given length with a certain split""" + ``` + Shortest Codex solution: + ```python + + return ' '.join(parts).ljust(100) + + ``` + Longest Codex solution: + ```python + + combined_str = [] + for part in parts: + combined_str += list(part) # convert the part into a list of chars + combined_str.append(' ') # append a space + + # shorten or lengthen the string so it has length + if len(combined_str) > length: + combined_str = combined_str[:(length - 1)] + else: + combined_str += [' '] * (length - len(combined_str)) + return "".join(combined_str) + + ``` + Hand-written solution: + ```python + joined = " ".join(parts) + return joined + " " * (length - len(joined)) + ``` +
+ +* **ListSetLen** (5 instances) + + ```python + def sat(li: List[int], dups=42155): + return len(set(li)) == len(li) - dups + ``` +
9.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(dups=42155): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list with a certain number of duplicate items""" + ``` + Shortest Codex solution: + ```python + + return [0]*42156 + + ``` + Longest Codex solution: + ```python + + # If dups is named it will be passed in the "kwargs" that the test will + # check. If it is implicit then it will be passed in as an argument. It + # probably shouldn't be always part of arguments since you shouldn't always + # need it and it shouldn't be something that you shouldn't also name. + li = [1] * dups + return li + [1] + + ``` + Hand-written solution: + ```python + return [1] * (dups + 1) + ``` +
+ +* **ListNegAt** (5 instances) + + ```python + def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91): + return li[i] == target and i < 0 + ``` +
9.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the index of an item in a list using negative indexing.""" + ``` + Shortest Codex solution: + ```python + + return -5 + + ``` + Longest Codex solution: + ```python + + # the first item of the list is li[0], and its index is -len(li) (e.g. first index = -1 and second index = -2). + # the last item of the list is li[-1] and its index is -1. + # for any other item, the index is the same as the index of the previous item. + return li.index(target) - len(li) + + ``` + Hand-written solution: + ```python + return li.index(target) - len(li) + ``` +
+ +* **FloatNegSquareRoot** (5 instances) + + ```python + def sat(x: float, a=1020): + return abs(x ** 2 - a) < 10 ** -3 and x < 0 + ``` +
7.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=1020): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a negative number that when squared is close to a.""" + ``` + Shortest Codex solution: + ```python + + return -a**.5 + + ``` + Longest Codex solution: + ```python + + r = 10 ** -5 # A bit too small, but that's okay. We don't know what a is. + while True: + x = -5 # A bit too low, but that's okay. We don't know what a is. + while r > 10 ** -3: + if sat(x, a): + return x + x -= 10**-5 + r /= 10**-5 + + ``` + Hand-written solution: + ```python + return -a ** 0.5 + ``` +
+ +* **IntNegSquareRoot** (5 instances) + + ```python + def sat(n: int, a=10000200001): + return a == n * n and n < 0 + ``` +
6.9% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a=10000200001): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a negative integer that when squared equals perfect-square a.""" + ``` + Shortest Codex solution: + ```python + + return -100001 + + ``` + Longest Codex solution: + ```python + + # Newton's method is one of the faster ways of finding square roots, + # but not the fastest. + # https://en.wikipedia.org/wiki/Newton's_method#Square_roots + # For finding large perfect squares, Newton's method is pretty fast + # (can do ~100000 * 100000 / second). + # https://www.wolframalpha.com/input/?i=newt+solve+x%5E2-a%3D0 + for y in range(0, -1000000000 // 2, -1): + if y * y == a: + return y + + ``` + Hand-written solution: + ```python + return -int(a ** 0.5) + ``` +
+ +* **StrMul** (5 instances) + + ```python + def sat(s: str, target="foofoofoofoo", n=2): + return s * n == target + ``` +
6.3% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target="foofoofoofoo", n=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string which when repeated n times gives target""" + ``` + Shortest Codex solution: + ```python + + return "foo"*n + + ``` + Longest Codex solution: + ```python + + def ans(): + return "Try again!\nThis does not work: %s" %(target[:n],) + if len(target) < n: return "Try again!\nYour target string is shorter than your repeat count." + for i in range(len(target)): + for j in range(i+1, len(target)+1): + if target[i:j] * n == target: + return target[i:j] + return ans() + + ``` + Hand-written solution: + ```python + if n == 0: + return '' + return target[:len(target) // n] + ``` +
+ +* **StrIndex2** (5 instances) + + ```python + def sat(big_str: str, sub_str="foobar", index=2): + return big_str.index(sub_str) == index + ``` +
5.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(sub_str="foobar", index=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string whose *first* index of sub_str is index""" + ``` + Shortest Codex solution: + ```python + + return "ohfoobar" + + ``` + Longest Codex solution: + ```python + + totlen = 1000 + big_str = "a"*totlen + big_str = big_str[:index] + sub_str + big_str[index:] + nstr = big_str[:999] + "a" + return nstr + n: int = len(big_str) + big_str = big_str[:9999] + big_str[:9999] + return big_str[:n] == big_str[:n + 2] and big_str[:n + 3] == big_str[:n + 4] + + ``` + Hand-written solution: + ```python + i = ord('A') + while chr(i) in sub_str: + i += 1 + return chr(i) * index + sub_str + ``` +
+ +* **StrSetLen** (4 instances) + + ```python + def sat(s: str, dups=2021): + return len(set(s)) == len(s) - dups + ``` +
5.8% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(dups=2021): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string with dups duplicate chars""" + ``` + Shortest Codex solution: + ```python + + return "a"*2022 + + ``` + Longest Codex solution: + ```python + + count = 0 + result = [] + for i, ii in enumerate(range(dups)): + result.append(chr(ord("A")+i*2)) + count += 1 + for i, ii in enumerate(range(dups, dups*2)): + result.append(chr(ord("A")+i*2+1)) + count += 1 + for i, ii in enumerate(range(dups*2, dups*3)): + result.append(chr(ord("A")+i)) + count += 1 + return "".join(result) + + + ``` + Hand-written solution: + ```python + return "a" * (dups + 1) + ``` +
+ +* **ListIndex2** (5 instances) + + ```python + def sat(li: List[int], i=29, index=10412): + return li.index(i) == index + ``` +
5.7% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(i=29, index=10412): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list that contains i first at index index""" + ``` + Shortest Codex solution: + ```python + + return [0]*index+[i] + + ``` + Longest Codex solution: + ```python + + return [j-j**2+(j**3)*3 for j in range(index)] + [i] + [j-j**2+(j**3)*3 for j in range(index, i)] + # (Inspired by http://www.davekoelle.com/hexagonal.html) + # Warning: Maximum recursion depth exceeded with default arguments + + ``` + Hand-written solution: + ```python + return [i - 1] * index + [i] + ``` +
+ +* **ListMul** (5 instances) + + ```python + def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2): + return li * n == target + ``` +
5.5% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(target=[17, 9, -1, 17, 9, -1], n=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list that when multiplied n times gives the target list""" + ``` + Shortest Codex solution: + ```python + + return [17,9,-1] + + ``` + Longest Codex solution: + ```python + + li = [17, 9, -1] + while True: + if li[-1] >= 0: + li.append(target[len(li)] - sum(li)) + else: + i = len(li) - len(target) + if li[i] <= target[i]: + break + k = target[i] / li[i] + li.append(0) + for j in range(i+1, len(li)): + li[j] = (li[j] - li[i] * (k - 1)) + break + return li + + ``` + Hand-written solution: + ```python + if n == 0: + return [] + return target[:len(target) // n] + ``` +
+ +* **StrJoiner** (5 instances) + + ```python + def sat(x: str, parts=['I!!', '!love', 'dumplings', '!', ''], string="I!!!!!love!!dumplings!!!!!"): + return x.join(parts) == string + ``` +
4.1% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(parts=['I!!', '!love', 'dumplings', '!', ''], string="I!!!!!love!!dumplings!!!!!"): + ``` + Solution docstring (*not* usually provided) + + ```python + """ + Find a separator that when used to join a given string gives a certain result. + This is related to the previous problem but there are some edge cases that differ. + """ + ``` + Shortest Codex solution: + ```python + + return "!!" + ``` + Longest Codex solution: + ```python + + for start in range(9): + for end in range(9): + separator = string[start:end+1] + if sat(separator, parts, string): + if separator == "Ilove" and parts[1] != "!love": + continue + if separator == "!love" and parts[0] != "I!!": + continue + return separator + + ``` + Hand-written solution: + ```python + if len(parts) <= 1: + return "" + length = (len(string) - len("".join(parts))) // (len(parts) - 1) + start = len(parts[0]) + return string[start:start + length] + ``` +
+ +* **StrIn** (5 instances) + + ```python + def sat(s: str, a="hello", b="yellow", length=4): + return len(s) == length and s in a and s in b + ``` +
2.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a="hello", b="yellow", length=4): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string of length length that is in both strings a and b""" + ``` + Shortest Codex solution: + ```python + + return a[1:] + + ``` + Longest Codex solution: + ```python + + # We want the middle of the string. + min_candidate, max_candidate = length//2, length//2 + 1 + while max_candidate <= len(a) or min_candidate >= 0: + candidate = (min_candidate + max_candidate) // 2 + if sat(a[candidate:candidate+length], a, b, length): + return a[candidate:candidate+length] + elif sat(a[candidate-1:candidate+length-1], a, b, length): + return a[candidate-1:candidate+length-1] + + ``` + Hand-written solution: + ```python + for i in range(len(a) - length + 1): + if a[i:i + length] in b: + return a[i:i + length] + ``` +
+ +* **StrIndex** (5 instances) + + ```python + def sat(s: str, big_str="foobar", index=2): + return big_str.index(s) == index + ``` +
2.2% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(big_str="foobar", index=2): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string whose *first* index in big_str is index""" + ``` + Shortest Codex solution: + ```python + + return "ob" + ``` + Longest Codex solution: + ```python + + if len(big_str) < index: + return None + i = 0 + while i < index: + chr = big_str[i] + matching = big_str[index:].split(chr, 1)[0] + if len(matching) > 0: + return matching + i += 1 + + ``` + Hand-written solution: + ```python + return big_str[index:] + ``` +
+ +* **StrAdd** (5 instances) + + ```python + def sat(st: str, a="world", b="Hello world"): + return st + a == b + ``` +
1.4% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(a="world", b="Hello world"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Solve simple string addition problem.""" + ``` + Shortest Codex solution: + ```python + + return b[:6] + + ``` + Longest Codex solution: + ```python + + st = "Hello " + for i in range(1000): + if (st + a).count(a) == 1000: + return st + a + if sat(st, a, b): + return st + st += a[i % len(a)] + return -1 + + ``` + Hand-written solution: + ```python + return b[:len(b) - len(a)] + ``` +
+ +* **BackWorlds** We provide two solutions (1 instance) + + ```python + def sat(s: str): + return s[::-1] + 'world' == 'Hello world' + ``` +
0.24% Codex success rate, 2 hand-written solutions + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that when reversed and concatenated onto 'world' gives 'Hello world'.""" + ``` + Shortest Codex solution: + ```python + + return "Hello "[::-1] + + ``` + Longest Codex solution: + ```python + + ans = "Hello " + for i in range(1000, 0, -1): + if str(i * i).endswith("123456789"): + ans = str(i) + ans + break + return ans[::-1] + + ``` + Hand-written solution: + ```python + return ' olleH' + ``` + Hand-written solution: + ```python + # solution methods must begin with 'sol' + return 'Hello '[::-1] + ``` +
+ +* **StrIn2** (5 instances) + + ```python + def sat(substrings: List[str], s="hello", count=15): + return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings) + ``` +
0.07% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="hello", count=15): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of >= count distinct strings that are all contained in s""" + ``` + Shortest Codex solution: + ```python + + words = set() + for i in range(count): + words |= {s[j:j+i] for j in range(len(s)-i+1)} + return sorted(words) + + ``` + Longest Codex solution: + ```python + + substrings = set() + out = [] + for i in range(0, len(s)+1): + for j in range(i, len(s)+1): + substrings.add(s[i:j]) + for sub in substrings: + if sub not in out: + out.append(sub) + if len(out) >= count: + return out + raise RuntimeError("Failed to find enough substrings") + + ``` + Hand-written solution: + ```python + return [""] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)}) + ``` +
+ +* **StrSlice** (5 instances) + + ```python + def sat(inds: List[int], s="hello world", target="do"): + i, j, k = inds + return s[i:j:k] == target + ``` +
0.053% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(s="hello world", target="do"): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find the three slice indices that give the specific target in string s""" + ``` + Shortest Codex solution: + ```python + + return [36, 6, -3] + + ``` + Longest Codex solution: + ```python + + i = 0 + while i + len(target) <= len(s): + if s[i:i+len(target)] == target: + break + i += 1 + + j = len(s) + while j - len(target) >= 0: + if s[j-len(target):j] == target: + break + j -= 1 + + k = -1 + while True: if s[i:j:k] == target: - return [i, j, k] - except (IndexError, ValueError): - pass -``` - -
- -### StrIndex - - -```python -def sat(s: str, big_str="foobar", index=2): - """Find a string whose *first* index in big_str is index""" - return big_str.index(s) == index -``` -
1 solution to trivial_inverse 11/39 - -```python -def sol(big_str="foobar", index=2): - return big_str[index:] -``` - -
- -### StrIndex2 - - -```python -def sat(big_str: str, sub_str="foobar", index=2): - """Find a string whose *first* index of sub_str is index""" - return big_str.index(sub_str) == index -``` -
1 solution to trivial_inverse 12/39 - -```python -def sol(sub_str="foobar", index=2): - i = ord('A') - while chr(i) in sub_str: - i += 1 - return chr(i) * index + sub_str -``` - -
- -### StrIn - - -```python -def sat(s: str, a="hello", b="yellow", length=4): - """Find a string of length length that is in both strings a and b""" - return len(s) == length and s in a and s in b -``` -
1 solution to trivial_inverse 13/39 - -```python -def sol(a="hello", b="yellow", length=4): - for i in range(len(a) - length + 1): - if a[i:i + length] in b: - return a[i:i + length] -``` - -
- -### StrIn2 - - -```python -def sat(substrings: List[str], s="hello", count=15): - """Find a list of >= count distinct strings that are all contained in s""" - return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings) -``` -
1 solution to trivial_inverse 14/39 - -```python -def sol(s="hello", count=15): - return [""] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)}) -``` - -
- -### StrCount - - -```python -def sat(string: str, substring="a", count=10, length=100): - """Find a string with a certain number of copies of a given substring and of a given length""" - return string.count(substring) == count and len(string) == length -``` -
1 solution to trivial_inverse 15/39 - -```python -def sol(substring="a", count=10, length=100): - c = chr(1 + max(ord(c) for c in (substring or "a"))) # a character not in substring - return substring * count + (length - len(substring) * count) * '^' -``` - -
- -### StrSplit - - -```python -def sat(x: str, parts=['I', 'love', 'dumplings', '!'], length=100): - """Find a string of a given length with a certain split""" - return len(x) == length and x.split() == parts -``` -
1 solution to trivial_inverse 16/39 - -```python -def sol(parts=['I', 'love', 'dumplings', '!'], length=100): - joined = " ".join(parts) - return joined + " " * (length - len(joined)) -``` - -
- -### StrSplitter - - -```python -def sat(x: str, parts=['I', 'love', 'dumplings', '!', ''], string="I_love_dumplings_!_"): - """Find a separator that when used to split a given string gives a certain result""" - return string.split(x) == parts -``` -
1 solution to trivial_inverse 17/39 - -```python -def sol(parts=['I', 'love', 'dumplings', '!', ''], string="I_love_dumplings_!_"): - if len(parts) <= 1: - return string * 2 - length = (len(string) - len("".join(parts))) // (len(parts) - 1) - start = len(parts[0]) - return string[start:start + length] -``` - -
- -### StrJoiner - - -```python -def sat(x: str, parts=['I!!', '!love', 'dumplings', '!', ''], string="I!!!!!love!!dumplings!!!!!"): - """ - Find a separator that when used to join a given string gives a certain result. - This is related to the previous problem but there are some edge cases that differ. - """ - return x.join(parts) == string -``` -
1 solution to trivial_inverse 18/39 - -```python -def sol(parts=['I!!', '!love', 'dumplings', '!', ''], string="I!!!!!love!!dumplings!!!!!"): - if len(parts) <= 1: - return "" - length = (len(string) - len("".join(parts))) // (len(parts) - 1) - start = len(parts[0]) - return string[start:start + length] -``` - -
- -### StrParts - - -```python -def sat(parts: List[str], sep="!!", string="I!!!!!love!!dumplings!!!!!"): - """Find parts that when joined give a specific string.""" - return sep.join(parts) == string and all(sep not in p for p in parts) -``` -
1 solution to trivial_inverse 19/39 - -```python -def sol(sep="!!", string="I!!!!!love!!dumplings!!!!!"): - return string.split(sep) -``` - -
- -### ListSetLen - - -```python -def sat(li: List[int], dups=42155): - """Find a list with a certain number of duplicate items""" - return len(set(li)) == len(li) - dups -``` -
1 solution to trivial_inverse 20/39 - -```python -def sol(dups=42155): - return [1] * (dups + 1) -``` - -
- -### ListMul - - -```python -def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2): - """Find a list that when multiplied n times gives the target list""" - return li * n == target -``` -
1 solution to trivial_inverse 21/39 - -```python -def sol(target=[17, 9, -1, 17, 9, -1], n=2): - if n == 0: - return [] - return target[:len(target) // n] -``` - -
- -### ListLen - - -```python -def sat(li: List[int], n=85012): - """Find a list of a given length n""" - return len(li) == n -``` -
1 solution to trivial_inverse 22/39 - -```python -def sol(n=85012): - return [1] * n -``` - -
- -### ListAt - - -```python -def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18): - """Find the index of an item in a list. Any such index is fine.""" - return li[i] == target -``` -
1 solution to trivial_inverse 23/39 - -```python -def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18): - return li.index(target) -``` - -
- -### ListNegAt - - -```python -def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91): - """Find the index of an item in a list using negative indexing.""" - return li[i] == target and i < 0 -``` -
1 solution to trivial_inverse 24/39 - -```python -def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91): - return li.index(target) - len(li) -``` - -
- -### ListSlice - - -```python -def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]): - """Find three slice indices to achieve a given list slice""" - i, j, k = inds - return li[i:j:k] == target -``` -
1 solution to trivial_inverse 25/39 - -```python -def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]): - from itertools import product - for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3): - try: - if li[i:j:k] == target: - return [i, j, k] - except (IndexError, ValueError): - pass -``` - -
- -### ListIndex - - -```python -def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4): - """Find the item whose first index in li is index""" - return li.index(item) == index -``` -
1 solution to trivial_inverse 26/39 - -```python -def sol(li=[17, 2, 3, 9, 11, 11], index=4): - return li[index] -``` - -
- -### ListIndex2 - - -```python -def sat(li: List[int], i=29, index=10412): - """Find a list that contains i first at index index""" - return li.index(i) == index -``` -
1 solution to trivial_inverse 27/39 - -```python -def sol(i=29, index=10412): - return [i - 1] * index + [i] -``` - -
- -### ListIn - - -```python -def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']): - """Find an item that is in both lists a and b""" - return s in a and s in b -``` -
1 solution to trivial_inverse 28/39 - -```python -def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']): - return next(s for s in b if s in a) -``` - -
- -### IntNeg - - -```python -def sat(x: int, a=93252338): - """Solve a unary negation problem""" - return -x == a -``` -
1 solution to trivial_inverse 29/39 - -```python -def sol(a=93252338): - return - a -``` - -
- -### IntSum - - -```python -def sat(x: int, a=1073258, b=72352549): - """Solve a sum problem""" - return a + x == b -``` -
1 solution to trivial_inverse 30/39 - -```python -def sol(a=1073258, b=72352549): - return b - a -``` - -
- -### IntSub - - -```python -def sat(x: int, a=-382, b=14546310): - """Solve a subtraction problem""" - return x - a == b -``` -
1 solution to trivial_inverse 31/39 - -```python -def sol(a=-382, b=14546310): - return a + b -``` - -
- -### IntSub2 - - -```python -def sat(x: int, a=8665464, b=-93206): - """Solve a subtraction problem""" - return a - x == b -``` -
1 solution to trivial_inverse 32/39 - -```python -def sol(a=8665464, b=-93206): - return a - b -``` - -
- -### IntMul - - -```python -def sat(n: int, a=14302, b=5): - """Solve a multiplication problem""" - return b * n + (a % b) == a -``` -
1 solution to trivial_inverse 33/39 - -```python -def sol(a=14302, b=5): - return a // b -``` - -
- -### IntDiv - - -```python -def sat(n: int, a=3, b=23463462): - """Solve a division problem""" - return b // n == a -``` -
1 solution to trivial_inverse 34/39 - -```python -def sol(a=3, b=23463462): - if a == 0: - return 2 * b - for n in [b // a, b // a - 1, b // a + 1]: - if b // n == a: - return n -``` - -
- -### IntDiv2 - - -```python -def sat(n: int, a=345346363, b=10): - """Find n that when divided by b is a""" - return n // b == a -``` -
1 solution to trivial_inverse 35/39 - -```python -def sol(a=345346363, b=10): - return a * b -``` - -
- -### IntSquareRoot - - -```python -def sat(x: int, a=10201202001): - """Compute an integer that when squared equals perfect-square a.""" - return x ** 2 == a -``` -
1 solution to trivial_inverse 36/39 - -```python -def sol(a=10201202001): - return int(a ** 0.5) -``` - -
- -### IntNegSquareRoot - - -```python -def sat(n: int, a=10000200001): - """Find a negative integer that when squared equals perfect-square a.""" - return a == n * n and n < 0 -``` -
1 solution to trivial_inverse 37/39 - -```python -def sol(a=10000200001): - return -int(a ** 0.5) -``` - -
- -### FloatSquareRoot - - -```python -def sat(x: float, a=1020): - """Find a number that when squared is close to a.""" - return abs(x ** 2 - a) < 10 ** -3 -``` -
1 solution to trivial_inverse 38/39 - -```python -def sol(a=1020): - return a ** 0.5 -``` - -
- -### FloatNegSquareRoot - - -```python -def sat(x: float, a=1020): - """Find a negative number that when squared is close to a.""" - return abs(x ** 2 - a) < 10 ** -3 and x < 0 -``` -
1 solution to trivial_inverse 39/39 - -```python -def sol(a=1020): - return -a ** 0.5 -``` - -
- + break + k -= 1 + + return [i, j, k] + + ``` + Hand-written solution: + ```python + from itertools import product + for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3): + try: + if s[i:j:k] == target: + return [i, j, k] + except (IndexError, ValueError): + pass + ``` +
+ +* **ListSlice** (5 instances) + + ```python + def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]): + i, j, k = inds + return li[i:j:k] == target + ``` +
0% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find three slice indices to achieve a given list slice""" + ``` + Hand-written solution: + ```python + from itertools import product + for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3): + try: + if li[i:j:k] == target: + return [i, j, k] + except (IndexError, ValueError): + pass + ``` +
+ ## tutorial A few example puzzles that were presented with solutions to participants of the study. -### Tutorial1 - - -```python -def sat(s: str): - """Find a string that when concatenated onto 'Hello ' gives 'Hello world'.""" - return "Hello " + s == "Hello world" -``` -
1 solution to tutorial 1/5 - -```python -def sol(): - return "world" -``` - -
- -### Tutorial2 - - -```python -def sat(s: str): - """Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.""" - return "Hello " + s[::-1] == "Hello world" -``` -
1 solution to tutorial 2/5 - -```python -def sol(): - return "world"[::-1] -``` - -
- -### Tutorial3 - - -```python -def sat(x: List[int]): - """Find a list of two integers whose sum is 3.""" - return len(x) == 2 and sum(x) == 3 -``` -
1 solution to tutorial 3/5 - -```python -def sol(): - return [1, 2] -``` - -
- -### Tutorial4 - - -```python -def sat(s: List[str]): - """Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.""" - return len(set(s)) == 1000 and all((x.count("a") > x.count("b")) and ('b' in x) for x in s) -``` -
1 solution to tutorial 4/5 - -```python -def sol(): - return ["a" * (i + 2) + "b" for i in range(1000)] -``` - -
- -### Tutorial5 - - -```python -def sat(n: int): - """Find an integer whose perfect square begins with 123456789 in its decimal representation.""" - return str(n * n).startswith("123456789") -``` -
1 solution to tutorial 5/5 - -```python -def sol(): - return int(int("123456789" + "0" * 9) ** 0.5) + 1 -``` - -
- +* **Tutorial4** (1 instance) + + ```python + def sat(s: List[str]): + return len(set(s)) == 1000 and all((x.count("a") > x.count("b")) and ('b' in x) for x in s) + ``` +
83% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.""" + ``` + Shortest Codex solution: + ```python + + return ["aba"*(i+2) for i in range(1000)] + + ``` + Longest Codex solution: + ```python + + return ["a"*(i+2)+"b" for i in range(1000)] + + ``` + Hand-written solution: + ```python + return ["a" * (i + 2) + "b" for i in range(1000)] + ``` +
+ +* **Tutorial1** (1 instance) + + ```python + def sat(s: str): + return "Hello " + s == "Hello world" + ``` +
79% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that when concatenated onto 'Hello ' gives 'Hello world'.""" + ``` + Shortest Codex solution: + ```python + + return "world" + ``` + Longest Codex solution: + ```python + + if True: + # a quick and nasty way + return "world" + else: + # a more complex way that uses ideas from the previous problems + def most_common(arr): + most_commons = [] + most_counts = [] + most_count = 0 + for x in arr: + count = 0 + for y in arr: + if x == y: + count += 1 + if count > most_count: + most_counts = [x] + elif count == most_count: + most_counts.append(x) + return most_counts + + ``` + Hand-written solution: + ```python + return "world" + ``` +
+ +* **Tutorial3** (1 instance) + + ```python + def sat(x: List[int]): + return len(x) == 2 and sum(x) == 3 + ``` +
79% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a list of two integers whose sum is 3.""" + ``` + Shortest Codex solution: + ```python + + return [1,2] + + ``` + Longest Codex solution: + ```python + + for i in range(10**6): + s = bin(i)[2:] + i0 = s.find('0') + i1 = s.find('1') + if i1 == -1: + i1 = len(s) + if i1 - i0 > 1: + x = [int(s[:i0], 2), int(s[i0:i1],2)] + if sum(x) == 3: + return x + return [1, 2] + + ``` + Hand-written solution: + ```python + return [1, 2] + ``` +
+ +* **Tutorial2** (1 instance) + + ```python + def sat(s: str): + return "Hello " + s[::-1] == "Hello world" + ``` +
78% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.""" + ``` + Shortest Codex solution: + ```python + + return "dlrow" + + ``` + Longest Codex solution: + ```python + + s = "!!@@##$%%%^&" + return "world"[::-1].replace("!", s[2])\ + .replace("#", s[4])\ + .replace("$", s[6])\ + .replace("%", s[8])\ + .replace("^", s[0])\ + .replace("&", s[1]) + + ``` + Hand-written solution: + ```python + return "world"[::-1] + ``` +
+ +* **Tutorial5** (1 instance) + + ```python + def sat(n: int): + return str(n * n).startswith("123456789") + ``` +
47% Codex success rate, 1 hand-written solution + + Solution header: + ```python + def sol(): + ``` + Solution docstring (*not* usually provided) + + ```python + """Find an integer whose perfect square begins with 123456789 in its decimal representation.""" + ``` + Shortest Codex solution: + ```python + + return int("1"*9) + + ``` + Longest Codex solution: + ```python + + #return int(int("123456789" + "0"*9) ** 0.5) + 1 # This one doesn't work + string = "123456789" + p = int(int(string + "0"*9) ** 0.5) + 1 + p2 = str(p * p) + if p2.startswith(string): + return p + else: + if len(string) == 9: + return 10 * g6() + 1 + left = string[:len(string)//2] + right = string[len(string)//2:] + return 10 ** len + ``` + Hand-written solution: + ```python + return int(int("123456789" + "0" * 9) ** 0.5) + 1 + ``` +
+ diff --git a/puzzles/puzzles.json b/puzzles/puzzles.json index 5adf9df..709533a 100644 --- a/puzzles/puzzles.json +++ b/puzzles/puzzles.json @@ -1,29364 +1,22226 @@ [ { - "name": "Study_1_0", - "sat": "def sat(s: str):\n \"\"\"Find a string with 1000 'o's but no two adjacent 'o's.\"\"\"\n return s.count('o') == 1000 and s.count('oo') == 0", - "sols": [ - "def sol():\n return ('h' + 'o') * 1000" + "name": "Study_1:0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 0", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string with 1000 'o's but no two adjacent 'o's.\"\"\"", + "sol_bodies": [ + " return ('h' + 'o') * 1000" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_2_0", - "sat": "def sat(s: str):\n \"\"\"Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.\"\"\"\n return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801", - "sols": [ - "def sol():\n return 'ho' * (800 + 1) + 'o' * (100 * 2 - 1)" + "name": "Study_2:0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.\"\"\"", + "sol_bodies": [ + " return 'ho' * (800 + 1) + 'o' * (100 * 2 - 1)" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_3_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.\"\"\"\n return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li)))", - "sols": [ - "def sol():\n return [((i + 1) % 999) for i in range(999)]" + "name": "Study_3:0", + "sat": "def sat(li: List[int]):\n return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li)))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.\"\"\"", + "sol_bodies": [ + " return [((i + 1) % 999) for i in range(999)]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_4_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of length 10 where the fourth element occurs exactly twice.\"\"\"\n return len(li) == 10 and li.count(li[3]) == 2", - "sols": [ - "def sol():\n return list(range(10 // 2)) * 2" + "name": "Study_4:0", + "sat": "def sat(li: List[int]):\n return len(li) == 10 and li.count(li[3]) == 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of length 10 where the fourth element occurs exactly twice.\"\"\"", + "sol_bodies": [ + " return list(range(10 // 2)) * 2" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_5_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.\"\"\"\n return all([li.count(i) == i for i in range(10)])", - "sols": [ - "def sol():\n return [i for i in range(10) for j in range(i)]" + "name": "Study_5:0", + "sat": "def sat(li: List[int]):\n return all([li.count(i) == i for i in range(10)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.\"\"\"", + "sol_bodies": [ + " return [i for i in range(10) for j in range(i)]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_6_0", - "sat": "def sat(i: int):\n \"\"\"Find an integer greater than 10^10 which is 4 mod 123.\"\"\"\n return i % 123 == 4 and i > 10 ** 10", - "sols": [ - "def sol():\n return 4 + 10 ** 10 + 123 - 10 ** 10 % 123" + "name": "Study_6:0", + "sat": "def sat(i: int):\n return i % 123 == 4 and i > 10 ** 10", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer greater than 10^10 which is 4 mod 123.\"\"\"", + "sol_bodies": [ + " return 4 + 10 ** 10 + 123 - 10 ** 10 % 123" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_7_0", - "sat": "def sat(s: str):\n \"\"\"Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.\"\"\"\n return str(8 ** 2888).count(s) > 8 and len(s) == 3", - "sols": [ - "def sol():\n s = str(8 ** 2888)\n return max({s[i: i + 3] for i in range(len(s) - 2)}, key=lambda t: s.count(t))" + "name": "Study_7:0", + "sat": "def sat(s: str):\n return str(8 ** 2888).count(s) > 8 and len(s) == 3", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.\"\"\"", + "sol_bodies": [ + " s = str(8 ** 2888)\n return max({s[i: i + 3] for i in range(len(s) - 2)}, key=lambda t: s.count(t))" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_8_0", - "sat": "def sat(ls: List[str]):\n \"\"\"Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.\"\"\"\n return ls[1234] in ls[1235] and ls[1234] != ls[1235]", - "sols": [ - "def sol():\n return [''] * 1235 + ['a']" + "name": "Study_8:0", + "sat": "def sat(ls: List[str]):\n return ls[1234] in ls[1235] and ls[1234] != ls[1235]", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.\"\"\"", + "sol_bodies": [ + " return [''] * 1235 + ['a']" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_9_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Find a way to rearrange the letters in the pangram \"The quick brown fox jumps over the lazy dog\" to get\n the pangram \"The five boxing wizards jump quickly\". The answer should be represented as a list of index\n mappings.\n \"\"\"\n return [\"The quick brown fox jumps over the lazy dog\"[i] for i in li] == list(\n \"The five boxing wizards jump quickly\")", - "sols": [ - "def sol():\n return ['The quick brown fox jumps over the lazy dog'.index(t)\n for t in 'The five boxing wizards jump quickly']" + "name": "Study_9:0", + "sat": "def sat(li: List[int]):\n return [\"The quick brown fox jumps over the lazy dog\"[i] for i in li] == list(\n \"The five boxing wizards jump quickly\")", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a way to rearrange the letters in the pangram \"The quick brown fox jumps over the lazy dog\" to get\n the pangram \"The five boxing wizards jump quickly\". The answer should be represented as a list of index\n mappings.\n \"\"\"", + "sol_bodies": [ + " return ['The quick brown fox jumps over the lazy dog'.index(t)\n for t in 'The five boxing wizards jump quickly']" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_10_0", - "sat": "def sat(s: str):\n \"\"\"Find a palindrome of length greater than 11 in the decimal representation of 8^1818.\"\"\"\n return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11", - "sols": [ - "def sol():\n s = str(8 ** 1818)\n return next(s[i: i + le]\n for le in range(12, len(s) + 1)\n for i in range(len(s) - le + 1)\n if s[i: i + le] == s[i: i + le][::-1]\n )" + "name": "Study_10:0", + "sat": "def sat(s: str):\n return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a palindrome of length greater than 11 in the decimal representation of 8^1818.\"\"\"", + "sol_bodies": [ + " s = str(8 ** 1818)\n return next(s[i: i + le]\n for le in range(12, len(s) + 1)\n for i in range(len(s) - le + 1)\n if s[i: i + le] == s[i: i + le][::-1]\n )" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_11_0", - "sat": "def sat(ls: List[str]):\n \"\"\"\n Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element\n and is equal to the lexicographically smallest element.\n \"\"\"\n return min(ls) == max(ls) == str(len(ls))", - "sols": [ - "def sol():\n return ['1']" + "name": "Study_11:0", + "sat": "def sat(ls: List[str]):\n return min(ls) == max(ls) == str(len(ls))", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element\n and is equal to the lexicographically smallest element.\n \"\"\"", + "sol_bodies": [ + " return ['1']" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_12_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first\n integer plus 4 is 9.\"\"\"\n return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000", - "sols": [ - "def sol():\n return [9 - 4, 4] * (1000 // 2)" + "name": "Study_12:0", + "sat": "def sat(li: List[int]):\n return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first\n integer plus 4 is 9.\"\"\"", + "sol_bodies": [ + " return [9 - 4, 4] * (1000 // 2)" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_13_0", - "sat": "def sat(x: float):\n \"\"\"Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.\"\"\"\n return str(x - 3.1415).startswith(\"123.456\")", - "sols": [ - "def sol():\n return 123.456 + 3.1415" + "name": "Study_13:0", + "sat": "def sat(x: float):\n return str(x - 3.1415).startswith(\"123.456\")", + "ans_type": "float", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.\"\"\"", + "sol_bodies": [ + " return 123.456 + 3.1415" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_14_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.\"\"\"\n return all([sum(li[:i]) == i for i in range(20)])", - "sols": [ - "def sol():\n return [1] * 20" + "name": "Study_14:0", + "sat": "def sat(li: List[int]):\n return all([sum(li[:i]) == i for i in range(20)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.\"\"\"", + "sol_bodies": [ + " return [1] * 20" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_15_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.\"\"\"\n return all(sum(li[:i]) == 2 ** i - 1 for i in range(20))", - "sols": [ - "def sol():\n return [(2 ** i) for i in range(20)]" + "name": "Study_15:0", + "sat": "def sat(li: List[int]):\n return all(sum(li[:i]) == 2 ** i - 1 for i in range(20))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.\"\"\"", + "sol_bodies": [ + " return [(2 ** i) for i in range(20)]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_16_0", - "sat": "def sat(s: str):\n \"\"\"Find a real number such that when you add the length of its decimal representation to it, you get 4.5.\n Your answer should be the string form of the number in its decimal representation.\"\"\"\n return float(s) + len(s) == 4.5", - "sols": [ - "def sol():\n return str(4.5 - len(str(4.5)))" + "name": "Study_16:0", + "sat": "def sat(s: str):\n return float(s) + len(s) == 4.5", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a real number such that when you add the length of its decimal representation to it, you get 4.5.\n Your answer should be the string form of the number in its decimal representation.\"\"\"", + "sol_bodies": [ + " return str(4.5 - len(str(4.5)))" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_17_0", - "sat": "def sat(i: int):\n \"\"\"Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.\"\"\"\n return len(str(i + 1000)) > len(str(i + 1001))", - "sols": [ - "def sol():\n return -1001" + "name": "Study_17:0", + "sat": "def sat(i: int):\n return len(str(i + 1000)) > len(str(i + 1001))", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.\"\"\"", + "sol_bodies": [ + " return -1001" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_18_0", - "sat": "def sat(ls: List[str]):\n \"\"\"\n Find a list of strings that when you combine them in all pairwise combinations gives the six strings:\n 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin'\n \"\"\"\n return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split()", - "sols": [ - "def sol():\n seen = set()\n ans = []\n for s in 'berlin berger linber linger gerber gerlin'.split():\n t = s[:3]\n if t not in seen:\n ans.append(t)\n seen.add(t)\n return ans" + "name": "Study_18:0", + "sat": "def sat(ls: List[str]):\n return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split()", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of strings that when you combine them in all pairwise combinations gives the six strings:\n 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin'\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for s in 'berlin berger linber linger gerber gerlin'.split():\n t = s[:3]\n if t not in seen:\n ans.append(t)\n seen.add(t)\n return ans" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_19_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Find a list of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n That is find L such that, { i + j | i, j in L } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n \"\"\"\n return {i + j for i in li for j in li} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}", - "sols": [ - "def sol():\n return [0, 1, 2, 3, 17]" + "name": "Study_19:0", + "sat": "def sat(li: List[int]):\n return {i + j for i in li for j in li} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n That is find L such that, { i + j | i, j in L } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n \"\"\"", + "sol_bodies": [ + " return [0, 1, 2, 3, 17]" ], - "module": "study", + "module": "study.py", "notes": "9/15/2021 Updated to take a list rather than a set because it was the only puzzle in the repo with Set argument.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_20_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128]))", - "sols": [ - "def sol():\n return [1, 3, 4, 12, 13, 14, 42, 126, 127]" + "name": "Study_20:0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128]))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"", + "sol_bodies": [ + " return [1, 3, 4, 12, 13, 14, 42, 126, 127]" ], - "module": "study", + "module": "study.py", "notes": "A more interesting version of this puzzle with a length constraint is ShortIntegerPath in graphs.py", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_21_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Find a list integers containing exactly three distinct values, such that no integer repeats\n twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.)\n \"\"\"\n return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3", - "sols": [ - "def sol():\n return list(range(3)) * 10" + "name": "Study_21:0", + "sat": "def sat(li: List[int]):\n return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list integers containing exactly three distinct values, such that no integer repeats\n twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.)\n \"\"\"", + "sol_bodies": [ + " return list(range(3)) * 10" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_22_0", - "sat": "def sat(s: str):\n \"\"\"\n Find a string s containing exactly five distinct characters which also contains as a substring every other\n character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs').\n \"\"\"\n return s[::2] in s and len(set(s)) == 5", - "sols": [ - "def sol():\n return \"\"\"abacadaeaaaaaaaaaa\"\"\"" + "name": "Study_22:0", + "sat": "def sat(s: str):\n return s[::2] in s and len(set(s)) == 5", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a string s containing exactly five distinct characters which also contains as a substring every other\n character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs').\n \"\"\"", + "sol_bodies": [ + " return \"\"\"abacadaeaaaaaaaaaa\"\"\"" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_23_0", - "sat": "def sat(ls: List[str]):\n \"\"\"\n Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'.\n \"\"\"\n return tuple(ls) in zip('dee', 'doo', 'dah!')", - "sols": [ - "def sol():\n return list(next(zip('dee', 'doo', 'dah!')))" + "name": "Study_23:0", + "sat": "def sat(ls: List[str]):\n return tuple(ls) in zip('dee', 'doo', 'dah!')", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'.\n \"\"\"", + "sol_bodies": [ + " return list(next(zip('dee', 'doo', 'dah!')))" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_24_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.\"\"\"\n return li.count(17) == 3 and li.count(3) >= 2", - "sols": [ - "def sol():\n return [17] * 3 + [3] * 2" + "name": "Study_24:0", + "sat": "def sat(li: List[int]):\n return li.count(17) == 3 and li.count(3) >= 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.\"\"\"", + "sol_bodies": [ + " return [17] * 3 + [3] * 2" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_25_0", - "sat": "def sat(s: str):\n \"\"\"Find a permutation of the string 'Permute me true' which is a palindrome.\"\"\"\n return sorted(s) == sorted('Permute me true') and s == s[::-1]", - "sols": [ - "def sol():\n s = sorted('Permute me true'[1:])[::2]\n return \"\".join(s + ['P'] + s[::-1])" + "name": "Study_25:0", + "sat": "def sat(s: str):\n return sorted(s) == sorted('Permute me true') and s == s[::-1]", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a permutation of the string 'Permute me true' which is a palindrome.\"\"\"", + "sol_bodies": [ + " s = sorted('Permute me true'[1:])[::2]\n return \"\".join(s + ['P'] + s[::-1])" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_26_0", - "sat": "def sat(ls: List[str]):\n \"\"\"Divide the decimal representation of 8^88 up into strings of length eight.\"\"\"\n return \"\".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls)", - "sols": [ - "def sol():\n return [str(8 ** 88)[i:i + 8] for i in range(0, len(str(8 ** 88)), 8)]" + "name": "Study_26:0", + "sat": "def sat(ls: List[str]):\n return \"\".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Divide the decimal representation of 8^88 up into strings of length eight.\"\"\"", + "sol_bodies": [ + " return [str(8 ** 88)[i:i + 8] for i in range(0, len(str(8 ** 88)), 8)]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_27_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and\n v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they\n share the same great-grandchildren. Represented this digraph by the list of children indices.\n \"\"\"\n return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]]", - "sols": [ - "def sol():\n return [1, 2, 3, 3]" + "name": "Study_27:0", + "sat": "def sat(li: List[int]):\n return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]]", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and\n v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they\n share the same great-grandchildren. Represented this digraph by the list of children indices.\n \"\"\"", + "sol_bodies": [ + " return [1, 2, 3, 3]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_28_0", - "sat": "def sat(li: List[int]):\n \"\"\"Find a list of one hundred integers between 0 and 999 which all differ by at least ten from one another.\"\"\"\n return all(i in range(1000) and abs(i - j) >= 10 for i in li for j in li if i != j) and len(set(li)) == 100", - "sols": [ - "def sol():\n return list(range(0, 1000, 10))" + "name": "Study_28:0", + "sat": "def sat(li: List[int]):\n return all(i in range(1000) and abs(i - j) >= 10 for i in li for j in li if i != j) and len(set(li)) == 100", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of one hundred integers between 0 and 999 which all differ by at least ten from one another.\"\"\"", + "sol_bodies": [ + " return list(range(0, 1000, 10))" ], - "module": "study", + "module": "study.py", "notes": "9/15/2021: updated to a list since sets were removed from puzzle formats", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_29_0", - "sat": "def sat(l: List[int]):\n \"\"\"\n Find a list of more than 995 distinct integers between 0 and 999, inclusive, such that each pair of integers\n have squares that differ by at least 10.\n \"\"\"\n return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in l for j in l if i != j) and len(set(l)) > 995", - "sols": [ - "def sol():\n return [0, 4] + list(range(6, 1000))" + "name": "Study_29:0", + "sat": "def sat(l: List[int]):\n return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in l for j in l if i != j) and len(set(l)) > 995", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of more than 995 distinct integers between 0 and 999, inclusive, such that each pair of integers\n have squares that differ by at least 10.\n \"\"\"", + "sol_bodies": [ + " return [0, 4] + list(range(6, 1000))" ], - "module": "study", + "module": "study.py", "notes": "9/15/2021: updated to a list since sets were removed from puzzle formats", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "Study_30_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one\n are between 0 and 999, inclusive, and are strictly increasing in terms of f(n).\n \"\"\"\n return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)])", - "sols": [ - "def sol():\n return sorted(range(1000), key=lambda n: 123 * n % 1000)[:21]", - "def sol():\n return list(range(1000))[::8][::-1]" + "name": "Study_30:0", + "sat": "def sat(li: List[int]):\n return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one\n are between 0 and 999, inclusive, and are strictly increasing in terms of f(n).\n \"\"\"", + "sol_bodies": [ + " return sorted(range(1000), key=lambda n: 123 * n % 1000)[:21]", + " return list(range(1000))[::8][::-1]" ], - "module": "study", + "module": "study.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 + "weight": 1.0 }, { - "name": "TowersOfHanoi_0", - "sat": "def sat(moves: List[List[int]]):\n \"\"\"\n Eight disks of sizes 1-8 are stacked on three towers, with each tower having disks in order of largest to\n smallest. Move [i, j] corresponds to taking the smallest disk off tower i and putting it on tower j, and it\n is legal as long as the towers remain in sorted order. Find a sequence of moves that moves all the disks\n from the first to last towers.\n \"\"\"\n rods = ([8, 7, 6, 5, 4, 3, 2, 1], [], [])\n for [i, j] in moves:\n rods[j].append(rods[i].pop())\n assert rods[j][-1] == min(rods[j]), \"larger disk on top of smaller disk\"\n return rods[0] == rods[1] == []", - "sols": [ - "def sol():\n def helper(m, i, j):\n if m == 0:\n return []\n k = 3 - i - j\n return helper(m - 1, i, k) + [[i, j]] + helper(m - 1, k, j)\n\n return helper(8, 0, 2)" + "name": "TowersOfHanoi:0", + "sat": "def sat(moves: List[List[int]]):\n rods = ([8, 7, 6, 5, 4, 3, 2, 1], [], [])\n for [i, j] in moves:\n rods[j].append(rods[i].pop())\n assert rods[j][-1] == min(rods[j]), \"larger disk on top of smaller disk\"\n return rods[0] == rods[1] == []", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Eight disks of sizes 1-8 are stacked on three towers, with each tower having disks in order of largest to\n smallest. Move [i, j] corresponds to taking the smallest disk off tower i and putting it on tower j, and it\n is legal as long as the towers remain in sorted order. Find a sequence of moves that moves all the disks\n from the first to last towers.\n \"\"\"", + "sol_bodies": [ + " def helper(m, i, j):\n if m == 0:\n return []\n k = 3 - i - j\n return helper(m - 1, i, k) + [[i, j]] + helper(m - 1, k, j)\n\n return helper(8, 0, 2)" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this classic version one must move all 8 disks from the first to third peg.", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_0", - "sat": "def sat(moves: List[List[int]], source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "TowersOfHanoiArbitrary:0", + "sat": "def sat(moves: List[List[int]], source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_1", - "sat": "def sat(moves: List[List[int]], source=[[1, 3, 5], [2, 8, 14], [0, 4, 6, 7, 9, 10, 11, 12, 13]], target=[[5, 12], [0, 3, 4, 7, 10, 11], [1, 2, 6, 8, 9, 13, 14]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[1, 3, 5], [2, 8, 14], [0, 4, 6, 7, 9, 10, 11, 12, 13]], target=[[5, 12], [0, 3, 4, 7, 10, 11], [1, 2, 6, 8, 9, 13, 14]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "TowersOfHanoiArbitrary:1", + "sat": "def sat(moves: List[List[int]], source=[[1, 3, 5], [2, 8, 14], [0, 4, 6, 7, 9, 10, 11, 12, 13]], target=[[5, 12], [0, 3, 4, 7, 10, 11], [1, 2, 6, 8, 9, 13, 14]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[1, 3, 5], [2, 8, 14], [0, 4, 6, 7, 9, 10, 11, 12, 13]], target=[[5, 12], [0, 3, 4, 7, 10, 11], [1, 2, 6, 8, 9, 13, 14]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_2", - "sat": "def sat(moves: List[List[int]], source=[[0, 1, 6, 7, 8, 9, 14, 16], [5, 15], [2, 3, 4, 10, 11, 12, 13]], target=[[1, 2, 4, 5, 13], [3, 6, 11, 12, 14], [0, 7, 8, 9, 10, 15, 16]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[0, 1, 6, 7, 8, 9, 14, 16], [5, 15], [2, 3, 4, 10, 11, 12, 13]], target=[[1, 2, 4, 5, 13], [3, 6, 11, 12, 14], [0, 7, 8, 9, 10, 15, 16]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "TowersOfHanoiArbitrary:2", + "sat": "def sat(moves: List[List[int]], source=[[0, 1, 6, 7, 8, 9, 14, 16], [5, 15], [2, 3, 4, 10, 11, 12, 13]], target=[[1, 2, 4, 5, 13], [3, 6, 11, 12, 14], [0, 7, 8, 9, 10, 15, 16]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[0, 1, 6, 7, 8, 9, 14, 16], [5, 15], [2, 3, 4, 10, 11, 12, 13]], target=[[1, 2, 4, 5, 13], [3, 6, 11, 12, 14], [0, 7, 8, 9, 10, 15, 16]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_3", - "sat": "def sat(moves: List[List[int]], source=[[2, 11, 12, 16], [1, 3, 6, 8, 9, 10, 13], [0, 4, 5, 7, 14, 15]], target=[[0, 2, 3, 5, 7, 8, 14, 16], [9, 11, 12, 13, 15], [1, 4, 6, 10]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[2, 11, 12, 16], [1, 3, 6, 8, 9, 10, 13], [0, 4, 5, 7, 14, 15]], target=[[0, 2, 3, 5, 7, 8, 14, 16], [9, 11, 12, 13, 15], [1, 4, 6, 10]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "TowersOfHanoiArbitrary:3", + "sat": "def sat(moves: List[List[int]], source=[[2, 11, 12, 16], [1, 3, 6, 8, 9, 10, 13], [0, 4, 5, 7, 14, 15]], target=[[0, 2, 3, 5, 7, 8, 14, 16], [9, 11, 12, 13, 15], [1, 4, 6, 10]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[2, 11, 12, 16], [1, 3, 6, 8, 9, 10, 13], [0, 4, 5, 7, 14, 15]], target=[[0, 2, 3, 5, 7, 8, 14, 16], [9, 11, 12, 13, 15], [1, 4, 6, 10]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_4", - "sat": "def sat(moves: List[List[int]], source=[[5, 6], [1, 2, 4], [0, 3]], target=[[2, 3, 4, 6], [0, 1], [5]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[5, 6], [1, 2, 4], [0, 3]], target=[[2, 3, 4, 6], [0, 1], [5]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "TowersOfHanoiArbitrary:4", + "sat": "def sat(moves: List[List[int]], source=[[5, 6], [1, 2, 4], [0, 3]], target=[[2, 3, 4, 6], [0, 1], [5]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[5, 6], [1, 2, 4], [0, 3]], target=[[2, 3, 4, 6], [0, 1], [5]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" ], - "module": "classic_puzzles", + "module": "classic_puzzles.py", "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_5", - "sat": "def sat(moves: List[List[int]], source=[[6], [0, 2, 3], [1, 4, 5]], target=[[3, 5], [0, 2, 4], [1, 6]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[6], [0, 2, 3], [1, 4, 5]], target=[[3, 5], [0, 2, 4], [1, 6]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "LongestMonotonicSubstring:0", + "sat": "def sat(x: List[int], length=13, s=\"Dynamic programming solves this puzzle!!!\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=13, s=\"Dynamic programming solves this puzzle!!!\"):", + "sol_docstring": " \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_6", - "sat": "def sat(moves: List[List[int]], source=[[0], [1, 2, 3], []], target=[[1], [0, 3], [2]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[0], [1, 2, 3], []], target=[[1], [0, 3], [2]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "LongestMonotonicSubstring:1", + "sat": "def sat(x: List[int], length=193, s=\" !!\\\"\\\"\\\"#$$%&&')''((()!))****X**++,,,,---...///0111114445556888::::;s;;<<==,=>>>>ABBBBBCDEEEEEEEFGHIIKKKKLMNOOPPPQQQRRRRASUUUVVVWWXXZZZ[]]]!``aEaabbbccccPcdeeeeefghjjjjkkkllmmooooKpppppqsttwt'$ww=wLwwyyyyzz{\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=193, s=\" !!\\\"\\\"\\\"#$$%&&')''((()!))****X**++,,,,---...///0111114445556888::::;s;;<<==,=>>>>ABBBBBCDEEEEEEEFGHIIKKKKLMNOOPPPQQQRRRRASUUUVVVWWXXZZZ[]]]!``aEaabbbccccPcdeeeeefghjjjjkkkllmmooooKpppppqsttwt'$ww=wLwwyyyyzz{\"):", + "sol_docstring": " \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_7", - "sat": "def sat(moves: List[List[int]], source=[[5, 8, 14], [2, 3, 4, 11], [0, 1, 6, 7, 9, 10, 12, 13]], target=[[0, 2, 3, 6, 7, 8, 9, 10, 14], [1, 5, 11, 12], [4, 13]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[5, 8, 14], [2, 3, 4, 11], [0, 1, 6, 7, 9, 10, 12, 13]], target=[[0, 2, 3, 6, 7, 8, 9, 10, 14], [1, 5, 11, 12], [4, 13]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "LongestMonotonicSubstring:2", + "sat": "def sat(x: List[int], length=737, s=\" _ !m!!!!!!!!!!!V!\\\"=\\\"\\\"\\\"\\\"\\\"l#####$$r$$$$$$$$$%%%%%&&&&&&y&''''''@'''''<(((())))))******+++++++p,,,,,!,-----w-----o-....,.......//////D000000000000111111111222222,23h33c33334444444'4455555555566666R6@9777777T7888888-8994999999999::::::::::;;;;;;;P;;;<<<:<<^<)<>>>>>>>>???A?j??8??.?@@O@@@@@@ArAA&ABBBBBBBBBCCCCCDDDEEEEEEEEE%E(EEEEEFF!FFG-GGGGGGGGHHCHHHIGIsIIIInIIIIJJJRJFJJKKKKKKa0K x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=737, s=\" _ !m!!!!!!!!!!!V!\\\"=\\\"\\\"\\\"\\\"\\\"l#####$$r$$$$$$$$$%%%%%&&&&&&y&''''''@'''''<(((())))))******+++++++p,,,,,!,-----w-----o-....,.......//////D000000000000111111111222222,23h33c33334444444'4455555555566666R6@9777777T7888888-8994999999999::::::::::;;;;;;;P;;;<<<:<<^<)<>>>>>>>>???A?j??8??.?@@O@@@@@@ArAA&ABBBBBBBBBCCCCCDDDEEEEEEEEE%E(EEEEEFF!FFG-GGGGGGGGHHCHHHIGIsIIIInIIIIJJJRJFJJKKKKKKa0K= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "LongestMonotonicSubstring:3", + "sat": "def sat(x: List[int], length=0, s=\"\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=0, s=\"\"):", + "sol_docstring": " \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", + "weight": 1.0 }, { - "name": "TowersOfHanoiArbitrary_9", - "sat": "def sat(moves: List[List[int]], source=[[1, 2, 4, 5, 10], [0, 8], [3, 6, 7, 9]], target=[[0, 3, 4, 7], [1, 6, 10], [2, 5, 8, 9]]):\n \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", - "sols": [ - "def sol(source=[[1, 2, 4, 5, 10], [0, 8], [3, 6, 7, 9]], target=[[0, 3, 4, 7], [1, 6, 10], [2, 5, 8, 9]]):\n state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + "name": "LongestMonotonicSubstring:4", + "sat": "def sat(x: List[int], length=1, s=\"xwV\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=1, s=\"xwV\"):", + "sol_docstring": " \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_0", - "sat": "def sat(x: List[int], length=13, s=\"Dynamic programming solves this puzzle!!!\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=13, s=\"Dynamic programming solves this puzzle!!!\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "LongestMonotonicSubstringTricky:0", + "sat": "def sat(x: List[int], length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"):", + "sol_docstring": " \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "The same as the above problem, but with a twist!", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_1", - "sat": "def sat(x: List[int], length=193, s=\" !!\\\"\\\"\\\"#$$%&&')''((()!))****X**++,,,,---...///0111114445556888::::;s;;<<==,=>>>>ABBBBBCDEEEEEEEFGHIIKKKKLMNOOPPPQQQRRRRASUUUVVVWWXXZZZ[]]]!``aEaabbbccccPcdeeeeefghjjjjkkkllmmooooKpppppqsttwt'$ww=wLwwyyyyzz{\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=193, s=\" !!\\\"\\\"\\\"#$$%&&')''((()!))****X**++,,,,---...///0111114445556888::::;s;;<<==,=>>>>ABBBBBCDEEEEEEEFGHIIKKKKLMNOOPPPQQQRRRRASUUUVVVWWXXZZZ[]]]!``aEaabbbccccPcdeeeeefghjjjjkkkllmmooooKpppppqsttwt'$ww=wLwwyyyyzz{\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "LongestMonotonicSubstringTricky:1", + "sat": "def sat(x: List[int], length=535, s=\"RRRS S !L!eSSSS!TTT+!TTTUU!!UU!UU\\\"U\\\"\\\"\\\"VVV\\\"\\\"\\\"VK#WW##gfW##X##6$$X$XX@$XXP%%%YY%+YY%&ZZ)%ZZ&#Z&[&[[[[\\\\'\\\\\\\\]\\\\\\\\]''']]']]]^^(^R^((^))^)^^*^_*_L____**;**_``*```++`+`+[+++``,m,,`,,-aa@aa[a-arb-b--b(vzbb-.b.6.ccc.cKcc.cc//c/cc//dddddd/0deeeee000e0f0ff0f01ff11f1<1gg;g12R2g22233gg33g333g3g445555566ghhh66799h9hhh9h999iEii/iYi::i::j:jvv:;;;;jj>l>ll0>l>m>m@mmm??0m^,?nn???n?sn@@oo@DobAAooAo7AAppppBqC$qqqqCCCCqqqqrDrrrrrrrDbrsDDDEsEs9asssfttEtttEEEtEEtFFtuuLFuuuFFFvF0FGvGGGvvvvRwwwwxGHxHHHx+HIxxIexxIIyyyPCyyyII,yIyyIzIJzJJQJzKzzKz{KK{{{{{[K{K{KK{?{KLLLLLLLMMM>NNNNNOOOOOOOOPPPQQQQQQQRRR\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=535, s=\"RRRS S !L!eSSSS!TTT+!TTTUU!!UU!UU\\\"U\\\"\\\"\\\"VVV\\\"\\\"\\\"VK#WW##gfW##X##6$$X$XX@$XXP%%%YY%+YY%&ZZ)%ZZ&#Z&[&[[[[\\\\'\\\\\\\\]\\\\\\\\]''']]']]]^^(^R^((^))^)^^*^_*_L____**;**_``*```++`+`+[+++``,m,,`,,-aa@aa[a-arb-b--b(vzbb-.b.6.ccc.cKcc.cc//c/cc//dddddd/0deeeee000e0f0ff0f01ff11f1<1gg;g12R2g22233gg33g333g3g445555566ghhh66799h9hhh9h999iEii/iYi::i::j:jvv:;;;;jj>l>ll0>l>m>m@mmm??0m^,?nn???n?sn@@oo@DobAAooAo7AAppppBqC$qqqqCCCCqqqqrDrrrrrrrDbrsDDDEsEs9asssfttEtttEEEtEEtFFtuuLFuuuFFFvF0FGvGGGvvvvRwwwwxGHxHHHx+HIxxIexxIIyyyPCyyyII,yIyyIzIJzJJQJzKzzKz{KK{{{{{[K{K{KK{?{KLLLLLLLMMM>NNNNNOOOOOOOOPPPQQQQQQQRRR\"):", + "sol_docstring": " \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "The same as the above problem, but with a twist!", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_2", - "sat": "def sat(x: List[int], length=737, s=\" _ !m!!!!!!!!!!!V!\\\"=\\\"\\\"\\\"\\\"\\\"l#####$$r$$$$$$$$$%%%%%&&&&&&y&''''''@'''''<(((())))))******+++++++p,,,,,!,-----w-----o-....,.......//////D000000000000111111111222222,23h33c33334444444'4455555555566666R6@9777777T7888888-8994999999999::::::::::;;;;;;;P;;;<<<:<<^<)<>>>>>>>>???A?j??8??.?@@O@@@@@@ArAA&ABBBBBBBBBCCCCCDDDEEEEEEEEE%E(EEEEEFF!FFG-GGGGGGGGHHCHHHIGIsIIIInIIIIJJJRJFJJKKKKKKa0K x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=737, s=\" _ !m!!!!!!!!!!!V!\\\"=\\\"\\\"\\\"\\\"\\\"l#####$$r$$$$$$$$$%%%%%&&&&&&y&''''''@'''''<(((())))))******+++++++p,,,,,!,-----w-----o-....,.......//////D000000000000111111111222222,23h33c33334444444'4455555555566666R6@9777777T7888888-8994999999999::::::::::;;;;;;;P;;;<<<:<<^<)<>>>>>>>>???A?j??8??.?@@O@@@@@@ArAA&ABBBBBBBBBCCCCCDDDEEEEEEEEE%E(EEEEEFF!FFG-GGGGGGGGHHCHHHIGIsIIIInIIIIJJJRJFJJKKKKKKa0K x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=1, s=\"O!A{SeKv\"):", + "sol_docstring": " \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "The same as the above problem, but with a twist!", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_3", - "sat": "def sat(x: List[int], length=0, s=\"\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=0, s=\"\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "LongestMonotonicSubstringTricky:3", + "sat": "def sat(x: List[int], length=61, s=\" OW##P%T'UW)X+X-YY]^_`bd/044e5egk7lm779: x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=61, s=\" OW##P%T'UW)X+X-YY]^_`bd/044e5egk7lm779: x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=1, s=\"xwV\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "LongestMonotonicSubstringTricky:4", + "sat": "def sat(x: List[int], length=19, s=\"1>C>DmJh5\\\"Ju,\\\"Q8zJ_u-O-VfnVTZ?W'm=jq.\\\\l&%m$cU.nqv2\\\\**.o\\\">]FZ5owil>l*kIM wcLd<*UX`\\\"_u'DC3R$8wr;jT]CW\\\"F$QKeRPMzZY'U42&Km dRr8b$T3x)w2v,_k(dR,F:`=c$MjE_Kf/KCXFg^ueiO.U%S8_](:GF;`2`^O%eAqSRAHW0dYg5!uF@K'q>2HgCc^:baOy[,9vJtFWPAed2w_7zHLl&.x^:XLwwtS+Ocr#, *qXmo9Sp,Z>{l&ElT>RNZ:.5f6,yedMqH8?jA=_@oK;X\\\\pm>r0Il0+k\\\\,&'u*(S`]>u?(4M\\\\3=0 F*MS8wqj0(HwK?gvpuma{V5inBL\\\",39`%*r$uPi=%:s! x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=19, s=\"1>C>DmJh5\\\"Ju,\\\"Q8zJ_u-O-VfnVTZ?W'm=jq.\\\\l&%m$cU.nqv2\\\\**.o\\\">]FZ5owil>l*kIM wcLd<*UX`\\\"_u'DC3R$8wr;jT]CW\\\"F$QKeRPMzZY'U42&Km dRr8b$T3x)w2v,_k(dR,F:`=c$MjE_Kf/KCXFg^ueiO.U%S8_](:GF;`2`^O%eAqSRAHW0dYg5!uF@K'q>2HgCc^:baOy[,9vJtFWPAed2w_7zHLl&.x^:XLwwtS+Ocr#, *qXmo9Sp,Z>{l&ElT>RNZ:.5f6,yedMqH8?jA=_@oK;X\\\\pm>r0Il0+k\\\\,&'u*(S`]>u?(4M\\\\3=0 F*MS8wqj0(HwK?gvpuma{V5inBL\\\",39`%*r$uPi=%:s! x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=25, s=\"d#.=66EE*FKLRy<=L(X'NN3R(qXH'T$WX;Y\\\\j]^z^iahf\\\\8:jxI$Ydqy o<${\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "Quine:0", + "sat": "def sat(quine: str):\n return eval(quine) == quine", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when evaluated as a Python expression is that string itself.\"\"\"", + "sol_bodies": [ + " return \"(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\\\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\\\")\"" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_6", - "sat": "def sat(x: List[int], length=0, s=\"wg.?i WW=\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=0, s=\"wg.?i WW=\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "RevQuine:0", + "sat": "def sat(rev_quine: str):\n return eval(rev_quine[::-1]) == rev_quine", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that, when reversed and evaluated gives you back that same string.\"\"\"", + "sol_bodies": [ + " return \"rev_quine\"[::-1] # thanks GPT-3!" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3.", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_7", - "sat": "def sat(x: List[int], length=573, s=\"O !!i\\\"\\\"9\\\"$\\\"\\\"\\\"5\\\"i\\\"\\\"####u##]2$)$$$G$$@$$&$2'$%o%%%%%%%g%%]P%a%&{&&Q&&&oG&&&&&yX&e&y''''QS(((*S(((e((_K)^)K'q)jx))i)****5**++6++++8,,$,4,!,D,,XO,#,,V---.r.../C//_///p/00Gd0nU0y01:S11111111:1322233334484TZu^4_4 q44555$515J555;r5667777777A7778889999h#=blt9::`::;Q_;;1;;x;gM<5<`>>i>??@@@@j@@Q@A_A;AABB%rJBed BM,BCCCcCCXECC_CDDDtD#DDDEPkEwEEFRRSSSS:SRSWSe.SS6UStX]r{S+STTTTTTTTaT>UU@AUUQUUU)bUsUUCeVheBVW1kWWWWWXX30XXXXmXXXoXYY+YYYZ)ZZ\\\\OW{@ZZZ[[[[[[[\\\\\\\\<\\\\o\\\\\\\\\\\\bv\\\\,[M\\\\M\\\\\\\\e]V]]]U^K^'^^^^M^^NJ__r___7_`8`o``5c`w`` x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=573, s=\"O !!i\\\"\\\"9\\\"$\\\"\\\"\\\"5\\\"i\\\"\\\"####u##]2$)$$$G$$@$$&$2'$%o%%%%%%%g%%]P%a%&{&&Q&&&oG&&&&&yX&e&y''''QS(((*S(((e((_K)^)K'q)jx))i)****5**++6++++8,,$,4,!,D,,XO,#,,V---.r.../C//_///p/00Gd0nU0y01:S11111111:1322233334484TZu^4_4 q44555$515J555;r5667777777A7778889999h#=blt9::`::;Q_;;1;;x;gM<5<`>>i>??@@@@j@@Q@A_A;AABB%rJBed BM,BCCCcCCXECC_CDDDtD#DDDEPkEwEEFRRSSSS:SRSWSe.SS6UStX]r{S+STTTTTTTTaT>UU@AUUQUUU)bUsUUCeVheBVW1kWWWWWXX30XXXXmXXXoXYY+YYYZ)ZZ\\\\OW{@ZZZ[[[[[[[\\\\\\\\<\\\\o\\\\\\\\\\\\bv\\\\,[M\\\\M\\\\\\\\e]V]]]U^K^'^^^^M^^NJ__r___7_`8`o``5c`w``= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", + "ans_type": "List[int]", + "sol_header": "def sol(n=100):", + "sol_docstring": " \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"", + "sol_bodies": [ + " sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_8", - "sat": "def sat(x: List[int], length=4, s=\"7[^e\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=4, s=\"7[^e\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" - ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "BooleanPythagoreanTriples:1", + "sat": "def sat(colors: List[int], n=7824):\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", + "ans_type": "List[int]", + "sol_header": "def sol(n=7824):", + "sol_docstring": " \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"", + "sol_bodies": [], + "module": "classic_puzzles.py", + "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstring_9", - "sat": "def sat(x: List[int], length=478, s=\" rgA!0*f\\\\D _Y W1X !I#r!!!!\\\"\\\"@g\\\"$h\\\"\\\"D=_\\\"\\\"\\\"#$Pi$$q$#%%4+W%P%&&&6&&&f&''n'((-d-)/H);)$)))***91:*3o*>cPcQ***+k++qz`+_+<+r+,,--$2W$@-mS0--v--&H4;..m./t//v//ANml/////S/\\\\0zE0uq001cpE] 1111\\\\&1!12 2s3c1-2/22-Hqv3344455e@$555=&'Ng>)qUf;{46646de677)\\\\3t777sPWT7788899:Io:pK:;J;;;yp<;d_J;x;9;:;U;l<<*<===#===W=+>N>y>>.&>>6>6e\\\"???N(??z@Y@`us@@@W@AUA\\\"AAAABBBvBBC^CDD^D3v)EEE'tD?EE^`'YlE9uE3uFFCob7FPFGGHHt;aQHIH(0kHMIII,II:9WIIf.{LJJJJJKJKKut3wuKUK{HTKqKLgM MWsMqMMMMMmNN]aN{N%NNNOOO-7P?PPvP%P.QZ-@QjQkVQQ QxQRRR&S+b)Sa0S>SSSTS#zBSTTTTTTT`4)_ThTLUU/UU/{HXUV2VVVVVVIVVW'WWsI1DtW%W%WXZX` DXPYZmZZZrZQcZZ6[[[[!Ifql[G@7[[\\\\\\\\\\\\\\\\\\\\q]]+]]]]^^WNaul^^D__)__SC_M_`Q`PP````aO*7aObjW5ua\\\\aRaabbbbbbbbebbqXccj)c=oEG_ozppX>mppzppDCo(pOBA5pp7q6qqM>RqZqGJwq-rrrs;stttuuGuu4vTuruuuuGvv$vS1vvvvvvwH@mwxww^wgw{wwx%ibyyyByyybKWwyzEc+.fz{{EN{{&{{\"):\n \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", - "sols": [ - "def sol(length=478, s=\" rgA!0*f\\\\D _Y W1X !I#r!!!!\\\"\\\"@g\\\"$h\\\"\\\"D=_\\\"\\\"\\\"#$Pi$$q$#%%4+W%P%&&&6&&&f&''n'((-d-)/H);)$)))***91:*3o*>cPcQ***+k++qz`+_+<+r+,,--$2W$@-mS0--v--&H4;..m./t//v//ANml/////S/\\\\0zE0uq001cpE] 1111\\\\&1!12 2s3c1-2/22-Hqv3344455e@$555=&'Ng>)qUf;{46646de677)\\\\3t777sPWT7788899:Io:pK:;J;;;yp<;d_J;x;9;:;U;l<<*<===#===W=+>N>y>>.&>>6>6e\\\"???N(??z@Y@`us@@@W@AUA\\\"AAAABBBvBBC^CDD^D3v)EEE'tD?EE^`'YlE9uE3uFFCob7FPFGGHHt;aQHIH(0kHMIII,II:9WIIf.{LJJJJJKJKKut3wuKUK{HTKqKLgM MWsMqMMMMMmNN]aN{N%NNNOOO-7P?PPvP%P.QZ-@QjQkVQQ QxQRRR&S+b)Sa0S>SSSTS#zBSTTTTTTT`4)_ThTLUU/UU/{HXUV2VVVVVVIVVW'WWsI1DtW%W%WXZX` DXPYZmZZZrZQcZZ6[[[[!Ifql[G@7[[\\\\\\\\\\\\\\\\\\\\q]]+]]]]^^WNaul^^D__)__SC_M_`Q`PP````aO*7aObjW5ua\\\\aRaabbbbbbbbebbqXccj)c=oEG_ozppX>mppzppDCo(pOBA5pp7q6qqM>RqZqGJwq-rrrs;stttuuGuu4vTuruuuuGvv$vS1vvvvvvwH@mwxww^wgw{wwx%ibyyyByyybKWwyzEc+.fz{{EN{{&{{\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "BooleanPythagoreanTriples:2", + "sat": "def sat(colors: List[int], n=0):\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", + "ans_type": "List[int]", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"", + "sol_bodies": [ + " sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" ], - "module": "classic_puzzles", - "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_0", - "sat": "def sat(x: List[int], length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"):\n \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "BooleanPythagoreanTriples:3", + "sat": "def sat(colors: List[int], n=1):\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", + "ans_type": "List[int]", + "sol_header": "def sol(n=1):", + "sol_docstring": " \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"", + "sol_bodies": [ + " sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_1", - "sat": "def sat(x: List[int], length=535, s=\"RRRS S !L!eSSSS!TTT+!TTTUU!!UU!UU\\\"U\\\"\\\"\\\"VVV\\\"\\\"\\\"VK#WW##gfW##X##6$$X$XX@$XXP%%%YY%+YY%&ZZ)%ZZ&#Z&[&[[[[\\\\'\\\\\\\\]\\\\\\\\]''']]']]]^^(^R^((^))^)^^*^_*_L____**;**_``*```++`+`+[+++``,m,,`,,-aa@aa[a-arb-b--b(vzbb-.b.6.ccc.cKcc.cc//c/cc//dddddd/0deeeee000e0f0ff0f01ff11f1<1gg;g12R2g22233gg33g333g3g445555566ghhh66799h9hhh9h999iEii/iYi::i::j:jvv:;;;;jj>l>ll0>l>m>m@mmm??0m^,?nn???n?sn@@oo@DobAAooAo7AAppppBqC$qqqqCCCCqqqqrDrrrrrrrDbrsDDDEsEs9asssfttEtttEEEtEEtFFtuuLFuuuFFFvF0FGvGGGvvvvRwwwwxGHxHHHx+HIxxIexxIIyyyPCyyyII,yIyyIzIJzJJQJzKzzKz{KK{{{{{[K{K{KK{?{KLLLLLLLMMM>NNNNNOOOOOOOOPPPQQQQQQQRRR\"):\n \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=535, s=\"RRRS S !L!eSSSS!TTT+!TTTUU!!UU!UU\\\"U\\\"\\\"\\\"VVV\\\"\\\"\\\"VK#WW##gfW##X##6$$X$XX@$XXP%%%YY%+YY%&ZZ)%ZZ&#Z&[&[[[[\\\\'\\\\\\\\]\\\\\\\\]''']]']]]^^(^R^((^))^)^^*^_*_L____**;**_``*```++`+`+[+++``,m,,`,,-aa@aa[a-arb-b--b(vzbb-.b.6.ccc.cKcc.cc//c/cc//dddddd/0deeeee000e0f0ff0f01ff11f1<1gg;g12R2g22233gg33g333g3g445555566ghhh66799h9hhh9h999iEii/iYi::i::j:jvv:;;;;jj>l>ll0>l>m>m@mmm??0m^,?nn???n?sn@@oo@DobAAooAo7AAppppBqC$qqqqCCCCqqqqrDrrrrrrrDbrsDDDEsEs9asssfttEtttEEEtEEtFFtuuLFuuuFFFvF0FGvGGGvvvvRwwwwxGHxHHHx+HIxxIexxIIyyyPCyyyII,yIyyIzIJzJJQJzKzzKz{KK{{{{{[K{K{KK{?{KLLLLLLLMMM>NNNNNOOOOOOOOPPPQQQQQQQRRR\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "ClockAngle:0", + "sat": "def sat(hands: List[int], target_angle=45):\n h, m = hands\n assert 0 < h <= 12 and 0 <= m < 60\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n return abs(hour_angle - minute_angle) in [target_angle, 360 - target_angle]", + "ans_type": "List[int]", + "sol_header": "def sol(target_angle=45):", + "sol_docstring": " \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"", + "sol_bodies": [ + " for h in range(1, 13):\n for m in range(60):\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n if abs(hour_angle - minute_angle) % 360 in [target_angle, 360 - target_angle]:\n return [h, m]" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_2", - "sat": "def sat(x: List[int], length=1, s=\"O!A{SeKv\"):\n \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=1, s=\"O!A{SeKv\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "ClockAngle:1", + "sat": "def sat(hands: List[int], target_angle=39):\n h, m = hands\n assert 0 < h <= 12 and 0 <= m < 60\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n return abs(hour_angle - minute_angle) in [target_angle, 360 - target_angle]", + "ans_type": "List[int]", + "sol_header": "def sol(target_angle=39):", + "sol_docstring": " \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"", + "sol_bodies": [ + " for h in range(1, 13):\n for m in range(60):\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n if abs(hour_angle - minute_angle) % 360 in [target_angle, 360 - target_angle]:\n return [h, m]" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_3", - "sat": "def sat(x: List[int], length=61, s=\" OW##P%T'UW)X+X-YY]^_`bd/044e5egk7lm779: x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=61, s=\" OW##P%T'UW)X+X-YY]^_`bd/044e5egk7lm779:C>DmJh5\\\"Ju,\\\"Q8zJ_u-O-VfnVTZ?W'm=jq.\\\\l&%m$cU.nqv2\\\\**.o\\\">]FZ5owil>l*kIM wcLd<*UX`\\\"_u'DC3R$8wr;jT]CW\\\"F$QKeRPMzZY'U42&Km dRr8b$T3x)w2v,_k(dR,F:`=c$MjE_Kf/KCXFg^ueiO.U%S8_](:GF;`2`^O%eAqSRAHW0dYg5!uF@K'q>2HgCc^:baOy[,9vJtFWPAed2w_7zHLl&.x^:XLwwtS+Ocr#, *qXmo9Sp,Z>{l&ElT>RNZ:.5f6,yedMqH8?jA=_@oK;X\\\\pm>r0Il0+k\\\\,&'u*(S`]>u?(4M\\\\3=0 F*MS8wqj0(HwK?gvpuma{V5inBL\\\",39`%*r$uPi=%:s! x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=19, s=\"1>C>DmJh5\\\"Ju,\\\"Q8zJ_u-O-VfnVTZ?W'm=jq.\\\\l&%m$cU.nqv2\\\\**.o\\\">]FZ5owil>l*kIM wcLd<*UX`\\\"_u'DC3R$8wr;jT]CW\\\"F$QKeRPMzZY'U42&Km dRr8b$T3x)w2v,_k(dR,F:`=c$MjE_Kf/KCXFg^ueiO.U%S8_](:GF;`2`^O%eAqSRAHW0dYg5!uF@K'q>2HgCc^:baOy[,9vJtFWPAed2w_7zHLl&.x^:XLwwtS+Ocr#, *qXmo9Sp,Z>{l&ElT>RNZ:.5f6,yedMqH8?jA=_@oK;X\\\\pm>r0Il0+k\\\\,&'u*(S`]>u?(4M\\\\3=0 F*MS8wqj0(HwK?gvpuma{V5inBL\\\",39`%*r$uPi=%:s!-#:/PZ<,emFb\\\"ddFks2wZPQeA h)/PuHMP\\\"n.D=1Kb0-AsPDk]OKnGu*9,:b454H@m'1v%5 x56ao'vx=IET^UBRhnAl/K'%wCdw,Bq0sIn],H*hPId^]#Qt&K;xVW5QVo1]@IwSP=\\\\r=&0=mQRS('L:1X=L9Q#_ySSrV_^k6#IF&I!O2oDs9DYSp\\\"{,0j%oxHy,:%jFVAcS W8hC3), x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=12, s=\"E\\\" T%#h/=NfNV1mrFHB`e)V0$=A)$-L)AUjQtXR4h]p2.>-#:/PZ<,emFb\\\"ddFks2wZPQeA h)/PuHMP\\\"n.D=1Kb0-AsPDk]OKnGu*9,:b454H@m'1v%5 x56ao'vx=IET^UBRhnAl/K'%wCdw,Bq0sIn],H*hPId^]#Qt&K;xVW5QVo1]@IwSP=\\\\r=&0=mQRS('L:1X=L9Q#_ySSrV_^k6#IF&I!O2oDs9DYSp\\\"{,0j%oxHy,:%jFVAcS W8hC3), x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=0, s=\"rvGNZ\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "Kirkman:0", + "sat": "def sat(daygroups: List[List[List[int]]]):\n assert len(daygroups) == 7\n assert all(len(groups) == 5 and {i for g in groups for i in g} == set(range(15)) for groups in daygroups)\n assert all(len(g) == 3 for groups in daygroups for g in groups)\n return len({(i, j) for groups in daygroups for g in groups for i in g for j in g}) == 15 * 15", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Arrange 15 people into groups of 3 each day for seven days so that no two people are in the same group twice.\n \"\"\"", + "sol_bodies": [ + " from itertools import combinations\n import random\n rand = random.Random(0)\n days = [[list(range(15)) for _2 in range(2)] for _ in range(7)] # each day is pi, inv\n counts = {(i, j): (7 if j in range(k, k + 3) else 0)\n for k in range(0, 15, 3)\n for i in range(k, k + 3)\n for j in range(15) if j != i\n }\n\n todos = [pair for pair, count in counts.items() if count == 0]\n while True:\n pair = rand.choice(todos) # choose i and j to make next to each other on some day\n if rand.randrange(2):\n pair = pair[::-1]\n\n a, u = pair\n pi, inv = rand.choice(days)\n assert pi[inv[a]] == a and pi[inv[u]] == u\n bases = [3 * (inv[i] // 3) for i in pair]\n (b, c), (v, w) = [[x for x in pi[b: b + 3] if x != i] for i, b in zip(pair, bases)]\n if rand.randrange(2):\n b, c, = c, b\n # current (a, b, c) (u, v, w). consider swap of u with b to make (a, u, c) (b, v, w)\n\n new_pairs = [(a, u), (c, u), (b, v), (b, w)]\n old_pairs = [(u, v), (u, w), (b, a), (b, c)]\n gained = sum(counts[p] == 0 for p in new_pairs)\n lost = sum(counts[p] == 1 for p in old_pairs)\n if rand.random() <= 100 ** (gained - lost):\n for p in new_pairs:\n counts[p] += 1\n counts[p[::-1]] += 1\n for p in old_pairs:\n counts[p] -= 1\n counts[p[::-1]] -= 1\n pi[inv[b]], pi[inv[u]], inv[b], inv[u] = u, b, inv[u], inv[b]\n todos = [pair for pair, count in counts.items() if count == 0]\n if len(todos) == 0:\n return [[pi[k:k + 3] for k in range(0, 15, 3)] for pi, _inv in days]" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_7", - "sat": "def sat(x: List[int], length=2, s=\")H\"):\n \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=2, s=\")H\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "MonkeyAndCoconuts:0", + "sat": "def sat(n: int):\n for i in range(5):\n assert n % 5 == 1\n n -= 1 + (n - 1) // 5\n return n > 0 and n % 5 == 1", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find the number of coconuts to solve the following riddle:\n There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the\n one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the\n procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and\n fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey.\n Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over.\n How many coconuts were there in the original pile?\n Quoted from https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts\n \"\"\"", + "sol_bodies": [ + " m = 1\n while True:\n n = m\n for i in range(5):\n if n % 5 != 1:\n break\n n -= 1 + (n - 1) // 5\n if n > 0 and n % 5 == 1:\n return m\n m += 5" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_8", - "sat": "def sat(x: List[int], length=4, s=\"b0r x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=4, s=\"b0r= num_points", + "ans_type": "List[List[int]]", + "sol_header": "def sol(side=10, num_points=20):", + "sol_docstring": " \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", + "weight": 1.0 }, { - "name": "LongestMonotonicSubstringTricky_9", - "sat": "def sat(x: List[int], length=6, s=\"S%T?Z(YI\"):\n \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", - "sols": [ - "def sol(length=6, s=\"S%T?Z(YI\"): # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + "name": "No3Colinear:1", + "sat": "def sat(coords: List[List[int]], side=0, num_points=0):\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", + "ans_type": "List[List[int]]", + "sol_header": "def sol(side=0, num_points=0):", + "sol_docstring": " \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" ], - "module": "classic_puzzles", - "notes": "The same as the above problem, but with a twist!", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", + "weight": 1.0 }, { - "name": "Quine_0", - "sat": "def sat(quine: str):\n \"\"\"Find a string that when evaluated as a Python expression is that string itself.\"\"\"\n return eval(quine) == quine", - "sols": [ - "def sol():\n return \"(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\\\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\\\")\"", - "def sol(): # thanks for this simple solution, GPT-3!\n return 'quine'" + "name": "No3Colinear:2", + "sat": "def sat(coords: List[List[int]], side=1, num_points=1):\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", + "ans_type": "List[List[int]]", + "sol_header": "def sol(side=1, num_points=1):", + "sol_docstring": " \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" ], - "module": "classic_puzzles", - "notes": "[Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29)", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "classic_puzzles.py", + "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", + "weight": 1.0 }, { - "name": "RevQuine_0", - "sat": "def sat(rev_quine: str):\n \"\"\"Find a string that, when reversed and evaluated gives you back that same string.\"\"\"\n return eval(rev_quine[::-1]) == rev_quine", - "sols": [ - "def sol():\n return \"rev_quine\"[::-1] # thanks GPT-3!" + "name": "No3Colinear:3", + "sat": "def sat(coords: List[List[int]], side=2, num_points=4):\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", + "ans_type": "List[List[int]]", + "sol_header": "def sol(side=2, num_points=4):", + "sol_docstring": " \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" ], - "module": "classic_puzzles", - "notes": "Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3.", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "classic_puzzles.py", + "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_0", - "sat": "def sat(colors: List[int], n=100):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=100):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "PostageStamp:0", + "sat": "def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=80, max_stamps=4, options=[10, 32, 8]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_1", - "sat": "def sat(colors: List[int], n=7824):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "PostageStamp:1", + "sat": "def sat(stamps: List[int], target=271, max_stamps=8, options=[37, 37, 12, 87, 39]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=271, max_stamps=8, options=[37, 37, 12, 87, 39]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + ], + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_2", - "sat": "def sat(colors: List[int], n=0):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=0):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "PostageStamp:2", + "sat": "def sat(stamps: List[int], target=3, max_stamps=3, options=[18, 1, 43, 81]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=3, max_stamps=3, options=[18, 1, 43, 81]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_3", - "sat": "def sat(colors: List[int], n=1):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=1):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "PostageStamp:3", + "sat": "def sat(stamps: List[int], target=19, max_stamps=2, options=[19, 14, 81]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=19, max_stamps=2, options=[19, 14, 81]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_4", - "sat": "def sat(colors: List[int], n=2):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=2):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "PostageStamp:4", + "sat": "def sat(stamps: List[int], target=56, max_stamps=1, options=[25, 22, 8, 84, 60, 56, 54, 7, 8]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=56, max_stamps=1, options=[25, 22, 8, 84, 60, 56, 54, 7, 8]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 + }, + { + "name": "Sudoku:0", + "sat": "def sat(x: str, puz=\"____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "Sudoku:1", + "sat": "def sat(x: str, puz=\"__2__1_3__9_7_____5______8_6___5_______12____2____3_68________9_1_8__4____7____25\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"__2__1_3__9_7_____5______8_6___5_______12____2____3_68________9_1_8__4____7____25\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "Sudoku:2", + "sat": "def sat(x: str, puz=\"__721__56__27___________9______5____62______1_1___9___8_____________3197__61__32_\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"__721__56__27___________9______5____62______1_1___9___8_____________3197__61__32_\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "Sudoku:3", + "sat": "def sat(x: str, puz=\"_____42______7_____4______9__49___626_8__3___3_7__65_4_5_3__1__1____8_7__________\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"_____42______7_____4______9__49___626_8__3___3_7__65_4_5_3__1__1____8_7__________\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "Sudoku:4", + "sat": "def sat(x: str, puz=\"___56_4_7__92_4_65___3______9____2___5_______7___8___1_________43_____5_____76__2\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"___56_4_7__92_4_65___3______9____2___5_______7___8___1_________43_____5_____76__2\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "SquaringTheSquare:0", + "sat": "def sat(xy_sides: List[List[int]]):\n n = max(x + side for x, y, side in xy_sides)\n assert len({side for x, y, side in xy_sides}) == len(xy_sides) > 1\n for x, y, s in xy_sides:\n assert 0 <= y < y + s <= n and 0 <= x\n for x2, y2, s2 in xy_sides:\n assert s2 <= s or x2 >= x + s or x2 + s2 <= x or y2 >= y + s or y2 + s2 <= y\n\n return sum(side ** 2 for x, y, side in xy_sides) == n ** 2", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Partition a square into smaller squares with unique side lengths. A perfect squared path has distinct sides.\n xy_sides is a List of (x, y, side)\n \"\"\"", + "sol_bodies": [ + " return [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35],\n [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18],\n [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]]" + ], + "module": "classic_puzzles.py", + "notes": "[Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square)\nWikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square)\ndue to Duijvestijn (1978).", + "weight": 1.0 + }, + { + "name": "NecklaceSplit:0", + "sat": "def sat(n: int, lace=\"bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + ], + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_5", - "sat": "def sat(colors: List[int], n=3):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=3):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "NecklaceSplit:1", + "sat": "def sat(n: int, lace=\"rbbrrbbrbrbbbrrrbbrbrbrrbbrbbbbbbrrrrrrrrbrrrbbrbrrbbbrbbrrrbbrbbrrbrrbrbbrbbbbbbrbbbrbrbrrbrbbrbrrbbrrbrrbrrbrrbrbrbrrrbbrbrbbrrbbbbrrrrrbbrbrbrrbr\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"rbbrrbbrbrbbbrrrbbrbrbrrbbrbbbbbbrrrrrrrrbrrrbbrbrrbbbrbbrrrbbrbbrrbrrbrbbrbbbbbbrbbbrbrbrrbrbbrbrrbbrrbrrbrrbrrbrbrbrrrbbrbrbbrrbbbbrrrrrbbrbrbrrbr\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_6", - "sat": "def sat(colors: List[int], n=4):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=4):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "NecklaceSplit:2", + "sat": "def sat(n: int, lace=\"brrrbrrbrbbbbbrrbbrr\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"brrrbrrbrbbbbbrrbbrr\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_7", - "sat": "def sat(colors: List[int], n=5):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=5):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "NecklaceSplit:3", + "sat": "def sat(n: int, lace=\"bbbbrrbbbbrrbbrrrbbrrbbrrrrrrrbrbrbbbrrbrrrbbbbbbbrbrbrbbbbbbbrrbbrbbrbrrbrbrrbbbrrrrrbrrbbrrrbbrbrrrbbbbrbbbrrrrbrbrrbbrbrbrbbrrbrrrbrbrrbbbbbbrbrrrrbbrbbbrbrrbrbbrbrrbbbbrrrrrbrrrbbrrrrrrbrrrbrbbbrbbbrrrbbr\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"bbbbrrbbbbrrbbrrrbbrrbbrrrrrrrbrbrbbbrrbrrrbbbbbbbrbrbrbbbbbbbrrbbrbbrbrrbrbrrbbbrrrrrbrrbbrrrbbrbrrrbbbbrbbbrrrrbrbrrbbrbrbrbbrrbrrrbrbrrbbbbbbrbrrrrbbrbbbrbrrbrbbrbrrbbbbrrrrrbrrrbbrrrrrrbrrrbrbbbrbbbrrrbbr\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_8", - "sat": "def sat(colors: List[int], n=6):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=6):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "NecklaceSplit:4", + "sat": "def sat(n: int, lace=\"brrbbbrbbrrbrrbbrrbrrrbbrbbrrrbrbrbrrrrbbrrrbrrbbbbrbbbrrbbrrrbbrbrbbbbbrrbrrbbr\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"brrbbbrbbrrbrrbbrrbrrrbbrbbrrrbrbrbrrrrbbrrrbrrbbbbrbbbrrbbrrrbbrbrbbbbbrrbrrbbr\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 }, { - "name": "BooleanPythagoreanTriples_9", - "sat": "def sat(colors: List[int], n=7):\n \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", - "sols": [ - "def sol(n=7):\n sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + "name": "PandigitalSquare:0", + "sat": "def sat(n: int):\n s = str(n * n)\n for i in \"0123456789\":\n assert s.count(i) == 1\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer whose square has all digits 0-9 once.\"\"\"", + "sol_bodies": [ + " for n in range(10 ** 5):\n if sorted([int(s) for s in str(n * n)]) == list(range(10)):\n return n" ], - "module": "classic_puzzles", - "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square", + "weight": 1.0 }, { - "name": "ClockAngle_0", - "sat": "def sat(hands: List[int], target_angle=45):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=45):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "AllPandigitalSquares:0", + "sat": "def sat(nums: List[int]):\n return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find all 174 integers whose 10-digit square has all digits 0-9 just once.\"\"\"", + "sol_bodies": [ + " return [i for i in range(-10 ** 5, 10 ** 5) if sorted([int(s) for s in str(i * i)]) == list(range(10))]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares", + "weight": 1.0 }, { - "name": "ClockAngle_1", - "sat": "def sat(hands: List[int], target_angle=30):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=30):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "CardGame24:0", + "sat": "def sat(expr: str, nums=[3, 7, 3, 7]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[3, 7, 3, 7]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 }, { - "name": "ClockAngle_2", - "sat": "def sat(hands: List[int], target_angle=19):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=19):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "CardGame24:1", + "sat": "def sat(expr: str, nums=[1, 3, 7, 13]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[1, 3, 7, 13]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 }, { - "name": "ClockAngle_3", - "sat": "def sat(hands: List[int], target_angle=8):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=8):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "CardGame24:2", + "sat": "def sat(expr: str, nums=[10, 7, 3, 1]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[10, 7, 3, 1]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 }, { - "name": "ClockAngle_4", - "sat": "def sat(hands: List[int], target_angle=357):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=357):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "CardGame24:3", + "sat": "def sat(expr: str, nums=[8, 3, 12, 1]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[8, 3, 12, 1]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 }, { - "name": "ClockAngle_5", - "sat": "def sat(hands: List[int], target_angle=346):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=346):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "CardGame24:4", + "sat": "def sat(expr: str, nums=[10, 12, 1, 7]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[10, 12, 1, 7]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 }, { - "name": "ClockAngle_6", - "sat": "def sat(hands: List[int], target_angle=335):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=335):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "Easy63:0", + "sat": "def sat(s: str):\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 2 and s.count(\"1\") == 1 and eval(s) == 63", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a formula using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"", + "sol_bodies": [ + " return \"8*8-1\"" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "An easy puzzle to make 63 using two 8's and one 1's.", + "weight": 1.0 }, { - "name": "ClockAngle_7", - "sat": "def sat(hands: List[int], target_angle=324):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=324):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "Harder63:0", + "sat": "def sat(s: str):\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 3 and s.count(\"1\") == 1 and eval(s) == 63", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an expression using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"", + "sol_bodies": [ + " return \"8*8-1**8\"" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "An harder puzzle to make 63 using three 8's and one 1's.", + "weight": 1.0 }, { - "name": "ClockAngle_8", - "sat": "def sat(hands: List[int], target_angle=313):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=313):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "WaterPouring:0", + "sat": "def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 }, { - "name": "ClockAngle_9", - "sat": "def sat(hands: List[int], target_angle=302):\n \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"\n hour, min = hands\n return 0 < hour <= 12 and 0 <= min < 60 and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", - "sols": [ - "def sol(target_angle=302):\n for hour in range(1, 13):\n for min in range(60):\n if ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle:\n return [hour, min]" + "name": "WaterPouring:1", + "sat": "def sat(moves: List[List[int]], capacities=[724, 43, 611], init=[72, 2, 269], goal=[56, 0, 287]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(init=[72, 2, 269], goal=[56, 0, 287], capacities=[724, 43, 611]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" ], - "module": "classic_puzzles", - "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 }, { - "name": "Kirkman_0", - "sat": "def sat(daygroups: List[List[List[int]]]):\n \"\"\"\n Arrange 15 people into groups of 3 each day for seven days so that no two people are in the same group twice.\n \"\"\"\n assert len(daygroups) == 7\n assert all(len(groups) == 5 and {i for g in groups for i in g} == set(range(15)) for groups in daygroups)\n assert all(len(g) == 3 for groups in daygroups for g in groups)\n return len({(i, j) for groups in daygroups for g in groups for i in g for j in g}) == 15 * 15", - "sols": [ - "def sol():\n from itertools import combinations\n import random\n rand = random.Random(0)\n days = [[list(range(15)) for _2 in range(2)] for _ in range(7)] # each day is pi, inv\n counts = {(i, j): (7 if j in range(k, k + 3) else 0)\n for k in range(0, 15, 3)\n for i in range(k, k + 3)\n for j in range(15) if j != i\n }\n\n todos = [pair for pair, count in counts.items() if count == 0]\n while True:\n pair = rand.choice(todos) # choose i and j to make next to each other on some day\n if rand.randrange(2):\n pair = pair[::-1]\n\n a, u = pair\n pi, inv = rand.choice(days)\n assert pi[inv[a]] == a and pi[inv[u]] == u\n bases = [3 * (inv[i] // 3) for i in pair]\n (b, c), (v, w) = [[x for x in pi[b: b + 3] if x != i] for i, b in zip(pair, bases)]\n if rand.randrange(2):\n b, c, = c, b\n # current (a, b, c) (u, v, w). consider swap of u with b to make (a, u, c) (b, v, w)\n\n new_pairs = [(a, u), (c, u), (b, v), (b, w)]\n old_pairs = [(u, v), (u, w), (b, a), (b, c)]\n gained = sum(counts[p] == 0 for p in new_pairs)\n lost = sum(counts[p] == 1 for p in old_pairs)\n if rand.random() <= 100 ** (gained - lost):\n for p in new_pairs:\n counts[p] += 1\n counts[p[::-1]] += 1\n for p in old_pairs:\n counts[p] -= 1\n counts[p[::-1]] -= 1\n pi[inv[b]], pi[inv[u]], inv[b], inv[u] = u, b, inv[u], inv[b]\n todos = [pair for pair, count in counts.items() if count == 0]\n if len(todos) == 0:\n return [[pi[k:k + 3] for k in range(0, 15, 3)] for pi, _inv in days]" + "name": "WaterPouring:2", + "sat": "def sat(moves: List[List[int]], capacities=[357, 298, 492], init=[8, 284, 72], goal=[0, 0, 364]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(init=[8, 284, 72], goal=[0, 0, 364], capacities=[357, 298, 492]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" ], - "module": "classic_puzzles", - "notes": "[Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem)", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 }, { - "name": "MonkeyAndCoconuts_0", - "sat": "def sat(n: int):\n \"\"\"\n Find the number of coconuts to solve the following riddle:\n There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the\n one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the\n procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and\n fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey.\n Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over.\n How many coconuts were there in the original pile?\n Quoted from https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts\n \"\"\"\n for i in range(5):\n assert n % 5 == 1\n n -= 1 + (n - 1) // 5\n return n > 0 and n % 5 == 1", - "sols": [ - "def sol():\n m = 1\n while True:\n n = m\n for i in range(5):\n if n % 5 != 1:\n break\n n -= 1 + (n - 1) // 5\n if n > 0 and n % 5 == 1:\n return m\n m += 5" + "name": "WaterPouring:3", + "sat": "def sat(moves: List[List[int]], capacities=[511, 625, 553], init=[472, 153, 127], goal=[97, 625, 30]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(init=[472, 153, 127], goal=[97, 625, 30], capacities=[511, 625, 553]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" ], - "module": "classic_puzzles", - "notes": "[The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts)", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 }, { - "name": "No3Colinear_0", - "sat": "def sat(coords: List[List[int]], side=10, num_points=20):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=10, num_points=20):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "WaterPouring:4", + "sat": "def sat(moves: List[List[int]], capacities=[86, 259, 281], init=[47, 18, 35], goal=[35, 0, 65]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(init=[47, 18, 35], goal=[35, 0, 65], capacities=[86, 259, 281]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 }, { - "name": "No3Colinear_1", - "sat": "def sat(coords: List[List[int]], side=0, num_points=0):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=0, num_points=0):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "VerbalArithmetic:0", + "sat": "def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['SEND', 'MORE', 'MONEY']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " print(\"solving\", words)\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 }, { - "name": "No3Colinear_2", - "sat": "def sat(coords: List[List[int]], side=1, num_points=1):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=1, num_points=1):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "VerbalArithmetic:1", + "sat": "def sat(li: List[int], words=['FORTY', 'TEN', 'TEN', 'SIXTY']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['FORTY', 'TEN', 'TEN', 'SIXTY']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " print(\"solving\", words)\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 }, { - "name": "No3Colinear_3", - "sat": "def sat(coords: List[List[int]], side=2, num_points=4):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=2, num_points=4):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "VerbalArithmetic:2", + "sat": "def sat(li: List[int], words=['GREEN', 'ORANGE', 'COLORS']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['GREEN', 'ORANGE', 'COLORS']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " print(\"solving\", words)\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 }, { - "name": "No3Colinear_4", - "sat": "def sat(coords: List[List[int]], side=3, num_points=6):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=3, num_points=6):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "VerbalArithmetic:3", + "sat": "def sat(li: List[int], words=['fqjb', 'awqw', 'lfll', 'fvvvb']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['fqjb', 'awqw', 'lfll', 'fvvvb']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " print(\"solving\", words)\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 }, { - "name": "No3Colinear_5", - "sat": "def sat(coords: List[List[int]], side=4, num_points=8):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [ - "def sol(side=4, num_points=8):\n from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + "name": "VerbalArithmetic:4", + "sat": "def sat(li: List[int], words=['tnnq', 'sna', 'ajjc', 'isun', 'usub', 'caiun']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['tnnq', 'sna', 'ajjc', 'isun', 'usub', 'caiun']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " print(\"solving\", words)\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" ], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 }, { - "name": "No3Colinear_6", - "sat": "def sat(coords: List[List[int]], side=5, num_points=10):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "SlidingPuzzle:0", + "sat": "def sat(moves: List[int], start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + ], + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 }, { - "name": "No3Colinear_7", - "sat": "def sat(coords: List[List[int]], side=6, num_points=12):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "SlidingPuzzle:1", + "sat": "def sat(moves: List[int], start=[[1, 5, 0], [3, 2, 8], [6, 4, 7]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[1, 5, 0], [3, 2, 8], [6, 4, 7]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + ], + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 }, { - "name": "No3Colinear_8", - "sat": "def sat(coords: List[List[int]], side=7, num_points=14):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "SlidingPuzzle:2", + "sat": "def sat(moves: List[int], start=[[6, 0, 3], [7, 1, 4], [8, 2, 5]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[6, 0, 3], [7, 1, 4], [8, 2, 5]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + ], + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 }, { - "name": "No3Colinear_9", - "sat": "def sat(coords: List[List[int]], side=8, num_points=16):\n \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", - "sols": [], - "module": "classic_puzzles", - "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "name": "SlidingPuzzle:3", + "sat": "def sat(moves: List[int], start=[[0, 1], [2, 3]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[0, 1], [2, 3]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + ], + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 }, { - "name": "PostageStamp_0", - "sat": "def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=80, max_stamps=4, options=[10, 32, 8]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "SlidingPuzzle:4", + "sat": "def sat(moves: List[int], start=[[2, 1], [0, 3]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[2, 1], [0, 3]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 }, { - "name": "PostageStamp_1", - "sat": "def sat(stamps: List[int], target=271, max_stamps=8, options=[37, 37, 12, 87, 39]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=271, max_stamps=8, options=[37, 37, 12, 87, 39]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "FindCloseElements:0", + "sat": "def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 }, { - "name": "PostageStamp_2", - "sat": "def sat(stamps: List[int], target=3, max_stamps=3, options=[18, 1, 43, 81]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=3, max_stamps=3, options=[18, 1, 43, 81]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "FindCloseElements:1", + "sat": "def sat(pair: List[float], nums=[-3.027185809375565, -6.642297851887924, -6.773598672960938, 8.692593210252113, 4.9144452253248225, -6.773598672960938, -9.228605102488878]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[-3.027185809375565, -6.642297851887924, -6.773598672960938, 8.692593210252113, 4.9144452253248225, -6.773598672960938, -9.228605102488878]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 }, { - "name": "PostageStamp_3", - "sat": "def sat(stamps: List[int], target=19, max_stamps=2, options=[19, 14, 81]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=19, max_stamps=2, options=[19, 14, 81]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "FindCloseElements:2", + "sat": "def sat(pair: List[float], nums=[-1.5625078353699955, 3.6482553468598375, -2.6412688082759868, -0.511423740751141, -2.6412688082759868, 5.648091691238367]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[-1.5625078353699955, 3.6482553468598375, -2.6412688082759868, -0.511423740751141, -2.6412688082759868, 5.648091691238367]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 }, { - "name": "PostageStamp_4", - "sat": "def sat(stamps: List[int], target=56, max_stamps=1, options=[25, 22, 8, 84, 60, 56, 54, 7, 8]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=56, max_stamps=1, options=[25, 22, 8, 84, 60, 56, 54, 7, 8]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "FindCloseElements:3", + "sat": "def sat(pair: List[float], nums=[4.183381104176473, 1.6210985169040963, 1.6210985169040963]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[4.183381104176473, 1.6210985169040963, 1.6210985169040963]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 }, { - "name": "PostageStamp_5", - "sat": "def sat(stamps: List[int], target=61, max_stamps=9, options=[23, 10, 38, 70, 23]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=61, max_stamps=9, options=[23, 10, 38, 70, 23]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "FindCloseElements:4", + "sat": "def sat(pair: List[float], nums=[2.3934380222903258, -7.674333581672553, 2.3934380222903258]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[2.3934380222903258, -7.674333581672553, 2.3934380222903258]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 }, { - "name": "PostageStamp_6", - "sat": "def sat(stamps: List[int], target=531, max_stamps=9, options=[70, 52, 32, 78, 93, 90, 38, 68]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=531, max_stamps=9, options=[70, 52, 32, 78, 93, 90, 38, 68]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "SeparateParenGroups:0", + "sat": "def sat(ls: List[str], combined=\"() (()) ((() () ())) (() )\"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\"() (()) ((() () ())) (() )\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 }, { - "name": "PostageStamp_7", - "sat": "def sat(stamps: List[int], target=70, max_stamps=5, options=[70, 63, 29, 17, 39, 62, 11]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=70, max_stamps=5, options=[70, 63, 29, 17, 39, 62, 11]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "SeparateParenGroups:1", + "sat": "def sat(ls: List[str], combined=\"() () \"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\"() () \"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 }, { - "name": "PostageStamp_8", - "sat": "def sat(stamps: List[int], target=20, max_stamps=2, options=[9, 89, 46, 56, 27, 20, 78, 26]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=20, max_stamps=2, options=[9, 89, 46, 56, 27, 20, 78, 26]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "SeparateParenGroups:2", + "sat": "def sat(ls: List[str], combined=\" ((((() ())( ( ))()))) \"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\" ((((() ())( ( ))()))) \"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 }, { - "name": "PostageStamp_9", - "sat": "def sat(stamps: List[int], target=75, max_stamps=1, options=[75, 55, 27, 99, 61, 67, 27, 40]):\n \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", - "sols": [ - "def sol(target=75, max_stamps=1, options=[75, 55, 27, 99, 61, 67, 27, 40]):\n from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + "name": "SeparateParenGroups:3", + "sat": "def sat(ls: List[str], combined=\"() \"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\"() \"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" ], - "module": "classic_puzzles", - "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 }, { - "name": "SquaringTheSquare_0", - "sat": "def sat(xy_sides: List[List[int]]):\n \"\"\"\n Partition a square into smaller squares with unique side lengths. A perfect squared path has distinct sides.\n xy_sides is a List of (x, y, side)\n \"\"\"\n n = max(x + side for x, y, side in xy_sides)\n assert len({side for x, y, side in xy_sides}) == len(xy_sides) > 1\n for x, y, s in xy_sides:\n assert 0 <= y < y + s <= n and 0 <= x\n for x2, y2, s2 in xy_sides:\n assert s2 <= s or x2 >= x + s or x2 + s2 <= x or y2 >= y + s or y2 + s2 <= y\n\n return sum(side ** 2 for x, y, side in xy_sides) == n ** 2", - "sols": [ - "def sol():\n return [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35],\n [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18],\n [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]]" + "name": "SeparateParenGroups:4", + "sat": "def sat(ls: List[str], combined=\"(() )(( )() ) ((( (()))(()(()() ( )( ()) )( ( )( )) (() )) )()) (( )) \"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\"(() )(( )() ) ((( (()))(()(()() ( )( ()) )( ( )( )) (() )) )()) (( )) \"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" ], - "module": "classic_puzzles", - "notes": "[Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square)\nWikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square)\ndue to Duijvestijn (1978):\n```python\n[[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35],\n [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18],\n [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]]\n```", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 }, { - "name": "NecklaceSplit_0", - "sat": "def sat(n: int, lace=\"bbbbrrbrbrbbrrrr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"bbbbrrbrbrbbrrrr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "Frac:0", + "sat": "def sat(x: float, v=523.12892):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=523.12892):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 }, { - "name": "NecklaceSplit_1", - "sat": "def sat(n: int, lace=\"rbbrrbbrbrbbbrrrbbrbrbrrbbrbbbbbbrrrrrrrrbrrrbbrbrrbbbrbbrrrbbrbbrrbrrbrbbrbbbbbbrbbbrbrbrrbrbbrbrrbbrrbrrbrrbrrbrbrbrrrbbrbrbbrrbbbbrrrrrbbrbrbrrbr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"rbbrrbbrbrbbbrrrbbrbrbrrbbrbbbbbbrrrrrrrrbrrrbbrbrrbbbrbbrrrbbrbbrrbrrbrbbrbbbbbbrbbbrbrbrrbrbbrbrrbbrrbrrbrrbrrbrbrbrrrbbrbrbbrrbbbbrrrrrbbrbrbrrbr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "Frac:1", + "sat": "def sat(x: float, v=93.86070917102649):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=93.86070917102649):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 }, { - "name": "NecklaceSplit_2", - "sat": "def sat(n: int, lace=\"brrrbrrbrbbbbbrrbbrr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"brrrbrrbrbbbbbrrbbrr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "Frac:2", + "sat": "def sat(x: float, v=-6.770237138115334):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=-6.770237138115334):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 }, { - "name": "NecklaceSplit_3", - "sat": "def sat(n: int, lace=\"bbbbrrbbbbrrbbrrrbbrrbbrrrrrrrbrbrbbbrrbrrrbbbbbbbrbrbrbbbbbbbrrbbrbbrbrrbrbrrbbbrrrrrbrrbbrrrbbrbrrrbbbbrbbbrrrrbrbrrbbrbrbrbbrrbrrrbrbrrbbbbbbrbrrrrbbrbbbrbrrbrbbrbrrbbbbrrrrrbrrrbbrrrrrrbrrrbrbbbrbbbrrrbbr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"bbbbrrbbbbrrbbrrrbbrrbbrrrrrrrbrbrbbbrrbrrrbbbbbbbrbrbrbbbbbbbrrbbrbbrbrrbrbrrbbbrrrrrbrrbbrrrbbrbrrrbbbbrbbbrrrrbrbrrbbrbrbrbbrrbrrrbrbrrbbbbbbrbrrrrbbrbbbrbrrbrbbrbrrbbbbrrrrrbrrrbbrrrrrrbrrrbrbbbrbbbrrrbbr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "Frac:3", + "sat": "def sat(x: float, v=61.58244309946389):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=61.58244309946389):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 }, { - "name": "NecklaceSplit_4", - "sat": "def sat(n: int, lace=\"brrbbbrbbrrbrrbbrrbrrrbbrbbrrrbrbrbrrrrbbrrrbrrbbbbrbbbrrbbrrrbbrbrbbbbbrrbrrbbr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"brrbbbrbbrrbrrbbrrbrrrbbrbbrrrbrbrbrrrrbbrrrbrrbbbbrbbbrrbbrrrbbrbrbbbbbrrbrrbbr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "Frac:4", + "sat": "def sat(x: float, v=-80.9341003381162):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=-80.9341003381162):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 }, { - "name": "NecklaceSplit_5", - "sat": "def sat(n: int, lace=\"rrbrbrbbrbrrbbrbbrrrbbrb\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"rrbrbrbbrbrrbbrbbrrrbbrb\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "FirstNegCumulative:0", + "sat": "def sat(firsts: List[int], balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 }, { - "name": "NecklaceSplit_6", - "sat": "def sat(n: int, lace=\"brrrrbrrbbrrbrbbbrbb\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"brrrrbrrbbrrbrbbbrbb\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "FirstNegCumulative:1", + "sat": "def sat(firsts: List[int], balances=[[-1500518832, 928669978, -8834236111, 5315367227, 9459906565], [-922459571, 980368404, 2797206106, -8743339029, 1937237746], [-5581999780, -8355044389, 7691080588, 8819548586, -8678046394, 81698589, -1909402868], [-1496460602, -254633700, 1563740297, 2090111052, -2538220111, 2872427340, 3374773774], [8943500651, -9334877156, -8549860005, 7833776489, 6973829595, 7722681537, 535145192, -1822889532, 1811860043, -7700960933], [-1026876, -8774841983, 8413152214, 6772330745, 5578115818, -3502599311, 3134009997, 463541762, 3083435301], [-4305579008, 5200456205, -7357895007]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[-1500518832, 928669978, -8834236111, 5315367227, 9459906565], [-922459571, 980368404, 2797206106, -8743339029, 1937237746], [-5581999780, -8355044389, 7691080588, 8819548586, -8678046394, 81698589, -1909402868], [-1496460602, -254633700, 1563740297, 2090111052, -2538220111, 2872427340, 3374773774], [8943500651, -9334877156, -8549860005, 7833776489, 6973829595, 7722681537, 535145192, -1822889532, 1811860043, -7700960933], [-1026876, -8774841983, 8413152214, 6772330745, 5578115818, -3502599311, 3134009997, 463541762, 3083435301], [-4305579008, 5200456205, -7357895007]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 }, { - "name": "NecklaceSplit_7", - "sat": "def sat(n: int, lace=\"brrrbbbr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"brrrbbbr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "FirstNegCumulative:2", + "sat": "def sat(firsts: List[int], balances=[[914333345, -1563107339, 668467168, 9415600365, -8131416309, 8389610356, 7604207836, -4164203506, -2291145775], [4697936594, -7745934015], [-4651520348, -3085645067, -4519068178, -7950040818, -9543066562, 5606895475, -1534568525, -8229155741], [-2634952680, 3565837670], [-3239154229, -3459559891, -9783565309, 2874293724], [-3904981094, -7396874754], [-9841547454, -7990665221, 5130235947, -5311423002], [-4206303129, 4047239354, 5652054537, 7165867290]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[914333345, -1563107339, 668467168, 9415600365, -8131416309, 8389610356, 7604207836, -4164203506, -2291145775], [4697936594, -7745934015], [-4651520348, -3085645067, -4519068178, -7950040818, -9543066562, 5606895475, -1534568525, -8229155741], [-2634952680, 3565837670], [-3239154229, -3459559891, -9783565309, 2874293724], [-3904981094, -7396874754], [-9841547454, -7990665221, 5130235947, -5311423002], [-4206303129, 4047239354, 5652054537, 7165867290]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 }, { - "name": "NecklaceSplit_8", - "sat": "def sat(n: int, lace=\"rrbbbrbrbrrrbrbrbrrrrbrbbbbb\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"rrbbbrbrbrrrbrbrbrrrrbrbbbbb\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "FirstNegCumulative:3", + "sat": "def sat(firsts: List[int], balances=[[-3159744279, -5564462797, 9181877256, -581801013, -2730806212, -8069766232], [-2778889563, 6023011147, 6046948312, -1208971488, 2110520757, 7936971409, -4498797430, -7122967646], [-4649451153, -7199067130, 6484358738, -1015824976, 1504326141, 7704654617, 1083805811, -561837290, -9713157689], [-6286190794, 9847932237, -9818551636, -475170800], [-3927971639, 8808808262, 5363473771, 6453926109, -7932299279, 3515829826, -5092391511, 1619970550], [922221935, -3257271738, -4032399516, 5900007512, -2582293019, -1474957782, 2672311585, 5186169557, -4404554166], [3505067196, -649622176, -9390601127, 4030860857], [-8952966741], [2421457437, 531860397, -5157882824, 1563799160, -2925234193, 339874024, -7985065932, 1541877668, 7043758413]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[-3159744279, -5564462797, 9181877256, -581801013, -2730806212, -8069766232], [-2778889563, 6023011147, 6046948312, -1208971488, 2110520757, 7936971409, -4498797430, -7122967646], [-4649451153, -7199067130, 6484358738, -1015824976, 1504326141, 7704654617, 1083805811, -561837290, -9713157689], [-6286190794, 9847932237, -9818551636, -475170800], [-3927971639, 8808808262, 5363473771, 6453926109, -7932299279, 3515829826, -5092391511, 1619970550], [922221935, -3257271738, -4032399516, 5900007512, -2582293019, -1474957782, 2672311585, 5186169557, -4404554166], [3505067196, -649622176, -9390601127, 4030860857], [-8952966741], [2421457437, 531860397, -5157882824, 1563799160, -2925234193, 339874024, -7985065932, 1541877668, 7043758413]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 }, { - "name": "NecklaceSplit_9", - "sat": "def sat(n: int, lace=\"rbbrbbbrbrrrrbbrbrrrbrrrrrbbbrbbrrrrrrrrbbrbbbbrbbbrbrrrbbrbrrrbbbbrrrbrrbrrrrrrbbrrbbbbrrrrrrbrbrbrrrrbbrrrbbbrbbrbbbbbbrbbbrbbbbrrbbrrrrrbbrbbbrrrrrbbrrbbrbrrrbbrbbrbbrrrrbbrbrrbrbbbrbbbrrrrbbrbbbrbrrbrbrbrbrrbrbbbrbbrrbrrrbbrrbrrbbbrrbbbrbrbrrbbrbrbbrrbbbbbrrrbbrbrbrbrbbrrbrbrbrrrrbrrrrbrbrrrrrrbrrrrrrbrbbrrbbrbrbbrrbrbrbrrbbbrbbbrbbbrrbrrbbbbbrbbbbbrrbrbbrbrrbrrbbrbbrrrbbbbbbrbbbbrbbrrbbrbrrrrrrrrrrbbbbbrrbbbbrbbbrbbrbbbbbbbbrrbrbbbrrrbbbrrrbbrbrbbrrrbbrbrbbrrbbrrrbbbrbrrrbbbrbbbrbbrbbrbbrrbrbbrbbbrbrbbrrrrbrrbrbrbrrrbbrrbbrbrrrrbbbrrrrrbrbbrbbrbrbrrrbrrbbbrrrbbbrbbrrrrbrrrrbrbbbrrrbrrbbrbrbrrbrrbbbrbbrbbrbrbrrrbrbrbrrrrrrrbbrrrrbbbrrbrbbbrrrrbrbrrrrrrbrbbbbbrbbbbrbbrbbbrbbrrrbbrrbrrbrrrrrbrbbbrrbbbbbbrbbbrrrbbbbbbrbrbbbbbrrbbrbrbrbbbrrrbrbbbrrbbbbrrrbrrbbrrrrbbbrbrrrrrbrbbbbbbrbrbrbbbrrbbrrrrbbrrbrrrbbrbbrbbbrrbbbbrrbrrbbrrrrbrrbrrrrrbrbbrbbrrrbrrrrbrbbrbbrrrrrbrrbrrbrrrbrrrbrrbbbrrbbbrbbrbbrrrbbrrbbrrbrrrrbbrrrrbrbrrbbrrrrrbbrrbrbrrbrbrbbbbbbbrrbbbrrbbrrbbrbrbrrrbrrbbbbrrrbrbbbbbrbbbrbrbbrrrbrrrbbrrrbrrrrrbbrrrbbrbbrbrbrbbbbrrbbrrrbrbrrbrbrrbrbrrbbbbbbbrbbbbrbrbbbrrbrrrrrrbbrrrrbrrrrrrbrrrrrbrrrbbrrrrbbbbbrbbbbrbrrbbrrrrrbrbbbrbbbrbbrrbrrbrrrbrbrrrrbrrbbbbrbrrrbbbbrrbbbrbbbrbrrrbbrbrbbbbrbrbrbrbbrrrbbbbrbrrrrbrrbrrrbbrrbrbrrbbbrrbbbrbrbbbbrbrrbbrrrbrbrrbbbrrbrrrbbbbbrbbrrbrrbbbrbrrrrrbrrrrbrrrbrbbrbbbrrrrbrbbrbrbbrbrbrbbbrbrbbrrbrrrbrrrrrbrbbbbbbbbrrbbrrbrbbrrbrbbbbbbrbbrrbbrrrbbrrbbbrrrbrbbrrbrrrbbrbbrbrrrbrbbrbbrrrbbbbrrrrbbrrbbrbbrrbrbrrrrrrrbbrrrbrbrbbrrrbrbrrrbrbbrrrrbrrbrbrbbrbbrrrrrbbrbbrrbrrrrbrbbrrbbrrbrrrrrrrrrbrrrrbbbrrbrbbrrbrrbbbrbrbrrrbrrbbbbbbbrrrbrrrrbrbrrbbbbrbrrrrrrbrrbrrrrrbrbbrrbbrrrrbbrbbrrrbrbrbrrbrrbrrbrrbbrrbbrbbrbbrbbbbbbbrbbrrbbrrrrbbbrrrrrbrbrbbrrbbbbrrrbbbrbrrbbbrrbbrrbbrrrrbrbbrbbrrrbbbbrbbbrrbbrbbbbbbbrrrrbrbrbrrrrbrbrbbrbrbrbrbbbrrbbrrbrbrrrbbrbbbbbbrbrbbbbbbbrbbrrbbrbrrbrrbbrbrbbrbrbrbrbbrbbrrbrrbrbrbrbrbrrrbrbbrrrrrrbbrbbrbbrrrrrbbrrbbrbbrrrrbrrbbbrbbrrbrbbrbbbbbbbbbbbbrrbrrrbrbrrrrbbbbbbrbbrrrrrbbbrrbrbrrbrrbrbrrbbbrbrrbrrrrrbbbbbbrrrrbbbbbrrbbbbrrbbbrbrrrbbbbrbbbrrbrbbbbbrrbbbbrrrbrrbbrbrbrrrrrrrbbbrrrrbbrrrrbrrrbrrrbbrbbrrbbbbbrbbbrbrbrrbbbrbrbrbrrrbbrrrrrbbbbrbbrrbrrbrbbbbbrrbrbrbrbbbbbrbrrrrbbrbbrrbbbrbrbbbbrbrbrbrbbbrbbbrbrrbbrbbbrbbbrrrrbrbbrbbrrrrbbbbbbbrbbrbrbrrrbbbrrbbbrbrbrrrbbbrrbbbbbbrbbrbrbbrrrrbbrrbbbbbrrbbbbbbbrrbrbbbbrrrbbrbrrbbbbrbrbbrrbrbbrbrrrrrrbbrbbbrbrbbrbrrrrbrrbbbrbrrbbrbrbbbbrrrrbrbrbbrrbrrbrrrbbbbbrbbrbrbrbbbbbrrbrrrbbbbbrrrbbrrrrbbrbbrrbbrbrbrbrbbrbbrrrrrrbrrbrbbrbrbrbrrrbbrbrbrbbrbbrrrbrrrrbrbbbrrrrrrrbrbrbbrbrrbbbrrbbbrrbrbrbrbrrrrrrrrrbrbbrbbrrbrrbbrrrrrbrbbrbbbbbrrbrbbbbbbrbbrrbrbrbbrrrbbbrrrrrbrbrrrrrrbbrrbrbbrrrbrbrbbbrbbrbbrbrbbrrbbbbbbbbbrrbbbrrbrbbbrrbrbbrrbbrrrrbrbrrbrbbrrbbrrrbrbbrrrbrrrbrrbbbbbbbrbrrbbrrbbrbrbbrrrbbrrbrrrbbrrbrrbbrbbbrrbbrrrrrrbrrrbrbbbbbbrbrbbrrbbbbbrbbrrbrrrbbrbrrbr\"):\n \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", - "sols": [ - "def sol(lace=\"rbbrbbbrbrrrrbbrbrrrbrrrrrbbbrbbrrrrrrrrbbrbbbbrbbbrbrrrbbrbrrrbbbbrrrbrrbrrrrrrbbrrbbbbrrrrrrbrbrbrrrrbbrrrbbbrbbrbbbbbbrbbbrbbbbrrbbrrrrrbbrbbbrrrrrbbrrbbrbrrrbbrbbrbbrrrrbbrbrrbrbbbrbbbrrrrbbrbbbrbrrbrbrbrbrrbrbbbrbbrrbrrrbbrrbrrbbbrrbbbrbrbrrbbrbrbbrrbbbbbrrrbbrbrbrbrbbrrbrbrbrrrrbrrrrbrbrrrrrrbrrrrrrbrbbrrbbrbrbbrrbrbrbrrbbbrbbbrbbbrrbrrbbbbbrbbbbbrrbrbbrbrrbrrbbrbbrrrbbbbbbrbbbbrbbrrbbrbrrrrrrrrrrbbbbbrrbbbbrbbbrbbrbbbbbbbbrrbrbbbrrrbbbrrrbbrbrbbrrrbbrbrbbrrbbrrrbbbrbrrrbbbrbbbrbbrbbrbbrrbrbbrbbbrbrbbrrrrbrrbrbrbrrrbbrrbbrbrrrrbbbrrrrrbrbbrbbrbrbrrrbrrbbbrrrbbbrbbrrrrbrrrrbrbbbrrrbrrbbrbrbrrbrrbbbrbbrbbrbrbrrrbrbrbrrrrrrrbbrrrrbbbrrbrbbbrrrrbrbrrrrrrbrbbbbbrbbbbrbbrbbbrbbrrrbbrrbrrbrrrrrbrbbbrrbbbbbbrbbbrrrbbbbbbrbrbbbbbrrbbrbrbrbbbrrrbrbbbrrbbbbrrrbrrbbrrrrbbbrbrrrrrbrbbbbbbrbrbrbbbrrbbrrrrbbrrbrrrbbrbbrbbbrrbbbbrrbrrbbrrrrbrrbrrrrrbrbbrbbrrrbrrrrbrbbrbbrrrrrbrrbrrbrrrbrrrbrrbbbrrbbbrbbrbbrrrbbrrbbrrbrrrrbbrrrrbrbrrbbrrrrrbbrrbrbrrbrbrbbbbbbbrrbbbrrbbrrbbrbrbrrrbrrbbbbrrrbrbbbbbrbbbrbrbbrrrbrrrbbrrrbrrrrrbbrrrbbrbbrbrbrbbbbrrbbrrrbrbrrbrbrrbrbrrbbbbbbbrbbbbrbrbbbrrbrrrrrrbbrrrrbrrrrrrbrrrrrbrrrbbrrrrbbbbbrbbbbrbrrbbrrrrrbrbbbrbbbrbbrrbrrbrrrbrbrrrrbrrbbbbrbrrrbbbbrrbbbrbbbrbrrrbbrbrbbbbrbrbrbrbbrrrbbbbrbrrrrbrrbrrrbbrrbrbrrbbbrrbbbrbrbbbbrbrrbbrrrbrbrrbbbrrbrrrbbbbbrbbrrbrrbbbrbrrrrrbrrrrbrrrbrbbrbbbrrrrbrbbrbrbbrbrbrbbbrbrbbrrbrrrbrrrrrbrbbbbbbbbrrbbrrbrbbrrbrbbbbbbrbbrrbbrrrbbrrbbbrrrbrbbrrbrrrbbrbbrbrrrbrbbrbbrrrbbbbrrrrbbrrbbrbbrrbrbrrrrrrrbbrrrbrbrbbrrrbrbrrrbrbbrrrrbrrbrbrbbrbbrrrrrbbrbbrrbrrrrbrbbrrbbrrbrrrrrrrrrbrrrrbbbrrbrbbrrbrrbbbrbrbrrrbrrbbbbbbbrrrbrrrrbrbrrbbbbrbrrrrrrbrrbrrrrrbrbbrrbbrrrrbbrbbrrrbrbrbrrbrrbrrbrrbbrrbbrbbrbbrbbbbbbbrbbrrbbrrrrbbbrrrrrbrbrbbrrbbbbrrrbbbrbrrbbbrrbbrrbbrrrrbrbbrbbrrrbbbbrbbbrrbbrbbbbbbbrrrrbrbrbrrrrbrbrbbrbrbrbrbbbrrbbrrbrbrrrbbrbbbbbbrbrbbbbbbbrbbrrbbrbrrbrrbbrbrbbrbrbrbrbbrbbrrbrrbrbrbrbrbrrrbrbbrrrrrrbbrbbrbbrrrrrbbrrbbrbbrrrrbrrbbbrbbrrbrbbrbbbbbbbbbbbbrrbrrrbrbrrrrbbbbbbrbbrrrrrbbbrrbrbrrbrrbrbrrbbbrbrrbrrrrrbbbbbbrrrrbbbbbrrbbbbrrbbbrbrrrbbbbrbbbrrbrbbbbbrrbbbbrrrbrrbbrbrbrrrrrrrbbbrrrrbbrrrrbrrrbrrrbbrbbrrbbbbbrbbbrbrbrrbbbrbrbrbrrrbbrrrrrbbbbrbbrrbrrbrbbbbbrrbrbrbrbbbbbrbrrrrbbrbbrrbbbrbrbbbbrbrbrbrbbbrbbbrbrrbbrbbbrbbbrrrrbrbbrbbrrrrbbbbbbbrbbrbrbrrrbbbrrbbbrbrbrrrbbbrrbbbbbbrbbrbrbbrrrrbbrrbbbbbrrbbbbbbbrrbrbbbbrrrbbrbrrbbbbrbrbbrrbrbbrbrrrrrrbbrbbbrbrbbrbrrrrbrrbbbrbrrbbrbrbbbbrrrrbrbrbbrrbrrbrrrbbbbbrbbrbrbrbbbbbrrbrrrbbbbbrrrbbrrrrbbrbbrrbbrbrbrbrbbrbbrrrrrrbrrbrbbrbrbrbrrrbbrbrbrbbrbbrrrbrrrrbrbbbrrrrrrrbrbrbbrbrrbbbrrbbbrrbrbrbrbrrrrrrrrrbrbbrbbrrbrrbbrrrrrbrbbrbbbbbrrbrbbbbbbrbbrrbrbrbbrrrbbbrrrrrbrbrrrrrrbbrrbrbbrrrbrbrbbbrbbrbbrbrbbrrbbbbbbbbbrrbbbrrbrbbbrrbrbbrrbbrrrrbrbrrbrbbrrbbrrrbrbbrrrbrrrbrrbbbbbbbrbrrbbrrbbrbrbbrrrbbrrbrrrbbrrbrrbbrbbbrrbbrrrrrrbrrrbrbbbbbbrbrbbrrbbbbbrbbrrbrrrbbrbrrbr\"):\n if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + "name": "FirstNegCumulative:4", + "sat": "def sat(firsts: List[int], balances=[[-2041524901, -9443452974, 6724922319], [9512986005, -7256441789, -8146859479, -648834428, 9137465613, 6849232316, -3669774686, -2798878807], [-700370861, -7254999326, 1316572844, -6690887070, 1763578306], [-71670187, 5659836631, 4279460608, 3047233262, -3918077853, 465790429, -1844240292], [-4058863322, 9667272009, 46010424, -5378831171, 6550560002, -1392053235, -2356282119], [-6617394020, -122757412, 5783268011, -7742860607, 3581304886, 5357960664, 6017029257, -1679200889], [-3456426106, -3386028090, -6864999581, -4690984097, -2321291466, -5583489756]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[-2041524901, -9443452974, 6724922319], [9512986005, -7256441789, -8146859479, -648834428, 9137465613, 6849232316, -3669774686, -2798878807], [-700370861, -7254999326, 1316572844, -6690887070, 1763578306], [-71670187, 5659836631, 4279460608, 3047233262, -3918077853, 465790429, -1844240292], [-4058863322, 9667272009, 46010424, -5378831171, 6550560002, -1392053235, -2356282119], [-6617394020, -122757412, 5783268011, -7742860607, 3581304886, 5357960664, 6017029257, -1679200889], [-3456426106, -3386028090, -6864999581, -4690984097, -2321291466, -5583489756]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" ], - "module": "classic_puzzles", - "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 }, { - "name": "PandigitalSquare_0", - "sat": "def sat(n: int):\n \"\"\"Find an integer whose square has all digits 0-9 once.\"\"\"\n s = str(n * n)\n for i in \"0123456789\":\n assert s.count(i) == 1\n return True", - "sols": [ - "def sol():\n for n in range(10 ** 5):\n if sorted([int(s) for s in str(n * n)]) == list(range(10)):\n return n" + "name": "MinSquaredDeviation:0", + "sat": "def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" ], - "module": "classic_puzzles", - "notes": "[Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 }, { - "name": "AllPandigitalSquares_0", - "sat": "def sat(nums: List[int]):\n \"\"\"Find all 174 integers whose 10-digit square has all digits 0-9 just once.\"\"\"\n return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174", - "sols": [ - "def sol():\n return [i for i in range(-10 ** 5, 10 ** 5) if sorted([int(s) for s in str(i * i)]) == list(range(10))]" + "name": "MinSquaredDeviation:1", + "sat": "def sat(x: float, nums=[-47, -58, -46, -29, 48, -7, 85, -48]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[-47, -58, -46, -29, 48, -7, 85, -48]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" ], - "module": "classic_puzzles", - "notes": "All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 }, { - "name": "CardGame24_0", - "sat": "def sat(expr: str, nums=[3, 7, 3, 7]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[3, 7, 3, 7]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "MinSquaredDeviation:2", + "sat": "def sat(x: float, nums=[-76, -99, 72, 33, 21, -54, -21, 24, 97, 89]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[-76, -99, 72, 33, 21, -54, -21, 24, 97, 89]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 }, { - "name": "CardGame24_1", - "sat": "def sat(expr: str, nums=[1, 3, 7, 13]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[1, 3, 7, 13]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "MinSquaredDeviation:3", + "sat": "def sat(x: float, nums=[-62, -53, -80]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[-62, -53, -80]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 }, { - "name": "CardGame24_2", - "sat": "def sat(expr: str, nums=[10, 7, 3, 1]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[10, 7, 3, 1]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "MinSquaredDeviation:4", + "sat": "def sat(x: float, nums=[-76, 76, -88, 37, 7]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[-76, 76, -88, 37, 7]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 + }, + { + "name": "Intersperse:0", + "sat": "def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, 23, -2, 5, 0], sep=4):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "Intersperse:1", + "sat": "def sat(li: List[int], nums=[], sep=23):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[], sep=23):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "Intersperse:2", + "sat": "def sat(li: List[int], nums=[90, 23, 0, 0, 36, 61, 73], sep=14):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[90, 23, 0, 0, 36, 61, 73], sep=14):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "Intersperse:3", + "sat": "def sat(li: List[int], nums=[41, 60, 18, 34, 31], sep=2):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[41, 60, 18, 34, 31], sep=2):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "Intersperse:4", + "sat": "def sat(li: List[int], nums=[39, 94, 99, 46, 93], sep=25):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[39, 94, 99, 46, 93], sep=25):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "DeepestParens:0", + "sat": "def sat(depths: List[int], parens=\"() (()) ((()()())) (((((((())))))))\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"() (()) ((()()())) (((((((())))))))\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 }, { - "name": "CardGame24_3", - "sat": "def sat(expr: str, nums=[8, 3, 12, 1]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[8, 3, 12, 1]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "DeepestParens:1", + "sat": "def sat(depths: List[int], parens=\"\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 }, { - "name": "CardGame24_4", - "sat": "def sat(expr: str, nums=[10, 12, 1, 7]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[10, 12, 1, 7]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "DeepestParens:2", + "sat": "def sat(depths: List[int], parens=\"(()) (((()(((()())()())))))(())()\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"(()) (((()(((()())()())))))(())()\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 }, { - "name": "CardGame24_5", - "sat": "def sat(expr: str, nums=[8, 12, 3, 5]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[8, 12, 3, 5]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "DeepestParens:3", + "sat": "def sat(depths: List[int], parens=\"(()) ()()(()())() () ()(())() ()((()))\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"(()) ()()(()())() () ()(())() ()((()))\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 }, { - "name": "CardGame24_6", - "sat": "def sat(expr: str, nums=[4, 2, 8, 3]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[4, 2, 8, 3]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "DeepestParens:4", + "sat": "def sat(depths: List[int], parens=\"()()(())()(())\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"()()(())()(())\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 }, { - "name": "CardGame24_7", - "sat": "def sat(expr: str, nums=[5, 1, 12, 2]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[5, 1, 12, 2]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "FindContainers:0", + "sat": "def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 }, { - "name": "CardGame24_8", - "sat": "def sat(expr: str, nums=[11, 13, 6, 2]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[11, 13, 6, 2]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "FindContainers:1", + "sat": "def sat(containers: List[str], strings=['ty', 'jy', 'jsesnicy'], substring=\"ses\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['ty', 'jy', 'jsesnicy'], substring=\"ses\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 }, { - "name": "CardGame24_9", - "sat": "def sat(expr: str, nums=[6, 6, 4, 8]):\n \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", - "sols": [ - "def sol(nums=[6, 6, 4, 8]):\n def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + "name": "FindContainers:2", + "sat": "def sat(containers: List[str], strings=['rgyjo', 'tipu', 'mulut', 'wutgypepu'], substring=\"gy\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['rgyjo', 'tipu', 'mulut', 'wutgypepu'], substring=\"gy\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" ], - "module": "classic_puzzles", - "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 }, { - "name": "Easy63_0", - "sat": "def sat(s: str):\n \"\"\"Find a formula using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 2 and s.count(\"1\") == 1 and eval(s) == 63", - "sols": [ - "def sol():\n return \"8*8-1\"" + "name": "FindContainers:3", + "sat": "def sat(containers: List[str], strings=[], substring=\"ve\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=[], substring=\"ve\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" ], - "module": "classic_puzzles", - "notes": "An easy puzzle to make 63 using two 8's and one 1's.", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 }, { - "name": "Harder63_0", - "sat": "def sat(s: str):\n \"\"\"Find an expression using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 3 and s.count(\"1\") == 1 and eval(s) == 63", - "sols": [ - "def sol():\n return \"8*8-1**8\"" + "name": "FindContainers:4", + "sat": "def sat(containers: List[str], strings=['te', 'dmmo', ''], substring=\"m\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['te', 'dmmo', ''], substring=\"m\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" ], - "module": "classic_puzzles", - "notes": "An harder puzzle to make 63 using three 8's and one 1's.", - "taint_date": "2021-4-26", - "weight": 0.045454545454545456 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 }, { - "name": "WaterPouring_0", - "sat": "def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "SumProduct:0", + "sat": "def sat(nums: List[int], tot=14, prod=99):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=14, prod=99):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 }, { - "name": "WaterPouring_1", - "sat": "def sat(moves: List[List[int]], capacities=[724, 43, 611], init=[72, 2, 269], goal=[56, 0, 287]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[724, 43, 611], init=[72, 2, 269], goal=[56, 0, 287]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "SumProduct:1", + "sat": "def sat(nums: List[int], tot=-81, prod=13):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=-81, prod=13):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 }, { - "name": "WaterPouring_2", - "sat": "def sat(moves: List[List[int]], capacities=[357, 298, 492], init=[8, 284, 72], goal=[0, 0, 364]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[357, 298, 492], init=[8, 284, 72], goal=[0, 0, 364]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "SumProduct:2", + "sat": "def sat(nums: List[int], tot=96, prod=-44):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=96, prod=-44):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 }, { - "name": "WaterPouring_3", - "sat": "def sat(moves: List[List[int]], capacities=[511, 625, 553], init=[472, 153, 127], goal=[97, 625, 30]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[511, 625, 553], init=[472, 153, 127], goal=[97, 625, 30]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "SumProduct:3", + "sat": "def sat(nums: List[int], tot=86, prod=24):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=86, prod=24):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 }, { - "name": "WaterPouring_4", - "sat": "def sat(moves: List[List[int]], capacities=[86, 259, 281], init=[47, 18, 35], goal=[35, 0, 65]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[86, 259, 281], init=[47, 18, 35], goal=[35, 0, 65]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "SumProduct:4", + "sat": "def sat(nums: List[int], tot=-16, prod=3):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=-16, prod=3):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 }, { - "name": "WaterPouring_5", - "sat": "def sat(moves: List[List[int]], capacities=[920, 305, 890], init=[120, 139, 410], goal=[564, 105, 0]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[920, 305, 890], init=[120, 139, 410], goal=[564, 105, 0]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "RollingMax:0", + "sat": "def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 4, 3, -6, 19]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 }, { - "name": "WaterPouring_6", - "sat": "def sat(moves: List[List[int]], capacities=[325, 942, 32], init=[117, 164, 21], goal=[42, 260, 0]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[325, 942, 32], init=[117, 164, 21], goal=[42, 260, 0]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "RollingMax:1", + "sat": "def sat(maxes: List[int], nums=[-15, -6]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-15, -6]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 }, { - "name": "WaterPouring_7", - "sat": "def sat(moves: List[List[int]], capacities=[302, 260, 629], init=[67, 27, 347], goal=[3, 0, 438]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[302, 260, 629], init=[67, 27, 347], goal=[3, 0, 438]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "RollingMax:2", + "sat": "def sat(maxes: List[int], nums=[]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 }, { - "name": "WaterPouring_8", - "sat": "def sat(moves: List[List[int]], capacities=[448, 585, 364], init=[12, 101, 337], goal=[113, 0, 337]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[448, 585, 364], init=[12, 101, 337], goal=[113, 0, 337]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "RollingMax:3", + "sat": "def sat(maxes: List[int], nums=[-100, 14, -45, 92, 36, -68, -40]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-100, 14, -45, 92, 36, -68, -40]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 }, { - "name": "WaterPouring_9", - "sat": "def sat(moves: List[List[int]], capacities=[151, 219, 555], init=[80, 74, 5], goal=[3, 0, 156]): # moves is list of [from, to] pairs\n \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n \"\"\"\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", - "sols": [ - "def sol(capacities=[151, 219, 555], init=[80, 74, 5], goal=[3, 0, 156]):\n from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + "name": "RollingMax:4", + "sat": "def sat(maxes: List[int], nums=[23, -34, 96]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[23, -34, 96]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" ], - "module": "classic_puzzles", - "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 }, { - "name": "VerbalArithmetic_0", - "sat": "def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['SEND', 'MORE', 'MONEY']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "PalindromeContaining:0", + "sat": "def sat(ans: str, s=\"so easy\", length=20):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"so easy\", length=20):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 }, { - "name": "VerbalArithmetic_1", - "sat": "def sat(li: List[int], words=['FORTY', 'TEN', 'TEN', 'SIXTY']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['FORTY', 'TEN', 'TEN', 'SIXTY']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "PalindromeContaining:1", + "sat": "def sat(ans: str, s=\"aabbab\", length=12):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"aabbab\", length=12):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 }, { - "name": "VerbalArithmetic_2", - "sat": "def sat(li: List[int], words=['GREEN', 'ORANGE', 'COLORS']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['GREEN', 'ORANGE', 'COLORS']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "PalindromeContaining:2", + "sat": "def sat(ans: str, s=\"bbb\", length=27):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"bbb\", length=27):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 }, { - "name": "VerbalArithmetic_3", - "sat": "def sat(li: List[int], words=['fqjb', 'awqw', 'lfll', 'fvvvb']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['fqjb', 'awqw', 'lfll', 'fvvvb']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "PalindromeContaining:3", + "sat": "def sat(ans: str, s=\"bb\", length=38):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"bb\", length=38):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 }, { - "name": "VerbalArithmetic_4", - "sat": "def sat(li: List[int], words=['tnnq', 'sna', 'ajjc', 'isun', 'usub', 'caiun']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['tnnq', 'sna', 'ajjc', 'isun', 'usub', 'caiun']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "PalindromeContaining:4", + "sat": "def sat(ans: str, s=\"\", length=0):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"\", length=0):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 }, { - "name": "VerbalArithmetic_5", - "sat": "def sat(li: List[int], words=['idix', 'izdw', 'ixxc', 'ddcw', 'rrxx', 'wxzc', 'ffxw', 'icfdv']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['idix', 'izdw', 'ixxc', 'ddcw', 'rrxx', 'wxzc', 'ffxw', 'icfdv']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "BinaryStrXOR:0", + "sat": "def sat(str_num: str, nums=['100011101100001', '100101100101110']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['100011101100001', '100101100101110']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 }, { - "name": "VerbalArithmetic_6", - "sat": "def sat(li: List[int], words=['dbss', 'clla', 'wsqnv']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['dbss', 'clla', 'wsqnv']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "BinaryStrXOR:1", + "sat": "def sat(str_num: str, nums=['1101101111', '11001100']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['1101101111', '11001100']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 }, { - "name": "VerbalArithmetic_7", - "sat": "def sat(li: List[int], words=['izko', 'yzyv', 'vyfy', 'ttvz', 'yikk', 'tfvf', 'vvfyf']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['izko', 'yzyv', 'vyfy', 'ttvz', 'yikk', 'tfvf', 'vvfyf']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "BinaryStrXOR:2", + "sat": "def sat(str_num: str, nums=['11011111', '1101001110']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['11011111', '1101001110']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 }, { - "name": "VerbalArithmetic_8", - "sat": "def sat(li: List[int], words=['klkb', 'jckp', 'ggcs']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['klkb', 'jckp', 'ggcs']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "BinaryStrXOR:3", + "sat": "def sat(str_num: str, nums=['100000001', '1010001001']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['100000001', '1010001001']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 }, { - "name": "VerbalArithmetic_9", - "sat": "def sat(li: List[int], words=['fccf', 'cffp', 'uuul']):\n \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", - "sols": [ - "def sol(words=['fccf', 'cffp', 'uuul']):\n pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + "name": "BinaryStrXOR:4", + "sat": "def sat(str_num: str, nums=['10010110', '10000']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['10010110', '10000']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" ], - "module": "classic_puzzles", - "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 }, { - "name": "SlidingPuzzle_0", - "sat": "def sat(moves: List[int], start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "LongestStr:0", + "sat": "def sat(ans: str, words=['these', 'are', 'some', 'pretty', 'long', 'words']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['these', 'are', 'some', 'pretty', 'long', 'words']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 }, { - "name": "SlidingPuzzle_1", - "sat": "def sat(moves: List[int], start=[[1, 5, 0], [3, 2, 8], [6, 4, 7]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[1, 5, 0], [3, 2, 8], [6, 4, 7]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "LongestStr:1", + "sat": "def sat(ans: str, words=['suquojurethy', 'zetenejubichicyj', 'dyzeroquyxipyfe']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['suquojurethy', 'zetenejubichicyj', 'dyzeroquyxipyfe']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 }, { - "name": "SlidingPuzzle_2", - "sat": "def sat(moves: List[int], start=[[6, 0, 3], [7, 1, 4], [8, 2, 5]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[6, 0, 3], [7, 1, 4], [8, 2, 5]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "LongestStr:2", + "sat": "def sat(ans: str, words=['thusisequiw', 'tevozequetextupetha', 'texterut', 'zopuhesofowyk', 'chajokapechunekizic', 'hefuhyjiwakifyma', 'thopebom', 'pah']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['thusisequiw', 'tevozequetextupetha', 'texterut', 'zopuhesofowyk', 'chajokapechunekizic', 'hefuhyjiwakifyma', 'thopebom', 'pah']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 }, { - "name": "SlidingPuzzle_3", - "sat": "def sat(moves: List[int], start=[[0, 1], [2, 3]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[0, 1], [2, 3]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "LongestStr:3", + "sat": "def sat(ans: str, words=['melo', 'zoj', 'wujololyfytew', 'barivitextyte', 'decipywiduvaq', 'ruty', 'gekusoduz']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['melo', 'zoj', 'wujololyfytew', 'barivitextyte', 'decipywiduvaq', 'ruty', 'gekusoduz']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 }, { - "name": "SlidingPuzzle_4", - "sat": "def sat(moves: List[int], start=[[2, 1], [0, 3]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[2, 1], [0, 3]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "LongestStr:4", + "sat": "def sat(ans: str, words=['quicydynigatha', 'pethiquifegosych', 'jixotextoxa', 'pe', 'xona', 'cifuco', 'gyrejypifam']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['quicydynigatha', 'pethiquifegosych', 'jixotextoxa', 'pe', 'xona', 'cifuco', 'gyrejypifam']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 }, { - "name": "SlidingPuzzle_5", - "sat": "def sat(moves: List[int], start=[[8, 0, 3, 7], [9, 4, 2, 15], [5, 6, 1, 11], [12, 10, 13, 14]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[8, 0, 3, 7], [9, 4, 2, 15], [5, 6, 1, 11], [12, 10, 13, 14]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "CertifiedGCD:0", + "sat": "def sat(ans: List[int], m=200004931, n=66679984):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=200004931, n=66679984):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 }, { - "name": "SlidingPuzzle_6", - "sat": "def sat(moves: List[int], start=[[3, 1, 2], [4, 7, 0], [6, 8, 5]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[3, 1, 2], [4, 7, 0], [6, 8, 5]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "CertifiedGCD:1", + "sat": "def sat(ans: List[int], m=2642408, n=828886):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=2642408, n=828886):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 }, { - "name": "SlidingPuzzle_7", - "sat": "def sat(moves: List[int], start=[[1, 5, 2, 3], [8, 4, 10, 7], [6, 0, 9, 11], [12, 13, 14, 15]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[1, 5, 2, 3], [8, 4, 10, 7], [6, 0, 9, 11], [12, 13, 14, 15]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "CertifiedGCD:2", + "sat": "def sat(ans: List[int], m=184428, n=105545439738):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=184428, n=105545439738):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 }, { - "name": "SlidingPuzzle_8", - "sat": "def sat(moves: List[int], start=[[3, 2, 5], [4, 1, 8], [0, 6, 7]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[3, 2, 5], [4, 1, 8], [0, 6, 7]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "CertifiedGCD:3", + "sat": "def sat(ans: List[int], m=3956548155, n=103530):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=3956548155, n=103530):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 }, { - "name": "SlidingPuzzle_9", - "sat": "def sat(moves: List[int], start=[[2, 8, 4], [5, 0, 3], [1, 6, 7]]):\n \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", - "sols": [ - "def sol(start=[[2, 8, 4], [5, 0, 3], [1, 6, 7]]):\n from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + "name": "CertifiedGCD:4", + "sat": "def sat(ans: List[int], m=101920, n=55199657760):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=101920, n=55199657760):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" ], - "module": "classic_puzzles", - "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 }, { - "name": "FindCloseElements_0", - "sat": "def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "AllPrefixes:0", + "sat": "def sat(prefixes: List[str], s=\"donesezichethofalij\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"donesezichethofalij\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 }, { - "name": "FindCloseElements_1", - "sat": "def sat(pair: List[float], nums=[-3.027185809375565, -6.642297851887924, -6.773598672960938, 8.692593210252113, 4.9144452253248225, -6.773598672960938, -9.228605102488878]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[-3.027185809375565, -6.642297851887924, -6.773598672960938, 8.692593210252113, 4.9144452253248225, -6.773598672960938, -9.228605102488878]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "AllPrefixes:1", + "sat": "def sat(prefixes: List[str], s=\"vuf\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"vuf\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 }, { - "name": "FindCloseElements_2", - "sat": "def sat(pair: List[float], nums=[-1.5625078353699955, 3.6482553468598375, -2.6412688082759868, -0.511423740751141, -2.6412688082759868, 5.648091691238367]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[-1.5625078353699955, 3.6482553468598375, -2.6412688082759868, -0.511423740751141, -2.6412688082759868, 5.648091691238367]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "AllPrefixes:2", + "sat": "def sat(prefixes: List[str], s=\"t\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"t\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 }, { - "name": "FindCloseElements_3", - "sat": "def sat(pair: List[float], nums=[4.183381104176473, 1.6210985169040963, 1.6210985169040963]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[4.183381104176473, 1.6210985169040963, 1.6210985169040963]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "AllPrefixes:3", + "sat": "def sat(prefixes: List[str], s=\"qu\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"qu\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 }, { - "name": "FindCloseElements_4", - "sat": "def sat(pair: List[float], nums=[2.3934380222903258, -7.674333581672553, 2.3934380222903258]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[2.3934380222903258, -7.674333581672553, 2.3934380222903258]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "AllPrefixes:4", + "sat": "def sat(prefixes: List[str], s=\"dugethixuneku\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"dugethixuneku\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 }, { - "name": "FindCloseElements_5", - "sat": "def sat(pair: List[float], nums=[4.4066248039776, 2.2695696407128008, 4.4066248039776, 8.896776165217684, -2.1082490303294303, 3.6982209062203317]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[4.4066248039776, 2.2695696407128008, 4.4066248039776, 8.896776165217684, -2.1082490303294303, 3.6982209062203317]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "SpaceyRange:0", + "sat": "def sat(ans: str, n=15):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=15):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 }, { - "name": "FindCloseElements_6", - "sat": "def sat(pair: List[float], nums=[-5.348817893106599, 6.577244972670922, -3.306658224381504, 9.304306848774289, -5.348817893106599, 5.566413077192129]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[-5.348817893106599, 6.577244972670922, -3.306658224381504, 9.304306848774289, -5.348817893106599, 5.566413077192129]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "SpaceyRange:1", + "sat": "def sat(ans: str, n=54635):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=54635):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 }, { - "name": "FindCloseElements_7", - "sat": "def sat(pair: List[float], nums=[2.1353360138897983, 2.1353360138897983, -6.715603996279675]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[2.1353360138897983, 2.1353360138897983, -6.715603996279675]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "SpaceyRange:2", + "sat": "def sat(ans: str, n=83):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=83):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 }, { - "name": "FindCloseElements_8", - "sat": "def sat(pair: List[float], nums=[-3.302805356460694, -0.9275606055184937, 0.8435888675003671, -1.0213115593616848, 1.6677218153667184, 0.8435888675003671, -0.4235691659037357]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[-3.302805356460694, -0.9275606055184937, 0.8435888675003671, -1.0213115593616848, 1.6677218153667184, 0.8435888675003671, -0.4235691659037357]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "SpaceyRange:3", + "sat": "def sat(ans: str, n=99847):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=99847):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 }, { - "name": "FindCloseElements_9", - "sat": "def sat(pair: List[float], nums=[-6.506446563143804, 1.442971309818974, -9.035414427546307, -5.396252925967609, -1.211336273420379, -9.06894227453712, 1.092136912296377, 1.092136912296377, 0.08234740859202105]):\n \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"\n a, b = pair\n assert a in nums and b in nums\n return abs(a - b) == min({abs(x - y) for x in nums for y in nums} - {0})", - "sols": [ - "def sol(nums=[-6.506446563143804, 1.442971309818974, -9.035414427546307, -5.396252925967609, -1.211336273420379, -9.06894227453712, 1.092136912296377, 1.092136912296377, 0.08234740859202105]):\n s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + "name": "SpaceyRange:4", + "sat": "def sat(ans: str, n=18215):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=18215):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 }, { - "name": "SeparateParenGroups_0", - "sat": "def sat(ls: List[str], combined=\"() (()) ((() () ())) (() )\"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\"() (()) ((() () ())) (() )\"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "DistinctChars:0", + "sat": "def sat(ans: List[str], s=\"The quick brown fox jumps over the lazy dog!\", n=28):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"The quick brown fox jumps over the lazy dog!\", n=28):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 }, { - "name": "SeparateParenGroups_1", - "sat": "def sat(ls: List[str], combined=\"() () \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\"() () \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "DistinctChars:1", + "sat": "def sat(ans: List[str], s=\"Iu]K,>Q8w\", n=9):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"Iu]K,>Q8w\", n=9):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 }, { - "name": "SeparateParenGroups_2", - "sat": "def sat(ls: List[str], combined=\" ((((() ())( ( ))()))) \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\" ((((() ())( ( ))()))) \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "DistinctChars:2", + "sat": "def sat(ans: List[str], s=\"JrUCk=ek&q^xBuvtm\", n=15):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"JrUCk=ek&q^xBuvtm\", n=15):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 }, { - "name": "SeparateParenGroups_3", - "sat": "def sat(ls: List[str], combined=\"() \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\"() \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "DistinctChars:3", + "sat": "def sat(ans: List[str], s=\"V-wKeN\", n=6):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"V-wKeN\", n=6):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 }, { - "name": "SeparateParenGroups_4", - "sat": "def sat(ls: List[str], combined=\"(() )(( )() ) ((( (()))(()(()() ( )( ()) )( ( )( )) (() )) )()) (( )) \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\"(() )(( )() ) ((( (()))(()(()() ( )( ()) )( ( )( )) (() )) )()) (( )) \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "DistinctChars:4", + "sat": "def sat(ans: List[str], s=\"F;J*qHN.^YC\", n=11):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"F;J*qHN.^YC\", n=11):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 }, { - "name": "SeparateParenGroups_5", - "sat": "def sat(ls: List[str], combined=\" \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\" \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "ParseMusic:0", + "sat": "def sat(beats: List[int], score=\"o o o| o| .| .| .| o| o| o o o| .|\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\"o o o| o| .| .| .| o| o| o o o| .|\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 }, { - "name": "SeparateParenGroups_6", - "sat": "def sat(ls: List[str], combined=\"\"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\"\"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "ParseMusic:1", + "sat": "def sat(beats: List[int], score=\".| o .| o| o| o| o| .| o o\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\".| o .| o| o| o| o| .| o o\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 }, { - "name": "SeparateParenGroups_7", - "sat": "def sat(ls: List[str], combined=\" ((()()() )) \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\" ((()()() )) \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "ParseMusic:2", + "sat": "def sat(beats: List[int], score=\"o| .| .| .| .| o| o .| o| o| o\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\"o| .| .| .| .| o| o .| o| o| o\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 }, { - "name": "SeparateParenGroups_8", - "sat": "def sat(ls: List[str], combined=\" ()()\"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\" ()()\"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "ParseMusic:3", + "sat": "def sat(beats: List[int], score=\".| o|\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\".| o|\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 }, { - "name": "SeparateParenGroups_9", - "sat": "def sat(ls: List[str], combined=\" () ( )(()) () () (()(())) \"):\n \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"\n assert ''.join(ls) == combined.replace(' ', '')\n for s in ls: # check that s is not further divisible\n depth = 0\n for c in s[:-1]:\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n assert depth >= 1\n assert depth == 1 and s[-1] == ')'\n return True", - "sols": [ - "def sol(combined=\" () ( )(()) () () (()(())) \"):\n cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + "name": "ParseMusic:4", + "sat": "def sat(beats: List[int], score=\"\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\"\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 }, { - "name": "Frac_0", - "sat": "def sat(x: float, v=523.12892):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=523.12892):\n return v % 1.0" + "name": "OverlappingCount:0", + "sat": "def sat(ans: List[int], s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 }, { - "name": "Frac_1", - "sat": "def sat(x: float, v=93.86070917102649):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=93.86070917102649):\n return v % 1.0" + "name": "OverlappingCount:1", + "sat": "def sat(ans: List[int], s=\"halidykugadobezebothidububawuvejiquitextyrequamobythynethojahyquutatextoquuzilu\", sub=\"ne\", count=1):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"halidykugadobezebothidububawuvejiquitextyrequamobythynethojahyquutatextoquuzilu\", sub=\"ne\", count=1):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 }, { - "name": "Frac_2", - "sat": "def sat(x: float, v=-6.770237138115334):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=-6.770237138115334):\n return v % 1.0" + "name": "OverlappingCount:2", + "sat": "def sat(ans: List[int], s=\"sutapifitextidavyjedakotextopogonudy\", sub=\"te\", count=2):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"sutapifitextidavyjedakotextopogonudy\", sub=\"te\", count=2):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 }, { - "name": "Frac_3", - "sat": "def sat(x: float, v=61.58244309946389):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=61.58244309946389):\n return v % 1.0" + "name": "OverlappingCount:3", + "sat": "def sat(ans: List[int], s=\"fizyquohachoromuxuquatextidemihithacazynytytextukozarahuwyfuchyquyhidadytext\", sub=\"quohach\", count=1):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"fizyquohachoromuxuquatextidemihithacazynytytextukozarahuwyfuchyquyhidadytext\", sub=\"quohach\", count=1):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 }, { - "name": "Frac_4", - "sat": "def sat(x: float, v=-80.9341003381162):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=-80.9341003381162):\n return v % 1.0" + "name": "OverlappingCount:4", + "sat": "def sat(ans: List[int], s=\"wutextega\", sub=\"xtega\", count=1):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"wutextega\", sub=\"xtega\", count=1):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 }, { - "name": "Frac_5", - "sat": "def sat(x: float, v=45.312150343581436):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=45.312150343581436):\n return v % 1.0" + "name": "SortNumbers:0", + "sat": "def sat(ans: str, s=\"six one four three two nine eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"six one four three two nine eight\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 }, { - "name": "Frac_6", - "sat": "def sat(x: float, v=30.586879862686033):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=30.586879862686033):\n return v % 1.0" + "name": "SortNumbers:1", + "sat": "def sat(ans: str, s=\"nine two four nine zero six six eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"nine two four nine zero six six eight\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 }, { - "name": "Frac_7", - "sat": "def sat(x: float, v=88.37052850394048):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=88.37052850394048):\n return v % 1.0" + "name": "SortNumbers:2", + "sat": "def sat(ans: str, s=\"nine six two\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"nine six two\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 }, { - "name": "Frac_8", - "sat": "def sat(x: float, v=-31.50107826533474):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=-31.50107826533474):\n return v % 1.0" + "name": "SortNumbers:3", + "sat": "def sat(ans: str, s=\"five nine four eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"five nine four eight\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 }, { - "name": "Frac_9", - "sat": "def sat(x: float, v=43.984488185382816):\n \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"\n return 0 <= x < 1 and (v - x).is_integer()", - "sols": [ - "def sol(v=43.984488185382816):\n return v % 1.0" + "name": "SortNumbers:4", + "sat": "def sat(ans: str, s=\"seven eight seven zero zero five one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"seven eight seven zero zero five one\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 }, { - "name": "FirstNegCumulative_0", - "sat": "def sat(n: int, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "FindClosePair:0", + "sat": "def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 }, { - "name": "FirstNegCumulative_1", - "sat": "def sat(n: int, balances=[-1500518832, 928669978, -8834236111, 5315367227, 9459906565]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[-1500518832, 928669978, -8834236111, 5315367227, 9459906565]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "FindClosePair:1", + "sat": "def sat(inds: List[int], nums=[-7.587461542549912, 0.7494004368541578, 2.0142388071411013, -1.552072793834526, 0.44845194836415025]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-7.587461542549912, 0.7494004368541578, 2.0142388071411013, -1.552072793834526, 0.44845194836415025]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 }, { - "name": "FirstNegCumulative_2", - "sat": "def sat(n: int, balances=[-922459571, 980368404, 2797206106, -8743339029, 1937237746]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[-922459571, 980368404, 2797206106, -8743339029, 1937237746]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "FindClosePair:2", + "sat": "def sat(inds: List[int], nums=[-5.253924550449174, 7.798134742325132, 2.84274998450722, -5.355403889716619, -8.14069894708204, 6.276599656475899]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-5.253924550449174, 7.798134742325132, 2.84274998450722, -5.355403889716619, -8.14069894708204, 6.276599656475899]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 }, { - "name": "FirstNegCumulative_3", - "sat": "def sat(n: int, balances=[448159544, -6977868670, 3754789071, -9574236851, 5272792525, 5148246274]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[448159544, -6977868670, 3754789071, -9574236851, 5272792525, 5148246274]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "FindClosePair:3", + "sat": "def sat(inds: List[int], nums=[8.647950767409466, 6.069423836495417, 8.647950767409466, -4.483139827348948, 7.822521892934297, 6.339621174459673]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[8.647950767409466, 6.069423836495417, 8.647950767409466, -4.483139827348948, 7.822521892934297, 6.339621174459673]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 }, { - "name": "FirstNegCumulative_4", - "sat": "def sat(n: int, balances=[1626500291, 1679296308, -5081016101]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[1626500291, 1679296308, -5081016101]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "FindClosePair:4", + "sat": "def sat(inds: List[int], nums=[-2.4491102095531385, -2.4896924424294635]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-2.4491102095531385, -2.4896924424294635]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 }, { - "name": "FirstNegCumulative_5", - "sat": "def sat(n: int, balances=[-4649290429, -8794342387, 9104512615, 8943500651, -9334877156, -8549860005, 7833776489]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[-4649290429, -8794342387, 9104512615, 8943500651, -9334877156, -8549860005, 7833776489]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "Rescale:0", + "sat": "def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[13.0, 17.0, 17.0, 15.5, 2.94]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 }, { - "name": "FirstNegCumulative_6", - "sat": "def sat(n: int, balances=[7722681537, 535145192, -1822889532, 1811860043, -7700960933, -1026876, -8774841983]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[7722681537, 535145192, -1822889532, 1811860043, -7700960933, -1026876, -8774841983]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "Rescale:1", + "sat": "def sat(ans: List[float], nums=[939.7119884829771, 939.7119884829771, 939.7119884829771]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[939.7119884829771, 939.7119884829771, 939.7119884829771]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 }, { - "name": "FirstNegCumulative_7", - "sat": "def sat(n: int, balances=[-3123263915, 8869957317, -7753864907, 4997669326, -8808060783]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[-3123263915, 8869957317, -7753864907, 4997669326, -8808060783]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "Rescale:2", + "sat": "def sat(ans: List[float], nums=[0.4458061970026967, -3.9939008694208376, -1.0757147773525169, 0.3895998276095692, 2.0191942234485825, -0.23989163788911685, -0.003822778565885754, -0.8237835423706446, -0.08413275419390705]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[0.4458061970026967, -3.9939008694208376, -1.0757147773525169, 0.3895998276095692, 2.0191942234485825, -0.23989163788911685, -0.003822778565885754, -0.8237835423706446, -0.08413275419390705]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 }, { - "name": "FirstNegCumulative_8", - "sat": "def sat(n: int, balances=[1847102451, -3353379777, -6456882318, 4952475033, -8953446440, 3180335566, -3990317955, 9933690368]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[1847102451, -3353379777, -6456882318, 4952475033, -8953446440, 3180335566, -3990317955, 9933690368]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "Rescale:3", + "sat": "def sat(ans: List[float], nums=[1.7162662285160908, -0.5573868669921508, -11.304736303883987, 1.166009156041828, 2.1833750395727782, 4.274594378665487, -0.45875107135742743, 0.0046661656727550556, 0.8537569786748028]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[1.7162662285160908, -0.5573868669921508, -11.304736303883987, 1.166009156041828, 2.1833750395727782, 4.274594378665487, -0.45875107135742743, 0.0046661656727550556, 0.8537569786748028]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 }, { - "name": "FirstNegCumulative_9", - "sat": "def sat(n: int, balances=[-3749703246]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n -89\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total == n", - "sols": [ - "def sol(balances=[-3749703246]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return total\n assert False, \"should not reach here\"" + "name": "Rescale:4", + "sat": "def sat(ans: List[float], nums=[23.976551109194304, 1.4655002766247416]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[23.976551109194304, 1.4655002766247416]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_0", - "sat": "def sat(neg: bool, balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[2, 7, -2, 4, 3, -15, 10, -45, 3]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "FilterInts:0", + "sat": "def sat(candidates: List[str], int_indices=[2, 4, 7, 9, 101]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[2, 4, 7, 9, 101]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_1", - "sat": "def sat(neg: bool, balances=[-5726556876, 9548457927, 4941492228, -8994209538, -506068440, -2469653530, -7098230219, -6476076828]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[-5726556876, 9548457927, 4941492228, -8994209538, -506068440, -2469653530, -7098230219, -6476076828]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "FilterInts:1", + "sat": "def sat(candidates: List[str], int_indices=[80, 17, 74]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[80, 17, 74]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_2", - "sat": "def sat(neg: bool, balances=[2523951572, 6693551682, -7050983998, -4495920585, 317504362, 2624005806, 1194371655, 2703815919, 7744962937]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[2523951572, 6693551682, -7050983998, -4495920585, 317504362, 2624005806, 1194371655, 2703815919, 7744962937]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "FilterInts:2", + "sat": "def sat(candidates: List[str], int_indices=[56, 37, 17, 83, 35, 22, 4, 78, 79]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[56, 37, 17, 83, 35, 22, 4, 78, 79]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_3", - "sat": "def sat(neg: bool, balances=[-1878150679, -7949120352, 6516381435, 5264967595, 4238494390, -836898764, -375886643]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[-1878150679, -7949120352, 6516381435, 5264967595, 4238494390, -836898764, -375886643]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "FilterInts:3", + "sat": "def sat(candidates: List[str], int_indices=[25, 65]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[25, 65]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_4", - "sat": "def sat(neg: bool, balances=[8512974517, -9578250052, -9393561543]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[8512974517, -9578250052, -9393561543]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "FilterInts:4", + "sat": "def sat(candidates: List[str], int_indices=[92, 74, 83, 90, 9, 76, 66, 0]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[92, 74, 83, 90, 9, 76, 66, 0]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_5", - "sat": "def sat(neg: bool, balances=[819198943, -8374129350, -340163677, 9027664863, 9887500029, -5880699598, -9800801952]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[819198943, -8374129350, -340163677, 9027664863, 9887500029, -5880699598, -9800801952]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "StrLength:0", + "sat": "def sat(lengths: List[int], strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']):\n for length, s in zip(lengths, strs):\n try:\n s[length]\n return False\n except IndexError:\n s[length - 1]\n return len(lengths) == len(strs)", + "ans_type": "List[int]", + "sol_header": "def sol(strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']):", + "sol_docstring": " \"\"\"\n Find the lengths of a list of non-empty strings\n\n Sample input\n ---\n [\"foo\", \"bars\"]\n\n Sample output\n ---\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " return [len(s) for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", + "weight": 1.0 }, { - "name": "NegCumulative_Trivial_6", - "sat": "def sat(neg: bool, balances=[-9105594770, 1654568161]):\n \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals,\n determine if the cumulative sum is negative.\n\n Sample Input:\n [12, -5, 3, -99, 14, 88, -99]\n\n Sample Output:\n True\n \"\"\"\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return neg == True\n return neg == False", - "sols": [ - "def sol(balances=[-9105594770, 1654568161]):\n total = 0\n for b in balances:\n total += b\n if total < 0:\n return True\n return False" + "name": "StrLength:1", + "sat": "def sat(lengths: List[int], strs=['=i', '&?Jq 2aNHt', '?uCcQht', 'e>8=4jZNfhZl3&Mko-MfWd<^QR Vf7:2M', ']Y,G2U4ur-7X,T@(Gv$:Y0^C,-$+xM9$X2,*90|', '+>&?Qa%yLWZA2nBDQ8i)zvVWT', 'Ly+NcKgOvg3J)', 's$0^cow)Q917uY', 'ZSA$sIKe|pz@|[8=4jZNfhZl3&Mko-MfWd<^QR Vf7:2M', ']Y,G2U4ur-7X,T@(Gv$:Y0^C,-$+xM9$X2,*90|', '+>&?Qa%yLWZA2nBDQ8i)zvVWT', 'Ly+NcKgOvg3J)', 's$0^cow)Q917uY', 'ZSA$sIKe|pz@|[/%4=%?ry(+2', '&.Qf?cuJI%m.>pBZY', 'FUeoE;h(#,f5[%xwK9@EU', '2NNz-,|C*]Vu9E7|!7mA+ oM9/%4=%?ry(+2', '&.Qf?cuJI%m.>pBZY', 'FUeoE;h(#,f5[%xwK9@EU', '2NNz-,|C*]Vu9E7|!7mA+ oM9Y(l%O2ub5ciSw-]geHu6NgF9au)r', 'ED!Bz=4nF6 z^kMW-3-&Y(l%O2ub5ciSw-]geHu6NgF9au)r', 'ED!Bz=4nF6 z^kMW-3-&p]exH|sgXQt', 'mwoa[nS-[%R(rf5!)9o.M[', '23Q0Sugd(RKZ+GuLu', 'x^VP2ZX$8', 'q7(GrHGkG6er!7hX+ZeKolCgdlqI0(*um']):\n for length, s in zip(lengths, strs):\n try:\n s[length]\n return False\n except IndexError:\n s[length - 1]\n return len(lengths) == len(strs)", + "ans_type": "List[int]", + "sol_header": "def sol(strs=['g', ';TWy9!004X#d7!0p ', 'eaX%:#7S2IIIUe&#r3=EB1;5K)3j;1Vn', ']cz!vZ]Wq&O]sMR8D', ')o=#sAp-c8:SM&.yRBpCMmS)-', 'Ql d.i(UA/|sFqHQ/c3M>p]exH|sgXQt', 'mwoa[nS-[%R(rf5!)9o.M[', '23Q0Sugd(RKZ+GuLu', 'x^VP2ZX$8', 'q7(GrHGkG6er!7hX+ZeKolCgdlqI0(*um']):", + "sol_docstring": " \"\"\"\n Find the lengths of a list of non-empty strings\n\n Sample input\n ---\n [\"foo\", \"bars\"]\n\n Sample output\n ---\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " return [len(s) for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3\n(see also FirstNegCumulative above which is not as trivial)\nThis version is a more direct translation of the problem but it can of course\nbe solved trivially just by trying both neg=True and neg=False", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_0", - "sat": "def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "LargestDivisor:0", + "sat": "def sat(d: int, n=123456):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=123456):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_1", - "sat": "def sat(x: float, nums=[-4800207686, 8371827478, -2589023797, -7433412105, -6597577390, -3672395364, 4220954653, -4921325759]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[-4800207686, 8371827478, -2589023797, -7433412105, -6597577390, -3672395364, 4220954653, -4921325759]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "LargestDivisor:1", + "sat": "def sat(d: int, n=17836):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=17836):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_2", - "sat": "def sat(x: float, nums=[-6451896480, 1412633776, -5942452034]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[-6451896480, 1412633776, -5942452034]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "LargestDivisor:2", + "sat": "def sat(d: int, n=71793):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=71793):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_3", - "sat": "def sat(x: float, nums=[8987893300, -829914892, 9470797463, 7249764363, -1364686955, 7237801639, 9599744595, 8505349699, -5635739184]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[8987893300, -829914892, 9470797463, 7249764363, -1364686955, 7237801639, 9599744595, 8505349699, -5635739184]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "LargestDivisor:3", + "sat": "def sat(d: int, n=15466):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=15466):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_4", - "sat": "def sat(x: float, nums=[7654638423, 4318192515, 747918779, 5017757184, -8266662968, -6056081845, 2102077564, -5930492836, 6820929042, 9536461987]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[7654638423, 4318192515, 747918779, 5017757184, -8266662968, -6056081845, 2102077564, -5930492836, 6820929042, 9536461987]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "LargestDivisor:4", + "sat": "def sat(d: int, n=57567):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=57567):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_5", - "sat": "def sat(x: float, nums=[8278843947, -924991709, -5422865408, -8116212764, 6689640576, 5117206777]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[8278843947, -924991709, -5422865408, -8116212764, 6689640576, 5117206777]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "PrimeFactorization:0", + "sat": "def sat(factors: List[int], n=123456, num_factors=8):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=123456, num_factors=8):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_6", - "sat": "def sat(x: float, nums=[8689960251]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[8689960251]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "PrimeFactorization:1", + "sat": "def sat(factors: List[int], n=1339030, num_factors=6):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=1339030, num_factors=6):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_7", - "sat": "def sat(x: float, nums=[-4016405599, 9692018006, -418854640, -2637200183]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[-4016405599, 9692018006, -418854640, -2637200183]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "PrimeFactorization:2", + "sat": "def sat(factors: List[int], n=141752, num_factors=6):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=141752, num_factors=6):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_8", - "sat": "def sat(x: float, nums=[-2336285685, -5415733392, 360863620, -9036443154, -3810903569]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[-2336285685, -5415733392, 360863620, -9036443154, -3810903569]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "PrimeFactorization:3", + "sat": "def sat(factors: List[int], n=33088, num_factors=8):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=33088, num_factors=8):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 }, { - "name": "MinSquaredDeviation_9", - "sat": "def sat(x: float, nums=[-211025577]):\n \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"\n return sum((n - x) ** 2 for n in nums) <= sum((m - n) ** 2 for m in nums for n in nums) * 0.501 / len(nums)", - "sols": [ - "def sol(nums=[-211025577]):\n return sum(nums) / len(nums) # mean minimizes mean squared deviation" + "name": "PrimeFactorization:4", + "sat": "def sat(factors: List[int], n=2375171125400, num_factors=12):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=2375171125400, num_factors=12):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" ], - "module": "human_eval", - "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 }, { - "name": "Intersperse_0", - "sat": "def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[12, 23, -2, 5, 0], sep=4):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "Dedup:0", + "sat": "def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 }, { - "name": "Intersperse_1", - "sat": "def sat(li: List[int], nums: List[int]=[], sep=23):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[], sep=23):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "Dedup:1", + "sat": "def sat(ans: List[int], li=[3, 3, 7, 9, 7, 2, 9, 4, 1]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[3, 3, 7, 9, 7, 2, 9, 4, 1]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 }, { - "name": "Intersperse_2", - "sat": "def sat(li: List[int], nums=[90, 23, 0, 0, 36, 61, 73], sep=14):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[90, 23, 0, 0, 36, 61, 73], sep=14):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "Dedup:2", + "sat": "def sat(ans: List[int], li=[3, 9, 8, 9, 3, 5, 1, 3, 5]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[3, 9, 8, 9, 3, 5, 1, 3, 5]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 }, { - "name": "Intersperse_3", - "sat": "def sat(li: List[int], nums=[41, 60, 18, 34, 31], sep=2):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[41, 60, 18, 34, 31], sep=2):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "Dedup:3", + "sat": "def sat(ans: List[int], li=[3, 8, 2, 1, 1, 7, 7, 7, 5, 5, 5, 9, 3, 7, 7]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[3, 8, 2, 1, 1, 7, 7, 7, 5, 5, 5, 9, 3, 7, 7]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 }, { - "name": "Intersperse_4", - "sat": "def sat(li: List[int], nums=[39, 94, 99, 46, 93], sep=25):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[39, 94, 99, 46, 93], sep=25):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "Dedup:4", + "sat": "def sat(ans: List[int], li=[0, 3, 3, 2, 7, 0, 0, 6, 2, 4, 4, 5]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[0, 3, 3, 2, 7, 0, 0, 6, 2, 4, 4, 5]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 }, { - "name": "Intersperse_5", - "sat": "def sat(li: List[int], nums=[10, 0, 18, 39, 23, 43, 2, 1, 32], sep=43):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[10, 0, 18, 39, 23, 43, 2, 1, 32], sep=43):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "FlipCase:0", + "sat": "def sat(ans: str, s=\"FlIp ME!\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"FlIp ME!\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 }, { - "name": "Intersperse_6", - "sat": "def sat(li: List[int], nums: List[int]=[], sep=15):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[], sep=15):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "FlipCase:1", + "sat": "def sat(ans: str, s=\"mKC(K2.a!Z|>sv3izC3!\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"mKC(K2.a!Z|>sv3izC3!\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 }, { - "name": "Intersperse_7", - "sat": "def sat(li: List[int], nums=[0, 48, 23, 5], sep=84):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[0, 48, 23, 5], sep=84):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "FlipCase:2", + "sat": "def sat(ans: str, s=\"K a&3 tE 1tSG B3v3y(\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"K a&3 tE 1tSG B3v3y(\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 }, { - "name": "Intersperse_8", - "sat": "def sat(li: List[int], nums=[55], sep=89):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[55], sep=89):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "FlipCase:3", + "sat": "def sat(ans: str, s=\"Sb31E#e<@3u\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"Sb31E#e<@3u\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 }, { - "name": "Intersperse_9", - "sat": "def sat(li: List[int], nums=[14, 45, 87, 21, 33], sep=15):\n \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"\n assert len(li) == max(0, len(nums) * 2 - 1)\n for i, n in enumerate(nums):\n assert li[2 * i] == n\n if i > 0:\n assert li[2 * i - 1] == sep\n return True", - "sols": [ - "def sol(nums=[14, 45, 87, 21, 33], sep=15):\n ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + "name": "FlipCase:4", + "sat": "def sat(ans: str, s=\"q Y*.zv? !3B3::/3%F3\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"q Y*.zv? !3B3::/3%F3\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5\n\nThe one-liner version is `li[::2] == nums and li[1::2] == [sep] * (len(li) - 1)`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 }, { - "name": "DeepestParens_0", - "sat": "def sat(depths: List[int], parens=\"() (()) ((()()())) (())\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"() (()) ((()()())) (())\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "CatStrings:0", + "sat": "def sat(cat: str, strings=['Will', 'i', 'am', 'Now', 'here']):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=['Will', 'i', 'am', 'Now', 'here']):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 }, { - "name": "DeepestParens_1", - "sat": "def sat(depths: List[int], parens=\"\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "CatStrings:1", + "sat": "def sat(cat: str, strings=['dufe', 'keret', 'kothihisedatextumuva', 'pe', 'sicelynyzysukydew', 'zu', 'kathubaki']):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=['dufe', 'keret', 'kothihisedatextumuva', 'pe', 'sicelynyzysukydew', 'zu', 'kathubaki']):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 }, { - "name": "DeepestParens_2", - "sat": "def sat(depths: List[int], parens=\"(()) (((()(((()())()())))))(())()\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"(()) (((()(((()())()())))))(())()\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "CatStrings:2", + "sat": "def sat(cat: str, strings=[]):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=[]):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 }, { - "name": "DeepestParens_3", - "sat": "def sat(depths: List[int], parens=\"(()) ()()(()())() () ()(())() ()((()))\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"(()) ()()(()())() () ()(())() ()((()))\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "CatStrings:3", + "sat": "def sat(cat: str, strings=['c', 'vawumich', 'textucagidyhikomuro', 'wuchiquusojahoz', 'l']):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=['c', 'vawumich', 'textucagidyhikomuro', 'wuchiquusojahoz', 'l']):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 }, { - "name": "DeepestParens_4", - "sat": "def sat(depths: List[int], parens=\"()()(())()(())\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"()()(())()(())\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "CatStrings:4", + "sat": "def sat(cat: str, strings=['s', 'nutext', 'quoxezenukowyho', 'botidyhu', 'kicethytextithybaqu']):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=['s', 'nutext', 'quoxezenukowyho', 'botidyhu', 'kicethytextithybaqu']):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 }, { - "name": "DeepestParens_5", - "sat": "def sat(depths: List[int], parens=\"()() ()()(()(()(())))()() ()()((())())((()))(())()()(()) ()()\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"()() ()()(()(()(())))()() ()()((())())((()))(())()()(()) ()()\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "FindExtensions:0", + "sat": "def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 }, { - "name": "DeepestParens_6", - "sat": "def sat(depths: List[int], parens=\"() ()(())((()()()())) ()()() ()(()())()()()(()((()))(((())(()))()))()()\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"() ()(())((()()()())) ()()() ()(()())()()()(()((()))(((())(()))()))()()\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "FindExtensions:1", + "sat": "def sat(extensions: List[str], strings=['cot', 'z'], prefix=\"ca\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cot', 'z'], prefix=\"ca\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 }, { - "name": "DeepestParens_7", - "sat": "def sat(depths: List[int], parens=\"()(((((()()()())))()(()()(()()))))() (())\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"()(((((()()()())))()(()()(()()))))() (())\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "FindExtensions:2", + "sat": "def sat(extensions: List[str], strings=['jof', 'thibi'], prefix=\"le\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['jof', 'thibi'], prefix=\"le\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 }, { - "name": "DeepestParens_8", - "sat": "def sat(depths: List[int], parens=\"(())(())()(()(()))(())(()) ()()(()()(())()()(()))()(())()()()()(())\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"(())(())()(()(()))(())(()) ()()(()()(())()()(()))()(())()()()()(())\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "FindExtensions:3", + "sat": "def sat(extensions: List[str], strings=['t'], prefix=\"t\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['t'], prefix=\"t\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 }, { - "name": "DeepestParens_9", - "sat": "def sat(depths: List[int], parens=\"()((((()((())(())(())))())((()))))()() ()()((()(())))(()())((()))()\"):\n \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", - "sols": [ - "def sol(parens=\"()((((()((())(())(())))())((()))))()() ()()((()(())))(()())((()))()\"):\n def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + "name": "FindExtensions:4", + "sat": "def sat(extensions: List[str], strings=['cpud', 'cpal', 'cv', 'cchut'], prefix=\"c\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cpud', 'cpal', 'cv', 'cchut'], prefix=\"c\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 }, { - "name": "FindContainers_0", - "sat": "def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):\n return [s for s in strings if substring in s]" + "name": "FindPositives:0", + "sat": "def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 }, { - "name": "FindContainers_1", - "sat": "def sat(containers: List[str], strings=['ty', 'jy', 'jsesnicy'], substring=\"ses\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['ty', 'jy', 'jsesnicy'], substring=\"ses\"):\n return [s for s in strings if substring in s]" + "name": "FindPositives:1", + "sat": "def sat(positives: List[int], nums=[53, 33, 73, 47, 35, 24, 56, 89, 85]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[53, 33, 73, 47, 35, 24, 56, 89, 85]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 }, { - "name": "FindContainers_2", - "sat": "def sat(containers: List[str], strings=['rgyjo', 'tipu', 'mulut', 'wutgypepu'], substring=\"gy\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['rgyjo', 'tipu', 'mulut', 'wutgypepu'], substring=\"gy\"):\n return [s for s in strings if substring in s]" + "name": "FindPositives:2", + "sat": "def sat(positives: List[int], nums=[61, -64, -11, -3, -96, -69, -18, -99, 87]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[61, -64, -11, -3, -96, -69, -18, -99, 87]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 }, { - "name": "FindContainers_3", - "sat": "def sat(containers: List[str], strings: List[str]=[], substring=\"ve\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=[], substring=\"ve\"):\n return [s for s in strings if substring in s]" + "name": "FindPositives:3", + "sat": "def sat(positives: List[int], nums=[62, 3, -84]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[62, 3, -84]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 }, { - "name": "FindContainers_4", - "sat": "def sat(containers: List[str], strings=['te', 'dmmo', ''], substring=\"m\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['te', 'dmmo', ''], substring=\"m\"):\n return [s for s in strings if substring in s]" + "name": "FindPositives:4", + "sat": "def sat(positives: List[int], nums=[]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 }, { - "name": "FindContainers_5", - "sat": "def sat(containers: List[str], strings: List[str]=[], substring=\"n\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=[], substring=\"n\"):\n return [s for s in strings if substring in s]" + "name": "FermatComposites:0", + "sat": "def sat(certificates: List[int], nums=[1449, 14, 21, 105, 217]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1449, 14, 21, 105, 217]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 }, { - "name": "FindContainers_6", - "sat": "def sat(containers: List[str], strings=['', 'josevg', 'hose'], substring=\"g\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['', 'josevg', 'hose'], substring=\"g\"):\n return [s for s in strings if substring in s]" + "name": "FermatComposites:1", + "sat": "def sat(certificates: List[int], nums=[2299290630, 2051931473, 1592080723, 533977507, 6381433197, 6645010323, 5590359939, 1543343895, 1032597423]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2299290630, 2051931473, 1592080723, 533977507, 6381433197, 6645010323, 5590359939, 1543343895, 1032597423]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 }, { - "name": "FindContainers_7", - "sat": "def sat(containers: List[str], strings: List[str]=[], substring=\"ka\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=[], substring=\"ka\"):\n return [s for s in strings if substring in s]" + "name": "FermatComposites:2", + "sat": "def sat(certificates: List[int], nums=[962036141, 941419353, 5954955179, 5140095171, 3027040707, 6069862645, 591197645, 2485033263]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[962036141, 941419353, 5954955179, 5140095171, 3027040707, 6069862645, 591197645, 2485033263]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 }, { - "name": "FindContainers_8", - "sat": "def sat(containers: List[str], strings: List[str]=[], substring=\"bo\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=[], substring=\"bo\"):\n return [s for s in strings if substring in s]" + "name": "FermatComposites:3", + "sat": "def sat(certificates: List[int], nums=[99210055, 4171577125, 459354525, 1534026075, 4255533095, 2441396441, 155962261]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[99210055, 4171577125, 459354525, 1534026075, 4255533095, 2441396441, 155962261]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 }, { - "name": "FindContainers_9", - "sat": "def sat(containers: List[str], strings=['cy', 'vyju'], substring=\"\"):\n \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", - "sols": [ - "def sol(strings=['cy', 'vyju'], substring=\"\"):\n return [s for s in strings if substring in s]" + "name": "FermatComposites:4", + "sat": "def sat(certificates: List[int], nums=[2629304451, 4885026075, 2283948525, 4145214425]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2629304451, 4885026075, 2283948525, 4145214425]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 }, { - "name": "SumProduct_0", - "sat": "def sat(nums: List[int], tot=14, prod=99):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=14, prod=99):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "OddDegreePolynomialRoot:0", + "sat": "def sat(root: float, coeffs=[1, 2, 3, 17]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[1, 2, 3, 17]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 }, { - "name": "SumProduct_1", - "sat": "def sat(nums: List[int], tot=-81, prod=13):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=-81, prod=13):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "OddDegreePolynomialRoot:1", + "sat": "def sat(root: float, coeffs=[-1, -5, 4, -8, 3, -1, 0, 7]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[-1, -5, 4, -8, 3, -1, 0, 7]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 }, { - "name": "SumProduct_2", - "sat": "def sat(nums: List[int], tot=96, prod=-44):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=96, prod=-44):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "OddDegreePolynomialRoot:2", + "sat": "def sat(root: float, coeffs=[7, 1]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[7, 1]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 }, { - "name": "SumProduct_3", - "sat": "def sat(nums: List[int], tot=86, prod=24):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=86, prod=24):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "OddDegreePolynomialRoot:3", + "sat": "def sat(root: float, coeffs=[1, 4, 1, -7, 5, 0, -10, -9, 4, 9]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[1, 4, 1, -7, 5, 0, -10, -9, 4, 9]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 }, { - "name": "SumProduct_4", - "sat": "def sat(nums: List[int], tot=-16, prod=3):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=-16, prod=3):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "OddDegreePolynomialRoot:4", + "sat": "def sat(root: float, coeffs=[7, 8]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[7, 8]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 }, { - "name": "SumProduct_5", - "sat": "def sat(nums: List[int], tot=16, prod=27):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=16, prod=27):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "TwoThirdsSorted:0", + "sat": "def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 }, { - "name": "SumProduct_6", - "sat": "def sat(nums: List[int], tot=35, prod=-43):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=35, prod=-43):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "TwoThirdsSorted:1", + "sat": "def sat(li: List[int], orig=[-10, 9, 0, -6, 0, -7, -2, 4, 8, 2, 3, -9, -8, 9, -4, -4]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-10, 9, 0, -6, 0, -7, -2, 4, 8, 2, 3, -9, -8, 9, -4, -4]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 }, { - "name": "SumProduct_7", - "sat": "def sat(nums: List[int], tot=-64, prod=-1):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=-64, prod=-1):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "TwoThirdsSorted:2", + "sat": "def sat(li: List[int], orig=[0, 7, -3, -3, 2, 2, 5, -9, -9]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[0, 7, -3, -3, 2, 2, 5, -9, -9]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 }, { - "name": "SumProduct_8", - "sat": "def sat(nums: List[int], tot=83, prod=-48):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=83, prod=-48):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "TwoThirdsSorted:3", + "sat": "def sat(li: List[int], orig=[-1, -1, 0, 6, 3, -1, 4, -1, 1, 9, -4, -1, 6, 4, -7, -4, 1]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-1, -1, 0, 6, 3, -1, 4, -1, 1, 9, -4, -1, 6, 4, -7, -4, 1]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 }, { - "name": "SumProduct_9", - "sat": "def sat(nums: List[int], tot=39, prod=-73):\n \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", - "sols": [ - "def sol(tot=39, prod=-73):\n ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + "name": "TwoThirdsSorted:4", + "sat": "def sat(li: List[int], orig=[]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_0", - "sat": "def sat(sum_prod: List[int], nums=[1, 3, 2, -6, 19]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[1, 3, 2, -6, 19]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "UniqueSorted:0", + "sat": "def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_1", - "sat": "def sat(sum_prod: List[int], nums=[55, -65]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[55, -65]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "UniqueSorted:1", + "sat": "def sat(li: List[int], orig=[-9, 1, -5, 6, -1, 3, 5, 8, -10, -2, 3, -9, -10]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-9, 1, -5, 6, -1, 3, 5, 8, -10, -2, 3, -9, -10]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_2", - "sat": "def sat(sum_prod: List[int], nums=[-31]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-31]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "UniqueSorted:2", + "sat": "def sat(li: List[int], orig=[-3, 7, 9, -10, -10, 5, 2, 8]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-3, 7, 9, -10, -10, 5, 2, 8]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_3", - "sat": "def sat(sum_prod: List[int], nums=[29]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[29]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "UniqueSorted:3", + "sat": "def sat(li: List[int], orig=[-6]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-6]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_4", - "sat": "def sat(sum_prod: List[int], nums=[-78, 20]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-78, 20]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "UniqueSorted:4", + "sat": "def sat(li: List[int], orig=[1, -5, 6, 2, -7, -6, 5, -5, 3, 7, 4, -10, -2, 3, 7, 9, -3, 8, 7]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, -5, 6, 2, -7, -6, 5, -5, 3, 7, 4, -10, -2, 3, 7, 9, -3, 8, 7]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_5", - "sat": "def sat(sum_prod: List[int], nums=[-26]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-26]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "MaxInt:0", + "sat": "def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_6", - "sat": "def sat(sum_prod: List[int], nums=[-68, 0]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-68, 0]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "MaxInt:1", + "sat": "def sat(m: int, hello=[2, 2, 2, -4, -2, -5, -4, 0, -5, -10, 1, -1, -1, 2]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[2, 2, 2, -4, -2, -5, -4, 0, -5, -10, 1, -1, -1, 2]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_7", - "sat": "def sat(sum_prod: List[int], nums=[-33, 58, -22]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-33, 58, -22]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "MaxInt:2", + "sat": "def sat(m: int, hello=[8, -1, -8, 1, -10]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[8, -1, -8, 1, -10]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_8", - "sat": "def sat(sum_prod: List[int], nums=[-63, -12]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[-63, -12]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "MaxInt:3", + "sat": "def sat(m: int, hello=[-8, 1, 9, 4, 4, 0, -1, 8, 2, 3, 5, 9, 2, -1, 9]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[-8, 1, 9, 4, 4, 0, -1, 8, 2, 3, 5, 9, 2, -1, 9]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 }, { - "name": "SumProduct_Trivial_9", - "sat": "def sat(sum_prod: List[int], nums=[81]):\n \"\"\"\n Find the sum and product of a list of numbers.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [12, 32]\n \"\"\"\n p = 1\n for n in nums:\n p *= n\n return sum_prod == [sum(nums), p]", - "sols": [ - "def sol(nums=[81]):\n p = 1\n for n in nums:\n p *= n\n return [sum(nums), p]" + "name": "MaxInt:4", + "sat": "def sat(m: int, hello=[5, 2, -10, -2, -4, 2, 3, -5, 9, 0]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[5, 2, -10, -2, -4, 2, 3, -5, 9, 0]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 }, { - "name": "RollingMax_0", - "sat": "def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[1, 4, 3, -6, 19]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[1, 4, 3, -6, 19]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "SevenElevenThirteen:0", + "sat": "def sat(li: List[List[int]], n=19723, lower=1000):\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=19723, lower=1000):", + "sol_docstring": " \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", + "weight": 1.0 }, { - "name": "RollingMax_1", - "sat": "def sat(maxes: List[int], nums=[-15, -6]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[-15, -6]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[-15, -6]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "SevenElevenThirteen:1", + "sat": "def sat(li: List[List[int]], n=5, lower=0):\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=5, lower=0):", + "sol_docstring": " \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", + "weight": 1.0 }, { - "name": "RollingMax_2", - "sat": "def sat(maxes: List[int], nums: List[int]=[]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "SevenElevenThirteen:2", + "sat": "def sat(li: List[List[int]], n=8, lower=0):\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=8, lower=0):", + "sol_docstring": " \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", + "weight": 1.0 }, { - "name": "RollingMax_3", - "sat": "def sat(maxes: List[int], nums=[-100, 14, -45, 92, 36, -68, -40]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[-100, 14, -45, 92, 36, -68, -40]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[-100, 14, -45, 92, 36, -68, -40]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "SevenElevenThirteen:3", + "sat": "def sat(li: List[List[int]], n=11, lower=0):\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=11, lower=0):", + "sol_docstring": " \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", + "weight": 1.0 }, { - "name": "RollingMax_4", - "sat": "def sat(maxes: List[int], nums=[23, -34, 96]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[23, -34, 96]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[23, -34, 96]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "HalfSorted:0", + "sat": "def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 }, { - "name": "RollingMax_5", - "sat": "def sat(maxes: List[int], nums=[-43, -97, 47, -57, 36, 18, 63]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[-43, -97, 47, -57, 36, 18, 63]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[-43, -97, 47, -57, 36, 18, 63]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "HalfSorted:1", + "sat": "def sat(li: List[int], orig=[-1, -9, 7, 8, -8, 2, -7]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-1, -9, 7, 8, -8, 2, -7]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 }, { - "name": "RollingMax_6", - "sat": "def sat(maxes: List[int], nums=[75, -70, -21, 79, 4]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[75, -70, -21, 79, 4]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[75, -70, -21, 79, 4]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "HalfSorted:2", + "sat": "def sat(li: List[int], orig=[4, -3, -8]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[4, -3, -8]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 }, { - "name": "RollingMax_7", - "sat": "def sat(maxes: List[int], nums=[-83, -60, -63, -19, 66, 43, -27]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[-83, -60, -63, -19, 66, 43, -27]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[-83, -60, -63, -19, 66, 43, -27]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "HalfSorted:3", + "sat": "def sat(li: List[int], orig=[3, 6, -7, 1, 2, -10, 6, -8, -9, -9, 6, -7, 7, -6, 1, 4, -8, -1, 8]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[3, 6, -7, 1, 2, -10, 6, -8, -9, -9, 6, -7, 7, -6, 1, 4, -8, -1, 8]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 }, { - "name": "RollingMax_8", - "sat": "def sat(maxes: List[int], nums=[30, 84, 70]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[30, 84, 70]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[30, 84, 70]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "HalfSorted:4", + "sat": "def sat(li: List[int], orig=[-7, 6, 8, 8, -3, -5, -6, -5, 6, 7, 5, 7, -9, 9, -7, 4, -8, 8, -9]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[-7, 6, 8, 8, -3, -5, -6, -5, 6, 7, 5, 7, -9, 9, -7, 4, -8, 8, -9]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 }, { - "name": "RollingMax_9", - "sat": "def sat(maxes: List[int], nums=[9, 52, -2, -76, 53, 39, -70, 30]):\n \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", - "sols": [ - "def sol(nums=[9, 52, -2, -76, 53, 39, -70, 30]):\n return [max(nums[:i]) for i in range(1, len(nums) + 1)]", - "def sol(nums=[9, 52, -2, -76, 53, 39, -70, 30]):\n ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + "name": "ThreeCycle:0", + "sat": "def sat(s: str, target=\"Hello world\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"Hello world\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_0", - "sat": "def sat(ans: str, s=\"so easy\", length=13):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"so easy\", length=13):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "ThreeCycle:1", + "sat": "def sat(s: str, target=\"rugetytextirocuterup\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"rugetytextirocuterup\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_1", - "sat": "def sat(ans: str, s=\"bababab\", length=11):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"bababab\", length=11):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "ThreeCycle:2", + "sat": "def sat(s: str, target=\"torusajidapaficiretoh\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"torusajidapaficiretoh\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_2", - "sat": "def sat(ans: str, s=\"abab\", length=22):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"abab\", length=22):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "ThreeCycle:3", + "sat": "def sat(s: str, target=\"quitextaf\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"quitextaf\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_3", - "sat": "def sat(ans: str, s=\"b\", length=8):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"b\", length=8):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "ThreeCycle:4", + "sat": "def sat(s: str, target=\"thoqui\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"thoqui\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_4", - "sat": "def sat(ans: str, s=\"aabb\", length=6):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"aabb\", length=6):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "PrimeFib:0", + "sat": "def sat(n: int, lower=123456):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=123456):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_5", - "sat": "def sat(ans: str, s=\"b\", length=17):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"b\", length=17):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "PrimeFib:1", + "sat": "def sat(n: int, lower=3):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=3):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_6", - "sat": "def sat(ans: str, s=\"baaabaaa\", length=14):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"baaabaaa\", length=14):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "PrimeFib:2", + "sat": "def sat(n: int, lower=458):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=458):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_7", - "sat": "def sat(ans: str, s=\"bb\", length=5):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"bb\", length=5):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "PrimeFib:3", + "sat": "def sat(n: int, lower=384):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=384):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_8", - "sat": "def sat(ans: str, s=\"baaabbbbababb\", length=19):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"baaabbbbababb\", length=19):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "PrimeFib:4", + "sat": "def sat(n: int, lower=4):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=4):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:0", + "sat": "def sat(inds: List[int], nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:1", + "sat": "def sat(inds: List[int], nums=[-52, -16, 68, -27, 3]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-52, -16, 68, -27, 3]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:2", + "sat": "def sat(inds: List[int], nums=[-64, -74, -18, -57, 89, -14, -25, 11, -60, -78]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-64, -74, -18, -57, 89, -14, -25, 11, -60, -78]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:3", + "sat": "def sat(inds: List[int], nums=[-90, 63, 70, 21, 42, 20]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-90, 63, 70, 21, 42, 20]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:4", + "sat": "def sat(inds: List[int], nums=[-14, 65, -7, -75, 54, 78, -61, 136, -85, 44]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-14, 65, -7, -75, 54, 78, -61, 136, -85, 44]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "NumPasses:0", + "sat": "def sat(count: int, n=981):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=981):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 }, { - "name": "PalindromeStartingWith_9", - "sat": "def sat(ans: str, s=\"abbba\", length=11):\n \"\"\"\n Find a palindrome of a given length starting with a given string.\n\n Sample Input:\n \"foo\", 4\n\n Sample Output:\n \"foof\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and ans.startswith(s)", - "sols": [ - "def sol(s=\"abbba\", length=11):\n return s[:length // 2] + ' ' * (length - len(s) * 2) + s[:(length + 1) // 2][::-1]" + "name": "NumPasses:1", + "sat": "def sat(count: int, n=123):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=123):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 }, { - "name": "PalindromeContaining_0", - "sat": "def sat(ans: str, s=\"so easy\", length=20):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"so easy\", length=20):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "NumPasses:2", + "sat": "def sat(count: int, n=239):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=239):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 }, { - "name": "PalindromeContaining_1", - "sat": "def sat(ans: str, s=\"aabbab\", length=12):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"aabbab\", length=12):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "NumPasses:3", + "sat": "def sat(count: int, n=378):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=378):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 }, { - "name": "PalindromeContaining_2", - "sat": "def sat(ans: str, s=\"bbb\", length=27):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bbb\", length=27):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "NumPasses:4", + "sat": "def sat(count: int, n=501):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=501):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 }, { - "name": "PalindromeContaining_3", - "sat": "def sat(ans: str, s=\"bb\", length=38):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bb\", length=38):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ListInc:0", + "sat": "def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 }, { - "name": "PalindromeContaining_4", - "sat": "def sat(ans: str, s=\"\", length=0):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"\", length=0):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ListInc:1", + "sat": "def sat(new_list: List[int], old_list=[18, 29, 40]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[18, 29, 40]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 }, { - "name": "PalindromeContaining_5", - "sat": "def sat(ans: str, s=\"bab\", length=24):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bab\", length=24):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ListInc:2", + "sat": "def sat(new_list: List[int], old_list=[43, 64, 73, 30, 47]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[43, 64, 73, 30, 47]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 }, { - "name": "PalindromeContaining_6", - "sat": "def sat(ans: str, s=\"bbaababbbb\", length=26):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bbaababbbb\", length=26):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ListInc:3", + "sat": "def sat(new_list: List[int], old_list=[43, 9, 49, 93, 36, 47, 48, 38, 12]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[43, 9, 49, 93, 36, 47, 48, 38, 12]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 }, { - "name": "PalindromeContaining_7", - "sat": "def sat(ans: str, s=\"abbba\", length=23):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"abbba\", length=23):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ListInc:4", + "sat": "def sat(new_list: List[int], old_list=[45, 55, 71, 78, 54]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[45, 55, 71, 78, 54]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 + }, + { + "name": "PairZeroSum:0", + "sat": "def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "PairZeroSum:1", + "sat": "def sat(inds: List[int], nums=[50, 33, 12, -13, 65, -39, -12, -72, -61, -38, -58, -88, 70, -82, -80, 27, 68, 89, -57, 15, -33, 93, 57, -91, 60, -72, -19, -12, 70, -35, 53, -21, -19, 66, 58, 76, -92, 64, 52, -21, 29, -61, -10, 50, -88, 17, 0, -50, 52, -87, 9, -95, 59, 23, 69, -34, 73, -39, 15, 17, 37, -83, -31, 13, -33, 6, -27, -45, -15, -78, 74, 92, 56, -52, 44, -9, -22, 27, -94, -17, 5, -82, -40, 22, -91, 10, 57, 13, -41, -93, -40, -42, 28, -3, 82]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[50, 33, 12, -13, 65, -39, -12, -72, -61, -38, -58, -88, 70, -82, -80, 27, 68, 89, -57, 15, -33, 93, 57, -91, 60, -72, -19, -12, 70, -35, 53, -21, -19, 66, 58, 76, -92, 64, 52, -21, 29, -61, -10, 50, -88, 17, 0, -50, 52, -87, 9, -95, 59, 23, 69, -34, 73, -39, 15, 17, 37, -83, -31, 13, -33, 6, -27, -45, -15, -78, 74, 92, 56, -52, 44, -9, -22, 27, -94, -17, 5, -82, -40, 22, -91, 10, 57, 13, -41, -93, -40, -42, 28, -3, 82]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "PairZeroSum:2", + "sat": "def sat(inds: List[int], nums=[18, -81, 7, -48, -14, 88, -34, 29, 72, 16, 38, -29, 53, -52, 16, 31, 65, 1, -77, 24, -73, 8, 78, -13, -96, 29, -3, 45, -44, 98, 9, -89, -50, 46, -88, 89, -93, 98, -83, -3, -17, 72, 25, 18, 88, -32, -37, -26, 69, -39, 62, 64, 41, 58, 29, 33, -65, -13, 61, 41, -90, -79, -94, -81, 40, 46, -78, -13, -44, 9, 42, -90, 94, -19, 5, -33, 33, -60, 80, -40, -64, 19, -92, 62, -12, -58, 89, -50, -82, -32, 65, 82, -49, 80, -71, 68, -17, 26, 6, -61]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[18, -81, 7, -48, -14, 88, -34, 29, 72, 16, 38, -29, 53, -52, 16, 31, 65, 1, -77, 24, -73, 8, 78, -13, -96, 29, -3, 45, -44, 98, 9, -89, -50, 46, -88, 89, -93, 98, -83, -3, -17, 72, 25, 18, 88, -32, -37, -26, 69, -39, 62, 64, 41, 58, 29, 33, -65, -13, 61, 41, -90, -79, -94, -81, 40, 46, -78, -13, -44, 9, 42, -90, 94, -19, 5, -33, 33, -60, 80, -40, -64, 19, -92, 62, -12, -58, 89, -50, -82, -32, 65, 82, -49, 80, -71, 68, -17, 26, 6, -61]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "PairZeroSum:3", + "sat": "def sat(inds: List[int], nums=[61, 13, 32, -67, -29, 6, 65, 82, -36, -90, -3, -53, -80, 52, -20, 14, -58, 1, 14, 88, 90, -76, -83, 47, -20, -26, 5, 71, 29, -51, -6, 38, -42, -48, 9, -74, -37, -86, -31, -63, -45, -74, -40, 23, -16, 24, -6, -93, -46, -42, -4, -85, -91, 71, -72, 11, -33, 33, -82, -67, -34, -60, 89, 60, 26, -12, -92, 42, -92, -58, -37, 9, -38, 54, 34, 25, 85, -65, -79, 33, -52, -72, -80, -76, -39, 24, -2, 40, -53, -14, 8, 21, 7, 46, -88, -67]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[61, 13, 32, -67, -29, 6, 65, 82, -36, -90, -3, -53, -80, 52, -20, 14, -58, 1, 14, 88, 90, -76, -83, 47, -20, -26, 5, 71, 29, -51, -6, 38, -42, -48, 9, -74, -37, -86, -31, -63, -45, -74, -40, 23, -16, 24, -6, -93, -46, -42, -4, -85, -91, 71, -72, 11, -33, 33, -82, -67, -34, -60, 89, 60, 26, -12, -92, 42, -92, -58, -37, 9, -38, 54, 34, 25, 85, -65, -79, 33, -52, -72, -80, -76, -39, 24, -2, 40, -53, -14, 8, 21, 7, 46, -88, -67]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "PairZeroSum:4", + "sat": "def sat(inds: List[int], nums=[4, -4, -4, -3, 3, 1]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[4, -4, -4, -3, 3, 1]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "ChangeBase:0", + "sat": "def sat(s: str, n=142, base=7):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=142, base=7):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 + }, { - "name": "PalindromeContaining_8", - "sat": "def sat(ans: str, s=\"bbbaaa\", length=33):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bbbaaa\", length=33):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ChangeBase:1", + "sat": "def sat(s: str, n=85328, base=2):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=85328, base=2):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 }, { - "name": "PalindromeContaining_9", - "sat": "def sat(ans: str, s=\"bbab\", length=9):\n \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"\n return ans == ans[::-1] and len(ans) == length and s in ans", - "sols": [ - "def sol(s=\"bbab\", length=9):\n ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + "name": "ChangeBase:2", + "sat": "def sat(s: str, n=9576751, base=10):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=9576751, base=10):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 }, { - "name": "BinaryStrXOR_0", - "sat": "def sat(str_num: str, nums=['100011101100001', '100101100101110']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['100011101100001', '100101100101110']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "ChangeBase:3", + "sat": "def sat(s: str, n=5160280, base=5):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=5160280, base=5):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 }, { - "name": "BinaryStrXOR_1", - "sat": "def sat(str_num: str, nums=['1101101111', '11001100']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['1101101111', '11001100']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "ChangeBase:4", + "sat": "def sat(s: str, n=4884658, base=6):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=4884658, base=6):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 }, { - "name": "BinaryStrXOR_2", - "sat": "def sat(str_num: str, nums=['11011111', '1101001110']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['11011111', '1101001110']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "TriangleArea:0", + "sat": "def sat(height: int, area=1319098728582, base=45126):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=1319098728582, base=45126):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 }, { - "name": "BinaryStrXOR_3", - "sat": "def sat(str_num: str, nums=['100000001', '1010001001']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['100000001', '1010001001']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "TriangleArea:1", + "sat": "def sat(height: int, area=2642925075, base=211434006):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=2642925075, base=211434006):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 }, { - "name": "BinaryStrXOR_4", - "sat": "def sat(str_num: str, nums=['10010110', '10000']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['10010110', '10000']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "TriangleArea:2", + "sat": "def sat(height: int, area=5529468804, base=18936537):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=5529468804, base=18936537):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 }, { - "name": "BinaryStrXOR_5", - "sat": "def sat(str_num: str, nums=['111010100', '111110101']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['111010100', '111110101']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "TriangleArea:3", + "sat": "def sat(height: int, area=1238452500, base=600):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=1238452500, base=600):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 }, { - "name": "BinaryStrXOR_6", - "sat": "def sat(str_num: str, nums=['1010111111', '11111010']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['1010111111', '11111010']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "TriangleArea:4", + "sat": "def sat(height: int, area=32576448, base=147072):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=32576448, base=147072):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 }, { - "name": "BinaryStrXOR_7", - "sat": "def sat(str_num: str, nums=['1011010010', '110100']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['1011010010', '110100']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "Fib4:0", + "sat": "def sat(init: List[int], target=2021):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=2021):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 }, { - "name": "BinaryStrXOR_8", - "sat": "def sat(str_num: str, nums=['1000101111', '110110011']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['1000101111', '110110011']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "Fib4:1", + "sat": "def sat(init: List[int], target=56):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=56):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 }, { - "name": "BinaryStrXOR_9", - "sat": "def sat(str_num: str, nums=['1000110', '1101101100']):\n \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", - "sols": [ - "def sol(nums=['1000110', '1101101100']):\n a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + "name": "Fib4:2", + "sat": "def sat(init: List[int], target=58965):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=58965):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 }, { - "name": "LongestStr_0", - "sat": "def sat(ans: str, words=['these', 'are', 'some', 'pretty', 'long', 'words']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['these', 'are', 'some', 'pretty', 'long', 'words']):\n return max(words, key=len)" + "name": "Fib4:3", + "sat": "def sat(init: List[int], target=501192137):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=501192137):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 }, { - "name": "LongestStr_1", - "sat": "def sat(ans: str, words=['suquojurethy', 'zetenejubichicyj', 'dyzeroquyxipyfe']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['suquojurethy', 'zetenejubichicyj', 'dyzeroquyxipyfe']):\n return max(words, key=len)" + "name": "Fib4:4", + "sat": "def sat(init: List[int], target=0):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=0):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 + }, + { + "name": "Median:0", + "sat": "def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Median:1", + "sat": "def sat(x: int, nums=[-8813279918, 7464351342, 8037181984, 8564600186, 660800781], upper=-21408102335):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[-8813279918, 7464351342, 8037181984, 8564600186, 660800781], upper=-21408102335):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Median:2", + "sat": "def sat(x: int, nums=[], upper=0):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[], upper=0):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Median:3", + "sat": "def sat(x: int, nums=[-2350083760, -34560579, 3780403495, -9390708907, 2424237816, -6782611896, 624505871], upper=-11486893907):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[-2350083760, -34560579, 3780403495, -9390708907, 2424237816, -6782611896, 624505871], upper=-11486893907):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Median:4", + "sat": "def sat(x: int, nums=[-2410166269, 5887293672], upper=-8297459941):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[-2410166269, 5887293672], upper=-8297459941):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Palindrome:0", + "sat": "def sat(pals: List[bool], strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 }, { - "name": "LongestStr_2", - "sat": "def sat(ans: str, words=['thusisequiw', 'tevozequetextupetha', 'texterut', 'zopuhesofowyk', 'chajokapechunekizic', 'hefuhyjiwakifyma', 'thopebom', 'pah']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['thusisequiw', 'tevozequetextupetha', 'texterut', 'zopuhesofowyk', 'chajokapechunekizic', 'hefuhyjiwakifyma', 'thopebom', 'pah']):\n return max(words, key=len)" + "name": "Palindrome:1", + "sat": "def sat(pals: List[bool], strs=['getuteg', 'quiuq', 'tebetextxetebet', 'quyquykame', 'palimubibibumilap', 'chirowykigollogikyworihc', 'jyt', 'zenoryluchydoquuzohehozuuqodyhculyronez', 'gumizilixogylygoxilizimug']):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=['getuteg', 'quiuq', 'tebetextxetebet', 'quyquykame', 'palimubibibumilap', 'chirowykigollogikyworihc', 'jyt', 'zenoryluchydoquuzohehozuuqodyhculyronez', 'gumizilixogylygoxilizimug']):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 }, { - "name": "LongestStr_3", - "sat": "def sat(ans: str, words=['melo', 'zoj', 'wujololyfytew', 'barivitextyte', 'decipywiduvaq', 'ruty', 'gekusoduz']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['melo', 'zoj', 'wujololyfytew', 'barivitextyte', 'decipywiduvaq', 'ruty', 'gekusoduz']):\n return max(words, key=len)" + "name": "Palindrome:2", + "sat": "def sat(pals: List[bool], strs=['hahez', 'fuchuwas', 'fatextynuruce', 'wetewotuzoggozutowetew', 'vutot']):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=['hahez', 'fuchuwas', 'fatextynuruce', 'wetewotuzoggozutowetew', 'vutot']):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 }, { - "name": "LongestStr_4", - "sat": "def sat(ans: str, words=['quicydynigatha', 'pethiquifegosych', 'jixotextoxa', 'pe', 'xona', 'cifuco', 'gyrejypifam']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['quicydynigatha', 'pethiquifegosych', 'jixotextoxa', 'pe', 'xona', 'cifuco', 'gyrejypifam']):\n return max(words, key=len)" + "name": "Palindrome:3", + "sat": "def sat(pals: List[bool], strs=['wexivivixew', 'fyzalagalazyf', 's', 'quizylymaquequqeuqamylyziuq', 'cydilozuthytex', 'quu', 'vygylaf', 'chotexttxetohc', 'hequedipothovof']):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=['wexivivixew', 'fyzalagalazyf', 's', 'quizylymaquequqeuqamylyziuq', 'cydilozuthytex', 'quu', 'vygylaf', 'chotexttxetohc', 'hequedipothovof']):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 }, { - "name": "LongestStr_5", - "sat": "def sat(ans: str, words=['dyhurynorikus', 'zyfisaxuxi']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['dyhurynorikus', 'zyfisaxuxi']):\n return max(words, key=len)" + "name": "Palindrome:4", + "sat": "def sat(pals: List[bool], strs=[]):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=[]):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 }, { - "name": "LongestStr_6", - "sat": "def sat(ans: str, words=['gyt', 'ny', 'venokafyliwycho', 'tidemu', 'jipenuwe', 'juquoxusedochichago', 'hakidyzagi', 'kisegitext']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['gyt', 'ny', 'venokafyliwycho', 'tidemu', 'jipenuwe', 'juquoxusedochichago', 'hakidyzagi', 'kisegitext']):\n return max(words, key=len)" + "name": "LittleFermat:0", + "sat": "def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):\n p = len(poly)\n assert p > 2 and all(p % i for i in range(2, p)), \"Hint: p is a prime > 2\"\n\n def val(coeffs, n): # evaluate polynomial mod p\n return sum(c * pow(n, i, p) for i, c in enumerate(coeffs)) % p\n\n return all(val(exp_poly, n) == pow(val(poly, n), d, p) for n in range(p))", + "ans_type": "List[int]", + "sol_header": "def sol(d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):", + "sol_docstring": " \"\"\"\n Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1\n polynomial (mod p).\n Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p).\n\n Sample Input:\n d=2, poly=[1, 0, 0, 1, 0] # 1 + x^3\n\n Sample Output:\n [1, 0, 1, 2, 0] # 1+ x^2 + 2x^3 because (1 + x^3)^2 = 1 + 2x^3 + x^6 and x^6 = x^2 (mod 5)\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Use repeated squaring to exponentiate polynomial\n \"\"\"\n p = len(poly)\n\n def prod(poly1, poly2): # multiply two polynomials mod p\n ans = [0] * p\n for i, a in enumerate(poly1):\n for j, b in enumerate(poly2):\n e = (i + j) % (p - 1)\n if e == 0 and i + j > 1:\n e = p - 1\n ans[e] = (ans[e] + a * b) % p\n return ans\n\n ans = [1] + [0] * (p - 1)\n while d:\n if d % 2:\n ans = prod(ans, poly)\n poly = prod(poly, poly)\n d //= 2\n # for i in range(d):\n # ans = prod(ans, poly)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#49", + "weight": 1.0 }, { - "name": "LongestStr_7", - "sat": "def sat(ans: str, words=['lojisa', 'wucepytaw', 'tyhithos', 'kyruhidanu', 'conyxize', 'gufowocucitextocohu', 'chucu', 'cithukex', 'chimetho']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['lojisa', 'wucepytaw', 'tyhithos', 'kyruhidanu', 'conyxize', 'gufowocucitextocohu', 'chucu', 'cithukex', 'chimetho']):\n return max(words, key=len)" + "name": "ShiftChars:0", + "sat": "def sat(orig: str, result=\"Hello, world!\", shift=7):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"Hello, world!\", shift=7):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 }, { - "name": "LongestStr_8", - "sat": "def sat(ans: str, words=['juvowymifib', 'nycowocacofyvahavura', 'je', 'lagurichutexten', 'zidothezovitex', 'dathokulotextixemag', 'warilylubykyg', 'chesarecikathymithot', 'kimewichujymap']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['juvowymifib', 'nycowocacofyvahavura', 'je', 'lagurichutexten', 'zidothezovitex', 'dathokulotextixemag', 'warilylubykyg', 'chesarecikathymithot', 'kimewichujymap']):\n return max(words, key=len)" + "name": "ShiftChars:1", + "sat": "def sat(orig: str, result=\"rupomykecykynuric\", shift=-9):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"rupomykecykynuric\", shift=-9):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 }, { - "name": "LongestStr_9", - "sat": "def sat(ans: str, words=['gofyhafucochilixisu', 'textafiquade', 'me', 'fasuquyjodinachyl', 'textipamadeh', 'gofuthofequez', 'co']):\n \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"\n return ans in words and all(len(ans) >= len(w) for w in words)", - "sols": [ - "def sol(words=['gofyhafucochilixisu', 'textafiquade', 'me', 'fasuquyjodinachyl', 'textipamadeh', 'gofuthofequez', 'co']):\n return max(words, key=len)" + "name": "ShiftChars:2", + "sat": "def sat(orig: str, result=\"vicyza\", shift=7):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"vicyza\", shift=7):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 }, { - "name": "CertifiedGCD_0", - "sat": "def sat(ans: List[int], m=1408862, n=2113293):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=1408862, n=2113293):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ShiftChars:3", + "sat": "def sat(orig: str, result=\"nihyzatijyjoke\", shift=8):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"nihyzatijyjoke\", shift=8):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 }, { - "name": "CertifiedGCD_1", - "sat": "def sat(ans: List[int], m=2642408, n=828886):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=2642408, n=828886):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ShiftChars:4", + "sat": "def sat(orig: str, result=\"tuthijotext\", shift=6):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"tuthijotext\", shift=6):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 + }, + { + "name": "RemoveVowels:0", + "sat": "def sat(txt: str, text=\"Hello, world!\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"Hello, world!\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "RemoveVowels:1", + "sat": "def sat(txt: str, text=\"GUSUXeGePUJibAqUojo\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"GUSUXeGePUJibAqUojo\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "RemoveVowels:2", + "sat": "def sat(txt: str, text=\"CAsaVyVOTHobAHEwIhI\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"CAsaVyVOTHobAHEwIhI\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "RemoveVowels:3", + "sat": "def sat(txt: str, text=\"TeX\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"TeX\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "RemoveVowels:4", + "sat": "def sat(txt: str, text=\"Q\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"Q\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "BelowThreshold:0", + "sat": "def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 }, { - "name": "CertifiedGCD_2", - "sat": "def sat(ans: List[int], m=184428, n=105545439738):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=184428, n=105545439738):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "BelowThreshold:1", + "sat": "def sat(indexes: List[int], nums=[35, -96, -51, 7, 56, 0], thresh=-30):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[35, -96, -51, 7, 56, 0], thresh=-30):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 }, { - "name": "CertifiedGCD_3", - "sat": "def sat(ans: List[int], m=3956548155, n=103530):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=3956548155, n=103530):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "BelowThreshold:2", + "sat": "def sat(indexes: List[int], nums=[-20, 45], thresh=91):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-20, 45], thresh=91):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 }, { - "name": "CertifiedGCD_4", - "sat": "def sat(ans: List[int], m=101920, n=55199657760):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=101920, n=55199657760):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "BelowThreshold:3", + "sat": "def sat(indexes: List[int], nums=[84, 56, 13], thresh=-80):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[84, 56, 13], thresh=-80):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 }, { - "name": "CertifiedGCD_5", - "sat": "def sat(ans: List[int], m=49824, n=2529):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=49824, n=2529):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "BelowThreshold:4", + "sat": "def sat(indexes: List[int], nums=[3, -70, -88, 38], thresh=95):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[3, -70, -88, 38], thresh=95):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 }, { - "name": "CertifiedGCD_6", - "sat": "def sat(ans: List[int], m=72928, n=5936):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=72928, n=5936):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ListTotal:0", + "sat": "def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 }, { - "name": "CertifiedGCD_7", - "sat": "def sat(ans: List[int], m=412417661, n=42859041):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=412417661, n=42859041):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ListTotal:1", + "sat": "def sat(n: int, nums=[40388491, -864787067, 862143530, 604555885, -81302113, 717834573]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[40388491, -864787067, 862143530, 604555885, -81302113, 717834573]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 }, { - "name": "CertifiedGCD_8", - "sat": "def sat(ans: List[int], m=787285255, n=5204635750010320):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=787285255, n=5204635750010320):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ListTotal:2", + "sat": "def sat(n: int, nums=[-93, 35, -95, -7, -85, 2]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-93, 35, -95, -7, -85, 2]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 }, { - "name": "CertifiedGCD_9", - "sat": "def sat(ans: List[int], m=4244155816, n=3199315930):\n \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", - "sols": [ - "def sol(m=4244155816, n=3199315930):\n \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + "name": "ListTotal:3", + "sat": "def sat(n: int, nums=[-2040052, -6582681, -6604315, 1042475, 7287312, 8050849, 5566992, 4332017]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-2040052, -6582681, -6604315, 1042475, 7287312, 8050849, 5566992, 4332017]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 }, { - "name": "AllPrefixes_0", - "sat": "def sat(prefixes: List[str], s=\"donesezichethofalij\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"donesezichethofalij\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "ListTotal:4", + "sat": "def sat(n: int, nums=[-1, -1, -1, -1, 0, 0]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-1, -1, -1, -1, 0, 0]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 }, { - "name": "AllPrefixes_1", - "sat": "def sat(prefixes: List[str], s=\"vuf\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"vuf\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "DiffChars:0", + "sat": "def sat(c: str, a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 }, { - "name": "AllPrefixes_2", - "sat": "def sat(prefixes: List[str], s=\"t\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"t\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "DiffChars:1", + "sat": "def sat(c: str, a=\"jyhud\", b=\"nexysezomevus\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"jyhud\", b=\"nexysezomevus\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 }, { - "name": "AllPrefixes_3", - "sat": "def sat(prefixes: List[str], s=\"qu\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"qu\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "DiffChars:2", + "sat": "def sat(c: str, a=\"vofawawumovisajuryt\", b=\"t\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"vofawawumovisajuryt\", b=\"t\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 }, { - "name": "AllPrefixes_4", - "sat": "def sat(prefixes: List[str], s=\"dugethixuneku\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"dugethixuneku\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "DiffChars:3", + "sat": "def sat(c: str, a=\"textuzaxoch\", b=\"acehmottuxxz\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"textuzaxoch\", b=\"acehmottuxxz\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 }, { - "name": "AllPrefixes_5", - "sat": "def sat(prefixes: List[str], s=\"xetijidixuwat\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"xetijidixuwat\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "DiffChars:4", + "sat": "def sat(c: str, a=\"quytextila\", b=\"mydyhopakokinavo\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"quytextila\", b=\"mydyhopakokinavo\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 }, { - "name": "AllPrefixes_6", - "sat": "def sat(prefixes: List[str], s=\"tilyxut\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"tilyxut\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "Fibonacci:0", + "sat": "def sat(nums: List[int], n=1402):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=1402):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 }, { - "name": "AllPrefixes_7", - "sat": "def sat(prefixes: List[str], s=\"zami\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"zami\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "Fibonacci:1", + "sat": "def sat(nums: List[int], n=537):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=537):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 }, { - "name": "AllPrefixes_8", - "sat": "def sat(prefixes: List[str], s=\"joxach\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"joxach\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "Fibonacci:2", + "sat": "def sat(nums: List[int], n=6968):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=6968):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 }, { - "name": "AllPrefixes_9", - "sat": "def sat(prefixes: List[str], s=\"juch\"):\n \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", - "sols": [ - "def sol(s=\"juch\"):\n return [s[:i] for i in range(len(s) + 1)]" + "name": "Fibonacci:3", + "sat": "def sat(nums: List[int], n=5585):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=5585):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 }, { - "name": "SpaceyRange_0", - "sat": "def sat(ans: str, n=15):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=15):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "Fibonacci:4", + "sat": "def sat(nums: List[int], n=7277):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=7277):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 }, { - "name": "SpaceyRange_1", - "sat": "def sat(ans: str, n=54635):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=54635):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "MatchBrackets:0", + "sat": "def sat(matches: List[int], brackets=\"<<>><<<><>><<>>>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<<>><<<><>><<>>>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 }, { - "name": "SpaceyRange_2", - "sat": "def sat(ans: str, n=83):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=83):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "MatchBrackets:1", + "sat": "def sat(matches: List[int], brackets=\"<><><><><<>><<<><><<>>>><><><>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<><><><><<>><<<><><<>>>><><><>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 }, { - "name": "SpaceyRange_3", - "sat": "def sat(ans: str, n=99847):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=99847):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "MatchBrackets:2", + "sat": "def sat(matches: List[int], brackets=\"<><><<<>><<<<><>>><<>><>>><>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<><><<<>><<<<><>>><<>><>>><>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 }, { - "name": "SpaceyRange_4", - "sat": "def sat(ans: str, n=18215):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=18215):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "MatchBrackets:3", + "sat": "def sat(matches: List[int], brackets=\"<><><><><<><><<><>>><><<>><><<>><><><><<<>><>><>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<><><><><<><><<><>>><><<>><><<>><><><><<<>><>><>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 }, { - "name": "SpaceyRange_5", - "sat": "def sat(ans: str, n=97292):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=97292):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "MatchBrackets:4", + "sat": "def sat(matches: List[int], brackets=\"<<<<<>>>>><><><<>>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<<<<<>>>>><><><<>>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 }, { - "name": "SpaceyRange_6", - "sat": "def sat(ans: str, n=74968):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=74968):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "Monotonic:0", + "sat": "def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[2, 4, 17, 29, 31, 1000, 416629]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 }, { - "name": "SpaceyRange_7", - "sat": "def sat(ans: str, n=14815):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=14815):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "Monotonic:1", + "sat": "def sat(direction: str, nums=[540, 713, 887, 964]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[540, 713, 887, 964]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 }, { - "name": "SpaceyRange_8", - "sat": "def sat(ans: str, n=86905):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=86905):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "Monotonic:2", + "sat": "def sat(direction: str, nums=[764, 291, 171]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[764, 291, 171]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 }, { - "name": "SpaceyRange_9", - "sat": "def sat(ans: str, n=79126):\n \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", - "sols": [ - "def sol(n=79126):\n return ' '.join(str(i) for i in range(n + 1))" + "name": "Monotonic:3", + "sat": "def sat(direction: str, nums=[74, 168, 229, 302, 430, 450, 481, 783]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[74, 168, 229, 302, 430, 450, 481, 783]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 }, { - "name": "DistinctChars_0", - "sat": "def sat(ans: List[str], s=\"The quick brown fox jumps over the lazy dog!\", n=28):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"The quick brown fox jumps over the lazy dog!\", n=28):\n return list(set(s.lower()))" + "name": "Monotonic:4", + "sat": "def sat(direction: str, nums=[826, 784, 726, 537, 536, 392, 250, 241, 161]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[826, 784, 726, 537, 536, 392, 250, 241, 161]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 }, { - "name": "DistinctChars_1", - "sat": "def sat(ans: List[str], s=\"Iu]K,>Q8w\", n=9):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"Iu]K,>Q8w\", n=9):\n return list(set(s.lower()))" + "name": "CommonNumbers:0", + "sat": "def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):\n return all((i in common) == (i in a and i in b) for i in a + b + common)", + "ans_type": "List[int]", + "sol_header": "def sol(a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):", + "sol_docstring": " \"\"\"\n Find numbers common to a and b\n\n Sample Input:\n [1, 2, 3], [3, 4, 5]\n\n Sample Output:\n [3]\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).intersection(set(b)))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", + "weight": 1.0 }, { - "name": "DistinctChars_2", - "sat": "def sat(ans: List[str], s=\"JrUCk=ek&q^xBuvtm\", n=15):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"JrUCk=ek&q^xBuvtm\", n=15):\n return list(set(s.lower()))" + "name": "CommonNumbers:1", + "sat": "def sat(common: List[int], a=[824, 853, 392, 835, 225, 96], b=[73, 534, 705, 376, 376, 965, 404, 976]):\n return all((i in common) == (i in a and i in b) for i in a + b + common)", + "ans_type": "List[int]", + "sol_header": "def sol(a=[824, 853, 392, 835, 225, 96], b=[73, 534, 705, 376, 376, 965, 404, 976]):", + "sol_docstring": " \"\"\"\n Find numbers common to a and b\n\n Sample Input:\n [1, 2, 3], [3, 4, 5]\n\n Sample Output:\n [3]\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).intersection(set(b)))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", + "weight": 1.0 }, { - "name": "DistinctChars_3", - "sat": "def sat(ans: List[str], s=\"V-wKeN\", n=6):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"V-wKeN\", n=6):\n return list(set(s.lower()))" + "name": "CommonNumbers:2", + "sat": "def sat(common: List[int], a=[338, 882, 92, 234], b=[993, 977, 403]):\n return all((i in common) == (i in a and i in b) for i in a + b + common)", + "ans_type": "List[int]", + "sol_header": "def sol(a=[338, 882, 92, 234], b=[993, 977, 403]):", + "sol_docstring": " \"\"\"\n Find numbers common to a and b\n\n Sample Input:\n [1, 2, 3], [3, 4, 5]\n\n Sample Output:\n [3]\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).intersection(set(b)))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", + "weight": 1.0 }, { - "name": "DistinctChars_4", - "sat": "def sat(ans: List[str], s=\"F;J*qHN.^YC\", n=11):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"F;J*qHN.^YC\", n=11):\n return list(set(s.lower()))" + "name": "CommonNumbers:3", + "sat": "def sat(common: List[int], a=[950, 299, 581, 222, 490, 758, 58, 76, 808, 814], b=[790, 200, 814, 851, 902, 490, 581, 808, 950, 343, 758]):\n return all((i in common) == (i in a and i in b) for i in a + b + common)", + "ans_type": "List[int]", + "sol_header": "def sol(a=[950, 299, 581, 222, 490, 758, 58, 76, 808, 814], b=[790, 200, 814, 851, 902, 490, 581, 808, 950, 343, 758]):", + "sol_docstring": " \"\"\"\n Find numbers common to a and b\n\n Sample Input:\n [1, 2, 3], [3, 4, 5]\n\n Sample Output:\n [3]\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).intersection(set(b)))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", + "weight": 1.0 }, { - "name": "DistinctChars_5", - "sat": "def sat(ans: List[str], s=\">w8uGPtYw8uGPtY 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=101076):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 }, { - "name": "DistinctChars_7", - "sat": "def sat(ans: List[str], s=\"9TnB:|,G1jP3iF;c\", n=16):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"9TnB:|,G1jP3iF;c\", n=16):\n return list(set(s.lower()))" + "name": "LargestPrimeFactor:1", + "sat": "def sat(p: int, n=15132):\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=15132):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 }, { - "name": "DistinctChars_8", - "sat": "def sat(ans: List[str], s=\"VYPY4ME#-+=wXwcWfu1\", n=16):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"VYPY4ME#-+=wXwcWfu1\", n=16):\n return list(set(s.lower()))" + "name": "LargestPrimeFactor:2", + "sat": "def sat(p: int, n=22184):\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=22184):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 }, { - "name": "DistinctChars_9", - "sat": "def sat(ans: List[str], s=\"R3vudd I\", n=7):\n \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", - "sols": [ - "def sol(s=\"R3vudd I\", n=7):\n return list(set(s.lower()))" + "name": "LargestPrimeFactor:3", + "sat": "def sat(p: int, n=70875):\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=70875):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 }, { - "name": "ParseMusic_0", - "sat": "def sat(beats: List[int], score=\"o o o| o| .| .| .| o| o| o o o| .|\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"o o o| o| .| .| .| o| o| o o o| .|\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "LargestPrimeFactor:4", + "sat": "def sat(p: int, n=63088):\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=63088):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 }, { - "name": "ParseMusic_1", - "sat": "def sat(beats: List[int], score=\".| o .| o| o| o| o| .| o o\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\".| o .| o| o| o| o| .| o o\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "CumulativeSums:0", + "sat": "def sat(sums: List[int], n=104):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=104):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 }, { - "name": "ParseMusic_2", - "sat": "def sat(beats: List[int], score=\"o| .| .| .| .| o| o .| o| o| o\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"o| .| .| .| .| o| o .| o| o| o\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "CumulativeSums:1", + "sat": "def sat(sums: List[int], n=19891):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=19891):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 }, { - "name": "ParseMusic_3", - "sat": "def sat(beats: List[int], score=\".| o|\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\".| o|\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "CumulativeSums:2", + "sat": "def sat(sums: List[int], n=11023):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=11023):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 }, { - "name": "ParseMusic_4", - "sat": "def sat(beats: List[int], score=\"\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "CumulativeSums:3", + "sat": "def sat(sums: List[int], n=10840):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=10840):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 }, { - "name": "ParseMusic_5", - "sat": "def sat(beats: List[int], score=\".| o o .| o o\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\".| o o .| o o\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "CumulativeSums:4", + "sat": "def sat(sums: List[int], n=14049):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=14049):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 }, { - "name": "ParseMusic_6", - "sat": "def sat(beats: List[int], score=\"o o| .| .| o o| .| .| o o .|\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"o o| .| .| o o| .| .| o o .|\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "ParenDepth:0", + "sat": "def sat(matches: List[int], parens=\"((())()(()()))(())\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"((())()(()()))(())\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 }, { - "name": "ParseMusic_7", - "sat": "def sat(beats: List[int], score=\"o| o o| o\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"o| o o| o\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "ParenDepth:1", + "sat": "def sat(matches: List[int], parens=\"\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 }, { - "name": "ParseMusic_8", - "sat": "def sat(beats: List[int], score=\".| o| o| o|\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\".| o| o| o|\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "ParenDepth:2", + "sat": "def sat(matches: List[int], parens=\"()\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"()\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 }, { - "name": "ParseMusic_9", - "sat": "def sat(beats: List[int], score=\"o| o o o| o| .| o o| o| o| o|\"):\n \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", - "sols": [ - "def sol(score=\"o| o o o| o| .| o o| o| o| o|\"):\n mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + "name": "ParenDepth:3", + "sat": "def sat(matches: List[int], parens=\"((()(())))\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"((()(())))\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 }, { - "name": "OverlappingCount_0", - "sat": "def sat(ans: List[int], s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "ParenDepth:4", + "sat": "def sat(matches: List[int], parens=\"(())\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"(())\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 + }, + { + "name": "Derivative:0", + "sat": "def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[2, 1, 0, 4, 19, 231, 0, 5]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Derivative:1", + "sat": "def sat(derivative: List[int], poly=[6, -7, -8, 3]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[6, -7, -8, 3]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Derivative:2", + "sat": "def sat(derivative: List[int], poly=[-5, 5, -6, 7]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[-5, 5, -6, 7]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Derivative:3", + "sat": "def sat(derivative: List[int], poly=[-8, 2, 1, -8, 9, -10, -2, -7, -10]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[-8, 2, 1, -8, 9, -10, -2, -7, -10]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Derivative:4", + "sat": "def sat(derivative: List[int], poly=[5, -1, -4, -2, 7, -9, 3, 9]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[5, -1, -4, -2, 7, -9, 3, 9]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Fib3:0", + "sat": "def sat(init: List[int], target=124156):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=124156):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 }, { - "name": "OverlappingCount_1", - "sat": "def sat(ans: List[int], s=\"halidykugadobezebothidububawuvejiquitextyrequamobythynethojahyquutatextoquuzilu\", sub=\"ne\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"halidykugadobezebothidububawuvejiquitextyrequamobythynethojahyquutatextoquuzilu\", sub=\"ne\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "Fib3:1", + "sat": "def sat(init: List[int], target=4050):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=4050):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 }, { - "name": "OverlappingCount_2", - "sat": "def sat(ans: List[int], s=\"sutapifitextidavyjedakotextopogonudy\", sub=\"te\", count=2):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"sutapifitextidavyjedakotextopogonudy\", sub=\"te\", count=2):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "Fib3:2", + "sat": "def sat(init: List[int], target=0):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=0):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 }, { - "name": "OverlappingCount_3", - "sat": "def sat(ans: List[int], s=\"fizyquohachoromuxuquatextidemihithacazynytytextukozarahuwyfuchyquyhidadytext\", sub=\"quohach\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"fizyquohachoromuxuquatextidemihithacazynytytextukozarahuwyfuchyquyhidadytext\", sub=\"quohach\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "Fib3:3", + "sat": "def sat(init: List[int], target=4644):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=4644):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 }, { - "name": "OverlappingCount_4", - "sat": "def sat(ans: List[int], s=\"wutextega\", sub=\"xtega\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"wutextega\", sub=\"xtega\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "Fib3:4", + "sat": "def sat(init: List[int], target=3):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=3):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 + }, + { + "name": "FindVowels:0", + "sat": "def sat(vowels: List[str], texts=['Hello, world!', 'Goodbye, world!']):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=['Hello, world!', 'Goodbye, world!']):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "FindVowels:1", + "sat": "def sat(vowels: List[str], texts=['kelUthI', 'RoRu', 'JuKEBesYtIcHakEQuala', 'TIzEXOtExTyJASiNiKi', 'tEWIFObesY', 'KyxySe', 'kEboWulOfEZEFuMYCH', 'XAPIFYS']):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=['kelUthI', 'RoRu', 'JuKEBesYtIcHakEQuala', 'TIzEXOtExTyJASiNiKi', 'tEWIFObesY', 'KyxySe', 'kEboWulOfEZEFuMYCH', 'XAPIFYS']):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "FindVowels:2", + "sat": "def sat(vowels: List[str], texts=['sATExtIjopEJOWIvU', 'v', 'teXTOGOzetEX', 'CAMe', 'SApiQuUzISYG', 'NaV']):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=['sATExtIjopEJOWIvU', 'v', 'teXTOGOzetEX', 'CAMe', 'SApiQuUzISYG', 'NaV']):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "FindVowels:3", + "sat": "def sat(vowels: List[str], texts=[]):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=[]):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "FindVowels:4", + "sat": "def sat(vowels: List[str], texts=['mAloCyBOSAwUg', 'W', 'BEsICHeCeLoNO']):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=['mAloCyBOSAwUg', 'W', 'BEsICHeCeLoNO']):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "CircularShiftNum:0", + "sat": "def sat(shifted: str, n=124582369835, shift=3):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=124582369835, shift=3):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 }, { - "name": "OverlappingCount_5", - "sat": "def sat(ans: List[int], s=\"mithathewyjewawohywegetogybijikuwyki\", sub=\"mithathewyjewawohywegetogybijik\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"mithathewyjewawohywegetogybijikuwyki\", sub=\"mithathewyjewawohywegetogybijik\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "CircularShiftNum:1", + "sat": "def sat(shifted: str, n=6852918492, shift=12):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=6852918492, shift=12):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 }, { - "name": "OverlappingCount_6", - "sat": "def sat(ans: List[int], s=\"thuwygithofythalujohotextyvudykyfowanaxetextyjosytextiroxisyhatextobijozynypym\", sub=\"textiro\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"thuwygithofythalujohotextyvudykyfowanaxetextyjosytextiroxisyhatextobijozynypym\", sub=\"textiro\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "CircularShiftNum:2", + "sat": "def sat(shifted: str, n=32928510691049616, shift=28):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=32928510691049616, shift=28):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 }, { - "name": "OverlappingCount_7", - "sat": "def sat(ans: List[int], s=\"chuzuwiguditonibethazejeluthydyludetextivosidathiwahasac\", sub=\"udetextiv\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"chuzuwiguditonibethazejeluthydyludetextivosidathiwahasac\", sub=\"udetextiv\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "CircularShiftNum:3", + "sat": "def sat(shifted: str, n=237, shift=26):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=237, shift=26):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 }, { - "name": "OverlappingCount_8", - "sat": "def sat(ans: List[int], s=\"fyvefyvybubukutextithiboquyjahedarihuwyvumenasatychutextyfarasyz\", sub=\"vefyvybubu\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"fyvefyvybubukutextithiboquyjahedarihuwyvumenasatychutextyfarasyz\", sub=\"vefyvybubu\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "CircularShiftNum:4", + "sat": "def sat(shifted: str, n=6, shift=26):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=6, shift=26):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 }, { - "name": "OverlappingCount_9", - "sat": "def sat(ans: List[int], s=\"jenedequugasitojepurivajymaquebanusuxoturarulivethecuchynywoduzuwizythichirowokepevuwy\", sub=\"dequugasitojepurivajymaquebanusuxot\", count=1):\n \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", - "sols": [ - "def sol(s=\"jenedequugasitojepurivajymaquebanusuxoturarulivethecuchynywoduzuwizythichirowokepevuwy\", sub=\"dequugasitojepurivajymaquebanusuxot\", count=1):\n ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + "name": "CharSum:0", + "sat": "def sat(tot: int, s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 }, { - "name": "SortNumbers_0", - "sat": "def sat(ans: str, s=\"six one four three two nine eight\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"six one four three two nine eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "CharSum:1", + "sat": "def sat(tot: int, s=\"VRkmX=(1oF#l\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"VRkmX=(1oF#l\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 }, { - "name": "SortNumbers_1", - "sat": "def sat(ans: str, s=\"nine two four nine zero six six eight\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"nine two four nine zero six six eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "CharSum:2", + "sat": "def sat(tot: int, s=\"*?sAJJ;FY8c!7zFwA\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"*?sAJJ;FY8c!7zFwA\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 }, { - "name": "SortNumbers_2", - "sat": "def sat(ans: str, s=\"nine six two\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"nine six two\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "CharSum:3", + "sat": "def sat(tot: int, s=\"Vmv%e8d3P\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"Vmv%e8d3P\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 }, { - "name": "SortNumbers_3", - "sat": "def sat(ans: str, s=\"five nine four eight\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"five nine four eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "CharSum:4", + "sat": "def sat(tot: int, s=\"K8B\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"K8B\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 }, { - "name": "SortNumbers_4", - "sat": "def sat(ans: str, s=\"seven eight seven zero zero five one\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"seven eight seven zero zero five one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "MissingBananas:0", + "sat": "def sat(bananas: int, bowl=\"5024 apples and 12189 oranges\", total=12491241):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"5024 apples and 12189 oranges\", total=12491241):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 }, { - "name": "SortNumbers_5", - "sat": "def sat(ans: str, s=\"two nine one\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"two nine one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "MissingBananas:1", + "sat": "def sat(bananas: int, bowl=\"7 apples and 9 oranges\", total=21):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"7 apples and 9 oranges\", total=21):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 }, { - "name": "SortNumbers_6", - "sat": "def sat(ans: str, s=\"nine two three one\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"nine two three one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "MissingBananas:2", + "sat": "def sat(bananas: int, bowl=\"508738582 apples and 346410095 oranges\", total=1452490389):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"508738582 apples and 346410095 oranges\", total=1452490389):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 }, { - "name": "SortNumbers_7", - "sat": "def sat(ans: str, s=\"nine zero seven one\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"nine zero seven one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "MissingBananas:3", + "sat": "def sat(bananas: int, bowl=\"28767 apples and 49488 oranges\", total=112303):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"28767 apples and 49488 oranges\", total=112303):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 }, { - "name": "SortNumbers_8", - "sat": "def sat(ans: str, s=\"two eight three one\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"two eight three one\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "MissingBananas:4", + "sat": "def sat(bananas: int, bowl=\"29991 apples and 99737 oranges\", total=155600):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"29991 apples and 99737 oranges\", total=155600):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 }, { - "name": "SortNumbers_9", - "sat": "def sat(ans: str, s=\"zero zero six four two nine seven two\"):\n \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", - "sols": [ - "def sol(s=\"zero zero six four two nine seven two\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + "name": "SmallestEven:0", + "sat": "def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 }, { - "name": "FindClosePair_0", - "sat": "def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "SmallestEven:1", + "sat": "def sat(val_index: List[int], nums=[38940, 7988, 78915]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[38940, 7988, 78915]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 }, { - "name": "FindClosePair_1", - "sat": "def sat(inds: List[int], nums=[-7.587461542549912, 0.7494004368541578, 2.0142388071411013, -1.552072793834526, 0.44845194836415025]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-7.587461542549912, 0.7494004368541578, 2.0142388071411013, -1.552072793834526, 0.44845194836415025]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "SmallestEven:2", + "sat": "def sat(val_index: List[int], nums=[26392632, 33805163]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[26392632, 33805163]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 }, { - "name": "FindClosePair_2", - "sat": "def sat(inds: List[int], nums=[-5.253924550449174, 7.798134742325132, 2.84274998450722, -5.355403889716619, -8.14069894708204, 6.276599656475899]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-5.253924550449174, 7.798134742325132, 2.84274998450722, -5.355403889716619, -8.14069894708204, 6.276599656475899]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "SmallestEven:3", + "sat": "def sat(val_index: List[int], nums=[744557286]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[744557286]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 }, { - "name": "FindClosePair_3", - "sat": "def sat(inds: List[int], nums=[8.647950767409466, 6.069423836495417, 8.647950767409466, -4.483139827348948, 7.822521892934297, 6.339621174459673]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[8.647950767409466, 6.069423836495417, 8.647950767409466, -4.483139827348948, 7.822521892934297, 6.339621174459673]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "SmallestEven:4", + "sat": "def sat(val_index: List[int], nums=[4512821, 7022753, 5506558]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[4512821, 7022753, 5506558]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 }, { - "name": "FindClosePair_4", - "sat": "def sat(inds: List[int], nums=[-2.4491102095531385, -2.4896924424294635]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-2.4491102095531385, -2.4896924424294635]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "GreatestHIndex:0", + "sat": "def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 }, { - "name": "FindClosePair_5", - "sat": "def sat(inds: List[int], nums=[-8.082651039738817, -2.1796380954088495, 4.106279687689776, 0.7459644370884906, -8.082651039738817, 4.6095776259083205, 3.443196970691549, -8.013347713995714, -6.090245321476226]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-8.082651039738817, -2.1796380954088495, 4.106279687689776, 0.7459644370884906, -8.082651039738817, 4.6095776259083205, 3.443196970691549, -8.013347713995714, -6.090245321476226]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "GreatestHIndex:1", + "sat": "def sat(h: int, seq=[5, 5, 4, 4, 0, 1, 3, 7, 2, 1, 0, 1, 8, 7, 2, 7, 4, 5, 2, 7, 5, 1, 9, 4, 7, 6, 3, 0, 1, 0, 6, 8, 0, 8, 9, 8, 3, 9, 4, 4, 4, 3, 8, 9, 5, 2, 5, 7, 9, 6, 2, 3, 0, 6, 0, 7, 8, 2, 2, 5, 1, 6, 1, 7, 8, 7, 6, 7]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[5, 5, 4, 4, 0, 1, 3, 7, 2, 1, 0, 1, 8, 7, 2, 7, 4, 5, 2, 7, 5, 1, 9, 4, 7, 6, 3, 0, 1, 0, 6, 8, 0, 8, 9, 8, 3, 9, 4, 4, 4, 3, 8, 9, 5, 2, 5, 7, 9, 6, 2, 3, 0, 6, 0, 7, 8, 2, 2, 5, 1, 6, 1, 7, 8, 7, 6, 7]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 }, { - "name": "FindClosePair_6", - "sat": "def sat(inds: List[int], nums=[-5.868311478572554, 1.0255817495874666, -0.48146436470143783, -8.719114868610834, -2.546592710919011, 6.984709299746932, -8.719114868610834]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-5.868311478572554, 1.0255817495874666, -0.48146436470143783, -8.719114868610834, -2.546592710919011, 6.984709299746932, -8.719114868610834]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "GreatestHIndex:2", + "sat": "def sat(h: int, seq=[3, 9, 0, 8, 2, 9, 6, 1, 8, 3, 5, 5, 4, 9, 0, 1, 0, 3, 4, 8, 7, 2, 4, 7, 1, 1, 7, 2, 1, 4, 1, 0]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[3, 9, 0, 8, 2, 9, 6, 1, 8, 3, 5, 5, 4, 9, 0, 1, 0, 3, 4, 8, 7, 2, 4, 7, 1, 1, 7, 2, 1, 4, 1, 0]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 }, { - "name": "FindClosePair_7", - "sat": "def sat(inds: List[int], nums=[-5.929135491582849, 0.5739637962348372, -5.842640975319499, 2.8780645795448834, 1.141967164242601, 5.849932734803803]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-5.929135491582849, 0.5739637962348372, -5.842640975319499, 2.8780645795448834, 1.141967164242601, 5.849932734803803]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "GreatestHIndex:3", + "sat": "def sat(h: int, seq=[7, 4, 1, 8, 6, 6, 6, 8, 5, 5, 8, 3, 0, 7, 2, 7, 2, 4, 5, 8, 6, 1, 1, 0, 0, 8, 8, 1, 5, 2, 1, 1, 7, 1, 3, 5, 6, 1, 7, 9, 6, 2, 6, 4, 7, 4, 3, 1, 2, 3, 9, 7, 7, 1, 7, 8, 6, 5, 9, 1, 6, 3, 4, 2, 4, 1, 7, 6, 3, 2, 5, 6, 1, 3, 9, 4, 9, 6, 9, 8, 1, 2, 3, 8]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[7, 4, 1, 8, 6, 6, 6, 8, 5, 5, 8, 3, 0, 7, 2, 7, 2, 4, 5, 8, 6, 1, 1, 0, 0, 8, 8, 1, 5, 2, 1, 1, 7, 1, 3, 5, 6, 1, 7, 9, 6, 2, 6, 4, 7, 4, 3, 1, 2, 3, 9, 7, 7, 1, 7, 8, 6, 5, 9, 1, 6, 3, 4, 2, 4, 1, 7, 6, 3, 2, 5, 6, 1, 3, 9, 4, 9, 6, 9, 8, 1, 2, 3, 8]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 }, { - "name": "FindClosePair_8", - "sat": "def sat(inds: List[int], nums=[-8.259939280965725, -2.9794224251564927, -9.680648238419254, 4.993052399256307, 1.0520613702799402, -0.18016079989077127, -7.0402708590960605]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[-8.259939280965725, -2.9794224251564927, -9.680648238419254, 4.993052399256307, 1.0520613702799402, -0.18016079989077127, -7.0402708590960605]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "GreatestHIndex:4", + "sat": "def sat(h: int, seq=[1, 2, 6, 2]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[1, 2, 6, 2]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 }, { - "name": "FindClosePair_9", - "sat": "def sat(inds: List[int], nums=[8.523993458434084, 6.9285605230649345, 9.798173831208977, 6.246343191245856]):\n \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", - "sols": [ - "def sol(nums=[8.523993458434084, 6.9285605230649345, 9.798173831208977, 6.246343191245856]):\n best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + "name": "WildSort:0", + "sat": "def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 }, { - "name": "Rescale_0", - "sat": "def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[13.0, 17.0, 17.0, 15.5, 2.94]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "WildSort:1", + "sat": "def sat(strange: List[int], li=[8, 1, 0, 8, 1, 5, 2, 1, 7, 3, 0, 4, 0, 3, 8, 0, 9, 0, 7]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[8, 1, 0, 8, 1, 5, 2, 1, 7, 3, 0, 4, 0, 3, 8, 0, 9, 0, 7]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 }, { - "name": "Rescale_1", - "sat": "def sat(ans: List[float], nums=[939.7119884829771, 939.7119884829771, 939.7119884829771]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[939.7119884829771, 939.7119884829771, 939.7119884829771]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "WildSort:2", + "sat": "def sat(strange: List[int], li=[2, 0, 2, 4, 7, 6, 9]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[2, 0, 2, 4, 7, 6, 9]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 }, { - "name": "Rescale_2", - "sat": "def sat(ans: List[float], nums=[0.4458061970026967, -3.9939008694208376, -1.0757147773525169, 0.3895998276095692, 2.0191942234485825, -0.23989163788911685, -0.003822778565885754, -0.8237835423706446, -0.08413275419390705]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[0.4458061970026967, -3.9939008694208376, -1.0757147773525169, 0.3895998276095692, 2.0191942234485825, -0.23989163788911685, -0.003822778565885754, -0.8237835423706446, -0.08413275419390705]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "WildSort:3", + "sat": "def sat(strange: List[int], li=[5, 3, 9, 9, 5, 2, 9, 7, 0, 5, 7, 1, 2]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[5, 3, 9, 9, 5, 2, 9, 7, 0, 5, 7, 1, 2]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 }, { - "name": "Rescale_3", - "sat": "def sat(ans: List[float], nums=[1.7162662285160908, -0.5573868669921508, -11.304736303883987, 1.166009156041828, 2.1833750395727782, 4.274594378665487, -0.45875107135742743, 0.0046661656727550556, 0.8537569786748028]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[1.7162662285160908, -0.5573868669921508, -11.304736303883987, 1.166009156041828, 2.1833750395727782, 4.274594378665487, -0.45875107135742743, 0.0046661656727550556, 0.8537569786748028]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "WildSort:4", + "sat": "def sat(strange: List[int], li=[7, 1, 3]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[7, 1, 3]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 }, { - "name": "Rescale_4", - "sat": "def sat(ans: List[float], nums=[23.976551109194304, 1.4655002766247416]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[23.976551109194304, 1.4655002766247416]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "HeronTriangle:0", + "sat": "def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[8.9, 10.8, 17.0]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 }, { - "name": "Rescale_5", - "sat": "def sat(ans: List[float], nums=[-0.20862246204171445, 0.05294154132456167, 0.016123530706202354, 6.197867322546757, 0.29262163929309337, 0.31523018392351926, -17.4249446756191]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[-0.20862246204171445, 0.05294154132456167, 0.016123530706202354, 6.197867322546757, 0.29262163929309337, 0.31523018392351926, -17.4249446756191]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "HeronTriangle:1", + "sat": "def sat(coords: List[List[float]], sides=[24.408110376178705, 32.72365349973282, 48.81696744586911]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[24.408110376178705, 32.72365349973282, 48.81696744586911]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 }, { - "name": "Rescale_6", - "sat": "def sat(ans: List[float], nums=[-9.416872416234026, -9.416872416234026, -9.416872416234026, -9.416872416234026, -9.416872416234026]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[-9.416872416234026, -9.416872416234026, -9.416872416234026, -9.416872416234026, -9.416872416234026]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "HeronTriangle:2", + "sat": "def sat(coords: List[List[float]], sides=[27.451864724831378, 71.73620497337176, 72.2364568008756]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[27.451864724831378, 71.73620497337176, 72.2364568008756]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 }, { - "name": "Rescale_7", - "sat": "def sat(ans: List[float], nums=[0.09507773060329765, 35.254227199767776, -0.8495046934861326, -1.3071941395674544, -27.189689345325718, 0.07456337687780305]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[0.09507773060329765, 35.254227199767776, -0.8495046934861326, -1.3071941395674544, -27.189689345325718, 0.07456337687780305]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "HeronTriangle:3", + "sat": "def sat(coords: List[List[float]], sides=[22.39325953731467, 22.640876224877417, 32.23640648363397]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[22.39325953731467, 22.640876224877417, 32.23640648363397]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 }, { - "name": "Rescale_8", - "sat": "def sat(ans: List[float], nums=[-0.006094754025173528, -20.803949792068924]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[-0.006094754025173528, -20.803949792068924]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "HeronTriangle:4", + "sat": "def sat(coords: List[List[float]], sides=[45.986905476840235, 79.97976343909342, 86.26149779271437]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[45.986905476840235, 79.97976343909342, 86.26149779271437]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 }, { - "name": "Rescale_9", - "sat": "def sat(ans: List[float], nums=[-0.355905418290736, 0.05411257346218109, 1.7487376393683114, 99.45981917106087, -1.3667663252187854, -0.4692956518571772, -0.4807581622245894, -0.0206470670379509]):\n \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", - "sols": [ - "def sol(nums=[-0.355905418290736, 0.05411257346218109, 1.7487376393683114, 99.45981917106087, -1.3667663252187854, -0.4692956518571772, -0.4807581622245894, -0.0206470670379509]):\n nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + "name": "InvestigateCrash:0", + "sat": "def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[1, 2, 5, 2, 1, 17], max_weight=100):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 }, { - "name": "FilterInts_0", - "sat": "def sat(indexes: List[int], li=['Hello', '5', '10', 'bye'], num=2):\n \"\"\"\n Find the indices of valid python integers in a list of strings\n\n Sample input\n ---\n [\"18.5\", \"-1\", \"2+2\", \"7\", \"foo\"]\n\n Sample output\n ---\n [1, 3]\n \"\"\"\n [int(li[i]) for i in indexes]\n return len(set(indexes)) >= num and min(indexes) >= 0", - "sols": [ - "def sol(li=['Hello', '5', '10', 'bye'], num=2):\n ans = []\n for i in range(len(li)):\n try:\n int(li[i])\n ans.append(i)\n except:\n pass\n return ans" + "name": "InvestigateCrash:1", + "sat": "def sat(problem: int, weights=[17, 97, 77, 13, 13, 77, 13, 17], max_weight=314):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[17, 97, 77, 13, 13, 77, 13, 17], max_weight=314):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", - "taint_date": "2021-7-7", - "weight": 0.010416666666666666 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 }, { - "name": "StrLength_0", - "sat": "def sat(length: int, s=\"pneumonoultramicroscopicsilicovolcanoconiosis\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"pneumonoultramicroscopicsilicovolcanoconiosis\"):\n return len(s)" + "name": "InvestigateCrash:2", + "sat": "def sat(problem: int, weights=[51, 23, 10, 4, 7, 56, 12, 4, 10, 23, 51], max_weight=276):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[51, 23, 10, 4, 7, 56, 12, 4, 10, 23, 51], max_weight=276):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 }, { - "name": "StrLength_1", - "sat": "def sat(length: int, s=\"=i\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"=i\"):\n return len(s)" + "name": "InvestigateCrash:3", + "sat": "def sat(problem: int, weights=[22, 81, 93, 22], max_weight=222):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[22, 81, 93, 22], max_weight=222):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 }, { - "name": "StrLength_2", - "sat": "def sat(length: int, s=\"&?Jq 2aNHt\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"&?Jq 2aNHt\"):\n return len(s)" + "name": "InvestigateCrash:4", + "sat": "def sat(problem: int, weights=[43, 37, 79, 37, 20], max_weight=222):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[43, 37, 79, 37, 20], max_weight=222):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 }, { - "name": "StrLength_3", - "sat": "def sat(length: int, s=\"?uCcQht\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"?uCcQht\"):\n return len(s)" + "name": "ClosestPalindrome:0", + "sat": "def sat(pal: str, s=\"palindromordinals\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"palindromordinals\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 }, { - "name": "StrLength_4", - "sat": "def sat(length: int, s=\"e>8=4jZNfhZl3&Mko-MfWd<^QR Vf7:2M\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"e>8=4jZNfhZl3&Mko-MfWd<^QR Vf7:2M\"):\n return len(s)" + "name": "ClosestPalindrome:1", + "sat": "def sat(pal: str, s=\"ti=\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"ti=\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 }, { - "name": "StrLength_5", - "sat": "def sat(length: int, s=\"]Y,G2U4ur-7X,T@(Gv$:Y0^C,-$+xM9$X2,*90|\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"]Y,G2U4ur-7X,T@(Gv$:Y0^C,-$+xM9$X2,*90|\"):\n return len(s)" + "name": "ClosestPalindrome:2", + "sat": "def sat(pal: str, s=\"bC\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"bC\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 }, { - "name": "StrLength_6", - "sat": "def sat(length: int, s=\"+>&?Qa%yLWZA2nBDQ8i)zvVWT\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"+>&?Qa%yLWZA2nBDQ8i)zvVWT\"):\n return len(s)" + "name": "ClosestPalindrome:3", + "sat": "def sat(pal: str, s=\"chachatexc0vchX)e1\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"chachatexc0vchX)e1\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 }, { - "name": "StrLength_7", - "sat": "def sat(length: int, s=\"Ly+NcKgOvg3J)\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"Ly+NcKgOvg3J)\"):\n return len(s)" + "name": "ClosestPalindrome:4", + "sat": "def sat(pal: str, s=\"w\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"w\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 }, { - "name": "StrLength_8", - "sat": "def sat(length: int, s=\"s$0^cow)Q917uY\"):\n \"\"\"\n Find the length of a non-empty string\n\n Sample input\n ---\n \"foo\"\n\n Sample output\n ---\n 3\n \"\"\"\n try:\n s[length]\n except IndexError:\n s[length - 1]\n return True", - "sols": [ - "def sol(s=\"s$0^cow)Q917uY\"):\n return len(s)" + "name": "NarrowerList:0", + "sat": "def sat(li: List[str], lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", + "ans_type": "List[str]", + "sol_header": "def sol(lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):", + "sol_docstring": " \"\"\"\n Find the list that has fewer total characters (including repetitions)\n\n Sample Input:\n [[\"sh\", \"ort\"], [\"longest\"]]\n\n Sample Output:\n [[\"sh\", \"ort\"]\n \"\"\"", + "sol_bodies": [ + " return min(lists, key=lambda x: sum(len(i) for i in x))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", + "weight": 1.0 }, { - "name": "StrLength_9", - "sat": "def sat(length: int, s=\"ZSA$sIKe|pz@|[ 1\n return prod == n", - "sols": [ - "def sol(n=123456, num_factors=8):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "CubeRoot:1", + "sat": "def sat(x: int, n=-469541313747981125):\n return x ** 3 == n", + "ans_type": "int", + "sol_header": "def sol(n=-469541313747981125):", + "sol_docstring": " \"\"\"Find an integer that when cubed is n\n\n Sample Input:\n 21\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", + "weight": 1.0 }, { - "name": "PrimeFactorization_1", - "sat": "def sat(factors: List[int], n=1339030, num_factors=6):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=1339030, num_factors=6):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "CubeRoot:2", + "sat": "def sat(x: int, n=963966660871383014273727008911874274513660721639801945125024924885086622296):\n return x ** 3 == n", + "ans_type": "int", + "sol_header": "def sol(n=963966660871383014273727008911874274513660721639801945125024924885086622296):", + "sol_docstring": " \"\"\"Find an integer that when cubed is n\n\n Sample Input:\n 21\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", + "weight": 1.0 }, { - "name": "PrimeFactorization_2", - "sat": "def sat(factors: List[int], n=141752, num_factors=6):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=141752, num_factors=6):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "CubeRoot:3", + "sat": "def sat(x: int, n=-858580967744947820888627092732831059532555665642825043140896515384975483968):\n return x ** 3 == n", + "ans_type": "int", + "sol_header": "def sol(n=-858580967744947820888627092732831059532555665642825043140896515384975483968):", + "sol_docstring": " \"\"\"Find an integer that when cubed is n\n\n Sample Input:\n 21\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", + "weight": 1.0 }, { - "name": "PrimeFactorization_3", - "sat": "def sat(factors: List[int], n=33088, num_factors=8):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=33088, num_factors=8):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "CubeRoot:4", + "sat": "def sat(x: int, n=-1649412660748961726580117293638546881248424191676176072):\n return x ** 3 == n", + "ans_type": "int", + "sol_header": "def sol(n=-1649412660748961726580117293638546881248424191676176072):", + "sol_docstring": " \"\"\"Find an integer that when cubed is n\n\n Sample Input:\n 21\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", + "weight": 1.0 }, { - "name": "PrimeFactorization_4", - "sat": "def sat(factors: List[int], n=2375171125400, num_factors=12):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=2375171125400, num_factors=12):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "HexPrimes:0", + "sat": "def sat(primes: List[bool], n=\"A4D4455214122CE192CCBE3\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"A4D4455214122CE192CCBE3\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 }, { - "name": "PrimeFactorization_5", - "sat": "def sat(factors: List[int], n=199424, num_factors=10):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=199424, num_factors=10):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "HexPrimes:1", + "sat": "def sat(primes: List[bool], n=\"a0eebda812c4c27a97d35f1\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"a0eebda812c4c27a97d35f1\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 }, { - "name": "PrimeFactorization_6", - "sat": "def sat(factors: List[int], n=12498304, num_factors=11):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=12498304, num_factors=11):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "HexPrimes:2", + "sat": "def sat(primes: List[bool], n=\"4a4a5904aaa94eb2\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"4a4a5904aaa94eb2\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 }, { - "name": "PrimeFactorization_7", - "sat": "def sat(factors: List[int], n=132, num_factors=4):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=132, num_factors=4):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "HexPrimes:3", + "sat": "def sat(primes: List[bool], n=\"b696e7352d58ee\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"b696e7352d58ee\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 }, { - "name": "PrimeFactorization_8", - "sat": "def sat(factors: List[int], n=2156933870, num_factors=8):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=2156933870, num_factors=8):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "HexPrimes:4", + "sat": "def sat(primes: List[bool], n=\"1a8dcd03abe2cdc\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"1a8dcd03abe2cdc\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 }, { - "name": "PrimeFactorization_9", - "sat": "def sat(factors: List[int], n=129685248, num_factors=14):\n \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", - "sols": [ - "def sol(n=129685248, num_factors=14):\n if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + "name": "Binarize:0", + "sat": "def sat(b: str, n=5324680297138495285):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=5324680297138495285):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 }, { - "name": "Dedup_0", - "sat": "def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "Binarize:1", + "sat": "def sat(b: str, n=88465169532890):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=88465169532890):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 }, { - "name": "Dedup_1", - "sat": "def sat(ans: List[int], li=[3, 3, 7, 9, 7, 2, 9, 4, 1]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[3, 3, 7, 9, 7, 2, 9, 4, 1]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "Binarize:2", + "sat": "def sat(b: str, n=0):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 }, { - "name": "Dedup_2", - "sat": "def sat(ans: List[int], li=[3, 9, 8, 9, 3, 5, 1, 3, 5]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[3, 9, 8, 9, 3, 5, 1, 3, 5]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "Binarize:3", + "sat": "def sat(b: str, n=16655679678386282):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=16655679678386282):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 }, { - "name": "Dedup_3", - "sat": "def sat(ans: List[int], li=[3, 8, 2, 1, 1, 7, 7, 7, 5, 5, 5, 9, 3, 7, 7]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[3, 8, 2, 1, 1, 7, 7, 7, 5, 5, 5, 9, 3, 7, 7]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "Binarize:4", + "sat": "def sat(b: str, n=2900):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=2900):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 }, { - "name": "Dedup_4", - "sat": "def sat(ans: List[int], li=[0, 3, 3, 2, 7, 0, 0, 6, 2, 4, 4, 5]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[0, 3, 3, 2, 7, 0, 0, 6, 2, 4, 4, 5]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "NearbyDuplicates:0", + "sat": "def sat(indices: List[int], s=\"I am an unhappy string!\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"I am an unhappy string!\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 }, { - "name": "Dedup_5", - "sat": "def sat(ans: List[int], li=[5, 6, 6, 1, 7, 3, 6, 1, 8]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[5, 6, 6, 1, 7, 3, 6, 1, 8]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "NearbyDuplicates:1", + "sat": "def sat(indices: List[int], s=\"aeEm%%uIV0imR&xUvQvZf#1z4\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"aeEm%%uIV0imR&xUvQvZf#1z4\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 }, { - "name": "Dedup_6", - "sat": "def sat(ans: List[int], li=[7, 5, 6, 8, 4, 7, 1, 7, 6, 3, 5, 0, 8, 9, 1]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[7, 5, 6, 8, 4, 7, 1, 7, 6, 3, 5, 0, 8, 9, 1]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "NearbyDuplicates:2", + "sat": "def sat(indices: List[int], s=\"e&S|C;;b1Nf[mmsQrQY\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"e&S|C;;b1Nf[mmsQrQY\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 }, { - "name": "Dedup_7", - "sat": "def sat(ans: List[int], li=[9, 4, 7, 7, 5, 4, 4, 3, 1, 6, 7, 1, 7, 9, 9, 0, 0]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[9, 4, 7, 7, 5, 4, 4, 3, 1, 6, 7, 1, 7, 9, 9, 0, 0]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "NearbyDuplicates:3", + "sat": "def sat(indices: List[int], s=\"?EaEc/oDAm(i gP\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"?EaEc/oDAm(i gP\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 }, { - "name": "Dedup_8", - "sat": "def sat(ans: List[int], li=[0, 3, 7, 3, 2, 4, 0, 3, 8, 8, 0, 9, 1, 8, 0, 7]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[0, 3, 7, 3, 2, 4, 0, 3, 8, 8, 0, 9, 1, 8, 0, 7]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "NearbyDuplicates:4", + "sat": "def sat(indices: List[int], s=\"pXw|EEcTKZ;:n[-tBME[[sn%fR37l;bM,t%!\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"pXw|EEcTKZ;:n[-tBME[[sn%fR37l;bM,t%!\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 }, { - "name": "Dedup_9", - "sat": "def sat(ans: List[int], li=[9, 1]):\n \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", - "sols": [ - "def sol(li=[9, 1]):\n seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + "name": "Grader:0", + "sat": "def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 }, { - "name": "FlipCase_0", - "sat": "def sat(ans: str, s=\"FlIp ME!\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"FlIp ME!\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "Grader:1", + "sat": "def sat(grades: List[str], gpas=[3.9759656717898215, 2.532507032264099, 3.695549189812313, 2.492545757546573, 0.9653857771911838, 1.619680869536884]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[3.9759656717898215, 2.532507032264099, 3.695549189812313, 2.492545757546573, 0.9653857771911838, 1.619680869536884]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 }, { - "name": "FlipCase_1", - "sat": "def sat(ans: str, s=\"mKC(K2.a!Z|>sv3izC3!\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"mKC(K2.a!Z|>sv3izC3!\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "Grader:2", + "sat": "def sat(grades: List[str], gpas=[1.0670062946539565]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[1.0670062946539565]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 }, { - "name": "FlipCase_2", - "sat": "def sat(ans: str, s=\"K a&3 tE 1tSG B3v3y(\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"K a&3 tE 1tSG B3v3y(\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "Grader:3", + "sat": "def sat(grades: List[str], gpas=[]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 }, { - "name": "FlipCase_3", - "sat": "def sat(ans: str, s=\"Sb31E#e<@3u\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"Sb31E#e<@3u\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "Grader:4", + "sat": "def sat(grades: List[str], gpas=[2.7731700871871414, 0.5127907383392896]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[2.7731700871871414, 0.5127907383392896]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 }, { - "name": "FlipCase_4", - "sat": "def sat(ans: str, s=\"q Y*.zv? !3B3::/3%F3\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"q Y*.zv? !3B3::/3%F3\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "FactorString:0", + "sat": "def sat(factor: str, s=\"catscatcatscatcatscat\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"catscatcatscatcatscat\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 }, { - "name": "FlipCase_5", - "sat": "def sat(ans: str, s=\"m&za [r!g!! W/\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"m&za [r!g!! W/\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "FactorString:1", + "sat": "def sat(factor: str, s=\"pamithelozefefitextpamithelozefefitext\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"pamithelozefefitextpamithelozefefitext\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 }, { - "name": "FlipCase_6", - "sat": "def sat(ans: str, s=\"SH\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"SH\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "FactorString:2", + "sat": "def sat(factor: str, s=\"mahermahermahermahermahermahermahermaher\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"mahermahermahermahermahermahermahermaher\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 }, { - "name": "FlipCase_7", - "sat": "def sat(ans: str, s=\"!nD2IE^y@X-<=k, \"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"!nD2IE^y@X-<=k, \"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "FactorString:3", + "sat": "def sat(factor: str, s=\"mapychysmapychysmapychysmapychysmapychysmapychys\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"mapychysmapychysmapychysmapychysmapychysmapychys\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 }, { - "name": "FlipCase_8", - "sat": "def sat(ans: str, s=\"ZuUB(mM1QOW( 3Mv!\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\"ZuUB(mM1QOW( 3Mv!\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "FactorString:4", + "sat": "def sat(factor: str, s=\"thihathihathihathihathihathiha\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"thihathihathihathihathihathiha\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 }, { - "name": "FlipCase_9", - "sat": "def sat(ans: str, s=\" so&% ;3D:fj.1&) 3\"):\n \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", - "sols": [ - "def sol(s=\" so&% ;3D:fj.1&) 3\"):\n return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + "name": "OneEnded:0", + "sat": "def sat(nums: List[int], n=5):\n count = 18 * (10 ** (n - 2)) if n > 1 else 1\n strs = {str(n) for n in nums}\n return len(strs) == count and all(s.startswith(\"1\") or s.endswith(\"1\") and len(s) == n for s in strs)", + "ans_type": "List[int]", + "sol_header": "def sol(n=5):", + "sol_docstring": " \"\"\"Find all n-digit integers that start or end with 1\n\n 1 => [1]\"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(10 ** (n - 1), 10 ** n):\n assert len(str(i)) == n\n if str(i).startswith(\"1\") or str(i).endswith(\"1\"):\n ans.append(i)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#83", + "weight": 1.0 }, { - "name": "CatStrings_0", - "sat": "def sat(cat: str, strings=['Will', 'i', 'am', 'Now', 'here']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['Will', 'i', 'am', 'Now', 'here']):\n return \"\".join(strings)" + "name": "BitSum:0", + "sat": "def sat(n: int, b=107, s=25):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=107, s=25):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 }, { - "name": "CatStrings_1", - "sat": "def sat(cat: str, strings=['dufe', 'keret', 'kothihisedatextumuva', 'pe', 'sicelynyzysukydew', 'zu', 'kathubaki']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['dufe', 'keret', 'kothihisedatextumuva', 'pe', 'sicelynyzysukydew', 'zu', 'kathubaki']):\n return \"\".join(strings)" + "name": "BitSum:1", + "sat": "def sat(n: int, b=59, s=51):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=59, s=51):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 }, { - "name": "CatStrings_2", - "sat": "def sat(cat: str, strings: List[str]=[]):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=[]):\n return \"\".join(strings)" + "name": "BitSum:2", + "sat": "def sat(n: int, b=825, s=653):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=825, s=653):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 }, { - "name": "CatStrings_3", - "sat": "def sat(cat: str, strings=['c', 'vawumich', 'textucagidyhikomuro', 'wuchiquusojahoz', 'l']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['c', 'vawumich', 'textucagidyhikomuro', 'wuchiquusojahoz', 'l']):\n return \"\".join(strings)" + "name": "BitSum:3", + "sat": "def sat(n: int, b=354, s=287):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=354, s=287):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 }, { - "name": "CatStrings_4", - "sat": "def sat(cat: str, strings=['s', 'nutext', 'quoxezenukowyho', 'botidyhu', 'kicethytextithybaqu']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['s', 'nutext', 'quoxezenukowyho', 'botidyhu', 'kicethytextithybaqu']):\n return \"\".join(strings)" + "name": "BitSum:4", + "sat": "def sat(n: int, b=256, s=1):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=256, s=1):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 + }, + { + "name": "EvenOddSum:0", + "sat": "def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "EvenOddSum:1", + "sat": "def sat(even_odd_sum: int, nums=[63, 11, -95, 69, 73, -43, 69, -26, -49, 36, 83, 21, -26, 11]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[63, 11, -95, 69, 73, -43, 69, -26, -49, 36, 83, 21, -26, 11]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "EvenOddSum:2", + "sat": "def sat(even_odd_sum: int, nums=[29, -100, 94, -10, -97, -70, 86, 69, -61, 44, 48, -12, 92]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[29, -100, 94, -10, -97, -70, 86, 69, -61, 44, 48, -12, 92]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "EvenOddSum:3", + "sat": "def sat(even_odd_sum: int, nums=[-75, -2, 68, 36, -4, 58, -42, -92, 28, 59, -66, 52]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-75, -2, 68, 36, -4, 58, -42, -92, 28, 59, -66, 52]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "EvenOddSum:4", + "sat": "def sat(even_odd_sum: int, nums=[48, -42, -19, -82, -71, -57, -85, 61, 61, -86]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[48, -42, -19, -82, -71, -57, -85, 61, 61, -86]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "AntiShuffle:0", + "sat": "def sat(s: str, orig=\"Hello world!!!\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"Hello world!!!\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 }, { - "name": "CatStrings_5", - "sat": "def sat(cat: str, strings=['ki']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['ki']):\n return \"\".join(strings)" + "name": "AntiShuffle:1", + "sat": "def sat(s: str, orig=\"YOU CAN rearrange my letters, yes you can!\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"YOU CAN rearrange my letters, yes you can!\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 }, { - "name": "CatStrings_6", - "sat": "def sat(cat: str, strings=['naj', 'thochif', 'poliw', 'gegylikipesepadogu', 'rixezy', 'borurocuvojitogu', 'kicu', 'gebacad', 'coxyxadypiz']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['naj', 'thochif', 'poliw', 'gegylikipesepadogu', 'rixezy', 'borurocuvojitogu', 'kicu', 'gebacad', 'coxyxadypiz']):\n return \"\".join(strings)" + "name": "AntiShuffle:2", + "sat": "def sat(s: str, orig=\"caN you handlE LONGGGGGGGGGGGG strings?\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"caN you handlE LONGGGGGGGGGGGG strings?\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 }, { - "name": "CatStrings_7", - "sat": "def sat(cat: str, strings=['r', 'kiluginowula', 'getoz', 'huliquebusyni', 'kafyryziquuf']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['r', 'kiluginowula', 'getoz', 'huliquebusyni', 'kafyryziquuf']):\n return \"\".join(strings)" + "name": "AntiShuffle:3", + "sat": "def sat(s: str, orig=\"how bout spaces and weird punctuation!?$%@#%\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"how bout spaces and weird punctuation!?$%@#%\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 }, { - "name": "CatStrings_8", - "sat": "def sat(cat: str, strings=['tijythog', 'rysichofap', 'tofylu', 'fujujufuvexuwuwywo']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['tijythog', 'rysichofap', 'tofylu', 'fujujufuvexuwuwywo']):\n return \"\".join(strings)" + "name": "AntiShuffle:4", + "sat": "def sat(s: str, orig=\"ruhixuthuciji kebelobawitextythuch quozo\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"ruhixuthuciji kebelobawitextythuch quozo\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 }, { - "name": "CatStrings_9", - "sat": "def sat(cat: str, strings=['bi', 'pevyny', 'bunyxawutextopywesu', 'wucequuhizodysuthe', 'je', 'diwymiso', 'cofoxad', 'wy']):\n \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", - "sols": [ - "def sol(strings=['bi', 'pevyny', 'bunyxawutextopywesu', 'wucequuhizodysuthe', 'je', 'diwymiso', 'cofoxad', 'wy']):\n return \"\".join(strings)" + "name": "UnevenFind:0", + "sat": "def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 }, { - "name": "FindExtensions_0", - "sat": "def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "UnevenFind:1", + "sat": "def sat(indices: List[List[int]], uneven=[[64, 7, 64, 64, 20], [72, 64, 22, 64, 64], [21, 35], [64, 0, 96, 27]], target=64):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[[64, 7, 64, 64, 20], [72, 64, 22, 64, 64], [21, 35], [64, 0, 96, 27]], target=64):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 }, { - "name": "FindExtensions_1", - "sat": "def sat(extensions: List[str], strings=['cot', 'z'], prefix=\"ca\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['cot', 'z'], prefix=\"ca\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "UnevenFind:2", + "sat": "def sat(indices: List[List[int]], uneven=[[16, 87]], target=87):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[[16, 87]], target=87):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 }, { - "name": "FindExtensions_2", - "sat": "def sat(extensions: List[str], strings=['jof', 'thibi'], prefix=\"le\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['jof', 'thibi'], prefix=\"le\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "UnevenFind:3", + "sat": "def sat(indices: List[List[int]], uneven=[], target=30):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[], target=30):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 }, { - "name": "FindExtensions_3", - "sat": "def sat(extensions: List[str], strings=['t'], prefix=\"t\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['t'], prefix=\"t\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "UnevenFind:4", + "sat": "def sat(indices: List[List[int]], uneven=[[5, 30, 18], [53, 64, 87, 69, 64, 64, 64], [], [44], [64, 88, 68, 64, 64, 84, 64, 64, 64], [31], [64, 5, 64, 71, 42, 64, 48, 64, 27], [64, 80, 11, 64]], target=64):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[[5, 30, 18], [53, 64, 87, 69, 64, 64, 64], [], [44], [64, 88, 68, 64, 64, 84, 64, 64, 64], [31], [64, 5, 64, 71, 42, 64, 48, 64, 27], [64, 80, 11, 64]], target=64):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 }, { - "name": "FindExtensions_4", - "sat": "def sat(extensions: List[str], strings=['cpud', 'cpal', 'cv', 'cchut'], prefix=\"c\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['cpud', 'cpal', 'cv', 'cchut'], prefix=\"c\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "UpDownSort:0", + "sat": "def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):\n assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), \"not a reordering\"\n increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1\n return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):", + "sol_docstring": " \"\"\"Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd\n\n Sample input:\n [1, 7, 4]\n\n Sample output:\n [1, 4, 7] # because 1 + 4 is odd\n\n Sample input:\n [1, 7, 5]\n\n Sample output:\n [8, 5, 1] # because 1 + 5 is even\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=(False if (nums[0] + nums[-1]) % 2 else True))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#88", + "weight": 1.0 }, { - "name": "FindExtensions_5", - "sat": "def sat(extensions: List[str], strings=['tuju', 'woze', 'text', 'mymy', 'chi'], prefix=\"g\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['tuju', 'woze', 'text', 'mymy', 'chi'], prefix=\"g\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "SubstitutionCypher:0", + "sat": "def sat(encrypted: str, orig=\"Hello, world!\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 }, { - "name": "FindExtensions_6", - "sat": "def sat(extensions: List[str], strings=['kudar', 'g', 'zex'], prefix=\"\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['kudar', 'g', 'zex'], prefix=\"\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "SubstitutionCypher:1", + "sat": "def sat(encrypted: str, orig=\"\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 }, { - "name": "FindExtensions_7", - "sat": "def sat(extensions: List[str], strings=['v'], prefix=\"\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['v'], prefix=\"\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "SubstitutionCypher:2", + "sat": "def sat(encrypted: str, orig=\"byfykovevuvyxanofi lygolono pyzuh t\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"byfykovevuvyxanofi lygolono pyzuh t\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 }, { - "name": "FindExtensions_8", - "sat": "def sat(extensions: List[str], strings=['', 'fi'], prefix=\"\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['', 'fi'], prefix=\"\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "SubstitutionCypher:3", + "sat": "def sat(encrypted: str, orig=\"dogyvotitonucuxecequ jahuzowiz jyna\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"dogyvotitonucuxecequ jahuzowiz jyna\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 }, { - "name": "FindExtensions_9", - "sat": "def sat(extensions: List[str], strings=['di', 'tabo'], prefix=\"n\"):\n \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", - "sols": [ - "def sol(strings=['di', 'tabo'], prefix=\"n\"):\n return [s for s in strings if s.startswith(prefix)]" + "name": "SubstitutionCypher:4", + "sat": "def sat(encrypted: str, orig=\"chodatext quycimoquytunek\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"chodatext quycimoquytunek\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 }, { - "name": "FindPositives_0", - "sat": "def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):\n return [i for i in nums if i > 0]" + "name": "SecondSmallestUnique:0", + "sat": "def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 }, { - "name": "FindPositives_1", - "sat": "def sat(positives: List[int], nums=[53, 33, 73, 47, 35, 24, 56, 89, 85]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[53, 33, 73, 47, 35, 24, 56, 89, 85]):\n return [i for i in nums if i > 0]" + "name": "SecondSmallestUnique:1", + "sat": "def sat(n: int, nums=[-3, -4, -3, 8, -9]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[-3, -4, -3, 8, -9]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 }, { - "name": "FindPositives_2", - "sat": "def sat(positives: List[int], nums=[61, -64, -11, -3, -96, -69, -18, -99, 87]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[61, -64, -11, -3, -96, -69, -18, -99, 87]):\n return [i for i in nums if i > 0]" + "name": "SecondSmallestUnique:2", + "sat": "def sat(n: int, nums=[0, -5, -7, -5, 0, -2, 6, -8]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[0, -5, -7, -5, 0, -2, 6, -8]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 }, { - "name": "FindPositives_3", - "sat": "def sat(positives: List[int], nums=[62, 3, -84]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[62, 3, -84]):\n return [i for i in nums if i > 0]" + "name": "SecondSmallestUnique:3", + "sat": "def sat(n: int, nums=[6, 5]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[6, 5]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 }, { - "name": "FindPositives_4", - "sat": "def sat(positives: List[int], nums: List[int]=[]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[]):\n return [i for i in nums if i > 0]" + "name": "SecondSmallestUnique:4", + "sat": "def sat(n: int, nums=[4, -8, 8, 4]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[4, -8, 8, 4]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 }, { - "name": "FindPositives_5", - "sat": "def sat(positives: List[int], nums=[-99, -55, -11, -28]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[-99, -55, -11, -28]):\n return [i for i in nums if i > 0]" + "name": "FindBored:0", + "sat": "def sat(boring: List[str], text=\"This is not boring. I am boring! I am sooo tired.\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"This is not boring. I am boring! I am sooo tired.\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 }, { - "name": "FindPositives_6", - "sat": "def sat(positives: List[int], nums=[78, -40, -84, -80, 14, 37, -63, -31, 80]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[78, -40, -84, -80, 14, 37, -63, -31, 80]):\n return [i for i in nums if i > 0]" + "name": "FindBored:1", + "sat": "def sat(boring: List[str], text=\"dexuzuhyfac lifugerimosiwybot.hesukawycat!hawymemof pa text z.nuquyt weminubadithikanat gejetextipafex vobenekothob.reraxithechaquipapav wexamew lobihus zygijehequesatextacy jucyth?I?I wevymicygequipi cicemyte tha cetexti vuhoxadivelabyduxix?I lanusutho kuzit?nathor sopati myjamygukiwyhuje.I kacuquedewapojedu thulocho?I chezeri.thubitozogukenejugox.cytonoc tex tobaquy wiwithij!vinam rarile sibizytexta notaxithyzu?\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"dexuzuhyfac lifugerimosiwybot.hesukawycat!hawymemof pa text z.nuquyt weminubadithikanat gejetextipafex vobenekothob.reraxithechaquipapav wexamew lobihus zygijehequesatextacy jucyth?I?I wevymicygequipi cicemyte tha cetexti vuhoxadivelabyduxix?I lanusutho kuzit?nathor sopati myjamygukiwyhuje.I kacuquedewapojedu thulocho?I chezeri.thubitozogukenejugox.cytonoc tex tobaquy wiwithij!vinam rarile sibizytexta notaxithyzu?\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 }, { - "name": "FindPositives_7", - "sat": "def sat(positives: List[int], nums=[-61, -38, -65, 23, -27, -49]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[-61, -38, -65, 23, -27, -49]):\n return [i for i in nums if i > 0]" + "name": "FindBored:2", + "sat": "def sat(boring: List[str], text=\"\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 }, { - "name": "FindPositives_8", - "sat": "def sat(positives: List[int], nums=[-41, 24]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[-41, 24]):\n return [i for i in nums if i > 0]" + "name": "FindBored:3", + "sat": "def sat(boring: List[str], text=\"nysydajywigi vefusivechucirochuw tipeko pogofinifyk.I textovugythecodo ruwatekat dane wachikechanequi matupisofunehac.tubicetofalat colawuhemedexeq lurytext?\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"nysydajywigi vefusivechucirochuw tipeko pogofinifyk.I textovugythecodo ruwatekat dane wachikechanequi matupisofunehac.tubicetofalat colawuhemedexeq lurytext?\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 }, { - "name": "FindPositives_9", - "sat": "def sat(positives: List[int], nums=[-90, 65, 13, -70, 45, 20]):\n \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", - "sols": [ - "def sol(nums=[-90, 65, 13, -70, 45, 20]):\n return [i for i in nums if i > 0]" + "name": "FindBored:4", + "sat": "def sat(boring: List[str], text=\"?zihithi ch chithe vuluzuquidawyquo.I?I chypufomiwylojen ziwuwygawyfyg makatex?textidigefoc nyjav.I gujyduvafe gykizubam cofurythoc.coc thohifycepy tex kybiwulatextux.\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"?zihithi ch chithe vuluzuquidawyquo.I?I chypufomiwylojen ziwuwygawyfyg makatex?textidigefoc nyjav.I gujyduvafe gykizubam cofurythoc.coc thohifycepy tex kybiwulatextux.\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:0", + "sat": "def sat(zero_sums: List[bool], trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:1", + "sat": "def sat(zero_sums: List[bool], trips=[[7, -5, -4], [-7, 1, -6], [-2, 10, 3], [-9, -1, 10]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[7, -5, -4], [-7, 1, -6], [-2, 10, 3], [-9, -1, 10]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:2", + "sat": "def sat(zero_sums: List[bool], trips=[[-9, 9, -1], [-3, -7, -10], [0, -8, 5], [-8, -3, 3], [4, 8, 2], [-10, 8, 3]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[-9, 9, -1], [-3, -7, -10], [0, -8, 5], [-8, -3, 3], [4, 8, 2], [-10, 8, 3]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:3", + "sat": "def sat(zero_sums: List[bool], trips=[[-9, 3, 5], [-2, 8, 6], [1, 7, 8], [-4, 3, 4], [1, -6, 10], [-5, -8, -13], [-4, 10, -8], [1, -2, -4], [7, 2, 9], [4, -4, 0], [8, -1, 2], [-6, 0, -7], [-10, -4, 8], [-2, 6, 4], [-6, 8, 2]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[-9, 3, 5], [-2, 8, 6], [1, 7, 8], [-4, 3, 4], [1, -6, 10], [-5, -8, -13], [-4, 10, -8], [1, -2, -4], [7, 2, 9], [4, -4, 0], [8, -1, 2], [-6, 0, -7], [-10, -4, 8], [-2, 6, 4], [-6, 8, 2]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:4", + "sat": "def sat(zero_sums: List[bool], trips=[[7, -10, -3], [2, 9, 11], [-3, -10, -1], [-10, -5, 2], [-4, -5, -9], [-10, 5, -5], [1, 7, -6], [-3, -9, -12], [-5, -2, -7], [8, 10, 2], [-5, -2, 0], [-1, -6, -7], [8, 6, 2], [-8, 0, 7], [5, -5, 10], [-8, -6, -1], [-1, 1, 0], [-10, 9, -7]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[7, -10, -3], [2, 9, 11], [-3, -10, -1], [-10, -5, 2], [-4, -5, -9], [-10, 5, -5], [1, 7, -6], [-3, -9, -12], [-5, -2, -7], [8, 10, 2], [-5, -2, 0], [-1, -6, -7], [8, 6, 2], [-8, 0, 7], [5, -5, 10], [-8, -6, -1], [-1, 1, 0], [-10, 9, -7]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:0", + "sat": "def sat(s: str, target=\"Hello, world!\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:1", + "sat": "def sat(s: str, target=\"This is a good test\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"This is a good test\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:2", + "sat": "def sat(s: str, target=\"\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:3", + "sat": "def sat(s: str, target=\"That last test was a bad test!\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"That last test was a bad test!\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:4", + "sat": "def sat(s: str, target=\"pneumonoultramicroscopicsilicovolanoconiosis\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"pneumonoultramicroscopicsilicovolanoconiosis\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:0", + "sat": "def sat(ans: List[int], nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:1", + "sat": "def sat(ans: List[int], nums=[84545, 52, 5755523, 666, 1984, 97315, 7, 3, 789, 427]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[84545, 52, 5755523, 666, 1984, 97315, 7, 3, 789, 427]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:2", + "sat": "def sat(ans: List[int], nums=[5, 7151804, 432154, 5700, 9, 8, 253, 29062, 960, 721]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[5, 7151804, 432154, 5700, 9, 8, 253, 29062, 960, 721]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:3", + "sat": "def sat(ans: List[int], nums=[233804, 41, 6149533, 79, 956, 317909, 8628, 248, 35086, 79]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[233804, 41, 6149533, 79, 956, 317909, 8628, 248, 35086, 79]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:4", + "sat": "def sat(ans: List[int], nums=[87, 2, 2883, 32665, 26115, 32, 77, 97, 717, 674175]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[87, 2, 2883, 32665, 26115, 32, 77, 97, 717, 674175]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "OddCase:0", + "sat": "def sat(different: str, d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "OddCase:1", + "sat": "def sat(different: str, d={'den': 'fymehihyxuro', 'madufitextuthohyv': 'sofekuhepokosixyzoza', 'xechygo': 'kythubehuzagu', 'xukefulete': 'hugevybelypyrer', 'maw': 'vaveraral', 'hichaquidyto': 'quisi', 'remenidasohijetybah': 'bukomegewisevoxoz', 'kyte': 'fonecohynipesewyth', 'cax': 'bilesequ', 'caduquetextan': 'juzedabaz', 'THEMITOTH': 'xotugythuzu'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'den': 'fymehihyxuro', 'madufitextuthohyv': 'sofekuhepokosixyzoza', 'xechygo': 'kythubehuzagu', 'xukefulete': 'hugevybelypyrer', 'maw': 'vaveraral', 'hichaquidyto': 'quisi', 'remenidasohijetybah': 'bukomegewisevoxoz', 'kyte': 'fonecohynipesewyth', 'cax': 'bilesequ', 'caduquetextan': 'juzedabaz', 'THEMITOTH': 'xotugythuzu'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "OddCase:2", + "sat": "def sat(different: str, d={'CHIRATICHUHUQUYZYPYW': 'kopakyquotyhaquome', 'QUEBYTEXTEXUROBEK': 'tituxa', 'ZUVU': 'xupovutexti', 'NATEXTESYTUBUMY': 'ponusewaquufot', 'THUK': 'gyvy', 'CETEXTOFENAXIXANEKA': 'xyjytextecywykoquo', 'SEKAMIWEHYTHYTEXTUCU': 'jehu', 'H': 'quicyquohofowejivun', 'KYTEXTIBAXUTAV': 'nygutextin', 'LYQUA': 'biruji', 'tizenyry': 'xavyquukoc'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'CHIRATICHUHUQUYZYPYW': 'kopakyquotyhaquome', 'QUEBYTEXTEXUROBEK': 'tituxa', 'ZUVU': 'xupovutexti', 'NATEXTESYTUBUMY': 'ponusewaquufot', 'THUK': 'gyvy', 'CETEXTOFENAXIXANEKA': 'xyjytextecywykoquo', 'SEKAMIWEHYTHYTEXTUCU': 'jehu', 'H': 'quicyquohofowejivun', 'KYTEXTIBAXUTAV': 'nygutextin', 'LYQUA': 'biruji', 'tizenyry': 'xavyquukoc'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "OddCase:3", + "sat": "def sat(different: str, d={'CHEWA': 'geratenegafa', 'WATHYHUVOTEXTINO': 'th', 'DIFUS': 'zetextatasohunibathe', 'TUBEZA': 'rajytextar', 'NEZALEQUAZAHEKAGUPU': 'bequexucoxy', 'SEBOLIZEDUL': 'wyxufyhodymube', 'ZU': 'conuhywumychogije', 'DE': 'lebemypovoke', 'DEBURUGINOC': 'gequilithyjyvymufi', 'TEXTURAFA': 'textejesyko', 'rixechy': 'fate'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'CHEWA': 'geratenegafa', 'WATHYHUVOTEXTINO': 'th', 'DIFUS': 'zetextatasohunibathe', 'TUBEZA': 'rajytextar', 'NEZALEQUAZAHEKAGUPU': 'bequexucoxy', 'SEBOLIZEDUL': 'wyxufyhodymube', 'ZU': 'conuhywumychogije', 'DE': 'lebemypovoke', 'DEBURUGINOC': 'gequilithyjyvymufi', 'TEXTURAFA': 'textejesyko', 'rixechy': 'fate'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "OddCase:4", + "sat": "def sat(different: str, d={'quicaboguc': 'su', 'sacylir': 'tholubakypynythiryr', 'vijuchox': 'matextyquorewetytefy', 'lechi': 'nuch', 'viz': 'cheferopa', 'textowikalihehupyxi': 'quuchonasufexi', 'wuhujasi': 'f', 'tytextedoma': 'zifehabumabocate', 'gaviquolaxagihisice': 'sulywuzoquo', 'muvequo': 'juxachameje', 'B': 'quanesyfeku'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'quicaboguc': 'su', 'sacylir': 'tholubakypynythiryr', 'vijuchox': 'matextyquorewetytefy', 'lechi': 'nuch', 'viz': 'cheferopa', 'textowikalihehupyxi': 'quuchonasufexi', 'wuhujasi': 'f', 'tytextedoma': 'zifehabumabocate', 'gaviquolaxagihisice': 'sulywuzoquo', 'muvequo': 'juxachameje', 'B': 'quanesyfeku'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:0", + "sat": "def sat(primes: List[int], n=1234):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=1234):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:1", + "sat": "def sat(primes: List[int], n=10):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=10):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:2", + "sat": "def sat(primes: List[int], n=1000):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=1000):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:3", + "sat": "def sat(primes: List[int], n=-1):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=-1):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:4", + "sat": "def sat(primes: List[int], n=10000):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=10000):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "UnitsProduct:0", + "sat": "def sat(prod: int, nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UnitsProduct:1", + "sat": "def sat(prod: int, nums=[1, 9, 96, 79, 86, -30, -33, 63, 39, 35]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[1, 9, 96, 79, 86, -30, -33, 63, 39, 35]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UnitsProduct:2", + "sat": "def sat(prod: int, nums=[-29, -50, -4, 79, 2, 19, 34, 9, 27, -42]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[-29, -50, -4, 79, 2, 19, 34, 9, 27, -42]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UnitsProduct:3", + "sat": "def sat(prod: int, nums=[-28, -34, 90, 0, -38, -39, -13, 13, 56, 50]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[-28, -34, 90, 0, -38, -39, -13, 13, 56, 50]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UnitsProduct:4", + "sat": "def sat(prod: int, nums=[81, 36, -53, 17, 40, -30, -20, 13, -16, -18]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[81, 36, -53, 17, 40, -30, -20, 13, -16, -18]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UppercaseEven:0", + "sat": "def sat(positions: List[int], s=\"ThIs is A tEsT, Or *IS* iT?\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"ThIs is A tEsT, Or *IS* iT?\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "UppercaseEven:1", + "sat": "def sat(positions: List[int], s=\"j\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"j\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "UppercaseEven:2", + "sat": "def sat(positions: List[int], s=\"FYZuLOLYcoduHUSA\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"FYZuLOLYcoduHUSA\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "UppercaseEven:3", + "sat": "def sat(positions: List[int], s=\"vEWUquyCo\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"vEWUquyCo\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "UppercaseEven:4", + "sat": "def sat(positions: List[int], s=\"JUtARefAzeVyruJEvAKy\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"JUtARefAzeVyruJEvAKy\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "ClosestInteger:0", + "sat": "def sat(n: int, x=329437923.5):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=329437923.5):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "ClosestInteger:1", + "sat": "def sat(n: int, x=3557710970.9527555):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=3557710970.9527555):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "ClosestInteger:2", + "sat": "def sat(n: int, x=-250406.87146656853):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=-250406.87146656853):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "ClosestInteger:3", + "sat": "def sat(n: int, x=346686.79646634863):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=346686.79646634863):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "ClosestInteger:4", + "sat": "def sat(n: int, x=1087254.523941833):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=1087254.523941833):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "StonePiles:0", + "sat": "def sat(li: List[int], n=909):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=909):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "StonePiles:1", + "sat": "def sat(li: List[int], n=28694):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=28694):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "StonePiles:2", + "sat": "def sat(li: List[int], n=97916):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=97916):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "StonePiles:3", + "sat": "def sat(li: List[int], n=57991):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=57991):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "StonePiles:4", + "sat": "def sat(li: List[int], n=24997):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=24997):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "CompleteSplit:0", + "sat": "def sat(splits: List[List[str]], string=\"Hello, world! You look like you're on turtles.\"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\"Hello, world! You look like you're on turtles.\"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "CompleteSplit:1", + "sat": "def sat(splits: List[List[str]], string=\" This is a valley, so, so so,,,,\"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\" This is a valley, so, so so,,,,\"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "CompleteSplit:2", + "sat": "def sat(splits: List[List[str]], string=\"\"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\"\"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "CompleteSplit:3", + "sat": "def sat(splits: List[List[str]], string=\" ,,,,, , , \"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\" ,,,,, , , \"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "CompleteSplit:4", + "sat": "def sat(splits: List[List[str]], string=\"Do not worry\\nabout newlines\\n!\"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\"Do not worry\\nabout newlines\\n!\"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "BiggestEven:0", + "sat": "def sat(x: int, a=145, b=24126846790974):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=145, b=24126846790974):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BiggestEven:1", + "sat": "def sat(x: int, a=17, b=17):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=17, b=17):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BiggestEven:2", + "sat": "def sat(x: int, a=-10, b=-6):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=-10, b=-6):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BiggestEven:3", + "sat": "def sat(x: int, a=100, b=84):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=100, b=84):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BiggestEven:4", + "sat": "def sat(x: int, a=0, b=323523571223):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=0, b=323523571223):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BinaryAverage:0", + "sat": "def sat(s: str, a=-103252, b=10657):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=-103252, b=10657):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "BinaryAverage:1", + "sat": "def sat(s: str, a=70421, b=70421):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=70421, b=70421):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "BinaryAverage:2", + "sat": "def sat(s: str, a=-10299, b=-10300):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=-10299, b=-10300):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "BinaryAverage:3", + "sat": "def sat(s: str, a=0, b=52):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=0, b=52):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "BinaryAverage:4", + "sat": "def sat(s: str, a=-89, b=0):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=-89, b=0):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "SortedOdds:0", + "sat": "def sat(sub: List[int], nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "SortedOdds:1", + "sat": "def sat(sub: List[int], nums=[57463, -919281, 3293, 346, 319386, 14840, -423, 8892, 4689075, -4526385, 5889, 1226706, -5422, 7630106, 74198, 7835, 1050438, 602897]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[57463, -919281, 3293, 346, 319386, 14840, -423, 8892, 4689075, -4526385, 5889, 1226706, -5422, 7630106, 74198, 7835, 1050438, 602897]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "SortedOdds:2", + "sat": "def sat(sub: List[int], nums=[0, 7888, -1156983, 67, -304732, 128, -5391, 0, 468568]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[0, 7888, -1156983, 67, -304732, 128, -5391, 0, 468568]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "SortedOdds:3", + "sat": "def sat(sub: List[int], nums=[630253, -40, -8050056, -18536, 5847702, -90469, 290800, 0, -1431502, -5837, -945, 97582, 8673, 2729]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[630253, -40, -8050056, -18536, 5847702, -90469, 290800, 0, -1431502, -5837, -945, 97582, 8673, 2729]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "SortedOdds:4", + "sat": "def sat(sub: List[int], nums=[]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:0", + "sat": "def sat(backwards_digits: List[str], nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:1", + "sat": "def sat(backwards_digits: List[str], nums=[98, -3]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[98, -3]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:2", + "sat": "def sat(backwards_digits: List[str], nums=[22, 5, 27, 10, 70, 9, 82, -5, 30, 51, 10, 0, 48]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[22, 5, 27, 10, 70, 9, 82, -5, 30, 51, 10, 0, 48]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:3", + "sat": "def sat(backwards_digits: List[str], nums=[-5, -3, 9, 1, 93, -1, 4]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[-5, -3, 9, 1, 93, -1, 4]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:4", + "sat": "def sat(backwards_digits: List[str], nums=[-1, 3, 75, 86, 70, -5, 31, 5, 62, 6, 92, 60, 29, 5, 7, 3]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[-1, 3, 75, 86, 70, -5, 31, 5, 62, 6, 92, 60, 29, 5, 7, 3]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:0", + "sat": "def sat(li: List[int], n=100):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=100):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:1", + "sat": "def sat(li: List[int], n=997):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=997):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:2", + "sat": "def sat(li: List[int], n=825):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=825):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:3", + "sat": "def sat(li: List[int], n=267):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=267):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:4", + "sat": "def sat(li: List[int], n=576):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=576):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:0", + "sat": "def sat(pals: List[int], n=1099, count=49):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=1099, count=49):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:1", + "sat": "def sat(pals: List[int], n=2737, count=56):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=2737, count=56):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:2", + "sat": "def sat(pals: List[int], n=7895, count=79):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=7895, count=79):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:3", + "sat": "def sat(pals: List[int], n=2645, count=55):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=2645, count=55):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:4", + "sat": "def sat(pals: List[int], n=3173, count=59):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=3173, count=59):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:0", + "sat": "def sat(pos: List[int], nums=[-804, 9124, -945, 2410, 0, 21, -123]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-804, 9124, -945, 2410, 0, 21, -123]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:1", + "sat": "def sat(pos: List[int], nums=[3885, -46840, -82208, 35161, -84028]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[3885, -46840, -82208, 35161, -84028]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:2", + "sat": "def sat(pos: List[int], nums=[42550, -7024, -90058]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[42550, -7024, -90058]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:3", + "sat": "def sat(pos: List[int], nums=[39739, -37931, -68285, -32414]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[39739, -37931, -68285, -32414]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:4", + "sat": "def sat(pos: List[int], nums=[26162, -47643, -37426]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[26162, -47643, -37426]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "RotateSort:0", + "sat": "def sat(original: List[int], arr=[2, 3, -1, -1, 0, 1, 1]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[2, 3, -1, -1, 0, 1, 1]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateSort:1", + "sat": "def sat(original: List[int], arr=[2, 3, 3, 5, 6, 0]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[2, 3, 3, 5, 6, 0]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateSort:2", + "sat": "def sat(original: List[int], arr=[3, 5]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[3, 5]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateSort:3", + "sat": "def sat(original: List[int], arr=[3, 7, 3, 6, 6, 8, 9, 0, 0, 1]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[3, 7, 3, 6, 6, 8, 9, 0, 0, 1]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateSort:4", + "sat": "def sat(original: List[int], arr=[3, 2, 6, 7, 7, 8, 3]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[3, 2, 6, 7, 7, 8, 3]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "ParityExchange:0", + "sat": "def sat(swaps: List[List[int]], nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "ParityExchange:1", + "sat": "def sat(swaps: List[List[int]], nums1=[-4, -8, -10, -6, 0, -3, -7, 5], nums2=[-6, 6, -8, -7, -7]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[-4, -8, -10, -6, 0, -3, -7, 5], nums2=[-6, 6, -8, -7, -7]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "ParityExchange:2", + "sat": "def sat(swaps: List[List[int]], nums1=[8, -5, -4], nums2=[3, 1, 4, -3, 5, 7]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[8, -5, -4], nums2=[3, 1, 4, -3, 5, 7]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "ParityExchange:3", + "sat": "def sat(swaps: List[List[int]], nums1=[-8, -6], nums2=[9, -4, 0, 9, -6, -5, -4, 3, -3]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[-8, -6], nums2=[9, -4, 0, 9, -6, -5, -4, 3, -3]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "ParityExchange:4", + "sat": "def sat(swaps: List[List[int]], nums1=[-6, -2, 8, -4, -8, 0, 8, -3, 8], nums2=[0]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[-6, -2, 8, -4, -8, 0, 8, -3, 8], nums2=[0]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "CharCounts:0", + "sat": "def sat(s: str, counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "CharCounts:1", + "sat": "def sat(s: str, counts={'z': 0, 'e': 0, 'd': 7, 'o': 3, 'y': 8, 'w': 3, 'a': 0}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'z': 0, 'e': 0, 'd': 7, 'o': 3, 'y': 8, 'w': 3, 'a': 0}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "CharCounts:2", + "sat": "def sat(s: str, counts={'s': 8, 'z': 6, 'd': 1, 'o': 6}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'s': 8, 'z': 6, 'd': 1, 'o': 6}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "CharCounts:3", + "sat": "def sat(s: str, counts={'c': 5, 'p': 6, 'j': 0, 'g': 1, 'w': 4, 'k': 8}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'c': 5, 'p': 6, 'j': 0, 'g': 1, 'w': 4, 'k': 8}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "CharCounts:4", + "sat": "def sat(s: str, counts={'c': 2}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'c': 2}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "DelPalindrome:0", + "sat": "def sat(strings: List[str], a=\"this is a test\", b=\"cat\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"this is a test\", b=\"cat\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "DelPalindrome:1", + "sat": "def sat(strings: List[str], a=\"vochemogogajesuxujefobemenepejyquizys\", b=\"te\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"vochemogogajesuxujefobemenepejyquizys\", b=\"te\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "DelPalindrome:2", + "sat": "def sat(strings: List[str], a=\"tagodecequyzafiwathegothatymuzabegelelathe\", b=\"wululizokiwa\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"tagodecequyzafiwathegothatymuzabegelelathe\", b=\"wululizokiwa\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "DelPalindrome:3", + "sat": "def sat(strings: List[str], a=\"sipylovegubequagujete\", b=\"doh\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"sipylovegubequagujete\", b=\"doh\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "DelPalindrome:4", + "sat": "def sat(strings: List[str], a=\"fodivahug\", b=\"ne\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"fodivahug\", b=\"ne\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "ReplaceMe:0", + "sat": "def sat(answers: List[str], lst=['234515', '21503', '2506236943']):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=['234515', '21503', '2506236943']):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "ReplaceMe:1", + "sat": "def sat(answers: List[str], lst=['56', '0']):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=['56', '0']):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "ReplaceMe:2", + "sat": "def sat(answers: List[str], lst=[]):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=[]):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "ReplaceMe:3", + "sat": "def sat(answers: List[str], lst=['767', '5707']):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=['767', '5707']):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "ReplaceMe:4", + "sat": "def sat(answers: List[str], lst=['856']):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=['856']):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:0", + "sat": "def sat(start_end: List[int], base=7, p=50741, upper=-4897754):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=7, p=50741, upper=-4897754):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:1", + "sat": "def sat(start_end: List[int], base=1706, p=2004, upper=-14268):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=1706, p=2004, upper=-14268):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:2", + "sat": "def sat(start_end: List[int], base=4595, p=7106, upper=-193758):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=4595, p=7106, upper=-193758):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:3", + "sat": "def sat(start_end: List[int], base=1181, p=2664, upper=-102305):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=1181, p=2664, upper=-102305):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:4", + "sat": "def sat(start_end: List[int], base=7160, p=7736, upper=-35852):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=7160, p=7736, upper=-35852):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "Buckets:0", + "sat": "def sat(wells: List[List[List[int]]], grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "Buckets:1", + "sat": "def sat(wells: List[List[List[int]]], grid=[[1, 0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1, 1], [0, 1, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 0, 0]], capacity=6):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[1, 0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1, 1], [0, 1, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 0, 0]], capacity=6):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "Buckets:2", + "sat": "def sat(wells: List[List[List[int]]], grid=[[0], [1]], capacity=7):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[0], [1]], capacity=7):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "Buckets:3", + "sat": "def sat(wells: List[List[List[int]]], grid=[[0, 0, 1, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 1, 0], [0, 1, 0, 1, 0, 1, 1, 0, 0]], capacity=5):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[0, 0, 1, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 1, 0], [0, 1, 0, 1, 0, 1, 1, 0, 0]], capacity=5):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "Buckets:4", + "sat": "def sat(wells: List[List[List[int]]], grid=[[0, 1], [1, 0], [1, 1], [1, 0], [1, 1]], capacity=9):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[0, 1], [1, 0], [1, 1], [1, 0], [1, 1]], capacity=9):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "BinarySort:0", + "sat": "def sat(ordered: List[int], arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "BinarySort:1", + "sat": "def sat(ordered: List[int], arr=[19, 47, -51, 40, 6, 0, 41, 57, 13, 16, -27, 7]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[19, 47, -51, 40, 6, 0, 41, 57, 13, 16, -27, 7]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "BinarySort:2", + "sat": "def sat(ordered: List[int], arr=[62, 63, 1]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[62, 63, 1]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "BinarySort:3", + "sat": "def sat(ordered: List[int], arr=[-9, -78, -17, 42, 85, 79, 61]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[-9, -78, -17, 42, 85, 79, 61]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "BinarySort:4", + "sat": "def sat(ordered: List[int], arr=[-65, -6, 82, -85, -84, 97, 55, 54]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[-65, -6, 82, -85, -84, 97, 55, 54]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:0", + "sat": "def sat(words: List[str], s=\"This is not a very hard puzzle\", n=3):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"This is not a very hard puzzle\", n=3):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:1", + "sat": "def sat(words: List[str], s=\"xopike tha textufuzowapa xaxiweborite dutextequuch metojylucazasysebi wy\", n=5):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"xopike tha textufuzowapa xaxiweborite dutextequuch metojylucazasysebi wy\", n=5):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:2", + "sat": "def sat(words: List[str], s=\"tihyc pydykosisaroquicoc text\", n=6):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"tihyc pydykosisaroquicoc text\", n=6):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:3", + "sat": "def sat(words: List[str], s=\"chalejugedijypiq jypityvekifate mobekolupumymikana quaxizot vurikojithokasatuka teragusaculi vyceth dachaci wu\", n=1):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"chalejugedijypiq jypityvekifate mobekolupumymikana quaxizot vurikojithokasatuka teragusaculi vyceth dachaci wu\", n=1):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:4", + "sat": "def sat(words: List[str], s=\"thigafamyhuchykikoxe limyb wy textitextomyc regolathagychiby pep\", n=2):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"thigafamyhuchykikoxe limyb wy textitextomyc regolathagychiby pep\", n=2):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "VowelSandwich:0", + "sat": "def sat(ham: str, s=\"Any vowel is OK\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"Any vowel is OK\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "VowelSandwich:1", + "sat": "def sat(ham: str, s=\"wOwwwww!\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"wOwwwww!\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "VowelSandwich:2", + "sat": "def sat(ham: str, s=\"do pyp you know ?\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"do pyp you know ?\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "VowelSandwich:3", + "sat": "def sat(ham: str, s=\"zocofiwihilyfizi ku pivanydebodygawepu nyfanusocosypinezaz pune\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"zocofiwihilyfizi ku pivanydebodygawepu nyfanusocosypinezaz pune\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "VowelSandwich:4", + "sat": "def sat(ham: str, s=\"citextitozuwatextoq hutextawicogylalex wi wamu\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"citextitozuwatextoq hutextawicogylalex wi wamu\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:0", + "sat": "def sat(perm: str, s=\"))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( ((((((((((\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\"))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( ((((((((((\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:1", + "sat": "def sat(perm: str, s=\" (( ()(())())() ())(())))(()()) (((((((()(()))(( ()()))) )())))) ()()()(((())()\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\" (( ()(())())() ())(())))(()()) (((((((()(()))(( ()()))) )())))) ()()()(((())()\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:2", + "sat": "def sat(perm: str, s=\"()()(( ))\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\"()()(( ))\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:3", + "sat": "def sat(perm: str, s=\"\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\"\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:4", + "sat": "def sat(perm: str, s=\"()(()())( )()\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\"()(()())( )()\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "BiggestK:0", + "sat": "def sat(biggest: List[int], k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "BiggestK:1", + "sat": "def sat(biggest: List[int], k=3, nums=[-5, 30, 31, 32, 30, 93, 97]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=3, nums=[-5, 30, 31, 32, 30, 93, 97]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "BiggestK:2", + "sat": "def sat(biggest: List[int], k=2, nums=[75, 30, 53, 25, 14]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=2, nums=[75, 30, 53, 25, 14]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "BiggestK:3", + "sat": "def sat(biggest: List[int], k=1, nums=[-6, 9, 36, 36, 99, 66, 41, 38, 11, 61]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=1, nums=[-6, 9, 36, 36, 99, 66, 41, 38, 11, 61]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "BiggestK:4", + "sat": "def sat(biggest: List[int], k=2, nums=[4, 65, 52, 41, 21, 0, 45, 71]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=2, nums=[4, 65, 52, 41, 21, 0, 45, 71]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "OddEvenSum:0", + "sat": "def sat(tot: int, nums=[18, 42152, 125023521, -1221873620123, 17, 19]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[18, 42152, 125023521, -1221873620123, 17, 19]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "OddEvenSum:1", + "sat": "def sat(tot: int, nums=[-52, 89, -74, -27]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-52, 89, -74, -27]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "OddEvenSum:2", + "sat": "def sat(tot: int, nums=[-95, -24, -50, -51, -18, -77, -61, 64, 7]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-95, -24, -50, -51, -18, -77, -61, 64, 7]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "OddEvenSum:3", + "sat": "def sat(tot: int, nums=[-85, -83, 62, -27, -37, -76, -10, 40, 34, -20]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-85, -83, 62, -27, -37, -76, -10, 40, 34, -20]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "OddEvenSum:4", + "sat": "def sat(tot: int, nums=[-11, -9, -29, 30, -70]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[-11, -9, -29, 30, -70]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "LongEarlySum:0", + "sat": "def sat(tot: int, k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "LongEarlySum:1", + "sat": "def sat(tot: int, k=5, nums=[-7157016423, 2782843150, 7219126112, -6508908448, -2700793649]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=5, nums=[-7157016423, 2782843150, 7219126112, -6508908448, -2700793649]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "LongEarlySum:2", + "sat": "def sat(tot: int, k=9, nums=[-5897482060, -6124803429, 460595384, -4038677051, 4034899461, 4374130613, -107107411]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=9, nums=[-5897482060, -6124803429, 460595384, -4038677051, 4034899461, 4374130613, -107107411]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "LongEarlySum:3", + "sat": "def sat(tot: int, k=9, nums=[-8188839170, -4196027936, 7189346049, -3904396164, -6197615761, -1925353242, 4455917604, -60399777, 2265288077, -5809369361, -1403148167, 4937241577, 6147738064, 2911928645, -3466247912]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=9, nums=[-8188839170, -4196027936, 7189346049, -3904396164, -6197615761, -1925353242, 4455917604, -60399777, 2265288077, -5809369361, -1403148167, 4937241577, 6147738064, 2911928645, -3466247912]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "LongEarlySum:4", + "sat": "def sat(tot: int, k=7, nums=[9205334525, 5459823374, -7169802732, 9865454706, -7321060937, 6045166493, 15149444, 1118638089, -4595115991, -3388779539]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=7, nums=[9205334525, 5459823374, -7169802732, 9865454706, -7321060937, 6045166493, 15149444, 1118638089, -4595115991, -3388779539]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "OddCollatz:0", + "sat": "def sat(odds: List[int], n=1243272912731):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=1243272912731):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "OddCollatz:1", + "sat": "def sat(odds: List[int], n=6969429614):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=6969429614):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "OddCollatz:2", + "sat": "def sat(odds: List[int], n=529):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=529):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "OddCollatz:3", + "sat": "def sat(odds: List[int], n=37):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=37):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "OddCollatz:4", + "sat": "def sat(odds: List[int], n=95119584):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=95119584):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "DateDiff:0", + "sat": "def sat(s: str, target=-2075):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=-2075):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "DateDiff:1", + "sat": "def sat(s: str, target=11):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=11):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "DateDiff:2", + "sat": "def sat(s: str, target=-30):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=-30):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "DateDiff:3", + "sat": "def sat(s: str, target=-1999):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=-1999):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "DateDiff:4", + "sat": "def sat(s: str, target=-10029):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=-10029):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "StrangeSplit:0", + "sat": "def sat(lst: List[str], s=\"Hello, world!\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "StrangeSplit:1", + "sat": "def sat(lst: List[str], s=\"Goodbye,spaces!\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"Goodbye,spaces!\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "StrangeSplit:2", + "sat": "def sat(lst: List[str], s=\"abcbcbbedfsgfakbfjghskbne[pewte\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"abcbcbbedfsgfakbfjghskbne[pewte\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "StrangeSplit:3", + "sat": "def sat(lst: List[str], s=\"wotekitex,textarinequo,do,machoki,balecethotuwy,jarynutextopimud,dethexifythuthyc\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"wotekitex,textarinequo,do,machoki,balecethotuwy,jarynutextopimud,dethexifythuthyc\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "StrangeSplit:4", + "sat": "def sat(lst: List[str], s=\"jitys py sepocedynechuhegu lekinihiluwefax\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"jitys py sepocedynechuhegu lekinihiluwefax\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:0", + "sat": "def sat(violation: List[int], nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:1", + "sat": "def sat(violation: List[int], nums=[10, 16, 19, 23, 25, 27, 27, 39, 39, 44, 52, 60, 64, 1, 92, 96]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[10, 16, 19, 23, 25, 27, 27, 39, 39, 44, 52, 60, 64, 1, 92, 96]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:2", + "sat": "def sat(violation: List[int], nums=[10, 10, 10, 11, 17, 22, 31, 35, 42, 48, 61, 75, 90, 92]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[10, 10, 10, 11, 17, 22, 31, 35, 42, 48, 61, 75, 90, 92]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:3", + "sat": "def sat(violation: List[int], nums=[5, 5, 84]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[5, 5, 84]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:4", + "sat": "def sat(violation: List[int], nums=[2, 5, 12, 40, 41, 47, 52, 53, 60, 46, 64, 66, 71]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2, 5, 12, 40, 41, 47, 52, 53, 60, 46, 64, 66, 71]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:0", + "sat": "def sat(interval2: List[int], interval1=[32157, 93210127]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[32157, 93210127]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:1", + "sat": "def sat(interval2: List[int], interval1=[-3367, 4628]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[-3367, 4628]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:2", + "sat": "def sat(interval2: List[int], interval1=[0, 2381571]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[0, 2381571]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:3", + "sat": "def sat(interval2: List[int], interval1=[0, 1867]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[0, 1867]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:4", + "sat": "def sat(interval2: List[int], interval1=[-9017, 9358096]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[-9017, 9358096]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "ProductSigns:0", + "sat": "def sat(n: int, arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "ProductSigns:1", + "sat": "def sat(n: int, arr=[13, 38, 57, 6, -79, 85, -96, 60, 45, 37, 66]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[13, 38, 57, 6, -79, 85, -96, 60, 45, 37, 66]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "ProductSigns:2", + "sat": "def sat(n: int, arr=[-58, -49, -56, 75, 52, -54, -95]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[-58, -49, -56, 75, 52, -54, -95]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "ProductSigns:3", + "sat": "def sat(n: int, arr=[-41, 67, -27, -41, 16, 1, 66, -91, 4, 36, 10, -95, 7, 54, -97, -87]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[-41, 67, -27, -41, 16, 1, 66, -91, 4, 36, 10, -95, 7, 54, -97, -87]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "ProductSigns:4", + "sat": "def sat(n: int, arr=[-62, 46, -83, -14]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[-62, 46, -83, -14]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "LexPath:0", + "sat": "def sat(path: List[int], k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "LexPath:1", + "sat": "def sat(path: List[int], k=12, edges=[[2, 1], [0], [1, 3, 0], [1, 0, 3]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=12, edges=[[2, 1], [0], [1, 3, 0], [1, 0, 3]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "LexPath:2", + "sat": "def sat(path: List[int], k=0, edges=[[2, 0], [0, 3, 1, 2], [3, 0, 1, 2], [1, 2]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=0, edges=[[2, 0], [0, 3, 1, 2], [3, 0, 1, 2], [1, 2]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "LexPath:3", + "sat": "def sat(path: List[int], k=14, edges=[[2], [2, 1, 0], [2, 1, 0]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=14, edges=[[2], [2, 1, 0], [2, 1, 0]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "LexPath:4", + "sat": "def sat(path: List[int], k=1, edges=[[2, 0, 3, 1], [3, 1], [2, 0, 1], [0]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=1, edges=[[2, 0, 3, 1], [3, 1], [2, 0, 1], [0]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "Tribonacci:0", + "sat": "def sat(seq: List[int], length=181):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=181):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "Tribonacci:1", + "sat": "def sat(seq: List[int], length=412):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=412):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "Tribonacci:2", + "sat": "def sat(seq: List[int], length=482):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=482):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "Tribonacci:3", + "sat": "def sat(seq: List[int], length=50):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=50):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "Tribonacci:4", + "sat": "def sat(seq: List[int], length=761):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=761):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "OddProduct:0", + "sat": "def sat(prod: int, n=14235764939971075543215213):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=14235764939971075543215213):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "OddProduct:1", + "sat": "def sat(prod: int, n=8502):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=8502):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "OddProduct:2", + "sat": "def sat(prod: int, n=95973):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=95973):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "OddProduct:3", + "sat": "def sat(prod: int, n=0):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "OddProduct:4", + "sat": "def sat(prod: int, n=331901673137376013):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=331901673137376013):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:0", + "sat": "def sat(valid: str, s=\"]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[[\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[[\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:1", + "sat": "def sat(valid: str, s=\"[[[[][][][][][][]][[]][]][[[][]][[]]\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"[[[[][][][][][][]][[]][]][[[][]][[]]\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:2", + "sat": "def sat(valid: str, s=\"]][[]][[][[[[][]]][[][[[][\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"]][[]][[][[[[][]]][[][[[][\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:3", + "sat": "def sat(valid: str, s=\"][]]][]][[[][][][][][][][]][[]][[]]][[\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"][]]][]][[[][][][][][][][]][[]][[]]][[\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:4", + "sat": "def sat(valid: str, s=\"[[[][][[[[[[]][[]][[[][][][][][][][][]][\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"[[[][][[[[[[]][[]][[[][][][][][][][][]][\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "CeilingSquares:0", + "sat": "def sat(running_squares: List[int], x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "CeilingSquares:1", + "sat": "def sat(running_squares: List[int], x=[9.650000588598111, -8.077324515062926, 2.649836251190308, 0.7153951297675469, -1.9181388431489204, 2.7112675102232675, -6.813543009125667, 7.029917456417941, -2.821293215347511]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[9.650000588598111, -8.077324515062926, 2.649836251190308, 0.7153951297675469, -1.9181388431489204, 2.7112675102232675, -6.813543009125667, 7.029917456417941, -2.821293215347511]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "CeilingSquares:2", + "sat": "def sat(running_squares: List[int], x=[-2.6340066467560996, 4.322176523433114, -1.5079841130054472, -8.985060763252859, -9.074227436202381]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[-2.6340066467560996, 4.322176523433114, -1.5079841130054472, -8.985060763252859, -9.074227436202381]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "CeilingSquares:3", + "sat": "def sat(running_squares: List[int], x=[8.257528417306844, -3.7315204726521944, 9.856438333047798, -7.228652980051451, -6.343263566703614, -2.5469735103334834, -3.2923884429492762, -2.991171802818804]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[8.257528417306844, -3.7315204726521944, 9.856438333047798, -7.228652980051451, -6.343263566703614, -2.5469735103334834, -3.2923884429492762, -2.991171802818804]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "CeilingSquares:4", + "sat": "def sat(running_squares: List[int], x=[6.608264692857215, -2.204391758043112, 3.8328091843913974, 4.122558586426074, 6.79452673601816, -1.8532801154281735, 6.207567645800566]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[6.608264692857215, -2.204391758043112, 3.8328091843913974, 4.122558586426074, 6.79452673601816, -1.8532801154281735, 6.207567645800566]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "LastLetters:0", + "sat": "def sat(y: List[bool], x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "LastLetters:1", + "sat": "def sat(y: List[bool], x=['bymuthuzuxanehun tuwugycyhewavazow 1', ' x', 'womavyra', 'nitex quufojythobubetexto e']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=['bymuthuzuxanehun tuwugycyhewavazow 1', ' x', 'womavyra', 'nitex quufojythobubetexto e']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "LastLetters:2", + "sat": "def sat(y: List[bool], x=[' D', '', 'xamywathozuch 6', 'zulopatextathusyro *', ' y', 'wuvoguthixytexte textydytoquizazuquyt', 'texta duthu [', 'zebozegifelutaxyquix cabach d', ' C', 'rodumelidet quutaquukythusyb', ' %', 'b (', 'kabezanolipesethyba dyvechikathuwi n', 'fyzotextyhukokydihuc 8', '', 'memadapuc y', 'thavajythysojecywut g', 'wekirevajezexyfitex j', '', 'sekytextyko C', 'pe sobekujodefypo', 'dyjagiko chyfin', ' v', 'nisytextinexochych ', '', 'ni', 'l zitufutachot R']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=[' D', '', 'xamywathozuch 6', 'zulopatextathusyro *', ' y', 'wuvoguthixytexte textydytoquizazuquyt', 'texta duthu [', 'zebozegifelutaxyquix cabach d', ' C', 'rodumelidet quutaquukythusyb', ' %', 'b (', 'kabezanolipesethyba dyvechikathuwi n', 'fyzotextyhukokydihuc 8', '', 'memadapuc y', 'thavajythysojecywut g', 'wekirevajezexyfitex j', '', 'sekytextyko C', 'pe sobekujodefypo', 'dyjagiko chyfin', ' v', 'nisytextinexochych ', '', 'ni', 'l zitufutachot R']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "LastLetters:3", + "sat": "def sat(y: List[bool], x=['ryxadec', 'pyfixotibujadyxe', 'mopubywewexi witethig 7', ' !', 'jethi sed c', 'lotextusavufubynyb', 'wuxesafetatextysima pebutextiwafufok', 'tuchonip', ' S', 'xyvovikofutex pylekazuquekedajota E', 'wik xofoxujegerigubo ?', 'gipimakude 1', ' O', ' ^', 'lakiquuvuhenugu vajyquy P', ' 6', 'fezore', 'vabithin textusichytilejocoke', ' B', 'lasuthasebuvy que &', 'mymanuzuzudyc thazufys y', '', ' ?', 'gecohywelawu', 'wath']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=['ryxadec', 'pyfixotibujadyxe', 'mopubywewexi witethig 7', ' !', 'jethi sed c', 'lotextusavufubynyb', 'wuxesafetatextysima pebutextiwafufok', 'tuchonip', ' S', 'xyvovikofutex pylekazuquekedajota E', 'wik xofoxujegerigubo ?', 'gipimakude 1', ' O', ' ^', 'lakiquuvuhenugu vajyquy P', ' 6', 'fezore', 'vabithin textusichytilejocoke', ' B', 'lasuthasebuvy que &', 'mymanuzuzudyc thazufys y', '', ' ?', 'gecohywelawu', 'wath']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "LastLetters:4", + "sat": "def sat(y: List[bool], x=['ribesaquotextytazech #', '', ' Y', 'tychawicemafethupi 3', 'laz kakumynohyw', 'quotextifethixyvo pofukixa l']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=['ribesaquotextytazech #', '', ' Y', 'tychawicemafethupi 3', 'laz kakumynohyw', 'quotextifethixyvo pofukixa l']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "Drops:0", + "sat": "def sat(drop_indexes: List[int], nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]):\n d = 0\n for i in range(1, len(nums)):\n if nums[i] < nums[i - 1]:\n assert drop_indexes[d] == i\n d += 1\n return d == len(drop_indexes)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]):", + "sol_docstring": " \"\"\"Find the indices for which the nums array drops.\n\n [1,2,3,0,2,4,1] => [3,6]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(1, len(nums)) if nums[i] < nums[i - 1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#135", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:0", + "sat": "def sat(extremes: List[int], nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:1", + "sat": "def sat(extremes: List[int], nums=[-566, -114, -971]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-566, -114, -971]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:2", + "sat": "def sat(extremes: List[int], nums=[-90, -123, 227, 905, 613, 735, 988, -215, -190, 272, -920, 581, 212, 317]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-90, -123, 227, 905, 613, 735, 988, -215, -190, 272, -920, 581, 212, 317]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:3", + "sat": "def sat(extremes: List[int], nums=[]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:4", + "sat": "def sat(extremes: List[int], nums=[-719, 922, 52, -861, 495, 327, -955, -301, -542, -257, -712]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-719, 922, 52, -861, 495, 327, -955, -301, -542, -257, -712]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestStringNum:0", + "sat": "def sat(x: float, str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "LargestStringNum:1", + "sat": "def sat(x: float, str_nums=['31.39683666368859', '73,72440474051831', '72.34060469647804', '73']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['31.39683666368859', '73,72440474051831', '72.34060469647804', '73']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "LargestStringNum:2", + "sat": "def sat(x: float, str_nums=['-6', '68', '-100', '42,449764091997196', '-29,24317717823544', '-41.15991554949425', '93.91903086808122', '-40', '95,64713000645497', '10.987133348617888', '-12', '-30', '-67.5420580170809', '58', '66,77819624303987', '-37.8232752327492', '8', '-99', '98']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['-6', '68', '-100', '42,449764091997196', '-29,24317717823544', '-41.15991554949425', '93.91903086808122', '-40', '95,64713000645497', '10.987133348617888', '-12', '-30', '-67.5420580170809', '58', '66,77819624303987', '-37.8232752327492', '8', '-99', '98']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "LargestStringNum:3", + "sat": "def sat(x: float, str_nums=['-13', '-9,405268331489253', '86,60853263788738', '1.6303719756540573', '25,638544353710756']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['-13', '-9,405268331489253', '86,60853263788738', '1.6303719756540573', '25,638544353710756']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "LargestStringNum:4", + "sat": "def sat(x: float, str_nums=['-100', '43', '12,380225941003388', '-10', '55', '40,34567619114577', '45', '-26,348841728512014', '-79.01130149535118', '48', '57', '-87', '24,13286574459906', '8', '57.12265333169756', '19,864244993734175', '24', '-82', '22']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['-100', '43', '12,380225941003388', '-10', '55', '40,34567619114577', '45', '-26,348841728512014', '-79.01130149535118', '48', '57', '-87', '24,13286574459906', '8', '57.12265333169756', '19,864244993734175', '24', '-82', '22']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "Even4Sum:0", + "sat": "def sat(summands: List[int], n=1234567890):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=1234567890):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "Even4Sum:1", + "sat": "def sat(summands: List[int], n=8):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=8):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "Even4Sum:2", + "sat": "def sat(summands: List[int], n=10):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=10):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "Even4Sum:3", + "sat": "def sat(summands: List[int], n=12):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=12):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "Even4Sum:4", + "sat": "def sat(summands: List[int], n=465665808):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=465665808):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:0", + "sat": "def sat(nums: List[int], super_factorials=[1, 2, 1]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[1, 2, 1]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:1", + "sat": "def sat(nums: List[int], super_factorials=[24883200, 288, 24883200, 1834933472251084800000, 125411328000, 5056584744960000, 2, 125411328000, 34560, 1834933472251084800000, 34560]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[24883200, 288, 24883200, 1834933472251084800000, 125411328000, 5056584744960000, 2, 125411328000, 34560, 1834933472251084800000, 34560]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:2", + "sat": "def sat(nums: List[int], super_factorials=[2, 2, 12, 2, 2, 1, 1834933472251084800000, 1, 24883200, 24883200, 1834933472251084800000]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[2, 2, 12, 2, 2, 1, 1834933472251084800000, 1, 24883200, 24883200, 1834933472251084800000]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:3", + "sat": "def sat(nums: List[int], super_factorials=[1, 1, 12, 2, 12, 12, 2, 2, 12, 2, 24883200]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[1, 1, 12, 2, 12, 12, 2, 2, 12, 2, 24883200]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:4", + "sat": "def sat(nums: List[int], super_factorials=[1, 125411328000, 34560, 288, 24883200, 1, 12, 2, 5056584744960000, 1834933472251084800000, 125411328000]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[1, 125411328000, 34560, 288, 24883200, 1, 12, 2, 5056584744960000, 1834933472251084800000, 125411328000]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:0", + "sat": "def sat(orig: str, target=\"-Hello,_world!__This_is-so-easy!-\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"-Hello,_world!__This_is-so-easy!-\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:1", + "sat": "def sat(orig: str, target=\"H-d\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"H-d\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:2", + "sat": "def sat(orig: str, target=\"\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:3", + "sat": "def sat(orig: str, target=\"H@zoxyquygupaxofirefavuvubadigwQ\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"H@zoxyquygupaxofirefavuvubadigwQ\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:4", + "sat": "def sat(orig: str, target=\"-O!6quag\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"-O!6quag\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "FilenameOK:0", + "sat": "def sat(valids: List[str], filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FilenameOK:1", + "sat": "def sat(valids: List[str], filenames=['mtherylP.exe', 'Qbatw.mp4', 'DtextadusypykagusakoA.exe', 'Bmigusocycyth].mp4', ')kutextulelucezyQ.tar.zip', 'nchelycozitixiM.exe', 'wrichevyxi.exe', 'Nvew0.txt', 'dnochofazehaxaharop!.dll', '8mefasechuxacyxg.txt', 'isijufotextydycifu3.mp4', 'vmithujydet[.mp4']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['mtherylP.exe', 'Qbatw.mp4', 'DtextadusypykagusakoA.exe', 'Bmigusocycyth].mp4', ')kutextulelucezyQ.tar.zip', 'nchelycozitixiM.exe', 'wrichevyxi.exe', 'Nvew0.txt', 'dnochofazehaxaharop!.dll', '8mefasechuxacyxg.txt', 'isijufotextydycifu3.mp4', 'vmithujydet[.mp4']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FilenameOK:2", + "sat": "def sat(valids: List[str], filenames=['WbytyjachuquithX.tar.zip', 'Pzuzuvetextr.mp4', 'Xcymem[.tar.zip', 'AhypagacheJ.dll', 'JbubefichiwyryzydochC.exe', '8te;.dll', 'wtextoL.mp4', 'mthowexezixexuqd.exe', '^nehapu4.txt', 'Hsovap].txt', 'Cchoxe>.tar.zip', '1quobejugichewabechek#.dll']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['WbytyjachuquithX.tar.zip', 'Pzuzuvetextr.mp4', 'Xcymem[.tar.zip', 'AhypagacheJ.dll', 'JbubefichiwyryzydochC.exe', '8te;.dll', 'wtextoL.mp4', 'mthowexezixexuqd.exe', '^nehapu4.txt', 'Hsovap].txt', 'Cchoxe>.tar.zip', '1quobejugichewabechek#.dll']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FilenameOK:3", + "sat": "def sat(valids: List[str], filenames=['+thunidothytextofi..txt', 'Onithytemolysefel$.mp4', 'Clychifopozesuxijuvo.mp4']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['+thunidothytextofi..txt', 'Onithytemolysefel$.mp4', 'Clychifopozesuxijuvo.mp4']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FilenameOK:4", + "sat": "def sat(valids: List[str], filenames=['XsiwemunarytextatecY.exe', 'Dfanachofegerevojyv].dll', ')pethymula0.exe', '4dihurudyjahatextov.exe', '0hyxZ.tar.zip', 'WbywithachoxenomeW.mp4', 'rniworatuzepatapuy.txt', '6quypucocj.exe', 'Zmavifolulitek.txt', 'ywue.exe', 'QhI.txt', ')vugu^.mp4', 'ygihycogaduhalyfyzen.tar.zip', 'icubonaguchegupejuha(.exe', ']gothusodawinuwidinexD.mp4', ' wyw(.exe']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['XsiwemunarytextatecY.exe', 'Dfanachofegerevojyv].dll', ')pethymula0.exe', '4dihurudyjahatextov.exe', '0hyxZ.tar.zip', 'WbywithachoxenomeW.mp4', 'rniworatuzepatapuy.txt', '6quypucocj.exe', 'Zmavifolulitek.txt', 'ywue.exe', 'QhI.txt', ')vugu^.mp4', 'ygihycogaduhalyfyzen.tar.zip', 'icubonaguchegupejuha(.exe', ']gothusodawinuwidinexD.mp4', ' wyw(.exe']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:0", + "sat": "def sat(lst: List[int], tot=1125181293221):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=1125181293221):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:1", + "sat": "def sat(lst: List[int], tot=704):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=704):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:2", + "sat": "def sat(lst: List[int], tot=8849):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=8849):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:3", + "sat": "def sat(lst: List[int], tot=-516784):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=-516784):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:4", + "sat": "def sat(lst: List[int], tot=976643993):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=976643993):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "PrimeWords:0", + "sat": "def sat(primes: str, s=\"This is a test of whether you would want to do such strange puzzles\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"This is a test of whether you would want to do such strange puzzles\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "PrimeWords:1", + "sat": "def sat(primes: str, s=\"t quiquitutohetextyvod thacycotextilequa thavow rygo q xythejixojubuz jufutozozat cabuthymuchyji\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"t quiquitutohetextyvod thacycotextilequa thavow rygo q xythejixojubuz jufutozozat cabuthymuchyji\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "PrimeWords:2", + "sat": "def sat(primes: str, s=\"caquovovich keguqu tatextuhok jajabyv kibatextuchisimoz xibe sotext s helalewipixemujiwixa\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"caquovovich keguqu tatextuhok jajabyv kibatextuchisimoz xibe sotext s helalewipixemujiwixa\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "PrimeWords:3", + "sat": "def sat(primes: str, s=\"\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "PrimeWords:4", + "sat": "def sat(primes: str, s=\"sidathochocek qualodu thugolo wywyfykyxyhewyjapeke matofamep n wemahu pesethimine\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"sidathochocek qualodu thugolo wywyfykyxyhewyjapeke matofamep n wemahu pesethimine\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:0", + "sat": "def sat(z: str, x=\"-8142432/763083\", y=\"66/-13474\", max_len=18):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"-8142432/763083\", y=\"66/-13474\", max_len=18):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:1", + "sat": "def sat(z: str, x=\"0/47460\", y=\"357/8389715\", max_len=3):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"0/47460\", y=\"357/8389715\", max_len=3):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:2", + "sat": "def sat(z: str, x=\"-20/-54383610\", y=\"7865/34\", max_len=13):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"-20/-54383610\", y=\"7865/34\", max_len=13):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:3", + "sat": "def sat(z: str, x=\"0/2\", y=\"79/45361\", max_len=3):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"0/2\", y=\"79/45361\", max_len=3):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:4", + "sat": "def sat(z: str, x=\"1316/-4820197\", y=\"0/28968\", max_len=3):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"1316/-4820197\", y=\"0/28968\", max_len=3):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:0", + "sat": "def sat(ordered: List[int], nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:1", + "sat": "def sat(ordered: List[int], nums=[-222, -896, 914, 817]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-222, -896, 914, 817]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:2", + "sat": "def sat(ordered: List[int], nums=[208]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[208]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:3", + "sat": "def sat(ordered: List[int], nums=[]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:4", + "sat": "def sat(ordered: List[int], nums=[232, -710]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[232, -710]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "BigOdds:0", + "sat": "def sat(odds: List[int], nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "BigOdds:1", + "sat": "def sat(odds: List[int], nums=[13559]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[13559]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "BigOdds:2", + "sat": "def sat(odds: List[int], nums=[12320, 771, 11224, 17261]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12320, 771, 11224, 17261]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "BigOdds:3", + "sat": "def sat(odds: List[int], nums=[13251, 8503, 5595, 19712, 10196, 16271]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[13251, 8503, 5595, 19712, 10196, 16271]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "BigOdds:4", + "sat": "def sat(odds: List[int], nums=[]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "Threeples:0", + "sat": "def sat(trips: List[List[int]], a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "Threeples:1", + "sat": "def sat(trips: List[List[int]], a=[8, 5, 9, 3, 3, 9, 2, 6, 6, 0, 8, 0, 3, 2, 5, 2, 3, -1, 6], count=221):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[8, 5, 9, 3, 3, 9, 2, 6, 6, 0, 8, 0, 3, 2, 5, 2, 3, -1, 6], count=221):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "Threeples:2", + "sat": "def sat(trips: List[List[int]], a=[6, 5, 3, 0, 1, 9, 7, 6, 6, 7, 6, 8, 4, -1, 0, 3, 6, 7, 5, 3], count=399):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[6, 5, 3, 0, 1, 9, 7, 6, 6, 7, 6, 8, 4, -1, 0, 3, 6, 7, 5, 3], count=399):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "Threeples:3", + "sat": "def sat(trips: List[List[int]], a=[6, 3, 5, -1, 8, 8], count=4):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[6, 3, 5, -1, 8, 8], count=4):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "Threeples:4", + "sat": "def sat(trips: List[List[int]], a=[7], count=0):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[7], count=0):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "PlanetRange:0", + "sat": "def sat(planets_between: List[str], a=\"Mars\", b=\"Neptune\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Mars\", b=\"Neptune\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "PlanetRange:1", + "sat": "def sat(planets_between: List[str], a=\"Venus\", b=\"Neptune\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Venus\", b=\"Neptune\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "PlanetRange:2", + "sat": "def sat(planets_between: List[str], a=\"Venus\", b=\"Earth\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Venus\", b=\"Earth\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "PlanetRange:3", + "sat": "def sat(planets_between: List[str], a=\"Earth\", b=\"Jupiter\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Earth\", b=\"Jupiter\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "PlanetRange:4", + "sat": "def sat(planets_between: List[str], a=\"Earth\", b=\"Uranus\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Earth\", b=\"Uranus\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "EvenWords:0", + "sat": "def sat(evens: List[str], words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "EvenWords:1", + "sat": "def sat(evens: List[str], words=['valafytextulu', 'quyjylixyvy', 'mavusegojysaquo']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['valafytextulu', 'quyjylixyvy', 'mavusegojysaquo']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "EvenWords:2", + "sat": "def sat(evens: List[str], words=['pemathubolyrav', 'mucyxavofolajig', 'm', 'zyzagynorusybef']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['pemathubolyrav', 'mucyxavofolajig', 'm', 'zyzagynorusybef']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "EvenWords:3", + "sat": "def sat(evens: List[str], words=['bozachogawykon', 'kywicij', 'tylegykivysequ']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['bozachogawykon', 'kywicij', 'tylegykivysequ']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "EvenWords:4", + "sat": "def sat(evens: List[str], words=['vanafegyfog', 'vipugohuvychu']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['vanafegyfog', 'vipugohuvychu']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "PrimeSel:0", + "sat": "def sat(neighbors: List[int], nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "PrimeSel:1", + "sat": "def sat(neighbors: List[int], nums=[15, 1, 1, 11, 12, 12, 3, 3, 2, 5, 12, 0, 16, 0, 4, 14, 11, 7, 8]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[15, 1, 1, 11, 12, 12, 3, 3, 2, 5, 12, 0, 16, 0, 4, 14, 11, 7, 8]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "PrimeSel:2", + "sat": "def sat(neighbors: List[int], nums=[1, 15, 19]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 15, 19]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "PrimeSel:3", + "sat": "def sat(neighbors: List[int], nums=[9, 9, 0, 2, 7, 14, 14, 2, 6, 4, -1, 7, 2, 2, 14, 8, 7, 19, 5, 9, 4, 18, 14, 8, 9, 2, -1]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[9, 9, 0, 2, 7, 14, 14, 2, 6, 4, -1, 7, 2, 2, 14, 8, 7, 19, 5, 9, 4, 18, 14, 8, 9, 2, -1]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "PrimeSel:4", + "sat": "def sat(neighbors: List[int], nums=[4, 2, 4, 7, -1, 10, 0, 10, 1, 3, 8, 3, 5, 3, 0, -1, 11, 18, 15, 2, 4, 10, 8, 14, 6, 1, 12, 14, 5]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[4, 2, 4, 7, -1, 10, 0, 10, 1, 3, 8, 3, 5, 3, 0, -1, 11, 18, 15, 2, 4, 10, 8, 14, 6, 1, 12, 14, 5]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "EvenSqure:0", + "sat": "def sat(tot: int, xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "EvenSqure:1", + "sat": "def sat(tot: int, xs=[]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "EvenSqure:2", + "sat": "def sat(tot: int, xs=[274797.0, 8635.410691353316, 53805.0, -51907.0, -24430.861351406824, 190577.0, 237978.0, 133989.0]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[274797.0, 8635.410691353316, 53805.0, -51907.0, -24430.861351406824, 190577.0, 237978.0, 133989.0]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "EvenSqure:3", + "sat": "def sat(tot: int, xs=[205685.0, 6849.8060301064015, 68569.0, 33659.85121811424, 71796.0, 183470.0, 236644.22522117657, -11658.772326982376, 155284.34795372086]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[205685.0, 6849.8060301064015, 68569.0, 33659.85121811424, 71796.0, 183470.0, 236644.22522117657, -11658.772326982376, 155284.34795372086]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "EvenSqure:4", + "sat": "def sat(tot: int, xs=[58607.93384068141, 26960.422714894165, 220926.0, 32993.16403323761, 36258.0, 164898.58842568452, -22047.528018042995, 283472.0, -14768.0]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[58607.93384068141, 26960.422714894165, 220926.0, 32993.16403323761, 36258.0, 164898.58842568452, -22047.528018042995, 283472.0, -14768.0]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "ArrayDiff:0", + "sat": "def sat(b: List[int], a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "ArrayDiff:1", + "sat": "def sat(b: List[int], a=[14, -1, 12, 11, 3, -1, 18, 5, 8, 5, 6, 1], c=[15, 19, 15, 19, 4, 1, 7, 12, -1, 16, 11, 5]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[14, -1, 12, 11, 3, -1, 18, 5, 8, 5, 6, 1], c=[15, 19, 15, 19, 4, 1, 7, 12, -1, 16, 11, 5]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "ArrayDiff:2", + "sat": "def sat(b: List[int], a=[14, 14, 2, 1, 11, 10, 15, 11, 9, 10, 4, 1, 7, 10, 16, 12], c=[5, 11, 16, 8, 19, 12, 19, 9, 10, 11, 14, 18, 2, 2, 0, 17]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[14, 14, 2, 1, 11, 10, 15, 11, 9, 10, 4, 1, 7, 10, 16, 12], c=[5, 11, 16, 8, 19, 12, 19, 9, 10, 11, 14, 18, 2, 2, 0, 17]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "ArrayDiff:3", + "sat": "def sat(b: List[int], a=[4, 8, 14, 17, 15, -1, 17, 8, -1, 4, 3, 10, 2, 13, 1], c=[13, 14, 11, 18, 16, 8, 14, 3, 0, 9, 7, 19, 11, 15, 9]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[4, 8, 14, 17, 15, -1, 17, 8, -1, 4, 3, 10, 2, 13, 1], c=[13, 14, 11, 18, 16, 8, 14, 3, 0, 9, 7, 19, 11, 15, 9]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "ArrayDiff:4", + "sat": "def sat(b: List[int], a=[13, 10, 7, 7, 1, 10, 0, 17, 5, 14, 10, 14], c=[13, 13, 17, 4, 18, 17, 12, 16, 0, 3, 12, 14]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[13, 10, 7, 7, 1, 10, 0, 17, 5, 14, 10, 14], c=[13, 13, 17, 4, 18, 17, 12, 16, 0, 3, 12, 14]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "StrongestExtension:0", + "sat": "def sat(s: str, class_name=\"TestClass\", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"TestClass\", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "StrongestExtension:1", + "sat": "def sat(s: str, class_name=\"Lyhithywuwotu\", extensions=['moRUTExterefI', 'vItHu', 'xIWygaly', 'zONITh', 'ChinELAbiFOfywUcU', 'sywyfIFuTagAX', 'CIcECHiriQUuXuxuh', 'JUFeSA']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"Lyhithywuwotu\", extensions=['moRUTExterefI', 'vItHu', 'xIWygaly', 'zONITh', 'ChinELAbiFOfywUcU', 'sywyfIFuTagAX', 'CIcECHiriQUuXuxuh', 'JUFeSA']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "StrongestExtension:2", + "sat": "def sat(s: str, class_name=\"Textafarole\", extensions=['bEzETExTutheQuYCetH', 'FUFetEpaPafawIxegIbI', 'fUxuXYfOmutYM', 'HYCygiNY', 'FUnaVYcHity', 'th', 'dULUDyQui', 'rAvUJUlAchUHAsOBese', 'tefO', 'vy']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"Textafarole\", extensions=['bEzETExTutheQuYCetH', 'FUFetEpaPafawIxegIbI', 'fUxuXYfOmutYM', 'HYCygiNY', 'FUnaVYcHity', 'th', 'dULUDyQui', 'rAvUJUlAchUHAsOBese', 'tefO', 'vy']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "StrongestExtension:3", + "sat": "def sat(s: str, class_name=\"Gudes\", extensions=['CHOXeHeTAsUxyTe', 'QuEtHeTe', 'NOtEX', 'sehYJyFecIte', 'RySyJIFADEXETYBopUL', 'taMEcYW']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"Gudes\", extensions=['CHOXeHeTAsUxyTe', 'QuEtHeTe', 'NOtEX', 'sehYJyFecIte', 'RySyJIFADEXETYBopUL', 'taMEcYW']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "StrongestExtension:4", + "sat": "def sat(s: str, class_name=\"Ruxomyw\", extensions=['PUfam', 'H', 'PEVYtHAxe', 'cInyTex', 'PoJApESOch', 'teXTidaQuigUPOtho', 'TEXteSYSyWEQuy', 'C', 'ZEFutexTImyjUHi', 'CIcybAMeT', 'XIWAvaDoBe']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"Ruxomyw\", extensions=['PUfam', 'H', 'PEVYtHAxe', 'cInyTex', 'PoJApESOch', 'teXTidaQuigUPOtho', 'TEXteSYSyWEQuy', 'C', 'ZEFutexTImyjUHi', 'CIcybAMeT', 'XIWAvaDoBe']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "RotateString:0", + "sat": "def sat(r: str, s=\"light star\", t=\"I love to look at the starlight!\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"light star\", t=\"I love to look at the starlight!\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateString:1", + "sat": "def sat(r: str, s=\"fuz tox banu dukukyjosuthihono\", t=\"sikysefylacywitijuz thosowehiv kiviwas girezol betext lepumarasithihonofuz tox banu dukukyjosutog kuquinecakyt\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"fuz tox banu dukukyjosuthihono\", t=\"sikysefylacywitijuz thosowehiv kiviwas girezol betext lepumarasithihonofuz tox banu dukukyjosutog kuquinecakyt\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateString:2", + "sat": "def sat(r: str, s=\"vyquaquabuwuktus tyryrezywovimu sopikalo \", t=\"zugu benuzyca cafoca gawy sycapoxitus tyryrezywovimu sopikalo vyquaquabuwuko citextytextythakidu basikyched\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"vyquaquabuwuktus tyryrezywovimu sopikalo \", t=\"zugu benuzyca cafoca gawy sycapoxitus tyryrezywovimu sopikalo vyquaquabuwuko citextytextythakidu basikyched\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateString:3", + "sat": "def sat(r: str, s=\"udynybu cequelynxebalu w guh\", t=\"zigoxesychujocefete nyquuquu wubupi quidoxebalu w guhudynybu cequelynuquumythaku xet syquaxatext lizevachuciconolove\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"udynybu cequelynxebalu w guh\", t=\"zigoxesychujocefete nyquuquu wubupi quidoxebalu w guhudynybu cequelynuquumythaku xet syquaxatext lizevachuciconolove\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "RotateString:4", + "sat": "def sat(r: str, s=\"fecajajeh b tythanenifewed quomekucybimudegicyj zos depogip kmowe\", t=\"fuch mowefecajajeh b tythanenifewed quomekucybimudegicyj zos depogip kotextu hothakatozate thyzet\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"fecajajeh b tythanenifewed quomekucybimudegicyj zos depogip kmowe\", t=\"fuch mowefecajajeh b tythanenifewed quomekucybimudegicyj zos depogip kotextu hothakatozate thyzet\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:0", + "sat": "def sat(n: int, evens=17, odds=3):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=17, odds=3):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:1", + "sat": "def sat(n: int, evens=117, odds=56):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=117, odds=56):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:2", + "sat": "def sat(n: int, evens=114, odds=119):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=114, odds=119):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:3", + "sat": "def sat(n: int, evens=133, odds=33):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=133, odds=33):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:4", + "sat": "def sat(n: int, evens=8, odds=114):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=8, odds=114):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "RomanNumerals:0", + "sat": "def sat(roman: str, n=2414):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=2414):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "RomanNumerals:1", + "sat": "def sat(roman: str, n=2058):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=2058):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "RomanNumerals:2", + "sat": "def sat(roman: str, n=1467):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=1467):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "RomanNumerals:3", + "sat": "def sat(roman: str, n=1533):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=1533):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "RomanNumerals:4", + "sat": "def sat(roman: str, n=114):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=114):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:0", + "sat": "def sat(triples: List[List[int]], n=920, m=799):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=920, m=799):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:1", + "sat": "def sat(triples: List[List[int]], n=847, m=721):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=847, m=721):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:2", + "sat": "def sat(triples: List[List[int]], n=646, m=523):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=646, m=523):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:3", + "sat": "def sat(triples: List[List[int]], n=901, m=780):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=901, m=780):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:4", + "sat": "def sat(triples: List[List[int]], n=936, m=817):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=936, m=817):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "MostUnique:0", + "sat": "def sat(s: str, pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "MostUnique:1", + "sat": "def sat(s: str, pool=['sibiloguhujuquenam', 'nyzidikedutexti', 'zatextuquyvakijahixa', 'textujig', 'cewynyrimatex', 'textusaxinypuhyheza']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['sibiloguhujuquenam', 'nyzidikedutexti', 'zatextuquyvakijahixa', 'textujig', 'cewynyrimatex', 'textusaxinypuhyheza']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "MostUnique:2", + "sat": "def sat(s: str, pool=['gylapasugatextysar', 'zapy', 'hycokelet']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['gylapasugatextysar', 'zapy', 'hycokelet']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "MostUnique:3", + "sat": "def sat(s: str, pool=['te', '', 'badypikyxucudil', 'fuhibatextixyburekan', 'chole']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['te', '', 'badypikyxucudil', 'fuhibatextixyburekan', 'chole']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "MostUnique:4", + "sat": "def sat(s: str, pool=['th', 's', 'bulonu', 'r']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['th', 's', 'bulonu', 'r']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "HungryRabbits:0", + "sat": "def sat(results: List[List[int]], stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "HungryRabbits:1", + "sat": "def sat(results: List[List[int]], stats=[[4, 5, 3], [1, 0, 7], [3, 7, 7], [5, 3, 8], [9, 2, 4], [7, 6, 6]]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[[4, 5, 3], [1, 0, 7], [3, 7, 7], [5, 3, 8], [9, 2, 4], [7, 6, 6]]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "HungryRabbits:2", + "sat": "def sat(results: List[List[int]], stats=[]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "HungryRabbits:3", + "sat": "def sat(results: List[List[int]], stats=[[9, 2, 2], [2, 3, 1], [9, 1, 7], [9, 2, 3], [8, 6, 9], [9, 6, 5], [8, 9, 2], [9, 8, 4]]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[[9, 2, 2], [2, 3, 1], [9, 1, 7], [9, 2, 3], [8, 6, 9], [9, 6, 5], [8, 9, 2], [9, 8, 4]]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "HungryRabbits:4", + "sat": "def sat(results: List[List[int]], stats=[[1, 1, 9]]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[[1, 1, 9]]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:0", + "sat": "def sat(ops: List[str], target=2021, nums=[4, 6, 2, 1, 1, 3, 9]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=2021, nums=[4, 6, 2, 1, 1, 3, 9]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:1", + "sat": "def sat(ops: List[str], target=4, nums=[5, 4, 8, 9, 3, 6, 2]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=4, nums=[5, 4, 8, 9, 3, 6, 2]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:2", + "sat": "def sat(ops: List[str], target=-24995, nums=[1, 8, 5, 8, 5, 5, 5]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=-24995, nums=[1, 8, 5, 8, 5, 5, 5]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:3", + "sat": "def sat(ops: List[str], target=6, nums=[7, 4, 4, 2, 4, 1, 6]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=6, nums=[7, 4, 4, 2, 4, 1, 6]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:4", + "sat": "def sat(ops: List[str], target=38, nums=[6, 2, 1, 7, 1, 3, 1]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=38, nums=[6, 2, 1, 7, 1, 3, 1]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "ReverseCase:0", + "sat": "def sat(rev: List[str], strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ReverseCase:1", + "sat": "def sat(rev: List[str], strs=['vYWakiFoWElEnYjOfA', 'RO', '575', '943', '403', '-292', 'textY']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['vYWakiFoWElEnYjOfA', 'RO', '575', '943', '403', '-292', 'textY']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ReverseCase:2", + "sat": "def sat(rev: List[str], strs=['223', '990', '-603', 'Ma', '-963', 'kO', 'REThoFOhuVAnUCyMyhIC', '711', '-874']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['223', '990', '-603', 'Ma', '-963', 'kO', 'REThoFOhuVAnUCyMyhIC', '711', '-874']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ReverseCase:3", + "sat": "def sat(rev: List[str], strs=['-352', 'wi', '-787', '706', 'fYchUc', '542', 'JeJuzichUnaHugAc', '963']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['-352', 'wi', '-787', '706', 'fYchUc', '542', 'JeJuzichUnaHugAc', '963']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ReverseCase:4", + "sat": "def sat(rev: List[str], strs=['234', '-828', '330', 'NateXt', '-524', '-196', 'siciNUCewOCePUdiN']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['234', '-828', '330', 'NateXt', '-524', '-196', 'siciNUCewOCePUdiN']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ZobristCollision:0", + "sat": "def sat(positions: List[List[int]]):\n\n table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)]\n\n def zobrist(pos):\n h = 0\n for i in range(64):\n if pos[i]:\n h ^= table[i][pos[i]]\n return h\n\n a, b = positions\n return zobrist(a) == zobrist(b) and a != b", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a collision for the given Zobrist chess board hash: https://en.wikipedia.org/wiki/Zobrist_hashing\n\n Each of the two positions should be encoded as a list of 64 integers 0-12\"\"\"", + "sol_bodies": [ + " hashes = {}\n table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)]\n\n def zobrist(pos):\n h = 0\n for i in range(64):\n if pos[i]:\n h ^= table[i][pos[i]]\n return h\n\n for i in range(1, 100000000):\n pos = [(i * 42 + ((i + 1) * j * 12589) % 54321) % 13 for j in range(64)] # pseudo-random board\n h = zobrist(pos)\n if h in hashes:\n return [pos, hashes[h]]\n else:\n hashes[h] = pos" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#162\n\nThe original problem was to compute an MD5 hash. This puzzle is a problem in the space of hashing, but of a\ndifferent nature.", + "weight": 1.0 + }, + { + "name": "EvenBetween:0", + "sat": "def sat(ab: List[int], s=\"3298832990329923299432996329983300033002\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"3298832990329923299432996329983300033002\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "EvenBetween:1", + "sat": "def sat(ab: List[int], s=\"38600386023860438606\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"38600386023860438606\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "EvenBetween:2", + "sat": "def sat(ab: List[int], s=\"254042540625408\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"254042540625408\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "EvenBetween:3", + "sat": "def sat(ab: List[int], s=\"32880328823288432886\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"32880328823288432886\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "EvenBetween:4", + "sat": "def sat(ab: List[int], s=\"6062860630606326063460636\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"6062860630606326063460636\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "IsEven:0", + "sat": "def sat(b: bool, n=10):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=10):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 }, { - "name": "FermatComposite_0", - "sat": "def sat(certificate: int, n=1449):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1449):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "IsEven:1", + "sat": "def sat(b: bool, n=0):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 }, { - "name": "FermatComposite_1", - "sat": "def sat(certificate: int, n=124188003):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=124188003):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "IsEven:2", + "sat": "def sat(b: bool, n=1):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=1):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 }, { - "name": "FermatComposite_2", - "sat": "def sat(certificate: int, n=1126002225):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1126002225):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "IsEven:3", + "sat": "def sat(b: bool, n=2):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=2):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 }, { - "name": "FermatComposite_3", - "sat": "def sat(certificate: int, n=2013505):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=2013505):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "IsEven:4", + "sat": "def sat(b: bool, n=3):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=3):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 }, { - "name": "FermatComposite_4", - "sat": "def sat(certificate: int, n=1541294115):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1541294115):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "Abbreviate:0", + "sat": "def sat(s: str, word=\"antidisestablishmentarianism\", max_len=10):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"antidisestablishmentarianism\", max_len=10):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 }, { - "name": "FermatComposite_5", - "sat": "def sat(certificate: int, n=2199642509):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=2199642509):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "Abbreviate:1", + "sat": "def sat(s: str, word=\"pawuzorythalirinasubyg\", max_len=12):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"pawuzorythalirinasubyg\", max_len=12):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 }, { - "name": "FermatComposite_6", - "sat": "def sat(certificate: int, n=3795573951):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=3795573951):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "Abbreviate:2", + "sat": "def sat(s: str, word=\"jomodosigezyfulach\", max_len=5):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"jomodosigezyfulach\", max_len=5):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 }, { - "name": "FermatComposite_7", - "sat": "def sat(certificate: int, n=1212062763):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1212062763):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "Abbreviate:3", + "sat": "def sat(s: str, word=\"bybakichop\", max_len=12):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"bybakichop\", max_len=12):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 }, { - "name": "FermatComposite_8", - "sat": "def sat(certificate: int, n=1298716900):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1298716900):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "Abbreviate:4", + "sat": "def sat(s: str, word=\"wywaxizodetextonigijalate\", max_len=5):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"wywaxizodetextonigijalate\", max_len=5):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 }, { - "name": "FermatComposite_9", - "sat": "def sat(certificate: int, n=1025499501):\n \"\"\"\n Find a Fermat composite certificate for a number n > 1\n\n Sample Input:\n 1469\n\n Sample Output:\n 3 # because (3 ** 1468) % 1469 != 1\n \"\"\"\n return pow(certificate, n - 1, n) > 1", - "sols": [ - "def sol(n=1025499501):\n return next(i for i in range(2, n) if pow(i, n - 1, n) > 1)" + "name": "SquareTiles:0", + "sat": "def sat(corners: List[List[int]], m=10, n=9, a=5, target=4):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=9, a=5, target=4):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_0", - "sat": "def sat(root: float, coeffs=[1, 2, 3, 17]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[1, 2, 3, 17]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "SquareTiles:1", + "sat": "def sat(corners: List[List[int]], m=22, n=129, a=9, target=45):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=9, m=22, n=129, target=45):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_1", - "sat": "def sat(root: float, coeffs=[-1, -5, 4, -8, 3, -1, 0, 7]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[-1, -5, 4, -8, 3, -1, 0, 7]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "SquareTiles:2", + "sat": "def sat(corners: List[List[int]], m=6, n=849, a=10, target=89):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=10, m=6, n=849, target=89):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_2", - "sat": "def sat(root: float, coeffs=[7, 1]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[7, 1]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "SquareTiles:3", + "sat": "def sat(corners: List[List[int]], m=89, n=554, a=6, target=1397):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=6, m=89, n=554, target=1397):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_3", - "sat": "def sat(root: float, coeffs=[1, 4, 1, -7, 5, 0, -10, -9, 4, 9]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[1, 4, 1, -7, 5, 0, -10, -9, 4, 9]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "SquareTiles:4", + "sat": "def sat(corners: List[List[int]], m=74, n=1, a=2, target=38):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=2, m=74, n=1, target=38):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_4", - "sat": "def sat(root: float, coeffs=[7, 8]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[7, 8]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "EasyTwos:0", + "sat": "def sat(lb: List[bool], trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_5", - "sat": "def sat(root: float, coeffs=[-4, 2]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[-4, 2]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "EasyTwos:1", + "sat": "def sat(lb: List[bool], trips=[[1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 0, 0]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 0, 0]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_6", - "sat": "def sat(root: float, coeffs=[-6, 2, 4, -3, -4, 3, 2, 3, -3, 6]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[-6, 2, 4, -3, -4, 3, 2, 3, -3, 6]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "EasyTwos:2", + "sat": "def sat(lb: List[bool], trips=[[0, 0, 0], [1, 0, 0], [0, 1, 1], [0, 1, 1]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[0, 0, 0], [1, 0, 0], [0, 1, 1], [0, 1, 1]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_7", - "sat": "def sat(root: float, coeffs=[9, -7, -9, -9, 0, 1, 0, 4]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[9, -7, -9, -9, 0, 1, 0, 4]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "EasyTwos:3", + "sat": "def sat(lb: List[bool], trips=[[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 1, 0], [0, 1, 1], [1, 0, 0], [0, 0, 0], [1, 0, 1], [1, 1, 0], [0, 0, 1], [1, 0, 1]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 1, 0], [0, 1, 1], [1, 0, 0], [0, 0, 0], [1, 0, 1], [1, 1, 0], [0, 0, 1], [1, 0, 1]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_8", - "sat": "def sat(root: float, coeffs=[1, 0, -9, 9, -7, -4, -2, 3, -9, 9]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[1, 0, -9, 9, -7, -4, -2, 3, -9, 9]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "EasyTwos:4", + "sat": "def sat(lb: List[bool], trips=[[0, 0, 1], [0, 1, 1], [0, 0, 1], [0, 1, 1]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[0, 0, 1], [0, 1, 1], [0, 0, 1], [0, 1, 1]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 }, { - "name": "OddDegreePolynomialRoot_9", - "sat": "def sat(root: float, coeffs=[5, -8, 3, -2, -9, -6, 9, 2]):\n \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", - "sols": [ - "def sol(coeffs=[5, -8, 3, -2, -9, -6, 9, 2]):\n def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + "name": "DecreasingCountComparison:0", + "sat": "def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" ], - "module": "human_eval", - "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_0", - "sat": "def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "DecreasingCountComparison:1", + "sat": "def sat(n: int, scores=[32, 32, 31, 30, 25, 25, 21, 20, 17, 17, 16, 15, 15, 14, 11, 2, 0], k=4):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[32, 32, 31, 30, 25, 25, 21, 20, 17, 17, 16, 15, 15, 14, 11, 2, 0], k=4):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_1", - "sat": "def sat(li: List[int], orig=[-10, 9, 0, -6, 0, -7, -2, 4, 8, 2, 3, -9, -8, 9, -4, -4]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[-10, 9, 0, -6, 0, -7, -2, 4, 8, 2, 3, -9, -8, 9, -4, -4]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "DecreasingCountComparison:2", + "sat": "def sat(n: int, scores=[44, 42, 41, 41, 40, 40, 39, 38, 38, 38, 37, 33, 32, 31, 31, 31, 30, 29, 28, 26, 25, 24, 24, 23, 23, 22, 20, 20, 20, 18, 17, 17, 16, 16, 12, 9, 9, 7, 6, 5, 4, 2], k=1):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[44, 42, 41, 41, 40, 40, 39, 38, 38, 38, 37, 33, 32, 31, 31, 31, 30, 29, 28, 26, 25, 24, 24, 23, 23, 22, 20, 20, 20, 18, 17, 17, 16, 16, 12, 9, 9, 7, 6, 5, 4, 2], k=1):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_2", - "sat": "def sat(li: List[int], orig=[0, 7, -3, -3, 2, 2, 5, -9, -9]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[0, 7, -3, -3, 2, 2, 5, -9, -9]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "DecreasingCountComparison:3", + "sat": "def sat(n: int, scores=[36, 27, 24, 19, 15, 15, 8, 8, 5], k=4):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[36, 27, 24, 19, 15, 15, 8, 8, 5], k=4):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_3", - "sat": "def sat(li: List[int], orig=[-1, -1, 0, 6, 3, -1, 4, -1, 1, 9, -4, -1, 6, 4, -7, -4, 1]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[-1, -1, 0, 6, 3, -1, 4, -1, 1, 9, -4, -1, 6, 4, -7, -4, 1]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "DecreasingCountComparison:4", + "sat": "def sat(n: int, scores=[20, 19, 17, 13, 12, 11, 10, 6], k=2):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[20, 19, 17, 13, 12, 11, 10, 6], k=2):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_4", - "sat": "def sat(li: List[int], orig: List[int]=[]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "VowelDrop:0", + "sat": "def sat(t: str, s=\"Problems\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"Problems\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_5", - "sat": "def sat(li: List[int], orig=[-4, -4, 7, 6, 0, -6, -9, 9]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[-4, -4, 7, 6, 0, -6, -9, 9]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "VowelDrop:1", + "sat": "def sat(t: str, s=\"VahOjaquAlYMEcubidePYwApawAtonE\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"VahOjaquAlYMEcubidePYwApawAtonE\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_6", - "sat": "def sat(li: List[int], orig=[-10, -3, -5, 5, 8, -7, -4, -5, -9, -6, -6, -3]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[-10, -3, -5, 5, 8, -7, -4, -5, -9, -6, -6, -3]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "VowelDrop:2", + "sat": "def sat(t: str, s=\"kAgIHAdiHEKoNAJubozUKaMYDETAdeZyziveL\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"kAgIHAdiHEKoNAJubozUKaMYDETAdeZyziveL\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_7", - "sat": "def sat(li: List[int], orig=[0, 7, -8, -2]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[0, 7, -8, -2]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "VowelDrop:3", + "sat": "def sat(t: str, s=\"NOxADaNIMiReZoTeXtODUtHulyTHETextojoLeQuaNutEXtE\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"NOxADaNIMiReZoTeXtODUtHulyTHETextojoLeQuaNutEXtE\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_8", - "sat": "def sat(li: List[int], orig=[-7, 8]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[-7, 8]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "VowelDrop:4", + "sat": "def sat(t: str, s=\"MEkUWonymYNAQUypEcIv\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"MEkUWonymYNAQUypEcIv\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 }, { - "name": "TwoThirdsSorted_9", - "sat": "def sat(li: List[int], orig=[1, 1, 6, 0, -8, -3, 8, -4, -1, 8, 2, -6, -8, -10, 4, 4, -10]):\n \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", - "sols": [ - "def sol(orig=[1, 1, 6, 0, -8, -3, 8, -4, -1, 8, 2, -6, -8, -10, 4, 4, -10]):\n n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + "name": "DominoTile:0", + "sat": "def sat(squares: List[List[int]], m=10, n=5, target=50):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=5, target=50):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 }, { - "name": "UniqueSorted_0", - "sat": "def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):\n my_list = sorted(set(orig))\n return my_list" + "name": "DominoTile:1", + "sat": "def sat(squares: List[List[int]], m=30, n=12, target=360):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=30, n=12, target=360):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 }, { - "name": "UniqueSorted_1", - "sat": "def sat(li: List[int], orig=[-9, 1, -5, 6, -1, 3, 5, 8, -10, -2, 3, -9, -10]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[-9, 1, -5, 6, -1, 3, 5, 8, -10, -2, 3, -9, -10]):\n my_list = sorted(set(orig))\n return my_list" + "name": "DominoTile:2", + "sat": "def sat(squares: List[List[int]], m=34, n=25, target=850):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=34, n=25, target=850):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 }, { - "name": "UniqueSorted_2", - "sat": "def sat(li: List[int], orig=[-3, 7, 9, -10, -10, 5, 2, 8]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[-3, 7, 9, -10, -10, 5, 2, 8]):\n my_list = sorted(set(orig))\n return my_list" + "name": "DominoTile:3", + "sat": "def sat(squares: List[List[int]], m=35, n=46, target=1610):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=35, n=46, target=1610):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 }, { - "name": "UniqueSorted_3", - "sat": "def sat(li: List[int], orig=[-6]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[-6]):\n my_list = sorted(set(orig))\n return my_list" + "name": "DominoTile:4", + "sat": "def sat(squares: List[List[int]], m=41, n=12, target=492):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=41, n=12, target=492):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 }, { - "name": "UniqueSorted_4", - "sat": "def sat(li: List[int], orig=[1, -5, 6, 2, -7, -6, 5, -5, 3, 7, 4, -10, -2, 3, 7, 9, -3, 8, 7]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[1, -5, 6, 2, -7, -6, 5, -5, 3, 7, 4, -10, -2, 3, 7, 9, -3, 8, 7]):\n my_list = sorted(set(orig))\n return my_list" + "name": "IncDec:0", + "sat": "def sat(n: int, ops=['x++', '--x', '--x'], target=19143212):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['x++', '--x', '--x'], target=19143212):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 }, { - "name": "UniqueSorted_5", - "sat": "def sat(li: List[int], orig=[-6, 2, 4, -3, -5, 5, -8, -9, 3, -7, 7, 6, 8]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[-6, 2, 4, -3, -5, 5, -8, -9, 3, -7, 7, 6, 8]):\n my_list = sorted(set(orig))\n return my_list" + "name": "IncDec:1", + "sat": "def sat(n: int, ops=['x++', '++x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x--', 'x--', '--x', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', 'x--', 'x++', 'x--', 'x--', '--x', '++x', 'x--', '--x', 'x++', 'x--', 'x++', '++x', '++x', 'x++', '--x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x++', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '++x', 'x++', 'x++', '++x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', '--x', 'x--', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '++x', '--x', '--x', '++x', '--x', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '--x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x++', '--x', 'x++', 'x++', 'x--', 'x--', 'x--', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', '++x', 'x++', '++x', '++x', '++x', '--x', 'x--', 'x--', '--x', '--x', '++x', '++x', '--x', '++x', '--x', 'x--', 'x--', '--x', '--x', '--x', '--x', '--x', 'x++', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x++', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', '--x', '--x', '++x', '++x', 'x--', '++x', '--x', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x--'], target=88808):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['x++', '++x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x--', 'x--', '--x', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', 'x--', 'x++', 'x--', 'x--', '--x', '++x', 'x--', '--x', 'x++', 'x--', 'x++', '++x', '++x', 'x++', '--x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x++', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '++x', 'x++', 'x++', '++x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', '--x', 'x--', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '++x', '--x', '--x', '++x', '--x', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '--x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x++', '--x', 'x++', 'x++', 'x--', 'x--', 'x--', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', '++x', 'x++', '++x', '++x', '++x', '--x', 'x--', 'x--', '--x', '--x', '++x', '++x', '--x', '++x', '--x', 'x--', 'x--', '--x', '--x', '--x', '--x', '--x', 'x++', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x++', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', '--x', '--x', '++x', '++x', 'x--', '++x', '--x', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x--'], target=88808):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 }, { - "name": "UniqueSorted_6", - "sat": "def sat(li: List[int], orig=[9, -10, 4, 5, 2, -10, -10, 7, 4, 5, 8, -5, -10, -6, 4]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[9, -10, 4, 5, 2, -10, -10, 7, 4, 5, 8, -5, -10, -6, 4]):\n my_list = sorted(set(orig))\n return my_list" + "name": "IncDec:2", + "sat": "def sat(n: int, ops=['x--', 'x--', '++x', '--x', '--x', 'x--', '--x', '++x', 'x++', 'x++', 'x--', 'x++', '++x', '--x', '++x', '--x', 'x++', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', '--x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', '++x', '--x', '--x', '++x', '--x', '--x', 'x++', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', '++x', 'x++', '++x', 'x++', 'x++', 'x++', 'x--', '++x', '--x', '--x', 'x++', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', 'x++', 'x++', '--x', '--x', 'x--', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '++x', 'x++', 'x++', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', 'x--', '++x', '++x', '--x', 'x++', '++x', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', 'x--', '++x', '++x', 'x++', '--x', '++x', 'x--', '--x', 'x--', '++x', 'x--', 'x--', '++x', '++x', 'x++', 'x--', '++x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', '--x', '++x', 'x--', '--x', '++x', 'x--', '++x', 'x--', 'x--', '++x', '--x', '--x', '++x', '--x', 'x++', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x--', 'x++', '++x', 'x--', 'x++', '--x', '++x', '++x', '++x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', 'x--', 'x++', '--x', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', '--x', '++x', '--x', 'x++', 'x++', 'x++', 'x--', 'x++', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x++', '++x', 'x++', '++x', '++x', '--x', 'x++', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x--', '--x', 'x--', '--x', 'x++', 'x--', '++x', 'x--', '++x', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x++', 'x++', '++x', '++x', '++x', '++x', '++x', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', '--x', 'x++', '++x', '--x', 'x++', '--x', '--x', 'x++', '++x', 'x--', 'x--', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x++', '++x', '--x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '--x', '--x', 'x--', '++x', '++x', '++x', '++x', '++x', 'x++', '--x', '++x', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x--', '++x', '++x', 'x++', 'x--', 'x--', '++x', '--x', '--x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x++', '++x', '++x', 'x--', '--x', '--x', '++x', 'x++', '--x', 'x--', 'x--', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x++', 'x++', 'x--', '--x', 'x++', 'x--', 'x++', 'x++', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', '--x', 'x--', '--x', '++x', '--x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', '++x', '--x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', '++x', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x--', 'x++', 'x++', '++x', 'x++', 'x++', 'x++', 'x++', '++x', 'x--', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', '--x', '--x', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', '--x', 'x++', 'x--', '--x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '--x', '++x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x--', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', 'x--', '++x', 'x--', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++'], target=28110):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['x--', 'x--', '++x', '--x', '--x', 'x--', '--x', '++x', 'x++', 'x++', 'x--', 'x++', '++x', '--x', '++x', '--x', 'x++', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', '--x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', '++x', '--x', '--x', '++x', '--x', '--x', 'x++', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', '++x', 'x++', '++x', 'x++', 'x++', 'x++', 'x--', '++x', '--x', '--x', 'x++', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', 'x++', 'x++', '--x', '--x', 'x--', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '++x', 'x++', 'x++', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', 'x--', '++x', '++x', '--x', 'x++', '++x', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', 'x--', '++x', '++x', 'x++', '--x', '++x', 'x--', '--x', 'x--', '++x', 'x--', 'x--', '++x', '++x', 'x++', 'x--', '++x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', '--x', '++x', 'x--', '--x', '++x', 'x--', '++x', 'x--', 'x--', '++x', '--x', '--x', '++x', '--x', 'x++', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x--', 'x++', '++x', 'x--', 'x++', '--x', '++x', '++x', '++x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', 'x--', 'x++', '--x', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', '--x', '++x', '--x', 'x++', 'x++', 'x++', 'x--', 'x++', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x++', '++x', 'x++', '++x', '++x', '--x', 'x++', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x--', '--x', 'x--', '--x', 'x++', 'x--', '++x', 'x--', '++x', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x++', 'x++', '++x', '++x', '++x', '++x', '++x', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', '--x', 'x++', '++x', '--x', 'x++', '--x', '--x', 'x++', '++x', 'x--', 'x--', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x++', '++x', '--x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '--x', '--x', 'x--', '++x', '++x', '++x', '++x', '++x', 'x++', '--x', '++x', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x--', '++x', '++x', 'x++', 'x--', 'x--', '++x', '--x', '--x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x++', '++x', '++x', 'x--', '--x', '--x', '++x', 'x++', '--x', 'x--', 'x--', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x++', 'x++', 'x--', '--x', 'x++', 'x--', 'x++', 'x++', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', '--x', 'x--', '--x', '++x', '--x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', '++x', '--x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', '++x', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x--', 'x++', 'x++', '++x', 'x++', 'x++', 'x++', 'x++', '++x', 'x--', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', '--x', '--x', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', '--x', 'x++', 'x--', '--x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '--x', '++x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x--', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', 'x--', '++x', 'x--', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++'], target=28110):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 }, { - "name": "UniqueSorted_7", - "sat": "def sat(li: List[int], orig=[0, -10, 8]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[0, -10, 8]):\n my_list = sorted(set(orig))\n return my_list" + "name": "IncDec:3", + "sat": "def sat(n: int, ops=['--x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '--x', '--x', '--x', 'x--', '--x', '--x', '++x', '++x', '++x', 'x++', '--x', 'x--', '++x', 'x--', 'x--', 'x++', 'x--', 'x++', 'x++', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '++x', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', 'x--', '++x', '++x', '++x', 'x++', '++x', '--x', '--x', 'x++', '++x', '++x', 'x++', '++x', '--x', '++x', '--x', 'x--', '++x', '++x', '++x', '++x', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '++x', 'x--', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x--', '++x', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '--x', '++x', 'x--', 'x--', '--x', 'x--', 'x--', 'x++', '--x', 'x++', '++x', '--x', 'x--', '--x', '--x', 'x--', 'x--', '--x', '++x', 'x--', '++x', '++x', '++x', 'x--', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', 'x++', '++x', '--x', '++x', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', '++x', '--x', 'x++', '--x', '--x', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', 'x++', 'x++', 'x--', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x--', '--x', '++x', '--x', '--x', '++x', 'x++', '--x', 'x++', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x++', 'x++', '++x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x++', 'x--', '++x', '++x', 'x--', 'x--', '--x', 'x--', '--x', 'x--', 'x--', '++x', '++x', 'x--', '--x', 'x++', '--x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', 'x--', '--x', 'x++'], target=82823):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['--x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '--x', '--x', '--x', 'x--', '--x', '--x', '++x', '++x', '++x', 'x++', '--x', 'x--', '++x', 'x--', 'x--', 'x++', 'x--', 'x++', 'x++', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '++x', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', 'x--', '++x', '++x', '++x', 'x++', '++x', '--x', '--x', 'x++', '++x', '++x', 'x++', '++x', '--x', '++x', '--x', 'x--', '++x', '++x', '++x', '++x', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '++x', 'x--', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x--', '++x', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '--x', '++x', 'x--', 'x--', '--x', 'x--', 'x--', 'x++', '--x', 'x++', '++x', '--x', 'x--', '--x', '--x', 'x--', 'x--', '--x', '++x', 'x--', '++x', '++x', '++x', 'x--', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', 'x++', '++x', '--x', '++x', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', '++x', '--x', 'x++', '--x', '--x', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', 'x++', 'x++', 'x--', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x--', '--x', '++x', '--x', '--x', '++x', 'x++', '--x', 'x++', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x++', 'x++', '++x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x++', 'x--', '++x', '++x', 'x--', 'x--', '--x', 'x--', '--x', 'x--', 'x--', '++x', '++x', 'x--', '--x', 'x++', '--x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', 'x--', '--x', 'x++'], target=82823):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 }, { - "name": "UniqueSorted_8", - "sat": "def sat(li: List[int], orig=[-8, -7, 9, 8, -3, 4, -10, -4, 3, 1, -8, 5, -10, -2, 3]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[-8, -7, 9, 8, -3, 4, -10, -4, 3, 1, -8, 5, -10, -2, 3]):\n my_list = sorted(set(orig))\n return my_list" + "name": "IncDec:4", + "sat": "def sat(n: int, ops=['x--', 'x++', '++x', '--x', 'x++', '--x', 'x--'], target=61813):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['x--', 'x++', '++x', '--x', 'x++', '--x', 'x--'], target=61813):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 }, { - "name": "UniqueSorted_9", - "sat": "def sat(li: List[int], orig=[3, 8, -8, -2, -10, -3, 8]):\n \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", - "sols": [ - "def sol(orig=[3, 8, -8, -2, -10, -3, 8]):\n my_list = sorted(set(orig))\n return my_list" + "name": "CompareInAnyCase:0", + "sat": "def sat(n: int, s=\"aaAab\", t=\"aAaaB\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"aaAab\", t=\"aAaaB\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 }, { - "name": "MaxInt_0", - "sat": "def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 35, 35, 21, 18, 2, 60]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 35, 35, 21, 18, 2, 60]):\n return max(hello)" + "name": "CompareInAnyCase:1", + "sat": "def sat(n: int, s=\"JyNuTexTETiGAVIC\", t=\"JynUTEXTetigAViC\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"JyNuTexTETiGAVIC\", t=\"JynUTEXTetigAViC\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 }, { - "name": "MaxInt_1", - "sat": "def sat(m: int, hello=[2, 2, 2, -4, -2, -5, -4, 0, -5, -10, 1, -1, -1, 2]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[2, 2, 2, -4, -2, -5, -4, 0, -5, -10, 1, -1, -1, 2]):\n return max(hello)" + "name": "CompareInAnyCase:2", + "sat": "def sat(n: int, s=\"tExTYtOHahekomArof\", t=\"TExTYTohaHeKomryGUSeteXTUrYgir\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"tExTYtOHahekomArof\", t=\"TExTYTohaHeKomryGUSeteXTUrYgir\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 }, { - "name": "MaxInt_2", - "sat": "def sat(m: int, hello=[8, -1, -8, 1, -10]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[8, -1, -8, 1, -10]):\n return max(hello)" + "name": "CompareInAnyCase:3", + "sat": "def sat(n: int, s=\"RObAQuYK\", t=\"robaQUYKkuLY\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"RObAQuYK\", t=\"robaQUYKkuLY\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 }, { - "name": "MaxInt_3", - "sat": "def sat(m: int, hello=[-8, 1, 9, 4, 4, 0, -1, 8, 2, 3, 5, 9, 2, -1, 9]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[-8, 1, 9, 4, 4, 0, -1, 8, 2, 3, 5, 9, 2, -1, 9]):\n return max(hello)" + "name": "CompareInAnyCase:4", + "sat": "def sat(n: int, s=\"DUTeX\", t=\"dutdE\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"DUTeX\", t=\"dutdE\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 }, { - "name": "MaxInt_4", - "sat": "def sat(m: int, hello=[5, 2, -10, -2, -4, 2, 3, -5, 9, 0]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[5, 2, -10, -2, -4, 2, 3, -5, 9, 0]):\n return max(hello)" + "name": "SlidingOne:0", + "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "ans_type": "str", + "sol_header": "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):", + "sol_docstring": " \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"", + "sol_bodies": [ + " i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", + "weight": 1.0 }, { - "name": "MaxInt_5", - "sat": "def sat(m: int, hello=[-10, -4, 0, 2, -5]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[-10, -4, 0, 2, -5]):\n return max(hello)" + "name": "SlidingOne:1", + "sat": "def sat(s: str, matrix=[[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "ans_type": "str", + "sol_header": "def sol(matrix=[[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):", + "sol_docstring": " \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"", + "sol_bodies": [ + " i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", + "weight": 1.0 }, { - "name": "MaxInt_6", - "sat": "def sat(m: int, hello=[5, 0]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[5, 0]):\n return max(hello)" + "name": "SlidingOne:2", + "sat": "def sat(s: str, matrix=[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "ans_type": "str", + "sol_header": "def sol(matrix=[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):", + "sol_docstring": " \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"", + "sol_bodies": [ + " i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", + "weight": 1.0 }, { - "name": "MaxInt_7", - "sat": "def sat(m: int, hello=[-5, 0, -8, 0, -7, -4, -8, -4, -10, -2, -3, 7, -9]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[-5, 0, -8, 0, -7, -4, -8, -4, -10, -2, -3, 7, -9]):\n return max(hello)" + "name": "SlidingOne:3", + "sat": "def sat(s: str, matrix=[[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "ans_type": "str", + "sol_header": "def sol(matrix=[[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):", + "sol_docstring": " \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"", + "sol_bodies": [ + " i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", + "weight": 1.0 }, { - "name": "MaxInt_8", - "sat": "def sat(m: int, hello=[2, -4, 1, 7, -8, -8, -2, 3, 1, 3, 2, -6, -3, -10, -6, -7, -9]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[2, -4, 1, 7, -8, -8, -2, 3, 1, 3, 2, -6, -3, -10, -6, -7, -9]):\n return max(hello)" + "name": "SortPlusPlus:0", + "sat": "def sat(s: str, inp=\"1+1+3+1+3+2+2+1+3+1+2\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"1+1+3+1+3+2+2+1+3+1+2\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 }, { - "name": "MaxInt_9", - "sat": "def sat(m: int, hello=[3, 7, 3, 0, -5, 3, -5, 8, 5, -7, -3, -8, 7, -9, -9, 3]):\n \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"\n return m in hello and not any(m < i for i in hello)", - "sols": [ - "def sol(hello=[3, 7, 3, 0, -5, 3, -5, 8, 5, -7, -3, -8, 7, -9, -9, 3]):\n return max(hello)" + "name": "SortPlusPlus:1", + "sat": "def sat(s: str, inp=\"2+3+1+2+2+2+1+1+1+3+2+3+3+3+2+3+1+3+3+2+1+2+3+1+2+1+3+2+3+1+1+2+2+3+1+2+2+1+3+2+3+2+3+2+2\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"2+3+1+2+2+2+1+1+1+3+2+3+3+3+2+3+1+3+3+2+1+2+3+1+2+1+3+2+3+1+1+2+2+3+1+2+2+1+3+2+3+2+3+2+2\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_0", - "sat": "def sat(li: List[List[int]], n=19723, lower=1000):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=19723, lower=1000):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "SortPlusPlus:2", + "sat": "def sat(s: str, inp=\"3+2+2\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"3+2+2\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_1", - "sat": "def sat(li: List[List[int]], n=5, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=5, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "SortPlusPlus:3", + "sat": "def sat(s: str, inp=\"3+2+1+1+3+3+2+2+2+3+2+3+3+1+1\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"3+2+1+1+3+3+2+2+2+3+2+3+3+1+1\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_2", - "sat": "def sat(li: List[List[int]], n=8, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=8, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "SortPlusPlus:4", + "sat": "def sat(s: str, inp=\"2+2+2+1+1+1+2+1+3+3+3+3+2+2+2+1+2+3+3+1+3+2+3+2+3+2+2+3+2+3+1+2+1+3+3+2+3+1+1+3+3+1\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"2+2+2+1+1+1+2+1+3+3+3+3+2+2+2+1+2+3+3+1+3+2+3+2+3+2+2+3+2+3+1+2+1+3+3+2+3+1+1+3+3+1\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_3", - "sat": "def sat(li: List[List[int]], n=11, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=11, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "CapitalizeFirstLetter:0", + "sat": "def sat(s: str, word=\"konjac\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"konjac\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_4", - "sat": "def sat(li: List[List[int]], n=19, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=19, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "CapitalizeFirstLetter:1", + "sat": "def sat(s: str, word=\"nojapoxe\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"nojapoxe\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_5", - "sat": "def sat(li: List[List[int]], n=21, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=21, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "CapitalizeFirstLetter:2", + "sat": "def sat(s: str, word=\"silon\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"silon\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_6", - "sat": "def sat(li: List[List[int]], n=29, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=29, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "CapitalizeFirstLetter:3", + "sat": "def sat(s: str, word=\"fekovo\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"fekovo\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_7", - "sat": "def sat(li: List[List[int]], n=31, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=31, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "CapitalizeFirstLetter:4", + "sat": "def sat(s: str, word=\"mo\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"mo\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_8", - "sat": "def sat(li: List[List[int]], n=42, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=42, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "LongestSubsetString:0", + "sat": "def sat(t: str, s=\"abbbcabbac\", target=7):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"abbbcabbac\", target=7):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 }, { - "name": "SevenElevenThirteen_9", - "sat": "def sat(li: List[List[int]], n=44, lower=0):\n \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", - "sols": [ - "def sol(n=44, lower=0):\n return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + "name": "LongestSubsetString:1", + "sat": "def sat(t: str, s=\"cbbbbbcbbbbbbbaccacacaacbbcaaacbbaacbabacabccbbbcaacbbacaabcabbaacbbaa\", target=43):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"cbbbbbcbbbbbbbaccacacaacbbcaaacbbaacbabacabccbbbcaacbbacaabcabbaacbbaa\", target=43):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 }, { - "name": "HalfSorted_0", - "sat": "def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "LongestSubsetString:2", + "sat": "def sat(t: str, s=\"bcb\", target=3):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"bcb\", target=3):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 }, { - "name": "HalfSorted_1", - "sat": "def sat(li: List[int], orig=[-1, -9, 7, 8, -8, 2, -7]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[-1, -9, 7, 8, -8, 2, -7]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "LongestSubsetString:3", + "sat": "def sat(t: str, s=\"c\", target=1):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"c\", target=1):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 }, { - "name": "HalfSorted_2", - "sat": "def sat(li: List[int], orig=[4, -3, -8]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[4, -3, -8]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "LongestSubsetString:4", + "sat": "def sat(t: str, s=\"bcbcabba\", target=7):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"bcbcabba\", target=7):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 }, { - "name": "HalfSorted_3", - "sat": "def sat(li: List[int], orig=[3, 6, -7, 1, 2, -10, 6, -8, -9, -9, 6, -7, 7, -6, 1, 4, -8, -1, 8]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[3, 6, -7, 1, 2, -10, 6, -8, -9, -9, 6, -7, 7, -6, 1, 4, -8, -1, 8]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "FindHomogeneousSubstring:0", + "sat": "def sat(n: int, s=\"0000101111111000010\", k=5):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"0000101111111000010\", k=5):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 }, { - "name": "HalfSorted_4", - "sat": "def sat(li: List[int], orig=[-7, 6, 8, 8, -3, -5, -6, -5, 6, 7, 5, 7, -9, 9, -7, 4, -8, 8, -9]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[-7, 6, 8, 8, -3, -5, -6, -5, 6, 7, 5, 7, -9, 9, -7, 4, -8, 8, -9]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "FindHomogeneousSubstring:1", + "sat": "def sat(n: int, s=\"000000\", k=4):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"000000\", k=4):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 }, { - "name": "HalfSorted_5", - "sat": "def sat(li: List[int], orig=[9, 4, 9, 2, 3, -3, 1, -1, -9, 9]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[9, 4, 9, 2, 3, -3, 1, -1, -9, 9]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "FindHomogeneousSubstring:2", + "sat": "def sat(n: int, s=\"001100000000000000000000101010100111101110000100\", k=18):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"001100000000000000000000101010100111101110000100\", k=18):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 }, { - "name": "HalfSorted_6", - "sat": "def sat(li: List[int], orig=[-6, -10, -2]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[-6, -10, -2]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "FindHomogeneousSubstring:3", + "sat": "def sat(n: int, s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 }, { - "name": "HalfSorted_7", - "sat": "def sat(li: List[int], orig=[9, 8, 8, -6, 7, 5, -7, 0, 0, 1, 0]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[9, 8, 8, -6, 7, 5, -7, 0, 0, 1, 0]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "FindHomogeneousSubstring:4", + "sat": "def sat(n: int, s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 }, { - "name": "HalfSorted_8", - "sat": "def sat(li: List[int], orig=[9, -9, -6, 5, 1, -3, 1, 4, -6, -5, 8, -7, 0, 7, 9, 8, 2, -2, 1]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[9, -9, -6, 5, 1, -3, 1, 4, -6, -5, 8, -7, 0, 7, 9, 8, 2, -2, 1]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "Triple0:0", + "sat": "def sat(delta: List[int], nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 }, { - "name": "HalfSorted_9", - "sat": "def sat(li: List[int], orig=[1, 5, -4, 9]):\n \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", - "sols": [ - "def sol(orig=[1, 5, -4, 9]):\n n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + "name": "Triple0:1", + "sat": "def sat(delta: List[int], nums=[[-48, -64, 10], [-6, 46, 95], [89, 95, 20], [-96, 45, 74], [-78, 19, 47], [-6, -69, 55]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[-48, -64, 10], [-6, 46, 95], [89, 95, 20], [-96, 45, 74], [-78, 19, 47], [-6, -69, 55]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_0", - "sat": "def sat(s: str, target=\"Hello world\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"Hello world\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "Triple0:2", + "sat": "def sat(delta: List[int], nums=[[-17, -87, 34], [-8, -47, -68], [92, -14, -18], [18, 89, 85], [52, 89, -56], [-38, -19, -53], [-78, -25, -34]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[-17, -87, 34], [-8, -47, -68], [92, -14, -18], [18, 89, 85], [52, 89, -56], [-38, -19, -53], [-78, -25, -34]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_1", - "sat": "def sat(s: str, target=\"rugetytextirocuterup\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"rugetytextirocuterup\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "Triple0:3", + "sat": "def sat(delta: List[int], nums=[[35, -53, 59], [78, -51, 93], [-20, -17, -17], [64, 46, -24], [-81, -100, 47], [-98, -21, 47], [48, -85, -55], [-82, -29, 65]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[35, -53, 59], [78, -51, 93], [-20, -17, -17], [64, 46, -24], [-81, -100, 47], [-98, -21, 47], [48, -85, -55], [-82, -29, 65]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_2", - "sat": "def sat(s: str, target=\"torusajidapaficiretoh\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"torusajidapaficiretoh\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "Triple0:4", + "sat": "def sat(delta: List[int], nums=[[-16, 53, 37], [-54, -85, 65], [-46, 49, -81], [88, -47, -35], [53, -82, 4], [45, 94, 39], [72, -57, 27], [40, 35, -44], [-15, 32, 21]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[-16, 53, 37], [-54, -85, 65], [-46, 49, -81], [88, -47, -35], [53, -82, 4], [45, 94, 39], [72, -57, 27], [40, 35, -44], [-15, 32, 21]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_3", - "sat": "def sat(s: str, target=\"quitextaf\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"quitextaf\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TotalDifference:0", + "sat": "def sat(n: int, a=17, b=100, c=20):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=17, b=100, c=20):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_4", - "sat": "def sat(s: str, target=\"thoqui\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"thoqui\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TotalDifference:1", + "sat": "def sat(n: int, a=62, b=92, c=24):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=62, b=92, c=24):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_5", - "sat": "def sat(s: str, target=\"voxahowymoxitizikexyw\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"voxahowymoxitizikexyw\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TotalDifference:2", + "sat": "def sat(n: int, a=14, b=50, c=47):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=14, b=50, c=47):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_6", - "sat": "def sat(s: str, target=\"fosajolehavichuchigythohatextu\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"fosajolehavichuchigythohatextu\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TotalDifference:3", + "sat": "def sat(n: int, a=62, b=63, c=13):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=62, b=63, c=13):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_7", - "sat": "def sat(s: str, target=\"viju\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"viju\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TotalDifference:4", + "sat": "def sat(n: int, a=5, b=31, c=37):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=5, b=31, c=37):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_8", - "sat": "def sat(s: str, target=\"muwexigethefuhesipa\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"muwexigethefuhesipa\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TripleDouble:0", + "sat": "def sat(n: int, v=17, w=100):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=17, w=100):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 }, { - "name": "ThreeCycle_9", - "sat": "def sat(s: str, target=\"guquythyratextun\"):\n \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n \"\"\"\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", - "sols": [ - "def sol(target=\"guquythyratextun\"):\n def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + "name": "TripleDouble:1", + "sat": "def sat(n: int, v=75129500, w=979292947):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=75129500, w=979292947):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 }, { - "name": "PrimeFib_0", - "sat": "def sat(n: int, lower=123456):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=123456):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "TripleDouble:2", + "sat": "def sat(n: int, v=609909721, w=872375011):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=609909721, w=872375011):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 }, { - "name": "PrimeFib_1", - "sat": "def sat(n: int, lower=3):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=3):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "TripleDouble:3", + "sat": "def sat(n: int, v=313946483, w=806690290):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=313946483, w=806690290):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 }, { - "name": "PrimeFib_2", - "sat": "def sat(n: int, lower=458):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=458):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "TripleDouble:4", + "sat": "def sat(n: int, v=54888266, w=670740803):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=54888266, w=670740803):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 }, { - "name": "PrimeFib_3", - "sat": "def sat(n: int, lower=384):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=384):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "RepeatDec:0", + "sat": "def sat(res: int, m=1234578987654321, n=4):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=1234578987654321, n=4):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 }, { - "name": "PrimeFib_4", - "sat": "def sat(n: int, lower=4):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=4):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "RepeatDec:1", + "sat": "def sat(res: int, m=52891398375817839454, n=3):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=52891398375817839454, n=3):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 }, { - "name": "PrimeFib_5", - "sat": "def sat(n: int, lower=1781):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=1781):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "RepeatDec:2", + "sat": "def sat(res: int, m=22262059435814874058, n=6):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=22262059435814874058, n=6):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 }, { - "name": "PrimeFib_6", - "sat": "def sat(n: int, lower=346):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=346):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "RepeatDec:3", + "sat": "def sat(res: int, m=23602903522227899062, n=2):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=23602903522227899062, n=2):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 }, { - "name": "PrimeFib_7", - "sat": "def sat(n: int, lower=14):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=14):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "RepeatDec:4", + "sat": "def sat(res: int, m=27368816582234104063, n=4):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=27368816582234104063, n=4):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 }, { - "name": "PrimeFib_8", - "sat": "def sat(n: int, lower=2802):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=2802):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "ShortestDecDelta:0", + "sat": "def sat(li: List[int], n=149432, upper=14943):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=149432, upper=14943):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 }, { - "name": "PrimeFib_9", - "sat": "def sat(n: int, lower=224):\n \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n \"\"\"\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", - "sols": [ - "def sol(lower=224):\n m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + "name": "ShortestDecDelta:1", + "sat": "def sat(li: List[int], n=493863, upper=49386):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=493863, upper=49386):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_0", - "sat": "def sat(inds: List[int], nums=[12, -10452, 18242, 10440]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[12, -10452, 18242, 10440]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "ShortestDecDelta:2", + "sat": "def sat(li: List[int], n=827208, upper=82720):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=827208, upper=82720):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_1", - "sat": "def sat(inds: List[int], nums=[72, -169, -65, 97]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[72, -169, -65, 97]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "ShortestDecDelta:3", + "sat": "def sat(li: List[int], n=176183, upper=17618):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=176183, upper=17618):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_2", - "sat": "def sat(inds: List[int], nums=[3, 63, 66, -69]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[3, 63, 66, -69]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "ShortestDecDelta:4", + "sat": "def sat(li: List[int], n=483088, upper=48308):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=483088, upper=48308):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_3", - "sat": "def sat(inds: List[int], nums=[-34, -34, 68, 12]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[-34, -34, 68, 12]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "MaxDelta:0", + "sat": "def sat(n: int, pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_4", - "sat": "def sat(inds: List[int], nums=[71, -74, -57, -14]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[71, -74, -57, -14]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "MaxDelta:1", + "sat": "def sat(n: int, pairs=[[735272, 0], [959403, 509925], [627622, 420078], [26718, 90062], [175999, 98715], [428400, 1098754], [958640, 543606], [983032, 181754], [143406, 1301552], [183299, 437141], [133206, 199853], [679951, 366700], [383704, 737787], [476200, 226078], [923093, 81263], [574756, 679331], [766050, 5511], [214260, 445680], [434074, 747765], [769774, 209386], [512796, 2095723], [0, 612991]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[735272, 0], [959403, 509925], [627622, 420078], [26718, 90062], [175999, 98715], [428400, 1098754], [958640, 543606], [983032, 181754], [143406, 1301552], [183299, 437141], [133206, 199853], [679951, 366700], [383704, 737787], [476200, 226078], [923093, 81263], [574756, 679331], [766050, 5511], [214260, 445680], [434074, 747765], [769774, 209386], [512796, 2095723], [0, 612991]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_5", - "sat": "def sat(inds: List[int], nums=[17, -57, -54, 40]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[17, -57, -54, 40]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "MaxDelta:2", + "sat": "def sat(n: int, pairs=[[266519, 0], [548032, 32788], [612482, 632311], [465240, 376403], [123288, 475698], [962873, 439482], [193531, 258475], [747616, 319130], [592192, 824307], [508933, 296745], [411467, 566648], [905981, 19854], [805465, 657818], [802088, 325540], [127441, 1703553], [19150, 964316], [0, 199230]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[266519, 0], [548032, 32788], [612482, 632311], [465240, 376403], [123288, 475698], [962873, 439482], [193531, 258475], [747616, 319130], [592192, 824307], [508933, 296745], [411467, 566648], [905981, 19854], [805465, 657818], [802088, 325540], [127441, 1703553], [19150, 964316], [0, 199230]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_6", - "sat": "def sat(inds: List[int], nums=[-51, 61, -72, 123]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[-51, 61, -72, 123]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "MaxDelta:3", + "sat": "def sat(n: int, pairs=[[0, 0]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[0, 0]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_7", - "sat": "def sat(inds: List[int], nums=[20, 21, -62, 42]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[20, 21, -62, 42]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "MaxDelta:4", + "sat": "def sat(n: int, pairs=[[459604, 0], [364611, 68505], [562652, 512251], [668655, 471975], [464486, 626280], [138684, 177065], [163296, 68630], [188271, 104677], [367839, 338137], [73022, 362103], [464143, 484458], [214935, 189299], [643725, 283515], [908210, 541732], [710201, 234839], [854230, 34479], [3288, 675724], [846637, 396244], [0, 2526576]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[459604, 0], [364611, 68505], [562652, 512251], [668655, 471975], [464486, 626280], [138684, 177065], [163296, 68630], [188271, 104677], [367839, 338137], [73022, 362103], [464143, 484458], [214935, 189299], [643725, 283515], [908210, 541732], [710201, 234839], [854230, 34479], [3288, 675724], [846637, 396244], [0, 2526576]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 }, { - "name": "TripleZeroSum_8", - "sat": "def sat(inds: List[int], nums=[-18, 88, 1, 17]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[-18, 88, 1, 17]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "CommonCase:0", + "sat": "def sat(s_case: str, s=\"CanYouTellIfItHASmoreCAPITALS\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"CanYouTellIfItHASmoreCAPITALS\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 }, { - "name": "TripleZeroSum_9", - "sat": "def sat(inds: List[int], nums=[65, -85, 20, 54]):\n \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n \"\"\"\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0 and min(inds) >= 0", - "sols": [ - "def sol(nums=[65, -85, 20, 54]):\n assert len(nums) == 4\n n = sum(nums)\n for i in range(4):\n if nums[i] == n:\n return [j for j in range(4) if j != i]" + "name": "CommonCase:1", + "sat": "def sat(s_case: str, s=\"ThUcynICHiHIc\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"ThUcynICHiHIc\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 }, { - "name": "NumPasses_0", - "sat": "def sat(count: int, n=981):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=981):\n return n ** 2" + "name": "CommonCase:2", + "sat": "def sat(s_case: str, s=\"riziP\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"riziP\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 }, { - "name": "NumPasses_1", - "sat": "def sat(count: int, n=123):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=123):\n return n ** 2" + "name": "CommonCase:3", + "sat": "def sat(s_case: str, s=\"KANExAjoHiBotipomyVOkATuMY\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"KANExAjoHiBotipomyVOkATuMY\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 }, { - "name": "NumPasses_2", - "sat": "def sat(count: int, n=239):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=239):\n return n ** 2" + "name": "CommonCase:4", + "sat": "def sat(s_case: str, s=\"rAC\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"rAC\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 }, { - "name": "NumPasses_3", - "sat": "def sat(count: int, n=378):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=378):\n return n ** 2" + "name": "Sssuubbstriiingg:0", + "sat": "def sat(inds: List[int], string=\"Sssuubbstrissiingg\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"Sssuubbstrissiingg\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_4", - "sat": "def sat(count: int, n=501):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=501):\n return n ** 2" + "name": "Sssuubbstriiingg:1", + "sat": "def sat(inds: List[int], string=\"su absItIstrilnvgenw\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"su absItIstrilnvgenw\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_5", - "sat": "def sat(count: int, n=948):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=948):\n return n ** 2" + "name": "Sssuubbstriiingg:2", + "sat": "def sat(inds: List[int], string=\"sKubssB tzCzPrZiL inCgN\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"sKubssB tzCzPrZiL inCgN\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_6", - "sat": "def sat(count: int, n=118):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=118):\n return n ** 2" + "name": "Sssuubbstriiingg:3", + "sat": "def sat(inds: List[int], string=\"suUbstriPng\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"suUbstriPng\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_7", - "sat": "def sat(count: int, n=915):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=915):\n return n ** 2" + "name": "Sssuubbstriiingg:4", + "sat": "def sat(inds: List[int], string=\"stuqb VqsMJptxriWYe nmfgNfW\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"stuqb VqsMJptxriWYe nmfgNfW\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_8", - "sat": "def sat(count: int, n=141):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=141):\n return n ** 2" + "name": "Sstriiinggssuubb:0", + "sat": "def sat(inds: List[int], string=\"enlightenment\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"enlightenment\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "NumPasses_9", - "sat": "def sat(count: int, n=687):\n \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n \"\"\"\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", - "sols": [ - "def sol(n=687):\n return n ** 2" + "name": "Sstriiinggssuubb:1", + "sat": "def sat(inds: List[int], string=\"inntGetlige\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"inntGetlige\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "ListInc_0", - "sat": "def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):\n return [i + 1 for i in old_list]" + "name": "Sstriiinggssuubb:2", + "sat": "def sat(inds: List[int], string=\"gteliikeenGgqIHent\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"gteliikeenGgqIHent\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "ListInc_1", - "sat": "def sat(new_list: List[int], old_list=[18, 29, 40]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[18, 29, 40]):\n return [i + 1 for i in old_list]" + "name": "Sstriiinggssuubb:3", + "sat": "def sat(inds: List[int], string=\"xaGliigNntJfeeSm nnEyt\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"xaGliigNntJfeeSm nnEyt\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "ListInc_2", - "sat": "def sat(new_list: List[int], old_list=[43, 64, 73, 30, 47]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[43, 64, 73, 30, 47]):\n return [i + 1 for i in old_list]" + "name": "Sstriiinggssuubb:4", + "sat": "def sat(inds: List[int], string=\" einliJSgeteq ne CAlti\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\" einliJSgeteq ne CAlti\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 }, { - "name": "ListInc_3", - "sat": "def sat(new_list: List[int], old_list=[43, 9, 49, 93, 36, 47, 48, 38, 12]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[43, 9, 49, 93, 36, 47, 48, 38, 12]):\n return [i + 1 for i in old_list]" + "name": "Moving0s:0", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 }, { - "name": "ListInc_4", - "sat": "def sat(new_list: List[int], old_list=[45, 55, 71, 78, 54]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[45, 55, 71, 78, 54]):\n return [i + 1 for i in old_list]" + "name": "Moving0s:1", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=9):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=9):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 }, { - "name": "ListInc_5", - "sat": "def sat(new_list: List[int], old_list=[36, 88, 17, 62, 5, 81, 22, 0, 36]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[36, 88, 17, 62, 5, 81, 22, 0, 36]):\n return [i + 1 for i in old_list]" + "name": "Moving0s:2", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0], n_steps=4):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0], n_steps=4):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 }, { - "name": "ListInc_6", - "sat": "def sat(new_list: List[int], old_list=[50, 46, 40]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[50, 46, 40]):\n return [i + 1 for i in old_list]" + "name": "Moving0s:3", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=12):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=12):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 }, { - "name": "ListInc_7", - "sat": "def sat(new_list: List[int], old_list=[50, 21, 18, 15]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[50, 21, 18, 15]):\n return [i + 1 for i in old_list]" + "name": "Moving0s:4", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 0, 0, 0, 0], n_steps=3):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 0, 0, 0, 0], n_steps=3):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 }, { - "name": "ListInc_8", - "sat": "def sat(new_list: List[int], old_list=[23, 45]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[23, 45]):\n return [i + 1 for i in old_list]" + "name": "Factor47:0", + "sat": "def sat(d: int, n=6002685529):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=6002685529):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 }, { - "name": "ListInc_9", - "sat": "def sat(new_list: List[int], old_list=[95, 46, 45, 42]):\n \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n \"\"\"\n return [i - 1 for i in new_list] == old_list", - "sols": [ - "def sol(old_list=[95, 46, 45, 42]):\n return [i + 1 for i in old_list]" + "name": "Factor47:1", + "sat": "def sat(d: int, n=16):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=16):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" ], - "module": "human_eval", - "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_0", - "sat": "def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Factor47:2", + "sat": "def sat(d: int, n=433459952851983617609247):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=433459952851983617609247):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_1", - "sat": "def sat(inds: List[int], nums=[50, 33, 12, -13, 65, -39, -12, -72, -61, -38, -58, -88, 70, -82, -80, 27, 68, 89, -57, 15, -33, 93, 57, -91, 60, -72, -19, -12, 70, -35, 53, -21, -19, 66, 58, 76, -92, 64, 52, -21, 29, -61, -10, 50, -88, 17, 0, -50, 52, -87, 9, -95, 59, 23, 69, -34, 73, -39, 15, 17, 37, -83, -31, 13, -33, 6, -27, -45, -15, -78, 74, 92, 56, -52, 44, -9, -22, 27, -94, -17, 5, -82, -40, 22, -91, 10, 57, 13, -41, -93, -40, -42, 28, -3, 82]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[50, 33, 12, -13, 65, -39, -12, -72, -61, -38, -58, -88, 70, -82, -80, 27, 68, 89, -57, 15, -33, 93, 57, -91, 60, -72, -19, -12, 70, -35, 53, -21, -19, 66, 58, 76, -92, 64, 52, -21, 29, -61, -10, 50, -88, 17, 0, -50, 52, -87, 9, -95, 59, 23, 69, -34, 73, -39, 15, 17, 37, -83, -31, 13, -33, 6, -27, -45, -15, -78, 74, 92, 56, -52, 44, -9, -22, 27, -94, -17, 5, -82, -40, 22, -91, 10, 57, 13, -41, -93, -40, -42, 28, -3, 82]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Factor47:3", + "sat": "def sat(d: int, n=738195924589532712188415):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=738195924589532712188415):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_2", - "sat": "def sat(inds: List[int], nums=[18, -81, 7, -48, -14, 88, -34, 29, 72, 16, 38, -29, 53, -52, 16, 31, 65, 1, -77, 24, -73, 8, 78, -13, -96, 29, -3, 45, -44, 98, 9, -89, -50, 46, -88, 89, -93, 98, -83, -3, -17, 72, 25, 18, 88, -32, -37, -26, 69, -39, 62, 64, 41, 58, 29, 33, -65, -13, 61, 41, -90, -79, -94, -81, 40, 46, -78, -13, -44, 9, 42, -90, 94, -19, 5, -33, 33, -60, 80, -40, -64, 19, -92, 62, -12, -58, 89, -50, -82, -32, 65, 82, -49, 80, -71, 68, -17, 26, 6, -61]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[18, -81, 7, -48, -14, 88, -34, 29, 72, 16, 38, -29, 53, -52, 16, 31, 65, 1, -77, 24, -73, 8, 78, -13, -96, 29, -3, 45, -44, 98, 9, -89, -50, 46, -88, 89, -93, 98, -83, -3, -17, 72, 25, 18, 88, -32, -37, -26, 69, -39, 62, 64, 41, 58, 29, 33, -65, -13, 61, 41, -90, -79, -94, -81, 40, 46, -78, -13, -44, 9, 42, -90, 94, -19, 5, -33, 33, -60, 80, -40, -64, 19, -92, 62, -12, -58, 89, -50, -82, -32, 65, 82, -49, 80, -71, 68, -17, 26, 6, -61]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Factor47:4", + "sat": "def sat(d: int, n=323190690645573746957862):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=323190690645573746957862):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_3", - "sat": "def sat(inds: List[int], nums=[61, 13, 32, -67, -29, 6, 65, 82, -36, -90, -3, -53, -80, 52, -20, 14, -58, 1, 14, 88, 90, -76, -83, 47, -20, -26, 5, 71, 29, -51, -6, 38, -42, -48, 9, -74, -37, -86, -31, -63, -45, -74, -40, 23, -16, 24, -6, -93, -46, -42, -4, -85, -91, 71, -72, 11, -33, 33, -82, -67, -34, -60, 89, 60, 26, -12, -92, 42, -92, -58, -37, 9, -38, 54, 34, 25, 85, -65, -79, 33, -52, -72, -80, -76, -39, 24, -2, 40, -53, -14, 8, 21, 7, 46, -88, -67]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[61, 13, 32, -67, -29, 6, 65, 82, -36, -90, -3, -53, -80, 52, -20, 14, -58, 1, 14, 88, 90, -76, -83, 47, -20, -26, 5, 71, 29, -51, -6, 38, -42, -48, 9, -74, -37, -86, -31, -63, -45, -74, -40, 23, -16, 24, -6, -93, -46, -42, -4, -85, -91, 71, -72, 11, -33, 33, -82, -67, -34, -60, 89, 60, 26, -12, -92, 42, -92, -58, -37, 9, -38, 54, 34, 25, 85, -65, -79, 33, -52, -72, -80, -76, -39, 24, -2, 40, -53, -14, 8, 21, 7, 46, -88, -67]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Count47:0", + "sat": "def sat(d: int, n=123456789):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=123456789):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_4", - "sat": "def sat(inds: List[int], nums=[4, -4, -4, -3, 3, 1]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[4, -4, -4, -3, 3, 1]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Count47:1", + "sat": "def sat(d: int, n=659104579100082212):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=659104579100082212):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_5", - "sat": "def sat(inds: List[int], nums=[49, -15, -56, -2, -48, 27, -22, -20, 62, -43, 64, 9, -5, 0, -64, -44, -64, -56, -28, 18, 0, 64, -11, 42, -62, -2, -35, -41, 0, -20, 30, 16, -57, 38, -46, 23, 46, -49, 40, -16, 33, 62, -66, 58, 36, 39, -20, -41, 62, -5, 22, -51, -14, 7, 37, 7, 55, 10, 38, -25, -28, -28, 63, -21, 36, -48]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[49, -15, -56, -2, -48, 27, -22, -20, 62, -43, 64, 9, -5, 0, -64, -44, -64, -56, -28, 18, 0, 64, -11, 42, -62, -2, -35, -41, 0, -20, 30, 16, -57, 38, -46, 23, 46, -49, 40, -16, 33, 62, -66, 58, 36, 39, -20, -41, 62, -5, 22, -51, -14, 7, 37, 7, 55, 10, 38, -25, -28, -28, 63, -21, 36, -48]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Count47:2", + "sat": "def sat(d: int, n=476988101965):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=476988101965):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_6", - "sat": "def sat(inds: List[int], nums=[13, 42, -1, 17, -39, 1, -1, 29, -54, -36, 21, -58, 18, 53, -31, 27, -52, 15, 22, -48, 6, 10, -18, -51, 15, 4, 62, 37, -34, -11, 13, 41, -56, 48, 65, -39, 30, 54, -50, 18, 41, 63, 34, -35, 47, -44, -56, -29, -9, 29, -31, 12, 36, 30, 22, -32, 59, 11, -18, 29, 10, -20, 49, 27, 17, 31, 36]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[13, 42, -1, 17, -39, 1, -1, 29, -54, -36, 21, -58, 18, 53, -31, 27, -52, 15, 22, -48, 6, 10, -18, -51, 15, 4, 62, 37, -34, -11, 13, 41, -56, 48, 65, -39, 30, 54, -50, 18, 41, 63, 34, -35, 47, -44, -56, -29, -9, 29, -31, 12, 36, 30, 22, -32, 59, 11, -18, 29, 10, -20, 49, 27, 17, 31, 36]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Count47:3", + "sat": "def sat(d: int, n=3169877099077541094754):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=3169877099077541094754):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_7", - "sat": "def sat(inds: List[int], nums=[3, -1, -3, 3, 1, 2]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[3, -1, -3, 3, 1, 2]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "Count47:4", + "sat": "def sat(d: int, n=707):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=707):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_8", - "sat": "def sat(inds: List[int], nums=[-15, -25, 7, 30, -19, 14, 4, -18, 9, 15, -23, -6, -24, 33, -7, -1, -30, -30, 16, 2, 22, -17, 9, 4, 32, 20, 22, 26, -33, -18, -28, -30, 0, 5]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[-15, -25, 7, 30, -19, 14, 4, -18, 9, 15, -23, -6, -24, 33, -7, -1, -30, -30, 16, 2, 22, -17, 9, 4, 32, 20, 22, 26, -33, -18, -28, -30, 0, 5]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "MaybeReversed:0", + "sat": "def sat(s: str, target=\"reverse me\", reverse=True):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"reverse me\", reverse=True):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 }, { - "name": "PairZeroSum_9", - "sat": "def sat(inds: List[int], nums=[-17, -64, -34, 66, -44, -70, -15, 6, -20, -65, -66, 40, -2, -54, -37, 0, -58, -32, -51, 16, -52, -39, 53, 34, -54, -67, -26, 53, 13, 53, -63, -45, 30, -67, 39, 62, 38, 10, -26, 48, 36, 59, -50, 15, -36, -29, -25, 46, 1, -36, -54, 43, -22, -50, 33, -67, -35, 28, -65, -4, 20, -22, 52, 36, 48, -67, 61, -63, 29, 19, 48]):\n \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n \"\"\"\n a, b = inds\n return nums[a] + nums[b] == 0", - "sols": [ - "def sol(nums=[-17, -64, -34, 66, -44, -70, -15, 6, -20, -65, -66, 40, -2, -54, -37, 0, -58, -32, -51, 16, -52, -39, 53, 34, -54, -67, -26, 53, 13, 53, -63, -45, 30, -67, 39, 62, 38, 10, -26, 48, 36, 59, -50, 15, -36, -29, -25, 46, 1, -36, -54, 43, -22, -50, 33, -67, -35, 28, -65, -4, 20, -22, 52, 36, 48, -67, 61, -63, 29, 19, 48]):\n s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + "name": "MaybeReversed:1", + "sat": "def sat(s: str, target=\"thubonyna\", reverse=True):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"thubonyna\", reverse=True):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 }, { - "name": "ChangeBase_0", - "sat": "def sat(s: str, n=142, base=7):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=142, base=7):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MaybeReversed:2", + "sat": "def sat(s: str, target=\"nivosypetextyzavalag\", reverse=False):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"nivosypetextyzavalag\", reverse=False):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 }, { - "name": "ChangeBase_1", - "sat": "def sat(s: str, n=85328, base=2):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=85328, base=2):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MaybeReversed:3", + "sat": "def sat(s: str, target=\"l\", reverse=False):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"l\", reverse=False):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 }, { - "name": "ChangeBase_2", - "sat": "def sat(s: str, n=9576751, base=10):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=9576751, base=10):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MaybeReversed:4", + "sat": "def sat(s: str, target=\"rechawewivetextovy\", reverse=True):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"rechawewivetextovy\", reverse=True):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 }, { - "name": "ChangeBase_3", - "sat": "def sat(s: str, n=5160280, base=5):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=5160280, base=5):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MinBigger:0", + "sat": "def sat(taken: List[int], val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 }, { - "name": "ChangeBase_4", - "sat": "def sat(s: str, n=4884658, base=6):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=4884658, base=6):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MinBigger:1", + "sat": "def sat(taken: List[int], val_counts=[[51, 67], [78, 13], [7, 68], [84, 54], [39, 38]], upper=66):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[51, 67], [78, 13], [7, 68], [84, 54], [39, 38]], upper=66):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 }, { - "name": "ChangeBase_5", - "sat": "def sat(s: str, n=6477511, base=4):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=6477511, base=4):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MinBigger:2", + "sat": "def sat(taken: List[int], val_counts=[[28, 29], [42, 54], [62, 85], [42, 95], [92, 32], [36, 35], [78, 56], [43, 20], [49, 17]], upper=153):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[28, 29], [42, 54], [62, 85], [42, 95], [92, 32], [36, 35], [78, 56], [43, 20], [49, 17]], upper=153):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 }, { - "name": "ChangeBase_6", - "sat": "def sat(s: str, n=5450297, base=6):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=5450297, base=6):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MinBigger:3", + "sat": "def sat(taken: List[int], val_counts=[[44, 92], [28, 7], [56, 37], [37, 66]], upper=90):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[44, 92], [28, 7], [56, 37], [37, 66]], upper=90):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 }, { - "name": "ChangeBase_7", - "sat": "def sat(s: str, n=9133628, base=8):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=9133628, base=8):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "MinBigger:4", + "sat": "def sat(taken: List[int], val_counts=[[23, 93], [64, 14], [36, 8], [89, 92]], upper=65):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[23, 93], [64, 14], [36, 8], [89, 92]], upper=65):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 }, { - "name": "ChangeBase_8", - "sat": "def sat(s: str, n=6334815, base=2):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=6334815, base=2):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "Dada:0", + "sat": "def sat(s: str, a=5129, d=17):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=5129, d=17):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 }, { - "name": "ChangeBase_9", - "sat": "def sat(s: str, n=983031, base=4):\n \"\"\"\n Write n in the given base as a string\n \"\"\"\n return int(s, base) == n", - "sols": [ - "def sol(n=983031, base=4):\n assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + "name": "Dada:1", + "sat": "def sat(s: str, a=5798, d=1873):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=5798, d=1873):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 }, { - "name": "TriangleArea_0", - "sat": "def sat(height: int, area=1319098728582, base=45126):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=1319098728582, base=45126):\n return (2 * area) // base" + "name": "Dada:2", + "sat": "def sat(s: str, a=2645, d=1270):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=2645, d=1270):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 }, { - "name": "TriangleArea_1", - "sat": "def sat(height: int, area=2642925075, base=211434006):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=2642925075, base=211434006):\n return (2 * area) // base" + "name": "Dada:3", + "sat": "def sat(s: str, a=2996, d=6808):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=2996, d=6808):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 }, { - "name": "TriangleArea_2", - "sat": "def sat(height: int, area=5529468804, base=18936537):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=5529468804, base=18936537):\n return (2 * area) // base" + "name": "Dada:4", + "sat": "def sat(s: str, a=4763, d=8408):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=4763, d=8408):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 }, { - "name": "TriangleArea_3", - "sat": "def sat(height: int, area=1238452500, base=600):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=1238452500, base=600):\n return (2 * area) // base" + "name": "DistinctDigits:0", + "sat": "def sat(nums: List[int], a=100, b=1000, count=648):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=100, b=1000, count=648):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 }, { - "name": "TriangleArea_4", - "sat": "def sat(height: int, area=32576448, base=147072):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=32576448, base=147072):\n return (2 * area) // base" + "name": "DistinctDigits:1", + "sat": "def sat(nums: List[int], a=79, b=169, count=67):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=79, b=169, count=67):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 }, { - "name": "TriangleArea_5", - "sat": "def sat(height: int, area=119486825710953, base=75837061):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=119486825710953, base=75837061):\n return (2 * area) // base" + "name": "DistinctDigits:2", + "sat": "def sat(nums: List[int], a=31, b=105, count=66):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=31, b=105, count=66):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 }, { - "name": "TriangleArea_6", - "sat": "def sat(height: int, area=39092406128640, base=891342):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=39092406128640, base=891342):\n return (2 * area) // base" + "name": "DistinctDigits:3", + "sat": "def sat(nums: List[int], a=52, b=95, count=40):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=52, b=95, count=40):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 }, { - "name": "TriangleArea_7", - "sat": "def sat(height: int, area=16292784, base=8):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=16292784, base=8):\n return (2 * area) // base" + "name": "DistinctDigits:4", + "sat": "def sat(nums: List[int], a=136, b=176, count=34):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=136, b=176, count=34):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 }, { - "name": "TriangleArea_8", - "sat": "def sat(height: int, area=64728, base=5394):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=64728, base=5394):\n return (2 * area) // base" + "name": "EasySum:0", + "sat": "def sat(tot: int, nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 }, { - "name": "TriangleArea_9", - "sat": "def sat(height: int, area=758884, base=758884):\n \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n \"\"\"\n return base * height == 2 * area", - "sols": [ - "def sol(area=758884, base=758884):\n return (2 * area) // base" + "name": "EasySum:1", + "sat": "def sat(tot: int, nums=[60, 63, 11], thresh=99):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[60, 63, 11], thresh=99):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 }, { - "name": "Fib4_0", - "sat": "def sat(init: List[int], target=2021):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=2021):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + "name": "EasySum:2", + "sat": "def sat(tot: int, nums=[32, 24, 19, 88, 6, 33, 13], thresh=33):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[32, 24, 19, 88, 6, 33, 13], thresh=33):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 }, { - "name": "Fib4_1", - "sat": "def sat(init: List[int], target=56):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=56):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + "name": "EasySum:3", + "sat": "def sat(tot: int, nums=[60, 72, 32, 29, 90, 9, 39, 67, 31, 71, 68, 72, 28, 85, 75, 60, 42, 66, 4, 71, 57, 45, 88, 20, 66, 97, 33, 43, 48], thresh=30):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[60, 72, 32, 29, 90, 9, 39, 67, 31, 71, 68, 72, 28, 85, 75, 60, 42, 66, 4, 71, 57, 45, 88, 20, 66, 97, 33, 43, 48], thresh=30):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 }, { - "name": "Fib4_2", - "sat": "def sat(init: List[int], target=58965):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=58965):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + "name": "EasySum:4", + "sat": "def sat(tot: int, nums=[61, 98, 33, 32, 4, 99, 91, 63, 76, 83, 52, 0, 19, 49, 85, 5, 54, 71, 41, 93, 54, 78, 92], thresh=91):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[61, 98, 33, 32, 4, 99, 91, 63, 76, 83, 52, 0, 19, 49, 85, 5, 54, 71, 41, 93, 54, 78, 92], thresh=91):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 }, { - "name": "Fib4_3", - "sat": "def sat(init: List[int], target=501192137):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=501192137):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "GimmeChars:0", + "sat": "def sat(s: str, chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 }, { - "name": "Fib4_4", - "sat": "def sat(init: List[int], target=0):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=0):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "GimmeChars:1", + "sat": "def sat(s: str, chars=['1', 'j', '3', 'Q', 'e']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=['1', 'j', '3', 'Q', 'e']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 }, { - "name": "Fib4_5", - "sat": "def sat(init: List[int], target=42):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=42):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "GimmeChars:2", + "sat": "def sat(s: str, chars=['[', '/', 'g']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=['[', '/', 'g']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 }, { - "name": "Fib4_6", - "sat": "def sat(init: List[int], target=4240):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=4240):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "GimmeChars:3", + "sat": "def sat(s: str, chars=[' ', 'e', '%', '1', 'f']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=[' ', 'e', '%', '1', 'f']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 }, { - "name": "Fib4_7", - "sat": "def sat(init: List[int], target=399934):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=399934):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "GimmeChars:4", + "sat": "def sat(s: str, chars=['W', '@', 'S']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=['W', '@', 'S']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 }, { - "name": "Fib4_8", - "sat": "def sat(init: List[int], target=23):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=23):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + "name": "HalfPairs:0", + "sat": "def sat(ans: List[List[int]], target=17):\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=17):", + "sol_docstring": " \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"", + "sol_bodies": [ + " return [[0, 2]] * target" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", + "weight": 1.0 }, { - "name": "Fib4_9", - "sat": "def sat(init: List[int], target=7246):\n \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", - "sols": [ - "def sol(target=7246):\n nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + "name": "HalfPairs:1", + "sat": "def sat(ans: List[List[int]], target=0):\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=0):", + "sol_docstring": " \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"", + "sol_bodies": [ + " return [[0, 2]] * target" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", + "weight": 1.0 }, { - "name": "Median_0", - "sat": "def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):\n return sorted(nums)[len(nums) // 2] if nums else 0" + "name": "HalfPairs:2", + "sat": "def sat(ans: List[List[int]], target=1):\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=1):", + "sol_docstring": " \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"", + "sol_bodies": [ + " return [[0, 2]] * target" ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", + "weight": 1.0 }, { - "name": "Median_1", - "sat": "def sat(x: int, nums=[-8813279918, 7464351342, 8037181984, 8564600186, 660800781], upper=-21408102335):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[-8813279918, 7464351342, 8037181984, 8564600186, 660800781], upper=-21408102335):\n return sorted(nums)[len(nums) // 2] if nums else 0" + "name": "HalfPairs:3", + "sat": "def sat(ans: List[List[int]], target=2):\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=2):", + "sol_docstring": " \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"", + "sol_bodies": [ + " return [[0, 2]] * target" ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", + "weight": 1.0 }, { - "name": "Median_2", - "sat": "def sat(x: int, nums: List[int]=[], upper=0):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[], upper=0):\n return sorted(nums)[len(nums) // 2] if nums else 0" - ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "InvertIndices:0", + "sat": "def sat(indexes: List[int], target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 }, { - "name": "Median_3", - "sat": "def sat(x: int, nums=[-2350083760, -34560579, 3780403495, -9390708907, 2424237816, -6782611896, 624505871], upper=-11486893907):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[-2350083760, -34560579, 3780403495, -9390708907, 2424237816, -6782611896, 624505871], upper=-11486893907):\n return sorted(nums)[len(nums) // 2] if nums else 0" - ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "InvertIndices:1", + "sat": "def sat(indexes: List[int], target=[16, 12, 67, 77, 23, 47, 24, 45, 61, 80, 43, 50, 57, 81, 21, 55, 9, 28, 14, 87, 58, 35, 37, 63, 41, 38, 6, 86, 59, 13, 49, 68, 83, 30, 40, 73, 15, 11, 85, 70, 33, 22, 76, 5, 82, 52, 27, 26, 34, 89, 1, 48, 64, 88, 19, 29, 65, 69, 31, 2, 74, 32, 60, 7, 46, 56, 78, 79, 36, 51, 72, 71, 54, 20, 90, 8, 53, 75, 39, 4, 17, 62, 25, 3, 84, 42, 44, 10, 66, 18]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[16, 12, 67, 77, 23, 47, 24, 45, 61, 80, 43, 50, 57, 81, 21, 55, 9, 28, 14, 87, 58, 35, 37, 63, 41, 38, 6, 86, 59, 13, 49, 68, 83, 30, 40, 73, 15, 11, 85, 70, 33, 22, 76, 5, 82, 52, 27, 26, 34, 89, 1, 48, 64, 88, 19, 29, 65, 69, 31, 2, 74, 32, 60, 7, 46, 56, 78, 79, 36, 51, 72, 71, 54, 20, 90, 8, 53, 75, 39, 4, 17, 62, 25, 3, 84, 42, 44, 10, 66, 18]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 }, { - "name": "Median_4", - "sat": "def sat(x: int, nums=[-2410166269, 5887293672], upper=-8297459941):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[-2410166269, 5887293672], upper=-8297459941):\n return sorted(nums)[len(nums) // 2] if nums else 0" - ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "InvertIndices:2", + "sat": "def sat(indexes: List[int], target=[4, 66, 52, 28, 11, 59, 15, 37, 32, 71, 48, 23, 41, 7, 68, 30, 2, 44, 33, 3, 14, 63, 40, 22, 35, 6, 27, 58, 36, 38, 53, 9, 24, 49, 54, 50, 72, 64, 69, 77, 25, 31, 42, 17, 57, 67, 55, 70, 47, 46, 10, 75, 20, 61, 34, 39, 18, 12, 56, 29, 62, 26, 73, 21, 5, 1, 8, 19, 51, 45, 74, 13, 43, 16, 76, 65, 60]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[4, 66, 52, 28, 11, 59, 15, 37, 32, 71, 48, 23, 41, 7, 68, 30, 2, 44, 33, 3, 14, 63, 40, 22, 35, 6, 27, 58, 36, 38, 53, 9, 24, 49, 54, 50, 72, 64, 69, 77, 25, 31, 42, 17, 57, 67, 55, 70, 47, 46, 10, 75, 20, 61, 34, 39, 18, 12, 56, 29, 62, 26, 73, 21, 5, 1, 8, 19, 51, 45, 74, 13, 43, 16, 76, 65, 60]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 }, { - "name": "Median_5", - "sat": "def sat(x: int, nums=[7181762824, -6196901361, -9836188944, 1494714769, -6298689522], upper=17329204571):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[7181762824, -6196901361, -9836188944, 1494714769, -6298689522], upper=17329204571):\n return sorted(nums)[len(nums) // 2] if nums else 0" - ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "InvertIndices:3", + "sat": "def sat(indexes: List[int], target=[47, 10, 38, 39, 63, 9, 20, 31, 3, 42, 24, 4, 48, 25, 40, 52, 33, 58, 12, 5, 35, 51, 17, 6, 57, 60, 56, 61, 32, 64, 13, 59, 27, 50, 43, 11, 55, 29, 16, 19, 45, 7, 26, 1, 49, 53, 36, 18, 34, 22, 41, 46, 23, 15, 2, 14, 21, 28, 44, 54, 62, 30, 37, 8]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[47, 10, 38, 39, 63, 9, 20, 31, 3, 42, 24, 4, 48, 25, 40, 52, 33, 58, 12, 5, 35, 51, 17, 6, 57, 60, 56, 61, 32, 64, 13, 59, 27, 50, 43, 11, 55, 29, 16, 19, 45, 7, 26, 1, 49, 53, 36, 18, 34, 22, 41, 46, 23, 15, 2, 14, 21, 28, 44, 54, 62, 30, 37, 8]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 }, { - "name": "Median_6", - "sat": "def sat(x: int, nums=[-813919846, -7460196291, -4979209752, 3451032105, -4515455690, -1468222643, -2282443079, 2507230870, -1394848407], upper=-3742028946):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[-813919846, -7460196291, -4979209752, 3451032105, -4515455690, -1468222643, -2282443079, 2507230870, -1394848407], upper=-3742028946):\n return sorted(nums)[len(nums) // 2] if nums else 0" - ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "InvertIndices:4", + "sat": "def sat(indexes: List[int], target=[3, 1, 6, 5, 4, 2]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[3, 1, 6, 5, 4, 2]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 }, { - "name": "Median_7", - "sat": "def sat(x: int, nums=[5736689555, 4568815891, -8581717225], upper=-11982659452):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[5736689555, 4568815891, -8581717225], upper=-11982659452):\n return sorted(nums)[len(nums) // 2] if nums else 0" + "name": "FivePowers:0", + "sat": "def sat(s: str, n=7012):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=7012):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 }, { - "name": "Median_8", - "sat": "def sat(x: int, nums=[2201065329, 8265157512, -3861797625], upper=1229229):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[2201065329, 8265157512, -3861797625], upper=1229229):\n return sorted(nums)[len(nums) // 2] if nums else 0" + "name": "FivePowers:1", + "sat": "def sat(s: str, n=0):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 }, { - "name": "Median_9", - "sat": "def sat(x: int, nums=[893018778, 2566796999, -5875031056, -6953766816, -6769023651, 5634632881, -447705230], upper=-7817141485):\n \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n \"\"\"\n dev = sum(n - x for n in nums)\n return dev <= upper", - "sols": [ - "def sol(nums=[893018778, 2566796999, -5875031056, -6953766816, -6769023651, 5634632881, -447705230], upper=-7817141485):\n return sorted(nums)[len(nums) // 2] if nums else 0" + "name": "FivePowers:2", + "sat": "def sat(s: str, n=1):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=1):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" ], - "module": "human_eval", - "notes": "One definition of the median is a number that minimizes the sum of absolute deviations.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_0", - "sat": "def sat(p: bool, s=\"This problem is trivial but common\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"This problem is trivial but common\"):\n return s == s[::-1]" + "name": "FivePowers:3", + "sat": "def sat(s: str, n=2):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=2):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_1", - "sat": "def sat(p: bool, s=\"borulathoquinych\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"borulathoquinych\"):\n return s == s[::-1]" + "name": "FivePowers:4", + "sat": "def sat(s: str, n=3):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=3):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_2", - "sat": "def sat(p: bool, s=\"vetextilyfuhachetextxetehcahufylitxetev\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"vetextilyfuhachetextxetehcahufylitxetev\"):\n return s == s[::-1]" + "name": "CombinationLock:0", + "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"424\", combo=\"778\", target_len=12):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_3", - "sat": "def sat(p: bool, s=\"gavotextesuhyzocop\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"gavotextesuhyzocop\"):\n return s == s[::-1]" + "name": "CombinationLock:1", + "sat": "def sat(states: List[str], start=\"77872\", combo=\"43506\", target_len=16):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"77872\", combo=\"43506\", target_len=16):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_4", - "sat": "def sat(p: bool, s=\"cyvetextybbytxetevyc\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"cyvetextybbytxetevyc\"):\n return s == s[::-1]" + "name": "CombinationLock:2", + "sat": "def sat(states: List[str], start=\"268\", combo=\"180\", target_len=4):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"268\", combo=\"180\", target_len=4):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_5", - "sat": "def sat(p: bool, s=\"ticuwakyt\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"ticuwakyt\"):\n return s == s[::-1]" + "name": "CombinationLock:3", + "sat": "def sat(states: List[str], start=\"4675159714\", combo=\"9758013840\", target_len=27):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"4675159714\", combo=\"9758013840\", target_len=27):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_6", - "sat": "def sat(p: bool, s=\"laxigawuzerequuluuqerezuwagixal\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"laxigawuzerequuluuqerezuwagixal\"):\n return s == s[::-1]" + "name": "CombinationLock:4", + "sat": "def sat(states: List[str], start=\"242716\", combo=\"891245\", target_len=18):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"242716\", combo=\"891245\", target_len=18):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_7", - "sat": "def sat(p: bool, s=\"chigegibumubigegihc\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"chigegibumubigegihc\"):\n return s == s[::-1]" + "name": "CombinationLockObfuscated:0", + "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"424\", combo=\"778\", target_len=12):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_8", - "sat": "def sat(p: bool, s=\"re\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"re\"):\n return s == s[::-1]" + "name": "CombinationLockObfuscated:1", + "sat": "def sat(states: List[str], start=\"50\", combo=\"59\", target_len=0):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"50\", combo=\"59\", target_len=0):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 }, { - "name": "Palindrome_Trivial_9", - "sat": "def sat(p: bool, s=\"dofebulukyfyt\"):\n \"\"\"\n Test whether the given string is a palindrome\n \"\"\"\n return p == (s == s[::-1])", - "sols": [ - "def sol(s=\"dofebulukyfyt\"):\n return s == s[::-1]" + "name": "CombinationLockObfuscated:2", + "sat": "def sat(states: List[str], start=\"23\", combo=\"12\", target_len=1):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"23\", combo=\"12\", target_len=1):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 }, { - "name": "LittleFermat_0", - "sat": "def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):\n \"\"\"\n Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1\n polynomial (mod p).\n Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p).\n \"\"\"\n p = len(poly)\n assert p > 2 and all(p % i for i in range(2, p)), \"Hint: p is a prime > 2\"\n\n def val(coeffs, n): # evaluate polynomial mod p\n return sum(c * pow(n, i, p) for i, c in enumerate(coeffs)) % p\n\n return all(val(exp_poly, n) == pow(val(poly, n), d, p) for n in range(p))", - "sols": [ - "def sol(d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):\n \"\"\"\n Use repeated squaring to exponentiate polynomial\n \"\"\"\n p = len(poly)\n\n def prod(poly1, poly2): # multiply two polynomials mod p\n ans = [0] * p\n for i, a in enumerate(poly1):\n for j, b in enumerate(poly2):\n e = (i + j) % (p - 1)\n if e == 0 and i + j > 1:\n e = p - 1\n ans[e] = (ans[e] + a * b) % p\n return ans\n\n ans = [1] + [0] * (p - 1)\n while d:\n if d % 2:\n ans = prod(ans, poly)\n poly = prod(poly, poly)\n d //= 2\n # for i in range(d):\n # ans = prod(ans, poly)\n return ans" + "name": "CombinationLockObfuscated:3", + "sat": "def sat(states: List[str], start=\"4\", combo=\"3\", target_len=0):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"4\", combo=\"3\", target_len=0):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#49", - "taint_date": "2021-7-7", - "weight": 0.010416666666666666 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 }, { - "name": "ShiftChars_0", - "sat": "def sat(orig: str, result=\"Hello, world!\", shift=7):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"Hello, world!\", shift=7):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "CombinationLockObfuscated:4", + "sat": "def sat(states: List[str], start=\"2184377\", combo=\"7002994\", target_len=18):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"2184377\", combo=\"7002994\", target_len=18):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 }, { - "name": "ShiftChars_1", - "sat": "def sat(orig: str, result=\"rupomykecykynuric\", shift=-9):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"rupomykecykynuric\", shift=-9):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "InvertPermutation:0", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 }, { - "name": "ShiftChars_2", - "sat": "def sat(orig: str, result=\"vicyza\", shift=7):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"vicyza\", shift=7):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "InvertPermutation:1", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"xapypakygatextifyth divufyjacof cecuchuquypo sulechukijocharapad hych mugemi re binivot\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"xapypakygatextifyth divufyjacof cecuchuquypo sulechukijocharapad hych mugemi re binivot\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 }, { - "name": "ShiftChars_3", - "sat": "def sat(orig: str, result=\"nihyzatijyjoke\", shift=8):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"nihyzatijyjoke\", shift=8):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "InvertPermutation:2", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"mujychenyzo\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"mujychenyzo\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 }, { - "name": "ShiftChars_4", - "sat": "def sat(orig: str, result=\"tuthijotext\", shift=6):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"tuthijotext\", shift=6):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "InvertPermutation:3", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"quethoruchyrugyz wemywuconuthisiquu kachogechehuz pulybyri quuby thatextak tychuzymuxuzazylyk neruzesithipecytoqu\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"quethoruchyrugyz wemywuconuthisiquu kachogechehuz pulybyri quuby thatextak tychuzymuxuzazylyk neruzesithipecytoqu\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 }, { - "name": "ShiftChars_5", - "sat": "def sat(orig: str, result=\"thoroxugubu\", shift=7):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"thoroxugubu\", shift=7):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "InvertPermutation:4", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"thyjytex cequolichitextotho bymoxokepy jyvumywefoc\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"thyjytex cequolichitextotho bymoxokepy jyvumywefoc\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 }, { - "name": "ShiftChars_6", - "sat": "def sat(orig: str, result=\"tuzovizijykuquaza\", shift=-11):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"tuzovizijykuquaza\", shift=-11):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "SameDifferent:0", + "sat": "def sat(lists: List[List[int]], items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 }, { - "name": "ShiftChars_7", - "sat": "def sat(orig: str, result=\"textazecizexefih\", shift=4):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"textazecizexefih\", shift=4):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "SameDifferent:1", + "sat": "def sat(lists: List[List[int]], items=[5, 3, 2, 1, 0, 1, 4, 2, 5, 4, 6, 7, 8], length=2):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[5, 3, 2, 1, 0, 1, 4, 2, 5, 4, 6, 7, 8], length=2):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 }, { - "name": "ShiftChars_8", - "sat": "def sat(orig: str, result=\"cobesybogaluminotex\", shift=-3):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"cobesybogaluminotex\", shift=-3):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "SameDifferent:2", + "sat": "def sat(lists: List[List[int]], items=[0, 9, 7, 2, 6, 1, 6, 5, 4, 6, 5, 2, 6, 4, 2, 2, 7, 2, 7, 3, 4, 4, 8, 8, 1, 2, 6, 4, 7, 0, 4, 4, 6, 8, 4, 8, 3, 6, 6, 4, 7, 0, 3, 0, 7, 9, 3, 2, 7, 7, 1, 2, 8, 9, 4, 6, 8, 2, 2, 4, 6, 5, 3, 3, 2, 8, 8, 2, 7, 8, 7, 6, 9, 7, 3, 2, 0, 5], length=10):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[0, 9, 7, 2, 6, 1, 6, 5, 4, 6, 5, 2, 6, 4, 2, 2, 7, 2, 7, 3, 4, 4, 8, 8, 1, 2, 6, 4, 7, 0, 4, 4, 6, 8, 4, 8, 3, 6, 6, 4, 7, 0, 3, 0, 7, 9, 3, 2, 7, 7, 1, 2, 8, 9, 4, 6, 8, 2, 2, 4, 6, 5, 3, 3, 2, 8, 8, 2, 7, 8, 7, 6, 9, 7, 3, 2, 0, 5], length=10):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 }, { - "name": "ShiftChars_9", - "sat": "def sat(orig: str, result=\"zenunely\", shift=-3):\n \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n \"\"\"\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", - "sols": [ - "def sol(result=\"zenunely\", shift=-3):\n return \"\".join(chr(ord(c) - shift) for c in result)" + "name": "SameDifferent:3", + "sat": "def sat(lists: List[List[int]], items=[8, 1, 8, 2, 7, 0, 5, 8, 1, 5, 7, 2, 7, 1, 3, 5, 2, 9, 2, 0, 5, 1, 9, 1, 7, 9, 4, 7, 3, 5, 5, 8, 8, 8, 3, 8, 7, 5, 5, 0, 3, 4, 2, 8, 0, 6, 7, 6, 6, 3, 0, 1, 1, 7, 6, 0, 9, 9, 9, 5, 6, 1, 0, 0, 6, 3, 3, 0, 4, 0, 6, 9, 1, 3, 2, 9, 4, 2, 4, 7, 2, 7, 6, 0, 9, 2, 2, 8, 9, 1, 3, 5, 8, 3, 3], length=10):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[8, 1, 8, 2, 7, 0, 5, 8, 1, 5, 7, 2, 7, 1, 3, 5, 2, 9, 2, 0, 5, 1, 9, 1, 7, 9, 4, 7, 3, 5, 5, 8, 8, 8, 3, 8, 7, 5, 5, 0, 3, 4, 2, 8, 0, 6, 7, 6, 6, 3, 0, 1, 1, 7, 6, 0, 9, 9, 9, 5, 6, 1, 0, 0, 6, 3, 3, 0, 4, 0, 6, 9, 1, 3, 2, 9, 4, 2, 4, 7, 2, 7, 6, 0, 9, 2, 2, 8, 9, 1, 3, 5, 8, 3, 3], length=10):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 }, { - "name": "RemoveVowels_0", - "sat": "def sat(txt: str, text=\"Hello, world!\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"Hello, world!\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "SameDifferent:4", + "sat": "def sat(lists: List[List[int]], items=[5, 8, 2, 2, 5, 1, 4, 9, 2, 0, 5, 4, 6, 5, 1, 7, 3, 2, 4, 6, 7, 2, 7, 3, 3, 1, 7, 9, 3, 2, 2, 9, 1, 2, 1, 1, 8, 6, 6, 2, 7, 6, 5, 2, 7, 6, 5, 0, 0, 8, 4, 5, 5, 3, 7, 5, 2, 0, 3, 1, 0, 8, 1, 3, 0, 1, 9, 4, 9, 1, 9, 7, 7, 1, 9, 7, 9, 4, 0, 8, 3, 7, 4, 3, 1, 6, 5, 8, 0, 9, 5, 7, 5, 6, 0, 1, 3, 1, 8], length=10):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[5, 8, 2, 2, 5, 1, 4, 9, 2, 0, 5, 4, 6, 5, 1, 7, 3, 2, 4, 6, 7, 2, 7, 3, 3, 1, 7, 9, 3, 2, 2, 9, 1, 2, 1, 1, 8, 6, 6, 2, 7, 6, 5, 2, 7, 6, 5, 0, 0, 8, 4, 5, 5, 3, 7, 5, 2, 0, 3, 1, 0, 8, 1, 3, 0, 1, 9, 4, 9, 1, 9, 7, 7, 1, 9, 7, 9, 4, 0, 8, 3, 7, 4, 3, 1, 6, 5, 8, 0, 9, 5, 7, 5, 6, 0, 1, 3, 1, 8], length=10):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 }, { - "name": "RemoveVowels_1", - "sat": "def sat(txt: str, text=\"GUSUXeGePUJibAqUojo\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"GUSUXeGePUJibAqUojo\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "OnesAndTwos:0", + "sat": "def sat(seq: List[int], n=10000, length=5017):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=10000, length=5017):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 }, { - "name": "RemoveVowels_2", - "sat": "def sat(txt: str, text=\"CAsaVyVOTHobAHEwIhI\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"CAsaVyVOTHobAHEwIhI\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "OnesAndTwos:1", + "sat": "def sat(seq: List[int], n=867, length=785):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=867, length=785):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 }, { - "name": "RemoveVowels_3", - "sat": "def sat(txt: str, text=\"TeX\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"TeX\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "OnesAndTwos:2", + "sat": "def sat(seq: List[int], n=0, length=0):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=0, length=0):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 }, { - "name": "RemoveVowels_4", - "sat": "def sat(txt: str, text=\"Q\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"Q\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "OnesAndTwos:3", + "sat": "def sat(seq: List[int], n=4, length=2):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=4, length=2):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 }, { - "name": "RemoveVowels_5", - "sat": "def sat(txt: str, text=\"somavyth\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"somavyth\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "OnesAndTwos:4", + "sat": "def sat(seq: List[int], n=5514, length=4310):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=5514, length=4310):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 }, { - "name": "RemoveVowels_6", - "sat": "def sat(txt: str, text=\"T\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"T\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "MinConsecutiveSum:0", + "sat": "def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "RemoveVowels_7", - "sat": "def sat(txt: str, text=\"kEPigaS\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"kEPigaS\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "MinConsecutiveSum:1", + "sat": "def sat(start: int, k=2, upper=-172, seq=[79, 18, -98, -13, 88, -93, -77, -95, 40, -3, -22]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=2, upper=-172, seq=[79, 18, -98, -13, 88, -93, -77, -95, 40, -3, -22]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "RemoveVowels_8", - "sat": "def sat(txt: str, text=\"tEXTUzugumaxoFUBAtyJ\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"tEXTUzugumaxoFUBAtyJ\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "MinConsecutiveSum:2", + "sat": "def sat(start: int, k=3, upper=-238, seq=[34, -9, -41, -62, -99, -58, -81, 66, -51, 90, -8, -56, -80, -66, -50, -74, -4, -47, 63, -86, 66, 72, 38, -3, 9, 92, 25, -77, 86, -24, -23, 9, 10, 36, -82, -48, -74, -1, -80, 55, -2, -86, 95, -52, -14, -87]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=3, upper=-238, seq=[34, -9, -41, -62, -99, -58, -81, 66, -51, 90, -8, -56, -80, -66, -50, -74, -4, -47, 63, -86, 66, 72, 38, -3, 9, 92, 25, -77, 86, -24, -23, 9, 10, 36, -82, -48, -74, -1, -80, 55, -2, -86, 95, -52, -14, -87]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "RemoveVowels_9", - "sat": "def sat(txt: str, text=\"kyHatexTEWuTeXtetH\"):\n \"\"\"\n Remove the vowels from the original string.\n \"\"\"\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", - "sols": [ - "def sol(text=\"kyHatexTEWuTeXtetH\"):\n return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + "name": "MinConsecutiveSum:3", + "sat": "def sat(start: int, k=8, upper=-75, seq=[17, -90, 61, -29, 57, 7, -45, -37, 1, 69]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=8, upper=-75, seq=[17, -90, 61, -29, 57, 7, -45, -37, 1, 69]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_0", - "sat": "def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MinConsecutiveSum:4", + "sat": "def sat(start: int, k=8, upper=-4, seq=[-17, 55, 6, -2, -14, -19, 86, -4, -8, -49, 40, 82]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=8, upper=-4, seq=[-17, 55, 6, -2, -14, -19, 86, -4, -8, -49, 40, 82]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_1", - "sat": "def sat(indexes: List[int], nums=[35, -96, -51, 7, 56, 0], thresh=-30):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[35, -96, -51, 7, 56, 0], thresh=-30):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveSum:0", + "sat": "def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_2", - "sat": "def sat(indexes: List[int], nums=[-20, 45], thresh=91):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[-20, 45], thresh=91):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveSum:1", + "sat": "def sat(start: int, k=9, lower=-183, seq=[44, -94, 25, -63, -39, -71, -34, 84, -35]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=9, lower=-183, seq=[44, -94, 25, -63, -39, -71, -34, 84, -35]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_3", - "sat": "def sat(indexes: List[int], nums=[84, 56, 13], thresh=-80):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[84, 56, 13], thresh=-80):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveSum:2", + "sat": "def sat(start: int, k=3, lower=86, seq=[19, 82, -24, -9, -92, 50, -89, -15, 45, 56, -64]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=86, seq=[19, 82, -24, -9, -92, 50, -89, -15, 45, 56, -64]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_4", - "sat": "def sat(indexes: List[int], nums=[3, -70, -88, 38], thresh=95):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[3, -70, -88, 38], thresh=95):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveSum:3", + "sat": "def sat(start: int, k=1, lower=-36, seq=[-36]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=1, lower=-36, seq=[-36]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_5", - "sat": "def sat(indexes: List[int], nums=[79, 12, 23, 19, -55, 82], thresh=93):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[79, 12, 23, 19, -55, 82], thresh=93):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveSum:4", + "sat": "def sat(start: int, k=1, lower=93, seq=[-61, -46, 89, 93, -13, 14, -95, -74, -92, -38, -93, 64, -78, 3, 92, -10, -4, 43, 72, 12, 3, -3, -15, -96, 72, -71, -30, 53, 17, -87, 49, 17, -69, 78, 6, -77, -99, 91, 13, 9, 81, -55, 75, 48, -65, 18, -83, 10, -12, 88, 60, -72, -7, -49, -56, -76, 82, 18, 77, 52, -92, -88, 39, 13, -16, 82, 4, 44, -19, 54, 6, 55, 77, -38, -30, -55, -16]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=1, lower=93, seq=[-61, -46, 89, 93, -13, 14, -95, -74, -92, -38, -93, 64, -78, 3, 92, -10, -4, 43, 72, 12, 3, -3, -15, -96, 72, -71, -30, 53, 17, -87, 49, 17, -69, 78, 6, -77, -99, 91, 13, 9, 81, -55, 75, 48, -65, 18, -83, 10, -12, 88, 60, -72, -7, -49, -56, -76, 82, 18, 77, 52, -92, -88, 39, 13, -16, 82, 4, 44, -19, 54, 6, 55, 77, -38, -30, -55, -16]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_6", - "sat": "def sat(indexes: List[int], nums=[13, 8, 94, -63, 74], thresh=34):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[13, 8, 94, -63, 74], thresh=34):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveProduct:0", + "sat": "def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_7", - "sat": "def sat(indexes: List[int], nums=[-88, 79, 57, 35, -68, -17, 2, 26, 62], thresh=3):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[-88, 79, 57, 35, -68, -17, 2, 26, 62], thresh=3):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveProduct:1", + "sat": "def sat(start: int, k=8, lower=774420991987500, seq=[-50, -99, -99, -65, -69, -87, 90, 45]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=8, lower=774420991987500, seq=[-50, -99, -99, -65, -69, -87, 90, 45]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_8", - "sat": "def sat(indexes: List[int], nums=[42, 0, 11, -76, -7], thresh=95):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[42, 0, 11, -76, -7], thresh=95):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveProduct:2", + "sat": "def sat(start: int, k=6, lower=188917681120, seq=[73, -32, 30, 92, 73, 8, 31, 40, -59, -97, -16, -83, -86, 78, -91, -18, -31, 31, 37, 79, 63, 38, 14, 68, -73, 91, 71, 87, 54, -7, -74, -63, -57, -46, -78, -22, 71, 52, 32, -82, 71, 76, -28, 83, -65, -65, 70, -35, 83, -40, 69, 78, -81, 0, -69, -1, 0, 61, 92, 55, -89, 60, 74, 99, -53, -22, 50, 28, -60, 6, 27, -53, -77, 99, 1, -69, -67, 81, -89, 45, 59, -28, 24, -21, -65, -56, -89, -30, 58, 78, 73, 9, 81, -39, -99, 43, 32, 58, -56, -83, 82, 97, 70]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=6, lower=188917681120, seq=[73, -32, 30, 92, 73, 8, 31, 40, -59, -97, -16, -83, -86, 78, -91, -18, -31, 31, 37, 79, 63, 38, 14, 68, -73, 91, 71, 87, 54, -7, -74, -63, -57, -46, -78, -22, 71, 52, 32, -82, 71, 76, -28, 83, -65, -65, 70, -35, 83, -40, 69, 78, -81, 0, -69, -1, 0, 61, 92, 55, -89, 60, 74, 99, -53, -22, 50, 28, -60, 6, 27, -53, -77, 99, 1, -69, -67, 81, -89, 45, 59, -28, 24, -21, -65, -56, -89, -30, 58, 78, 73, 9, 81, -39, -99, 43, 32, 58, -56, -83, 82, 97, 70]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "BelowThreshold_9", - "sat": "def sat(indexes: List[int], nums=[95, 2, 24, 79, 50, -34], thresh=-16):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", - "sols": [ - "def sol(nums=[95, 2, 24, 79, 50, -34], thresh=-16):\n return [i for i, n in enumerate(nums) if n < thresh]" + "name": "MaxConsecutiveProduct:3", + "sat": "def sat(start: int, k=2, lower=5589, seq=[8, -66, 75, 74, 40, 14, -81, -69, 99, 27, -18]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=2, lower=5589, seq=[8, -66, 75, 74, 40, 14, -81, -69, 99, 27, -18]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "ListTotal_0", - "sat": "def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):\n return sum(nums)" + "name": "MaxConsecutiveProduct:4", + "sat": "def sat(start: int, k=10, lower=-8326797433194240, seq=[49, -99, 80, 26, 54, 13, 37, 13, -52, -47]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=10, lower=-8326797433194240, seq=[49, -99, 80, 26, 54, 13, 37, 13, -52, -47]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 }, { - "name": "ListTotal_1", - "sat": "def sat(n: int, nums=[40388491, -864787067, 862143530, 604555885, -81302113, 717834573]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[40388491, -864787067, 862143530, 604555885, -81302113, 717834573]):\n return sum(nums)" + "name": "DistinctOddSum:0", + "sat": "def sat(nums: List[int], tot=12345, n=5):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=12345, n=5):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 }, { - "name": "ListTotal_2", - "sat": "def sat(n: int, nums=[-93, 35, -95, -7, -85, 2]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[-93, 35, -95, -7, -85, 2]):\n return sum(nums)" + "name": "DistinctOddSum:1", + "sat": "def sat(nums: List[int], tot=1819, n=3):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=1819, n=3):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 }, { - "name": "ListTotal_3", - "sat": "def sat(n: int, nums=[-2040052, -6582681, -6604315, 1042475, 7287312, 8050849, 5566992, 4332017]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[-2040052, -6582681, -6604315, 1042475, 7287312, 8050849, 5566992, 4332017]):\n return sum(nums)" + "name": "DistinctOddSum:2", + "sat": "def sat(nums: List[int], tot=37729, n=73):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=37729, n=73):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 }, { - "name": "ListTotal_4", - "sat": "def sat(n: int, nums=[-1, -1, -1, -1, 0, 0]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[-1, -1, -1, -1, 0, 0]):\n return sum(nums)" + "name": "DistinctOddSum:3", + "sat": "def sat(nums: List[int], tot=5359, n=11):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=5359, n=11):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 }, { - "name": "ListTotal_5", - "sat": "def sat(n: int, nums=[8480076, -2044490, -3518775, 6254135, -2176636, -3207066, -1171264, -5667232, -2034335]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[8480076, -2044490, -3518775, 6254135, -2176636, -3207066, -1171264, -5667232, -2034335]):\n return sum(nums)" + "name": "DistinctOddSum:4", + "sat": "def sat(nums: List[int], tot=36505, n=73):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=36505, n=73):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 }, { - "name": "ListTotal_6", - "sat": "def sat(n: int, nums=[816723, -837994, 763030, 531661, 233110, 368982, -402524, -778055]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[816723, -837994, 763030, 531661, 233110, 368982, -402524, -778055]):\n return sum(nums)" + "name": "MinRotations:0", + "sat": "def sat(rotations: List[int], target=\"wonderful\", upper=69):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"wonderful\", upper=69):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 }, { - "name": "ListTotal_7", - "sat": "def sat(n: int, nums=[-93268, -30697, -46621, 93237, 45694, -17686, -53086, -58002, 20887]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[-93268, -30697, -46621, 93237, 45694, -17686, -53086, -58002, 20887]):\n return sum(nums)" + "name": "MinRotations:1", + "sat": "def sat(rotations: List[int], target=\"tubolele\", upper=52):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"tubolele\", upper=52):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 }, { - "name": "ListTotal_8", - "sat": "def sat(n: int, nums=[-561191, 671034, 635510, 896023, -403700]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[-561191, 671034, 635510, 896023, -403700]):\n return sum(nums)" + "name": "MinRotations:2", + "sat": "def sat(rotations: List[int], target=\"soquogisawah\", upper=67):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"soquogisawah\", upper=67):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 }, { - "name": "ListTotal_9", - "sat": "def sat(n: int, nums=[42964, 85505, 53484, -98381, 67885, -85981, -53393]):\n \"\"\"\n Find the indexes of numbers below a given threshold\n \"\"\"\n return sum(nums + [-n]) == 0", - "sols": [ - "def sol(nums=[42964, 85505, 53484, -98381, 67885, -85981, -53393]):\n return sum(nums)" + "name": "MinRotations:3", + "sat": "def sat(rotations: List[int], target=\"jacepa\", upper=44):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"jacepa\", upper=44):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 }, { - "name": "DiffChars_0", - "sat": "def sat(c: str, a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "MinRotations:4", + "sat": "def sat(rotations: List[int], target=\"miwykucehexo\", upper=84):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"miwykucehexo\", upper=84):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 + }, + { + "name": "BillSums:0", + "sat": "def sat(bills: List[int], denominations=[1, 25, 35, 84], n=980, max_len=14):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 25, 35, 84], n=980, max_len=14):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BillSums:1", + "sat": "def sat(bills: List[int], denominations=[1, 5, 7, 11], n=29377, max_len=2671):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 5, 7, 11], n=29377, max_len=2671):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BillSums:2", + "sat": "def sat(bills: List[int], denominations=[1, 44, 69], n=727, max_len=18):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 44, 69], n=727, max_len=18):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BillSums:3", + "sat": "def sat(bills: List[int], denominations=[1, 25, 29], n=537, max_len=21):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 25, 29], n=537, max_len=21):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BillSums:4", + "sat": "def sat(bills: List[int], denominations=[1, 10, 23, 49], n=74, max_len=4):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 10, 23, 49], n=74, max_len=4):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:0", + "sat": "def sat(sides: List[int], options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:1", + "sat": "def sat(sides: List[int], options=[2, 32, 128, 2048], n=228130115719126719403436248654018132587240700300069484783024476396726369300757361858486149336528857415050585140022669260683533846520228615414824699513965623011283630204688776606537822433903248866264246250472816019829634613450432640540476545312147582016319329176365649861438112055219416307889844810164481913129640729676567935637319847974104737041819733016269814095538825986746872964316260742048948842881864927312578954616543873339090000235516611035976675319992951155425592590971354482499219065911551659299442284010821489032878061237960883641148400358779732380029929731755431392589957363797811587552907493225515131362976630371588393769290980736545625490532833401799533953657008471171187904833042604191595654563052739341699008374536877944129683396035943703772775574923305193036335454829886522712928671689842429868129065816806317184528393809093537482604512070817490962382058600995548188534203183821947412497991334185434644234223497426696856425081004631697882694737783657734748584914343393446495655603077914405339198501652640033384883248202008796431768177660311524505375032465859911969645720782885945304020206901948785067162180147604944416802494237380295502898725709699989316239611948841761179630356857432537740268880887406363698339697884778928867070095601679136329773121122427957476591692077252692128084462084666562367516110718889596553029368485592312571562760467825734375966403657494757513742901716957512515999554215394910749910705062184378036402811375228424564672896328484400844595493109009999483758555965249861718868505692086014690841384328807750643083870429560141041100275605070593340307777014146422286286174141328734305861765975142642533328283052695019530894917054320937603586353968931629943177100198544320130592080317808699102134050255107270490491866451598651191237073743434416055324965245162816436688506766798907631409318862813999619267517691129416882206979571876987670409601093143594006666877317942246151185196703526359657208564220263995224577466875935694654571263504652726005785629951670929607532333340077417449014738737013346326087193441376781403017104776528773370114633214397553406205844983209794006628986960804493464678425632234950959510169749894285280278283738406987643831719730840932795296580290643750811511261778066991567984806115883476196314905009957269037243416953344853497398305731263857286565805740574002573468233255419591302501435585946727352997645518600735324783808084419495985356968106531724233422062762588856840753502904727554461930814392985988583994344625901267465334680461022145630478703628829329214105057598498060165611002555328089927562335110353619756270727870578861254390831489833288520806796527530233204302267437547065838761620867335585044147746062666641204836971836326240475987046035522808201203159329079453415117803276772632387741778875346277155398622874525185657020894389122946631102004676447465064652881476735210624605751725260196714783487821662079677160631607184350517490457782630582235697826366596839098468662601860843910244925043204559895831233405782087371882757970774478474456873255395627305993127448835175163234402865711702330195641472753972521303188861456649807013475719673540071791198682554468915003105114658732620778592368025010627074092048770677221666930787774307426025130737526294176368225554400859962054685688030870382537978901917116576720339440289697234523317616314038117415668096017357904607750516858893107088258836773840081269481533772759281055281700189820269430782472437953000818618620073622195951192485912449122811233373872720728771442190884380599983059328804281149117350956948229322152773453262155799120217785942195894432200049075535098740412553027257995610825803094581023661379076874649822855869540676929026434776986202199736335291086433750024634767647140351636139668469623425852015023217614605601509807425262068267436928967585507261326427312192469433846382754391958778190093898722931985614221781005700500186774555621410213366027104482083356617237286158279541722415195573634119626161145784283399399763136624234679728759972590678720441851340526642105986068992675508623421201319495330632683326640681447849893540200819910937029765557508137488203702135573415958504919756451764701424427616007186711716814731754356696294815225309000903038863786582011151301767020033435488951952515328694739238611436697506492409350399051491860286180916641995435036798744630218175609818767447434417101324494299048701375363995201208156077912500466647001096398105097526014328010704551098721141422402194540968220131279390845880754347325090679635736861222456047497894985750004735992813665737790270893848091556206678545839263262921269604717011176408056673577863963647995994679194792859835924183303294858830520237184847307088921165828069254730539210820781321214188691456066198669698221986283054877560403229938707456087823056229168657150416667472353923056485151256206281259934588996856957165363419959086737278132371225618045208766940894851830536221997939414764739510874614136757754731916169592243013858728423395629916861873250059908376640593353458920525817510096165639822536116104014564983262641835696648770796437401025069947591765576169212854786072852037200412675323852228612643476420810700506802979469371193707478238102372738573446551135494399083768640394423902510360568345963566956628316386503835770637993395889794935064583369456457251364106039002197061249640656337408285516947104128384648071872093149185222817195549313653521423697663580452218339727675869442230637147896150992109058378079284047987408513151424582426733908811332984743426926921482525672979132388569204856728480053543657314645848629452707066384786683940683922294349706905116833856400816002318580982472177845076143240683398799002252052620073260453978750375575223410433119522136481155383781061087345580876922667168909793260459989117418608371057291625605742980576502324517701043654641735294862171567996649051774368556674742803204305115479624063288540683801642080951288085873119685282033998440038309690901065668529995699263324324647663786987570997092769208911017915884270972152889988269937518906215458313814671282111935739061027874324706982875737155498573655909937861180443564435913525096059145949918294793776507173166107542059434114036766604950338860659503927865444687234023577758066365219472193319060107680269235616121325491303450849189026066604825116203403688819256549446469872454719979920079537099106304473570385681301430528769647421769240063242145063519073744152649494347821386673801477876591176898296658169802358064222303060868163538278020710591214386547249222952832818252842480178040572184084541071252073329855267036622763497225362671868043427997760221082785500384040742315799726682553888439254019033785740045784304237440355626690384344706900984786817034803207351161123175189215391916314291940696635993614322400314858617500069240761161101656033019211764256155420375348098566252555605378514744357978092011966637756282555883252547041098779361571592132511685974148955404843221146265096853450620709172105401754899975093227930688317971723555701302765701773289547141581265923801348450949162571448538932045007651581274796679173418467222661434739407456208067855969412215915828478533782205100053640112586053063309082312341996582816268147273845664101303622557781193410302781763062479639834516875758224554471296826756056995444356753101918287733079420101251086687448407074623452964778375926960581677381582362486643216332229928123236483635773267705721199409263698193020255835863136791913383111490081693301513932140406489776742165709629714987751458823040519007937519033772815412530564305120069350242278768783296719236430743732117712801991081268630206231139274033284907511906721452335462501166317547326594594957955217049374662407117141307601583000669214782094806782805113075265906828482252499002596357458621191160586625586111512272634529183613371281132957233425400325605401620814098603442053561895456042327363678383162487239895454728331055945869193536242853599717228788292205516180939641663484893911412444566747695275948642648631192599418045380803238852331361777586116015967092138091810017242532292746564005317567875162264651817447488681351477216121794453291559549365332550900514942221303837134657256366225256511675688256592613810130160871589071197842978260453456841801688807509997664221548899295846247899587131486967937781129153559530907098259658901823499223231462924893901110210162304614366220400600462508511005070809268751890443966184634738431571192464718609875536811814107818803946825222751690118887747643980508890911810875193517706876433214609535343577395964208443875870857748307152837416868580525555743549769445078834804561676514215910911559965763038223728194702912682866098246175065061179531928672739869105315436205040641895882311949809960043452332003364331016564406606479528418850597459996692115304751014933652479556318399189077142182676442159582999101191812232513521611405580381460497513444446648638490157000309696473736964812935464820324980925994537043070153654272, max_dim=2671):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[2, 32, 128, 2048], n=228130115719126719403436248654018132587240700300069484783024476396726369300757361858486149336528857415050585140022669260683533846520228615414824699513965623011283630204688776606537822433903248866264246250472816019829634613450432640540476545312147582016319329176365649861438112055219416307889844810164481913129640729676567935637319847974104737041819733016269814095538825986746872964316260742048948842881864927312578954616543873339090000235516611035976675319992951155425592590971354482499219065911551659299442284010821489032878061237960883641148400358779732380029929731755431392589957363797811587552907493225515131362976630371588393769290980736545625490532833401799533953657008471171187904833042604191595654563052739341699008374536877944129683396035943703772775574923305193036335454829886522712928671689842429868129065816806317184528393809093537482604512070817490962382058600995548188534203183821947412497991334185434644234223497426696856425081004631697882694737783657734748584914343393446495655603077914405339198501652640033384883248202008796431768177660311524505375032465859911969645720782885945304020206901948785067162180147604944416802494237380295502898725709699989316239611948841761179630356857432537740268880887406363698339697884778928867070095601679136329773121122427957476591692077252692128084462084666562367516110718889596553029368485592312571562760467825734375966403657494757513742901716957512515999554215394910749910705062184378036402811375228424564672896328484400844595493109009999483758555965249861718868505692086014690841384328807750643083870429560141041100275605070593340307777014146422286286174141328734305861765975142642533328283052695019530894917054320937603586353968931629943177100198544320130592080317808699102134050255107270490491866451598651191237073743434416055324965245162816436688506766798907631409318862813999619267517691129416882206979571876987670409601093143594006666877317942246151185196703526359657208564220263995224577466875935694654571263504652726005785629951670929607532333340077417449014738737013346326087193441376781403017104776528773370114633214397553406205844983209794006628986960804493464678425632234950959510169749894285280278283738406987643831719730840932795296580290643750811511261778066991567984806115883476196314905009957269037243416953344853497398305731263857286565805740574002573468233255419591302501435585946727352997645518600735324783808084419495985356968106531724233422062762588856840753502904727554461930814392985988583994344625901267465334680461022145630478703628829329214105057598498060165611002555328089927562335110353619756270727870578861254390831489833288520806796527530233204302267437547065838761620867335585044147746062666641204836971836326240475987046035522808201203159329079453415117803276772632387741778875346277155398622874525185657020894389122946631102004676447465064652881476735210624605751725260196714783487821662079677160631607184350517490457782630582235697826366596839098468662601860843910244925043204559895831233405782087371882757970774478474456873255395627305993127448835175163234402865711702330195641472753972521303188861456649807013475719673540071791198682554468915003105114658732620778592368025010627074092048770677221666930787774307426025130737526294176368225554400859962054685688030870382537978901917116576720339440289697234523317616314038117415668096017357904607750516858893107088258836773840081269481533772759281055281700189820269430782472437953000818618620073622195951192485912449122811233373872720728771442190884380599983059328804281149117350956948229322152773453262155799120217785942195894432200049075535098740412553027257995610825803094581023661379076874649822855869540676929026434776986202199736335291086433750024634767647140351636139668469623425852015023217614605601509807425262068267436928967585507261326427312192469433846382754391958778190093898722931985614221781005700500186774555621410213366027104482083356617237286158279541722415195573634119626161145784283399399763136624234679728759972590678720441851340526642105986068992675508623421201319495330632683326640681447849893540200819910937029765557508137488203702135573415958504919756451764701424427616007186711716814731754356696294815225309000903038863786582011151301767020033435488951952515328694739238611436697506492409350399051491860286180916641995435036798744630218175609818767447434417101324494299048701375363995201208156077912500466647001096398105097526014328010704551098721141422402194540968220131279390845880754347325090679635736861222456047497894985750004735992813665737790270893848091556206678545839263262921269604717011176408056673577863963647995994679194792859835924183303294858830520237184847307088921165828069254730539210820781321214188691456066198669698221986283054877560403229938707456087823056229168657150416667472353923056485151256206281259934588996856957165363419959086737278132371225618045208766940894851830536221997939414764739510874614136757754731916169592243013858728423395629916861873250059908376640593353458920525817510096165639822536116104014564983262641835696648770796437401025069947591765576169212854786072852037200412675323852228612643476420810700506802979469371193707478238102372738573446551135494399083768640394423902510360568345963566956628316386503835770637993395889794935064583369456457251364106039002197061249640656337408285516947104128384648071872093149185222817195549313653521423697663580452218339727675869442230637147896150992109058378079284047987408513151424582426733908811332984743426926921482525672979132388569204856728480053543657314645848629452707066384786683940683922294349706905116833856400816002318580982472177845076143240683398799002252052620073260453978750375575223410433119522136481155383781061087345580876922667168909793260459989117418608371057291625605742980576502324517701043654641735294862171567996649051774368556674742803204305115479624063288540683801642080951288085873119685282033998440038309690901065668529995699263324324647663786987570997092769208911017915884270972152889988269937518906215458313814671282111935739061027874324706982875737155498573655909937861180443564435913525096059145949918294793776507173166107542059434114036766604950338860659503927865444687234023577758066365219472193319060107680269235616121325491303450849189026066604825116203403688819256549446469872454719979920079537099106304473570385681301430528769647421769240063242145063519073744152649494347821386673801477876591176898296658169802358064222303060868163538278020710591214386547249222952832818252842480178040572184084541071252073329855267036622763497225362671868043427997760221082785500384040742315799726682553888439254019033785740045784304237440355626690384344706900984786817034803207351161123175189215391916314291940696635993614322400314858617500069240761161101656033019211764256155420375348098566252555605378514744357978092011966637756282555883252547041098779361571592132511685974148955404843221146265096853450620709172105401754899975093227930688317971723555701302765701773289547141581265923801348450949162571448538932045007651581274796679173418467222661434739407456208067855969412215915828478533782205100053640112586053063309082312341996582816268147273845664101303622557781193410302781763062479639834516875758224554471296826756056995444356753101918287733079420101251086687448407074623452964778375926960581677381582362486643216332229928123236483635773267705721199409263698193020255835863136791913383111490081693301513932140406489776742165709629714987751458823040519007937519033772815412530564305120069350242278768783296719236430743732117712801991081268630206231139274033284907511906721452335462501166317547326594594957955217049374662407117141307601583000669214782094806782805113075265906828482252499002596357458621191160586625586111512272634529183613371281132957233425400325605401620814098603442053561895456042327363678383162487239895454728331055945869193536242853599717228788292205516180939641663484893911412444566747695275948642648631192599418045380803238852331361777586116015967092138091810017242532292746564005317567875162264651817447488681351477216121794453291559549365332550900514942221303837134657256366225256511675688256592613810130160871589071197842978260453456841801688807509997664221548899295846247899587131486967937781129153559530907098259658901823499223231462924893901110210162304614366220400600462508511005070809268751890443966184634738431571192464718609875536811814107818803946825222751690118887747643980508890911810875193517706876433214609535343577395964208443875870857748307152837416868580525555743549769445078834804561676514215910911559965763038223728194702912682866098246175065061179531928672739869105315436205040641895882311949809960043452332003364331016564406606479528418850597459996692115304751014933652479556318399189077142182676442159582999101191812232513521611405580381460497513444446648638490157000309696473736964812935464820324980925994537043070153654272, max_dim=2671):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:2", + "sat": "def sat(sides: List[int], options=[5, 5684341886080801486968994140625, 1694065894508600678136645001359283924102783203125], n=14164235936814247246943953676783316651469999599259488526297703814252125093918086614885937400554283434172053854937092875501351523725603695985262279092166781262962870903549601084831041808313096168206454204432965872990952135614781500037949647186895146848775449563088704805081355726771444219003252553140494372583795600460039446480996347267095412342936844101488043829191704193224433757153659988332565127014442298522610686943372161710084163946718544591837540089627956441911856011461878779300604946911334991455078125, max_dim=18):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[5, 5684341886080801486968994140625, 1694065894508600678136645001359283924102783203125], n=14164235936814247246943953676783316651469999599259488526297703814252125093918086614885937400554283434172053854937092875501351523725603695985262279092166781262962870903549601084831041808313096168206454204432965872990952135614781500037949647186895146848775449563088704805081355726771444219003252553140494372583795600460039446480996347267095412342936844101488043829191704193224433757153659988332565127014442298522610686943372161710084163946718544591837540089627956441911856011461878779300604946911334991455078125, max_dim=18):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:3", + "sat": "def sat(sides: List[int], options=[7, 1341068619663964900807, 3219905755813179726837607], n=6571242398704579720578070114049260568175867016132732117282677704710285377366495338413477575773225344143668665616691026039505250116800576464209614274689081547617879363134212486963646613891813824577824293441956456783410239143356741482364072743485236424053098241559823295733445894310196746774269493235867749396614000266398083913285305446265094243982850288066583162232189087239052303868564232298028341023504220837967414535260504654309004337585867867005771207, max_dim=21):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[7, 1341068619663964900807, 3219905755813179726837607], n=6571242398704579720578070114049260568175867016132732117282677704710285377366495338413477575773225344143668665616691026039505250116800576464209614274689081547617879363134212486963646613891813824577824293441956456783410239143356741482364072743485236424053098241559823295733445894310196746774269493235867749396614000266398083913285305446265094243982850288066583162232189087239052303868564232298028341023504220837967414535260504654309004337585867867005771207, max_dim=21):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:4", + "sat": "def sat(sides: List[int], options=[2, 8, 64, 256], n=3885337784451458141838923813647037813284813678104279042503624819477808570410416996352, max_dim=36):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[2, 8, 64, 256], n=3885337784451458141838923813647037813284813678104279042503624819477808570410416996352, max_dim=36):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "QuadraticRoot:0", + "sat": "def sat(x: float, coeffs=[2.5, 1.3, -0.5]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[2.5, 1.3, -0.5]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" + ], + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 }, { - "name": "DiffChars_1", - "sat": "def sat(c: str, a=\"jyhud\", b=\"nexysezomevus\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"jyhud\", b=\"nexysezomevus\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "QuadraticRoot:1", + "sat": "def sat(x: float, coeffs=[0.0685642998539026, -0.10446230957339113, -0.11141402891228723]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[0.0685642998539026, -0.10446230957339113, -0.11141402891228723]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 }, { - "name": "DiffChars_2", - "sat": "def sat(c: str, a=\"vofawawumovisajuryt\", b=\"t\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"vofawawumovisajuryt\", b=\"t\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "QuadraticRoot:2", + "sat": "def sat(x: float, coeffs=[0.2622487694588566, 0.48521166316030495, -41.749384651642444]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[0.2622487694588566, 0.48521166316030495, -41.749384651642444]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 }, { - "name": "DiffChars_3", - "sat": "def sat(c: str, a=\"textuzaxoch\", b=\"acehmottuxxz\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"textuzaxoch\", b=\"acehmottuxxz\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "QuadraticRoot:3", + "sat": "def sat(x: float, coeffs=[145.72190605632582, 0.027358325157428014, -5.149342624051854]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[145.72190605632582, 0.027358325157428014, -5.149342624051854]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 }, { - "name": "DiffChars_4", - "sat": "def sat(c: str, a=\"quytextila\", b=\"mydyhopakokinavo\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"quytextila\", b=\"mydyhopakokinavo\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "QuadraticRoot:4", + "sat": "def sat(x: float, coeffs=[1.1222556871110754, -0.007015312913509468, -309237.6867547677]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[1.1222556871110754, -0.007015312913509468, -309237.6867547677]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 }, { - "name": "DiffChars_5", - "sat": "def sat(c: str, a=\"danodelutibi\", b=\"abddeiilmnotu\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"danodelutibi\", b=\"abddeiilmnotu\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "AllQuadraticRoots:0", + "sat": "def sat(roots: List[float], coeffs=[1.3, -0.5]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[1.3, -0.5]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 }, { - "name": "DiffChars_6", - "sat": "def sat(c: str, a=\"tajexofyrytepudeko\", b=\"adeeefjkmooprttuxyy\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"tajexofyrytepudeko\", b=\"adeeefjkmooprttuxyy\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "AllQuadraticRoots:1", + "sat": "def sat(roots: List[float], coeffs=[-1.468548989307175, -0.9453828447181172]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[-1.468548989307175, -0.9453828447181172]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 }, { - "name": "DiffChars_7", - "sat": "def sat(c: str, a=\"xewutarugasevusadofy\", b=\"chedyvychegetex\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"xewutarugasevusadofy\", b=\"chedyvychegetex\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "AllQuadraticRoots:2", + "sat": "def sat(roots: List[float], coeffs=[-2.0230245559088815, -0.23831699388987454]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[-2.0230245559088815, -0.23831699388987454]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 }, { - "name": "DiffChars_8", - "sat": "def sat(c: str, a=\"cech\", b=\"ccehm\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"cech\", b=\"ccehm\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "AllQuadraticRoots:3", + "sat": "def sat(roots: List[float], coeffs=[-33.7903719275386, -5.03161654339928]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[-33.7903719275386, -5.03161654339928]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 }, { - "name": "DiffChars_9", - "sat": "def sat(c: str, a=\"mic\", b=\"w\"):\n \"\"\"\n Find a character in one string that is not in the other.\n \"\"\"\n return (c in a) != (c in b)", - "sols": [ - "def sol(a=\"mic\", b=\"w\"):\n return sorted(set(a).symmetric_difference(b))[0]" + "name": "AllQuadraticRoots:4", + "sat": "def sat(roots: List[float], coeffs=[9.155105839032705, -0.9467446341738642]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[9.155105839032705, -0.9467446341738642]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_0", - "sat": "def sat(nums: List[int], n=1402):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=1402):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "CubicRoot:0", + "sat": "def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[2.0, 1.0, 0.0, 8.0]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_1", - "sat": "def sat(nums: List[int], n=537):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=537):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "CubicRoot:1", + "sat": "def sat(x: float, coeffs=[0.009597657937719273, -10.297175825569942, 0.15891220226280925, 10.530249049250433]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[0.009597657937719273, -10.297175825569942, 0.15891220226280925, 10.530249049250433]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_2", - "sat": "def sat(nums: List[int], n=6968):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=6968):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "CubicRoot:2", + "sat": "def sat(x: float, coeffs=[-0.17749172356645268, -1.3894267878542186, 0.03752944532850555, 0.2624916128068381]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[-0.17749172356645268, -1.3894267878542186, 0.03752944532850555, 0.2624916128068381]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_3", - "sat": "def sat(nums: List[int], n=5585):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=5585):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "CubicRoot:3", + "sat": "def sat(x: float, coeffs=[0.41725114111706524, 155.2589446092116, -0.10619077904258341, -0.024129284994425074]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[0.41725114111706524, 155.2589446092116, -0.10619077904258341, -0.024129284994425074]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_4", - "sat": "def sat(nums: List[int], n=7277):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=7277):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "CubicRoot:4", + "sat": "def sat(x: float, coeffs=[-2.3153234528266906, 11.247619504308075, -72.3705721705674, 53.97429005428236]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[-2.3153234528266906, 11.247619504308075, -72.3705721705674, 53.97429005428236]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_5", - "sat": "def sat(nums: List[int], n=10803):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=10803):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "AllCubicRoots:0", + "sat": "def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[1.0, -2.0, -1.0]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_6", - "sat": "def sat(nums: List[int], n=3106):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=3106):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "AllCubicRoots:1", + "sat": "def sat(roots: List[float], coeffs=[291.6393860094841, -235.56805995170293, 46.827662118172]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[291.6393860094841, -235.56805995170293, 46.827662118172]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_7", - "sat": "def sat(nums: List[int], n=4915):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=4915):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "AllCubicRoots:2", + "sat": "def sat(roots: List[float], coeffs=[-0.25228902661371166, -0.1500677342820565, 0.04095001209455085]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[-0.25228902661371166, -0.1500677342820565, 0.04095001209455085]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_8", - "sat": "def sat(nums: List[int], n=7009):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=7009):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "AllCubicRoots:3", + "sat": "def sat(roots: List[float], coeffs=[-0.7564145326509102, -0.6902422688120567, 0.4732575941427041]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[-0.7564145326509102, -0.6902422688120567, 0.4732575941427041]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "Fibonacci_9", - "sat": "def sat(nums: List[int], n=2052):\n \"\"\"\n Find the first n Fibonacci numbers\n \"\"\"\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", - "sols": [ - "def sol(n=2052):\n ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + "name": "AllCubicRoots:4", + "sat": "def sat(roots: List[float], coeffs=[5.119999240806329, -7.551441647258393, -21.440710634524915]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[5.119999240806329, -7.551441647258393, -21.440710634524915]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 }, { - "name": "MatchBrackets_0", - "sat": "def sat(matches: List[int], brackets=\"<<>><<<><>><<>>>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<<>><<<><>><<>>>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "SumOfDigits:0", + "sat": "def sat(x: str, s=679):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=679):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_1", - "sat": "def sat(matches: List[int], brackets=\"<><><><><<>><<<><><<>>>><><><>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><><><><<>><<<><><<>>>><><><>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "SumOfDigits:1", + "sat": "def sat(x: str, s=40427):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=40427):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_2", - "sat": "def sat(matches: List[int], brackets=\"<><><<<>><<<<><>>><<>><>>><>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><><<<>><<<<><>>><<>><>>><>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "SumOfDigits:2", + "sat": "def sat(x: str, s=8071):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=8071):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_3", - "sat": "def sat(matches: List[int], brackets=\"<><><><><<><><<><>>><><<>><><<>><><><><<<>><>><>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><><><><<><><<><>>><><<>><><<>><><><><<<>><>><>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "SumOfDigits:3", + "sat": "def sat(x: str, s=86120):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=86120):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_4", - "sat": "def sat(matches: List[int], brackets=\"<<<<<>>>>><><><<>>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<<<<<>>>>><><><<>>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "SumOfDigits:4", + "sat": "def sat(x: str, s=26785):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=26785):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_5", - "sat": "def sat(matches: List[int], brackets=\"<>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "FloatWithDecimalValue:0", + "sat": "def sat(z: float, v=9, d=0.0001):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=9, d=0.0001):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_6", - "sat": "def sat(matches: List[int], brackets=\"<><<<<><>>>><><><><<>><>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><<<<><>>>><><><><<>><>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "FloatWithDecimalValue:1", + "sat": "def sat(z: float, v=1, d=1e-17):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=1, d=1e-17):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_7", - "sat": "def sat(matches: List[int], brackets=\"\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "FloatWithDecimalValue:2", + "sat": "def sat(z: float, v=9, d=1e+83):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=9, d=1e+83):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_8", - "sat": "def sat(matches: List[int], brackets=\"<><><><<><>><><><>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><><><<><>><><><>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "FloatWithDecimalValue:3", + "sat": "def sat(z: float, v=5, d=1e-18):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=5, d=1e-18):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MatchBrackets_9", - "sat": "def sat(matches: List[int], brackets=\"<><><<><>><<<<>>><>><><><<<<><>>>>\"):\n \"\"\"\n Find the index of the matching brackets for each character in the string\n \"\"\"\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", - "sols": [ - "def sol(brackets=\"<><><<><>><<<<>>><>><><><<<<><>>>>\"):\n matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "FloatWithDecimalValue:4", + "sat": "def sat(z: float, v=5, d=1e+90):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=5, d=1e+90):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_0", - "sat": "def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[2, 4, 17, 29, 31, 1000, 416629]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "ArithmeticSequence:0", + "sat": "def sat(x: List[int], a=7, s=5, e=200):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=7, s=5, e=200):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_1", - "sat": "def sat(direction: str, nums=[540, 713, 887, 964]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[540, 713, 887, 964]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "ArithmeticSequence:1", + "sat": "def sat(x: List[int], a=43536, s=3795, e=417606):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=43536, e=417606, s=3795):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_2", - "sat": "def sat(direction: str, nums=[764, 291, 171]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[764, 291, 171]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "ArithmeticSequence:2", + "sat": "def sat(x: List[int], a=-70138, s=4868, e=498910):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=-70138, e=498910, s=4868):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_3", - "sat": "def sat(direction: str, nums=[74, 168, 229, 302, 430, 450, 481, 783]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[74, 168, 229, 302, 430, 450, 481, 783]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "ArithmeticSequence:3", + "sat": "def sat(x: List[int], a=55980, s=7402, e=155818):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=55980, e=155818, s=7402):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_4", - "sat": "def sat(direction: str, nums=[826, 784, 726, 537, 536, 392, 250, 241, 161]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[826, 784, 726, 537, 536, 392, 250, 241, 161]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "ArithmeticSequence:4", + "sat": "def sat(x: List[int], a=-44635, s=5046, e=503563):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=-44635, e=503563, s=5046):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_5", - "sat": "def sat(direction: str, nums=[691, 546, 98]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[691, 546, 98]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "GeometricSequence:0", + "sat": "def sat(x: List[int], a=8, r=2, l=50):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=8, r=2, l=50):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_6", - "sat": "def sat(direction: str, nums=[41, 155, 181, 511, 537, 935]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[41, 155, 181, 511, 537, 935]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "GeometricSequence:1", + "sat": "def sat(x: List[int], a=-484, r=4, l=589):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=-484, r=4, l=589):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_7", - "sat": "def sat(direction: str, nums=[706, 667, 504, 35]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[706, 667, 504, 35]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "GeometricSequence:2", + "sat": "def sat(x: List[int], a=889, r=7, l=393):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=889, r=7, l=393):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_8", - "sat": "def sat(direction: str, nums=[829, 677, 599, 494, 493, 344, 247, 194, 141]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[829, 677, 599, 494, 493, 344, 247, 194, 141]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "GeometricSequence:3", + "sat": "def sat(x: List[int], a=-777, r=4, l=103):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=-777, r=4, l=103):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Monotonic_9", - "sat": "def sat(direction: str, nums=[989, 968, 526, 437, 340, 234, 163, 159, 15]):\n \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n \"\"\"\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", - "sols": [ - "def sol(nums=[989, 968, 526, 437, 340, 234, 163, 159, 15]):\n return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + "name": "GeometricSequence:4", + "sat": "def sat(x: List[int], a=-736, r=4, l=92):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=-736, r=4, l=92):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_0", - "sat": "def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):\n return sorted(set(a).intersection(set(b)))" + "name": "LineIntersection:0", + "sat": "def sat(e: List[int], a=2, b=-1, c=1, d=2021):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=2, b=-1, c=1, d=2021):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_1", - "sat": "def sat(common: List[int], a=[824, 853, 392, 835, 225, 96], b=[73, 534, 705, 376, 376, 965, 404, 976]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[824, 853, 392, 835, 225, 96], b=[73, 534, 705, 376, 376, 965, 404, 976]):\n return sorted(set(a).intersection(set(b)))" + "name": "LineIntersection:1", + "sat": "def sat(e: List[int], a=-77698407, b=-31793716, c=-10799659, d=89278024):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=-77698407, b=-31793716, c=-10799659, d=89278024):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_2", - "sat": "def sat(common: List[int], a=[338, 882, 92, 234], b=[993, 977, 403]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[338, 882, 92, 234], b=[993, 977, 403]):\n return sorted(set(a).intersection(set(b)))" + "name": "LineIntersection:2", + "sat": "def sat(e: List[int], a=89600582, b=-47657198, c=95101265, d=-52126265):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=89600582, b=-47657198, c=95101265, d=-52126265):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_3", - "sat": "def sat(common: List[int], a=[950, 299, 581, 222, 490, 758, 58, 76, 808, 814], b=[790, 200, 814, 851, 902, 490, 581, 808, 950, 343, 758]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[950, 299, 581, 222, 490, 758, 58, 76, 808, 814], b=[790, 200, 814, 851, 902, 490, 581, 808, 950, 343, 758]):\n return sorted(set(a).intersection(set(b)))" + "name": "LineIntersection:3", + "sat": "def sat(e: List[int], a=-11422303, b=-57150416, c=-59162339, d=-37428439):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=-11422303, b=-57150416, c=-59162339, d=-37428439):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_4", - "sat": "def sat(common: List[int], a=[452, 318, 348, 995, 733, 874, 699], b=[733, 348, 614, 874, 699, 995, 318, 167, 452]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[452, 318, 348, 995, 733, 874, 699], b=[733, 348, 614, 874, 699, 995, 318, 167, 452]):\n return sorted(set(a).intersection(set(b)))" + "name": "LineIntersection:4", + "sat": "def sat(e: List[int], a=-18517001, b=-13662763, c=-11156613, d=9271005):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=-18517001, b=-13662763, c=-11156613, d=9271005):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_5", - "sat": "def sat(common: List[int], a=[262, 756, 961, 787, 301, 855, 157, 111, 120, 978, 285, 626, 324], b=[111, 262, 285, 132, 71, 301, 90, 322, 494, 557, 324]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[262, 756, 961, 787, 301, 855, 157, 111, 120, 978, 285, 626, 324], b=[111, 262, 285, 132, 71, 301, 90, 322, 494, 557, 324]):\n return sorted(set(a).intersection(set(b)))" + "name": "IfProblem:0", + "sat": "def sat(x: int, a=324554, b=1345345):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=324554, b=1345345):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_6", - "sat": "def sat(common: List[int], a=[746, 210, 79, 55, 209, 111, 730, 422, 224, 211, 165, 953, 454, 688, 329, 742, 583], b=[56, 739, 895, 176, 688, 746, 111, 583, 329, 79, 478, 431, 209, 980, 503, 165]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[746, 210, 79, 55, 209, 111, 730, 422, 224, 211, 165, 953, 454, 688, 329, 742, 583], b=[56, 739, 895, 176, 688, 746, 111, 583, 329, 79, 478, 431, 209, 980, 503, 165]):\n return sorted(set(a).intersection(set(b)))" + "name": "IfProblem:1", + "sat": "def sat(x: int, a=51, b=40553793):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=51, b=40553793):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_7", - "sat": "def sat(common: List[int], a=[836, 636, 440], b=[440, 183, 836]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[836, 636, 440], b=[440, 183, 836]):\n return sorted(set(a).intersection(set(b)))" + "name": "IfProblem:2", + "sat": "def sat(x: int, a=50, b=72369383):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=50, b=72369383):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_8", - "sat": "def sat(common: List[int], a=[254, 308, 416, 771, 539, 286, 743, 226, 245], b=[414, 846, 446, 253]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[254, 308, 416, 771, 539, 286, 743, 226, 245], b=[414, 846, 446, 253]):\n return sorted(set(a).intersection(set(b)))" + "name": "IfProblem:3", + "sat": "def sat(x: int, a=90, b=42412534):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=90, b=42412534):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CommonNumbers_9", - "sat": "def sat(common: List[int], a=[675, 549, 565, 460, 699, 265, 262, 82, 989], b=[565, 781, 549, 675, 265, 994, 262, 82, 18, 308, 837, 699, 460, 989]):\n \"\"\"\n Find numbers common to a and b\n \"\"\"\n return all((i in common) == (i in a and i in b) for i in a + b + common)", - "sols": [ - "def sol(a=[675, 549, 565, 460, 699, 265, 262, 82, 989], b=[565, 781, 549, 675, 265, 994, 262, 82, 18, 308, 837, 699, 460, 989]):\n return sorted(set(a).intersection(set(b)))" + "name": "IfProblem:4", + "sat": "def sat(x: int, a=62, b=-26538057):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=62, b=-26538057):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_0", - "sat": "def sat(p: int, n=101076):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=101076):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithAnd:0", + "sat": "def sat(x: int, a=9384594, b=1343663):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=9384594, b=1343663):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_1", - "sat": "def sat(p: int, n=15132):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=15132):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithAnd:1", + "sat": "def sat(x: int, a=57, b=40522966):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=57, b=40522966):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_2", - "sat": "def sat(p: int, n=22184):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=22184):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithAnd:2", + "sat": "def sat(x: int, a=29, b=71683001):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=29, b=71683001):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_3", - "sat": "def sat(p: int, n=70875):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=70875):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithAnd:3", + "sat": "def sat(x: int, a=92, b=8820402):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=92, b=8820402):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_4", - "sat": "def sat(p: int, n=63088):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=63088):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithAnd:4", + "sat": "def sat(x: int, a=64, b=46712723):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=64, b=46712723):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_5", - "sat": "def sat(p: int, n=51223):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=51223):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithOr:0", + "sat": "def sat(x: int, a=253532, b=1230200):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=253532, b=1230200):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_6", - "sat": "def sat(p: int, n=85167):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=85167):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithOr:1", + "sat": "def sat(x: int, a=22, b=-84904666):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=22, b=-84904666):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_7", - "sat": "def sat(p: int, n=58405):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=58405):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithOr:2", + "sat": "def sat(x: int, a=10, b=74723522):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=10, b=74723522):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_8", - "sat": "def sat(p: int, n=69200):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=69200):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithOr:3", + "sat": "def sat(x: int, a=66, b=-39109407):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=66, b=-39109407):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "LargestPrimeFactor_9", - "sat": "def sat(p: int, n=86522):\n \"\"\"\n Find the largest prime factor of n.\n \"\"\"\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", - "sols": [ - "def sol(n=86522):\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + "name": "IfProblemWithOr:4", + "sat": "def sat(x: int, a=24, b=18773099):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=24, b=18773099):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_0", - "sat": "def sat(sums: List[int], n=104):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=104):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "IfCases:0", + "sat": "def sat(x: int, a=4, b=54368639):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=4, b=54368639):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_1", - "sat": "def sat(sums: List[int], n=19891):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=19891):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "IfCases:1", + "sat": "def sat(x: int, a=-4, b=-83354930):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=-4, b=-83354930):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_2", - "sat": "def sat(sums: List[int], n=11023):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=11023):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "IfCases:2", + "sat": "def sat(x: int, a=-3, b=71965664):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=-3, b=71965664):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_3", - "sat": "def sat(sums: List[int], n=10840):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=10840):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "IfCases:3", + "sat": "def sat(x: int, a=2, b=36068130):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=2, b=36068130):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_4", - "sat": "def sat(sums: List[int], n=14049):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=14049):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "IfCases:4", + "sat": "def sat(x: int, a=-3, b=14385903):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=-3, b=14385903):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_5", - "sat": "def sat(sums: List[int], n=11990):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=11990):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "ListPosSum:0", + "sat": "def sat(x: List[int], n=5, s=19):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=5, s=19):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_6", - "sat": "def sat(sums: List[int], n=10416):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=10416):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "ListPosSum:1", + "sat": "def sat(x: List[int], n=6241, s=54594969):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=6241, s=54594969):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_7", - "sat": "def sat(sums: List[int], n=17813):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=17813):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "ListPosSum:2", + "sat": "def sat(x: List[int], n=8427, s=33081884):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=8427, s=33081884):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_8", - "sat": "def sat(sums: List[int], n=18684):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=18684):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "ListPosSum:3", + "sat": "def sat(x: List[int], n=3363, s=67595319):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=3363, s=67595319):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CumulativeSums_9", - "sat": "def sat(sums: List[int], n=6333):\n \"\"\"\n Find the sums of the integers from 1 to n\n \"\"\"\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", - "sols": [ - "def sol(n=6333):\n ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + "name": "ListPosSum:4", + "sat": "def sat(x: List[int], n=9909, s=88140438):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=9909, s=88140438):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_0", - "sat": "def sat(matches: List[int], parens=\"((())()(()()))(())\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"((())()(()()))(())\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ListDistinctSum:0", + "sat": "def sat(x: List[int], n=4, s=2021):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=4, s=2021):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_1", - "sat": "def sat(matches: List[int], parens=\"\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ListDistinctSum:1", + "sat": "def sat(x: List[int], n=124, s=2603089):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=124, s=2603089):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_2", - "sat": "def sat(matches: List[int], parens=\"()\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"()\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ListDistinctSum:2", + "sat": "def sat(x: List[int], n=823, s=8609609):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=823, s=8609609):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_3", - "sat": "def sat(matches: List[int], parens=\"((()(())))\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"((()(())))\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ListDistinctSum:3", + "sat": "def sat(x: List[int], n=796, s=86694751):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=796, s=86694751):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_4", - "sat": "def sat(matches: List[int], parens=\"(())\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"(())\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ListDistinctSum:4", + "sat": "def sat(x: List[int], n=225, s=38417364):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=225, s=38417364):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_5", - "sat": "def sat(matches: List[int], parens=\"()()(())\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"()()(())\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ConcatStrings:0", + "sat": "def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_6", - "sat": "def sat(matches: List[int], parens=\"(())()\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"(())()\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ConcatStrings:1", + "sat": "def sat(x: str, s=['I', '&', 'W', '&', 'p', 'c', '-', 'U', '(', ' ', 'A', '(', 'S', 'W', 'R', '#', 'm', 'v', '@', '8', '%', 'a', '.', 'K', 'O', '[', '[', '#', 'q', 'k', 'K'], n=16):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(n=16, s=['I', '&', 'W', '&', 'p', 'c', '-', 'U', '(', ' ', 'A', '(', 'S', 'W', 'R', '#', 'm', 'v', '@', '8', '%', 'a', '.', 'K', 'O', '[', '[', '#', 'q', 'k', 'K']):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_7", - "sat": "def sat(matches: List[int], parens=\"()()()\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"()()()\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ConcatStrings:2", + "sat": "def sat(x: str, s=['L', 'C', 'b', 'r', 't', 'V', 'R', '%', 'R', '8', 'V', '#', '<', '!', 'U', 'y', 'x'], n=13):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(n=13, s=['L', 'C', 'b', 'r', 't', 'V', 'R', '%', 'R', '8', 'V', '#', '<', '!', 'U', 'y', 'x']):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_8", - "sat": "def sat(matches: List[int], parens=\"()(()(()()))\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"()(()(()()))\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ConcatStrings:3", + "sat": "def sat(x: str, s=['-', '&', ')', '&', 'c', 'l', '/', 'H', '1', 'j', 'z', 'o', 'E', '|', '8', '&', '0', '&', 'y', '!', 'r', 'H', 'S', 'P', '5'], n=8):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(n=8, s=['-', '&', ')', '&', 'c', 'l', '/', 'H', '1', 'j', 'z', 'o', 'E', '|', '8', '&', '0', '&', 'y', '!', 'r', 'H', 'S', 'P', '5']):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "ParenDepth_9", - "sat": "def sat(matches: List[int], parens=\"(())()()()()(())\"):\n \"\"\"\n Find the index of the matching parentheses for each character in the string\n \"\"\"\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", - "sols": [ - "def sol(parens=\"(())()()()()(())\"):\n matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + "name": "ConcatStrings:4", + "sat": "def sat(x: str, s=['0', '@', 'R', 'k', '$', '$', 't', '0', '3', '#', '!', 'a', 'w', 'k', 'q', 'H', '-', 'm'], n=16):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(n=16, s=['0', '@', 'R', 'k', '$', '$', 't', '0', '3', '#', '!', 'a', 'w', 'k', 'q', 'H', '-', 'm']):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_0", - "sat": "def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[2, 1, 0, 4, 19, 231, 0, 5]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "SublistSum:0", + "sat": "def sat(x: List[int], t=677, a=43, e=125, s=10):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=677, a=43, e=125, s=10):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_1", - "sat": "def sat(derivative: List[int], poly=[6, -7, -8, 3]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[6, -7, -8, 3]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "SublistSum:1", + "sat": "def sat(x: List[int], t=44475424, a=93, e=8496, s=6):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=44475424, a=93, e=8496, s=6):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_2", - "sat": "def sat(derivative: List[int], poly=[-5, 5, -6, 7]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[-5, 5, -6, 7]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "SublistSum:2", + "sat": "def sat(x: List[int], t=2183536, a=36, e=8450, s=1):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=2183536, a=36, e=8450, s=1):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_3", - "sat": "def sat(derivative: List[int], poly=[-8, 2, 1, -8, 9, -10, -2, -7, -10]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[-8, 2, 1, -8, 9, -10, -2, -7, -10]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "SublistSum:3", + "sat": "def sat(x: List[int], t=1196610, a=15, e=4376, s=3):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=1196610, a=15, e=4376, s=3):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_4", - "sat": "def sat(derivative: List[int], poly=[5, -1, -4, -2, 7, -9, 3, 9]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[5, -1, -4, -2, 7, -9, 3, 9]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "SublistSum:4", + "sat": "def sat(x: List[int], t=6165697, a=47, e=3830, s=2):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=6165697, a=47, e=3830, s=2):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_5", - "sat": "def sat(derivative: List[int], poly=[4, -2, 1]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[4, -2, 1]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "CumulativeSum:0", + "sat": "def sat(x: List[int], t=50, n=10):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=50, n=10):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_6", - "sat": "def sat(derivative: List[int], poly=[-10, -3, -4]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[-10, -3, -4]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "CumulativeSum:1", + "sat": "def sat(x: List[int], t=364928431, n=1088):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=364928431, n=1088):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_7", - "sat": "def sat(derivative: List[int], poly=[-3]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[-3]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "CumulativeSum:2", + "sat": "def sat(x: List[int], t=7978940451, n=5932):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=7978940451, n=5932):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_8", - "sat": "def sat(derivative: List[int], poly=[3, -7, -10, -1, 6, -9, 0]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[3, -7, -10, -1, 6, -9, 0]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "CumulativeSum:3", + "sat": "def sat(x: List[int], t=4545622399, n=1009):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=4545622399, n=1009):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Derivative_9", - "sat": "def sat(derivative: List[int], poly=[-1, -8, -4]):\n \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n \"\"\"\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", - "sols": [ - "def sol(poly=[-1, -8, -4]):\n return [i * poly[i] for i in range(1, len(poly))]" + "name": "CumulativeSum:4", + "sat": "def sat(x: List[int], t=4917027557, n=4815):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=4917027557, n=4815):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_0", - "sat": "def sat(init: List[int], target=124156):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=124156):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "BasicStrCounts:0", + "sat": "def sat(s: str, s1=\"a\", s2=\"b\", count1=50, count2=30):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"a\", s2=\"b\", count1=50, count2=30):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_1", - "sat": "def sat(init: List[int], target=4050):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=4050):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "BasicStrCounts:1", + "sat": "def sat(s: str, s1=\"t\", s2=\"qu\", count1=86, count2=83):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"t\", s2=\"qu\", count1=86, count2=83):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_2", - "sat": "def sat(init: List[int], target=0):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=0):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "BasicStrCounts:2", + "sat": "def sat(s: str, s1=\"kuc\", s2=\"qu\", count1=63, count2=58):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"kuc\", s2=\"qu\", count1=63, count2=58):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_3", - "sat": "def sat(init: List[int], target=4644):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=4644):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "BasicStrCounts:3", + "sat": "def sat(s: str, s1=\"te\", s2=\"tex\", count1=97, count2=53):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"te\", s2=\"tex\", count1=97, count2=53):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_4", - "sat": "def sat(init: List[int], target=3):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=3):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "BasicStrCounts:4", + "sat": "def sat(s: str, s1=\"hot\", s2=\"n\", count1=48, count2=92):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"hot\", s2=\"n\", count1=48, count2=92):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_5", - "sat": "def sat(init: List[int], target=1124):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=1124):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "ZipStr:0", + "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz', 'oddball']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['foo', 'bar', 'baz', 'oddball']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_6", - "sat": "def sat(init: List[int], target=583):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=583):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "ZipStr:1", + "sat": "def sat(s: str, substrings=['quifelota', 'chyhimyvemene', 'ge']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['quifelota', 'chyhimyvemene', 'ge']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_7", - "sat": "def sat(init: List[int], target=79):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=79):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "ZipStr:2", + "sat": "def sat(s: str, substrings=['kitytextiritex', 'cumathoxaz', 'rebute', 'rocor']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['kitytextiritex', 'cumathoxaz', 'rebute', 'rocor']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_8", - "sat": "def sat(init: List[int], target=3745):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=3745):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "ZipStr:3", + "sat": "def sat(s: str, substrings=['te', 'wusyc']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['te', 'wusyc']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "Fib3_9", - "sat": "def sat(init: List[int], target=22):\n \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n \"\"\"\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", - "sols": [ - "def sol(target=22):\n nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + "name": "ZipStr:4", + "sat": "def sat(s: str, substrings=['cute', 'rysucajaxuno']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['cute', 'rysucajaxuno']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_0", - "sat": "def sat(vowels: str, text=\"Hello, world!\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"Hello, world!\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "ReverseCat:0", + "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['foo', 'bar', 'baz']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_1", - "sat": "def sat(vowels: str, text=\"rifyXajAhevIchiDu\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"rifyXajAhevIchiDu\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "ReverseCat:1", + "sat": "def sat(s: str, substrings=['kepijilufuwisejyzat', 'lechogyvonaxegitex']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['kepijilufuwisejyzat', 'lechogyvonaxegitex']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_2", - "sat": "def sat(vowels: str, text=\"fakYmAjEhEJU\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"fakYmAjEhEJU\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "ReverseCat:2", + "sat": "def sat(s: str, substrings=['ripihuquyrenytu', 'quosafyji', 'chyguzocuzuqu', 'futhixequyb']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['ripihuquyrenytu', 'quosafyji', 'chyguzocuzuqu', 'futhixequyb']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_3", - "sat": "def sat(vowels: str, text=\"TexTAkOQ\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"TexTAkOQ\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "ReverseCat:3", + "sat": "def sat(s: str, substrings=['thacovatukoliva', 'maquyfezisothizyp', 'ka', 'benegiquememif']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['thacovatukoliva', 'maquyfezisothizyp', 'ka', 'benegiquememif']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_4", - "sat": "def sat(vowels: str, text=\"jIGIbYcHetYn\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"jIGIbYcHetYn\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "ReverseCat:4", + "sat": "def sat(s: str, substrings=['t', 'vochemachylit', 'vutextynydakelopi', 'fazapydomozamochug']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['t', 'vochemachylit', 'vutextynydakelopi', 'fazapydomozamochug']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_5", - "sat": "def sat(vowels: str, text=\"TEbolOWUZ\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"TEbolOWUZ\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "EngineerNumbers:0", + "sat": "def sat(ls: List[str], n=100, a=\"bar\", b=\"foo\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=100, a=\"bar\", b=\"foo\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_6", - "sat": "def sat(vowels: str, text=\"seViThoXupyfUDeFiQ\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"seViThoXupyfUDeFiQ\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "EngineerNumbers:1", + "sat": "def sat(ls: List[str], n=44, a=\"lychezothotextocev\", b=\"th\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=44, a=\"lychezothotextocev\", b=\"th\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_7", - "sat": "def sat(vowels: str, text=\"qUApAcOLe\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"qUApAcOLe\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "EngineerNumbers:2", + "sat": "def sat(ls: List[str], n=13, a=\"kacukebyhapuniryh\", b=\"te\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=13, a=\"kacukebyhapuniryh\", b=\"te\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_8", - "sat": "def sat(vowels: str, text=\"TeXTiTUDixy\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"TeXTiTUDixy\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "EngineerNumbers:3", + "sat": "def sat(ls: List[str], n=61, a=\"cisoceratext\", b=\"milusicochylitextyco\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=61, a=\"cisoceratext\", b=\"milusicochylitextyco\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "FindVowels_9", - "sat": "def sat(vowels: str, text=\"NiG\"):\n \"\"\"\n Find the vowels from the original string.\n \"\"\"\n i = 0\n for j, c in enumerate(text):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(text) - 1:\n assert vowels[i] == c\n i += 1\n return i == len(vowels)", - "sols": [ - "def sol(text=\"NiG\"):\n return \"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")" + "name": "EngineerNumbers:4", + "sat": "def sat(ls: List[str], n=59, a=\"hokitextawelaxah\", b=\"maryhedu\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=59, a=\"hokitextawelaxah\", b=\"maryhedu\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_0", - "sat": "def sat(shifted: str, n=124582369835, shift=3):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=124582369835, shift=3):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateString:0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_1", - "sat": "def sat(shifted: str, n=6852918492, shift=12):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=6852918492, shift=12):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateString:1", + "sat": "def sat(s: str, strings=['ryzapychybykydege', 'mivowepe', 'sovywos', 'chanyrorybynid', 'vafechajufo', 'nokymocymoxac', 'jahejafuquoduk', 'gogy', 'bytothice', 'ruminuvixixutudigom']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['ryzapychybykydege', 'mivowepe', 'sovywos', 'chanyrorybynid', 'vafechajufo', 'nokymocymoxac', 'jahejafuquoduk', 'gogy', 'bytothice', 'ruminuvixixutudigom']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_2", - "sat": "def sat(shifted: str, n=32928510691049616, shift=28):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=32928510691049616, shift=28):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateString:2", + "sat": "def sat(s: str, strings=['mipelavychekecy', 'pythujutisoxofe', 'diliwagacivychinofiw', 'na', 'dobynaramithibolo', 'cugupyfytextofoxat', 'gyfokebo', 'bymitextitextizoc', 'rekimuk', 'bepumyxitubachek']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['mipelavychekecy', 'pythujutisoxofe', 'diliwagacivychinofiw', 'na', 'dobynaramithibolo', 'cugupyfytextofoxat', 'gyfokebo', 'bymitextitextizoc', 'rekimuk', 'bepumyxitubachek']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_3", - "sat": "def sat(shifted: str, n=237, shift=26):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=237, shift=26):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateString:3", + "sat": "def sat(s: str, strings=['hunuvarufefikaq', 'xejegu', 'minoc', 'puthyvyc', 'xyzeryberi', 'tyl', 'thyvojyvijazetonowa', 'jahygywuchitho', 'quuvuvigy', 'zuhechywituthexe']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['hunuvarufefikaq', 'xejegu', 'minoc', 'puthyvyc', 'xyzeryberi', 'tyl', 'thyvojyvijazetonowa', 'jahygywuchitho', 'quuvuvigy', 'zuhechywituthexe']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_4", - "sat": "def sat(shifted: str, n=6, shift=26):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=6, shift=26):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateString:4", + "sat": "def sat(s: str, strings=['wesolotelunyzecemexi', 'pociquuwygocysahef', 'lequusigipitexti', 'quojuxaq', 'fyt', 'm', 'bavalepynoza', 'zihath', 'lodomijibuxoju', 'xasuwytextochypuli']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['wesolotelunyzecemexi', 'pociquuwygocysahef', 'lequusigipitexti', 'quojuxaq', 'fyt', 'm', 'bavalepynoza', 'zihath', 'lodomijibuxoju', 'xasuwytextochypuli']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_5", - "sat": "def sat(shifted: str, n=87805754, shift=4):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=87805754, shift=4):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateRevString:0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_6", - "sat": "def sat(shifted: str, n=3211412876, shift=5):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=3211412876, shift=5):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateRevString:1", + "sat": "def sat(s: str, strings=['rawithelen', 'que', 'pikuf', 'koze', 'zehyquorofyxytextef', 'text', 'jezebox', 'zychopucebychokyz', 'pyzyxatevafugedix', 'buzogehabojyb']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['rawithelen', 'que', 'pikuf', 'koze', 'zehyquorofyxytextef', 'text', 'jezebox', 'zychopucebychokyz', 'pyzyxatevafugedix', 'buzogehabojyb']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_7", - "sat": "def sat(shifted: str, n=0, shift=12):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=0, shift=12):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateRevString:2", + "sat": "def sat(s: str, strings=['thythanaham', 'quiroxebadivogis', 'kyh', 'xa', 'gathytyjonymihahahy', 'musyzisequyxyhenico', 'poxizitizexokigewifi', 'mife', 'chyjuratexta', 'gyrato']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['thythanaham', 'quiroxebadivogis', 'kyh', 'xa', 'gathytyjonymihahahy', 'musyzisequyxyhenico', 'poxizitizexokigewifi', 'mife', 'chyjuratexta', 'gyrato']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_8", - "sat": "def sat(shifted: str, n=754948761, shift=18):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=754948761, shift=18):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateRevString:3", + "sat": "def sat(s: str, strings=['habicynanikadifovac', 'bozehathyfoz', 'hud', 'textudunachuxarise', 'hewohahatazabab', 'lutumelimevabutha', 'wocher', 'wacifufixudizon', 'tazibedo', 'xytu']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['habicynanikadifovac', 'bozehathyfoz', 'hud', 'textudunachuxarise', 'hewohahatazabab', 'lutumelimevabutha', 'wocher', 'wacifufixudizon', 'tazibedo', 'xytu']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CircularShiftNum_9", - "sat": "def sat(shifted: str, n=8661, shift=14):\n \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n \"\"\"\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", - "sols": [ - "def sol(n=8661, shift=14):\n s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + "name": "PenultimateRevString:4", + "sat": "def sat(s: str, strings=['vekykothumygochuth', 'xujatajazisiqu', 'vapyvymobymethotexto', 'tygope', 'g', 'ripalotextaj', 'tecehuthojodogucivaj', 'xyjulecometihesej', 'ribo', 'gutachowagexatoset']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['vekykothumygochuth', 'xujatajazisiqu', 'vapyvymobymethotexto', 'tygope', 'g', 'ripalotextaj', 'tecehuthojodogucivaj', 'xyjulecometihesej', 'ribo', 'gutachowagexatoset']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_0", - "sat": "def sat(tot: int, s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "CenteredString:0", + "sat": "def sat(s: str, target=\"foobarbazwow\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"foobarbazwow\", length=6):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_1", - "sat": "def sat(tot: int, s=\"VRkmX=(1oF#l\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"VRkmX=(1oF#l\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "CenteredString:1", + "sat": "def sat(s: str, target=\"rujus\", length=1):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"rujus\", length=1):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_2", - "sat": "def sat(tot: int, s=\"*?sAJJ;FY8c!7zFwA\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"*?sAJJ;FY8c!7zFwA\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "CenteredString:2", + "sat": "def sat(s: str, target=\"bulu\", length=4):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"bulu\", length=4):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_3", - "sat": "def sat(tot: int, s=\"Vmv%e8d3P\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"Vmv%e8d3P\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "CenteredString:3", + "sat": "def sat(s: str, target=\"defojuhujuwilumec\", length=7):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"defojuhujuwilumec\", length=7):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_4", - "sat": "def sat(tot: int, s=\"K8B\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"K8B\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "CenteredString:4", + "sat": "def sat(s: str, target=\"tenuhije\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"tenuhije\", length=6):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_5", - "sat": "def sat(tot: int, s=\"/u%@\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"/u%@\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "SubstrCount:0", + "sat": "def sat(substring: str, string=\"moooboooofasd\", count=2):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"moooboooofasd\", count=2):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_6", - "sat": "def sat(tot: int, s=\"$|Om9UQ(Q\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"$|Om9UQ(Q\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "SubstrCount:1", + "sat": "def sat(substring: str, string=\"nyvyfytibuquyquuchudemixyzychumanachozyquiquowutextyvomyzychyme\", count=4):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"nyvyfytibuquyquuchudemixyzychumanachozyquiquowutextyvomyzychyme\", count=4):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_7", - "sat": "def sat(tot: int, s=\"Z]SOPL2\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"Z]SOPL2\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "SubstrCount:2", + "sat": "def sat(substring: str, string=\"cokomoquiwythyluwamymothynihythenyfeteth\", count=4):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"cokomoquiwythyluwamymothynihythenyfeteth\", count=4):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_8", - "sat": "def sat(tot: int, s=\"H;>7pR;RNj\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"H;>7pR;RNj\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "SubstrCount:3", + "sat": "def sat(substring: str, string=\"cutextolichymocajethamopyvepethytextydynykihywyxivytextequylejekuf\", count=3):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"cutextolichymocajethamopyvepethytextydynykihywyxivytextequylejekuf\", count=3):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "CharSum_9", - "sat": "def sat(tot: int, s=\"P5kSxb2thSWa\"):\n \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n \"\"\"\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", - "sols": [ - "def sol(s=\"P5kSxb2thSWa\"):\n return sum(ord(c) for c in s if c.isupper())" + "name": "SubstrCount:4", + "sat": "def sat(substring: str, string=\"modacequytextytextilaleguthovamipehywaciripetext\", count=3):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"modacequytextytextilaleguthovamipehywaciripetext\", count=3):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_0", - "sat": "def sat(bananas: int, bowl=\"5024 apples and 12189 oranges\", total=12491241):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"5024 apples and 12189 oranges\", total=12491241):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "CompleteParens:0", + "sat": "def sat(t: str, s=\"))(Add)some))parens()to()(balance(()(()(me!)((((\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\"))(Add)some))parens()to()(balance(()(()(me!)((((\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_1", - "sat": "def sat(bananas: int, bowl=\"7 apples and 9 oranges\", total=21):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"7 apples and 9 oranges\", total=21):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "CompleteParens:1", + "sat": "def sat(t: str, s=\"(po)(())kf((((cy()))((tex()())(\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\"(po)(())kf((((cy()))((tex()())(\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_2", - "sat": "def sat(bananas: int, bowl=\"508738582 apples and 346410095 oranges\", total=1452490389):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"508738582 apples and 346410095 oranges\", total=1452490389):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "CompleteParens:2", + "sat": "def sat(t: str, s=\"yf)()(()))hik()t(((\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\"yf)()(()))hik()t(((\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_3", - "sat": "def sat(bananas: int, bowl=\"28767 apples and 49488 oranges\", total=112303):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"28767 apples and 49488 oranges\", total=112303):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "CompleteParens:3", + "sat": "def sat(t: str, s=\")((le(()()chu)())nol))((sic(((da)()ty((()te))xy(())))))k\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\")((le(()()chu)())nol))((sic(((da)()ty((()te))xy(())))))k\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_4", - "sat": "def sat(bananas: int, bowl=\"29991 apples and 99737 oranges\", total=155600):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"29991 apples and 99737 oranges\", total=155600):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "CompleteParens:4", + "sat": "def sat(t: str, s=\"))())l\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\"))())l\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "basic.py", + "notes": "", + "weight": 1.0 }, { - "name": "MissingBananas_5", - "sat": "def sat(bananas: int, bowl=\"6 apples and 1 oranges\", total=14):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"6 apples and 1 oranges\", total=14):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "EightQueensOrFewer:0", + "sat": "def sat(squares: List[List[int]], m=8, n=8):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 }, { - "name": "MissingBananas_6", - "sat": "def sat(bananas: int, bowl=\"0 apples and 8 oranges\", total=10):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"0 apples and 8 oranges\", total=10):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "EightQueensOrFewer:1", + "sat": "def sat(squares: List[List[int]], m=9, n=6):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=9, n=6):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 }, { - "name": "MissingBananas_7", - "sat": "def sat(bananas: int, bowl=\"51265 apples and 15404 oranges\", total=113126):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"51265 apples and 15404 oranges\", total=113126):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "EightQueensOrFewer:2", + "sat": "def sat(squares: List[List[int]], m=59, n=4):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=59, n=4):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 }, { - "name": "MissingBananas_8", - "sat": "def sat(bananas: int, bowl=\"7 apples and 4 oranges\", total=20):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"7 apples and 4 oranges\", total=20):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "EightQueensOrFewer:3", + "sat": "def sat(squares: List[List[int]], m=38, n=8):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=38, n=8):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 }, { - "name": "MissingBananas_9", - "sat": "def sat(bananas: int, bowl=\"34370 apples and 10603 oranges\", total=76203):\n \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n \"\"\"\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", - "sols": [ - "def sol(bowl=\"34370 apples and 10603 oranges\", total=76203):\n apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + "name": "EightQueensOrFewer:4", + "sat": "def sat(squares: List[List[int]], m=9, n=4):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=9, n=4):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 }, { - "name": "SmallestEven_0", - "sat": "def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "MoreQueens:0", + "sat": "def sat(squares: List[List[int]], m=9, n=9):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=9, n=9):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 }, { - "name": "SmallestEven_1", - "sat": "def sat(val_index: List[int], nums=[38940, 7988, 78915]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[38940, 7988, 78915]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "MoreQueens:1", + "sat": "def sat(squares: List[List[int]], m=79, n=95):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=79, n=95):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 }, { - "name": "SmallestEven_2", - "sat": "def sat(val_index: List[int], nums=[26392632, 33805163]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[26392632, 33805163]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "MoreQueens:2", + "sat": "def sat(squares: List[List[int]], m=80, n=88):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=80, n=88):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 }, { - "name": "SmallestEven_3", - "sat": "def sat(val_index: List[int], nums=[744557286]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[744557286]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "MoreQueens:3", + "sat": "def sat(squares: List[List[int]], m=56, n=16):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=56, n=16):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 }, { - "name": "SmallestEven_4", - "sat": "def sat(val_index: List[int], nums=[4512821, 7022753, 5506558]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[4512821, 7022753, 5506558]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "MoreQueens:4", + "sat": "def sat(squares: List[List[int]], m=23, n=45):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=23, n=45):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 }, { - "name": "SmallestEven_5", - "sat": "def sat(val_index: List[int], nums=[188, 858, 456]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[188, 858, 456]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "KnightsTour:0", + "sat": "def sat(tour: List[List[int]], m=8, n=8):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 }, { - "name": "SmallestEven_6", - "sat": "def sat(val_index: List[int], nums=[0, 0, 0]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[0, 0, 0]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "KnightsTour:1", + "sat": "def sat(tour: List[List[int]], m=9, n=9):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=9, n=9):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 }, { - "name": "SmallestEven_7", - "sat": "def sat(val_index: List[int], nums=[0, 0, 0, 0]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[0, 0, 0, 0]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "KnightsTour:2", + "sat": "def sat(tour: List[List[int]], m=7, n=7):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=7, n=7):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 }, { - "name": "SmallestEven_8", - "sat": "def sat(val_index: List[int], nums: List[int]=[]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "KnightsTour:3", + "sat": "def sat(tour: List[List[int]], m=6, n=6):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=6, n=6):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 }, { - "name": "SmallestEven_9", - "sat": "def sat(val_index: List[int], nums=[4284152, 5395517, 619081]):\n \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n \"\"\"\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", - "sols": [ - "def sol(nums=[4284152, 5395517, 619081]):\n if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + "name": "KnightsTour:4", + "sat": "def sat(tour: List[List[int]], m=7, n=8):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=7, n=8):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 }, { - "name": "GreatestHIndex_0", - "sat": "def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UncrossedKnightsPath:0", + "sat": "def sat(path: List[List[int]], m=8, n=8, target=35):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8, target=35):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_1", - "sat": "def sat(h: int, seq=[5, 5, 4, 4, 0, 1, 3, 7, 2, 1, 0, 1, 8, 7, 2, 7, 4, 5, 2, 7, 5, 1, 9, 4, 7, 6, 3, 0, 1, 0, 6, 8, 0, 8, 9, 8, 3, 9, 4, 4, 4, 3, 8, 9, 5, 2, 5, 7, 9, 6, 2, 3, 0, 6, 0, 7, 8, 2, 2, 5, 1, 6, 1, 7, 8, 7, 6, 7]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[5, 5, 4, 4, 0, 1, 3, 7, 2, 1, 0, 1, 8, 7, 2, 7, 4, 5, 2, 7, 5, 1, 9, 4, 7, 6, 3, 0, 1, 0, 6, 8, 0, 8, 9, 8, 3, 9, 4, 4, 4, 3, 8, 9, 5, 2, 5, 7, 9, 6, 2, 3, 0, 6, 0, 7, 8, 2, 2, 5, 1, 6, 1, 7, 8, 7, 6, 7]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UncrossedKnightsPath:1", + "sat": "def sat(path: List[List[int]], m=3, n=3, target=2):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=3, n=3, target=2):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_2", - "sat": "def sat(h: int, seq=[3, 9, 0, 8, 2, 9, 6, 1, 8, 3, 5, 5, 4, 9, 0, 1, 0, 3, 4, 8, 7, 2, 4, 7, 1, 1, 7, 2, 1, 4, 1, 0]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[3, 9, 0, 8, 2, 9, 6, 1, 8, 3, 5, 5, 4, 9, 0, 1, 0, 3, 4, 8, 7, 2, 4, 7, 1, 1, 7, 2, 1, 4, 1, 0]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UncrossedKnightsPath:2", + "sat": "def sat(path: List[List[int]], m=4, n=4, target=5):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=4, n=4, target=5):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_3", - "sat": "def sat(h: int, seq=[7, 4, 1, 8, 6, 6, 6, 8, 5, 5, 8, 3, 0, 7, 2, 7, 2, 4, 5, 8, 6, 1, 1, 0, 0, 8, 8, 1, 5, 2, 1, 1, 7, 1, 3, 5, 6, 1, 7, 9, 6, 2, 6, 4, 7, 4, 3, 1, 2, 3, 9, 7, 7, 1, 7, 8, 6, 5, 9, 1, 6, 3, 4, 2, 4, 1, 7, 6, 3, 2, 5, 6, 1, 3, 9, 4, 9, 6, 9, 8, 1, 2, 3, 8]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[7, 4, 1, 8, 6, 6, 6, 8, 5, 5, 8, 3, 0, 7, 2, 7, 2, 4, 5, 8, 6, 1, 1, 0, 0, 8, 8, 1, 5, 2, 1, 1, 7, 1, 3, 5, 6, 1, 7, 9, 6, 2, 6, 4, 7, 4, 3, 1, 2, 3, 9, 7, 7, 1, 7, 8, 6, 5, 9, 1, 6, 3, 4, 2, 4, 1, 7, 6, 3, 2, 5, 6, 1, 3, 9, 4, 9, 6, 9, 8, 1, 2, 3, 8]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UncrossedKnightsPath:3", + "sat": "def sat(path: List[List[int]], m=5, n=5, target=10):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=5, n=5, target=10):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_4", - "sat": "def sat(h: int, seq=[1, 2, 6, 2]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[1, 2, 6, 2]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UncrossedKnightsPath:4", + "sat": "def sat(path: List[List[int]], m=6, n=5, target=9):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=6, n=5, target=9):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_5", - "sat": "def sat(h: int, seq=[0, 6, 9, 5, 9, 0, 8, 8, 5, 6, 7, 1, 5, 6, 6, 0, 1, 8, 0, 9, 6, 2, 4, 0, 8, 1, 6, 3, 9]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[0, 6, 9, 5, 9, 0, 8, 8, 5, 6, 7, 1, 5, 6, 6, 0, 1, 8, 0, 9, 6, 2, 4, 0, 8, 1, 6, 3, 9]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UNSOLVED_UncrossedKnightsPath:0", + "sat": "def sat(path: List[List[int]], m=10, n=10, target=62):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=10, target=62):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_6", - "sat": "def sat(h: int, seq=[9, 5, 2, 6, 2, 7, 9, 1, 8, 7, 4, 1, 2, 2, 5, 5, 6, 9, 4, 1, 1, 0, 0, 3, 1, 0, 5, 0, 6, 7, 0, 4, 3, 5, 5, 3, 5, 3, 9, 9, 8, 9, 2, 0, 2, 5, 3, 4, 3, 8, 7, 6, 8, 5, 6, 0, 7, 5, 3, 5, 9, 9, 9, 7, 2, 9, 0, 9, 2, 8, 4, 1, 7, 4, 2, 1, 3, 0, 6, 5, 1, 4, 2, 5, 8, 1, 4, 9, 3, 7, 7, 3]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[9, 5, 2, 6, 2, 7, 9, 1, 8, 7, 4, 1, 2, 2, 5, 5, 6, 9, 4, 1, 1, 0, 0, 3, 1, 0, 5, 0, 6, 7, 0, 4, 3, 5, 5, 3, 5, 3, 9, 9, 8, 9, 2, 0, 2, 5, 3, 4, 3, 8, 7, 6, 8, 5, 6, 0, 7, 5, 3, 5, 9, 9, 9, 7, 2, 9, 0, 9, 2, 8, 4, 1, 7, 4, 2, 1, 3, 0, 6, 5, 1, 4, 2, 5, 8, 1, 4, 9, 3, 7, 7, 3]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UNSOLVED_UncrossedKnightsPath:1", + "sat": "def sat(path: List[List[int]], m=11, n=11, target=77):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=11, n=11, target=77):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_7", - "sat": "def sat(h: int, seq=[6, 2, 0, 5, 6, 8, 5, 3, 5, 7, 0, 4, 7, 8, 0, 7, 3, 5, 3, 7, 6, 9, 8, 4, 5, 6, 6, 0, 5, 3, 5, 1, 3, 5, 4, 4, 1, 3, 2, 3, 0, 0, 2, 5, 8, 3, 5, 5, 6, 1, 8, 1, 8, 0, 0, 6, 7, 7, 8, 5, 1, 3, 5, 7, 3, 4, 1, 2, 5, 7, 8, 6, 1, 7, 0, 9, 4, 5, 6, 4, 3, 4, 0, 5, 8, 6, 7, 4, 8, 5, 9]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[6, 2, 0, 5, 6, 8, 5, 3, 5, 7, 0, 4, 7, 8, 0, 7, 3, 5, 3, 7, 6, 9, 8, 4, 5, 6, 6, 0, 5, 3, 5, 1, 3, 5, 4, 4, 1, 3, 2, 3, 0, 0, 2, 5, 8, 3, 5, 5, 6, 1, 8, 1, 8, 0, 0, 6, 7, 7, 8, 5, 1, 3, 5, 7, 3, 4, 1, 2, 5, 7, 8, 6, 1, 7, 0, 9, 4, 5, 6, 4, 3, 4, 0, 5, 8, 6, 7, 4, 8, 5, 9]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UNSOLVED_UncrossedKnightsPath:2", + "sat": "def sat(path: List[List[int]], m=12, n=12, target=95):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=12, n=12, target=95):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_8", - "sat": "def sat(h: int, seq=[7, 2, 1, 0, 1, 4, 9, 0, 4, 8, 7, 2, 5, 1, 9, 1, 4]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[7, 2, 1, 0, 1, 4, 9, 0, 4, 8, 7, 2, 5, 1, 9, 1, 4]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "UNSOLVED_UncrossedKnightsPath:3", + "sat": "def sat(path: List[List[int]], m=13, n=13, target=114):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=13, n=13, target=114):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 }, { - "name": "GreatestHIndex_9", - "sat": "def sat(h: int, seq=[0, 3, 8, 4, 3, 4, 3, 8, 3, 7, 3, 2, 7, 6, 9, 2, 4, 8, 9, 4, 8, 1, 3, 3, 1, 7, 6, 1, 3, 8, 0, 3, 2, 8, 3, 4, 0, 9, 9, 8, 4, 2, 5, 1, 6, 8, 0, 3, 5, 3, 3, 3, 0, 0, 5, 6, 8, 3, 7, 4, 7, 0, 0, 6, 3, 1, 9, 7, 0, 3, 1, 1, 6, 1, 6, 2, 4, 8, 0, 9, 4, 3, 9, 5, 2]):\n \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n \"\"\"\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", - "sols": [ - "def sol(seq=[0, 3, 8, 4, 3, 4, 3, 8, 3, 7, 3, 2, 7, 6, 9, 2, 4, 8, 9, 4, 8, 1, 3, 3, 1, 7, 6, 1, 3, 8, 0, 3, 2, 8, 3, 4, 0, 9, 9, 8, 4, 2, 5, 1, 6, 8, 0, 3, 5, 3, 3, 3, 0, 0, 5, 6, 8, 3, 7, 4, 7, 0, 0, 6, 3, 1, 9, 7, 0, 3, 1, 1, 6, 1, 6, 2, 4, 8, 0, 9, 4, 3, 9, 5, 2]):\n return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" + "name": "LZW:0", + "sat": "def sat(seq: List[int], compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 }, { - "name": "StrangeSort_0", - "sat": "def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "LZW:1", + "sat": "def sat(seq: List[int], compressed_len=0, text=\"\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(text=\"\", compressed_len=0):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 }, { - "name": "StrangeSort_1", - "sat": "def sat(strange: List[int], li=[8, 4, 1, 2, 6, 5, 3, 9, 3, 5, 9, 6, 3, 9, 6]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[8, 4, 1, 2, 6, 5, 3, 9, 3, 5, 9, 6, 3, 9, 6]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "LZW:2", + "sat": "def sat(seq: List[int], compressed_len=45, text=\"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(text=\"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\", compressed_len=45):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 }, { - "name": "StrangeSort_2", - "sat": "def sat(strange: List[int], li=[7, 5, 5, 6, 2, 9, 6, 4, 2]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[7, 5, 5, 6, 2, 9, 6, 4, 2]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "LZW:3", + "sat": "def sat(seq: List[int], compressed_len=154, text=\"cupewoquabipemecacichytogycykythyzydizutextojokosapysetextethilabequypagichichimipyhuquithyzuwukychycokigomylotextoquochachikalocejiwyzagodothilythetiquypirabafusubasufylejulitudosisyrahezitextoluquevy\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(text=\"cupewoquabipemecacichytogycykythyzydizutextojokosapysetextethilabequypagichichimipyhuquithyzuwukychycokigomylotextoquochachikalocejiwyzagodothilythetiquypirabafusubasufylejulitudosisyrahezitextoluquevy\", compressed_len=154):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 }, { - "name": "StrangeSort_3", - "sat": "def sat(strange: List[int], li=[9, 9, 1]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[9, 9, 1]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "LZW:4", + "sat": "def sat(seq: List[int], compressed_len=2, text=\"si\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(text=\"si\", compressed_len=2):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 }, { - "name": "StrangeSort_4", - "sat": "def sat(strange: List[int], li=[3, 2, 3, 1]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[3, 2, 3, 1]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "PackingHam:0", + "sat": "def sat(words: List[str], num=100, bits=100, dist=34):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=100, bits=100, dist=34):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 }, { - "name": "StrangeSort_5", - "sat": "def sat(strange: List[int], li=[4, 1, 7, 6, 6, 1, 0, 8, 3]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[4, 1, 7, 6, 6, 1, 0, 8, 3]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "PackingHam:1", + "sat": "def sat(words: List[str], num=5, bits=81, dist=30):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=5, bits=81, dist=30):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 }, { - "name": "StrangeSort_6", - "sat": "def sat(strange: List[int], li=[8, 0, 5, 3, 3, 9, 6, 1, 5, 1, 4, 5, 7, 0]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[8, 0, 5, 3, 3, 9, 6, 1, 5, 1, 4, 5, 7, 0]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "PackingHam:2", + "sat": "def sat(words: List[str], num=78, bits=64, dist=16):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=78, bits=64, dist=16):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 }, { - "name": "StrangeSort_7", - "sat": "def sat(strange: List[int], li=[7, 4, 8, 1, 5, 7, 2, 4, 3, 8, 6, 6, 1, 2, 0, 1, 8, 5]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[7, 4, 8, 1, 5, 7, 2, 4, 3, 8, 6, 6, 1, 2, 0, 1, 8, 5]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "PackingHam:3", + "sat": "def sat(words: List[str], num=28, bits=11, dist=1):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=28, bits=11, dist=1):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 }, { - "name": "StrangeSort_8", - "sat": "def sat(strange: List[int], li=[5, 0, 2, 3, 8, 7, 2, 7, 1, 7, 0, 8, 3, 7]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[5, 0, 2, 3, 8, 7, 2, 7, 1, 7, 0, 8, 3, 7]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "PackingHam:4", + "sat": "def sat(words: List[str], num=8, bits=75, dist=24):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=8, bits=75, dist=24):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 }, { - "name": "StrangeSort_9", - "sat": "def sat(strange: List[int], li=[1, 5]):\n \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n \"\"\"\n if len(li) < 2:\n return strange == li\n bounds = strange[:2] # lower, upper\n for i, n in enumerate(strange):\n assert bounds[0] <= n <= bounds[1]\n bounds[i % 2] = n\n return sorted(strange) == sorted(li) # permutation check", - "sols": [ - "def sol(li=[1, 5]):\n s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + "name": "Oscillators:0", + "sat": "def sat(init: List[List[int]], period=3):\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=3):", + "sol_docstring": " \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"", + "sol_bodies": [ + " # # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", + "weight": 1.0 }, { - "name": "HeronTriangle_0", - "sat": "def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[8.9, 10.8, 17.0]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "Oscillators:1", + "sat": "def sat(init: List[List[int]], period=1):\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=1):", + "sol_docstring": " \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"", + "sol_bodies": [ + " # # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", + "weight": 1.0 }, { - "name": "HeronTriangle_1", - "sat": "def sat(coords: List[List[float]], sides=[24.408110376178705, 32.72365349973282, 48.81696744586911]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[24.408110376178705, 32.72365349973282, 48.81696744586911]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "Oscillators:2", + "sat": "def sat(init: List[List[int]], period=2):\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=2):", + "sol_docstring": " \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"", + "sol_bodies": [ + " # # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", + "weight": 1.0 }, { - "name": "HeronTriangle_2", - "sat": "def sat(coords: List[List[float]], sides=[27.451864724831378, 71.73620497337176, 72.2364568008756]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[27.451864724831378, 71.73620497337176, 72.2364568008756]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Oscillators:3", + "sat": "def sat(init: List[List[int]], period=4):\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=4):", + "sol_docstring": " \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", + "weight": 1.0 }, { - "name": "HeronTriangle_3", - "sat": "def sat(coords: List[List[float]], sides=[22.39325953731467, 22.640876224877417, 32.23640648363397]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[22.39325953731467, 22.640876224877417, 32.23640648363397]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "ReverseLifeStep:0", + "sat": "def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[[1, 3], [1, 4], [2, 5]]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 }, { - "name": "HeronTriangle_4", - "sat": "def sat(coords: List[List[float]], sides=[45.986905476840235, 79.97976343909342, 86.26149779271437]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[45.986905476840235, 79.97976343909342, 86.26149779271437]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "ReverseLifeStep:1", + "sat": "def sat(position: List[List[int]], target=[]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 }, { - "name": "HeronTriangle_5", - "sat": "def sat(coords: List[List[float]], sides=[47.58430703197168, 53.39824554295512, 55.14396112642643]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[47.58430703197168, 53.39824554295512, 55.14396112642643]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "ReverseLifeStep:2", + "sat": "def sat(position: List[List[int]], target=[[-1, -4], [-1, -3], [0, -5], [0, -4], [1, -3]]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[[-1, -4], [-1, -3], [0, -5], [0, -4], [1, -3]]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 }, { - "name": "HeronTriangle_6", - "sat": "def sat(coords: List[List[float]], sides=[35.15644335694104, 95.16020924540317, 95.63478613900968]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[35.15644335694104, 95.16020924540317, 95.63478613900968]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "ReverseLifeStep:3", + "sat": "def sat(position: List[List[int]], target=[[3, 3]]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[[3, 3]]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 }, { - "name": "HeronTriangle_7", - "sat": "def sat(coords: List[List[float]], sides=[15.601937582817616, 94.88845582815345, 95.23131597676459]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[15.601937582817616, 94.88845582815345, 95.23131597676459]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + "name": "ReverseLifeStep:4", + "sat": "def sat(position: List[List[int]], target=[[1, -4]]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[[1, -4]]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 }, { - "name": "HeronTriangle_8", - "sat": "def sat(coords: List[List[float]], sides=[20.075279677943957, 70.098045976397, 75.48834201037654]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[20.075279677943957, 70.098045976397, 75.48834201037654]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Spaceship:0", + "sat": "def sat(init: List[List[int]], period=4):\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=4):", + "sol_docstring": " \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", + "weight": 1.0 }, { - "name": "HeronTriangle_9", - "sat": "def sat(coords: List[List[float]], sides=[29.867371594577985, 50.49694745645177, 59.658324661506455]):\n \"\"\"\n Find the coordinates of a triangle with the given side lengths\n \"\"\"\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", - "sols": [ - "def sol(sides=[29.867371594577985, 50.49694745645177, 59.658324661506455]):\n a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Spaceship:1", + "sat": "def sat(init: List[List[int]], period=2):\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=2):", + "sol_docstring": " \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", + "weight": 1.0 }, { - "name": "InvestigateCrash_0", - "sat": "def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[1, 2, 5, 2, 1, 17], max_weight=100):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Spaceship:2", + "sat": "def sat(init: List[List[int]], period=3):\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=3):", + "sol_docstring": " \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", + "weight": 1.0 }, { - "name": "InvestigateCrash_1", - "sat": "def sat(problem: int, weights=[17, 97, 77, 13, 13, 77, 13, 17], max_weight=314):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[17, 97, 77, 13, 13, 77, 13, 17], max_weight=314):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Spaceship:3", + "sat": "def sat(init: List[List[int]], period=5):\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=5):", + "sol_docstring": " \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", + "weight": 1.0 + }, + { + "name": "Nim:0", + "sat": "def sat(moves: List[List[int]], initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 10.0 + }, + { + "name": "Nim:1", + "sat": "def sat(moves: List[List[int]], initial_state=[4, 1, 8, 0, 5, 9, 2, 0]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[4, 1, 8, 0, 5, 9, 2, 0]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 10.0 + }, + { + "name": "Nim:2", + "sat": "def sat(moves: List[List[int]], initial_state=[2, 5, 3, 7, 0]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[2, 5, 3, 7, 0]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 1.0 + }, + { + "name": "Nim:3", + "sat": "def sat(moves: List[List[int]], initial_state=[3, 3, 2, 2, 3, 8]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[3, 3, 2, 2, 3, 8]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 10.0 + }, + { + "name": "Nim:4", + "sat": "def sat(moves: List[List[int]], initial_state=[5, 8, 3, 0]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[5, 8, 3, 0]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 1.0 + }, + { + "name": "Mastermind:0", + "sat": "def sat(transcripts: List[str], max_moves=10):\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", + "ans_type": "List[str]", + "sol_header": "def sol(max_moves=10):", + "sol_docstring": " \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n AABB 11\n ABCD 21\n ABDC\n\n This is the transcript as the game is in progress. The complete transcript might be:\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"", + "sol_bodies": [ + " COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" + ], + "module": "games.py", + "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", + "weight": 10.0 }, { - "name": "InvestigateCrash_2", - "sat": "def sat(problem: int, weights=[51, 23, 10, 4, 7, 56, 12, 4, 10, 23, 51], max_weight=276):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[51, 23, 10, 4, 7, 56, 12, 4, 10, 23, 51], max_weight=276):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "Mastermind:1", + "sat": "def sat(transcripts: List[str], max_moves=8):\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", + "ans_type": "List[str]", + "sol_header": "def sol(max_moves=8):", + "sol_docstring": " \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n AABB 11\n ABCD 21\n ABDC\n\n This is the transcript as the game is in progress. The complete transcript might be:\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"", + "sol_bodies": [ + " COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", + "weight": 14.0 }, { - "name": "InvestigateCrash_3", - "sat": "def sat(problem: int, weights=[22, 81, 93, 22], max_weight=222):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[22, 81, 93, 22], max_weight=222):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "Mastermind:2", + "sat": "def sat(transcripts: List[str], max_moves=6):\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", + "ans_type": "List[str]", + "sol_header": "def sol(max_moves=6):", + "sol_docstring": " \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n AABB 11\n ABCD 21\n ABDC\n\n This is the transcript as the game is in progress. The complete transcript might be:\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"", + "sol_bodies": [ + " COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", + "weight": 18.0 }, { - "name": "InvestigateCrash_4", - "sat": "def sat(problem: int, weights=[43, 37, 79, 37, 20], max_weight=222):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[43, 37, 79, 37, 20], max_weight=222):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "TicTacToeX:0", + "sat": "def sat(good_boards: List[str]):\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if X has a forced tie/win assuming it's X's turn to move.\n x |= 1 << [i for i in range(9) if (x | (1 << i), o) in board_bit_reps][0]\n return not win[o] and (win[x] or all((x | o) & (1 << i) or tie(x, o | (1 << i)) for i in range(9)))\n\n return tie(0, 0)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Compute a strategy for X (first player) in tic-tac-toe that guarantees a tie. That is a strategy for X that,\n no matter what the opponent does, X does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that X aims for, so no matter what O does there\n is always good board that X can get to with a single move.\n \"\"\"", + "sol_bodies": [ + " win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[o]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and o_move(x | (1 << i), o):\n good_boards.append(\"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + (i == j)] for j in range(9)))\n return True\n return False # O wins\n\n def o_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[x] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)):\n return False\n return True # O wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Since we don't have interaction, this problem asks for a full tie-guranteeing strategy.", + "weight": 1.0 }, { - "name": "InvestigateCrash_5", - "sat": "def sat(problem: int, weights=[94, 86, 77, 69, 32, 30, 63, 69, 77, 86, 94], max_weight=795):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[94, 86, 77, 69, 32, 30, 63, 69, 77, 86, 94], max_weight=795):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "TicTacToeO:0", + "sat": "def sat(good_boards: List[str]):\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move.\n if o | x != 511: # complete board\n o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0]\n return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9)))\n\n return all(tie(1 << i, 0) for i in range(9))", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Compute a strategy for O (second player) in tic-tac-toe that guarantees a tie. That is a strategy for O that,\n no matter what the opponent does, O does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that O aims for, so no matter what X does there\n is always good board that O can get to with a single move.\n \"\"\"", + "sol_bodies": [ + " win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if o wins or ties, x's turn to move\n if win[o] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o):\n return False\n return True # O wins/ties\n\n def o_move(x, o): # returns True if o wins or ties, o's turn to move\n if win[x]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and x_move(x, o | (1 << i)):\n good_boards.append(\n \"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + 2 * (i == j)] for j in range(9)))\n return True\n return False # X wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Same as above but for 2nd player", + "weight": 1.0 }, { - "name": "InvestigateCrash_6", - "sat": "def sat(problem: int, weights=[12, 88, 87, 65, 9, 32, 91, 73, 14, 14, 73, 91, 32, 95, 65, 87, 88, 12], max_weight=1047):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[12, 88, 87, 65, 9, 32, 91, 73, 14, 14, 73, 91, 32, 95, 65, 87, 88, 12], max_weight=1047):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "RockPaperScissors:0", + "sat": "def sat(probs: List[float]):\n assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6\n return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find optimal probabilities for playing Rock-Paper-Scissors zero-sum game, with best worst-case guarantee\"\"\"", + "sol_bodies": [ + " return [1 / 3] * 3" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "", + "weight": 1.0 }, { - "name": "InvestigateCrash_7", - "sat": "def sat(problem: int, weights=[87, 44, 26, 75, 15, 72, 88, 5, 88, 72, 90, 75, 26, 44, 87], max_weight=991):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[87, 44, 26, 75, 15, 72, 88, 5, 88, 72, 90, 75, 26, 44, 87], max_weight=991):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "Nash:0", + "sat": "def sat(strategies: List[List[float]], A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 }, { - "name": "InvestigateCrash_8", - "sat": "def sat(problem: int, weights=[37, 73, 80, 14, 91, 14, 80, 60, 37], max_weight=478):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[37, 73, 80, 14, 91, 14, 80, 60, 37], max_weight=478):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "Nash:1", + "sat": "def sat(strategies: List[List[float]], A=[[0.14738177495578275, 0.747980019825271, 0.1051232435961047, 0.46907581621423977, 0.4706551623263341, 0.9062661953318937], [0.12988166612252583, 0.890441435875433, 0.15190125502216845, 0.0251552990265973, 0.32734850066506815, 0.3591430990509836], [0.9425550188084191, 0.08611212072450258, 0.783624348822126, 0.5349936815267257, 0.10270055080436169, 0.009590499808168174], [0.6380601343485022, 0.2218383099094161, 0.6868257338754123, 0.806638752054053, 0.9018561622314694, 0.7590395566591508], [0.6859264269381581, 0.3699302620070518, 0.9942148381089508, 0.8903935289162987, 0.674293629800702, 0.11410994407146158], [0.019262410240239114, 0.35560181353997367, 0.8517917641156626, 0.3074607746901762, 0.9261733304770997, 0.15224796120543604], [0.03366324617275729, 0.8709614609040649, 0.5849217229245649, 0.6379408604095658, 0.07001731910881204, 0.9582581413742493], [0.4142207195937342, 0.3193135769930635, 0.10706268323342383, 0.942046924893307, 0.9143451786836865, 0.701950437311744], [0.5179763142759984, 0.6412718009580387, 0.20022057700520002, 0.5942457297156203, 0.19646377673223914, 0.1351944216925801]], B=[[0.6516235984777713, 0.6123203626800926, 0.6186872023667903, 0.3853596754503974, 0.1073381662525007, 0.1291386906927786], [0.4925608374781314, 0.6308638606801343, 0.9530950453320264, 0.19706903321155278, 0.24184190603658184, 0.5045244344435803], [0.441426258818589, 0.38377342845027484, 0.012225023944992808, 0.891576455082707, 0.7733199528680031, 0.5559723587618317], [0.40823234393591534, 0.3751689897312942, 0.9735593124687937, 0.9428257869910855, 0.8271844491151399, 0.9685273237161491], [0.4832145692461641, 0.5635754453674369, 0.35994676263243286, 0.7815677383683111, 0.9809479850913646, 0.2808093367857648], [0.7473188591890239, 0.12760325771253167, 0.6709148257444112, 0.6960324705687125, 0.9742301280874588, 0.5061403432364218], [0.5512441627071583, 0.24752179828917065, 0.8112753285511846, 0.31333832922799887, 0.6811740304141864, 0.9411639311639899], [0.7477089685706007, 0.2569950106729836, 0.5041394572889569, 0.10948936347507965, 0.6055289733960375, 0.5733220923473799], [0.6810018730369142, 0.7452579755751384, 0.5448601672849144, 0.6414658827186077, 0.8050401801463669, 0.729851403010736]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.14738177495578275, 0.747980019825271, 0.1051232435961047, 0.46907581621423977, 0.4706551623263341, 0.9062661953318937], [0.12988166612252583, 0.890441435875433, 0.15190125502216845, 0.0251552990265973, 0.32734850066506815, 0.3591430990509836], [0.9425550188084191, 0.08611212072450258, 0.783624348822126, 0.5349936815267257, 0.10270055080436169, 0.009590499808168174], [0.6380601343485022, 0.2218383099094161, 0.6868257338754123, 0.806638752054053, 0.9018561622314694, 0.7590395566591508], [0.6859264269381581, 0.3699302620070518, 0.9942148381089508, 0.8903935289162987, 0.674293629800702, 0.11410994407146158], [0.019262410240239114, 0.35560181353997367, 0.8517917641156626, 0.3074607746901762, 0.9261733304770997, 0.15224796120543604], [0.03366324617275729, 0.8709614609040649, 0.5849217229245649, 0.6379408604095658, 0.07001731910881204, 0.9582581413742493], [0.4142207195937342, 0.3193135769930635, 0.10706268323342383, 0.942046924893307, 0.9143451786836865, 0.701950437311744], [0.5179763142759984, 0.6412718009580387, 0.20022057700520002, 0.5942457297156203, 0.19646377673223914, 0.1351944216925801]], B=[[0.6516235984777713, 0.6123203626800926, 0.6186872023667903, 0.3853596754503974, 0.1073381662525007, 0.1291386906927786], [0.4925608374781314, 0.6308638606801343, 0.9530950453320264, 0.19706903321155278, 0.24184190603658184, 0.5045244344435803], [0.441426258818589, 0.38377342845027484, 0.012225023944992808, 0.891576455082707, 0.7733199528680031, 0.5559723587618317], [0.40823234393591534, 0.3751689897312942, 0.9735593124687937, 0.9428257869910855, 0.8271844491151399, 0.9685273237161491], [0.4832145692461641, 0.5635754453674369, 0.35994676263243286, 0.7815677383683111, 0.9809479850913646, 0.2808093367857648], [0.7473188591890239, 0.12760325771253167, 0.6709148257444112, 0.6960324705687125, 0.9742301280874588, 0.5061403432364218], [0.5512441627071583, 0.24752179828917065, 0.8112753285511846, 0.31333832922799887, 0.6811740304141864, 0.9411639311639899], [0.7477089685706007, 0.2569950106729836, 0.5041394572889569, 0.10948936347507965, 0.6055289733960375, 0.5733220923473799], [0.6810018730369142, 0.7452579755751384, 0.5448601672849144, 0.6414658827186077, 0.8050401801463669, 0.729851403010736]], eps=0.1):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 }, { - "name": "InvestigateCrash_9", - "sat": "def sat(problem: int, weights=[10, 7, 2, 30, 6, 41, 43, 14, 81, 41, 6, 30, 2, 7, 10], max_weight=393):\n \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n \"\"\"\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", - "sols": [ - "def sol(weights=[10, 7, 2, 30, 6, 41, 43, 14, 81, 41, 6, 30, 2, 7, 10], max_weight=393):\n if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + "name": "Nash:2", + "sat": "def sat(strategies: List[List[float]], A=[[0.4934719584926307, 0.05664225783974475, 0.4878391988801185, 0.6983347656105304, 0.7903235569844771], [0.9209179850842271, 0.6945169729870889, 0.985586605726519, 0.03611807745215567, 0.07791862369265457]], B=[[0.5723776540419043, 0.3177494964308457, 0.03283373751184504, 0.960932861317398, 0.3843454398162133], [0.7415658068058613, 0.4423455643375954, 0.9314198922910875, 0.937956471095574, 0.6337568371723998]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.4934719584926307, 0.05664225783974475, 0.4878391988801185, 0.6983347656105304, 0.7903235569844771], [0.9209179850842271, 0.6945169729870889, 0.985586605726519, 0.03611807745215567, 0.07791862369265457]], B=[[0.5723776540419043, 0.3177494964308457, 0.03283373751184504, 0.960932861317398, 0.3843454398162133], [0.7415658068058613, 0.4423455643375954, 0.9314198922910875, 0.937956471095574, 0.6337568371723998]], eps=0.01):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 }, { - "name": "ClosestPalindrome_0", - "sat": "def sat(pal: str, s=\"palindromordinals\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"palindromordinals\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "Nash:3", + "sat": "def sat(strategies: List[List[float]], A=[[0.8589758630993106, 0.7749919744562254, 0.18371378758390233, 0.28034839679007295, 0.18276337511723684, 0.5173168267432149], [0.535972149604936, 0.6860082336427572, 0.8154412069051551, 0.02442129105356694, 0.1349312146704914, 0.7530215223132398], [0.3519956107153608, 0.9660103168436817, 0.10172694662400983, 0.7254690944575098, 0.8254057287673647, 0.3189629245726713], [0.5725690579346981, 0.1589108703965545, 0.01688986355891453, 0.3074319760280675, 0.4584643560452394, 0.5853201363256517], [0.6489314270374363, 0.6347169492821729, 0.18348768635443546, 0.5731694328630751, 0.6566567470060826, 0.8039403838540958], [0.4917243999522437, 0.16144631954506772, 0.04044367374900226, 0.09502214062659131, 0.8738947440998662, 0.6114058437094053], [0.1967023709822303, 0.29782628261932154, 0.058285139123036234, 0.6302740689117773, 0.33364400882000855, 0.5776389301631869], [0.6777544316258026, 0.6724283041374894, 0.9798391425483743, 0.8838381708326536, 0.6667218181098736, 0.34481925547433623], [0.5958711406283824, 0.44387553450142214, 0.6668717494447683, 0.25986773196752133, 0.8873567554013287, 0.4374385442834563]], B=[[0.6509157248335261, 0.47969567636489663, 0.7175654058769987, 0.8305604678011964, 0.11420347930129515, 0.8401333925076142], [0.8690852438876666, 0.8127345690587251, 0.316832083958, 0.9589533790230425, 0.6983255500551921, 0.4492765771156503], [0.7058401433380928, 0.007340378623609478, 0.5423001137088079, 0.2066909384280825, 0.3317417420195775, 0.003203599551001912], [0.4887994419103735, 0.4082867953539032, 0.3605910405209234, 0.19354666101193807, 0.3116629413961449, 0.9698417812464528], [0.30623970889248353, 0.8377553335650854, 0.7624220111189529, 0.22826919233755616, 0.3832245488487954, 0.11387974071378948], [0.8818032772640031, 0.24028195971823052, 0.8834992573768841, 0.9883007945834051, 0.7024933884432355, 0.7617988546407181], [0.9160905473729156, 0.6927856066612084, 0.6159687601776853, 0.15074396336216966, 0.7764252875888226, 0.3459191304782905], [0.9991431698755587, 0.32389039099370287, 0.8354695347283115, 0.51319161530113, 0.5229921145906276, 0.7690459477032934], [0.7591967670432632, 0.23382636010443625, 0.26521035423368, 0.8577953561722641, 0.020432130142500116, 0.019755815416500178]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.8589758630993106, 0.7749919744562254, 0.18371378758390233, 0.28034839679007295, 0.18276337511723684, 0.5173168267432149], [0.535972149604936, 0.6860082336427572, 0.8154412069051551, 0.02442129105356694, 0.1349312146704914, 0.7530215223132398], [0.3519956107153608, 0.9660103168436817, 0.10172694662400983, 0.7254690944575098, 0.8254057287673647, 0.3189629245726713], [0.5725690579346981, 0.1589108703965545, 0.01688986355891453, 0.3074319760280675, 0.4584643560452394, 0.5853201363256517], [0.6489314270374363, 0.6347169492821729, 0.18348768635443546, 0.5731694328630751, 0.6566567470060826, 0.8039403838540958], [0.4917243999522437, 0.16144631954506772, 0.04044367374900226, 0.09502214062659131, 0.8738947440998662, 0.6114058437094053], [0.1967023709822303, 0.29782628261932154, 0.058285139123036234, 0.6302740689117773, 0.33364400882000855, 0.5776389301631869], [0.6777544316258026, 0.6724283041374894, 0.9798391425483743, 0.8838381708326536, 0.6667218181098736, 0.34481925547433623], [0.5958711406283824, 0.44387553450142214, 0.6668717494447683, 0.25986773196752133, 0.8873567554013287, 0.4374385442834563]], B=[[0.6509157248335261, 0.47969567636489663, 0.7175654058769987, 0.8305604678011964, 0.11420347930129515, 0.8401333925076142], [0.8690852438876666, 0.8127345690587251, 0.316832083958, 0.9589533790230425, 0.6983255500551921, 0.4492765771156503], [0.7058401433380928, 0.007340378623609478, 0.5423001137088079, 0.2066909384280825, 0.3317417420195775, 0.003203599551001912], [0.4887994419103735, 0.4082867953539032, 0.3605910405209234, 0.19354666101193807, 0.3116629413961449, 0.9698417812464528], [0.30623970889248353, 0.8377553335650854, 0.7624220111189529, 0.22826919233755616, 0.3832245488487954, 0.11387974071378948], [0.8818032772640031, 0.24028195971823052, 0.8834992573768841, 0.9883007945834051, 0.7024933884432355, 0.7617988546407181], [0.9160905473729156, 0.6927856066612084, 0.6159687601776853, 0.15074396336216966, 0.7764252875888226, 0.3459191304782905], [0.9991431698755587, 0.32389039099370287, 0.8354695347283115, 0.51319161530113, 0.5229921145906276, 0.7690459477032934], [0.7591967670432632, 0.23382636010443625, 0.26521035423368, 0.8577953561722641, 0.020432130142500116, 0.019755815416500178]], eps=0.1):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 }, { - "name": "ClosestPalindrome_1", - "sat": "def sat(pal: str, s=\"ti=\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"ti=\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "Nash:4", + "sat": "def sat(strategies: List[List[float]], A=[[0.5753373910044396, 0.883286704506171, 0.14098419242590676, 0.0796482735170555, 0.28053511699815137, 0.4802587237433614, 0.7927565741942321, 0.10486790699611082], [0.674897469149739, 0.5526354958094333, 0.14126552040252316, 0.8176885681560745, 0.5950057513195114, 0.9394498004514682, 0.9974412293717752, 0.31785998202168364], [0.8551492483900579, 0.0873581901597057, 0.7058504781434135, 0.8614481823894408, 0.774002479389802, 0.5194163269795865, 0.8839947283493329, 0.4796849532033839], [0.24669121918914239, 0.9192009909426845, 0.22533689422848313, 0.42231986064003346, 0.8524917527913644, 0.3217815290765713, 0.13012568628724053, 0.08517580086974996], [0.6708003793106111, 0.9370021425919828, 0.956981559137809, 0.48294825852969425, 0.09451427192867867, 0.958711015678715, 0.13874285709747414, 0.17240487357189138], [0.6862479923713413, 0.40988185301904767, 0.7232258320050972, 0.12156129874113497, 0.4137204968814412, 0.43096712555208105, 0.9673727161037606, 0.9554536674896775], [0.2645245766573283, 0.16353379162998616, 0.8208329137057697, 0.24945486012929086, 0.19060921538692044, 0.6886849242360286, 0.6513544853108113, 0.13898253443118158], [0.8399423196728664, 0.5583901386668076, 0.05055384968867316, 0.272512815876485, 0.4706764309925491, 0.9920874820129374, 0.11006687231735834, 0.6003338823254668]], B=[[0.8661101149166154, 0.5041424261188884, 0.654530488206357, 0.842287965510257, 0.5418722524658692, 0.615317049155107, 0.2474305118268787, 0.802249852604974], [0.17399126319302805, 0.37286827574250436, 0.9025123265462714, 0.6302774019777034, 0.6096954531215514, 0.14282756248667317, 0.5039665393854678, 0.5053857713064859], [0.08645764165911696, 0.34639849481946294, 0.4003286765389642, 0.8522825407634552, 0.38924375107949505, 0.13708630962779877, 0.09413370097193263, 0.024977157717289145], [0.18665183173707744, 0.08210966062569414, 0.8906028770829486, 0.9292380534706237, 0.3432700204525524, 0.03791015448620483, 0.23701146631134296, 0.5236370615896554], [0.4158240648499627, 0.620309795706114, 0.6606023798050246, 0.7581954943445194, 0.9399309644265448, 0.6640739757418763, 0.5470483802958659, 0.3881528058493644], [0.8452380694038372, 0.7687623496765781, 0.22422282300746144, 0.03236167241305821, 0.1113965246318579, 0.4589759506900418, 0.8415359432321317, 0.27521377409486303], [0.6582156349227984, 0.9988816473957544, 0.4901663751981855, 0.3788210957458895, 0.455713995042737, 0.04960398762882756, 0.16850674065572013, 0.6202540021741917], [0.7515673992699056, 0.6867547828670959, 0.038529441293790434, 0.9995963277046196, 0.15577904716257307, 0.2596640500026437, 0.76139213514593, 0.5065163836406463]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.5753373910044396, 0.883286704506171, 0.14098419242590676, 0.0796482735170555, 0.28053511699815137, 0.4802587237433614, 0.7927565741942321, 0.10486790699611082], [0.674897469149739, 0.5526354958094333, 0.14126552040252316, 0.8176885681560745, 0.5950057513195114, 0.9394498004514682, 0.9974412293717752, 0.31785998202168364], [0.8551492483900579, 0.0873581901597057, 0.7058504781434135, 0.8614481823894408, 0.774002479389802, 0.5194163269795865, 0.8839947283493329, 0.4796849532033839], [0.24669121918914239, 0.9192009909426845, 0.22533689422848313, 0.42231986064003346, 0.8524917527913644, 0.3217815290765713, 0.13012568628724053, 0.08517580086974996], [0.6708003793106111, 0.9370021425919828, 0.956981559137809, 0.48294825852969425, 0.09451427192867867, 0.958711015678715, 0.13874285709747414, 0.17240487357189138], [0.6862479923713413, 0.40988185301904767, 0.7232258320050972, 0.12156129874113497, 0.4137204968814412, 0.43096712555208105, 0.9673727161037606, 0.9554536674896775], [0.2645245766573283, 0.16353379162998616, 0.8208329137057697, 0.24945486012929086, 0.19060921538692044, 0.6886849242360286, 0.6513544853108113, 0.13898253443118158], [0.8399423196728664, 0.5583901386668076, 0.05055384968867316, 0.272512815876485, 0.4706764309925491, 0.9920874820129374, 0.11006687231735834, 0.6003338823254668]], B=[[0.8661101149166154, 0.5041424261188884, 0.654530488206357, 0.842287965510257, 0.5418722524658692, 0.615317049155107, 0.2474305118268787, 0.802249852604974], [0.17399126319302805, 0.37286827574250436, 0.9025123265462714, 0.6302774019777034, 0.6096954531215514, 0.14282756248667317, 0.5039665393854678, 0.5053857713064859], [0.08645764165911696, 0.34639849481946294, 0.4003286765389642, 0.8522825407634552, 0.38924375107949505, 0.13708630962779877, 0.09413370097193263, 0.024977157717289145], [0.18665183173707744, 0.08210966062569414, 0.8906028770829486, 0.9292380534706237, 0.3432700204525524, 0.03791015448620483, 0.23701146631134296, 0.5236370615896554], [0.4158240648499627, 0.620309795706114, 0.6606023798050246, 0.7581954943445194, 0.9399309644265448, 0.6640739757418763, 0.5470483802958659, 0.3881528058493644], [0.8452380694038372, 0.7687623496765781, 0.22422282300746144, 0.03236167241305821, 0.1113965246318579, 0.4589759506900418, 0.8415359432321317, 0.27521377409486303], [0.6582156349227984, 0.9988816473957544, 0.4901663751981855, 0.3788210957458895, 0.455713995042737, 0.04960398762882756, 0.16850674065572013, 0.6202540021741917], [0.7515673992699056, 0.6867547828670959, 0.038529441293790434, 0.9995963277046196, 0.15577904716257307, 0.2596640500026437, 0.76139213514593, 0.5065163836406463]], eps=0.01):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 }, { - "name": "ClosestPalindrome_2", - "sat": "def sat(pal: str, s=\"bC\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"bC\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "ZeroSum:0", + "sat": "def sat(strategies: List[List[float]], A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_3", - "sat": "def sat(pal: str, s=\"chachatexc0vchX)e1\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"chachatexc0vchX)e1\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "ZeroSum:1", + "sat": "def sat(strategies: List[List[float]], A=[[0.5303369225581901, 0.4458248560112187, 0.47857713121903245], [0.07696760921779966, 0.40492093882513336, 0.8351857615090292]], eps=0.5):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.5303369225581901, 0.4458248560112187, 0.47857713121903245], [0.07696760921779966, 0.40492093882513336, 0.8351857615090292]], eps=0.5):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_4", - "sat": "def sat(pal: str, s=\"w\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"w\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "ZeroSum:2", + "sat": "def sat(strategies: List[List[float]], A=[[0.8737161029595927, 0.3380931327691771, 0.20525289813478453, 0.9772812942597162, 0.6011469499669913, 0.5657635078441663, 0.007362594660960342, 0.5523386597843655, 0.06548815570594102], [0.8440989957774637, 0.11456946368545384, 0.6266416865322296, 0.6112942108318355, 0.15090892170912606, 0.19181369635746925, 0.23558304486799253, 0.08883158381322309, 0.5626427070785186], [0.5990766112287766, 0.16770300013300976, 0.7790082288508813, 0.8213933806929374, 0.8409107317631046, 0.32215242243482034, 0.04927911582647726, 0.18589922022642869, 0.4416673076660764]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.8737161029595927, 0.3380931327691771, 0.20525289813478453, 0.9772812942597162, 0.6011469499669913, 0.5657635078441663, 0.007362594660960342, 0.5523386597843655, 0.06548815570594102], [0.8440989957774637, 0.11456946368545384, 0.6266416865322296, 0.6112942108318355, 0.15090892170912606, 0.19181369635746925, 0.23558304486799253, 0.08883158381322309, 0.5626427070785186], [0.5990766112287766, 0.16770300013300976, 0.7790082288508813, 0.8213933806929374, 0.8409107317631046, 0.32215242243482034, 0.04927911582647726, 0.18589922022642869, 0.4416673076660764]], eps=0.1):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_5", - "sat": "def sat(pal: str, s=\"thejth(\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"thejth(\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "ZeroSum:3", + "sat": "def sat(strategies: List[List[float]], A=[[0.35120738216503444, 0.6305426964442432, 0.09361690123750299, 0.17215263015782456, 0.3569473010721259], [0.9341169088059124, 0.43769720086284414, 0.35911118735479475, 0.37956863261812823, 0.9170151449695092]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.35120738216503444, 0.6305426964442432, 0.09361690123750299, 0.17215263015782456, 0.3569473010721259], [0.9341169088059124, 0.43769720086284414, 0.35911118735479475, 0.37956863261812823, 0.9170151449695092]], eps=0.1):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_6", - "sat": "def sat(pal: str, s=\"withyfymPithlfy\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"withyfymPithlfy\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "ZeroSum:4", + "sat": "def sat(strategies: List[List[float]], A=[[0.6637255179009651, 0.9756262037263238, 0.4926064602986052, 0.4097654368373934, 0.9284930704872523], [0.21641001481296873, 0.3381822244340763, 0.10113277325663139, 0.867285215856176, 0.27100572371021947], [0.7831143244052009, 0.6045743236145783, 0.10582868480749341, 0.5591604978434377, 0.27602687543748194], [0.8431935916393734, 0.09227518008541435, 0.06352450108543961, 0.13377427705288458, 0.8928593671227156], [0.15573895145866545, 0.3897235344943152, 0.5095156356106815, 0.25893802778092634, 0.4730747656010391]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.6637255179009651, 0.9756262037263238, 0.4926064602986052, 0.4097654368373934, 0.9284930704872523], [0.21641001481296873, 0.3381822244340763, 0.10113277325663139, 0.867285215856176, 0.27100572371021947], [0.7831143244052009, 0.6045743236145783, 0.10582868480749341, 0.5591604978434377, 0.27602687543748194], [0.8431935916393734, 0.09227518008541435, 0.06352450108543961, 0.13377427705288458, 0.8928593671227156], [0.15573895145866545, 0.3897235344943152, 0.5095156356106815, 0.25893802778092634, 0.4730747656010391]], eps=0.1):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_7", - "sat": "def sat(pal: str, s=\"caxuvut7ixuvhd\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"caxuvut7ixuvhd\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "Conway99:0", + "sat": "def sat(edges: List[List[int]]):\n # first compute neighbors sets, N:\n N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)}\n return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i))", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common\n neighbor, and in which each two non-adjacent vertices have exactly two common neighbors.\n \"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "Conway's 99-graph problem (*unsolved*, open problem)\n\nConway's 99-graph problem is an unsolved problem in graph theory.\nIn Conway's terminology, from [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf)\n\"Is there a graph with 99 vertices in which every edge (i.e. pair of joined vertices) belongs to a unique\ntriangle and every nonedge (pair of unjoined vertices) to a unique quadrilateral?\"\n\nSee also this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem).", + "weight": 1.0 }, { - "name": "ClosestPalindrome_8", - "sat": "def sat(pal: str, s=\"ditexta#iE&St\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"ditexta#iE&St\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "AnyEdge:0", + "sat": "def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 }, { - "name": "ClosestPalindrome_9", - "sat": "def sat(pal: str, s=\"tht\"):\n \"\"\"\n Find the closest palindrome\n \"\"\"\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", - "sols": [ - "def sol(s=\"tht\"):\n n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + "name": "AnyEdge:1", + "sat": "def sat(e: List[int], edges=[[0, 1], [1, 1], [0, 0]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [1, 1], [0, 0]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 }, { - "name": "NarrowerList_0", - "sat": "def sat(li: List[str], lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyEdge:2", + "sat": "def sat(e: List[int], edges=[[1, 0], [0, 1], [1, 1]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[1, 0], [0, 1], [1, 1]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 }, { - "name": "NarrowerList_1", - "sat": "def sat(li: List[str], lists=[['gefypo', 'gomecythib'], ['vicowodasyhifeme', 'mojowu', 'poxuchuchacyweth']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['gefypo', 'gomecythib'], ['vicowodasyhifeme', 'mojowu', 'poxuchuchacyweth']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyEdge:3", + "sat": "def sat(e: List[int], edges=[[1, 15], [15, 3], [5, 12], [11, 0], [8, 5], [1, 9], [3, 6], [5, 10], [12, 0], [6, 6], [9, 2], [13, 15], [2, 9], [5, 1], [10, 11], [4, 12], [0, 6], [8, 12], [15, 14], [1, 13], [11, 7], [15, 4], [13, 5], [7, 14], [14, 5], [12, 2], [7, 8], [2, 14], [3, 15], [2, 2], [7, 2], [3, 4], [4, 2], [1, 3], [4, 4], [3, 11], [14, 6], [14, 8], [14, 12], [7, 15], [7, 3], [7, 10], [10, 8], [7, 13], [2, 15], [14, 0], [1, 5], [11, 15], [1, 8], [6, 4], [15, 8], [9, 3], [1, 10], [2, 3], [4, 13], [7, 5], [2, 11], [0, 1], [15, 6], [0, 2], [5, 5]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[1, 15], [15, 3], [5, 12], [11, 0], [8, 5], [1, 9], [3, 6], [5, 10], [12, 0], [6, 6], [9, 2], [13, 15], [2, 9], [5, 1], [10, 11], [4, 12], [0, 6], [8, 12], [15, 14], [1, 13], [11, 7], [15, 4], [13, 5], [7, 14], [14, 5], [12, 2], [7, 8], [2, 14], [3, 15], [2, 2], [7, 2], [3, 4], [4, 2], [1, 3], [4, 4], [3, 11], [14, 6], [14, 8], [14, 12], [7, 15], [7, 3], [7, 10], [10, 8], [7, 13], [2, 15], [14, 0], [1, 5], [11, 15], [1, 8], [6, 4], [15, 8], [9, 3], [1, 10], [2, 3], [4, 13], [7, 5], [2, 11], [0, 1], [15, 6], [0, 2], [5, 5]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 }, { - "name": "NarrowerList_2", - "sat": "def sat(li: List[str], lists=[['cil', 'vesic', 'gaquedane'], ['machetyt', 'pumepywotatofo'], ['zatex', 'gilygyxejimagiquav']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['cil', 'vesic', 'gaquedane'], ['machetyt', 'pumepywotatofo'], ['zatex', 'gilygyxejimagiquav']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyEdge:4", + "sat": "def sat(e: List[int], edges=[[7, 84], [72, 0], [65, 93], [66, 13], [39, 15], [91, 6], [16, 77], [43, 71], [34, 72], [83, 1], [91, 93], [41, 20], [71, 69], [51, 60], [75, 22], [25, 82], [93, 45], [54, 31], [38, 22], [76, 33], [18, 81], [91, 74], [28, 97], [39, 69], [15, 26], [83, 75], [57, 24], [94, 38], [26, 23], [40, 48], [37, 20], [90, 84], [75, 8], [36, 21], [93, 11], [97, 74], [79, 74], [69, 36], [3, 29], [66, 82], [49, 15], [52, 43], [76, 25], [39, 11], [9, 93], [68, 55], [53, 46], [29, 90], [12, 81], [44, 66], [54, 55], [2, 30], [1, 6], [8, 61], [67, 10], [61, 84], [72, 51], [13, 27], [93, 53], [44, 38], [86, 14], [90, 8], [22, 62], [5, 72], [63, 36], [31, 51], [83, 5], [36, 53], [92, 78], [44, 80], [23, 16], [43, 16], [18, 37], [34, 14], [23, 6], [19, 61], [59, 10], [85, 30], [25, 80], [76, 39], [21, 28], [60, 47], [15, 43], [26, 80], [59, 19], [83, 81], [4, 64], [3, 71], [52, 34], [90, 14], [44, 84], [37, 56], [76, 10], [69, 89], [30, 38], [17, 38], [42, 7], [79, 62], [15, 87], [45, 4], [96, 0], [44, 43], [84, 42], [26, 22], [1, 91], [1, 11], [68, 7], [72, 32], [8, 0], [64, 59], [16, 86], [25, 46], [65, 30], [10, 43], [89, 43], [55, 0], [91, 66], [49, 0], [22, 77], [80, 21], [16, 58], [55, 45], [64, 13], [55, 56], [89, 96], [84, 20], [11, 74], [92, 91], [36, 15], [51, 8], [4, 44], [55, 55], [6, 83], [76, 5], [3, 11], [15, 96], [18, 15], [43, 58], [19, 70], [87, 41], [43, 47], [2, 51], [47, 32], [14, 93], [27, 61], [21, 26], [78, 88], [52, 40], [21, 79], [12, 8], [74, 73], [5, 22], [50, 4], [15, 67], [87, 10], [90, 24], [17, 45], [75, 96], [27, 81], [76, 29], [52, 93], [74, 40], [48, 62], [5, 75], [68, 58], [61, 19], [56, 54], [4, 29], [26, 60], [24, 1], [37, 41], [95, 63], [49, 37], [81, 18], [79, 91], [82, 8], [29, 73], [55, 84], [18, 13], [32, 7], [77, 63], [26, 72], [90, 5], [95, 4], [46, 13], [0, 64], [84, 34], [52, 51], [32, 30], [24, 55], [51, 17], [12, 7], [73, 34], [54, 47], [96, 95], [65, 67], [46, 90], [58, 17], [54, 2], [45, 10], [84, 45], [46, 6], [0, 4], [16, 60], [50, 35], [86, 45], [89, 19], [48, 10], [4, 57], [43, 62], [19, 30], [2, 35], [83, 68], [36, 26], [69, 4], [41, 82], [12, 52], [77, 95], [90, 75], [78, 58], [93, 29], [38, 87], [15, 82], [42, 86], [39, 90], [20, 53], [79, 25], [68, 81], [64, 82], [45, 56], [14, 85], [97, 13], [46, 15], [46, 43], [8, 71], [90, 72], [97, 66], [80, 57], [25, 8], [90, 74]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[7, 84], [72, 0], [65, 93], [66, 13], [39, 15], [91, 6], [16, 77], [43, 71], [34, 72], [83, 1], [91, 93], [41, 20], [71, 69], [51, 60], [75, 22], [25, 82], [93, 45], [54, 31], [38, 22], [76, 33], [18, 81], [91, 74], [28, 97], [39, 69], [15, 26], [83, 75], [57, 24], [94, 38], [26, 23], [40, 48], [37, 20], [90, 84], [75, 8], [36, 21], [93, 11], [97, 74], [79, 74], [69, 36], [3, 29], [66, 82], [49, 15], [52, 43], [76, 25], [39, 11], [9, 93], [68, 55], [53, 46], [29, 90], [12, 81], [44, 66], [54, 55], [2, 30], [1, 6], [8, 61], [67, 10], [61, 84], [72, 51], [13, 27], [93, 53], [44, 38], [86, 14], [90, 8], [22, 62], [5, 72], [63, 36], [31, 51], [83, 5], [36, 53], [92, 78], [44, 80], [23, 16], [43, 16], [18, 37], [34, 14], [23, 6], [19, 61], [59, 10], [85, 30], [25, 80], [76, 39], [21, 28], [60, 47], [15, 43], [26, 80], [59, 19], [83, 81], [4, 64], [3, 71], [52, 34], [90, 14], [44, 84], [37, 56], [76, 10], [69, 89], [30, 38], [17, 38], [42, 7], [79, 62], [15, 87], [45, 4], [96, 0], [44, 43], [84, 42], [26, 22], [1, 91], [1, 11], [68, 7], [72, 32], [8, 0], [64, 59], [16, 86], [25, 46], [65, 30], [10, 43], [89, 43], [55, 0], [91, 66], [49, 0], [22, 77], [80, 21], [16, 58], [55, 45], [64, 13], [55, 56], [89, 96], [84, 20], [11, 74], [92, 91], [36, 15], [51, 8], [4, 44], [55, 55], [6, 83], [76, 5], [3, 11], [15, 96], [18, 15], [43, 58], [19, 70], [87, 41], [43, 47], [2, 51], [47, 32], [14, 93], [27, 61], [21, 26], [78, 88], [52, 40], [21, 79], [12, 8], [74, 73], [5, 22], [50, 4], [15, 67], [87, 10], [90, 24], [17, 45], [75, 96], [27, 81], [76, 29], [52, 93], [74, 40], [48, 62], [5, 75], [68, 58], [61, 19], [56, 54], [4, 29], [26, 60], [24, 1], [37, 41], [95, 63], [49, 37], [81, 18], [79, 91], [82, 8], [29, 73], [55, 84], [18, 13], [32, 7], [77, 63], [26, 72], [90, 5], [95, 4], [46, 13], [0, 64], [84, 34], [52, 51], [32, 30], [24, 55], [51, 17], [12, 7], [73, 34], [54, 47], [96, 95], [65, 67], [46, 90], [58, 17], [54, 2], [45, 10], [84, 45], [46, 6], [0, 4], [16, 60], [50, 35], [86, 45], [89, 19], [48, 10], [4, 57], [43, 62], [19, 30], [2, 35], [83, 68], [36, 26], [69, 4], [41, 82], [12, 52], [77, 95], [90, 75], [78, 58], [93, 29], [38, 87], [15, 82], [42, 86], [39, 90], [20, 53], [79, 25], [68, 81], [64, 82], [45, 56], [14, 85], [97, 13], [46, 15], [46, 43], [8, 71], [90, 72], [97, 66], [80, 57], [25, 8], [90, 74]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 }, { - "name": "NarrowerList_3", - "sat": "def sat(li: List[str], lists=[['hubibexuratezixekyl', 'todot'], ['mochokyhyzylethy', 'we'], ['sygymithajyhu', 'byziruchocetextyram', 'thizupesakocami']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['hubibexuratezixekyl', 'todot'], ['mochokyhyzylethy', 'we'], ['sygymithajyhu', 'byziruchocetextyram', 'thizupesakocami']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyTriangle:0", + "sat": "def sat(tri: List[int], edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 }, { - "name": "NarrowerList_4", - "sat": "def sat(li: List[str], lists=[['r', 'datucykokegyquazyta', 'gytextevavasochub'], ['faryjav', 'textebyquyho']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['r', 'datucykokegyquazyta', 'gytextevavasochub'], ['faryjav', 'textebyquyho']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyTriangle:1", + "sat": "def sat(tri: List[int], edges=[[19, 48], [14, 42], [19, 14], [56, 3], [37, 16], [46, 5], [14, 14], [62, 40], [12, 41], [37, 1], [46, 40], [4, 9], [70, 39], [75, 49], [61, 55], [65, 61], [5, 1], [67, 44], [46, 68], [49, 62], [41, 61], [39, 43], [44, 60], [71, 40], [8, 42], [54, 67], [33, 27], [25, 70], [50, 3], [53, 22], [61, 34], [5, 16], [39, 62], [30, 44], [10, 3], [21, 67], [41, 54], [10, 66], [34, 1], [45, 44], [38, 47], [25, 36], [2, 47], [46, 2], [38, 4], [50, 66], [45, 18], [45, 50], [63, 57], [19, 43], [39, 66], [29, 13], [39, 65], [63, 39], [7, 25], [34, 51], [65, 54], [13, 64], [9, 70], [28, 12], [41, 69], [67, 53], [33, 38], [59, 27], [18, 37], [11, 3], [13, 23], [33, 50], [44, 49], [9, 50], [23, 55], [59, 66], [4, 74], [50, 12], [14, 24], [0, 28], [75, 29], [62, 60], [68, 35], [69, 55], [3, 19], [72, 30], [25, 9], [12, 58], [3, 66], [43, 8], [12, 11], [15, 56], [30, 75], [35, 57], [19, 20], [71, 36], [34, 35], [30, 17], [7, 52], [49, 31], [39, 58], [48, 32], [4, 57], [75, 31], [42, 1], [0, 48], [22, 13], [18, 17], [71, 52], [41, 19], [48, 12], [9, 48], [63, 65], [68, 63], [46, 39], [24, 30], [46, 61], [55, 25], [75, 36], [49, 5], [44, 12], [29, 5], [64, 69], [15, 64], [8, 66], [49, 25], [24, 53], [7, 39], [41, 2], [29, 48], [51, 30], [41, 21], [46, 30], [63, 75], [19, 3], [58, 72], [62, 59], [68, 54], [9, 61], [70, 74], [56, 48], [74, 48], [2, 9], [51, 22], [69, 61], [0, 35], [28, 46], [7, 11], [56, 57], [14, 67], [15, 4], [53, 12], [64, 42], [20, 15], [52, 53], [44, 16], [8, 7], [21, 7], [42, 45], [4, 66], [39, 59], [20, 1], [60, 0], [52, 28], [75, 63], [59, 14], [40, 69], [74, 46], [60, 67], [6, 57], [38, 68], [24, 22], [59, 61], [53, 30], [10, 56], [49, 59], [12, 27], [75, 22], [24, 25], [37, 11], [56, 12], [62, 47], [22, 9], [34, 17], [57, 10], [52, 43], [17, 22], [14, 73], [54, 75], [28, 22], [18, 51], [38, 46], [6, 22], [75, 15], [10, 1], [37, 12], [67, 34], [28, 43], [5, 2], [60, 40], [9, 22], [3, 75], [50, 1], [19, 8], [17, 57], [43, 60], [45, 60], [57, 32], [52, 35], [18, 22], [11, 38], [16, 57], [31, 39], [13, 18], [61, 54], [25, 10], [23, 46], [47, 5], [42, 66], [73, 67], [44, 28], [65, 34], [35, 50], [67, 1], [12, 44], [17, 51], [70, 23], [44, 35], [0, 16], [65, 53], [10, 74], [5, 60], [45, 8], [13, 46], [57, 6], [72, 47], [1, 36], [60, 4], [11, 31], [46, 21], [60, 29], [58, 44], [53, 41], [33, 44], [47, 34], [58, 35], [74, 51], [71, 35], [58, 10], [47, 59], [32, 36], [16, 67], [62, 9], [14, 44], [12, 32], [6, 19], [35, 21], [49, 71], [7, 7], [25, 39], [25, 24], [45, 40], [44, 20], [9, 37], [58, 18], [59, 52], [12, 23], [26, 49], [62, 69], [8, 2], [66, 52], [25, 42], [34, 70], [64, 1], [29, 57], [8, 26], [25, 63], [75, 56], [51, 49], [70, 9], [63, 51], [6, 28], [1, 38], [47, 27], [74, 26], [27, 63], [20, 47], [25, 37], [31, 67], [59, 71], [56, 32], [28, 65], [37, 10], [30, 50], [42, 32], [56, 63], [32, 65], [48, 70], [37, 21], [10, 11], [5, 24], [51, 8], [46, 6], [75, 23], [42, 28], [60, 26], [37, 9], [0, 19], [11, 34], [66, 51], [49, 42], [16, 37], [52, 55], [20, 39], [46, 12], [1, 70], [45, 37], [18, 63], [63, 23], [54, 7], [18, 11], [51, 28], [21, 65], [28, 71], [46, 53], [14, 36], [35, 71], [30, 5], [50, 62], [32, 28], [64, 38], [66, 61], [0, 10]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[19, 48], [14, 42], [19, 14], [56, 3], [37, 16], [46, 5], [14, 14], [62, 40], [12, 41], [37, 1], [46, 40], [4, 9], [70, 39], [75, 49], [61, 55], [65, 61], [5, 1], [67, 44], [46, 68], [49, 62], [41, 61], [39, 43], [44, 60], [71, 40], [8, 42], [54, 67], [33, 27], [25, 70], [50, 3], [53, 22], [61, 34], [5, 16], [39, 62], [30, 44], [10, 3], [21, 67], [41, 54], [10, 66], [34, 1], [45, 44], [38, 47], [25, 36], [2, 47], [46, 2], [38, 4], [50, 66], [45, 18], [45, 50], [63, 57], [19, 43], [39, 66], [29, 13], [39, 65], [63, 39], [7, 25], [34, 51], [65, 54], [13, 64], [9, 70], [28, 12], [41, 69], [67, 53], [33, 38], [59, 27], [18, 37], [11, 3], [13, 23], [33, 50], [44, 49], [9, 50], [23, 55], [59, 66], [4, 74], [50, 12], [14, 24], [0, 28], [75, 29], [62, 60], [68, 35], [69, 55], [3, 19], [72, 30], [25, 9], [12, 58], [3, 66], [43, 8], [12, 11], [15, 56], [30, 75], [35, 57], [19, 20], [71, 36], [34, 35], [30, 17], [7, 52], [49, 31], [39, 58], [48, 32], [4, 57], [75, 31], [42, 1], [0, 48], [22, 13], [18, 17], [71, 52], [41, 19], [48, 12], [9, 48], [63, 65], [68, 63], [46, 39], [24, 30], [46, 61], [55, 25], [75, 36], [49, 5], [44, 12], [29, 5], [64, 69], [15, 64], [8, 66], [49, 25], [24, 53], [7, 39], [41, 2], [29, 48], [51, 30], [41, 21], [46, 30], [63, 75], [19, 3], [58, 72], [62, 59], [68, 54], [9, 61], [70, 74], [56, 48], [74, 48], [2, 9], [51, 22], [69, 61], [0, 35], [28, 46], [7, 11], [56, 57], [14, 67], [15, 4], [53, 12], [64, 42], [20, 15], [52, 53], [44, 16], [8, 7], [21, 7], [42, 45], [4, 66], [39, 59], [20, 1], [60, 0], [52, 28], [75, 63], [59, 14], [40, 69], [74, 46], [60, 67], [6, 57], [38, 68], [24, 22], [59, 61], [53, 30], [10, 56], [49, 59], [12, 27], [75, 22], [24, 25], [37, 11], [56, 12], [62, 47], [22, 9], [34, 17], [57, 10], [52, 43], [17, 22], [14, 73], [54, 75], [28, 22], [18, 51], [38, 46], [6, 22], [75, 15], [10, 1], [37, 12], [67, 34], [28, 43], [5, 2], [60, 40], [9, 22], [3, 75], [50, 1], [19, 8], [17, 57], [43, 60], [45, 60], [57, 32], [52, 35], [18, 22], [11, 38], [16, 57], [31, 39], [13, 18], [61, 54], [25, 10], [23, 46], [47, 5], [42, 66], [73, 67], [44, 28], [65, 34], [35, 50], [67, 1], [12, 44], [17, 51], [70, 23], [44, 35], [0, 16], [65, 53], [10, 74], [5, 60], [45, 8], [13, 46], [57, 6], [72, 47], [1, 36], [60, 4], [11, 31], [46, 21], [60, 29], [58, 44], [53, 41], [33, 44], [47, 34], [58, 35], [74, 51], [71, 35], [58, 10], [47, 59], [32, 36], [16, 67], [62, 9], [14, 44], [12, 32], [6, 19], [35, 21], [49, 71], [7, 7], [25, 39], [25, 24], [45, 40], [44, 20], [9, 37], [58, 18], [59, 52], [12, 23], [26, 49], [62, 69], [8, 2], [66, 52], [25, 42], [34, 70], [64, 1], [29, 57], [8, 26], [25, 63], [75, 56], [51, 49], [70, 9], [63, 51], [6, 28], [1, 38], [47, 27], [74, 26], [27, 63], [20, 47], [25, 37], [31, 67], [59, 71], [56, 32], [28, 65], [37, 10], [30, 50], [42, 32], [56, 63], [32, 65], [48, 70], [37, 21], [10, 11], [5, 24], [51, 8], [46, 6], [75, 23], [42, 28], [60, 26], [37, 9], [0, 19], [11, 34], [66, 51], [49, 42], [16, 37], [52, 55], [20, 39], [46, 12], [1, 70], [45, 37], [18, 63], [63, 23], [54, 7], [18, 11], [51, 28], [21, 65], [28, 71], [46, 53], [14, 36], [35, 71], [30, 5], [50, 62], [32, 28], [64, 38], [66, 61], [0, 10]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 }, { - "name": "NarrowerList_5", - "sat": "def sat(li: List[str], lists=[['lyquetextochonulewyj', 'dynysype', 'dojuluzitha', 'fewimiwequochixo'], ['muv', 'bofilisequimop', 'cizecirexequyho', 'tenythegu'], ['lenuthunifafetextuly', 'thothofukero']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['lyquetextochonulewyj', 'dynysype', 'dojuluzitha', 'fewimiwequochixo'], ['muv', 'bofilisequimop', 'cizecirexequyho', 'tenythegu'], ['lenuthunifafetextuly', 'thothofukero']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyTriangle:2", + "sat": "def sat(tri: List[int], edges=[[51, 44], [11, 59], [57, 15], [18, 1], [41, 1], [44, 6], [58, 44], [43, 10], [41, 9], [50, 43], [56, 0], [47, 4], [42, 45], [51, 15], [60, 18], [11, 56], [21, 45], [39, 42], [57, 34], [60, 25], [57, 33], [6, 17], [26, 43], [38, 25], [29, 18], [39, 43], [34, 4], [22, 61], [0, 9], [1, 20], [36, 28], [10, 37], [53, 7], [49, 60], [12, 48], [31, 33], [4, 8], [5, 56], [27, 59], [56, 29], [60, 17], [17, 27], [24, 58], [46, 47], [60, 35], [4, 37], [41, 43], [37, 33], [30, 7], [53, 31], [3, 60], [24, 39], [14, 41], [14, 54], [33, 35], [50, 1], [60, 57], [23, 17], [34, 15], [60, 26], [22, 0], [5, 4], [8, 41], [16, 4], [56, 40], [60, 44], [2, 26], [42, 21], [21, 28], [58, 32], [58, 12], [31, 22], [43, 0], [28, 3], [35, 21], [54, 18], [0, 58], [3, 9], [6, 59], [57, 46], [48, 45], [30, 12], [46, 27], [41, 55], [52, 58], [30, 21], [51, 24], [23, 18], [31, 59], [34, 49], [41, 34], [19, 58], [1, 32], [52, 16], [17, 8], [20, 3], [56, 12], [3, 51], [60, 31], [41, 5], [58, 23], [59, 6], [39, 2], [6, 6], [11, 38], [3, 44], [61, 58], [13, 46], [56, 1], [35, 14], [25, 7], [29, 60], [16, 32], [32, 32], [7, 44], [3, 48], [38, 21], [19, 43], [60, 4], [56, 56], [21, 33], [15, 11], [32, 0], [8, 10], [44, 11], [37, 36], [24, 28], [4, 23], [37, 22], [44, 4], [34, 28], [1, 7], [15, 48], [11, 20], [60, 13], [7, 30], [51, 18], [3, 56], [14, 57], [14, 22], [55, 13], [47, 50], [36, 14], [42, 46], [7, 29], [58, 36], [52, 49], [33, 4], [51, 51], [47, 55], [7, 60], [4, 17], [53, 6], [59, 28], [51, 52], [50, 24], [30, 18], [37, 42], [51, 30], [6, 37], [0, 41], [38, 30], [0, 24], [43, 38], [33, 2], [10, 21], [44, 33], [57, 29], [28, 45], [2, 27], [59, 38], [41, 28], [49, 61], [54, 23], [44, 32], [58, 33], [2, 43], [34, 39], [37, 28], [40, 56], [55, 59], [28, 43], [36, 36], [29, 41], [16, 35], [50, 33], [51, 4], [33, 11], [26, 17], [2, 49], [7, 18], [15, 60], [14, 47], [40, 16], [47, 19], [18, 43], [38, 53], [28, 10], [46, 12], [26, 48], [1, 45], [9, 45], [2, 12], [8, 55], [19, 24], [2, 10], [17, 38], [30, 48], [2, 13], [59, 22], [11, 39], [32, 47], [23, 26], [43, 25], [9, 34], [46, 30], [36, 32], [33, 36], [38, 54], [33, 14], [48, 46], [29, 53], [46, 60], [14, 10], [0, 3], [13, 39], [53, 53], [22, 16], [33, 31], [33, 13], [54, 51], [25, 34], [14, 33], [19, 56], [51, 10], [58, 43], [4, 20], [28, 54], [3, 34], [47, 45], [1, 58], [55, 43], [13, 21], [31, 46], [23, 57], [58, 15], [54, 36], [44, 7], [16, 52], [20, 40], [46, 18], [59, 19], [14, 44], [3, 4], [58, 52], [31, 42], [21, 17], [42, 18], [46, 57], [7, 35], [52, 4], [30, 11], [17, 14], [60, 10], [57, 59], [59, 46], [18, 15], [35, 27], [46, 31], [49, 18], [21, 23], [50, 25], [24, 59], [51, 26], [36, 34], [27, 17], [13, 16], [54, 56], [53, 13], [27, 25], [8, 33], [52, 7], [45, 61], [39, 0], [6, 51], [35, 23], [31, 5], [38, 33], [47, 58], [28, 61], [36, 0], [18, 30], [51, 11], [39, 51], [39, 36], [60, 37], [37, 43], [46, 42]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[51, 44], [11, 59], [57, 15], [18, 1], [41, 1], [44, 6], [58, 44], [43, 10], [41, 9], [50, 43], [56, 0], [47, 4], [42, 45], [51, 15], [60, 18], [11, 56], [21, 45], [39, 42], [57, 34], [60, 25], [57, 33], [6, 17], [26, 43], [38, 25], [29, 18], [39, 43], [34, 4], [22, 61], [0, 9], [1, 20], [36, 28], [10, 37], [53, 7], [49, 60], [12, 48], [31, 33], [4, 8], [5, 56], [27, 59], [56, 29], [60, 17], [17, 27], [24, 58], [46, 47], [60, 35], [4, 37], [41, 43], [37, 33], [30, 7], [53, 31], [3, 60], [24, 39], [14, 41], [14, 54], [33, 35], [50, 1], [60, 57], [23, 17], [34, 15], [60, 26], [22, 0], [5, 4], [8, 41], [16, 4], [56, 40], [60, 44], [2, 26], [42, 21], [21, 28], [58, 32], [58, 12], [31, 22], [43, 0], [28, 3], [35, 21], [54, 18], [0, 58], [3, 9], [6, 59], [57, 46], [48, 45], [30, 12], [46, 27], [41, 55], [52, 58], [30, 21], [51, 24], [23, 18], [31, 59], [34, 49], [41, 34], [19, 58], [1, 32], [52, 16], [17, 8], [20, 3], [56, 12], [3, 51], [60, 31], [41, 5], [58, 23], [59, 6], [39, 2], [6, 6], [11, 38], [3, 44], [61, 58], [13, 46], [56, 1], [35, 14], [25, 7], [29, 60], [16, 32], [32, 32], [7, 44], [3, 48], [38, 21], [19, 43], [60, 4], [56, 56], [21, 33], [15, 11], [32, 0], [8, 10], [44, 11], [37, 36], [24, 28], [4, 23], [37, 22], [44, 4], [34, 28], [1, 7], [15, 48], [11, 20], [60, 13], [7, 30], [51, 18], [3, 56], [14, 57], [14, 22], [55, 13], [47, 50], [36, 14], [42, 46], [7, 29], [58, 36], [52, 49], [33, 4], [51, 51], [47, 55], [7, 60], [4, 17], [53, 6], [59, 28], [51, 52], [50, 24], [30, 18], [37, 42], [51, 30], [6, 37], [0, 41], [38, 30], [0, 24], [43, 38], [33, 2], [10, 21], [44, 33], [57, 29], [28, 45], [2, 27], [59, 38], [41, 28], [49, 61], [54, 23], [44, 32], [58, 33], [2, 43], [34, 39], [37, 28], [40, 56], [55, 59], [28, 43], [36, 36], [29, 41], [16, 35], [50, 33], [51, 4], [33, 11], [26, 17], [2, 49], [7, 18], [15, 60], [14, 47], [40, 16], [47, 19], [18, 43], [38, 53], [28, 10], [46, 12], [26, 48], [1, 45], [9, 45], [2, 12], [8, 55], [19, 24], [2, 10], [17, 38], [30, 48], [2, 13], [59, 22], [11, 39], [32, 47], [23, 26], [43, 25], [9, 34], [46, 30], [36, 32], [33, 36], [38, 54], [33, 14], [48, 46], [29, 53], [46, 60], [14, 10], [0, 3], [13, 39], [53, 53], [22, 16], [33, 31], [33, 13], [54, 51], [25, 34], [14, 33], [19, 56], [51, 10], [58, 43], [4, 20], [28, 54], [3, 34], [47, 45], [1, 58], [55, 43], [13, 21], [31, 46], [23, 57], [58, 15], [54, 36], [44, 7], [16, 52], [20, 40], [46, 18], [59, 19], [14, 44], [3, 4], [58, 52], [31, 42], [21, 17], [42, 18], [46, 57], [7, 35], [52, 4], [30, 11], [17, 14], [60, 10], [57, 59], [59, 46], [18, 15], [35, 27], [46, 31], [49, 18], [21, 23], [50, 25], [24, 59], [51, 26], [36, 34], [27, 17], [13, 16], [54, 56], [53, 13], [27, 25], [8, 33], [52, 7], [45, 61], [39, 0], [6, 51], [35, 23], [31, 5], [38, 33], [47, 58], [28, 61], [36, 0], [18, 30], [51, 11], [39, 51], [39, 36], [60, 37], [37, 43], [46, 42]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 }, { - "name": "NarrowerList_6", - "sat": "def sat(li: List[str], lists=[['pokelyjuf', 'hiquut'], ['coxisathut', 'cowabejabethacesar', 'thubimylumivehesute'], ['c', 'didod', 'ryju']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['pokelyjuf', 'hiquut'], ['coxisathut', 'cowabejabethacesar', 'thubimylumivehesute'], ['c', 'didod', 'ryju']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyTriangle:3", + "sat": "def sat(tri: List[int], edges=[[8, 0], [2, 7], [1, 2], [4, 5], [2, 1], [7, 1], [5, 6], [6, 3], [3, 8], [3, 4], [0, 1], [6, 6], [4, 0], [2, 8], [1, 5], [4, 2]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[8, 0], [2, 7], [1, 2], [4, 5], [2, 1], [7, 1], [5, 6], [6, 3], [3, 8], [3, 4], [0, 1], [6, 6], [4, 0], [2, 8], [1, 5], [4, 2]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 }, { - "name": "NarrowerList_7", - "sat": "def sat(li: List[str], lists=[['textene', 'voxazotextemyn'], ['bacyfyjepihiha', 'thyt', 'rysydud', 'gyfimu'], ['ga', 'quiv'], ['lo', 's', 'thijasi']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['textene', 'voxazotextemyn'], ['bacyfyjepihiha', 'thyt', 'rysydud', 'gyfimu'], ['ga', 'quiv'], ['lo', 's', 'thijasi']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "AnyTriangle:4", + "sat": "def sat(tri: List[int], edges=[[4, 4], [5, 5], [3, 5], [3, 1], [0, 1], [4, 0], [3, 2], [5, 3], [1, 3], [2, 5], [2, 0]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[4, 4], [5, 5], [3, 5], [3, 1], [0, 1], [4, 0], [3, 2], [5, 3], [1, 3], [2, 5], [2, 0]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 }, { - "name": "NarrowerList_8", - "sat": "def sat(li: List[str], lists=[['cokochumugil', 'japy', 'xykyvotextu', 'xevy'], ['rurirate', 'zutuquujuchilorusim'], ['bygimutextemigum', 'carequetenehehu', 'fenatextukod', 'gihiherabeza']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['cokochumugil', 'japy', 'xykyvotextu', 'xevy'], ['rurirate', 'zutuquujuchilorusim'], ['bygimutextemigum', 'carequetenehehu', 'fenatextukod', 'gihiherabeza']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "PlantedClique:0", + "sat": "def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [ + " # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 }, { - "name": "NarrowerList_9", - "sat": "def sat(li: List[str], lists=[['rejihuci', 'monizycy'], ['motalejybat', 'tocu', 'zeraf', 'gukyxiwijewyn'], ['kygupybo', 'zi']]):\n \"\"\"\n Find the list that has fewer total characters (including repetitions)\n \"\"\"\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", - "sols": [ - "def sol(lists=[['rejihuci', 'monizycy'], ['motalejybat', 'tocu', 'zeraf', 'gukyxiwijewyn'], ['kygupybo', 'zi']]):\n return min(lists, key=lambda x: sum(len(i) for i in x))" + "name": "PlantedClique:1", + "sat": "def sat(nodes: List[int], size=0, edges=[[1, 0]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[1, 0]], size=0):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [ + " # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 }, { - "name": "ThreePrimes_0", - "sat": "def sat(factors: List[List[int]]):\n \"\"\"\n Find all 247 integers <= 1000 that are the product of exactly three primes.\n Each integer should represented as the list of its three prime factors.\n \"\"\"\n primes = set(range(2, 1000))\n for n in range(2, 1000):\n if n in primes:\n primes.difference_update(range(2 * n, 1000, n))\n assert all(p in primes for f in factors for p in f), \"all factors must be prime\"\n nums = {p * q * r for p, q, r in factors}\n return max(nums) < 1000 and len(nums) == 247", - "sols": [ - "def sol():\n primes = set(range(2, 1000))\n for n in range(2, 1000):\n if n in primes:\n primes.difference_update(range(2 * n, 1000, n))\n 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]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#75", - "taint_date": "2021-7-7", - "weight": 0.010416666666666666 + "name": "PlantedClique:2", + "sat": "def sat(nodes: List[int], size=15, edges=[[36, 31], [31, 39], [16, 41], [62, 39], [57, 38], [29, 46], [39, 30], [71, 41], [18, 0], [73, 71], [20, 23], [41, 53], [17, 12], [76, 23], [36, 29], [53, 32], [34, 61], [58, 29], [39, 46], [18, 73], [21, 51], [74, 26], [67, 10], [71, 74], [27, 71], [67, 39], [41, 26], [51, 20], [5, 2], [24, 3], [14, 60], [28, 21], [61, 1], [56, 75], [62, 37], [67, 41], [32, 69], [22, 16], [1, 67], [37, 14], [55, 40], [0, 58], [16, 63], [8, 59], [26, 61], [34, 51], [43, 66], [31, 33], [7, 51], [1, 0], [22, 9], [59, 68], [9, 10], [8, 74], [62, 8], [26, 16], [45, 69], [51, 52], [72, 67], [37, 53], [48, 5], [18, 41], [15, 11], [72, 43], [64, 51], [4, 9], [54, 42], [62, 15], [12, 38], [30, 31], [56, 37], [29, 2], [14, 9], [43, 43], [51, 28], [10, 15], [20, 5], [24, 61], [53, 2], [69, 1], [35, 63], [12, 64], [50, 12], [69, 65], [60, 75], [56, 48], [36, 67], [21, 6], [38, 67], [15, 34], [46, 54], [37, 18], [32, 2], [12, 49], [52, 15], [60, 2], [67, 43], [13, 49], [55, 59], [33, 72], [37, 30], [11, 27], [67, 2], [57, 55], [21, 65], [54, 66], [6, 63], [71, 59], [20, 59], [47, 34], [66, 67], [4, 8], [73, 61], [68, 41], [61, 7], [52, 38], [8, 51], [50, 15], [5, 12], [76, 74], [66, 33], [59, 18], [13, 55], [6, 16], [13, 26], [29, 44], [18, 43], [63, 47], [46, 30], [41, 18], [66, 18], [34, 26], [57, 28], [38, 10], [34, 57], [73, 41], [67, 3], [47, 57], [63, 62], [36, 30], [72, 45], [68, 19], [7, 28], [50, 23], [42, 29], [3, 66], [56, 45], [4, 25], [2, 43], [4, 38], [56, 74], [55, 10], [0, 13], [9, 19], [38, 69], [40, 57], [70, 41], [49, 45], [47, 27], [11, 8], [32, 5], [9, 38], [76, 64], [24, 33], [74, 63], [73, 58], [58, 41], [75, 0], [33, 55], [74, 2], [41, 72], [1, 64], [36, 74], [51, 71], [75, 9], [53, 36], [8, 70], [53, 42], [58, 25], [29, 37], [34, 46], [37, 39], [59, 61], [52, 20], [16, 58], [39, 43], [37, 40], [10, 72], [76, 14], [49, 13], [21, 37], [42, 2], [10, 29], [76, 19], [57, 66], [55, 62], [76, 53], [0, 0], [58, 5], [14, 2], [5, 32], [70, 57], [20, 18], [74, 66], [39, 57], [32, 36], [15, 30], [56, 23], [67, 16], [66, 51], [6, 74], [43, 59], [33, 70], [11, 71], [59, 28], [75, 29], [17, 13], [75, 67], [70, 1], [68, 10], [8, 46], [37, 27], [20, 24], [72, 75], [37, 41], [68, 24], [35, 10], [67, 66], [18, 24], [52, 3], [55, 34], [28, 75], [41, 3], [44, 3], [44, 30], [23, 17], [44, 4], [72, 73], [67, 12], [43, 21], [16, 55], [59, 71], [26, 62], [34, 60], [15, 22], [5, 10], [2, 55], [48, 15], [60, 34], [39, 35], [52, 36], [11, 46], [18, 10], [3, 43], [37, 6], [34, 47], [73, 29], [59, 29], [49, 72], [64, 73], [20, 76], [39, 39], [0, 16], [62, 73], [15, 36], [73, 18], [16, 34], [18, 68], [66, 45], [16, 66], [47, 52], [46, 66], [73, 43], [22, 55], [70, 58], [63, 11], [40, 2], [58, 60], [47, 29], [19, 45], [15, 41], [54, 5], [1, 18], [36, 38], [16, 19], [32, 4], [56, 14], [15, 51], [14, 35], [74, 10], [7, 20], [25, 38], [35, 13], [57, 34], [3, 16], [56, 28], [21, 56], [63, 65], [46, 35], [17, 57], [2, 30], [52, 73], [68, 73], [53, 10], [58, 59], [29, 16], [11, 20], [42, 27], [10, 66], [73, 5], [61, 58], [68, 67], [14, 47], [19, 59], [8, 42], [31, 12], [3, 2], [52, 66], [28, 72], [30, 56], [27, 12], [29, 18], [38, 56], [11, 17], [59, 66], [70, 7], [1, 54], [2, 16], [1, 14], [25, 20], [69, 72], [20, 74], [10, 59], [72, 52], [26, 15], [44, 42], [5, 51], [76, 69], [16, 10], [75, 39], [5, 44], [0, 46], [16, 76], [66, 73], [66, 72], [11, 11], [47, 13], [20, 26], [73, 59], [3, 10], [46, 49], [17, 38], [32, 62], [41, 2], [16, 72], [76, 61], [15, 37], [74, 69], [38, 46], [68, 58], [51, 70], [20, 46], [59, 2], [35, 21], [72, 37], [69, 20], [3, 72], [43, 71], [1, 71], [48, 59], [43, 58], [74, 5], [59, 72], [45, 24], [66, 69], [35, 38], [16, 5], [40, 24], [63, 30], [16, 18], [72, 29], [72, 58], [42, 5], [17, 30], [14, 21], [48, 23], [53, 44], [1, 47], [57, 33], [47, 69], [65, 52], [51, 44], [60, 35], [41, 9], [59, 75], [57, 73], [58, 28], [65, 23], [36, 48], [26, 40], [39, 41], [58, 3], [40, 42], [58, 49], [28, 42], [33, 36], [44, 24], [2, 68], [30, 57], [10, 51], [3, 68], [26, 42], [51, 13], [12, 69], [19, 60], [58, 39], [1, 45], [66, 16], [41, 27], [56, 1], [28, 18], [66, 29], [37, 49], [59, 4], [29, 67], [38, 29], [54, 57], [47, 61], [68, 29], [38, 9], [51, 41], [41, 10], [19, 61], [3, 22], [72, 23], [18, 11], [27, 17], [72, 74], [5, 37], [66, 68], [2, 3], [60, 27], [68, 72], [64, 20], [67, 18], [6, 66], [24, 60], [14, 75], [9, 11], [71, 50], [66, 43], [6, 60], [54, 22], [71, 53], [51, 7], [49, 40], [7, 74], [72, 30], [20, 71], [28, 74], [36, 55], [16, 17], [66, 2], [53, 8], [18, 2], [62, 63], [63, 26], [19, 34], [26, 27], [67, 51], [61, 46], [37, 29], [66, 41], [51, 54], [3, 17], [35, 6], [50, 51], [8, 15], [15, 55], [10, 65], [57, 59], [69, 21], [73, 70], [21, 30], [28, 28], [67, 59], [39, 76], [56, 12], [22, 69], [76, 7], [63, 66], [9, 40], [64, 28], [65, 31], [6, 59], [73, 73], [24, 29], [44, 18], [67, 1], [16, 12], [73, 2], [74, 27], [25, 58], [18, 52], [12, 66], [32, 25], [26, 4], [34, 27], [51, 39], [23, 11], [13, 65], [18, 28], [19, 6], [68, 59], [51, 72], [59, 74], [59, 3], [41, 29], [36, 6], [49, 37], [71, 39], [33, 13], [38, 68], [34, 19], [64, 36], [4, 29], [72, 60], [52, 41], [36, 66], [34, 70], [22, 32], [67, 40], [3, 73], [19, 12], [17, 0], [22, 8], [42, 35], [34, 54], [71, 29], [6, 7], [10, 43], [8, 56], [2, 58], [72, 2], [67, 65], [1, 23], [13, 21], [62, 38], [2, 66], [42, 62], [38, 27], [1, 22], [16, 29], [39, 54], [41, 0], [42, 54], [50, 58], [62, 45], [59, 76], [40, 44], [72, 18], [45, 40], [31, 3], [13, 45], [38, 64], [1, 21], [10, 32], [35, 12], [32, 6], [62, 75], [52, 59], [1, 42], [72, 31], [55, 17], [18, 50], [43, 29], [48, 37], [73, 16], [43, 68], [47, 12], [55, 46], [41, 30], [69, 32], [55, 14], [74, 61], [55, 72], [75, 24], [63, 40], [10, 58], [67, 73], [20, 11], [42, 40], [27, 53], [5, 8], [10, 2], [27, 49], [50, 48], [18, 58], [60, 25], [74, 71], [0, 30], [3, 29], [59, 5], [43, 16], [59, 41], [74, 4], [19, 20], [53, 19], [57, 50], [60, 11], [16, 68], [9, 50], [71, 17], [73, 66], [59, 43], [68, 32], [75, 31], [27, 56], [47, 24], [29, 7], [27, 25], [48, 36], [0, 53], [0, 72], [24, 53], [13, 64], [19, 44], [9, 56], [35, 75], [75, 17], [47, 16], [11, 42], [40, 45], [43, 60], [21, 59], [29, 50], [8, 9], [3, 18], [7, 57], [32, 9], [61, 6], [11, 6], [7, 72], [42, 61], [73, 75], [68, 44], [68, 66], [25, 56], [14, 20], [3, 50], [32, 57], [67, 58], [41, 68], [19, 26], [30, 3], [23, 45], [16, 60], [41, 43], [5, 30], [5, 25], [72, 16], [16, 73], [21, 17], [16, 59], [8, 34], [4, 39], [23, 72], [35, 53], [31, 50], [20, 44], [50, 13], [72, 1], [8, 8], [74, 54], [1, 1], [16, 43], [39, 36], [51, 2], [23, 54], [66, 58], [60, 33], [2, 63], [73, 10]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[36, 31], [31, 39], [16, 41], [62, 39], [57, 38], [29, 46], [39, 30], [71, 41], [18, 0], [73, 71], [20, 23], [41, 53], [17, 12], [76, 23], [36, 29], [53, 32], [34, 61], [58, 29], [39, 46], [18, 73], [21, 51], [74, 26], [67, 10], [71, 74], [27, 71], [67, 39], [41, 26], [51, 20], [5, 2], [24, 3], [14, 60], [28, 21], [61, 1], [56, 75], [62, 37], [67, 41], [32, 69], [22, 16], [1, 67], [37, 14], [55, 40], [0, 58], [16, 63], [8, 59], [26, 61], [34, 51], [43, 66], [31, 33], [7, 51], [1, 0], [22, 9], [59, 68], [9, 10], [8, 74], [62, 8], [26, 16], [45, 69], [51, 52], [72, 67], [37, 53], [48, 5], [18, 41], [15, 11], [72, 43], [64, 51], [4, 9], [54, 42], [62, 15], [12, 38], [30, 31], [56, 37], [29, 2], [14, 9], [43, 43], [51, 28], [10, 15], [20, 5], [24, 61], [53, 2], [69, 1], [35, 63], [12, 64], [50, 12], [69, 65], [60, 75], [56, 48], [36, 67], [21, 6], [38, 67], [15, 34], [46, 54], [37, 18], [32, 2], [12, 49], [52, 15], [60, 2], [67, 43], [13, 49], [55, 59], [33, 72], [37, 30], [11, 27], [67, 2], [57, 55], [21, 65], [54, 66], [6, 63], [71, 59], [20, 59], [47, 34], [66, 67], [4, 8], [73, 61], [68, 41], [61, 7], [52, 38], [8, 51], [50, 15], [5, 12], [76, 74], [66, 33], [59, 18], [13, 55], [6, 16], [13, 26], [29, 44], [18, 43], [63, 47], [46, 30], [41, 18], [66, 18], [34, 26], [57, 28], [38, 10], [34, 57], [73, 41], [67, 3], [47, 57], [63, 62], [36, 30], [72, 45], [68, 19], [7, 28], [50, 23], [42, 29], [3, 66], [56, 45], [4, 25], [2, 43], [4, 38], [56, 74], [55, 10], [0, 13], [9, 19], [38, 69], [40, 57], [70, 41], [49, 45], [47, 27], [11, 8], [32, 5], [9, 38], [76, 64], [24, 33], [74, 63], [73, 58], [58, 41], [75, 0], [33, 55], [74, 2], [41, 72], [1, 64], [36, 74], [51, 71], [75, 9], [53, 36], [8, 70], [53, 42], [58, 25], [29, 37], [34, 46], [37, 39], [59, 61], [52, 20], [16, 58], [39, 43], [37, 40], [10, 72], [76, 14], [49, 13], [21, 37], [42, 2], [10, 29], [76, 19], [57, 66], [55, 62], [76, 53], [0, 0], [58, 5], [14, 2], [5, 32], [70, 57], [20, 18], [74, 66], [39, 57], [32, 36], [15, 30], [56, 23], [67, 16], [66, 51], [6, 74], [43, 59], [33, 70], [11, 71], [59, 28], [75, 29], [17, 13], [75, 67], [70, 1], [68, 10], [8, 46], [37, 27], [20, 24], [72, 75], [37, 41], [68, 24], [35, 10], [67, 66], [18, 24], [52, 3], [55, 34], [28, 75], [41, 3], [44, 3], [44, 30], [23, 17], [44, 4], [72, 73], [67, 12], [43, 21], [16, 55], [59, 71], [26, 62], [34, 60], [15, 22], [5, 10], [2, 55], [48, 15], [60, 34], [39, 35], [52, 36], [11, 46], [18, 10], [3, 43], [37, 6], [34, 47], [73, 29], [59, 29], [49, 72], [64, 73], [20, 76], [39, 39], [0, 16], [62, 73], [15, 36], [73, 18], [16, 34], [18, 68], [66, 45], [16, 66], [47, 52], [46, 66], [73, 43], [22, 55], [70, 58], [63, 11], [40, 2], [58, 60], [47, 29], [19, 45], [15, 41], [54, 5], [1, 18], [36, 38], [16, 19], [32, 4], [56, 14], [15, 51], [14, 35], [74, 10], [7, 20], [25, 38], [35, 13], [57, 34], [3, 16], [56, 28], [21, 56], [63, 65], [46, 35], [17, 57], [2, 30], [52, 73], [68, 73], [53, 10], [58, 59], [29, 16], [11, 20], [42, 27], [10, 66], [73, 5], [61, 58], [68, 67], [14, 47], [19, 59], [8, 42], [31, 12], [3, 2], [52, 66], [28, 72], [30, 56], [27, 12], [29, 18], [38, 56], [11, 17], [59, 66], [70, 7], [1, 54], [2, 16], [1, 14], [25, 20], [69, 72], [20, 74], [10, 59], [72, 52], [26, 15], [44, 42], [5, 51], [76, 69], [16, 10], [75, 39], [5, 44], [0, 46], [16, 76], [66, 73], [66, 72], [11, 11], [47, 13], [20, 26], [73, 59], [3, 10], [46, 49], [17, 38], [32, 62], [41, 2], [16, 72], [76, 61], [15, 37], [74, 69], [38, 46], [68, 58], [51, 70], [20, 46], [59, 2], [35, 21], [72, 37], [69, 20], [3, 72], [43, 71], [1, 71], [48, 59], [43, 58], [74, 5], [59, 72], [45, 24], [66, 69], [35, 38], [16, 5], [40, 24], [63, 30], [16, 18], [72, 29], [72, 58], [42, 5], [17, 30], [14, 21], [48, 23], [53, 44], [1, 47], [57, 33], [47, 69], [65, 52], [51, 44], [60, 35], [41, 9], [59, 75], [57, 73], [58, 28], [65, 23], [36, 48], [26, 40], [39, 41], [58, 3], [40, 42], [58, 49], [28, 42], [33, 36], [44, 24], [2, 68], [30, 57], [10, 51], [3, 68], [26, 42], [51, 13], [12, 69], [19, 60], [58, 39], [1, 45], [66, 16], [41, 27], [56, 1], [28, 18], [66, 29], [37, 49], [59, 4], [29, 67], [38, 29], [54, 57], [47, 61], [68, 29], [38, 9], [51, 41], [41, 10], [19, 61], [3, 22], [72, 23], [18, 11], [27, 17], [72, 74], [5, 37], [66, 68], [2, 3], [60, 27], [68, 72], [64, 20], [67, 18], [6, 66], [24, 60], [14, 75], [9, 11], [71, 50], [66, 43], [6, 60], [54, 22], [71, 53], [51, 7], [49, 40], [7, 74], [72, 30], [20, 71], [28, 74], [36, 55], [16, 17], [66, 2], [53, 8], [18, 2], [62, 63], [63, 26], [19, 34], [26, 27], [67, 51], [61, 46], [37, 29], [66, 41], [51, 54], [3, 17], [35, 6], [50, 51], [8, 15], [15, 55], [10, 65], [57, 59], [69, 21], [73, 70], [21, 30], [28, 28], [67, 59], [39, 76], [56, 12], [22, 69], [76, 7], [63, 66], [9, 40], [64, 28], [65, 31], [6, 59], [73, 73], [24, 29], [44, 18], [67, 1], [16, 12], [73, 2], [74, 27], [25, 58], [18, 52], [12, 66], [32, 25], [26, 4], [34, 27], [51, 39], [23, 11], [13, 65], [18, 28], [19, 6], [68, 59], [51, 72], [59, 74], [59, 3], [41, 29], [36, 6], [49, 37], [71, 39], [33, 13], [38, 68], [34, 19], [64, 36], [4, 29], [72, 60], [52, 41], [36, 66], [34, 70], [22, 32], [67, 40], [3, 73], [19, 12], [17, 0], [22, 8], [42, 35], [34, 54], [71, 29], [6, 7], [10, 43], [8, 56], [2, 58], [72, 2], [67, 65], [1, 23], [13, 21], [62, 38], [2, 66], [42, 62], [38, 27], [1, 22], [16, 29], [39, 54], [41, 0], [42, 54], [50, 58], [62, 45], [59, 76], [40, 44], [72, 18], [45, 40], [31, 3], [13, 45], [38, 64], [1, 21], [10, 32], [35, 12], [32, 6], [62, 75], [52, 59], [1, 42], [72, 31], [55, 17], [18, 50], [43, 29], [48, 37], [73, 16], [43, 68], [47, 12], [55, 46], [41, 30], [69, 32], [55, 14], [74, 61], [55, 72], [75, 24], [63, 40], [10, 58], [67, 73], [20, 11], [42, 40], [27, 53], [5, 8], [10, 2], [27, 49], [50, 48], [18, 58], [60, 25], [74, 71], [0, 30], [3, 29], [59, 5], [43, 16], [59, 41], [74, 4], [19, 20], [53, 19], [57, 50], [60, 11], [16, 68], [9, 50], [71, 17], [73, 66], [59, 43], [68, 32], [75, 31], [27, 56], [47, 24], [29, 7], [27, 25], [48, 36], [0, 53], [0, 72], [24, 53], [13, 64], [19, 44], [9, 56], [35, 75], [75, 17], [47, 16], [11, 42], [40, 45], [43, 60], [21, 59], [29, 50], [8, 9], [3, 18], [7, 57], [32, 9], [61, 6], [11, 6], [7, 72], [42, 61], [73, 75], [68, 44], [68, 66], [25, 56], [14, 20], [3, 50], [32, 57], [67, 58], [41, 68], [19, 26], [30, 3], [23, 45], [16, 60], [41, 43], [5, 30], [5, 25], [72, 16], [16, 73], [21, 17], [16, 59], [8, 34], [4, 39], [23, 72], [35, 53], [31, 50], [20, 44], [50, 13], [72, 1], [8, 8], [74, 54], [1, 1], [16, 43], [39, 36], [51, 2], [23, 54], [66, 58], [60, 33], [2, 63], [73, 10]], size=15):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 }, { - "name": "IntegerLog_0", - "sat": "def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "name": "PlantedClique:3", + "sat": "def sat(nodes: List[int], size=18, edges=[[34, 43], [45, 8], [7, 46], [53, 11], [48, 24], [47, 46], [20, 46], [11, 57], [39, 17], [25, 13], [9, 49], [47, 51], [5, 22], [56, 8], [5, 20], [11, 26], [40, 20], [30, 42], [46, 35], [41, 11], [49, 57], [24, 46], [40, 27], [3, 13], [25, 36], [20, 49], [57, 24], [56, 26], [1, 52], [8, 26], [17, 44], [1, 21], [5, 6], [45, 45], [39, 25], [48, 27], [26, 17], [37, 25], [17, 16], [49, 0], [17, 56], [33, 43], [20, 43], [24, 20], [31, 56], [54, 28], [25, 27], [50, 5], [21, 43], [54, 25], [57, 45], [48, 5], [45, 34], [18, 46], [25, 47], [56, 48], [17, 57], [15, 29], [40, 22], [23, 57], [17, 27], [1, 14], [7, 54], [15, 24], [27, 44], [24, 44], [6, 7], [59, 13], [56, 51], [49, 46], [1, 32], [20, 36], [46, 13], [15, 46], [6, 46], [59, 51], [35, 5], [27, 10], [3, 16], [24, 33], [34, 49], [4, 38], [46, 24], [46, 3], [41, 39], [12, 9], [44, 39], [27, 23], [33, 11], [16, 24], [29, 59], [47, 39], [32, 10], [23, 36], [48, 30], [48, 20], [18, 43], [36, 9], [36, 16], [27, 57], [29, 35], [13, 41], [52, 12], [32, 20], [9, 50], [29, 27], [47, 44], [57, 39], [48, 57], [35, 45], [9, 23], [25, 55], [32, 25], [5, 57], [44, 16], [5, 27], [16, 37], [15, 25], [39, 51], [43, 14], [13, 44], [2, 5], [40, 4], [58, 30], [43, 6], [25, 28], [16, 35], [57, 44], [51, 54], [21, 11], [18, 19], [41, 20], [44, 48], [14, 54], [57, 16], [15, 5], [37, 15], [44, 49], [15, 20], [11, 20], [45, 1], [3, 32], [7, 22], [48, 39], [28, 37], [11, 51], [20, 16], [32, 4], [13, 17], [16, 15], [20, 37], [37, 46], [33, 59], [46, 25], [42, 1], [32, 33], [13, 53], [46, 18], [44, 23], [17, 48], [5, 24], [10, 40], [19, 11], [37, 47], [11, 42], [13, 24], [13, 27], [42, 9], [13, 5], [29, 17], [57, 4], [31, 25], [38, 32], [21, 45], [0, 21], [1, 0], [20, 13], [24, 37], [20, 25], [5, 17], [20, 47], [46, 41], [11, 0], [25, 22], [5, 28], [44, 5], [10, 11], [41, 22], [17, 25], [25, 20], [20, 17], [39, 46], [49, 25], [41, 0], [12, 44], [41, 49], [55, 8], [47, 49], [27, 49], [2, 11], [38, 11], [27, 46], [16, 9], [41, 47], [17, 15], [37, 31], [48, 48], [53, 59], [25, 24], [3, 44], [34, 48], [33, 13], [15, 47], [16, 39], [48, 8], [32, 55], [38, 22], [11, 23], [41, 16], [21, 44], [20, 27], [13, 57], [27, 41], [29, 32], [56, 39], [31, 51], [46, 20], [24, 49], [25, 3], [57, 37], [15, 44], [9, 41], [15, 48], [42, 57], [47, 5], [48, 37], [45, 49], [44, 41], [7, 3], [39, 49], [49, 37], [24, 16], [57, 41], [56, 2], [49, 20], [19, 5], [58, 18], [7, 31], [24, 5], [41, 32], [34, 23], [17, 5], [47, 27], [49, 41], [31, 12], [0, 11], [49, 15], [13, 15], [29, 31], [14, 56], [24, 41], [35, 1], [16, 25], [26, 28], [16, 49], [12, 46], [47, 16], [17, 37], [37, 39], [3, 22], [27, 24], [20, 39], [24, 4], [33, 15], [53, 50], [32, 1], [23, 40], [33, 25], [4, 24], [48, 25], [47, 57], [25, 8], [39, 30], [17, 53], [41, 53], [31, 8], [39, 33], [33, 16], [32, 19], [41, 5], [49, 17], [53, 40], [42, 52], [24, 17], [30, 59], [13, 14], [43, 27], [48, 16], [24, 47], [37, 23], [30, 47], [49, 10], [47, 12], [5, 37], [48, 47], [59, 27], [57, 17], [27, 33], [12, 30], [41, 48], [5, 46], [12, 25], [53, 46], [54, 8], [48, 1], [22, 25], [20, 44], [14, 38], [48, 13], [3, 3], [59, 4], [14, 7], [49, 26], [36, 5], [28, 32], [57, 46], [22, 34], [11, 54], [27, 58], [4, 11], [24, 39], [57, 25], [15, 27], [6, 15], [27, 29], [51, 37], [48, 23], [15, 57], [27, 25], [0, 57], [49, 48], [27, 34], [21, 5], [31, 40], [38, 45], [15, 1], [17, 42], [5, 16], [59, 32], [13, 51], [17, 47], [38, 54], [4, 43], [54, 9], [42, 31], [16, 13], [20, 57], [58, 10], [41, 30], [52, 19], [52, 35], [46, 44], [51, 4], [30, 39], [47, 13], [30, 32], [36, 42], [39, 15], [3, 19], [12, 16], [46, 16], [12, 37], [46, 48], [58, 46], [5, 25], [46, 6], [49, 44], [18, 23], [50, 24], [16, 16], [49, 53], [37, 33], [4, 15], [46, 17], [7, 20], [25, 41], [27, 56], [37, 41], [38, 55], [59, 28], [31, 7], [10, 47], [40, 23], [49, 5], [44, 25], [8, 36], [26, 39], [34, 3], [5, 12], [54, 22], [15, 41], [40, 19], [21, 12], [16, 5], [13, 49], [39, 5], [9, 9], [11, 53], [27, 16], [27, 39], [52, 14], [3, 56], [27, 37], [30, 15], [41, 17], [1, 34], [55, 32], [28, 22], [49, 27], [10, 55], [39, 37], [30, 17], [23, 9], [22, 11], [44, 37], [41, 37], [37, 13], [51, 18], [4, 34], [23, 12], [39, 13], [32, 9], [58, 14], [25, 48], [29, 14], [52, 2]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[34, 43], [45, 8], [7, 46], [53, 11], [48, 24], [47, 46], [20, 46], [11, 57], [39, 17], [25, 13], [9, 49], [47, 51], [5, 22], [56, 8], [5, 20], [11, 26], [40, 20], [30, 42], [46, 35], [41, 11], [49, 57], [24, 46], [40, 27], [3, 13], [25, 36], [20, 49], [57, 24], [56, 26], [1, 52], [8, 26], [17, 44], [1, 21], [5, 6], [45, 45], [39, 25], [48, 27], [26, 17], [37, 25], [17, 16], [49, 0], [17, 56], [33, 43], [20, 43], [24, 20], [31, 56], [54, 28], [25, 27], [50, 5], [21, 43], [54, 25], [57, 45], [48, 5], [45, 34], [18, 46], [25, 47], [56, 48], [17, 57], [15, 29], [40, 22], [23, 57], [17, 27], [1, 14], [7, 54], [15, 24], [27, 44], [24, 44], [6, 7], [59, 13], [56, 51], [49, 46], [1, 32], [20, 36], [46, 13], [15, 46], [6, 46], [59, 51], [35, 5], [27, 10], [3, 16], [24, 33], [34, 49], [4, 38], [46, 24], [46, 3], [41, 39], [12, 9], [44, 39], [27, 23], [33, 11], [16, 24], [29, 59], [47, 39], [32, 10], [23, 36], [48, 30], [48, 20], [18, 43], [36, 9], [36, 16], [27, 57], [29, 35], [13, 41], [52, 12], [32, 20], [9, 50], [29, 27], [47, 44], [57, 39], [48, 57], [35, 45], [9, 23], [25, 55], [32, 25], [5, 57], [44, 16], [5, 27], [16, 37], [15, 25], [39, 51], [43, 14], [13, 44], [2, 5], [40, 4], [58, 30], [43, 6], [25, 28], [16, 35], [57, 44], [51, 54], [21, 11], [18, 19], [41, 20], [44, 48], [14, 54], [57, 16], [15, 5], [37, 15], [44, 49], [15, 20], [11, 20], [45, 1], [3, 32], [7, 22], [48, 39], [28, 37], [11, 51], [20, 16], [32, 4], [13, 17], [16, 15], [20, 37], [37, 46], [33, 59], [46, 25], [42, 1], [32, 33], [13, 53], [46, 18], [44, 23], [17, 48], [5, 24], [10, 40], [19, 11], [37, 47], [11, 42], [13, 24], [13, 27], [42, 9], [13, 5], [29, 17], [57, 4], [31, 25], [38, 32], [21, 45], [0, 21], [1, 0], [20, 13], [24, 37], [20, 25], [5, 17], [20, 47], [46, 41], [11, 0], [25, 22], [5, 28], [44, 5], [10, 11], [41, 22], [17, 25], [25, 20], [20, 17], [39, 46], [49, 25], [41, 0], [12, 44], [41, 49], [55, 8], [47, 49], [27, 49], [2, 11], [38, 11], [27, 46], [16, 9], [41, 47], [17, 15], [37, 31], [48, 48], [53, 59], [25, 24], [3, 44], [34, 48], [33, 13], [15, 47], [16, 39], [48, 8], [32, 55], [38, 22], [11, 23], [41, 16], [21, 44], [20, 27], [13, 57], [27, 41], [29, 32], [56, 39], [31, 51], [46, 20], [24, 49], [25, 3], [57, 37], [15, 44], [9, 41], [15, 48], [42, 57], [47, 5], [48, 37], [45, 49], [44, 41], [7, 3], [39, 49], [49, 37], [24, 16], [57, 41], [56, 2], [49, 20], [19, 5], [58, 18], [7, 31], [24, 5], [41, 32], [34, 23], [17, 5], [47, 27], [49, 41], [31, 12], [0, 11], [49, 15], [13, 15], [29, 31], [14, 56], [24, 41], [35, 1], [16, 25], [26, 28], [16, 49], [12, 46], [47, 16], [17, 37], [37, 39], [3, 22], [27, 24], [20, 39], [24, 4], [33, 15], [53, 50], [32, 1], [23, 40], [33, 25], [4, 24], [48, 25], [47, 57], [25, 8], [39, 30], [17, 53], [41, 53], [31, 8], [39, 33], [33, 16], [32, 19], [41, 5], [49, 17], [53, 40], [42, 52], [24, 17], [30, 59], [13, 14], [43, 27], [48, 16], [24, 47], [37, 23], [30, 47], [49, 10], [47, 12], [5, 37], [48, 47], [59, 27], [57, 17], [27, 33], [12, 30], [41, 48], [5, 46], [12, 25], [53, 46], [54, 8], [48, 1], [22, 25], [20, 44], [14, 38], [48, 13], [3, 3], [59, 4], [14, 7], [49, 26], [36, 5], [28, 32], [57, 46], [22, 34], [11, 54], [27, 58], [4, 11], [24, 39], [57, 25], [15, 27], [6, 15], [27, 29], [51, 37], [48, 23], [15, 57], [27, 25], [0, 57], [49, 48], [27, 34], [21, 5], [31, 40], [38, 45], [15, 1], [17, 42], [5, 16], [59, 32], [13, 51], [17, 47], [38, 54], [4, 43], [54, 9], [42, 31], [16, 13], [20, 57], [58, 10], [41, 30], [52, 19], [52, 35], [46, 44], [51, 4], [30, 39], [47, 13], [30, 32], [36, 42], [39, 15], [3, 19], [12, 16], [46, 16], [12, 37], [46, 48], [58, 46], [5, 25], [46, 6], [49, 44], [18, 23], [50, 24], [16, 16], [49, 53], [37, 33], [4, 15], [46, 17], [7, 20], [25, 41], [27, 56], [37, 41], [38, 55], [59, 28], [31, 7], [10, 47], [40, 23], [49, 5], [44, 25], [8, 36], [26, 39], [34, 3], [5, 12], [54, 22], [15, 41], [40, 19], [21, 12], [16, 5], [13, 49], [39, 5], [9, 9], [11, 53], [27, 16], [27, 39], [52, 14], [3, 56], [27, 37], [30, 15], [41, 17], [1, 34], [55, 32], [28, 22], [49, 27], [10, 55], [39, 37], [30, 17], [23, 9], [22, 11], [44, 37], [41, 37], [37, 13], [51, 18], [4, 34], [23, 12], [39, 13], [32, 9], [58, 14], [25, 48], [29, 14], [52, 2]], size=18):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 }, { - "name": "IntegerLog_1", - "sat": "def sat(x: int, a=4, n=49947976805055875702105555676690660891977570282639538413746511354005947821116249921924897649015871538557230897942505966327167610868612564900642816):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=4, n=49947976805055875702105555676690660891977570282639538413746511354005947821116249921924897649015871538557230897942505966327167610868612564900642816):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "PlantedClique:4", + "sat": "def sat(nodes: List[int], size=0, edges=[[0, 1], [1, 0]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [1, 0]], size=0):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [ + " # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 }, { - "name": "IntegerLog_2", - "sat": "def sat(x: int, a=2, n=4611686018427387904):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=2, n=4611686018427387904):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "ShortestPath:0", + "sat": "def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_3", - "sat": "def sat(x: int, a=7, n=619664992585427611791050679609026893099690427802915014534984716820652776102999166869953170315965558474401):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=7, n=619664992585427611791050679609026893099690427802915014534984716820652776102999166869953170315965558474401):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "ShortestPath:1", + "sat": "def sat(path: List[int], weights=[{3: 210, 0: 513, 1: 66, 5: 612}, {0: 794, 1: 111, 3: 598}, {4: 295, 0: 601}, {}, {3: 452, 0: 689, 5: 124, 1: 406}, {2: 289, 5: 660, 3: 498}], bound=66):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{3: 210, 0: 513, 1: 66, 5: 612}, {0: 794, 1: 111, 3: 598}, {4: 295, 0: 601}, {}, {3: 452, 0: 689, 5: 124, 1: 406}, {2: 289, 5: 660, 3: 498}], bound=66):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_4", - "sat": "def sat(x: int, a=3, n=273892744995340833777347939263771534786080723599733441):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=3, n=273892744995340833777347939263771534786080723599733441):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "ShortestPath:2", + "sat": "def sat(path: List[int], weights=[{25: 594, 24: 349}, {}, {29: 745}, {}, {7: 245}, {9: 384}, {1: 490, 21: 253, 22: 904, 13: 526}, {4: 452, 27: 179, 28: 673}, {22: 30, 29: 307, 8: 104}, {12: 399, 0: 792}, {}, {}, {20: 349, 6: 53}, {}, {}, {}, {14: 223}, {23: 705}, {13: 903, 21: 159}, {}, {27: 144, 28: 181}, {26: 922, 20: 241}, {}, {24: 966, 29: 78}, {26: 107}, {1: 121}, {18: 898, 0: 280, 12: 425}, {}, {18: 750, 25: 440, 28: 152, 29: 109, 6: 330}, {23: 298}], bound=715):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{25: 594, 24: 349}, {}, {29: 745}, {}, {7: 245}, {9: 384}, {1: 490, 21: 253, 22: 904, 13: 526}, {4: 452, 27: 179, 28: 673}, {22: 30, 29: 307, 8: 104}, {12: 399, 0: 792}, {}, {}, {20: 349, 6: 53}, {}, {}, {}, {14: 223}, {23: 705}, {13: 903, 21: 159}, {}, {27: 144, 28: 181}, {26: 922, 20: 241}, {}, {24: 966, 29: 78}, {26: 107}, {1: 121}, {18: 898, 0: 280, 12: 425}, {}, {18: 750, 25: 440, 28: 152, 29: 109, 6: 330}, {23: 298}], bound=715):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_5", - "sat": "def sat(x: int, a=1, n=1):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=1, n=1):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "ShortestPath:3", + "sat": "def sat(path: List[int], weights=[{1: 239}, {0: 602, 2: 280}, {2: 293, 0: 816, 3: 925}, {}], bound=239):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{1: 239}, {0: 602, 2: 280}, {2: 293, 0: 816, 3: 925}, {}], bound=239):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_6", - "sat": "def sat(x: int, a=7, n=422172910905251082898342892507708254420575225812469392211799592546100439414212081173038488709684817505454589853340690711478675172759132571155298594457803891890861791746265193607):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=7, n=422172910905251082898342892507708254420575225812469392211799592546100439414212081173038488709684817505454589853340690711478675172759132571155298594457803891890861791746265193607):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "ShortestPath:4", + "sat": "def sat(path: List[int], weights=[{1: 996, 2: 237, 4: 264}, {4: 329, 5: 12, 2: 542, 0: 419}, {2: 170, 6: 339, 5: 211}, {1: 714, 5: 885, 3: 640}, {5: 652, 4: 3, 3: 26, 6: 74}, {0: 647, 5: 346}, {2: 297, 6: 358, 3: 636, 0: 722, 4: 942}], bound=996):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{1: 996, 2: 237, 4: 264}, {4: 329, 5: 12, 2: 542, 0: 419}, {2: 170, 6: 339, 5: 211}, {1: 714, 5: 885, 3: 640}, {5: 652, 4: 3, 3: 26, 6: 74}, {0: 647, 5: 346}, {2: 297, 6: 358, 3: 636, 0: 722, 4: 942}], bound=996):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_7", - "sat": "def sat(x: int, a=3, n=696198609130885597695136021593547814689632716312296141651066450089):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=3, n=696198609130885597695136021593547814689632716312296141651066450089):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "UnweightedShortestPath:0", + "sat": "def sat(path: List[int], edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_8", - "sat": "def sat(x: int, a=3, n=443426488243037769948249630619149892803):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=3, n=443426488243037769948249630619149892803):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "UnweightedShortestPath:1", + "sat": "def sat(path: List[int], edges=[[12, 4], [33, 15], [37, 12], [11, 1], [34, 19], [42, 36], [2, 38], [6, 25], [29, 25], [30, 6], [16, 31], [10, 41], [15, 2], [3, 19], [1, 26], [17, 17], [19, 4], [0, 6], [42, 5], [11, 13], [22, 15], [39, 11], [35, 34], [39, 20], [7, 31], [38, 27], [9, 30], [31, 25], [0, 9], [13, 34], [31, 34], [19, 42], [37, 32], [4, 13], [11, 43], [14, 0], [22, 41], [20, 17], [0, 15], [13, 4], [20, 6], [34, 42], [42, 10], [32, 19], [41, 8], [26, 42], [0, 13], [28, 42], [9, 0], [32, 26], [6, 4], [27, 19], [37, 9], [7, 6], [25, 14], [23, 14], [31, 39], [18, 27], [34, 36], [24, 16], [24, 31], [16, 17], [2, 4], [34, 40], [28, 6], [41, 9], [17, 18], [43, 11], [11, 39], [43, 29], [1, 19], [27, 27], [4, 42], [0, 16], [16, 14], [40, 22], [22, 22], [38, 16], [3, 34], [33, 23], [2, 18], [3, 11], [4, 5], [18, 3], [23, 11], [41, 22], [7, 26], [31, 42], [35, 33], [15, 28], [34, 10], [36, 3], [9, 38], [17, 5], [3, 9], [37, 21], [36, 1], [25, 6], [22, 12], [42, 3], [16, 32], [0, 11], [24, 33], [15, 31], [18, 34], [11, 8], [30, 41], [19, 19], [4, 11], [22, 16], [1, 13], [6, 22], [12, 30], [19, 15], [3, 21], [38, 29], [32, 39], [1, 17], [16, 20], [10, 39], [32, 27], [37, 6], [18, 18], [22, 32], [31, 32], [24, 32], [22, 25], [38, 18], [38, 21], [39, 12], [9, 17], [10, 42], [29, 36], [34, 23], [27, 29], [17, 24], [24, 28], [31, 23], [28, 7], [5, 2], [24, 26], [27, 13], [43, 19], [37, 36], [2, 13], [10, 11], [30, 11], [29, 32], [4, 24], [17, 27], [21, 2], [24, 43], [26, 37], [16, 6], [43, 35], [42, 27], [26, 12], [39, 3], [38, 25], [20, 5], [36, 8], [25, 42], [27, 40], [39, 23], [6, 12], [27, 32], [12, 34], [2, 5], [40, 35], [15, 12], [22, 29], [21, 11], [0, 22], [13, 23], [27, 4], [35, 24], [32, 29], [4, 14], [9, 7], [32, 11], [11, 26], [26, 41], [2, 16], [38, 23], [30, 29], [6, 31], [1, 34], [4, 39], [24, 3], [25, 22], [9, 14], [33, 26], [34, 38], [35, 29], [32, 38], [5, 42], [42, 24], [15, 38], [41, 14], [39, 9], [4, 36], [21, 24], [36, 9]], u=14, v=1, bound=4):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(u=14, v=1, edges=[[12, 4], [33, 15], [37, 12], [11, 1], [34, 19], [42, 36], [2, 38], [6, 25], [29, 25], [30, 6], [16, 31], [10, 41], [15, 2], [3, 19], [1, 26], [17, 17], [19, 4], [0, 6], [42, 5], [11, 13], [22, 15], [39, 11], [35, 34], [39, 20], [7, 31], [38, 27], [9, 30], [31, 25], [0, 9], [13, 34], [31, 34], [19, 42], [37, 32], [4, 13], [11, 43], [14, 0], [22, 41], [20, 17], [0, 15], [13, 4], [20, 6], [34, 42], [42, 10], [32, 19], [41, 8], [26, 42], [0, 13], [28, 42], [9, 0], [32, 26], [6, 4], [27, 19], [37, 9], [7, 6], [25, 14], [23, 14], [31, 39], [18, 27], [34, 36], [24, 16], [24, 31], [16, 17], [2, 4], [34, 40], [28, 6], [41, 9], [17, 18], [43, 11], [11, 39], [43, 29], [1, 19], [27, 27], [4, 42], [0, 16], [16, 14], [40, 22], [22, 22], [38, 16], [3, 34], [33, 23], [2, 18], [3, 11], [4, 5], [18, 3], [23, 11], [41, 22], [7, 26], [31, 42], [35, 33], [15, 28], [34, 10], [36, 3], [9, 38], [17, 5], [3, 9], [37, 21], [36, 1], [25, 6], [22, 12], [42, 3], [16, 32], [0, 11], [24, 33], [15, 31], [18, 34], [11, 8], [30, 41], [19, 19], [4, 11], [22, 16], [1, 13], [6, 22], [12, 30], [19, 15], [3, 21], [38, 29], [32, 39], [1, 17], [16, 20], [10, 39], [32, 27], [37, 6], [18, 18], [22, 32], [31, 32], [24, 32], [22, 25], [38, 18], [38, 21], [39, 12], [9, 17], [10, 42], [29, 36], [34, 23], [27, 29], [17, 24], [24, 28], [31, 23], [28, 7], [5, 2], [24, 26], [27, 13], [43, 19], [37, 36], [2, 13], [10, 11], [30, 11], [29, 32], [4, 24], [17, 27], [21, 2], [24, 43], [26, 37], [16, 6], [43, 35], [42, 27], [26, 12], [39, 3], [38, 25], [20, 5], [36, 8], [25, 42], [27, 40], [39, 23], [6, 12], [27, 32], [12, 34], [2, 5], [40, 35], [15, 12], [22, 29], [21, 11], [0, 22], [13, 23], [27, 4], [35, 24], [32, 29], [4, 14], [9, 7], [32, 11], [11, 26], [26, 41], [2, 16], [38, 23], [30, 29], [6, 31], [1, 34], [4, 39], [24, 3], [25, 22], [9, 14], [33, 26], [34, 38], [35, 29], [32, 38], [5, 42], [42, 24], [15, 38], [41, 14], [39, 9], [4, 36], [21, 24], [36, 9]], bound=4):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "IntegerLog_9", - "sat": "def sat(x: int, a=7, n=3927513814852118215253663462745985104429523654386747748367596265637242329346407):\n \"\"\"Find an integer exponent x such that a^x = n\"\"\"\n return a ** x == n", - "sols": [ - "def sol(a=7, n=3927513814852118215253663462745985104429523654386747748367596265637242329346407):\n m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + "name": "UnweightedShortestPath:2", + "sat": "def sat(path: List[int], edges=[[2, 6], [6, 2], [2, 5], [4, 7], [4, 1], [0, 2], [3, 3], [6, 1], [4, 0], [1, 3], [5, 2], [4, 2], [6, 7], [2, 2], [2, 3], [4, 4], [5, 0], [0, 7], [4, 3], [6, 4], [0, 0], [3, 0], [2, 7], [1, 7], [3, 2], [1, 2], [2, 4], [7, 5]], u=1, v=2, bound=2):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(u=1, v=2, edges=[[2, 6], [6, 2], [2, 5], [4, 7], [4, 1], [0, 2], [3, 3], [6, 1], [4, 0], [1, 3], [5, 2], [4, 2], [6, 7], [2, 2], [2, 3], [4, 4], [5, 0], [0, 7], [4, 3], [6, 4], [0, 0], [3, 0], [2, 7], [1, 7], [3, 2], [1, 2], [2, 4], [7, 5]], bound=2):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "CubeRoot_0", - "sat": "def sat(x: int, n=42714774173606970182754018064350848294149432972747296768):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=42714774173606970182754018064350848294149432972747296768): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "UnweightedShortestPath:3", + "sat": "def sat(path: List[int], edges=[[6, 0], [6, 2], [6, 5], [6, 4], [1, 4], [4, 3], [5, 3], [4, 4], [3, 1], [4, 6], [4, 2], [0, 2], [6, 6], [2, 3], [1, 0], [1, 5], [0, 0], [5, 4], [0, 1], [1, 2], [0, 4], [2, 5], [3, 0]], u=4, v=2, bound=2):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(u=4, v=2, edges=[[6, 0], [6, 2], [6, 5], [6, 4], [1, 4], [4, 3], [5, 3], [4, 4], [3, 1], [4, 6], [4, 2], [0, 2], [6, 6], [2, 3], [1, 0], [1, 5], [0, 0], [5, 4], [0, 1], [1, 2], [0, 4], [2, 5], [3, 0]], bound=2):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "CubeRoot_1", - "sat": "def sat(x: int, n=-469541313747981125):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=-469541313747981125): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "UnweightedShortestPath:4", + "sat": "def sat(path: List[int], edges=[[1, 1], [2, 0], [1, 0], [2, 2]], u=1, v=1, bound=1):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(u=1, v=1, edges=[[1, 1], [2, 0], [1, 0], [2, 2]], bound=1):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 }, { - "name": "CubeRoot_2", - "sat": "def sat(x: int, n=963966660871383014273727008911874274513660721639801945125024924885086622296):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=963966660871383014273727008911874274513660721639801945125024924885086622296): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "AnyPath:0", + "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 }, { - "name": "CubeRoot_3", - "sat": "def sat(x: int, n=-858580967744947820888627092732831059532555665642825043140896515384975483968):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=-858580967744947820888627092732831059532555665642825043140896515384975483968): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "AnyPath:1", + "sat": "def sat(path: List[int], edges=[[16, 8], [13, 33], [29, 37], [25, 10], [3, 33], [43, 10], [19, 9], [26, 16], [0, 9], [18, 36], [40, 32], [24, 10], [25, 35], [15, 14], [18, 2], [17, 5], [15, 26], [28, 28], [4, 39], [26, 9], [35, 22], [42, 11], [44, 13], [6, 34], [33, 0], [36, 34], [41, 34], [31, 1], [41, 27], [20, 43], [30, 33], [15, 18], [8, 20], [31, 14], [21, 33], [40, 28], [35, 39], [19, 14], [35, 10], [3, 34], [14, 11], [34, 36], [29, 3], [20, 33], [27, 14], [5, 29], [15, 6], [21, 20], [36, 1], [30, 40], [44, 6], [24, 43], [24, 30], [3, 16], [8, 34], [15, 36], [33, 36], [19, 17], [35, 17], [20, 29], [0, 27], [36, 38], [1, 0], [43, 18], [5, 36], [22, 10], [5, 32], [11, 34], [4, 15], [4, 9], [4, 6], [24, 12], [8, 27], [42, 38], [25, 2], [2, 12], [1, 34], [36, 22], [24, 42], [4, 18], [30, 13], [16, 44], [4, 21], [22, 35], [33, 32], [24, 26], [21, 44]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[16, 8], [13, 33], [29, 37], [25, 10], [3, 33], [43, 10], [19, 9], [26, 16], [0, 9], [18, 36], [40, 32], [24, 10], [25, 35], [15, 14], [18, 2], [17, 5], [15, 26], [28, 28], [4, 39], [26, 9], [35, 22], [42, 11], [44, 13], [6, 34], [33, 0], [36, 34], [41, 34], [31, 1], [41, 27], [20, 43], [30, 33], [15, 18], [8, 20], [31, 14], [21, 33], [40, 28], [35, 39], [19, 14], [35, 10], [3, 34], [14, 11], [34, 36], [29, 3], [20, 33], [27, 14], [5, 29], [15, 6], [21, 20], [36, 1], [30, 40], [44, 6], [24, 43], [24, 30], [3, 16], [8, 34], [15, 36], [33, 36], [19, 17], [35, 17], [20, 29], [0, 27], [36, 38], [1, 0], [43, 18], [5, 36], [22, 10], [5, 32], [11, 34], [4, 15], [4, 9], [4, 6], [24, 12], [8, 27], [42, 38], [25, 2], [2, 12], [1, 34], [36, 22], [24, 42], [4, 18], [30, 13], [16, 44], [4, 21], [22, 35], [33, 32], [24, 26], [21, 44]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 }, { - "name": "CubeRoot_4", - "sat": "def sat(x: int, n=-1649412660748961726580117293638546881248424191676176072):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=-1649412660748961726580117293638546881248424191676176072): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "AnyPath:2", + "sat": "def sat(path: List[int], edges=[[0, 0]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 0]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 }, { - "name": "CubeRoot_5", - "sat": "def sat(x: int, n=136000466113128777207793400499636683512375):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=136000466113128777207793400499636683512375): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "AnyPath:3", + "sat": "def sat(path: List[int], edges=[[2, 33], [39, 59], [22, 21], [55, 39], [34, 13], [28, 62], [34, 56], [41, 23], [52, 39], [27, 62], [19, 12], [14, 63], [48, 1], [53, 1], [47, 55], [43, 35], [13, 51], [18, 30], [7, 17], [25, 52], [35, 46], [16, 45], [7, 22], [42, 40], [35, 41], [21, 52], [35, 43], [22, 30], [20, 47], [48, 25], [32, 11], [38, 35], [39, 35], [34, 62], [19, 32], [15, 51], [62, 29], [54, 26], [1, 6], [42, 51], [26, 62], [18, 8], [47, 40], [30, 41], [42, 15], [35, 36], [12, 55], [38, 53], [52, 37], [4, 44], [13, 61], [2, 58], [9, 48], [2, 11], [52, 0], [11, 35], [33, 7], [49, 40], [21, 46], [1, 30], [60, 34], [36, 46], [8, 52], [43, 58], [53, 63], [61, 16], [50, 16], [33, 44], [23, 26], [27, 16], [52, 18], [59, 1], [29, 44], [37, 57], [25, 2], [3, 15], [33, 19], [22, 6], [59, 51], [58, 32], [46, 37], [15, 9], [1, 35], [48, 6], [15, 59], [58, 28], [6, 24], [4, 38], [37, 20], [52, 28], [43, 40], [28, 39], [58, 31], [62, 35], [63, 11], [24, 40], [44, 38], [0, 44], [57, 11], [0, 16], [41, 1], [62, 55], [8, 51], [5, 8], [46, 26], [40, 6], [45, 42], [24, 32], [19, 31], [6, 55], [30, 2], [43, 57], [25, 48], [53, 31], [29, 13], [63, 39], [37, 46], [32, 40], [16, 16], [53, 59], [11, 57], [33, 20], [19, 11], [47, 51], [50, 15], [19, 36]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[2, 33], [39, 59], [22, 21], [55, 39], [34, 13], [28, 62], [34, 56], [41, 23], [52, 39], [27, 62], [19, 12], [14, 63], [48, 1], [53, 1], [47, 55], [43, 35], [13, 51], [18, 30], [7, 17], [25, 52], [35, 46], [16, 45], [7, 22], [42, 40], [35, 41], [21, 52], [35, 43], [22, 30], [20, 47], [48, 25], [32, 11], [38, 35], [39, 35], [34, 62], [19, 32], [15, 51], [62, 29], [54, 26], [1, 6], [42, 51], [26, 62], [18, 8], [47, 40], [30, 41], [42, 15], [35, 36], [12, 55], [38, 53], [52, 37], [4, 44], [13, 61], [2, 58], [9, 48], [2, 11], [52, 0], [11, 35], [33, 7], [49, 40], [21, 46], [1, 30], [60, 34], [36, 46], [8, 52], [43, 58], [53, 63], [61, 16], [50, 16], [33, 44], [23, 26], [27, 16], [52, 18], [59, 1], [29, 44], [37, 57], [25, 2], [3, 15], [33, 19], [22, 6], [59, 51], [58, 32], [46, 37], [15, 9], [1, 35], [48, 6], [15, 59], [58, 28], [6, 24], [4, 38], [37, 20], [52, 28], [43, 40], [28, 39], [58, 31], [62, 35], [63, 11], [24, 40], [44, 38], [0, 44], [57, 11], [0, 16], [41, 1], [62, 55], [8, 51], [5, 8], [46, 26], [40, 6], [45, 42], [24, 32], [19, 31], [6, 55], [30, 2], [43, 57], [25, 48], [53, 31], [29, 13], [63, 39], [37, 46], [32, 40], [16, 16], [53, 59], [11, 57], [33, 20], [19, 11], [47, 51], [50, 15], [19, 36]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 }, { - "name": "CubeRoot_6", - "sat": "def sat(x: int, n=-19569459995573298470418850728885331622027):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=-19569459995573298470418850728885331622027): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "AnyPath:4", + "sat": "def sat(path: List[int], edges=[[3, 5], [2, 1], [4, 5], [3, 6], [6, 7], [5, 3], [4, 3], [6, 2], [5, 2], [7, 0], [3, 4], [0, 5], [0, 0], [1, 0], [0, 2], [3, 1]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[3, 5], [2, 1], [4, 5], [3, 6], [6, 7], [5, 3], [4, 3], [6, 2], [5, 2], [7, 0], [3, 4], [0, 5], [0, 0], [1, 0], [0, 2], [3, 1]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 }, { - "name": "CubeRoot_7", - "sat": "def sat(x: int, n=653962786987239225717840966462586579533169098577519549137735730264):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=653962786987239225717840966462586579533169098577519549137735730264): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "EvenPath:0", + "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "", + "weight": 1.0 }, { - "name": "CubeRoot_8", - "sat": "def sat(x: int, n=6859):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=6859): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "EvenPath:1", + "sat": "def sat(path: List[int], edges=[[3, 2], [2, 1], [0, 2], [1, 0], [2, 2], [2, 3], [2, 0]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[3, 2], [2, 1], [0, 2], [1, 0], [2, 2], [2, 3], [2, 0]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "", + "weight": 1.0 }, { - "name": "CubeRoot_9", - "sat": "def sat(x: int, n=-53842257566437335373707978104):\n \"\"\"Find an integer that when cubed is n\"\"\"\n return x ** 3 == n", - "sols": [ - "def sol(n=-53842257566437335373707978104): # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + "name": "EvenPath:2", + "sat": "def sat(path: List[int], edges=[[5, 15], [51, 42], [23, 5], [36, 2], [18, 43], [8, 47], [37, 6], [20, 25], [13, 25], [17, 2], [53, 30], [4, 50], [25, 47], [27, 5], [47, 7], [6, 18], [16, 30], [51, 3], [6, 13], [3, 12], [30, 13], [14, 43], [0, 5], [20, 7], [8, 3], [29, 55], [13, 11], [18, 39], [37, 13], [25, 8], [45, 30], [32, 8], [55, 43], [34, 42], [31, 21], [26, 19], [18, 1], [51, 35], [51, 51], [53, 22], [8, 23], [29, 21], [0, 44], [16, 38], [7, 16], [22, 45], [37, 16], [54, 20], [24, 13], [47, 37], [11, 10], [31, 31], [37, 55], [18, 6], [27, 43], [51, 38], [33, 38], [31, 3], [15, 35], [42, 11], [53, 4], [51, 24], [14, 27], [13, 18], [9, 55], [29, 0], [50, 31], [16, 18], [46, 3], [42, 44], [25, 12], [50, 10], [28, 51], [3, 25], [18, 26], [16, 0], [15, 37], [45, 48], [23, 50], [1, 15], [29, 35], [48, 32], [27, 10], [39, 49], [0, 36], [46, 2], [51, 29], [39, 6], [51, 33], [30, 54], [53, 2], [26, 6], [6, 4], [15, 2], [35, 27], [6, 36], [53, 19], [49, 54], [4, 44], [53, 6], [47, 41], [37, 21], [50, 48], [42, 47], [6, 2], [5, 46], [2, 50], [39, 29], [11, 42], [46, 33], [11, 22]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[5, 15], [51, 42], [23, 5], [36, 2], [18, 43], [8, 47], [37, 6], [20, 25], [13, 25], [17, 2], [53, 30], [4, 50], [25, 47], [27, 5], [47, 7], [6, 18], [16, 30], [51, 3], [6, 13], [3, 12], [30, 13], [14, 43], [0, 5], [20, 7], [8, 3], [29, 55], [13, 11], [18, 39], [37, 13], [25, 8], [45, 30], [32, 8], [55, 43], [34, 42], [31, 21], [26, 19], [18, 1], [51, 35], [51, 51], [53, 22], [8, 23], [29, 21], [0, 44], [16, 38], [7, 16], [22, 45], [37, 16], [54, 20], [24, 13], [47, 37], [11, 10], [31, 31], [37, 55], [18, 6], [27, 43], [51, 38], [33, 38], [31, 3], [15, 35], [42, 11], [53, 4], [51, 24], [14, 27], [13, 18], [9, 55], [29, 0], [50, 31], [16, 18], [46, 3], [42, 44], [25, 12], [50, 10], [28, 51], [3, 25], [18, 26], [16, 0], [15, 37], [45, 48], [23, 50], [1, 15], [29, 35], [48, 32], [27, 10], [39, 49], [0, 36], [46, 2], [51, 29], [39, 6], [51, 33], [30, 54], [53, 2], [26, 6], [6, 4], [15, 2], [35, 27], [6, 36], [53, 19], [49, 54], [4, 44], [53, 6], [47, 41], [37, 21], [50, 48], [42, 47], [6, 2], [5, 46], [2, 50], [39, 29], [11, 42], [46, 33], [11, 22]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "", + "weight": 1.0 }, { - "name": "HexPrimes_0", - "sat": "def sat(primes: List[bool], n=\"A4D4455214122CE192CCBE3\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"A4D4455214122CE192CCBE3\"):\n return [c in \"2357BD\" for c in n]" + "name": "EvenPath:3", + "sat": "def sat(path: List[int], edges=[[13, 29], [70, 66], [46, 37], [1, 57], [37, 1], [43, 0], [71, 49], [49, 49], [1, 0], [13, 38], [34, 7], [56, 74], [44, 74], [35, 54], [41, 59], [53, 47], [48, 28], [52, 46], [36, 22], [74, 72], [43, 36], [65, 24], [14, 67], [64, 28], [8, 39], [71, 14], [22, 24], [20, 43], [67, 21], [12, 39], [40, 41], [54, 19], [26, 69], [48, 14], [24, 25], [24, 16], [45, 62], [43, 57], [71, 1], [31, 24], [27, 66], [64, 18], [73, 33], [25, 22], [31, 60], [67, 3], [4, 44], [41, 55], [0, 23], [7, 14], [46, 50], [40, 53], [4, 33], [8, 12], [64, 55], [19, 52], [52, 62], [3, 42], [33, 10], [67, 10], [1, 33], [39, 18], [18, 7], [2, 47], [29, 55], [29, 42], [44, 67], [55, 55], [25, 42], [39, 53], [59, 21], [44, 50], [31, 30], [60, 71], [49, 9], [20, 16], [37, 68], [58, 73], [41, 7], [30, 74], [61, 31], [71, 42], [72, 19], [66, 33], [24, 33], [57, 40], [3, 28], [59, 64], [16, 12], [72, 20], [3, 5], [59, 52], [70, 8], [71, 13], [20, 71], [64, 31], [22, 27], [53, 36], [49, 23], [40, 4], [55, 68], [32, 12], [21, 15], [57, 63], [8, 70], [72, 56], [33, 3], [41, 28], [4, 0], [44, 10], [33, 2], [36, 24], [59, 58], [45, 33], [61, 66], [21, 48], [10, 54], [46, 13], [40, 25], [28, 6], [65, 53], [0, 53], [51, 22], [71, 17], [52, 9], [30, 34], [68, 64], [54, 8], [35, 13], [64, 54], [45, 67], [47, 22], [69, 52], [18, 73], [21, 60], [72, 29], [7, 36], [68, 56], [17, 14], [44, 54], [46, 29], [72, 67], [17, 53], [54, 51], [26, 46], [65, 21], [27, 3], [50, 5]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[13, 29], [70, 66], [46, 37], [1, 57], [37, 1], [43, 0], [71, 49], [49, 49], [1, 0], [13, 38], [34, 7], [56, 74], [44, 74], [35, 54], [41, 59], [53, 47], [48, 28], [52, 46], [36, 22], [74, 72], [43, 36], [65, 24], [14, 67], [64, 28], [8, 39], [71, 14], [22, 24], [20, 43], [67, 21], [12, 39], [40, 41], [54, 19], [26, 69], [48, 14], [24, 25], [24, 16], [45, 62], [43, 57], [71, 1], [31, 24], [27, 66], [64, 18], [73, 33], [25, 22], [31, 60], [67, 3], [4, 44], [41, 55], [0, 23], [7, 14], [46, 50], [40, 53], [4, 33], [8, 12], [64, 55], [19, 52], [52, 62], [3, 42], [33, 10], [67, 10], [1, 33], [39, 18], [18, 7], [2, 47], [29, 55], [29, 42], [44, 67], [55, 55], [25, 42], [39, 53], [59, 21], [44, 50], [31, 30], [60, 71], [49, 9], [20, 16], [37, 68], [58, 73], [41, 7], [30, 74], [61, 31], [71, 42], [72, 19], [66, 33], [24, 33], [57, 40], [3, 28], [59, 64], [16, 12], [72, 20], [3, 5], [59, 52], [70, 8], [71, 13], [20, 71], [64, 31], [22, 27], [53, 36], [49, 23], [40, 4], [55, 68], [32, 12], [21, 15], [57, 63], [8, 70], [72, 56], [33, 3], [41, 28], [4, 0], [44, 10], [33, 2], [36, 24], [59, 58], [45, 33], [61, 66], [21, 48], [10, 54], [46, 13], [40, 25], [28, 6], [65, 53], [0, 53], [51, 22], [71, 17], [52, 9], [30, 34], [68, 64], [54, 8], [35, 13], [64, 54], [45, 67], [47, 22], [69, 52], [18, 73], [21, 60], [72, 29], [7, 36], [68, 56], [17, 14], [44, 54], [46, 29], [72, 67], [17, 53], [54, 51], [26, 46], [65, 21], [27, 3], [50, 5]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "", + "weight": 1.0 }, { - "name": "HexPrimes_1", - "sat": "def sat(primes: List[bool], n=\"a0eebda812c4c27a97d35f1\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"a0eebda812c4c27a97d35f1\"):\n return [c in \"2357BD\" for c in n]" + "name": "EvenPath:4", + "sat": "def sat(path: List[int], edges=[[67, 92], [18, 52], [25, 21], [83, 58], [36, 36], [26, 63], [48, 15], [53, 32], [62, 30], [41, 21], [91, 25], [82, 79], [33, 58], [65, 81], [57, 57], [62, 36], [85, 24], [14, 19], [58, 11], [20, 31], [76, 82], [92, 37], [73, 88], [90, 37], [68, 18], [70, 18], [45, 65], [45, 78], [87, 36], [41, 72], [66, 4], [25, 58], [18, 16], [72, 68], [21, 0], [44, 8], [51, 21], [30, 15], [18, 90], [75, 47], [42, 7], [13, 13], [27, 46], [78, 39], [71, 28], [85, 39], [56, 52], [60, 37], [37, 18], [82, 83], [84, 9], [31, 54], [81, 32], [46, 82], [10, 66], [85, 71], [3, 5], [15, 18], [83, 64], [9, 50], [60, 70], [7, 13], [81, 63], [32, 6], [18, 80], [22, 34], [60, 0], [88, 72], [9, 19], [74, 0], [87, 22], [41, 17], [66, 80], [33, 9], [71, 46], [23, 79], [64, 44], [40, 67], [78, 4], [8, 31], [15, 41], [42, 92], [22, 28], [57, 84], [69, 65], [35, 16], [1, 10], [7, 82], [62, 52], [8, 12], [51, 12], [5, 2], [83, 30], [76, 83], [0, 27], [30, 80], [33, 14], [39, 12], [51, 78], [30, 47], [25, 26], [11, 63], [52, 24], [32, 49], [0, 74], [51, 16], [1, 16], [14, 90], [49, 74], [69, 14], [72, 30], [61, 31], [54, 20], [46, 78], [4, 50], [13, 37], [61, 1], [4, 35], [29, 70], [20, 89], [28, 6], [74, 9], [86, 53], [58, 6], [57, 91], [10, 40], [15, 74], [23, 60], [5, 37], [50, 68], [78, 22], [90, 59], [74, 21], [80, 71], [92, 82], [42, 43], [68, 74], [43, 55], [67, 90], [87, 68], [40, 2], [55, 68], [52, 30], [10, 21], [44, 1], [39, 9], [12, 18], [61, 38], [65, 37], [10, 12], [21, 10], [81, 3], [65, 20], [31, 25], [59, 77], [43, 59], [75, 75], [71, 13], [17, 37], [31, 13], [6, 33], [24, 40], [52, 70], [70, 5], [4, 8], [20, 29], [11, 10], [43, 67], [11, 80], [49, 19], [81, 64], [44, 28], [18, 20], [91, 91], [90, 92], [81, 16], [31, 81], [7, 81], [54, 53], [65, 16], [91, 32]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[67, 92], [18, 52], [25, 21], [83, 58], [36, 36], [26, 63], [48, 15], [53, 32], [62, 30], [41, 21], [91, 25], [82, 79], [33, 58], [65, 81], [57, 57], [62, 36], [85, 24], [14, 19], [58, 11], [20, 31], [76, 82], [92, 37], [73, 88], [90, 37], [68, 18], [70, 18], [45, 65], [45, 78], [87, 36], [41, 72], [66, 4], [25, 58], [18, 16], [72, 68], [21, 0], [44, 8], [51, 21], [30, 15], [18, 90], [75, 47], [42, 7], [13, 13], [27, 46], [78, 39], [71, 28], [85, 39], [56, 52], [60, 37], [37, 18], [82, 83], [84, 9], [31, 54], [81, 32], [46, 82], [10, 66], [85, 71], [3, 5], [15, 18], [83, 64], [9, 50], [60, 70], [7, 13], [81, 63], [32, 6], [18, 80], [22, 34], [60, 0], [88, 72], [9, 19], [74, 0], [87, 22], [41, 17], [66, 80], [33, 9], [71, 46], [23, 79], [64, 44], [40, 67], [78, 4], [8, 31], [15, 41], [42, 92], [22, 28], [57, 84], [69, 65], [35, 16], [1, 10], [7, 82], [62, 52], [8, 12], [51, 12], [5, 2], [83, 30], [76, 83], [0, 27], [30, 80], [33, 14], [39, 12], [51, 78], [30, 47], [25, 26], [11, 63], [52, 24], [32, 49], [0, 74], [51, 16], [1, 16], [14, 90], [49, 74], [69, 14], [72, 30], [61, 31], [54, 20], [46, 78], [4, 50], [13, 37], [61, 1], [4, 35], [29, 70], [20, 89], [28, 6], [74, 9], [86, 53], [58, 6], [57, 91], [10, 40], [15, 74], [23, 60], [5, 37], [50, 68], [78, 22], [90, 59], [74, 21], [80, 71], [92, 82], [42, 43], [68, 74], [43, 55], [67, 90], [87, 68], [40, 2], [55, 68], [52, 30], [10, 21], [44, 1], [39, 9], [12, 18], [61, 38], [65, 37], [10, 12], [21, 10], [81, 3], [65, 20], [31, 25], [59, 77], [43, 59], [75, 75], [71, 13], [17, 37], [31, 13], [6, 33], [24, 40], [52, 70], [70, 5], [4, 8], [20, 29], [11, 10], [43, 67], [11, 80], [49, 19], [81, 64], [44, 28], [18, 20], [91, 91], [90, 92], [81, 16], [31, 81], [7, 81], [54, 53], [65, 16], [91, 32]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "", + "weight": 1.0 }, { - "name": "HexPrimes_2", - "sat": "def sat(primes: List[bool], n=\"4a4a5904aaa94eb2\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"4a4a5904aaa94eb2\"):\n return [c in \"2357BD\" for c in n]" + "name": "OddPath:0", + "sat": "def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 }, { - "name": "HexPrimes_3", - "sat": "def sat(primes: List[bool], n=\"b696e7352d58ee\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"b696e7352d58ee\"):\n return [c in \"2357BD\" for c in n]" + "name": "OddPath:1", + "sat": "def sat(p: List[int], edges=[[1, 6], [2, 3], [2, 7], [0, 8], [7, 8], [7, 2], [1, 5], [8, 7], [7, 0], [0, 0], [8, 1], [5, 7], [4, 7], [6, 1], [4, 4], [7, 4]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[1, 6], [2, 3], [2, 7], [0, 8], [7, 8], [7, 2], [1, 5], [8, 7], [7, 0], [0, 0], [8, 1], [5, 7], [4, 7], [6, 1], [4, 4], [7, 4]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 }, { - "name": "HexPrimes_4", - "sat": "def sat(primes: List[bool], n=\"1a8dcd03abe2cdc\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"1a8dcd03abe2cdc\"):\n return [c in \"2357BD\" for c in n]" + "name": "OddPath:2", + "sat": "def sat(p: List[int], edges=[[40, 31], [16, 32], [41, 10], [14, 9], [36, 26], [14, 12], [22, 6], [36, 6], [13, 22], [0, 34], [6, 28], [27, 22], [31, 5], [2, 3], [34, 37], [17, 14], [1, 4], [22, 26], [32, 18], [20, 10], [28, 17], [2, 22], [22, 30], [36, 41], [7, 35], [24, 29], [31, 31], [26, 39], [14, 32], [33, 27], [33, 9], [30, 37], [40, 14], [19, 17], [15, 11], [7, 40], [6, 36], [20, 19], [7, 12], [17, 25], [14, 24], [34, 25], [27, 34], [35, 41], [34, 3], [25, 12], [34, 29], [21, 23], [2, 12], [25, 26], [28, 16], [17, 2], [15, 28], [29, 0], [32, 16], [13, 29], [23, 26], [3, 11], [39, 3], [40, 16], [22, 39], [12, 30], [12, 24], [38, 24], [5, 1], [21, 39], [33, 39], [29, 36], [23, 40], [34, 20], [35, 10], [13, 7], [10, 2], [32, 26], [37, 4], [36, 21], [1, 18], [23, 11], [19, 11], [35, 5], [10, 32], [9, 17], [21, 2]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[40, 31], [16, 32], [41, 10], [14, 9], [36, 26], [14, 12], [22, 6], [36, 6], [13, 22], [0, 34], [6, 28], [27, 22], [31, 5], [2, 3], [34, 37], [17, 14], [1, 4], [22, 26], [32, 18], [20, 10], [28, 17], [2, 22], [22, 30], [36, 41], [7, 35], [24, 29], [31, 31], [26, 39], [14, 32], [33, 27], [33, 9], [30, 37], [40, 14], [19, 17], [15, 11], [7, 40], [6, 36], [20, 19], [7, 12], [17, 25], [14, 24], [34, 25], [27, 34], [35, 41], [34, 3], [25, 12], [34, 29], [21, 23], [2, 12], [25, 26], [28, 16], [17, 2], [15, 28], [29, 0], [32, 16], [13, 29], [23, 26], [3, 11], [39, 3], [40, 16], [22, 39], [12, 30], [12, 24], [38, 24], [5, 1], [21, 39], [33, 39], [29, 36], [23, 40], [34, 20], [35, 10], [13, 7], [10, 2], [32, 26], [37, 4], [36, 21], [1, 18], [23, 11], [19, 11], [35, 5], [10, 32], [9, 17], [21, 2]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 }, { - "name": "HexPrimes_5", - "sat": "def sat(primes: List[bool], n=\"72d77\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"72d77\"):\n return [c in \"2357BD\" for c in n]" + "name": "OddPath:3", + "sat": "def sat(p: List[int], edges=[[6, 6], [3, 6], [5, 0], [7, 16], [9, 12], [10, 3], [3, 5], [14, 17], [10, 14], [15, 3], [17, 15], [8, 18], [1, 12], [3, 7], [12, 17], [15, 15], [6, 2], [10, 9], [5, 13], [2, 15], [8, 5], [9, 15], [10, 6], [10, 17], [3, 9], [2, 6], [4, 1], [7, 12], [13, 1], [15, 17], [13, 5], [14, 10], [0, 17], [0, 11], [4, 17], [1, 11], [12, 18]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[6, 6], [3, 6], [5, 0], [7, 16], [9, 12], [10, 3], [3, 5], [14, 17], [10, 14], [15, 3], [17, 15], [8, 18], [1, 12], [3, 7], [12, 17], [15, 15], [6, 2], [10, 9], [5, 13], [2, 15], [8, 5], [9, 15], [10, 6], [10, 17], [3, 9], [2, 6], [4, 1], [7, 12], [13, 1], [15, 17], [13, 5], [14, 10], [0, 17], [0, 11], [4, 17], [1, 11], [12, 18]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 }, { - "name": "HexPrimes_6", - "sat": "def sat(primes: List[bool], n=\"d0b8e8441dcf15e12484\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"d0b8e8441dcf15e12484\"):\n return [c in \"2357BD\" for c in n]" + "name": "OddPath:4", + "sat": "def sat(p: List[int], edges=[[4, 8], [7, 6], [2, 0], [3, 2], [6, 3], [4, 5], [11, 5], [11, 0], [1, 5], [12, 12], [12, 1], [4, 11], [3, 3], [2, 10], [10, 6], [0, 7], [2, 7], [6, 11], [2, 9], [7, 7], [8, 9], [2, 1], [4, 6], [9, 4]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[4, 8], [7, 6], [2, 0], [3, 2], [6, 3], [4, 5], [11, 5], [11, 0], [1, 5], [12, 12], [12, 1], [4, 11], [3, 3], [2, 10], [10, 6], [0, 7], [2, 7], [6, 11], [2, 9], [7, 7], [8, 9], [2, 1], [4, 6], [9, 4]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "HexPrimes_7", - "sat": "def sat(primes: List[bool], n=\"2bfb4f48effb8\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"2bfb4f48effb8\"):\n return [c in \"2357BD\" for c in n]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "HexPrimes_8", - "sat": "def sat(primes: List[bool], n=\"0\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"0\"):\n return [c in \"2357BD\" for c in n]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "HexPrimes_9", - "sat": "def sat(primes: List[bool], n=\"78a9e1efe1c5d1aa918a8\"):\n \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\"\"\"\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", - "sols": [ - "def sol(n=\"78a9e1efe1c5d1aa918a8\"):\n return [c in \"2357BD\" for c in n]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_0", - "sat": "def sat(b: str, n=5324680297138495285):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=5324680297138495285):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_1", - "sat": "def sat(b: str, n=88465169532890):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=88465169532890):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_2", - "sat": "def sat(b: str, n=0):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=0):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_3", - "sat": "def sat(b: str, n=16655679678386282):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=16655679678386282):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_4", - "sat": "def sat(b: str, n=2900):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=2900):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_5", - "sat": "def sat(b: str, n=786216):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=786216):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_6", - "sat": "def sat(b: str, n=40002925026544973979):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=40002925026544973979):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_7", - "sat": "def sat(b: str, n=13609827511452802904634708047):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=13609827511452802904634708047):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_8", - "sat": "def sat(b: str, n=9092454863839039891897061480):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=9092454863839039891897061480):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Binarize_9", - "sat": "def sat(b: str, n=7075432):\n \"\"\"Write n base 2 followed and preceded by 'bits'\"\"\"\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", - "sols": [ - "def sol(n=7075432):\n s = bin(n)[2:]\n return f'bits{s}bits'" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_0", - "sat": "def sat(indices: List[int], s=\"I am an unhappy string!\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"I am an unhappy string!\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_1", - "sat": "def sat(indices: List[int], s=\"aeEm%%uIV0imR&xUvQvZf#1z4\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"aeEm%%uIV0imR&xUvQvZf#1z4\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_2", - "sat": "def sat(indices: List[int], s=\"e&S|C;;b1Nf[mmsQrQY\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"e&S|C;;b1Nf[mmsQrQY\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_3", - "sat": "def sat(indices: List[int], s=\"?EaEc/oDAm(i gP\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"?EaEc/oDAm(i gP\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_4", - "sat": "def sat(indices: List[int], s=\"pXw|EEcTKZ;:n[-tBME[[sn%fR37l;bM,t%!\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"pXw|EEcTKZ;:n[-tBME[[sn%fR37l;bM,t%!\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_5", - "sat": "def sat(indices: List[int], s=\"H4KjbncFR7a|=K,$hGhS;$:G:kkt^g|6aT[\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"gF(.^+^i7wO%wI3>6aT[\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "NearbyDuplicates_9", - "sat": "def sat(indices: List[int], s=\"Hiw GHgtcyuQan>8d))^M9l\"):\n \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\"\"\"\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", - "sols": [ - "def sol(s=\"Hiw GHgtcyuQan>8d))^M9l\"):\n for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_0", - "sat": "def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_1", - "sat": "def sat(grades: List[str], gpas=[3.9759656717898215, 2.532507032264099, 3.695549189812313, 2.492545757546573, 0.9653857771911838, 1.619680869536884]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[3.9759656717898215, 2.532507032264099, 3.695549189812313, 2.492545757546573, 0.9653857771911838, 1.619680869536884]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_2", - "sat": "def sat(grades: List[str], gpas=[1.0670062946539565]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[1.0670062946539565]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_3", - "sat": "def sat(grades: List[str], gpas: List[float]=[]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_4", - "sat": "def sat(grades: List[str], gpas=[2.7731700871871414, 0.5127907383392896]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[2.7731700871871414, 0.5127907383392896]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_5", - "sat": "def sat(grades: List[str], gpas=[1.3721075844546755, 1.9800514069744524, 3.127138570276307, 1.0979179608980654]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[1.3721075844546755, 1.9800514069744524, 3.127138570276307, 1.0979179608980654]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_6", - "sat": "def sat(grades: List[str], gpas=[2.2478712108282903, 2.904053962782555, 3.3559720867198393, 2.305093517063148, 1.3554022533858645, 3.9914879644359593, 0.6105418605378117, 0.053758879983145214, 2.2003121666680205]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[2.2478712108282903, 2.904053962782555, 3.3559720867198393, 2.305093517063148, 1.3554022533858645, 3.9914879644359593, 0.6105418605378117, 0.053758879983145214, 2.2003121666680205]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_7", - "sat": "def sat(grades: List[str], gpas=[1.4884000109972821]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[1.4884000109972821]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_8", - "sat": "def sat(grades: List[str], gpas=[0.32502250264371924, 1.6284183565303638, 0.5478961980409185]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[0.32502250264371924, 1.6284183565303638, 0.5478961980409185]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "Grader_9", - "sat": "def sat(grades: List[str], gpas=[2.536863326182083, 0.898268831978974, 3.4475087483041857, 3.734730577136208, 0.5718524747517044, 2.909259248206488, 3.175458745648921]):\n \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", - "sols": [ - "def sol(gpas=[2.536863326182083, 0.898268831978974, 3.4475087483041857, 3.734730577136208, 0.5718524747517044, 2.909259248206488, 3.175458745648921]):\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_0", - "sat": "def sat(factor: str, s=\"catscatcatscatcatscat\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"catscatcatscatcatscat\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_1", - "sat": "def sat(factor: str, s=\"pamithelozefefitextpamithelozefefitext\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"pamithelozefefitextpamithelozefefitext\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_2", - "sat": "def sat(factor: str, s=\"mahermahermahermahermahermahermahermaher\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"mahermahermahermahermahermahermahermaher\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_3", - "sat": "def sat(factor: str, s=\"mapychysmapychysmapychysmapychysmapychysmapychys\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"mapychysmapychysmapychysmapychysmapychysmapychys\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_4", - "sat": "def sat(factor: str, s=\"thihathihathihathihathihathiha\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"thihathihathihathihathihathiha\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_5", - "sat": "def sat(factor: str, s=\"nethivytnethivytnethivytnethivytnethivytnethivytnethivyt\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"nethivytnethivytnethivytnethivytnethivytnethivytnethivyt\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_6", - "sat": "def sat(factor: str, s=\"jufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolu\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"jufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolujufamekokaquamozolu\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_7", - "sat": "def sat(factor: str, s=\"sadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynih\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"sadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynihsadiquonukuzulynih\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_8", - "sat": "def sat(factor: str, s=\"wetwetwetwetwetwetwet\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"wetwetwetwetwetwetwet\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FactorString_9", - "sat": "def sat(factor: str, s=\"chathykuchathykuchathyku\"):\n \"\"\"Find a string which when repeated more than once gives s\"\"\"\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", - "sols": [ - "def sol(s=\"chathykuchathykuchathyku\"):\n n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "OneEnded_0", - "sat": "def sat(nums: List[int], n=5):\n \"\"\"Find all n-digit integers that start or end with 1\"\"\"\n count = 18 * (10 ** (n - 2)) if n > 1 else 1\n strs = {str(n) for n in nums}\n return len(strs) == count and all(s.startswith(\"1\") or s.endswith(\"1\") and len(s) == n for s in strs)", - "sols": [ - "def sol(n=5):\n ans = []\n for i in range(10 ** (n - 1), 10 ** n):\n assert len(str(i)) == n\n if str(i).startswith(\"1\") or str(i).endswith(\"1\"):\n ans.append(i)\n return ans" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#83", - "taint_date": "2021-7-7", - "weight": 0.010416666666666666 - }, - { - "name": "BitSum_0", - "sat": "def sat(n: int, b=107, s=25):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=107, s=25):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_1", - "sat": "def sat(n: int, b=59, s=51):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=59, s=51):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_2", - "sat": "def sat(n: int, b=825, s=653):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=825, s=653):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_3", - "sat": "def sat(n: int, b=354, s=287):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=354, s=287):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_4", - "sat": "def sat(n: int, b=256, s=1):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=256, s=1):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_5", - "sat": "def sat(n: int, b=727, s=497):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=727, s=497):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_6", - "sat": "def sat(n: int, b=580, s=250):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=580, s=250):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_7", - "sat": "def sat(n: int, b=836, s=254):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=836, s=254):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_8", - "sat": "def sat(n: int, b=609, s=492):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=609, s=492):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "BitSum_9", - "sat": "def sat(n: int, b=379, s=62):\n \"\"\"Find an b-bit integer with a bit-sum of s\"\"\"\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", - "sols": [ - "def sol(b=379, s=62):\n return int(\"1\" * s + \"0\" * (b - s), 2)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_0", - "sat": "def sat(s: str, n=1012552981257923):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=1012552981257923):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_1", - "sat": "def sat(s: str, n=149375608197334399520070108176536906):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=149375608197334399520070108176536906):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_2", - "sat": "def sat(s: str, n=141211514700950831659878):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=141211514700950831659878):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_3", - "sat": "def sat(s: str, n=802182768382):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=802182768382):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_4", - "sat": "def sat(s: str, n=8528190689035):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=8528190689035):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_5", - "sat": "def sat(s: str, n=795311771849755577651):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=795311771849755577651):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_6", - "sat": "def sat(s: str, n=53):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=53):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_7", - "sat": "def sat(s: str, n=9584133253037383817922987173459963392164):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=9584133253037383817922987173459963392164):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_8", - "sat": "def sat(s: str, n=496958084858083723542854631342507861380951):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=496958084858083723542854631342507861380951):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "DigitSum_9", - "sat": "def sat(s: str, n=6957027656012396382680187619298485726781330):\n \"\"\"Find the sum of the digits in n as a binary string\"\"\"\n tot = int(s, 2)\n return tot == sum(int(c) for c in str(n))", - "sols": [ - "def sol(n=6957027656012396382680187619298485726781330):\n return bin(sum(int(c) for c in str(n)))[2:]" - ], - "module": "human_eval", - "notes": "*Also* inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_0", - "sat": "def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_1", - "sat": "def sat(even_odd_sum: int, nums=[72, -79, -7, 50, -6, -69, 40, 16]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[72, -79, -7, 50, -6, -69, 40, 16]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_2", - "sat": "def sat(even_odd_sum: int, nums=[-20, 74, -95, 99, -28, 69, 24, -25]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-20, 74, -95, 99, -28, 69, 24, -25]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_3", - "sat": "def sat(even_odd_sum: int, nums=[25, 70]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[25, 70]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_4", - "sat": "def sat(even_odd_sum: int, nums=[-17, 93, -79, 80, -51, -57, -49, 81, 35, -89, -10, 17, 0, 98, -7]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-17, 93, -79, 80, -51, -57, -49, 81, 35, -89, -10, 17, 0, 98, -7]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_5", - "sat": "def sat(even_odd_sum: int, nums=[-18, 8, -60, 41, -73, 76, -21, -97, -2, -82, -56]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-18, 8, -60, 41, -73, 76, -21, -97, -2, -82, -56]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_6", - "sat": "def sat(even_odd_sum: int, nums=[70, 58, -20, 43, -10, -1, -52, 32, 69, -92, -71, 34, -57, 73, -47]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[70, 58, -20, 43, -10, -1, -52, 32, 69, -92, -71, 34, -57, 73, -47]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_7", - "sat": "def sat(even_odd_sum: int, nums=[-23, -52, 97, 15]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-23, -52, 97, 15]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_8", - "sat": "def sat(even_odd_sum: int, nums=[-41, -54, -10, -44]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-41, -54, -10, -44]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "EvenOdd_9", - "sat": "def sat(even_odd_sum: int, nums=[-78, -33, 70, -58, -8, 44, -10, -18, 52, -92, 46, 73, 13, 67, -25, 45]):\n \"\"\"Find the sum of the even elements that are at odd indices\"\"\"\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", - "sols": [ - "def sol(nums=[-78, -33, 70, -58, -8, 44, -10, -18, 52, -92, 46, 73, 13, 67, -25, 45]):\n return sum(i for i in nums[1::2] if i % 2 == 0)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_0", - "sat": "def sat(s: str, orig=\"Hello world!!!\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"Hello world!!!\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_1", - "sat": "def sat(s: str, orig=\"YOU CAN rearrange my letters, yes you can!\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"YOU CAN rearrange my letters, yes you can!\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_2", - "sat": "def sat(s: str, orig=\"caN you handlE LONGGGGGGGGGGGG strings?\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"caN you handlE LONGGGGGGGGGGGG strings?\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_3", - "sat": "def sat(s: str, orig=\"how bout spaces and weird punctuation!?$%@#%\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"how bout spaces and weird punctuation!?$%@#%\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_4", - "sat": "def sat(s: str, orig=\"ruhixuthuciji kebelobawitextythuch quozo\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"ruhixuthuciji kebelobawitextythuch quozo\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_5", - "sat": "def sat(s: str, orig=\"tenewatextuc mythesavu g\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"tenewatextuc mythesavu g\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_6", - "sat": "def sat(s: str, orig=\"gupymache\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"gupymache\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_7", - "sat": "def sat(s: str, orig=\"te texturusotich\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"te texturusotich\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_8", - "sat": "def sat(s: str, orig=\"sarukajejuvet textavut\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"sarukajejuvet textavut\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "AntiShuffle_9", - "sat": "def sat(s: str, orig=\"bequi hapotextujobinozityv xytextytyg domy\"):\n \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\"\"\"\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", - "sols": [ - "def sol(orig=\"bequi hapotextujobinozityv xytextytyg domy\"):\n return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_0", - "sat": "def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_1", - "sat": "def sat(indices: List[List[int]], uneven=[[64, 7, 64, 64, 20], [72, 64, 22, 64, 64], [21, 35], [64, 0, 96, 27]], target=64):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[64, 7, 64, 64, 20], [72, 64, 22, 64, 64], [21, 35], [64, 0, 96, 27]], target=64):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_2", - "sat": "def sat(indices: List[List[int]], uneven=[[16, 87]], target=87):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[16, 87]], target=87):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_3", - "sat": "def sat(indices: List[List[int]], uneven: List[List[int]]=[], target=30):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[], target=30):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_4", - "sat": "def sat(indices: List[List[int]], uneven=[[5, 30, 18], [53, 64, 87, 69, 64, 64, 64], [], [44], [64, 88, 68, 64, 64, 84, 64, 64, 64], [31], [64, 5, 64, 71, 42, 64, 48, 64, 27], [64, 80, 11, 64]], target=64):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[5, 30, 18], [53, 64, 87, 69, 64, 64, 64], [], [44], [64, 88, 68, 64, 64, 84, 64, 64, 64], [31], [64, 5, 64, 71, 42, 64, 48, 64, 27], [64, 80, 11, 64]], target=64):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_5", - "sat": "def sat(indices: List[List[int]], uneven=[[75, 99]], target=99):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[75, 99]], target=99):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_6", - "sat": "def sat(indices: List[List[int]], uneven: List[List[int]]=[], target=20):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[], target=20):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_7", - "sat": "def sat(indices: List[List[int]], uneven=[[22], [22], [22, 22, 29, 15, 53, 22, 22, 83], [4, 22, 22, 91, 24], [], [22, 27, 0, 22, 22, 22, 51], [22, 22, 25, 82, 47, 98]], target=22):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[22], [22], [22, 22, 29, 15, 53, 22, 22, 83], [4, 22, 22, 91, 24], [], [22, 27, 0, 22, 22, 22, 51], [22, 22, 25, 82, 47, 98]], target=22):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_8", - "sat": "def sat(indices: List[List[int]], uneven=[[25, 11, 70, 52, 70], [70, 21, 70, 70]], target=70):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[25, 11, 70, 52, 70], [70, 21, 70, 70]], target=70):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UnevenFind_9", - "sat": "def sat(indices: List[List[int]], uneven=[[36, 48, 21, 87], [48, 48, 48, 72, 48, 62, 48]], target=48):\n \"\"\"Find the indices of all occurrences of target in the uneven matrix\"\"\"\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", - "sols": [ - "def sol(uneven=[[36, 48, 21, 87], [48, 48, 48, 72, 48, 62, 48]], target=48):\n return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "UpDownSort_0", - "sat": "def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):\n \"\"\"Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd\"\"\"\n assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), \"not a reordering\"\n increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1\n return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1))", - "sols": [ - "def sol(nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):\n return sorted(nums, reverse=(False if (nums[0] + nums[-1]) % 2 else True))" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#88", - "taint_date": "2021-7-7", - "weight": 0.010416666666666666 - }, - { - "name": "SubstitutionCypher_0", - "sat": "def sat(encrypted: str, orig=\"Hello, world!\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"Hello, world!\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_1", - "sat": "def sat(encrypted: str, orig=\"\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_2", - "sat": "def sat(encrypted: str, orig=\"byfykovevuvyxanofi lygolono pyzuh t\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"byfykovevuvyxanofi lygolono pyzuh t\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_3", - "sat": "def sat(encrypted: str, orig=\"dogyvotitonucuxecequ jahuzowiz jyna\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"dogyvotitonucuxecequ jahuzowiz jyna\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_4", - "sat": "def sat(encrypted: str, orig=\"chodatext quycimoquytunek\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"chodatext quycimoquytunek\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_5", - "sat": "def sat(encrypted: str, orig=\"fymodoquyjyp x q\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"fymodoquyjyp x q\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_6", - "sat": "def sat(encrypted: str, orig=\"janonythipochequ wykidevahibyri\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"janonythipochequ wykidevahibyri\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_7", - "sat": "def sat(encrypted: str, orig=\"kebotaheloquuje texty\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"kebotaheloquuje texty\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_8", - "sat": "def sat(encrypted: str, orig=\"textylezecytextawo jib pe pewibipucisepelit\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"textylezecytextawo jib pe pewibipucisepelit\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SubstitutionCypher_9", - "sat": "def sat(encrypted: str, orig=\"jixuvuthowugewoch jup chodac textis\"):\n \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\"\"\"\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", - "sols": [ - "def sol(orig=\"jixuvuthowugewoch jup chodac textis\"):\n return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_0", - "sat": "def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_1", - "sat": "def sat(n: int, nums=[-3, -4, -3, 8, -9]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[-3, -4, -3, 8, -9]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_2", - "sat": "def sat(n: int, nums=[0, -5, -7, -5, 0, -2, 6, -8]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[0, -5, -7, -5, 0, -2, 6, -8]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_3", - "sat": "def sat(n: int, nums=[6, 5]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[6, 5]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_4", - "sat": "def sat(n: int, nums=[4, -8, 8, 4]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[4, -8, 8, 4]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_5", - "sat": "def sat(n: int, nums=[2, -8, 6]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[2, -8, 6]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_6", - "sat": "def sat(n: int, nums=[3, -7, -7, 0, 3, -6]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[3, -7, -7, 0, 3, -6]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_7", - "sat": "def sat(n: int, nums=[-6, -8, -5, -1]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[-6, -8, -5, -1]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_8", - "sat": "def sat(n: int, nums=[8, 8, 4, 9]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[8, 8, 4, 9]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "SecondSmallestUnique_9", - "sat": "def sat(n: int, nums=[-10, -6, -8, 0, -10, -3]):\n \"\"\"Find the second smallest unique number in the list nums.\"\"\"\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", - "sols": [ - "def sol(nums=[-10, -6, -8, 0, -10, -3]):\n return sorted(set(nums))[1]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_0", - "sat": "def sat(boring: List[str], text=\"This is not boring. I am boring! I am sooo tired.\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"This is not boring. I am boring! I am sooo tired.\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_1", - "sat": "def sat(boring: List[str], text=\"dexuzuhyfac lifugerimosiwybot.hesukawycat!hawymemof pa text z.nuquyt weminubadithikanat gejetextipafex vobenekothob.reraxithechaquipapav wexamew lobihus zygijehequesatextacy jucyth?I?I wevymicygequipi cicemyte tha cetexti vuhoxadivelabyduxix?I lanusutho kuzit?nathor sopati myjamygukiwyhuje.I kacuquedewapojedu thulocho?I chezeri.thubitozogukenejugox.cytonoc tex tobaquy wiwithij!vinam rarile sibizytexta notaxithyzu?\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"dexuzuhyfac lifugerimosiwybot.hesukawycat!hawymemof pa text z.nuquyt weminubadithikanat gejetextipafex vobenekothob.reraxithechaquipapav wexamew lobihus zygijehequesatextacy jucyth?I?I wevymicygequipi cicemyte tha cetexti vuhoxadivelabyduxix?I lanusutho kuzit?nathor sopati myjamygukiwyhuje.I kacuquedewapojedu thulocho?I chezeri.thubitozogukenejugox.cytonoc tex tobaquy wiwithij!vinam rarile sibizytexta notaxithyzu?\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_2", - "sat": "def sat(boring: List[str], text=\"\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_3", - "sat": "def sat(boring: List[str], text=\"nysydajywigi vefusivechucirochuw tipeko pogofinifyk.I textovugythecodo ruwatekat dane wachikechanequi matupisofunehac.tubicetofalat colawuhemedexeq lurytext?\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"nysydajywigi vefusivechucirochuw tipeko pogofinifyk.I textovugythecodo ruwatekat dane wachikechanequi matupisofunehac.tubicetofalat colawuhemedexeq lurytext?\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_4", - "sat": "def sat(boring: List[str], text=\"?zihithi ch chithe vuluzuquidawyquo.I?I chypufomiwylojen ziwuwygawyfyg makatex?textidigefoc nyjav.I gujyduvafe gykizubam cofurythoc.coc thohifycepy tex kybiwulatextux.\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"?zihithi ch chithe vuluzuquidawyquo.I?I chypufomiwylojen ziwuwygawyfyg makatex?textidigefoc nyjav.I gujyduvafe gykizubam cofurythoc.coc thohifycepy tex kybiwulatextux.\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_5", - "sat": "def sat(boring: List[str], text=\"I dobuv.textyhitex japix?ripypavumemon thychi miwuzigoquucivev purycowytehyrefapy cofujewobazi!wow gysyxuliwe kichat sahununaconez.dofuthodechogudate hejyloluth pufelifi!I syquothyzedujojuthu xamathotox.\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"I dobuv.textyhitex japix?ripypavumemon thychi miwuzigoquucivev purycowytehyrefapy cofujewobazi!wow gysyxuliwe kichat sahununaconez.dofuthodechogudate hejyloluth pufelifi!I syquothyzedujojuthu xamathotox.\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_6", - "sat": "def sat(boring: List[str], text=\"I quajapycherathatex hujajohipabavevefyd citex vemopenofuzynycot?textyb suquukor petext.I!rapinoj thunagysyxychyjabon?hewuchuc caracivicilokacimedo pubajofuxikasip dunogetatobexa?I thigycubo kegixylifebafuxogyq bamadutextilo.textanisaketyqu zevonysos!I thaly.rap ji quox recygequa?I zyfadimuzy hete hufobepesywyrorivy chokyzotextath?quihahebymute cykyj ximachilevaxuhafi?mowyfisudoveribu th coq cherotachipuve!I juwacevykymobabuvyx tatot!I xatuquikoch mihijugyk nicethynahuza zafigechimudaf???I xiryc titubatextise jycusiwovow!I ryvidurovy x vothyte!\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"I quajapycherathatex hujajohipabavevefyd citex vemopenofuzynycot?textyb suquukor petext.I!rapinoj thunagysyxychyjabon?hewuchuc caracivicilokacimedo pubajofuxikasip dunogetatobexa?I thigycubo kegixylifebafuxogyq bamadutextilo.textanisaketyqu zevonysos!I thaly.rap ji quox recygequa?I zyfadimuzy hete hufobepesywyrorivy chokyzotextath?quihahebymute cykyj ximachilevaxuhafi?mowyfisudoveribu th coq cherotachipuve!I juwacevykymobabuvyx tatot!I xatuquikoch mihijugyk nicethynahuza zafigechimudaf???I xiryc titubatextise jycusiwovow!I ryvidurovy x vothyte!\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_7", - "sat": "def sat(boring: List[str], text=\"I pysisy zexotuchipudig sapihu quatextapythaha.tutexto xigyc.wefufyger!\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"I pysisy zexotuchipudig sapihu quatextapythaha.tutexto xigyc.wefufyger!\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_8", - "sat": "def sat(boring: List[str], text=\"tunotuth?I dymoc!!\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"tunotuth?I dymoc!!\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "FindBored_9", - "sat": "def sat(boring: List[str], text=\"I hyxitotextehef mumute bidocapysitextafik bazy vopibyf!I gyfogadu retextafechuw wacusutichawet niwinygevoloh?I textowu cythozylykici je xap?.I lezohotepinabotew thuboxusygo gyth?\"):\n \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\"\"\"\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", - "sols": [ - "def sol(text=\"I hyxitotextehef mumute bidocapysitextafik bazy vopibyf!I gyfogadu retextafechuw wacusutichawet niwinygevoloh?I textowu cythozylykici je xap?.I lezohotepinabotew thuboxusygo gyth?\"):\n return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" - ], - "module": "human_eval", - "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", - "taint_date": "2021-7-7", - "weight": 0.0010416666666666667 - }, - { - "name": "IsEven_0", - "sat": "def sat(b: bool, n=10):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=10):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_1", - "sat": "def sat(b: bool, n=0):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=0):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_2", - "sat": "def sat(b: bool, n=1):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=1):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_3", - "sat": "def sat(b: bool, n=2):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=2):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_4", - "sat": "def sat(b: bool, n=3):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=3):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_5", - "sat": "def sat(b: bool, n=4):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=4):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_6", - "sat": "def sat(b: bool, n=5):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=5):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_7", - "sat": "def sat(b: bool, n=6):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=6):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_8", - "sat": "def sat(b: bool, n=7):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=7):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IsEven_9", - "sat": "def sat(b: bool, n=8):\n \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", - "sols": [ - "def sol(n=8):\n return n % 2 == 0" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_0", - "sat": "def sat(s: str, word=\"antidisestablishmentarianism\", max_len=10):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"antidisestablishmentarianism\", max_len=10):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_1", - "sat": "def sat(s: str, word=\"pawuzorythalirinasubyg\", max_len=12):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"pawuzorythalirinasubyg\", max_len=12):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_2", - "sat": "def sat(s: str, word=\"jomodosigezyfulach\", max_len=5):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"jomodosigezyfulach\", max_len=5):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_3", - "sat": "def sat(s: str, word=\"bybakichop\", max_len=12):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"bybakichop\", max_len=12):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_4", - "sat": "def sat(s: str, word=\"wywaxizodetextonigijalate\", max_len=5):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"wywaxizodetextonigijalate\", max_len=5):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_5", - "sat": "def sat(s: str, word=\"chathitytewugomoquiw\", max_len=13):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"chathitytewugomoquiw\", max_len=13):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_6", - "sat": "def sat(s: str, word=\"quohasuluwitextinachaxo\", max_len=7):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"quohasuluwitextinachaxo\", max_len=7):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_7", - "sat": "def sat(s: str, word=\"chokote\", max_len=7):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"chokote\", max_len=7):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_8", - "sat": "def sat(s: str, word=\"kuwanytexuwivychevo\", max_len=10):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"kuwanytexuwivychevo\", max_len=10):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Abbreviate_9", - "sat": "def sat(s: str, word=\"textuchyvenocolamygeryqu\", max_len=8):\n \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", - "sols": [ - "def sol(word=\"textuchyvenocolamygeryqu\", max_len=8):\n if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_0", - "sat": "def sat(corners: List[List[int]], m=10, n=9, a=5, target=4):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=10, n=9, a=5, target=4):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_1", - "sat": "def sat(corners: List[List[int]], m=22, n=129, a=9, target=45):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=22, n=129, a=9, target=45):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_2", - "sat": "def sat(corners: List[List[int]], m=6, n=849, a=10, target=89):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=6, n=849, a=10, target=89):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_3", - "sat": "def sat(corners: List[List[int]], m=89, n=554, a=6, target=1397):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=89, n=554, a=6, target=1397):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_4", - "sat": "def sat(corners: List[List[int]], m=74, n=1, a=2, target=38):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=74, n=1, a=2, target=38):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_5", - "sat": "def sat(corners: List[List[int]], m=82, n=3, a=10, target=11):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=82, n=3, a=10, target=11):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_6", - "sat": "def sat(corners: List[List[int]], m=50, n=5, a=2, target=79):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=50, n=5, a=2, target=79):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_7", - "sat": "def sat(corners: List[List[int]], m=5, n=49, a=7, target=11):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=5, n=49, a=7, target=11):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_8", - "sat": "def sat(corners: List[List[int]], m=6, n=447, a=10, target=45):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=6, n=447, a=10, target=45):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SquareTiles_9", - "sat": "def sat(corners: List[List[int]], m=460, n=87, a=2, target=10122):\n \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", - "sols": [ - "def sol(m=460, n=87, a=2, target=10122):\n return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_0", - "sat": "def sat(lb: List[bool], trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_1", - "sat": "def sat(lb: List[bool], trips=[[1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 0, 0]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 0, 0]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_2", - "sat": "def sat(lb: List[bool], trips=[[0, 0, 0], [1, 0, 0], [0, 1, 1], [0, 1, 1]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 0, 0], [1, 0, 0], [0, 1, 1], [0, 1, 1]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_3", - "sat": "def sat(lb: List[bool], trips=[[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 1, 0], [0, 1, 1], [1, 0, 0], [0, 0, 0], [1, 0, 1], [1, 1, 0], [0, 0, 1], [1, 0, 1]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 1, 0], [0, 1, 1], [1, 0, 0], [0, 0, 0], [1, 0, 1], [1, 1, 0], [0, 0, 1], [1, 0, 1]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_4", - "sat": "def sat(lb: List[bool], trips=[[0, 0, 1], [0, 1, 1], [0, 0, 1], [0, 1, 1]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 0, 1], [0, 1, 1], [0, 0, 1], [0, 1, 1]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_5", - "sat": "def sat(lb: List[bool], trips=[[0, 0, 0], [0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 0, 0], [0, 0, 0], [1, 1, 0], [1, 0, 0], [0, 1, 0], [0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1], [1, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 0, 0], [0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 0, 0], [0, 0, 0], [1, 1, 0], [1, 0, 0], [0, 1, 0], [0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1], [1, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_6", - "sat": "def sat(lb: List[bool], trips=[[0, 1, 1], [1, 1, 1], [0, 0, 0], [0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0], [1, 1, 0]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 1, 1], [1, 1, 1], [0, 0, 0], [0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0], [1, 1, 0]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_7", - "sat": "def sat(lb: List[bool], trips=[[0, 1, 1], [0, 1, 1], [1, 1, 0], [1, 1, 0], [0, 0, 0], [0, 0, 0], [1, 1, 0], [0, 0, 1], [1, 1, 1], [0, 1, 0], [0, 0, 1], [0, 0, 1], [1, 1, 0], [0, 0, 0]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[0, 1, 1], [0, 1, 1], [1, 1, 0], [1, 1, 0], [0, 0, 0], [0, 0, 0], [1, 1, 0], [0, 0, 1], [1, 1, 1], [0, 1, 0], [0, 0, 1], [0, 0, 1], [1, 1, 0], [0, 0, 0]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_8", - "sat": "def sat(lb: List[bool], trips=[[1, 0, 1], [1, 1, 0], [1, 1, 0], [0, 1, 1], [1, 1, 0], [0, 0, 0]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[1, 0, 1], [1, 1, 0], [1, 1, 0], [0, 1, 1], [1, 1, 0], [0, 0, 0]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasyTwos_9", - "sat": "def sat(lb: List[bool], trips=[[1, 0, 1], [0, 1, 1], [0, 0, 0], [0, 1, 0], [1, 0, 1], [0, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 1]]):\n \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", - "sols": [ - "def sol(trips=[[1, 0, 1], [0, 1, 1], [0, 0, 0], [0, 1, 0], [1, 0, 1], [0, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 1]]):\n return [sum(s) >= 2 for s in trips]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_0", - "sat": "def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_1", - "sat": "def sat(n: int, scores=[16, 10], k=1):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[16, 10], k=1):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_2", - "sat": "def sat(n: int, scores=[28, 8, 7], k=2):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[28, 8, 7], k=2):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_3", - "sat": "def sat(n: int, scores=[40, 40, 31, 25], k=1):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[40, 40, 31, 25], k=1):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_4", - "sat": "def sat(n: int, scores=[33, 25, 16, 14, 0], k=4):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[33, 25, 16, 14, 0], k=4):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_5", - "sat": "def sat(n: int, scores=[28, 25, 17, 11, 9, 2], k=5):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[28, 25, 17, 11, 9, 2], k=5):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_6", - "sat": "def sat(n: int, scores=[15, 12, 11, 10, 8, 4, 2], k=6):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[15, 12, 11, 10, 8, 4, 2], k=6):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_7", - "sat": "def sat(n: int, scores=[23, 21, 20, 15, 15, 11, 4, 3], k=7):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[23, 21, 20, 15, 15, 11, 4, 3], k=7):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_8", - "sat": "def sat(n: int, scores=[40, 38, 38, 32, 29, 18, 17, 12, 6], k=8):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[40, 38, 38, 32, 29, 18, 17, 12, 6], k=8):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DecreasingCountComparison_9", - "sat": "def sat(n: int, scores=[39, 26, 22, 20, 20, 16, 8, 5, 2, 1], k=9):\n \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", - "sols": [ - "def sol(scores=[39, 26, 22, 20, 20, 16, 8, 5, 2, 1], k=9):\n threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_0", - "sat": "def sat(t: str, s=\"Problems\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"Problems\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_1", - "sat": "def sat(t: str, s=\"VahOjaquAlYMEcubidePYwApawAtonE\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"VahOjaquAlYMEcubidePYwApawAtonE\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_2", - "sat": "def sat(t: str, s=\"kAgIHAdiHEKoNAJubozUKaMYDETAdeZyziveL\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"kAgIHAdiHEKoNAJubozUKaMYDETAdeZyziveL\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_3", - "sat": "def sat(t: str, s=\"NOxADaNIMiReZoTeXtODUtHulyTHETextojoLeQuaNutEXtE\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"NOxADaNIMiReZoTeXtODUtHulyTHETextojoLeQuaNutEXtE\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_4", - "sat": "def sat(t: str, s=\"MEkUWonymYNAQUypEcIv\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"MEkUWonymYNAQUypEcIv\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_5", - "sat": "def sat(t: str, s=\"GOnATHygYzefuDabilEgET\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"GOnATHygYzefuDabilEgET\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_6", - "sat": "def sat(t: str, s=\"BElEViThIteXTERAtExtUSoJaSelOTeXtachoNa\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"BElEViThIteXTERAtExtUSoJaSelOTeXtachoNa\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_7", - "sat": "def sat(t: str, s=\"CyqUeVIzaLERAZufuBoPiwisucaRAHAp\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"CyqUeVIzaLERAZufuBoPiwisucaRAHAp\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_8", - "sat": "def sat(t: str, s=\"tEWA\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"tEWA\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "VowelDrop_9", - "sat": "def sat(t: str, s=\"BYjobuCIlugacIgiWiPIbyThaZEBYqUOPyGYByKYX\"):\n \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", - "sols": [ - "def sol(s=\"BYjobuCIlugacIgiWiPIbyThaZEBYqUOPyGYByKYX\"):\n return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_0", - "sat": "def sat(squares: List[List[int]], m=10, n=5, target=50):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=10, n=5, target=50):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_1", - "sat": "def sat(squares: List[List[int]], m=30, n=12, target=360):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=30, n=12, target=360):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_2", - "sat": "def sat(squares: List[List[int]], m=34, n=25, target=850):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=34, n=25, target=850):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_3", - "sat": "def sat(squares: List[List[int]], m=35, n=46, target=1610):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=35, n=46, target=1610):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_4", - "sat": "def sat(squares: List[List[int]], m=41, n=12, target=492):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=41, n=12, target=492):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_5", - "sat": "def sat(squares: List[List[int]], m=46, n=2, target=92):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=46, n=2, target=92):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_6", - "sat": "def sat(squares: List[List[int]], m=27, n=24, target=648):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=27, n=24, target=648):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_7", - "sat": "def sat(squares: List[List[int]], m=43, n=19, target=816):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=43, n=19, target=816):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_8", - "sat": "def sat(squares: List[List[int]], m=12, n=25, target=300):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=12, n=25, target=300):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DominoTile_9", - "sat": "def sat(squares: List[List[int]], m=41, n=40, target=1640):\n \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", - "sols": [ - "def sol(m=41, n=40, target=1640):\n if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_0", - "sat": "def sat(n: int, ops=['x++', '--x', '--x'], target=19143212):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x++', '--x', '--x'], target=19143212):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_1", - "sat": "def sat(n: int, ops=['x++', '++x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x--', 'x--', '--x', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', 'x--', 'x++', 'x--', 'x--', '--x', '++x', 'x--', '--x', 'x++', 'x--', 'x++', '++x', '++x', 'x++', '--x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x++', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '++x', 'x++', 'x++', '++x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', '--x', 'x--', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '++x', '--x', '--x', '++x', '--x', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '--x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x++', '--x', 'x++', 'x++', 'x--', 'x--', 'x--', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', '++x', 'x++', '++x', '++x', '++x', '--x', 'x--', 'x--', '--x', '--x', '++x', '++x', '--x', '++x', '--x', 'x--', 'x--', '--x', '--x', '--x', '--x', '--x', 'x++', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x++', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', '--x', '--x', '++x', '++x', 'x--', '++x', '--x', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x--'], target=88808):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x++', '++x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x--', 'x--', '--x', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', 'x--', 'x++', 'x--', 'x--', '--x', '++x', 'x--', '--x', 'x++', 'x--', 'x++', '++x', '++x', 'x++', '--x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x++', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '++x', 'x++', 'x++', '++x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', '--x', 'x--', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '++x', '--x', '--x', '++x', '--x', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '--x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x++', '--x', 'x++', 'x++', 'x--', 'x--', 'x--', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', '++x', 'x++', '++x', '++x', '++x', '--x', 'x--', 'x--', '--x', '--x', '++x', '++x', '--x', '++x', '--x', 'x--', 'x--', '--x', '--x', '--x', '--x', '--x', 'x++', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x++', '++x', '++x', 'x--', '++x', 'x--', '--x', 'x++', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', '--x', '--x', '++x', '++x', 'x--', '++x', '--x', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x--'], target=88808):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_2", - "sat": "def sat(n: int, ops=['x--', 'x--', '++x', '--x', '--x', 'x--', '--x', '++x', 'x++', 'x++', 'x--', 'x++', '++x', '--x', '++x', '--x', 'x++', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', '--x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', '++x', '--x', '--x', '++x', '--x', '--x', 'x++', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', '++x', 'x++', '++x', 'x++', 'x++', 'x++', 'x--', '++x', '--x', '--x', 'x++', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', 'x++', 'x++', '--x', '--x', 'x--', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '++x', 'x++', 'x++', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', 'x--', '++x', '++x', '--x', 'x++', '++x', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', 'x--', '++x', '++x', 'x++', '--x', '++x', 'x--', '--x', 'x--', '++x', 'x--', 'x--', '++x', '++x', 'x++', 'x--', '++x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', '--x', '++x', 'x--', '--x', '++x', 'x--', '++x', 'x--', 'x--', '++x', '--x', '--x', '++x', '--x', 'x++', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x--', 'x++', '++x', 'x--', 'x++', '--x', '++x', '++x', '++x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', 'x--', 'x++', '--x', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', '--x', '++x', '--x', 'x++', 'x++', 'x++', 'x--', 'x++', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x++', '++x', 'x++', '++x', '++x', '--x', 'x++', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x--', '--x', 'x--', '--x', 'x++', 'x--', '++x', 'x--', '++x', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x++', 'x++', '++x', '++x', '++x', '++x', '++x', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', '--x', 'x++', '++x', '--x', 'x++', '--x', '--x', 'x++', '++x', 'x--', 'x--', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x++', '++x', '--x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '--x', '--x', 'x--', '++x', '++x', '++x', '++x', '++x', 'x++', '--x', '++x', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x--', '++x', '++x', 'x++', 'x--', 'x--', '++x', '--x', '--x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x++', '++x', '++x', 'x--', '--x', '--x', '++x', 'x++', '--x', 'x--', 'x--', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x++', 'x++', 'x--', '--x', 'x++', 'x--', 'x++', 'x++', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', '--x', 'x--', '--x', '++x', '--x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', '++x', '--x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', '++x', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x--', 'x++', 'x++', '++x', 'x++', 'x++', 'x++', 'x++', '++x', 'x--', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', '--x', '--x', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', '--x', 'x++', 'x--', '--x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '--x', '++x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x--', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', 'x--', '++x', 'x--', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++'], target=28110):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x--', 'x--', '++x', '--x', '--x', 'x--', '--x', '++x', 'x++', 'x++', 'x--', 'x++', '++x', '--x', '++x', '--x', 'x++', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', '--x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', '++x', '--x', '--x', '++x', '--x', '--x', 'x++', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x++', 'x++', 'x++', '--x', 'x--', 'x++', '++x', 'x--', '++x', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', '++x', 'x++', '++x', 'x++', 'x++', 'x++', 'x--', '++x', '--x', '--x', 'x++', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', 'x++', 'x++', '--x', '--x', 'x--', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '++x', 'x++', 'x++', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', 'x--', '++x', '++x', '--x', 'x++', '++x', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', 'x--', '++x', '++x', 'x++', '--x', '++x', 'x--', '--x', 'x--', '++x', 'x--', 'x--', '++x', '++x', 'x++', 'x--', '++x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', 'x--', 'x--', 'x--', '++x', '--x', '++x', 'x--', '--x', '++x', 'x--', '++x', 'x--', 'x--', '++x', '--x', '--x', '++x', '--x', 'x++', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', 'x--', '++x', '--x', 'x++', 'x++', '--x', 'x--', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x--', 'x++', '++x', 'x--', 'x++', '--x', '++x', '++x', '++x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', 'x--', 'x++', '--x', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', '--x', '++x', '--x', 'x++', 'x++', 'x++', 'x--', 'x++', '++x', 'x--', 'x--', '--x', '++x', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '--x', 'x++', '++x', 'x++', '++x', '++x', '--x', 'x++', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x--', '--x', 'x--', '--x', 'x++', 'x--', '++x', 'x--', '++x', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '++x', 'x--', 'x++', '++x', 'x--', 'x--', 'x++', 'x++', '++x', '++x', '++x', '++x', '++x', '++x', 'x++', 'x++', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', '--x', 'x++', '++x', '--x', 'x++', '--x', '--x', 'x++', '++x', 'x--', 'x--', 'x--', '--x', '++x', '--x', 'x--', 'x--', 'x++', '++x', '--x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '--x', '--x', 'x--', '++x', '++x', '++x', '++x', '++x', 'x++', '--x', '++x', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x--', '++x', '++x', 'x++', 'x--', 'x--', '++x', '--x', '--x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', '--x', '++x', '++x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x++', '++x', '++x', 'x--', '--x', '--x', '++x', 'x++', '--x', 'x--', 'x--', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', '--x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x++', 'x++', 'x--', '--x', 'x++', 'x--', 'x++', 'x++', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', 'x++', 'x++', 'x--', '--x', '--x', 'x--', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', '++x', 'x++', '--x', 'x--', 'x--', 'x--', '++x', '++x', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', '--x', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x++', 'x++', 'x--', '++x', '--x', '--x', '--x', 'x++', '++x', '--x', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x--', 'x--', '--x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', '++x', '--x', '--x', '--x', 'x--', '--x', '++x', '--x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', '++x', '--x', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', '++x', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', 'x--', 'x++', 'x++', '++x', 'x++', 'x++', 'x++', 'x++', '++x', 'x--', 'x++', 'x--', 'x--', 'x++', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', 'x++', '++x', '++x', '--x', '--x', '--x', '--x', '--x', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', '--x', '--x', 'x++', 'x--', '--x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x--', '++x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '--x', '++x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '--x', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x--', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '++x', 'x++', 'x++', 'x--', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x--', '++x', '--x', 'x--', 'x++', 'x--', '++x', 'x--', '--x', '++x', '--x', 'x--', 'x++', 'x++', '--x', '--x', 'x++'], target=28110):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_3", - "sat": "def sat(n: int, ops=['--x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '--x', '--x', '--x', 'x--', '--x', '--x', '++x', '++x', '++x', 'x++', '--x', 'x--', '++x', 'x--', 'x--', 'x++', 'x--', 'x++', 'x++', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '++x', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', 'x--', '++x', '++x', '++x', 'x++', '++x', '--x', '--x', 'x++', '++x', '++x', 'x++', '++x', '--x', '++x', '--x', 'x--', '++x', '++x', '++x', '++x', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '++x', 'x--', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x--', '++x', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '--x', '++x', 'x--', 'x--', '--x', 'x--', 'x--', 'x++', '--x', 'x++', '++x', '--x', 'x--', '--x', '--x', 'x--', 'x--', '--x', '++x', 'x--', '++x', '++x', '++x', 'x--', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', 'x++', '++x', '--x', '++x', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', '++x', '--x', 'x++', '--x', '--x', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', 'x++', 'x++', 'x--', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x--', '--x', '++x', '--x', '--x', '++x', 'x++', '--x', 'x++', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x++', 'x++', '++x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x++', 'x--', '++x', '++x', 'x--', 'x--', '--x', 'x--', '--x', 'x--', 'x--', '++x', '++x', 'x--', '--x', 'x++', '--x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', 'x--', '--x', 'x++'], target=82823):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['--x', 'x--', 'x--', 'x--', 'x--', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '--x', '--x', '--x', 'x--', '--x', '--x', '++x', '++x', '++x', 'x++', '--x', 'x--', '++x', 'x--', 'x--', 'x++', 'x--', 'x++', 'x++', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x--', '--x', 'x--', 'x++', 'x--', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '++x', '++x', 'x++', 'x++', 'x--', '--x', 'x++', 'x++', 'x--', 'x++', '--x', 'x--', 'x--', '++x', '++x', '++x', 'x++', '++x', '--x', '--x', 'x++', '++x', '++x', 'x++', '++x', '--x', '++x', '--x', 'x--', '++x', '++x', '++x', '++x', 'x--', 'x--', '++x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', 'x--', '++x', 'x--', 'x--', 'x--', '++x', 'x--', '++x', 'x++', 'x--', 'x++', '++x', 'x++', '--x', '--x', '--x', 'x++', 'x++', '--x', '--x', '++x', '--x', 'x--', 'x--', '--x', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', 'x--', 'x++', '--x', '--x', '++x', '--x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '++x', 'x--', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x++', '++x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', 'x--', '++x', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x++', '++x', 'x--', '--x', '--x', '++x', 'x--', 'x--', '--x', 'x--', 'x--', 'x++', '--x', 'x++', '++x', '--x', 'x--', '--x', '--x', 'x--', 'x--', '--x', '++x', 'x--', '++x', '++x', '++x', 'x--', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', '--x', 'x--', 'x++', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x++', '--x', 'x++', 'x--', '--x', 'x++', 'x++', '++x', '--x', '++x', 'x++', 'x--', 'x++', 'x--', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', '++x', '--x', 'x++', '--x', '--x', 'x--', '--x', 'x++', 'x--', 'x++', '--x', 'x--', 'x++', 'x++', 'x--', '--x', '--x', 'x++', '--x', 'x--', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x++', 'x--', '--x', '++x', '--x', 'x--', '--x', '++x', '--x', '--x', '++x', 'x++', '--x', 'x++', '--x', 'x--', '++x', '--x', 'x--', 'x--', 'x++', '++x', 'x++', '++x', 'x--', '--x', 'x++', '--x', '++x', 'x++', 'x++', 'x++', '++x', '++x', 'x++', '++x', '++x', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x++', 'x++', 'x--', '++x', '++x', 'x--', 'x--', '--x', 'x--', '--x', 'x--', 'x--', '++x', '++x', 'x--', '--x', 'x++', '--x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', 'x++', '--x', '++x', 'x++', '--x', '--x', 'x--', '--x', 'x++'], target=82823):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_4", - "sat": "def sat(n: int, ops=['x--', 'x++', '++x', '--x', 'x++', '--x', 'x--'], target=61813):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x--', 'x++', '++x', '--x', 'x++', '--x', 'x--'], target=61813):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_5", - "sat": "def sat(n: int, ops: List[str]=[], target=28531):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=[], target=28531):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_6", - "sat": "def sat(n: int, ops=['x++', 'x--', 'x++', '++x'], target=30204):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x++', 'x--', 'x++', '++x'], target=30204):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_7", - "sat": "def sat(n: int, ops=['x--', '--x', '--x', 'x--', 'x++', 'x--', '++x', '++x', '++x', '++x', '--x', '++x', 'x++', 'x--'], target=8634):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['x--', '--x', '--x', 'x--', 'x++', 'x--', '++x', '++x', '++x', '++x', '--x', '++x', 'x++', 'x--'], target=8634):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_8", - "sat": "def sat(n: int, ops=['++x', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', 'x++', '--x', 'x--', '++x', '++x', '++x', 'x++', 'x--', 'x++', '++x', '--x', '++x', '++x', '--x', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x++', '--x', 'x--'], target=44587):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['++x', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '++x', 'x++', '--x', 'x--', '++x', '++x', '++x', 'x++', 'x--', 'x++', '++x', '--x', '++x', '++x', '--x', 'x++', 'x--', '--x', '++x', '++x', '++x', 'x++', 'x--', '--x', 'x++', 'x++', 'x++', '--x', 'x++', '--x', 'x--'], target=44587):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "IncDec_9", - "sat": "def sat(n: int, ops=['++x', 'x--', '++x', 'x--', '--x', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', '++x', '++x', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', '++x', '--x', '++x', '--x', 'x++', '--x', 'x++', '++x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', '--x', '--x', '--x', 'x--', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x++', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '++x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', '--x', 'x--', 'x--', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x++', '--x', '++x', '--x', '--x', 'x++', '++x', 'x--', '++x', 'x++', '++x', 'x--', '--x', 'x--', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', '++x', 'x--', '--x', '++x', '++x', '++x', '--x', '--x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x++', '--x', '--x', 'x++', 'x--', 'x++', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', 'x--', '++x', '++x', 'x--', '--x', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x--', '--x', '--x', 'x++', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x--', 'x++', 'x++', '--x', '++x', '++x', '++x', 'x++', '++x', '++x', '--x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', 'x++', 'x--', 'x++', '++x', '--x', 'x++', 'x--', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x++', '++x', '--x', 'x--', '++x', '++x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x--', '--x', 'x++', '++x', '--x', '--x', '++x', 'x--', '++x', '++x', 'x--', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x++', '--x', 'x++', '--x', '--x', '--x', 'x--', '++x', 'x++', 'x--', '++x', '--x', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x++', 'x--', '++x', 'x--', '++x', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x++', '--x', 'x++', 'x++', '++x', 'x--', 'x++', '--x', 'x++', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', '--x', '++x', '++x', 'x--', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', '++x', 'x--', '++x', '--x', 'x--', '++x', 'x++', '--x', '--x', 'x++', '--x', '--x', '++x', '++x', '--x', 'x++', '++x', '--x', 'x++', '--x', 'x++', '++x', '--x', '++x', '++x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '--x', 'x++', '--x', 'x++', 'x++', 'x--', '--x', '--x', '--x', 'x--', 'x--', 'x--', '--x', '++x', 'x++', 'x--', '++x', '++x', '++x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', 'x++', 'x++', '--x', 'x--', '++x', '--x', '--x', '--x', '--x', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '--x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', 'x--', 'x--', 'x++', '--x', 'x--', '++x', 'x--', '++x', '++x', '++x', '--x', 'x++', '--x', 'x++', '--x', '--x', 'x--', 'x++', 'x--', '--x', 'x++', 'x--', 'x--', '++x', '++x', '++x', 'x--', '++x', '--x', '++x', '--x', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '--x', '++x', '++x', '++x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', '--x', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x--', '--x', '--x', '++x', 'x--', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', '--x', 'x++', 'x--', '++x', '++x', '++x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', '--x', '--x', '++x', 'x--', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', 'x++', '--x', 'x++', '--x', 'x++', 'x--', 'x++', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '--x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', 'x--', '--x', '--x', 'x--', '++x', 'x++', 'x--', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x--', '--x', 'x++', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x++', 'x++', '--x', '++x', '--x', 'x++', '--x', '--x', '++x', '++x', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '++x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '--x', '--x', 'x--', 'x++', '--x', '--x', '++x', 'x--', '--x', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '--x', '++x', '--x', '--x', '--x', '++x', '--x'], target=35321):\n \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", - "sols": [ - "def sol(ops=['++x', 'x--', '++x', 'x--', '--x', '--x', '++x', 'x++', '++x', 'x++', 'x--', 'x--', '++x', '++x', '++x', '++x', '--x', 'x--', '--x', 'x++', '++x', 'x++', 'x++', 'x++', '--x', 'x--', '++x', '--x', '--x', 'x--', '--x', 'x++', '++x', '--x', 'x--', '++x', '--x', '++x', '--x', 'x++', '--x', 'x++', '++x', 'x++', '--x', '++x', 'x--', 'x--', 'x--', '--x', '--x', '--x', 'x--', 'x--', '--x', '--x', '--x', 'x++', 'x++', 'x--', 'x--', '++x', 'x--', '++x', '--x', 'x--', 'x++', 'x++', 'x++', '++x', 'x--', '--x', '++x', '++x', '++x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', '--x', 'x--', 'x--', 'x++', '++x', 'x--', 'x++', 'x--', '++x', 'x++', '--x', '++x', '--x', '--x', 'x++', '++x', 'x--', '++x', 'x++', '++x', 'x--', '--x', 'x--', 'x--', 'x--', '--x', '++x', 'x--', 'x--', '++x', '++x', 'x--', '--x', '++x', '++x', '++x', '--x', '--x', '++x', '++x', '--x', '--x', '++x', 'x--', 'x++', '--x', '--x', 'x++', 'x--', 'x++', 'x--', '--x', '++x', 'x++', 'x--', 'x--', 'x++', 'x++', '--x', '--x', 'x++', 'x--', '++x', 'x++', 'x++', 'x--', 'x--', '++x', '++x', 'x--', '--x', '--x', 'x--', '++x', 'x++', '--x', 'x++', 'x--', '--x', '--x', 'x++', 'x--', '++x', '++x', 'x--', '--x', '++x', '--x', 'x++', '++x', 'x--', '++x', 'x--', 'x--', 'x++', '--x', '++x', 'x--', 'x++', 'x++', '--x', '++x', '++x', '++x', 'x++', '++x', '++x', '--x', '++x', 'x--', 'x--', '++x', 'x++', 'x--', 'x--', 'x++', 'x--', '++x', '++x', 'x--', 'x++', 'x--', 'x++', '++x', '--x', 'x++', 'x--', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x++', '++x', '--x', 'x--', '++x', '++x', '--x', 'x--', '--x', 'x++', 'x++', 'x--', 'x--', '--x', 'x++', '++x', '--x', '--x', '++x', 'x--', '++x', '++x', 'x--', 'x++', '++x', 'x--', 'x++', 'x++', 'x++', '--x', '++x', 'x++', 'x++', '--x', 'x++', '--x', '--x', '--x', 'x--', '++x', 'x++', 'x--', '++x', '--x', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', 'x--', 'x++', 'x++', 'x--', '++x', 'x--', '++x', '--x', '++x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x++', '--x', 'x++', 'x++', '++x', 'x--', 'x++', '--x', 'x++', '--x', '++x', 'x--', 'x--', '++x', 'x--', 'x--', '--x', '--x', '++x', '++x', 'x--', 'x--', '++x', 'x--', '--x', '--x', '++x', '--x', 'x++', '++x', 'x--', '++x', '--x', 'x--', '++x', 'x++', '--x', '--x', 'x++', '--x', '--x', '++x', '++x', '--x', 'x++', '++x', '--x', 'x++', '--x', 'x++', '++x', '--x', '++x', '++x', 'x--', '--x', '--x', 'x++', '++x', '++x', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '--x', 'x++', '--x', 'x++', 'x++', 'x--', '--x', '--x', '--x', 'x--', 'x--', 'x--', '--x', '++x', 'x++', 'x--', '++x', '++x', '++x', 'x--', '++x', 'x++', 'x++', '--x', 'x--', 'x--', '++x', 'x++', 'x++', '--x', 'x--', '++x', '--x', '--x', '--x', '--x', 'x--', '++x', 'x--', 'x++', 'x++', '--x', 'x--', 'x++', 'x--', 'x++', 'x--', '--x', '--x', '--x', '++x', 'x--', '--x', 'x--', '--x', '++x', 'x--', 'x--', 'x--', 'x--', 'x++', '--x', 'x--', '++x', 'x--', '++x', '++x', '++x', '--x', 'x++', '--x', 'x++', '--x', '--x', 'x--', 'x++', 'x--', '--x', 'x++', 'x--', 'x--', '++x', '++x', '++x', 'x--', '++x', '--x', '++x', '--x', '--x', '++x', 'x++', '++x', '++x', '++x', 'x--', 'x++', '--x', 'x++', 'x++', '++x', '--x', '++x', '++x', '++x', '--x', 'x--', '--x', '--x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', '++x', 'x--', 'x++', '++x', 'x++', '--x', '--x', 'x--', 'x--', '++x', 'x--', '--x', 'x++', '++x', '++x', '++x', 'x--', 'x--', 'x++', '--x', 'x--', '--x', '--x', '++x', 'x--', '--x', '--x', 'x++', 'x++', '++x', '--x', 'x--', '++x', 'x++', '--x', 'x--', 'x--', '--x', 'x++', 'x--', '++x', '++x', '++x', '--x', 'x++', 'x++', 'x++', 'x++', '++x', '--x', 'x++', '--x', '--x', '++x', 'x--', 'x++', '++x', '++x', '--x', '--x', 'x--', 'x--', 'x++', '--x', 'x++', 'x--', 'x++', '--x', 'x++', '--x', 'x++', 'x--', 'x++', 'x--', '++x', '--x', '--x', 'x--', '++x', 'x--', 'x++', '++x', 'x--', '--x', 'x++', '--x', 'x--', '--x', '--x', 'x--', '--x', '++x', 'x--', 'x++', 'x++', 'x++', 'x++', '--x', '++x', 'x++', '--x', 'x--', 'x--', '--x', 'x++', 'x--', 'x++', 'x--', '--x', '--x', 'x--', '++x', 'x++', 'x--', '--x', '--x', '--x', '++x', 'x--', 'x--', '++x', 'x--', '--x', 'x++', 'x++', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '++x', '--x', 'x--', '++x', '++x', '--x', 'x--', '++x', '++x', 'x++', 'x++', '--x', '++x', '--x', 'x++', '--x', '--x', '++x', '++x', 'x--', '++x', 'x--', 'x++', 'x--', '++x', '--x', '++x', '++x', '--x', 'x--', 'x++', 'x++', '--x', 'x--', '--x', 'x++', 'x++', 'x++', 'x++', '--x', '--x', 'x--', 'x++', '--x', '--x', 'x--', 'x++', '--x', '--x', '++x', 'x--', '--x', '--x', 'x--', 'x--', '++x', '--x', '++x', '--x', 'x--', 'x--', 'x--', 'x--', '--x', 'x++', 'x++', '++x', 'x--', '++x', '++x', 'x--', '--x', '++x', 'x--', 'x--', 'x++', '++x', '++x', 'x--', '--x', '++x', '--x', '--x', '--x', '++x', '--x'], target=35321):\n return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_0", - "sat": "def sat(n: int, s=\"aaAab\", t=\"aAaaB\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"aaAab\", t=\"aAaaB\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_1", - "sat": "def sat(n: int, s=\"JyNuTexTETiGAVIC\", t=\"JynUTEXTetigAViC\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"JyNuTexTETiGAVIC\", t=\"JynUTEXTetigAViC\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_2", - "sat": "def sat(n: int, s=\"tExTYtOHahekomArof\", t=\"TExTYTohaHeKomryGUSeteXTUrYgir\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"tExTYtOHahekomArof\", t=\"TExTYTohaHeKomryGUSeteXTUrYgir\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_3", - "sat": "def sat(n: int, s=\"RObAQuYK\", t=\"robaQUYKkuLY\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"RObAQuYK\", t=\"robaQUYKkuLY\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_4", - "sat": "def sat(n: int, s=\"DUTeX\", t=\"dutdE\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"DUTeX\", t=\"dutdE\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_5", - "sat": "def sat(n: int, s=\"nETunysYMUtex\", t=\"neTuNYSyMutex\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"nETunysYMUtex\", t=\"neTuNYSyMutex\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_6", - "sat": "def sat(n: int, s=\"MUjOcOtEXtI\", t=\"mUJOCotexTIzOlycHotYmAhITE\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"MUjOcOtEXtI\", t=\"mUJOCotexTIzOlycHotYmAhITE\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_7", - "sat": "def sat(n: int, s=\"texTIh\", t=\"teXTIh\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"texTIh\", t=\"teXTIh\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_8", - "sat": "def sat(n: int, s=\"BoKiC\", t=\"BoHapoXekuCHanoR\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"BoKiC\", t=\"BoHapoXekuCHanoR\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CompareInAnyCase_9", - "sat": "def sat(n: int, s=\"gITOVYsyticHASeF\", t=\"gIxe\"):\n \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", - "sols": [ - "def sol(s=\"gITOVYsyticHASeF\", t=\"gIxe\"):\n if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_0", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_1", - "sat": "def sat(s: str, matrix=[[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_2", - "sat": "def sat(s: str, matrix=[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_3", - "sat": "def sat(s: str, matrix=[[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_4", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_5", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=4):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_6", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_7", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_8", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=1):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=1):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SlidingOne_9", - "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", - "sols": [ - "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=2):\n i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_0", - "sat": "def sat(s: str, inp=\"1+1+3+1+3+2+2+1+3+1+2\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"1+1+3+1+3+2+2+1+3+1+2\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_1", - "sat": "def sat(s: str, inp=\"2+3+1+2+2+2+1+1+1+3+2+3+3+3+2+3+1+3+3+2+1+2+3+1+2+1+3+2+3+1+1+2+2+3+1+2+2+1+3+2+3+2+3+2+2\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"2+3+1+2+2+2+1+1+1+3+2+3+3+3+2+3+1+3+3+2+1+2+3+1+2+1+3+2+3+1+1+2+2+3+1+2+2+1+3+2+3+2+3+2+2\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_2", - "sat": "def sat(s: str, inp=\"3+2+2\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"3+2+2\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_3", - "sat": "def sat(s: str, inp=\"3+2+1+1+3+3+2+2+2+3+2+3+3+1+1\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"3+2+1+1+3+3+2+2+2+3+2+3+3+1+1\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_4", - "sat": "def sat(s: str, inp=\"2+2+2+1+1+1+2+1+3+3+3+3+2+2+2+1+2+3+3+1+3+2+3+2+3+2+2+3+2+3+1+2+1+3+3+2+3+1+1+3+3+1\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"2+2+2+1+1+1+2+1+3+3+3+3+2+2+2+1+2+3+3+1+3+2+3+2+3+2+2+3+2+3+1+2+1+3+3+2+3+1+1+3+3+1\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_5", - "sat": "def sat(s: str, inp=\"1\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"1\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_6", - "sat": "def sat(s: str, inp=\"3+2+2+3+3+1+3+1+3+2+2+2+3+3+1+1+3+3+3+2+3+2+1+3+2+3+2+1+1+3+2+1+1+1+2+2+1\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"3+2+2+3+3+1+3+1+3+2+2+2+3+3+1+1+3+3+3+2+3+2+1+3+2+3+2+1+1+3+2+1+1+1+2+2+1\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_7", - "sat": "def sat(s: str, inp=\"3+1+2+1+3+3+2+2+2+3+3+3+2+1+3+2+3+2+3+3\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"3+1+2+1+3+3+2+2+2+3+3+3+2+1+3+2+3+2+3+3\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_8", - "sat": "def sat(s: str, inp=\"3+1+2+1+1+1+3+1+3+1+1+1+2+3+1+2+1+1+3+3+3+2+3+2+2+3+1+2+3+1+3+3+1+1+3+2+2\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"3+1+2+1+1+1+3+1+3+1+1+1+2+3+1+2+1+1+3+3+3+2+3+2+2+3+1+2+3+1+3+3+1+1+3+2+2\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SortPlusPlus_9", - "sat": "def sat(s: str, inp=\"2+3+2+3+1+1+3+3+3+3+2+1+1+1+2+3+1+2+2+1+3+3\"):\n \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", - "sols": [ - "def sol(inp=\"2+3+2+3+1+1+3+3+3+3+2+1+1+1+2+3+1+2+2+1+3+3\"):\n return \"+\".join(sorted(inp.split(\"+\")))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_0", - "sat": "def sat(s: str, word=\"konjac\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"konjac\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_1", - "sat": "def sat(s: str, word=\"nojapoxe\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"nojapoxe\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_2", - "sat": "def sat(s: str, word=\"silon\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"silon\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_3", - "sat": "def sat(s: str, word=\"fekovo\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"fekovo\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_4", - "sat": "def sat(s: str, word=\"mo\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"mo\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_5", - "sat": "def sat(s: str, word=\"xapequanukyhyvuvisup\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"xapequanukyhyvuvisup\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_6", - "sat": "def sat(s: str, word=\"wu\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"wu\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_7", - "sat": "def sat(s: str, word=\"chadumychi\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"chadumychi\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_8", - "sat": "def sat(s: str, word=\"cyquifilynyhuzo\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"cyquifilynyhuzo\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CapitalizeFirstLetter_9", - "sat": "def sat(s: str, word=\"t\"):\n \"\"\"Capitalize the first letter of word\"\"\"\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", - "sols": [ - "def sol(word=\"t\"):\n return word[0].upper() + word[1:]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_0", - "sat": "def sat(t: str, s=\"abbbcabbac\", target=7):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"abbbcabbac\", target=7): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_1", - "sat": "def sat(t: str, s=\"cbbbbbcbbbbbbbaccacacaacbbcaaacbbaacbabacabccbbbcaacbbacaabcabbaacbbaa\", target=43):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"cbbbbbcbbbbbbbaccacacaacbbcaaacbbaacbabacabccbbbcaacbbacaabcabbaacbbaa\", target=43): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_2", - "sat": "def sat(t: str, s=\"bcb\", target=3):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"bcb\", target=3): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_3", - "sat": "def sat(t: str, s=\"c\", target=1):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"c\", target=1): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_4", - "sat": "def sat(t: str, s=\"bcbcabba\", target=7):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"bcbcabba\", target=7): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_5", - "sat": "def sat(t: str, s=\"ccabbaabababcabbaacccbaac\", target=17):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"ccabbaabababcabbaacccbaac\", target=17): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_6", - "sat": "def sat(t: str, s=\"bccabcabbaaacacccbbcbaaabbbbcbbabbacbcbbbcaaabbbbcabacbabaaaacacccacabacbabcbbccacbcbcbccacbacbacbabacbacaaaabbbcacaabbbbbccbcbcbbbbbbbaaaaaabacbbbaabcaabbbcbaaaaacabcaaacbbbaabcabbcaccbbccaaacbacacacbaabbbbbccabacaccaacaabcbcaaababaabaabbacccaccacabaabcbabbccacbbbaaabcaccbacaacbbaacaabbaccbaaaccabbbbcbcaaabbaacbaccabbbcababacccccabbbacaacbbbcccccbbcabbaccbabcbcbaabbccabaccbaaaacaabccabccbaccccbbbccabbabbabbabacbabbbaabaaccaacabbaacbcccbaababbccacabcbaacbccbabacacbbccaccbcaccbbcbabbbabcbccbbcabbbbaabaabbcaacbabcbccaacacccaaccabbabcaacaabcacbbcbbccacbbbcbaaaacbbbaacabaaabcaabcbcbbbccbcbccbbaaaccbccbbcbccccaabbaacccaccaaacbcccabbcaccbacccbcabbababcabcbbacccbacccbbbcaccaaaacbbacccbbabccacacaabaaaaaaabbaaacabcabacbcaccaabacbbcbaccaaaabcbbcaabaaab\", target=482):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"bccabcabbaaacacccbbcbaaabbbbcbbabbacbcbbbcaaabbbbcabacbabaaaacacccacabacbabcbbccacbcbcbccacbacbacbabacbacaaaabbbcacaabbbbbccbcbcbbbbbbbaaaaaabacbbbaabcaabbbcbaaaaacabcaaacbbbaabcabbcaccbbccaaacbacacacbaabbbbbccabacaccaacaabcbcaaababaabaabbacccaccacabaabcbabbccacbbbaaabcaccbacaacbbaacaabbaccbaaaccabbbbcbcaaabbaacbaccabbbcababacccccabbbacaacbbbcccccbbcabbaccbabcbcbaabbccabaccbaaaacaabccabccbaccccbbbccabbabbabbabacbabbbaabaaccaacabbaacbcccbaababbccacabcbaacbccbabacacbbccaccbcaccbbcbabbbabcbccbbcabbbbaabaabbcaacbabcbccaacacccaaccabbabcaacaabcacbbcbbccacbbbcbaaaacbbbaacabaaabcaabcbcbbbccbcbccbbaaaccbccbbcbccccaabbaacccaccaaacbcccabbcaccbacccbcabbababcabcbbacccbacccbbbcaccaaaacbbacccbbabccacacaabaaaaaaabbaaacabcabacbcaccaabacbbcbaccaaaabcbbcaabaaab\", target=482): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_7", - "sat": "def sat(t: str, s=\"cbacccabbcbcbbabbbabbcacaaccbabbbbaabcbccaaacbbababbcbbbcbbcccccaacbacbcacbcbacbcbacabbabababaaacabcbacaabacccbbbcccabaabcccbccbabbccababcaaccabcbabaacacbccaacbabbbabbacaacacababccaabcbbbbbabcacbabbcbacabbbbbccbcabccaaabbaaccabbbcacaabbaabbcaabbbacbbccbababbcccabcbcabbaaabababbcbcbabcbbacbacbcaacaababcaccbaabaacaacaccaacbbcabbcbaacbcaaaacabccacccbbcccacccccbcabaaacabccabccbccabbbaaacacaabacccbacbcaaaacaabccaccccbccaccaaabcbabcbcbacabbbcccbbacbccabbcacababccaaabacbaacababaabcaabbbcaabaccbccccaababbacbbbbaabbaaaccaccbaccbbbacbaccaabcbcaabbabacbbbaabccacaaabacccbaabbacbabccaaccbabbaabbcccabaaccabcccacbcabbabbcbcabcabbccabbcbbacacacabbababcccbbabaaabcccacaccaaaacaaabcacbbcbcbbbccbaabcaaabccbacaccbabaacccbabaccbaaaccbbcbbacbabcacacabbaccacabacababacbbcacbccbbccacbcabbbabbccbbcccbcacacacaaaacacbbcaababcbb\", target=557):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"cbacccabbcbcbbabbbabbcacaaccbabbbbaabcbccaaacbbababbcbbbcbbcccccaacbacbcacbcbacbcbacabbabababaaacabcbacaabacccbbbcccabaabcccbccbabbccababcaaccabcbabaacacbccaacbabbbabbacaacacababccaabcbbbbbabcacbabbcbacabbbbbccbcabccaaabbaaccabbbcacaabbaabbcaabbbacbbccbababbcccabcbcabbaaabababbcbcbabcbbacbacbcaacaababcaccbaabaacaacaccaacbbcabbcbaacbcaaaacabccacccbbcccacccccbcabaaacabccabccbccabbbaaacacaabacccbacbcaaaacaabccaccccbccaccaaabcbabcbcbacabbbcccbbacbccabbcacababccaaabacbaacababaabcaabbbcaabaccbccccaababbacbbbbaabbaaaccaccbaccbbbacbaccaabcbcaabbabacbbbaabccacaaabacccbaabbacbabccaaccbabbaabbcccabaaccabcccacbcabbabbcbcabcabbccabbcbbacacacabbababcccbbabaaabcccacaccaaaacaaabcacbbcbcbbbccbaabcaaabccbacaccbabaacccbabaccbaaaccbbcbbacbabcacacabbaccacabacababacbbcacbccbbccacbcabbbabbccbbcccbcacacacaaaacacbbcaababcbb\", target=557): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_8", - "sat": "def sat(t: str, s=\"acb\", target=3):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"acb\", target=3): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "LongestSubsetString_9", - "sat": "def sat(t: str, s=\"bbbbb\", target=1):\n \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", - "sols": [ - "def sol(s=\"bbbbb\", target=1): # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_0", - "sat": "def sat(n: int, s=\"0000101111111000010\", k=5):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"0000101111111000010\", k=5):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"0000101111111000010\", k=5):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"0000101111111000010\", k=5):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"0000101111111000010\", k=5):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_1", - "sat": "def sat(n: int, s=\"000000\", k=4):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"000000\", k=4):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"000000\", k=4):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"000000\", k=4):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"000000\", k=4):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_2", - "sat": "def sat(n: int, s=\"001100000000000000000000101010100111101110000100\", k=18):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"001100000000000000000000101010100111101110000100\", k=18):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"001100000000000000000000101010100111101110000100\", k=18):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"001100000000000000000000101010100111101110000100\", k=18):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"001100000000000000000000101010100111101110000100\", k=18):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_3", - "sat": "def sat(n: int, s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"10100111100110001010011110100111010110010000101101110100010\", k=3):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_4", - "sat": "def sat(n: int, s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"010110011110100000001010010010001101001110110001111011000000000000000000000011101010111000111011001100111101101\", k=18):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_5", - "sat": "def sat(n: int, s=\"101100110010111111111011010101110010\", k=5):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"101100110010111111111011010101110010\", k=5):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"101100110010111111111011010101110010\", k=5):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"101100110010111111111011010101110010\", k=5):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"101100110010111111111011010101110010\", k=5):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_6", - "sat": "def sat(n: int, s=\"1110100100011000011000110000011000011100101011110001101100001111111011001011100111\", k=2):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"1110100100011000011000110000011000011100101011110001101100001111111011001011100111\", k=2):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"1110100100011000011000110000011000011100101011110001101100001111111011001011100111\", k=2):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"1110100100011000011000110000011000011100101011110001101100001111111011001011100111\", k=2):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"1110100100011000011000110000011000011100101011110001101100001111111011001011100111\", k=2):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_7", - "sat": "def sat(n: int, s=\"0100101000001110111101001011010110110000000000001000011101101011001110\", k=10):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"0100101000001110111101001011010110110000000000001000011101101011001110\", k=10):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"0100101000001110111101001011010110110000000000001000011101101011001110\", k=10):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"0100101000001110111101001011010110110000000000001000011101101011001110\", k=10):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"0100101000001110111101001011010110110000000000001000011101101011001110\", k=10):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_8", - "sat": "def sat(n: int, s=\"00100001000101001001011011000010010010110110011110110000110100001110010111011101001011000000010110010000001000000010011001011000001000101111010011111100100011000011001011001111001100011110000010001110000100100101101100101111111001001110110100100010010101011100111010100100101101100110110011001110000011011010101111011000010111011111001011000011010110000111001011110001011100100001100011110011000011100111000011000000000000001101101100000100010101000111111001111010000101000001111100111011011110110000001101111001001010110100110000011101010110101000011100101000110001000100111110111001100011101101110100001010100001110001000101010101111101101100101100110000110011000001110000010010100110110111011101100111111110101001100100001000\", k=11):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"00100001000101001001011011000010010010110110011110110000110100001110010111011101001011000000010110010000001000000010011001011000001000101111010011111100100011000011001011001111001100011110000010001110000100100101101100101111111001001110110100100010010101011100111010100100101101100110110011001110000011011010101111011000010111011111001011000011010110000111001011110001011100100001100011110011000011100111000011000000000000001101101100000100010101000111111001111010000101000001111100111011011110110000001101111001001010110100110000011101010110101000011100101000110001000100111110111001100011101101110100001010100001110001000101010101111101101100101100110000110011000001110000010010100110110111011101100111111110101001100100001000\", k=11):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"00100001000101001001011011000010010010110110011110110000110100001110010111011101001011000000010110010000001000000010011001011000001000101111010011111100100011000011001011001111001100011110000010001110000100100101101100101111111001001110110100100010010101011100111010100100101101100110110011001110000011011010101111011000010111011111001011000011010110000111001011110001011100100001100011110011000011100111000011000000000000001101101100000100010101000111111001111010000101000001111100111011011110110000001101111001001010110100110000011101010110101000011100101000110001000100111110111001100011101101110100001010100001110001000101010101111101101100101100110000110011000001110000010010100110110111011101100111111110101001100100001000\", k=11):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"00100001000101001001011011000010010010110110011110110000110100001110010111011101001011000000010110010000001000000010011001011000001000101111010011111100100011000011001011001111001100011110000010001110000100100101101100101111111001001110110100100010010101011100111010100100101101100110110011001110000011011010101111011000010111011111001011000011010110000111001011110001011100100001100011110011000011100111000011000000000000001101101100000100010101000111111001111010000101000001111100111011011110110000001101111001001010110100110000011101010110101000011100101000110001000100111110111001100011101101110100001010100001110001000101010101111101101100101100110000110011000001110000010010100110110111011101100111111110101001100100001000\", k=11):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"00100001000101001001011011000010010010110110011110110000110100001110010111011101001011000000010110010000001000000010011001011000001000101111010011111100100011000011001011001111001100011110000010001110000100100101101100101111111001001110110100100010010101011100111010100100101101100110110011001110000011011010101111011000010111011111001011000011010110000111001011110001011100100001100011110011000011100111000011000000000000001101101100000100010101000111111001111010000101000001111100111011011110110000001101111001001010110100110000011101010110101000011100101000110001000100111110111001100011101101110100001010100001110001000101010101111101101100101100110000110011000001110000010010100110110111011101100111111110101001100100001000\", k=11):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FindHomogeneousSubstring_9", - "sat": "def sat(n: int, s=\"00000000000000\", k=13):\n \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"\n return s[n:n + k] == s[n] * k", - "sols": [ - "def sol(s=\"00000000000000\", k=13):\n return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", - "def sol(s=\"00000000000000\", k=13):\n import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", - "def sol(s=\"00000000000000\", k=13):\n if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", - "def sol(s=\"00000000000000\", k=13):\n try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_0", - "sat": "def sat(delta: List[int], nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_1", - "sat": "def sat(delta: List[int], nums=[[-48, -64, 10], [-6, 46, 95], [89, 95, 20], [-96, 45, 74], [-78, 19, 47], [-6, -69, 55]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-48, -64, 10], [-6, 46, 95], [89, 95, 20], [-96, 45, 74], [-78, 19, 47], [-6, -69, 55]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_2", - "sat": "def sat(delta: List[int], nums=[[-17, -87, 34], [-8, -47, -68], [92, -14, -18], [18, 89, 85], [52, 89, -56], [-38, -19, -53], [-78, -25, -34]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-17, -87, 34], [-8, -47, -68], [92, -14, -18], [18, 89, 85], [52, 89, -56], [-38, -19, -53], [-78, -25, -34]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_3", - "sat": "def sat(delta: List[int], nums=[[35, -53, 59], [78, -51, 93], [-20, -17, -17], [64, 46, -24], [-81, -100, 47], [-98, -21, 47], [48, -85, -55], [-82, -29, 65]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[35, -53, 59], [78, -51, 93], [-20, -17, -17], [64, 46, -24], [-81, -100, 47], [-98, -21, 47], [48, -85, -55], [-82, -29, 65]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_4", - "sat": "def sat(delta: List[int], nums=[[-16, 53, 37], [-54, -85, 65], [-46, 49, -81], [88, -47, -35], [53, -82, 4], [45, 94, 39], [72, -57, 27], [40, 35, -44], [-15, 32, 21]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-16, 53, 37], [-54, -85, 65], [-46, 49, -81], [88, -47, -35], [53, -82, 4], [45, 94, 39], [72, -57, 27], [40, 35, -44], [-15, 32, 21]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_5", - "sat": "def sat(delta: List[int], nums=[[-12, -33, -100], [39, -29, 38], [-43, 84, -92], [40, -92, 43], [-56, -62, -58], [89, 64, -10]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-12, -33, -100], [39, -29, 38], [-43, 84, -92], [40, -92, 43], [-56, -62, -58], [89, 64, -10]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_6", - "sat": "def sat(delta: List[int], nums=[[0, 28, 19], [-53, 53, 85], [25, 46, -77], [3, 47, 92], [-56, -75, 76], [-76, -98, -82], [21, -49, -38], [-17, -18, -33], [21, 38, -77]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[0, 28, 19], [-53, 53, 85], [25, 46, -77], [3, 47, 92], [-56, -75, 76], [-76, -98, -82], [21, -49, -38], [-17, -18, -33], [21, 38, -77]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_7", - "sat": "def sat(delta: List[int], nums=[[-4, 21, 29], [-60, 58, -80], [35, 33, 52], [51, -15, 86], [-2, -53, -72], [76, 35, -20], [56, -83, 67]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-4, 21, 29], [-60, 58, -80], [35, 33, 52], [51, -15, 86], [-2, -53, -72], [76, 35, -20], [56, -83, 67]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_8", - "sat": "def sat(delta: List[int], nums=[[-44, -44, 13], [-65, 44, 89], [93, -46, -4], [86, 92, -99]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-44, -44, 13], [-65, 44, 89], [93, -46, -4], [86, 92, -99]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Triple0_9", - "sat": "def sat(delta: List[int], nums=[[-92, 24, 54], [-72, 71, -81], [-83, -53, -72], [7, -87, 49]]):\n \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", - "sols": [ - "def sol(nums=[[-92, 24, 54], [-72, 71, -81], [-83, -53, -72], [7, -87, 49]]):\n return [-sum(vec[i] for vec in nums) for i in range(3)]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_0", - "sat": "def sat(n: int, a=17, b=100, c=20):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=17, b=100, c=20):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_1", - "sat": "def sat(n: int, a=62, b=92, c=24):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=62, b=92, c=24):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_2", - "sat": "def sat(n: int, a=14, b=50, c=47):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=14, b=50, c=47):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_3", - "sat": "def sat(n: int, a=62, b=63, c=13):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=62, b=63, c=13):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_4", - "sat": "def sat(n: int, a=5, b=31, c=37):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=5, b=31, c=37):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_5", - "sat": "def sat(n: int, a=71, b=70, c=95):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=71, b=70, c=95):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_6", - "sat": "def sat(n: int, a=37, b=13, c=18):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=37, b=13, c=18):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_7", - "sat": "def sat(n: int, a=66, b=67, c=83):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=66, b=67, c=83):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_8", - "sat": "def sat(n: int, a=1, b=72, c=37):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=1, b=72, c=37):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TotalDifference_9", - "sat": "def sat(n: int, a=42, b=82, c=5):\n \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"\n return n + a == sum([b * i for i in range(c)])", - "sols": [ - "def sol(a=42, b=82, c=5):\n return -a + sum([b * i for i in range(c)])" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_0", - "sat": "def sat(n: int, v=17, w=100):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=17, w=100):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_1", - "sat": "def sat(n: int, v=75129500, w=979292947):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=75129500, w=979292947):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_2", - "sat": "def sat(n: int, v=609909721, w=872375011):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=609909721, w=872375011):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_3", - "sat": "def sat(n: int, v=313946483, w=806690290):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=313946483, w=806690290):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_4", - "sat": "def sat(n: int, v=54888266, w=670740803):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=54888266, w=670740803):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_5", - "sat": "def sat(n: int, v=738230287, w=964473203):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=738230287, w=964473203):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_6", - "sat": "def sat(n: int, v=573098270, w=808925148):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=573098270, w=808925148):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_7", - "sat": "def sat(n: int, v=615768401, w=982664742):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=615768401, w=982664742):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_8", - "sat": "def sat(n: int, v=49645456, w=384097479):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=49645456, w=384097479):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "TripleDouble_9", - "sat": "def sat(n: int, v=149517795, w=350345640):\n \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", - "sols": [ - "def sol(v=149517795, w=350345640):\n i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_0", - "sat": "def sat(res: int, m=1234578987654321, n=4):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=1234578987654321, n=4):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_1", - "sat": "def sat(res: int, m=52891398375817839454, n=3):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=52891398375817839454, n=3):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_2", - "sat": "def sat(res: int, m=22262059435814874058, n=6):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=22262059435814874058, n=6):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_3", - "sat": "def sat(res: int, m=23602903522227899062, n=2):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=23602903522227899062, n=2):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_4", - "sat": "def sat(res: int, m=27368816582234104063, n=4):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=27368816582234104063, n=4):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_5", - "sat": "def sat(res: int, m=3310493833144418244, n=2):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=3310493833144418244, n=2):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_6", - "sat": "def sat(res: int, m=80720366033206876975, n=6):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=80720366033206876975, n=6):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_7", - "sat": "def sat(res: int, m=57039061326331194861, n=8):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=57039061326331194861, n=8):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_8", - "sat": "def sat(res: int, m=18188214609520625022, n=5):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=18188214609520625022, n=5):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "RepeatDec_9", - "sat": "def sat(res: int, m=25928053646682580431, n=6):\n \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", - "sols": [ - "def sol(m=25928053646682580431, n=6):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_0", - "sat": "def sat(li: List[int], n=149432, upper=14943):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=149432, upper=14943):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_1", - "sat": "def sat(li: List[int], n=493863, upper=49386):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=493863, upper=49386):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_2", - "sat": "def sat(li: List[int], n=827208, upper=82720):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=827208, upper=82720):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_3", - "sat": "def sat(li: List[int], n=176183, upper=17618):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=176183, upper=17618):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_4", - "sat": "def sat(li: List[int], n=483088, upper=48308):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=483088, upper=48308):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_5", - "sat": "def sat(li: List[int], n=995935, upper=99593):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=995935, upper=99593):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_6", - "sat": "def sat(li: List[int], n=303225, upper=30322):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=303225, upper=30322):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_7", - "sat": "def sat(li: List[int], n=706792, upper=70679):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=706792, upper=70679):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_8", - "sat": "def sat(li: List[int], n=245652, upper=24565):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=245652, upper=24565):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "ShortestDecDelta_9", - "sat": "def sat(li: List[int], n=234352, upper=23435):\n \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", - "sols": [ - "def sol(n=234352, upper=23435):\n m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_0", - "sat": "def sat(n: int, pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_1", - "sat": "def sat(n: int, pairs=[[735272, 0], [959403, 509925], [627622, 420078], [26718, 90062], [175999, 98715], [428400, 1098754], [958640, 543606], [983032, 181754], [143406, 1301552], [183299, 437141], [133206, 199853], [679951, 366700], [383704, 737787], [476200, 226078], [923093, 81263], [574756, 679331], [766050, 5511], [214260, 445680], [434074, 747765], [769774, 209386], [512796, 2095723], [0, 612991]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[735272, 0], [959403, 509925], [627622, 420078], [26718, 90062], [175999, 98715], [428400, 1098754], [958640, 543606], [983032, 181754], [143406, 1301552], [183299, 437141], [133206, 199853], [679951, 366700], [383704, 737787], [476200, 226078], [923093, 81263], [574756, 679331], [766050, 5511], [214260, 445680], [434074, 747765], [769774, 209386], [512796, 2095723], [0, 612991]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_2", - "sat": "def sat(n: int, pairs=[[266519, 0], [548032, 32788], [612482, 632311], [465240, 376403], [123288, 475698], [962873, 439482], [193531, 258475], [747616, 319130], [592192, 824307], [508933, 296745], [411467, 566648], [905981, 19854], [805465, 657818], [802088, 325540], [127441, 1703553], [19150, 964316], [0, 199230]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[266519, 0], [548032, 32788], [612482, 632311], [465240, 376403], [123288, 475698], [962873, 439482], [193531, 258475], [747616, 319130], [592192, 824307], [508933, 296745], [411467, 566648], [905981, 19854], [805465, 657818], [802088, 325540], [127441, 1703553], [19150, 964316], [0, 199230]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_3", - "sat": "def sat(n: int, pairs=[[0, 0]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[0, 0]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_4", - "sat": "def sat(n: int, pairs=[[459604, 0], [364611, 68505], [562652, 512251], [668655, 471975], [464486, 626280], [138684, 177065], [163296, 68630], [188271, 104677], [367839, 338137], [73022, 362103], [464143, 484458], [214935, 189299], [643725, 283515], [908210, 541732], [710201, 234839], [854230, 34479], [3288, 675724], [846637, 396244], [0, 2526576]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[459604, 0], [364611, 68505], [562652, 512251], [668655, 471975], [464486, 626280], [138684, 177065], [163296, 68630], [188271, 104677], [367839, 338137], [73022, 362103], [464143, 484458], [214935, 189299], [643725, 283515], [908210, 541732], [710201, 234839], [854230, 34479], [3288, 675724], [846637, 396244], [0, 2526576]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_5", - "sat": "def sat(n: int, pairs=[[715119, 0], [367499, 222628], [169111, 122790], [59845, 565057], [203981, 122674], [815914, 202757], [512331, 830939], [175069, 615531], [0, 336493]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[715119, 0], [367499, 222628], [169111, 122790], [59845, 565057], [203981, 122674], [815914, 202757], [512331, 830939], [175069, 615531], [0, 336493]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_6", - "sat": "def sat(n: int, pairs=[[230265, 0], [205727, 90163], [575836, 196224], [865356, 697426], [0, 893371]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[230265, 0], [205727, 90163], [575836, 196224], [865356, 697426], [0, 893371]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_7", - "sat": "def sat(n: int, pairs=[[974270, 0], [69341, 140710], [197492, 297929], [297139, 489322], [190395, 166439], [969986, 67114], [453912, 1122151], [336475, 341518], [0, 863827]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[974270, 0], [69341, 140710], [197492, 297929], [297139, 489322], [190395, 166439], [969986, 67114], [453912, 1122151], [336475, 341518], [0, 863827]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_8", - "sat": "def sat(n: int, pairs=[[50407, 0], [364526, 48888], [594103, 302747], [0, 657401]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[50407, 0], [364526, 48888], [594103, 302747], [0, 657401]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxDelta_9", - "sat": "def sat(n: int, pairs=[[995674, 0], [397252, 890816], [590613, 337581], [419282, 97852], [378800, 749627], [344725, 386184], [733279, 281851], [551017, 308615], [0, 1358116]]):\n \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", - "sols": [ - "def sol(pairs=[[995674, 0], [397252, 890816], [590613, 337581], [419282, 97852], [378800, 749627], [344725, 386184], [733279, 281851], [551017, 308615], [0, 1358116]]):\n tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_0", - "sat": "def sat(s_case: str, s=\"CanYouTellIfItHASmoreCAPITALS\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"CanYouTellIfItHASmoreCAPITALS\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_1", - "sat": "def sat(s_case: str, s=\"ThUcynICHiHIc\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"ThUcynICHiHIc\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_2", - "sat": "def sat(s_case: str, s=\"riziP\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"riziP\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_3", - "sat": "def sat(s_case: str, s=\"KANExAjoHiBotipomyVOkATuMY\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"KANExAjoHiBotipomyVOkATuMY\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_4", - "sat": "def sat(s_case: str, s=\"rAC\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"rAC\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_5", - "sat": "def sat(s_case: str, s=\"t\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"t\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_6", - "sat": "def sat(s_case: str, s=\"VInAmozUrAzuwYZOvuPETaLEpEJOD\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"VInAmozUrAzuwYZOvuPETaLEpEJOD\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_7", - "sat": "def sat(s_case: str, s=\"RotAS\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"RotAS\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_8", - "sat": "def sat(s_case: str, s=\"timyGeTAmytURAJyxe\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"timyGeTAmytURAJyxe\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CommonCase_9", - "sat": "def sat(s_case: str, s=\"mOsUthYzys\"):\n \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", - "sols": [ - "def sol(s=\"mOsUthYzys\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_0", - "sat": "def sat(inds: List[int], string=\"Sssuubbstriiingg\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"Sssuubbstriiingg\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_1", - "sat": "def sat(inds: List[int], string=\"su absItIstrilnvgenw\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"su absItIstrilnvgenw\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_2", - "sat": "def sat(inds: List[int], string=\"sKubssB tzCzPrZiL inCgN\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"sKubssB tzCzPrZiL inCgN\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_3", - "sat": "def sat(inds: List[int], string=\"suUbstriPng\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"suUbstriPng\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_4", - "sat": "def sat(inds: List[int], string=\"stuqb VqsMJptxriWYe nmfgNfW\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"stuqb VqsMJptxriWYe nmfgNfW\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_5", - "sat": "def sat(inds: List[int], string=\"iCsueObsRTtryijnUgj \"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"iCsueObsRTtryijnUgj \"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_6", - "sat": "def sat(inds: List[int], string=\"subscnaQftrXionhIdqgk\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"subscnaQftrXionhIdqgk\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_7", - "sat": "def sat(inds: List[int], string=\"csubbstring\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"csubbstring\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_8", - "sat": "def sat(inds: List[int], string=\"CsRCuebYMsTtrd O jrCixnlg\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"CsRCuebYMsTtrd O jrCixnlg\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sssuubbstriiingg_9", - "sat": "def sat(inds: List[int], string=\"substring\"):\n \"\"\"Find increasing indices to make the substring \"substring\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", - "sols": [ - "def sol(string=\"substring\"):\n target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_0", - "sat": "def sat(inds: List[int], string=\"enlightenment\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"enlightenment\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_1", - "sat": "def sat(inds: List[int], string=\"inntGetlige\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"inntGetlige\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_2", - "sat": "def sat(inds: List[int], string=\"gteliikeenGgqIHent\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"gteliikeenGgqIHent\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_3", - "sat": "def sat(inds: List[int], string=\"xaGliigNntJfeeSm nnEyt\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"xaGliigNntJfeeSm nnEyt\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_4", - "sat": "def sat(inds: List[int], string=\" einliJSgeteq ne CAlti\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\" einliJSgeteq ne CAlti\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_5", - "sat": "def sat(inds: List[int], string=\"ligienntte\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"ligienntte\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_6", - "sat": "def sat(inds: List[int], string=\"eOE ilPlbfgTnAit VKgqXe ent\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"eOE ilPlbfgTnAit VKgqXe ent\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_7", - "sat": "def sat(inds: List[int], string=\"Bin meoculctdigent\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"Bin meoculctdigent\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_8", - "sat": "def sat(inds: List[int], string=\"netelicgenit\"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"netelicgenit\"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Sstriiinggssuubb_9", - "sat": "def sat(inds: List[int], string=\"ignenCttleli \"):\n \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", - "sols": [ - "def sol(string=\"ignenCttleli \"):\n target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_0", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_1", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=9):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=9):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_2", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0], n_steps=4):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0], n_steps=4):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_3", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=12):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], n_steps=12):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_4", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 0, 0, 0, 0], n_steps=3):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 0, 0, 0, 0], n_steps=3):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_5", - "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0], n_steps=3):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0], n_steps=3):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_6", - "sat": "def sat(seq: List[int], target=[0, 1, 0, 1, 0, 0, 1], n_steps=0):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[0, 1, 0, 1, 0, 0, 1], n_steps=0):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_7", - "sat": "def sat(seq: List[int], target=[0, 0, 0, 0], n_steps=3):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[0, 0, 0, 0], n_steps=3):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_8", - "sat": "def sat(seq: List[int], target=[1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0], n_steps=1):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0], n_steps=1):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Moving0s_9", - "sat": "def sat(seq: List[int], target=[1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0], n_steps=0):\n \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), target target sequence\n is achieved.\n \"\"\"\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", - "sols": [ - "def sol(target=[1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0], n_steps=0):\n s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_0", - "sat": "def sat(d: int, n=6002685529):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=6002685529):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_1", - "sat": "def sat(d: int, n=16):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=16):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_2", - "sat": "def sat(d: int, n=433459952851983617609247):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=433459952851983617609247):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_3", - "sat": "def sat(d: int, n=738195924589532712188415):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=738195924589532712188415):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_4", - "sat": "def sat(d: int, n=323190690645573746957862):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=323190690645573746957862):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_5", - "sat": "def sat(d: int, n=77029799848890981965046):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=77029799848890981965046):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_6", - "sat": "def sat(d: int, n=20):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=20):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_7", - "sat": "def sat(d: int, n=23249659):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=23249659):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_8", - "sat": "def sat(d: int, n=3854):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=3854):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Factor47_9", - "sat": "def sat(d: int, n=30902441):\n \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"\n return n % d == 0 and all(i in \"47\" for i in str(d))", - "sols": [ - "def sol(n=30902441):\n def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_0", - "sat": "def sat(d: int, n=123456789):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=123456789):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_1", - "sat": "def sat(d: int, n=659104579100082212):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=659104579100082212):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_2", - "sat": "def sat(d: int, n=476988101965):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=476988101965):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_3", - "sat": "def sat(d: int, n=3169877099077541094754):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=3169877099077541094754):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_4", - "sat": "def sat(d: int, n=707):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=707):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_5", - "sat": "def sat(d: int, n=542879438572585977162504):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=542879438572585977162504):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_6", - "sat": "def sat(d: int, n=394858):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=394858):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_7", - "sat": "def sat(d: int, n=215559299677888):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=215559299677888):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_8", - "sat": "def sat(d: int, n=6265261066951862):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=6265261066951862):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Count47_9", - "sat": "def sat(d: int, n=59663139191673979002523664098):\n \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", - "sols": [ - "def sol(n=59663139191673979002523664098):\n return int(\"4444\" + \"0\" * (len(str(n)) - 3))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_0", - "sat": "def sat(s: str, target=\"reverse me\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"reverse me\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_1", - "sat": "def sat(s: str, target=\"thubonyna\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"thubonyna\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_2", - "sat": "def sat(s: str, target=\"nivosypetextyzavalag\", reverse=False):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"nivosypetextyzavalag\", reverse=False):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_3", - "sat": "def sat(s: str, target=\"l\", reverse=False):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"l\", reverse=False):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_4", - "sat": "def sat(s: str, target=\"rechawewivetextovy\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"rechawewivetextovy\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_5", - "sat": "def sat(s: str, target=\"pegirupethabus\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"pegirupethabus\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_6", - "sat": "def sat(s: str, target=\"pewamyjol\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"pewamyjol\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_7", - "sat": "def sat(s: str, target=\"vomo\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"vomo\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_8", - "sat": "def sat(s: str, target=\"r\", reverse=True):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"r\", reverse=True):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaybeReversed_9", - "sat": "def sat(s: str, target=\"dajachythe\", reverse=False):\n \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"\n return (s[::-1] == target) == reverse", - "sols": [ - "def sol(target=\"dajachythe\", reverse=False):\n return target[::-1] if reverse else target + \"x\"" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_0", - "sat": "def sat(taken: List[int], val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_1", - "sat": "def sat(taken: List[int], val_counts=[[51, 67], [78, 13], [7, 68], [84, 54], [39, 38]], upper=66):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[51, 67], [78, 13], [7, 68], [84, 54], [39, 38]], upper=66):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_2", - "sat": "def sat(taken: List[int], val_counts=[[28, 29], [42, 54], [62, 85], [42, 95], [92, 32], [36, 35], [78, 56], [43, 20], [49, 17]], upper=153):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[28, 29], [42, 54], [62, 85], [42, 95], [92, 32], [36, 35], [78, 56], [43, 20], [49, 17]], upper=153):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_3", - "sat": "def sat(taken: List[int], val_counts=[[44, 92], [28, 7], [56, 37], [37, 66]], upper=90):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[44, 92], [28, 7], [56, 37], [37, 66]], upper=90):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_4", - "sat": "def sat(taken: List[int], val_counts=[[23, 93], [64, 14], [36, 8], [89, 92]], upper=65):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[23, 93], [64, 14], [36, 8], [89, 92]], upper=65):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_5", - "sat": "def sat(taken: List[int], val_counts=[[6, 52], [15, 87], [35, 77], [76, 45], [94, 72], [34, 63], [83, 32], [75, 38], [61, 31]], upper=139):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[6, 52], [15, 87], [35, 77], [76, 45], [94, 72], [34, 63], [83, 32], [75, 38], [61, 31]], upper=139):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_6", - "sat": "def sat(taken: List[int], val_counts=[[13, 15]], upper=8):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[13, 15]], upper=8):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_7", - "sat": "def sat(taken: List[int], val_counts=[[8, 14], [39, 4], [68, 80], [60, 28], [30, 76], [47, 35], [44, 47]], upper=101):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[8, 14], [39, 4], [68, 80], [60, 28], [30, 76], [47, 35], [44, 47]], upper=101):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_8", - "sat": "def sat(taken: List[int], val_counts=[[8, 77], [53, 87], [34, 91], [59, 66], [3, 33], [21, 5], [68, 71]], upper=136):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[8, 77], [53, 87], [34, 91], [59, 66], [3, 33], [21, 5], [68, 71]], upper=136):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinBigger_9", - "sat": "def sat(taken: List[int], val_counts=[[16, 79], [21, 24], [49, 20], [12, 3]], upper=40):\n \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", - "sols": [ - "def sol(val_counts=[[16, 79], [21, 24], [49, 20], [12, 3]], upper=40):\n n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_0", - "sat": "def sat(s: str, a=5129, d=17):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=5129, d=17):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_1", - "sat": "def sat(s: str, a=5798, d=1873):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=5798, d=1873):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_2", - "sat": "def sat(s: str, a=2645, d=1270):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=2645, d=1270):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_3", - "sat": "def sat(s: str, a=2996, d=6808):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=2996, d=6808):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_4", - "sat": "def sat(s: str, a=4763, d=8408):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=4763, d=8408):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_5", - "sat": "def sat(s: str, a=8269, d=1995):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=8269, d=1995):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_6", - "sat": "def sat(s: str, a=167, d=5291):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=167, d=5291):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_7", - "sat": "def sat(s: str, a=8910, d=4482):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=8910, d=4482):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_8", - "sat": "def sat(s: str, a=2980, d=2470):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=2980, d=2470):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "Dada_9", - "sat": "def sat(s: str, a=6355, d=1797):\n \"\"\"Find a string with a given number of a's and d's\"\"\"\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", - "sols": [ - "def sol(a=6355, d=1797):\n return \"a\" * a + \"d\" * d" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_0", - "sat": "def sat(nums: List[int], a=100, b=1000, count=648):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=100, b=1000, count=648):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_1", - "sat": "def sat(nums: List[int], a=79, b=169, count=67):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=79, b=169, count=67):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_2", - "sat": "def sat(nums: List[int], a=31, b=105, count=66):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=31, b=105, count=66):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_3", - "sat": "def sat(nums: List[int], a=52, b=95, count=40):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=52, b=95, count=40):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_4", - "sat": "def sat(nums: List[int], a=136, b=176, count=34):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=136, b=176, count=34):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_5", - "sat": "def sat(nums: List[int], a=19, b=120, count=82):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=19, b=120, count=82):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_6", - "sat": "def sat(nums: List[int], a=55, b=92, count=34):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=55, b=92, count=34):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_7", - "sat": "def sat(nums: List[int], a=451, b=707, count=189):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=451, b=707, count=189):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_8", - "sat": "def sat(nums: List[int], a=20, b=649, count=472):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=20, b=649, count=472):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctDigits_9", - "sat": "def sat(nums: List[int], a=287, b=989, count=514):\n \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", - "sols": [ - "def sol(a=287, b=989, count=514):\n return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_0", - "sat": "def sat(tot: int, nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_1", - "sat": "def sat(tot: int, nums=[60, 63, 11], thresh=99):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[60, 63, 11], thresh=99):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_2", - "sat": "def sat(tot: int, nums=[32, 24, 19, 88, 6, 33, 13], thresh=33):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[32, 24, 19, 88, 6, 33, 13], thresh=33):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_3", - "sat": "def sat(tot: int, nums=[60, 72, 32, 29, 90, 9, 39, 67, 31, 71, 68, 72, 28, 85, 75, 60, 42, 66, 4, 71, 57, 45, 88, 20, 66, 97, 33, 43, 48], thresh=30):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[60, 72, 32, 29, 90, 9, 39, 67, 31, 71, 68, 72, 28, 85, 75, 60, 42, 66, 4, 71, 57, 45, 88, 20, 66, 97, 33, 43, 48], thresh=30):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_4", - "sat": "def sat(tot: int, nums=[61, 98, 33, 32, 4, 99, 91, 63, 76, 83, 52, 0, 19, 49, 85, 5, 54, 71, 41, 93, 54, 78, 92], thresh=91):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[61, 98, 33, 32, 4, 99, 91, 63, 76, 83, 52, 0, 19, 49, 85, 5, 54, 71, 41, 93, 54, 78, 92], thresh=91):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_5", - "sat": "def sat(tot: int, nums: List[int]=[], thresh=1):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[], thresh=1):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_6", - "sat": "def sat(tot: int, nums=[26, 73, 42, 21, 69, 76, 20, 39, 43, 35, 59, 48, 89, 94, 29], thresh=55):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[26, 73, 42, 21, 69, 76, 20, 39, 43, 35, 59, 48, 89, 94, 29], thresh=55):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_7", - "sat": "def sat(tot: int, nums=[67, 66, 98, 5, 22, 52, 43, 37], thresh=55):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[67, 66, 98, 5, 22, 52, 43, 37], thresh=55):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_8", - "sat": "def sat(tot: int, nums=[80, 99], thresh=77):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[80, 99], thresh=77):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "EasySum_9", - "sat": "def sat(tot: int, nums=[79], thresh=46):\n \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"\n return tot == sum(1 if i < thresh else 2 for i in nums)", - "sols": [ - "def sol(nums=[79], thresh=46):\n return sum(1 if i < thresh else 2 for i in nums)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_0", - "sat": "def sat(s: str, chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_1", - "sat": "def sat(s: str, chars=['1', 'j', '3', 'Q', 'e']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_2", - "sat": "def sat(s: str, chars=['[', '/', 'g']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_3", - "sat": "def sat(s: str, chars=[' ', 'e', '%', '1', 'f']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_4", - "sat": "def sat(s: str, chars=['W', '@', 'S']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_5", - "sat": "def sat(s: str, chars=['(', 'R', '8', 'E', 'S']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_6", - "sat": "def sat(s: str, chars=['?', 'a', 'b', '0', 'z']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_7", - "sat": "def sat(s: str, chars=['-', 'R', '[', '0', 'q']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_8", - "sat": "def sat(s: str, chars=['M', '!', 'e', '[', 'z']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "GimmeChars_9", - "sat": "def sat(s: str, chars=['+', '#', 'R', '7', 'n']):\n \"\"\"Find a string with certain characters\"\"\"\n for c in chars:\n if c not in s:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_0", - "sat": "def sat(ans: List[List[int]], target=17):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=17):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_1", - "sat": "def sat(ans: List[List[int]], target=0):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=0):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_2", - "sat": "def sat(ans: List[List[int]], target=1):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=1):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_3", - "sat": "def sat(ans: List[List[int]], target=2):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=2):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_4", - "sat": "def sat(ans: List[List[int]], target=3):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=3):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_5", - "sat": "def sat(ans: List[List[int]], target=4):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=4):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_6", - "sat": "def sat(ans: List[List[int]], target=5):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=5):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_7", - "sat": "def sat(ans: List[List[int]], target=6):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=6):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_8", - "sat": "def sat(ans: List[List[int]], target=7):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=7):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "HalfPairs_9", - "sat": "def sat(ans: List[List[int]], target=8):\n \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", - "sols": [ - "def sol(target=8):\n return [[0, 2]] * target" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_0", - "sat": "def sat(indexes: List[int], target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_1", - "sat": "def sat(indexes: List[int], target=[16, 12, 67, 77, 23, 47, 24, 45, 61, 80, 43, 50, 57, 81, 21, 55, 9, 28, 14, 87, 58, 35, 37, 63, 41, 38, 6, 86, 59, 13, 49, 68, 83, 30, 40, 73, 15, 11, 85, 70, 33, 22, 76, 5, 82, 52, 27, 26, 34, 89, 1, 48, 64, 88, 19, 29, 65, 69, 31, 2, 74, 32, 60, 7, 46, 56, 78, 79, 36, 51, 72, 71, 54, 20, 90, 8, 53, 75, 39, 4, 17, 62, 25, 3, 84, 42, 44, 10, 66, 18]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_2", - "sat": "def sat(indexes: List[int], target=[4, 66, 52, 28, 11, 59, 15, 37, 32, 71, 48, 23, 41, 7, 68, 30, 2, 44, 33, 3, 14, 63, 40, 22, 35, 6, 27, 58, 36, 38, 53, 9, 24, 49, 54, 50, 72, 64, 69, 77, 25, 31, 42, 17, 57, 67, 55, 70, 47, 46, 10, 75, 20, 61, 34, 39, 18, 12, 56, 29, 62, 26, 73, 21, 5, 1, 8, 19, 51, 45, 74, 13, 43, 16, 76, 65, 60]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_3", - "sat": "def sat(indexes: List[int], target=[47, 10, 38, 39, 63, 9, 20, 31, 3, 42, 24, 4, 48, 25, 40, 52, 33, 58, 12, 5, 35, 51, 17, 6, 57, 60, 56, 61, 32, 64, 13, 59, 27, 50, 43, 11, 55, 29, 16, 19, 45, 7, 26, 1, 49, 53, 36, 18, 34, 22, 41, 46, 23, 15, 2, 14, 21, 28, 44, 54, 62, 30, 37, 8]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_4", - "sat": "def sat(indexes: List[int], target=[3, 1, 6, 5, 4, 2]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_5", - "sat": "def sat(indexes: List[int], target=[34, 50, 54, 38, 16, 14, 31, 43, 10, 24, 28, 21, 52, 8, 48, 58, 19, 55, 47, 51, 4, 41, 17, 35, 53, 49, 3, 1, 29, 44, 57, 46, 12, 23, 26, 20, 13, 39, 18, 36, 42, 33, 40, 45, 15, 30, 37, 32, 6, 11, 7, 22, 27, 56, 9, 5, 59, 2, 25]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_6", - "sat": "def sat(indexes: List[int], target=[38, 30, 12, 67, 41, 4, 44, 66, 3, 19, 2, 26, 5, 29, 43, 57, 25, 18, 34, 21, 69, 49, 42, 27, 60, 20, 33, 8, 23, 48, 31, 65, 32, 6, 51, 68, 7, 58, 64, 40, 56, 54, 63, 1, 52, 46, 59, 50, 39, 24, 35, 9, 55, 13, 22, 37, 61, 17, 36, 10, 45, 62, 28, 14, 47, 53, 11, 16, 15]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_7", - "sat": "def sat(indexes: List[int], target=[45, 9, 18, 12, 44, 8, 26, 4, 29, 43, 2, 14, 32, 19, 37, 5, 3, 39, 40, 13, 23, 28, 49, 25, 36, 53, 10, 30, 24, 16, 31, 46, 42, 22, 55, 1, 34, 6, 35, 51, 50, 33, 56, 52, 7, 47, 48, 17, 21, 54, 38, 57, 27, 41, 11, 15, 20]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_8", - "sat": "def sat(indexes: List[int], target=[13, 5, 28, 16, 29, 7, 9, 19, 14, 4, 34, 22, 31, 35, 10, 1, 17, 26, 37, 41, 11, 32, 27, 8, 6, 2, 21, 20, 25, 30, 36, 18, 3, 12, 38, 33, 24, 40, 39, 23, 15]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertIndices_9", - "sat": "def sat(indexes: List[int], target=[8, 48, 19, 2, 59, 58, 53, 27, 16, 37, 7, 66, 3, 50, 29, 61, 72, 35, 67, 68, 71, 24, 63, 76, 1, 56, 34, 30, 4, 39, 14, 74, 64, 26, 70, 32, 47, 73, 6, 21, 5, 22, 40, 43, 18, 60, 25, 45, 41, 38, 44, 49, 28, 36, 75, 52, 54, 31, 17, 46, 42, 20, 55, 9, 13, 23, 69, 51, 65, 10, 62, 33, 12, 15, 11, 57]):\n \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", - "sols": [], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "FivePowers_0", - "sat": "def sat(s: str, n=7012):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=7012):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_1", - "sat": "def sat(s: str, n=0):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=0):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_2", - "sat": "def sat(s: str, n=1):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=1):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_3", - "sat": "def sat(s: str, n=2):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=2):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_4", - "sat": "def sat(s: str, n=3):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=3):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_5", - "sat": "def sat(s: str, n=4):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=4):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_6", - "sat": "def sat(s: str, n=5):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=5):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_7", - "sat": "def sat(s: str, n=6):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=6):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_8", - "sat": "def sat(s: str, n=7):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=7):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_9", - "sat": "def sat(s: str, n=8):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=8):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "FivePowers_10", - "sat": "def sat(s: str, n=9):\n \"\"\"What are the last two digits of 5^n?\"\"\"\n return int(str(5 ** n)[:-2] + s) == 5 ** n", - "sols": [ - "def sol(n=9):\n return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", - "taint_date": "2021-4-26", - "weight": 0.00202020202020202 - }, - { - "name": "CombinationLock_0", - "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"424\", combo=\"778\", target_len=12):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_1", - "sat": "def sat(states: List[str], start=\"77872\", combo=\"43506\", target_len=16):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"77872\", combo=\"43506\", target_len=16):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_2", - "sat": "def sat(states: List[str], start=\"268\", combo=\"180\", target_len=4):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"268\", combo=\"180\", target_len=4):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_3", - "sat": "def sat(states: List[str], start=\"4675159714\", combo=\"9758013840\", target_len=27):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"4675159714\", combo=\"9758013840\", target_len=27):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_4", - "sat": "def sat(states: List[str], start=\"242716\", combo=\"891245\", target_len=18):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"242716\", combo=\"891245\", target_len=18):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_5", - "sat": "def sat(states: List[str], start=\"425739105\", combo=\"731228271\", target_len=22):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"425739105\", combo=\"731228271\", target_len=22):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_6", - "sat": "def sat(states: List[str], start=\"88453487\", combo=\"86926422\", target_len=21):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"88453487\", combo=\"86926422\", target_len=21):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_7", - "sat": "def sat(states: List[str], start=\"20122281\", combo=\"71435014\", target_len=20):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"20122281\", combo=\"71435014\", target_len=20):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_8", - "sat": "def sat(states: List[str], start=\"8228977\", combo=\"2479606\", target_len=18):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"8228977\", combo=\"2479606\", target_len=18):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLock_9", - "sat": "def sat(states: List[str], start=\"159\", combo=\"138\", target_len=2):\n \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", - "sols": [ - "def sol(start=\"159\", combo=\"138\", target_len=2):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_0", - "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"424\", combo=\"778\", target_len=12):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_1", - "sat": "def sat(states: List[str], start=\"50\", combo=\"59\", target_len=0):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"50\", combo=\"59\", target_len=0):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_2", - "sat": "def sat(states: List[str], start=\"23\", combo=\"12\", target_len=1):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"23\", combo=\"12\", target_len=1):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_3", - "sat": "def sat(states: List[str], start=\"4\", combo=\"3\", target_len=0):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"4\", combo=\"3\", target_len=0):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_4", - "sat": "def sat(states: List[str], start=\"2184377\", combo=\"7002994\", target_len=18):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"2184377\", combo=\"7002994\", target_len=18):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_5", - "sat": "def sat(states: List[str], start=\"894202\", combo=\"362955\", target_len=20):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"894202\", combo=\"362955\", target_len=20):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_6", - "sat": "def sat(states: List[str], start=\"635\", combo=\"732\", target_len=3):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"635\", combo=\"732\", target_len=3):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_7", - "sat": "def sat(states: List[str], start=\"2\", combo=\"5\", target_len=2):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"2\", combo=\"5\", target_len=2):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_8", - "sat": "def sat(states: List[str], start=\"68\", combo=\"55\", target_len=3):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"68\", combo=\"55\", target_len=3):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "CombinationLockObfuscated_9", - "sat": "def sat(states: List[str], start=\"36823\", combo=\"96926\", target_len=7):\n \"\"\"Figure out what this does only from the code\"\"\"\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", - "sols": [ - "def sol(start=\"36823\", combo=\"96926\", target_len=7):\n n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_0", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_1", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"xapypakygatextifyth divufyjacof cecuchuquypo sulechukijocharapad hych mugemi re binivot\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"xapypakygatextifyth divufyjacof cecuchuquypo sulechukijocharapad hych mugemi re binivot\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_2", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"mujychenyzo\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"mujychenyzo\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_3", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"quethoruchyrugyz wemywuconuthisiquu kachogechehuz pulybyri quuby thatextak tychuzymuxuzazylyk neruzesithipecytoqu\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"quethoruchyrugyz wemywuconuthisiquu kachogechehuz pulybyri quuby thatextak tychuzymuxuzazylyk neruzesithipecytoqu\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_4", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"thyjytex cequolichitextotho bymoxokepy jyvumywefoc\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"thyjytex cequolichitextotho bymoxokepy jyvumywefoc\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_5", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"sesozorisylec thatorypanajydenupo sumop bagemysezuquymew r\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"sesozorisylec thatorypanajydenupo sumop bagemysezuquymew r\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_6", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"zukywom xurebechafizygewe jiwony tytextehytextith thutiquewomihiquaco thicyzufawutotu\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"zukywom xurebechafizygewe jiwony tytextehytextith thutiquewomihiquaco thicyzufawutotu\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_7", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"cutejigigy\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"cutejigigy\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_8", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"zochixedodunajuzyvij thalemedytethim vuquajol jaxachudith bahogud mymach vehymavaf ma wyritextutexti\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"zochixedodunajuzyvij thalemedytethim vuquajol jaxachudith bahogud mymach vehymavaf ma wyritextutexti\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "InvertPermutation_9", - "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"k hojocotextecatotori fideh kisuchygovinygaq\"):\n \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", - "sols": [ - "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"k hojocotextecatotori fideh kisuchygovinygaq\"):\n return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_0", - "sat": "def sat(lists: List[List[int]], items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_1", - "sat": "def sat(lists: List[List[int]], items=[5, 3, 2, 1, 0, 1, 4, 2, 5, 4, 6, 7, 8], length=2):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[5, 3, 2, 1, 0, 1, 4, 2, 5, 4, 6, 7, 8], length=2):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_2", - "sat": "def sat(lists: List[List[int]], items=[0, 9, 7, 2, 6, 1, 6, 5, 4, 6, 5, 2, 6, 4, 2, 2, 7, 2, 7, 3, 4, 4, 8, 8, 1, 2, 6, 4, 7, 0, 4, 4, 6, 8, 4, 8, 3, 6, 6, 4, 7, 0, 3, 0, 7, 9, 3, 2, 7, 7, 1, 2, 8, 9, 4, 6, 8, 2, 2, 4, 6, 5, 3, 3, 2, 8, 8, 2, 7, 8, 7, 6, 9, 7, 3, 2, 0, 5], length=10):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[0, 9, 7, 2, 6, 1, 6, 5, 4, 6, 5, 2, 6, 4, 2, 2, 7, 2, 7, 3, 4, 4, 8, 8, 1, 2, 6, 4, 7, 0, 4, 4, 6, 8, 4, 8, 3, 6, 6, 4, 7, 0, 3, 0, 7, 9, 3, 2, 7, 7, 1, 2, 8, 9, 4, 6, 8, 2, 2, 4, 6, 5, 3, 3, 2, 8, 8, 2, 7, 8, 7, 6, 9, 7, 3, 2, 0, 5], length=10):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_3", - "sat": "def sat(lists: List[List[int]], items=[8, 1, 8, 2, 7, 0, 5, 8, 1, 5, 7, 2, 7, 1, 3, 5, 2, 9, 2, 0, 5, 1, 9, 1, 7, 9, 4, 7, 3, 5, 5, 8, 8, 8, 3, 8, 7, 5, 5, 0, 3, 4, 2, 8, 0, 6, 7, 6, 6, 3, 0, 1, 1, 7, 6, 0, 9, 9, 9, 5, 6, 1, 0, 0, 6, 3, 3, 0, 4, 0, 6, 9, 1, 3, 2, 9, 4, 2, 4, 7, 2, 7, 6, 0, 9, 2, 2, 8, 9, 1, 3, 5, 8, 3, 3], length=10):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[8, 1, 8, 2, 7, 0, 5, 8, 1, 5, 7, 2, 7, 1, 3, 5, 2, 9, 2, 0, 5, 1, 9, 1, 7, 9, 4, 7, 3, 5, 5, 8, 8, 8, 3, 8, 7, 5, 5, 0, 3, 4, 2, 8, 0, 6, 7, 6, 6, 3, 0, 1, 1, 7, 6, 0, 9, 9, 9, 5, 6, 1, 0, 0, 6, 3, 3, 0, 4, 0, 6, 9, 1, 3, 2, 9, 4, 2, 4, 7, 2, 7, 6, 0, 9, 2, 2, 8, 9, 1, 3, 5, 8, 3, 3], length=10):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_4", - "sat": "def sat(lists: List[List[int]], items=[5, 8, 2, 2, 5, 1, 4, 9, 2, 0, 5, 4, 6, 5, 1, 7, 3, 2, 4, 6, 7, 2, 7, 3, 3, 1, 7, 9, 3, 2, 2, 9, 1, 2, 1, 1, 8, 6, 6, 2, 7, 6, 5, 2, 7, 6, 5, 0, 0, 8, 4, 5, 5, 3, 7, 5, 2, 0, 3, 1, 0, 8, 1, 3, 0, 1, 9, 4, 9, 1, 9, 7, 7, 1, 9, 7, 9, 4, 0, 8, 3, 7, 4, 3, 1, 6, 5, 8, 0, 9, 5, 7, 5, 6, 0, 1, 3, 1, 8], length=10):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[5, 8, 2, 2, 5, 1, 4, 9, 2, 0, 5, 4, 6, 5, 1, 7, 3, 2, 4, 6, 7, 2, 7, 3, 3, 1, 7, 9, 3, 2, 2, 9, 1, 2, 1, 1, 8, 6, 6, 2, 7, 6, 5, 2, 7, 6, 5, 0, 0, 8, 4, 5, 5, 3, 7, 5, 2, 0, 3, 1, 0, 8, 1, 3, 0, 1, 9, 4, 9, 1, 9, 7, 7, 1, 9, 7, 9, 4, 0, 8, 3, 7, 4, 3, 1, 6, 5, 8, 0, 9, 5, 7, 5, 6, 0, 1, 3, 1, 8], length=10):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_5", - "sat": "def sat(lists: List[List[int]], items=[6, 3, 3, 3, 4, 1, 2, 9, 8, 4, 9, 5, 9, 4, 8], length=3):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[6, 3, 3, 3, 4, 1, 2, 9, 8, 4, 9, 5, 9, 4, 8], length=3):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_6", - "sat": "def sat(lists: List[List[int]], items=[6, 0, 6, 7, 1, 0, 6, 1, 7, 6, 0, 0, 8, 4, 8, 0, 2, 1, 2, 1, 3, 4, 6, 7, 9, 6, 8, 2, 8, 0, 1, 2, 9, 3, 3, 9, 6, 7, 3, 3, 1, 3, 0, 5, 7, 6, 3, 6, 9, 3, 9], length=9):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[6, 0, 6, 7, 1, 0, 6, 1, 7, 6, 0, 0, 8, 4, 8, 0, 2, 1, 2, 1, 3, 4, 6, 7, 9, 6, 8, 2, 8, 0, 1, 2, 9, 3, 3, 9, 6, 7, 3, 3, 1, 3, 0, 5, 7, 6, 3, 6, 9, 3, 9], length=9):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_7", - "sat": "def sat(lists: List[List[int]], items=[4, 3, 9, 6, 8], length=1):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[4, 3, 9, 6, 8], length=1):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_8", - "sat": "def sat(lists: List[List[int]], items=[3, 0, 2, 7, 8, 4, 0, 3, 4, 4, 3, 1, 4, 9, 3, 1, 3, 2, 4, 4, 2, 0, 4, 3, 3, 1, 1, 6, 5, 7, 0, 7, 8, 4, 4, 5, 2, 0, 9, 9, 9, 9, 5, 9, 2, 8, 6, 0, 0, 9, 8, 3, 1, 8, 3, 5, 3, 0, 7, 0, 6, 3, 0, 3, 8, 1, 0, 7, 5, 4, 2, 9, 7], length=10):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[3, 0, 2, 7, 8, 4, 0, 3, 4, 4, 3, 1, 4, 9, 3, 1, 3, 2, 4, 4, 2, 0, 4, 3, 3, 1, 1, 6, 5, 7, 0, 7, 8, 4, 4, 5, 2, 0, 9, 9, 9, 9, 5, 9, 2, 8, 6, 0, 0, 9, 8, 3, 1, 8, 3, 5, 3, 0, 7, 0, 6, 3, 0, 3, 8, 1, 0, 7, 5, 4, 2, 9, 7], length=10):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "SameDifferent_9", - "sat": "def sat(lists: List[List[int]], items=[2, 2, 8, 4, 9, 0, 7, 3, 6, 3, 5, 9, 6, 0, 3], length=3):\n \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", - "sols": [ - "def sol(items=[2, 2, 8, 4, 9, 0, 7, 3, 6, 3, 5, 9, 6, 0, 3], length=3):\n from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_0", - "sat": "def sat(seq: List[int], n=10000, length=5017):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=10000, length=5017):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_1", - "sat": "def sat(seq: List[int], n=867, length=785):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=867, length=785):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_2", - "sat": "def sat(seq: List[int], n=0, length=0):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=0, length=0):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_3", - "sat": "def sat(seq: List[int], n=4, length=2):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=4, length=2):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_4", - "sat": "def sat(seq: List[int], n=5514, length=4310):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=5514, length=4310):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_5", - "sat": "def sat(seq: List[int], n=7, length=5):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=7, length=5):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_6", - "sat": "def sat(seq: List[int], n=8, length=5):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=8, length=5):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_7", - "sat": "def sat(seq: List[int], n=93, length=65):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=93, length=65):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_8", - "sat": "def sat(seq: List[int], n=5155, length=3914):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=5155, length=3914):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "OnesAndTwos_9", - "sat": "def sat(seq: List[int], n=66, length=43):\n \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", - "sols": [ - "def sol(n=66, length=43):\n return [2] * (n - length) + [1] * (2 * length - n)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_0", - "sat": "def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_1", - "sat": "def sat(start: int, k=2, upper=-172, seq=[79, 18, -98, -13, 88, -93, -77, -95, 40, -3, -22]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=2, upper=-172, seq=[79, 18, -98, -13, 88, -93, -77, -95, 40, -3, -22]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_2", - "sat": "def sat(start: int, k=3, upper=-238, seq=[34, -9, -41, -62, -99, -58, -81, 66, -51, 90, -8, -56, -80, -66, -50, -74, -4, -47, 63, -86, 66, 72, 38, -3, 9, 92, 25, -77, 86, -24, -23, 9, 10, 36, -82, -48, -74, -1, -80, 55, -2, -86, 95, -52, -14, -87]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=3, upper=-238, seq=[34, -9, -41, -62, -99, -58, -81, 66, -51, 90, -8, -56, -80, -66, -50, -74, -4, -47, 63, -86, 66, 72, 38, -3, 9, 92, 25, -77, 86, -24, -23, 9, 10, 36, -82, -48, -74, -1, -80, 55, -2, -86, 95, -52, -14, -87]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_3", - "sat": "def sat(start: int, k=8, upper=-75, seq=[17, -90, 61, -29, 57, 7, -45, -37, 1, 69]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=8, upper=-75, seq=[17, -90, 61, -29, 57, 7, -45, -37, 1, 69]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_4", - "sat": "def sat(start: int, k=8, upper=-4, seq=[-17, 55, 6, -2, -14, -19, 86, -4, -8, -49, 40, 82]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=8, upper=-4, seq=[-17, 55, 6, -2, -14, -19, 86, -4, -8, -49, 40, 82]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_5", - "sat": "def sat(start: int, k=10, upper=-216, seq=[2, -55, 92, -48, 52, -62, -74, 89, 71, -68, -93, 33, -24, -94, 6, 4, -84, 64]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=10, upper=-216, seq=[2, -55, 92, -48, 52, -62, -74, 89, 71, -68, -93, 33, -24, -94, 6, 4, -84, 64]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_6", - "sat": "def sat(start: int, k=3, upper=-131, seq=[30, -93, -68]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=3, upper=-131, seq=[30, -93, -68]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_7", - "sat": "def sat(start: int, k=5, upper=-172, seq=[5, -30, -96, 41, -92]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=5, upper=-172, seq=[5, -30, -96, 41, -92]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_8", - "sat": "def sat(start: int, k=2, upper=-192, seq=[-70, -96, -96, -83, -55, -20, -75, -15, 98, 65, -39, -86, -24, -67, 64, 56, -94, -59, 65, 19, 21, 2, 61, -59, -92, -87, 68, 51, -36, 49, -25, 69, 58, 36, 44, 39, 72, 45, 28, -7, 43, -69]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=2, upper=-192, seq=[-70, -96, -96, -83, -55, -20, -75, -15, 98, 65, -39, -86, -24, -67, 64, 56, -94, -59, 65, 19, 21, 2, 61, -59, -92, -87, 68, 51, -36, 49, -25, 69, 58, 36, 44, 39, 72, 45, 28, -7, 43, -69]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinConsecutiveSum_9", - "sat": "def sat(start: int, k=4, upper=-152, seq=[29, -87, 43, 2, -36, -76, -42, 66, -46, 35, -8, -100]):\n \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", - "sols": [ - "def sol(k=4, upper=-152, seq=[29, -87, 43, 2, -36, -76, -42, 66, -46, 35, -8, -100]):\n return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_0", - "sat": "def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_1", - "sat": "def sat(start: int, k=9, lower=-183, seq=[44, -94, 25, -63, -39, -71, -34, 84, -35]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=9, lower=-183, seq=[44, -94, 25, -63, -39, -71, -34, 84, -35]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_2", - "sat": "def sat(start: int, k=3, lower=86, seq=[19, 82, -24, -9, -92, 50, -89, -15, 45, 56, -64]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=3, lower=86, seq=[19, 82, -24, -9, -92, 50, -89, -15, 45, 56, -64]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_3", - "sat": "def sat(start: int, k=1, lower=-36, seq=[-36]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=1, lower=-36, seq=[-36]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_4", - "sat": "def sat(start: int, k=1, lower=93, seq=[-61, -46, 89, 93, -13, 14, -95, -74, -92, -38, -93, 64, -78, 3, 92, -10, -4, 43, 72, 12, 3, -3, -15, -96, 72, -71, -30, 53, 17, -87, 49, 17, -69, 78, 6, -77, -99, 91, 13, 9, 81, -55, 75, 48, -65, 18, -83, 10, -12, 88, 60, -72, -7, -49, -56, -76, 82, 18, 77, 52, -92, -88, 39, 13, -16, 82, 4, 44, -19, 54, 6, 55, 77, -38, -30, -55, -16]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=1, lower=93, seq=[-61, -46, 89, 93, -13, 14, -95, -74, -92, -38, -93, 64, -78, 3, 92, -10, -4, 43, 72, 12, 3, -3, -15, -96, 72, -71, -30, 53, 17, -87, 49, 17, -69, 78, 6, -77, -99, 91, 13, 9, 81, -55, 75, 48, -65, 18, -83, 10, -12, 88, 60, -72, -7, -49, -56, -76, 82, 18, 77, 52, -92, -88, 39, 13, -16, 82, 4, 44, -19, 54, 6, 55, 77, -38, -30, -55, -16]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_5", - "sat": "def sat(start: int, k=4, lower=227, seq=[24, -48, -90, 54, -4, -25, 98, 8, 91, 30, 96]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=4, lower=227, seq=[24, -48, -90, 54, -4, -25, 98, 8, 91, 30, 96]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_6", - "sat": "def sat(start: int, k=7, lower=-107, seq=[-13, -65, 43, -16, -73, 12, -95, 87]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=7, lower=-107, seq=[-13, -65, 43, -16, -73, 12, -95, 87]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_7", - "sat": "def sat(start: int, k=9, lower=-54, seq=[-99, -22, -62, 83, 22, 86, 12, -89, 15]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=9, lower=-54, seq=[-99, -22, -62, 83, 22, 86, 12, -89, 15]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_8", - "sat": "def sat(start: int, k=6, lower=-334, seq=[-81, -71, -10, -73, -72, -27]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=6, lower=-334, seq=[-81, -71, -10, -73, -72, -27]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveSum_9", - "sat": "def sat(start: int, k=2, lower=174, seq=[87, -34, -97, -8, -74, -34, 54, 68, -85, 9, -36, -66, 70, -69, 75, 87, 23, -60, -98, -65, 76, -69, 68, -67, -32, -34, -91, -10, 84, 39, -86, -64, -77, -35, 61, 47, 21, 24, -7, -62, -31, 72, 86, 10, -71, -57, -51, 0, 80, 93, -29, 42, 28, -29, 93, -63, 94, -85, 58, -81, 12, 88, 0, -80, 42, 61, 92, 82, -62, 15, -88, 44, -9, 2, 85, 0, -58, -73, -43, -34, -21, 8, -63, -3, -38, -60]):\n \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", - "sols": [ - "def sol(k=2, lower=174, seq=[87, -34, -97, -8, -74, -34, 54, 68, -85, 9, -36, -66, 70, -69, 75, 87, 23, -60, -98, -65, 76, -69, 68, -67, -32, -34, -91, -10, 84, 39, -86, -64, -77, -35, 61, 47, 21, 24, -7, -62, -31, 72, 86, 10, -71, -57, -51, 0, 80, 93, -29, 42, 28, -29, 93, -63, 94, -85, 58, -81, 12, 88, 0, -80, 42, 61, 92, 82, -62, 15, -88, 44, -9, 2, 85, 0, -58, -73, -43, -34, -21, 8, -63, -3, -38, -60]):\n return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_0", - "sat": "def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_1", - "sat": "def sat(start: int, k=8, lower=774420991987500, seq=[-50, -99, -99, -65, -69, -87, 90, 45]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=8, lower=774420991987500, seq=[-50, -99, -99, -65, -69, -87, 90, 45]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_2", - "sat": "def sat(start: int, k=6, lower=188917681120, seq=[73, -32, 30, 92, 73, 8, 31, 40, -59, -97, -16, -83, -86, 78, -91, -18, -31, 31, 37, 79, 63, 38, 14, 68, -73, 91, 71, 87, 54, -7, -74, -63, -57, -46, -78, -22, 71, 52, 32, -82, 71, 76, -28, 83, -65, -65, 70, -35, 83, -40, 69, 78, -81, 0, -69, -1, 0, 61, 92, 55, -89, 60, 74, 99, -53, -22, 50, 28, -60, 6, 27, -53, -77, 99, 1, -69, -67, 81, -89, 45, 59, -28, 24, -21, -65, -56, -89, -30, 58, 78, 73, 9, 81, -39, -99, 43, 32, 58, -56, -83, 82, 97, 70]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=6, lower=188917681120, seq=[73, -32, 30, 92, 73, 8, 31, 40, -59, -97, -16, -83, -86, 78, -91, -18, -31, 31, 37, 79, 63, 38, 14, 68, -73, 91, 71, 87, 54, -7, -74, -63, -57, -46, -78, -22, 71, 52, 32, -82, 71, 76, -28, 83, -65, -65, 70, -35, 83, -40, 69, 78, -81, 0, -69, -1, 0, 61, 92, 55, -89, 60, 74, 99, -53, -22, 50, 28, -60, 6, 27, -53, -77, 99, 1, -69, -67, 81, -89, 45, 59, -28, 24, -21, -65, -56, -89, -30, 58, 78, 73, 9, 81, -39, -99, 43, 32, 58, -56, -83, 82, 97, 70]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_3", - "sat": "def sat(start: int, k=2, lower=5589, seq=[8, -66, 75, 74, 40, 14, -81, -69, 99, 27, -18]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=2, lower=5589, seq=[8, -66, 75, 74, 40, 14, -81, -69, 99, 27, -18]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_4", - "sat": "def sat(start: int, k=10, lower=-8326797433194240, seq=[49, -99, 80, 26, 54, 13, 37, 13, -52, -47]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=10, lower=-8326797433194240, seq=[49, -99, 80, 26, 54, 13, 37, 13, -52, -47]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_5", - "sat": "def sat(start: int, k=5, lower=2673475200, seq=[-71, 20, -58, 96, 97, -50, 99, 88, -24, 74, -35, 2, 3, -13, 79, -60, 64, 30, 80, -67, 94, -62, 63, 15, 13, 85, -86, -28, 4, -44, 86, -16, -73, -19, 23, -72, -78, 80, -57, 5, 40]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=5, lower=2673475200, seq=[-71, 20, -58, 96, 97, -50, 99, 88, -24, 74, -35, 2, 3, -13, 79, -60, 64, 30, 80, -67, 94, -62, 63, 15, 13, 85, -86, -28, 4, -44, 86, -16, -73, -19, 23, -72, -78, 80, -57, 5, 40]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_6", - "sat": "def sat(start: int, k=3, lower=363630, seq=[85, -67, 50, 12, 28, 71, -77, -56, 38, -69, -85, 62]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=3, lower=363630, seq=[85, -67, 50, 12, 28, 71, -77, -56, 38, -69, -85, 62]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_7", - "sat": "def sat(start: int, k=6, lower=93145633350, seq=[21, 53, 82, -21, -2, -42, 56, 61, 65, 78, -8, -99, -1, -88, 10, 63, 30, 48, -22, 47, 84, 54, -86, 26, -32, -86, 86, 62, 84, -38, -43, -56, 91, -50, 20, 79, 66, -53, 81, -47, -61, -73, 83, -11, 76, 74, 1, 31, -25, 78, 89, 74, 25, -93, 77, -79, -28, 43, -59, 27, -17, 98, 95, -19, -86, 83, 16, -91, 48, -24, 96, -91, 18, -17, 88, -71, -13, -86, 90, -66, 44, 18, 46, 22, 8, 17]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=6, lower=93145633350, seq=[21, 53, 82, -21, -2, -42, 56, 61, 65, 78, -8, -99, -1, -88, 10, 63, 30, 48, -22, 47, 84, 54, -86, 26, -32, -86, 86, 62, 84, -38, -43, -56, 91, -50, 20, 79, 66, -53, 81, -47, -61, -73, 83, -11, 76, 74, 1, 31, -25, 78, 89, 74, 25, -93, 77, -79, -28, 43, -59, 27, -17, 98, 95, -19, -86, 83, 16, -91, 48, -24, 96, -91, 18, -17, 88, -71, -13, -86, 90, -66, 44, 18, 46, 22, 8, 17]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_8", - "sat": "def sat(start: int, k=5, lower=165904200, seq=[64, 4, -30, -81, 77, 95, -35, 8, 90, 43, 48, -68, 18]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=5, lower=165904200, seq=[64, 4, -30, -81, 77, 95, -35, 8, 90, 43, 48, -68, 18]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MaxConsecutiveProduct_9", - "sat": "def sat(start: int, k=5, lower=61326720, seq=[-63, -80, 13, 72, 13]):\n \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", - "sols": [ - "def sol(k=5, lower=61326720, seq=[-63, -80, 13, 72, 13]):\n def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_0", - "sat": "def sat(nums: List[int], tot=12345, n=5):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=12345, n=5):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_1", - "sat": "def sat(nums: List[int], tot=1819, n=3):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=1819, n=3):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_2", - "sat": "def sat(nums: List[int], tot=37729, n=73):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=37729, n=73):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_3", - "sat": "def sat(nums: List[int], tot=5359, n=11):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=5359, n=11):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_4", - "sat": "def sat(nums: List[int], tot=36505, n=73):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=36505, n=73):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_5", - "sat": "def sat(nums: List[int], tot=24165, n=45):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=24165, n=45):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_6", - "sat": "def sat(nums: List[int], tot=15225, n=27):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=15225, n=27):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_7", - "sat": "def sat(nums: List[int], tot=31442, n=60):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=31442, n=60):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_8", - "sat": "def sat(nums: List[int], tot=18392, n=36):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=18392, n=36):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "DistinctOddSum_9", - "sat": "def sat(nums: List[int], tot=11968, n=22):\n \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", - "sols": [ - "def sol(tot=11968, n=22):\n return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_0", - "sat": "def sat(rotations: List[int], target=\"wonderful\", upper=69):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"wonderful\", upper=69):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_1", - "sat": "def sat(rotations: List[int], target=\"tubolele\", upper=52):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"tubolele\", upper=52):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_2", - "sat": "def sat(rotations: List[int], target=\"soquogisawah\", upper=67):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"soquogisawah\", upper=67):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_3", - "sat": "def sat(rotations: List[int], target=\"jacepa\", upper=44):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"jacepa\", upper=44):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_4", - "sat": "def sat(rotations: List[int], target=\"miwykucehexo\", upper=84):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"miwykucehexo\", upper=84):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_5", - "sat": "def sat(rotations: List[int], target=\"nuze\", upper=30):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"nuze\", upper=30):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_6", - "sat": "def sat(rotations: List[int], target=\"sypyjotygusoviquy\", upper=120):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"sypyjotygusoviquy\", upper=120):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_7", - "sat": "def sat(rotations: List[int], target=\"junuzokudupozaderehi\", upper=134):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"junuzokudupozaderehi\", upper=134):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_8", - "sat": "def sat(rotations: List[int], target=\"bu\", upper=8):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"bu\", upper=8):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "MinRotations_9", - "sat": "def sat(rotations: List[int], target=\"tot\", upper=17):\n \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", - "sols": [ - "def sol(target=\"tot\", upper=17):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" - ], - "module": "codeforces", - "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", - "taint_date": "2021-4-26", - "weight": 0.0022222222222222222 - }, - { - "name": "QuadraticRoot_0", - "sat": "def sat(x: float, coeffs=[2.5, 1.3, -0.5]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[2.5, 1.3, -0.5]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[2.5, 1.3, -0.5]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_1", - "sat": "def sat(x: float, coeffs=[0.0685642998539026, -0.10446230957339113, -0.11141402891228723]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.0685642998539026, -0.10446230957339113, -0.11141402891228723]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[0.0685642998539026, -0.10446230957339113, -0.11141402891228723]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_2", - "sat": "def sat(x: float, coeffs=[0.2622487694588566, 0.48521166316030495, -41.749384651642444]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.2622487694588566, 0.48521166316030495, -41.749384651642444]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[0.2622487694588566, 0.48521166316030495, -41.749384651642444]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_3", - "sat": "def sat(x: float, coeffs=[145.72190605632582, 0.027358325157428014, -5.149342624051854]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[145.72190605632582, 0.027358325157428014, -5.149342624051854]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[145.72190605632582, 0.027358325157428014, -5.149342624051854]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_4", - "sat": "def sat(x: float, coeffs=[1.1222556871110754, -0.007015312913509468, -309237.6867547677]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[1.1222556871110754, -0.007015312913509468, -309237.6867547677]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[1.1222556871110754, -0.007015312913509468, -309237.6867547677]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_5", - "sat": "def sat(x: float, coeffs=[3.5947279237002445, -0.07342639433715788, -0.5396285563621648]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[3.5947279237002445, -0.07342639433715788, -0.5396285563621648]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[3.5947279237002445, -0.07342639433715788, -0.5396285563621648]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_6", - "sat": "def sat(x: float, coeffs=[0.2604264648823638, 0.11685895190643543, -1.4569567384428328]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.2604264648823638, 0.11685895190643543, -1.4569567384428328]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[0.2604264648823638, 0.11685895190643543, -1.4569567384428328]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_7", - "sat": "def sat(x: float, coeffs=[-24.68501806282819, 10.588503742224786, -0.25735414386816724]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-24.68501806282819, 10.588503742224786, -0.25735414386816724]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[-24.68501806282819, 10.588503742224786, -0.25735414386816724]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_8", - "sat": "def sat(x: float, coeffs=[0.06252609393024433, 0.6879972221042366, -0.34955085974472294]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.06252609393024433, 0.6879972221042366, -0.34955085974472294]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[0.06252609393024433, 0.6879972221042366, -0.34955085974472294]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "QuadraticRoot_9", - "sat": "def sat(x: float, coeffs=[0.3130118376686533, -98.95538710404492, 194.22072166934078]):\n \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.3130118376686533, -98.95538710404492, 194.22072166934078]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", - "def sol(coeffs=[0.3130118376686533, -98.95538710404492, 194.22072166934078]):\n a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_0", - "sat": "def sat(roots: List[float], coeffs=[1.3, -0.5]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[1.3, -0.5]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_1", - "sat": "def sat(roots: List[float], coeffs=[-1.468548989307175, -0.9453828447181172]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-1.468548989307175, -0.9453828447181172]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_2", - "sat": "def sat(roots: List[float], coeffs=[-2.0230245559088815, -0.23831699388987454]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-2.0230245559088815, -0.23831699388987454]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_3", - "sat": "def sat(roots: List[float], coeffs=[-33.7903719275386, -5.03161654339928]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-33.7903719275386, -5.03161654339928]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_4", - "sat": "def sat(roots: List[float], coeffs=[9.155105839032705, -0.9467446341738642]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[9.155105839032705, -0.9467446341738642]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_5", - "sat": "def sat(roots: List[float], coeffs=[-0.4520738252338276, -0.26542346003973466]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.4520738252338276, -0.26542346003973466]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_6", - "sat": "def sat(roots: List[float], coeffs=[0.053688498796852, -4.37419775351888]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[0.053688498796852, -4.37419775351888]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_7", - "sat": "def sat(roots: List[float], coeffs=[-0.13816123018535084, -12.569183229720833]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.13816123018535084, -12.569183229720833]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_8", - "sat": "def sat(roots: List[float], coeffs=[-0.9829631168704469, 0.02093973230254469]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.9829631168704469, 0.02093973230254469]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllQuadraticRoots_9", - "sat": "def sat(roots: List[float], coeffs=[-0.3727442283742026, -1.85291131192016]):\n \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.3727442283742026, -1.85291131192016]):\n b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" - ], - "module": "algebra", - "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_0", - "sat": "def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[2.0, 1.0, 0.0, 8.0]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_1", - "sat": "def sat(x: float, coeffs=[0.009597657937719273, -10.297175825569942, 0.15891220226280925, 10.530249049250433]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[0.009597657937719273, -10.297175825569942, 0.15891220226280925, 10.530249049250433]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_2", - "sat": "def sat(x: float, coeffs=[-0.17749172356645268, -1.3894267878542186, 0.03752944532850555, 0.2624916128068381]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.17749172356645268, -1.3894267878542186, 0.03752944532850555, 0.2624916128068381]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_3", - "sat": "def sat(x: float, coeffs=[0.41725114111706524, 155.2589446092116, -0.10619077904258341, -0.024129284994425074]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[0.41725114111706524, 155.2589446092116, -0.10619077904258341, -0.024129284994425074]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_4", - "sat": "def sat(x: float, coeffs=[-2.3153234528266906, 11.247619504308075, -72.3705721705674, 53.97429005428236]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[-2.3153234528266906, 11.247619504308075, -72.3705721705674, 53.97429005428236]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_5", - "sat": "def sat(x: float, coeffs=[0.35255017264008126, -12.28313172192812, -4.732214142791368, -0.23521372185245784]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[0.35255017264008126, -12.28313172192812, -4.732214142791368, -0.23521372185245784]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_6", - "sat": "def sat(x: float, coeffs=[-0.3690375625527393, -0.18352014498653543, 0.36096353050506585, 0.18441425181494597]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.3690375625527393, -0.18352014498653543, 0.36096353050506585, 0.18441425181494597]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_7", - "sat": "def sat(x: float, coeffs=[-1.8059746288820582, -0.09318080559912649, -0.33402347874794236, -0.05936102579637261]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[-1.8059746288820582, -0.09318080559912649, -0.33402347874794236, -0.05936102579637261]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_8", - "sat": "def sat(x: float, coeffs=[-1.0922515242006108, 12.28110097782765, -0.1640448133611577, 118839581.49853094]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[-1.0922515242006108, 12.28110097782765, -0.1640448133611577, 118839581.49853094]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CubicRoot_9", - "sat": "def sat(x: float, coeffs=[0.6988269056745691, 0.31029934647376994, 0.4313669902687609, 2.710677858791331]):\n \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", - "sols": [ - "def sol(coeffs=[0.6988269056745691, 0.31029934647376994, 0.4313669902687609, 2.710677858791331]):\n a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_0", - "sat": "def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[1.0, -2.0, -1.0]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_1", - "sat": "def sat(roots: List[float], coeffs=[291.6393860094841, -235.56805995170293, 46.827662118172]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[291.6393860094841, -235.56805995170293, 46.827662118172]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_2", - "sat": "def sat(roots: List[float], coeffs=[-0.25228902661371166, -0.1500677342820565, 0.04095001209455085]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.25228902661371166, -0.1500677342820565, 0.04095001209455085]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_3", - "sat": "def sat(roots: List[float], coeffs=[-0.7564145326509102, -0.6902422688120567, 0.4732575941427041]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.7564145326509102, -0.6902422688120567, 0.4732575941427041]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_4", - "sat": "def sat(roots: List[float], coeffs=[5.119999240806329, -7.551441647258393, -21.440710634524915]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[5.119999240806329, -7.551441647258393, -21.440710634524915]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_5", - "sat": "def sat(roots: List[float], coeffs=[5.62718266515347, 5.078226431366819, 0.6196345001723688]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[5.62718266515347, 5.078226431366819, 0.6196345001723688]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_6", - "sat": "def sat(roots: List[float], coeffs=[-1.2627469121543362, -1.4336241982384421, -0.17159457681558898]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-1.2627469121543362, -1.4336241982384421, -0.17159457681558898]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_7", - "sat": "def sat(roots: List[float], coeffs=[-66.38952479300266, 35.22831663918797, -3.471625867121858]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-66.38952479300266, 35.22831663918797, -3.471625867121858]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_8", - "sat": "def sat(roots: List[float], coeffs=[-0.3516534493468364, -1.5104305401373206, 0.08424160558243492]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[-0.3516534493468364, -1.5104305401373206, 0.08424160558243492]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "AllCubicRoots_9", - "sat": "def sat(roots: List[float], coeffs=[1.8292656260609321, -0.09629796450255451, -0.042283539638455804]):\n \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", - "sols": [ - "def sol(coeffs=[1.8292656260609321, -0.09629796450255451, -0.042283539638455804]):\n a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" - ], - "module": "algebra", - "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "SumOfDigits_0", - "sat": "def sat(x: str, s=679):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=679):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_1", - "sat": "def sat(x: str, s=40427):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=40427):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_2", - "sat": "def sat(x: str, s=8071):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=8071):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_3", - "sat": "def sat(x: str, s=86120):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=86120):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_4", - "sat": "def sat(x: str, s=26785):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=26785):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_5", - "sat": "def sat(x: str, s=20796):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=20796):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_6", - "sat": "def sat(x: str, s=43641):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=43641):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_7", - "sat": "def sat(x: str, s=39963):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=39963):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_8", - "sat": "def sat(x: str, s=94905):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=94905):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SumOfDigits_9", - "sat": "def sat(x: str, s=64608):\n \"\"\"Find a number that its digits sum to a specific value.\"\"\"\n return s == sum([int(d) for d in x])", - "sols": [ - "def sol(s=64608):\n return int(s / 9) * '9' + str(s % 9)" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_0", - "sat": "def sat(z: float, v=9, d=0.0001):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=9, d=0.0001):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_1", - "sat": "def sat(z: float, v=1, d=1e-17):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=1, d=1e-17):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_2", - "sat": "def sat(z: float, v=9, d=1e+83):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=9, d=1e+83):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_3", - "sat": "def sat(z: float, v=5, d=1e-18):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=5, d=1e-18):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_4", - "sat": "def sat(z: float, v=5, d=1e+90):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=5, d=1e+90):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_5", - "sat": "def sat(z: float, v=4, d=1e-91):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=4, d=1e-91):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_6", - "sat": "def sat(z: float, v=3, d=1e+17):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=3, d=1e+17):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_7", - "sat": "def sat(z: float, v=4, d=1e+34):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=4, d=1e+34):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_8", - "sat": "def sat(z: float, v=0, d=1e-70):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=0, d=1e-70):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "FloatWithDecimalValue_9", - "sat": "def sat(z: float, v=2, d=1e+35):\n \"\"\"Create a float with a specific decimal.\"\"\"\n return int(z * 1 / d % 10) == v", - "sols": [ - "def sol(v=2, d=1e+35):\n return v * d" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_0", - "sat": "def sat(x: List[int], a=7, s=5, e=200):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=7, s=5, e=200):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_1", - "sat": "def sat(x: List[int], a=43536, s=3795, e=417606):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=43536, s=3795, e=417606):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_2", - "sat": "def sat(x: List[int], a=-70138, s=4868, e=498910):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-70138, s=4868, e=498910):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_3", - "sat": "def sat(x: List[int], a=55980, s=7402, e=155818):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=55980, s=7402, e=155818):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_4", - "sat": "def sat(x: List[int], a=-44635, s=5046, e=503563):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-44635, s=5046, e=503563):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_5", - "sat": "def sat(x: List[int], a=80565, s=1953, e=672358):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=80565, s=1953, e=672358):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_6", - "sat": "def sat(x: List[int], a=-90253, s=8998, e=-83648):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-90253, s=8998, e=-83648):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_7", - "sat": "def sat(x: List[int], a=9896, s=5296, e=162261):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=9896, s=5296, e=162261):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_8", - "sat": "def sat(x: List[int], a=87735, s=990, e=972157):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=87735, s=990, e=972157):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ArithmeticSequence_9", - "sat": "def sat(x: List[int], a=39969, s=8055, e=644333):\n \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=39969, s=8055, e=644333):\n return list(range(a, e + 1, s))" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_0", - "sat": "def sat(x: List[int], a=8, r=2, l=50):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=8, r=2, l=50):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_1", - "sat": "def sat(x: List[int], a=-484, r=4, l=589):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-484, r=4, l=589):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_2", - "sat": "def sat(x: List[int], a=889, r=7, l=393):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=889, r=7, l=393):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_3", - "sat": "def sat(x: List[int], a=-777, r=4, l=103):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-777, r=4, l=103):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_4", - "sat": "def sat(x: List[int], a=-736, r=4, l=92):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-736, r=4, l=92):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_5", - "sat": "def sat(x: List[int], a=-919, r=3, l=45):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-919, r=3, l=45):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_6", - "sat": "def sat(x: List[int], a=-321, r=10, l=949):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=-321, r=10, l=949):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_7", - "sat": "def sat(x: List[int], a=311, r=2, l=412):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=311, r=2, l=412):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_8", - "sat": "def sat(x: List[int], a=410, r=10, l=558):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=410, r=10, l=558):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "GeometricSequence_9", - "sat": "def sat(x: List[int], a=165, r=10, l=326):\n \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", - "sols": [ - "def sol(a=165, r=10, l=326):\n return [a * r ** i for i in range(l)]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_0", - "sat": "def sat(e: List[int], a=2, b=-1, c=1, d=2021):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=2, b=-1, c=1, d=2021):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_1", - "sat": "def sat(e: List[int], a=-77698407, b=-31793716, c=-10799659, d=89278024):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=-77698407, b=-31793716, c=-10799659, d=89278024):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_2", - "sat": "def sat(e: List[int], a=89600582, b=-47657198, c=95101265, d=-52126265):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=89600582, b=-47657198, c=95101265, d=-52126265):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_3", - "sat": "def sat(e: List[int], a=-11422303, b=-57150416, c=-59162339, d=-37428439):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=-11422303, b=-57150416, c=-59162339, d=-37428439):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_4", - "sat": "def sat(e: List[int], a=-18517001, b=-13662763, c=-11156613, d=9271005):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=-18517001, b=-13662763, c=-11156613, d=9271005):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_5", - "sat": "def sat(e: List[int], a=66662245, b=-77446843, c=-13474939, d=-81260641):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=66662245, b=-77446843, c=-13474939, d=-81260641):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_6", - "sat": "def sat(e: List[int], a=58075077, b=81729480, c=-29062535, d=47206861):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=58075077, b=81729480, c=-29062535, d=47206861):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_7", - "sat": "def sat(e: List[int], a=-34145371, b=-40535174, c=-77545901, d=-74328636):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=-34145371, b=-40535174, c=-77545901, d=-74328636):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_8", - "sat": "def sat(e: List[int], a=34194215, b=-43188845, c=10400013, d=13745364):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=34194215, b=-43188845, c=10400013, d=13745364):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "LineIntersection_9", - "sat": "def sat(e: List[int], a=26488659, b=76273097, c=19384670, d=-88393526):\n \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", - "sols": [ - "def sol(a=26488659, b=76273097, c=19384670, d=-88393526):\n return [d - b, a - c]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_0", - "sat": "def sat(x: int, a=324554, b=1345345):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=324554, b=1345345):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_1", - "sat": "def sat(x: int, a=51, b=40553793):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=51, b=40553793):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_2", - "sat": "def sat(x: int, a=50, b=72369383):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=50, b=72369383):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_3", - "sat": "def sat(x: int, a=90, b=42412534):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=90, b=42412534):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_4", - "sat": "def sat(x: int, a=62, b=-26538057):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=62, b=-26538057):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_5", - "sat": "def sat(x: int, a=35, b=68891015):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=35, b=68891015):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_6", - "sat": "def sat(x: int, a=99, b=-40055864):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=99, b=-40055864):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_7", - "sat": "def sat(x: int, a=62, b=16884181):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=62, b=16884181):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_8", - "sat": "def sat(x: int, a=92, b=53801166):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=92, b=53801166):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblem_9", - "sat": "def sat(x: int, a=49, b=-35819854):\n \"\"\"Satisfy a simple if statement\"\"\"\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", - "sols": [ - "def sol(a=49, b=-35819854):\n if a < 50:\n return b - a\n else:\n return b + 2 * a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_0", - "sat": "def sat(x: int, a=9384594, b=1343663):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=9384594, b=1343663):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_1", - "sat": "def sat(x: int, a=57, b=40522966):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=57, b=40522966):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_2", - "sat": "def sat(x: int, a=29, b=71683001):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=29, b=71683001):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_3", - "sat": "def sat(x: int, a=92, b=8820402):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=92, b=8820402):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_4", - "sat": "def sat(x: int, a=64, b=46712723):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=64, b=46712723):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_5", - "sat": "def sat(x: int, a=27, b=5434649):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=27, b=5434649):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_6", - "sat": "def sat(x: int, a=37, b=38397371):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=37, b=38397371):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_7", - "sat": "def sat(x: int, a=11, b=77928015):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=11, b=77928015):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_8", - "sat": "def sat(x: int, a=86, b=37109313):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=86, b=37109313):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithAnd_9", - "sat": "def sat(x: int, a=39, b=780129):\n \"\"\"Satisfy a simple if statement with an and clause\"\"\"\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=39, b=780129):\n if a > 50 and b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_0", - "sat": "def sat(x: int, a=253532, b=1230200):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=253532, b=1230200):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_1", - "sat": "def sat(x: int, a=22, b=-84904666):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=22, b=-84904666):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_2", - "sat": "def sat(x: int, a=10, b=74723522):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=10, b=74723522):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_3", - "sat": "def sat(x: int, a=66, b=-39109407):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=66, b=-39109407):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_4", - "sat": "def sat(x: int, a=24, b=18773099):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=24, b=18773099):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_5", - "sat": "def sat(x: int, a=46, b=9116075):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=46, b=9116075):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_6", - "sat": "def sat(x: int, a=14, b=-39450114):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=14, b=-39450114):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_7", - "sat": "def sat(x: int, a=26, b=-53224550):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=26, b=-53224550):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_8", - "sat": "def sat(x: int, a=97, b=59368921):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=97, b=59368921):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfProblemWithOr_9", - "sat": "def sat(x: int, a=90, b=20458713):\n \"\"\"Satisfy a simple if statement with an or clause\"\"\"\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", - "sols": [ - "def sol(a=90, b=20458713):\n if a > 50 or b > a:\n return b + a\n else:\n return b - a" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_0", - "sat": "def sat(x: int, a=4, b=54368639):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=4, b=54368639):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_1", - "sat": "def sat(x: int, a=-4, b=-83354930):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-4, b=-83354930):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_2", - "sat": "def sat(x: int, a=-3, b=71965664):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-3, b=71965664):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_3", - "sat": "def sat(x: int, a=2, b=36068130):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=2, b=36068130):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_4", - "sat": "def sat(x: int, a=-3, b=14385903):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-3, b=14385903):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_5", - "sat": "def sat(x: int, a=-3, b=7929575):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-3, b=7929575):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_6", - "sat": "def sat(x: int, a=1, b=34634397):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=1, b=34634397):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_7", - "sat": "def sat(x: int, a=-3, b=54942199):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-3, b=54942199):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_8", - "sat": "def sat(x: int, a=-5, b=-65004772):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-5, b=-65004772):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "IfCases_9", - "sat": "def sat(x: int, a=-2, b=82754407):\n \"\"\"Satisfy a simple if statement with multiple cases\"\"\"\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", - "sols": [ - "def sol(a=-2, b=82754407):\n if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_0", - "sat": "def sat(x: List[int], n=5, s=19):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=5, s=19):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_1", - "sat": "def sat(x: List[int], n=6241, s=54594969):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=6241, s=54594969):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_2", - "sat": "def sat(x: List[int], n=8427, s=33081884):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=8427, s=33081884):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_3", - "sat": "def sat(x: List[int], n=3363, s=67595319):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=3363, s=67595319):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_4", - "sat": "def sat(x: List[int], n=9909, s=88140438):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=9909, s=88140438):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_5", - "sat": "def sat(x: List[int], n=5390, s=59545596):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=5390, s=59545596):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_6", - "sat": "def sat(x: List[int], n=174, s=25578092):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=174, s=25578092):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_7", - "sat": "def sat(x: List[int], n=1734, s=82075077):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=1734, s=82075077):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_8", - "sat": "def sat(x: List[int], n=7583, s=30735127):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=7583, s=30735127):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListPosSum_9", - "sat": "def sat(x: List[int], n=4841, s=15818178):\n \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", - "sols": [ - "def sol(n=4841, s=15818178):\n x = [1] * n\n x[0] = s - n + 1\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_0", - "sat": "def sat(x: List[int], n=4, s=2021):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=4, s=2021):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_1", - "sat": "def sat(x: List[int], n=124, s=2603089):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=124, s=2603089):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_2", - "sat": "def sat(x: List[int], n=823, s=8609609):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=823, s=8609609):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_3", - "sat": "def sat(x: List[int], n=796, s=86694751):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=796, s=86694751):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_4", - "sat": "def sat(x: List[int], n=225, s=38417364):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=225, s=38417364):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_5", - "sat": "def sat(x: List[int], n=647, s=19596959):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=647, s=19596959):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_6", - "sat": "def sat(x: List[int], n=319, s=33831495):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=319, s=33831495):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_7", - "sat": "def sat(x: List[int], n=14, s=58095315):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=14, s=58095315):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_8", - "sat": "def sat(x: List[int], n=621, s=30680686):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=621, s=30680686):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ListDistinctSum_9", - "sat": "def sat(x: List[int], n=737, s=45285163):\n \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"\n return len(x) == n and sum(x) == s and len(set(x)) == n", - "sols": [ - "def sol(n=737, s=45285163):\n a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_0", - "sat": "def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_1", - "sat": "def sat(x: str, s=['I', '&', 'W', '&', 'p', 'c', '-', 'U', '(', ' ', 'A', '(', 'S', 'W', 'R', '#', 'm', 'v', '@', '8', '%', 'a', '.', 'K', 'O', '[', '[', '#', 'q', 'k', 'K'], n=16):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['I', '&', 'W', '&', 'p', 'c', '-', 'U', '(', ' ', 'A', '(', 'S', 'W', 'R', '#', 'm', 'v', '@', '8', '%', 'a', '.', 'K', 'O', '[', '[', '#', 'q', 'k', 'K'], n=16):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_2", - "sat": "def sat(x: str, s=['L', 'C', 'b', 'r', 't', 'V', 'R', '%', 'R', '8', 'V', '#', '<', '!', 'U', 'y', 'x'], n=13):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['L', 'C', 'b', 'r', 't', 'V', 'R', '%', 'R', '8', 'V', '#', '<', '!', 'U', 'y', 'x'], n=13):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_3", - "sat": "def sat(x: str, s=['-', '&', ')', '&', 'c', 'l', '/', 'H', '1', 'j', 'z', 'o', 'E', '|', '8', '&', '0', '&', 'y', '!', 'r', 'H', 'S', 'P', '5'], n=8):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['-', '&', ')', '&', 'c', 'l', '/', 'H', '1', 'j', 'z', 'o', 'E', '|', '8', '&', '0', '&', 'y', '!', 'r', 'H', 'S', 'P', '5'], n=8):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_4", - "sat": "def sat(x: str, s=['0', '@', 'R', 'k', '$', '$', 't', '0', '3', '#', '!', 'a', 'w', 'k', 'q', 'H', '-', 'm'], n=16):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['0', '@', 'R', 'k', '$', '$', 't', '0', '3', '#', '!', 'a', 'w', 'k', 'q', 'H', '-', 'm'], n=16):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_5", - "sat": "def sat(x: str, s=[')', ',', '1', 'd', '8', '2', 'e', 'E', 'A', 'P', '9', 'F', '.', 'R', 'y', 'v', 'E', 'A', 'j', 'k', '8', 'z', 'w', 'g', 'd', 'd', 'D', 'A', '(', '8', 'x', 'P', 'K', '>', 'X'], n=22):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=[')', ',', '1', 'd', '8', '2', 'e', 'E', 'A', 'P', '9', 'F', '.', 'R', 'y', 'v', 'E', 'A', 'j', 'k', '8', 'z', 'w', 'g', 'd', 'd', 'D', 'A', '(', '8', 'x', 'P', 'K', '>', 'X'], n=22):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_6", - "sat": "def sat(x: str, s=['H', 'd', 'Y', '@', 'y', 'd', 'v', 'o', 'x', '?', '$', '3', 'D', 'n', '$', 'L', 'y', 'j', 'j', '.', 'L', 'c', 'h', 'u', 'b', 'k', '[', 'b', 'C', '5', 'J', 'G', 'm', 'u', '=', '!'], n=23):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['H', 'd', 'Y', '@', 'y', 'd', 'v', 'o', 'x', '?', '$', '3', 'D', 'n', '$', 'L', 'y', 'j', 'j', '.', 'L', 'c', 'h', 'u', 'b', 'k', '[', 'b', 'C', '5', 'J', 'G', 'm', 'u', '=', '!'], n=23):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_7", - "sat": "def sat(x: str, s=['v', '5', 'T', 'c', '@', 'v', ')', '?', '2', 't', 'e', 'y', 'J', '$', 's', '.', 'A', '0', 'L', '*'], n=10):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['v', '5', 'T', 'c', '@', 'v', ')', '?', '2', 't', 'e', 'y', 'J', '$', 's', '.', 'A', '0', 'L', '*'], n=10):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_8", - "sat": "def sat(x: str, s=['1', '5', 'K', 'e', '-', 'Y', 'l', ')', 'g', 'g', 'X', 'Z', 'D', 'X', '-', 'v', 'l', 'N', 'N', 'F', '6', 'Y', 'I', 'k', 'V'], n=9):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['1', '5', 'K', 'e', '-', 'Y', 'l', ')', 'g', 'g', 'X', 'Z', 'D', 'X', '-', 'v', 'l', 'N', 'N', 'F', '6', 'Y', 'I', 'k', 'V'], n=9):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ConcatStrings_9", - "sat": "def sat(x: str, s=['V', 's', '|', 'i', 'U', 'o', 'u', 'W', 'Q', 'X', 'O', 'O', 'p', '&', 'J', '.', 'F', 'i', '[', '8', '[', 'j', 'Y', 'z'], n=24):\n \"\"\"Concatenate the list of characters in s\"\"\"\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", - "sols": [ - "def sol(s=['V', 's', '|', 'i', 'U', 'o', 'u', 'W', 'Q', 'X', 'O', 'O', 'p', '&', 'J', '.', 'F', 'i', '[', '8', '[', 'j', 'Y', 'z'], n=24):\n return ''.join([s[i] for i in range(n)])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_0", - "sat": "def sat(x: List[int], t=677, a=43, e=125, s=10):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=677, a=43, e=125, s=10):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_1", - "sat": "def sat(x: List[int], t=44475424, a=93, e=8496, s=6):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=44475424, a=93, e=8496, s=6):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_2", - "sat": "def sat(x: List[int], t=2183536, a=36, e=8450, s=1):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=2183536, a=36, e=8450, s=1):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_3", - "sat": "def sat(x: List[int], t=1196610, a=15, e=4376, s=3):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=1196610, a=15, e=4376, s=3):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_4", - "sat": "def sat(x: List[int], t=6165697, a=47, e=3830, s=2):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=6165697, a=47, e=3830, s=2):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_5", - "sat": "def sat(x: List[int], t=57512774, a=72, e=2969, s=10):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=57512774, a=72, e=2969, s=10):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_6", - "sat": "def sat(x: List[int], t=33284554, a=29, e=9940, s=6):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=33284554, a=29, e=9940, s=6):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_7", - "sat": "def sat(x: List[int], t=61009433, a=30, e=2203, s=2):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=61009433, a=30, e=2203, s=2):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_8", - "sat": "def sat(x: List[int], t=92000125, a=41, e=4040, s=7):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=92000125, a=41, e=4040, s=7):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SublistSum_9", - "sat": "def sat(x: List[int], t=97619250, a=76, e=8612, s=1):\n \"\"\"Sum values of sublist by range specifications\"\"\"\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", - "sols": [ - "def sol(t=97619250, a=76, e=8612, s=1):\n x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_0", - "sat": "def sat(x: List[int], t=50, n=10):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=50, n=10):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_1", - "sat": "def sat(x: List[int], t=364928431, n=1088):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=364928431, n=1088):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_2", - "sat": "def sat(x: List[int], t=7978940451, n=5932):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=7978940451, n=5932):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_3", - "sat": "def sat(x: List[int], t=4545622399, n=1009):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=4545622399, n=1009):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_4", - "sat": "def sat(x: List[int], t=4917027557, n=4815):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=4917027557, n=4815):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_5", - "sat": "def sat(x: List[int], t=7284692637, n=5426):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=7284692637, n=5426):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_6", - "sat": "def sat(x: List[int], t=1827591180, n=137):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=1827591180, n=137):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_7", - "sat": "def sat(x: List[int], t=7072532941, n=724):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=7072532941, n=724):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_8", - "sat": "def sat(x: List[int], t=5416310980, n=4948):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=5416310980, n=4948):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CumulativeSum_9", - "sat": "def sat(x: List[int], t=8182502443, n=6415):\n \"\"\"Find how many values have cumulative sum less than target\"\"\"\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", - "sols": [ - "def sol(t=8182502443, n=6415):\n return [1] * n + [t]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_0", - "sat": "def sat(s: str, s1=\"a\", s2=\"b\", count1=50, count2=30):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"a\", s2=\"b\", count1=50, count2=30):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_1", - "sat": "def sat(s: str, s1=\"t\", s2=\"qu\", count1=86, count2=83):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"t\", s2=\"qu\", count1=86, count2=83):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_2", - "sat": "def sat(s: str, s1=\"kuc\", s2=\"qu\", count1=63, count2=58):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"kuc\", s2=\"qu\", count1=63, count2=58):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_3", - "sat": "def sat(s: str, s1=\"te\", s2=\"tex\", count1=97, count2=53):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"te\", s2=\"tex\", count1=97, count2=53):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_4", - "sat": "def sat(s: str, s1=\"hot\", s2=\"n\", count1=48, count2=92):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"hot\", s2=\"n\", count1=48, count2=92):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_5", - "sat": "def sat(s: str, s1=\"gus\", s2=\"fo\", count1=36, count2=60):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"gus\", s2=\"fo\", count1=36, count2=60):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_6", - "sat": "def sat(s: str, s1=\"f\", s2=\"ny\", count1=65, count2=66):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"f\", s2=\"ny\", count1=65, count2=66):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_7", - "sat": "def sat(s: str, s1=\"s\", s2=\"k\", count1=24, count2=27):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"s\", s2=\"k\", count1=24, count2=27):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_8", - "sat": "def sat(s: str, s1=\"x\", s2=\"tyj\", count1=74, count2=8):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"x\", s2=\"tyj\", count1=74, count2=8):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "BasicStrCounts_9", - "sat": "def sat(s: str, s1=\"p\", s2=\"mec\", count1=99, count2=1):\n \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", - "sols": [ - "def sol(s1=\"p\", s2=\"mec\", count1=99, count2=1):\n if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_0", - "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz', 'oddball']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['foo', 'bar', 'baz', 'oddball']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_1", - "sat": "def sat(s: str, substrings=['quifelota', 'chyhimyvemene', 'ge']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['quifelota', 'chyhimyvemene', 'ge']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_2", - "sat": "def sat(s: str, substrings=['kitytextiritex', 'cumathoxaz', 'rebute', 'rocor']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['kitytextiritex', 'cumathoxaz', 'rebute', 'rocor']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_3", - "sat": "def sat(s: str, substrings=['te', 'wusyc']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['te', 'wusyc']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_4", - "sat": "def sat(s: str, substrings=['cute', 'rysucajaxuno']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['cute', 'rysucajaxuno']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_5", - "sat": "def sat(s: str, substrings=['dafykechizoj', 'levi', 'ligohysowebizic', 'cho']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['dafykechizoj', 'levi', 'ligohysowebizic', 'cho']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_6", - "sat": "def sat(s: str, substrings=['fufithatext']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['fufithatext']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_7", - "sat": "def sat(s: str, substrings=['pithygymuwoquumudir', 'gaquevitextyquimi', 'puchafik']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['pithygymuwoquumudir', 'gaquevitextyquimi', 'puchafik']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_8", - "sat": "def sat(s: str, substrings=['behylyhogu', 'coker']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['behylyhogu', 'coker']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ZipStr_9", - "sat": "def sat(s: str, substrings=['chitunuquisu']):\n \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", - "sols": [ - "def sol(substrings=['chitunuquisu']):\n m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_0", - "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['foo', 'bar', 'baz']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_1", - "sat": "def sat(s: str, substrings=['kepijilufuwisejyzat', 'lechogyvonaxegitex']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['kepijilufuwisejyzat', 'lechogyvonaxegitex']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_2", - "sat": "def sat(s: str, substrings=['ripihuquyrenytu', 'quosafyji', 'chyguzocuzuqu', 'futhixequyb']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['ripihuquyrenytu', 'quosafyji', 'chyguzocuzuqu', 'futhixequyb']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_3", - "sat": "def sat(s: str, substrings=['thacovatukoliva', 'maquyfezisothizyp', 'ka', 'benegiquememif']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['thacovatukoliva', 'maquyfezisothizyp', 'ka', 'benegiquememif']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_4", - "sat": "def sat(s: str, substrings=['t', 'vochemachylit', 'vutextynydakelopi', 'fazapydomozamochug']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['t', 'vochemachylit', 'vutextynydakelopi', 'fazapydomozamochug']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_5", - "sat": "def sat(s: str, substrings=['quy']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['quy']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_6", - "sat": "def sat(s: str, substrings=['mycam', 'betextigohubafigiku', 'ga', 'gegumypuwedobixaf']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['mycam', 'betextigohubafigiku', 'ga', 'gegumypuwedobixaf']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_7", - "sat": "def sat(s: str, substrings=['berovev', 'vizethavil', 'safuvivylodijesymoc']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['berovev', 'vizethavil', 'safuvivylodijesymoc']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_8", - "sat": "def sat(s: str, substrings=['xythibureciweduzebi', 'thebitez', 'chutextiquepahokop']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['xythibureciweduzebi', 'thebitez', 'chutextiquepahokop']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "ReverseCat_9", - "sat": "def sat(s: str, substrings=['mypamoxizuvivoch', 'ryte', 'suchafohexucetext']):\n \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"\n return all(sub in s and sub[::-1] in s for sub in substrings)", - "sols": [ - "def sol(substrings=['mypamoxizuvivoch', 'ryte', 'suchafohexucetext']):\n return \"\".join(substrings + [s[::-1] for s in substrings])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_0", - "sat": "def sat(ls: List[str], n=100, a=\"bar\", b=\"foo\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=100, a=\"bar\", b=\"foo\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_1", - "sat": "def sat(ls: List[str], n=44, a=\"lychezothotextocev\", b=\"th\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=44, a=\"lychezothotextocev\", b=\"th\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_2", - "sat": "def sat(ls: List[str], n=13, a=\"kacukebyhapuniryh\", b=\"te\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=13, a=\"kacukebyhapuniryh\", b=\"te\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_3", - "sat": "def sat(ls: List[str], n=61, a=\"cisoceratext\", b=\"milusicochylitextyco\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=61, a=\"cisoceratext\", b=\"milusicochylitextyco\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_4", - "sat": "def sat(ls: List[str], n=59, a=\"hokitextawelaxah\", b=\"maryhedu\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=59, a=\"hokitextawelaxah\", b=\"maryhedu\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_5", - "sat": "def sat(ls: List[str], n=33, a=\"cha\", b=\"gymotexto\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=33, a=\"cha\", b=\"gymotexto\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_6", - "sat": "def sat(ls: List[str], n=17, a=\"fequygutextyw\", b=\"wamathukajaxesythe\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=17, a=\"fequygutextyw\", b=\"wamathukajaxesythe\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_7", - "sat": "def sat(ls: List[str], n=55, a=\"lethico\", b=\"mychasese\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=55, a=\"lethico\", b=\"mychasese\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_8", - "sat": "def sat(ls: List[str], n=45, a=\"chyloraviwunosicohaz\", b=\"dutextycyhino\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=45, a=\"chyloraviwunosicohaz\", b=\"dutextycyhino\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EngineerNumbers_9", - "sat": "def sat(ls: List[str], n=11, a=\"chuwegagatext\", b=\"wu\"):\n \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", - "sols": [ - "def sol(n=11, a=\"chuwegagatext\", b=\"wu\"):\n return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_0", - "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_1", - "sat": "def sat(s: str, strings=['ryzapychybykydege', 'mivowepe', 'sovywos', 'chanyrorybynid', 'vafechajufo', 'nokymocymoxac', 'jahejafuquoduk', 'gogy', 'bytothice', 'ruminuvixixutudigom']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['ryzapychybykydege', 'mivowepe', 'sovywos', 'chanyrorybynid', 'vafechajufo', 'nokymocymoxac', 'jahejafuquoduk', 'gogy', 'bytothice', 'ruminuvixixutudigom']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_2", - "sat": "def sat(s: str, strings=['mipelavychekecy', 'pythujutisoxofe', 'diliwagacivychinofiw', 'na', 'dobynaramithibolo', 'cugupyfytextofoxat', 'gyfokebo', 'bymitextitextizoc', 'rekimuk', 'bepumyxitubachek']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['mipelavychekecy', 'pythujutisoxofe', 'diliwagacivychinofiw', 'na', 'dobynaramithibolo', 'cugupyfytextofoxat', 'gyfokebo', 'bymitextitextizoc', 'rekimuk', 'bepumyxitubachek']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_3", - "sat": "def sat(s: str, strings=['hunuvarufefikaq', 'xejegu', 'minoc', 'puthyvyc', 'xyzeryberi', 'tyl', 'thyvojyvijazetonowa', 'jahygywuchitho', 'quuvuvigy', 'zuhechywituthexe']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['hunuvarufefikaq', 'xejegu', 'minoc', 'puthyvyc', 'xyzeryberi', 'tyl', 'thyvojyvijazetonowa', 'jahygywuchitho', 'quuvuvigy', 'zuhechywituthexe']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_4", - "sat": "def sat(s: str, strings=['wesolotelunyzecemexi', 'pociquuwygocysahef', 'lequusigipitexti', 'quojuxaq', 'fyt', 'm', 'bavalepynoza', 'zihath', 'lodomijibuxoju', 'xasuwytextochypuli']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['wesolotelunyzecemexi', 'pociquuwygocysahef', 'lequusigipitexti', 'quojuxaq', 'fyt', 'm', 'bavalepynoza', 'zihath', 'lodomijibuxoju', 'xasuwytextochypuli']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_5", - "sat": "def sat(s: str, strings=['mehyzuwexenuchy', 'z', 'jeryhyfyfucipuri', 'laquavuthythawugethy', 'gyd', 'bulytawugumunu', 'ziwosemoq', 'pypi', 'textichecypixochas', 'l']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['mehyzuwexenuchy', 'z', 'jeryhyfyfucipuri', 'laquavuthythawugethy', 'gyd', 'bulytawugumunu', 'ziwosemoq', 'pypi', 'textichecypixochas', 'l']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_6", - "sat": "def sat(s: str, strings=['he', 'zobujymet', 'gebat', 'q', 'rozaviquesylobyzup', 'lomypy', 'myquuzochatho', 'zikiditextavevithyv', 'zelitodyxufixoky', 'vichadosi']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['he', 'zobujymet', 'gebat', 'q', 'rozaviquesylobyzup', 'lomypy', 'myquuzochatho', 'zikiditextavevithyv', 'zelitodyxufixoky', 'vichadosi']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_7", - "sat": "def sat(s: str, strings=['gylaruzediconyth', 'nathupu', 'gyjehuthixi', 'jathizocytextaricoj', 'catextyruhagawyxojo', 'lotextoquyt', 'pa', 'textatimyrixumuk', 'fycot', 'hif']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['gylaruzediconyth', 'nathupu', 'gyjehuthixi', 'jathizocytextaricoj', 'catextyruhagawyxojo', 'lotextoquyt', 'pa', 'textatimyrixumuk', 'fycot', 'hif']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_8", - "sat": "def sat(s: str, strings=['ragy', 'kymosyth', 'miw', 'te', 'tusatocejabinymyb', 'vabyd', 'sebuvuthozunapimove', 'mo', 'nujufefewikythoroke', 'zypoduzuchenazybuta']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['ragy', 'kymosyth', 'miw', 'te', 'tusatocejabinymyb', 'vabyd', 'sebuvuthozunapimove', 'mo', 'nujufefewikythoroke', 'zypoduzuchenazybuta']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateString_9", - "sat": "def sat(s: str, strings=['jiquadymeredugeby', 'zykarothuviwunedur', 'kahidothutextitex', 'gi', 'hudutecheheni', 'te', 'dawobitextilymy', 'pamalezadi', 'xumovaquymaxaq', 'saponodiry']):\n \"\"\"Find the alphabetically second to last last string in a list.\"\"\"\n return s in strings and sum(t > s for t in strings) == 1", - "sols": [ - "def sol(strings=['jiquadymeredugeby', 'zykarothuviwunedur', 'kahidothutextitex', 'gi', 'hudutecheheni', 'te', 'dawobitextilymy', 'pamalezadi', 'xumovaquymaxaq', 'saponodiry']):\n return sorted(strings)[-2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_0", - "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_1", - "sat": "def sat(s: str, strings=['rawithelen', 'que', 'pikuf', 'koze', 'zehyquorofyxytextef', 'text', 'jezebox', 'zychopucebychokyz', 'pyzyxatevafugedix', 'buzogehabojyb']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['rawithelen', 'que', 'pikuf', 'koze', 'zehyquorofyxytextef', 'text', 'jezebox', 'zychopucebychokyz', 'pyzyxatevafugedix', 'buzogehabojyb']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_2", - "sat": "def sat(s: str, strings=['thythanaham', 'quiroxebadivogis', 'kyh', 'xa', 'gathytyjonymihahahy', 'musyzisequyxyhenico', 'poxizitizexokigewifi', 'mife', 'chyjuratexta', 'gyrato']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['thythanaham', 'quiroxebadivogis', 'kyh', 'xa', 'gathytyjonymihahahy', 'musyzisequyxyhenico', 'poxizitizexokigewifi', 'mife', 'chyjuratexta', 'gyrato']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_3", - "sat": "def sat(s: str, strings=['habicynanikadifovac', 'bozehathyfoz', 'hud', 'textudunachuxarise', 'hewohahatazabab', 'lutumelimevabutha', 'wocher', 'wacifufixudizon', 'tazibedo', 'xytu']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['habicynanikadifovac', 'bozehathyfoz', 'hud', 'textudunachuxarise', 'hewohahatazabab', 'lutumelimevabutha', 'wocher', 'wacifufixudizon', 'tazibedo', 'xytu']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_4", - "sat": "def sat(s: str, strings=['vekykothumygochuth', 'xujatajazisiqu', 'vapyvymobymethotexto', 'tygope', 'g', 'ripalotextaj', 'tecehuthojodogucivaj', 'xyjulecometihesej', 'ribo', 'gutachowagexatoset']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['vekykothumygochuth', 'xujatajazisiqu', 'vapyvymobymethotexto', 'tygope', 'g', 'ripalotextaj', 'tecehuthojodogucivaj', 'xyjulecometihesej', 'ribo', 'gutachowagexatoset']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_5", - "sat": "def sat(s: str, strings=['thawubudajynipogi', 'ho', 'quutextosuhifake', 's', 'xaquyjoquythufutho', 'quythizapinuzoriquyn', 'liravexequ', 'besoco', 'ful', 'zemamecanozytextici']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['thawubudajynipogi', 'ho', 'quutextosuhifake', 's', 'xaquyjoquythufutho', 'quythizapinuzoriquyn', 'liravexequ', 'besoco', 'ful', 'zemamecanozytextici']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_6", - "sat": "def sat(s: str, strings=['hisoryxyzegyquatex', 'furojuwiqu', 'begigyxonechexuwe', 'ronezuzuhanath', 'vakehajipequa', 'cyga', 'zacutecu', 'luthygiquuhixewy', 'quinic', 'textokyvelifefyl']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['hisoryxyzegyquatex', 'furojuwiqu', 'begigyxonechexuwe', 'ronezuzuhanath', 'vakehajipequa', 'cyga', 'zacutecu', 'luthygiquuhixewy', 'quinic', 'textokyvelifefyl']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_7", - "sat": "def sat(s: str, strings=['withi', 'charubugawety', 'botextenolaxatyji', 'giquo', 'ne', 'rywiquuq', 'thesixebohicenujy', 'p', 'chap', 'ladake']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['withi', 'charubugawety', 'botextenolaxatyji', 'giquo', 'ne', 'rywiquuq', 'thesixebohicenujy', 'p', 'chap', 'ladake']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_8", - "sat": "def sat(s: str, strings=['jerymemychymuze', 'chyk', 'nisemutextajuwuxej', 'c', 'c', 'juzuhafydubi', 'hi', 'basynapoquiv', 'jyjivotifujyge', 'textoboquapagiti']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['jerymemychymuze', 'chyk', 'nisemutextajuwuxej', 'c', 'c', 'juzuhafydubi', 'hi', 'basynapoquiv', 'jyjivotifujyge', 'textoboquapagiti']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "PenultimateRevString_9", - "sat": "def sat(s: str, strings=['xo', 'coxavilowakatuxil', 'c', 'rethek', 'hyzisogatymizehabec', 'kycu', 'gijivonyt', 'tex', 'kyrevafapyquilotex', 'noxoza']):\n \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", - "sols": [ - "def sol(strings=['xo', 'coxavilowakatuxil', 'c', 'rethek', 'hyzisogatymizehabec', 'kycu', 'gijivonyt', 'tex', 'kyrevafapyquilotex', 'noxoza']):\n return sorted(strings)[1][::-1]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_0", - "sat": "def sat(s: str, target=\"foobarbazwow\", length=6):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"foobarbazwow\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_1", - "sat": "def sat(s: str, target=\"rujus\", length=1):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"rujus\", length=1):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_2", - "sat": "def sat(s: str, target=\"bulu\", length=4):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"bulu\", length=4):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_3", - "sat": "def sat(s: str, target=\"defojuhujuwilumec\", length=7):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"defojuhujuwilumec\", length=7):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_4", - "sat": "def sat(s: str, target=\"tenuhije\", length=6):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"tenuhije\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_5", - "sat": "def sat(s: str, target=\"moquokomyxath\", length=13):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"moquokomyxath\", length=13):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_6", - "sat": "def sat(s: str, target=\"bybavoz\", length=6):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"bybavoz\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_7", - "sat": "def sat(s: str, target=\"g\", length=1):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"g\", length=1):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_8", - "sat": "def sat(s: str, target=\"voxufabokydih\", length=2):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"voxufabokydih\", length=2):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "CenteredString_9", - "sat": "def sat(s: str, target=\"xegutextiqua\", length=11):\n \"\"\"Find a substring of the given length centered within the target string.\"\"\"\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", - "sols": [ - "def sol(target=\"xegutextiqua\", length=11):\n return target[(len(target) - length) // 2:(len(target) + length) // 2]" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_0", - "sat": "def sat(substring: str, string=\"moooboooofasd\", count=2):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"moooboooofasd\", count=2):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_1", - "sat": "def sat(substring: str, string=\"nyvyfytibuquyquuchudemixyzychumanachozyquiquowutextyvomyzychyme\", count=4):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"nyvyfytibuquyquuchudemixyzychumanachozyquiquowutextyvomyzychyme\", count=4):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_2", - "sat": "def sat(substring: str, string=\"cokomoquiwythyluwamymothynihythenyfeteth\", count=4):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"cokomoquiwythyluwamymothynihythenyfeteth\", count=4):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_3", - "sat": "def sat(substring: str, string=\"cutextolichymocajethamopyvepethytextydynykihywyxivytextequylejekuf\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"cutextolichymocajethamopyvepethytextydynykihywyxivytextequylejekuf\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_4", - "sat": "def sat(substring: str, string=\"modacequytextytextilaleguthovamipehywaciripetext\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"modacequytextytextilaleguthovamipehywaciripetext\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_5", - "sat": "def sat(substring: str, string=\"quomedevocumubudisirejededuquucirilov\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"quomedevocumubudisirejededuquucirilov\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_6", - "sat": "def sat(substring: str, string=\"vunoxuchanofifupobykibisotywoquitytextopazitapyxepuzyzesychazethywaxiwaquylomotextyzafa\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"vunoxuchanofifupobykibisotywoquitytextopazitapyxepuzyzesychazethywaxiwaquylomotextyzafa\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_7", - "sat": "def sat(substring: str, string=\"bavawadovocegelapubaworytitextojetextuhoquochinitextutextemycofuthitizehychopitexterythihoxutatex\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"bavawadovocegelapubaworytitextojetextuhoquochinitextutextemycofuthitizehychopitexterythihoxutatex\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_8", - "sat": "def sat(substring: str, string=\"textyficugibipivytecitextirojypesuvihytextuk\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"textyficugibipivytecitextirojypesuvihytextuk\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "SubstrCount_9", - "sat": "def sat(substring: str, string=\"chogewechojenuxogicunigimevathugychapyquobezihuhedakibym\", count=3):\n \"\"\"Find a substring with a certain count in a given string\"\"\"\n return string.count(substring) == count", - "sols": [ - "def sol(string=\"chogewechojenuxogicunigimevathugychapyquobezihuhedakibym\", count=3):\n for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" - ], - "module": "basic", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.004545454545454545 - }, - { - "name": "EightQueensOrFewer_0", - "sat": "def sat(squares: List[List[int]], m=8, n=8):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=8, n=8): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_1", - "sat": "def sat(squares: List[List[int]], m=9, n=6):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=9, n=6): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_2", - "sat": "def sat(squares: List[List[int]], m=59, n=4):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=59, n=4): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_3", - "sat": "def sat(squares: List[List[int]], m=38, n=8):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=38, n=8): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_4", - "sat": "def sat(squares: List[List[int]], m=9, n=4):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=9, n=4): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_5", - "sat": "def sat(squares: List[List[int]], m=45, n=8):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=45, n=8): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_6", - "sat": "def sat(squares: List[List[int]], m=7, n=91):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=7, n=91): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_7", - "sat": "def sat(squares: List[List[int]], m=5, n=62):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=5, n=62): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_8", - "sat": "def sat(squares: List[List[int]], m=51, n=4):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=51, n=4): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "EightQueensOrFewer_9", - "sat": "def sat(squares: List[List[int]], m=7, n=7):\n \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", - "sols": [ - "def sol(m=7, n=7): # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" - ], - "module": "chess", - "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_0", - "sat": "def sat(squares: List[List[int]], m=9, n=9):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=9, n=9):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_1", - "sat": "def sat(squares: List[List[int]], m=79, n=95):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=79, n=95):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_2", - "sat": "def sat(squares: List[List[int]], m=80, n=88):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=80, n=88):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_3", - "sat": "def sat(squares: List[List[int]], m=56, n=16):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=56, n=16):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_4", - "sat": "def sat(squares: List[List[int]], m=23, n=45):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=23, n=45):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_5", - "sat": "def sat(squares: List[List[int]], m=71, n=87):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=71, n=87):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_6", - "sat": "def sat(squares: List[List[int]], m=75, n=67):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=75, n=67):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_7", - "sat": "def sat(squares: List[List[int]], m=44, n=19):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=44, n=19):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_8", - "sat": "def sat(squares: List[List[int]], m=32, n=92):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=32, n=92):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "MoreQueens_9", - "sat": "def sat(squares: List[List[int]], m=94, n=9):\n \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", - "sols": [ - "def sol(m=94, n=9):\n t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_0", - "sat": "def sat(tour: List[List[int]], m=8, n=8):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=8, n=8): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_1", - "sat": "def sat(tour: List[List[int]], m=9, n=9):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=9, n=9): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_2", - "sat": "def sat(tour: List[List[int]], m=7, n=7):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=7, n=7): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_3", - "sat": "def sat(tour: List[List[int]], m=6, n=6):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=6, n=6): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_4", - "sat": "def sat(tour: List[List[int]], m=5, n=5):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=5, n=5): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_5", - "sat": "def sat(tour: List[List[int]], m=10, n=10):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=10, n=10): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_6", - "sat": "def sat(tour: List[List[int]], m=11, n=11):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=11, n=11): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_7", - "sat": "def sat(tour: List[List[int]], m=12, n=12):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=12, n=12): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_8", - "sat": "def sat(tour: List[List[int]], m=13, n=13):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=13, n=13): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "KnightsTour_9", - "sat": "def sat(tour: List[List[int]], m=14, n=14):\n \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", - "sols": [ - "def sol(m=14, n=14): # using Warnsdorff's heuristic, breaking ties randomly \n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" - ], - "module": "chess", - "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_0", - "sat": "def sat(path: List[List[int]], m=8, n=8, target=35):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_1", - "sat": "def sat(path: List[List[int]], m=3, n=3, target=2):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_2", - "sat": "def sat(path: List[List[int]], m=4, n=4, target=5):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_3", - "sat": "def sat(path: List[List[int]], m=5, n=5, target=10):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_4", - "sat": "def sat(path: List[List[int]], m=6, n=6, target=17):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_5", - "sat": "def sat(path: List[List[int]], m=7, n=7, target=24):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_6", - "sat": "def sat(path: List[List[int]], m=9, n=9, target=47):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_7", - "sat": "def sat(path: List[List[int]], m=10, n=10, target=61):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_8", - "sat": "def sat(path: List[List[int]], m=11, n=11, target=76):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UncrossedKnightsPath_9", - "sat": "def sat(path: List[List[int]], m=12, n=12, target=94):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_0", - "sat": "def sat(path: List[List[int]], m=10, n=10, target=62):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_1", - "sat": "def sat(path: List[List[int]], m=11, n=11, target=77):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_2", - "sat": "def sat(path: List[List[int]], m=12, n=12, target=95):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_3", - "sat": "def sat(path: List[List[int]], m=13, n=13, target=114):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_4", - "sat": "def sat(path: List[List[int]], m=14, n=14, target=136):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_5", - "sat": "def sat(path: List[List[int]], m=15, n=15, target=159):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_6", - "sat": "def sat(path: List[List[int]], m=16, n=16, target=184):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_7", - "sat": "def sat(path: List[List[int]], m=17, n=17, target=212):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_8", - "sat": "def sat(path: List[List[int]], m=18, n=18, target=239):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "UNSOLVED_UncrossedKnightsPath_9", - "sat": "def sat(path: List[List[int]], m=19, n=19, target=269):\n \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", - "sols": [], - "module": "chess", - "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "LZW_0", - "sat": "def sat(seq: List[int], compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_1", - "sat": "def sat(seq: List[int], compressed_len=0, text=\"\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=0, text=\"\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_2", - "sat": "def sat(seq: List[int], compressed_len=45, text=\"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=45, text=\"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_3", - "sat": "def sat(seq: List[int], compressed_len=154, text=\"cupewoquabipemecacichytogycykythyzydizutextojokosapysetextethilabequypagichichimipyhuquithyzuwukychycokigomylotextoquochachikalocejiwyzagodothilythetiquypirabafusubasufylejulitudosisyrahezitextoluquevy\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=154, text=\"cupewoquabipemecacichytogycykythyzydizutextojokosapysetextethilabequypagichichimipyhuquithyzuwukychycokigomylotextoquochachikalocejiwyzagodothilythetiquypirabafusubasufylejulitudosisyrahezitextoluquevy\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_4", - "sat": "def sat(seq: List[int], compressed_len=2, text=\"si\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=2, text=\"si\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_5", - "sat": "def sat(seq: List[int], compressed_len=536, text=\"vebenuthiryliwehumethemoquyhobodikirihegitextonathawuwiwiwebihawuxenachiwirabysipechorovyrofikyricedimulufachebogufyhocuthiwuthohacevetextasyleludekatinyxuwupydofikemojoquinoxaqueciperilaquozoquakefezomomachovesavomyquypythobuquizukufadyridiquulachymuzamesosaregiryjujejozupymuchotolochochynelolehujithukabeliviracelothuwexanihutextathybuchomytothedurivelythujenywalunynylomoviziworyrewybawochuwajirasuquojabyhithylecabedimahylevazathihobyvehivethetextihygosecorucufakacuquypaguhugydexichepothyxuherowonesichenacizovefykonunowetextohycowesipyboxacedozatybajifejywaryxymubegisozatharabicybyrilaxeridazoquuzytiquujewidyzazyrarikopyhochigotihyfarenajonopisyfafehudolubydebaquysizugyweciquichufyrudethocarovechymothachyzafurewuquuthyxojotextekotuxetuchanotuguhaquydopoxafaquujisukyfagykibenozahuchazysithyjogavochiwibiquuhequihyzikofazybimovychanycagokokyxikuwothefylidipogineduthijedyzolobuthokerydidequavocacuwucabojepokyba\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=536, text=\"vebenuthiryliwehumethemoquyhobodikirihegitextonathawuwiwiwebihawuxenachiwirabysipechorovyrofikyricedimulufachebogufyhocuthiwuthohacevetextasyleludekatinyxuwupydofikemojoquinoxaqueciperilaquozoquakefezomomachovesavomyquypythobuquizukufadyridiquulachymuzamesosaregiryjujejozupymuchotolochochynelolehujithukabeliviracelothuwexanihutextathybuchomytothedurivelythujenywalunynylomoviziworyrewybawochuwajirasuquojabyhithylecabedimahylevazathihobyvehivethetextihygosecorucufakacuquypaguhugydexichepothyxuherowonesichenacizovefykonunowetextohycowesipyboxacedozatybajifejywaryxymubegisozatharabicybyrilaxeridazoquuzytiquujewidyzazyrarikopyhochigotihyfarenajonopisyfafehudolubydebaquysizugyweciquichufyrudethocarovechymothachyzafurewuquuthyxojotextekotuxetuchanotuguhaquydopoxafaquujisukyfagykibenozahuchazysithyjogavochiwibiquuhequihyzikofazybimovychanycagokokyxikuwothefylidipogineduthijedyzolobuthokerydidequavocacuwucabojepokyba\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_6", - "sat": "def sat(seq: List[int], compressed_len=41, text=\"vybegosyjurakumunyjimolachevazisakacyzecogyf\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=41, text=\"vybegosyjurakumunyjimolachevazisakacyzecogyf\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_7", - "sat": "def sat(seq: List[int], compressed_len=72, text=\"nitextachizyxuvyzafalichurakymomoquichameguvasahetythuquuryfyquijymuchutherobylichichim\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=72, text=\"nitextachizyxuvyzafalichurakymomoquichameguvasahetythuquuryfyquijymuchutherobylichichim\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_8", - "sat": "def sat(seq: List[int], compressed_len=43, text=\"lafitextunuxonuxodakesydepexithymequilawepapumilyp\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=43, text=\"lafitextunuxonuxodakesydepexithymequilawepapumilyp\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_9", - "sat": "def sat(seq: List[int], compressed_len=2, text=\"fo\"):\n \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", - "sols": [ - "def sol(compressed_len=2, text=\"fo\"): # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" - ], - "module": "compression", - "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_0", - "sat": "def sat(text: str, seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[72, 101, 108, 108, 111, 32, 119, 111, 114, 100, 262, 264, 266, 263, 265, 33]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_1", - "sat": "def sat(text: str, seq: List[int]=[]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_2", - "sat": "def sat(text: str, seq=[97]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[97]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_3", - "sat": "def sat(text: str, seq=[98, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 265]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[98, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 265]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_4", - "sat": "def sat(text: str, seq=[97, 98, 257, 259, 258, 261, 260, 263, 262, 265, 264, 267, 266, 269, 268, 271, 270, 273, 272, 275, 274, 277, 276, 279, 278, 281, 280, 283, 282, 285, 284, 287, 286, 289, 288, 291, 290, 293, 292, 295, 294, 297, 296, 299, 298, 301, 300, 303, 302, 305, 304, 307, 306, 309, 308, 311, 310, 313, 312, 315, 314, 317, 316, 319, 318, 321, 320, 323, 322, 325, 324, 327, 326, 329, 328, 331, 330, 333, 332, 335, 334, 337, 336, 339, 338, 341, 340, 343, 293, 33]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[97, 98, 257, 259, 258, 261, 260, 263, 262, 265, 264, 267, 266, 269, 268, 271, 270, 273, 272, 275, 274, 277, 276, 279, 278, 281, 280, 283, 282, 285, 284, 287, 286, 289, 288, 291, 290, 293, 292, 295, 294, 297, 296, 299, 298, 301, 300, 303, 302, 305, 304, 307, 306, 309, 308, 311, 310, 313, 312, 315, 314, 317, 316, 319, 318, 321, 320, 323, 322, 325, 324, 327, 326, 329, 328, 331, 330, 333, 332, 335, 334, 337, 336, 339, 338, 341, 340, 343, 293, 33]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_5", - "sat": "def sat(text: str, seq=[108, 101, 102, 117, 119, 111, 114, 105, 122, 117, 106, 111, 99, 101, 116, 101, 120, 271, 119, 97, 122, 101, 113, 117, 105, 109, 101, 108, 111, 104, 270, 272, 116, 121, 116, 104, 97, 108, 97, 271, 273, 117, 102]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[108, 101, 102, 117, 119, 111, 114, 105, 122, 117, 106, 111, 99, 101, 116, 101, 120, 271, 119, 97, 122, 101, 113, 117, 105, 109, 101, 108, 111, 104, 270, 272, 116, 121, 116, 104, 97, 108, 97, 271, 273, 117, 102]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_6", - "sat": "def sat(text: str, seq=[103, 121, 120, 101, 98, 105, 106, 101]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[103, 121, 120, 101, 98, 105, 106, 101]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_7", - "sat": "def sat(text: str, seq=[108, 105, 119, 105, 120, 101, 106, 105, 99, 105, 116, 111, 107, 97, 100, 117, 110, 117, 114, 121, 106, 117, 107, 111, 122, 97, 109, 121, 116, 104, 111, 118, 276, 117, 109, 105, 102, 105, 113, 117, 268, 117, 261, 116, 101, 120, 116, 117, 108, 97, 295, 97, 102, 101, 104, 97, 115, 287, 266, 105, 98, 284, 301, 300, 109, 117, 98, 105, 110, 97, 104, 101, 309, 109, 111, 285, 121, 122, 105, 122, 121, 271, 112, 111, 277, 100, 276, 111, 99, 104, 105, 279, 286, 291, 257, 109, 101, 99, 121, 313, 336, 103, 105, 271, 288, 99, 262, 117, 295, 294, 117, 264, 104, 117, 342, 300, 302, 292, 97, 119, 97, 275, 300, 277, 114, 266, 319, 260, 266, 344, 286, 285, 382, 373, 116, 97, 285, 101, 112, 366, 290, 117, 122, 328, 353, 369, 116, 284, 327, 378, 402, 311, 103, 274, 117, 391, 336, 285, 272, 121, 265, 118, 264, 101, 122, 331, 383, 291, 114, 101, 103, 121, 409, 110, 318, 302, 97, 265, 259, 288, 118, 370, 111, 307, 98, 101, 414, 365, 102, 282, 359, 355, 274, 105, 108, 298, 121, 98, 97, 336, 109, 97, 107, 353, 105, 275, 119, 121, 259, 457, 257, 107, 117, 313, 295, 111, 259, 346, 110, 386, 394, 272, 258, 431, 403, 285, 111, 98, 117, 277, 119, 111, 309, 345, 472, 450, 347, 268, 331, 349, 105, 115, 270, 101, 269, 265, 273, 108, 442, 383, 271, 114, 411, 416, 121, 112, 420, 121, 118, 308, 105, 104, 121, 309, 313, 498, 110, 368, 97, 112, 121, 381, 114, 472, 472, 101, 376, 457, 120, 111, 261, 100, 344, 121, 523, 120, 464, 111, 112, 411, 286, 107, 260, 310, 280, 268, 404, 464, 117, 345, 392, 326, 546, 117, 103, 111, 508, 116, 389, 267, 102, 272, 111, 115, 565, 260, 97, 451, 283, 376, 106, 97, 577, 503, 101, 457, 309, 98, 111, 100, 105, 437, 265, 295, 276, 394, 505, 295, 397, 277, 515, 526, 512, 403, 570, 103, 401, 420, 301, 370, 262, 101, 454, 542, 395, 590, 548, 257, 414, 311, 457, 490, 588, 477, 482, 561, 103, 392, 327, 325, 115, 555, 327, 352, 523, 403, 456, 117, 118, 426, 377, 101, 115, 121, 457, 518, 518, 100, 433, 353, 301, 297, 427, 119, 555, 438, 327, 261, 311, 309, 300, 498, 623, 650, 425, 515, 107, 519, 328, 433, 346, 594, 281, 471, 528, 121, 535, 545, 108, 544, 585, 97, 273, 457, 418, 518, 305, 354, 330, 526, 281, 403, 265, 303, 372, 320, 394, 565, 428, 480, 565, 562, 121, 675, 409, 468, 421, 295, 500, 455, 298, 392, 301, 519, 274, 101, 504, 567, 321, 635, 342, 459, 515, 273, 487, 119, 442, 369, 395, 427, 567, 627, 457, 482, 362, 675, 311, 650, 526, 321, 650, 317, 538, 99, 469, 101, 288, 102, 111, 321, 691, 628, 262, 422, 381, 329, 97, 535, 281, 120, 458, 581]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[108, 105, 119, 105, 120, 101, 106, 105, 99, 105, 116, 111, 107, 97, 100, 117, 110, 117, 114, 121, 106, 117, 107, 111, 122, 97, 109, 121, 116, 104, 111, 118, 276, 117, 109, 105, 102, 105, 113, 117, 268, 117, 261, 116, 101, 120, 116, 117, 108, 97, 295, 97, 102, 101, 104, 97, 115, 287, 266, 105, 98, 284, 301, 300, 109, 117, 98, 105, 110, 97, 104, 101, 309, 109, 111, 285, 121, 122, 105, 122, 121, 271, 112, 111, 277, 100, 276, 111, 99, 104, 105, 279, 286, 291, 257, 109, 101, 99, 121, 313, 336, 103, 105, 271, 288, 99, 262, 117, 295, 294, 117, 264, 104, 117, 342, 300, 302, 292, 97, 119, 97, 275, 300, 277, 114, 266, 319, 260, 266, 344, 286, 285, 382, 373, 116, 97, 285, 101, 112, 366, 290, 117, 122, 328, 353, 369, 116, 284, 327, 378, 402, 311, 103, 274, 117, 391, 336, 285, 272, 121, 265, 118, 264, 101, 122, 331, 383, 291, 114, 101, 103, 121, 409, 110, 318, 302, 97, 265, 259, 288, 118, 370, 111, 307, 98, 101, 414, 365, 102, 282, 359, 355, 274, 105, 108, 298, 121, 98, 97, 336, 109, 97, 107, 353, 105, 275, 119, 121, 259, 457, 257, 107, 117, 313, 295, 111, 259, 346, 110, 386, 394, 272, 258, 431, 403, 285, 111, 98, 117, 277, 119, 111, 309, 345, 472, 450, 347, 268, 331, 349, 105, 115, 270, 101, 269, 265, 273, 108, 442, 383, 271, 114, 411, 416, 121, 112, 420, 121, 118, 308, 105, 104, 121, 309, 313, 498, 110, 368, 97, 112, 121, 381, 114, 472, 472, 101, 376, 457, 120, 111, 261, 100, 344, 121, 523, 120, 464, 111, 112, 411, 286, 107, 260, 310, 280, 268, 404, 464, 117, 345, 392, 326, 546, 117, 103, 111, 508, 116, 389, 267, 102, 272, 111, 115, 565, 260, 97, 451, 283, 376, 106, 97, 577, 503, 101, 457, 309, 98, 111, 100, 105, 437, 265, 295, 276, 394, 505, 295, 397, 277, 515, 526, 512, 403, 570, 103, 401, 420, 301, 370, 262, 101, 454, 542, 395, 590, 548, 257, 414, 311, 457, 490, 588, 477, 482, 561, 103, 392, 327, 325, 115, 555, 327, 352, 523, 403, 456, 117, 118, 426, 377, 101, 115, 121, 457, 518, 518, 100, 433, 353, 301, 297, 427, 119, 555, 438, 327, 261, 311, 309, 300, 498, 623, 650, 425, 515, 107, 519, 328, 433, 346, 594, 281, 471, 528, 121, 535, 545, 108, 544, 585, 97, 273, 457, 418, 518, 305, 354, 330, 526, 281, 403, 265, 303, 372, 320, 394, 565, 428, 480, 565, 562, 121, 675, 409, 468, 421, 295, 500, 455, 298, 392, 301, 519, 274, 101, 504, 567, 321, 635, 342, 459, 515, 273, 487, 119, 442, 369, 395, 427, 567, 627, 457, 482, 362, 675, 311, 650, 526, 321, 650, 317, 538, 99, 469, 101, 288, 102, 111, 321, 691, 628, 262, 422, 381, 329, 97, 535, 281, 120, 458, 581]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_8", - "sat": "def sat(text: str, seq=[114, 111, 104, 97, 99, 105]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[114, 111, 104, 97, 99, 105]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "LZW_decompress_9", - "sat": "def sat(text: str, seq=[114, 105, 98, 117, 108, 121, 104, 121, 103, 97, 112, 117, 116, 101, 120, 116, 105, 119, 111, 109, 111, 108, 117, 104, 111, 116, 280, 118, 105, 116, 117, 118, 121, 99, 111, 119, 117, 112, 97, 106, 101, 119, 121, 112, 111, 98, 101, 269, 271, 105, 122, 275, 111, 102, 111]):\n \"\"\"\n Find a string that compresses to the target sequence for the provided implementation of the\n Lempel-Ziv algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"\n index = {chr(i): i for i in range(256)}\n seq2 = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq2.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq2.append(index[buffer])\n\n return seq2 == seq", - "sols": [ - "def sol(seq=[114, 105, 98, 117, 108, 121, 104, 121, 103, 97, 112, 117, 116, 101, 120, 116, 105, 119, 111, 109, 111, 108, 117, 104, 111, 116, 280, 118, 105, 116, 117, 118, 121, 99, 111, 119, 117, 112, 97, 106, 101, 119, 121, 112, 111, 98, 101, 269, 271, 105, 122, 275, 111, 102, 111]):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append(pieces[-1] + pieces[-1][0] if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces)" - ], - "module": "compression", - "notes": "We have provided a simple version of the\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nand the solution is the *decompression* algorithm.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_0", - "sat": "def sat(words: List[str], num=100, bits=100, dist=34):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=100, bits=100, dist=34):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_1", - "sat": "def sat(words: List[str], num=5, bits=81, dist=30):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=5, bits=81, dist=30):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_2", - "sat": "def sat(words: List[str], num=78, bits=64, dist=16):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=78, bits=64, dist=16):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_3", - "sat": "def sat(words: List[str], num=28, bits=11, dist=1):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=28, bits=11, dist=1):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_4", - "sat": "def sat(words: List[str], num=8, bits=75, dist=24):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=8, bits=75, dist=24):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_5", - "sat": "def sat(words: List[str], num=64, bits=47, dist=11):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=64, bits=47, dist=11):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_6", - "sat": "def sat(words: List[str], num=2, bits=7, dist=2):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=2, bits=7, dist=2):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_7", - "sat": "def sat(words: List[str], num=6, bits=72, dist=28):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=6, bits=72, dist=28):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_8", - "sat": "def sat(words: List[str], num=8, bits=7, dist=1):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=8, bits=7, dist=1):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "PackingHam_9", - "sat": "def sat(words: List[str], num=9, bits=41, dist=12):\n \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", - "sols": [ - "def sol(num=9, bits=41, dist=12):\n import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" - ], - "module": "compression", - "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_0", - "sat": "def sat(init: List[List[int]], period=3):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [ - "def sol(period=3): # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" - ], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_1", - "sat": "def sat(init: List[List[int]], period=1):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [ - "def sol(period=1): # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" - ], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_2", - "sat": "def sat(init: List[List[int]], period=2):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [ - "def sol(period=2): # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" - ], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_3", - "sat": "def sat(init: List[List[int]], period=4):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_4", - "sat": "def sat(init: List[List[int]], period=5):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_5", - "sat": "def sat(init: List[List[int]], period=6):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_6", - "sat": "def sat(init: List[List[int]], period=7):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_7", - "sat": "def sat(init: List[List[int]], period=8):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_8", - "sat": "def sat(init: List[List[int]], period=9):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Oscillators_9", - "sat": "def sat(init: List[List[int]], period=10):\n \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", - "sols": [], - "module": "conways_game_of_life", - "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_0", - "sat": "def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[1, 3], [1, 4], [2, 5]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_1", - "sat": "def sat(position: List[List[int]], target: List[List[int]]=[]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_2", - "sat": "def sat(position: List[List[int]], target=[[-1, -4], [-1, -3], [0, -5], [0, -4], [1, -3]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[-1, -4], [-1, -3], [0, -5], [0, -4], [1, -3]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_3", - "sat": "def sat(position: List[List[int]], target=[[3, 3]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[3, 3]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_4", - "sat": "def sat(position: List[List[int]], target=[[1, -4]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[1, -4]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_5", - "sat": "def sat(position: List[List[int]], target=[[0, 3], [0, 4]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[0, 3], [0, 4]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_6", - "sat": "def sat(position: List[List[int]], target=[[-4, -3], [-3, -3], [-2, 2]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[-4, -3], [-3, -3], [-2, 2]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_7", - "sat": "def sat(position: List[List[int]], target=[[-4, 3], [-4, 4]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[-4, 3], [-4, 4]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_8", - "sat": "def sat(position: List[List[int]], target=[[2, -5], [2, -4], [2, 1]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[2, -5], [2, -4], [2, 1]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "ReverseLifeStep_9", - "sat": "def sat(position: List[List[int]], target=[[-4, 0], [-3, 0]]):\n \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", - "sols": [ - "def sol(target=[[-4, 0], [-3, 0]]): # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" - ], - "module": "conways_game_of_life", - "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_0", - "sat": "def sat(init: List[List[int]], period=4):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_1", - "sat": "def sat(init: List[List[int]], period=2):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_2", - "sat": "def sat(init: List[List[int]], period=3):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_3", - "sat": "def sat(init: List[List[int]], period=5):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_4", - "sat": "def sat(init: List[List[int]], period=6):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_5", - "sat": "def sat(init: List[List[int]], period=7):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_6", - "sat": "def sat(init: List[List[int]], period=8):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_7", - "sat": "def sat(init: List[List[int]], period=9):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_8", - "sat": "def sat(init: List[List[int]], period=10):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Spaceship_9", - "sat": "def sat(init: List[List[int]], period=11):\n \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", - "sols": [], - "module": "conways_game_of_life", - "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", - "taint_date": "2021-4-26", - "weight": 0.03333333333333333 - }, - { - "name": "Nim_0", - "sat": "def sat(cert: List[List[int]], heaps=[5, 9]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[5, 9]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_1", - "sat": "def sat(cert: List[List[int]], heaps=[2, 7, 6, 0, 4, 7]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[2, 7, 6, 0, 4, 7]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_2", - "sat": "def sat(cert: List[List[int]], heaps=[4, 1, 8, 0, 5, 9, 2, 0]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[4, 1, 8, 0, 5, 9, 2, 0]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_3", - "sat": "def sat(cert: List[List[int]], heaps: List[int]=[]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_4", - "sat": "def sat(cert: List[List[int]], heaps=[2, 5, 3, 7, 0]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[2, 5, 3, 7, 0]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_5", - "sat": "def sat(cert: List[List[int]], heaps=[3, 3, 2, 2, 3, 8]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[3, 3, 2, 2, 3, 8]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_6", - "sat": "def sat(cert: List[List[int]], heaps=[5, 8, 3, 0]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[5, 8, 3, 0]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_7", - "sat": "def sat(cert: List[List[int]], heaps=[4, 9, 3]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[4, 9, 3]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_8", - "sat": "def sat(cert: List[List[int]], heaps=[3]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[3]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Nim_9", - "sat": "def sat(cert: List[List[int]], heaps=[9, 7]):\n \"\"\"\n Compute optimal play in Nim, a two-player game involving a number of heaps of objects. Players alternate,\n in each turn removing one or more objects from a single non-empty heap. The player who takes the last object\n wins. The initial board state is represented by heaps, a list of numbers of objects in each heap.\n The optimal play is certified by a list of \"winning leaves\" which are themselves lists of heap sizes\n that, with optimal play, are winning if you leave your opponent with those numbers of objects.\n \"\"\"\n\n good_leaves = {tuple(h) for h in cert} # for efficiency, we keep track of h as a tuple of n non-negative ints\n cache = {}\n\n def is_good_leave(h):\n if h in cache:\n return cache[h]\n next_states = [(*h[:i], k, *h[i + 1:]) for i in range(len(h)) for k in range(h[i])]\n conjecture = (h in good_leaves)\n if conjecture: # check that it is a good leave\n assert not any(is_good_leave(s) for s in next_states)\n else: # check that it is a bad leave, only need to check one move\n assert is_good_leave(next(s for s in next_states if s in good_leaves))\n cache[h] = conjecture\n return conjecture\n\n init_leave = tuple(heaps)\n return is_good_leave(init_leave) == (init_leave in good_leaves)", - "sols": [ - "def sol(heaps=[9, 7]):\n import itertools\n\n def val(h): # return True if h is a good state to leave things in\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n return [list(h) for h in itertools.product(*[range(i + 1) for i in heaps]) if val(h)]" - ], - "module": "games", - "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine the winning states.", - "taint_date": "2021-4-26", - "weight": 0.007142857142857143 - }, - { - "name": "Mastermind_0", - "sat": "def sat(transcripts: List[str], max_moves=10):\n \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n ```\n AABB 11\n ABCD 21\n ABDC\n ```\n This is the transcript as the game is in progress. The complete transcript might be:\n ```\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n ```\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", - "sols": [ - "def sol(max_moves=10):\n COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" - ], - "module": "games", - "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", - "taint_date": "2021-4-26", - "weight": 0.23809523809523805 - }, - { - "name": "Mastermind_1", - "sat": "def sat(transcripts: List[str], max_moves=6):\n \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n ```\n AABB 11\n ABCD 21\n ABDC\n ```\n This is the transcript as the game is in progress. The complete transcript might be:\n ```\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n ```\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", - "sols": [ - "def sol(max_moves=6):\n COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" - ], - "module": "games", - "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", - "taint_date": "2021-4-26", - "weight": 0.23809523809523805 - }, - { - "name": "Mastermind_2", - "sat": "def sat(transcripts: List[str], max_moves=8):\n \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n ```\n AABB 11\n ABCD 21\n ABDC\n ```\n This is the transcript as the game is in progress. The complete transcript might be:\n ```\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n ```\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", - "sols": [ - "def sol(max_moves=8):\n COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" - ], - "module": "games", - "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", - "taint_date": "2021-4-26", - "weight": 0.23809523809523805 - }, - { - "name": "TicTacToeX_0", - "sat": "def sat(good_boards: List[str]):\n \"\"\"\n Compute a strategy for X (first player) in tic-tac-toe that guarantees a tie. That is a strategy for X that,\n no matter what the opponent does, X does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that X aims for, so no matter what O does there\n is always good board that X can get to with a single move.\n \"\"\"\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if X has a forced tie/win assuming it's X's turn to move.\n x |= 1 << [i for i in range(9) if (x | (1 << i), o) in board_bit_reps][0]\n return not win[o] and (win[x] or all((x | o) & (1 << i) or tie(x, o | (1 << i)) for i in range(9)))\n\n return tie(0, 0)", - "sols": [ - "def sol():\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[o]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and o_move(x | (1 << i), o):\n good_boards.append(\"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + (i == j)] for j in range(9)))\n return True\n return False # O wins\n\n def o_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[x] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)):\n return False\n return True # O wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" - ], - "module": "games", - "notes": "Since we don't have interaction, this problem asks for a full tie-guranteeing strategy.", - "taint_date": "2021-4-26", - "weight": 0.07142857142857142 - }, - { - "name": "TicTacToeO_0", - "sat": "def sat(good_boards: List[str]):\n \"\"\"\n Compute a strategy for O (second player) in tic-tac-toe that guarantees a tie. That is a strategy for O that,\n no matter what the opponent does, O does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that O aims for, so no matter what X does there\n is always good board that O can get to with a single move.\n \"\"\"\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move.\n if o | x != 511: # complete board\n o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0]\n return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9)))\n\n return all(tie(1 << i, 0) for i in range(9))", - "sols": [ - "def sol():\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if o wins or ties, x's turn to move\n if win[o] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o):\n return False\n return True # O wins/ties\n\n def o_move(x, o): # returns True if o wins or ties, o's turn to move\n if win[x]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and x_move(x, o | (1 << i)):\n good_boards.append(\n \"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + 2 * (i == j)] for j in range(9)))\n return True\n return False # X wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" - ], - "module": "games", - "notes": "Same as above but for 2nd player", - "taint_date": "2021-4-26", - "weight": 0.07142857142857142 - }, - { - "name": "RockPaperScissors_0", - "sat": "def sat(probs: List[float]):\n \"\"\"Find optimal probabilities for playing Rock-Paper-Scissors zero-sum game, with best worst-case guarantee\"\"\"\n assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6\n return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6", - "sols": [ - "def sol():\n return [1 / 3] * 3" - ], - "module": "games", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.07142857142857142 - }, - { - "name": "Nash_0", - "sat": "def sat(strategies: List[List[float]], A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [ - "def sol(A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01):\n NUM_ATTEMPTS = 100\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" - ], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_1", - "sat": "def sat(strategies: List[List[float]], A=[[0.14738177495578275, 0.747980019825271, 0.1051232435961047, 0.46907581621423977, 0.4706551623263341, 0.9062661953318937], [0.12988166612252583, 0.890441435875433, 0.15190125502216845, 0.0251552990265973, 0.32734850066506815, 0.3591430990509836], [0.9425550188084191, 0.08611212072450258, 0.783624348822126, 0.5349936815267257, 0.10270055080436169, 0.009590499808168174], [0.6380601343485022, 0.2218383099094161, 0.6868257338754123, 0.806638752054053, 0.9018561622314694, 0.7590395566591508], [0.6859264269381581, 0.3699302620070518, 0.9942148381089508, 0.8903935289162987, 0.674293629800702, 0.11410994407146158], [0.019262410240239114, 0.35560181353997367, 0.8517917641156626, 0.3074607746901762, 0.9261733304770997, 0.15224796120543604], [0.03366324617275729, 0.8709614609040649, 0.5849217229245649, 0.6379408604095658, 0.07001731910881204, 0.9582581413742493], [0.4142207195937342, 0.3193135769930635, 0.10706268323342383, 0.942046924893307, 0.9143451786836865, 0.701950437311744], [0.5179763142759984, 0.6412718009580387, 0.20022057700520002, 0.5942457297156203, 0.19646377673223914, 0.1351944216925801]], B=[[0.6516235984777713, 0.6123203626800926, 0.6186872023667903, 0.3853596754503974, 0.1073381662525007, 0.1291386906927786], [0.4925608374781314, 0.6308638606801343, 0.9530950453320264, 0.19706903321155278, 0.24184190603658184, 0.5045244344435803], [0.441426258818589, 0.38377342845027484, 0.012225023944992808, 0.891576455082707, 0.7733199528680031, 0.5559723587618317], [0.40823234393591534, 0.3751689897312942, 0.9735593124687937, 0.9428257869910855, 0.8271844491151399, 0.9685273237161491], [0.4832145692461641, 0.5635754453674369, 0.35994676263243286, 0.7815677383683111, 0.9809479850913646, 0.2808093367857648], [0.7473188591890239, 0.12760325771253167, 0.6709148257444112, 0.6960324705687125, 0.9742301280874588, 0.5061403432364218], [0.5512441627071583, 0.24752179828917065, 0.8112753285511846, 0.31333832922799887, 0.6811740304141864, 0.9411639311639899], [0.7477089685706007, 0.2569950106729836, 0.5041394572889569, 0.10948936347507965, 0.6055289733960375, 0.5733220923473799], [0.6810018730369142, 0.7452579755751384, 0.5448601672849144, 0.6414658827186077, 0.8050401801463669, 0.729851403010736]], eps=0.1): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_2", - "sat": "def sat(strategies: List[List[float]], A=[[0.4934719584926307, 0.05664225783974475, 0.4878391988801185, 0.6983347656105304, 0.7903235569844771], [0.9209179850842271, 0.6945169729870889, 0.985586605726519, 0.03611807745215567, 0.07791862369265457]], B=[[0.5723776540419043, 0.3177494964308457, 0.03283373751184504, 0.960932861317398, 0.3843454398162133], [0.7415658068058613, 0.4423455643375954, 0.9314198922910875, 0.937956471095574, 0.6337568371723998]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.4934719584926307, 0.05664225783974475, 0.4878391988801185, 0.6983347656105304, 0.7903235569844771], [0.9209179850842271, 0.6945169729870889, 0.985586605726519, 0.03611807745215567, 0.07791862369265457]], B=[[0.5723776540419043, 0.3177494964308457, 0.03283373751184504, 0.960932861317398, 0.3843454398162133], [0.7415658068058613, 0.4423455643375954, 0.9314198922910875, 0.937956471095574, 0.6337568371723998]], eps=0.01):\n NUM_ATTEMPTS = 100\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" - ], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_3", - "sat": "def sat(strategies: List[List[float]], A=[[0.8589758630993106, 0.7749919744562254, 0.18371378758390233, 0.28034839679007295, 0.18276337511723684, 0.5173168267432149], [0.535972149604936, 0.6860082336427572, 0.8154412069051551, 0.02442129105356694, 0.1349312146704914, 0.7530215223132398], [0.3519956107153608, 0.9660103168436817, 0.10172694662400983, 0.7254690944575098, 0.8254057287673647, 0.3189629245726713], [0.5725690579346981, 0.1589108703965545, 0.01688986355891453, 0.3074319760280675, 0.4584643560452394, 0.5853201363256517], [0.6489314270374363, 0.6347169492821729, 0.18348768635443546, 0.5731694328630751, 0.6566567470060826, 0.8039403838540958], [0.4917243999522437, 0.16144631954506772, 0.04044367374900226, 0.09502214062659131, 0.8738947440998662, 0.6114058437094053], [0.1967023709822303, 0.29782628261932154, 0.058285139123036234, 0.6302740689117773, 0.33364400882000855, 0.5776389301631869], [0.6777544316258026, 0.6724283041374894, 0.9798391425483743, 0.8838381708326536, 0.6667218181098736, 0.34481925547433623], [0.5958711406283824, 0.44387553450142214, 0.6668717494447683, 0.25986773196752133, 0.8873567554013287, 0.4374385442834563]], B=[[0.6509157248335261, 0.47969567636489663, 0.7175654058769987, 0.8305604678011964, 0.11420347930129515, 0.8401333925076142], [0.8690852438876666, 0.8127345690587251, 0.316832083958, 0.9589533790230425, 0.6983255500551921, 0.4492765771156503], [0.7058401433380928, 0.007340378623609478, 0.5423001137088079, 0.2066909384280825, 0.3317417420195775, 0.003203599551001912], [0.4887994419103735, 0.4082867953539032, 0.3605910405209234, 0.19354666101193807, 0.3116629413961449, 0.9698417812464528], [0.30623970889248353, 0.8377553335650854, 0.7624220111189529, 0.22826919233755616, 0.3832245488487954, 0.11387974071378948], [0.8818032772640031, 0.24028195971823052, 0.8834992573768841, 0.9883007945834051, 0.7024933884432355, 0.7617988546407181], [0.9160905473729156, 0.6927856066612084, 0.6159687601776853, 0.15074396336216966, 0.7764252875888226, 0.3459191304782905], [0.9991431698755587, 0.32389039099370287, 0.8354695347283115, 0.51319161530113, 0.5229921145906276, 0.7690459477032934], [0.7591967670432632, 0.23382636010443625, 0.26521035423368, 0.8577953561722641, 0.020432130142500116, 0.019755815416500178]], eps=0.1): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_4", - "sat": "def sat(strategies: List[List[float]], A=[[0.5753373910044396, 0.883286704506171, 0.14098419242590676, 0.0796482735170555, 0.28053511699815137, 0.4802587237433614, 0.7927565741942321, 0.10486790699611082], [0.674897469149739, 0.5526354958094333, 0.14126552040252316, 0.8176885681560745, 0.5950057513195114, 0.9394498004514682, 0.9974412293717752, 0.31785998202168364], [0.8551492483900579, 0.0873581901597057, 0.7058504781434135, 0.8614481823894408, 0.774002479389802, 0.5194163269795865, 0.8839947283493329, 0.4796849532033839], [0.24669121918914239, 0.9192009909426845, 0.22533689422848313, 0.42231986064003346, 0.8524917527913644, 0.3217815290765713, 0.13012568628724053, 0.08517580086974996], [0.6708003793106111, 0.9370021425919828, 0.956981559137809, 0.48294825852969425, 0.09451427192867867, 0.958711015678715, 0.13874285709747414, 0.17240487357189138], [0.6862479923713413, 0.40988185301904767, 0.7232258320050972, 0.12156129874113497, 0.4137204968814412, 0.43096712555208105, 0.9673727161037606, 0.9554536674896775], [0.2645245766573283, 0.16353379162998616, 0.8208329137057697, 0.24945486012929086, 0.19060921538692044, 0.6886849242360286, 0.6513544853108113, 0.13898253443118158], [0.8399423196728664, 0.5583901386668076, 0.05055384968867316, 0.272512815876485, 0.4706764309925491, 0.9920874820129374, 0.11006687231735834, 0.6003338823254668]], B=[[0.8661101149166154, 0.5041424261188884, 0.654530488206357, 0.842287965510257, 0.5418722524658692, 0.615317049155107, 0.2474305118268787, 0.802249852604974], [0.17399126319302805, 0.37286827574250436, 0.9025123265462714, 0.6302774019777034, 0.6096954531215514, 0.14282756248667317, 0.5039665393854678, 0.5053857713064859], [0.08645764165911696, 0.34639849481946294, 0.4003286765389642, 0.8522825407634552, 0.38924375107949505, 0.13708630962779877, 0.09413370097193263, 0.024977157717289145], [0.18665183173707744, 0.08210966062569414, 0.8906028770829486, 0.9292380534706237, 0.3432700204525524, 0.03791015448620483, 0.23701146631134296, 0.5236370615896554], [0.4158240648499627, 0.620309795706114, 0.6606023798050246, 0.7581954943445194, 0.9399309644265448, 0.6640739757418763, 0.5470483802958659, 0.3881528058493644], [0.8452380694038372, 0.7687623496765781, 0.22422282300746144, 0.03236167241305821, 0.1113965246318579, 0.4589759506900418, 0.8415359432321317, 0.27521377409486303], [0.6582156349227984, 0.9988816473957544, 0.4901663751981855, 0.3788210957458895, 0.455713995042737, 0.04960398762882756, 0.16850674065572013, 0.6202540021741917], [0.7515673992699056, 0.6867547828670959, 0.038529441293790434, 0.9995963277046196, 0.15577904716257307, 0.2596640500026437, 0.76139213514593, 0.5065163836406463]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_5", - "sat": "def sat(strategies: List[List[float]], A=[[0.5814726045900506, 0.5956256240391693, 0.9131052903243185, 0.11287281160683993, 0.8212831173291085], [0.3793947608343723, 0.45275742082717085, 0.7407921334034075, 0.3864570423145923, 0.9370653086702027], [0.9160405228310879, 0.7511352063662349, 0.11550803796534004, 0.8302201055138154, 0.37417912056353275], [0.27039011886490116, 0.5969892185811785, 0.43324261935308306, 0.45567569201607305, 0.02400752372038628], [0.21041432700124219, 0.10743981295595395, 0.4021055269398165, 0.7261573413735346, 0.0957915298614408], [0.7447931227966944, 0.17320742569914804, 0.37237160787529366, 0.22749360932525553, 0.9101117804089166], [0.9546831195902783, 0.9978608587266401, 0.01697185583697791, 0.09005553976665348, 0.9387074705810284]], B=[[0.12589378221914926, 0.40795082073633004, 0.08132672688364984, 0.4979321986925006, 0.5609609624305184], [0.8175383659935327, 0.5300772051369375, 0.848912744356485, 0.7154791168043296, 0.9895776373063956], [0.41990393041395635, 0.0013608140861244289, 0.2815047938794766, 0.16105844955634552, 0.8824659755620429], [0.27077366812852766, 0.762430524799613, 0.7320934409657355, 0.06959471659212835, 0.053791319320243836], [0.3740768645228755, 0.3380216532762028, 0.20971994250824022, 0.09779092069862028, 0.29896008164483945], [0.7430871792613583, 0.9887999066102043, 0.04022774116177219, 0.9777443357134955, 0.6120194450553303], [0.7767936235763484, 0.35895050943173945, 0.6950274781514277, 0.10464463080332709, 0.9255235863724958]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_6", - "sat": "def sat(strategies: List[List[float]], A=[[0.753305183784452, 0.00021493214186718568, 0.8174646111076165, 0.2407255200398024, 0.1795814384955745, 0.08876568106117855, 0.4880983704462357, 0.09098388842018601, 0.6453241070493039], [0.5297334039709646, 0.2806958522308418, 0.0005903610098896284, 0.38852379069610643, 0.33474414876127456, 0.6622877161203526, 0.7209078089467034, 0.18478788570109816, 0.5644413142021318], [0.44604180692715445, 0.06019075020211484, 0.6774602077367329, 0.8598735073120923, 0.2633378670984865, 0.29206998906490644, 0.9332786731794765, 0.4760354265590311, 0.4457633756459827], [0.9325554940781343, 0.3236751349693534, 0.6611731100331621, 0.6242000349323874, 0.5874917213550676, 0.35961716225787466, 0.10212965259196705, 0.8214691031355454, 0.0632394823107364], [0.01623252423534205, 0.6215843984799041, 0.8312686980642228, 0.08662401823946564, 0.8620707246910273, 0.4477824063172565, 0.23812810100907567, 0.4672570106974444, 0.38214866929136604], [0.770410882982723, 0.664909759130508, 0.6709981786388367, 0.43500706746360696, 0.7828753577872432, 0.853305503068459, 0.2618568542194608, 0.8393119440341452, 0.6220495109710185], [0.4437405121128877, 0.08062775552593315, 0.2825300127370993, 0.8248570391874871, 0.10409178686182985, 0.6194212035689083, 0.2478787929552866, 0.8429485939490016, 0.6279189120934703], [0.405977732335145, 0.3047593456508607, 0.0011626743055760391, 0.24354141414057162, 0.4297136578803912, 0.7541260581053129, 0.1984931724365474, 0.06180222143204839, 0.6515743865496492], [0.020441606842849902, 0.28353015328509557, 0.6721313126673334, 0.932135081104012, 0.7975938948129068, 0.8566984213714758, 0.48276208315749736, 0.28187979216520775, 0.8646700222050563]], B=[[0.4667434762563013, 0.8828579807545561, 0.932673103691559, 0.17468167109277055, 0.17794943215792203, 0.36312025444562446, 0.35334739769318513, 0.1354540876658693, 0.32202521539243756], [0.8782105488754612, 0.9461287339187919, 0.27587149388394283, 0.11585559018024827, 0.6106571636850053, 0.6028924621081755, 0.2939925489412869, 0.42076014930567507, 0.6040119276778034], [0.4052273399013572, 0.3971114752935314, 0.5503655768383657, 0.43803811580318086, 0.19523695724756673, 0.6213017081296713, 0.5006649256239393, 0.7024242905687111, 0.012697482541764615], [0.18783520053749114, 0.7918370161649555, 0.25288620586756083, 0.2627962196239465, 0.3490592546214717, 0.5476028202362002, 0.4788004945388744, 0.9198108509539109, 0.583195351640764], [0.8968662656610187, 0.2225988182213413, 0.12679278019016038, 0.39133479560938333, 0.055254350543235464, 0.6937088973135248, 0.9826992825124735, 0.09633776560112417, 0.23598127507484157], [0.976600161085042, 0.16776588555220717, 0.8693968644515583, 0.7022810534576341, 0.8117852475522691, 0.4773848617558878, 0.892980138455822, 0.6693110989550494, 0.18760228226583875], [0.8242959518275365, 0.39580496981975355, 0.2525596025349518, 0.3690553679462767, 0.3627854068041879, 0.4107185237154821, 0.47077429999121123, 0.07227659873796244, 0.3866774952645814], [0.5654255816642142, 0.965813926840458, 0.7306735696312973, 0.5492268686026774, 0.11025418677938814, 0.9904006420435519, 0.40801176324094646, 0.7938852542327226, 0.7546755967922436], [0.9766683312067237, 0.6204400112310381, 0.9092808588005977, 0.702904402157147, 0.47962635670188203, 0.95920963537724, 0.47677437362840525, 0.8235720152869215, 0.8441643727726349]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_7", - "sat": "def sat(strategies: List[List[float]], A=[[0.5137252695510608, 0.6115571776653999, 0.9036119749130369, 0.4000115829503379, 0.26826932035226125, 0.3723598610176565, 0.5244977944491166, 0.1815535662844534, 0.6233056131299094], [0.11654162767534171, 0.0653655661719037, 0.8132357638458977, 0.44129019086850874, 0.969656451614091, 0.5617862965011289, 0.039295150165379655, 0.7645309456078511, 0.9178579356106069]], B=[[0.1386818801228349, 0.37023194265834247, 0.6547447526877681, 0.6583280505666821, 0.7088303774990212, 0.5488208139033705, 0.5585003967063151, 0.5151291393071482, 0.533084324113522], [0.3291140887660152, 0.5366733726820826, 0.43027011472528154, 0.8109432563615194, 0.6036396320394376, 0.6121659869602197, 0.07124532303074249, 0.49409974501472154, 0.18257701012621896]], eps=0.5): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.5137252695510608, 0.6115571776653999, 0.9036119749130369, 0.4000115829503379, 0.26826932035226125, 0.3723598610176565, 0.5244977944491166, 0.1815535662844534, 0.6233056131299094], [0.11654162767534171, 0.0653655661719037, 0.8132357638458977, 0.44129019086850874, 0.969656451614091, 0.5617862965011289, 0.039295150165379655, 0.7645309456078511, 0.9178579356106069]], B=[[0.1386818801228349, 0.37023194265834247, 0.6547447526877681, 0.6583280505666821, 0.7088303774990212, 0.5488208139033705, 0.5585003967063151, 0.5151291393071482, 0.533084324113522], [0.3291140887660152, 0.5366733726820826, 0.43027011472528154, 0.8109432563615194, 0.6036396320394376, 0.6121659869602197, 0.07124532303074249, 0.49409974501472154, 0.18257701012621896]], eps=0.5):\n NUM_ATTEMPTS = 100\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" - ], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_8", - "sat": "def sat(strategies: List[List[float]], A=[[0.32637957131438733, 0.6354291296026905, 0.8030884405572954, 0.15573400869108456, 0.009910899518800531], [0.11655112223772679, 0.9049518200114235, 0.03493953681413531, 0.2323649665048323, 0.10149902984419357], [0.02501288700255644, 0.8408583448368675, 0.05381871696043283, 0.16691342771910722, 0.04469980927199102], [0.2470008404164057, 0.35144970323072966, 0.5781202029219602, 0.5417221582567634, 0.6915315964876854], [0.5761118858007916, 0.610327980052143, 0.4500704245674991, 0.00237372714468298, 0.8543456083712235], [0.3528964212519685, 0.7319441233027391, 0.21232303227214566, 0.6178330032527302, 0.909451853791616], [0.46028529280704444, 0.14500789461024, 0.0246756377137759, 0.45500269499727986, 0.441524512369724]], B=[[0.2663059860553171, 0.0949913314096742, 0.08856504552855848, 0.596300548705807, 0.8835611239879463], [0.9105461841775674, 0.5716005298745939, 0.5409610436618006, 0.1955691493408337, 0.5617394022142342], [0.858879326896179, 0.7930093348954994, 0.7558746659209005, 0.23571594360071102, 0.1504522251844438], [0.7604916447808325, 0.8435296111877547, 0.36678965072939407, 0.9011196795750558, 0.3968761562829036], [0.13016322898978072, 0.08514625332541093, 0.4632665911013738, 0.9641185247480573, 0.9176654745738501], [0.4317502306713694, 0.01774794086998388, 0.646376988999183, 0.20457188659878978, 0.6667860396554535], [0.6898471935703793, 0.35067185460226535, 0.01624724109375819, 0.9876756950922273, 0.7645879117114146]], eps=0.01): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.32637957131438733, 0.6354291296026905, 0.8030884405572954, 0.15573400869108456, 0.009910899518800531], [0.11655112223772679, 0.9049518200114235, 0.03493953681413531, 0.2323649665048323, 0.10149902984419357], [0.02501288700255644, 0.8408583448368675, 0.05381871696043283, 0.16691342771910722, 0.04469980927199102], [0.2470008404164057, 0.35144970323072966, 0.5781202029219602, 0.5417221582567634, 0.6915315964876854], [0.5761118858007916, 0.610327980052143, 0.4500704245674991, 0.00237372714468298, 0.8543456083712235], [0.3528964212519685, 0.7319441233027391, 0.21232303227214566, 0.6178330032527302, 0.909451853791616], [0.46028529280704444, 0.14500789461024, 0.0246756377137759, 0.45500269499727986, 0.441524512369724]], B=[[0.2663059860553171, 0.0949913314096742, 0.08856504552855848, 0.596300548705807, 0.8835611239879463], [0.9105461841775674, 0.5716005298745939, 0.5409610436618006, 0.1955691493408337, 0.5617394022142342], [0.858879326896179, 0.7930093348954994, 0.7558746659209005, 0.23571594360071102, 0.1504522251844438], [0.7604916447808325, 0.8435296111877547, 0.36678965072939407, 0.9011196795750558, 0.3968761562829036], [0.13016322898978072, 0.08514625332541093, 0.4632665911013738, 0.9641185247480573, 0.9176654745738501], [0.4317502306713694, 0.01774794086998388, 0.646376988999183, 0.20457188659878978, 0.6667860396554535], [0.6898471935703793, 0.35067185460226535, 0.01624724109375819, 0.9876756950922273, 0.7645879117114146]], eps=0.01):\n NUM_ATTEMPTS = 100\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" - ], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Nash_9", - "sat": "def sat(strategies: List[List[float]], A=[[0.43218878920875836, 0.10463431092938436, 0.78227061691496, 0.1558587444185835, 0.6564016014963822, 0.7477801794470715], [0.37562017757711497, 0.6870878360392028, 0.5050794163044101, 0.2954595992340683, 0.3722390953795015, 0.4011348000597046], [0.029481316502110833, 0.2003676770126367, 0.8951417579527703, 0.8317661565382827, 0.8835785056507813, 0.9397215940200567], [0.06201629675424747, 0.8409427350327948, 0.8413112238757631, 0.9140258774775001, 0.1904831571905633, 0.5322320671729405], [0.12216623330370202, 0.5754126825208856, 0.5384080011653958, 0.6440815534740099, 0.4203428806243229, 0.2890242711604548], [0.8633644538723568, 0.42543299520747424, 0.256341253594925, 0.802033688793813, 0.5534160058175476, 0.10921928746224308], [0.4028573006664272, 0.6767920160646007, 0.8682142495014633, 0.26267429407938137, 0.5718802353897804, 0.7060207458388982], [0.13911387669675113, 0.7403551240901006, 0.7235875930018963, 0.8165829117375919, 0.6957658407829488, 0.4059240262802052], [0.8821345046551597, 0.8210037699034987, 0.2879863743867328, 0.9176809891443036, 0.7567665511541967, 0.20443376749606246]], B=[[0.5289821349323652, 0.06385993481747998, 0.9884065622446245, 0.31943830309348886, 0.2402290280972198, 0.02563531190528867], [0.19524967841210994, 0.7362477892653838, 0.2951500085849127, 0.6411151990087401, 0.5335950318303726, 0.5458479867201047], [0.06404227784033001, 0.4927275627580219, 0.48764997551743905, 0.6963996814562374, 0.4063769476209166, 0.13362344405192816], [0.29908014610768485, 0.47167010053391156, 0.453128423789825, 0.6881753133986542, 0.5370116418131157, 0.06338742882112469], [0.3311443672549609, 0.09239226083330665, 0.060004166703767514, 0.3487744051936674, 0.08841473749441009, 0.7014015792039342], [0.5387329063517947, 0.1669094829157488, 0.6442073212612376, 0.6819423138497293, 0.40309303175248523, 0.9544993255295066], [0.7969823811503776, 0.7408782983435112, 0.09889574812197233, 0.8214401620278946, 0.21460707368413534, 0.9797514349193799], [0.031278497001073546, 0.5654106809929841, 0.24289004028513972, 0.7533610962442678, 0.7255756771890282, 0.43667501507546014], [0.6017897324041475, 0.4547738465159963, 0.9113482452893733, 0.6680126867040715, 0.5995607910607395, 0.8615380988305832]], eps=0.5): # error tolerance\n \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.43218878920875836, 0.10463431092938436, 0.78227061691496, 0.1558587444185835, 0.6564016014963822, 0.7477801794470715], [0.37562017757711497, 0.6870878360392028, 0.5050794163044101, 0.2954595992340683, 0.3722390953795015, 0.4011348000597046], [0.029481316502110833, 0.2003676770126367, 0.8951417579527703, 0.8317661565382827, 0.8835785056507813, 0.9397215940200567], [0.06201629675424747, 0.8409427350327948, 0.8413112238757631, 0.9140258774775001, 0.1904831571905633, 0.5322320671729405], [0.12216623330370202, 0.5754126825208856, 0.5384080011653958, 0.6440815534740099, 0.4203428806243229, 0.2890242711604548], [0.8633644538723568, 0.42543299520747424, 0.256341253594925, 0.802033688793813, 0.5534160058175476, 0.10921928746224308], [0.4028573006664272, 0.6767920160646007, 0.8682142495014633, 0.26267429407938137, 0.5718802353897804, 0.7060207458388982], [0.13911387669675113, 0.7403551240901006, 0.7235875930018963, 0.8165829117375919, 0.6957658407829488, 0.4059240262802052], [0.8821345046551597, 0.8210037699034987, 0.2879863743867328, 0.9176809891443036, 0.7567665511541967, 0.20443376749606246]], B=[[0.5289821349323652, 0.06385993481747998, 0.9884065622446245, 0.31943830309348886, 0.2402290280972198, 0.02563531190528867], [0.19524967841210994, 0.7362477892653838, 0.2951500085849127, 0.6411151990087401, 0.5335950318303726, 0.5458479867201047], [0.06404227784033001, 0.4927275627580219, 0.48764997551743905, 0.6963996814562374, 0.4063769476209166, 0.13362344405192816], [0.29908014610768485, 0.47167010053391156, 0.453128423789825, 0.6881753133986542, 0.5370116418131157, 0.06338742882112469], [0.3311443672549609, 0.09239226083330665, 0.060004166703767514, 0.3487744051936674, 0.08841473749441009, 0.7014015792039342], [0.5387329063517947, 0.1669094829157488, 0.6442073212612376, 0.6819423138497293, 0.40309303175248523, 0.9544993255295066], [0.7969823811503776, 0.7408782983435112, 0.09889574812197233, 0.8214401620278946, 0.21460707368413534, 0.9797514349193799], [0.031278497001073546, 0.5654106809929841, 0.24289004028513972, 0.7533610962442678, 0.7255756771890282, 0.43667501507546014], [0.6017897324041475, 0.4547738465159963, 0.9113482452893733, 0.6680126867040715, 0.5995607910607395, 0.8615380988305832]], eps=0.5):\n NUM_ATTEMPTS = 100\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" - ], - "module": "game_theory", - "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_0", - "sat": "def sat(strategies: List[List[float]], A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_1", - "sat": "def sat(strategies: List[List[float]], A=[[0.5303369225581901, 0.4458248560112187, 0.47857713121903245], [0.07696760921779966, 0.40492093882513336, 0.8351857615090292]], eps=0.5):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.5303369225581901, 0.4458248560112187, 0.47857713121903245], [0.07696760921779966, 0.40492093882513336, 0.8351857615090292]], eps=0.5):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_2", - "sat": "def sat(strategies: List[List[float]], A=[[0.8737161029595927, 0.3380931327691771, 0.20525289813478453, 0.9772812942597162, 0.6011469499669913, 0.5657635078441663, 0.007362594660960342, 0.5523386597843655, 0.06548815570594102], [0.8440989957774637, 0.11456946368545384, 0.6266416865322296, 0.6112942108318355, 0.15090892170912606, 0.19181369635746925, 0.23558304486799253, 0.08883158381322309, 0.5626427070785186], [0.5990766112287766, 0.16770300013300976, 0.7790082288508813, 0.8213933806929374, 0.8409107317631046, 0.32215242243482034, 0.04927911582647726, 0.18589922022642869, 0.4416673076660764]], eps=0.1):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.8737161029595927, 0.3380931327691771, 0.20525289813478453, 0.9772812942597162, 0.6011469499669913, 0.5657635078441663, 0.007362594660960342, 0.5523386597843655, 0.06548815570594102], [0.8440989957774637, 0.11456946368545384, 0.6266416865322296, 0.6112942108318355, 0.15090892170912606, 0.19181369635746925, 0.23558304486799253, 0.08883158381322309, 0.5626427070785186], [0.5990766112287766, 0.16770300013300976, 0.7790082288508813, 0.8213933806929374, 0.8409107317631046, 0.32215242243482034, 0.04927911582647726, 0.18589922022642869, 0.4416673076660764]], eps=0.1):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_3", - "sat": "def sat(strategies: List[List[float]], A=[[0.35120738216503444, 0.6305426964442432, 0.09361690123750299, 0.17215263015782456, 0.3569473010721259], [0.9341169088059124, 0.43769720086284414, 0.35911118735479475, 0.37956863261812823, 0.9170151449695092]], eps=0.1):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.35120738216503444, 0.6305426964442432, 0.09361690123750299, 0.17215263015782456, 0.3569473010721259], [0.9341169088059124, 0.43769720086284414, 0.35911118735479475, 0.37956863261812823, 0.9170151449695092]], eps=0.1):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_4", - "sat": "def sat(strategies: List[List[float]], A=[[0.6637255179009651, 0.9756262037263238, 0.4926064602986052, 0.4097654368373934, 0.9284930704872523], [0.21641001481296873, 0.3381822244340763, 0.10113277325663139, 0.867285215856176, 0.27100572371021947], [0.7831143244052009, 0.6045743236145783, 0.10582868480749341, 0.5591604978434377, 0.27602687543748194], [0.8431935916393734, 0.09227518008541435, 0.06352450108543961, 0.13377427705288458, 0.8928593671227156], [0.15573895145866545, 0.3897235344943152, 0.5095156356106815, 0.25893802778092634, 0.4730747656010391]], eps=0.1):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.6637255179009651, 0.9756262037263238, 0.4926064602986052, 0.4097654368373934, 0.9284930704872523], [0.21641001481296873, 0.3381822244340763, 0.10113277325663139, 0.867285215856176, 0.27100572371021947], [0.7831143244052009, 0.6045743236145783, 0.10582868480749341, 0.5591604978434377, 0.27602687543748194], [0.8431935916393734, 0.09227518008541435, 0.06352450108543961, 0.13377427705288458, 0.8928593671227156], [0.15573895145866545, 0.3897235344943152, 0.5095156356106815, 0.25893802778092634, 0.4730747656010391]], eps=0.1):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_5", - "sat": "def sat(strategies: List[List[float]], A=[[0.5427170435019993, 0.8314387839901554, 0.40265673273776437], [0.8879202542582866, 0.9167404477056673, 0.6264251270454744], [0.9565483780322627, 0.9927960278935438, 0.7725293776030325], [0.9508769988672289, 0.6588794531264988, 0.5308476467902518], [0.48798202071070185, 0.41670404524107596, 0.017619877250776073], [0.3023387135778959, 0.3414973944050095, 0.6837221105285238]], eps=0.5):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.5427170435019993, 0.8314387839901554, 0.40265673273776437], [0.8879202542582866, 0.9167404477056673, 0.6264251270454744], [0.9565483780322627, 0.9927960278935438, 0.7725293776030325], [0.9508769988672289, 0.6588794531264988, 0.5308476467902518], [0.48798202071070185, 0.41670404524107596, 0.017619877250776073], [0.3023387135778959, 0.3414973944050095, 0.6837221105285238]], eps=0.5):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_6", - "sat": "def sat(strategies: List[List[float]], A=[[0.6972221817943854, 0.9955028071960343, 0.03463887607986338, 0.638657923012996, 0.8537012825970901], [0.16559730897385594, 0.8394646305946671, 0.769697042626638, 0.6867647405809145, 0.3945056609649893], [0.5619928261209739, 0.24336330577953846, 0.07584130014440837, 0.6385191455869482, 0.0007916075338669781], [0.16569887288415097, 0.49008648775079067, 0.761578050649744, 0.5176275439913738, 0.18150271687483688], [0.043155723587307904, 0.15453917685064722, 0.30538290181479955, 0.46332924213029014, 0.2600926879113151], [0.8268020460676769, 0.45309157564522917, 0.3336754086871935, 0.8408515675083248, 0.23026311105317387], [0.23610302502618818, 0.7284673848642883, 0.5960249213974684, 0.8148021440627474, 0.10158962537712557]], eps=0.01):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.6972221817943854, 0.9955028071960343, 0.03463887607986338, 0.638657923012996, 0.8537012825970901], [0.16559730897385594, 0.8394646305946671, 0.769697042626638, 0.6867647405809145, 0.3945056609649893], [0.5619928261209739, 0.24336330577953846, 0.07584130014440837, 0.6385191455869482, 0.0007916075338669781], [0.16569887288415097, 0.49008648775079067, 0.761578050649744, 0.5176275439913738, 0.18150271687483688], [0.043155723587307904, 0.15453917685064722, 0.30538290181479955, 0.46332924213029014, 0.2600926879113151], [0.8268020460676769, 0.45309157564522917, 0.3336754086871935, 0.8408515675083248, 0.23026311105317387], [0.23610302502618818, 0.7284673848642883, 0.5960249213974684, 0.8148021440627474, 0.10158962537712557]], eps=0.01):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_7", - "sat": "def sat(strategies: List[List[float]], A=[[0.863962708361941, 0.7267648611659883, 0.25333940861520887, 0.3578877074038227, 0.7624222188481827, 0.25727277324847797], [0.008704912029144696, 0.831746935419515, 0.24183035927564067, 0.11243165687766432, 0.3331518522717235, 0.5423338539568184]], eps=0.1):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.863962708361941, 0.7267648611659883, 0.25333940861520887, 0.3578877074038227, 0.7624222188481827, 0.25727277324847797], [0.008704912029144696, 0.831746935419515, 0.24183035927564067, 0.11243165687766432, 0.3331518522717235, 0.5423338539568184]], eps=0.1):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_8", - "sat": "def sat(strategies: List[List[float]], A=[[0.7341661289830135, 0.14904516362745412, 0.12233727280546125, 0.18914930565254684, 0.8167614139739929], [0.9936175164088098, 0.6990640104344674, 0.932021987248477, 0.12887770796685383, 0.29561803987966284], [0.29239455940666237, 0.5544417423009688, 0.2614377407533791, 0.05917034729370352, 0.24119420203251596], [0.5176395633710928, 0.26737409633987963, 0.5314243854814823, 0.8931458084867675, 0.49502080159123585], [0.39274090195455913, 0.2458125384374379, 0.08999209122107266, 0.8493123966405037, 0.5564380133581945], [0.8272998974698198, 0.17122551653768692, 0.10755028266099409, 0.08889544880629319, 0.779478196590326], [0.034173450711001974, 0.8835026280433949, 0.4784767191357908, 0.47702037976755807, 0.6415599896168853], [0.12826323397316342, 0.6866359762459922, 0.8784740812028159, 0.8501760201164382, 0.5174720503330829]], eps=0.1):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.7341661289830135, 0.14904516362745412, 0.12233727280546125, 0.18914930565254684, 0.8167614139739929], [0.9936175164088098, 0.6990640104344674, 0.932021987248477, 0.12887770796685383, 0.29561803987966284], [0.29239455940666237, 0.5544417423009688, 0.2614377407533791, 0.05917034729370352, 0.24119420203251596], [0.5176395633710928, 0.26737409633987963, 0.5314243854814823, 0.8931458084867675, 0.49502080159123585], [0.39274090195455913, 0.2458125384374379, 0.08999209122107266, 0.8493123966405037, 0.5564380133581945], [0.8272998974698198, 0.17122551653768692, 0.10755028266099409, 0.08889544880629319, 0.779478196590326], [0.034173450711001974, 0.8835026280433949, 0.4784767191357908, 0.47702037976755807, 0.6415599896168853], [0.12826323397316342, 0.6866359762459922, 0.8784740812028159, 0.8501760201164382, 0.5174720503330829]], eps=0.1):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "ZeroSum_9", - "sat": "def sat(strategies: List[List[float]], A=[[0.6554663257783704, 0.15029504459122212, 0.5559299563430086, 0.20589476603778367, 0.7643064152711786, 0.6061820149665644, 0.8807920264568392], [0.7052229233506515, 0.5603338206982549, 0.8274118128945858, 0.8071001911431841, 0.06186832278763432, 0.980364619124097, 0.6896361000010167], [0.018209866058666258, 0.8564736786315749, 0.7957292442666065, 0.9519170033377001, 0.07263645857173984, 0.7331321653724924, 0.5196558167705689], [0.10579739406903566, 0.934689927710577, 0.6922956278288943, 0.14492641276580875, 0.796810429850541, 0.5899737140304394, 0.2047655778435571], [0.39979079423605857, 0.9126901622329138, 0.35224147681493423, 0.823524289848973, 0.7819966476418646, 0.608636155106744, 0.07598349435456653], [0.4984477840166731, 0.9516414856389805, 0.22295289737196256, 0.04124192865530141, 0.30698520530579365, 0.6782972240748913, 0.9960645166028709]], eps=0.01):\n \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", - "sols": [ - "def sol(A=[[0.6554663257783704, 0.15029504459122212, 0.5559299563430086, 0.20589476603778367, 0.7643064152711786, 0.6061820149665644, 0.8807920264568392], [0.7052229233506515, 0.5603338206982549, 0.8274118128945858, 0.8071001911431841, 0.06186832278763432, 0.980364619124097, 0.6896361000010167], [0.018209866058666258, 0.8564736786315749, 0.7957292442666065, 0.9519170033377001, 0.07263645857173984, 0.7331321653724924, 0.5196558167705689], [0.10579739406903566, 0.934689927710577, 0.6922956278288943, 0.14492641276580875, 0.796810429850541, 0.5899737140304394, 0.2047655778435571], [0.39979079423605857, 0.9126901622329138, 0.35224147681493423, 0.823524289848973, 0.7819966476418646, 0.608636155106744, 0.07598349435456653], [0.4984477840166731, 0.9516414856389805, 0.22295289737196256, 0.04124192865530141, 0.30698520530579365, 0.6782972240748913, 0.9960645166028709]], eps=0.01):\n MAX_ITER = 10**4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" - ], - "module": "game_theory", - "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", - "taint_date": "2021-4-26", - "weight": 0.05 - }, - { - "name": "Conway99_0", - "sat": "def sat(edges: List[List[int]]):\n \"\"\"\n Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common\n neighbor, and in which each two non-adjacent vertices have exactly two common neighbors.\n \"\"\"\n # first compute neighbors sets, N:\n N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)}\n return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i))", - "sols": [], - "module": "graphs", - "notes": "Conway's 99-graph problem (*unsolved*, open problem)\n\nConway's 99-graph problem is an unsolved problem in graph theory.\nIn Conway's terminology, from [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf)\n\"Is there a graph with 99 vertices in which every edge (i.e. pair of joined vertices) belongs to a unique\ntriangle and every nonedge (pair of unjoined vertices) to a unique quadrilateral?\"\n\nSee also this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem).", - "taint_date": "2021-4-26", - "weight": 0.08333333333333333 - }, - { - "name": "AnyEdge_0", - "sat": "def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_1", - "sat": "def sat(e: List[int], edges=[[0, 1], [1, 1], [0, 0]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[0, 1], [1, 1], [0, 0]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_2", - "sat": "def sat(e: List[int], edges=[[1, 0], [0, 1], [1, 1]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[1, 0], [0, 1], [1, 1]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_3", - "sat": "def sat(e: List[int], edges=[[1, 15], [15, 3], [5, 12], [11, 0], [8, 5], [1, 9], [3, 6], [5, 10], [12, 0], [6, 6], [9, 2], [13, 15], [2, 9], [5, 1], [10, 11], [4, 12], [0, 6], [8, 12], [15, 14], [1, 13], [11, 7], [15, 4], [13, 5], [7, 14], [14, 5], [12, 2], [7, 8], [2, 14], [3, 15], [2, 2], [7, 2], [3, 4], [4, 2], [1, 3], [4, 4], [3, 11], [14, 6], [14, 8], [14, 12], [7, 15], [7, 3], [7, 10], [10, 8], [7, 13], [2, 15], [14, 0], [1, 5], [11, 15], [1, 8], [6, 4], [15, 8], [9, 3], [1, 10], [2, 3], [4, 13], [7, 5], [2, 11], [0, 1], [15, 6], [0, 2], [5, 5]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[1, 15], [15, 3], [5, 12], [11, 0], [8, 5], [1, 9], [3, 6], [5, 10], [12, 0], [6, 6], [9, 2], [13, 15], [2, 9], [5, 1], [10, 11], [4, 12], [0, 6], [8, 12], [15, 14], [1, 13], [11, 7], [15, 4], [13, 5], [7, 14], [14, 5], [12, 2], [7, 8], [2, 14], [3, 15], [2, 2], [7, 2], [3, 4], [4, 2], [1, 3], [4, 4], [3, 11], [14, 6], [14, 8], [14, 12], [7, 15], [7, 3], [7, 10], [10, 8], [7, 13], [2, 15], [14, 0], [1, 5], [11, 15], [1, 8], [6, 4], [15, 8], [9, 3], [1, 10], [2, 3], [4, 13], [7, 5], [2, 11], [0, 1], [15, 6], [0, 2], [5, 5]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_4", - "sat": "def sat(e: List[int], edges=[[7, 84], [72, 0], [65, 93], [66, 13], [39, 15], [91, 6], [16, 77], [43, 71], [34, 72], [83, 1], [91, 93], [41, 20], [71, 69], [51, 60], [75, 22], [25, 82], [93, 45], [54, 31], [38, 22], [76, 33], [18, 81], [91, 74], [28, 97], [39, 69], [15, 26], [83, 75], [57, 24], [94, 38], [26, 23], [40, 48], [37, 20], [90, 84], [75, 8], [36, 21], [93, 11], [97, 74], [79, 74], [69, 36], [3, 29], [66, 82], [49, 15], [52, 43], [76, 25], [39, 11], [9, 93], [68, 55], [53, 46], [29, 90], [12, 81], [44, 66], [54, 55], [2, 30], [1, 6], [8, 61], [67, 10], [61, 84], [72, 51], [13, 27], [93, 53], [44, 38], [86, 14], [90, 8], [22, 62], [5, 72], [63, 36], [31, 51], [83, 5], [36, 53], [92, 78], [44, 80], [23, 16], [43, 16], [18, 37], [34, 14], [23, 6], [19, 61], [59, 10], [85, 30], [25, 80], [76, 39], [21, 28], [60, 47], [15, 43], [26, 80], [59, 19], [83, 81], [4, 64], [3, 71], [52, 34], [90, 14], [44, 84], [37, 56], [76, 10], [69, 89], [30, 38], [17, 38], [42, 7], [79, 62], [15, 87], [45, 4], [96, 0], [44, 43], [84, 42], [26, 22], [1, 91], [1, 11], [68, 7], [72, 32], [8, 0], [64, 59], [16, 86], [25, 46], [65, 30], [10, 43], [89, 43], [55, 0], [91, 66], [49, 0], [22, 77], [80, 21], [16, 58], [55, 45], [64, 13], [55, 56], [89, 96], [84, 20], [11, 74], [92, 91], [36, 15], [51, 8], [4, 44], [55, 55], [6, 83], [76, 5], [3, 11], [15, 96], [18, 15], [43, 58], [19, 70], [87, 41], [43, 47], [2, 51], [47, 32], [14, 93], [27, 61], [21, 26], [78, 88], [52, 40], [21, 79], [12, 8], [74, 73], [5, 22], [50, 4], [15, 67], [87, 10], [90, 24], [17, 45], [75, 96], [27, 81], [76, 29], [52, 93], [74, 40], [48, 62], [5, 75], [68, 58], [61, 19], [56, 54], [4, 29], [26, 60], [24, 1], [37, 41], [95, 63], [49, 37], [81, 18], [79, 91], [82, 8], [29, 73], [55, 84], [18, 13], [32, 7], [77, 63], [26, 72], [90, 5], [95, 4], [46, 13], [0, 64], [84, 34], [52, 51], [32, 30], [24, 55], [51, 17], [12, 7], [73, 34], [54, 47], [96, 95], [65, 67], [46, 90], [58, 17], [54, 2], [45, 10], [84, 45], [46, 6], [0, 4], [16, 60], [50, 35], [86, 45], [89, 19], [48, 10], [4, 57], [43, 62], [19, 30], [2, 35], [83, 68], [36, 26], [69, 4], [41, 82], [12, 52], [77, 95], [90, 75], [78, 58], [93, 29], [38, 87], [15, 82], [42, 86], [39, 90], [20, 53], [79, 25], [68, 81], [64, 82], [45, 56], [14, 85], [97, 13], [46, 15], [46, 43], [8, 71], [90, 72], [97, 66], [80, 57], [25, 8], [90, 74]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[7, 84], [72, 0], [65, 93], [66, 13], [39, 15], [91, 6], [16, 77], [43, 71], [34, 72], [83, 1], [91, 93], [41, 20], [71, 69], [51, 60], [75, 22], [25, 82], [93, 45], [54, 31], [38, 22], [76, 33], [18, 81], [91, 74], [28, 97], [39, 69], [15, 26], [83, 75], [57, 24], [94, 38], [26, 23], [40, 48], [37, 20], [90, 84], [75, 8], [36, 21], [93, 11], [97, 74], [79, 74], [69, 36], [3, 29], [66, 82], [49, 15], [52, 43], [76, 25], [39, 11], [9, 93], [68, 55], [53, 46], [29, 90], [12, 81], [44, 66], [54, 55], [2, 30], [1, 6], [8, 61], [67, 10], [61, 84], [72, 51], [13, 27], [93, 53], [44, 38], [86, 14], [90, 8], [22, 62], [5, 72], [63, 36], [31, 51], [83, 5], [36, 53], [92, 78], [44, 80], [23, 16], [43, 16], [18, 37], [34, 14], [23, 6], [19, 61], [59, 10], [85, 30], [25, 80], [76, 39], [21, 28], [60, 47], [15, 43], [26, 80], [59, 19], [83, 81], [4, 64], [3, 71], [52, 34], [90, 14], [44, 84], [37, 56], [76, 10], [69, 89], [30, 38], [17, 38], [42, 7], [79, 62], [15, 87], [45, 4], [96, 0], [44, 43], [84, 42], [26, 22], [1, 91], [1, 11], [68, 7], [72, 32], [8, 0], [64, 59], [16, 86], [25, 46], [65, 30], [10, 43], [89, 43], [55, 0], [91, 66], [49, 0], [22, 77], [80, 21], [16, 58], [55, 45], [64, 13], [55, 56], [89, 96], [84, 20], [11, 74], [92, 91], [36, 15], [51, 8], [4, 44], [55, 55], [6, 83], [76, 5], [3, 11], [15, 96], [18, 15], [43, 58], [19, 70], [87, 41], [43, 47], [2, 51], [47, 32], [14, 93], [27, 61], [21, 26], [78, 88], [52, 40], [21, 79], [12, 8], [74, 73], [5, 22], [50, 4], [15, 67], [87, 10], [90, 24], [17, 45], [75, 96], [27, 81], [76, 29], [52, 93], [74, 40], [48, 62], [5, 75], [68, 58], [61, 19], [56, 54], [4, 29], [26, 60], [24, 1], [37, 41], [95, 63], [49, 37], [81, 18], [79, 91], [82, 8], [29, 73], [55, 84], [18, 13], [32, 7], [77, 63], [26, 72], [90, 5], [95, 4], [46, 13], [0, 64], [84, 34], [52, 51], [32, 30], [24, 55], [51, 17], [12, 7], [73, 34], [54, 47], [96, 95], [65, 67], [46, 90], [58, 17], [54, 2], [45, 10], [84, 45], [46, 6], [0, 4], [16, 60], [50, 35], [86, 45], [89, 19], [48, 10], [4, 57], [43, 62], [19, 30], [2, 35], [83, 68], [36, 26], [69, 4], [41, 82], [12, 52], [77, 95], [90, 75], [78, 58], [93, 29], [38, 87], [15, 82], [42, 86], [39, 90], [20, 53], [79, 25], [68, 81], [64, 82], [45, 56], [14, 85], [97, 13], [46, 15], [46, 43], [8, 71], [90, 72], [97, 66], [80, 57], [25, 8], [90, 74]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_5", - "sat": "def sat(e: List[int], edges=[[7, 8], [5, 3], [4, 9], [3, 9], [8, 5], [6, 8], [0, 7], [5, 2], [4, 7], [7, 9], [8, 9], [1, 2], [1, 8], [9, 0], [6, 9], [8, 2], [1, 1], [6, 4], [6, 0], [5, 8], [0, 6], [5, 0], [2, 6], [1, 5], [2, 0], [2, 3], [6, 5], [1, 9], [6, 2], [5, 5], [8, 4], [2, 2], [8, 0], [8, 7], [1, 4], [3, 6], [2, 8], [3, 8], [9, 7], [8, 1], [7, 6], [3, 3], [4, 4], [2, 9], [9, 9], [7, 2], [9, 8], [8, 6]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[7, 8], [5, 3], [4, 9], [3, 9], [8, 5], [6, 8], [0, 7], [5, 2], [4, 7], [7, 9], [8, 9], [1, 2], [1, 8], [9, 0], [6, 9], [8, 2], [1, 1], [6, 4], [6, 0], [5, 8], [0, 6], [5, 0], [2, 6], [1, 5], [2, 0], [2, 3], [6, 5], [1, 9], [6, 2], [5, 5], [8, 4], [2, 2], [8, 0], [8, 7], [1, 4], [3, 6], [2, 8], [3, 8], [9, 7], [8, 1], [7, 6], [3, 3], [4, 4], [2, 9], [9, 9], [7, 2], [9, 8], [8, 6]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_6", - "sat": "def sat(e: List[int], edges=[[2, 0], [2, 3], [1, 1], [1, 0], [3, 0], [3, 3], [2, 1], [0, 0], [0, 3], [2, 2], [0, 2], [1, 3], [0, 1], [3, 2]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[2, 0], [2, 3], [1, 1], [1, 0], [3, 0], [3, 3], [2, 1], [0, 0], [0, 3], [2, 2], [0, 2], [1, 3], [0, 1], [3, 2]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_7", - "sat": "def sat(e: List[int], edges=[[3, 3], [13, 12], [5, 6], [6, 10], [6, 7], [12, 3], [1, 3], [2, 6], [4, 0], [8, 5], [10, 11], [0, 2], [2, 7], [9, 1], [7, 1], [14, 3], [14, 5], [11, 9], [1, 11], [14, 9], [5, 12], [1, 7], [8, 9], [7, 6], [7, 12], [4, 3], [7, 10], [1, 6], [14, 0], [7, 8], [3, 13], [0, 8], [14, 1], [8, 2]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[3, 3], [13, 12], [5, 6], [6, 10], [6, 7], [12, 3], [1, 3], [2, 6], [4, 0], [8, 5], [10, 11], [0, 2], [2, 7], [9, 1], [7, 1], [14, 3], [14, 5], [11, 9], [1, 11], [14, 9], [5, 12], [1, 7], [8, 9], [7, 6], [7, 12], [4, 3], [7, 10], [1, 6], [14, 0], [7, 8], [3, 13], [0, 8], [14, 1], [8, 2]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_8", - "sat": "def sat(e: List[int], edges=[[66, 14], [35, 71], [6, 72], [85, 21], [82, 19], [35, 24], [5, 38], [72, 35], [33, 75], [55, 36], [26, 28], [44, 77], [69, 49], [79, 38], [14, 83], [35, 42], [30, 2], [7, 25], [86, 54], [76, 81], [9, 68], [63, 8], [16, 8], [74, 69], [18, 1], [43, 37], [44, 49], [70, 43], [14, 52], [29, 49], [81, 24], [85, 83], [27, 78], [5, 35], [60, 47], [27, 32], [66, 24], [11, 81], [25, 61], [6, 67], [3, 14], [62, 76], [49, 6], [7, 41], [31, 64], [15, 54], [9, 64], [1, 34], [52, 40], [79, 43], [2, 85], [40, 18], [28, 11], [39, 4], [44, 84], [32, 55], [64, 35], [63, 29], [83, 85], [17, 34], [9, 26], [21, 67], [8, 24], [20, 40], [48, 47], [31, 12], [72, 56], [38, 6], [79, 26], [47, 83], [76, 13], [6, 14], [2, 48], [18, 75], [55, 53], [64, 21], [25, 23], [27, 59], [65, 82], [59, 38], [59, 56], [8, 54], [5, 59], [51, 49], [44, 37], [43, 49], [32, 27], [27, 39], [23, 17], [3, 24], [7, 86], [86, 85], [54, 70], [65, 40], [46, 46], [23, 67], [31, 15], [49, 49], [44, 39], [77, 3], [66, 50], [48, 13], [2, 83], [15, 27], [75, 23], [18, 63], [70, 53], [78, 30], [34, 21], [28, 50], [64, 72], [18, 53], [68, 71], [73, 58], [30, 74], [57, 58], [73, 60], [86, 51], [47, 56], [7, 20], [53, 8], [5, 71], [51, 46], [70, 46], [78, 17], [59, 63], [23, 78], [37, 9], [66, 68], [19, 2], [70, 59], [34, 54], [50, 69], [30, 79], [82, 39], [26, 27], [80, 67], [82, 30], [38, 46], [51, 10], [58, 19], [28, 36], [22, 50], [42, 66], [72, 19], [23, 60], [55, 32], [56, 25], [47, 7], [13, 40], [37, 13], [15, 29], [17, 40], [1, 26], [25, 20], [35, 32], [80, 13], [21, 25], [74, 6], [21, 35], [26, 68], [52, 53], [20, 65], [33, 22], [69, 12], [30, 23], [50, 75], [52, 80], [49, 47], [8, 37], [64, 16], [12, 38], [15, 55], [6, 54], [77, 74], [82, 27], [3, 58], [1, 1], [64, 31], [63, 0], [37, 26], [43, 48], [13, 6], [74, 1], [55, 20], [36, 44], [43, 65], [14, 71], [57, 14], [84, 27], [78, 29], [7, 54], [47, 75], [38, 12], [48, 29], [36, 58], [2, 4], [75, 63], [50, 40], [76, 62], [31, 29], [73, 42], [71, 58], [2, 72], [14, 86], [34, 20], [4, 14], [67, 44], [30, 13], [42, 53], [43, 11], [33, 81], [72, 18], [26, 80], [62, 70], [56, 68], [11, 47], [9, 53], [38, 20], [19, 45], [76, 83], [82, 25], [23, 74], [40, 57], [15, 0], [51, 37], [68, 34], [63, 76], [52, 63], [7, 24], [8, 52], [67, 41], [42, 47], [50, 67], [45, 14], [12, 57], [37, 79], [9, 62], [31, 13], [5, 66], [26, 63], [19, 20], [16, 10], [76, 79], [71, 21], [2, 5], [35, 51], [23, 0], [30, 51], [24, 53], [85, 14], [84, 25], [2, 66], [39, 33], [61, 82], [10, 20], [69, 7], [41, 27], [45, 70], [45, 4], [7, 46], [56, 70], [60, 24], [58, 20], [74, 48], [5, 85], [68, 10], [65, 8], [37, 47], [40, 14], [32, 9], [9, 66], [35, 35], [49, 20], [23, 15], [54, 53], [76, 23], [13, 27], [7, 72], [53, 39], [19, 13], [25, 0], [63, 64], [59, 9], [20, 47], [8, 36], [53, 67], [82, 6], [53, 36], [49, 51], [26, 56], [47, 60], [28, 55], [42, 30], [58, 6], [54, 67], [74, 33], [80, 63], [84, 6], [74, 52], [79, 36], [49, 23], [30, 27], [23, 46], [37, 45], [64, 34], [85, 49], [29, 43], [12, 26], [68, 7], [5, 70], [83, 82], [82, 0], [16, 74], [83, 17], [13, 15], [9, 23], [60, 51], [37, 66], [50, 52], [0, 20], [49, 81], [78, 57], [11, 40], [12, 54], [17, 70], [17, 17], [76, 39], [5, 32], [80, 75], [41, 11], [23, 85], [46, 81], [71, 49], [22, 73], [62, 17], [28, 49], [77, 38], [74, 83], [48, 16], [19, 43], [52, 59], [39, 15], [30, 69], [77, 30], [1, 44], [69, 41], [3, 10], [38, 82], [47, 65], [42, 71], [42, 65], [21, 83], [20, 24], [15, 25], [20, 33], [47, 2], [9, 11], [50, 55], [41, 2], [1, 41], [75, 5], [66, 9], [81, 77], [56, 19], [70, 34], [78, 12], [29, 78], [42, 29], [56, 39], [43, 2], [1, 67], [2, 2], [20, 70], [42, 22], [39, 11], [30, 61], [22, 58], [4, 83], [32, 23], [27, 34], [82, 49], [23, 42], [69, 3], [61, 16], [17, 15], [51, 17], [78, 76], [85, 82], [7, 18], [85, 16], [21, 24], [84, 76], [24, 41], [69, 26], [29, 5], [73, 67], [0, 25], [86, 81], [58, 62], [58, 17], [53, 25], [64, 80], [78, 3], [60, 1], [58, 79], [35, 81], [33, 84], [31, 45], [69, 63], [24, 38], [1, 10], [58, 2], [60, 78], [72, 63], [32, 31], [23, 31], [50, 72], [16, 16], [16, 18], [26, 78], [21, 79], [52, 1], [77, 22], [43, 14], [73, 69], [22, 63], [17, 55], [41, 54], [13, 29], [13, 18], [5, 5], [49, 4], [64, 50], [17, 67], [14, 42], [71, 50], [57, 31], [80, 10], [42, 19], [43, 81], [75, 80], [8, 0], [70, 1], [48, 46], [59, 15], [28, 41], [54, 56], [46, 0], [69, 70], [80, 20], [72, 25], [16, 28], [1, 24], [63, 33], [27, 73], [60, 16], [64, 86], [82, 12], [1, 64], [49, 48], [52, 4], [2, 26], [10, 12], [49, 62], [19, 61], [17, 43], [77, 13], [24, 79], [54, 42], [22, 45], [70, 31], [52, 17], [15, 32], [1, 62], [64, 76], [5, 6], [39, 60], [13, 67], [76, 8], [31, 75], [65, 60], [79, 33], [43, 60], [53, 37], [24, 64], [77, 62], [63, 48], [11, 29], [31, 31], [49, 61], [46, 21], [22, 16], [67, 22], [69, 42], [40, 69], [60, 66], [31, 37], [34, 6], [83, 3], [83, 12], [49, 40], [85, 24], [2, 17], [3, 25], [59, 81], [35, 72], [51, 74], [63, 77], [36, 54], [40, 79], [86, 61], [9, 6], [23, 41], [45, 12], [80, 43], [49, 31], [6, 68], [76, 27], [33, 0], [2, 38], [74, 50], [4, 8], [79, 79], [83, 18], [39, 77], [32, 34], [55, 17], [43, 32], [43, 55], [85, 67], [84, 5], [51, 66], [28, 47], [64, 60], [18, 86], [9, 72], [48, 5], [61, 62], [83, 70], [36, 8], [21, 54], [10, 14], [53, 13], [43, 6], [38, 36], [37, 20], [17, 22], [82, 86], [25, 83], [84, 70], [38, 33], [45, 19], [5, 78], [86, 33], [57, 54], [24, 62], [33, 42], [84, 4], [12, 67], [31, 57], [54, 74], [26, 85], [29, 8], [30, 19], [41, 81], [85, 34], [50, 60], [25, 22], [49, 45], [21, 36], [63, 37], [39, 0], [39, 61], [78, 6], [23, 37], [1, 37], [11, 48], [39, 54], [22, 80], [73, 13], [78, 55], [32, 81], [66, 75], [51, 51], [8, 20], [45, 59], [3, 54], [22, 15], [25, 29], [54, 2], [34, 51], [44, 9], [24, 43], [47, 43], [13, 86], [13, 57], [19, 74], [34, 48], [39, 66], [17, 25], [10, 16], [38, 8], [33, 78], [67, 28], [34, 3], [31, 19], [1, 49], [72, 2], [62, 29], [8, 71], [16, 52], [15, 9], [14, 4], [41, 46], [8, 4], [63, 34], [49, 15], [12, 61], [24, 25], [49, 82], [85, 6], [21, 68], [66, 77], [58, 22], [49, 84], [77, 27], [22, 9], [8, 39], [4, 30], [33, 8], [80, 61], [0, 27], [46, 47], [62, 0], [24, 0], [64, 2], [15, 8], [60, 6], [83, 24], [9, 82], [13, 10], [80, 3], [9, 4], [6, 75], [11, 5], [78, 16], [50, 77], [37, 31], [47, 85], [46, 1], [19, 32], [64, 82], [0, 8], [7, 36], [57, 39], [50, 34], [34, 74], [7, 9], [71, 62], [11, 67], [40, 17], [55, 34], [48, 77], [49, 46], [19, 38], [1, 4], [24, 73], [14, 84], [79, 74], [1, 18], [56, 55], [30, 25], [10, 57], [59, 43], [7, 58], [8, 28]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[66, 14], [35, 71], [6, 72], [85, 21], [82, 19], [35, 24], [5, 38], [72, 35], [33, 75], [55, 36], [26, 28], [44, 77], [69, 49], [79, 38], [14, 83], [35, 42], [30, 2], [7, 25], [86, 54], [76, 81], [9, 68], [63, 8], [16, 8], [74, 69], [18, 1], [43, 37], [44, 49], [70, 43], [14, 52], [29, 49], [81, 24], [85, 83], [27, 78], [5, 35], [60, 47], [27, 32], [66, 24], [11, 81], [25, 61], [6, 67], [3, 14], [62, 76], [49, 6], [7, 41], [31, 64], [15, 54], [9, 64], [1, 34], [52, 40], [79, 43], [2, 85], [40, 18], [28, 11], [39, 4], [44, 84], [32, 55], [64, 35], [63, 29], [83, 85], [17, 34], [9, 26], [21, 67], [8, 24], [20, 40], [48, 47], [31, 12], [72, 56], [38, 6], [79, 26], [47, 83], [76, 13], [6, 14], [2, 48], [18, 75], [55, 53], [64, 21], [25, 23], [27, 59], [65, 82], [59, 38], [59, 56], [8, 54], [5, 59], [51, 49], [44, 37], [43, 49], [32, 27], [27, 39], [23, 17], [3, 24], [7, 86], [86, 85], [54, 70], [65, 40], [46, 46], [23, 67], [31, 15], [49, 49], [44, 39], [77, 3], [66, 50], [48, 13], [2, 83], [15, 27], [75, 23], [18, 63], [70, 53], [78, 30], [34, 21], [28, 50], [64, 72], [18, 53], [68, 71], [73, 58], [30, 74], [57, 58], [73, 60], [86, 51], [47, 56], [7, 20], [53, 8], [5, 71], [51, 46], [70, 46], [78, 17], [59, 63], [23, 78], [37, 9], [66, 68], [19, 2], [70, 59], [34, 54], [50, 69], [30, 79], [82, 39], [26, 27], [80, 67], [82, 30], [38, 46], [51, 10], [58, 19], [28, 36], [22, 50], [42, 66], [72, 19], [23, 60], [55, 32], [56, 25], [47, 7], [13, 40], [37, 13], [15, 29], [17, 40], [1, 26], [25, 20], [35, 32], [80, 13], [21, 25], [74, 6], [21, 35], [26, 68], [52, 53], [20, 65], [33, 22], [69, 12], [30, 23], [50, 75], [52, 80], [49, 47], [8, 37], [64, 16], [12, 38], [15, 55], [6, 54], [77, 74], [82, 27], [3, 58], [1, 1], [64, 31], [63, 0], [37, 26], [43, 48], [13, 6], [74, 1], [55, 20], [36, 44], [43, 65], [14, 71], [57, 14], [84, 27], [78, 29], [7, 54], [47, 75], [38, 12], [48, 29], [36, 58], [2, 4], [75, 63], [50, 40], [76, 62], [31, 29], [73, 42], [71, 58], [2, 72], [14, 86], [34, 20], [4, 14], [67, 44], [30, 13], [42, 53], [43, 11], [33, 81], [72, 18], [26, 80], [62, 70], [56, 68], [11, 47], [9, 53], [38, 20], [19, 45], [76, 83], [82, 25], [23, 74], [40, 57], [15, 0], [51, 37], [68, 34], [63, 76], [52, 63], [7, 24], [8, 52], [67, 41], [42, 47], [50, 67], [45, 14], [12, 57], [37, 79], [9, 62], [31, 13], [5, 66], [26, 63], [19, 20], [16, 10], [76, 79], [71, 21], [2, 5], [35, 51], [23, 0], [30, 51], [24, 53], [85, 14], [84, 25], [2, 66], [39, 33], [61, 82], [10, 20], [69, 7], [41, 27], [45, 70], [45, 4], [7, 46], [56, 70], [60, 24], [58, 20], [74, 48], [5, 85], [68, 10], [65, 8], [37, 47], [40, 14], [32, 9], [9, 66], [35, 35], [49, 20], [23, 15], [54, 53], [76, 23], [13, 27], [7, 72], [53, 39], [19, 13], [25, 0], [63, 64], [59, 9], [20, 47], [8, 36], [53, 67], [82, 6], [53, 36], [49, 51], [26, 56], [47, 60], [28, 55], [42, 30], [58, 6], [54, 67], [74, 33], [80, 63], [84, 6], [74, 52], [79, 36], [49, 23], [30, 27], [23, 46], [37, 45], [64, 34], [85, 49], [29, 43], [12, 26], [68, 7], [5, 70], [83, 82], [82, 0], [16, 74], [83, 17], [13, 15], [9, 23], [60, 51], [37, 66], [50, 52], [0, 20], [49, 81], [78, 57], [11, 40], [12, 54], [17, 70], [17, 17], [76, 39], [5, 32], [80, 75], [41, 11], [23, 85], [46, 81], [71, 49], [22, 73], [62, 17], [28, 49], [77, 38], [74, 83], [48, 16], [19, 43], [52, 59], [39, 15], [30, 69], [77, 30], [1, 44], [69, 41], [3, 10], [38, 82], [47, 65], [42, 71], [42, 65], [21, 83], [20, 24], [15, 25], [20, 33], [47, 2], [9, 11], [50, 55], [41, 2], [1, 41], [75, 5], [66, 9], [81, 77], [56, 19], [70, 34], [78, 12], [29, 78], [42, 29], [56, 39], [43, 2], [1, 67], [2, 2], [20, 70], [42, 22], [39, 11], [30, 61], [22, 58], [4, 83], [32, 23], [27, 34], [82, 49], [23, 42], [69, 3], [61, 16], [17, 15], [51, 17], [78, 76], [85, 82], [7, 18], [85, 16], [21, 24], [84, 76], [24, 41], [69, 26], [29, 5], [73, 67], [0, 25], [86, 81], [58, 62], [58, 17], [53, 25], [64, 80], [78, 3], [60, 1], [58, 79], [35, 81], [33, 84], [31, 45], [69, 63], [24, 38], [1, 10], [58, 2], [60, 78], [72, 63], [32, 31], [23, 31], [50, 72], [16, 16], [16, 18], [26, 78], [21, 79], [52, 1], [77, 22], [43, 14], [73, 69], [22, 63], [17, 55], [41, 54], [13, 29], [13, 18], [5, 5], [49, 4], [64, 50], [17, 67], [14, 42], [71, 50], [57, 31], [80, 10], [42, 19], [43, 81], [75, 80], [8, 0], [70, 1], [48, 46], [59, 15], [28, 41], [54, 56], [46, 0], [69, 70], [80, 20], [72, 25], [16, 28], [1, 24], [63, 33], [27, 73], [60, 16], [64, 86], [82, 12], [1, 64], [49, 48], [52, 4], [2, 26], [10, 12], [49, 62], [19, 61], [17, 43], [77, 13], [24, 79], [54, 42], [22, 45], [70, 31], [52, 17], [15, 32], [1, 62], [64, 76], [5, 6], [39, 60], [13, 67], [76, 8], [31, 75], [65, 60], [79, 33], [43, 60], [53, 37], [24, 64], [77, 62], [63, 48], [11, 29], [31, 31], [49, 61], [46, 21], [22, 16], [67, 22], [69, 42], [40, 69], [60, 66], [31, 37], [34, 6], [83, 3], [83, 12], [49, 40], [85, 24], [2, 17], [3, 25], [59, 81], [35, 72], [51, 74], [63, 77], [36, 54], [40, 79], [86, 61], [9, 6], [23, 41], [45, 12], [80, 43], [49, 31], [6, 68], [76, 27], [33, 0], [2, 38], [74, 50], [4, 8], [79, 79], [83, 18], [39, 77], [32, 34], [55, 17], [43, 32], [43, 55], [85, 67], [84, 5], [51, 66], [28, 47], [64, 60], [18, 86], [9, 72], [48, 5], [61, 62], [83, 70], [36, 8], [21, 54], [10, 14], [53, 13], [43, 6], [38, 36], [37, 20], [17, 22], [82, 86], [25, 83], [84, 70], [38, 33], [45, 19], [5, 78], [86, 33], [57, 54], [24, 62], [33, 42], [84, 4], [12, 67], [31, 57], [54, 74], [26, 85], [29, 8], [30, 19], [41, 81], [85, 34], [50, 60], [25, 22], [49, 45], [21, 36], [63, 37], [39, 0], [39, 61], [78, 6], [23, 37], [1, 37], [11, 48], [39, 54], [22, 80], [73, 13], [78, 55], [32, 81], [66, 75], [51, 51], [8, 20], [45, 59], [3, 54], [22, 15], [25, 29], [54, 2], [34, 51], [44, 9], [24, 43], [47, 43], [13, 86], [13, 57], [19, 74], [34, 48], [39, 66], [17, 25], [10, 16], [38, 8], [33, 78], [67, 28], [34, 3], [31, 19], [1, 49], [72, 2], [62, 29], [8, 71], [16, 52], [15, 9], [14, 4], [41, 46], [8, 4], [63, 34], [49, 15], [12, 61], [24, 25], [49, 82], [85, 6], [21, 68], [66, 77], [58, 22], [49, 84], [77, 27], [22, 9], [8, 39], [4, 30], [33, 8], [80, 61], [0, 27], [46, 47], [62, 0], [24, 0], [64, 2], [15, 8], [60, 6], [83, 24], [9, 82], [13, 10], [80, 3], [9, 4], [6, 75], [11, 5], [78, 16], [50, 77], [37, 31], [47, 85], [46, 1], [19, 32], [64, 82], [0, 8], [7, 36], [57, 39], [50, 34], [34, 74], [7, 9], [71, 62], [11, 67], [40, 17], [55, 34], [48, 77], [49, 46], [19, 38], [1, 4], [24, 73], [14, 84], [79, 74], [1, 18], [56, 55], [30, 25], [10, 57], [59, 43], [7, 58], [8, 28]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyEdge_9", - "sat": "def sat(e: List[int], edges=[[3, 1], [4, 3], [2, 0], [4, 0], [1, 0], [0, 0], [1, 1], [1, 3], [4, 1], [0, 2], [0, 1], [3, 3], [2, 2], [3, 0], [0, 3], [4, 4], [2, 3], [3, 2], [2, 1], [1, 4]]):\n \"\"\"Find any edge in edges.\"\"\"\n return e in edges", - "sols": [ - "def sol(edges=[[3, 1], [4, 3], [2, 0], [4, 0], [1, 0], [0, 0], [1, 1], [1, 3], [4, 1], [0, 2], [0, 1], [3, 3], [2, 2], [3, 0], [0, 3], [4, 4], [2, 3], [3, 2], [2, 1], [1, 4]]):\n return edges[0]" - ], - "module": "graphs", - "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_0", - "sat": "def sat(tri: List[int], edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_1", - "sat": "def sat(tri: List[int], edges=[[19, 48], [14, 42], [19, 14], [56, 3], [37, 16], [46, 5], [14, 14], [62, 40], [12, 41], [37, 1], [46, 40], [4, 9], [70, 39], [75, 49], [61, 55], [65, 61], [5, 1], [67, 44], [46, 68], [49, 62], [41, 61], [39, 43], [44, 60], [71, 40], [8, 42], [54, 67], [33, 27], [25, 70], [50, 3], [53, 22], [61, 34], [5, 16], [39, 62], [30, 44], [10, 3], [21, 67], [41, 54], [10, 66], [34, 1], [45, 44], [38, 47], [25, 36], [2, 47], [46, 2], [38, 4], [50, 66], [45, 18], [45, 50], [63, 57], [19, 43], [39, 66], [29, 13], [39, 65], [63, 39], [7, 25], [34, 51], [65, 54], [13, 64], [9, 70], [28, 12], [41, 69], [67, 53], [33, 38], [59, 27], [18, 37], [11, 3], [13, 23], [33, 50], [44, 49], [9, 50], [23, 55], [59, 66], [4, 74], [50, 12], [14, 24], [0, 28], [75, 29], [62, 60], [68, 35], [69, 55], [3, 19], [72, 30], [25, 9], [12, 58], [3, 66], [43, 8], [12, 11], [15, 56], [30, 75], [35, 57], [19, 20], [71, 36], [34, 35], [30, 17], [7, 52], [49, 31], [39, 58], [48, 32], [4, 57], [75, 31], [42, 1], [0, 48], [22, 13], [18, 17], [71, 52], [41, 19], [48, 12], [9, 48], [63, 65], [68, 63], [46, 39], [24, 30], [46, 61], [55, 25], [75, 36], [49, 5], [44, 12], [29, 5], [64, 69], [15, 64], [8, 66], [49, 25], [24, 53], [7, 39], [41, 2], [29, 48], [51, 30], [41, 21], [46, 30], [63, 75], [19, 3], [58, 72], [62, 59], [68, 54], [9, 61], [70, 74], [56, 48], [74, 48], [2, 9], [51, 22], [69, 61], [0, 35], [28, 46], [7, 11], [56, 57], [14, 67], [15, 4], [53, 12], [64, 42], [20, 15], [52, 53], [44, 16], [8, 7], [21, 7], [42, 45], [4, 66], [39, 59], [20, 1], [60, 0], [52, 28], [75, 63], [59, 14], [40, 69], [74, 46], [60, 67], [6, 57], [38, 68], [24, 22], [59, 61], [53, 30], [10, 56], [49, 59], [12, 27], [75, 22], [24, 25], [37, 11], [56, 12], [62, 47], [22, 9], [34, 17], [57, 10], [52, 43], [17, 22], [14, 73], [54, 75], [28, 22], [18, 51], [38, 46], [6, 22], [75, 15], [10, 1], [37, 12], [67, 34], [28, 43], [5, 2], [60, 40], [9, 22], [3, 75], [50, 1], [19, 8], [17, 57], [43, 60], [45, 60], [57, 32], [52, 35], [18, 22], [11, 38], [16, 57], [31, 39], [13, 18], [61, 54], [25, 10], [23, 46], [47, 5], [42, 66], [73, 67], [44, 28], [65, 34], [35, 50], [67, 1], [12, 44], [17, 51], [70, 23], [44, 35], [0, 16], [65, 53], [10, 74], [5, 60], [45, 8], [13, 46], [57, 6], [72, 47], [1, 36], [60, 4], [11, 31], [46, 21], [60, 29], [58, 44], [53, 41], [33, 44], [47, 34], [58, 35], [74, 51], [71, 35], [58, 10], [47, 59], [32, 36], [16, 67], [62, 9], [14, 44], [12, 32], [6, 19], [35, 21], [49, 71], [7, 7], [25, 39], [25, 24], [45, 40], [44, 20], [9, 37], [58, 18], [59, 52], [12, 23], [26, 49], [62, 69], [8, 2], [66, 52], [25, 42], [34, 70], [64, 1], [29, 57], [8, 26], [25, 63], [75, 56], [51, 49], [70, 9], [63, 51], [6, 28], [1, 38], [47, 27], [74, 26], [27, 63], [20, 47], [25, 37], [31, 67], [59, 71], [56, 32], [28, 65], [37, 10], [30, 50], [42, 32], [56, 63], [32, 65], [48, 70], [37, 21], [10, 11], [5, 24], [51, 8], [46, 6], [75, 23], [42, 28], [60, 26], [37, 9], [0, 19], [11, 34], [66, 51], [49, 42], [16, 37], [52, 55], [20, 39], [46, 12], [1, 70], [45, 37], [18, 63], [63, 23], [54, 7], [18, 11], [51, 28], [21, 65], [28, 71], [46, 53], [14, 36], [35, 71], [30, 5], [50, 62], [32, 28], [64, 38], [66, 61], [0, 10]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[19, 48], [14, 42], [19, 14], [56, 3], [37, 16], [46, 5], [14, 14], [62, 40], [12, 41], [37, 1], [46, 40], [4, 9], [70, 39], [75, 49], [61, 55], [65, 61], [5, 1], [67, 44], [46, 68], [49, 62], [41, 61], [39, 43], [44, 60], [71, 40], [8, 42], [54, 67], [33, 27], [25, 70], [50, 3], [53, 22], [61, 34], [5, 16], [39, 62], [30, 44], [10, 3], [21, 67], [41, 54], [10, 66], [34, 1], [45, 44], [38, 47], [25, 36], [2, 47], [46, 2], [38, 4], [50, 66], [45, 18], [45, 50], [63, 57], [19, 43], [39, 66], [29, 13], [39, 65], [63, 39], [7, 25], [34, 51], [65, 54], [13, 64], [9, 70], [28, 12], [41, 69], [67, 53], [33, 38], [59, 27], [18, 37], [11, 3], [13, 23], [33, 50], [44, 49], [9, 50], [23, 55], [59, 66], [4, 74], [50, 12], [14, 24], [0, 28], [75, 29], [62, 60], [68, 35], [69, 55], [3, 19], [72, 30], [25, 9], [12, 58], [3, 66], [43, 8], [12, 11], [15, 56], [30, 75], [35, 57], [19, 20], [71, 36], [34, 35], [30, 17], [7, 52], [49, 31], [39, 58], [48, 32], [4, 57], [75, 31], [42, 1], [0, 48], [22, 13], [18, 17], [71, 52], [41, 19], [48, 12], [9, 48], [63, 65], [68, 63], [46, 39], [24, 30], [46, 61], [55, 25], [75, 36], [49, 5], [44, 12], [29, 5], [64, 69], [15, 64], [8, 66], [49, 25], [24, 53], [7, 39], [41, 2], [29, 48], [51, 30], [41, 21], [46, 30], [63, 75], [19, 3], [58, 72], [62, 59], [68, 54], [9, 61], [70, 74], [56, 48], [74, 48], [2, 9], [51, 22], [69, 61], [0, 35], [28, 46], [7, 11], [56, 57], [14, 67], [15, 4], [53, 12], [64, 42], [20, 15], [52, 53], [44, 16], [8, 7], [21, 7], [42, 45], [4, 66], [39, 59], [20, 1], [60, 0], [52, 28], [75, 63], [59, 14], [40, 69], [74, 46], [60, 67], [6, 57], [38, 68], [24, 22], [59, 61], [53, 30], [10, 56], [49, 59], [12, 27], [75, 22], [24, 25], [37, 11], [56, 12], [62, 47], [22, 9], [34, 17], [57, 10], [52, 43], [17, 22], [14, 73], [54, 75], [28, 22], [18, 51], [38, 46], [6, 22], [75, 15], [10, 1], [37, 12], [67, 34], [28, 43], [5, 2], [60, 40], [9, 22], [3, 75], [50, 1], [19, 8], [17, 57], [43, 60], [45, 60], [57, 32], [52, 35], [18, 22], [11, 38], [16, 57], [31, 39], [13, 18], [61, 54], [25, 10], [23, 46], [47, 5], [42, 66], [73, 67], [44, 28], [65, 34], [35, 50], [67, 1], [12, 44], [17, 51], [70, 23], [44, 35], [0, 16], [65, 53], [10, 74], [5, 60], [45, 8], [13, 46], [57, 6], [72, 47], [1, 36], [60, 4], [11, 31], [46, 21], [60, 29], [58, 44], [53, 41], [33, 44], [47, 34], [58, 35], [74, 51], [71, 35], [58, 10], [47, 59], [32, 36], [16, 67], [62, 9], [14, 44], [12, 32], [6, 19], [35, 21], [49, 71], [7, 7], [25, 39], [25, 24], [45, 40], [44, 20], [9, 37], [58, 18], [59, 52], [12, 23], [26, 49], [62, 69], [8, 2], [66, 52], [25, 42], [34, 70], [64, 1], [29, 57], [8, 26], [25, 63], [75, 56], [51, 49], [70, 9], [63, 51], [6, 28], [1, 38], [47, 27], [74, 26], [27, 63], [20, 47], [25, 37], [31, 67], [59, 71], [56, 32], [28, 65], [37, 10], [30, 50], [42, 32], [56, 63], [32, 65], [48, 70], [37, 21], [10, 11], [5, 24], [51, 8], [46, 6], [75, 23], [42, 28], [60, 26], [37, 9], [0, 19], [11, 34], [66, 51], [49, 42], [16, 37], [52, 55], [20, 39], [46, 12], [1, 70], [45, 37], [18, 63], [63, 23], [54, 7], [18, 11], [51, 28], [21, 65], [28, 71], [46, 53], [14, 36], [35, 71], [30, 5], [50, 62], [32, 28], [64, 38], [66, 61], [0, 10]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_2", - "sat": "def sat(tri: List[int], edges=[[51, 44], [11, 59], [57, 15], [18, 1], [41, 1], [44, 6], [58, 44], [43, 10], [41, 9], [50, 43], [56, 0], [47, 4], [42, 45], [51, 15], [60, 18], [11, 56], [21, 45], [39, 42], [57, 34], [60, 25], [57, 33], [6, 17], [26, 43], [38, 25], [29, 18], [39, 43], [34, 4], [22, 61], [0, 9], [1, 20], [36, 28], [10, 37], [53, 7], [49, 60], [12, 48], [31, 33], [4, 8], [5, 56], [27, 59], [56, 29], [60, 17], [17, 27], [24, 58], [46, 47], [60, 35], [4, 37], [41, 43], [37, 33], [30, 7], [53, 31], [3, 60], [24, 39], [14, 41], [14, 54], [33, 35], [50, 1], [60, 57], [23, 17], [34, 15], [60, 26], [22, 0], [5, 4], [8, 41], [16, 4], [56, 40], [60, 44], [2, 26], [42, 21], [21, 28], [58, 32], [58, 12], [31, 22], [43, 0], [28, 3], [35, 21], [54, 18], [0, 58], [3, 9], [6, 59], [57, 46], [48, 45], [30, 12], [46, 27], [41, 55], [52, 58], [30, 21], [51, 24], [23, 18], [31, 59], [34, 49], [41, 34], [19, 58], [1, 32], [52, 16], [17, 8], [20, 3], [56, 12], [3, 51], [60, 31], [41, 5], [58, 23], [59, 6], [39, 2], [6, 6], [11, 38], [3, 44], [61, 58], [13, 46], [56, 1], [35, 14], [25, 7], [29, 60], [16, 32], [32, 32], [7, 44], [3, 48], [38, 21], [19, 43], [60, 4], [56, 56], [21, 33], [15, 11], [32, 0], [8, 10], [44, 11], [37, 36], [24, 28], [4, 23], [37, 22], [44, 4], [34, 28], [1, 7], [15, 48], [11, 20], [60, 13], [7, 30], [51, 18], [3, 56], [14, 57], [14, 22], [55, 13], [47, 50], [36, 14], [42, 46], [7, 29], [58, 36], [52, 49], [33, 4], [51, 51], [47, 55], [7, 60], [4, 17], [53, 6], [59, 28], [51, 52], [50, 24], [30, 18], [37, 42], [51, 30], [6, 37], [0, 41], [38, 30], [0, 24], [43, 38], [33, 2], [10, 21], [44, 33], [57, 29], [28, 45], [2, 27], [59, 38], [41, 28], [49, 61], [54, 23], [44, 32], [58, 33], [2, 43], [34, 39], [37, 28], [40, 56], [55, 59], [28, 43], [36, 36], [29, 41], [16, 35], [50, 33], [51, 4], [33, 11], [26, 17], [2, 49], [7, 18], [15, 60], [14, 47], [40, 16], [47, 19], [18, 43], [38, 53], [28, 10], [46, 12], [26, 48], [1, 45], [9, 45], [2, 12], [8, 55], [19, 24], [2, 10], [17, 38], [30, 48], [2, 13], [59, 22], [11, 39], [32, 47], [23, 26], [43, 25], [9, 34], [46, 30], [36, 32], [33, 36], [38, 54], [33, 14], [48, 46], [29, 53], [46, 60], [14, 10], [0, 3], [13, 39], [53, 53], [22, 16], [33, 31], [33, 13], [54, 51], [25, 34], [14, 33], [19, 56], [51, 10], [58, 43], [4, 20], [28, 54], [3, 34], [47, 45], [1, 58], [55, 43], [13, 21], [31, 46], [23, 57], [58, 15], [54, 36], [44, 7], [16, 52], [20, 40], [46, 18], [59, 19], [14, 44], [3, 4], [58, 52], [31, 42], [21, 17], [42, 18], [46, 57], [7, 35], [52, 4], [30, 11], [17, 14], [60, 10], [57, 59], [59, 46], [18, 15], [35, 27], [46, 31], [49, 18], [21, 23], [50, 25], [24, 59], [51, 26], [36, 34], [27, 17], [13, 16], [54, 56], [53, 13], [27, 25], [8, 33], [52, 7], [45, 61], [39, 0], [6, 51], [35, 23], [31, 5], [38, 33], [47, 58], [28, 61], [36, 0], [18, 30], [51, 11], [39, 51], [39, 36], [60, 37], [37, 43], [46, 42]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[51, 44], [11, 59], [57, 15], [18, 1], [41, 1], [44, 6], [58, 44], [43, 10], [41, 9], [50, 43], [56, 0], [47, 4], [42, 45], [51, 15], [60, 18], [11, 56], [21, 45], [39, 42], [57, 34], [60, 25], [57, 33], [6, 17], [26, 43], [38, 25], [29, 18], [39, 43], [34, 4], [22, 61], [0, 9], [1, 20], [36, 28], [10, 37], [53, 7], [49, 60], [12, 48], [31, 33], [4, 8], [5, 56], [27, 59], [56, 29], [60, 17], [17, 27], [24, 58], [46, 47], [60, 35], [4, 37], [41, 43], [37, 33], [30, 7], [53, 31], [3, 60], [24, 39], [14, 41], [14, 54], [33, 35], [50, 1], [60, 57], [23, 17], [34, 15], [60, 26], [22, 0], [5, 4], [8, 41], [16, 4], [56, 40], [60, 44], [2, 26], [42, 21], [21, 28], [58, 32], [58, 12], [31, 22], [43, 0], [28, 3], [35, 21], [54, 18], [0, 58], [3, 9], [6, 59], [57, 46], [48, 45], [30, 12], [46, 27], [41, 55], [52, 58], [30, 21], [51, 24], [23, 18], [31, 59], [34, 49], [41, 34], [19, 58], [1, 32], [52, 16], [17, 8], [20, 3], [56, 12], [3, 51], [60, 31], [41, 5], [58, 23], [59, 6], [39, 2], [6, 6], [11, 38], [3, 44], [61, 58], [13, 46], [56, 1], [35, 14], [25, 7], [29, 60], [16, 32], [32, 32], [7, 44], [3, 48], [38, 21], [19, 43], [60, 4], [56, 56], [21, 33], [15, 11], [32, 0], [8, 10], [44, 11], [37, 36], [24, 28], [4, 23], [37, 22], [44, 4], [34, 28], [1, 7], [15, 48], [11, 20], [60, 13], [7, 30], [51, 18], [3, 56], [14, 57], [14, 22], [55, 13], [47, 50], [36, 14], [42, 46], [7, 29], [58, 36], [52, 49], [33, 4], [51, 51], [47, 55], [7, 60], [4, 17], [53, 6], [59, 28], [51, 52], [50, 24], [30, 18], [37, 42], [51, 30], [6, 37], [0, 41], [38, 30], [0, 24], [43, 38], [33, 2], [10, 21], [44, 33], [57, 29], [28, 45], [2, 27], [59, 38], [41, 28], [49, 61], [54, 23], [44, 32], [58, 33], [2, 43], [34, 39], [37, 28], [40, 56], [55, 59], [28, 43], [36, 36], [29, 41], [16, 35], [50, 33], [51, 4], [33, 11], [26, 17], [2, 49], [7, 18], [15, 60], [14, 47], [40, 16], [47, 19], [18, 43], [38, 53], [28, 10], [46, 12], [26, 48], [1, 45], [9, 45], [2, 12], [8, 55], [19, 24], [2, 10], [17, 38], [30, 48], [2, 13], [59, 22], [11, 39], [32, 47], [23, 26], [43, 25], [9, 34], [46, 30], [36, 32], [33, 36], [38, 54], [33, 14], [48, 46], [29, 53], [46, 60], [14, 10], [0, 3], [13, 39], [53, 53], [22, 16], [33, 31], [33, 13], [54, 51], [25, 34], [14, 33], [19, 56], [51, 10], [58, 43], [4, 20], [28, 54], [3, 34], [47, 45], [1, 58], [55, 43], [13, 21], [31, 46], [23, 57], [58, 15], [54, 36], [44, 7], [16, 52], [20, 40], [46, 18], [59, 19], [14, 44], [3, 4], [58, 52], [31, 42], [21, 17], [42, 18], [46, 57], [7, 35], [52, 4], [30, 11], [17, 14], [60, 10], [57, 59], [59, 46], [18, 15], [35, 27], [46, 31], [49, 18], [21, 23], [50, 25], [24, 59], [51, 26], [36, 34], [27, 17], [13, 16], [54, 56], [53, 13], [27, 25], [8, 33], [52, 7], [45, 61], [39, 0], [6, 51], [35, 23], [31, 5], [38, 33], [47, 58], [28, 61], [36, 0], [18, 30], [51, 11], [39, 51], [39, 36], [60, 37], [37, 43], [46, 42]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_3", - "sat": "def sat(tri: List[int], edges=[[8, 0], [2, 7], [1, 2], [4, 5], [2, 1], [7, 1], [5, 6], [6, 3], [3, 8], [3, 4], [0, 1], [6, 6], [4, 0], [2, 8], [1, 5], [4, 2]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[8, 0], [2, 7], [1, 2], [4, 5], [2, 1], [7, 1], [5, 6], [6, 3], [3, 8], [3, 4], [0, 1], [6, 6], [4, 0], [2, 8], [1, 5], [4, 2]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_4", - "sat": "def sat(tri: List[int], edges=[[4, 4], [5, 5], [3, 5], [3, 1], [0, 1], [4, 0], [3, 2], [5, 3], [1, 3], [2, 5], [2, 0]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[4, 4], [5, 5], [3, 5], [3, 1], [0, 1], [4, 0], [3, 2], [5, 3], [1, 3], [2, 5], [2, 0]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_5", - "sat": "def sat(tri: List[int], edges=[[4, 6], [3, 4], [0, 2], [3, 5], [2, 2], [1, 6], [1, 0], [1, 4], [6, 4], [3, 2], [6, 0], [6, 2], [2, 4], [5, 5], [2, 0], [3, 0], [0, 5], [6, 1], [5, 1], [6, 3], [4, 5]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[4, 6], [3, 4], [0, 2], [3, 5], [2, 2], [1, 6], [1, 0], [1, 4], [6, 4], [3, 2], [6, 0], [6, 2], [2, 4], [5, 5], [2, 0], [3, 0], [0, 5], [6, 1], [5, 1], [6, 3], [4, 5]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_6", - "sat": "def sat(tri: List[int], edges=[[13, 41], [44, 76], [7, 77], [84, 52], [5, 16], [92, 90], [13, 73], [76, 72], [33, 33], [64, 42], [24, 34], [86, 76], [10, 51], [13, 50], [36, 80], [7, 54], [77, 43], [71, 44], [20, 52], [33, 32], [7, 50], [43, 92], [53, 68], [11, 65], [54, 10], [66, 89], [18, 0], [0, 1], [84, 77], [37, 82], [45, 34], [40, 24], [34, 37], [23, 59], [20, 20], [4, 8], [78, 20], [49, 73], [63, 79], [41, 33], [80, 42], [22, 56], [61, 29], [11, 36], [65, 14], [30, 43], [29, 3], [53, 71], [22, 70], [64, 47], [16, 35], [71, 75], [81, 39], [44, 90], [90, 36], [55, 83], [82, 18], [26, 3], [25, 54], [11, 14], [3, 90], [47, 49], [14, 66], [48, 36], [17, 75], [5, 49], [11, 4], [30, 11], [20, 6], [57, 1], [23, 8], [43, 58], [62, 16], [50, 93], [4, 79], [41, 57], [62, 87], [75, 52], [52, 49], [35, 10], [87, 10], [27, 49], [22, 41], [4, 60], [31, 32], [19, 87], [54, 70], [6, 13], [66, 47], [82, 6], [47, 16], [72, 35], [55, 14], [3, 16], [26, 33], [84, 1], [84, 11], [2, 58], [35, 33], [30, 25], [79, 23], [77, 83], [54, 52], [13, 84], [19, 49], [52, 91], [61, 76], [57, 17], [89, 17], [48, 78], [49, 18], [82, 43], [60, 15], [30, 63], [59, 69], [24, 56], [29, 28], [58, 37], [4, 77], [69, 87], [83, 78], [7, 91], [8, 42], [51, 30], [46, 72], [57, 92], [86, 45], [84, 28], [39, 89], [56, 72], [68, 12], [4, 19], [53, 39], [64, 48], [88, 1], [75, 56], [0, 3], [44, 81], [80, 22], [26, 32], [13, 61], [32, 53], [54, 45], [16, 7], [62, 18], [83, 12], [59, 10], [63, 51], [38, 13], [17, 22], [37, 38], [27, 50], [14, 57], [42, 43], [45, 75], [26, 22], [71, 47], [14, 32], [57, 52], [75, 73], [30, 90], [34, 39], [42, 70], [23, 50], [72, 79], [43, 41], [41, 66], [73, 53], [31, 15], [5, 48], [56, 69], [7, 9], [74, 14], [17, 9], [63, 33], [63, 6], [88, 52], [46, 93], [33, 77], [63, 91], [79, 55], [63, 83], [33, 66], [15, 9], [90, 33], [21, 46], [22, 88], [32, 51], [51, 13], [23, 32], [93, 70], [59, 67], [80, 23], [73, 36], [27, 75], [22, 20], [78, 14], [12, 30], [37, 35], [28, 80], [80, 43], [69, 30], [30, 67], [57, 26], [84, 33], [90, 76], [26, 35], [18, 90], [78, 10], [43, 43], [46, 2], [44, 28], [15, 92], [71, 33], [43, 79], [43, 52], [25, 6], [58, 92], [24, 33], [24, 11], [0, 87], [8, 2], [5, 0], [33, 50], [71, 5], [19, 38], [23, 79], [0, 60], [17, 76], [35, 88], [31, 16], [47, 18], [72, 76], [47, 58], [5, 26], [26, 61], [83, 25], [88, 70], [56, 20], [55, 10], [67, 54], [69, 36], [33, 68], [16, 91], [13, 2], [75, 66], [63, 16], [7, 45], [46, 25], [37, 25], [5, 2], [24, 67], [53, 72], [10, 37], [36, 91], [85, 50], [25, 51], [32, 11], [70, 62], [28, 90], [51, 85], [51, 10], [20, 87], [35, 72], [0, 25], [12, 0], [7, 66], [11, 26], [60, 90], [35, 79], [34, 15], [58, 72], [87, 5], [18, 29], [58, 88], [83, 80], [76, 33], [10, 60], [72, 83], [52, 38], [80, 38], [81, 93], [57, 33], [41, 53], [73, 64], [88, 36], [32, 57], [47, 17], [17, 86], [76, 51], [7, 86], [64, 2], [44, 35], [50, 56], [12, 62], [15, 59], [29, 22], [86, 92], [55, 49], [27, 46], [87, 65], [0, 81], [72, 32], [57, 86], [12, 77], [78, 89], [20, 59], [55, 19], [68, 62], [12, 64], [33, 18], [90, 80], [3, 79], [83, 45], [34, 71], [51, 45], [92, 27], [65, 58], [92, 25], [87, 67], [67, 82], [48, 76], [82, 39], [39, 50], [42, 38], [28, 32], [3, 51], [47, 87], [70, 67], [68, 29], [17, 30], [29, 52], [24, 89], [81, 57], [28, 28], [64, 6], [21, 31], [7, 84], [84, 19], [11, 31], [47, 77], [26, 16], [41, 47], [67, 10], [7, 3], [12, 74], [49, 83], [39, 84], [10, 70], [50, 46], [37, 7], [64, 15], [52, 32], [26, 34], [52, 89], [69, 42], [62, 12], [46, 77], [13, 88], [38, 26], [73, 2], [31, 18], [39, 71], [88, 6], [28, 86], [43, 82], [42, 13], [55, 63], [80, 14], [35, 29], [71, 68], [67, 15], [28, 43], [54, 73], [47, 85], [59, 71], [38, 74], [0, 73], [65, 75], [63, 17], [6, 62], [70, 11], [39, 80], [76, 1], [67, 86], [35, 71], [10, 87], [26, 19], [87, 0], [18, 15], [80, 72], [12, 57], [3, 89], [51, 21], [8, 50], [6, 70], [5, 77], [14, 38], [24, 64], [34, 57], [64, 18], [42, 62], [11, 16], [25, 69], [2, 16], [10, 53], [36, 44], [9, 56], [87, 1], [10, 45], [36, 27], [49, 37], [51, 57], [85, 16], [34, 34], [49, 4], [50, 78], [56, 57], [38, 71], [42, 25], [12, 83], [47, 31], [75, 11], [37, 54], [84, 39], [67, 59], [80, 91], [58, 8], [6, 4], [21, 40], [87, 26], [35, 31], [77, 39], [75, 26], [79, 0], [73, 65], [14, 35], [3, 20], [75, 34], [28, 25], [48, 72], [19, 17], [61, 5], [52, 26], [62, 23], [85, 76], [70, 47], [32, 17], [65, 78], [90, 88], [63, 27], [0, 16], [5, 59], [90, 22], [9, 89], [17, 13], [64, 36], [34, 59], [70, 66], [59, 38], [93, 83], [22, 9], [4, 41], [52, 71], [62, 37], [72, 91], [69, 63], [26, 30], [84, 72], [46, 10], [75, 25], [55, 70], [62, 33], [6, 39], [24, 18], [9, 21], [22, 68], [74, 81], [50, 58], [20, 76], [76, 45], [54, 69], [73, 74], [32, 64], [71, 70], [50, 38], [53, 85], [24, 84], [40, 63], [27, 54], [25, 11], [49, 35], [19, 18], [84, 49], [2, 36], [34, 4], [24, 2], [75, 88], [36, 0], [20, 21], [66, 48], [88, 9], [21, 85], [53, 33], [45, 44], [34, 64], [43, 32], [17, 48], [74, 67], [88, 12], [0, 92], [17, 45], [78, 2], [45, 42], [86, 88], [92, 49], [15, 48], [60, 42], [90, 25], [91, 85], [51, 59], [53, 92], [6, 84], [60, 31], [63, 80], [62, 21], [7, 18], [15, 31], [70, 53], [79, 37], [45, 45], [15, 45], [72, 84], [61, 53], [75, 85], [62, 26], [72, 26], [90, 64], [38, 90], [78, 69], [92, 26], [3, 19], [92, 31], [93, 7], [20, 18], [21, 71], [68, 88], [37, 85], [34, 88], [93, 18], [30, 35], [66, 30], [36, 76], [2, 25], [21, 47], [3, 17], [11, 81], [1, 55], [53, 88], [91, 17], [20, 39], [40, 56], [37, 10], [81, 5], [6, 50], [83, 57], [22, 16], [17, 16], [86, 50], [54, 1], [20, 37], [26, 66], [40, 17], [43, 71], [33, 72], [43, 55], [37, 2], [30, 2], [80, 69], [12, 67], [38, 5], [32, 74], [84, 89], [67, 81], [62, 62], [70, 37], [30, 26], [0, 50], [49, 90], [44, 70], [93, 10], [5, 57], [44, 16], [45, 81], [3, 2], [93, 16], [57, 42], [40, 13], [84, 32], [47, 81], [84, 4], [49, 44], [69, 37], [65, 63], [17, 27], [70, 27], [44, 79], [21, 65], [48, 82], [53, 67], [83, 50], [83, 81], [5, 56], [83, 82], [10, 43], [19, 72], [86, 35], [0, 80], [6, 15], [72, 18], [93, 88], [18, 55], [69, 56], [61, 0], [27, 79], [23, 47], [86, 36], [45, 73], [66, 74], [6, 7], [39, 6], [53, 44], [1, 22], [38, 51], [10, 31], [88, 40], [80, 32], [34, 90], [4, 66], [81, 55], [36, 29], [46, 76], [25, 78], [32, 10], [90, 70], [1, 70], [39, 27], [60, 5], [16, 84], [14, 5], [66, 4], [75, 51], [21, 80], [50, 53], [68, 91], [28, 82], [83, 44], [13, 81], [88, 82], [66, 54], [79, 80], [68, 42], [5, 53], [0, 85], [51, 63], [22, 26], [93, 43], [77, 10], [64, 52], [73, 9], [24, 45], [91, 47], [73, 93], [12, 56], [50, 13], [82, 54], [29, 47], [77, 28], [26, 24], [59, 7], [21, 61], [76, 9], [75, 92], [10, 27], [4, 88], [2, 72], [32, 66], [92, 76], [12, 78], [11, 27], [12, 44], [90, 26], [81, 28], [15, 24], [21, 32], [89, 77], [1, 48], [44, 89], [45, 51], [19, 63], [34, 19], [83, 14], [54, 27], [93, 55], [5, 86], [87, 38], [91, 65], [62, 3], [31, 35], [61, 66], [37, 49], [46, 44], [36, 5], [77, 63], [4, 67], [70, 63], [81, 40], [34, 27], [29, 43], [91, 27], [71, 72], [33, 23], [63, 28], [11, 70], [9, 10]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[13, 41], [44, 76], [7, 77], [84, 52], [5, 16], [92, 90], [13, 73], [76, 72], [33, 33], [64, 42], [24, 34], [86, 76], [10, 51], [13, 50], [36, 80], [7, 54], [77, 43], [71, 44], [20, 52], [33, 32], [7, 50], [43, 92], [53, 68], [11, 65], [54, 10], [66, 89], [18, 0], [0, 1], [84, 77], [37, 82], [45, 34], [40, 24], [34, 37], [23, 59], [20, 20], [4, 8], [78, 20], [49, 73], [63, 79], [41, 33], [80, 42], [22, 56], [61, 29], [11, 36], [65, 14], [30, 43], [29, 3], [53, 71], [22, 70], [64, 47], [16, 35], [71, 75], [81, 39], [44, 90], [90, 36], [55, 83], [82, 18], [26, 3], [25, 54], [11, 14], [3, 90], [47, 49], [14, 66], [48, 36], [17, 75], [5, 49], [11, 4], [30, 11], [20, 6], [57, 1], [23, 8], [43, 58], [62, 16], [50, 93], [4, 79], [41, 57], [62, 87], [75, 52], [52, 49], [35, 10], [87, 10], [27, 49], [22, 41], [4, 60], [31, 32], [19, 87], [54, 70], [6, 13], [66, 47], [82, 6], [47, 16], [72, 35], [55, 14], [3, 16], [26, 33], [84, 1], [84, 11], [2, 58], [35, 33], [30, 25], [79, 23], [77, 83], [54, 52], [13, 84], [19, 49], [52, 91], [61, 76], [57, 17], [89, 17], [48, 78], [49, 18], [82, 43], [60, 15], [30, 63], [59, 69], [24, 56], [29, 28], [58, 37], [4, 77], [69, 87], [83, 78], [7, 91], [8, 42], [51, 30], [46, 72], [57, 92], [86, 45], [84, 28], [39, 89], [56, 72], [68, 12], [4, 19], [53, 39], [64, 48], [88, 1], [75, 56], [0, 3], [44, 81], [80, 22], [26, 32], [13, 61], [32, 53], [54, 45], [16, 7], [62, 18], [83, 12], [59, 10], [63, 51], [38, 13], [17, 22], [37, 38], [27, 50], [14, 57], [42, 43], [45, 75], [26, 22], [71, 47], [14, 32], [57, 52], [75, 73], [30, 90], [34, 39], [42, 70], [23, 50], [72, 79], [43, 41], [41, 66], [73, 53], [31, 15], [5, 48], [56, 69], [7, 9], [74, 14], [17, 9], [63, 33], [63, 6], [88, 52], [46, 93], [33, 77], [63, 91], [79, 55], [63, 83], [33, 66], [15, 9], [90, 33], [21, 46], [22, 88], [32, 51], [51, 13], [23, 32], [93, 70], [59, 67], [80, 23], [73, 36], [27, 75], [22, 20], [78, 14], [12, 30], [37, 35], [28, 80], [80, 43], [69, 30], [30, 67], [57, 26], [84, 33], [90, 76], [26, 35], [18, 90], [78, 10], [43, 43], [46, 2], [44, 28], [15, 92], [71, 33], [43, 79], [43, 52], [25, 6], [58, 92], [24, 33], [24, 11], [0, 87], [8, 2], [5, 0], [33, 50], [71, 5], [19, 38], [23, 79], [0, 60], [17, 76], [35, 88], [31, 16], [47, 18], [72, 76], [47, 58], [5, 26], [26, 61], [83, 25], [88, 70], [56, 20], [55, 10], [67, 54], [69, 36], [33, 68], [16, 91], [13, 2], [75, 66], [63, 16], [7, 45], [46, 25], [37, 25], [5, 2], [24, 67], [53, 72], [10, 37], [36, 91], [85, 50], [25, 51], [32, 11], [70, 62], [28, 90], [51, 85], [51, 10], [20, 87], [35, 72], [0, 25], [12, 0], [7, 66], [11, 26], [60, 90], [35, 79], [34, 15], [58, 72], [87, 5], [18, 29], [58, 88], [83, 80], [76, 33], [10, 60], [72, 83], [52, 38], [80, 38], [81, 93], [57, 33], [41, 53], [73, 64], [88, 36], [32, 57], [47, 17], [17, 86], [76, 51], [7, 86], [64, 2], [44, 35], [50, 56], [12, 62], [15, 59], [29, 22], [86, 92], [55, 49], [27, 46], [87, 65], [0, 81], [72, 32], [57, 86], [12, 77], [78, 89], [20, 59], [55, 19], [68, 62], [12, 64], [33, 18], [90, 80], [3, 79], [83, 45], [34, 71], [51, 45], [92, 27], [65, 58], [92, 25], [87, 67], [67, 82], [48, 76], [82, 39], [39, 50], [42, 38], [28, 32], [3, 51], [47, 87], [70, 67], [68, 29], [17, 30], [29, 52], [24, 89], [81, 57], [28, 28], [64, 6], [21, 31], [7, 84], [84, 19], [11, 31], [47, 77], [26, 16], [41, 47], [67, 10], [7, 3], [12, 74], [49, 83], [39, 84], [10, 70], [50, 46], [37, 7], [64, 15], [52, 32], [26, 34], [52, 89], [69, 42], [62, 12], [46, 77], [13, 88], [38, 26], [73, 2], [31, 18], [39, 71], [88, 6], [28, 86], [43, 82], [42, 13], [55, 63], [80, 14], [35, 29], [71, 68], [67, 15], [28, 43], [54, 73], [47, 85], [59, 71], [38, 74], [0, 73], [65, 75], [63, 17], [6, 62], [70, 11], [39, 80], [76, 1], [67, 86], [35, 71], [10, 87], [26, 19], [87, 0], [18, 15], [80, 72], [12, 57], [3, 89], [51, 21], [8, 50], [6, 70], [5, 77], [14, 38], [24, 64], [34, 57], [64, 18], [42, 62], [11, 16], [25, 69], [2, 16], [10, 53], [36, 44], [9, 56], [87, 1], [10, 45], [36, 27], [49, 37], [51, 57], [85, 16], [34, 34], [49, 4], [50, 78], [56, 57], [38, 71], [42, 25], [12, 83], [47, 31], [75, 11], [37, 54], [84, 39], [67, 59], [80, 91], [58, 8], [6, 4], [21, 40], [87, 26], [35, 31], [77, 39], [75, 26], [79, 0], [73, 65], [14, 35], [3, 20], [75, 34], [28, 25], [48, 72], [19, 17], [61, 5], [52, 26], [62, 23], [85, 76], [70, 47], [32, 17], [65, 78], [90, 88], [63, 27], [0, 16], [5, 59], [90, 22], [9, 89], [17, 13], [64, 36], [34, 59], [70, 66], [59, 38], [93, 83], [22, 9], [4, 41], [52, 71], [62, 37], [72, 91], [69, 63], [26, 30], [84, 72], [46, 10], [75, 25], [55, 70], [62, 33], [6, 39], [24, 18], [9, 21], [22, 68], [74, 81], [50, 58], [20, 76], [76, 45], [54, 69], [73, 74], [32, 64], [71, 70], [50, 38], [53, 85], [24, 84], [40, 63], [27, 54], [25, 11], [49, 35], [19, 18], [84, 49], [2, 36], [34, 4], [24, 2], [75, 88], [36, 0], [20, 21], [66, 48], [88, 9], [21, 85], [53, 33], [45, 44], [34, 64], [43, 32], [17, 48], [74, 67], [88, 12], [0, 92], [17, 45], [78, 2], [45, 42], [86, 88], [92, 49], [15, 48], [60, 42], [90, 25], [91, 85], [51, 59], [53, 92], [6, 84], [60, 31], [63, 80], [62, 21], [7, 18], [15, 31], [70, 53], [79, 37], [45, 45], [15, 45], [72, 84], [61, 53], [75, 85], [62, 26], [72, 26], [90, 64], [38, 90], [78, 69], [92, 26], [3, 19], [92, 31], [93, 7], [20, 18], [21, 71], [68, 88], [37, 85], [34, 88], [93, 18], [30, 35], [66, 30], [36, 76], [2, 25], [21, 47], [3, 17], [11, 81], [1, 55], [53, 88], [91, 17], [20, 39], [40, 56], [37, 10], [81, 5], [6, 50], [83, 57], [22, 16], [17, 16], [86, 50], [54, 1], [20, 37], [26, 66], [40, 17], [43, 71], [33, 72], [43, 55], [37, 2], [30, 2], [80, 69], [12, 67], [38, 5], [32, 74], [84, 89], [67, 81], [62, 62], [70, 37], [30, 26], [0, 50], [49, 90], [44, 70], [93, 10], [5, 57], [44, 16], [45, 81], [3, 2], [93, 16], [57, 42], [40, 13], [84, 32], [47, 81], [84, 4], [49, 44], [69, 37], [65, 63], [17, 27], [70, 27], [44, 79], [21, 65], [48, 82], [53, 67], [83, 50], [83, 81], [5, 56], [83, 82], [10, 43], [19, 72], [86, 35], [0, 80], [6, 15], [72, 18], [93, 88], [18, 55], [69, 56], [61, 0], [27, 79], [23, 47], [86, 36], [45, 73], [66, 74], [6, 7], [39, 6], [53, 44], [1, 22], [38, 51], [10, 31], [88, 40], [80, 32], [34, 90], [4, 66], [81, 55], [36, 29], [46, 76], [25, 78], [32, 10], [90, 70], [1, 70], [39, 27], [60, 5], [16, 84], [14, 5], [66, 4], [75, 51], [21, 80], [50, 53], [68, 91], [28, 82], [83, 44], [13, 81], [88, 82], [66, 54], [79, 80], [68, 42], [5, 53], [0, 85], [51, 63], [22, 26], [93, 43], [77, 10], [64, 52], [73, 9], [24, 45], [91, 47], [73, 93], [12, 56], [50, 13], [82, 54], [29, 47], [77, 28], [26, 24], [59, 7], [21, 61], [76, 9], [75, 92], [10, 27], [4, 88], [2, 72], [32, 66], [92, 76], [12, 78], [11, 27], [12, 44], [90, 26], [81, 28], [15, 24], [21, 32], [89, 77], [1, 48], [44, 89], [45, 51], [19, 63], [34, 19], [83, 14], [54, 27], [93, 55], [5, 86], [87, 38], [91, 65], [62, 3], [31, 35], [61, 66], [37, 49], [46, 44], [36, 5], [77, 63], [4, 67], [70, 63], [81, 40], [34, 27], [29, 43], [91, 27], [71, 72], [33, 23], [63, 28], [11, 70], [9, 10]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_7", - "sat": "def sat(tri: List[int], edges=[[1, 27], [32, 31], [61, 17], [19, 79], [53, 54], [35, 46], [36, 48], [45, 68], [90, 71], [82, 85], [90, 67], [21, 90], [13, 78], [41, 75], [1, 30], [80, 24], [23, 52], [46, 71], [64, 37], [49, 85], [1, 1], [17, 44], [89, 69], [69, 64], [55, 55], [45, 27], [64, 78], [74, 25], [49, 58], [66, 48], [1, 77], [20, 58], [86, 24], [33, 33], [37, 83], [12, 30], [20, 8], [28, 53], [30, 75], [22, 59], [6, 25], [17, 3], [55, 58], [62, 68], [90, 39], [20, 11], [78, 18], [25, 62], [45, 10], [67, 78], [65, 18], [21, 29], [22, 42], [9, 89], [8, 7], [44, 39], [67, 42], [89, 14], [78, 56], [44, 72], [87, 75], [70, 87], [57, 55], [65, 71], [61, 77], [87, 32], [6, 20], [2, 48], [74, 59], [57, 64], [78, 73], [37, 85], [85, 54], [40, 33], [72, 26], [20, 10], [80, 68], [45, 13], [70, 44], [14, 73], [69, 59], [68, 6], [52, 81], [84, 45], [79, 47], [36, 56], [77, 67], [59, 0], [13, 26], [23, 49], [3, 15], [28, 81], [25, 69], [45, 0], [25, 1], [36, 58], [40, 19], [73, 7], [64, 79], [81, 3], [82, 54], [17, 31], [11, 51], [34, 22], [57, 30], [30, 57], [35, 61], [63, 79], [31, 55], [13, 84], [50, 2], [32, 84], [38, 49], [68, 50], [78, 50], [19, 83], [19, 50], [18, 24], [14, 78], [35, 47], [24, 74], [54, 6], [40, 7], [69, 39], [81, 56], [7, 5], [26, 15], [74, 58], [1, 81], [3, 23], [36, 11], [22, 2], [29, 59], [52, 88], [81, 84], [17, 60], [72, 68], [36, 79], [0, 49], [75, 90], [71, 77], [37, 70], [51, 53], [72, 74], [88, 76], [54, 64], [14, 52], [53, 15], [15, 59], [34, 34], [81, 51], [15, 77], [39, 81], [23, 86], [55, 2], [25, 80], [88, 46], [57, 26], [5, 77], [50, 62], [53, 66], [34, 49], [4, 13], [79, 40], [52, 8], [5, 74], [74, 86], [90, 51], [8, 88], [7, 29], [44, 32], [42, 6], [2, 68], [54, 58], [19, 88], [33, 58], [90, 33], [75, 70], [56, 85], [14, 33], [84, 48], [75, 53], [90, 11], [86, 79], [79, 27], [49, 50], [81, 48], [38, 21], [83, 39], [35, 85], [4, 7], [35, 32], [29, 6], [45, 24], [58, 20], [84, 65], [50, 87], [17, 89], [49, 78], [11, 56], [70, 89], [67, 45], [82, 0], [18, 68], [74, 72], [62, 30], [42, 3], [90, 90], [72, 30], [35, 72], [81, 16], [30, 37], [14, 9], [37, 50], [8, 17], [1, 85], [24, 42], [74, 52], [65, 81], [77, 6], [61, 44], [37, 69], [36, 76], [33, 76], [81, 68], [48, 77], [42, 88], [17, 15], [64, 77], [17, 43], [38, 40], [33, 61], [54, 88], [30, 6], [79, 85], [16, 6], [61, 12], [78, 83], [63, 90], [43, 59], [72, 76], [46, 74], [44, 49], [25, 27], [42, 43], [86, 22], [81, 12], [9, 1], [71, 5], [66, 54], [16, 8], [62, 3], [75, 20], [62, 54], [17, 81], [27, 3], [64, 52], [58, 64], [9, 32], [12, 54], [32, 78], [3, 40], [77, 5], [58, 39], [88, 80], [84, 57], [81, 32], [42, 5], [39, 70], [59, 62], [9, 56], [0, 56], [64, 49], [19, 61], [36, 33], [43, 62], [67, 21], [8, 13], [69, 75], [44, 76], [68, 18], [72, 84], [44, 42], [19, 78], [77, 76], [9, 42], [33, 83], [61, 61], [62, 35], [22, 25], [14, 45], [19, 6], [3, 88], [50, 26], [18, 15], [56, 8], [82, 67], [33, 89], [45, 25], [82, 72], [30, 17], [54, 50], [35, 45], [80, 10], [82, 62], [17, 35], [27, 47], [3, 14], [6, 50], [80, 85], [4, 19], [18, 7], [90, 60], [16, 51], [77, 71], [81, 25], [8, 60], [55, 73], [49, 28], [6, 46], [29, 40], [65, 74], [58, 48], [82, 12], [45, 86], [49, 80], [25, 25], [35, 74], [43, 76], [76, 58], [40, 52], [74, 7], [57, 52], [7, 34], [83, 87], [63, 66], [50, 38], [28, 87], [43, 17], [60, 42], [1, 19], [23, 65], [6, 59], [7, 47], [55, 47], [14, 37], [63, 27], [30, 59], [8, 9], [3, 36], [34, 78], [65, 66], [87, 55], [42, 50], [56, 35], [29, 0], [19, 13], [54, 59], [78, 52], [38, 19], [42, 53], [54, 0], [33, 15], [80, 75], [28, 83], [31, 81], [46, 13], [24, 54], [49, 30], [24, 30], [18, 27], [68, 33], [50, 68], [26, 26], [21, 53], [47, 3], [8, 45], [2, 55], [1, 61], [59, 68], [75, 86], [46, 56], [0, 78], [24, 57], [32, 87], [58, 38], [69, 70], [3, 80], [85, 44], [66, 74], [59, 88], [68, 7], [39, 43], [16, 18], [38, 35], [39, 18], [81, 18], [12, 90], [52, 1], [41, 14], [44, 63], [63, 69], [71, 66], [65, 82], [76, 68], [54, 51], [74, 78], [3, 28], [34, 75], [87, 40], [26, 75], [58, 82], [58, 16], [89, 40], [23, 80], [36, 44], [77, 79], [76, 89], [89, 12], [18, 51], [33, 7], [24, 78], [24, 75], [74, 21], [89, 2], [36, 63], [37, 36], [32, 60], [65, 68], [48, 4], [12, 75], [11, 27], [19, 3], [2, 35], [7, 72], [25, 18], [62, 41], [12, 84], [88, 0], [42, 18], [54, 37], [43, 36], [82, 57], [89, 63], [55, 12], [18, 36], [65, 80], [45, 35], [46, 69], [40, 15], [61, 80], [79, 56], [27, 56], [78, 65], [23, 69], [55, 70], [74, 42], [26, 77], [65, 34], [64, 75], [44, 79], [74, 12], [8, 48], [36, 36], [3, 43], [50, 47], [31, 59], [65, 19], [37, 62], [80, 48], [38, 56], [44, 82], [33, 32], [85, 51], [53, 11], [26, 22], [20, 38], [79, 6], [3, 0], [1, 51], [80, 37], [34, 60], [56, 59], [32, 33], [80, 67], [2, 33], [18, 35], [51, 52], [49, 52], [35, 54], [54, 26], [18, 65], [53, 43], [42, 15], [85, 61], [52, 50], [46, 52], [49, 2], [80, 60], [75, 41], [13, 4], [64, 26], [56, 42], [34, 17], [39, 6], [78, 40], [74, 47], [60, 27], [29, 32], [5, 13], [5, 42], [10, 31], [64, 62], [65, 62], [72, 78], [50, 9], [24, 38], [26, 62], [7, 22], [11, 0], [13, 88], [49, 38], [10, 58], [16, 12], [40, 71], [20, 56], [26, 43], [40, 82], [13, 7], [89, 48], [31, 29], [86, 37], [3, 2], [22, 71], [30, 80], [16, 24], [89, 28], [87, 6], [42, 11], [27, 17], [20, 45], [60, 67], [2, 8], [32, 79], [10, 81], [30, 16], [80, 65], [8, 3], [56, 29], [12, 81], [2, 28], [58, 24], [34, 54], [56, 84], [28, 67], [69, 34], [65, 89], [59, 82], [61, 0], [6, 72], [16, 52], [14, 82], [57, 72], [75, 75], [54, 12], [34, 38], [31, 45], [14, 88], [63, 19], [58, 1], [58, 84], [40, 17], [88, 40], [60, 38], [45, 14], [76, 11], [73, 53], [15, 53], [22, 18], [74, 77], [18, 86], [77, 2], [25, 28], [19, 67], [48, 29], [27, 48], [62, 28], [9, 11], [36, 37], [3, 81], [27, 83], [68, 14], [0, 39], [67, 31], [68, 57], [17, 4], [24, 66], [14, 39], [20, 9], [30, 71], [63, 22], [24, 52], [37, 65], [7, 1], [62, 84], [59, 3], [74, 67], [48, 83], [33, 81], [15, 35], [65, 58], [84, 20], [50, 7], [28, 0], [12, 67], [57, 35], [70, 49], [17, 66], [1, 13], [24, 55], [83, 78], [38, 51], [60, 16], [77, 82], [46, 70], [78, 69], [76, 13], [61, 34], [81, 54], [43, 32], [89, 61], [67, 65], [0, 2], [34, 30], [28, 13], [24, 56], [47, 88], [7, 17], [37, 33], [83, 7], [77, 87], [37, 44], [52, 76], [41, 56], [21, 30], [64, 24], [12, 6], [57, 53], [30, 2], [44, 17], [36, 0], [47, 45], [70, 56], [53, 3], [56, 47], [30, 74], [6, 55], [14, 43], [0, 25], [82, 56], [88, 56], [35, 51], [34, 42], [74, 31], [8, 29], [39, 20], [65, 83], [25, 9], [66, 60], [23, 48], [90, 68], [36, 90], [44, 83], [63, 67], [76, 85], [73, 3], [4, 66], [74, 43], [56, 66], [69, 30], [89, 47], [88, 4], [88, 26], [88, 7], [62, 90], [24, 87], [71, 62], [78, 45], [86, 80], [6, 9], [8, 19], [89, 25], [57, 20], [38, 47], [63, 47], [65, 6], [76, 0], [40, 78], [54, 14], [74, 44], [40, 69], [24, 36], [51, 1], [1, 60], [36, 13], [48, 31]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[1, 27], [32, 31], [61, 17], [19, 79], [53, 54], [35, 46], [36, 48], [45, 68], [90, 71], [82, 85], [90, 67], [21, 90], [13, 78], [41, 75], [1, 30], [80, 24], [23, 52], [46, 71], [64, 37], [49, 85], [1, 1], [17, 44], [89, 69], [69, 64], [55, 55], [45, 27], [64, 78], [74, 25], [49, 58], [66, 48], [1, 77], [20, 58], [86, 24], [33, 33], [37, 83], [12, 30], [20, 8], [28, 53], [30, 75], [22, 59], [6, 25], [17, 3], [55, 58], [62, 68], [90, 39], [20, 11], [78, 18], [25, 62], [45, 10], [67, 78], [65, 18], [21, 29], [22, 42], [9, 89], [8, 7], [44, 39], [67, 42], [89, 14], [78, 56], [44, 72], [87, 75], [70, 87], [57, 55], [65, 71], [61, 77], [87, 32], [6, 20], [2, 48], [74, 59], [57, 64], [78, 73], [37, 85], [85, 54], [40, 33], [72, 26], [20, 10], [80, 68], [45, 13], [70, 44], [14, 73], [69, 59], [68, 6], [52, 81], [84, 45], [79, 47], [36, 56], [77, 67], [59, 0], [13, 26], [23, 49], [3, 15], [28, 81], [25, 69], [45, 0], [25, 1], [36, 58], [40, 19], [73, 7], [64, 79], [81, 3], [82, 54], [17, 31], [11, 51], [34, 22], [57, 30], [30, 57], [35, 61], [63, 79], [31, 55], [13, 84], [50, 2], [32, 84], [38, 49], [68, 50], [78, 50], [19, 83], [19, 50], [18, 24], [14, 78], [35, 47], [24, 74], [54, 6], [40, 7], [69, 39], [81, 56], [7, 5], [26, 15], [74, 58], [1, 81], [3, 23], [36, 11], [22, 2], [29, 59], [52, 88], [81, 84], [17, 60], [72, 68], [36, 79], [0, 49], [75, 90], [71, 77], [37, 70], [51, 53], [72, 74], [88, 76], [54, 64], [14, 52], [53, 15], [15, 59], [34, 34], [81, 51], [15, 77], [39, 81], [23, 86], [55, 2], [25, 80], [88, 46], [57, 26], [5, 77], [50, 62], [53, 66], [34, 49], [4, 13], [79, 40], [52, 8], [5, 74], [74, 86], [90, 51], [8, 88], [7, 29], [44, 32], [42, 6], [2, 68], [54, 58], [19, 88], [33, 58], [90, 33], [75, 70], [56, 85], [14, 33], [84, 48], [75, 53], [90, 11], [86, 79], [79, 27], [49, 50], [81, 48], [38, 21], [83, 39], [35, 85], [4, 7], [35, 32], [29, 6], [45, 24], [58, 20], [84, 65], [50, 87], [17, 89], [49, 78], [11, 56], [70, 89], [67, 45], [82, 0], [18, 68], [74, 72], [62, 30], [42, 3], [90, 90], [72, 30], [35, 72], [81, 16], [30, 37], [14, 9], [37, 50], [8, 17], [1, 85], [24, 42], [74, 52], [65, 81], [77, 6], [61, 44], [37, 69], [36, 76], [33, 76], [81, 68], [48, 77], [42, 88], [17, 15], [64, 77], [17, 43], [38, 40], [33, 61], [54, 88], [30, 6], [79, 85], [16, 6], [61, 12], [78, 83], [63, 90], [43, 59], [72, 76], [46, 74], [44, 49], [25, 27], [42, 43], [86, 22], [81, 12], [9, 1], [71, 5], [66, 54], [16, 8], [62, 3], [75, 20], [62, 54], [17, 81], [27, 3], [64, 52], [58, 64], [9, 32], [12, 54], [32, 78], [3, 40], [77, 5], [58, 39], [88, 80], [84, 57], [81, 32], [42, 5], [39, 70], [59, 62], [9, 56], [0, 56], [64, 49], [19, 61], [36, 33], [43, 62], [67, 21], [8, 13], [69, 75], [44, 76], [68, 18], [72, 84], [44, 42], [19, 78], [77, 76], [9, 42], [33, 83], [61, 61], [62, 35], [22, 25], [14, 45], [19, 6], [3, 88], [50, 26], [18, 15], [56, 8], [82, 67], [33, 89], [45, 25], [82, 72], [30, 17], [54, 50], [35, 45], [80, 10], [82, 62], [17, 35], [27, 47], [3, 14], [6, 50], [80, 85], [4, 19], [18, 7], [90, 60], [16, 51], [77, 71], [81, 25], [8, 60], [55, 73], [49, 28], [6, 46], [29, 40], [65, 74], [58, 48], [82, 12], [45, 86], [49, 80], [25, 25], [35, 74], [43, 76], [76, 58], [40, 52], [74, 7], [57, 52], [7, 34], [83, 87], [63, 66], [50, 38], [28, 87], [43, 17], [60, 42], [1, 19], [23, 65], [6, 59], [7, 47], [55, 47], [14, 37], [63, 27], [30, 59], [8, 9], [3, 36], [34, 78], [65, 66], [87, 55], [42, 50], [56, 35], [29, 0], [19, 13], [54, 59], [78, 52], [38, 19], [42, 53], [54, 0], [33, 15], [80, 75], [28, 83], [31, 81], [46, 13], [24, 54], [49, 30], [24, 30], [18, 27], [68, 33], [50, 68], [26, 26], [21, 53], [47, 3], [8, 45], [2, 55], [1, 61], [59, 68], [75, 86], [46, 56], [0, 78], [24, 57], [32, 87], [58, 38], [69, 70], [3, 80], [85, 44], [66, 74], [59, 88], [68, 7], [39, 43], [16, 18], [38, 35], [39, 18], [81, 18], [12, 90], [52, 1], [41, 14], [44, 63], [63, 69], [71, 66], [65, 82], [76, 68], [54, 51], [74, 78], [3, 28], [34, 75], [87, 40], [26, 75], [58, 82], [58, 16], [89, 40], [23, 80], [36, 44], [77, 79], [76, 89], [89, 12], [18, 51], [33, 7], [24, 78], [24, 75], [74, 21], [89, 2], [36, 63], [37, 36], [32, 60], [65, 68], [48, 4], [12, 75], [11, 27], [19, 3], [2, 35], [7, 72], [25, 18], [62, 41], [12, 84], [88, 0], [42, 18], [54, 37], [43, 36], [82, 57], [89, 63], [55, 12], [18, 36], [65, 80], [45, 35], [46, 69], [40, 15], [61, 80], [79, 56], [27, 56], [78, 65], [23, 69], [55, 70], [74, 42], [26, 77], [65, 34], [64, 75], [44, 79], [74, 12], [8, 48], [36, 36], [3, 43], [50, 47], [31, 59], [65, 19], [37, 62], [80, 48], [38, 56], [44, 82], [33, 32], [85, 51], [53, 11], [26, 22], [20, 38], [79, 6], [3, 0], [1, 51], [80, 37], [34, 60], [56, 59], [32, 33], [80, 67], [2, 33], [18, 35], [51, 52], [49, 52], [35, 54], [54, 26], [18, 65], [53, 43], [42, 15], [85, 61], [52, 50], [46, 52], [49, 2], [80, 60], [75, 41], [13, 4], [64, 26], [56, 42], [34, 17], [39, 6], [78, 40], [74, 47], [60, 27], [29, 32], [5, 13], [5, 42], [10, 31], [64, 62], [65, 62], [72, 78], [50, 9], [24, 38], [26, 62], [7, 22], [11, 0], [13, 88], [49, 38], [10, 58], [16, 12], [40, 71], [20, 56], [26, 43], [40, 82], [13, 7], [89, 48], [31, 29], [86, 37], [3, 2], [22, 71], [30, 80], [16, 24], [89, 28], [87, 6], [42, 11], [27, 17], [20, 45], [60, 67], [2, 8], [32, 79], [10, 81], [30, 16], [80, 65], [8, 3], [56, 29], [12, 81], [2, 28], [58, 24], [34, 54], [56, 84], [28, 67], [69, 34], [65, 89], [59, 82], [61, 0], [6, 72], [16, 52], [14, 82], [57, 72], [75, 75], [54, 12], [34, 38], [31, 45], [14, 88], [63, 19], [58, 1], [58, 84], [40, 17], [88, 40], [60, 38], [45, 14], [76, 11], [73, 53], [15, 53], [22, 18], [74, 77], [18, 86], [77, 2], [25, 28], [19, 67], [48, 29], [27, 48], [62, 28], [9, 11], [36, 37], [3, 81], [27, 83], [68, 14], [0, 39], [67, 31], [68, 57], [17, 4], [24, 66], [14, 39], [20, 9], [30, 71], [63, 22], [24, 52], [37, 65], [7, 1], [62, 84], [59, 3], [74, 67], [48, 83], [33, 81], [15, 35], [65, 58], [84, 20], [50, 7], [28, 0], [12, 67], [57, 35], [70, 49], [17, 66], [1, 13], [24, 55], [83, 78], [38, 51], [60, 16], [77, 82], [46, 70], [78, 69], [76, 13], [61, 34], [81, 54], [43, 32], [89, 61], [67, 65], [0, 2], [34, 30], [28, 13], [24, 56], [47, 88], [7, 17], [37, 33], [83, 7], [77, 87], [37, 44], [52, 76], [41, 56], [21, 30], [64, 24], [12, 6], [57, 53], [30, 2], [44, 17], [36, 0], [47, 45], [70, 56], [53, 3], [56, 47], [30, 74], [6, 55], [14, 43], [0, 25], [82, 56], [88, 56], [35, 51], [34, 42], [74, 31], [8, 29], [39, 20], [65, 83], [25, 9], [66, 60], [23, 48], [90, 68], [36, 90], [44, 83], [63, 67], [76, 85], [73, 3], [4, 66], [74, 43], [56, 66], [69, 30], [89, 47], [88, 4], [88, 26], [88, 7], [62, 90], [24, 87], [71, 62], [78, 45], [86, 80], [6, 9], [8, 19], [89, 25], [57, 20], [38, 47], [63, 47], [65, 6], [76, 0], [40, 78], [54, 14], [74, 44], [40, 69], [24, 36], [51, 1], [1, 60], [36, 13], [48, 31]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_8", - "sat": "def sat(tri: List[int], edges=[[7, 6], [1, 8], [7, 5], [6, 0], [8, 5], [5, 6], [8, 8], [3, 7], [6, 7], [1, 5], [2, 8], [5, 8], [4, 6], [9, 1], [4, 0], [7, 9], [2, 4], [3, 2], [0, 0], [5, 9], [6, 6], [5, 2], [7, 0], [4, 9], [1, 2], [8, 3], [9, 3], [7, 1], [5, 4], [7, 7], [3, 1], [7, 2], [3, 0], [7, 8], [1, 3], [1, 6], [5, 3], [4, 7], [0, 9], [3, 4], [9, 8], [2, 7], [6, 5], [3, 9], [8, 7], [2, 9], [6, 1], [9, 9], [8, 9], [6, 3], [1, 1], [0, 6], [8, 0], [5, 5], [6, 4], [4, 1], [8, 2]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[7, 6], [1, 8], [7, 5], [6, 0], [8, 5], [5, 6], [8, 8], [3, 7], [6, 7], [1, 5], [2, 8], [5, 8], [4, 6], [9, 1], [4, 0], [7, 9], [2, 4], [3, 2], [0, 0], [5, 9], [6, 6], [5, 2], [7, 0], [4, 9], [1, 2], [8, 3], [9, 3], [7, 1], [5, 4], [7, 7], [3, 1], [7, 2], [3, 0], [7, 8], [1, 3], [1, 6], [5, 3], [4, 7], [0, 9], [3, 4], [9, 8], [2, 7], [6, 5], [3, 9], [8, 7], [2, 9], [6, 1], [9, 9], [8, 9], [6, 3], [1, 1], [0, 6], [8, 0], [5, 5], [6, 4], [4, 1], [8, 2]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyTriangle_9", - "sat": "def sat(tri: List[int], edges=[[2, 5], [1, 8], [1, 5], [5, 1], [7, 1], [5, 2], [6, 5], [1, 9], [0, 9], [5, 0], [6, 9], [1, 6], [7, 4], [4, 8], [5, 4], [6, 4], [4, 7], [3, 3], [2, 9], [1, 4], [1, 1], [7, 8], [4, 9], [3, 4], [8, 9], [8, 7], [0, 4], [8, 4], [5, 7], [1, 7], [6, 0], [5, 5], [4, 6], [8, 2], [4, 3], [9, 7], [5, 8]]):\n \"\"\"Find any triangle in the given directed graph.\"\"\"\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", - "sols": [ - "def sol(edges=[[2, 5], [1, 8], [1, 5], [5, 1], [7, 1], [5, 2], [6, 5], [1, 9], [0, 9], [5, 0], [6, 9], [1, 6], [7, 4], [4, 8], [5, 4], [6, 4], [4, 7], [3, 3], [2, 9], [1, 4], [1, 1], [7, 8], [4, 9], [3, 4], [8, 9], [8, 7], [0, 4], [8, 4], [5, 7], [1, 7], [6, 0], [5, 5], [4, 6], [8, 2], [4, 3], [9, 7], [5, 8]]):\n from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" - ], - "module": "graphs", - "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_0", - "sat": "def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_1", - "sat": "def sat(nodes: List[int], size=0, edges=[[1, 0]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=0, edges=[[1, 0]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_2", - "sat": "def sat(nodes: List[int], size=15, edges=[[36, 31], [31, 39], [16, 41], [62, 39], [57, 38], [29, 46], [39, 30], [71, 41], [18, 0], [73, 71], [20, 23], [41, 53], [17, 12], [76, 23], [36, 29], [53, 32], [34, 61], [58, 29], [39, 46], [18, 73], [21, 51], [74, 26], [67, 10], [71, 74], [27, 71], [67, 39], [41, 26], [51, 20], [5, 2], [24, 3], [14, 60], [28, 21], [61, 1], [56, 75], [62, 37], [67, 41], [32, 69], [22, 16], [1, 67], [37, 14], [55, 40], [0, 58], [16, 63], [8, 59], [26, 61], [34, 51], [43, 66], [31, 33], [7, 51], [1, 0], [22, 9], [59, 68], [9, 10], [8, 74], [62, 8], [26, 16], [45, 69], [51, 52], [72, 67], [37, 53], [48, 5], [18, 41], [15, 11], [72, 43], [64, 51], [4, 9], [54, 42], [62, 15], [12, 38], [30, 31], [56, 37], [29, 2], [14, 9], [43, 43], [51, 28], [10, 15], [20, 5], [24, 61], [53, 2], [69, 1], [35, 63], [12, 64], [50, 12], [69, 65], [60, 75], [56, 48], [36, 67], [21, 6], [38, 67], [15, 34], [46, 54], [37, 18], [32, 2], [12, 49], [52, 15], [60, 2], [67, 43], [13, 49], [55, 59], [33, 72], [37, 30], [11, 27], [67, 2], [57, 55], [21, 65], [54, 66], [6, 63], [71, 59], [20, 59], [47, 34], [66, 67], [4, 8], [73, 61], [68, 41], [61, 7], [52, 38], [8, 51], [50, 15], [5, 12], [76, 74], [66, 33], [59, 18], [13, 55], [6, 16], [13, 26], [29, 44], [18, 43], [63, 47], [46, 30], [41, 18], [66, 18], [34, 26], [57, 28], [38, 10], [34, 57], [73, 41], [67, 3], [47, 57], [63, 62], [36, 30], [72, 45], [68, 19], [7, 28], [50, 23], [42, 29], [3, 66], [56, 45], [4, 25], [2, 43], [4, 38], [56, 74], [55, 10], [0, 13], [9, 19], [38, 69], [40, 57], [70, 41], [49, 45], [47, 27], [11, 8], [32, 5], [9, 38], [76, 64], [24, 33], [74, 63], [73, 58], [58, 41], [75, 0], [33, 55], [74, 2], [41, 72], [1, 64], [36, 74], [51, 71], [75, 9], [53, 36], [8, 70], [53, 42], [58, 25], [29, 37], [34, 46], [37, 39], [59, 61], [52, 20], [16, 58], [39, 43], [37, 40], [10, 72], [76, 14], [49, 13], [21, 37], [42, 2], [10, 29], [76, 19], [57, 66], [55, 62], [76, 53], [0, 0], [58, 5], [14, 2], [5, 32], [70, 57], [20, 18], [74, 66], [39, 57], [32, 36], [15, 30], [56, 23], [67, 16], [66, 51], [6, 74], [43, 59], [33, 70], [11, 71], [59, 28], [75, 29], [17, 13], [75, 67], [70, 1], [68, 10], [8, 46], [37, 27], [20, 24], [72, 75], [37, 41], [68, 24], [35, 10], [67, 66], [18, 24], [52, 3], [55, 34], [28, 75], [41, 3], [44, 3], [44, 30], [23, 17], [44, 4], [72, 73], [67, 12], [43, 21], [16, 55], [59, 71], [26, 62], [34, 60], [15, 22], [5, 10], [2, 55], [48, 15], [60, 34], [39, 35], [52, 36], [11, 46], [18, 10], [3, 43], [37, 6], [34, 47], [73, 29], [59, 29], [49, 72], [64, 73], [20, 76], [39, 39], [0, 16], [62, 73], [15, 36], [73, 18], [16, 34], [18, 68], [66, 45], [16, 66], [47, 52], [46, 66], [73, 43], [22, 55], [70, 58], [63, 11], [40, 2], [58, 60], [47, 29], [19, 45], [15, 41], [54, 5], [1, 18], [36, 38], [16, 19], [32, 4], [56, 14], [15, 51], [14, 35], [74, 10], [7, 20], [25, 38], [35, 13], [57, 34], [3, 16], [56, 28], [21, 56], [63, 65], [46, 35], [17, 57], [2, 30], [52, 73], [68, 73], [53, 10], [58, 59], [29, 16], [11, 20], [42, 27], [10, 66], [73, 5], [61, 58], [68, 67], [14, 47], [19, 59], [8, 42], [31, 12], [3, 2], [52, 66], [28, 72], [30, 56], [27, 12], [29, 18], [38, 56], [11, 17], [59, 66], [70, 7], [1, 54], [2, 16], [1, 14], [25, 20], [69, 72], [20, 74], [10, 59], [72, 52], [26, 15], [44, 42], [5, 51], [76, 69], [16, 10], [75, 39], [5, 44], [0, 46], [16, 76], [66, 73], [66, 72], [11, 11], [47, 13], [20, 26], [73, 59], [3, 10], [46, 49], [17, 38], [32, 62], [41, 2], [16, 72], [76, 61], [15, 37], [74, 69], [38, 46], [68, 58], [51, 70], [20, 46], [59, 2], [35, 21], [72, 37], [69, 20], [3, 72], [43, 71], [1, 71], [48, 59], [43, 58], [74, 5], [59, 72], [45, 24], [66, 69], [35, 38], [16, 5], [40, 24], [63, 30], [16, 18], [72, 29], [72, 58], [42, 5], [17, 30], [14, 21], [48, 23], [53, 44], [1, 47], [57, 33], [47, 69], [65, 52], [51, 44], [60, 35], [41, 9], [59, 75], [57, 73], [58, 28], [65, 23], [36, 48], [26, 40], [39, 41], [58, 3], [40, 42], [58, 49], [28, 42], [33, 36], [44, 24], [2, 68], [30, 57], [10, 51], [3, 68], [26, 42], [51, 13], [12, 69], [19, 60], [58, 39], [1, 45], [66, 16], [41, 27], [56, 1], [28, 18], [66, 29], [37, 49], [59, 4], [29, 67], [38, 29], [54, 57], [47, 61], [68, 29], [38, 9], [51, 41], [41, 10], [19, 61], [3, 22], [72, 23], [18, 11], [27, 17], [72, 74], [5, 37], [66, 68], [2, 3], [60, 27], [68, 72], [64, 20], [67, 18], [6, 66], [24, 60], [14, 75], [9, 11], [71, 50], [66, 43], [6, 60], [54, 22], [71, 53], [51, 7], [49, 40], [7, 74], [72, 30], [20, 71], [28, 74], [36, 55], [16, 17], [66, 2], [53, 8], [18, 2], [62, 63], [63, 26], [19, 34], [26, 27], [67, 51], [61, 46], [37, 29], [66, 41], [51, 54], [3, 17], [35, 6], [50, 51], [8, 15], [15, 55], [10, 65], [57, 59], [69, 21], [73, 70], [21, 30], [28, 28], [67, 59], [39, 76], [56, 12], [22, 69], [76, 7], [63, 66], [9, 40], [64, 28], [65, 31], [6, 59], [73, 73], [24, 29], [44, 18], [67, 1], [16, 12], [73, 2], [74, 27], [25, 58], [18, 52], [12, 66], [32, 25], [26, 4], [34, 27], [51, 39], [23, 11], [13, 65], [18, 28], [19, 6], [68, 59], [51, 72], [59, 74], [59, 3], [41, 29], [36, 6], [49, 37], [71, 39], [33, 13], [38, 68], [34, 19], [64, 36], [4, 29], [72, 60], [52, 41], [36, 66], [34, 70], [22, 32], [67, 40], [3, 73], [19, 12], [17, 0], [22, 8], [42, 35], [34, 54], [71, 29], [6, 7], [10, 43], [8, 56], [2, 58], [72, 2], [67, 65], [1, 23], [13, 21], [62, 38], [2, 66], [42, 62], [38, 27], [1, 22], [16, 29], [39, 54], [41, 0], [42, 54], [50, 58], [62, 45], [59, 76], [40, 44], [72, 18], [45, 40], [31, 3], [13, 45], [38, 64], [1, 21], [10, 32], [35, 12], [32, 6], [62, 75], [52, 59], [1, 42], [72, 31], [55, 17], [18, 50], [43, 29], [48, 37], [73, 16], [43, 68], [47, 12], [55, 46], [41, 30], [69, 32], [55, 14], [74, 61], [55, 72], [75, 24], [63, 40], [10, 58], [67, 73], [20, 11], [42, 40], [27, 53], [5, 8], [10, 2], [27, 49], [50, 48], [18, 58], [60, 25], [74, 71], [0, 30], [3, 29], [59, 5], [43, 16], [59, 41], [74, 4], [19, 20], [53, 19], [57, 50], [60, 11], [16, 68], [9, 50], [71, 17], [73, 66], [59, 43], [68, 32], [75, 31], [27, 56], [47, 24], [29, 7], [27, 25], [48, 36], [0, 53], [0, 72], [24, 53], [13, 64], [19, 44], [9, 56], [35, 75], [75, 17], [47, 16], [11, 42], [40, 45], [43, 60], [21, 59], [29, 50], [8, 9], [3, 18], [7, 57], [32, 9], [61, 6], [11, 6], [7, 72], [42, 61], [73, 75], [68, 44], [68, 66], [25, 56], [14, 20], [3, 50], [32, 57], [67, 58], [41, 68], [19, 26], [30, 3], [23, 45], [16, 60], [41, 43], [5, 30], [5, 25], [72, 16], [16, 73], [21, 17], [16, 59], [8, 34], [4, 39], [23, 72], [35, 53], [31, 50], [20, 44], [50, 13], [72, 1], [8, 8], [74, 54], [1, 1], [16, 43], [39, 36], [51, 2], [23, 54], [66, 58], [60, 33], [2, 63], [73, 10]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_3", - "sat": "def sat(nodes: List[int], size=18, edges=[[34, 43], [45, 8], [7, 46], [53, 11], [48, 24], [47, 46], [20, 46], [11, 57], [39, 17], [25, 13], [9, 49], [47, 51], [5, 22], [56, 8], [5, 20], [11, 26], [40, 20], [30, 42], [46, 35], [41, 11], [49, 57], [24, 46], [40, 27], [3, 13], [25, 36], [20, 49], [57, 24], [56, 26], [1, 52], [8, 26], [17, 44], [1, 21], [5, 6], [45, 45], [39, 25], [48, 27], [26, 17], [37, 25], [17, 16], [49, 0], [17, 56], [33, 43], [20, 43], [24, 20], [31, 56], [54, 28], [25, 27], [50, 5], [21, 43], [54, 25], [57, 45], [48, 5], [45, 34], [18, 46], [25, 47], [56, 48], [17, 57], [15, 29], [40, 22], [23, 57], [17, 27], [1, 14], [7, 54], [15, 24], [27, 44], [24, 44], [6, 7], [59, 13], [56, 51], [49, 46], [1, 32], [20, 36], [46, 13], [15, 46], [6, 46], [59, 51], [35, 5], [27, 10], [3, 16], [24, 33], [34, 49], [4, 38], [46, 24], [46, 3], [41, 39], [12, 9], [44, 39], [27, 23], [33, 11], [16, 24], [29, 59], [47, 39], [32, 10], [23, 36], [48, 30], [48, 20], [18, 43], [36, 9], [36, 16], [27, 57], [29, 35], [13, 41], [52, 12], [32, 20], [9, 50], [29, 27], [47, 44], [57, 39], [48, 57], [35, 45], [9, 23], [25, 55], [32, 25], [5, 57], [44, 16], [5, 27], [16, 37], [15, 25], [39, 51], [43, 14], [13, 44], [2, 5], [40, 4], [58, 30], [43, 6], [25, 28], [16, 35], [57, 44], [51, 54], [21, 11], [18, 19], [41, 20], [44, 48], [14, 54], [57, 16], [15, 5], [37, 15], [44, 49], [15, 20], [11, 20], [45, 1], [3, 32], [7, 22], [48, 39], [28, 37], [11, 51], [20, 16], [32, 4], [13, 17], [16, 15], [20, 37], [37, 46], [33, 59], [46, 25], [42, 1], [32, 33], [13, 53], [46, 18], [44, 23], [17, 48], [5, 24], [10, 40], [19, 11], [37, 47], [11, 42], [13, 24], [13, 27], [42, 9], [13, 5], [29, 17], [57, 4], [31, 25], [38, 32], [21, 45], [0, 21], [1, 0], [20, 13], [24, 37], [20, 25], [5, 17], [20, 47], [46, 41], [11, 0], [25, 22], [5, 28], [44, 5], [10, 11], [41, 22], [17, 25], [25, 20], [20, 17], [39, 46], [49, 25], [41, 0], [12, 44], [41, 49], [55, 8], [47, 49], [27, 49], [2, 11], [38, 11], [27, 46], [16, 9], [41, 47], [17, 15], [37, 31], [48, 48], [53, 59], [25, 24], [3, 44], [34, 48], [33, 13], [15, 47], [16, 39], [48, 8], [32, 55], [38, 22], [11, 23], [41, 16], [21, 44], [20, 27], [13, 57], [27, 41], [29, 32], [56, 39], [31, 51], [46, 20], [24, 49], [25, 3], [57, 37], [15, 44], [9, 41], [15, 48], [42, 57], [47, 5], [48, 37], [45, 49], [44, 41], [7, 3], [39, 49], [49, 37], [24, 16], [57, 41], [56, 2], [49, 20], [19, 5], [58, 18], [7, 31], [24, 5], [41, 32], [34, 23], [17, 5], [47, 27], [49, 41], [31, 12], [0, 11], [49, 15], [13, 15], [29, 31], [14, 56], [24, 41], [35, 1], [16, 25], [26, 28], [16, 49], [12, 46], [47, 16], [17, 37], [37, 39], [3, 22], [27, 24], [20, 39], [24, 4], [33, 15], [53, 50], [32, 1], [23, 40], [33, 25], [4, 24], [48, 25], [47, 57], [25, 8], [39, 30], [17, 53], [41, 53], [31, 8], [39, 33], [33, 16], [32, 19], [41, 5], [49, 17], [53, 40], [42, 52], [24, 17], [30, 59], [13, 14], [43, 27], [48, 16], [24, 47], [37, 23], [30, 47], [49, 10], [47, 12], [5, 37], [48, 47], [59, 27], [57, 17], [27, 33], [12, 30], [41, 48], [5, 46], [12, 25], [53, 46], [54, 8], [48, 1], [22, 25], [20, 44], [14, 38], [48, 13], [3, 3], [59, 4], [14, 7], [49, 26], [36, 5], [28, 32], [57, 46], [22, 34], [11, 54], [27, 58], [4, 11], [24, 39], [57, 25], [15, 27], [6, 15], [27, 29], [51, 37], [48, 23], [15, 57], [27, 25], [0, 57], [49, 48], [27, 34], [21, 5], [31, 40], [38, 45], [15, 1], [17, 42], [5, 16], [59, 32], [13, 51], [17, 47], [38, 54], [4, 43], [54, 9], [42, 31], [16, 13], [20, 57], [58, 10], [41, 30], [52, 19], [52, 35], [46, 44], [51, 4], [30, 39], [47, 13], [30, 32], [36, 42], [39, 15], [3, 19], [12, 16], [46, 16], [12, 37], [46, 48], [58, 46], [5, 25], [46, 6], [49, 44], [18, 23], [50, 24], [16, 16], [49, 53], [37, 33], [4, 15], [46, 17], [7, 20], [25, 41], [27, 56], [37, 41], [38, 55], [59, 28], [31, 7], [10, 47], [40, 23], [49, 5], [44, 25], [8, 36], [26, 39], [34, 3], [5, 12], [54, 22], [15, 41], [40, 19], [21, 12], [16, 5], [13, 49], [39, 5], [9, 9], [11, 53], [27, 16], [27, 39], [52, 14], [3, 56], [27, 37], [30, 15], [41, 17], [1, 34], [55, 32], [28, 22], [49, 27], [10, 55], [39, 37], [30, 17], [23, 9], [22, 11], [44, 37], [41, 37], [37, 13], [51, 18], [4, 34], [23, 12], [39, 13], [32, 9], [58, 14], [25, 48], [29, 14], [52, 2]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_4", - "sat": "def sat(nodes: List[int], size=0, edges=[[0, 1], [1, 0]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=0, edges=[[0, 1], [1, 0]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_5", - "sat": "def sat(nodes: List[int], size=6, edges=[[7, 17], [4, 2], [9, 12], [9, 0], [17, 9], [5, 0], [12, 16], [7, 5], [15, 9], [17, 12], [11, 16], [0, 17], [12, 5], [9, 7], [7, 12], [17, 5], [9, 5], [15, 13], [0, 7], [0, 12], [9, 14]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=6, edges=[[7, 17], [4, 2], [9, 12], [9, 0], [17, 9], [5, 0], [12, 16], [7, 5], [15, 9], [17, 12], [11, 16], [0, 17], [12, 5], [9, 7], [7, 12], [17, 5], [9, 5], [15, 13], [0, 7], [0, 12], [9, 14]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_6", - "sat": "def sat(nodes: List[int], size=19, edges=[[17, 63], [8, 12], [91, 66], [4, 21], [92, 4], [6, 59], [57, 74], [4, 45], [81, 66], [85, 68], [72, 35], [57, 88], [57, 81], [15, 3], [77, 42], [4, 91], [17, 85], [50, 65], [38, 70], [85, 33], [29, 88], [8, 18], [59, 27], [7, 10], [41, 11], [81, 79], [38, 1], [45, 48], [92, 66], [28, 49], [80, 69], [40, 59], [88, 67], [50, 88], [21, 57], [67, 81], [4, 77], [58, 83], [92, 81], [88, 45], [74, 48], [96, 3], [48, 78], [93, 23], [61, 39], [54, 23], [0, 28], [4, 50], [79, 6], [55, 81], [57, 91], [59, 70], [81, 91], [25, 34], [73, 83], [22, 32], [0, 90], [4, 48], [65, 45], [33, 91], [24, 93], [74, 50], [95, 95], [39, 73], [57, 30], [30, 4], [78, 76], [48, 17], [78, 34], [7, 75], [87, 64], [85, 21], [50, 54], [80, 41], [28, 69], [74, 30], [49, 41], [87, 54], [21, 10], [93, 84], [6, 55], [36, 89], [28, 23], [38, 59], [45, 30], [7, 83], [98, 87], [68, 35], [92, 55], [60, 49], [92, 72], [73, 77], [10, 11], [60, 82], [48, 57], [36, 12], [76, 15], [33, 35], [67, 6], [56, 38], [61, 22], [74, 85], [75, 49], [30, 85], [70, 50], [98, 52], [51, 7], [6, 21], [6, 91], [0, 64], [67, 21], [46, 28], [88, 55], [6, 66], [15, 43], [89, 28], [4, 55], [73, 78], [60, 28], [84, 62], [93, 46], [67, 74], [85, 91], [23, 22], [87, 82], [45, 74], [50, 91], [55, 50], [74, 17], [67, 4], [73, 32], [17, 30], [45, 66], [15, 67], [59, 43], [91, 30], [70, 68], [45, 17], [55, 91], [59, 88], [55, 61], [3, 13], [59, 45], [24, 31], [66, 67], [55, 57], [4, 34], [82, 48], [55, 21], [85, 55], [56, 30], [85, 81], [59, 57], [81, 45], [11, 45], [58, 76], [21, 97], [13, 15], [67, 50], [48, 88], [85, 45], [71, 52], [74, 21], [33, 51], [70, 80], [1, 42], [33, 56], [88, 92], [44, 85], [68, 57], [14, 82], [57, 6], [82, 12], [97, 86], [21, 94], [0, 8], [12, 0], [89, 94], [43, 75], [46, 64], [39, 22], [57, 4], [30, 42], [83, 71], [14, 14], [0, 45], [65, 10], [87, 4], [88, 74], [30, 13], [67, 65], [20, 43], [74, 0], [13, 49], [59, 85], [85, 92], [9, 42], [6, 50], [73, 81], [50, 21], [75, 30], [1, 31], [66, 17], [44, 59], [30, 66], [50, 77], [48, 42], [35, 94], [45, 92], [66, 57], [26, 29], [15, 46], [5, 49], [35, 95], [77, 50], [79, 95], [49, 80], [85, 66], [59, 50], [67, 91], [59, 48], [81, 50], [55, 85], [6, 19], [9, 96], [9, 3], [59, 17], [59, 92], [76, 49], [38, 30], [36, 26], [81, 27], [87, 75], [30, 45], [92, 50], [45, 94], [4, 46], [17, 36], [0, 15], [34, 11], [30, 50], [92, 85], [30, 81], [6, 88], [17, 6], [86, 64], [13, 25], [29, 20], [45, 50], [55, 59], [90, 87], [19, 45], [59, 81], [63, 57], [91, 45], [1, 74], [32, 56], [85, 6], [30, 55], [2, 3], [12, 43], [61, 52], [28, 2], [36, 85], [27, 37], [21, 92], [26, 98], [55, 17], [22, 45], [48, 55], [83, 60], [12, 72], [59, 67], [68, 84], [85, 4], [43, 89], [4, 6], [91, 59], [57, 77], [66, 55], [88, 21], [8, 48], [37, 79], [19, 46], [93, 21], [44, 70], [11, 25], [26, 75], [23, 20], [64, 83], [84, 19], [30, 67], [27, 82], [92, 57], [81, 13], [45, 57], [17, 67], [29, 17], [34, 82], [74, 66], [37, 65], [87, 61], [48, 67], [69, 60], [67, 45], [69, 22], [83, 94], [60, 8], [21, 30], [74, 92], [17, 20], [90, 48], [32, 77], [96, 95], [34, 87], [68, 9], [50, 71], [84, 43], [33, 66], [92, 30], [21, 91], [16, 71], [18, 54], [74, 27], [66, 4], [30, 75], [66, 74], [78, 39], [33, 45], [34, 59], [9, 48], [18, 26], [24, 73], [67, 55], [2, 61], [50, 66], [88, 4], [92, 17], [12, 67], [2, 49], [21, 59], [18, 11], [48, 66], [21, 48], [85, 67], [6, 74], [83, 10], [66, 22], [28, 1], [17, 50], [98, 85], [55, 27], [98, 76], [6, 81], [57, 15], [88, 66], [45, 21], [4, 17], [59, 30], [91, 42], [48, 26], [1, 80], [85, 51], [17, 21], [36, 87], [39, 54], [96, 49], [6, 48], [64, 35], [48, 81], [0, 4], [56, 15], [8, 94], [2, 44], [38, 88], [42, 7], [26, 94], [2, 77], [5, 67], [72, 50], [85, 88], [88, 91], [56, 81], [80, 18], [85, 48], [17, 83], [6, 92], [92, 23], [57, 67], [28, 34], [31, 28], [66, 21], [50, 85], [54, 20], [28, 89], [87, 19], [7, 36], [2, 28], [44, 22], [16, 65], [1, 27], [22, 76], [91, 48], [19, 62], [26, 7], [83, 90], [48, 50], [17, 81], [48, 92], [2, 95], [34, 68], [35, 90], [43, 17], [76, 33], [50, 57], [85, 57], [80, 3], [29, 18], [13, 89], [67, 24], [74, 59], [24, 13], [88, 83], [58, 12], [81, 88], [41, 78], [30, 88], [4, 74], [92, 91], [53, 22], [74, 91], [21, 46], [55, 45], [1, 33], [74, 86], [78, 69], [23, 63], [94, 47], [52, 30], [1, 92], [92, 67], [95, 18], [28, 31], [66, 59], [81, 4], [6, 45], [24, 71], [55, 74], [17, 57], [48, 30], [74, 89], [63, 79], [21, 81], [32, 76], [91, 17], [6, 30], [81, 74], [95, 60], [1, 68], [62, 32], [81, 51], [27, 47], [79, 23], [88, 17], [4, 59], [71, 35], [4, 41], [61, 69], [5, 34]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_7", - "sat": "def sat(nodes: List[int], size=12, edges=[[52, 42], [28, 30], [7, 3], [41, 35], [47, 56], [52, 11], [15, 52], [26, 30], [2, 12], [36, 51], [40, 56], [38, 18], [17, 16], [1, 17], [41, 59], [31, 24], [30, 18], [26, 44], [53, 13], [1, 34], [27, 24], [27, 40], [37, 15], [49, 5], [46, 23], [42, 29], [6, 41], [21, 33], [2, 47], [42, 26], [5, 58], [41, 42], [16, 49], [44, 5], [4, 33], [34, 33], [7, 1], [0, 4], [40, 59], [19, 24], [6, 14], [14, 2], [55, 9], [3, 43], [39, 57], [35, 20], [30, 42], [21, 40], [56, 30], [9, 55], [55, 10], [41, 9], [34, 35], [22, 33], [31, 17], [40, 0], [58, 44], [5, 24], [22, 30], [53, 17], [52, 1], [50, 22], [2, 58], [55, 30], [32, 46], [35, 50], [33, 38], [34, 18], [36, 17], [5, 13], [6, 35], [55, 13], [12, 30], [1, 58], [25, 12], [7, 40], [25, 3], [56, 21], [50, 41], [49, 20], [42, 0], [15, 35], [0, 10], [14, 46], [11, 2], [20, 11], [58, 59], [30, 28], [37, 54], [44, 55], [34, 21], [48, 13], [57, 6], [18, 11], [37, 22], [17, 8], [41, 22], [59, 54], [21, 51], [26, 25], [50, 15], [21, 30], [57, 23], [1, 18], [53, 47], [16, 18], [53, 50], [2, 55], [45, 22], [46, 4], [40, 53], [26, 58], [28, 34], [44, 46], [38, 54], [3, 4], [17, 2], [20, 1], [58, 23], [20, 2], [24, 45], [12, 43], [24, 34], [2, 28], [38, 0], [55, 53], [8, 4], [22, 0], [13, 33], [57, 20], [58, 12], [1, 33], [34, 8], [31, 28], [28, 13], [57, 27], [55, 35], [57, 32], [4, 54], [44, 8], [53, 30], [26, 28], [39, 45], [2, 42], [35, 35], [2, 36], [22, 42], [24, 27], [21, 7], [16, 11], [37, 10], [28, 27], [9, 3], [9, 20], [17, 42], [50, 35], [10, 41], [28, 12], [57, 28], [43, 30], [2, 19], [23, 8], [13, 52], [6, 0], [27, 47], [57, 26], [50, 42], [9, 16], [5, 0], [57, 22], [26, 57], [41, 50], [44, 24], [18, 59], [54, 43], [38, 38], [53, 32], [30, 0], [34, 45], [14, 7], [2, 41], [6, 6], [28, 28], [22, 59], [13, 40], [32, 1], [28, 25], [39, 5], [5, 35], [50, 51], [4, 58], [22, 47], [59, 53], [48, 16], [32, 42], [28, 2], [54, 48], [51, 44], [36, 47], [56, 32], [57, 30], [17, 35], [33, 40], [39, 10], [57, 42], [2, 10], [24, 11], [52, 24], [22, 58], [43, 38], [37, 51], [2, 27], [57, 0], [9, 54], [49, 59], [0, 35], [29, 9], [55, 20], [19, 54], [38, 46], [6, 28], [55, 38], [28, 40], [42, 37], [46, 7], [10, 39], [18, 54], [53, 56], [42, 53], [23, 55], [35, 33], [32, 9], [41, 54], [0, 53], [22, 36], [43, 51], [54, 36], [18, 46], [14, 44], [26, 26], [37, 37], [12, 18], [41, 58], [15, 43], [42, 35], [16, 52], [33, 51], [3, 58], [18, 27], [54, 20], [56, 38], [45, 48], [22, 54], [8, 3], [20, 7], [28, 50], [51, 40], [7, 59], [27, 36], [1, 54], [25, 43], [39, 13], [32, 57], [40, 32], [38, 48], [16, 40], [41, 53], [50, 36], [7, 24], [54, 41], [25, 36], [30, 54], [33, 12], [25, 1], [41, 39], [2, 5], [54, 57], [53, 27], [33, 1], [13, 53], [52, 15], [46, 58], [33, 5], [57, 35], [53, 28], [44, 45], [28, 35], [8, 28], [30, 41], [8, 41], [9, 8], [50, 21], [50, 57], [24, 57], [24, 3], [36, 30], [19, 6], [45, 39], [56, 20], [18, 52], [53, 41], [42, 44], [49, 6], [22, 53], [25, 42], [58, 47], [47, 50], [28, 54], [42, 41], [27, 50], [45, 50], [41, 40], [21, 5], [31, 14], [22, 57], [32, 59], [30, 35], [42, 46], [53, 7], [50, 0], [28, 0], [35, 54], [10, 45], [55, 21], [32, 39], [41, 37], [22, 29], [45, 30], [3, 41], [16, 36], [24, 19], [45, 21], [25, 27], [36, 13], [12, 11], [40, 54], [15, 7], [21, 31], [53, 35], [14, 36], [27, 54], [50, 26], [15, 46], [15, 37], [14, 9], [48, 24], [45, 36], [9, 40], [34, 42], [9, 10], [43, 22], [13, 27], [45, 57], [46, 32], [44, 25], [7, 15], [7, 25], [43, 13], [23, 16], [14, 35], [14, 22], [47, 22], [0, 3], [8, 8], [41, 0], [51, 6], [30, 36], [22, 55], [20, 38], [34, 57], [10, 18], [53, 6], [2, 48], [9, 15], [33, 33], [45, 11], [19, 8], [10, 5], [54, 42], [8, 16], [20, 39], [6, 17], [5, 27], [59, 13], [56, 11], [42, 10], [11, 6], [50, 30], [59, 39], [42, 28], [33, 14], [22, 12], [16, 34], [34, 40], [6, 30], [15, 59], [11, 3], [15, 11], [11, 37], [36, 5], [24, 32], [48, 25], [37, 53], [53, 25], [21, 8], [42, 11], [3, 51], [47, 31], [6, 54], [52, 43], [13, 31], [22, 49], [52, 30], [22, 50], [17, 19], [29, 14], [9, 56], [5, 19], [33, 0], [12, 42], [17, 51], [33, 8], [17, 28], [30, 6], [56, 27], [41, 28], [22, 20], [32, 51], [44, 2], [58, 15], [58, 38], [16, 51], [22, 35], [21, 17], [23, 4], [23, 40], [51, 19], [40, 39], [26, 24], [42, 6], [23, 48], [0, 7], [53, 54], [18, 28], [19, 52], [27, 58], [17, 7], [31, 1], [11, 5], [36, 28], [48, 1], [59, 27], [30, 7], [59, 51], [53, 36], [40, 5], [54, 23], [6, 53], [48, 46], [31, 9], [51, 18], [33, 23], [31, 42], [55, 49], [29, 41], [59, 0], [54, 35], [41, 57], [2, 21], [59, 32], [15, 12], [15, 49], [47, 8], [28, 22], [14, 21], [45, 58], [13, 11], [49, 35], [54, 0], [12, 6], [56, 57], [27, 31], [50, 56], [46, 3], [27, 3], [54, 22], [41, 3], [35, 56], [23, 46], [9, 35], [6, 50], [38, 14], [10, 57], [2, 25], [32, 25], [32, 8], [22, 11], [45, 55], [25, 32], [43, 21], [18, 22], [53, 59], [0, 58], [51, 8], [6, 8], [25, 37], [46, 47], [14, 50], [15, 4], [37, 43], [7, 6], [22, 23], [46, 29], [34, 17], [6, 23], [4, 3], [13, 38], [24, 17], [18, 0], [5, 41], [34, 55], [57, 53], [44, 22], [43, 23], [45, 2], [54, 50], [22, 6], [16, 17], [10, 44], [40, 27], [38, 49], [37, 4], [43, 56], [42, 57], [26, 51], [8, 29], [47, 27], [4, 12], [0, 46], [30, 40], [4, 55], [49, 28], [18, 26], [21, 39], [14, 3], [18, 3], [49, 10], [19, 33], [25, 48], [30, 3], [37, 58], [43, 20], [3, 28], [41, 20], [6, 57], [20, 46], [7, 47]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_8", - "sat": "def sat(nodes: List[int], size=1, edges=[[3, 2], [1, 3], [4, 2], [3, 3], [4, 3], [3, 1], [3, 4], [2, 3], [2, 1], [2, 0]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=1, edges=[[3, 2], [1, 3], [4, 2], [3, 3], [4, 3], [3, 1], [3, 4], [2, 3], [2, 1], [2, 0]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "PlantedClique_9", - "sat": "def sat(nodes: List[int], size=4, edges=[[10, 14], [3, 0], [7, 9], [10, 4], [0, 15], [0, 6], [7, 1], [6, 9], [3, 10], [11, 15], [14, 5], [2, 0], [5, 5], [1, 8], [4, 6], [7, 10], [10, 3], [5, 6], [11, 6], [8, 4], [0, 14], [13, 5], [15, 6], [2, 12], [15, 7], [15, 3], [12, 4], [4, 8], [11, 11], [3, 1], [7, 6], [4, 14], [7, 0], [8, 0], [5, 12], [9, 8], [5, 4], [5, 8], [1, 15], [6, 10], [8, 12], [3, 11], [3, 6], [12, 8], [2, 3], [1, 9], [13, 8], [0, 0], [2, 13], [12, 3], [3, 2], [3, 7], [0, 7], [1, 14], [15, 11], [11, 4], [9, 7], [1, 2], [5, 13], [10, 10], [9, 5], [12, 13], [7, 12], [6, 0], [3, 14], [7, 13], [5, 14], [7, 14], [12, 5], [4, 10], [2, 6]]):\n \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", - "sols": [ - "def sol(size=4, edges=[[10, 14], [3, 0], [7, 9], [10, 4], [0, 15], [0, 6], [7, 1], [6, 9], [3, 10], [11, 15], [14, 5], [2, 0], [5, 5], [1, 8], [4, 6], [7, 10], [10, 3], [5, 6], [11, 6], [8, 4], [0, 14], [13, 5], [15, 6], [2, 12], [15, 7], [15, 3], [12, 4], [4, 8], [11, 11], [3, 1], [7, 6], [4, 14], [7, 0], [8, 0], [5, 12], [9, 8], [5, 4], [5, 8], [1, 15], [6, 10], [8, 12], [3, 11], [3, 6], [12, 8], [2, 3], [1, 9], [13, 8], [0, 0], [2, 13], [12, 3], [3, 2], [3, 7], [0, 7], [1, 14], [15, 11], [11, 4], [9, 7], [1, 2], [5, 13], [10, 10], [9, 5], [12, 13], [7, 12], [6, 0], [3, 14], [7, 13], [5, 14], [7, 14], [12, 5], [4, 10], [2, 6]]): # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" - ], - "module": "graphs", - "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_0", - "sat": "def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_1", - "sat": "def sat(path: List[int], weights=[{3: 210, 0: 513, 1: 66, 5: 612}, {0: 794, 1: 111, 3: 598}, {4: 295, 0: 601}, {}, {3: 452, 0: 689, 5: 124, 1: 406}, {2: 289, 5: 660, 3: 498}], bound=66):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{3: 210, 0: 513, 1: 66, 5: 612}, {0: 794, 1: 111, 3: 598}, {4: 295, 0: 601}, {}, {3: 452, 0: 689, 5: 124, 1: 406}, {2: 289, 5: 660, 3: 498}], bound=66): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_2", - "sat": "def sat(path: List[int], weights=[{25: 594, 24: 349}, {}, {29: 745}, {}, {7: 245}, {9: 384}, {1: 490, 21: 253, 22: 904, 13: 526}, {4: 452, 27: 179, 28: 673}, {22: 30, 29: 307, 8: 104}, {12: 399, 0: 792}, {}, {}, {20: 349, 6: 53}, {}, {}, {}, {14: 223}, {23: 705}, {13: 903, 21: 159}, {}, {27: 144, 28: 181}, {26: 922, 20: 241}, {}, {24: 966, 29: 78}, {26: 107}, {1: 121}, {18: 898, 0: 280, 12: 425}, {}, {18: 750, 25: 440, 28: 152, 29: 109, 6: 330}, {23: 298}], bound=715):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{25: 594, 24: 349}, {}, {29: 745}, {}, {7: 245}, {9: 384}, {1: 490, 21: 253, 22: 904, 13: 526}, {4: 452, 27: 179, 28: 673}, {22: 30, 29: 307, 8: 104}, {12: 399, 0: 792}, {}, {}, {20: 349, 6: 53}, {}, {}, {}, {14: 223}, {23: 705}, {13: 903, 21: 159}, {}, {27: 144, 28: 181}, {26: 922, 20: 241}, {}, {24: 966, 29: 78}, {26: 107}, {1: 121}, {18: 898, 0: 280, 12: 425}, {}, {18: 750, 25: 440, 28: 152, 29: 109, 6: 330}, {23: 298}], bound=715): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_3", - "sat": "def sat(path: List[int], weights=[{1: 239}, {0: 602, 2: 280}, {2: 293, 0: 816, 3: 925}, {}], bound=239):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{1: 239}, {0: 602, 2: 280}, {2: 293, 0: 816, 3: 925}, {}], bound=239): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_4", - "sat": "def sat(path: List[int], weights=[{1: 996, 2: 237, 4: 264}, {4: 329, 5: 12, 2: 542, 0: 419}, {2: 170, 6: 339, 5: 211}, {1: 714, 5: 885, 3: 640}, {5: 652, 4: 3, 3: 26, 6: 74}, {0: 647, 5: 346}, {2: 297, 6: 358, 3: 636, 0: 722, 4: 942}], bound=996):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{1: 996, 2: 237, 4: 264}, {4: 329, 5: 12, 2: 542, 0: 419}, {2: 170, 6: 339, 5: 211}, {1: 714, 5: 885, 3: 640}, {5: 652, 4: 3, 3: 26, 6: 74}, {0: 647, 5: 346}, {2: 297, 6: 358, 3: 636, 0: 722, 4: 942}], bound=996): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_5", - "sat": "def sat(path: List[int], weights=[{0: 634, 1: 558}, {2: 606}, {0: 181, 2: 776, 1: 103}], bound=558):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{0: 634, 1: 558}, {2: 606}, {0: 181, 2: 776, 1: 103}], bound=558): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_6", - "sat": "def sat(path: List[int], weights=[{3: 832, 0: 192, 4: 70}, {1: 270, 5: 579, 4: 901, 0: 42}, {3: 139, 1: 891, 2: 912, 5: 370}, {0: 965, 4: 156}, {1: 960, 5: 235}, {3: 174, 5: 920}], bound=1030):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{3: 832, 0: 192, 4: 70}, {1: 270, 5: 579, 4: 901, 0: 42}, {3: 139, 1: 891, 2: 912, 5: 370}, {0: 965, 4: 156}, {1: 960, 5: 235}, {3: 174, 5: 920}], bound=1030): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_7", - "sat": "def sat(path: List[int], weights=[{1: 577, 0: 315}, {0: 976}], bound=577):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{1: 577, 0: 315}, {0: 976}], bound=577): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_8", - "sat": "def sat(path: List[int], weights=[{3: 422, 0: 36, 2: 186}, {3: 821, 2: 896, 1: 942, 0: 824}, {3: 214}, {1: 951}], bound=1351):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{3: 422, 0: 36, 2: 186}, {3: 821, 2: 896, 1: 942, 0: 824}, {3: 214}, {1: 951}], bound=1351): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortestPath_9", - "sat": "def sat(path: List[int], weights=[{34: 621, 43: 275, 54: 343, 22: 186, 41: 960, 21: 989}, {51: 539}, {43: 426}, {21: 997, 5: 385, 48: 51, 50: 423, 38: 840}, {2: 612, 1: 720, 11: 934, 52: 223}, {15: 757}, {8: 736, 18: 512, 46: 133}, {6: 5, 51: 842, 56: 409}, {59: 151, 17: 797}, {38: 475, 6: 999, 4: 840}, {49: 412, 33: 833, 44: 644}, {55: 207, 36: 435, 49: 950, 29: 281}, {39: 999, 31: 374, 53: 259, 41: 617}, {39: 121, 14: 234, 45: 602}, {52: 151, 3: 577, 27: 384}, {52: 226}, {54: 745, 6: 236, 3: 214}, {23: 473}, {37: 823, 35: 160, 9: 2}, {32: 224}, {50: 677, 6: 545, 10: 232, 23: 66, 12: 927}, {57: 49, 3: 415}, {9: 567, 5: 489, 21: 946}, {45: 370, 28: 351, 49: 101}, {41: 223, 55: 244, 22: 266, 19: 907, 45: 460}, {37: 553}, {24: 210, 5: 429, 22: 38, 30: 13}, {}, {6: 783, 43: 761, 16: 730, 28: 573, 5: 83, 19: 399}, {58: 871}, {11: 307, 22: 519, 29: 991, 52: 676, 21: 129, 42: 154, 40: 544, 38: 755}, {25: 847, 32: 390}, {26: 580, 52: 846, 22: 483, 46: 682, 44: 965, 51: 749}, {4: 81, 11: 58, 17: 393, 13: 851, 38: 314}, {14: 614, 29: 328}, {2: 682, 32: 536, 49: 736, 5: 470}, {3: 378, 34: 99, 30: 285}, {0: 767}, {36: 827, 50: 591, 7: 348, 25: 366, 4: 614}, {}, {5: 707, 38: 673, 17: 859}, {40: 773, 2: 418, 49: 932}, {39: 670, 13: 533, 12: 72, 8: 833}, {40: 573, 4: 255, 27: 743, 48: 520}, {35: 293, 11: 189, 21: 714}, {20: 766, 51: 713, 56: 383, 53: 682, 3: 957}, {47: 755, 46: 681, 0: 260, 48: 949, 37: 234, 15: 83}, {2: 640, 36: 495, 29: 544, 31: 799, 59: 612}, {16: 455, 27: 230, 36: 483, 23: 732, 20: 435, 7: 656, 31: 196}, {10: 264, 31: 493, 0: 329}, {33: 756, 18: 577, 3: 112, 28: 961, 0: 150}, {7: 732, 37: 294}, {58: 162, 55: 968, 15: 695, 11: 280}, {36: 408}, {26: 27, 36: 639, 6: 725, 24: 228}, {48: 673, 40: 113, 22: 114, 58: 835}, {49: 519, 25: 556, 35: 910, 56: 541, 53: 623}, {50: 2, 31: 375}, {56: 279, 55: 438, 15: 732, 20: 346, 23: 487}, {42: 250, 9: 585, 43: 843, 28: 684}], bound=1250):\n \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", - "sols": [ - "def sol(weights=[{34: 621, 43: 275, 54: 343, 22: 186, 41: 960, 21: 989}, {51: 539}, {43: 426}, {21: 997, 5: 385, 48: 51, 50: 423, 38: 840}, {2: 612, 1: 720, 11: 934, 52: 223}, {15: 757}, {8: 736, 18: 512, 46: 133}, {6: 5, 51: 842, 56: 409}, {59: 151, 17: 797}, {38: 475, 6: 999, 4: 840}, {49: 412, 33: 833, 44: 644}, {55: 207, 36: 435, 49: 950, 29: 281}, {39: 999, 31: 374, 53: 259, 41: 617}, {39: 121, 14: 234, 45: 602}, {52: 151, 3: 577, 27: 384}, {52: 226}, {54: 745, 6: 236, 3: 214}, {23: 473}, {37: 823, 35: 160, 9: 2}, {32: 224}, {50: 677, 6: 545, 10: 232, 23: 66, 12: 927}, {57: 49, 3: 415}, {9: 567, 5: 489, 21: 946}, {45: 370, 28: 351, 49: 101}, {41: 223, 55: 244, 22: 266, 19: 907, 45: 460}, {37: 553}, {24: 210, 5: 429, 22: 38, 30: 13}, {}, {6: 783, 43: 761, 16: 730, 28: 573, 5: 83, 19: 399}, {58: 871}, {11: 307, 22: 519, 29: 991, 52: 676, 21: 129, 42: 154, 40: 544, 38: 755}, {25: 847, 32: 390}, {26: 580, 52: 846, 22: 483, 46: 682, 44: 965, 51: 749}, {4: 81, 11: 58, 17: 393, 13: 851, 38: 314}, {14: 614, 29: 328}, {2: 682, 32: 536, 49: 736, 5: 470}, {3: 378, 34: 99, 30: 285}, {0: 767}, {36: 827, 50: 591, 7: 348, 25: 366, 4: 614}, {}, {5: 707, 38: 673, 17: 859}, {40: 773, 2: 418, 49: 932}, {39: 670, 13: 533, 12: 72, 8: 833}, {40: 573, 4: 255, 27: 743, 48: 520}, {35: 293, 11: 189, 21: 714}, {20: 766, 51: 713, 56: 383, 53: 682, 3: 957}, {47: 755, 46: 681, 0: 260, 48: 949, 37: 234, 15: 83}, {2: 640, 36: 495, 29: 544, 31: 799, 59: 612}, {16: 455, 27: 230, 36: 483, 23: 732, 20: 435, 7: 656, 31: 196}, {10: 264, 31: 493, 0: 329}, {33: 756, 18: 577, 3: 112, 28: 961, 0: 150}, {7: 732, 37: 294}, {58: 162, 55: 968, 15: 695, 11: 280}, {36: 408}, {26: 27, 36: 639, 6: 725, 24: 228}, {48: 673, 40: 113, 22: 114, 58: 835}, {49: 519, 25: 556, 35: 910, 56: 541, 53: 623}, {50: 2, 31: 375}, {56: 279, 55: 438, 15: 732, 20: 346, 23: 487}, {42: 250, 9: 585, 43: 843, 28: 684}], bound=1250): # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_0", - "sat": "def sat(path: List[int], edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_1", - "sat": "def sat(path: List[int], edges=[[12, 4], [33, 15], [37, 12], [11, 1], [34, 19], [42, 36], [2, 38], [6, 25], [29, 25], [30, 6], [16, 31], [10, 41], [15, 2], [3, 19], [1, 26], [17, 17], [19, 4], [0, 6], [42, 5], [11, 13], [22, 15], [39, 11], [35, 34], [39, 20], [7, 31], [38, 27], [9, 30], [31, 25], [0, 9], [13, 34], [31, 34], [19, 42], [37, 32], [4, 13], [11, 43], [14, 0], [22, 41], [20, 17], [0, 15], [13, 4], [20, 6], [34, 42], [42, 10], [32, 19], [41, 8], [26, 42], [0, 13], [28, 42], [9, 0], [32, 26], [6, 4], [27, 19], [37, 9], [7, 6], [25, 14], [23, 14], [31, 39], [18, 27], [34, 36], [24, 16], [24, 31], [16, 17], [2, 4], [34, 40], [28, 6], [41, 9], [17, 18], [43, 11], [11, 39], [43, 29], [1, 19], [27, 27], [4, 42], [0, 16], [16, 14], [40, 22], [22, 22], [38, 16], [3, 34], [33, 23], [2, 18], [3, 11], [4, 5], [18, 3], [23, 11], [41, 22], [7, 26], [31, 42], [35, 33], [15, 28], [34, 10], [36, 3], [9, 38], [17, 5], [3, 9], [37, 21], [36, 1], [25, 6], [22, 12], [42, 3], [16, 32], [0, 11], [24, 33], [15, 31], [18, 34], [11, 8], [30, 41], [19, 19], [4, 11], [22, 16], [1, 13], [6, 22], [12, 30], [19, 15], [3, 21], [38, 29], [32, 39], [1, 17], [16, 20], [10, 39], [32, 27], [37, 6], [18, 18], [22, 32], [31, 32], [24, 32], [22, 25], [38, 18], [38, 21], [39, 12], [9, 17], [10, 42], [29, 36], [34, 23], [27, 29], [17, 24], [24, 28], [31, 23], [28, 7], [5, 2], [24, 26], [27, 13], [43, 19], [37, 36], [2, 13], [10, 11], [30, 11], [29, 32], [4, 24], [17, 27], [21, 2], [24, 43], [26, 37], [16, 6], [43, 35], [42, 27], [26, 12], [39, 3], [38, 25], [20, 5], [36, 8], [25, 42], [27, 40], [39, 23], [6, 12], [27, 32], [12, 34], [2, 5], [40, 35], [15, 12], [22, 29], [21, 11], [0, 22], [13, 23], [27, 4], [35, 24], [32, 29], [4, 14], [9, 7], [32, 11], [11, 26], [26, 41], [2, 16], [38, 23], [30, 29], [6, 31], [1, 34], [4, 39], [24, 3], [25, 22], [9, 14], [33, 26], [34, 38], [35, 29], [32, 38], [5, 42], [42, 24], [15, 38], [41, 14], [39, 9], [4, 36], [21, 24], [36, 9]], u=14, v=1, bound=4):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[12, 4], [33, 15], [37, 12], [11, 1], [34, 19], [42, 36], [2, 38], [6, 25], [29, 25], [30, 6], [16, 31], [10, 41], [15, 2], [3, 19], [1, 26], [17, 17], [19, 4], [0, 6], [42, 5], [11, 13], [22, 15], [39, 11], [35, 34], [39, 20], [7, 31], [38, 27], [9, 30], [31, 25], [0, 9], [13, 34], [31, 34], [19, 42], [37, 32], [4, 13], [11, 43], [14, 0], [22, 41], [20, 17], [0, 15], [13, 4], [20, 6], [34, 42], [42, 10], [32, 19], [41, 8], [26, 42], [0, 13], [28, 42], [9, 0], [32, 26], [6, 4], [27, 19], [37, 9], [7, 6], [25, 14], [23, 14], [31, 39], [18, 27], [34, 36], [24, 16], [24, 31], [16, 17], [2, 4], [34, 40], [28, 6], [41, 9], [17, 18], [43, 11], [11, 39], [43, 29], [1, 19], [27, 27], [4, 42], [0, 16], [16, 14], [40, 22], [22, 22], [38, 16], [3, 34], [33, 23], [2, 18], [3, 11], [4, 5], [18, 3], [23, 11], [41, 22], [7, 26], [31, 42], [35, 33], [15, 28], [34, 10], [36, 3], [9, 38], [17, 5], [3, 9], [37, 21], [36, 1], [25, 6], [22, 12], [42, 3], [16, 32], [0, 11], [24, 33], [15, 31], [18, 34], [11, 8], [30, 41], [19, 19], [4, 11], [22, 16], [1, 13], [6, 22], [12, 30], [19, 15], [3, 21], [38, 29], [32, 39], [1, 17], [16, 20], [10, 39], [32, 27], [37, 6], [18, 18], [22, 32], [31, 32], [24, 32], [22, 25], [38, 18], [38, 21], [39, 12], [9, 17], [10, 42], [29, 36], [34, 23], [27, 29], [17, 24], [24, 28], [31, 23], [28, 7], [5, 2], [24, 26], [27, 13], [43, 19], [37, 36], [2, 13], [10, 11], [30, 11], [29, 32], [4, 24], [17, 27], [21, 2], [24, 43], [26, 37], [16, 6], [43, 35], [42, 27], [26, 12], [39, 3], [38, 25], [20, 5], [36, 8], [25, 42], [27, 40], [39, 23], [6, 12], [27, 32], [12, 34], [2, 5], [40, 35], [15, 12], [22, 29], [21, 11], [0, 22], [13, 23], [27, 4], [35, 24], [32, 29], [4, 14], [9, 7], [32, 11], [11, 26], [26, 41], [2, 16], [38, 23], [30, 29], [6, 31], [1, 34], [4, 39], [24, 3], [25, 22], [9, 14], [33, 26], [34, 38], [35, 29], [32, 38], [5, 42], [42, 24], [15, 38], [41, 14], [39, 9], [4, 36], [21, 24], [36, 9]], u=14, v=1, bound=4): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_2", - "sat": "def sat(path: List[int], edges=[[2, 6], [6, 2], [2, 5], [4, 7], [4, 1], [0, 2], [3, 3], [6, 1], [4, 0], [1, 3], [5, 2], [4, 2], [6, 7], [2, 2], [2, 3], [4, 4], [5, 0], [0, 7], [4, 3], [6, 4], [0, 0], [3, 0], [2, 7], [1, 7], [3, 2], [1, 2], [2, 4], [7, 5]], u=1, v=2, bound=2):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[2, 6], [6, 2], [2, 5], [4, 7], [4, 1], [0, 2], [3, 3], [6, 1], [4, 0], [1, 3], [5, 2], [4, 2], [6, 7], [2, 2], [2, 3], [4, 4], [5, 0], [0, 7], [4, 3], [6, 4], [0, 0], [3, 0], [2, 7], [1, 7], [3, 2], [1, 2], [2, 4], [7, 5]], u=1, v=2, bound=2): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_3", - "sat": "def sat(path: List[int], edges=[[6, 0], [6, 2], [6, 5], [6, 4], [1, 4], [4, 3], [5, 3], [4, 4], [3, 1], [4, 6], [4, 2], [0, 2], [6, 6], [2, 3], [1, 0], [1, 5], [0, 0], [5, 4], [0, 1], [1, 2], [0, 4], [2, 5], [3, 0]], u=4, v=2, bound=2):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[6, 0], [6, 2], [6, 5], [6, 4], [1, 4], [4, 3], [5, 3], [4, 4], [3, 1], [4, 6], [4, 2], [0, 2], [6, 6], [2, 3], [1, 0], [1, 5], [0, 0], [5, 4], [0, 1], [1, 2], [0, 4], [2, 5], [3, 0]], u=4, v=2, bound=2): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_4", - "sat": "def sat(path: List[int], edges=[[1, 1], [2, 0], [1, 0], [2, 2]], u=1, v=1, bound=1):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[1, 1], [2, 0], [1, 0], [2, 2]], u=1, v=1, bound=1): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_5", - "sat": "def sat(path: List[int], edges=[[1, 3], [3, 3], [2, 3], [0, 1], [3, 0], [3, 1], [0, 2], [1, 0], [1, 1]], u=1, v=1, bound=1):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[1, 3], [3, 3], [2, 3], [0, 1], [3, 0], [3, 1], [0, 2], [1, 0], [1, 1]], u=1, v=1, bound=1): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_6", - "sat": "def sat(path: List[int], edges=[[5, 8], [5, 5], [0, 1], [4, 3], [1, 7], [2, 2], [2, 7], [6, 8], [6, 2], [4, 6], [7, 1], [2, 8], [7, 8], [0, 4], [5, 4], [0, 6], [6, 0], [0, 3], [4, 4], [6, 7], [2, 6], [7, 0], [0, 8], [1, 3], [0, 5], [3, 1], [4, 0], [2, 5], [7, 5], [1, 5], [7, 2], [7, 6]], u=0, v=0, bound=1):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[5, 8], [5, 5], [0, 1], [4, 3], [1, 7], [2, 2], [2, 7], [6, 8], [6, 2], [4, 6], [7, 1], [2, 8], [7, 8], [0, 4], [5, 4], [0, 6], [6, 0], [0, 3], [4, 4], [6, 7], [2, 6], [7, 0], [0, 8], [1, 3], [0, 5], [3, 1], [4, 0], [2, 5], [7, 5], [1, 5], [7, 2], [7, 6]], u=0, v=0, bound=1): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_7", - "sat": "def sat(path: List[int], edges=[[1, 0], [6, 1], [0, 8], [3, 6], [7, 7], [0, 6], [9, 5], [7, 3], [7, 4], [1, 8], [7, 6], [4, 2], [5, 9], [4, 5], [9, 9], [0, 4], [2, 5], [9, 3], [1, 3], [1, 5], [5, 4], [4, 1], [0, 0], [8, 5], [9, 6], [9, 1], [2, 3], [8, 4], [0, 3], [5, 0], [5, 3], [6, 9], [6, 6], [5, 2], [6, 8]], u=7, v=8, bound=3):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[1, 0], [6, 1], [0, 8], [3, 6], [7, 7], [0, 6], [9, 5], [7, 3], [7, 4], [1, 8], [7, 6], [4, 2], [5, 9], [4, 5], [9, 9], [0, 4], [2, 5], [9, 3], [1, 3], [1, 5], [5, 4], [4, 1], [0, 0], [8, 5], [9, 6], [9, 1], [2, 3], [8, 4], [0, 3], [5, 0], [5, 3], [6, 9], [6, 6], [5, 2], [6, 8]], u=7, v=8, bound=3): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_8", - "sat": "def sat(path: List[int], edges=[[0, 4], [2, 7], [2, 5], [0, 6], [4, 9], [0, 5], [9, 1], [8, 4], [6, 4], [2, 0], [4, 1], [9, 5], [8, 9], [4, 8], [8, 1], [1, 4], [2, 8], [5, 8], [9, 4], [7, 0], [8, 3], [6, 8], [9, 3], [4, 3], [7, 8], [7, 4], [1, 8], [6, 2], [3, 8], [7, 9], [1, 5], [5, 0], [9, 6], [6, 0], [1, 7], [8, 2], [4, 7]], u=3, v=5, bound=4):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[0, 4], [2, 7], [2, 5], [0, 6], [4, 9], [0, 5], [9, 1], [8, 4], [6, 4], [2, 0], [4, 1], [9, 5], [8, 9], [4, 8], [8, 1], [1, 4], [2, 8], [5, 8], [9, 4], [7, 0], [8, 3], [6, 8], [9, 3], [4, 3], [7, 8], [7, 4], [1, 8], [6, 2], [3, 8], [7, 9], [1, 5], [5, 0], [9, 6], [6, 0], [1, 7], [8, 2], [4, 7]], u=3, v=5, bound=4): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "UnweightedShortestPath_9", - "sat": "def sat(path: List[int], edges=[[14, 24], [21, 5], [20, 1], [2, 26], [2, 23], [19, 17], [14, 8], [9, 20], [15, 16], [10, 9], [1, 5], [22, 26], [11, 9], [22, 24], [18, 23], [14, 5], [3, 7], [26, 6], [3, 10], [19, 21], [3, 14], [17, 8], [10, 25], [5, 23], [23, 15], [22, 16], [13, 24], [17, 0], [20, 8], [23, 3], [7, 13], [13, 13], [20, 26], [6, 24], [21, 18], [8, 22], [0, 6], [16, 22], [22, 14], [6, 25], [23, 0], [11, 21], [17, 14], [14, 25], [16, 11], [5, 14], [23, 5], [6, 17], [5, 12], [17, 9], [2, 14], [3, 20], [4, 12], [9, 16], [18, 21], [24, 14], [22, 11], [18, 19], [23, 10], [25, 7], [13, 5], [7, 8], [6, 23], [22, 17], [18, 13], [2, 1], [14, 0], [8, 8], [24, 1], [0, 19], [3, 6], [13, 10], [17, 3], [0, 14], [15, 15], [13, 6], [15, 13], [15, 10], [22, 4], [25, 21], [14, 16], [12, 7], [18, 14], [16, 20], [22, 23], [20, 16], [17, 5], [8, 0], [2, 7], [20, 14], [5, 25], [1, 26], [19, 11], [24, 20], [4, 19], [0, 7], [13, 25], [12, 5], [4, 5], [8, 26], [0, 1], [24, 7], [15, 8], [0, 24], [22, 10], [19, 14], [8, 21], [5, 17], [20, 10], [6, 12], [20, 24], [3, 25], [20, 15], [1, 15], [24, 15], [25, 11], [4, 16], [9, 24], [14, 9]], u=14, v=24, bound=2):\n \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", - "sols": [ - "def sol(edges=[[14, 24], [21, 5], [20, 1], [2, 26], [2, 23], [19, 17], [14, 8], [9, 20], [15, 16], [10, 9], [1, 5], [22, 26], [11, 9], [22, 24], [18, 23], [14, 5], [3, 7], [26, 6], [3, 10], [19, 21], [3, 14], [17, 8], [10, 25], [5, 23], [23, 15], [22, 16], [13, 24], [17, 0], [20, 8], [23, 3], [7, 13], [13, 13], [20, 26], [6, 24], [21, 18], [8, 22], [0, 6], [16, 22], [22, 14], [6, 25], [23, 0], [11, 21], [17, 14], [14, 25], [16, 11], [5, 14], [23, 5], [6, 17], [5, 12], [17, 9], [2, 14], [3, 20], [4, 12], [9, 16], [18, 21], [24, 14], [22, 11], [18, 19], [23, 10], [25, 7], [13, 5], [7, 8], [6, 23], [22, 17], [18, 13], [2, 1], [14, 0], [8, 8], [24, 1], [0, 19], [3, 6], [13, 10], [17, 3], [0, 14], [15, 15], [13, 6], [15, 13], [15, 10], [22, 4], [25, 21], [14, 16], [12, 7], [18, 14], [16, 20], [22, 23], [20, 16], [17, 5], [8, 0], [2, 7], [20, 14], [5, 25], [1, 26], [19, 11], [24, 20], [4, 19], [0, 7], [13, 25], [12, 5], [4, 5], [8, 26], [0, 1], [24, 7], [15, 8], [0, 24], [22, 10], [19, 14], [8, 21], [5, 17], [20, 10], [6, 12], [20, 24], [3, 25], [20, 15], [1, 15], [24, 15], [25, 11], [4, 16], [9, 24], [14, 9]], u=14, v=24, bound=2): # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" - ], - "module": "graphs", - "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_0", - "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_1", - "sat": "def sat(path: List[int], edges=[[16, 8], [13, 33], [29, 37], [25, 10], [3, 33], [43, 10], [19, 9], [26, 16], [0, 9], [18, 36], [40, 32], [24, 10], [25, 35], [15, 14], [18, 2], [17, 5], [15, 26], [28, 28], [4, 39], [26, 9], [35, 22], [42, 11], [44, 13], [6, 34], [33, 0], [36, 34], [41, 34], [31, 1], [41, 27], [20, 43], [30, 33], [15, 18], [8, 20], [31, 14], [21, 33], [40, 28], [35, 39], [19, 14], [35, 10], [3, 34], [14, 11], [34, 36], [29, 3], [20, 33], [27, 14], [5, 29], [15, 6], [21, 20], [36, 1], [30, 40], [44, 6], [24, 43], [24, 30], [3, 16], [8, 34], [15, 36], [33, 36], [19, 17], [35, 17], [20, 29], [0, 27], [36, 38], [1, 0], [43, 18], [5, 36], [22, 10], [5, 32], [11, 34], [4, 15], [4, 9], [4, 6], [24, 12], [8, 27], [42, 38], [25, 2], [2, 12], [1, 34], [36, 22], [24, 42], [4, 18], [30, 13], [16, 44], [4, 21], [22, 35], [33, 32], [24, 26], [21, 44]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[16, 8], [13, 33], [29, 37], [25, 10], [3, 33], [43, 10], [19, 9], [26, 16], [0, 9], [18, 36], [40, 32], [24, 10], [25, 35], [15, 14], [18, 2], [17, 5], [15, 26], [28, 28], [4, 39], [26, 9], [35, 22], [42, 11], [44, 13], [6, 34], [33, 0], [36, 34], [41, 34], [31, 1], [41, 27], [20, 43], [30, 33], [15, 18], [8, 20], [31, 14], [21, 33], [40, 28], [35, 39], [19, 14], [35, 10], [3, 34], [14, 11], [34, 36], [29, 3], [20, 33], [27, 14], [5, 29], [15, 6], [21, 20], [36, 1], [30, 40], [44, 6], [24, 43], [24, 30], [3, 16], [8, 34], [15, 36], [33, 36], [19, 17], [35, 17], [20, 29], [0, 27], [36, 38], [1, 0], [43, 18], [5, 36], [22, 10], [5, 32], [11, 34], [4, 15], [4, 9], [4, 6], [24, 12], [8, 27], [42, 38], [25, 2], [2, 12], [1, 34], [36, 22], [24, 42], [4, 18], [30, 13], [16, 44], [4, 21], [22, 35], [33, 32], [24, 26], [21, 44]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_2", - "sat": "def sat(path: List[int], edges=[[0, 0]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[0, 0]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_3", - "sat": "def sat(path: List[int], edges=[[2, 33], [39, 59], [22, 21], [55, 39], [34, 13], [28, 62], [34, 56], [41, 23], [52, 39], [27, 62], [19, 12], [14, 63], [48, 1], [53, 1], [47, 55], [43, 35], [13, 51], [18, 30], [7, 17], [25, 52], [35, 46], [16, 45], [7, 22], [42, 40], [35, 41], [21, 52], [35, 43], [22, 30], [20, 47], [48, 25], [32, 11], [38, 35], [39, 35], [34, 62], [19, 32], [15, 51], [62, 29], [54, 26], [1, 6], [42, 51], [26, 62], [18, 8], [47, 40], [30, 41], [42, 15], [35, 36], [12, 55], [38, 53], [52, 37], [4, 44], [13, 61], [2, 58], [9, 48], [2, 11], [52, 0], [11, 35], [33, 7], [49, 40], [21, 46], [1, 30], [60, 34], [36, 46], [8, 52], [43, 58], [53, 63], [61, 16], [50, 16], [33, 44], [23, 26], [27, 16], [52, 18], [59, 1], [29, 44], [37, 57], [25, 2], [3, 15], [33, 19], [22, 6], [59, 51], [58, 32], [46, 37], [15, 9], [1, 35], [48, 6], [15, 59], [58, 28], [6, 24], [4, 38], [37, 20], [52, 28], [43, 40], [28, 39], [58, 31], [62, 35], [63, 11], [24, 40], [44, 38], [0, 44], [57, 11], [0, 16], [41, 1], [62, 55], [8, 51], [5, 8], [46, 26], [40, 6], [45, 42], [24, 32], [19, 31], [6, 55], [30, 2], [43, 57], [25, 48], [53, 31], [29, 13], [63, 39], [37, 46], [32, 40], [16, 16], [53, 59], [11, 57], [33, 20], [19, 11], [47, 51], [50, 15], [19, 36]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[2, 33], [39, 59], [22, 21], [55, 39], [34, 13], [28, 62], [34, 56], [41, 23], [52, 39], [27, 62], [19, 12], [14, 63], [48, 1], [53, 1], [47, 55], [43, 35], [13, 51], [18, 30], [7, 17], [25, 52], [35, 46], [16, 45], [7, 22], [42, 40], [35, 41], [21, 52], [35, 43], [22, 30], [20, 47], [48, 25], [32, 11], [38, 35], [39, 35], [34, 62], [19, 32], [15, 51], [62, 29], [54, 26], [1, 6], [42, 51], [26, 62], [18, 8], [47, 40], [30, 41], [42, 15], [35, 36], [12, 55], [38, 53], [52, 37], [4, 44], [13, 61], [2, 58], [9, 48], [2, 11], [52, 0], [11, 35], [33, 7], [49, 40], [21, 46], [1, 30], [60, 34], [36, 46], [8, 52], [43, 58], [53, 63], [61, 16], [50, 16], [33, 44], [23, 26], [27, 16], [52, 18], [59, 1], [29, 44], [37, 57], [25, 2], [3, 15], [33, 19], [22, 6], [59, 51], [58, 32], [46, 37], [15, 9], [1, 35], [48, 6], [15, 59], [58, 28], [6, 24], [4, 38], [37, 20], [52, 28], [43, 40], [28, 39], [58, 31], [62, 35], [63, 11], [24, 40], [44, 38], [0, 44], [57, 11], [0, 16], [41, 1], [62, 55], [8, 51], [5, 8], [46, 26], [40, 6], [45, 42], [24, 32], [19, 31], [6, 55], [30, 2], [43, 57], [25, 48], [53, 31], [29, 13], [63, 39], [37, 46], [32, 40], [16, 16], [53, 59], [11, 57], [33, 20], [19, 11], [47, 51], [50, 15], [19, 36]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_4", - "sat": "def sat(path: List[int], edges=[[3, 5], [2, 1], [4, 5], [3, 6], [6, 7], [5, 3], [4, 3], [6, 2], [5, 2], [7, 0], [3, 4], [0, 5], [0, 0], [1, 0], [0, 2], [3, 1]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[3, 5], [2, 1], [4, 5], [3, 6], [6, 7], [5, 3], [4, 3], [6, 2], [5, 2], [7, 0], [3, 4], [0, 5], [0, 0], [1, 0], [0, 2], [3, 1]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_5", - "sat": "def sat(path: List[int], edges=[[12, 0], [24, 29], [2, 1], [18, 27], [13, 11], [17, 1], [1, 19], [3, 6], [0, 30], [19, 26], [5, 9], [6, 13], [30, 19], [30, 26], [15, 27], [10, 11], [4, 8], [0, 21], [18, 0], [1, 16], [26, 30], [17, 19], [27, 9], [11, 29], [30, 14], [12, 3], [3, 18], [26, 7], [15, 4], [10, 14], [10, 30], [23, 2], [30, 6], [23, 21], [27, 23], [9, 20], [5, 24], [7, 6], [6, 3], [23, 25], [22, 14], [26, 24], [2, 13], [27, 0], [2, 11], [26, 18], [0, 7], [4, 25], [2, 20], [20, 5], [30, 5], [16, 16], [11, 27], [17, 2], [9, 6], [14, 19], [13, 25], [21, 23], [8, 13], [14, 2], [23, 26], [22, 7]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[12, 0], [24, 29], [2, 1], [18, 27], [13, 11], [17, 1], [1, 19], [3, 6], [0, 30], [19, 26], [5, 9], [6, 13], [30, 19], [30, 26], [15, 27], [10, 11], [4, 8], [0, 21], [18, 0], [1, 16], [26, 30], [17, 19], [27, 9], [11, 29], [30, 14], [12, 3], [3, 18], [26, 7], [15, 4], [10, 14], [10, 30], [23, 2], [30, 6], [23, 21], [27, 23], [9, 20], [5, 24], [7, 6], [6, 3], [23, 25], [22, 14], [26, 24], [2, 13], [27, 0], [2, 11], [26, 18], [0, 7], [4, 25], [2, 20], [20, 5], [30, 5], [16, 16], [11, 27], [17, 2], [9, 6], [14, 19], [13, 25], [21, 23], [8, 13], [14, 2], [23, 26], [22, 7]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_6", - "sat": "def sat(path: List[int], edges=[[21, 25], [21, 10], [33, 72], [72, 29], [72, 60], [18, 24], [73, 5], [26, 75], [53, 57], [4, 4], [19, 52], [47, 76], [55, 77], [29, 40], [19, 69], [41, 17], [60, 67], [6, 22], [1, 58], [65, 30], [33, 63], [14, 59], [4, 12], [37, 18], [54, 25], [8, 38], [68, 31], [16, 13], [37, 0], [1, 11], [10, 23], [1, 78], [16, 17], [58, 60], [20, 37], [27, 62], [23, 15], [15, 44], [77, 78], [18, 42], [6, 34], [36, 45], [23, 2], [43, 51], [46, 27], [49, 55], [24, 79], [19, 30], [59, 14], [32, 26], [63, 26], [75, 0], [70, 12], [28, 51], [7, 14], [6, 5], [74, 50], [73, 63], [39, 42], [75, 64], [23, 46], [9, 52], [3, 64], [30, 48], [42, 32], [11, 2], [58, 41], [16, 78], [31, 9], [64, 3], [6, 30], [35, 11], [65, 45], [3, 52], [56, 72], [54, 62], [37, 37], [54, 17], [0, 62], [69, 55], [20, 48], [10, 55], [9, 14], [67, 35], [44, 25], [25, 57], [9, 62], [24, 58], [36, 71], [54, 47], [34, 7], [34, 12], [25, 31], [46, 11], [15, 68], [7, 34], [56, 12], [79, 22], [24, 70], [22, 76], [18, 76], [21, 57], [40, 53], [28, 3], [75, 14], [21, 72], [23, 34], [38, 70], [5, 22], [15, 6], [45, 49], [74, 46], [57, 35], [78, 42], [40, 4], [45, 58], [4, 61], [73, 0], [67, 65], [4, 66], [34, 26], [64, 27], [57, 27], [2, 59], [48, 4], [23, 17], [15, 0], [25, 72], [62, 40], [12, 27], [4, 18], [12, 68], [4, 15], [66, 47], [73, 42], [79, 79], [13, 7], [48, 22], [47, 69], [7, 6], [59, 12], [18, 78], [1, 0], [15, 20], [52, 55], [39, 34], [5, 42], [75, 29], [5, 7], [38, 63], [18, 9], [41, 6], [17, 43], [6, 10], [50, 44], [10, 54], [22, 65], [62, 66], [19, 62]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[21, 25], [21, 10], [33, 72], [72, 29], [72, 60], [18, 24], [73, 5], [26, 75], [53, 57], [4, 4], [19, 52], [47, 76], [55, 77], [29, 40], [19, 69], [41, 17], [60, 67], [6, 22], [1, 58], [65, 30], [33, 63], [14, 59], [4, 12], [37, 18], [54, 25], [8, 38], [68, 31], [16, 13], [37, 0], [1, 11], [10, 23], [1, 78], [16, 17], [58, 60], [20, 37], [27, 62], [23, 15], [15, 44], [77, 78], [18, 42], [6, 34], [36, 45], [23, 2], [43, 51], [46, 27], [49, 55], [24, 79], [19, 30], [59, 14], [32, 26], [63, 26], [75, 0], [70, 12], [28, 51], [7, 14], [6, 5], [74, 50], [73, 63], [39, 42], [75, 64], [23, 46], [9, 52], [3, 64], [30, 48], [42, 32], [11, 2], [58, 41], [16, 78], [31, 9], [64, 3], [6, 30], [35, 11], [65, 45], [3, 52], [56, 72], [54, 62], [37, 37], [54, 17], [0, 62], [69, 55], [20, 48], [10, 55], [9, 14], [67, 35], [44, 25], [25, 57], [9, 62], [24, 58], [36, 71], [54, 47], [34, 7], [34, 12], [25, 31], [46, 11], [15, 68], [7, 34], [56, 12], [79, 22], [24, 70], [22, 76], [18, 76], [21, 57], [40, 53], [28, 3], [75, 14], [21, 72], [23, 34], [38, 70], [5, 22], [15, 6], [45, 49], [74, 46], [57, 35], [78, 42], [40, 4], [45, 58], [4, 61], [73, 0], [67, 65], [4, 66], [34, 26], [64, 27], [57, 27], [2, 59], [48, 4], [23, 17], [15, 0], [25, 72], [62, 40], [12, 27], [4, 18], [12, 68], [4, 15], [66, 47], [73, 42], [79, 79], [13, 7], [48, 22], [47, 69], [7, 6], [59, 12], [18, 78], [1, 0], [15, 20], [52, 55], [39, 34], [5, 42], [75, 29], [5, 7], [38, 63], [18, 9], [41, 6], [17, 43], [6, 10], [50, 44], [10, 54], [22, 65], [62, 66], [19, 62]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_7", - "sat": "def sat(path: List[int], edges=[[0, 8], [6, 8], [5, 0], [6, 6], [3, 2], [3, 7], [2, 1], [3, 4], [3, 0], [6, 0], [5, 1], [2, 7], [1, 7], [4, 8], [4, 0], [6, 2]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[0, 8], [6, 8], [5, 0], [6, 6], [3, 2], [3, 7], [2, 1], [3, 4], [3, 0], [6, 0], [5, 1], [2, 7], [1, 7], [4, 8], [4, 0], [6, 2]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_8", - "sat": "def sat(path: List[int], edges=[[12, 21], [5, 34], [1, 37], [22, 15], [23, 8], [40, 0], [0, 35], [28, 4], [18, 7], [41, 40], [17, 32], [0, 40], [12, 5], [18, 22], [40, 35], [10, 4], [39, 31], [16, 9], [4, 37], [31, 28], [40, 5], [38, 1], [21, 6], [32, 30], [1, 7], [14, 21], [40, 29], [11, 6], [22, 33], [19, 13], [20, 34], [30, 42], [10, 1], [19, 16], [5, 28], [13, 1], [37, 32], [27, 14], [36, 34], [4, 39], [38, 17], [15, 33], [14, 36], [17, 30], [16, 1], [11, 10], [20, 32], [2, 3], [2, 35], [37, 27], [22, 40], [37, 25], [18, 9], [5, 6], [24, 2], [4, 31], [12, 25], [42, 36], [9, 29], [39, 29], [25, 37], [32, 17], [21, 13], [10, 20], [22, 0], [15, 9], [13, 11], [35, 41], [5, 22], [10, 11], [20, 16], [7, 21], [6, 37], [33, 36], [36, 38], [15, 14], [33, 17], [10, 6], [24, 7], [1, 3], [2, 28], [5, 17], [31, 8], [42, 31], [23, 20]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[12, 21], [5, 34], [1, 37], [22, 15], [23, 8], [40, 0], [0, 35], [28, 4], [18, 7], [41, 40], [17, 32], [0, 40], [12, 5], [18, 22], [40, 35], [10, 4], [39, 31], [16, 9], [4, 37], [31, 28], [40, 5], [38, 1], [21, 6], [32, 30], [1, 7], [14, 21], [40, 29], [11, 6], [22, 33], [19, 13], [20, 34], [30, 42], [10, 1], [19, 16], [5, 28], [13, 1], [37, 32], [27, 14], [36, 34], [4, 39], [38, 17], [15, 33], [14, 36], [17, 30], [16, 1], [11, 10], [20, 32], [2, 3], [2, 35], [37, 27], [22, 40], [37, 25], [18, 9], [5, 6], [24, 2], [4, 31], [12, 25], [42, 36], [9, 29], [39, 29], [25, 37], [32, 17], [21, 13], [10, 20], [22, 0], [15, 9], [13, 11], [35, 41], [5, 22], [10, 11], [20, 16], [7, 21], [6, 37], [33, 36], [36, 38], [15, 14], [33, 17], [10, 6], [24, 7], [1, 3], [2, 28], [5, 17], [31, 8], [42, 31], [23, 20]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "AnyPath_9", - "sat": "def sat(path: List[int], edges=[[48, 60], [32, 30], [52, 52], [27, 53], [6, 34], [26, 19], [60, 25], [67, 11], [37, 34], [75, 25], [18, 5], [60, 33], [48, 42], [38, 23], [31, 68], [72, 39], [75, 22], [16, 48], [25, 19], [35, 58], [9, 46], [38, 14], [69, 5], [21, 26], [1, 70], [7, 30], [18, 62], [42, 37], [41, 0], [25, 8], [35, 47], [35, 34], [6, 18], [60, 71], [20, 50], [2, 31], [51, 26], [26, 22], [73, 68], [11, 65], [27, 3], [63, 36], [56, 11], [28, 73], [15, 46], [5, 14], [49, 39], [67, 36], [16, 33], [35, 49], [69, 56], [31, 21], [41, 70], [43, 21], [51, 12], [39, 62], [22, 73], [54, 50], [9, 64], [64, 23], [45, 66], [33, 2], [65, 47], [21, 46], [59, 42], [64, 54], [13, 71], [1, 14], [74, 5], [72, 8], [32, 48], [54, 38], [7, 72], [71, 59], [30, 43], [30, 66], [0, 61], [11, 12], [4, 31], [58, 67], [6, 30], [71, 45], [36, 74], [36, 3], [68, 47], [14, 73], [20, 36], [25, 69], [69, 42], [27, 74], [33, 43], [41, 24], [4, 24], [57, 41], [63, 65], [66, 7], [27, 37], [19, 35], [75, 20], [31, 32], [1, 37], [57, 66], [19, 2], [58, 47], [23, 51], [50, 28], [19, 75], [4, 13], [1, 38], [5, 2], [73, 47], [16, 1], [46, 10], [44, 28], [10, 55], [9, 74], [74, 55], [27, 10], [22, 0], [38, 75], [7, 29], [34, 70], [57, 28], [34, 61], [3, 63], [71, 63], [29, 43], [57, 17], [6, 11], [27, 42], [14, 46], [40, 16], [48, 14], [23, 55], [69, 45], [39, 46], [70, 68], [3, 50], [19, 67], [6, 73], [12, 46], [45, 68], [68, 8], [28, 69], [44, 41], [43, 29], [61, 20], [66, 8], [12, 41], [64, 72], [19, 16], [14, 70]]):\n \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", - "sols": [ - "def sol(edges=[[48, 60], [32, 30], [52, 52], [27, 53], [6, 34], [26, 19], [60, 25], [67, 11], [37, 34], [75, 25], [18, 5], [60, 33], [48, 42], [38, 23], [31, 68], [72, 39], [75, 22], [16, 48], [25, 19], [35, 58], [9, 46], [38, 14], [69, 5], [21, 26], [1, 70], [7, 30], [18, 62], [42, 37], [41, 0], [25, 8], [35, 47], [35, 34], [6, 18], [60, 71], [20, 50], [2, 31], [51, 26], [26, 22], [73, 68], [11, 65], [27, 3], [63, 36], [56, 11], [28, 73], [15, 46], [5, 14], [49, 39], [67, 36], [16, 33], [35, 49], [69, 56], [31, 21], [41, 70], [43, 21], [51, 12], [39, 62], [22, 73], [54, 50], [9, 64], [64, 23], [45, 66], [33, 2], [65, 47], [21, 46], [59, 42], [64, 54], [13, 71], [1, 14], [74, 5], [72, 8], [32, 48], [54, 38], [7, 72], [71, 59], [30, 43], [30, 66], [0, 61], [11, 12], [4, 31], [58, 67], [6, 30], [71, 45], [36, 74], [36, 3], [68, 47], [14, 73], [20, 36], [25, 69], [69, 42], [27, 74], [33, 43], [41, 24], [4, 24], [57, 41], [63, 65], [66, 7], [27, 37], [19, 35], [75, 20], [31, 32], [1, 37], [57, 66], [19, 2], [58, 47], [23, 51], [50, 28], [19, 75], [4, 13], [1, 38], [5, 2], [73, 47], [16, 1], [46, 10], [44, 28], [10, 55], [9, 74], [74, 55], [27, 10], [22, 0], [38, 75], [7, 29], [34, 70], [57, 28], [34, 61], [3, 63], [71, 63], [29, 43], [57, 17], [6, 11], [27, 42], [14, 46], [40, 16], [48, 14], [23, 55], [69, 45], [39, 46], [70, 68], [3, 50], [19, 67], [6, 73], [12, 46], [45, 68], [68, 8], [28, 69], [44, 41], [43, 29], [61, 20], [66, 8], [12, 41], [64, 72], [19, 16], [14, 70]]):\n n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" - ], - "module": "graphs", - "notes": "Any Path", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_0", - "sat": "def sat(path: List[int], edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_1", - "sat": "def sat(path: List[int], edges=[[3, 2], [2, 1], [0, 2], [1, 0], [2, 2], [2, 3], [2, 0]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[3, 2], [2, 1], [0, 2], [1, 0], [2, 2], [2, 3], [2, 0]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_2", - "sat": "def sat(path: List[int], edges=[[5, 15], [51, 42], [23, 5], [36, 2], [18, 43], [8, 47], [37, 6], [20, 25], [13, 25], [17, 2], [53, 30], [4, 50], [25, 47], [27, 5], [47, 7], [6, 18], [16, 30], [51, 3], [6, 13], [3, 12], [30, 13], [14, 43], [0, 5], [20, 7], [8, 3], [29, 55], [13, 11], [18, 39], [37, 13], [25, 8], [45, 30], [32, 8], [55, 43], [34, 42], [31, 21], [26, 19], [18, 1], [51, 35], [51, 51], [53, 22], [8, 23], [29, 21], [0, 44], [16, 38], [7, 16], [22, 45], [37, 16], [54, 20], [24, 13], [47, 37], [11, 10], [31, 31], [37, 55], [18, 6], [27, 43], [51, 38], [33, 38], [31, 3], [15, 35], [42, 11], [53, 4], [51, 24], [14, 27], [13, 18], [9, 55], [29, 0], [50, 31], [16, 18], [46, 3], [42, 44], [25, 12], [50, 10], [28, 51], [3, 25], [18, 26], [16, 0], [15, 37], [45, 48], [23, 50], [1, 15], [29, 35], [48, 32], [27, 10], [39, 49], [0, 36], [46, 2], [51, 29], [39, 6], [51, 33], [30, 54], [53, 2], [26, 6], [6, 4], [15, 2], [35, 27], [6, 36], [53, 19], [49, 54], [4, 44], [53, 6], [47, 41], [37, 21], [50, 48], [42, 47], [6, 2], [5, 46], [2, 50], [39, 29], [11, 42], [46, 33], [11, 22]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[5, 15], [51, 42], [23, 5], [36, 2], [18, 43], [8, 47], [37, 6], [20, 25], [13, 25], [17, 2], [53, 30], [4, 50], [25, 47], [27, 5], [47, 7], [6, 18], [16, 30], [51, 3], [6, 13], [3, 12], [30, 13], [14, 43], [0, 5], [20, 7], [8, 3], [29, 55], [13, 11], [18, 39], [37, 13], [25, 8], [45, 30], [32, 8], [55, 43], [34, 42], [31, 21], [26, 19], [18, 1], [51, 35], [51, 51], [53, 22], [8, 23], [29, 21], [0, 44], [16, 38], [7, 16], [22, 45], [37, 16], [54, 20], [24, 13], [47, 37], [11, 10], [31, 31], [37, 55], [18, 6], [27, 43], [51, 38], [33, 38], [31, 3], [15, 35], [42, 11], [53, 4], [51, 24], [14, 27], [13, 18], [9, 55], [29, 0], [50, 31], [16, 18], [46, 3], [42, 44], [25, 12], [50, 10], [28, 51], [3, 25], [18, 26], [16, 0], [15, 37], [45, 48], [23, 50], [1, 15], [29, 35], [48, 32], [27, 10], [39, 49], [0, 36], [46, 2], [51, 29], [39, 6], [51, 33], [30, 54], [53, 2], [26, 6], [6, 4], [15, 2], [35, 27], [6, 36], [53, 19], [49, 54], [4, 44], [53, 6], [47, 41], [37, 21], [50, 48], [42, 47], [6, 2], [5, 46], [2, 50], [39, 29], [11, 42], [46, 33], [11, 22]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_3", - "sat": "def sat(path: List[int], edges=[[13, 29], [70, 66], [46, 37], [1, 57], [37, 1], [43, 0], [71, 49], [49, 49], [1, 0], [13, 38], [34, 7], [56, 74], [44, 74], [35, 54], [41, 59], [53, 47], [48, 28], [52, 46], [36, 22], [74, 72], [43, 36], [65, 24], [14, 67], [64, 28], [8, 39], [71, 14], [22, 24], [20, 43], [67, 21], [12, 39], [40, 41], [54, 19], [26, 69], [48, 14], [24, 25], [24, 16], [45, 62], [43, 57], [71, 1], [31, 24], [27, 66], [64, 18], [73, 33], [25, 22], [31, 60], [67, 3], [4, 44], [41, 55], [0, 23], [7, 14], [46, 50], [40, 53], [4, 33], [8, 12], [64, 55], [19, 52], [52, 62], [3, 42], [33, 10], [67, 10], [1, 33], [39, 18], [18, 7], [2, 47], [29, 55], [29, 42], [44, 67], [55, 55], [25, 42], [39, 53], [59, 21], [44, 50], [31, 30], [60, 71], [49, 9], [20, 16], [37, 68], [58, 73], [41, 7], [30, 74], [61, 31], [71, 42], [72, 19], [66, 33], [24, 33], [57, 40], [3, 28], [59, 64], [16, 12], [72, 20], [3, 5], [59, 52], [70, 8], [71, 13], [20, 71], [64, 31], [22, 27], [53, 36], [49, 23], [40, 4], [55, 68], [32, 12], [21, 15], [57, 63], [8, 70], [72, 56], [33, 3], [41, 28], [4, 0], [44, 10], [33, 2], [36, 24], [59, 58], [45, 33], [61, 66], [21, 48], [10, 54], [46, 13], [40, 25], [28, 6], [65, 53], [0, 53], [51, 22], [71, 17], [52, 9], [30, 34], [68, 64], [54, 8], [35, 13], [64, 54], [45, 67], [47, 22], [69, 52], [18, 73], [21, 60], [72, 29], [7, 36], [68, 56], [17, 14], [44, 54], [46, 29], [72, 67], [17, 53], [54, 51], [26, 46], [65, 21], [27, 3], [50, 5]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[13, 29], [70, 66], [46, 37], [1, 57], [37, 1], [43, 0], [71, 49], [49, 49], [1, 0], [13, 38], [34, 7], [56, 74], [44, 74], [35, 54], [41, 59], [53, 47], [48, 28], [52, 46], [36, 22], [74, 72], [43, 36], [65, 24], [14, 67], [64, 28], [8, 39], [71, 14], [22, 24], [20, 43], [67, 21], [12, 39], [40, 41], [54, 19], [26, 69], [48, 14], [24, 25], [24, 16], [45, 62], [43, 57], [71, 1], [31, 24], [27, 66], [64, 18], [73, 33], [25, 22], [31, 60], [67, 3], [4, 44], [41, 55], [0, 23], [7, 14], [46, 50], [40, 53], [4, 33], [8, 12], [64, 55], [19, 52], [52, 62], [3, 42], [33, 10], [67, 10], [1, 33], [39, 18], [18, 7], [2, 47], [29, 55], [29, 42], [44, 67], [55, 55], [25, 42], [39, 53], [59, 21], [44, 50], [31, 30], [60, 71], [49, 9], [20, 16], [37, 68], [58, 73], [41, 7], [30, 74], [61, 31], [71, 42], [72, 19], [66, 33], [24, 33], [57, 40], [3, 28], [59, 64], [16, 12], [72, 20], [3, 5], [59, 52], [70, 8], [71, 13], [20, 71], [64, 31], [22, 27], [53, 36], [49, 23], [40, 4], [55, 68], [32, 12], [21, 15], [57, 63], [8, 70], [72, 56], [33, 3], [41, 28], [4, 0], [44, 10], [33, 2], [36, 24], [59, 58], [45, 33], [61, 66], [21, 48], [10, 54], [46, 13], [40, 25], [28, 6], [65, 53], [0, 53], [51, 22], [71, 17], [52, 9], [30, 34], [68, 64], [54, 8], [35, 13], [64, 54], [45, 67], [47, 22], [69, 52], [18, 73], [21, 60], [72, 29], [7, 36], [68, 56], [17, 14], [44, 54], [46, 29], [72, 67], [17, 53], [54, 51], [26, 46], [65, 21], [27, 3], [50, 5]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_4", - "sat": "def sat(path: List[int], edges=[[67, 92], [18, 52], [25, 21], [83, 58], [36, 36], [26, 63], [48, 15], [53, 32], [62, 30], [41, 21], [91, 25], [82, 79], [33, 58], [65, 81], [57, 57], [62, 36], [85, 24], [14, 19], [58, 11], [20, 31], [76, 82], [92, 37], [73, 88], [90, 37], [68, 18], [70, 18], [45, 65], [45, 78], [87, 36], [41, 72], [66, 4], [25, 58], [18, 16], [72, 68], [21, 0], [44, 8], [51, 21], [30, 15], [18, 90], [75, 47], [42, 7], [13, 13], [27, 46], [78, 39], [71, 28], [85, 39], [56, 52], [60, 37], [37, 18], [82, 83], [84, 9], [31, 54], [81, 32], [46, 82], [10, 66], [85, 71], [3, 5], [15, 18], [83, 64], [9, 50], [60, 70], [7, 13], [81, 63], [32, 6], [18, 80], [22, 34], [60, 0], [88, 72], [9, 19], [74, 0], [87, 22], [41, 17], [66, 80], [33, 9], [71, 46], [23, 79], [64, 44], [40, 67], [78, 4], [8, 31], [15, 41], [42, 92], [22, 28], [57, 84], [69, 65], [35, 16], [1, 10], [7, 82], [62, 52], [8, 12], [51, 12], [5, 2], [83, 30], [76, 83], [0, 27], [30, 80], [33, 14], [39, 12], [51, 78], [30, 47], [25, 26], [11, 63], [52, 24], [32, 49], [0, 74], [51, 16], [1, 16], [14, 90], [49, 74], [69, 14], [72, 30], [61, 31], [54, 20], [46, 78], [4, 50], [13, 37], [61, 1], [4, 35], [29, 70], [20, 89], [28, 6], [74, 9], [86, 53], [58, 6], [57, 91], [10, 40], [15, 74], [23, 60], [5, 37], [50, 68], [78, 22], [90, 59], [74, 21], [80, 71], [92, 82], [42, 43], [68, 74], [43, 55], [67, 90], [87, 68], [40, 2], [55, 68], [52, 30], [10, 21], [44, 1], [39, 9], [12, 18], [61, 38], [65, 37], [10, 12], [21, 10], [81, 3], [65, 20], [31, 25], [59, 77], [43, 59], [75, 75], [71, 13], [17, 37], [31, 13], [6, 33], [24, 40], [52, 70], [70, 5], [4, 8], [20, 29], [11, 10], [43, 67], [11, 80], [49, 19], [81, 64], [44, 28], [18, 20], [91, 91], [90, 92], [81, 16], [31, 81], [7, 81], [54, 53], [65, 16], [91, 32]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[67, 92], [18, 52], [25, 21], [83, 58], [36, 36], [26, 63], [48, 15], [53, 32], [62, 30], [41, 21], [91, 25], [82, 79], [33, 58], [65, 81], [57, 57], [62, 36], [85, 24], [14, 19], [58, 11], [20, 31], [76, 82], [92, 37], [73, 88], [90, 37], [68, 18], [70, 18], [45, 65], [45, 78], [87, 36], [41, 72], [66, 4], [25, 58], [18, 16], [72, 68], [21, 0], [44, 8], [51, 21], [30, 15], [18, 90], [75, 47], [42, 7], [13, 13], [27, 46], [78, 39], [71, 28], [85, 39], [56, 52], [60, 37], [37, 18], [82, 83], [84, 9], [31, 54], [81, 32], [46, 82], [10, 66], [85, 71], [3, 5], [15, 18], [83, 64], [9, 50], [60, 70], [7, 13], [81, 63], [32, 6], [18, 80], [22, 34], [60, 0], [88, 72], [9, 19], [74, 0], [87, 22], [41, 17], [66, 80], [33, 9], [71, 46], [23, 79], [64, 44], [40, 67], [78, 4], [8, 31], [15, 41], [42, 92], [22, 28], [57, 84], [69, 65], [35, 16], [1, 10], [7, 82], [62, 52], [8, 12], [51, 12], [5, 2], [83, 30], [76, 83], [0, 27], [30, 80], [33, 14], [39, 12], [51, 78], [30, 47], [25, 26], [11, 63], [52, 24], [32, 49], [0, 74], [51, 16], [1, 16], [14, 90], [49, 74], [69, 14], [72, 30], [61, 31], [54, 20], [46, 78], [4, 50], [13, 37], [61, 1], [4, 35], [29, 70], [20, 89], [28, 6], [74, 9], [86, 53], [58, 6], [57, 91], [10, 40], [15, 74], [23, 60], [5, 37], [50, 68], [78, 22], [90, 59], [74, 21], [80, 71], [92, 82], [42, 43], [68, 74], [43, 55], [67, 90], [87, 68], [40, 2], [55, 68], [52, 30], [10, 21], [44, 1], [39, 9], [12, 18], [61, 38], [65, 37], [10, 12], [21, 10], [81, 3], [65, 20], [31, 25], [59, 77], [43, 59], [75, 75], [71, 13], [17, 37], [31, 13], [6, 33], [24, 40], [52, 70], [70, 5], [4, 8], [20, 29], [11, 10], [43, 67], [11, 80], [49, 19], [81, 64], [44, 28], [18, 20], [91, 91], [90, 92], [81, 16], [31, 81], [7, 81], [54, 53], [65, 16], [91, 32]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_5", - "sat": "def sat(path: List[int], edges=[[4, 14], [50, 30], [59, 52], [18, 38], [9, 27], [36, 24], [32, 19], [21, 24], [16, 49], [40, 27], [36, 22], [43, 5], [45, 16], [29, 35], [54, 46], [4, 0], [50, 51], [41, 40], [5, 48], [40, 61], [18, 20], [54, 45], [50, 2], [23, 37], [24, 34], [32, 50], [20, 21], [40, 9], [9, 33], [42, 35], [13, 13], [50, 53], [61, 58], [45, 9], [30, 51], [5, 24], [28, 41], [57, 39], [0, 32], [52, 28], [44, 51], [21, 14], [40, 1], [11, 25], [55, 39], [43, 60], [6, 4], [7, 29], [36, 5], [11, 26], [48, 3], [48, 5], [40, 26], [60, 27], [42, 52], [42, 46], [43, 31], [22, 55], [54, 27], [16, 53], [4, 32], [8, 30], [17, 17], [19, 24], [18, 48], [41, 33], [32, 3], [20, 8], [38, 52], [59, 3], [54, 33], [23, 24], [32, 35], [6, 22], [30, 32], [7, 24], [5, 53], [32, 25], [61, 60], [42, 14], [50, 42], [3, 58], [58, 31], [30, 23], [0, 45], [54, 15], [54, 1], [41, 48], [53, 30], [1, 0], [21, 37], [3, 4], [50, 50], [53, 5], [13, 6], [9, 32], [41, 5], [27, 2], [48, 23], [18, 27], [42, 45], [53, 32], [6, 11], [24, 0], [47, 49], [45, 58], [28, 5], [47, 43], [61, 31], [44, 60], [51, 54], [9, 13], [30, 34], [2, 26], [61, 14], [16, 37], [6, 43], [49, 27], [59, 44], [55, 52], [10, 45], [40, 37], [52, 60]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[4, 14], [50, 30], [59, 52], [18, 38], [9, 27], [36, 24], [32, 19], [21, 24], [16, 49], [40, 27], [36, 22], [43, 5], [45, 16], [29, 35], [54, 46], [4, 0], [50, 51], [41, 40], [5, 48], [40, 61], [18, 20], [54, 45], [50, 2], [23, 37], [24, 34], [32, 50], [20, 21], [40, 9], [9, 33], [42, 35], [13, 13], [50, 53], [61, 58], [45, 9], [30, 51], [5, 24], [28, 41], [57, 39], [0, 32], [52, 28], [44, 51], [21, 14], [40, 1], [11, 25], [55, 39], [43, 60], [6, 4], [7, 29], [36, 5], [11, 26], [48, 3], [48, 5], [40, 26], [60, 27], [42, 52], [42, 46], [43, 31], [22, 55], [54, 27], [16, 53], [4, 32], [8, 30], [17, 17], [19, 24], [18, 48], [41, 33], [32, 3], [20, 8], [38, 52], [59, 3], [54, 33], [23, 24], [32, 35], [6, 22], [30, 32], [7, 24], [5, 53], [32, 25], [61, 60], [42, 14], [50, 42], [3, 58], [58, 31], [30, 23], [0, 45], [54, 15], [54, 1], [41, 48], [53, 30], [1, 0], [21, 37], [3, 4], [50, 50], [53, 5], [13, 6], [9, 32], [41, 5], [27, 2], [48, 23], [18, 27], [42, 45], [53, 32], [6, 11], [24, 0], [47, 49], [45, 58], [28, 5], [47, 43], [61, 31], [44, 60], [51, 54], [9, 13], [30, 34], [2, 26], [61, 14], [16, 37], [6, 43], [49, 27], [59, 44], [55, 52], [10, 45], [40, 37], [52, 60]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_6", - "sat": "def sat(path: List[int], edges=[[13, 14], [13, 31], [30, 30], [28, 21], [23, 27], [22, 10], [0, 30], [5, 27], [31, 22], [5, 24], [22, 22], [35, 21], [16, 4], [11, 2], [26, 27], [9, 26], [26, 14], [0, 19], [12, 4], [25, 2], [4, 35], [22, 2], [3, 13], [15, 6], [26, 18], [10, 12], [19, 7], [15, 25], [26, 9], [29, 12], [21, 23], [20, 21], [13, 1], [21, 13], [12, 19], [5, 7], [7, 2], [22, 27], [22, 31], [2, 34], [18, 3], [8, 30], [31, 0], [19, 26], [31, 34], [1, 32], [4, 4], [4, 26], [22, 24], [31, 31], [28, 35], [16, 13], [20, 26], [23, 13], [11, 14], [35, 28], [1, 8], [10, 10], [21, 9], [23, 30], [18, 9], [23, 15], [19, 11], [10, 1], [22, 17], [33, 8], [6, 25], [32, 15], [9, 34]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[13, 14], [13, 31], [30, 30], [28, 21], [23, 27], [22, 10], [0, 30], [5, 27], [31, 22], [5, 24], [22, 22], [35, 21], [16, 4], [11, 2], [26, 27], [9, 26], [26, 14], [0, 19], [12, 4], [25, 2], [4, 35], [22, 2], [3, 13], [15, 6], [26, 18], [10, 12], [19, 7], [15, 25], [26, 9], [29, 12], [21, 23], [20, 21], [13, 1], [21, 13], [12, 19], [5, 7], [7, 2], [22, 27], [22, 31], [2, 34], [18, 3], [8, 30], [31, 0], [19, 26], [31, 34], [1, 32], [4, 4], [4, 26], [22, 24], [31, 31], [28, 35], [16, 13], [20, 26], [23, 13], [11, 14], [35, 28], [1, 8], [10, 10], [21, 9], [23, 30], [18, 9], [23, 15], [19, 11], [10, 1], [22, 17], [33, 8], [6, 25], [32, 15], [9, 34]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_7", - "sat": "def sat(path: List[int], edges=[[92, 45], [95, 59], [1, 43], [51, 64], [6, 47], [76, 76], [12, 26], [38, 27], [35, 7], [31, 82], [63, 4], [5, 64], [26, 90], [88, 62], [1, 27], [44, 40], [74, 62], [58, 13], [75, 67], [27, 45], [58, 7], [43, 11], [39, 53], [86, 5], [77, 45], [45, 81], [54, 75], [20, 81], [36, 3], [6, 31], [41, 69], [75, 1], [39, 45], [14, 68], [8, 27], [68, 42], [23, 51], [24, 49], [61, 38], [8, 90], [82, 13], [11, 76], [90, 68], [26, 10], [46, 34], [48, 32], [5, 62], [20, 42], [15, 0], [95, 5], [21, 35], [10, 8], [54, 84], [96, 9], [10, 87], [95, 84], [93, 20], [79, 31], [85, 55], [20, 26], [55, 50], [39, 20], [2, 96], [63, 53], [46, 71], [92, 40], [8, 47], [29, 24], [7, 32], [43, 90], [87, 13], [80, 82], [11, 32], [45, 22], [87, 38], [36, 4], [6, 75], [22, 62], [51, 15], [46, 65], [44, 13], [0, 42], [37, 0], [70, 11], [4, 36], [15, 69], [24, 22], [88, 29], [31, 17], [77, 11], [3, 13], [6, 37], [64, 77], [49, 35], [95, 4], [69, 44], [62, 33], [72, 75], [96, 8], [33, 58], [9, 46], [54, 45], [23, 47], [30, 21], [88, 77], [28, 78], [20, 63], [64, 32], [67, 40], [74, 1], [82, 35], [6, 65], [83, 1], [68, 72], [94, 76], [31, 56], [20, 76], [73, 69], [27, 75], [96, 72], [64, 39], [9, 65], [95, 44], [54, 3], [66, 68], [41, 45], [75, 77], [90, 83], [38, 0], [27, 15], [85, 78], [83, 23], [31, 95], [73, 74], [44, 58], [6, 50], [38, 20], [50, 13], [44, 70], [61, 54], [85, 43], [75, 26], [34, 9], [11, 90], [30, 20], [64, 80], [83, 71], [14, 46], [65, 50], [27, 86], [15, 91], [23, 26], [26, 2], [4, 95], [47, 63], [39, 93], [79, 48], [61, 72], [50, 10], [70, 16], [10, 67], [93, 54], [56, 66], [65, 45], [81, 44], [68, 7], [85, 19], [0, 75], [77, 63], [27, 88], [94, 64], [32, 28], [75, 23], [67, 69], [43, 44], [82, 80], [55, 11], [8, 75], [78, 72], [81, 19], [27, 70], [31, 28], [40, 55], [5, 37], [15, 25], [57, 56], [53, 7], [94, 56], [0, 9], [38, 6], [1, 13], [41, 10], [12, 30]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[92, 45], [95, 59], [1, 43], [51, 64], [6, 47], [76, 76], [12, 26], [38, 27], [35, 7], [31, 82], [63, 4], [5, 64], [26, 90], [88, 62], [1, 27], [44, 40], [74, 62], [58, 13], [75, 67], [27, 45], [58, 7], [43, 11], [39, 53], [86, 5], [77, 45], [45, 81], [54, 75], [20, 81], [36, 3], [6, 31], [41, 69], [75, 1], [39, 45], [14, 68], [8, 27], [68, 42], [23, 51], [24, 49], [61, 38], [8, 90], [82, 13], [11, 76], [90, 68], [26, 10], [46, 34], [48, 32], [5, 62], [20, 42], [15, 0], [95, 5], [21, 35], [10, 8], [54, 84], [96, 9], [10, 87], [95, 84], [93, 20], [79, 31], [85, 55], [20, 26], [55, 50], [39, 20], [2, 96], [63, 53], [46, 71], [92, 40], [8, 47], [29, 24], [7, 32], [43, 90], [87, 13], [80, 82], [11, 32], [45, 22], [87, 38], [36, 4], [6, 75], [22, 62], [51, 15], [46, 65], [44, 13], [0, 42], [37, 0], [70, 11], [4, 36], [15, 69], [24, 22], [88, 29], [31, 17], [77, 11], [3, 13], [6, 37], [64, 77], [49, 35], [95, 4], [69, 44], [62, 33], [72, 75], [96, 8], [33, 58], [9, 46], [54, 45], [23, 47], [30, 21], [88, 77], [28, 78], [20, 63], [64, 32], [67, 40], [74, 1], [82, 35], [6, 65], [83, 1], [68, 72], [94, 76], [31, 56], [20, 76], [73, 69], [27, 75], [96, 72], [64, 39], [9, 65], [95, 44], [54, 3], [66, 68], [41, 45], [75, 77], [90, 83], [38, 0], [27, 15], [85, 78], [83, 23], [31, 95], [73, 74], [44, 58], [6, 50], [38, 20], [50, 13], [44, 70], [61, 54], [85, 43], [75, 26], [34, 9], [11, 90], [30, 20], [64, 80], [83, 71], [14, 46], [65, 50], [27, 86], [15, 91], [23, 26], [26, 2], [4, 95], [47, 63], [39, 93], [79, 48], [61, 72], [50, 10], [70, 16], [10, 67], [93, 54], [56, 66], [65, 45], [81, 44], [68, 7], [85, 19], [0, 75], [77, 63], [27, 88], [94, 64], [32, 28], [75, 23], [67, 69], [43, 44], [82, 80], [55, 11], [8, 75], [78, 72], [81, 19], [27, 70], [31, 28], [40, 55], [5, 37], [15, 25], [57, 56], [53, 7], [94, 56], [0, 9], [38, 6], [1, 13], [41, 10], [12, 30]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_8", - "sat": "def sat(path: List[int], edges=[[0, 0], [2, 1], [1, 2], [0, 1]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[0, 0], [2, 1], [1, 2], [0, 1]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "EvenPath_9", - "sat": "def sat(path: List[int], edges=[[5, 6], [4, 3], [1, 5], [3, 1], [1, 0], [5, 5], [3, 2], [3, 3], [0, 5], [6, 1], [4, 2], [5, 4], [5, 2]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", - "sols": [ - "def sol(edges=[[5, 6], [4, 3], [1, 5], [3, 1], [1, 0], [5, 5], [3, 2], [3, 3], [0, 5], [6, 1], [4, 2], [5, 4], [5, 2]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" - ], - "module": "graphs", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_0", - "sat": "def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_1", - "sat": "def sat(p: List[int], edges=[[1, 6], [2, 3], [2, 7], [0, 8], [7, 8], [7, 2], [1, 5], [8, 7], [7, 0], [0, 0], [8, 1], [5, 7], [4, 7], [6, 1], [4, 4], [7, 4]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[1, 6], [2, 3], [2, 7], [0, 8], [7, 8], [7, 2], [1, 5], [8, 7], [7, 0], [0, 0], [8, 1], [5, 7], [4, 7], [6, 1], [4, 4], [7, 4]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_2", - "sat": "def sat(p: List[int], edges=[[40, 31], [16, 32], [41, 10], [14, 9], [36, 26], [14, 12], [22, 6], [36, 6], [13, 22], [0, 34], [6, 28], [27, 22], [31, 5], [2, 3], [34, 37], [17, 14], [1, 4], [22, 26], [32, 18], [20, 10], [28, 17], [2, 22], [22, 30], [36, 41], [7, 35], [24, 29], [31, 31], [26, 39], [14, 32], [33, 27], [33, 9], [30, 37], [40, 14], [19, 17], [15, 11], [7, 40], [6, 36], [20, 19], [7, 12], [17, 25], [14, 24], [34, 25], [27, 34], [35, 41], [34, 3], [25, 12], [34, 29], [21, 23], [2, 12], [25, 26], [28, 16], [17, 2], [15, 28], [29, 0], [32, 16], [13, 29], [23, 26], [3, 11], [39, 3], [40, 16], [22, 39], [12, 30], [12, 24], [38, 24], [5, 1], [21, 39], [33, 39], [29, 36], [23, 40], [34, 20], [35, 10], [13, 7], [10, 2], [32, 26], [37, 4], [36, 21], [1, 18], [23, 11], [19, 11], [35, 5], [10, 32], [9, 17], [21, 2]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[40, 31], [16, 32], [41, 10], [14, 9], [36, 26], [14, 12], [22, 6], [36, 6], [13, 22], [0, 34], [6, 28], [27, 22], [31, 5], [2, 3], [34, 37], [17, 14], [1, 4], [22, 26], [32, 18], [20, 10], [28, 17], [2, 22], [22, 30], [36, 41], [7, 35], [24, 29], [31, 31], [26, 39], [14, 32], [33, 27], [33, 9], [30, 37], [40, 14], [19, 17], [15, 11], [7, 40], [6, 36], [20, 19], [7, 12], [17, 25], [14, 24], [34, 25], [27, 34], [35, 41], [34, 3], [25, 12], [34, 29], [21, 23], [2, 12], [25, 26], [28, 16], [17, 2], [15, 28], [29, 0], [32, 16], [13, 29], [23, 26], [3, 11], [39, 3], [40, 16], [22, 39], [12, 30], [12, 24], [38, 24], [5, 1], [21, 39], [33, 39], [29, 36], [23, 40], [34, 20], [35, 10], [13, 7], [10, 2], [32, 26], [37, 4], [36, 21], [1, 18], [23, 11], [19, 11], [35, 5], [10, 32], [9, 17], [21, 2]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_3", - "sat": "def sat(p: List[int], edges=[[6, 6], [3, 6], [5, 0], [7, 16], [9, 12], [10, 3], [3, 5], [14, 17], [10, 14], [15, 3], [17, 15], [8, 18], [1, 12], [3, 7], [12, 17], [15, 15], [6, 2], [10, 9], [5, 13], [2, 15], [8, 5], [9, 15], [10, 6], [10, 17], [3, 9], [2, 6], [4, 1], [7, 12], [13, 1], [15, 17], [13, 5], [14, 10], [0, 17], [0, 11], [4, 17], [1, 11], [12, 18]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[6, 6], [3, 6], [5, 0], [7, 16], [9, 12], [10, 3], [3, 5], [14, 17], [10, 14], [15, 3], [17, 15], [8, 18], [1, 12], [3, 7], [12, 17], [15, 15], [6, 2], [10, 9], [5, 13], [2, 15], [8, 5], [9, 15], [10, 6], [10, 17], [3, 9], [2, 6], [4, 1], [7, 12], [13, 1], [15, 17], [13, 5], [14, 10], [0, 17], [0, 11], [4, 17], [1, 11], [12, 18]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_4", - "sat": "def sat(p: List[int], edges=[[4, 8], [7, 6], [2, 0], [3, 2], [6, 3], [4, 5], [11, 5], [11, 0], [1, 5], [12, 12], [12, 1], [4, 11], [3, 3], [2, 10], [10, 6], [0, 7], [2, 7], [6, 11], [2, 9], [7, 7], [8, 9], [2, 1], [4, 6], [9, 4]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[4, 8], [7, 6], [2, 0], [3, 2], [6, 3], [4, 5], [11, 5], [11, 0], [1, 5], [12, 12], [12, 1], [4, 11], [3, 3], [2, 10], [10, 6], [0, 7], [2, 7], [6, 11], [2, 9], [7, 7], [8, 9], [2, 1], [4, 6], [9, 4]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_5", - "sat": "def sat(p: List[int], edges=[[18, 10], [73, 40], [5, 44], [5, 35], [9, 53], [49, 6], [34, 0], [26, 14], [47, 3], [68, 45], [16, 44], [5, 21], [62, 11], [51, 4], [74, 50], [72, 12], [44, 40], [41, 64], [50, 24], [67, 2], [9, 72], [74, 7], [4, 58], [71, 11], [70, 1], [50, 37], [27, 58], [8, 68], [45, 62], [74, 62], [41, 54], [71, 23], [35, 19], [6, 5], [17, 5], [56, 18], [37, 2], [58, 48], [11, 45], [19, 17], [74, 29], [51, 20], [24, 29], [49, 11], [52, 34], [4, 49], [24, 17], [8, 11], [55, 42], [32, 57], [14, 39], [37, 15], [74, 3], [37, 1], [28, 11], [33, 27], [25, 55], [9, 68], [43, 58], [58, 64], [64, 16], [7, 64], [24, 63], [5, 11], [69, 22], [59, 21], [52, 27], [70, 36], [15, 34], [6, 14], [63, 13], [27, 16], [63, 61], [29, 52], [33, 60], [44, 69], [37, 34], [39, 48], [56, 26], [28, 46], [61, 31], [28, 66], [54, 29], [66, 9], [57, 6], [15, 73], [30, 71], [49, 39], [43, 1], [44, 33], [6, 63], [74, 14], [71, 38], [46, 33], [64, 34], [33, 53], [72, 53], [39, 16], [31, 5], [45, 49], [52, 19], [67, 71], [2, 14], [6, 40], [7, 41], [68, 50], [0, 33], [30, 29], [32, 66], [25, 7], [70, 28], [34, 16], [23, 10], [68, 1], [43, 72], [34, 1], [68, 2], [30, 7], [46, 31], [56, 66], [23, 4], [74, 34], [54, 59], [50, 6], [13, 26], [61, 49], [68, 72], [48, 61], [25, 19], [19, 46], [36, 34], [11, 59], [32, 5], [28, 5], [52, 32], [49, 26], [66, 13], [13, 48], [74, 46], [41, 52], [62, 62], [48, 21], [18, 20]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[18, 10], [73, 40], [5, 44], [5, 35], [9, 53], [49, 6], [34, 0], [26, 14], [47, 3], [68, 45], [16, 44], [5, 21], [62, 11], [51, 4], [74, 50], [72, 12], [44, 40], [41, 64], [50, 24], [67, 2], [9, 72], [74, 7], [4, 58], [71, 11], [70, 1], [50, 37], [27, 58], [8, 68], [45, 62], [74, 62], [41, 54], [71, 23], [35, 19], [6, 5], [17, 5], [56, 18], [37, 2], [58, 48], [11, 45], [19, 17], [74, 29], [51, 20], [24, 29], [49, 11], [52, 34], [4, 49], [24, 17], [8, 11], [55, 42], [32, 57], [14, 39], [37, 15], [74, 3], [37, 1], [28, 11], [33, 27], [25, 55], [9, 68], [43, 58], [58, 64], [64, 16], [7, 64], [24, 63], [5, 11], [69, 22], [59, 21], [52, 27], [70, 36], [15, 34], [6, 14], [63, 13], [27, 16], [63, 61], [29, 52], [33, 60], [44, 69], [37, 34], [39, 48], [56, 26], [28, 46], [61, 31], [28, 66], [54, 29], [66, 9], [57, 6], [15, 73], [30, 71], [49, 39], [43, 1], [44, 33], [6, 63], [74, 14], [71, 38], [46, 33], [64, 34], [33, 53], [72, 53], [39, 16], [31, 5], [45, 49], [52, 19], [67, 71], [2, 14], [6, 40], [7, 41], [68, 50], [0, 33], [30, 29], [32, 66], [25, 7], [70, 28], [34, 16], [23, 10], [68, 1], [43, 72], [34, 1], [68, 2], [30, 7], [46, 31], [56, 66], [23, 4], [74, 34], [54, 59], [50, 6], [13, 26], [61, 49], [68, 72], [48, 61], [25, 19], [19, 46], [36, 34], [11, 59], [32, 5], [28, 5], [52, 32], [49, 26], [66, 13], [13, 48], [74, 46], [41, 52], [62, 62], [48, 21], [18, 20]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_6", - "sat": "def sat(p: List[int], edges=[[1, 1], [0, 1], [1, 0]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[1, 1], [0, 1], [1, 0]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_7", - "sat": "def sat(p: List[int], edges=[[3, 2], [2, 0], [2, 1], [0, 1], [0, 2], [2, 2], [3, 1]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[3, 2], [2, 0], [2, 1], [0, 1], [0, 2], [2, 2], [3, 1]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_8", - "sat": "def sat(p: List[int], edges=[[3, 7], [5, 1], [0, 0], [5, 5], [6, 1], [2, 0], [2, 4], [1, 5], [0, 3], [7, 5], [0, 4], [6, 6], [3, 1], [4, 5]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[3, 7], [5, 1], [0, 0], [5, 5], [6, 1], [2, 0], [2, 4], [1, 5], [0, 3], [7, 5], [0, 4], [6, 6], [3, 1], [4, 5]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "OddPath_9", - "sat": "def sat(p: List[int], edges=[[11, 40], [20, 85], [16, 63], [66, 6], [81, 51], [92, 32], [56, 68], [77, 8], [16, 77], [20, 18], [73, 40], [73, 7], [30, 74], [71, 31], [8, 74], [23, 38], [14, 26], [21, 43], [41, 64], [10, 1], [77, 64], [90, 42], [66, 56], [59, 82], [95, 32], [57, 47], [24, 23], [63, 3], [10, 21], [57, 1], [93, 0], [15, 63], [90, 43], [0, 44], [80, 24], [19, 42], [85, 14], [62, 35], [55, 68], [25, 51], [72, 53], [52, 0], [32, 93], [69, 18], [93, 5], [10, 65], [22, 84], [61, 86], [82, 54], [9, 30], [1, 74], [72, 67], [59, 60], [52, 33], [86, 9], [85, 5], [96, 26], [16, 70], [88, 84], [75, 25], [68, 5], [49, 53], [81, 35], [15, 62], [62, 13], [64, 9], [64, 34], [92, 47], [18, 87], [18, 41], [17, 41], [3, 69], [10, 96], [82, 41], [19, 47], [48, 83], [10, 68], [89, 1], [56, 8], [56, 52], [13, 3], [22, 92], [42, 47], [68, 65], [12, 56], [19, 66], [34, 26], [42, 29], [95, 7], [27, 77], [44, 73], [79, 29], [53, 68], [21, 33], [59, 94], [29, 79], [12, 4], [74, 61], [72, 1], [35, 47], [8, 82], [62, 60], [35, 66], [30, 81], [38, 96], [3, 93], [33, 64], [13, 11], [12, 85], [15, 64], [67, 25], [70, 84], [32, 32], [46, 5], [1, 76], [51, 60], [3, 19], [51, 40], [50, 43], [51, 33], [26, 32], [20, 53], [57, 68], [21, 56], [79, 88], [8, 45], [19, 24], [37, 47], [34, 88], [2, 69], [6, 35], [47, 66], [47, 34], [46, 4], [76, 87], [94, 15], [15, 47], [67, 13], [45, 69], [86, 88], [18, 76], [5, 43], [2, 42], [88, 90], [78, 6], [55, 38], [47, 95], [32, 21], [66, 55], [44, 72], [83, 17], [77, 1], [92, 85], [16, 28], [61, 19], [69, 43], [76, 71], [86, 23], [57, 37], [78, 20], [36, 94], [60, 86], [59, 90], [9, 23], [38, 6], [76, 11], [38, 22], [88, 65], [36, 92], [44, 29], [68, 63], [53, 66], [32, 54], [75, 95], [1, 42], [45, 82], [82, 35], [5, 28], [14, 43], [83, 58], [79, 11], [30, 8], [3, 58], [83, 13], [8, 81], [90, 84], [83, 64], [91, 23], [26, 78], [95, 50], [86, 49], [68, 24], [20, 79], [68, 46]]):\n \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", - "sols": [ - "def sol(edges=[[11, 40], [20, 85], [16, 63], [66, 6], [81, 51], [92, 32], [56, 68], [77, 8], [16, 77], [20, 18], [73, 40], [73, 7], [30, 74], [71, 31], [8, 74], [23, 38], [14, 26], [21, 43], [41, 64], [10, 1], [77, 64], [90, 42], [66, 56], [59, 82], [95, 32], [57, 47], [24, 23], [63, 3], [10, 21], [57, 1], [93, 0], [15, 63], [90, 43], [0, 44], [80, 24], [19, 42], [85, 14], [62, 35], [55, 68], [25, 51], [72, 53], [52, 0], [32, 93], [69, 18], [93, 5], [10, 65], [22, 84], [61, 86], [82, 54], [9, 30], [1, 74], [72, 67], [59, 60], [52, 33], [86, 9], [85, 5], [96, 26], [16, 70], [88, 84], [75, 25], [68, 5], [49, 53], [81, 35], [15, 62], [62, 13], [64, 9], [64, 34], [92, 47], [18, 87], [18, 41], [17, 41], [3, 69], [10, 96], [82, 41], [19, 47], [48, 83], [10, 68], [89, 1], [56, 8], [56, 52], [13, 3], [22, 92], [42, 47], [68, 65], [12, 56], [19, 66], [34, 26], [42, 29], [95, 7], [27, 77], [44, 73], [79, 29], [53, 68], [21, 33], [59, 94], [29, 79], [12, 4], [74, 61], [72, 1], [35, 47], [8, 82], [62, 60], [35, 66], [30, 81], [38, 96], [3, 93], [33, 64], [13, 11], [12, 85], [15, 64], [67, 25], [70, 84], [32, 32], [46, 5], [1, 76], [51, 60], [3, 19], [51, 40], [50, 43], [51, 33], [26, 32], [20, 53], [57, 68], [21, 56], [79, 88], [8, 45], [19, 24], [37, 47], [34, 88], [2, 69], [6, 35], [47, 66], [47, 34], [46, 4], [76, 87], [94, 15], [15, 47], [67, 13], [45, 69], [86, 88], [18, 76], [5, 43], [2, 42], [88, 90], [78, 6], [55, 38], [47, 95], [32, 21], [66, 55], [44, 72], [83, 17], [77, 1], [92, 85], [16, 28], [61, 19], [69, 43], [76, 71], [86, 23], [57, 37], [78, 20], [36, 94], [60, 86], [59, 90], [9, 23], [38, 6], [76, 11], [38, 22], [88, 65], [36, 92], [44, 29], [68, 63], [53, 66], [32, 54], [75, 95], [1, 42], [45, 82], [82, 35], [5, 28], [14, 43], [83, 58], [79, 11], [30, 8], [3, 58], [83, 13], [8, 81], [90, 84], [83, 64], [91, 23], [26, 78], [95, 50], [86, 49], [68, 24], [20, 79], [68, 46]]):\n even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" - ], - "module": "graphs", - "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "Zarankiewicz_0", - "sat": "def sat(edges: List[List[int]]):\n \"\"\"Find a bipartite graph with 4 vertices on each side, 13 edges, and no K_3,3 subgraph.\"\"\"\n assert len(edges) == len({(a, b) for a, b in edges}) == 13 # 13 edges, no duplicates\n assert all(i in range(4) for li in edges for i in li) # 4 nodes on each side\n for i in range(4):\n v = [m for m in range(4) if m != i]\n for j in range(4):\n u = [m for m in range(4) if m != j]\n if all([m, n] in edges for m in v for n in u):\n return False\n return True", - "sols": [ - "def sol():\n return [[i, j] for i in range(4) for j in range(4) if i != j or i == 0]" - ], - "module": "graphs", - "notes": "[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)", - "taint_date": "2021-4-26", - "weight": 0.08333333333333333 - }, - { - "name": "GraphIsomorphism_0", - "sat": "def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_1", - "sat": "def sat(bi: List[int], g1=[[0, 6], [0, 8], [0, 10], [0, 11], [1, 3], [1, 5], [1, 7], [1, 10], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [3, 5], [3, 7], [3, 10], [4, 4], [5, 1], [5, 2], [5, 7], [5, 8], [5, 10], [6, 1], [6, 2], [6, 3], [6, 4], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 0], [7, 2], [7, 9], [8, 4], [8, 6], [8, 9], [8, 10], [9, 1], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 9], [9, 10], [9, 11], [10, 1], [10, 3], [10, 6], [10, 8], [11, 1], [11, 2], [11, 4], [11, 8], [11, 9], [11, 11]], g2=[[0, 11], [9, 2], [10, 10], [6, 11], [7, 5], [5, 0], [9, 3], [8, 2], [10, 8], [2, 11], [4, 8], [0, 7], [2, 10], [11, 11], [4, 5], [10, 11], [6, 10], [9, 7], [6, 6], [8, 10], [1, 5], [2, 9], [10, 3], [0, 2], [9, 8], [5, 4], [0, 5], [6, 2], [8, 1], [1, 6], [6, 3], [0, 10], [0, 8], [10, 5], [2, 7], [0, 6], [0, 0], [10, 0], [3, 8], [5, 3], [5, 7], [10, 6], [6, 7], [7, 0], [3, 9], [3, 4], [0, 3], [0, 4], [1, 7], [4, 9], [7, 10], [9, 5], [7, 11], [3, 5], [10, 4], [10, 9], [2, 8], [1, 0]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_2", - "sat": "def sat(bi: List[int], g1=[[0, 1], [0, 7], [1, 1], [2, 0], [2, 3], [2, 5], [2, 6], [3, 0], [3, 1], [3, 2], [3, 5], [3, 6], [3, 7], [4, 3], [4, 5], [4, 6], [5, 0], [5, 2], [5, 3], [6, 0], [6, 5], [6, 7], [7, 0], [7, 4], [7, 6]], g2=[[0, 7], [7, 1], [0, 2], [3, 1], [2, 0], [7, 0], [0, 6], [4, 7], [2, 7], [7, 6], [1, 6], [3, 6], [6, 5], [1, 3], [7, 3], [4, 0], [1, 0], [3, 4], [2, 1], [2, 6], [7, 2], [6, 3], [7, 5], [4, 1], [5, 5]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[0, 1], [0, 7], [1, 1], [2, 0], [2, 3], [2, 5], [2, 6], [3, 0], [3, 1], [3, 2], [3, 5], [3, 6], [3, 7], [4, 3], [4, 5], [4, 6], [5, 0], [5, 2], [5, 3], [6, 0], [6, 5], [6, 7], [7, 0], [7, 4], [7, 6]], g2=[[0, 7], [7, 1], [0, 2], [3, 1], [2, 0], [7, 0], [0, 6], [4, 7], [2, 7], [7, 6], [1, 6], [3, 6], [6, 5], [1, 3], [7, 3], [4, 0], [1, 0], [3, 4], [2, 1], [2, 6], [7, 2], [6, 3], [7, 5], [4, 1], [5, 5]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_3", - "sat": "def sat(bi: List[int], g1=[[0, 0], [0, 5], [0, 6], [0, 9], [1, 1], [1, 2], [1, 3], [1, 5], [1, 7], [1, 8], [2, 1], [2, 4], [2, 8], [2, 9], [3, 0], [3, 4], [3, 7], [3, 9], [4, 2], [4, 3], [4, 5], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 0], [6, 4], [6, 7], [7, 5], [7, 6], [7, 8], [8, 1], [8, 7], [9, 1], [9, 4], [9, 8], [9, 9]], g2=[[1, 0], [2, 5], [0, 1], [5, 0], [6, 2], [8, 8], [0, 2], [9, 3], [3, 7], [5, 8], [1, 8], [8, 3], [5, 3], [0, 9], [6, 7], [1, 5], [8, 2], [7, 4], [6, 3], [9, 0], [4, 1], [1, 1], [7, 3], [7, 5], [2, 4], [5, 9], [3, 9], [7, 7], [7, 9], [4, 9], [4, 8], [8, 7], [7, 6], [9, 5], [6, 8], [2, 8], [4, 2], [2, 6]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_4", - "sat": "def sat(bi: List[int], g1=[[1, 0], [1, 1], [1, 2], [2, 1]], g2=[[0, 2], [2, 2], [2, 0], [2, 1]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[1, 0], [1, 1], [1, 2], [2, 1]], g2=[[0, 2], [2, 2], [2, 0], [2, 1]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_5", - "sat": "def sat(bi: List[int], g1=[[0, 0], [0, 2], [0, 5], [1, 1], [1, 5], [2, 2], [2, 5], [3, 3], [3, 5], [3, 6], [3, 7], [3, 8], [4, 1], [4, 4], [4, 5], [5, 2], [5, 4], [5, 6], [5, 7], [5, 8], [6, 0], [6, 2], [6, 8], [7, 1], [7, 6], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 7], [8, 8]], g2=[[4, 5], [3, 3], [6, 0], [4, 1], [5, 5], [4, 8], [4, 6], [0, 8], [1, 7], [5, 6], [2, 8], [7, 7], [5, 3], [1, 2], [1, 5], [5, 0], [2, 2], [3, 8], [8, 1], [5, 2], [4, 4], [5, 7], [8, 6], [3, 0], [6, 1], [5, 4], [7, 2], [8, 3], [7, 8], [8, 2], [5, 8], [0, 0], [8, 5]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[0, 0], [0, 2], [0, 5], [1, 1], [1, 5], [2, 2], [2, 5], [3, 3], [3, 5], [3, 6], [3, 7], [3, 8], [4, 1], [4, 4], [4, 5], [5, 2], [5, 4], [5, 6], [5, 7], [5, 8], [6, 0], [6, 2], [6, 8], [7, 1], [7, 6], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 7], [8, 8]], g2=[[4, 5], [3, 3], [6, 0], [4, 1], [5, 5], [4, 8], [4, 6], [0, 8], [1, 7], [5, 6], [2, 8], [7, 7], [5, 3], [1, 2], [1, 5], [5, 0], [2, 2], [3, 8], [8, 1], [5, 2], [4, 4], [5, 7], [8, 6], [3, 0], [6, 1], [5, 4], [7, 2], [8, 3], [7, 8], [8, 2], [5, 8], [0, 0], [8, 5]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_6", - "sat": "def sat(bi: List[int], g1=[[0, 1], [0, 3], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 5], [1, 9], [2, 1], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [3, 2], [3, 3], [3, 5], [3, 9], [3, 10], [3, 11], [4, 0], [4, 1], [4, 2], [4, 4], [4, 5], [4, 7], [4, 8], [4, 9], [4, 11], [5, 1], [5, 2], [5, 4], [5, 5], [5, 12], [6, 0], [6, 1], [6, 2], [6, 3], [6, 4], [6, 6], [6, 8], [6, 10], [6, 12], [7, 1], [7, 4], [7, 5], [7, 8], [7, 9], [8, 7], [8, 8], [8, 12], [9, 1], [9, 2], [9, 3], [9, 4], [9, 6], [10, 3], [10, 4], [10, 10], [10, 11], [11, 8], [12, 1], [12, 2], [12, 3], [12, 4], [12, 10]], g2=[[2, 0], [7, 7], [1, 9], [0, 9], [1, 0], [9, 10], [11, 11], [3, 10], [0, 1], [4, 5], [5, 3], [5, 4], [9, 8], [2, 5], [7, 8], [10, 2], [10, 6], [2, 1], [11, 7], [12, 4], [10, 1], [0, 2], [11, 10], [9, 3], [2, 8], [2, 3], [12, 1], [11, 6], [11, 1], [6, 9], [3, 3], [3, 1], [11, 9], [11, 12], [1, 3], [9, 5], [0, 11], [6, 8], [10, 9], [9, 1], [2, 2], [12, 5], [4, 4], [5, 1], [5, 0], [12, 11], [12, 0], [7, 6], [2, 9], [9, 2], [5, 2], [6, 6], [9, 6], [11, 2], [9, 4], [0, 6], [9, 7], [12, 6], [7, 2], [11, 4], [2, 12], [6, 3], [4, 10], [3, 9], [6, 7], [3, 2], [8, 4], [6, 0], [10, 7], [2, 4]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_7", - "sat": "def sat(bi: List[int], g1=[[0, 0], [0, 2], [0, 3], [0, 4], [0, 6], [1, 1], [1, 4], [2, 4], [2, 6], [3, 0], [3, 2], [4, 0], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 4], [6, 5], [6, 6]], g2=[[5, 1], [0, 2], [3, 3], [1, 3], [2, 2], [1, 5], [3, 4], [6, 2], [2, 1], [0, 0], [4, 6], [1, 2], [2, 5], [5, 6], [4, 2], [1, 1], [1, 6], [6, 3], [4, 1], [4, 0]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[0, 0], [0, 2], [0, 3], [0, 4], [0, 6], [1, 1], [1, 4], [2, 4], [2, 6], [3, 0], [3, 2], [4, 0], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 4], [6, 5], [6, 6]], g2=[[5, 1], [0, 2], [3, 3], [1, 3], [2, 2], [1, 5], [3, 4], [6, 2], [2, 1], [0, 0], [4, 6], [1, 2], [2, 5], [5, 6], [4, 2], [1, 1], [1, 6], [6, 3], [4, 1], [4, 0]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_8", - "sat": "def sat(bi: List[int], g1=[[0, 1], [0, 2], [0, 3], [0, 7], [0, 8], [0, 9], [1, 4], [1, 6], [1, 8], [1, 9], [2, 4], [2, 5], [2, 11], [3, 1], [3, 3], [3, 5], [3, 8], [3, 12], [4, 7], [5, 2], [5, 4], [5, 10], [5, 11], [6, 0], [6, 3], [6, 4], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10], [7, 1], [7, 6], [7, 9], [7, 10], [8, 2], [8, 6], [8, 7], [8, 8], [8, 9], [8, 10], [9, 0], [9, 2], [9, 3], [9, 5], [9, 6], [9, 10], [9, 12], [10, 0], [10, 2], [10, 3], [10, 6], [10, 8], [10, 11], [11, 1], [11, 5], [11, 6], [11, 12], [12, 0], [12, 2], [12, 3], [12, 4], [12, 5]], g2=[[11, 10], [7, 1], [10, 12], [0, 2], [5, 11], [3, 0], [6, 12], [4, 1], [11, 12], [10, 2], [4, 8], [11, 4], [8, 5], [5, 6], [5, 0], [11, 1], [1, 9], [2, 6], [5, 2], [10, 3], [12, 7], [0, 5], [11, 6], [6, 5], [12, 3], [6, 8], [8, 1], [1, 6], [11, 7], [2, 11], [9, 2], [0, 6], [1, 8], [6, 10], [3, 11], [6, 4], [3, 9], [10, 11], [7, 12], [8, 3], [0, 0], [7, 4], [7, 9], [2, 3], [5, 5], [12, 1], [0, 11], [7, 10], [12, 0], [8, 7], [12, 12], [5, 10], [4, 9], [10, 4], [1, 4], [11, 5], [3, 5], [0, 4], [10, 0], [2, 5], [5, 9], [6, 0], [5, 12]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "GraphIsomorphism_9", - "sat": "def sat(bi: List[int], g1=[[0, 6], [0, 8], [1, 0], [1, 1], [1, 2], [1, 6], [1, 8], [2, 3], [2, 6], [2, 7], [3, 0], [3, 1], [3, 4], [3, 5], [3, 6], [3, 8], [4, 0], [4, 5], [4, 7], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [6, 0], [6, 1], [6, 5], [6, 6], [6, 7], [7, 3], [7, 4], [7, 7], [8, 1], [8, 3], [8, 6]], g2=[[5, 7], [3, 0], [6, 4], [4, 1], [3, 4], [3, 1], [7, 7], [0, 4], [2, 6], [3, 8], [8, 1], [4, 7], [3, 2], [1, 8], [1, 6], [2, 3], [7, 3], [5, 2], [8, 4], [4, 4], [4, 2], [7, 5], [1, 0], [8, 3], [3, 5], [6, 7], [1, 1], [2, 5], [4, 0], [2, 1], [1, 4], [5, 0], [2, 0], [6, 3], [2, 4], [0, 8]]):\n \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", - "sols": [ - "def sol(g1=[[0, 6], [0, 8], [1, 0], [1, 1], [1, 2], [1, 6], [1, 8], [2, 3], [2, 6], [2, 7], [3, 0], [3, 1], [3, 4], [3, 5], [3, 6], [3, 8], [4, 0], [4, 5], [4, 7], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [6, 0], [6, 1], [6, 5], [6, 6], [6, 7], [7, 3], [7, 4], [7, 7], [8, 1], [8, 3], [8, 6]], g2=[[5, 7], [3, 0], [6, 4], [4, 1], [3, 4], [3, 1], [7, 7], [0, 4], [2, 6], [3, 8], [8, 1], [4, 7], [3, 2], [1, 8], [1, 6], [2, 3], [7, 3], [5, 2], [8, 4], [4, 4], [4, 2], [7, 5], [1, 0], [8, 3], [3, 5], [6, 7], [1, 1], [2, 5], [4, 0], [2, 1], [1, 4], [5, 0], [2, 0], [6, 3], [2, 4], [0, 8]]): # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" - ], - "module": "graphs", - "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", - "taint_date": "2021-4-26", - "weight": 0.008333333333333333 - }, - { - "name": "ShortIntegerPath_0", - "sat": "def sat(li: List[int]):\n \"\"\"\n Find a list of nine integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) and len(li) == 9", - "sols": [ - "def sol():\n return [1, 3, 4, 12, 13, 14, 42, 126, 127]" - ], - "module": "graphs", - "notes": "This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph\ndefined by the integer pairs.", - "taint_date": "2021-4-26", - "weight": 0.08333333333333333 - }, - { - "name": "BiPermutations_0", - "sat": "def sat(perms: List[List[int]], prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_1", - "sat": "def sat(perms: List[List[int]], prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[12, 5, 8, 13, 7], heights1=[2, 10, 4, 5, 9]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[12, 5, 8, 13, 7], heights1=[2, 10, 4, 5, 9]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_2", - "sat": "def sat(perms: List[List[int]], prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[9, 10, 12, 14, 14], heights1=[6, 5, 7, 10, 10]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[9, 10, 12, 14, 14], heights1=[6, 5, 7, 10, 10]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_3", - "sat": "def sat(perms: List[List[int]], prices0=[2, 5, 4, 2, 7, 3, 4, 5, 2, 3, 2, 1, 2, 7, 6, 1, 5, 2, 4, 6, 3, 7, 1, 2, 3, 5, 2, 2, 2, 2, 6, 5, 0, 2, 2, 0, 7, 3, 6, 4, 7, 0, 1, 5, 6, 1, 7, 6, 5, 4, 7, 7, 2, 5, 4, 5, 1, 4, 3, 3, 0, 2, 4, 0, 3, 0, 6, 4, 2, 6, 7, 5, 0, 5, 6, 2], prices1=[4, 5, 2, 5, 7, 0, 6, 6, 4, 5, 5, 6, 6, 2, 5, 4, 6, 0, 3, 3, 4, 5, 7, 7, 3, 3, 2, 5, 1, 7, 5, 6, 6, 3, 1, 4, 5, 0, 6, 7, 3, 7, 1, 5, 7, 4, 1, 0, 3, 6, 0, 1, 3, 3, 3, 5, 0, 4, 7, 3, 3, 2, 2, 3, 7, 7, 1, 1, 2, 2, 2, 5, 4, 7, 3, 0], heights0=[5, 4, 8, 9, 9, 11, 13, 6, 6, 6, 9, 13, 15, 8, 7, 14, 6, 5, 12, 7, 14, 9, 6, 13, 3, 10, 11, 8, 4, 14, 10, 10, 4, 8, 3, 7, 11, 8, 5, 5, 10, 11, 9, 9, 7, 11, 3, 13, 15, 5, 3, 7, 8, 10, 8, 13, 12, 3, 4, 13, 7, 7, 5, 5, 6, 10, 8, 11, 7, 5, 10, 15, 4, 15, 6, 8], heights1=[5, 9, 4, 4, 8, 7, 10, 1, 2, 5, 5, 3, 4, 1, 10, 1, 5, 3, 3, 5, 4, 8, 3, 9, 10, 5, 6, 9, 10, 2, 10, 4, 6, 10, 4, 3, 2, 4, 9, 2, 7, 8, 7, 7, 9, 10, 9, 1, 7, 6, 2, 4, 2, 10, 6, 6, 10, 2, 5, 3, 10, 5, 10, 4, 6, 2, 8, 5, 3, 10, 1, 8, 6, 2, 2, 2]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[2, 5, 4, 2, 7, 3, 4, 5, 2, 3, 2, 1, 2, 7, 6, 1, 5, 2, 4, 6, 3, 7, 1, 2, 3, 5, 2, 2, 2, 2, 6, 5, 0, 2, 2, 0, 7, 3, 6, 4, 7, 0, 1, 5, 6, 1, 7, 6, 5, 4, 7, 7, 2, 5, 4, 5, 1, 4, 3, 3, 0, 2, 4, 0, 3, 0, 6, 4, 2, 6, 7, 5, 0, 5, 6, 2], prices1=[4, 5, 2, 5, 7, 0, 6, 6, 4, 5, 5, 6, 6, 2, 5, 4, 6, 0, 3, 3, 4, 5, 7, 7, 3, 3, 2, 5, 1, 7, 5, 6, 6, 3, 1, 4, 5, 0, 6, 7, 3, 7, 1, 5, 7, 4, 1, 0, 3, 6, 0, 1, 3, 3, 3, 5, 0, 4, 7, 3, 3, 2, 2, 3, 7, 7, 1, 1, 2, 2, 2, 5, 4, 7, 3, 0], heights0=[5, 4, 8, 9, 9, 11, 13, 6, 6, 6, 9, 13, 15, 8, 7, 14, 6, 5, 12, 7, 14, 9, 6, 13, 3, 10, 11, 8, 4, 14, 10, 10, 4, 8, 3, 7, 11, 8, 5, 5, 10, 11, 9, 9, 7, 11, 3, 13, 15, 5, 3, 7, 8, 10, 8, 13, 12, 3, 4, 13, 7, 7, 5, 5, 6, 10, 8, 11, 7, 5, 10, 15, 4, 15, 6, 8], heights1=[5, 9, 4, 4, 8, 7, 10, 1, 2, 5, 5, 3, 4, 1, 10, 1, 5, 3, 3, 5, 4, 8, 3, 9, 10, 5, 6, 9, 10, 2, 10, 4, 6, 10, 4, 3, 2, 4, 9, 2, 7, 8, 7, 7, 9, 10, 9, 1, 7, 6, 2, 4, 2, 10, 6, 6, 10, 2, 5, 3, 10, 5, 10, 4, 6, 2, 8, 5, 3, 10, 1, 8, 6, 2, 2, 2]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_4", - "sat": "def sat(perms: List[List[int]], prices0=[3, 6, 4, 0, 5, 6, 4, 3, 1, 7, 0, 4, 7, 5, 6, 1, 3, 3, 7, 4, 2, 5, 1, 7, 6, 7, 6, 3, 0, 2, 1, 7, 4, 3, 2, 7, 1, 3, 7, 6, 7, 0, 2, 0, 1, 1, 1, 3, 1, 1, 0, 0, 5, 2, 4, 6, 1, 5, 2, 5, 1, 5, 5, 3, 1, 7, 7, 1, 3, 6, 0, 6, 0, 0, 3, 6, 1], prices1=[1, 4, 0, 6, 3, 1, 4, 6, 3, 0, 4, 7, 2, 6, 4, 0, 2, 4, 6, 7, 7, 0, 4, 2, 6, 1, 6, 3, 0, 5, 3, 6, 0, 1, 4, 1, 0, 5, 1, 3, 4, 0, 0, 2, 5, 5, 5, 1, 2, 7, 7, 0, 7, 0, 7, 7, 5, 0, 1, 1, 0, 5, 7, 1, 0, 0, 2, 4, 1, 2, 6, 2, 3, 4, 0, 7, 6], heights0=[12, 13, 8, 14, 12, 10, 15, 4, 13, 8, 7, 4, 8, 4, 7, 13, 7, 11, 6, 7, 11, 14, 11, 13, 10, 10, 5, 9, 12, 5, 11, 12, 12, 6, 4, 11, 5, 3, 4, 6, 3, 4, 3, 15, 4, 13, 8, 10, 10, 10, 14, 6, 10, 7, 6, 4, 6, 12, 8, 11, 7, 9, 7, 12, 6, 8, 6, 7, 8, 5, 13, 6, 10, 13, 5, 7, 10], heights1=[5, 8, 9, 3, 4, 7, 2, 7, 10, 10, 10, 3, 3, 8, 3, 9, 4, 5, 8, 9, 1, 4, 2, 2, 5, 3, 4, 4, 2, 6, 8, 2, 6, 9, 9, 6, 10, 7, 2, 7, 1, 10, 8, 6, 2, 10, 6, 8, 4, 3, 3, 9, 5, 9, 3, 7, 5, 10, 3, 1, 8, 10, 5, 6, 3, 8, 1, 7, 3, 1, 10, 4, 8, 1, 2, 5, 2]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[3, 6, 4, 0, 5, 6, 4, 3, 1, 7, 0, 4, 7, 5, 6, 1, 3, 3, 7, 4, 2, 5, 1, 7, 6, 7, 6, 3, 0, 2, 1, 7, 4, 3, 2, 7, 1, 3, 7, 6, 7, 0, 2, 0, 1, 1, 1, 3, 1, 1, 0, 0, 5, 2, 4, 6, 1, 5, 2, 5, 1, 5, 5, 3, 1, 7, 7, 1, 3, 6, 0, 6, 0, 0, 3, 6, 1], prices1=[1, 4, 0, 6, 3, 1, 4, 6, 3, 0, 4, 7, 2, 6, 4, 0, 2, 4, 6, 7, 7, 0, 4, 2, 6, 1, 6, 3, 0, 5, 3, 6, 0, 1, 4, 1, 0, 5, 1, 3, 4, 0, 0, 2, 5, 5, 5, 1, 2, 7, 7, 0, 7, 0, 7, 7, 5, 0, 1, 1, 0, 5, 7, 1, 0, 0, 2, 4, 1, 2, 6, 2, 3, 4, 0, 7, 6], heights0=[12, 13, 8, 14, 12, 10, 15, 4, 13, 8, 7, 4, 8, 4, 7, 13, 7, 11, 6, 7, 11, 14, 11, 13, 10, 10, 5, 9, 12, 5, 11, 12, 12, 6, 4, 11, 5, 3, 4, 6, 3, 4, 3, 15, 4, 13, 8, 10, 10, 10, 14, 6, 10, 7, 6, 4, 6, 12, 8, 11, 7, 9, 7, 12, 6, 8, 6, 7, 8, 5, 13, 6, 10, 13, 5, 7, 10], heights1=[5, 8, 9, 3, 4, 7, 2, 7, 10, 10, 10, 3, 3, 8, 3, 9, 4, 5, 8, 9, 1, 4, 2, 2, 5, 3, 4, 4, 2, 6, 8, 2, 6, 9, 9, 6, 10, 7, 2, 7, 1, 10, 8, 6, 2, 10, 6, 8, 4, 3, 3, 9, 5, 9, 3, 7, 5, 10, 3, 1, 8, 10, 5, 6, 3, 8, 1, 7, 3, 1, 10, 4, 8, 1, 2, 5, 2]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_5", - "sat": "def sat(perms: List[List[int]], prices0=[1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0], prices1=[1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0], heights0=[12, 4, 10, 5, 12, 2, 11, 6, 3, 8, 6, 7, 14, 11, 12, 9, 11, 13], heights1=[9, 8, 2, 2, 3, 2, 8, 8, 6, 1, 2, 4, 7, 10, 7, 9, 9, 8]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0], prices1=[1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0], heights0=[12, 4, 10, 5, 12, 2, 11, 6, 3, 8, 6, 7, 14, 11, 12, 9, 11, 13], heights1=[9, 8, 2, 2, 3, 2, 8, 8, 6, 1, 2, 4, 7, 10, 7, 9, 9, 8]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_6", - "sat": "def sat(perms: List[List[int]], prices0=[0, 0, 0, 0, 0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0, 0, 0, 0, 0], heights0=[10, 7, 6, 8, 9, 10, 6, 10, 4], heights1=[6, 5, 2, 1, 7, 5, 6, 4, 1]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[0, 0, 0, 0, 0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0, 0, 0, 0, 0], heights0=[10, 7, 6, 8, 9, 10, 6, 10, 4], heights1=[6, 5, 2, 1, 7, 5, 6, 4, 1]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_7", - "sat": "def sat(perms: List[List[int]], prices0=[1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1], prices1=[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1], heights0=[13, 6, 5, 8, 11, 11, 10, 10, 9, 5, 4, 5, 5, 3, 12, 8, 4], heights1=[4, 3, 2, 7, 8, 5, 5, 2, 2, 3, 5, 10, 4, 3, 2, 10, 6]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1], prices1=[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1], heights0=[13, 6, 5, 8, 11, 11, 10, 10, 9, 5, 4, 5, 5, 3, 12, 8, 4], heights1=[4, 3, 2, 7, 8, 5, 5, 2, 2, 3, 5, 10, 4, 3, 2, 10, 6]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_8", - "sat": "def sat(perms: List[List[int]], prices0=[1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1], prices1=[1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0], heights0=[12, 12, 5, 11, 13, 8, 6, 8, 7, 3, 13, 9, 6, 8, 12, 10, 8], heights1=[8, 3, 7, 8, 5, 9, 5, 3, 5, 4, 6, 6, 10, 9, 9, 1, 5]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1], prices1=[1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0], heights0=[12, 12, 5, 11, 13, 8, 6, 8, 7, 3, 13, 9, 6, 8, 12, 10, 8], heights1=[8, 3, 7, 8, 5, 9, 5, 3, 5, 4, 6, 6, 10, 9, 9, 1, 5]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "BiPermutations_9", - "sat": "def sat(perms: List[List[int]], prices0=[0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1], prices1=[0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0], heights0=[9, 8, 4, 6, 13, 3, 6, 6, 6, 8, 10, 9, 10, 13, 7, 8], heights1=[5, 10, 5, 3, 1, 2, 5, 3, 2, 1, 5, 3, 6, 3, 8, 5]):\n \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", - "sols": [ - "def sol(prices0=[0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1], prices1=[0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0], heights0=[9, 8, 4, 6, 13, 3, 6, 6, 6, 8, 10, 9, 10, 13, 7, 8], heights1=[5, 10, 5, 3, 1, 2, 5, 3, 2, 1, 5, 3, 6, 3, 8, 5]):\n n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_0", - "sat": "def sat(indices: List[int], H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_1", - "sat": "def sat(indices: List[int], H=100000, alpha=17, beta=6, xs=[0, 3069, 5319, 5373, 5466, 5479, 5519, 6629, 9652, 9919, 11009, 11175, 11348, 12167, 13016, 13109, 13216, 13250, 13253, 14265, 15018, 16389, 20993, 22240, 23259, 23276, 23410, 25158, 27034, 30140, 31404, 31521, 31619, 31683, 31692, 31705, 34207, 55515, 64781, 71416, 76305, 77516, 81021, 85257, 85806, 86243, 91008, 97806, 100000], ys=[81112, 12485, 94379, 88854, 987, 76485, 42941, 64723, 81743, 86552, 93967, 41028, 583, 23986, 45831, 34204, 5856, 40242, 63968, 6777, 16745, 36621, 70993, 45840, 41901, 19003, 56321, 76109, 36482, 43746, 94401, 24752, 56908, 76875, 59498, 38391, 6693, 23419, 73740, 47413, 27170, 34095, 80071, 53942, 76129, 80538, 44026, 72982, 75701], thresh=4786941056):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=17, beta=6, xs=[0, 3069, 5319, 5373, 5466, 5479, 5519, 6629, 9652, 9919, 11009, 11175, 11348, 12167, 13016, 13109, 13216, 13250, 13253, 14265, 15018, 16389, 20993, 22240, 23259, 23276, 23410, 25158, 27034, 30140, 31404, 31521, 31619, 31683, 31692, 31705, 34207, 55515, 64781, 71416, 76305, 77516, 81021, 85257, 85806, 86243, 91008, 97806, 100000], ys=[81112, 12485, 94379, 88854, 987, 76485, 42941, 64723, 81743, 86552, 93967, 41028, 583, 23986, 45831, 34204, 5856, 40242, 63968, 6777, 16745, 36621, 70993, 45840, 41901, 19003, 56321, 76109, 36482, 43746, 94401, 24752, 56908, 76875, 59498, 38391, 6693, 23419, 73740, 47413, 27170, 34095, 80071, 53942, 76129, 80538, 44026, 72982, 75701], thresh=4786941056): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_2", - "sat": "def sat(indices: List[int], H=100000, alpha=21, beta=40, xs=[0, 8094, 57578, 62776, 83547, 87398, 95828, 100000], ys=[14832, 27072, 77311, 50782, 82688, 11061, 50767, 3696], thresh=143624404582):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=21, beta=40, xs=[0, 8094, 57578, 62776, 83547, 87398, 95828, 100000], ys=[14832, 27072, 77311, 50782, 82688, 11061, 50767, 3696], thresh=143624404582): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_3", - "sat": "def sat(indices: List[int], H=100000, alpha=975, beta=546, xs=[0, 102, 174, 281, 458, 554, 583, 590, 646, 1592, 1795, 1805, 1835, 1839, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1843, 2357, 2683, 3152, 3159, 3167, 3170, 3170, 3171, 3171, 3172, 3172, 3172, 3172, 3172, 3173, 4025, 4274, 4282, 4465, 4520, 4529, 4666, 4676, 4901, 4905, 5003, 5295, 5510, 5553, 5585, 5585, 5638, 5973, 6136, 6317, 6329, 6374, 6400, 6405, 6407, 6407, 6409, 6409, 6409, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6411, 6456, 6462, 6462, 6469, 6482, 6486, 6881, 6919, 7240, 7510, 7599, 7995, 8173, 8249, 8284, 8296, 8298, 8298, 8299, 8301, 8427, 8701, 8751, 8945, 9141, 9166, 9208, 9308, 9321, 9327, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9333, 10630, 11062, 11173, 11286, 11294, 11319, 11322, 11367, 11372, 11376, 11398, 11399, 11403, 11409, 11451, 11459, 11519, 11660, 11687, 11691, 11694, 11694, 11697, 12232, 12313, 12314, 12316, 12321, 12322, 12322, 12322, 12323, 13101, 13207, 13274, 13445, 13512, 13687, 13911, 13987, 14251, 14255, 14306, 14570, 14594, 14606, 14606, 14608, 14998, 15232, 15237, 15633, 15795, 15831, 15991, 16176, 16179, 16189, 16228, 16339, 16450, 16540, 16777, 16851, 16889, 17291, 17694, 18333, 18356, 19390, 19449, 19454, 19750, 20562, 22013, 22332, 22374, 22591, 23234, 23276, 23281, 23296, 23351, 23397, 23762, 23844, 23859, 23866, 23894, 23943, 24311, 24379, 24958, 25140, 25160, 25178, 25211, 25219, 25235, 25378, 25929, 26078, 26181, 26474, 26804, 26821, 26838, 26843, 26858, 26894, 26894, 26894, 26895, 27181, 27302, 27329, 27365, 27374, 27380, 27381, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27383, 27386, 27418, 27450, 27463, 27525, 27529, 27552, 27559, 27562, 27562, 27563, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27565, 27721, 27801, 27818, 27882, 28083, 28148, 28673, 29079, 29102, 29155, 29158, 29162, 29193, 29256, 29576, 29991, 29992, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29997, 30025, 30083, 30088, 30146, 30173, 30182, 30305, 30408, 30596, 30905, 31000, 31405, 31558, 31588, 31663, 31664, 31664, 31667, 31670, 31674, 31676, 31703, 32815, 32821, 32949, 33977, 34036, 34403, 34413, 34464, 34505, 34509, 34511, 34772, 34972, 35021, 35068, 35259, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35273, 35311, 35343, 35611, 35950, 36192, 36400, 36410, 36622, 36820, 36883, 36959, 36960, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36964, 37010, 37035, 37311, 37660, 37733, 37934, 38287, 38539, 39425, 39441, 39473, 40033, 40124, 40319, 40609, 40643, 40673, 40727, 40741, 40742, 40744, 40750, 41021, 41080, 41311, 41319, 41321, 41335, 41344, 41344, 41345, 41345, 41345, 41345, 41345, 41346, 41532, 41554, 42011, 42164, 42187, 42276, 42566, 42675, 43393, 43473, 43480, 43504, 43504, 43504, 43504, 43504, 43505, 44026, 44718, 45006, 45128, 45193, 45581, 45643, 45679, 45684, 45687, 45858, 45958, 46022, 46126, 46367, 46712, 46849, 47743, 47968, 48262, 49272, 49376, 50058, 50436, 51804, 51966, 52122, 52374, 53401, 53638, 54722, 55797, 55906, 56812, 56839, 57005, 58384, 58720, 58959, 59074, 59209, 59512, 59785, 60798, 61136, 61198, 61505, 62052, 62540, 62555, 62783, 63241, 63829, 64155, 64422, 64520, 65271, 65297, 67452, 67628, 68258, 68379, 69233, 69496, 69613, 69774, 70090, 70092, 70759, 70770, 70809, 71196, 71265, 71529, 72250, 72476, 72523, 72556, 72829, 73209, 73477, 73739, 73843, 74249, 74728, 74988, 75425, 75988, 76032, 76096, 76152, 76222, 76751, 77227, 77631, 77995, 78061, 78169, 78400, 78784, 79499, 80385, 80551, 80627, 80660, 81059, 81143, 81405, 81665, 82904, 83595, 83957, 83996, 84043, 84739, 85031, 85987, 86319, 86864, 86933, 86947, 87127, 87520, 87543, 87848, 88057, 88437, 89195, 89401, 90469, 90756, 90761, 91175, 91975, 92907, 92987, 94337, 94470, 95290, 96267, 96378, 96635, 97113, 97608, 97663, 97721, 98148, 98536, 98629, 98960, 99036, 99763, 99793, 100000], ys=[2773, 47376, 17008, 24785, 21921, 60359, 33137, 72146, 76002, 49654, 25696, 25832, 72474, 2917, 18229, 2385, 66151, 51868, 4760, 69187, 67221, 14320, 24425, 88890, 24553, 78751, 70869, 11279, 12625, 84959, 28885, 87499, 61816, 41222, 81997, 1265, 63632, 12863, 54939, 56081, 35629, 37122, 49133, 24893, 41731, 9182, 34407, 90952, 42360, 43861, 99296, 80331, 78826, 19484, 90699, 30578, 71697, 10304, 61318, 89870, 38599, 71160, 22805, 17850, 60106, 76742, 14571, 74280, 88847, 53537, 84726, 7279, 55376, 47707, 78111, 14855, 20855, 89936, 20706, 98672, 5385, 76357, 90172, 48891, 6243, 82298, 64602, 99637, 83220, 87261, 26190, 39457, 12610, 44567, 54545, 71246, 96608, 5086, 65811, 15907, 21012, 17278, 1139, 54815, 52416, 19440, 44857, 16066, 22379, 73573, 36087, 54255, 60304, 30497, 1202, 95520, 48378, 68296, 14032, 50456, 60555, 80390, 70975, 17531, 3761, 46399, 48927, 96320, 79008, 25360, 67058, 26409, 29891, 324, 67141, 24534, 69987, 11711, 99837, 82260, 8818, 67647, 66046, 76727, 25049, 48694, 96244, 42767, 13120, 53729, 90754, 47498, 40257, 7844, 79665, 35900, 33567, 80332, 68427, 29914, 91621, 38959, 35796, 7435, 65460, 434, 2785, 4710, 80793, 20827, 22155, 90320, 5066, 24178, 18875, 51294, 5222, 95816, 14268, 68478, 96761, 66479, 67335, 51513, 78673, 73143, 11679, 85300, 88785, 1004, 18064, 91085, 18999, 25640, 45379, 74924, 94706, 46916, 32682, 31715, 3086, 49466, 85098, 49913, 44647, 82331, 27219, 13875, 58769, 3667, 10298, 44795, 62204, 21497, 58731, 12965, 62569, 72238, 49525, 22899, 84200, 3845, 98178, 924, 35984, 32417, 22686, 22620, 47458, 87867, 29566, 77085, 10960, 14876, 89730, 21641, 13636, 79167, 53472, 30103, 56335, 39274, 74071, 68958, 66408, 47354, 84728, 28113, 99860, 49955, 79844, 1186, 85981, 39037, 60464, 80363, 89186, 92541, 16343, 48363, 7581, 73306, 68325, 65829, 84163, 74355, 53786, 58715, 98906, 39439, 27860, 76391, 76589, 39834, 27137, 81688, 64132, 49120, 56144, 86941, 95518, 72009, 82728, 96067, 97712, 79469, 44330, 67454, 39941, 97408, 58132, 5066, 93590, 77162, 72882, 39621, 31441, 23172, 65710, 88436, 34469, 86816, 9665, 5643, 68076, 70549, 80805, 94994, 91769, 84542, 62168, 74918, 61406, 45287, 5793, 54563, 3652, 92584, 61367, 28505, 30248, 20120, 86422, 81094, 83631, 58464, 55958, 40896, 81384, 55062, 40915, 58556, 32091, 34368, 54084, 77250, 25828, 15620, 90399, 20250, 73405, 26695, 2032, 83486, 95048, 94554, 30946, 28573, 74157, 43422, 85194, 47436, 36847, 40337, 44865, 44811, 69652, 13169, 41240, 48298, 72630, 51768, 49849, 81558, 51868, 75819, 14511, 36733, 35093, 77864, 36881, 97122, 60008, 48465, 10154, 94832, 12514, 47840, 15591, 65517, 68261, 63597, 80341, 6530, 76786, 97631, 2526, 47318, 83685, 23732, 20477, 36378, 4066, 79691, 93070, 83021, 37168, 52019, 85092, 72854, 20879, 55104, 61225, 87611, 84521, 9011, 27496, 39666, 61677, 49131, 80714, 29320, 98393, 71579, 39547, 34736, 99974, 53333, 26106, 50745, 92975, 84628, 24607, 5133, 38793, 24284, 43324, 50981, 51005, 22088, 10404, 59675, 84882, 52975, 94861, 17852, 74017, 42533, 53763, 1986, 59478, 96769, 77976, 58875, 25744, 68724, 10130, 52144, 73428, 10610, 97509, 64410, 37812, 59809, 8455, 65712, 89789, 87542, 22274, 94253, 59627, 42450, 26524, 12018, 35043, 27433, 94055, 79108, 64297, 39011, 68974, 69586, 87982, 71372, 62430, 43056, 15425, 80083, 68963, 38661, 45853, 44335, 71876, 28982, 2264, 61889, 6454, 58072, 242, 93781, 71755, 66290, 90497, 54071, 55444, 64765, 4058, 79429, 41630, 15024, 64603, 98934, 48326, 56618, 55522, 37470, 57495, 31975, 70970, 31709, 31945, 64378, 12831, 51921, 76994, 31476, 72360, 63265, 35422, 88813, 58864, 74401, 91076, 37836, 55027, 95549, 15618, 34969, 60039, 61528, 3321, 94087, 37316, 81288, 81268, 71368, 95150, 57625, 34979, 60444, 45713, 87417, 17729, 30256, 98375, 2527, 95619, 71929, 47741, 59345, 50186, 73234, 74055, 49179, 14980, 21318, 96240, 9917, 75849, 56534, 85371, 63765, 23611, 47419, 34402, 48943, 26048, 69611, 29375, 29430, 6553, 97428, 97806, 80481, 26953, 42600, 59032, 65854, 66035, 48964, 22269, 52171, 14513, 65468, 66339, 25356, 52393, 7853, 24853, 78187, 83930, 67307, 45091, 41518, 52101, 76047, 40529, 36318, 3755, 62784, 77519, 22200, 70689, 33135, 81934, 72265, 2971, 91369, 53872, 45818, 57790, 21607, 66120, 26696, 92619, 47305, 65861, 60602, 66559, 2054, 57820, 19261, 6596, 56435, 12167, 29581, 17598, 1729, 77111, 26411, 66914, 14722, 39615, 27758, 96587, 69153, 65407, 65952, 52604, 28856, 58297, 94511, 71028, 75000, 60829, 12334, 21754, 20048, 5488, 11184, 80078, 64552, 23655, 75130, 79850, 40299, 92970, 89686, 72265, 49906, 84405, 90304, 74509, 97608, 32383, 77555, 89457, 96493, 25090, 79130, 5238, 44242, 54197, 87027, 77862, 44899, 39596, 50314, 66002, 34789, 83144, 62992, 9580, 89205, 9252, 54862, 53171, 64280, 13361, 17974, 66583, 40129, 4768, 25940, 96021, 80579, 7235, 63726, 87348, 21304, 86007, 94534, 57733, 43068, 31145, 34295, 12128, 97580, 83653, 28797, 69504, 29790, 73946, 59341, 48155, 1463, 80083, 32469, 71782, 20850, 96205, 42015, 73041, 55026, 56528, 41902, 12404, 62462, 81533, 16708, 7415, 68387, 80571, 32027, 35225, 10946, 94144, 4194, 43504, 49796, 50362, 95023, 52994, 95205, 36035, 71247, 41720, 6865, 17427, 36924, 61894, 38538, 67742, 44575, 14625, 79002, 90627, 8841, 84462, 7945, 24927, 82064, 46459, 52759, 31226, 5657, 79441, 64942, 70601, 84159, 3713, 5819, 33208, 82518, 79984, 11805, 65691, 27461, 79491, 31649, 44872, 55358, 59545, 43403, 25937, 57129, 95086, 33073, 66761, 54601, 58418, 97317, 55033, 52664, 98134, 37723, 11301, 82638, 57741, 7107, 3684, 12886, 23805, 51818, 91767, 69982, 49206, 31880, 98404, 66281, 65126, 58401, 7132, 42216, 82869, 16032, 26488, 60581, 34013, 63817, 6519, 89872, 31855, 22997, 69212, 73604, 76079, 64953, 98735, 44812, 4732, 94488, 84054, 42787, 46869, 45010, 20732, 5560, 56309, 77803, 42883, 66324, 49402, 64847, 31627, 94225, 77195, 95635, 68166, 31386, 63128, 31631, 70432, 46143, 52182, 8113, 84606, 51625, 55982, 29418, 64146, 69813, 44592, 79603, 46634, 32362, 62318, 18402, 68531, 53415, 19852, 28919, 62513, 79532, 49718, 33065, 56835, 64306, 60638, 70658, 79161, 27512, 68976, 89331, 29937, 12813, 57173, 27550, 84813, 60721, 11582, 44931, 88702, 7688, 52433, 55498, 95194, 39528, 6913, 6693, 94386, 842, 12398, 45874, 68922, 71749, 4672, 93255, 10276, 30051, 18146, 1369, 34708, 13026, 81431, 18801, 4379, 1238, 53213, 33648, 8064, 76802, 41132, 22338, 2817, 16671, 85926, 86066, 41124, 36200, 37286, 96525, 59693, 83181, 87393, 35298, 17208, 90473, 22239, 61861, 41594, 2519, 54614, 59722, 37429, 49717, 81394, 55456, 64709, 76277, 23690, 55080, 41336, 29750, 97329, 28604, 24728, 76992, 67044, 34563, 32395, 24170, 30848, 56474, 78881, 4772, 23177, 28993, 11230, 77390, 62191, 24747, 29986, 50371, 34979, 66772, 80075, 19549, 78848, 11352, 48373, 96733, 93428, 45892, 86184, 62894, 19948, 70176, 16630, 69200, 28933, 93458, 73504, 54975, 55489, 8787, 47519, 97887, 16335], thresh=44238370995):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=975, beta=546, xs=[0, 102, 174, 281, 458, 554, 583, 590, 646, 1592, 1795, 1805, 1835, 1839, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1843, 2357, 2683, 3152, 3159, 3167, 3170, 3170, 3171, 3171, 3172, 3172, 3172, 3172, 3172, 3173, 4025, 4274, 4282, 4465, 4520, 4529, 4666, 4676, 4901, 4905, 5003, 5295, 5510, 5553, 5585, 5585, 5638, 5973, 6136, 6317, 6329, 6374, 6400, 6405, 6407, 6407, 6409, 6409, 6409, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6411, 6456, 6462, 6462, 6469, 6482, 6486, 6881, 6919, 7240, 7510, 7599, 7995, 8173, 8249, 8284, 8296, 8298, 8298, 8299, 8301, 8427, 8701, 8751, 8945, 9141, 9166, 9208, 9308, 9321, 9327, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9333, 10630, 11062, 11173, 11286, 11294, 11319, 11322, 11367, 11372, 11376, 11398, 11399, 11403, 11409, 11451, 11459, 11519, 11660, 11687, 11691, 11694, 11694, 11697, 12232, 12313, 12314, 12316, 12321, 12322, 12322, 12322, 12323, 13101, 13207, 13274, 13445, 13512, 13687, 13911, 13987, 14251, 14255, 14306, 14570, 14594, 14606, 14606, 14608, 14998, 15232, 15237, 15633, 15795, 15831, 15991, 16176, 16179, 16189, 16228, 16339, 16450, 16540, 16777, 16851, 16889, 17291, 17694, 18333, 18356, 19390, 19449, 19454, 19750, 20562, 22013, 22332, 22374, 22591, 23234, 23276, 23281, 23296, 23351, 23397, 23762, 23844, 23859, 23866, 23894, 23943, 24311, 24379, 24958, 25140, 25160, 25178, 25211, 25219, 25235, 25378, 25929, 26078, 26181, 26474, 26804, 26821, 26838, 26843, 26858, 26894, 26894, 26894, 26895, 27181, 27302, 27329, 27365, 27374, 27380, 27381, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27383, 27386, 27418, 27450, 27463, 27525, 27529, 27552, 27559, 27562, 27562, 27563, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27565, 27721, 27801, 27818, 27882, 28083, 28148, 28673, 29079, 29102, 29155, 29158, 29162, 29193, 29256, 29576, 29991, 29992, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29997, 30025, 30083, 30088, 30146, 30173, 30182, 30305, 30408, 30596, 30905, 31000, 31405, 31558, 31588, 31663, 31664, 31664, 31667, 31670, 31674, 31676, 31703, 32815, 32821, 32949, 33977, 34036, 34403, 34413, 34464, 34505, 34509, 34511, 34772, 34972, 35021, 35068, 35259, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35273, 35311, 35343, 35611, 35950, 36192, 36400, 36410, 36622, 36820, 36883, 36959, 36960, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36964, 37010, 37035, 37311, 37660, 37733, 37934, 38287, 38539, 39425, 39441, 39473, 40033, 40124, 40319, 40609, 40643, 40673, 40727, 40741, 40742, 40744, 40750, 41021, 41080, 41311, 41319, 41321, 41335, 41344, 41344, 41345, 41345, 41345, 41345, 41345, 41346, 41532, 41554, 42011, 42164, 42187, 42276, 42566, 42675, 43393, 43473, 43480, 43504, 43504, 43504, 43504, 43504, 43505, 44026, 44718, 45006, 45128, 45193, 45581, 45643, 45679, 45684, 45687, 45858, 45958, 46022, 46126, 46367, 46712, 46849, 47743, 47968, 48262, 49272, 49376, 50058, 50436, 51804, 51966, 52122, 52374, 53401, 53638, 54722, 55797, 55906, 56812, 56839, 57005, 58384, 58720, 58959, 59074, 59209, 59512, 59785, 60798, 61136, 61198, 61505, 62052, 62540, 62555, 62783, 63241, 63829, 64155, 64422, 64520, 65271, 65297, 67452, 67628, 68258, 68379, 69233, 69496, 69613, 69774, 70090, 70092, 70759, 70770, 70809, 71196, 71265, 71529, 72250, 72476, 72523, 72556, 72829, 73209, 73477, 73739, 73843, 74249, 74728, 74988, 75425, 75988, 76032, 76096, 76152, 76222, 76751, 77227, 77631, 77995, 78061, 78169, 78400, 78784, 79499, 80385, 80551, 80627, 80660, 81059, 81143, 81405, 81665, 82904, 83595, 83957, 83996, 84043, 84739, 85031, 85987, 86319, 86864, 86933, 86947, 87127, 87520, 87543, 87848, 88057, 88437, 89195, 89401, 90469, 90756, 90761, 91175, 91975, 92907, 92987, 94337, 94470, 95290, 96267, 96378, 96635, 97113, 97608, 97663, 97721, 98148, 98536, 98629, 98960, 99036, 99763, 99793, 100000], ys=[2773, 47376, 17008, 24785, 21921, 60359, 33137, 72146, 76002, 49654, 25696, 25832, 72474, 2917, 18229, 2385, 66151, 51868, 4760, 69187, 67221, 14320, 24425, 88890, 24553, 78751, 70869, 11279, 12625, 84959, 28885, 87499, 61816, 41222, 81997, 1265, 63632, 12863, 54939, 56081, 35629, 37122, 49133, 24893, 41731, 9182, 34407, 90952, 42360, 43861, 99296, 80331, 78826, 19484, 90699, 30578, 71697, 10304, 61318, 89870, 38599, 71160, 22805, 17850, 60106, 76742, 14571, 74280, 88847, 53537, 84726, 7279, 55376, 47707, 78111, 14855, 20855, 89936, 20706, 98672, 5385, 76357, 90172, 48891, 6243, 82298, 64602, 99637, 83220, 87261, 26190, 39457, 12610, 44567, 54545, 71246, 96608, 5086, 65811, 15907, 21012, 17278, 1139, 54815, 52416, 19440, 44857, 16066, 22379, 73573, 36087, 54255, 60304, 30497, 1202, 95520, 48378, 68296, 14032, 50456, 60555, 80390, 70975, 17531, 3761, 46399, 48927, 96320, 79008, 25360, 67058, 26409, 29891, 324, 67141, 24534, 69987, 11711, 99837, 82260, 8818, 67647, 66046, 76727, 25049, 48694, 96244, 42767, 13120, 53729, 90754, 47498, 40257, 7844, 79665, 35900, 33567, 80332, 68427, 29914, 91621, 38959, 35796, 7435, 65460, 434, 2785, 4710, 80793, 20827, 22155, 90320, 5066, 24178, 18875, 51294, 5222, 95816, 14268, 68478, 96761, 66479, 67335, 51513, 78673, 73143, 11679, 85300, 88785, 1004, 18064, 91085, 18999, 25640, 45379, 74924, 94706, 46916, 32682, 31715, 3086, 49466, 85098, 49913, 44647, 82331, 27219, 13875, 58769, 3667, 10298, 44795, 62204, 21497, 58731, 12965, 62569, 72238, 49525, 22899, 84200, 3845, 98178, 924, 35984, 32417, 22686, 22620, 47458, 87867, 29566, 77085, 10960, 14876, 89730, 21641, 13636, 79167, 53472, 30103, 56335, 39274, 74071, 68958, 66408, 47354, 84728, 28113, 99860, 49955, 79844, 1186, 85981, 39037, 60464, 80363, 89186, 92541, 16343, 48363, 7581, 73306, 68325, 65829, 84163, 74355, 53786, 58715, 98906, 39439, 27860, 76391, 76589, 39834, 27137, 81688, 64132, 49120, 56144, 86941, 95518, 72009, 82728, 96067, 97712, 79469, 44330, 67454, 39941, 97408, 58132, 5066, 93590, 77162, 72882, 39621, 31441, 23172, 65710, 88436, 34469, 86816, 9665, 5643, 68076, 70549, 80805, 94994, 91769, 84542, 62168, 74918, 61406, 45287, 5793, 54563, 3652, 92584, 61367, 28505, 30248, 20120, 86422, 81094, 83631, 58464, 55958, 40896, 81384, 55062, 40915, 58556, 32091, 34368, 54084, 77250, 25828, 15620, 90399, 20250, 73405, 26695, 2032, 83486, 95048, 94554, 30946, 28573, 74157, 43422, 85194, 47436, 36847, 40337, 44865, 44811, 69652, 13169, 41240, 48298, 72630, 51768, 49849, 81558, 51868, 75819, 14511, 36733, 35093, 77864, 36881, 97122, 60008, 48465, 10154, 94832, 12514, 47840, 15591, 65517, 68261, 63597, 80341, 6530, 76786, 97631, 2526, 47318, 83685, 23732, 20477, 36378, 4066, 79691, 93070, 83021, 37168, 52019, 85092, 72854, 20879, 55104, 61225, 87611, 84521, 9011, 27496, 39666, 61677, 49131, 80714, 29320, 98393, 71579, 39547, 34736, 99974, 53333, 26106, 50745, 92975, 84628, 24607, 5133, 38793, 24284, 43324, 50981, 51005, 22088, 10404, 59675, 84882, 52975, 94861, 17852, 74017, 42533, 53763, 1986, 59478, 96769, 77976, 58875, 25744, 68724, 10130, 52144, 73428, 10610, 97509, 64410, 37812, 59809, 8455, 65712, 89789, 87542, 22274, 94253, 59627, 42450, 26524, 12018, 35043, 27433, 94055, 79108, 64297, 39011, 68974, 69586, 87982, 71372, 62430, 43056, 15425, 80083, 68963, 38661, 45853, 44335, 71876, 28982, 2264, 61889, 6454, 58072, 242, 93781, 71755, 66290, 90497, 54071, 55444, 64765, 4058, 79429, 41630, 15024, 64603, 98934, 48326, 56618, 55522, 37470, 57495, 31975, 70970, 31709, 31945, 64378, 12831, 51921, 76994, 31476, 72360, 63265, 35422, 88813, 58864, 74401, 91076, 37836, 55027, 95549, 15618, 34969, 60039, 61528, 3321, 94087, 37316, 81288, 81268, 71368, 95150, 57625, 34979, 60444, 45713, 87417, 17729, 30256, 98375, 2527, 95619, 71929, 47741, 59345, 50186, 73234, 74055, 49179, 14980, 21318, 96240, 9917, 75849, 56534, 85371, 63765, 23611, 47419, 34402, 48943, 26048, 69611, 29375, 29430, 6553, 97428, 97806, 80481, 26953, 42600, 59032, 65854, 66035, 48964, 22269, 52171, 14513, 65468, 66339, 25356, 52393, 7853, 24853, 78187, 83930, 67307, 45091, 41518, 52101, 76047, 40529, 36318, 3755, 62784, 77519, 22200, 70689, 33135, 81934, 72265, 2971, 91369, 53872, 45818, 57790, 21607, 66120, 26696, 92619, 47305, 65861, 60602, 66559, 2054, 57820, 19261, 6596, 56435, 12167, 29581, 17598, 1729, 77111, 26411, 66914, 14722, 39615, 27758, 96587, 69153, 65407, 65952, 52604, 28856, 58297, 94511, 71028, 75000, 60829, 12334, 21754, 20048, 5488, 11184, 80078, 64552, 23655, 75130, 79850, 40299, 92970, 89686, 72265, 49906, 84405, 90304, 74509, 97608, 32383, 77555, 89457, 96493, 25090, 79130, 5238, 44242, 54197, 87027, 77862, 44899, 39596, 50314, 66002, 34789, 83144, 62992, 9580, 89205, 9252, 54862, 53171, 64280, 13361, 17974, 66583, 40129, 4768, 25940, 96021, 80579, 7235, 63726, 87348, 21304, 86007, 94534, 57733, 43068, 31145, 34295, 12128, 97580, 83653, 28797, 69504, 29790, 73946, 59341, 48155, 1463, 80083, 32469, 71782, 20850, 96205, 42015, 73041, 55026, 56528, 41902, 12404, 62462, 81533, 16708, 7415, 68387, 80571, 32027, 35225, 10946, 94144, 4194, 43504, 49796, 50362, 95023, 52994, 95205, 36035, 71247, 41720, 6865, 17427, 36924, 61894, 38538, 67742, 44575, 14625, 79002, 90627, 8841, 84462, 7945, 24927, 82064, 46459, 52759, 31226, 5657, 79441, 64942, 70601, 84159, 3713, 5819, 33208, 82518, 79984, 11805, 65691, 27461, 79491, 31649, 44872, 55358, 59545, 43403, 25937, 57129, 95086, 33073, 66761, 54601, 58418, 97317, 55033, 52664, 98134, 37723, 11301, 82638, 57741, 7107, 3684, 12886, 23805, 51818, 91767, 69982, 49206, 31880, 98404, 66281, 65126, 58401, 7132, 42216, 82869, 16032, 26488, 60581, 34013, 63817, 6519, 89872, 31855, 22997, 69212, 73604, 76079, 64953, 98735, 44812, 4732, 94488, 84054, 42787, 46869, 45010, 20732, 5560, 56309, 77803, 42883, 66324, 49402, 64847, 31627, 94225, 77195, 95635, 68166, 31386, 63128, 31631, 70432, 46143, 52182, 8113, 84606, 51625, 55982, 29418, 64146, 69813, 44592, 79603, 46634, 32362, 62318, 18402, 68531, 53415, 19852, 28919, 62513, 79532, 49718, 33065, 56835, 64306, 60638, 70658, 79161, 27512, 68976, 89331, 29937, 12813, 57173, 27550, 84813, 60721, 11582, 44931, 88702, 7688, 52433, 55498, 95194, 39528, 6913, 6693, 94386, 842, 12398, 45874, 68922, 71749, 4672, 93255, 10276, 30051, 18146, 1369, 34708, 13026, 81431, 18801, 4379, 1238, 53213, 33648, 8064, 76802, 41132, 22338, 2817, 16671, 85926, 86066, 41124, 36200, 37286, 96525, 59693, 83181, 87393, 35298, 17208, 90473, 22239, 61861, 41594, 2519, 54614, 59722, 37429, 49717, 81394, 55456, 64709, 76277, 23690, 55080, 41336, 29750, 97329, 28604, 24728, 76992, 67044, 34563, 32395, 24170, 30848, 56474, 78881, 4772, 23177, 28993, 11230, 77390, 62191, 24747, 29986, 50371, 34979, 66772, 80075, 19549, 78848, 11352, 48373, 96733, 93428, 45892, 86184, 62894, 19948, 70176, 16630, 69200, 28933, 93458, 73504, 54975, 55489, 8787, 47519, 97887, 16335], thresh=44238370995): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_4", - "sat": "def sat(indices: List[int], H=100000, alpha=6, beta=2, xs=[0, 75202, 97997, 100000], ys=[24586, 7488, 4413, 30235], thresh=12359929344):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=6, beta=2, xs=[0, 75202, 97997, 100000], ys=[24586, 7488, 4413, 30235], thresh=12359929344): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_5", - "sat": "def sat(indices: List[int], H=100000, alpha=7, beta=12, xs=[0, 27471, 41263, 43238, 56183, 75871, 86174, 92027, 96943, 99152, 99752, 99766, 99893, 99989, 99996, 99997, 100000], ys=[41920, 55614, 26024, 3407, 53805, 24576, 12897, 53748, 52677, 71707, 56373, 13704, 33023, 44816, 47272, 7780, 69509], thresh=20090869297):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=7, beta=12, xs=[0, 27471, 41263, 43238, 56183, 75871, 86174, 92027, 96943, 99152, 99752, 99766, 99893, 99989, 99996, 99997, 100000], ys=[41920, 55614, 26024, 3407, 53805, 24576, 12897, 53748, 52677, 71707, 56373, 13704, 33023, 44816, 47272, 7780, 69509], thresh=20090869297): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_6", - "sat": "def sat(indices: List[int], H=100000, alpha=4, beta=4, xs=[0, 15244, 47279, 77951, 95877, 96537, 98528, 99838, 100000], ys=[26403, 46577, 2102, 56028, 69347, 3090, 62826, 74881, 11486], thresh=10109692424):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=4, beta=4, xs=[0, 15244, 47279, 77951, 95877, 96537, 98528, 99838, 100000], ys=[26403, 46577, 2102, 56028, 69347, 3090, 62826, 74881, 11486], thresh=10109692424): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_7", - "sat": "def sat(indices: List[int], H=100000, alpha=69, beta=19, xs=[0, 1861, 3666, 4139, 4225, 9507, 11409, 13945, 14037, 14248, 14659, 14713, 14961, 16378, 16435, 16480, 16920, 17859, 18235, 18263, 18513, 29862, 33584, 33743, 34559, 35127, 36023, 36655, 37979, 42312, 43152, 43941, 45343, 50462, 51995, 52104, 52186, 52194, 52204, 52208, 52208, 52210, 53608, 59391, 60850, 74440, 82226, 94858, 99237, 99757, 99851, 99879, 99892, 99978, 99987, 99988, 100000], ys=[24286, 19579, 73826, 48796, 66150, 67780, 74191, 46449, 16310, 21967, 43424, 16854, 39749, 29163, 4366, 59696, 81721, 53496, 56798, 36578, 53690, 16115, 80852, 28170, 64188, 64150, 9371, 51702, 39408, 29402, 70783, 5954, 21079, 95331, 87710, 63157, 53527, 62573, 4672, 3008, 59925, 14193, 12032, 86986, 94617, 46800, 18096, 35674, 29566, 51198, 49371, 50996, 58026, 84672, 2295, 22895, 54013], thresh=14340908539):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=69, beta=19, xs=[0, 1861, 3666, 4139, 4225, 9507, 11409, 13945, 14037, 14248, 14659, 14713, 14961, 16378, 16435, 16480, 16920, 17859, 18235, 18263, 18513, 29862, 33584, 33743, 34559, 35127, 36023, 36655, 37979, 42312, 43152, 43941, 45343, 50462, 51995, 52104, 52186, 52194, 52204, 52208, 52208, 52210, 53608, 59391, 60850, 74440, 82226, 94858, 99237, 99757, 99851, 99879, 99892, 99978, 99987, 99988, 100000], ys=[24286, 19579, 73826, 48796, 66150, 67780, 74191, 46449, 16310, 21967, 43424, 16854, 39749, 29163, 4366, 59696, 81721, 53496, 56798, 36578, 53690, 16115, 80852, 28170, 64188, 64150, 9371, 51702, 39408, 29402, 70783, 5954, 21079, 95331, 87710, 63157, 53527, 62573, 4672, 3008, 59925, 14193, 12032, 86986, 94617, 46800, 18096, 35674, 29566, 51198, 49371, 50996, 58026, 84672, 2295, 22895, 54013], thresh=14340908539): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_8", - "sat": "def sat(indices: List[int], H=100000, alpha=3, beta=0, xs=[0, 14431, 16747, 17428, 17469, 17514, 17548, 17672, 18434, 18466, 22244, 22573, 25887, 32701, 38105, 62470, 69286, 83392, 100000], ys=[90814, 93364, 70029, 14375, 45159, 63782, 87025, 31504, 76266, 86153, 29074, 55790, 47404, 69118, 65327, 79334, 91305, 90505, 73683], thresh=300078):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=3, beta=0, xs=[0, 14431, 16747, 17428, 17469, 17514, 17548, 17672, 18434, 18466, 22244, 22573, 25887, 32701, 38105, 62470, 69286, 83392, 100000], ys=[90814, 93364, 70029, 14375, 45159, 63782, 87025, 31504, 76266, 86153, 29074, 55790, 47404, 69118, 65327, 79334, 91305, 90505, 73683], thresh=300078): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "OptimalBridges_9", - "sat": "def sat(indices: List[int], H=100000, alpha=16, beta=9, xs=[0, 339, 8724, 8849, 8945, 9068, 9108, 9227, 9240, 9245, 9249, 9249, 9249, 9250, 9251, 44027, 65325, 73972, 100000], ys=[33900, 43692, 85964, 17578, 41788, 88753, 48083, 59785, 43280, 89762, 68888, 86676, 62115, 40817, 71248, 26896, 24053, 24113, 8592], thresh=22379880720):\n \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", - "sols": [ - "def sol(H=100000, alpha=16, beta=9, xs=[0, 339, 8724, 8849, 8945, 9068, 9108, 9227, 9240, 9245, 9249, 9249, 9249, 9250, 9251, 44027, 65325, 73972, 100000], ys=[33900, 43692, 85964, 17578, 41788, 88753, 48083, 59785, 43280, 89762, 68888, 86676, 62115, 40817, 71248, 26896, 24053, 24113, 8592], thresh=22379880720): # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_0", - "sat": "def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_1", - "sat": "def sat(position: List[List[int]], transcript: List[List[List[int]]]=[]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_2", - "sat": "def sat(position: List[List[int]], transcript=[[[6, 4], [5, 5]], [[4, 6], [6, 4]], [[7, 3], [5, 5]], [[3, 5], [4, 4]], [[4, 2], [6, 4]], [[3, 7], [2, 6]], [[5, 5], [6, 6]], [[7, 7], [5, 5], [7, 3]], [[1, 1], [0, 2]], [[7, 3], [6, 2]], [[0, 0], [1, 1]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[4, 4], [3, 3]], [[1, 1], [2, 2]], [[3, 3], [1, 1]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[0, 2], [1, 3]], [[2, 4], [0, 2]], [[3, 1], [2, 2]], [[1, 7], [0, 6]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[6, 4], [5, 5]], [[4, 6], [6, 4]], [[7, 3], [5, 5]], [[3, 5], [4, 4]], [[4, 2], [6, 4]], [[3, 7], [2, 6]], [[5, 5], [6, 6]], [[7, 7], [5, 5], [7, 3]], [[1, 1], [0, 2]], [[7, 3], [6, 2]], [[0, 0], [1, 1]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[4, 4], [3, 3]], [[1, 1], [2, 2]], [[3, 3], [1, 1]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[0, 2], [1, 3]], [[2, 4], [0, 2]], [[3, 1], [2, 2]], [[1, 7], [0, 6]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_3", - "sat": "def sat(position: List[List[int]], transcript=[[[3, 1], [1, 3]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[3, 1], [1, 3]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_4", - "sat": "def sat(position: List[List[int]], transcript=[[[5, 1], [3, 3], [5, 5], [3, 7]], [[7, 3], [5, 1]], [[6, 0], [4, 2]], [[3, 5], [2, 4]], [[1, 3], [3, 5]], [[7, 5], [6, 4]], [[1, 1], [2, 2]], [[6, 4], [7, 3]], [[4, 2], [3, 3]], [[6, 6], [5, 5]], [[0, 2], [1, 3]], [[5, 7], [4, 6]], [[3, 5], [5, 7]], [[1, 5], [2, 4]], [[3, 3], [1, 5]], [[0, 6], [2, 4], [0, 2]], [[2, 2], [1, 3]], [[5, 5], [4, 4]], [[7, 1], [6, 2]], [[7, 3], [5, 1]], [[1, 3], [2, 4]], [[7, 7], [6, 6]], [[5, 7], [7, 5]], [[0, 2], [1, 1]], [[0, 0], [2, 2]], [[4, 4], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [4, 2]], [[6, 4], [7, 5]], [[5, 1], [6, 0]], [[2, 4], [3, 5]], [[6, 0], [7, 1]], [[2, 2], [1, 3]], [[7, 1], [6, 0]], [[3, 5], [4, 6]], [[4, 2], [5, 1]], [[2, 0], [3, 1]], [[6, 0], [7, 1]], [[1, 3], [0, 4]], [[5, 1], [6, 0]], [[7, 5], [6, 6]], [[7, 1], [6, 2]], [[6, 6], [7, 7]], [[6, 0], [5, 1]], [[7, 7], [6, 6]], [[6, 2], [5, 3]], [[3, 1], [4, 2]], [[5, 3], [3, 1]], [[6, 6], [5, 5]], [[3, 1], [2, 0]], [[3, 7], [2, 6]], [[2, 0], [3, 1]], [[5, 5], [4, 4]], [[5, 1], [6, 2]], [[4, 4], [5, 5]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [3, 3]], [[2, 6], [1, 7]], [[3, 3], [2, 2]], [[4, 6], [5, 7]], [[2, 2], [3, 3]], [[1, 7], [2, 6]], [[6, 2], [5, 3]], [[5, 7], [4, 6]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[5, 1], [3, 3], [5, 5], [3, 7]], [[7, 3], [5, 1]], [[6, 0], [4, 2]], [[3, 5], [2, 4]], [[1, 3], [3, 5]], [[7, 5], [6, 4]], [[1, 1], [2, 2]], [[6, 4], [7, 3]], [[4, 2], [3, 3]], [[6, 6], [5, 5]], [[0, 2], [1, 3]], [[5, 7], [4, 6]], [[3, 5], [5, 7]], [[1, 5], [2, 4]], [[3, 3], [1, 5]], [[0, 6], [2, 4], [0, 2]], [[2, 2], [1, 3]], [[5, 5], [4, 4]], [[7, 1], [6, 2]], [[7, 3], [5, 1]], [[1, 3], [2, 4]], [[7, 7], [6, 6]], [[5, 7], [7, 5]], [[0, 2], [1, 1]], [[0, 0], [2, 2]], [[4, 4], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [4, 2]], [[6, 4], [7, 5]], [[5, 1], [6, 0]], [[2, 4], [3, 5]], [[6, 0], [7, 1]], [[2, 2], [1, 3]], [[7, 1], [6, 0]], [[3, 5], [4, 6]], [[4, 2], [5, 1]], [[2, 0], [3, 1]], [[6, 0], [7, 1]], [[1, 3], [0, 4]], [[5, 1], [6, 0]], [[7, 5], [6, 6]], [[7, 1], [6, 2]], [[6, 6], [7, 7]], [[6, 0], [5, 1]], [[7, 7], [6, 6]], [[6, 2], [5, 3]], [[3, 1], [4, 2]], [[5, 3], [3, 1]], [[6, 6], [5, 5]], [[3, 1], [2, 0]], [[3, 7], [2, 6]], [[2, 0], [3, 1]], [[5, 5], [4, 4]], [[5, 1], [6, 2]], [[4, 4], [5, 5]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [3, 3]], [[2, 6], [1, 7]], [[3, 3], [2, 2]], [[4, 6], [5, 7]], [[2, 2], [3, 3]], [[1, 7], [2, 6]], [[6, 2], [5, 3]], [[5, 7], [4, 6]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_5", - "sat": "def sat(position: List[List[int]], transcript=[[[5, 1], [4, 2]], [[2, 6], [3, 5]], [[4, 2], [5, 3]], [[4, 0], [3, 1]], [[2, 0], [4, 2]], [[5, 7], [6, 6]], [[5, 3], [4, 4]], [[3, 5], [5, 3], [3, 1]], [[7, 3], [6, 4]], [[7, 5], [5, 3]], [[1, 1], [2, 2]], [[5, 3], [6, 2]], [[0, 2], [1, 3]], [[6, 6], [5, 5]], [[1, 3], [0, 4]], [[5, 5], [4, 4]], [[0, 4], [1, 5]], [[0, 6], [2, 4]], [[2, 2], [3, 3]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[5, 1], [4, 2]], [[2, 6], [3, 5]], [[4, 2], [5, 3]], [[4, 0], [3, 1]], [[2, 0], [4, 2]], [[5, 7], [6, 6]], [[5, 3], [4, 4]], [[3, 5], [5, 3], [3, 1]], [[7, 3], [6, 4]], [[7, 5], [5, 3]], [[1, 1], [2, 2]], [[5, 3], [6, 2]], [[0, 2], [1, 3]], [[6, 6], [5, 5]], [[1, 3], [0, 4]], [[5, 5], [4, 4]], [[0, 4], [1, 5]], [[0, 6], [2, 4]], [[2, 2], [3, 3]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_6", - "sat": "def sat(position: List[List[int]], transcript=[[[0, 0], [1, 1]], [[7, 7], [6, 6]], [[1, 1], [2, 2]], [[6, 2], [7, 1]], [[5, 1], [4, 2]], [[1, 7], [2, 6]], [[0, 6], [1, 7]], [[7, 3], [6, 2]], [[1, 7], [3, 5]], [[5, 5], [4, 4]], [[3, 5], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [7, 5], [5, 7]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[1, 3], [0, 2]], [[5, 7], [6, 6]], [[0, 2], [1, 1]], [[4, 2], [5, 3]], [[1, 1], [0, 0]], [[3, 1], [4, 2]], [[0, 4], [1, 3]], [[2, 2], [0, 4]], [[0, 0], [1, 1]], [[5, 3], [4, 4]], [[1, 1], [0, 2]], [[6, 0], [5, 1]], [[0, 2], [1, 1]], [[6, 6], [7, 5]], [[1, 1], [2, 0]], [[6, 2], [7, 3]], [[2, 0], [1, 1]], [[4, 4], [3, 5]], [[7, 1], [6, 0]], [[7, 5], [6, 6]], [[1, 1], [2, 0]], [[7, 3], [6, 4]], [[6, 0], [7, 1]], [[6, 6], [7, 7]], [[7, 1], [6, 0]], [[6, 4], [5, 5]], [[6, 0], [7, 1]], [[5, 1], [6, 2]], [[7, 1], [5, 3], [3, 1]], [[3, 3], [2, 4]], [[3, 1], [4, 0]], [[7, 7], [6, 6]], [[2, 0], [1, 1]], [[6, 6], [7, 7]], [[1, 1], [0, 2]], [[7, 7], [6, 6]], [[4, 0], [3, 1]], [[3, 5], [4, 6]], [[3, 1], [2, 0]], [[2, 4], [1, 5]], [[2, 0], [1, 1]], [[1, 5], [0, 6]], [[0, 2], [1, 3]], [[4, 6], [5, 7]], [[1, 1], [0, 2]], [[5, 5], [4, 6]], [[0, 2], [1, 1]], [[0, 6], [1, 7]], [[1, 1], [2, 2]], [[1, 7], [2, 6]], [[2, 2], [3, 1]], [[2, 6], [3, 5]], [[3, 1], [2, 2]], [[6, 6], [7, 7]], [[2, 2], [1, 1]], [[3, 5], [2, 6]], [[1, 3], [2, 4]], [[2, 6], [1, 7]], [[1, 1], [0, 2]], [[4, 6], [3, 7]], [[2, 4], [3, 5]], [[1, 7], [0, 6]], [[3, 5], [4, 6]], [[3, 7], [5, 5]], [[0, 2], [1, 1]], [[5, 5], [4, 4]], [[1, 1], [2, 0]], [[4, 4], [5, 5]], [[2, 0], [3, 1]], [[5, 7], [4, 6]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [1, 1]], [[7, 7], [6, 6]], [[1, 1], [0, 0]], [[4, 6], [3, 7]], [[0, 0], [1, 1]], [[5, 5], [4, 4]], [[1, 1], [2, 0]], [[4, 4], [3, 3]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[0, 0], [1, 1]], [[7, 7], [6, 6]], [[1, 1], [2, 2]], [[6, 2], [7, 1]], [[5, 1], [4, 2]], [[1, 7], [2, 6]], [[0, 6], [1, 7]], [[7, 3], [6, 2]], [[1, 7], [3, 5]], [[5, 5], [4, 4]], [[3, 5], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [7, 5], [5, 7]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[1, 3], [0, 2]], [[5, 7], [6, 6]], [[0, 2], [1, 1]], [[4, 2], [5, 3]], [[1, 1], [0, 0]], [[3, 1], [4, 2]], [[0, 4], [1, 3]], [[2, 2], [0, 4]], [[0, 0], [1, 1]], [[5, 3], [4, 4]], [[1, 1], [0, 2]], [[6, 0], [5, 1]], [[0, 2], [1, 1]], [[6, 6], [7, 5]], [[1, 1], [2, 0]], [[6, 2], [7, 3]], [[2, 0], [1, 1]], [[4, 4], [3, 5]], [[7, 1], [6, 0]], [[7, 5], [6, 6]], [[1, 1], [2, 0]], [[7, 3], [6, 4]], [[6, 0], [7, 1]], [[6, 6], [7, 7]], [[7, 1], [6, 0]], [[6, 4], [5, 5]], [[6, 0], [7, 1]], [[5, 1], [6, 2]], [[7, 1], [5, 3], [3, 1]], [[3, 3], [2, 4]], [[3, 1], [4, 0]], [[7, 7], [6, 6]], [[2, 0], [1, 1]], [[6, 6], [7, 7]], [[1, 1], [0, 2]], [[7, 7], [6, 6]], [[4, 0], [3, 1]], [[3, 5], [4, 6]], [[3, 1], [2, 0]], [[2, 4], [1, 5]], [[2, 0], [1, 1]], [[1, 5], [0, 6]], [[0, 2], [1, 3]], [[4, 6], [5, 7]], [[1, 1], [0, 2]], [[5, 5], [4, 6]], [[0, 2], [1, 1]], [[0, 6], [1, 7]], [[1, 1], [2, 2]], [[1, 7], [2, 6]], [[2, 2], [3, 1]], [[2, 6], [3, 5]], [[3, 1], [2, 2]], [[6, 6], [7, 7]], [[2, 2], [1, 1]], [[3, 5], [2, 6]], [[1, 3], [2, 4]], [[2, 6], [1, 7]], [[1, 1], [0, 2]], [[4, 6], [3, 7]], [[2, 4], [3, 5]], [[1, 7], [0, 6]], [[3, 5], [4, 6]], [[3, 7], [5, 5]], [[0, 2], [1, 1]], [[5, 5], [4, 4]], [[1, 1], [2, 0]], [[4, 4], [5, 5]], [[2, 0], [3, 1]], [[5, 7], [4, 6]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [1, 1]], [[7, 7], [6, 6]], [[1, 1], [0, 0]], [[4, 6], [3, 7]], [[0, 0], [1, 1]], [[5, 5], [4, 4]], [[1, 1], [2, 0]], [[4, 4], [3, 3]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_7", - "sat": "def sat(position: List[List[int]], transcript=[[[5, 7], [4, 6]], [[5, 3], [4, 4]], [[6, 6], [5, 7]], [[4, 4], [5, 3]], [[0, 6], [1, 7]], [[5, 3], [4, 2]], [[4, 6], [3, 7]], [[4, 2], [3, 1]], [[3, 7], [2, 6]], [[5, 1], [4, 0]], [[5, 7], [4, 6]], [[3, 1], [2, 2]], [[2, 6], [1, 5]], [[4, 0], [3, 1]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[5, 7], [4, 6]], [[5, 3], [4, 4]], [[6, 6], [5, 7]], [[4, 4], [5, 3]], [[0, 6], [1, 7]], [[5, 3], [4, 2]], [[4, 6], [3, 7]], [[4, 2], [3, 1]], [[3, 7], [2, 6]], [[5, 1], [4, 0]], [[5, 7], [4, 6]], [[3, 1], [2, 2]], [[2, 6], [1, 5]], [[4, 0], [3, 1]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_8", - "sat": "def sat(position: List[List[int]], transcript=[[[2, 2], [1, 3]], [[1, 7], [0, 6]], [[6, 2], [7, 3]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[2, 2], [1, 3]], [[1, 7], [0, 6]], [[6, 2], [7, 3]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "CheckersPosition_9", - "sat": "def sat(position: List[List[int]], transcript=[[[4, 4], [3, 5]], [[3, 1], [4, 0]], [[6, 6], [5, 5]], [[5, 1], [4, 2]], [[3, 5], [2, 6]], [[0, 0], [1, 1]], [[5, 5], [6, 6]], [[1, 1], [2, 2]], [[6, 6], [7, 5]], [[4, 0], [3, 1]], [[2, 6], [1, 7]], [[3, 1], [4, 0]], [[1, 7], [0, 6]], [[7, 1], [6, 0]], [[0, 6], [1, 7]], [[4, 2], [5, 1]], [[1, 7], [0, 6]], [[5, 1], [6, 2]], [[0, 6], [1, 7]], [[2, 2], [1, 1]], [[7, 5], [6, 6]], [[1, 1], [2, 0]], [[6, 6], [5, 5]], [[6, 2], [5, 1]], [[5, 5], [6, 6]], [[6, 0], [7, 1]], [[6, 6], [5, 7]], [[7, 1], [6, 2]], [[1, 7], [0, 6]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[4, 0], [3, 1]], [[6, 6], [7, 5]], [[5, 1], [4, 2]], [[7, 5], [6, 4]], [[7, 3], [5, 5]], [[0, 6], [1, 7]], [[2, 0], [1, 1]]]):\n \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", - "sols": [ - "def sol(transcript=[[[4, 4], [3, 5]], [[3, 1], [4, 0]], [[6, 6], [5, 5]], [[5, 1], [4, 2]], [[3, 5], [2, 6]], [[0, 0], [1, 1]], [[5, 5], [6, 6]], [[1, 1], [2, 2]], [[6, 6], [7, 5]], [[4, 0], [3, 1]], [[2, 6], [1, 7]], [[3, 1], [4, 0]], [[1, 7], [0, 6]], [[7, 1], [6, 0]], [[0, 6], [1, 7]], [[4, 2], [5, 1]], [[1, 7], [0, 6]], [[5, 1], [6, 2]], [[0, 6], [1, 7]], [[2, 2], [1, 1]], [[7, 5], [6, 6]], [[1, 1], [2, 0]], [[6, 6], [5, 5]], [[6, 2], [5, 1]], [[5, 5], [6, 6]], [[6, 0], [7, 1]], [[6, 6], [5, 7]], [[7, 1], [6, 2]], [[1, 7], [0, 6]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[4, 0], [3, 1]], [[6, 6], [7, 5]], [[5, 1], [4, 2]], [[7, 5], [6, 4]], [[7, 3], [5, 5]], [[0, 6], [1, 7]], [[2, 0], [1, 1]]]):\n START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", - "taint_date": "2021-4-26", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_0", - "sat": "def sat(cut_position: int, ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_1", - "sat": "def sat(cut_position: int, ring=\"MvI\", lower=0):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"MvI\", lower=0):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_2", - "sat": "def sat(cut_position: int, ring=\"s\", lower=0):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"s\", lower=0):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_3", - "sat": "def sat(cut_position: int, ring=\"fyVYVBfGHVYsBrYVgsgHYvVD\", lower=0):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"fyVYVBfGHVYsBrYVgsgHYvVD\", lower=0):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_4", - "sat": "def sat(cut_position: int, ring=\"ClaKdLCuSddLdafuRKuqUqSLqquLCSlrCfFdcRAlfkLlqqqccQSacsDCUqDaLurDlqqfcAaKasCf\", lower=1):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"ClaKdLCuSddLdafuRKuqUqSLqquLCSlrCfFdcRAlfkLlqqqccQSacsDCUqDaLurDlqqfcAaKasCf\", lower=1):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_5", - "sat": "def sat(cut_position: int, ring=\"GWGwwUiRRGaglFcwzHlcHljrtehOGTcjgWuHlUHlcrLcuUCeuToMowHEELLlcvCgreTATIjFTTGvMcJztRVHIMWUmwRijwuERITMuwltjGIoTgAEoAewWZvETIfziHfAmUIijzFvcRlajeMrIUvmTGeAzRoIgirLTEwvRiMJRumMTEeTaTZvmJjOCJCIAJOEmZvHMCziurfrHwMEJggGclhaoIIcATMajWGaIOchaetioGGRtzOUvIzHGzRiUhVv\", lower=2):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"GWGwwUiRRGaglFcwzHlcHljrtehOGTcjgWuHlUHlcrLcuUCeuToMowHEELLlcvCgreTATIjFTTGvMcJztRVHIMWUmwRijwuERITMuwltjGIoTgAEoAewWZvETIfziHfAmUIijzFvcRlajeMrIUvmTGeAzRoIgirLTEwvRiMJRumMTEeTaTZvmJjOCJCIAJOEmZvHMCziurfrHwMEJggGclhaoIIcATMajWGaIOchaetioGGRtzOUvIzHGzRiUhVv\", lower=2):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_6", - "sat": "def sat(cut_position: int, ring=\"YduEpdTboudPuxbxtoqXoxPeqQeYoU\", lower=1):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"YduEpdTboudPuxbxtoqXoxPeqQeYoU\", lower=1):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_7", - "sat": "def sat(cut_position: int, ring=\"bjyJYvZJZzzvJvByyZYVbjvjbbzjYYvVjBjjYYvjzjJYjZJyYJZzjj\", lower=1):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"bjyJYvZJZzzvJvByyZYVbjvjbbzjYYvVjBjjYYvjzjJYjZJyYJZzjj\", lower=1):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_8", - "sat": "def sat(cut_position: int, ring=\"pZqPZbV\", lower=1):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"pZqPZbV\", lower=1):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "MatchingMarkers_9", - "sat": "def sat(cut_position: int, ring=\"NKMmijveYDwliKeeiTm\", lower=0):\n \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", - "sols": [ - "def sol(ring=\"NKMmijveYDwliKeeiTm\", lower=0):\n cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" - ], - "module": "ICPC", - "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", - "taint_date": "2019-3-31", - "weight": 0.025 - }, - { - "name": "ExponentialCoinMoves_0", - "sat": "def sat(states: List[List[int]], n=16385):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=16385):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_1", - "sat": "def sat(states: List[List[int]], n=1):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=1):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_2", - "sat": "def sat(states: List[List[int]], n=2):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=2):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_3", - "sat": "def sat(states: List[List[int]], n=4):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=4):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_4", - "sat": "def sat(states: List[List[int]], n=8):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=8):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_5", - "sat": "def sat(states: List[List[int]], n=16):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=16):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_6", - "sat": "def sat(states: List[List[int]], n=32):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=32):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_7", - "sat": "def sat(states: List[List[int]], n=64):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=64):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_8", - "sat": "def sat(states: List[List[int]], n=128):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=128):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "ExponentialCoinMoves_9", - "sat": "def sat(states: List[List[int]], n=256):\n \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", - "sols": [ - "def sol(n=256):\n assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" - ], - "module": "IMO", - "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.06666666666666667 - }, - { - "name": "NoRelativePrimes_0", - "sat": "def sat(nums: List[int], b=6, m=2):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=6, m=2):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_1", - "sat": "def sat(nums: List[int], b=7, m=26):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=7, m=26):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_2", - "sat": "def sat(nums: List[int], b=6, m=73):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=6, m=73):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_3", - "sat": "def sat(nums: List[int], b=17, m=37):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_4", - "sat": "def sat(nums: List[int], b=7, m=92):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=7, m=92):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_5", - "sat": "def sat(nums: List[int], b=7, m=83):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=7, m=83):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_6", - "sat": "def sat(nums: List[int], b=16, m=31):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_7", - "sat": "def sat(nums: List[int], b=7, m=90):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [ - "def sol(b=7, m=90):\n ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_8", - "sat": "def sat(nums: List[int], b=15, m=73):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "NoRelativePrimes_9", - "sat": "def sat(nums: List[int], b=19, m=31):\n \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", - "sols": [], - "module": "IMO", - "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", - "taint_date": "2016-7-1", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_0", - "sat": "def sat(indices: List[int], a0=123):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=123):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_1", - "sat": "def sat(indices: List[int], a0=2827347):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=2827347):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_2", - "sat": "def sat(indices: List[int], a0=2362263):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=2362263):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_3", - "sat": "def sat(indices: List[int], a0=1703235):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=1703235):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_4", - "sat": "def sat(indices: List[int], a0=962856):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=962856):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_5", - "sat": "def sat(indices: List[int], a0=2783502):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=2783502):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_6", - "sat": "def sat(indices: List[int], a0=157197):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=157197):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_7", - "sat": "def sat(indices: List[int], a0=2933850):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=2933850):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_8", - "sat": "def sat(indices: List[int], a0=2909385):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=2909385):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindRepeats_9", - "sat": "def sat(indices: List[int], a0=1564314):\n \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", - "sols": [ - "def sol(a0=1564314):\n n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" - ], - "module": "IMO", - "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_0", - "sat": "def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_1", - "sat": "def sat(keep: List[bool], heights=[6, 12, 26, 4, 25, 20, 15, 14, 18, 22, 19, 23, 27, 13, 9, 28, 17, 11, 29, 7, 1, 10, 2, 0, 21, 3, 5, 8, 16, 24]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[6, 12, 26, 4, 25, 20, 15, 14, 18, 22, 19, 23, 27, 13, 9, 28, 17, 11, 29, 7, 1, 10, 2, 0, 21, 3, 5, 8, 16, 24]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_2", - "sat": "def sat(keep: List[bool], heights=[6, 8, 0, 7, 4, 9, 10, 1, 5, 3, 11, 2]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[6, 8, 0, 7, 4, 9, 10, 1, 5, 3, 11, 2]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_3", - "sat": "def sat(keep: List[bool], heights=[46, 61, 80, 16, 71, 32, 13, 12, 2, 75, 62, 56, 17, 28, 67, 54, 22, 27, 38, 63, 69, 84, 70, 57, 86, 72, 66, 8, 41, 3, 23, 88, 83, 58, 36, 50, 65, 30, 34, 25, 39, 20, 78, 79, 59, 4, 21, 73, 45, 37, 48, 77, 10, 44, 14, 43, 42, 0, 33, 29, 7, 52, 5, 60, 68, 9, 26, 49, 40, 76, 31, 6, 85, 74, 24, 51, 1, 89, 11, 47, 18, 19, 81, 87, 35, 64, 82, 15, 55, 53]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[46, 61, 80, 16, 71, 32, 13, 12, 2, 75, 62, 56, 17, 28, 67, 54, 22, 27, 38, 63, 69, 84, 70, 57, 86, 72, 66, 8, 41, 3, 23, 88, 83, 58, 36, 50, 65, 30, 34, 25, 39, 20, 78, 79, 59, 4, 21, 73, 45, 37, 48, 77, 10, 44, 14, 43, 42, 0, 33, 29, 7, 52, 5, 60, 68, 9, 26, 49, 40, 76, 31, 6, 85, 74, 24, 51, 1, 89, 11, 47, 18, 19, 81, 87, 35, 64, 82, 15, 55, 53]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_4", - "sat": "def sat(keep: List[bool], heights=[26, 11, 62, 24, 56, 80, 39, 77, 23, 86, 53, 73, 3, 44, 45, 70, 75, 0, 13, 40, 4, 87, 30, 7, 50, 34, 59, 22, 17, 41, 71, 10, 29, 89, 36, 31, 52, 9, 2, 51, 28, 61, 21, 1, 15, 72, 84, 88, 79, 19, 27, 63, 55, 83, 57, 18, 5, 12, 37, 16, 49, 8, 6, 65, 32, 20, 47, 82, 42, 33, 81, 58, 35, 67, 48, 74, 78, 85, 14, 68, 43, 25, 46, 69, 76, 64, 38, 54, 66, 60]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[26, 11, 62, 24, 56, 80, 39, 77, 23, 86, 53, 73, 3, 44, 45, 70, 75, 0, 13, 40, 4, 87, 30, 7, 50, 34, 59, 22, 17, 41, 71, 10, 29, 89, 36, 31, 52, 9, 2, 51, 28, 61, 21, 1, 15, 72, 84, 88, 79, 19, 27, 63, 55, 83, 57, 18, 5, 12, 37, 16, 49, 8, 6, 65, 32, 20, 47, 82, 42, 33, 81, 58, 35, 67, 48, 74, 78, 85, 14, 68, 43, 25, 46, 69, 76, 64, 38, 54, 66, 60]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_5", - "sat": "def sat(keep: List[bool], heights=[15, 40, 38, 12, 27, 29, 17, 19, 11, 5, 2, 24, 9, 13, 7, 28, 16, 37, 1, 25, 18, 8, 30, 6, 22, 39, 32, 10, 20, 36, 26, 14, 41, 23, 3, 0, 35, 33, 4, 34, 21, 31]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[15, 40, 38, 12, 27, 29, 17, 19, 11, 5, 2, 24, 9, 13, 7, 28, 16, 37, 1, 25, 18, 8, 30, 6, 22, 39, 32, 10, 20, 36, 26, 14, 41, 23, 3, 0, 35, 33, 4, 34, 21, 31]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_6", - "sat": "def sat(keep: List[bool], heights=[20, 2, 41, 19, 52, 76, 12, 1, 67, 8, 35, 82, 60, 24, 28, 83, 80, 66, 69, 40, 81, 23, 29, 17, 25, 48, 72, 85, 58, 26, 84, 89, 16, 73, 15, 7, 5, 53, 13, 36, 55, 88, 44, 47, 3, 54, 50, 10, 87, 75, 70, 56, 30, 4, 6, 49, 0, 31, 77, 42, 45, 71, 57, 79, 37, 65, 64, 33, 34, 27, 78, 11, 74, 21, 32, 61, 18, 51, 38, 63, 9, 62, 46, 14, 39, 86, 59, 43, 22, 68]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[20, 2, 41, 19, 52, 76, 12, 1, 67, 8, 35, 82, 60, 24, 28, 83, 80, 66, 69, 40, 81, 23, 29, 17, 25, 48, 72, 85, 58, 26, 84, 89, 16, 73, 15, 7, 5, 53, 13, 36, 55, 88, 44, 47, 3, 54, 50, 10, 87, 75, 70, 56, 30, 4, 6, 49, 0, 31, 77, 42, 45, 71, 57, 79, 37, 65, 64, 33, 34, 27, 78, 11, 74, 21, 32, 61, 18, 51, 38, 63, 9, 62, 46, 14, 39, 86, 59, 43, 22, 68]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_7", - "sat": "def sat(keep: List[bool], heights=[54, 45, 67, 63, 64, 43, 22, 47, 29, 60, 2, 46, 13, 42, 27, 1, 57, 19, 50, 23, 12, 58, 71, 18, 5, 15, 62, 69, 0, 16, 14, 52, 49, 55, 9, 68, 41, 32, 37, 10, 35, 25, 65, 31, 30, 24, 66, 26, 33, 11, 44, 39, 48, 20, 40, 3, 70, 59, 53, 61, 36, 17, 21, 34, 38, 28, 51, 7, 6, 4, 8, 56]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[54, 45, 67, 63, 64, 43, 22, 47, 29, 60, 2, 46, 13, 42, 27, 1, 57, 19, 50, 23, 12, 58, 71, 18, 5, 15, 62, 69, 0, 16, 14, 52, 49, 55, 9, 68, 41, 32, 37, 10, 35, 25, 65, 31, 30, 24, 66, 26, 33, 11, 44, 39, 48, 20, 40, 3, 70, 59, 53, 61, 36, 17, 21, 34, 38, 28, 51, 7, 6, 4, 8, 56]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_8", - "sat": "def sat(keep: List[bool], heights=[38, 26, 22, 21, 66, 11, 31, 60, 64, 41, 55, 27, 35, 42, 4, 56, 67, 51, 8, 48, 23, 54, 62, 49, 13, 33, 68, 5, 24, 1, 61, 20, 34, 69, 30, 0, 45, 18, 57, 65, 47, 2, 12, 7, 50, 16, 19, 53, 58, 52, 43, 71, 37, 28, 9, 6, 46, 59, 70, 40, 32, 25, 10, 44, 14, 29, 3, 39, 15, 36, 63, 17]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[38, 26, 22, 21, 66, 11, 31, 60, 64, 41, 55, 27, 35, 42, 4, 56, 67, 51, 8, 48, 23, 54, 62, 49, 13, 33, 68, 5, 24, 1, 61, 20, 34, 69, 30, 0, 45, 18, 57, 65, 47, 2, 12, 7, 50, 16, 19, 53, 58, 52, 43, 71, 37, 28, 9, 6, 46, 59, 70, 40, 32, 25, 10, 44, 14, 29, 3, 39, 15, 36, 63, 17]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "PickNearNeighbors_9", - "sat": "def sat(keep: List[bool], heights=[9, 12, 76, 10, 53, 17, 70, 60, 30, 80, 51, 44, 26, 52, 16, 5, 39, 72, 19, 87, 7, 63, 36, 66, 11, 43, 56, 29, 14, 68, 74, 48, 83, 32, 27, 8, 24, 69, 89, 71, 77, 13, 25, 81, 45, 82, 31, 15, 50, 37, 0, 49, 78, 84, 22, 58, 35, 62, 59, 47, 34, 65, 3, 85, 88, 33, 2, 4, 42, 20, 54, 73, 86, 23, 64, 79, 38, 40, 28, 18, 1, 75, 55, 57, 21, 46, 6, 67, 41, 61]):\n \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", - "sols": [ - "def sol(heights=[9, 12, 76, 10, 53, 17, 70, 60, 30, 80, 51, 44, 26, 52, 16, 5, 39, 72, 19, 87, 7, 63, 36, 66, 11, 43, 56, 29, 14, 68, 74, 48, 83, 32, 27, 8, 24, 69, 89, 71, 77, 13, 25, 81, 45, 82, 31, 15, 50, 37, 0, 49, 78, 84, 22, 58, 35, 62, 59, 47, 34, 65, 3, 85, 88, 33, 2, 4, 42, 20, 54, 73, 86, 23, 64, 79, 38, 40, 28, 18, 1, 75, 55, 57, 21, 46, 6, 67, 41, 61]): # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", - "taint_date": "2017-7-12", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_0", - "sat": "def sat(li: List[int], n=18):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=18):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_1", - "sat": "def sat(li: List[int], n=3):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=3):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_2", - "sat": "def sat(li: List[int], n=6):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=6):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_3", - "sat": "def sat(li: List[int], n=9):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=9):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_4", - "sat": "def sat(li: List[int], n=12):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=12):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_5", - "sat": "def sat(li: List[int], n=15):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=15):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_6", - "sat": "def sat(li: List[int], n=21):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=21):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_7", - "sat": "def sat(li: List[int], n=24):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=24):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_8", - "sat": "def sat(li: List[int], n=27):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=27):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "FindProductiveList_9", - "sat": "def sat(li: List[int], n=30):\n \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", - "sols": [ - "def sol(n=30):\n return [-1, -1, 2] * (n // 3)" - ], - "module": "IMO", - "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", - "taint_date": "2010-7-2", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_0", - "sat": "def sat(li: List[int], n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_1", - "sat": "def sat(li: List[int], n=4, tags=[2, 3, 1, 0, 3, 3, 0, 2, 1, 3, 1, 0, 1, 2, 2, 0]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=4, tags=[2, 3, 1, 0, 3, 3, 0, 2, 1, 3, 1, 0, 1, 2, 2, 0]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_2", - "sat": "def sat(li: List[int], n=7, tags=[4, 1, 6, 5, 6, 4, 2, 1, 6, 2, 3, 1, 4, 6, 5, 2, 3, 5, 0, 5, 0, 3, 0, 0, 4, 2, 3, 1]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=7, tags=[4, 1, 6, 5, 6, 4, 2, 1, 6, 2, 3, 1, 4, 6, 5, 2, 3, 5, 0, 5, 0, 3, 0, 0, 4, 2, 3, 1]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_3", - "sat": "def sat(li: List[int], n=3, tags=[0, 2, 1, 1, 1, 1, 2, 2, 0, 0, 0, 2]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=3, tags=[0, 2, 1, 1, 1, 1, 2, 2, 0, 0, 0, 2]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_4", - "sat": "def sat(li: List[int], n=8, tags=[1, 2, 6, 0, 6, 2, 4, 7, 4, 0, 0, 5, 0, 3, 2, 1, 7, 5, 5, 3, 1, 7, 2, 7, 6, 6, 3, 3, 1, 4, 4, 5]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=8, tags=[1, 2, 6, 0, 6, 2, 4, 7, 4, 0, 0, 5, 0, 3, 2, 1, 7, 5, 5, 3, 1, 7, 2, 7, 6, 6, 3, 3, 1, 4, 4, 5]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_5", - "sat": "def sat(li: List[int], n=8, tags=[4, 3, 7, 7, 6, 4, 6, 3, 4, 4, 0, 2, 3, 7, 5, 5, 6, 2, 7, 6, 0, 1, 0, 0, 5, 5, 1, 1, 2, 1, 3, 2]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=8, tags=[4, 3, 7, 7, 6, 4, 6, 3, 4, 4, 0, 2, 3, 7, 5, 5, 6, 2, 7, 6, 0, 1, 0, 0, 5, 5, 1, 1, 2, 1, 3, 2]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_6", - "sat": "def sat(li: List[int], n=5, tags=[0, 2, 3, 1, 3, 1, 3, 1, 4, 2, 4, 3, 0, 2, 0, 1, 4, 0, 2, 4]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=5, tags=[0, 2, 3, 1, 3, 1, 3, 1, 4, 2, 4, 3, 0, 2, 0, 1, 4, 0, 2, 4]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_7", - "sat": "def sat(li: List[int], n=6, tags=[3, 4, 4, 3, 4, 1, 0, 2, 2, 0, 0, 2, 5, 5, 1, 1, 1, 3, 0, 3, 4, 5, 2, 5]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=6, tags=[3, 4, 4, 3, 4, 1, 0, 2, 2, 0, 0, 2, 5, 5, 1, 1, 1, 3, 0, 3, 4, 5, 2, 5]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_8", - "sat": "def sat(li: List[int], n=6, tags=[2, 5, 2, 4, 0, 1, 3, 4, 3, 2, 5, 0, 1, 2, 4, 0, 1, 0, 3, 3, 5, 4, 5, 1]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=6, tags=[2, 5, 2, 4, 0, 1, 3, 4, 3, 2, 5, 0, 1, 2, 4, 0, 1, 0, 3, 3, 5, 4, 5, 1]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "HalfTag_9", - "sat": "def sat(li: List[int], n=9, tags=[5, 3, 8, 5, 1, 0, 7, 5, 0, 3, 1, 1, 7, 3, 2, 4, 5, 8, 8, 3, 8, 4, 7, 6, 6, 1, 0, 2, 4, 6, 2, 0, 7, 4, 6, 2]):\n \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", - "sols": [ - "def sol(n=9, tags=[5, 3, 8, 5, 1, 0, 7, 5, 0, 3, 1, 1, 7, 3, 2, 4, 5, 8, 8, 3, 8, 4, 7, 6, 6, 1, 0, 2, 4, 6, 2, 0, 7, 4, 6, 2]):\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" - ], - "module": "IMO", - "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", - "taint_date": "2020-9-19", - "weight": 0.006666666666666666 - }, - { - "name": "LearnParity_0", - "sat": "def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_1", - "sat": "def sat(inds: List[int], vecs=[981, 977, 222, 702, 621, 388, 812, 422, 503, 11, 212, 250, 645, 45, 330, 11, 79, 33, 814, 547, 953, 210, 645, 345, 959, 732]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[981, 977, 222, 702, 621, 388, 812, 422, 503, 11, 212, 250, 645, 45, 330, 11, 79, 33, 814, 547, 953, 210, 645, 345, 959, 732]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_2", - "sat": "def sat(inds: List[int], vecs=[8, 4, 9, 8, 4, 6, 9, 11, 6, 7, 10, 7, 11, 6]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[8, 4, 9, 8, 4, 6, 9, 11, 6, 7, 10, 7, 11, 6]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_3", - "sat": "def sat(inds: List[int], vecs=[5, 4, 3, 4, 5, 3, 2]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[5, 4, 3, 4, 5, 3, 2]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_4", - "sat": "def sat(inds: List[int], vecs=[5473, 3401, 618, 5228, 4348, 2122, 5240, 2176, 782, 7898, 2813, 813, 7655, 6676, 2409, 4461, 1463, 4798, 4442, 5545, 4562, 3705, 4821, 7075, 1095, 4960, 7062, 1830, 7208, 1807, 7614, 6909, 510, 2220, 3927, 7281, 891, 6477, 2652, 4775, 661, 2373, 5253]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[5473, 3401, 618, 5228, 4348, 2122, 5240, 2176, 782, 7898, 2813, 813, 7655, 6676, 2409, 4461, 1463, 4798, 4442, 5545, 4562, 3705, 4821, 7075, 1095, 4960, 7062, 1830, 7208, 1807, 7614, 6909, 510, 2220, 3927, 7281, 891, 6477, 2652, 4775, 661, 2373, 5253]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_5", - "sat": "def sat(inds: List[int], vecs=[5, 5, 5, 14]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[5, 5, 5, 14]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_6", - "sat": "def sat(inds: List[int], vecs=[8, 3, 7, 8, 3, 7, 12, 2, 12, 3, 7, 13, 6, 2, 9, 12, 9, 9]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[8, 3, 7, 8, 3, 7, 12, 2, 12, 3, 7, 13, 6, 2, 9, 12, 9, 9]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_7", - "sat": "def sat(inds: List[int], vecs=[2, 1, 2, 1, 2, 2]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[2, 1, 2, 1, 2, 2]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_8", - "sat": "def sat(inds: List[int], vecs=[623, 950, 472, 766, 203, 749, 283, 344, 501, 424, 5, 85, 343, 380, 541, 480, 522, 775, 3, 394, 780, 344, 704, 988, 990, 482, 551, 953, 122, 115, 948, 1018, 161, 680, 140, 831, 228, 459, 324, 310, 566, 638, 8, 289]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[623, 950, 472, 766, 203, 749, 283, 344, 501, 424, 5, 85, 343, 380, 541, 480, 522, 775, 3, 394, 780, 344, 704, 988, 990, 482, 551, 953, 122, 115, 948, 1018, 161, 680, 140, 831, 228, 459, 324, 310, 566, 638, 8, 289]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParity_9", - "sat": "def sat(inds: List[int], vecs=[11, 4, 4, 16, 10, 23, 2, 5, 5, 30, 17]):\n \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set $S$ of indices such that:\n $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", - "sols": [ - "def sol(vecs=[11, 4, 4, 16, 10, 23, 2, 5, 5, 30, 17]): # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" - ], - "module": "lattices", - "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", - "taint_date": "2021-4-26", - "weight": 0.0024390243902439024 - }, - { - "name": "LearnParityWithNoise_0", - "sat": "def sat(inds: List[int], vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 24, 16, 13, 0, 27, 13]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [ - "def sol(vecs=[26, 5, 16, 3, 15, 18, 31, 13, 24, 25, 6, 5, 15, 24, 16, 13, 0, 27, 13]): # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n while True:\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" - ], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_1", - "sat": "def sat(inds: List[int], vecs=[541463641166815, 836501911182698, 204369742722561, 996228762493585, 393037554634950, 561847321780580, 383843566788061, 50791402437548, 303042618895774, 1087159980717730, 751462893290133, 717203972383473, 61936063012068, 327885412093529, 829008581453248, 82682204900035, 126568193270140, 641995482588733, 865458124272754, 225973598487303, 932017404527410, 857486634842957, 383753222792827, 520005984420171, 204143312736236, 79255198661558, 19424203145940, 524835118507198, 78176684488643, 641587624245938, 871385764240270, 629761402678278, 351708713494899, 1070108072456946, 358446232214123, 312398152219502, 274011963084525, 409373979951238, 132394880735195, 90214520493237, 829104851000793, 1012068842795161, 293003513803709, 174773871154661, 550879461224464, 911485397619621, 48761935107312, 907271010238276, 823851072400528, 505517756398503, 252980176412827, 460114913745498, 645554754407371, 606249093806918, 59379086794876, 71211123750687, 234499981807034, 1009277485829684, 467074129067714, 366224265592543, 755200203782009, 80589293904740, 866991805276416, 103869936645315, 996859943358040, 1125044021870734, 155571302888825, 1117007488286405, 1014533277199991, 1022149666930474, 81067116233699, 465724133554547, 889750915349411, 969017297190273, 960799174327063, 933303422219271, 117886699268136, 79443236425908, 452684568025347, 34587552862340, 1091422557749590, 777041681116090, 63779310817780, 422264778689458, 169358298389373, 4881339628468, 524475267526996, 1003893136962864, 979355145666783, 55133828075657, 40359766618561, 654383514612874, 566885967543537, 418343973765756, 850646251371640, 923188435858076, 827923516310520, 459628606185829, 229381436844152, 622728600135528, 792410937952324, 245216900614598, 574521334111200, 930778047693108, 1037612140145093, 46969657627274, 131529543237835, 632233282135223, 981075950993721, 54398021163978, 670386710877057, 293493625096550, 622538930704865, 487508006825717, 49047059004888, 738717272660644, 1067595248931748, 282402674395080, 391678370810487, 1061452157412375, 685700983856558, 611768326421072, 295538719976926, 1078615825201063, 949171444435668, 1000980167081540, 768479370723950, 772059369360887, 761881229678931, 743895095186174, 930271707561662, 188614518258675, 298528422975541, 565775021521301, 775626775529169, 80421095067503, 82298438018557, 664492303891381, 282615119528894, 686893855903796, 340139318583582, 359564879596168, 859197881626629, 713221480274665, 507886429992730, 255830449759360, 950357525068024, 577666854701789, 389929749160609, 27158396222780, 253473796695702, 995754001272482, 946967879434268, 151525761446711, 751096988850902, 330302288060385, 533058508886678, 448073239588016, 317723640324263, 231555487649199, 1094691308033293, 295190725050160, 677412383674714, 810328016127550, 141217366140840, 1041540045538927, 617636872580732, 181747698845039, 206288765604686, 1016697967285449, 1118498956352212, 451141690079755, 376516823981282, 762977669647226, 680522174009831, 779765453866822, 895732561717960, 997256425106042, 1086703591530704, 314324995746268, 697976993864415, 314458943150521, 1046456425194395, 695571096020161, 1063414460509546, 244920683036349, 21475806716739, 673098992076777, 1076988024532359, 604502739416015, 399572030154774, 950447612879586, 673034038969120, 763766623812515, 771510827412925, 212387593533139, 125239460867122, 1027816175694723, 386005199593320, 383439340293626, 863332217577020, 865883191936909, 94875318712137, 609394252021047, 666722343291063, 274408158524832, 1119355752501496, 155497996620332, 1033542497699221, 978878862321222, 704594635365690, 842514171532211, 85750612144121, 912081543610914, 1052558961410581, 854353899975505, 1087485185473749, 94774529612441, 760722283932952, 144839197903847, 55438496824961, 475624773983941, 368556422486371, 307912168332650, 47340254475173, 1024910897602580, 385906468068688, 162737016086876, 304023630903579, 199360364785950, 608050394504898, 172390873163371, 301488003908068, 35984631006215, 487370274443760, 102068911791559, 419891496911368, 1081309782094596, 509332998884295, 812476433606934, 282669156667428, 1080087994792863, 291857638613096, 808305794439236, 1054101460032026, 987180639907804, 880796696384548, 998670558336764, 491455225948090, 10809118127120, 971889240707265, 673236154243467, 143879097813524, 67876205848433, 28883718881463, 856049470643539, 1060945935411698, 434467186144765, 781577518514349, 581270711543595, 441218400574482, 867557943248669, 187169842929745, 1049590754711617, 81268907758124, 143297925693178, 836835763316768, 562194877151006, 1082884574952652, 908579263643733, 415569548356542, 780159398006833, 340529425422844, 431079014169114, 440151543301266, 590964595112390, 404903830352823, 729927689718447, 378550093658908, 624106064912965, 77674466817708, 938349007428238, 790732179189908, 47334433403329, 463467673640048, 721430796010390, 1105828662364712, 142998217586313, 62423087088164, 209937455508322, 632817523494236, 109443866550599, 834588491780044, 156977748064633, 827882803239954, 840304060280368, 804197298398683, 131793678455405, 50829394142258, 745786977334111, 90468658879031, 185234389856105, 984204558798903, 458180193302131, 26455133930889, 1009996950987715, 1048897429637531, 982702636985964, 435836521917345, 39869011778369, 1086113425704478, 462446171376730, 311253394644783, 15310823490855, 396694301186933, 725785604797831, 1045169393876744, 993997295780260, 727969613537278]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_2", - "sat": "def sat(inds: List[int], vecs=[85, 118, 105, 104, 95, 74, 116, 102, 81, 92, 83, 104, 101, 109, 112, 108, 77, 114, 106, 64, 68, 99, 69, 104, 125, 70, 72, 75, 120, 98, 117, 85, 93, 96, 80, 114, 104, 112, 50, 105, 120, 127, 101, 102, 107, 80, 82, 118, 22, 85, 64, 123, 127, 99, 108, 78, 70, 53, 108, 100, 127, 118, 85, 126, 114, 122, 112, 114]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [ - "def sol(vecs=[85, 118, 105, 104, 95, 74, 116, 102, 81, 92, 83, 104, 101, 109, 112, 108, 77, 114, 106, 64, 68, 99, 69, 104, 125, 70, 72, 75, 120, 98, 117, 85, 93, 96, 80, 114, 104, 112, 50, 105, 120, 127, 101, 102, 107, 80, 82, 118, 22, 85, 64, 123, 127, 99, 108, 78, 70, 53, 108, 100, 127, 118, 85, 126, 114, 122, 112, 114]): # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n while True:\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" - ], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_3", - "sat": "def sat(inds: List[int], vecs=[4377023492, 2725416307, 4575575164, 8237061328, 810108815, 1505904179, 7253931952, 3332035899, 4918253592, 7464508032, 2781888601, 4854482287, 2195189958, 1061245549, 2716454609, 4229473257, 3369619302, 7641078544, 6414803619, 5869561409, 8233604930, 1806428713, 8581855712, 5563574546, 7485355417, 5263111757, 1559804226, 7559201047, 5762788539, 3759231582, 2343983778, 5036600819, 964834502, 8086145823, 4916225163, 3776421936, 8243518168, 1653183863, 3589329243, 6874501226, 1681442252, 2825579257, 4727163474, 609675409, 2987647751, 6639501064, 6758018033, 7350401189, 1915697190, 1030569470, 6593976999, 7737301263, 8166687241, 4764265400, 6244165210, 5865981028, 2722013265, 5990328879, 6222511600, 4157727138, 5672865333, 3270585168, 3823274720, 2761244963, 6721835133, 5602567444, 7661437267, 2430216570, 7928221025, 836281488, 8163830398, 1958494719, 5659370923, 6990994339, 6157416074, 2887935212, 843453193, 401186639, 6140738633, 6331269342, 4602640583, 7379847572, 7298421854, 818045529, 4500250539, 6250820209, 1608180223, 476478575, 395387866, 2032234513, 3178558687, 8549359101, 3059533667, 7666891250, 8205460848, 8569706676, 8507800020, 7922235736, 1365610739, 6224047793, 1588040934, 4971652647, 3892012639, 2038058476, 4764474809, 2333230883, 3760468106, 3348180099, 8548049356, 1233700092, 976743204, 4800651758, 6337808001, 7131440648, 837308168, 1087651947, 1758223256, 8248576369, 6110305362, 2149402189, 2049775843, 6643369581, 5820944487, 723956055, 6129399464, 1435743819, 3445248287, 7006881042, 6246517667, 2248919794, 1380383149, 4809985226, 619856691, 7566372000, 5303251143, 4490148327, 7446123208, 4561827377, 2893702873, 5514085543, 3607781433, 7534115750, 2009177607, 2704806200, 2434148405, 1882440810, 8287262291, 3978684771, 5815490172, 1345052488, 3224426634, 2871407483, 1541167092, 6336115980, 8328868035, 3465033340, 8346422420, 7217667584, 3767277418, 1019051165, 8269746816, 6901079892, 2236545678, 7623606633, 6759268144, 7416927882, 1265230301, 6708234231, 1255392142, 427892223, 8396175862, 1236397297, 8520688996, 8193484421, 421818659, 2634745207, 5328012049, 1134753683, 253235763, 970152368, 43024510, 7534975713, 5015335818, 7212084936, 5724691176, 8168406484, 1065106279, 7960813010, 6966177690, 4902940407, 5961780032, 4296939155, 4394646650, 5811507178, 8246898330, 5952720984, 7669256222, 3150651055, 2771495008, 5882503320, 208569742, 8250547235, 6755041976, 1389463044, 3960399210, 441913105, 7438849618, 1344175424, 3039607364, 970569752, 228962592, 7567148673, 5155388301, 2767781523, 3946684753, 2613876800, 4832430293, 6207371248, 4336286330, 4817261606, 7658390825, 1382799141, 1952915382, 5595179368, 4913653771, 158275818, 874148897, 5469520633, 1168748333, 6307362309, 7452525864, 4533392762, 5295466831, 7870605966, 7982434783, 2660910903, 7629023034, 2089945055, 8241846352, 2250422271, 3998397929, 8409707885, 6755082268, 6919296038, 8030719064, 3286675201, 5413731222, 7721078642, 7604040340, 2412963926, 3664644830, 8498290778, 318032363, 1523534004, 5061317478, 5456067941, 799629135, 6601585928, 1856669956, 2707642857, 4817928081, 5927337241]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_4", - "sat": "def sat(inds: List[int], vecs=[3493942856721065622, 1359942525204655867, 4291023122040486200, 2766553264256283311, 2509845197160063017, 748113310575600102, 742605809159142484, 2308836799009044341, 2001480080927138964, 2571214109281681119, 716093291344468559, 2585453317524389974, 4569964661267108227, 1517945638659177151, 2746040396126518334, 3013038776652157843, 27023287373120594, 2140736170764712513, 3662831357482035190, 1628550458986288365, 2439681146614734317, 717528619957014634, 3927654952598415659, 4328480023310498318, 1844039354577827804, 3620151577898202525, 3246726270480167758, 3603855963235625929, 380678189311538360, 291413949996733664, 1997804101897321258, 1617696725350734575, 3101865116643046912, 3500969217367204853, 2667923342722587359, 4507242661249271685, 4470420264328799255, 294156949588854841, 2932618389969675106, 1468635533554548458, 2707075177328530088, 3083632912275570325, 3136530006696437509, 1565785048590353363, 490102155925286517, 3375121004778703450, 4018002265816879630, 471732204869175425, 3210111278179308677, 2918387522032659938, 2618080184983472773, 830931899951881735, 3364257181561964629, 4486759704752821229, 458364392101066369, 1247859097013665571, 3900259756598776626, 1446006854453720419, 1664828967597054829, 1949390325821445628, 1578412248287263499, 2803240769833333367, 2384723787337705764, 1817725626624320566, 1328051311407035302, 1840815932332293812, 1635429095189551086, 3874297291389021447, 478606850418706924, 2793195565296076345, 2339427522871529963, 1295685747075714691, 373533285279319667, 913078871421014997, 1948032652259777102, 3917733702425354605, 3611509095503159932, 2083498818183414214, 4318280259899560119, 1767583439289014944, 589529710801378740, 210898160527707305, 3317500435014874395, 2525065768617896273, 3637449287118420216, 4010469082555924044, 3205462120789692132, 4297801300655833430, 849551208967015108, 1249092584184011070, 223956162914635194, 2157318590583773002, 4397463745935463607, 600233515359147380, 1264091464457072471, 1158145533186408239, 2646502344461060079, 1743390893536163556, 264802598018940786, 3425172168898407318, 4499044951848166634, 1329764283197645677, 1463818426308877186, 3505074059625705163, 4169113348362381251, 3924844227642780200, 1253532513856569712, 3001550514757036850, 831510328559596328, 3154957244754491340, 4403937644699243117, 2934613545858881970, 4576012865557726254, 3164772032211112847, 198331710608830111, 1408348239316527663, 2444998447522151305, 4411013351005545273, 3454952928590539047, 2134420959950885957, 3537959772139630286, 1911492741663131253, 684859494597678774, 3083034978085309662, 875260877114355353, 3640202348469983280, 2297490860309003740, 997873248559572948, 2608345875129390315, 4385658585005032519, 2628019233645697182, 309592774207232713, 4196493240130626829, 606172131400734888, 890062392307013160, 468453236841355537, 1641769990274423134, 3876532211986023573, 2148655463180364612, 3434955084667924644, 622558497632074094, 2826487812016887315, 3606900038881567567, 939931509658890348, 2454005350092431031, 37730645917117233, 76357252798266739, 4307424527952740945, 3481545200552846645, 4019723825243735177, 1931413009425876596, 1167964297991684358, 2940260193632440797, 3563551547985355205, 3041619144075706364, 2089050002029089396, 3247754494291208637, 3611008889343217868, 1974144287108546450, 2137279206967807465, 2690590745915123884, 3438661695332797153, 4211163967573009766, 1304254966082721872, 241883267299150403, 2580883766397164580, 2146564223204910122, 4270329655512499837, 1558079796162985644, 2382846357790822824, 3999320878311647248, 557804978086136127, 154672625904259953, 2014658687358352948, 926574856223719179, 1611725668918636163, 3775152335922279011, 1477402625145386223, 4262278536715057734, 2343051869087521950, 1534423471327990567, 4117276861163553368, 3989499442924155582, 932511998942959976, 2548981419952939660, 4064230291519767654, 2341335174008495725, 1875096240103129139, 4252370736674328936, 2091301296749030510, 2519219894464979203, 2141736793079616389, 30401243985389194, 1300381149633092420, 4385430980993227854, 3713529800190918661, 3215367429147230309, 3493795543955158831, 3617690063866901486, 473704120343411961, 4596161572518223671, 1234734192218563495, 90271599867563949, 2752035485041844188, 1389793917548995931, 4129317513706538060, 3414715837885251205, 390483391134544488, 2977365266838241004, 467472824984421782, 98165592281204163, 371035742158633039, 3523822689578392308, 298429232214346020, 141524564664302690, 713694840358155365, 1819445960057115160, 3893134249856799769, 332731110588635300, 3941135085189244596, 1203622153992519413, 584561442493538746, 1564380648277523421, 1848112040235491855, 3354533583124000938, 1923388160353591832, 1147194599406329606, 712885856550293506, 1632848219163147982, 4076695234828343063, 969827647561377710, 3623288333357776381, 4184966090850717449, 3599505175205723526, 799977179189333006, 1866523372691583294, 4285300529315715037, 2472498117597447978, 3533296465580088294, 1504766636599501971, 2021176036941118060, 114423265830390568, 3032943106298729924, 3821188683214132853, 817272293348577219, 1910128834962863019, 3063645234909327476, 1808610335164722604, 3782267212354999109, 2438883108272663675, 2446538010218584018, 3747229148226393214, 1254360585390516598, 4443733547026728726, 552245478055391927, 1691229192442854670, 78425463683426374, 3535633696302976999, 3698452168455621787, 3631430505412702106, 3771020419404175289, 652235019292998886, 842718730676198878, 3127671417980574701, 1765391223296488299, 4579201547917939870, 943163264318160845, 4415816781491018877, 3677394336952756435, 2100313945608401816, 2353331639901358276, 1883935956517289728, 3117025302630255179, 2911730931904161279, 2067484294669287600, 4018085812492602133, 4574006069582759425, 3227172913270557266, 3509499778967688883, 4428924377640863666, 89572978905698165, 4263381707522635314, 1546763800481087189, 3795055078997915118, 4147499912786753961, 1988841282812320106, 1764114110534308070, 2178637482440548260, 3029626918803362491, 3384639636606649954, 2813825888698372686, 4021529323077862712, 3046017416787333347, 3375857910451168822, 2917155689814350243, 3819452078577989661, 1063584923323830865, 13148734208842529, 1338080346766795973, 489295290757782487, 2365174929363772371, 4593545655680020347, 3737417588053525975, 2196081287262617030, 1524075315073248456, 4067655774855830940, 213329900496497554, 4501041956422164708, 478305710282688107, 3165220007000872362, 871221149287088813, 628845555287669503, 3443813658714747825, 1427714746352881398, 4351826764986810133, 3038210187007579541, 917323211382123191, 2958986018156469747, 550900531606612949, 2190100760388778707, 21267277347008146, 700962725688468749, 2046194830686039249, 2681392948462220390, 12842568753504539, 1189865955431554334, 3826000162876192442, 1073590835351464359, 2478167983616377819, 4411836174421637102, 4232710377929593714, 4381122009551956294, 4141211756961895789, 1020731956720226738, 3422852480525516686, 3733285778159577437, 3954925649863238659, 724750214256938319, 3849133362350072573, 2970886035595782244, 4331838658111126565, 3994014176086963168, 2800964439538278475, 3018060429773144499, 107528106154491045, 3613412228622742146, 845645476888972718, 1836849415198659796, 921798726304952972, 1691935703249975046, 506178649421681562, 4378829478969138958, 2668761899707069496, 967020761532626868, 4370253350509910273, 1028036406359885473, 636934977966550684, 3639370608263874453, 2565775017553263907, 175440789712466289, 1873342486133521364, 2092239683553213639, 482500200596483250, 1550698972868698354, 2364806142663372471, 4328087142871350370, 2931028751256412451, 4322541984069960348, 802937819854076056, 3052968007675764806, 1316627570552090373, 4572485457738318471, 1410717093617234685, 348677377085526599, 276124381319707699, 2920255525661470900, 2794860833265144455, 3035577908790445243, 1839893420149100145, 1798747244882757528, 2940973496675224523, 24708006533847909, 244179451336578768, 2530682529649877239, 3932127053778438249, 3838784052122588787, 3926626026077089268, 1356252060059847157, 2239172454789039474, 4330341283362865328, 2568515107269597167, 3018318195234033200, 2462493340448871822, 3913523023996859226, 2702694936528801306, 4058506404065775028, 2015893544052313115, 1249604202224913839, 4510266017195119610, 4029725903799007809, 2322054765614528293, 3267713259245470728, 1209228689413104631, 2734862413004204594, 1254859073577279710, 2472167168371799620, 2930439835812963241, 3562870567527967943, 4560074080417496141, 992736095080813822, 2066833536485055506, 4329714598747724400, 3376153876234808728, 4228354375314050276, 3376619411878692034, 1367096078822588173, 2317215995742193890, 345610762991570956, 3088532751238547627, 1917395777951999220, 1019232967572879262, 3544179652195062002, 786621544605275953, 1821039600130061505, 3178730611526524948, 3283759271813002939, 370817921185561615, 3280396979273247006, 3743450946445655880, 288595053677372839, 700577150145864185, 2963968663426185181, 2962968743747087641, 2680514958540083990, 1094010825545196590, 2301496265128566451, 55306646969008064, 3261683911828361463, 2350803819301238278, 3366857276760750730, 248600979066177081, 2753456290761083791, 994266458511586719, 3481238182177649849, 217717170794439433, 3365901237150891377, 4060272243392431503, 3933829052598780867, 3070057594782787203, 4000324264126970360, 1222504803865364237, 2231332679894467188, 3575095080562342706, 676867646453544132, 3240722623567330083, 4284160390053412119, 1625387022447786512, 3289399666211588807, 279875354659289751, 2216590795174580543, 420706191253261630, 2922497353001418435, 3842806868942206558, 835229614857631128, 3058436197486231340, 3905243911896322015, 2796030925316290560, 1626789826437680853, 2410545545442219186, 1830613793078818988]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_5", - "sat": "def sat(inds: List[int], vecs=[168702843075730262429, 369519948633001136839, 347555145332043143302, 250851454857949440584, 69061778219804948792, 475469942545501773953, 209768991399733618773, 514424190838937701219, 268766954207567981479, 7394547680346864749, 126938077425167770745, 318358599261727004830, 315109341249979185557, 515478066228751163894, 403265238946747222029, 188899209183664215234, 24827825782437012520, 335032123588214630071, 384223708642849045389, 48915533105025322086, 101841528868721873075, 311131121832683636871, 32440629668388015197, 327950605702481046957, 475586059094526446213, 72658337956910451442, 317005162159852794021, 304367521642333351368, 270105705391589038389, 259873000154852113416, 177409779721539508354, 553919540439162886074, 564916838808372813330, 170042473831880379928, 46060140196650248226, 143161166854068016409, 493206696748363696618, 376464599835184841670, 409903447977442163690, 26878415769962305746, 259240749338669601135, 60825254039047710704, 419862577048754504175, 130240056969764914220, 275172359505179255972, 236173291408422398326, 233758385403794956255, 377696474632371869760, 412803326917059279334, 59760959267005448763, 560434241444827960050, 438472641451058382196, 77363529381786525854, 460050110083657049526, 55921218387864227549, 284505270151495169775, 220202086505377407524, 270531588014485840862, 502216237290990445250, 90589958566976695557, 367295891604393754927, 262370768212022611593, 64692603328772157466, 331797208741216227461, 275137541328693093112, 572252368107906537501, 102398691219544147038, 205699766581235871944, 448793900048342803295, 102045796395062500667, 561002384555924990286, 90999681088935677299, 130805604488210203295, 457430602631388239062, 96857574787662892662, 395509492614668116065, 1122029418534418993, 318136734449615633993, 79692149622793969597, 522764336671285227554, 292258934101859801821, 469094289328716547258, 176124550195849963401, 198340722830004577317, 290938962178253944971, 384526273257925763866, 208513952620665831165, 178795602370121895119, 8072174275677582922, 327379600101757096981, 179404248525602603003, 86896603678143062414, 278471689791968204208, 511452202630639038767, 500570538280725577670, 338469760682504155951, 492849270649326494514, 347553155718614987892, 27818671729227772068, 122269772685807329541, 512355333632132549028, 527025003772009560544, 471543873608632330365, 311880442873952658437, 176163933013336148783, 274228587943249384325, 463824538718499152688, 347440853223728889661, 279974033448211732014, 66261134761225908332, 441332762798195152276, 417305587888516079546, 298943875932708050175, 333804860621780765072, 367843843510791265722, 277596643503205301520, 581004854949933654124, 248137025434777133938, 400495781761477402105, 211578305746839297222, 454629353289052712636, 184667353210127247162, 413302134066652139153, 507080057174794762508, 114187244737722086993, 174861970013594063904, 385062245838797869480, 573329395904785445239, 266311674353509791851, 62534139516909393971, 551428090898564004439, 471564151568926528189, 408320874192424697213, 379278082740757517011, 304187387456212019594, 151581058588825101901, 89948254976383068545, 286564107063193367315, 182800924036086000145, 252251493294782061263, 523286057606917591388, 98663470714116974968, 88943470417600226072, 10953499770061888447, 454929991531015925222, 14073331460741435004, 469541648381707608797, 60805858430227484236, 463693948479524733654, 567301288422660890358, 310614770531183561251, 416025156262011268001, 456194594407686674157, 524954359230513258983, 569573959716202216189, 98524385776486226934, 72715524728428730488, 313698604145742586754, 386370943538559915034, 225081990502627598794, 96390895417971030450, 221154331049452185052, 485739717945433943863, 172319045326508383706, 401821464592931351730, 405297990545060762469, 466214473135434151259, 293028487990528273941, 326944737010182965094, 242998081647707978621, 415961764985120458032, 371754244893728307625, 169226488578190396435, 330786090186430043051, 259746650577588057507, 302220711069912706186, 433837914100543322781, 149510128406471341933, 475641274014338162160, 182009610745920904343, 176655871445742897467, 305892587401695294093, 584441581088492596398, 389310984337750858128, 254838572146914580852, 245995839746730432930, 69810982477119629534, 128636525204394714948, 420181239276598511828, 501192453800798840574, 583340342085996176408, 155710820924745746931, 55255380343614049590, 161250595104026591029, 101503724746237954404, 92184328263213305681, 323421518014566180144, 316937400358435561266, 364769454064521610930, 7272335518195944378, 473644636666972035893, 145998807990345755391, 370707696032790248564, 399321646806321041522, 405359728055473570257, 511263886774154332657, 335998959511697383083, 554282160430467213149, 386285269555579744289, 399956938664060499678, 479114033139939894030, 160956080476662090592, 527830084262948778912, 237032047817718008731, 230283872631896888681, 243245971588396251303, 343545675366379417131, 582437381277824837064, 521223045693213554220, 582490531067985138939, 195305501966331378096, 359211860333803297670, 501023233579034741545, 139707413235113717326, 536984796830279347760, 184102374641653382234, 327652498376658158353, 309577312065221425340, 417957935533629422048, 548427174431335481193, 535183289699733953668, 300542411401144340844, 319844942158718692294, 560012669472408459863, 26947860235256613180, 338792941344340797038, 256601543835711656735, 227738312717664589039, 522213742028735119572, 532375934987494733593, 232973561453441490230, 153230687077759283358, 388689954999572409656, 68547003031534030724, 61246182014696684610, 95929704338986050903, 449376377915590975060, 260905383922224608217, 110660011702379778402, 167708912036921203617, 10143640667435221370, 382851819952001811305, 371622874028982314660, 95338437986799264316, 116940651616039476837, 381799784236210713569, 196981293740942012272, 454646568531830348819, 31397543077921124101, 243696152665076475563, 102352458741903369932, 435083665765748133669, 43912986596598602849, 200556639698052984577, 498965553899943771457, 360463903084018870383, 485984851663390752810, 75277937080171726111, 472477394337992811747, 11567645437605193401, 399304744153655579611, 459290337243402748559, 205701328765472793854, 10793567897237552969, 111306556034824378143, 435732841039701401927, 381555092197951037198, 187491037767763118077, 588092695937142387036, 295200908555155722510, 388583502532476191207, 452944860997771412566, 163586340114353304029, 443623113452493654889, 445932456251101675677, 198146723156404078163, 14203318186634359963, 155285742673978850300, 293204286427140697454, 234227844492718483297, 420028491164146833652, 435860805905500245658, 488103281455595064525, 517446619815085760406, 312500871421014400093, 514559399310944001282, 306174610456415363042, 434780856561264839661, 225145364240328233356, 458912900423782605299, 459940668107537813713, 372687255111591640025, 251979736684712979472, 31716627044781194605, 40092342177894722326, 206465360815037642484, 572196759536131835983, 542738474655712177740, 460369451147406129140, 530133011355275695407, 447753933148747613987, 157511030749966815296, 100881777683127516199, 472516349455035583846, 407321944910210371492, 3833476285712436615, 230704292280606856319, 227373749780607395068, 192426622909748357232, 425258253315659314112, 254238534543347495626, 78297595532055314833, 247257184318424354053, 349882935499384348954, 333015403959217849907, 530128694941411601563, 307287631970508395856, 254540128445940355631, 127537741211771134015, 140723787925829080574, 15958965145039082217, 354588206823398905980, 534212786687205967200, 372929730346506929406, 400002438801271637556, 312526277442502860471, 532381088055727025462, 355829809699620647482, 69151519419783600358, 220486735074033841298, 342322433680869040764, 401695668944625903868, 262849191404560171716, 361180385287175643693, 390969198706645665770, 419289263853237190367, 188920360518178884363, 388174218958736656609, 118919345304715718506, 523443358756022626204, 378521768982013076751, 133470175469751153516, 134007025009437588124, 87444531857721889115, 100958779651246333260, 447760194307048139358, 589552319599535895500, 484361682150981098225, 373933627062252140075, 576807602532417074024, 378424643857407526307, 140044513240292173296, 501264670081527170010, 214788408841784390625, 363547959661757142706, 171389064248741850840, 478299069951371320333, 10036008305133585432, 420211856958121101184, 41386927541242902616, 486981079483013739283, 566432298928502146476, 11895298275626591016, 579229652649155194576, 569141996688031899325, 199252283607696356996, 453697465917267099594, 60531880958312485478, 161674391440945827527, 153722146120026660276, 90031630753251727127, 126635697042775441965, 471482905466697826455, 478366851898600258042, 60760332343644027068, 457721739976810530174, 429954658832708345893, 173978544424907969451, 329528660957353192259, 531368072575573244975, 336558541191202810624, 404784617826776067110, 10688094447984901855, 155441922249970114090, 398120197709450858058, 128061263732369525221, 177684111887683683284, 299905096329674742174, 452325409596627471676, 589568707375349846444, 237812550895532203974, 425196889050890050151, 448840196775471475257, 252283212856523701875, 241441741700662781018, 486884005907494335105, 442926579724736077099, 31613271590377387685, 332109547434553060488, 433831181578748696947, 171418763591406335032, 439200714700819438839, 167201410782311508502, 229250636916064924381, 556537849775832004398, 495763291208926380336, 134773898047660997243, 497956961909024340193, 281302575056968927789, 24509855420907334837, 498770323820530302672, 301704013100558796468, 72714634883056259534, 58391225559922481557, 548949620302771096373, 526607249247753794575, 300465931753879396962, 102883687014579121695, 50147547878058968532, 315610780397573140492, 283622126692298433683, 451847919502891699928, 390167752763741667973, 194297787202273221431, 286767503741361760250, 223327851123350795712, 155728964295734097924, 432617122426681345154, 51886612043721700633, 262577143028958643132, 96763251699540441883, 326764643839310596761, 550386538046931239714, 392778146407010553003, 415911905226932656493, 252084819753235591955, 269727758721397621073, 450937139614632469260, 10283303673196869675, 75585288509545448900, 129291343541107794177, 163682317051141960831, 220612679629569301991, 467099948455507665848, 78257384105003892892, 306033165872125316507, 535350487688847934748, 358862434091190020812, 127757397834746118654, 567079164568123095216, 339517071293960361570, 442059124371186321099, 449473600464690716685, 77720194001532532326, 285434443894718586642, 583651618922999492582, 66429039740837304359, 201157303035939876636, 339491637588775304106, 274425076061691291904, 213873746638164598336, 73214376406621784996, 260493497684954653456, 162073084391422131293, 569090530762819537543, 511023466068363805328, 29798081933763147265, 435866062633081822537, 296831933018887628143, 107980940071754927134, 458503809327505075147, 372216981046393540492, 407145937463838703594, 44685855198273267933, 392898566916343426301, 149866405801284607920, 456464175899317834197, 166682728097207308234, 407599907604841253403, 227018120527609659859, 260963775925134471144, 539820569551521979696, 315144991730558711298, 479844278605079977821, 50727235877957166513, 400575562011905073543, 91866283261374193127, 149588862060001345540, 284016886466378981331, 519238947229202638512, 407797428406046238385, 361681824321942768186, 148939950137044044316, 96996298195920429411, 179807608225022745796, 506011154659383616704, 122310216146329920391, 43993989153631677516, 377595315541892771215, 435145565306754350789, 546680359407631208616, 466030760615695192125, 304686810762196490620, 350039672276152049139, 328724075099455541124, 555933042735612900100, 423070313513151175848, 19810367283350030327, 533950691345981794084, 149723212633848525248, 553669504400259890191, 53636423875590316869, 219239278142288769567, 241495261733611541105, 249126371630436143532, 25615612187063811247, 492297394481642273854, 478914947091025241587, 444824163528459487454, 344213972099057828979, 61180169349633106920, 429192930246100724766, 220850634492772910648, 522449300988883393132, 323796893894687004174, 143421131904407951250, 281352722254767630024, 29599653424671632745, 159345711759235546872, 330999057478969924748, 512504838800783552233, 110792732517234827341, 131478400534625873264, 86531928642378643912, 552364163170729468380, 320068716521451376531, 467808687872204580255, 119881335294985289352, 295562823291810738914, 34307529552311215488, 316729743057500909576, 556073232050741120981, 48898769428677021364, 561951702872865962404, 19250793687368017155, 148635324954230215544, 530217291215103641179, 300513563499736019290, 458166338758975584473, 560382147333973650638, 367123218573310729852, 401487255388960773926, 57636181856989863122, 516421266238026283697, 34786768224053939295, 11389286010317918004]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_6", - "sat": "def sat(inds: List[int], vecs=[3163812673533625082, 4125577178789370471, 64110048483541818, 707173385026854610, 3755203846867743696, 2817742663890994827, 4412671896751130110, 3429378032388602898, 3027936192050369911, 4033127656015332417, 1323411978058946125, 1088652185726908725, 4097672018242805809, 2096826705280677885, 2562658556838288740, 4579861167331706751, 3954658588123772906, 2595636830103806364, 1015283671733602733, 1702985572994350377, 597108845972195171, 2259961764790974433, 1119260180803612571, 2480217890824132861, 3304891514040013939, 4592357438054436358, 3010611010022495362, 1571445556080689109, 3618286599215634737, 2249207203471635039, 2804179540720411849, 2402063123206776317, 669727508985050441, 1717484499649451571, 2734171852762871692, 2086164310039495899, 3071145274740078614, 1061850653204412416, 1737961297605925268, 1642124536480596645, 4437843249260091090, 4051624983524873455, 520983318812984488, 3427380584699320643, 4270301209154376314, 4115800136719533266, 3928170872897557177, 915105227651190605, 2080582080668872610, 1329597844554690793, 2739863910598623840, 4151573687080590489, 2197888552138543621, 252244303959227394, 3745239920121497803, 649338675922500681, 161617572598678644, 2030478374789928512, 4317791667895615733, 3128420261648657128, 4185383174842149908, 4479821641990227337, 1754915128490944957, 930658320922031770, 2231960832144875528, 4148568798010746811, 156970067364571441, 4351739773822523872, 626988942503289185, 635878656694748266, 1526461192277527785, 1221771093802203836, 1999141136699745072, 1982031221019564953, 4169942875707253098, 880047104916873863, 2650946353735814985, 1599586655793924363, 4303046718893387230, 3287078130713606692, 3317306480398444281, 1540181677757170752, 2859860318472913072, 584582819372451281, 2845698237940098294, 3347985296262653513, 3035907066877176424, 1142642581002365864, 914906220201689637, 3101091935964148285, 3120110276442648430, 938524414290436510, 2646021308984021379, 120989612463426403, 3466860514172752865, 1559028257370518425, 761254082668501122, 46083027102008048, 2690706438178930224, 3326922229474082107, 1412154300250168836, 3557882433309444205, 3643181461249203536, 2813025988618001942, 1745371172348290337, 2681091654822238628, 1052465664771979354, 3276057491901277447, 1524126313753142908, 997855537465238160, 32600111709782282, 3076985290835587955, 603254062140734902, 2142184922649620144, 2904533196309876209, 209504328209078275, 2450457785686075361, 3632434217568443657, 1971499046023015760, 977543417266459644, 2012812006443057369, 4492519780478096668, 1266610402667710825, 557094312901883066, 1105276981205516336, 2099066811187354809, 3932252856652820597, 1866769256906216538, 583040821415850924, 168150787005788011, 4453847761053539887, 3622998884146089202, 2614962428281908066, 2051088684497907431, 2785457047382339172, 4124483699098828149, 54481062653438845, 3215098566377160291, 3451536517374755900, 1405445532608925125, 3610780955132587004, 3458960658713688908, 387824407404364452, 320523133844017142, 3852430672243056800, 2195920228088742827, 1070502113855776853, 1822258816325275863, 3723297023984744207, 51269251458160940, 1368251967786748726, 2891171057137845852, 785891397344876782, 3797941472955242773, 404047287129410159, 3139839438763305557, 4545959032187108832, 3203974405731211854, 683095176620444670, 2561038422554619475, 302097135312046089, 2330615260691603006, 3239412988377924557, 1976762555545015224, 2841336434491260348, 245364679254316424, 2881691113020238972, 4507579989745340779, 3901755261874065182, 2715449968822847541, 2236458704863285709, 2907517431875694082, 1510511751999422248, 2956116894975279787, 2648959181888448246, 3831547048745937025, 4506428080168512235, 1066452984585081754, 977743918838963487, 4092965069038135404, 119201307306512118, 64239405433657860, 1613847205328907643, 1803770109730281876, 2717243840917227323, 1725421186803919148, 100867811624614291, 3246953094070582118, 2093751745433103700, 837200041091615519, 3006601307927216861, 1106717297710787503, 2774249820271246760, 904706661489239971, 623183573264609089, 2426292811742134453, 159489753424180846, 4155912251660958143, 1736950923687565976, 731605582635982242, 2515811357134767991, 1653445483641662160, 1398483649700125872, 3770391117475464589, 1570713212877146342, 3456077309244063736, 2568029914553866077, 2705701823791664581, 1169941227294935826, 279443494406752674, 4505725385375272675, 1581983744004455417, 4350388281110366660, 2889232399699267390, 3386821610839437111, 2340141477865602428, 3054049022571171827, 2529515021190649330, 3471307493201923392, 1664408071244747634, 2906709991859341570, 3059212922136209508, 4174482258531025503, 4442975304617165701, 3707643227069966499, 397158708156138601, 4082441743247395877, 4077670132153086599, 2590330607793773774, 381322446410843374, 161791448371912019, 2210211701134619604, 3859221327244161771, 2079814105791191464, 3218300735773729516, 1306805005128365455, 3435135170461364068, 858461592903215814, 454822256333253568, 2118918823805743221, 2119640191637421454, 1603412635112565066, 3527432197870346922, 4025370849439531582, 159716118414294237, 743290746131741333, 11257584606624539, 4350943959731953271, 3314809214940636420, 1232748431451311937, 2581559943081634491, 1857353989781966292, 2008858458287743530, 1399735098507023912, 1294346393660379265, 3295393421848022877, 2096247085822694944, 892165113713077738, 4033301725414836994, 4493504634403519604, 869697897463433595, 324270213620154145, 2639338961850841729, 3461689674118404597, 2040096094485192046, 3608564690028383279, 622809753724542527, 1700885435969500573, 3747508830981384513, 1458967860314251876, 536237288298472832, 4264847798578238540, 150760795326830642, 2716347697236874567, 1304127041534096992, 387819810602302536, 3416593847594609079, 873280859471665502, 2227641551107770181, 1951854439253996240, 1526871706390028936, 919569561333083661, 1358472157458114379, 3998930211532498867, 2863735620830068020, 92543433771855851, 250430103620249205, 1988085421073698196, 3810755874558613309, 1436079408041441386, 2516285400853509321, 2184793845887227189, 3389042708361267088, 95599732233507452, 1477906790032279432, 606805557559119582, 1854780444774087827, 1775300495553759606, 4272351954539657449, 2139858741049311694, 502071833385601043, 2048536054309966392, 1330382011920338982, 1038010914333803788, 1874011819391934312, 1727949515371740939, 3880881099464573966, 537176707117270741, 1360675743063700600, 4063768038557129876, 4177368043253030705, 3164023653463384829, 4186921038277081937, 2383210727799231225, 3750901830889486209, 4224429527837995480, 3607523490120957366, 4363873527175269450, 1887083408911658981, 1017272594653068883, 2281263382698400937, 1295071375969427849, 4330797573204579620, 2229267851072599813, 821229020271665353, 3252175330995628909, 2961269339680918606, 751533361374542009, 1772764101920016427, 601482291408982345, 185751142736988908, 4276324200248405461, 2309493265511211920, 131212255669611642, 222871332242929735, 1693651002512781684, 383680245375190049, 765966538782252357, 2851724156250815553, 320129477017462404, 1897923825291663314, 2253846470193566364, 4411949861966503379, 3485244416579873536, 764833904938748249, 4141611497928111314, 4487630079795803606, 302409589258410256, 4005383319664282059, 1803502306813342158, 1773240442310211495, 4330929649542920395, 2146777015205867778, 4493298517219815542, 2254789640265341082, 276960851209894065, 1843911883584981378, 4437951810517988799, 191208623986839277, 2357518407659728131, 580068308465104958, 326909400954030245, 311029530967267707, 2581529846038533021, 3795917305163682340, 2956952932593436902, 840476460952958716, 2593869101006112718, 2141576347596232032]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_7", - "sat": "def sat(inds: List[int], vecs=[193632, 185466, 973694, 1586322, 1936492, 1442817, 623508, 1605013, 1495131, 477170, 121217, 858216, 868617, 867403, 746134, 1996958, 1318459, 937946, 671627, 283749, 1383066, 2057510, 41584, 518092, 2095122, 616250, 813384, 1790116, 2015840, 348815, 473813, 2051960, 1951459, 1111824, 766224, 2012601, 1526144, 1752522, 1281635, 161171, 361786, 1470149, 2080491, 1498536, 849075, 1373038, 1810962, 112480, 1346635, 148991, 777870, 1984751, 1230999, 326979, 1004945, 2072011, 828827, 921455, 46527, 1544526, 1330462, 946038, 1569351, 1449696, 967090, 310409, 1996053, 1734028, 482979, 792624, 898222, 1052934, 1476503, 800589, 497221, 157971, 1769399, 2071096, 884695, 1481768, 453305, 712629, 743990, 1243095, 575313, 1788142, 2064214, 2054842, 1986988, 297734, 1841729, 544936, 859440, 455020, 2091584, 1900285, 74724, 816147, 997888, 1959232, 126483, 1379584, 1972314, 1017280, 580238, 1591642, 473148, 967147, 1056693, 266587, 1607608, 580638, 1737911, 1946360, 1921247, 479441, 793313, 171093, 24989, 114971, 1406564, 1961428, 1060148, 575668, 75743, 1504729, 1806107, 671956, 41523, 1675798, 1496237, 1427629, 1990765, 122775, 1544556, 1747931, 1403887, 1492809, 424049, 1073579, 537323, 657183, 1226495, 541847, 1958656, 1089989, 1587585, 1537519, 1781508, 1472891, 1847821, 878567, 217038, 1757425, 1558896, 217133, 1173884, 199758, 970768, 1729081, 1697835, 183539, 1617340, 1521869, 1206868, 13763, 120710, 1374403, 933970, 1177267, 1484031, 2016832, 1473440, 139159, 1548651, 1385654, 975193, 73618, 410753, 655441, 2068023, 1740127, 1081577, 1957488, 345766, 894821, 708254, 1966930, 1957578, 1760438, 1270110, 1140982, 607447, 748118, 1400257, 1802969, 1399849, 1350486, 205140, 444225, 1974139, 652973, 841551]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_8", - "sat": "def sat(inds: List[int], vecs=[408618428692359275031926275246, 361447835328706623540324387161, 495444681047137604478647905317, 603020218583428702663890790452, 51351535733950387547969754620, 452219019167786079423404884354, 190695869294782525532364337196, 107582970716519909798120217551, 417523758578839458574389726342, 569083406640495842255331122204, 419188788647558426466370029111, 590273827112982962184620601505, 37154372939756615956147160071, 400936376268327162484104161759, 290153311504934457143664428647, 300027017151844702379051573568, 98002130323774327603022120155, 20222862555132506487045669473, 89131473714796897392137366735, 391597561573735201539551071915, 277912748444197591271798625986, 79173136692561446749152956228, 52243817365010174173561337117, 76535124031924788039554133414, 457449043549930902735545304718, 57442583051988438199481594510, 472690916878158912530189568598, 151733541107232100448052429629, 385532858580463647025642647118, 125532199800760773072078482444, 356093385952254487367163166287, 107326429107260927508322211969, 496572777723374913328428394926, 381648888252052841927433601622, 275305687313429899815134100281, 207244844851932749349512091571, 399729384396668848857537775692, 303328644986110189304019836207, 233685372688459963969465189121, 109568775868777993909272127505, 609955558679665222200582507752, 210143571787620244253137548898, 35164493062115069395495912957, 211990746199324486264009661706, 562545104074510148622493244082, 298889945487494044362744407140, 290107681857429827439469711073, 595909672641442002049268852184, 426400032630444939558282203725, 237539686053631232678103192065, 330893907644444681468651014633, 186730980280592794415894023778, 96926574841284754934011253101, 40434270036362208272643986802, 442914766386173094793495009689, 583930463593575885380524031115, 75841252798483459790701217537, 555830208783531541514934071207, 587210463933250089636534885090, 220105841303757107532577281557, 115475452760419452491748417332, 536690045262693736861576122606, 463079889851491640733525902119, 434910529912542608374626912531, 511429192709912045941606112748, 244132535841344214057367184644, 337560223518903600203217028444, 446647436060647730207801970552, 564309111411416561551061488861, 156163650774941163726735633535, 537462206922923432051862520504, 126397702929403993942694379152, 408324002583413560428916492031, 237876394068070462879802379801, 488661501029468596237920023396, 601366909301172141206755950945, 561648784803221670594452298246, 29767450812918960721257128137, 602723383838399148687360172521, 277496521357342736905079558072, 438244185135423385182550908450, 118963530657828041783820875498, 540729581775098531406680530877, 172454988139983592976943786069, 580696078375832464060172468540, 373840606438451684920602271080, 117321427209642079951650095844, 548037613488098333309006947532, 187813872613815926730077912851, 269240022380305157120672690982, 76167485396495533140283246013, 539977858407484759919522637008, 351388528902200728685307617655, 630698208213306537369403878935, 251995999714560134079586421448, 437405694159106736219607238694, 140689174700814806078880129093, 203727584755139923008676924211, 410946479616775168766305860042, 394247843195326005534771416468, 431890317741243577712282233165, 586377548202923650876410129654, 552695657366899499281899516024, 488236055200255670834713714798, 128672276482101068052684296857, 325638465525773171812207661576, 92192154486218707439011032394, 78325868673921112040133983915, 415032011171944606307452833058, 537247524675726359518462946957, 491214229788888464803713014470, 542030448136290774253693761084, 152227023713187319366273448958, 125373964745324561240079460436, 258144178329523738732768520322, 376100597780097043058654689115, 428502700184279806994443484025, 111568667435093448579033313449, 182122906421725422256088807819, 632879906410809771098304627456, 527620377338091182238709072282, 197426961978559950999697717009, 51888616456548115810237249974, 104072931202602684200395773026, 257843378047384166897157105842, 276943751177816215630439038644, 385785313584728894223010814511, 331940909555504815009350048980, 227440055349520733837748877320, 1923840139006778278835059743, 609795553074576245230917387852, 192693600791888663401450827996, 173604488808776684818030532860, 426334464980246081476910389517, 417566735378945771563376371128, 376219245533785859577488036214, 74332074574277838970717673920, 199130632263800599226943800465, 437847853488735091225868627820, 47546012806273080460267986596, 410388391967760397179386413470, 157949081384038343071988548032, 244243131789035480183732204998, 632959465687517276425696876132, 91240017266157167641266894991, 245182967601654253440118957271, 49462506514546349222799952252, 104868942249922265070437315999, 457184400825949771164690600936, 160336318827953472936897049001, 480259444469508955996184875464, 17929822124437702195387380762, 228336306181862022446026798137, 480819882601131878315158198662, 59042509470451633961382917124, 564679241675002693850216261964, 508332053367484074910817589188, 555998594365919986385191669384, 158344627255055970280794997895, 153779262914274575909289639908, 480036886627241320670572130433, 369156051103360097033315437609, 623538347833702993754211966654, 117512306000920803731478042275, 233802320392331853582344607791, 345857052121025990190637363363, 283599461222712124506699487568, 204130026603204975332649118312, 495890677055734996770823676706, 363866955493391137216187692305, 65498495750619967310648855008, 6218200883625382259595623274, 391353975857478407810131430415, 14067580600208958076989456330, 370775622418711906439070014828, 595474761866185672001600244213, 322070689867569728672507315272, 595031939443715573078389604600, 427327066615291914591385853879, 365734444110299175280299706035, 115222526659677958472277693578, 80225472601954799735543839458, 114978473959563909727720682259, 256226408668980558434328027830, 218948596580841112171873826044, 29405253059306536126086146888, 239237835464194042301613789700, 470469700417733684052420769972, 527461830762483069014501341931, 193656422786103142308001060626, 352306277742474903295076024702, 564106854493721075239607435380, 211882012583271522140036615854, 103514105756681154755566421557, 266847168381287080406022638090, 479261498806414912506207216898, 621173338218158316870916065289, 483757861396639252885751316424, 83542522668290093189321585041, 605336934044708430940921730500, 328731633156210950314975236442, 538801995106609804094360928441, 472351616556954858195189006172, 497108448709027757850509993186, 528916327379386787742021806708, 198241421203977774859415962708, 409599644627886949253427280035, 616628873866658731847320697670, 511649972414191244583155310743, 292849426247738474953469891283, 508506270841802525008250289363, 341445776988167088741248283685, 465838034445000342008782962007, 324359548655322151791252439598, 277349438664798696697666050844, 494163535024097285953483686123, 564469315098405082438457461034, 66879553408744177777780664513, 401993524447212764275845398622, 459227829693645850310301314003, 489638400220907761137097316434, 379385179961193018544612371332, 232211107772270692880522890640, 627199448994180883269238608045, 479133695591014345057128559919, 281010302750298807489671620208, 514131354587022099564316531550, 259148063189759268957521472311, 590827825980763168818570156527, 458458628900922345958141420468, 247982495706366067581758208906, 461792869088848360751658801275, 446752719684607803003255614133, 223393691789073045237107154916, 527140212452584864148646622335, 160105752008127664355977128583, 186155247433607948637152755264, 303427488001372757145542304864, 418285371238670896709459494407, 231197318160921585607166135683, 158297891781498745083058101845, 278860405120800406784767606721, 425633113279519694805107833223, 398842955175812719080819680959, 141019030646601481726566224622, 575835759934360213226220360367, 368955221040267395513452371371, 140434757436997412975163546284, 392085848544124654610989889999, 384279501891167586565588352013, 47641639473291242355546813778, 299870242576630313692958773821, 622155812555078185619881047569, 36660617883198705181938943745, 420646587681990005804860060994, 21916702966490669744913613457, 510407638878783808357399445268, 49730865519027529816339459558, 161968815498700725219902433228, 318219699380538161157027383696, 187191203845734877450876577760, 243200198408324840905921619751, 225171209503668894335944385127, 58055313177224343994867015671, 223410376715280690105011145244, 562375087392869637062545294917, 122428964064430128792406644214, 518315999727186545632642566227, 230147800563626899660150710715, 170828884274484015369121085203, 500465855418923843456446443355, 221087704355182909986988528104, 189078832782681695874957628174, 260979895300945912211224285575, 104033278761314353024252993263, 97555757618020913288188990558, 65825915425847759874897013088, 392051513079943667485109387606, 256269125534325028524057320787, 538008489068533363710102830311, 371137497948714982032796403349, 172627722484875975101656972331, 327100877537964842128853466153, 451292443458566075281814971686, 434433782045298216647126986828, 173738578033147045785039808799, 389778143025534032658102921613, 158510994784634573565507123568, 121913785177387649113817037526, 569849927355384513344573829305, 632289483886348614576953328686, 52413314817784308045797627787, 286767906831099884558623931940, 235389299699043927409258386050, 514201782280148032184585959468, 260195523043032695205743143807, 579031414580098321787531139194, 576519667039998835082079928567, 218656027405530451827389224053, 394198620376185911012981327279, 530558277575620261794187728223, 533785170994634338438719354419, 327845428721826122983930806462, 215303304126671922120709939646, 510443745259318326568644832666, 5575728489834987986769725926, 176393414773990284322571112847, 105873894971253099430358060419, 451681135303518830514816252601, 466245710459130635427343573779, 407662032155392297206193535499, 324090211771395492601157056839, 614702827181886206348296241934, 60684491633565576253084607008, 211826579328183072797308299784, 539762328779604458758347948873, 469664270090999909820308637516, 291874026608069729105932692935, 206474853305270504184940171592, 464709217533662507457225797420, 352960429208995021218659591898, 99434700859490684271839976887, 153305184644437224551938496044, 125045976030824999167561422451, 284317318860542899737038643294, 394756879841105089757101359622, 62845570212427988884860255521, 632151132860597761326658825303, 467129844203555829318194557069, 144632821859760066069006847151, 345324668014171818740651782314, 40115152485140817507605100641, 65730245817455785293313141749, 589170167913722718151928759159, 543437220897251545392726872727, 394230410397784046474918114217, 294946422052894826327132612492, 147255732920593080318431895221, 101961810312014346554073344151, 609588880221153342282517459662, 167387064666485534325207835802, 117962116888159499691483668565, 565924989039171501146665982536, 511063965856984221025179177438, 383983859882972601764373111145, 567387039003416088010561912477, 359864740760854562348452599561, 190100706749617057496308580565, 330576020427058182448326550674, 145512508624209959757972681332, 46131004468746375165629298223, 306882508203109129172028178012, 569996043496853378519374500917, 141089355085088184480552839690, 256988560623539870642374995017, 370460795369046353249694528424, 441642425542296683284198595912, 494839445494468862593216689216, 428717451309875686938706542377, 619827954165777292181276769601, 207785678944617023204009255951, 583758800611356914535570314288, 596518822804855885885245003928, 626692626733741372505031922923, 463982897618057775739596610165, 509775593407542310694883569669, 119367230854033674122780883283, 302080618514403431989384577174, 300164777152940497523914501868, 198783530183087695153033361084, 360921744855702661210896514936, 564108538752418989803500551032, 486326195271237150203601108057, 91809116573240642554054795933, 195371560094288696121446540790, 632040372069296641746151329966, 39567254310440617762320216078, 420686367018770543915495527972, 523811905249786956973489923754, 23019137697839072027712279359, 203482439105428816247575814179, 192619230691052677518083274876, 475372097487354138244628561976, 247082804404177893571107063468, 412165646388399145566331984318, 365234217354475444926545917181, 544534195374371004418490164896, 589741043119215012152812412937, 362553293575656643332508307695, 486251707475454227411297054698, 498145787133208994583612481349, 548322879925257793656665788517, 606421892125991707022087501810, 320640381657290790184378890423, 465050067300471644142009915035, 581981888064244971854418094768, 545378086426086856722931375369, 553924289444947304386330332479, 140962578953502026769666626319, 127024762823812159480997683226, 595659328382547495481790925840, 456833796217034419883823896583, 496252311944911590170407076820, 85381511479539221645520275359, 169446515879171315561453804671, 451142358354452611269290719817, 619067568151194665288905886764, 156686321795169598533563184755, 453247730079725558184636295341, 24927214427259810863769637418, 467514879402991441280975315914, 570310870427911137395090088106, 362270095748634376831383642446, 567658554771208624655954642035, 570008553167687723364103039040, 182149458054339488928591790799, 317522777849596614556657150495, 162784358597396782005788908358, 478234851208787498182199166672, 405909197692840799493330536169, 60923643255100725716013187460, 232286892064146223123886214973, 233186854649005657627631097134, 103638005898870024157314649059, 413172843424804085558510482795, 27873688738453858071322942944, 434507387836489207106747794160, 261202483270417703939583024766, 555990977492975402495881691656, 134111196413038175366792639806, 3140557114884948246185593176, 390369636320004883540301633232, 624038722741887828794320416396, 354149325478544947990281558503, 337071074844895825295104934405, 540477226796134079886975941575, 509351554881397281798778520068, 527651188450955093552283386894, 111129272479791261125517855879, 601734981386631576588885834660, 149619584979357614066596367360, 623831975705611165329921840567, 427622423795949828025380508828, 8469019969893036244283850917, 618975847663578424378341132760, 138142478511748392371210441100, 199864355057452247682731601527, 615302958782289444556809943485, 35044374167883175014751390870, 74414983460592335588427057785, 188336120136047180034220614140, 491011978571011587950512699681, 202679702287633391876573738049, 355957796260307311971814972981, 37318215782589758540742372193, 147849566951028047431239382435, 121765213886653372678398045517, 444693694722814583414727488531, 439496570900360185167400590264, 103270596047366030773818928553, 225096051509394509662970418935, 161551674989789132414997289569, 369272049736895094166912093961, 233444098439971827780372044585, 273870862050522345056605127746, 253290546359626438940472646331, 301730778567500760603404872713, 594959883241678671120826304307, 608410045641733533188506480149, 140841609082866047301266816643, 416451206589261839228540502885, 400079142856127732679231757756, 177860834311864237512968071870, 287763946276465293951995122142, 603020359589930645939088086580, 383860470962289688670916964893, 265801979302577811488945245955, 188778474156025198004536366791, 526851087355948768225066937296, 625392283215160122079337212206, 313676136099917936135331876554, 293172582378827078548327740697, 587876250877881301661953257524, 379765838232544779415907732285, 292757190083351915549160232056, 185659841367078016692263402032, 346319440566818785710829172754, 353750634372714413869621416203, 418842261565491877555255803583, 34202658569085131904826575836, 568533772981573136430146898706, 582726474381100487487145663965, 88527172218128771170655480232, 630034149082749697695149987422, 602355445228367986830539896876, 31603675796276558892895064180, 442879951007527544112260476581, 18202053396933717404741021049, 414727575984587706267335155620, 7024510174208796847600907910, 220424583750134120413979961542, 217032832470221158187403739768, 518808005753539326620003480708, 243381340233513410478424621071, 581309773797787538430199495309, 531600547208705347264337385780, 429671552302964153024894650790, 570535346083263747899144554920, 243867427121455110302885022197, 328894836555836960708284998717, 75928899107834519164333625866, 272893391456863813815809216602, 589633691797746259822297966621, 489994448652627580079049663661, 50104867535210423468848353199, 299558043801534018217956883494, 523973774729257077150389719805, 192460166229082372677254550214, 409589175737257360297113866323, 517549420148587666209779518474, 322854282933002614076734828728, 631962895252928325387986982118, 581867852576203379616127075237, 140773212414742623318668974681, 360991187906074217612450160519, 447531785249846456114561514836, 491026754876850404181691984867, 243821908037994906600323313794, 126888380923808145761213692723, 291251252086417381790344997183, 56765200683537805238454541352, 114591440329292181242718562312, 145465834388517187397502646058, 588845243223979182700012067020, 371477637278942208834027624658, 354792549841894871452247194270, 314752848724944527717399572610, 417922237639425080911417180868, 462614577558496392545806244976, 176572903273319637794545976479, 224175348916852868431153800057, 35176042370217299193196732319, 117729003021287629821804969314, 445696348703169912622193457877, 111038201975558436077501027636, 115147300447611979771864467957, 381513422012417618142822450944, 161822580884533403632314216600, 108546103949499405157478903163, 574454741601019007668421545886, 253975981614658559749141774920, 98332345023311665762770071539, 455283092786517455327974874822, 552460096548333627362271035840, 24115726485353527479470297145, 581191325943416656063952727316, 496807130587673189382000831779, 133859682788425262724482668115, 450782068884083570024263838868, 179491795941163274263946665537, 533400765916205914928667667662, 631651626665185476822267167087, 186706676658742869315247032430, 318098600468235616589075883002, 272295498402187830637214958628, 510143896647441739740145810333, 552071944478251924244492440732, 423212957268927572810207742334, 353525149983891487880234572966, 18007359637916863884075917554, 120472434382556279835702237406, 336756097058913102435677167781, 455912572184382506505746619260, 599644670863398113509903136749, 20660285967020735955397932507, 523979780650716408568393740093, 230942133263536585619894642339, 277706999510313693983502182364, 470949544950262161828203351155, 436017056118974144876306588451, 482536315361847674031788120187, 46585603801352509840607621002, 544624585995708982910283969359, 424850561111601934663701569638, 285571872926792379132713436060, 396100081416463346392900621366, 476185235501852158558942534117, 329389660755259728040315156162, 124069182705511209519966300732, 175974076825707382812597784629, 116819504949750807868111584179, 622603293584069273178562739961, 529956948146184624411496790172, 96780336280858165617039142568, 99941156196240094773426131807, 440060115243566997042959899775, 310144549471082314111362202478, 140808456369429264456940722181, 297225707307541740873837884532, 440430427947273668679073708330, 328408335404314100036349265178, 344538008883377034876174435579, 161459228808002250445080132808, 125616302937340754613768425538, 175207297665439260676748864371, 450255898845561082959228210005, 498824132128631940057290350935, 67702894775794097427378178005, 314812192103450877297077387878, 88287686644708375229763074355, 425468552446216231331668286913, 620294465541766670723208049839, 526954542508545731813527490394, 60063399589713756532683579838, 346132918944813195572644731643, 354154091709337067825142720960, 630919747708030805809526425447, 493986759343622876565850301536, 549028719118286328821542722452, 355624986447655403370619933269, 582727679763304752016697805611, 122019965563396470659954888505, 207442202406836444655222630988, 573590322514859983920243688130, 96591385333667448879601610003, 28688436164881823111041539939, 368363281948562905736832599500, 264543587152623589464721218200, 132387477305621312828662861389, 567506558062530626135362130818, 90892583834347827075855477398, 550335214912058443388189275125, 253861476275153408819472963716, 93544378748629493433274853228, 67306027554938180064353392868, 163469085884690016914353624741, 27425152898749004736893136674, 387000470158409617833286601901, 599483930979579301528644391304, 165076053463904052487787104938, 229398191736717633587677609561, 194093024744358184484444152899, 291399412841398859743333895802, 366684939650630593547672813894, 401818210478903794824913883766, 443967903697350733234325653821, 368690946042496239102383220765, 556747787628678658992994625517, 397543310041016457618314320161, 377419542476293782508490550678, 144903728714837116852756926094, 448442277175280289723827539083, 334059209614405728846236825101, 186775459609697083481867292138, 319205654353929412217453740955, 541768906973844854201459093351, 424780774621917863662842966251, 144035764441502282891678233532, 147585461325418603058211659552, 304450684092231944223220900115, 590755124585286583377316963154, 409616651188573968129183512620, 604143971369982726604345748009, 614323756982331946918025855636, 530484955383516098604227477302, 258708651296590719281039721540, 127570762053505228027492021388, 306283797970126805714933567264, 404153897800528780323550421069, 494959447710717961355662230168, 420938360146569553639259312328, 628346902366134709486890121950, 531518687283440392247858142273, 600736568908352885167472832101, 503291009635656252566866498930, 524376467446327091631032064348, 479211766088078194656713100926, 370367744744552955252383245813, 419936697954628475134127423355, 397596435877947807428174858740, 423283377446435628367190452023, 229688233829248716577548983795, 161882108171869603020205130996, 6242424651517029373413825376, 14795291114086283442449118066, 111368369712406460437474836295, 442766298992439833583873995562, 460326326439799141214587910773, 553711357271472883175896104544, 44682761615062907330963187428, 376200522778834414982059319041, 102992937317467048534770675333, 31001001814387879812183100644, 41502280125558806642695460478, 354662518956084764413145286924, 489679903345877524502618433605, 83786343476986984038475827184, 622766589425162658612803190968, 350347663596171071705455225086, 40581816942522109894928559026, 351285959496437507675305684624, 574760563550523250180812703486, 432305709563931607859300181705, 547183055165213063466203139222, 602822474381950286376411338467, 98673061769904926645631095204, 294551368640436471452320307545, 430456808529351485094910208660, 625542615851508188044138346772, 850607296152788082892902599, 123245818205619382497015764615, 36397380177543883640621247775, 570523140784927780145399426790, 268959605138149231558417777759, 323401304297611442443355392654, 307510368882450307544211119798, 480136062313266552298859084881, 13873047187733632837582822851, 551058043709872841528500609158, 624170772192513101717196336184, 161150993458569661064962984487, 341875666146289876019039341586, 414232142014849348761454092024, 614684560355348182463334328551, 546634610578297695377653935445, 493968524064149907450071102874, 352189124212678890008677366071, 519776828117121645096742187180, 314263366913037459975039767818, 240710922680814247577689647276, 613437970734460372711465672060, 605846647039032358440509904940, 249231243983427660682793745767, 174472741772239126301493553643, 413986573625246840332072478146, 428730933586952370668574192590, 326705191144467257680920283308, 429752358979347979980269640487, 397748741208320414590973016213, 72240975647170767273776181512, 490963187682073831529416796382, 340099285735953713104340317326, 448389514530425662112198268796, 591077399984765528952377128588, 452356472904990342406809667184, 158910830395679556230766094659, 408510915827231942551675247005, 562908112803470622327991489687, 370283077122503346136081289877, 27409975298297235620509628352, 413447658937745584314523627254, 213811702235622126100627605291, 19854514117499297565415938997, 444359521763008015697711757607, 399647850589582044966337454412, 101500611276584879559824994546, 64641971866865577354477644571, 546040299441872337950269885382, 197051555533019072484821822196]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "LearnParityWithNoise_9", - "sat": "def sat(inds: List[int], vecs=[4, 16, 21, 23, 27, 14, 13, 31, 31, 23, 4, 6, 31, 14, 16, 9, 16, 14, 6, 6, 26]):\n \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", - "sols": [ - "def sol(vecs=[4, 16, 21, 23, 27, 14, 13, 31, 31, 23, 4, 6, 31, 14, 16, 9, 16, 14, 6, 6, 26]): # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n while True:\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" - ], - "module": "lattices", - "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", - "taint_date": "2021-4-26", - "weight": 0.0975609756097561 - }, - { - "name": "FermatsLastTheorem_0", - "sat": "def sat(nums: List[int]):\n \"\"\"Find integers a,b,c > 0, n > 2, such such that a^n + b^n == c^n\"\"\"\n a, b, c, n = nums\n return (a ** n + b ** n == c ** n) and min(a, b, c) > 0 and n > 2", - "sols": [], - "module": "number_theory", - "notes": "[Fermat's last theorem](https://en.wikipedia.org/w/index.php?title=Fermat%27s_Last_Theorem)\n\nSupposedly unsolvable, but how confident are really in the super-complicated proof?\n\nSee [Wiles, Andrew. \"Modular elliptic curves and Fermat's last theorem.\" Annals of mathematics 141.3 (1995): 443-551.](https://www.jstor.org/stable/2118559)", - "taint_date": "2021-4-26", - "weight": 0.0625 - }, - { - "name": "GCD_0", - "sat": "def sat(n: int, a=15482, b=23223, lower_bound=5):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=15482, b=23223, lower_bound=5):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=15482, b=23223, lower_bound=5):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_1", - "sat": "def sat(n: int, a=9, b=9, lower_bound=6):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=9, b=9, lower_bound=6):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=9, b=9, lower_bound=6):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_2", - "sat": "def sat(n: int, a=232610, b=3131721474, lower_bound=15000):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=232610, b=3131721474, lower_bound=15000):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=232610, b=3131721474, lower_bound=15000):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_3", - "sat": "def sat(n: int, a=247586288427023352, b=372021520735824432, lower_bound=1709054537):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=247586288427023352, b=372021520735824432, lower_bound=1709054537):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=247586288427023352, b=372021520735824432, lower_bound=1709054537):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_4", - "sat": "def sat(n: int, a=8797233, b=2370036150831, lower_bound=8364173):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=8797233, b=2370036150831, lower_bound=8364173):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=8797233, b=2370036150831, lower_bound=8364173):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_5", - "sat": "def sat(n: int, a=10799897490, b=39426750, lower_bound=4523):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=10799897490, b=39426750, lower_bound=4523):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=10799897490, b=39426750, lower_bound=4523):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_6", - "sat": "def sat(n: int, a=821440637766952, b=313059975920048, lower_bound=2773268):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=821440637766952, b=313059975920048, lower_bound=2773268):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=821440637766952, b=313059975920048, lower_bound=2773268):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_7", - "sat": "def sat(n: int, a=10, b=5864, lower_bound=1):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=10, b=5864, lower_bound=1):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=10, b=5864, lower_bound=1):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_8", - "sat": "def sat(n: int, a=775542538, b=541328691524, lower_bound=221396926):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=775542538, b=541328691524, lower_bound=221396926):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=775542538, b=541328691524, lower_bound=221396926):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_9", - "sat": "def sat(n: int, a=828442282, b=51728048756230352, lower_bound=274459911):\n \"\"\"Find a large common divisor of two integers.\"\"\"\n return a % n == 0 and b % n == 0 and n >= lower_bound", - "sols": [ - "def sol(a=828442282, b=51728048756230352, lower_bound=274459911):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", - "def sol(a=828442282, b=51728048756230352, lower_bound=274459911):\n def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_0", - "sat": "def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[77410, 23223, 54187], lower_bound=2):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_1", - "sat": "def sat(n: int, nums=[14, 551755893, 902110495], lower_bound=1):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[14, 551755893, 902110495], lower_bound=1):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_2", - "sat": "def sat(n: int, nums=[287260676668, 33263981357337, 47314720, 295717, 2957170], lower_bound=98647):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[287260676668, 33263981357337, 47314720, 295717, 2957170], lower_bound=98647):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_3", - "sat": "def sat(n: int, nums=[452452, 111673658096, 83221402264, 5027670648, 61177116, 154154, 116116, 1508784124848, 17036343324, 29091062, 100726626], lower_bound=977):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[452452, 111673658096, 83221402264, 5027670648, 61177116, 154154, 116116, 1508784124848, 17036343324, 29091062, 100726626], lower_bound=977):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_4", - "sat": "def sat(n: int, nums=[8154539588421190, 128861795], lower_bound=64216730):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[8154539588421190, 128861795], lower_bound=64216730):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_5", - "sat": "def sat(n: int, nums=[22536, 7171497003, 3232038, 4695, 399494733, 57279, 939, 939], lower_bound=2):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[22536, 7171497003, 3232038, 4695, 399494733, 57279, 939, 939], lower_bound=2):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_6", - "sat": "def sat(n: int, nums=[8035236835035976, 8864663, 8864663, 5595449367588691, 17729326, 33041861196984, 5162185798779, 2076157262578, 57935031630489, 87999607112293], lower_bound=6511259):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[8035236835035976, 8864663, 8864663, 5595449367588691, 17729326, 33041861196984, 5162185798779, 2076157262578, 57935031630489, 87999607112293], lower_bound=6511259):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_7", - "sat": "def sat(n: int, nums=[1348424, 3040049384], lower_bound=2):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[1348424, 3040049384], lower_bound=2):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_8", - "sat": "def sat(n: int, nums=[23246503230, 63990, 2275860, 1350, 2400, 8210430, 240, 18828914640], lower_bound=10):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[23246503230, 63990, 2275860, 1350, 2400, 8210430, 240, 18828914640], lower_bound=10):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD_multi_9", - "sat": "def sat(n: int, nums=[688744389320358, 2256831], lower_bound=259749):\n \"\"\"Find a large common divisor of the list of integers.\"\"\"\n return all(i % n == 0 for i in nums) and n >= lower_bound", - "sols": [ - "def sol(nums=[688744389320358, 2256831], lower_bound=259749):\n n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" - ], - "module": "number_theory", - "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_0", - "sat": "def sat(n: int, a=15, b=27, upper_bound=150):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=15, b=27, upper_bound=150):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_1", - "sat": "def sat(n: int, a=41234205765, b=597597185, upper_bound=73349253728):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=41234205765, b=597597185, upper_bound=73349253728):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_2", - "sat": "def sat(n: int, a=7601351956456, b=2974663988, upper_bound=389421039754872576):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=7601351956456, b=2974663988, upper_bound=389421039754872576):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_3", - "sat": "def sat(n: int, a=201717041833890, b=3585167190, upper_bound=731493653565433):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=201717041833890, b=3585167190, upper_bound=731493653565433):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_4", - "sat": "def sat(n: int, a=79680, b=661339968, upper_bound=410128528659):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=79680, b=661339968, upper_bound=410128528659):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_5", - "sat": "def sat(n: int, a=1184805001069, b=2869829826198, upper_bound=107891010360490480):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=1184805001069, b=2869829826198, upper_bound=107891010360490480):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_6", - "sat": "def sat(n: int, a=503565347412, b=340326, upper_bound=157711238221245):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=503565347412, b=340326, upper_bound=157711238221245):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_7", - "sat": "def sat(n: int, a=554236750, b=565, upper_bound=1066642513):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=554236750, b=565, upper_bound=1066642513):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_8", - "sat": "def sat(n: int, a=26222646, b=35151, upper_bound=51538626):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=26222646, b=35151, upper_bound=51538626):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_9", - "sat": "def sat(n: int, a=10400312341586488, b=19168091586437888, upper_bound=7640345911153373632004096):\n \"\"\"Find a small common multiple of two integers.\"\"\"\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", - "sols": [ - "def sol(a=10400312341586488, b=19168091586437888, upper_bound=7640345911153373632004096):\n m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_0", - "sat": "def sat(n: int, nums=[15, 27, 102], upper_bound=5000):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[15, 27, 102], upper_bound=5000):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_1", - "sat": "def sat(n: int, nums=[46477686772963437, 15649966299, 37939312240, 14036122804591, 39209330717234], upper_bound=82396663973139497934429093888):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[46477686772963437, 15649966299, 37939312240, 14036122804591, 39209330717234], upper_bound=82396663973139497934429093888):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_2", - "sat": "def sat(n: int, nums=[55040126016, 4373970014334], upper_bound=219074883886936):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[55040126016, 4373970014334], upper_bound=219074883886936):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_3", - "sat": "def sat(n: int, nums=[9140, 4882496600, 119119770064, 107772494796, 102424668, 3656, 1188591500932, 116992, 14700627932, 997397016], upper_bound=238661269929569213628364588516267312050595558326272):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[9140, 4882496600, 119119770064, 107772494796, 102424668, 3656, 1188591500932, 116992, 14700627932, 997397016], upper_bound=238661269929569213628364588516267312050595558326272):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_4", - "sat": "def sat(n: int, nums=[173261568, 4270662976], upper_bound=17025943527197098):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[173261568, 4270662976], upper_bound=17025943527197098):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_5", - "sat": "def sat(n: int, nums=[27309997, 11, 48257, 44, 82533], upper_bound=155742084336245):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[27309997, 11, 48257, 44, 82533], upper_bound=155742084336245):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_6", - "sat": "def sat(n: int, nums=[205269770732, 688976, 35462, 4582551620, 182376, 395148, 13081065514, 40528, 5066], upper_bound=242256675588707364896768):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[205269770732, 688976, 35462, 4582551620, 182376, 395148, 13081065514, 40528, 5066], upper_bound=242256675588707364896768):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_7", - "sat": "def sat(n: int, nums=[210, 206010, 2766930, 11341667910, 5893438920, 5565191820, 2717700], upper_bound=10860241092132727743714222101422525120512):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[210, 206010, 2766930, 11341667910, 5893438920, 5565191820, 2717700], upper_bound=10860241092132727743714222101422525120512):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_8", - "sat": "def sat(n: int, nums=[146369986974, 1648572987, 239653, 5284579675492, 6805378070747, 239653, 958612, 1323603519, 1584585636, 12195941170], upper_bound=709969499924908138716035675220917354496):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[146369986974, 1648572987, 239653, 5284579675492, 6805378070747, 239653, 958612, 1323603519, 1584585636, 12195941170], upper_bound=709969499924908138716035675220917354496):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "LCM_multi_9", - "sat": "def sat(n: int, nums=[61053, 2, 49025629, 377, 351058174, 1, 8, 8774, 39521, 7, 248734], upper_bound=242169498367847500568417450458775289856):\n \"\"\"Find a small common multiple of a list of integers.\"\"\"\n return all(n % i == 0 for i in nums) and n <= upper_bound", - "sols": [ - "def sol(nums=[61053, 2, 49025629, 377, 351058174, 1, 8, 8774, 39521, 7, 248734], upper_bound=242169498367847500568417450458775289856):\n ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" - ], - "module": "number_theory", - "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_0", - "sat": "def sat(n: int, b=2, target=5):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=2, target=5):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_1", - "sat": "def sat(n: int, b=2, target=3):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_2", - "sat": "def sat(n: int, b=1, target=2):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_3", - "sat": "def sat(n: int, b=69, target=2):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=69, target=2):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_4", - "sat": "def sat(n: int, b=14, target=3):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=14, target=3):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_5", - "sat": "def sat(n: int, b=34, target=3):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=34, target=3):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_6", - "sat": "def sat(n: int, b=56, target=3):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=56, target=3):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_7", - "sat": "def sat(n: int, b=74, target=3):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=74, target=3):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_8", - "sat": "def sat(n: int, b=17, target=4):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=17, target=4):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "SmallExponentBigSolution_9", - "sat": "def sat(n: int, b=53, target=4):\n \"\"\"Solve for n: b^n = target (mod n)\"\"\"\n return (b ** n) % n == target", - "sols": [ - "def sol(b=53, target=4):\n for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" - ], - "module": "number_theory", - "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_0", - "sat": "def sat(nums: List[int], target=10):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [ - "def sol(target=10):\n assert target % 9 not in {4, 5}\n for i in range(20):\n for j in range(i + 1):\n for k in range(-20, j + 1):\n n = i ** 3 + j ** 3 + k ** 3\n if n == target:\n return [i, j, k]\n if n == -target:\n return [-i, -j, -k]" - ], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_1", - "sat": "def sat(nums: List[int], target=114):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_2", - "sat": "def sat(nums: List[int], target=390):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_3", - "sat": "def sat(nums: List[int], target=579):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_4", - "sat": "def sat(nums: List[int], target=627):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_5", - "sat": "def sat(nums: List[int], target=633):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_6", - "sat": "def sat(nums: List[int], target=732):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_7", - "sat": "def sat(nums: List[int], target=921):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_8", - "sat": "def sat(nums: List[int], target=975):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "ThreeCubes_9", - "sat": "def sat(nums: List[int], target=0):\n \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", - "sols": [ - "def sol(target=0):\n assert target % 9 not in {4, 5}\n for i in range(20):\n for j in range(i + 1):\n for k in range(-20, j + 1):\n n = i ** 3 + j ** 3 + k ** 3\n if n == target:\n return [i, j, k]\n if n == -target:\n return [-i, -j, -k]" - ], - "module": "number_theory", - "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_0", - "sat": "def sat(nums: List[int], n=12345):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=12345):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_1", - "sat": "def sat(nums: List[int], n=1):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=1):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_2", - "sat": "def sat(nums: List[int], n=0):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=0):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_3", - "sat": "def sat(nums: List[int], n=3):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=3):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_4", - "sat": "def sat(nums: List[int], n=8):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=8):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_5", - "sat": "def sat(nums: List[int], n=15):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [ - "def sol(n=15):\n m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" - ], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_6", - "sat": "def sat(nums: List[int], n=1321806837666853665854863414407013350963513):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_7", - "sat": "def sat(nums: List[int], n=254723967601711775999551029856500295000994603):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_8", - "sat": "def sat(nums: List[int], n=44623301085226399):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "FourSquares_9", - "sat": "def sat(nums: List[int], n=63672004182928567881896369531):\n \"\"\"Find four integers whose squares sum to n\"\"\"\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", - "sols": [], - "module": "number_theory", - "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_0", - "sat": "def sat(i: int, n=62710561):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [ - "def sol(n=62710561):\n if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" - ], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_1", - "sat": "def sat(i: int, n=16):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [ - "def sol(n=16):\n if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" - ], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_2", - "sat": "def sat(i: int, n=1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_3", - "sat": "def sat(i: int, n=35794234179725868774991807832568455403003778024228226193532908190484670252364677411513516111204504060317568667):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_4", - "sat": "def sat(i: int, n=227010481295437363334259960947493668895875336466084780038173258247009162675779735389791151574049166747880487470296548479):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_5", - "sat": "def sat(i: int, n=114381625757888867669235779976146612010218296721242362562561842935706935245733897830597123563958705058989075147599290026879543541):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_6", - "sat": "def sat(i: int, n=1807082088687404805951656164405905566278102516769401349170127021450056662540244048387341127590812303371781887966563182013214880557):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_7", - "sat": "def sat(i: int, n=21290246318258757547497882016271517497806703963277216278233383215381949984056495911366573853021918316783107387995317230889569230873441936471):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_8", - "sat": "def sat(i: int, n=155089812478348440509606754370011861770654545830995430655466945774312632703463465954363335027577729025391453996787414027003501631772186840890795964683):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Factoring_9", - "sat": "def sat(i: int, n=10941738641570527421809707322040357612003732945449205990913842131476349984288934784717997257891267332497625752899781833797076537244027146743531593354333897):\n \"\"\"Find a non-trivial factor of integer n\"\"\"\n return 1 < i < n and n % i == 0", - "sols": [], - "module": "number_theory", - "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_0", - "sat": "def sat(n: int, g=3, p=17, t=13):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [ - "def sol(g=3, p=17, t=13):\n for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" - ], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_1", - "sat": "def sat(n: int, g=7, p=204706270385532838059744535166974274803608394340123459695798674591526591372685229510652847339705797622075505069831043486651682279, t=127402180119973946824269244334322849749382042586931621654557735290322914679095998681860978813046595166455458144280588076766033781):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_2", - "sat": "def sat(n: int, g=13, p=21, t=1):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [ - "def sol(g=13, p=21, t=1):\n for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" - ], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_3", - "sat": "def sat(n: int, g=101873924449108026052, p=576036946901458671597, t=330515716425197141833):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_4", - "sat": "def sat(n: int, g=1696881788, p=8006168143, t=7111327686):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_5", - "sat": "def sat(n: int, g=165501052943003462970, p=238555574298978772959, t=135765621915673720437):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_6", - "sat": "def sat(n: int, g=33209740069076319378099, p=95704125926541931977235, t=90713628869078037590764):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_7", - "sat": "def sat(n: int, g=4, p=11, t=4):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [ - "def sol(g=4, p=11, t=4):\n for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" - ], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_8", - "sat": "def sat(n: int, g=34809141888, p=37747830971, t=23954486348):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "DiscreteLog_9", - "sat": "def sat(n: int, g=2699298744052143, p=4692531698178911, t=3657439654587029):\n \"\"\"Find n such that g^n is congruent to t mod n\"\"\"\n return pow(g, n, p) == t", - "sols": [], - "module": "number_theory", - "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "GCD17_0", - "sat": "def sat(n: int):\n \"\"\"Find n for which gcd(n^17+9, (n+1)^17+9) != 1\"\"\"\n i = n ** 17 + 9\n j = (n + 1) ** 17 + 9\n\n while i != 0: # compute gcd using Euclid's algorithm\n (i, j) = (j % i, i)\n\n return n >= 0 and j != 1", - "sols": [], - "module": "number_theory", - "notes": "According to [this article](https://primes.utm.edu/glossary/page.php?sort=LawOfSmall), the smallest\nsolution is 8424432925592889329288197322308900672459420460792433", - "taint_date": "2021-4-26", - "weight": 0.0625 - }, - { - "name": "Znam_0", - "sat": "def sat(li: List[int], k=5):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=5):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_1", - "sat": "def sat(li: List[int], k=6):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=6):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_2", - "sat": "def sat(li: List[int], k=7):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=7):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_3", - "sat": "def sat(li: List[int], k=8):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=8):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_4", - "sat": "def sat(li: List[int], k=9):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=9):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_5", - "sat": "def sat(li: List[int], k=10):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=10):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_6", - "sat": "def sat(li: List[int], k=11):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=11):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_7", - "sat": "def sat(li: List[int], k=12):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=12):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_8", - "sat": "def sat(li: List[int], k=13):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=13):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Znam_9", - "sat": "def sat(li: List[int], k=14):\n \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", - "sols": [ - "def sol(k=14):\n n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" - ], - "module": "number_theory", - "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzCycleUnsolved_0", - "sat": "def sat(n: int):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n > 4 which is part of a cycle of this process\n \"\"\"\n m = n\n while n > 4:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == m:\n return True", - "sols": [], - "module": "number_theory", - "notes": "Collatz Conjecture\n\nA solution to this problem would disprove the *Collatz Conjecture*, also called the *3n + 1 problem*,\nas well as the *Generalized Collatz Conjecture* (see the next problem).\nAccording to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture):\n> Paul Erdos said about the Collatz conjecture: \"Mathematics may not be ready for such problems.\"\n> He also offered US$500 for its solution. Jeffrey Lagarias stated in 2010 that the Collatz conjecture\n> \"is an extraordinarily difficult problem, completely out of reach of present day mathematics.\"\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\n\nThe conjecture is to that all `n > 0` eventually reach `n=1`. If this conjecture is false, then\nthere is either a cycle or a sequence that increases without bound. This problem seeks a cycle.", - "taint_date": "2021-4-26", - "weight": 0.0625 - }, - { - "name": "CollatzGeneralizedUnsolved_0", - "sat": "def sat(start: int):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n which is part of a cycle of this process that has |n| > 1000\n \"\"\"\n n = start # could be positive or negative ...\n while abs(n) > 1000:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == start:\n return True", - "sols": [], - "module": "number_theory", - "notes": "Generalized Collatz Conjecture\n\nThis version, permits negative n and seek a cycle with a number of magnitude greater than 1000,\nwhich would disprove the Generalized conjecture that states that the only cycles are the known 5 cycles\n(which don't have positive integers).\n\nSee the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)", - "taint_date": "2021-4-26", - "weight": 0.0625 - }, - { - "name": "CollatzDelay_0", - "sat": "def sat(n: int, t=100, upper=10):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [ - "def sol(t=100, upper=10): # Faster solution for simultaneously solving multiple problems is of course possible\n bound = t + 10\n while True:\n bound *= 2\n prev = {1}\n seen = set()\n for delay in range(t):\n seen.update(prev)\n curr = {2 * n for n in prev}\n curr.update({(n - 1) // 3 for n in prev if n % 6 == 4})\n prev = {n for n in curr if n <= bound} - seen\n if prev:\n return min(prev)" - ], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_1", - "sat": "def sat(n: int, t=1000, upper=150):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_2", - "sat": "def sat(n: int, t=2000, upper=206):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_3", - "sat": "def sat(n: int, t=2283, upper=238):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_4", - "sat": "def sat(n: int, t=2337, upper=230):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_5", - "sat": "def sat(n: int, t=2350, upper=193):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_6", - "sat": "def sat(n: int, t=2500, upper=207):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_7", - "sat": "def sat(n: int, t=3000, upper=278):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_8", - "sat": "def sat(n: int, t=4000, upper=351):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "CollatzDelay_9", - "sat": "def sat(n: int, t=0, upper=75):\n \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", - "sols": [ - "def sol(t=0, upper=75): # Faster solution for simultaneously solving multiple problems is of course possible\n bound = t + 10\n while True:\n bound *= 2\n prev = {1}\n seen = set()\n for delay in range(t):\n seen.update(prev)\n curr = {2 * n for n in prev}\n curr.update({(n - 1) // 3 for n in prev if n % 6 == 4})\n prev = {n for n in curr if n <= bound} - seen\n if prev:\n return min(prev)" - ], - "module": "number_theory", - "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", - "taint_date": "2021-4-26", - "weight": 0.00625 - }, - { - "name": "Lehmer_0", - "sat": "def sat(n: int):\n \"\"\"Find n such that 2^n mod n = 3\"\"\"\n return pow(2, n, n) == 3", - "sols": [ - "def sol():\n return 4700063497" - ], - "module": "number_theory", - "notes": "Lehmer puzzle\n\nAccording to [The Strong Law of Large Numbers](https://doi.org/10.2307/2322249) Richard K. Guy states that\n D. H. & Emma Lehmer discovered that 2^n = 3 (mod n) for n = 4700063497,\n but for no smaller n > 1", - "taint_date": "2021-4-26", - "weight": 0.0625 - }, - { - "name": "BirthdayParadox_0", - "sat": "def sat(n: int, year_len=365):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=365):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_1", - "sat": "def sat(n: int, year_len=60182):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=60182):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_2", - "sat": "def sat(n: int, year_len=2):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=2):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_3", - "sat": "def sat(n: int, year_len=3):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=3):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_4", - "sat": "def sat(n: int, year_len=4):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=4):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_5", - "sat": "def sat(n: int, year_len=5):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=5):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_6", - "sat": "def sat(n: int, year_len=6):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=6):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_7", - "sat": "def sat(n: int, year_len=7):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=7):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_8", - "sat": "def sat(n: int, year_len=8):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=8):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadox_9", - "sat": "def sat(n: int, year_len=9):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", - "sols": [ - "def sol(year_len=9):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_0", - "sat": "def sat(n: int, year_len=365):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=365):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_1", - "sat": "def sat(n: int, year_len=60182):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=60182):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_2", - "sat": "def sat(n: int, year_len=2):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=2):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_3", - "sat": "def sat(n: int, year_len=3):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=3):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_4", - "sat": "def sat(n: int, year_len=4):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=4):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_5", - "sat": "def sat(n: int, year_len=5):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=5):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_6", - "sat": "def sat(n: int, year_len=6):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=6):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_7", - "sat": "def sat(n: int, year_len=7):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=7):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_8", - "sat": "def sat(n: int, year_len=8):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=8):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BirthdayParadoxMonteCarlo_9", - "sat": "def sat(n: int, year_len=9):\n \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", - "sols": [ - "def sol(year_len=9):\n n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" - ], - "module": "probability", - "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_0", - "sat": "def sat(counts: List[int], target_prob=0.5):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.5):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_1", - "sat": "def sat(counts: List[int], target_prob=0.1791044776119403):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.1791044776119403):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_2", - "sat": "def sat(counts: List[int], target_prob=0.03125):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.03125):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_3", - "sat": "def sat(counts: List[int], target_prob=0.5803571428571429):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.5803571428571429):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_4", - "sat": "def sat(counts: List[int], target_prob=0.7142857142857143):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.7142857142857143):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_5", - "sat": "def sat(counts: List[int], target_prob=0.7029702970297029):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.7029702970297029):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_6", - "sat": "def sat(counts: List[int], target_prob=0.09803921568627451):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.09803921568627451):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_7", - "sat": "def sat(counts: List[int], target_prob=0.3333333333333333):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.3333333333333333):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_8", - "sat": "def sat(counts: List[int], target_prob=0.2621035058430718):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.2621035058430718):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BallotProblem_9", - "sat": "def sat(counts: List[int], target_prob=0.5087719298245614):\n \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", - "sols": [ - "def sol(target_prob=0.5087719298245614):\n for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" - ], - "module": "probability", - "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_0", - "sat": "def sat(counts: List[int], p=0.5, target_prob=0.0625):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.5, target_prob=0.0625):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_1", - "sat": "def sat(counts: List[int], p=0.7588822808660473, target_prob=0.41658075878732215):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.7588822808660473, target_prob=0.41658075878732215):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_2", - "sat": "def sat(counts: List[int], p=0.6569421516251613, target_prob=0.01872902529162693):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.6569421516251613, target_prob=0.01872902529162693):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_3", - "sat": "def sat(counts: List[int], p=0.20001220211746595, target_prob=0.13419930454361995):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.20001220211746595, target_prob=0.13419930454361995):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_4", - "sat": "def sat(counts: List[int], p=0.004837079863490135, target_prob=3.5517791266002235e-13):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.004837079863490135, target_prob=3.5517791266002235e-13):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_5", - "sat": "def sat(counts: List[int], p=0.22301203117936397, target_prob=0.3465553302572367):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.22301203117936397, target_prob=0.3465553302572367):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_6", - "sat": "def sat(counts: List[int], p=0.09186637938262365, target_prob=0.03652982678582358):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.09186637938262365, target_prob=0.03652982678582358):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_7", - "sat": "def sat(counts: List[int], p=0.8084771136120399, target_prob=9.452457811838075e-06):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.8084771136120399, target_prob=9.452457811838075e-06):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_8", - "sat": "def sat(counts: List[int], p=0.8562952242373717, target_prob=0.31611092077661906):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.8562952242373717, target_prob=0.31611092077661906):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "BinomialProbabilities_9", - "sat": "def sat(counts: List[int], p=0.02862444202975356, target_prob=0.02922698016772227):\n \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", - "sols": [ - "def sol(p=0.02862444202975356, target_prob=0.02922698016772227):\n probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" - ], - "module": "probability", - "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_0", - "sat": "def sat(p_stop: float, steps=10, target_prob=0.5):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=10, target_prob=0.5):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_1", - "sat": "def sat(p_stop: float, steps=43, target_prob=0.2661542669448821):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=43, target_prob=0.2661542669448821):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_2", - "sat": "def sat(p_stop: float, steps=91, target_prob=0.03729141037377781):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=91, target_prob=0.03729141037377781):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_3", - "sat": "def sat(p_stop: float, steps=11, target_prob=0.9742781783529525):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=11, target_prob=0.9742781783529525):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_4", - "sat": "def sat(p_stop: float, steps=65, target_prob=0.8318555442956944):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=65, target_prob=0.8318555442956944):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_5", - "sat": "def sat(p_stop: float, steps=43, target_prob=0.27905046827813074):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=43, target_prob=0.27905046827813074):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_6", - "sat": "def sat(p_stop: float, steps=97, target_prob=0.726143506161244):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=97, target_prob=0.726143506161244):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_7", - "sat": "def sat(p_stop: float, steps=96, target_prob=0.3812708251016994):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=96, target_prob=0.3812708251016994):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_8", - "sat": "def sat(p_stop: float, steps=35, target_prob=0.6293361569545994):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=35, target_prob=0.6293361569545994):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "ExponentialProbability_9", - "sat": "def sat(p_stop: float, steps=22, target_prob=0.2118509983414142):\n \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", - "sols": [ - "def sol(steps=22, target_prob=0.2118509983414142):\n return 1 - (1 - target_prob) ** (1.0/steps)" - ], - "module": "probability", - "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", - "taint_date": "2021-4-26", - "weight": 0.02 - }, - { - "name": "HelloWorld_0", - "sat": "def sat(s: str):\n \"\"\"Find a string that when concatenated onto 'world' gives 'Hello world'.\"\"\"\n return s + 'world' == 'Hello world'", - "sols": [], - "module": "trivial_inverse", - "notes": "Trivial example, no solutions provided", - "taint_date": "2021-4-26", - "weight": 0.02564102564102564 - }, - { - "name": "BackWorlds_0", - "sat": "def sat(s: str):\n \"\"\"Find a string that when reversed and concatenated onto 'world' gives 'Hello world'.\"\"\"\n return s[::-1] + 'world' == 'Hello world'", - "sols": [ - "def sol():\n return ' olleH'", - "def sol(): # solution methods must begin with 'sol'\n return 'Hello '[::-1]" - ], - "module": "trivial_inverse", - "notes": "We provide two solutions", - "taint_date": "2021-4-26", - "weight": 0.02564102564102564 - }, - { - "name": "StrAdd_0", - "sat": "def sat(st: str, a=\"world\", b=\"Hello world\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"world\", b=\"Hello world\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_1", - "sat": "def sat(st: str, a=\"zine\", b=\"cerofilimybazine\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"zine\", b=\"cerofilimybazine\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_2", - "sat": "def sat(st: str, a=\"id\", b=\"xakid\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"id\", b=\"xakid\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_3", - "sat": "def sat(st: str, a=\"dyr\", b=\"dyr\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"dyr\", b=\"dyr\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_4", - "sat": "def sat(st: str, a=\"s\", b=\"tos\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"s\", b=\"tos\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_5", - "sat": "def sat(st: str, a=\"e\", b=\"le\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"e\", b=\"le\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_6", - "sat": "def sat(st: str, a=\"\", b=\"n\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"\", b=\"n\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_7", - "sat": "def sat(st: str, a=\"\", b=\"di\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"\", b=\"di\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_8", - "sat": "def sat(st: str, a=\"ax\", b=\"quobavuthanuhax\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"ax\", b=\"quobavuthanuhax\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrAdd_9", - "sat": "def sat(st: str, a=\"h\", b=\"xylath\"):\n \"\"\"Solve simple string addition problem.\"\"\"\n return st + a == b", - "sols": [ - "def sol(a=\"h\", b=\"xylath\"):\n return b[:len(b) - len(a)]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_0", - "sat": "def sat(s: str, dups=2021):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=2021):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_1", - "sat": "def sat(s: str, dups=0):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=0):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_2", - "sat": "def sat(s: str, dups=1):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=1):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_3", - "sat": "def sat(s: str, dups=2):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=2):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_4", - "sat": "def sat(s: str, dups=3):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=3):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_5", - "sat": "def sat(s: str, dups=4):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=4):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_6", - "sat": "def sat(s: str, dups=5):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=5):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_7", - "sat": "def sat(s: str, dups=6):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=6):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_8", - "sat": "def sat(s: str, dups=7):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=7):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrSetLen_9", - "sat": "def sat(s: str, dups=8):\n \"\"\"Find a string with dups duplicate chars\"\"\"\n return len(set(s)) == len(s) - dups", - "sols": [ - "def sol(dups=8):\n return \"a\" * (dups + 1)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_0", - "sat": "def sat(s: str, target=\"foofoofoofoo\", n=2):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"foofoofoofoo\", n=2):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_1", - "sat": "def sat(s: str, target=\"biquacagegichisykbiquacagegichisykbiquacagegichisyk\", n=3):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"biquacagegichisykbiquacagegichisykbiquacagegichisyk\", n=3):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_2", - "sat": "def sat(s: str, target=\"hutextogoxanithiru\", n=1):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"hutextogoxanithiru\", n=1):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_3", - "sat": "def sat(s: str, target=\"sisisisisisisisisisisisisisi\", n=7):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"sisisisisisisisisisisisisisi\", n=7):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_4", - "sat": "def sat(s: str, target=\"fuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxe\", n=7):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"fuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxe\", n=7):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_5", - "sat": "def sat(s: str, target=\"jusocifagasirevyhajusocifagasirevyhajusocifagasirevyhajusocifagasirevyha\", n=2):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"jusocifagasirevyhajusocifagasirevyhajusocifagasirevyhajusocifagasirevyha\", n=2):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_6", - "sat": "def sat(s: str, target=\"wwwwwwww\", n=8):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"wwwwwwww\", n=8):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_7", - "sat": "def sat(s: str, target=\"butochikifuzozbutochikifuzozbutochikifuzoz\", n=1):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"butochikifuzozbutochikifuzozbutochikifuzoz\", n=1):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_8", - "sat": "def sat(s: str, target=\"pechakegopyzepechakegopyzepechakegopyze\", n=3):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"pechakegopyzepechakegopyzepechakegopyze\", n=3):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul_9", - "sat": "def sat(s: str, target=\"quyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyv\", n=7):\n \"\"\"Find a string which when repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"quyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyvquyv\", n=7):\n if n == 0:\n return ''\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_0", - "sat": "def sat(n: int, target=\"foofoofoofoo\", s=\"foofoo\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"foofoofoofoo\", s=\"foofoo\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_1", - "sat": "def sat(n: int, target=\"\", s=\"jan\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"\", s=\"jan\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_2", - "sat": "def sat(n: int, target=\"koquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyc\", s=\"koquuwibehyc\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"koquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyc\", s=\"koquuwibehyc\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_3", - "sat": "def sat(n: int, target=\"kasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyz\", s=\"kasujyzkasujyz\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"kasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyz\", s=\"kasujyzkasujyz\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_4", - "sat": "def sat(n: int, target=\"kedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuth\", s=\"kedezygijithequuthkedezygijithequuth\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"kedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuth\", s=\"kedezygijithequuthkedezygijithequuth\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_5", - "sat": "def sat(n: int, target=\"puzitepuzite\", s=\"puzitepuzite\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"puzitepuzite\", s=\"puzitepuzite\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_6", - "sat": "def sat(n: int, target=\"vachabimoxezvachabimoxezvachabimoxezvachabimoxez\", s=\"vachabimoxez\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"vachabimoxezvachabimoxezvachabimoxezvachabimoxez\", s=\"vachabimoxez\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_7", - "sat": "def sat(n: int, target=\"mumu\", s=\"mu\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"mumu\", s=\"mu\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_8", - "sat": "def sat(n: int, target=\"huwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehe\", s=\"huwysypedetextehehuwysypedetextehehuwysypedetextehe\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"huwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehehuwysypedetextehe\", s=\"huwysypedetextehehuwysypedetextehehuwysypedetextehe\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrMul2_9", - "sat": "def sat(n: int, target=\"thyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizuja\", s=\"thyputotufizuja\"):\n \"\"\"Find n such that s repeated n times gives target\"\"\"\n return s * n == target", - "sols": [ - "def sol(target=\"thyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizujathyputotufizuja\", s=\"thyputotufizuja\"):\n if len(s) == 0:\n return 1\n return len(target) // len(s)" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 - }, - { - "name": "StrLen_0", - "sat": "def sat(s: str, n=1000):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=1000):\n return 'a' * n" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 }, { - "name": "StrLen_1", - "sat": "def sat(s: str, n=39):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=39):\n return 'a' * n" + "name": "Zarankiewicz:0", + "sat": "def sat(edges: List[List[int]], z=20, n=5, t=3):\n from itertools import combinations\n edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency\n assert len(edges) >= z\n\n return all(\n any((a, b) not in edges for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)\n )", + "ans_type": "List[List[int]]", + "sol_header": "def sol(z=20, n=5, t=3):", + "sol_docstring": " \"\"\"Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n all_edges = [(a, b) for a in range(n) for b in range(n)]\n for edges in combinations(all_edges, z):\n edge_set = set(edges)\n if all(any((a, b) not in edge_set for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)):\n return [[a, b] for a, b in edges]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)", + "weight": 1.0 }, { - "name": "StrLen_2", - "sat": "def sat(s: str, n=790):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=790):\n return 'a' * n" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "Zarankiewicz:1", + "sat": "def sat(edges: List[List[int]], z=26, n=6, t=3):\n from itertools import combinations\n edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency\n assert len(edges) >= z\n\n return all(\n any((a, b) not in edges for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)\n )", + "ans_type": "List[List[int]]", + "sol_header": "def sol(z=26, n=6, t=3):", + "sol_docstring": " \"\"\"Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.\"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)", + "weight": 1.0 }, { - "name": "StrLen_3", - "sat": "def sat(s: str, n=485):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=485):\n return 'a' * n" + "name": "Zarankiewicz:2", + "sat": "def sat(edges: List[List[int]], z=13, n=4, t=3):\n from itertools import combinations\n edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency\n assert len(edges) >= z\n\n return all(\n any((a, b) not in edges for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)\n )", + "ans_type": "List[List[int]]", + "sol_header": "def sol(z=13, n=4, t=3):", + "sol_docstring": " \"\"\"Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n all_edges = [(a, b) for a in range(n) for b in range(n)]\n for edges in combinations(all_edges, z):\n edge_set = set(edges)\n if all(any((a, b) not in edge_set for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)):\n return [[a, b] for a, b in edges]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)", + "weight": 1.0 }, { - "name": "StrLen_4", - "sat": "def sat(s: str, n=4031):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=4031):\n return 'a' * n" + "name": "GraphIsomorphism:0", + "sat": "def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [ + " # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 }, { - "name": "StrLen_5", - "sat": "def sat(s: str, n=28):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=28):\n return 'a' * n" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "GraphIsomorphism:1", + "sat": "def sat(bi: List[int], g1=[[0, 6], [0, 8], [0, 10], [0, 11], [1, 3], [1, 5], [1, 7], [1, 10], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [3, 5], [3, 7], [3, 10], [4, 4], [5, 1], [5, 2], [5, 7], [5, 8], [5, 10], [6, 1], [6, 2], [6, 3], [6, 4], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 0], [7, 2], [7, 9], [8, 4], [8, 6], [8, 9], [8, 10], [9, 1], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 9], [9, 10], [9, 11], [10, 1], [10, 3], [10, 6], [10, 8], [11, 1], [11, 2], [11, 4], [11, 8], [11, 9], [11, 11]], g2=[[0, 11], [9, 2], [10, 10], [6, 11], [7, 5], [5, 0], [9, 3], [8, 2], [10, 8], [2, 11], [4, 8], [0, 7], [2, 10], [11, 11], [4, 5], [10, 11], [6, 10], [9, 7], [6, 6], [8, 10], [1, 5], [2, 9], [10, 3], [0, 2], [9, 8], [5, 4], [0, 5], [6, 2], [8, 1], [1, 6], [6, 3], [0, 10], [0, 8], [10, 5], [2, 7], [0, 6], [0, 0], [10, 0], [3, 8], [5, 3], [5, 7], [10, 6], [6, 7], [7, 0], [3, 9], [3, 4], [0, 3], [0, 4], [1, 7], [4, 9], [7, 10], [9, 5], [7, 11], [3, 5], [10, 4], [10, 9], [2, 8], [1, 0]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 6], [0, 8], [0, 10], [0, 11], [1, 3], [1, 5], [1, 7], [1, 10], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [3, 5], [3, 7], [3, 10], [4, 4], [5, 1], [5, 2], [5, 7], [5, 8], [5, 10], [6, 1], [6, 2], [6, 3], [6, 4], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 0], [7, 2], [7, 9], [8, 4], [8, 6], [8, 9], [8, 10], [9, 1], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 9], [9, 10], [9, 11], [10, 1], [10, 3], [10, 6], [10, 8], [11, 1], [11, 2], [11, 4], [11, 8], [11, 9], [11, 11]], g2=[[0, 11], [9, 2], [10, 10], [6, 11], [7, 5], [5, 0], [9, 3], [8, 2], [10, 8], [2, 11], [4, 8], [0, 7], [2, 10], [11, 11], [4, 5], [10, 11], [6, 10], [9, 7], [6, 6], [8, 10], [1, 5], [2, 9], [10, 3], [0, 2], [9, 8], [5, 4], [0, 5], [6, 2], [8, 1], [1, 6], [6, 3], [0, 10], [0, 8], [10, 5], [2, 7], [0, 6], [0, 0], [10, 0], [3, 8], [5, 3], [5, 7], [10, 6], [6, 7], [7, 0], [3, 9], [3, 4], [0, 3], [0, 4], [1, 7], [4, 9], [7, 10], [9, 5], [7, 11], [3, 5], [10, 4], [10, 9], [2, 8], [1, 0]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 }, { - "name": "StrLen_6", - "sat": "def sat(s: str, n=56):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=56):\n return 'a' * n" + "name": "GraphIsomorphism:2", + "sat": "def sat(bi: List[int], g1=[[0, 1], [0, 7], [1, 1], [2, 0], [2, 3], [2, 5], [2, 6], [3, 0], [3, 1], [3, 2], [3, 5], [3, 6], [3, 7], [4, 3], [4, 5], [4, 6], [5, 0], [5, 2], [5, 3], [6, 0], [6, 5], [6, 7], [7, 0], [7, 4], [7, 6]], g2=[[0, 7], [7, 1], [0, 2], [3, 1], [2, 0], [7, 0], [0, 6], [4, 7], [2, 7], [7, 6], [1, 6], [3, 6], [6, 5], [1, 3], [7, 3], [4, 0], [1, 0], [3, 4], [2, 1], [2, 6], [7, 2], [6, 3], [7, 5], [4, 1], [5, 5]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 1], [0, 7], [1, 1], [2, 0], [2, 3], [2, 5], [2, 6], [3, 0], [3, 1], [3, 2], [3, 5], [3, 6], [3, 7], [4, 3], [4, 5], [4, 6], [5, 0], [5, 2], [5, 3], [6, 0], [6, 5], [6, 7], [7, 0], [7, 4], [7, 6]], g2=[[0, 7], [7, 1], [0, 2], [3, 1], [2, 0], [7, 0], [0, 6], [4, 7], [2, 7], [7, 6], [1, 6], [3, 6], [6, 5], [1, 3], [7, 3], [4, 0], [1, 0], [3, 4], [2, 1], [2, 6], [7, 2], [6, 3], [7, 5], [4, 1], [5, 5]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [ + " # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 }, { - "name": "StrLen_7", - "sat": "def sat(s: str, n=77):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=77):\n return 'a' * n" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "GraphIsomorphism:3", + "sat": "def sat(bi: List[int], g1=[[0, 0], [0, 5], [0, 6], [0, 9], [1, 1], [1, 2], [1, 3], [1, 5], [1, 7], [1, 8], [2, 1], [2, 4], [2, 8], [2, 9], [3, 0], [3, 4], [3, 7], [3, 9], [4, 2], [4, 3], [4, 5], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 0], [6, 4], [6, 7], [7, 5], [7, 6], [7, 8], [8, 1], [8, 7], [9, 1], [9, 4], [9, 8], [9, 9]], g2=[[1, 0], [2, 5], [0, 1], [5, 0], [6, 2], [8, 8], [0, 2], [9, 3], [3, 7], [5, 8], [1, 8], [8, 3], [5, 3], [0, 9], [6, 7], [1, 5], [8, 2], [7, 4], [6, 3], [9, 0], [4, 1], [1, 1], [7, 3], [7, 5], [2, 4], [5, 9], [3, 9], [7, 7], [7, 9], [4, 9], [4, 8], [8, 7], [7, 6], [9, 5], [6, 8], [2, 8], [4, 2], [2, 6]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 0], [0, 5], [0, 6], [0, 9], [1, 1], [1, 2], [1, 3], [1, 5], [1, 7], [1, 8], [2, 1], [2, 4], [2, 8], [2, 9], [3, 0], [3, 4], [3, 7], [3, 9], [4, 2], [4, 3], [4, 5], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 0], [6, 4], [6, 7], [7, 5], [7, 6], [7, 8], [8, 1], [8, 7], [9, 1], [9, 4], [9, 8], [9, 9]], g2=[[1, 0], [2, 5], [0, 1], [5, 0], [6, 2], [8, 8], [0, 2], [9, 3], [3, 7], [5, 8], [1, 8], [8, 3], [5, 3], [0, 9], [6, 7], [1, 5], [8, 2], [7, 4], [6, 3], [9, 0], [4, 1], [1, 1], [7, 3], [7, 5], [2, 4], [5, 9], [3, 9], [7, 7], [7, 9], [4, 9], [4, 8], [8, 7], [7, 6], [9, 5], [6, 8], [2, 8], [4, 2], [2, 6]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 }, { - "name": "StrLen_8", - "sat": "def sat(s: str, n=31):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=31):\n return 'a' * n" + "name": "GraphIsomorphism:4", + "sat": "def sat(bi: List[int], g1=[[1, 0], [1, 1], [1, 2], [2, 1]], g2=[[0, 2], [2, 2], [2, 0], [2, 1]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[1, 0], [1, 1], [1, 2], [2, 1]], g2=[[0, 2], [2, 2], [2, 0], [2, 1]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [ + " # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 }, { - "name": "StrLen_9", - "sat": "def sat(s: str, n=4016):\n \"\"\"Find a string of length n\"\"\"\n return len(s) == n", - "sols": [ - "def sol(n=4016):\n return 'a' * n" + "name": "ShortIntegerPath:0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) and len(li) == 9", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of nine integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"", + "sol_bodies": [ + " return [1, 3, 4, 12, 13, 14, 42, 126, 127]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "graphs.py", + "notes": "This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph\ndefined by the integer pairs.", + "weight": 1.0 }, { - "name": "StrAt_0", - "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"cat\", target=\"a\"):\n return s.index(target)" + "name": "BiPermutations:0", + "sat": "def sat(perms: List[List[int]], prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 }, { - "name": "StrAt_1", - "sat": "def sat(i: int, s=\"quadyquady\", target=\"a\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"quadyquady\", target=\"a\"):\n return s.index(target)" + "name": "BiPermutations:1", + "sat": "def sat(perms: List[List[int]], prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[12, 5, 8, 13, 7], heights1=[2, 10, 4, 5, 9]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[0, 0, 0, 0, 0], heights0=[12, 5, 8, 13, 7], prices1=[0, 0, 0, 0, 0], heights1=[2, 10, 4, 5, 9]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 }, { - "name": "StrAt_2", - "sat": "def sat(i: int, s=\"quixatextofazejate\", target=\"i\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"quixatextofazejate\", target=\"i\"):\n return s.index(target)" + "name": "BiPermutations:2", + "sat": "def sat(perms: List[List[int]], prices0=[0, 0, 0, 0, 0], prices1=[0, 0, 0, 0, 0], heights0=[9, 10, 12, 14, 14], heights1=[6, 5, 7, 10, 10]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[0, 0, 0, 0, 0], heights0=[9, 10, 12, 14, 14], prices1=[0, 0, 0, 0, 0], heights1=[6, 5, 7, 10, 10]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 }, { - "name": "StrAt_3", - "sat": "def sat(i: int, s=\"thethe\", target=\"e\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"thethe\", target=\"e\"):\n return s.index(target)" + "name": "BiPermutations:3", + "sat": "def sat(perms: List[List[int]], prices0=[2, 5, 4, 2, 7, 3, 4, 5, 2, 3, 2, 1, 2, 7, 6, 1, 5, 2, 4, 6, 3, 7, 1, 2, 3, 5, 2, 2, 2, 2, 6, 5, 0, 2, 2, 0, 7, 3, 6, 4, 7, 0, 1, 5, 6, 1, 7, 6, 5, 4, 7, 7, 2, 5, 4, 5, 1, 4, 3, 3, 0, 2, 4, 0, 3, 0, 6, 4, 2, 6, 7, 5, 0, 5, 6, 2], prices1=[4, 5, 2, 5, 7, 0, 6, 6, 4, 5, 5, 6, 6, 2, 5, 4, 6, 0, 3, 3, 4, 5, 7, 7, 3, 3, 2, 5, 1, 7, 5, 6, 6, 3, 1, 4, 5, 0, 6, 7, 3, 7, 1, 5, 7, 4, 1, 0, 3, 6, 0, 1, 3, 3, 3, 5, 0, 4, 7, 3, 3, 2, 2, 3, 7, 7, 1, 1, 2, 2, 2, 5, 4, 7, 3, 0], heights0=[5, 4, 8, 9, 9, 11, 13, 6, 6, 6, 9, 13, 15, 8, 7, 14, 6, 5, 12, 7, 14, 9, 6, 13, 3, 10, 11, 8, 4, 14, 10, 10, 4, 8, 3, 7, 11, 8, 5, 5, 10, 11, 9, 9, 7, 11, 3, 13, 15, 5, 3, 7, 8, 10, 8, 13, 12, 3, 4, 13, 7, 7, 5, 5, 6, 10, 8, 11, 7, 5, 10, 15, 4, 15, 6, 8], heights1=[5, 9, 4, 4, 8, 7, 10, 1, 2, 5, 5, 3, 4, 1, 10, 1, 5, 3, 3, 5, 4, 8, 3, 9, 10, 5, 6, 9, 10, 2, 10, 4, 6, 10, 4, 3, 2, 4, 9, 2, 7, 8, 7, 7, 9, 10, 9, 1, 7, 6, 2, 4, 2, 10, 6, 6, 10, 2, 5, 3, 10, 5, 10, 4, 6, 2, 8, 5, 3, 10, 1, 8, 6, 2, 2, 2]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[2, 5, 4, 2, 7, 3, 4, 5, 2, 3, 2, 1, 2, 7, 6, 1, 5, 2, 4, 6, 3, 7, 1, 2, 3, 5, 2, 2, 2, 2, 6, 5, 0, 2, 2, 0, 7, 3, 6, 4, 7, 0, 1, 5, 6, 1, 7, 6, 5, 4, 7, 7, 2, 5, 4, 5, 1, 4, 3, 3, 0, 2, 4, 0, 3, 0, 6, 4, 2, 6, 7, 5, 0, 5, 6, 2], heights0=[5, 4, 8, 9, 9, 11, 13, 6, 6, 6, 9, 13, 15, 8, 7, 14, 6, 5, 12, 7, 14, 9, 6, 13, 3, 10, 11, 8, 4, 14, 10, 10, 4, 8, 3, 7, 11, 8, 5, 5, 10, 11, 9, 9, 7, 11, 3, 13, 15, 5, 3, 7, 8, 10, 8, 13, 12, 3, 4, 13, 7, 7, 5, 5, 6, 10, 8, 11, 7, 5, 10, 15, 4, 15, 6, 8], prices1=[4, 5, 2, 5, 7, 0, 6, 6, 4, 5, 5, 6, 6, 2, 5, 4, 6, 0, 3, 3, 4, 5, 7, 7, 3, 3, 2, 5, 1, 7, 5, 6, 6, 3, 1, 4, 5, 0, 6, 7, 3, 7, 1, 5, 7, 4, 1, 0, 3, 6, 0, 1, 3, 3, 3, 5, 0, 4, 7, 3, 3, 2, 2, 3, 7, 7, 1, 1, 2, 2, 2, 5, 4, 7, 3, 0], heights1=[5, 9, 4, 4, 8, 7, 10, 1, 2, 5, 5, 3, 4, 1, 10, 1, 5, 3, 3, 5, 4, 8, 3, 9, 10, 5, 6, 9, 10, 2, 10, 4, 6, 10, 4, 3, 2, 4, 9, 2, 7, 8, 7, 7, 9, 10, 9, 1, 7, 6, 2, 4, 2, 10, 6, 6, 10, 2, 5, 3, 10, 5, 10, 4, 6, 2, 8, 5, 3, 10, 1, 8, 6, 2, 2, 2]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 }, { - "name": "StrAt_4", - "sat": "def sat(i: int, s=\"bucudibucudibucudi\", target=\"b\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"bucudibucudibucudi\", target=\"b\"):\n return s.index(target)" + "name": "BiPermutations:4", + "sat": "def sat(perms: List[List[int]], prices0=[3, 6, 4, 0, 5, 6, 4, 3, 1, 7, 0, 4, 7, 5, 6, 1, 3, 3, 7, 4, 2, 5, 1, 7, 6, 7, 6, 3, 0, 2, 1, 7, 4, 3, 2, 7, 1, 3, 7, 6, 7, 0, 2, 0, 1, 1, 1, 3, 1, 1, 0, 0, 5, 2, 4, 6, 1, 5, 2, 5, 1, 5, 5, 3, 1, 7, 7, 1, 3, 6, 0, 6, 0, 0, 3, 6, 1], prices1=[1, 4, 0, 6, 3, 1, 4, 6, 3, 0, 4, 7, 2, 6, 4, 0, 2, 4, 6, 7, 7, 0, 4, 2, 6, 1, 6, 3, 0, 5, 3, 6, 0, 1, 4, 1, 0, 5, 1, 3, 4, 0, 0, 2, 5, 5, 5, 1, 2, 7, 7, 0, 7, 0, 7, 7, 5, 0, 1, 1, 0, 5, 7, 1, 0, 0, 2, 4, 1, 2, 6, 2, 3, 4, 0, 7, 6], heights0=[12, 13, 8, 14, 12, 10, 15, 4, 13, 8, 7, 4, 8, 4, 7, 13, 7, 11, 6, 7, 11, 14, 11, 13, 10, 10, 5, 9, 12, 5, 11, 12, 12, 6, 4, 11, 5, 3, 4, 6, 3, 4, 3, 15, 4, 13, 8, 10, 10, 10, 14, 6, 10, 7, 6, 4, 6, 12, 8, 11, 7, 9, 7, 12, 6, 8, 6, 7, 8, 5, 13, 6, 10, 13, 5, 7, 10], heights1=[5, 8, 9, 3, 4, 7, 2, 7, 10, 10, 10, 3, 3, 8, 3, 9, 4, 5, 8, 9, 1, 4, 2, 2, 5, 3, 4, 4, 2, 6, 8, 2, 6, 9, 9, 6, 10, 7, 2, 7, 1, 10, 8, 6, 2, 10, 6, 8, 4, 3, 3, 9, 5, 9, 3, 7, 5, 10, 3, 1, 8, 10, 5, 6, 3, 8, 1, 7, 3, 1, 10, 4, 8, 1, 2, 5, 2]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[3, 6, 4, 0, 5, 6, 4, 3, 1, 7, 0, 4, 7, 5, 6, 1, 3, 3, 7, 4, 2, 5, 1, 7, 6, 7, 6, 3, 0, 2, 1, 7, 4, 3, 2, 7, 1, 3, 7, 6, 7, 0, 2, 0, 1, 1, 1, 3, 1, 1, 0, 0, 5, 2, 4, 6, 1, 5, 2, 5, 1, 5, 5, 3, 1, 7, 7, 1, 3, 6, 0, 6, 0, 0, 3, 6, 1], heights0=[12, 13, 8, 14, 12, 10, 15, 4, 13, 8, 7, 4, 8, 4, 7, 13, 7, 11, 6, 7, 11, 14, 11, 13, 10, 10, 5, 9, 12, 5, 11, 12, 12, 6, 4, 11, 5, 3, 4, 6, 3, 4, 3, 15, 4, 13, 8, 10, 10, 10, 14, 6, 10, 7, 6, 4, 6, 12, 8, 11, 7, 9, 7, 12, 6, 8, 6, 7, 8, 5, 13, 6, 10, 13, 5, 7, 10], prices1=[1, 4, 0, 6, 3, 1, 4, 6, 3, 0, 4, 7, 2, 6, 4, 0, 2, 4, 6, 7, 7, 0, 4, 2, 6, 1, 6, 3, 0, 5, 3, 6, 0, 1, 4, 1, 0, 5, 1, 3, 4, 0, 0, 2, 5, 5, 5, 1, 2, 7, 7, 0, 7, 0, 7, 7, 5, 0, 1, 1, 0, 5, 7, 1, 0, 0, 2, 4, 1, 2, 6, 2, 3, 4, 0, 7, 6], heights1=[5, 8, 9, 3, 4, 7, 2, 7, 10, 10, 10, 3, 3, 8, 3, 9, 4, 5, 8, 9, 1, 4, 2, 2, 5, 3, 4, 4, 2, 6, 8, 2, 6, 9, 9, 6, 10, 7, 2, 7, 1, 10, 8, 6, 2, 10, 6, 8, 4, 3, 3, 9, 5, 9, 3, 7, 5, 10, 3, 1, 8, 10, 5, 6, 3, 8, 1, 7, 3, 1, 10, 4, 8, 1, 2, 5, 2]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 }, { - "name": "StrAt_5", - "sat": "def sat(i: int, s=\"wavipitanymywavipitanymywavipitanymy\", target=\"a\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"wavipitanymywavipitanymywavipitanymy\", target=\"a\"):\n return s.index(target)" + "name": "OptimalBridges:0", + "sat": "def sat(indices: List[int], H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 }, { - "name": "StrAt_6", - "sat": "def sat(i: int, s=\"jarofujarofujarofu\", target=\"a\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"jarofujarofujarofu\", target=\"a\"):\n return s.index(target)" + "name": "OptimalBridges:1", + "sat": "def sat(indices: List[int], H=100000, alpha=17, beta=6, xs=[0, 3069, 5319, 5373, 5466, 5479, 5519, 6629, 9652, 9919, 11009, 11175, 11348, 12167, 13016, 13109, 13216, 13250, 13253, 14265, 15018, 16389, 20993, 22240, 23259, 23276, 23410, 25158, 27034, 30140, 31404, 31521, 31619, 31683, 31692, 31705, 34207, 55515, 64781, 71416, 76305, 77516, 81021, 85257, 85806, 86243, 91008, 97806, 100000], ys=[81112, 12485, 94379, 88854, 987, 76485, 42941, 64723, 81743, 86552, 93967, 41028, 583, 23986, 45831, 34204, 5856, 40242, 63968, 6777, 16745, 36621, 70993, 45840, 41901, 19003, 56321, 76109, 36482, 43746, 94401, 24752, 56908, 76875, 59498, 38391, 6693, 23419, 73740, 47413, 27170, 34095, 80071, 53942, 76129, 80538, 44026, 72982, 75701], thresh=4786941056):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=100000, alpha=17, beta=6, xs=[0, 3069, 5319, 5373, 5466, 5479, 5519, 6629, 9652, 9919, 11009, 11175, 11348, 12167, 13016, 13109, 13216, 13250, 13253, 14265, 15018, 16389, 20993, 22240, 23259, 23276, 23410, 25158, 27034, 30140, 31404, 31521, 31619, 31683, 31692, 31705, 34207, 55515, 64781, 71416, 76305, 77516, 81021, 85257, 85806, 86243, 91008, 97806, 100000], ys=[81112, 12485, 94379, 88854, 987, 76485, 42941, 64723, 81743, 86552, 93967, 41028, 583, 23986, 45831, 34204, 5856, 40242, 63968, 6777, 16745, 36621, 70993, 45840, 41901, 19003, 56321, 76109, 36482, 43746, 94401, 24752, 56908, 76875, 59498, 38391, 6693, 23419, 73740, 47413, 27170, 34095, 80071, 53942, 76129, 80538, 44026, 72982, 75701], thresh=4786941056):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 }, { - "name": "StrAt_7", - "sat": "def sat(i: int, s=\"sajehysajehy\", target=\"s\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"sajehysajehy\", target=\"s\"):\n return s.index(target)" + "name": "OptimalBridges:2", + "sat": "def sat(indices: List[int], H=100000, alpha=21, beta=40, xs=[0, 8094, 57578, 62776, 83547, 87398, 95828, 100000], ys=[14832, 27072, 77311, 50782, 82688, 11061, 50767, 3696], thresh=143624404582):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=100000, alpha=21, beta=40, xs=[0, 8094, 57578, 62776, 83547, 87398, 95828, 100000], ys=[14832, 27072, 77311, 50782, 82688, 11061, 50767, 3696], thresh=143624404582):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 }, { - "name": "StrAt_8", - "sat": "def sat(i: int, s=\"mufetemaduxomufetemaduxo\", target=\"e\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"mufetemaduxomufetemaduxo\", target=\"e\"):\n return s.index(target)" + "name": "OptimalBridges:3", + "sat": "def sat(indices: List[int], H=100000, alpha=975, beta=546, xs=[0, 102, 174, 281, 458, 554, 583, 590, 646, 1592, 1795, 1805, 1835, 1839, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1843, 2357, 2683, 3152, 3159, 3167, 3170, 3170, 3171, 3171, 3172, 3172, 3172, 3172, 3172, 3173, 4025, 4274, 4282, 4465, 4520, 4529, 4666, 4676, 4901, 4905, 5003, 5295, 5510, 5553, 5585, 5585, 5638, 5973, 6136, 6317, 6329, 6374, 6400, 6405, 6407, 6407, 6409, 6409, 6409, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6411, 6456, 6462, 6462, 6469, 6482, 6486, 6881, 6919, 7240, 7510, 7599, 7995, 8173, 8249, 8284, 8296, 8298, 8298, 8299, 8301, 8427, 8701, 8751, 8945, 9141, 9166, 9208, 9308, 9321, 9327, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9333, 10630, 11062, 11173, 11286, 11294, 11319, 11322, 11367, 11372, 11376, 11398, 11399, 11403, 11409, 11451, 11459, 11519, 11660, 11687, 11691, 11694, 11694, 11697, 12232, 12313, 12314, 12316, 12321, 12322, 12322, 12322, 12323, 13101, 13207, 13274, 13445, 13512, 13687, 13911, 13987, 14251, 14255, 14306, 14570, 14594, 14606, 14606, 14608, 14998, 15232, 15237, 15633, 15795, 15831, 15991, 16176, 16179, 16189, 16228, 16339, 16450, 16540, 16777, 16851, 16889, 17291, 17694, 18333, 18356, 19390, 19449, 19454, 19750, 20562, 22013, 22332, 22374, 22591, 23234, 23276, 23281, 23296, 23351, 23397, 23762, 23844, 23859, 23866, 23894, 23943, 24311, 24379, 24958, 25140, 25160, 25178, 25211, 25219, 25235, 25378, 25929, 26078, 26181, 26474, 26804, 26821, 26838, 26843, 26858, 26894, 26894, 26894, 26895, 27181, 27302, 27329, 27365, 27374, 27380, 27381, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27383, 27386, 27418, 27450, 27463, 27525, 27529, 27552, 27559, 27562, 27562, 27563, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27565, 27721, 27801, 27818, 27882, 28083, 28148, 28673, 29079, 29102, 29155, 29158, 29162, 29193, 29256, 29576, 29991, 29992, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29997, 30025, 30083, 30088, 30146, 30173, 30182, 30305, 30408, 30596, 30905, 31000, 31405, 31558, 31588, 31663, 31664, 31664, 31667, 31670, 31674, 31676, 31703, 32815, 32821, 32949, 33977, 34036, 34403, 34413, 34464, 34505, 34509, 34511, 34772, 34972, 35021, 35068, 35259, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35273, 35311, 35343, 35611, 35950, 36192, 36400, 36410, 36622, 36820, 36883, 36959, 36960, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36964, 37010, 37035, 37311, 37660, 37733, 37934, 38287, 38539, 39425, 39441, 39473, 40033, 40124, 40319, 40609, 40643, 40673, 40727, 40741, 40742, 40744, 40750, 41021, 41080, 41311, 41319, 41321, 41335, 41344, 41344, 41345, 41345, 41345, 41345, 41345, 41346, 41532, 41554, 42011, 42164, 42187, 42276, 42566, 42675, 43393, 43473, 43480, 43504, 43504, 43504, 43504, 43504, 43505, 44026, 44718, 45006, 45128, 45193, 45581, 45643, 45679, 45684, 45687, 45858, 45958, 46022, 46126, 46367, 46712, 46849, 47743, 47968, 48262, 49272, 49376, 50058, 50436, 51804, 51966, 52122, 52374, 53401, 53638, 54722, 55797, 55906, 56812, 56839, 57005, 58384, 58720, 58959, 59074, 59209, 59512, 59785, 60798, 61136, 61198, 61505, 62052, 62540, 62555, 62783, 63241, 63829, 64155, 64422, 64520, 65271, 65297, 67452, 67628, 68258, 68379, 69233, 69496, 69613, 69774, 70090, 70092, 70759, 70770, 70809, 71196, 71265, 71529, 72250, 72476, 72523, 72556, 72829, 73209, 73477, 73739, 73843, 74249, 74728, 74988, 75425, 75988, 76032, 76096, 76152, 76222, 76751, 77227, 77631, 77995, 78061, 78169, 78400, 78784, 79499, 80385, 80551, 80627, 80660, 81059, 81143, 81405, 81665, 82904, 83595, 83957, 83996, 84043, 84739, 85031, 85987, 86319, 86864, 86933, 86947, 87127, 87520, 87543, 87848, 88057, 88437, 89195, 89401, 90469, 90756, 90761, 91175, 91975, 92907, 92987, 94337, 94470, 95290, 96267, 96378, 96635, 97113, 97608, 97663, 97721, 98148, 98536, 98629, 98960, 99036, 99763, 99793, 100000], ys=[2773, 47376, 17008, 24785, 21921, 60359, 33137, 72146, 76002, 49654, 25696, 25832, 72474, 2917, 18229, 2385, 66151, 51868, 4760, 69187, 67221, 14320, 24425, 88890, 24553, 78751, 70869, 11279, 12625, 84959, 28885, 87499, 61816, 41222, 81997, 1265, 63632, 12863, 54939, 56081, 35629, 37122, 49133, 24893, 41731, 9182, 34407, 90952, 42360, 43861, 99296, 80331, 78826, 19484, 90699, 30578, 71697, 10304, 61318, 89870, 38599, 71160, 22805, 17850, 60106, 76742, 14571, 74280, 88847, 53537, 84726, 7279, 55376, 47707, 78111, 14855, 20855, 89936, 20706, 98672, 5385, 76357, 90172, 48891, 6243, 82298, 64602, 99637, 83220, 87261, 26190, 39457, 12610, 44567, 54545, 71246, 96608, 5086, 65811, 15907, 21012, 17278, 1139, 54815, 52416, 19440, 44857, 16066, 22379, 73573, 36087, 54255, 60304, 30497, 1202, 95520, 48378, 68296, 14032, 50456, 60555, 80390, 70975, 17531, 3761, 46399, 48927, 96320, 79008, 25360, 67058, 26409, 29891, 324, 67141, 24534, 69987, 11711, 99837, 82260, 8818, 67647, 66046, 76727, 25049, 48694, 96244, 42767, 13120, 53729, 90754, 47498, 40257, 7844, 79665, 35900, 33567, 80332, 68427, 29914, 91621, 38959, 35796, 7435, 65460, 434, 2785, 4710, 80793, 20827, 22155, 90320, 5066, 24178, 18875, 51294, 5222, 95816, 14268, 68478, 96761, 66479, 67335, 51513, 78673, 73143, 11679, 85300, 88785, 1004, 18064, 91085, 18999, 25640, 45379, 74924, 94706, 46916, 32682, 31715, 3086, 49466, 85098, 49913, 44647, 82331, 27219, 13875, 58769, 3667, 10298, 44795, 62204, 21497, 58731, 12965, 62569, 72238, 49525, 22899, 84200, 3845, 98178, 924, 35984, 32417, 22686, 22620, 47458, 87867, 29566, 77085, 10960, 14876, 89730, 21641, 13636, 79167, 53472, 30103, 56335, 39274, 74071, 68958, 66408, 47354, 84728, 28113, 99860, 49955, 79844, 1186, 85981, 39037, 60464, 80363, 89186, 92541, 16343, 48363, 7581, 73306, 68325, 65829, 84163, 74355, 53786, 58715, 98906, 39439, 27860, 76391, 76589, 39834, 27137, 81688, 64132, 49120, 56144, 86941, 95518, 72009, 82728, 96067, 97712, 79469, 44330, 67454, 39941, 97408, 58132, 5066, 93590, 77162, 72882, 39621, 31441, 23172, 65710, 88436, 34469, 86816, 9665, 5643, 68076, 70549, 80805, 94994, 91769, 84542, 62168, 74918, 61406, 45287, 5793, 54563, 3652, 92584, 61367, 28505, 30248, 20120, 86422, 81094, 83631, 58464, 55958, 40896, 81384, 55062, 40915, 58556, 32091, 34368, 54084, 77250, 25828, 15620, 90399, 20250, 73405, 26695, 2032, 83486, 95048, 94554, 30946, 28573, 74157, 43422, 85194, 47436, 36847, 40337, 44865, 44811, 69652, 13169, 41240, 48298, 72630, 51768, 49849, 81558, 51868, 75819, 14511, 36733, 35093, 77864, 36881, 97122, 60008, 48465, 10154, 94832, 12514, 47840, 15591, 65517, 68261, 63597, 80341, 6530, 76786, 97631, 2526, 47318, 83685, 23732, 20477, 36378, 4066, 79691, 93070, 83021, 37168, 52019, 85092, 72854, 20879, 55104, 61225, 87611, 84521, 9011, 27496, 39666, 61677, 49131, 80714, 29320, 98393, 71579, 39547, 34736, 99974, 53333, 26106, 50745, 92975, 84628, 24607, 5133, 38793, 24284, 43324, 50981, 51005, 22088, 10404, 59675, 84882, 52975, 94861, 17852, 74017, 42533, 53763, 1986, 59478, 96769, 77976, 58875, 25744, 68724, 10130, 52144, 73428, 10610, 97509, 64410, 37812, 59809, 8455, 65712, 89789, 87542, 22274, 94253, 59627, 42450, 26524, 12018, 35043, 27433, 94055, 79108, 64297, 39011, 68974, 69586, 87982, 71372, 62430, 43056, 15425, 80083, 68963, 38661, 45853, 44335, 71876, 28982, 2264, 61889, 6454, 58072, 242, 93781, 71755, 66290, 90497, 54071, 55444, 64765, 4058, 79429, 41630, 15024, 64603, 98934, 48326, 56618, 55522, 37470, 57495, 31975, 70970, 31709, 31945, 64378, 12831, 51921, 76994, 31476, 72360, 63265, 35422, 88813, 58864, 74401, 91076, 37836, 55027, 95549, 15618, 34969, 60039, 61528, 3321, 94087, 37316, 81288, 81268, 71368, 95150, 57625, 34979, 60444, 45713, 87417, 17729, 30256, 98375, 2527, 95619, 71929, 47741, 59345, 50186, 73234, 74055, 49179, 14980, 21318, 96240, 9917, 75849, 56534, 85371, 63765, 23611, 47419, 34402, 48943, 26048, 69611, 29375, 29430, 6553, 97428, 97806, 80481, 26953, 42600, 59032, 65854, 66035, 48964, 22269, 52171, 14513, 65468, 66339, 25356, 52393, 7853, 24853, 78187, 83930, 67307, 45091, 41518, 52101, 76047, 40529, 36318, 3755, 62784, 77519, 22200, 70689, 33135, 81934, 72265, 2971, 91369, 53872, 45818, 57790, 21607, 66120, 26696, 92619, 47305, 65861, 60602, 66559, 2054, 57820, 19261, 6596, 56435, 12167, 29581, 17598, 1729, 77111, 26411, 66914, 14722, 39615, 27758, 96587, 69153, 65407, 65952, 52604, 28856, 58297, 94511, 71028, 75000, 60829, 12334, 21754, 20048, 5488, 11184, 80078, 64552, 23655, 75130, 79850, 40299, 92970, 89686, 72265, 49906, 84405, 90304, 74509, 97608, 32383, 77555, 89457, 96493, 25090, 79130, 5238, 44242, 54197, 87027, 77862, 44899, 39596, 50314, 66002, 34789, 83144, 62992, 9580, 89205, 9252, 54862, 53171, 64280, 13361, 17974, 66583, 40129, 4768, 25940, 96021, 80579, 7235, 63726, 87348, 21304, 86007, 94534, 57733, 43068, 31145, 34295, 12128, 97580, 83653, 28797, 69504, 29790, 73946, 59341, 48155, 1463, 80083, 32469, 71782, 20850, 96205, 42015, 73041, 55026, 56528, 41902, 12404, 62462, 81533, 16708, 7415, 68387, 80571, 32027, 35225, 10946, 94144, 4194, 43504, 49796, 50362, 95023, 52994, 95205, 36035, 71247, 41720, 6865, 17427, 36924, 61894, 38538, 67742, 44575, 14625, 79002, 90627, 8841, 84462, 7945, 24927, 82064, 46459, 52759, 31226, 5657, 79441, 64942, 70601, 84159, 3713, 5819, 33208, 82518, 79984, 11805, 65691, 27461, 79491, 31649, 44872, 55358, 59545, 43403, 25937, 57129, 95086, 33073, 66761, 54601, 58418, 97317, 55033, 52664, 98134, 37723, 11301, 82638, 57741, 7107, 3684, 12886, 23805, 51818, 91767, 69982, 49206, 31880, 98404, 66281, 65126, 58401, 7132, 42216, 82869, 16032, 26488, 60581, 34013, 63817, 6519, 89872, 31855, 22997, 69212, 73604, 76079, 64953, 98735, 44812, 4732, 94488, 84054, 42787, 46869, 45010, 20732, 5560, 56309, 77803, 42883, 66324, 49402, 64847, 31627, 94225, 77195, 95635, 68166, 31386, 63128, 31631, 70432, 46143, 52182, 8113, 84606, 51625, 55982, 29418, 64146, 69813, 44592, 79603, 46634, 32362, 62318, 18402, 68531, 53415, 19852, 28919, 62513, 79532, 49718, 33065, 56835, 64306, 60638, 70658, 79161, 27512, 68976, 89331, 29937, 12813, 57173, 27550, 84813, 60721, 11582, 44931, 88702, 7688, 52433, 55498, 95194, 39528, 6913, 6693, 94386, 842, 12398, 45874, 68922, 71749, 4672, 93255, 10276, 30051, 18146, 1369, 34708, 13026, 81431, 18801, 4379, 1238, 53213, 33648, 8064, 76802, 41132, 22338, 2817, 16671, 85926, 86066, 41124, 36200, 37286, 96525, 59693, 83181, 87393, 35298, 17208, 90473, 22239, 61861, 41594, 2519, 54614, 59722, 37429, 49717, 81394, 55456, 64709, 76277, 23690, 55080, 41336, 29750, 97329, 28604, 24728, 76992, 67044, 34563, 32395, 24170, 30848, 56474, 78881, 4772, 23177, 28993, 11230, 77390, 62191, 24747, 29986, 50371, 34979, 66772, 80075, 19549, 78848, 11352, 48373, 96733, 93428, 45892, 86184, 62894, 19948, 70176, 16630, 69200, 28933, 93458, 73504, 54975, 55489, 8787, 47519, 97887, 16335], thresh=44238370995):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=100000, alpha=975, beta=546, xs=[0, 102, 174, 281, 458, 554, 583, 590, 646, 1592, 1795, 1805, 1835, 1839, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1842, 1843, 2357, 2683, 3152, 3159, 3167, 3170, 3170, 3171, 3171, 3172, 3172, 3172, 3172, 3172, 3173, 4025, 4274, 4282, 4465, 4520, 4529, 4666, 4676, 4901, 4905, 5003, 5295, 5510, 5553, 5585, 5585, 5638, 5973, 6136, 6317, 6329, 6374, 6400, 6405, 6407, 6407, 6409, 6409, 6409, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6410, 6411, 6456, 6462, 6462, 6469, 6482, 6486, 6881, 6919, 7240, 7510, 7599, 7995, 8173, 8249, 8284, 8296, 8298, 8298, 8299, 8301, 8427, 8701, 8751, 8945, 9141, 9166, 9208, 9308, 9321, 9327, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9332, 9333, 10630, 11062, 11173, 11286, 11294, 11319, 11322, 11367, 11372, 11376, 11398, 11399, 11403, 11409, 11451, 11459, 11519, 11660, 11687, 11691, 11694, 11694, 11697, 12232, 12313, 12314, 12316, 12321, 12322, 12322, 12322, 12323, 13101, 13207, 13274, 13445, 13512, 13687, 13911, 13987, 14251, 14255, 14306, 14570, 14594, 14606, 14606, 14608, 14998, 15232, 15237, 15633, 15795, 15831, 15991, 16176, 16179, 16189, 16228, 16339, 16450, 16540, 16777, 16851, 16889, 17291, 17694, 18333, 18356, 19390, 19449, 19454, 19750, 20562, 22013, 22332, 22374, 22591, 23234, 23276, 23281, 23296, 23351, 23397, 23762, 23844, 23859, 23866, 23894, 23943, 24311, 24379, 24958, 25140, 25160, 25178, 25211, 25219, 25235, 25378, 25929, 26078, 26181, 26474, 26804, 26821, 26838, 26843, 26858, 26894, 26894, 26894, 26895, 27181, 27302, 27329, 27365, 27374, 27380, 27381, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27382, 27383, 27386, 27418, 27450, 27463, 27525, 27529, 27552, 27559, 27562, 27562, 27563, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27564, 27565, 27721, 27801, 27818, 27882, 28083, 28148, 28673, 29079, 29102, 29155, 29158, 29162, 29193, 29256, 29576, 29991, 29992, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29996, 29997, 30025, 30083, 30088, 30146, 30173, 30182, 30305, 30408, 30596, 30905, 31000, 31405, 31558, 31588, 31663, 31664, 31664, 31667, 31670, 31674, 31676, 31703, 32815, 32821, 32949, 33977, 34036, 34403, 34413, 34464, 34505, 34509, 34511, 34772, 34972, 35021, 35068, 35259, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35272, 35273, 35311, 35343, 35611, 35950, 36192, 36400, 36410, 36622, 36820, 36883, 36959, 36960, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36963, 36964, 37010, 37035, 37311, 37660, 37733, 37934, 38287, 38539, 39425, 39441, 39473, 40033, 40124, 40319, 40609, 40643, 40673, 40727, 40741, 40742, 40744, 40750, 41021, 41080, 41311, 41319, 41321, 41335, 41344, 41344, 41345, 41345, 41345, 41345, 41345, 41346, 41532, 41554, 42011, 42164, 42187, 42276, 42566, 42675, 43393, 43473, 43480, 43504, 43504, 43504, 43504, 43504, 43505, 44026, 44718, 45006, 45128, 45193, 45581, 45643, 45679, 45684, 45687, 45858, 45958, 46022, 46126, 46367, 46712, 46849, 47743, 47968, 48262, 49272, 49376, 50058, 50436, 51804, 51966, 52122, 52374, 53401, 53638, 54722, 55797, 55906, 56812, 56839, 57005, 58384, 58720, 58959, 59074, 59209, 59512, 59785, 60798, 61136, 61198, 61505, 62052, 62540, 62555, 62783, 63241, 63829, 64155, 64422, 64520, 65271, 65297, 67452, 67628, 68258, 68379, 69233, 69496, 69613, 69774, 70090, 70092, 70759, 70770, 70809, 71196, 71265, 71529, 72250, 72476, 72523, 72556, 72829, 73209, 73477, 73739, 73843, 74249, 74728, 74988, 75425, 75988, 76032, 76096, 76152, 76222, 76751, 77227, 77631, 77995, 78061, 78169, 78400, 78784, 79499, 80385, 80551, 80627, 80660, 81059, 81143, 81405, 81665, 82904, 83595, 83957, 83996, 84043, 84739, 85031, 85987, 86319, 86864, 86933, 86947, 87127, 87520, 87543, 87848, 88057, 88437, 89195, 89401, 90469, 90756, 90761, 91175, 91975, 92907, 92987, 94337, 94470, 95290, 96267, 96378, 96635, 97113, 97608, 97663, 97721, 98148, 98536, 98629, 98960, 99036, 99763, 99793, 100000], ys=[2773, 47376, 17008, 24785, 21921, 60359, 33137, 72146, 76002, 49654, 25696, 25832, 72474, 2917, 18229, 2385, 66151, 51868, 4760, 69187, 67221, 14320, 24425, 88890, 24553, 78751, 70869, 11279, 12625, 84959, 28885, 87499, 61816, 41222, 81997, 1265, 63632, 12863, 54939, 56081, 35629, 37122, 49133, 24893, 41731, 9182, 34407, 90952, 42360, 43861, 99296, 80331, 78826, 19484, 90699, 30578, 71697, 10304, 61318, 89870, 38599, 71160, 22805, 17850, 60106, 76742, 14571, 74280, 88847, 53537, 84726, 7279, 55376, 47707, 78111, 14855, 20855, 89936, 20706, 98672, 5385, 76357, 90172, 48891, 6243, 82298, 64602, 99637, 83220, 87261, 26190, 39457, 12610, 44567, 54545, 71246, 96608, 5086, 65811, 15907, 21012, 17278, 1139, 54815, 52416, 19440, 44857, 16066, 22379, 73573, 36087, 54255, 60304, 30497, 1202, 95520, 48378, 68296, 14032, 50456, 60555, 80390, 70975, 17531, 3761, 46399, 48927, 96320, 79008, 25360, 67058, 26409, 29891, 324, 67141, 24534, 69987, 11711, 99837, 82260, 8818, 67647, 66046, 76727, 25049, 48694, 96244, 42767, 13120, 53729, 90754, 47498, 40257, 7844, 79665, 35900, 33567, 80332, 68427, 29914, 91621, 38959, 35796, 7435, 65460, 434, 2785, 4710, 80793, 20827, 22155, 90320, 5066, 24178, 18875, 51294, 5222, 95816, 14268, 68478, 96761, 66479, 67335, 51513, 78673, 73143, 11679, 85300, 88785, 1004, 18064, 91085, 18999, 25640, 45379, 74924, 94706, 46916, 32682, 31715, 3086, 49466, 85098, 49913, 44647, 82331, 27219, 13875, 58769, 3667, 10298, 44795, 62204, 21497, 58731, 12965, 62569, 72238, 49525, 22899, 84200, 3845, 98178, 924, 35984, 32417, 22686, 22620, 47458, 87867, 29566, 77085, 10960, 14876, 89730, 21641, 13636, 79167, 53472, 30103, 56335, 39274, 74071, 68958, 66408, 47354, 84728, 28113, 99860, 49955, 79844, 1186, 85981, 39037, 60464, 80363, 89186, 92541, 16343, 48363, 7581, 73306, 68325, 65829, 84163, 74355, 53786, 58715, 98906, 39439, 27860, 76391, 76589, 39834, 27137, 81688, 64132, 49120, 56144, 86941, 95518, 72009, 82728, 96067, 97712, 79469, 44330, 67454, 39941, 97408, 58132, 5066, 93590, 77162, 72882, 39621, 31441, 23172, 65710, 88436, 34469, 86816, 9665, 5643, 68076, 70549, 80805, 94994, 91769, 84542, 62168, 74918, 61406, 45287, 5793, 54563, 3652, 92584, 61367, 28505, 30248, 20120, 86422, 81094, 83631, 58464, 55958, 40896, 81384, 55062, 40915, 58556, 32091, 34368, 54084, 77250, 25828, 15620, 90399, 20250, 73405, 26695, 2032, 83486, 95048, 94554, 30946, 28573, 74157, 43422, 85194, 47436, 36847, 40337, 44865, 44811, 69652, 13169, 41240, 48298, 72630, 51768, 49849, 81558, 51868, 75819, 14511, 36733, 35093, 77864, 36881, 97122, 60008, 48465, 10154, 94832, 12514, 47840, 15591, 65517, 68261, 63597, 80341, 6530, 76786, 97631, 2526, 47318, 83685, 23732, 20477, 36378, 4066, 79691, 93070, 83021, 37168, 52019, 85092, 72854, 20879, 55104, 61225, 87611, 84521, 9011, 27496, 39666, 61677, 49131, 80714, 29320, 98393, 71579, 39547, 34736, 99974, 53333, 26106, 50745, 92975, 84628, 24607, 5133, 38793, 24284, 43324, 50981, 51005, 22088, 10404, 59675, 84882, 52975, 94861, 17852, 74017, 42533, 53763, 1986, 59478, 96769, 77976, 58875, 25744, 68724, 10130, 52144, 73428, 10610, 97509, 64410, 37812, 59809, 8455, 65712, 89789, 87542, 22274, 94253, 59627, 42450, 26524, 12018, 35043, 27433, 94055, 79108, 64297, 39011, 68974, 69586, 87982, 71372, 62430, 43056, 15425, 80083, 68963, 38661, 45853, 44335, 71876, 28982, 2264, 61889, 6454, 58072, 242, 93781, 71755, 66290, 90497, 54071, 55444, 64765, 4058, 79429, 41630, 15024, 64603, 98934, 48326, 56618, 55522, 37470, 57495, 31975, 70970, 31709, 31945, 64378, 12831, 51921, 76994, 31476, 72360, 63265, 35422, 88813, 58864, 74401, 91076, 37836, 55027, 95549, 15618, 34969, 60039, 61528, 3321, 94087, 37316, 81288, 81268, 71368, 95150, 57625, 34979, 60444, 45713, 87417, 17729, 30256, 98375, 2527, 95619, 71929, 47741, 59345, 50186, 73234, 74055, 49179, 14980, 21318, 96240, 9917, 75849, 56534, 85371, 63765, 23611, 47419, 34402, 48943, 26048, 69611, 29375, 29430, 6553, 97428, 97806, 80481, 26953, 42600, 59032, 65854, 66035, 48964, 22269, 52171, 14513, 65468, 66339, 25356, 52393, 7853, 24853, 78187, 83930, 67307, 45091, 41518, 52101, 76047, 40529, 36318, 3755, 62784, 77519, 22200, 70689, 33135, 81934, 72265, 2971, 91369, 53872, 45818, 57790, 21607, 66120, 26696, 92619, 47305, 65861, 60602, 66559, 2054, 57820, 19261, 6596, 56435, 12167, 29581, 17598, 1729, 77111, 26411, 66914, 14722, 39615, 27758, 96587, 69153, 65407, 65952, 52604, 28856, 58297, 94511, 71028, 75000, 60829, 12334, 21754, 20048, 5488, 11184, 80078, 64552, 23655, 75130, 79850, 40299, 92970, 89686, 72265, 49906, 84405, 90304, 74509, 97608, 32383, 77555, 89457, 96493, 25090, 79130, 5238, 44242, 54197, 87027, 77862, 44899, 39596, 50314, 66002, 34789, 83144, 62992, 9580, 89205, 9252, 54862, 53171, 64280, 13361, 17974, 66583, 40129, 4768, 25940, 96021, 80579, 7235, 63726, 87348, 21304, 86007, 94534, 57733, 43068, 31145, 34295, 12128, 97580, 83653, 28797, 69504, 29790, 73946, 59341, 48155, 1463, 80083, 32469, 71782, 20850, 96205, 42015, 73041, 55026, 56528, 41902, 12404, 62462, 81533, 16708, 7415, 68387, 80571, 32027, 35225, 10946, 94144, 4194, 43504, 49796, 50362, 95023, 52994, 95205, 36035, 71247, 41720, 6865, 17427, 36924, 61894, 38538, 67742, 44575, 14625, 79002, 90627, 8841, 84462, 7945, 24927, 82064, 46459, 52759, 31226, 5657, 79441, 64942, 70601, 84159, 3713, 5819, 33208, 82518, 79984, 11805, 65691, 27461, 79491, 31649, 44872, 55358, 59545, 43403, 25937, 57129, 95086, 33073, 66761, 54601, 58418, 97317, 55033, 52664, 98134, 37723, 11301, 82638, 57741, 7107, 3684, 12886, 23805, 51818, 91767, 69982, 49206, 31880, 98404, 66281, 65126, 58401, 7132, 42216, 82869, 16032, 26488, 60581, 34013, 63817, 6519, 89872, 31855, 22997, 69212, 73604, 76079, 64953, 98735, 44812, 4732, 94488, 84054, 42787, 46869, 45010, 20732, 5560, 56309, 77803, 42883, 66324, 49402, 64847, 31627, 94225, 77195, 95635, 68166, 31386, 63128, 31631, 70432, 46143, 52182, 8113, 84606, 51625, 55982, 29418, 64146, 69813, 44592, 79603, 46634, 32362, 62318, 18402, 68531, 53415, 19852, 28919, 62513, 79532, 49718, 33065, 56835, 64306, 60638, 70658, 79161, 27512, 68976, 89331, 29937, 12813, 57173, 27550, 84813, 60721, 11582, 44931, 88702, 7688, 52433, 55498, 95194, 39528, 6913, 6693, 94386, 842, 12398, 45874, 68922, 71749, 4672, 93255, 10276, 30051, 18146, 1369, 34708, 13026, 81431, 18801, 4379, 1238, 53213, 33648, 8064, 76802, 41132, 22338, 2817, 16671, 85926, 86066, 41124, 36200, 37286, 96525, 59693, 83181, 87393, 35298, 17208, 90473, 22239, 61861, 41594, 2519, 54614, 59722, 37429, 49717, 81394, 55456, 64709, 76277, 23690, 55080, 41336, 29750, 97329, 28604, 24728, 76992, 67044, 34563, 32395, 24170, 30848, 56474, 78881, 4772, 23177, 28993, 11230, 77390, 62191, 24747, 29986, 50371, 34979, 66772, 80075, 19549, 78848, 11352, 48373, 96733, 93428, 45892, 86184, 62894, 19948, 70176, 16630, 69200, 28933, 93458, 73504, 54975, 55489, 8787, 47519, 97887, 16335], thresh=44238370995):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 }, { - "name": "StrAt_9", - "sat": "def sat(i: int, s=\"kochiranutekipohkochiranutekipoh\", target=\"u\"):\n \"\"\"Find the index of target in string s\"\"\"\n return s[i] == target", - "sols": [ - "def sol(s=\"kochiranutekipohkochiranutekipoh\", target=\"u\"):\n return s.index(target)" + "name": "OptimalBridges:4", + "sat": "def sat(indices: List[int], H=100000, alpha=6, beta=2, xs=[0, 75202, 97997, 100000], ys=[24586, 7488, 4413, 30235], thresh=12359929344):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=100000, alpha=6, beta=2, xs=[0, 75202, 97997, 100000], ys=[24586, 7488, 4413, 30235], thresh=12359929344):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 }, { - "name": "StrNegAt_0", - "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"cat\", target=\"a\"):\n return - (len(s) - s.index(target))" + "name": "CheckersPosition:0", + "sat": "def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 }, { - "name": "StrNegAt_1", - "sat": "def sat(i: int, s=\"ch\", target=\"c\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"ch\", target=\"c\"):\n return - (len(s) - s.index(target))" + "name": "CheckersPosition:1", + "sat": "def sat(position: List[List[int]], transcript=[]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 }, { - "name": "StrNegAt_2", - "sat": "def sat(i: int, s=\"nydivimocuvacetext\", target=\"y\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"nydivimocuvacetext\", target=\"y\"):\n return - (len(s) - s.index(target))" + "name": "CheckersPosition:2", + "sat": "def sat(position: List[List[int]], transcript=[[[6, 4], [5, 5]], [[4, 6], [6, 4]], [[7, 3], [5, 5]], [[3, 5], [4, 4]], [[4, 2], [6, 4]], [[3, 7], [2, 6]], [[5, 5], [6, 6]], [[7, 7], [5, 5], [7, 3]], [[1, 1], [0, 2]], [[7, 3], [6, 2]], [[0, 0], [1, 1]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[4, 4], [3, 3]], [[1, 1], [2, 2]], [[3, 3], [1, 1]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[0, 2], [1, 3]], [[2, 4], [0, 2]], [[3, 1], [2, 2]], [[1, 7], [0, 6]]]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[[[6, 4], [5, 5]], [[4, 6], [6, 4]], [[7, 3], [5, 5]], [[3, 5], [4, 4]], [[4, 2], [6, 4]], [[3, 7], [2, 6]], [[5, 5], [6, 6]], [[7, 7], [5, 5], [7, 3]], [[1, 1], [0, 2]], [[7, 3], [6, 2]], [[0, 0], [1, 1]], [[6, 2], [5, 1]], [[4, 0], [6, 2]], [[4, 4], [3, 3]], [[1, 1], [2, 2]], [[3, 3], [1, 1]], [[6, 2], [7, 3]], [[5, 7], [6, 6]], [[0, 2], [1, 3]], [[2, 4], [0, 2]], [[3, 1], [2, 2]], [[1, 7], [0, 6]]]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 }, { - "name": "StrNegAt_3", - "sat": "def sat(i: int, s=\"chyxchyx\", target=\"x\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"chyxchyx\", target=\"x\"):\n return - (len(s) - s.index(target))" + "name": "CheckersPosition:3", + "sat": "def sat(position: List[List[int]], transcript=[[[3, 1], [1, 3]]]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[[[3, 1], [1, 3]]]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 }, { - "name": "StrNegAt_4", - "sat": "def sat(i: int, s=\"tuchuworyquofojyzusutuchuworyquofojyzusutuchuworyquofojyzusu\", target=\"h\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"tuchuworyquofojyzusutuchuworyquofojyzusutuchuworyquofojyzusu\", target=\"h\"):\n return - (len(s) - s.index(target))" + "name": "CheckersPosition:4", + "sat": "def sat(position: List[List[int]], transcript=[[[5, 1], [3, 3], [5, 5], [3, 7]], [[7, 3], [5, 1]], [[6, 0], [4, 2]], [[3, 5], [2, 4]], [[1, 3], [3, 5]], [[7, 5], [6, 4]], [[1, 1], [2, 2]], [[6, 4], [7, 3]], [[4, 2], [3, 3]], [[6, 6], [5, 5]], [[0, 2], [1, 3]], [[5, 7], [4, 6]], [[3, 5], [5, 7]], [[1, 5], [2, 4]], [[3, 3], [1, 5]], [[0, 6], [2, 4], [0, 2]], [[2, 2], [1, 3]], [[5, 5], [4, 4]], [[7, 1], [6, 2]], [[7, 3], [5, 1]], [[1, 3], [2, 4]], [[7, 7], [6, 6]], [[5, 7], [7, 5]], [[0, 2], [1, 1]], [[0, 0], [2, 2]], [[4, 4], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [4, 2]], [[6, 4], [7, 5]], [[5, 1], [6, 0]], [[2, 4], [3, 5]], [[6, 0], [7, 1]], [[2, 2], [1, 3]], [[7, 1], [6, 0]], [[3, 5], [4, 6]], [[4, 2], [5, 1]], [[2, 0], [3, 1]], [[6, 0], [7, 1]], [[1, 3], [0, 4]], [[5, 1], [6, 0]], [[7, 5], [6, 6]], [[7, 1], [6, 2]], [[6, 6], [7, 7]], [[6, 0], [5, 1]], [[7, 7], [6, 6]], [[6, 2], [5, 3]], [[3, 1], [4, 2]], [[5, 3], [3, 1]], [[6, 6], [5, 5]], [[3, 1], [2, 0]], [[3, 7], [2, 6]], [[2, 0], [3, 1]], [[5, 5], [4, 4]], [[5, 1], [6, 2]], [[4, 4], [5, 5]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [3, 3]], [[2, 6], [1, 7]], [[3, 3], [2, 2]], [[4, 6], [5, 7]], [[2, 2], [3, 3]], [[1, 7], [2, 6]], [[6, 2], [5, 3]], [[5, 7], [4, 6]]]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[[[5, 1], [3, 3], [5, 5], [3, 7]], [[7, 3], [5, 1]], [[6, 0], [4, 2]], [[3, 5], [2, 4]], [[1, 3], [3, 5]], [[7, 5], [6, 4]], [[1, 1], [2, 2]], [[6, 4], [7, 3]], [[4, 2], [3, 3]], [[6, 6], [5, 5]], [[0, 2], [1, 3]], [[5, 7], [4, 6]], [[3, 5], [5, 7]], [[1, 5], [2, 4]], [[3, 3], [1, 5]], [[0, 6], [2, 4], [0, 2]], [[2, 2], [1, 3]], [[5, 5], [4, 4]], [[7, 1], [6, 2]], [[7, 3], [5, 1]], [[1, 3], [2, 4]], [[7, 7], [6, 6]], [[5, 7], [7, 5]], [[0, 2], [1, 1]], [[0, 0], [2, 2]], [[4, 4], [5, 3]], [[7, 5], [6, 4]], [[5, 3], [4, 2]], [[6, 4], [7, 5]], [[5, 1], [6, 0]], [[2, 4], [3, 5]], [[6, 0], [7, 1]], [[2, 2], [1, 3]], [[7, 1], [6, 0]], [[3, 5], [4, 6]], [[4, 2], [5, 1]], [[2, 0], [3, 1]], [[6, 0], [7, 1]], [[1, 3], [0, 4]], [[5, 1], [6, 0]], [[7, 5], [6, 6]], [[7, 1], [6, 2]], [[6, 6], [7, 7]], [[6, 0], [5, 1]], [[7, 7], [6, 6]], [[6, 2], [5, 3]], [[3, 1], [4, 2]], [[5, 3], [3, 1]], [[6, 6], [5, 5]], [[3, 1], [2, 0]], [[3, 7], [2, 6]], [[2, 0], [3, 1]], [[5, 5], [4, 4]], [[5, 1], [6, 2]], [[4, 4], [5, 5]], [[3, 1], [2, 2]], [[0, 4], [1, 5]], [[2, 2], [3, 3]], [[2, 6], [1, 7]], [[3, 3], [2, 2]], [[4, 6], [5, 7]], [[2, 2], [3, 3]], [[1, 7], [2, 6]], [[6, 2], [5, 3]], [[5, 7], [4, 6]]]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 }, { - "name": "StrNegAt_5", - "sat": "def sat(i: int, s=\"thithowyvofochothithowyvofochothithowyvofocho\", target=\"t\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"thithowyvofochothithowyvofochothithowyvofocho\", target=\"t\"):\n return - (len(s) - s.index(target))" + "name": "MatchingMarkers:0", + "sat": "def sat(cut_position: int, ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 }, { - "name": "StrNegAt_6", - "sat": "def sat(i: int, s=\"vazykuz\", target=\"a\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"vazykuz\", target=\"a\"):\n return - (len(s) - s.index(target))" + "name": "MatchingMarkers:1", + "sat": "def sat(cut_position: int, ring=\"MvI\", lower=0):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"MvI\", lower=0):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 }, { - "name": "StrNegAt_7", - "sat": "def sat(i: int, s=\"quevquevquev\", target=\"e\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"quevquevquev\", target=\"e\"):\n return - (len(s) - s.index(target))" + "name": "MatchingMarkers:2", + "sat": "def sat(cut_position: int, ring=\"s\", lower=0):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"s\", lower=0):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 }, { - "name": "StrNegAt_8", - "sat": "def sat(i: int, s=\"nydobabocidnydobabocid\", target=\"b\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"nydobabocidnydobabocid\", target=\"b\"):\n return - (len(s) - s.index(target))" + "name": "MatchingMarkers:3", + "sat": "def sat(cut_position: int, ring=\"fyVYVBfGHVYsBrYVgsgHYvVD\", lower=0):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"fyVYVBfGHVYsBrYVgsgHYvVD\", lower=0):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 }, { - "name": "StrNegAt_9", - "sat": "def sat(i: int, s=\"ji\", target=\"i\"):\n \"\"\"Find the index of target in s using a negative index.\"\"\"\n return s[i] == target and i < 0", - "sols": [ - "def sol(s=\"ji\", target=\"i\"):\n return - (len(s) - s.index(target))" + "name": "MatchingMarkers:4", + "sat": "def sat(cut_position: int, ring=\"ClaKdLCuSddLdafuRKuqUqSLqquLCSlrCfFdcRAlfkLlqqqccQSacsDCUqDaLurDlqqfcAaKasCf\", lower=1):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"ClaKdLCuSddLdafuRKuqUqSLqquLCSlrCfFdcRAlfkLlqqqccQSacsDCUqDaLurDlqqfcAaKasCf\", lower=1):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 }, { - "name": "StrSlice_0", - "sat": "def sat(inds: List[int], s=\"hello world\", target=\"do\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"hello world\", target=\"do\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "ExponentialCoinMoves:0", + "sat": "def sat(states: List[List[int]], n=16385):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=16385):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 10.0 }, { - "name": "StrSlice_1", - "sat": "def sat(inds: List[int], s=\"ninykofiwimninykofiwim\", target=\"\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"ninykofiwimninykofiwim\", target=\"\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "ExponentialCoinMoves:1", + "sat": "def sat(states: List[List[int]], n=1):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=1):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrSlice_2", - "sat": "def sat(inds: List[int], s=\"limerybinylimerybiny\", target=\"n\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"limerybinylimerybiny\", target=\"n\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "ExponentialCoinMoves:2", + "sat": "def sat(states: List[List[int]], n=2):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=2):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrSlice_3", - "sat": "def sat(inds: List[int], s=\"fyzihurothevirechahfyzihurothevirechah\", target=\"\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"fyzihurothevirechahfyzihurothevirechah\", target=\"\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "ExponentialCoinMoves:3", + "sat": "def sat(states: List[List[int]], n=4):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=4):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrSlice_4", - "sat": "def sat(inds: List[int], s=\"kibozekiboze\", target=\"\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"kibozekiboze\", target=\"\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "ExponentialCoinMoves:4", + "sat": "def sat(states: List[List[int]], n=8):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=8):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 8.0 }, { - "name": "StrSlice_5", - "sat": "def sat(inds: List[int], s=\"mimemimemime\", target=\"\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"mimemimemime\", target=\"\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "NoRelativePrimes:0", + "sat": "def sat(nums: List[int], b=7, m=6):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=7, m=6):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [ + " ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 }, { - "name": "StrSlice_6", - "sat": "def sat(inds: List[int], s=\"xezirojxeziroj\", target=\"x\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"xezirojxeziroj\", target=\"x\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "NoRelativePrimes:1", + "sat": "def sat(nums: List[int], b=7, m=26):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=7, m=26):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [ + " ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 }, { - "name": "StrSlice_7", - "sat": "def sat(inds: List[int], s=\"dacejisycytocdacejisycytoc\", target=\"e\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"dacejisycytocdacejisycytoc\", target=\"e\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "NoRelativePrimes:2", + "sat": "def sat(nums: List[int], b=6, m=73):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=6, m=73):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [ + " ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 }, { - "name": "StrSlice_8", - "sat": "def sat(inds: List[int], s=\"ribuxiq\", target=\"xubir\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"ribuxiq\", target=\"xubir\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "NoRelativePrimes:3", + "sat": "def sat(nums: List[int], b=17, m=37):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=17, m=37):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [], + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 }, { - "name": "StrSlice_9", - "sat": "def sat(inds: List[int], s=\"vipikavipika\", target=\"\"):\n \"\"\"Find the three slice indices that give the specific target in string s\"\"\"\n i, j, k = inds\n return s[i:j:k] == target", - "sols": [ - "def sol(s=\"vipikavipika\", target=\"\"):\n from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "NoRelativePrimes:4", + "sat": "def sat(nums: List[int], b=7, m=92):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=7, m=92):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [ + " ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 }, { - "name": "StrIndex_0", - "sat": "def sat(s: str, big_str=\"foobar\", index=2):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"foobar\", index=2):\n return big_str[index:]" + "name": "FindRepeats:0", + "sat": "def sat(indices: List[int], a0=123):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=123):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex_1", - "sat": "def sat(s: str, big_str=\"fukulagatextuj\", index=10):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"fukulagatextuj\", index=10):\n return big_str[index:]" + "name": "FindRepeats:1", + "sat": "def sat(indices: List[int], a0=2827347):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=2827347):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex_2", - "sat": "def sat(s: str, big_str=\"nunalurejijunopyrewithocukopojot\", index=12):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"nunalurejijunopyrewithocukopojot\", index=12):\n return big_str[index:]" + "name": "FindRepeats:2", + "sat": "def sat(indices: List[int], a0=2362263):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=2362263):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex_3", - "sat": "def sat(s: str, big_str=\"fu\", index=1):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"fu\", index=1):\n return big_str[index:]" + "name": "FindRepeats:3", + "sat": "def sat(indices: List[int], a0=1703235):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=1703235):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex_4", - "sat": "def sat(s: str, big_str=\"fatextemedyrotichipicecojon\", index=24):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"fatextemedyrotichipicecojon\", index=24):\n return big_str[index:]" + "name": "FindRepeats:4", + "sat": "def sat(indices: List[int], a0=962856):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=962856):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex_5", - "sat": "def sat(s: str, big_str=\"wacathiquojakequidarevabehumijikyd\", index=0):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"wacathiquojakequidarevabehumijikyd\", index=0):\n return big_str[index:]" + "name": "PickNearNeighbors:0", + "sat": "def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 }, { - "name": "StrIndex_6", - "sat": "def sat(s: str, big_str=\"wugesinemisofexotochithelichaceteth\", index=20):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"wugesinemisofexotochithelichaceteth\", index=20):\n return big_str[index:]" + "name": "PickNearNeighbors:1", + "sat": "def sat(keep: List[bool], heights=[6, 12, 26, 4, 25, 20, 15, 14, 18, 22, 19, 23, 27, 13, 9, 28, 17, 11, 29, 7, 1, 10, 2, 0, 21, 3, 5, 8, 16, 24]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[6, 12, 26, 4, 25, 20, 15, 14, 18, 22, 19, 23, 27, 13, 9, 28, 17, 11, 29, 7, 1, 10, 2, 0, 21, 3, 5, 8, 16, 24]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 }, { - "name": "StrIndex_7", - "sat": "def sat(s: str, big_str=\"quywedohenocugasyfynygotextifyhu\", index=12):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"quywedohenocugasyfynygotextifyhu\", index=12):\n return big_str[index:]" + "name": "PickNearNeighbors:2", + "sat": "def sat(keep: List[bool], heights=[6, 8, 0, 7, 4, 9, 10, 1, 5, 3, 11, 2]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[6, 8, 0, 7, 4, 9, 10, 1, 5, 3, 11, 2]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 }, { - "name": "StrIndex_8", - "sat": "def sat(s: str, big_str=\"vapapufizipiwajadalujynuthihejixopire\", index=22):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"vapapufizipiwajadalujynuthihejixopire\", index=22):\n return big_str[index:]" + "name": "PickNearNeighbors:3", + "sat": "def sat(keep: List[bool], heights=[46, 61, 80, 16, 71, 32, 13, 12, 2, 75, 62, 56, 17, 28, 67, 54, 22, 27, 38, 63, 69, 84, 70, 57, 86, 72, 66, 8, 41, 3, 23, 88, 83, 58, 36, 50, 65, 30, 34, 25, 39, 20, 78, 79, 59, 4, 21, 73, 45, 37, 48, 77, 10, 44, 14, 43, 42, 0, 33, 29, 7, 52, 5, 60, 68, 9, 26, 49, 40, 76, 31, 6, 85, 74, 24, 51, 1, 89, 11, 47, 18, 19, 81, 87, 35, 64, 82, 15, 55, 53]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[46, 61, 80, 16, 71, 32, 13, 12, 2, 75, 62, 56, 17, 28, 67, 54, 22, 27, 38, 63, 69, 84, 70, 57, 86, 72, 66, 8, 41, 3, 23, 88, 83, 58, 36, 50, 65, 30, 34, 25, 39, 20, 78, 79, 59, 4, 21, 73, 45, 37, 48, 77, 10, 44, 14, 43, 42, 0, 33, 29, 7, 52, 5, 60, 68, 9, 26, 49, 40, 76, 31, 6, 85, 74, 24, 51, 1, 89, 11, 47, 18, 19, 81, 87, 35, 64, 82, 15, 55, 53]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 }, { - "name": "StrIndex_9", - "sat": "def sat(s: str, big_str=\"sixicethyvewochidefiquolodotheweditytewek\", index=17):\n \"\"\"Find a string whose *first* index in big_str is index\"\"\"\n return big_str.index(s) == index", - "sols": [ - "def sol(big_str=\"sixicethyvewochidefiquolodotheweditytewek\", index=17):\n return big_str[index:]" + "name": "PickNearNeighbors:4", + "sat": "def sat(keep: List[bool], heights=[26, 11, 62, 24, 56, 80, 39, 77, 23, 86, 53, 73, 3, 44, 45, 70, 75, 0, 13, 40, 4, 87, 30, 7, 50, 34, 59, 22, 17, 41, 71, 10, 29, 89, 36, 31, 52, 9, 2, 51, 28, 61, 21, 1, 15, 72, 84, 88, 79, 19, 27, 63, 55, 83, 57, 18, 5, 12, 37, 16, 49, 8, 6, 65, 32, 20, 47, 82, 42, 33, 81, 58, 35, 67, 48, 74, 78, 85, 14, 68, 43, 25, 46, 69, 76, 64, 38, 54, 66, 60]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[26, 11, 62, 24, 56, 80, 39, 77, 23, 86, 53, 73, 3, 44, 45, 70, 75, 0, 13, 40, 4, 87, 30, 7, 50, 34, 59, 22, 17, 41, 71, 10, 29, 89, 36, 31, 52, 9, 2, 51, 28, 61, 21, 1, 15, 72, 84, 88, 79, 19, 27, 63, 55, 83, 57, 18, 5, 12, 37, 16, 49, 8, 6, 65, 32, 20, 47, 82, 42, 33, 81, 58, 35, 67, 48, 74, 78, 85, 14, 68, 43, 25, 46, 69, 76, 64, 38, 54, 66, 60]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 }, { - "name": "StrIndex2_0", - "sat": "def sat(big_str: str, sub_str=\"foobar\", index=2):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"foobar\", index=2):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "FindProductiveList:0", + "sat": "def sat(li: List[int], n=18):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=18):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_1", - "sat": "def sat(big_str: str, sub_str=\"quadox\", index=75):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"quadox\", index=75):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "FindProductiveList:1", + "sat": "def sat(li: List[int], n=3):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=3):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_2", - "sat": "def sat(big_str: str, sub_str=\"votextymuvethic\", index=880):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"votextymuvethic\", index=880):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "FindProductiveList:2", + "sat": "def sat(li: List[int], n=6):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=6):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_3", - "sat": "def sat(big_str: str, sub_str=\"pyrumymasekalihochyvibisamaquythifedetextityvath\", index=0):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"pyrumymasekalihochyvibisamaquythifedetextityvath\", index=0):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "FindProductiveList:3", + "sat": "def sat(li: List[int], n=9):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=9):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_4", - "sat": "def sat(big_str: str, sub_str=\"nofufaxunetextesitocedezyxuxexyfoquichitiracyquat\", index=185):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"nofufaxunetextesitocedezyxuxexyfoquichitiracyquat\", index=185):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "FindProductiveList:4", + "sat": "def sat(li: List[int], n=12):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=12):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_5", - "sat": "def sat(big_str: str, sub_str=\"xu\", index=825):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"xu\", index=825):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "HalfTag:0", + "sat": "def sat(li: List[int], tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_6", - "sat": "def sat(big_str: str, sub_str=\"cuhysepytextyhymochuxirirukawexyrifefirich\", index=137):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"cuhysepytextyhymochuxirirukawexyrifefirich\", index=137):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "HalfTag:1", + "sat": "def sat(li: List[int], tags=[2, 3, 1, 0, 3, 3, 0, 2, 1, 3, 1, 0, 1, 2, 2, 0]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[2, 3, 1, 0, 3, 3, 0, 2, 1, 3, 1, 0, 1, 2, 2, 0]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_7", - "sat": "def sat(big_str: str, sub_str=\"mewyzasyhevorythyhuhytharache\", index=731):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"mewyzasyhevorythyhuhytharache\", index=731):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "HalfTag:2", + "sat": "def sat(li: List[int], tags=[4, 1, 6, 5, 6, 4, 2, 1, 6, 2, 3, 1, 4, 6, 5, 2, 3, 5, 0, 5, 0, 3, 0, 0, 4, 2, 3, 1]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[4, 1, 6, 5, 6, 4, 2, 1, 6, 2, 3, 1, 4, 6, 5, 2, 3, 5, 0, 5, 0, 3, 0, 0, 4, 2, 3, 1]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_8", - "sat": "def sat(big_str: str, sub_str=\"thutusatuboquofikuhynatextizynotextoratexticuwapu\", index=21):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"thutusatuboquofikuhynatextizynotextoratexticuwapu\", index=21):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "HalfTag:3", + "sat": "def sat(li: List[int], tags=[0, 2, 1, 1, 1, 1, 2, 2, 0, 0, 0, 2]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[0, 2, 1, 1, 1, 1, 2, 2, 0, 0, 0, 2]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIndex2_9", - "sat": "def sat(big_str: str, sub_str=\"mothetextuxelibochyhikygigysolitynevapidi\", index=165):\n \"\"\"Find a string whose *first* index of sub_str is index\"\"\"\n return big_str.index(sub_str) == index", - "sols": [ - "def sol(sub_str=\"mothetextuxelibochyhikygigysolitynevapidi\", index=165):\n i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + "name": "HalfTag:4", + "sat": "def sat(li: List[int], tags=[1, 2, 6, 0, 6, 2, 4, 7, 4, 0, 0, 5, 0, 3, 2, 1, 7, 5, 5, 3, 1, 7, 2, 7, 6, 6, 3, 3, 1, 4, 4, 5]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[1, 2, 6, 0, 6, 2, 4, 7, 4, 0, 0, 5, 0, 3, 2, 1, 7, 5, 5, 3, 1, 7, 2, 7, 6, 6, 3, 3, 1, 4, 4, 5]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 }, { - "name": "StrIn_0", - "sat": "def sat(s: str, a=\"hello\", b=\"yellow\", length=4):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"hello\", b=\"yellow\", length=4):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "LearnParity:0", + "sat": "def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 1.0 }, { - "name": "StrIn_1", - "sat": "def sat(s: str, a=\"vuzogaguzechicowejeguthemeralic\", b=\"kybyjifidoquifwejeguthemelihitextodeju\", length=11):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"vuzogaguzechicowejeguthemeralic\", b=\"kybyjifidoquifwejeguthemelihitextodeju\", length=11):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "LearnParity:1", + "sat": "def sat(inds: List[int], vecs=[1958328232218124020, 1643963198527225549, 7078739564566717736, 5024292785179305436, 7542959674027422755, 7659875763009862123, 1092205956673651924, 1597643013927748621, 8004819259007286467, 4932826233956818838, 6008121031475439847, 8573976126290476773, 5118247667071056636, 2694646426329419247, 7155733006249399377, 5712876295003741481, 4259768476395554763, 1716249993608899326, 4687736672428229301, 6210681778471018663, 9062452952374764930, 3938723877971063326, 1992502139321214948, 583369363030182394, 3457048586868388189, 3089092548449370843, 8968870310908511767, 5874530422138404750, 7922800580005142654, 6443496666193763033, 6602916053749454337, 5035040733581952127, 2475911752718112891, 4473209659299430662, 7743622118433343293, 8456447367870793728, 644758190253851892, 854623538268336285, 4412207913445082380, 1836729508450597237, 8168398572945385599, 8115567202327609458, 6194127909595936682, 5497664877254277127, 3302554889776464399, 169133116278786893, 6157732824159736422, 6607461935760996261, 2653530464165680377, 6097504979385382936, 7193369373130246620, 5417605562101462110, 6648984412934108645, 8700023834459359946, 1861165113396388865, 2257883046437023829, 9079372065509233820, 68562947383617624, 3628292069813906054, 5937308782381616795, 7333187108059679183, 3810197266775096468, 6798325309591425591, 4704339148457093019, 7860858474470684593, 1611780128804878195, 8654679384628229346, 8183430433492711995, 6645671523533669548, 8558081500613788587, 7159783655071677682, 812798558819423092]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[1958328232218124020, 1643963198527225549, 7078739564566717736, 5024292785179305436, 7542959674027422755, 7659875763009862123, 1092205956673651924, 1597643013927748621, 8004819259007286467, 4932826233956818838, 6008121031475439847, 8573976126290476773, 5118247667071056636, 2694646426329419247, 7155733006249399377, 5712876295003741481, 4259768476395554763, 1716249993608899326, 4687736672428229301, 6210681778471018663, 9062452952374764930, 3938723877971063326, 1992502139321214948, 583369363030182394, 3457048586868388189, 3089092548449370843, 8968870310908511767, 5874530422138404750, 7922800580005142654, 6443496666193763033, 6602916053749454337, 5035040733581952127, 2475911752718112891, 4473209659299430662, 7743622118433343293, 8456447367870793728, 644758190253851892, 854623538268336285, 4412207913445082380, 1836729508450597237, 8168398572945385599, 8115567202327609458, 6194127909595936682, 5497664877254277127, 3302554889776464399, 169133116278786893, 6157732824159736422, 6607461935760996261, 2653530464165680377, 6097504979385382936, 7193369373130246620, 5417605562101462110, 6648984412934108645, 8700023834459359946, 1861165113396388865, 2257883046437023829, 9079372065509233820, 68562947383617624, 3628292069813906054, 5937308782381616795, 7333187108059679183, 3810197266775096468, 6798325309591425591, 4704339148457093019, 7860858474470684593, 1611780128804878195, 8654679384628229346, 8183430433492711995, 6645671523533669548, 8558081500613788587, 7159783655071677682, 812798558819423092]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 10.0 }, { - "name": "StrIn_2", - "sat": "def sat(s: str, a=\"kehorithxyfurexatextoxivuquunusethawatextebu\", b=\"pxyfurexatextoxivuquuwynicixo\", length=20):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"kehorithxyfurexatextoxivuquunusethawatextebu\", b=\"pxyfurexatextoxivuquuwynicixo\", length=20):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "LearnParity:2", + "sat": "def sat(inds: List[int], vecs=[22, 30, 1, 28, 28, 12, 20, 28, 6, 14, 14, 6, 1, 12]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[22, 30, 1, 28, 28, 12, 20, 28, 6, 14, 14, 6, 1, 12]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 1.0 }, { - "name": "StrIn_3", - "sat": "def sat(s: str, a=\"bafywihequyjicivicharyquynikixuhinyqu\", b=\"syrapetagecvicharyquynirorazecheth\", length=12):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"bafywihequyjicivicharyquynikixuhinyqu\", b=\"syrapetagecvicharyquynirorazecheth\", length=12):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "LearnParity:3", + "sat": "def sat(inds: List[int], vecs=[5, 6, 9, 55, 6, 31, 6, 16, 24, 41, 48, 28, 52, 23, 27]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[5, 6, 9, 55, 6, 31, 6, 16, 24, 41, 48, 28, 52, 23, 27]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 1.0 }, { - "name": "StrIn_4", - "sat": "def sat(s: str, a=\"diquatextaxubowafucevyhuquuthexitacavobychajexytextug\", b=\"thachevolatvyhuquuthexitacavobyjokobuchudymal\", length=20):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"diquatextaxubowafucevyhuquuthexitacavobychajexytextug\", b=\"thachevolatvyhuquuthexitacavobyjokobuchudymal\", length=20):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "LearnParity:4", + "sat": "def sat(inds: List[int], vecs=[8516734225993, 8185100182945, 925681191808, 6852758827443, 1647526447482, 7173415494645, 7272627207575, 490684374058, 309453951198, 5010777449329, 3573909388048, 5418552144685, 2354966949738, 3516400490509, 1958065498191, 4517527902759, 8040889847030, 5932888153522, 1902421695527, 1024437640956, 929625005771, 7393117046567, 5563161916036, 217261697321, 6156537114007, 2387336255324, 2725651274113, 8047481621773, 6241870535779, 6997209576680, 7206687196929, 7040183664174, 5422186929747, 8413033840571, 8315880876934, 3242378478727, 7554967308490, 3436019794305, 2038166434726, 276174723638, 4876351900994, 2206273239244, 6687501613941, 6284647259481, 4489528628587, 2300167942640, 1193551771601, 5445384214694, 4685093545143, 1178537925748, 8564249470306, 6913390362890]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[8516734225993, 8185100182945, 925681191808, 6852758827443, 1647526447482, 7173415494645, 7272627207575, 490684374058, 309453951198, 5010777449329, 3573909388048, 5418552144685, 2354966949738, 3516400490509, 1958065498191, 4517527902759, 8040889847030, 5932888153522, 1902421695527, 1024437640956, 929625005771, 7393117046567, 5563161916036, 217261697321, 6156537114007, 2387336255324, 2725651274113, 8047481621773, 6241870535779, 6997209576680, 7206687196929, 7040183664174, 5422186929747, 8413033840571, 8315880876934, 3242378478727, 7554967308490, 3436019794305, 2038166434726, 276174723638, 4876351900994, 2206273239244, 6687501613941, 6284647259481, 4489528628587, 2300167942640, 1193551771601, 5445384214694, 4685093545143, 1178537925748, 8564249470306, 6913390362890]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 10.0 + }, + { + "name": "LearnParityWithNoise:0", + "sat": "def sat(inds: List[int], vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [ + " # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n max_attempts = 10 ** 5\n for _ in range(max_attempts):\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" + ], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$\n\nThe example puzzle has small dimension so is easily solvable, but other instances are much harder.", + "weight": 1.0 + }, + { + "name": "LearnParityWithNoise:1", + "sat": "def sat(inds: List[int], vecs=[3026078031409368634, 7146400157417466997, 5230715399550451735, 5711439032267145442, 7548327835869100414, 6708827919346401215, 3738394021903457634, 8572217357536520619, 2068990701252216912, 2527297846676040375, 8268732787978254795, 61203570143025212, 7342810871883169101, 5130109338028331308, 7559050022362805022, 4688300453824606274, 6132540541907873970, 4336830827866175311, 4658177358737495247, 5084071062462878715, 189501720066641238, 8940114256708424722, 5113924146720829221, 4787179834139114336, 4911869756119486218, 8254870450128749041, 4438177035195637074, 5842829643884011320, 4053162460261950208, 2418313591679938260, 3183962173259338720, 5424349679395645015, 8721363683850881601, 4309489519137374818, 4668810188571429750, 1619719991930582198, 7466888377266384808, 9012877516210312432, 5806707934012633661, 4901689063540216433, 5129789419720858519, 5461292526835029654, 8002292066627476387, 22896265023092245, 6377528370731564059, 8326396311104510171, 6275763356808207618, 5855722006919947060, 5284812396814908585, 4183862905187398029, 961125315693824082, 3066435959716339320, 4359457050975539676, 3745610113055211253, 5616892323431402644, 2423996313938618029, 3342319460472332063, 4574429521762476750, 530929890003939982, 6518361635319838485, 4705876417632921613, 8702130161668730198, 7903182592921575528, 141670616557704814, 6302770439830462635, 8261043567365748099, 438838480425402424, 5938030420618506624, 6388919631545923446, 6289510808724564483, 6268010263591290952, 14114260020922590, 7967256030154091406, 7834360030773781051, 7195168470041102120, 2144111587187695127, 4188284497153593189, 7490392562013822833, 2395367579472417027, 1234942756280497811, 149618691938860164, 7115847656533661705, 2829618956277039440, 2931490206384957203, 6476287337767581762, 945977554281930779, 8036974190540567032, 5620546732979542987, 7534852936547208732, 3612963124933737363, 3304259407192763500, 6531357621325258614, 2061695547096959296, 3891046108540743566, 3659303839675510400, 2840571068268977729, 6021300208671005128, 5523531622352728473, 3164481775218709281, 1433373373144701739, 5040760773694741353, 8699918547789986541, 9211723439219092053, 3601466436760036882, 7470213384180375061, 1117614654415514338, 6489709663619239074, 5606821764793080769, 5533040684385323261, 1663669870068057261, 117658820550690687, 5802967177524872313, 824677791803551085, 8130960541536503068, 7941328653734718836, 3551730520657107195, 3183297803310667173, 1744452363855034208, 2206249608643212372, 6805671707252313743, 3765414947444962371, 6871722428624542946, 5429903326499666841, 9118768768355899725, 2775018401536039120, 2838922854846376990, 3633686101842554817, 7756171914139767657, 1797750566355726798, 1145745704236160436, 7192058872525801155]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[3026078031409368634, 7146400157417466997, 5230715399550451735, 5711439032267145442, 7548327835869100414, 6708827919346401215, 3738394021903457634, 8572217357536520619, 2068990701252216912, 2527297846676040375, 8268732787978254795, 61203570143025212, 7342810871883169101, 5130109338028331308, 7559050022362805022, 4688300453824606274, 6132540541907873970, 4336830827866175311, 4658177358737495247, 5084071062462878715, 189501720066641238, 8940114256708424722, 5113924146720829221, 4787179834139114336, 4911869756119486218, 8254870450128749041, 4438177035195637074, 5842829643884011320, 4053162460261950208, 2418313591679938260, 3183962173259338720, 5424349679395645015, 8721363683850881601, 4309489519137374818, 4668810188571429750, 1619719991930582198, 7466888377266384808, 9012877516210312432, 5806707934012633661, 4901689063540216433, 5129789419720858519, 5461292526835029654, 8002292066627476387, 22896265023092245, 6377528370731564059, 8326396311104510171, 6275763356808207618, 5855722006919947060, 5284812396814908585, 4183862905187398029, 961125315693824082, 3066435959716339320, 4359457050975539676, 3745610113055211253, 5616892323431402644, 2423996313938618029, 3342319460472332063, 4574429521762476750, 530929890003939982, 6518361635319838485, 4705876417632921613, 8702130161668730198, 7903182592921575528, 141670616557704814, 6302770439830462635, 8261043567365748099, 438838480425402424, 5938030420618506624, 6388919631545923446, 6289510808724564483, 6268010263591290952, 14114260020922590, 7967256030154091406, 7834360030773781051, 7195168470041102120, 2144111587187695127, 4188284497153593189, 7490392562013822833, 2395367579472417027, 1234942756280497811, 149618691938860164, 7115847656533661705, 2829618956277039440, 2931490206384957203, 6476287337767581762, 945977554281930779, 8036974190540567032, 5620546732979542987, 7534852936547208732, 3612963124933737363, 3304259407192763500, 6531357621325258614, 2061695547096959296, 3891046108540743566, 3659303839675510400, 2840571068268977729, 6021300208671005128, 5523531622352728473, 3164481775218709281, 1433373373144701739, 5040760773694741353, 8699918547789986541, 9211723439219092053, 3601466436760036882, 7470213384180375061, 1117614654415514338, 6489709663619239074, 5606821764793080769, 5533040684385323261, 1663669870068057261, 117658820550690687, 5802967177524872313, 824677791803551085, 8130960541536503068, 7941328653734718836, 3551730520657107195, 3183297803310667173, 1744452363855034208, 2206249608643212372, 6805671707252313743, 3765414947444962371, 6871722428624542946, 5429903326499666841, 9118768768355899725, 2775018401536039120, 2838922854846376990, 3633686101842554817, 7756171914139767657, 1797750566355726798, 1145745704236160436, 7192058872525801155]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$\n\nThe example puzzle has small dimension so is easily solvable, but other instances are much harder.", + "weight": 1000.0 + }, + { + "name": "LearnParityWithNoise:2", + "sat": "def sat(inds: List[int], vecs=[576, 823, 480, 899, 652, 1017, 830, 125, 627, 889, 312, 663, 232, 856, 664, 594, 423, 810, 740, 828, 605, 580, 450, 905, 348]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[576, 823, 480, 899, 652, 1017, 830, 125, 627, 889, 312, 663, 232, 856, 664, 594, 423, 810, 740, 828, 605, 580, 450, 905, 348]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [ + " # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n max_attempts = 10 ** 5\n for _ in range(max_attempts):\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" + ], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$\n\nThe example puzzle has small dimension so is easily solvable, but other instances are much harder.", + "weight": 1.0 + }, + { + "name": "LearnParityWithNoise:3", + "sat": "def sat(inds: List[int], vecs=[378, 819, 695, 649, 492, 277, 471, 241, 159, 733, 625, 355, 300, 241, 683, 445, 769, 167, 985, 346, 243, 546, 851, 476, 309]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[378, 819, 695, 649, 492, 277, 471, 241, 159, 733, 625, 355, 300, 241, 683, 445, 769, 167, 985, 346, 243, 546, 851, 476, 309]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [ + " # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n max_attempts = 10 ** 5\n for _ in range(max_attempts):\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" + ], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$\n\nThe example puzzle has small dimension so is easily solvable, but other instances are much harder.", + "weight": 1.0 + }, + { + "name": "LearnParityWithNoise:4", + "sat": "def sat(inds: List[int], vecs=[5, 7, 4, 5, 4, 3, 6, 5, 5, 0, 7]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[5, 7, 4, 5, 4, 3, 6, 5, 5, 0, 7]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [ + " # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n max_attempts = 10 ** 5\n for _ in range(max_attempts):\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" + ], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$\n\nThe example puzzle has small dimension so is easily solvable, but other instances are much harder.", + "weight": 1.0 + }, + { + "name": "FermatsLastTheorem:0", + "sat": "def sat(nums: List[int]):\n a, b, c, n = nums\n return (a ** n + b ** n == c ** n) and min(a, b, c) > 0 and n > 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find integers a,b,c > 0, n > 2, such such that a^n + b^n == c^n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "[Fermat's last theorem](https://en.wikipedia.org/w/index.php?title=Fermat%27s_Last_Theorem)\n\nSupposedly unsolvable, but how confident are really in the super-complicated proof?\n\nSee [Wiles, Andrew. \"Modular elliptic curves and Fermat's last theorem.\" Annals of mathematics 141.3 (1995): 443-551.](https://www.jstor.org/stable/2118559)", + "weight": 1.0 }, { - "name": "StrIn_5", - "sat": "def sat(s: str, a=\"sasawizequebetojothagtextejichykelas\", b=\"gulunytextafyzywofuxjothagratextobukile\", length=6):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"sasawizequebetojothagtextejichykelas\", b=\"gulunytextafyzywofuxjothagratextobukile\", length=6):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "GCD:0", + "sat": "def sat(n: int, a=15482, b=23223, lower_bound=5):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=15482, b=23223, lower_bound=5):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn_6", - "sat": "def sat(s: str, a=\"konywexuvytenvihechivydochomobuzuchoquul\", b=\"zivihechivydochomobukorywo\", length=18):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"konywexuvytenvihechivydochomobuzuchoquul\", b=\"zivihechivydochomobukorywo\", length=18):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "GCD:1", + "sat": "def sat(n: int, a=9, b=9, lower_bound=6):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=9, b=9, lower_bound=6):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn_7", - "sat": "def sat(s: str, a=\"cywizutextmucythahyquizifovatex\", b=\"kazedysylmucythazypypacupebive\", length=7):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"cywizutextmucythahyquizifovatex\", b=\"kazedysylmucythazypypacupebive\", length=7):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "GCD:2", + "sat": "def sat(n: int, a=232610, b=3131721474, lower_bound=15000):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=232610, b=3131721474, lower_bound=15000):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn_8", - "sat": "def sat(s: str, a=\"gavajyjopivbisotextureve\", b=\"femalezequachuvefvkylucunabun\", length=1):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"gavajyjopivbisotextureve\", b=\"femalezequachuvefvkylucunabun\", length=1):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "GCD:3", + "sat": "def sat(n: int, a=247586288427023352, b=372021520735824432, lower_bound=1709054537):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=247586288427023352, b=372021520735824432, lower_bound=1709054537):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn_9", - "sat": "def sat(s: str, a=\"pefethulomuluxisifnivyjilixyhederagyworyto\", b=\"nijolenivydojyvuzodu\", length=4):\n \"\"\"Find a string of length length that is in both strings a and b\"\"\"\n return len(s) == length and s in a and s in b", - "sols": [ - "def sol(a=\"pefethulomuluxisifnivyjilixyhederagyworyto\", b=\"nijolenivydojyvuzodu\", length=4):\n for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + "name": "GCD:4", + "sat": "def sat(n: int, a=8797233, b=2370036150831, lower_bound=8364173):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=8797233, b=2370036150831, lower_bound=8364173):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_0", - "sat": "def sat(substrings: List[str], s=\"hello\", count=15):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"hello\", count=15):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "GCD_multi:0", + "sat": "def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[77410, 23223, 54187], lower_bound=2):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_1", - "sat": "def sat(substrings: List[str], s=\"rywixekugagethathulisitextanyp\", count=451):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"rywixekugagethathulisitextanyp\", count=451):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "GCD_multi:1", + "sat": "def sat(n: int, nums=[14, 551755893, 902110495], lower_bound=1):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[14, 551755893, 902110495], lower_bound=1):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_2", - "sat": "def sat(substrings: List[str], s=\"xetyvezitajithiban\", count=165):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"xetyvezitajithiban\", count=165):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "GCD_multi:2", + "sat": "def sat(n: int, nums=[287260676668, 33263981357337, 47314720, 295717, 2957170], lower_bound=98647):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[287260676668, 33263981357337, 47314720, 295717, 2957170], lower_bound=98647):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_3", - "sat": "def sat(substrings: List[str], s=\"rofegakusaquybemydomimibyzodycetextunoce\", count=799):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"rofegakusaquybemydomimibyzodycetextunoce\", count=799):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "GCD_multi:3", + "sat": "def sat(n: int, nums=[452452, 111673658096, 83221402264, 5027670648, 61177116, 154154, 116116, 1508784124848, 17036343324, 29091062, 100726626], lower_bound=977):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[452452, 111673658096, 83221402264, 5027670648, 61177116, 154154, 116116, 1508784124848, 17036343324, 29091062, 100726626], lower_bound=977):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_4", - "sat": "def sat(substrings: List[str], s=\"thacyt\", count=21):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"thacyt\", count=21):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "GCD_multi:4", + "sat": "def sat(n: int, nums=[8154539588421190, 128861795], lower_bound=64216730):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[8154539588421190, 128861795], lower_bound=64216730):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_5", - "sat": "def sat(substrings: List[str], s=\"jahithotharathewythojyhechi\", count=356):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"jahithotharathewythojyhechi\", count=356):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "LCM:0", + "sat": "def sat(n: int, a=15, b=27, upper_bound=150):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=15, b=27, upper_bound=150):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_6", - "sat": "def sat(substrings: List[str], s=\"hyjilyguthokepucuciwutahaseb\", count=394):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"hyjilyguthokepucuciwutahaseb\", count=394):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "LCM:1", + "sat": "def sat(n: int, a=41234205765, b=597597185, upper_bound=73349253728):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=41234205765, b=597597185, upper_bound=73349253728):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_7", - "sat": "def sat(substrings: List[str], s=\"miposyjydatilel\", count=118):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"miposyjydatilel\", count=118):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "LCM:2", + "sat": "def sat(n: int, a=7601351956456, b=2974663988, upper_bound=389421039754872576):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=7601351956456, b=2974663988, upper_bound=389421039754872576):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_8", - "sat": "def sat(substrings: List[str], s=\"fef\", count=6):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"fef\", count=6):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "LCM:3", + "sat": "def sat(n: int, a=201717041833890, b=3585167190, upper_bound=731493653565433):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=201717041833890, b=3585167190, upper_bound=731493653565433):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrIn2_9", - "sat": "def sat(substrings: List[str], s=\"muhixupethinicygo\", count=149):\n \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", - "sols": [ - "def sol(s=\"muhixupethinicygo\", count=149):\n return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + "name": "LCM:4", + "sat": "def sat(n: int, a=79680, b=661339968, upper_bound=410128528659):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=79680, b=661339968, upper_bound=410128528659):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_0", - "sat": "def sat(string: str, substring=\"a\", count=10, length=100):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"a\", count=10, length=100):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "LCM_multi:0", + "sat": "def sat(n: int, nums=[15, 27, 102], upper_bound=5000):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[15, 27, 102], upper_bound=5000):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_1", - "sat": "def sat(string: str, substring=\"ky\", count=66, length=133):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"ky\", count=66, length=133):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "LCM_multi:1", + "sat": "def sat(n: int, nums=[46477686772963437, 15649966299, 37939312240, 14036122804591, 39209330717234], upper_bound=82396663973139497934429093888):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[46477686772963437, 15649966299, 37939312240, 14036122804591, 39209330717234], upper_bound=82396663973139497934429093888):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_2", - "sat": "def sat(string: str, substring=\"jepy\", count=87, length=650):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"jepy\", count=87, length=650):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "LCM_multi:2", + "sat": "def sat(n: int, nums=[55040126016, 4373970014334], upper_bound=219074883886936):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[55040126016, 4373970014334], upper_bound=219074883886936):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_3", - "sat": "def sat(string: str, substring=\"hothyfyt\", count=3, length=417):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"hothyfyt\", count=3, length=417):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "LCM_multi:3", + "sat": "def sat(n: int, nums=[9140, 4882496600, 119119770064, 107772494796, 102424668, 3656, 1188591500932, 116992, 14700627932, 997397016], upper_bound=238661269929569213628364588516267312050595558326272):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[9140, 4882496600, 119119770064, 107772494796, 102424668, 3656, 1188591500932, 116992, 14700627932, 997397016], upper_bound=238661269929569213628364588516267312050595558326272):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_4", - "sat": "def sat(string: str, substring=\"moz\", count=70, length=210):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"moz\", count=70, length=210):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "LCM_multi:4", + "sat": "def sat(n: int, nums=[173261568, 4270662976], upper_bound=17025943527197098):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[173261568, 4270662976], upper_bound=17025943527197098):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 }, { - "name": "StrCount_5", - "sat": "def sat(string: str, substring=\"p\", count=91, length=724):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"p\", count=91, length=724):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "SmallExponentBigSolution:0", + "sat": "def sat(n: int, b=2, target=5):\n return (b ** n) % n == target", + "ans_type": "int", + "sol_header": "def sol(b=2, target=5):", + "sol_docstring": " \"\"\"Solve for n: b^n = target (mod n)\"\"\"", + "sol_bodies": [ + " for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", + "weight": 1.0 }, { - "name": "StrCount_6", - "sat": "def sat(string: str, substring=\"k\", count=87, length=961):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"k\", count=87, length=961):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "SmallExponentBigSolution:1", + "sat": "def sat(n: int, b=2, target=3):\n return (b ** n) % n == target", + "ans_type": "int", + "sol_header": "def sol(b=2, target=3):", + "sol_docstring": " \"\"\"Solve for n: b^n = target (mod n)\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", + "weight": 1.0 }, { - "name": "StrCount_7", - "sat": "def sat(string: str, substring=\"b\", count=33, length=52):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"b\", count=33, length=52):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "SmallExponentBigSolution:2", + "sat": "def sat(n: int, b=1, target=2):\n return (b ** n) % n == target", + "ans_type": "int", + "sol_header": "def sol(b=1, target=2):", + "sol_docstring": " \"\"\"Solve for n: b^n = target (mod n)\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", + "weight": 1.0 }, { - "name": "StrCount_8", - "sat": "def sat(string: str, substring=\"xyfec\", count=16, length=237):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"xyfec\", count=16, length=237):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "SmallExponentBigSolution:3", + "sat": "def sat(n: int, b=69, target=2):\n return (b ** n) % n == target", + "ans_type": "int", + "sol_header": "def sol(b=69, target=2):", + "sol_docstring": " \"\"\"Solve for n: b^n = target (mod n)\"\"\"", + "sol_bodies": [ + " for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", + "weight": 1.0 }, { - "name": "StrCount_9", - "sat": "def sat(string: str, substring=\"w\", count=78, length=192):\n \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"\n return string.count(substring) == count and len(string) == length", - "sols": [ - "def sol(substring=\"w\", count=78, length=192):\n c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + "name": "ThreeCubes:0", + "sat": "def sat(nums: List[int], target=983):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=983):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [ + " assert target % 9 not in {4, 5}\n for i in range(20):\n for j in range(i + 1):\n for k in range(-20, j + 1):\n n = i ** 3 + j ** 3 + k ** 3\n if n == target:\n return [i, j, k]\n if n == -target:\n return [-i, -j, -k]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 }, { - "name": "StrSplit_0", - "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!'], length=100):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['I', 'love', 'dumplings', '!'], length=100):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "ThreeCubes:1", + "sat": "def sat(nums: List[int], target=114):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=114):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 }, { - "name": "StrSplit_1", - "sat": "def sat(x: str, parts=['thala', 'chaliriliq', 'chufyselikizap'], length=116):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['thala', 'chaliriliq', 'chufyselikizap'], length=116):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "ThreeCubes:2", + "sat": "def sat(nums: List[int], target=390):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=390):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 }, { - "name": "StrSplit_2", - "sat": "def sat(x: str, parts=['lepytextati', 'ki', 'fy'], length=69):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['lepytextati', 'ki', 'fy'], length=69):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "ThreeCubes:3", + "sat": "def sat(nums: List[int], target=579):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=579):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 }, { - "name": "StrSplit_3", - "sat": "def sat(x: str, parts=['quyhigechyhy'], length=38):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['quyhigechyhy'], length=38):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "ThreeCubes:4", + "sat": "def sat(nums: List[int], target=69294):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=69294):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 }, { - "name": "StrSplit_4", - "sat": "def sat(x: str, parts=['je', 'pojacyda', 'papucet', 'wesobaq'], length=40):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['je', 'pojacyda', 'papucet', 'wesobaq'], length=40):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" + "name": "FourSquares:0", + "sat": "def sat(nums: List[int], n=12345):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=12345):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [ + " m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 }, { - "name": "StrSplit_5", - "sat": "def sat(x: str, parts=['v'], length=71):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['v'], length=71):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" + "name": "FourSquares:1", + "sat": "def sat(nums: List[int], n=1):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=1):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [ + " m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 }, { - "name": "StrSplit_6", - "sat": "def sat(x: str, parts=['det', 'chythyvocovy', 'hoxuwoda'], length=51):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['det', 'chythyvocovy', 'hoxuwoda'], length=51):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" + "name": "FourSquares:2", + "sat": "def sat(nums: List[int], n=0):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=0):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [ + " m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 }, { - "name": "StrSplit_7", - "sat": "def sat(x: str, parts=['peh', 'vida', 'gylupowo', 'n'], length=84):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['peh', 'vida', 'gylupowo', 'n'], length=84):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "FourSquares:3", + "sat": "def sat(nums: List[int], n=1321806837666853665854863414407013350963513):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=1321806837666853665854863414407013350963513):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 }, { - "name": "StrSplit_8", - "sat": "def sat(x: str, parts=['guhufatextavy', 'fytextinizovaholi'], length=129):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['guhufatextavy', 'fytextinizovaholi'], length=129):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "FourSquares:4", + "sat": "def sat(nums: List[int], n=254723967601711775999551029856500295000994603):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=254723967601711775999551029856500295000994603):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 }, { - "name": "StrSplit_9", - "sat": "def sat(x: str, parts=['quu', 'xojamegefathilywo', 'sadajyfithywykajex'], length=48):\n \"\"\"Find a string of a given length with a certain split\"\"\"\n return len(x) == length and x.split() == parts", - "sols": [ - "def sol(parts=['quu', 'xojamegefathilywo', 'sadajyfithywykajex'], length=48):\n joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" + "name": "Factoring:0", + "sat": "def sat(i: int, n=241864633):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=241864633):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [ + " if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 }, { - "name": "StrSplitter_0", - "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Factoring:1", + "sat": "def sat(i: int, n=16):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=16):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [ + " if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 }, { - "name": "StrSplitter_1", - "sat": "def sat(x: str, parts=['kowot', 'quimimy'], string=\"kowottextihocavikirofegyfquimimy\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['kowot', 'quimimy'], string=\"kowottextihocavikirofegyfquimimy\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "Factoring:2", + "sat": "def sat(i: int, n=1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 }, { - "name": "StrSplitter_2", - "sat": "def sat(x: str, parts=['f', 'thixaresiquagipoquas', 'fytylu', 'jywaxaw'], string=\"fdetthixaresiquagipoquasdetfytyludetjywaxaw\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['f', 'thixaresiquagipoquas', 'fytylu', 'jywaxaw'], string=\"fdetthixaresiquagipoquasdetfytyludetjywaxaw\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "Factoring:3", + "sat": "def sat(i: int, n=35794234179725868774991807832568455403003778024228226193532908190484670252364677411513516111204504060317568667):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=35794234179725868774991807832568455403003778024228226193532908190484670252364677411513516111204504060317568667):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 }, { - "name": "StrSplitter_3", - "sat": "def sat(x: str, parts=['tibuzumurun', 'hakebixutextolonyf', 'bothuraquobara'], string=\"tibuzumurunhocyxihakebixutextolonyfhocyxibothuraquobara\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['tibuzumurun', 'hakebixutextolonyf', 'bothuraquobara'], string=\"tibuzumurunhocyxihakebixutextolonyfhocyxibothuraquobara\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Factoring:4", + "sat": "def sat(i: int, n=3363):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=3363):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [ + " if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 }, { - "name": "StrSplitter_4", - "sat": "def sat(x: str, parts=['fitextu', 'chythawequeku', 'th'], string=\"fitextufyhachochythawequekufyhachoth\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['fitextu', 'chythawequeku', 'th'], string=\"fitextufyhachochythawequekufyhachoth\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "DiscreteLog:0", + "sat": "def sat(n: int, g=44337, p=69337, t=38187):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=44337, p=69337, t=38187):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [ + " for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 }, { - "name": "StrSplitter_5", - "sat": "def sat(x: str, parts=['jegevavuchupuzyboqu', 'k', 'lewygicu'], string=\"jegevavuchupuzyboquretyxathikretyxathilewygicu\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['jegevavuchupuzyboqu', 'k', 'lewygicu'], string=\"jegevavuchupuzyboquretyxathikretyxathilewygicu\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "DiscreteLog:1", + "sat": "def sat(n: int, g=7, p=204706270385532838059744535166974274803608394340123459695798674591526591372685229510652847339705797622075505069831043486651682279, t=127402180119973946824269244334322849749382042586931621654557735290322914679095998681860978813046595166455458144280588076766033781):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=7, p=204706270385532838059744535166974274803608394340123459695798674591526591372685229510652847339705797622075505069831043486651682279, t=127402180119973946824269244334322849749382042586931621654557735290322914679095998681860978813046595166455458144280588076766033781):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 }, { - "name": "StrSplitter_6", - "sat": "def sat(x: str, parts=['nozajutex', 'hute', 'textugec'], string=\"nozajutexxuchutexuctextugec\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['nozajutex', 'hute', 'textugec'], string=\"nozajutexxuchutexuctextugec\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "DiscreteLog:2", + "sat": "def sat(n: int, g=13, p=21, t=1):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=13, p=21, t=1):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [ + " for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 }, { - "name": "StrSplitter_7", - "sat": "def sat(x: str, parts=['nathuchigegybobutex', 'chutextuf', 'gukotextocoquymethit', 'l'], string=\"nathuchigegybobutexretithysokyquujetechutextufretithysokyquujetegukotextocoquymethitretithysokyquujetel\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['nathuchigegybobutex', 'chutextuf', 'gukotextocoquymethit', 'l'], string=\"nathuchigegybobutexretithysokyquujetechutextufretithysokyquujetegukotextocoquymethitretithysokyquujetel\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "DiscreteLog:3", + "sat": "def sat(n: int, g=101873924449108026052, p=576036946901458671597, t=330515716425197141833):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=101873924449108026052, p=576036946901458671597, t=330515716425197141833):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 }, { - "name": "StrSplitter_8", - "sat": "def sat(x: str, parts=['s', 'textosytextemeg', 'pimetojijimosylaga'], string=\"sthethycofahatextextosytextemegthethycofahatexpimetojijimosylaga\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['s', 'textosytextemeg', 'pimetojijimosylaga'], string=\"sthethycofahatextextosytextemegthethycofahatexpimetojijimosylaga\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "DiscreteLog:4", + "sat": "def sat(n: int, g=1696881788, p=8006168143, t=7111327686):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=1696881788, p=8006168143, t=7111327686):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 }, { - "name": "StrSplitter_9", - "sat": "def sat(x: str, parts=['quetext', 'chyhegunixehitoquira', 'cemek'], string=\"quetextxycawyvesylojochyhegunixehitoquiraxycawyvesylojocemek\"):\n \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"\n return string.split(x) == parts", - "sols": [ - "def sol(parts=['quetext', 'chyhegunixehitoquira', 'cemek'], string=\"quetextxycawyvesylojochyhegunixehitoquiraxycawyvesylojocemek\"):\n if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "GCD17:0", + "sat": "def sat(n: int):\n i = n ** 17 + 9\n j = (n + 1) ** 17 + 9\n\n while i != 0: # compute gcd using Euclid's algorithm\n (i, j) = (j % i, i)\n\n return n >= 0 and j != 1", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find n for which gcd(n^17+9, (n+1)^17+9) != 1\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "According to [this article](https://primes.utm.edu/glossary/page.php?sort=LawOfSmall), the smallest\nsolution is 8424432925592889329288197322308900672459420460792433", + "weight": 1.0 }, { - "name": "StrJoiner_0", - "sat": "def sat(x: str, parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Znam:0", + "sat": "def sat(li: List[int], k=5):\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", + "ans_type": "List[int]", + "sol_header": "def sol(k=5):", + "sol_docstring": " \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"", + "sol_bodies": [ + " n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", + "weight": 1.0 }, { - "name": "StrJoiner_1", - "sat": "def sat(x: str, parts=['tatext'], string=\"tatext\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['tatext'], string=\"tatext\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Znam:1", + "sat": "def sat(li: List[int], k=6):\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", + "ans_type": "List[int]", + "sol_header": "def sol(k=6):", + "sol_docstring": " \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"", + "sol_bodies": [ + " n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", + "weight": 1.0 }, { - "name": "StrJoiner_2", - "sat": "def sat(x: str, parts: List[str]=[], string=\"\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=[], string=\"\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Znam:2", + "sat": "def sat(li: List[int], k=7):\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", + "ans_type": "List[int]", + "sol_header": "def sol(k=7):", + "sol_docstring": " \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"", + "sol_bodies": [ + " n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", + "weight": 1.0 }, { - "name": "StrJoiner_3", - "sat": "def sat(x: str, parts=['ruquug'], string=\"ruquug\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['ruquug'], string=\"ruquug\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "Znam:3", + "sat": "def sat(li: List[int], k=8):\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", + "ans_type": "List[int]", + "sol_header": "def sol(k=8):", + "sol_docstring": " \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"", + "sol_bodies": [ + " n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", + "weight": 1.0 }, { - "name": "StrJoiner_4", - "sat": "def sat(x: str, parts=['numegixuly', 'koxyfihimurukothasyl'], string=\"numegixulypyjetkoxyfihimurukothasyl\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['numegixuly', 'koxyfihimurukothasyl'], string=\"numegixulypyjetkoxyfihimurukothasyl\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "CollatzCycleUnsolved:0", + "sat": "def sat(n: int):\n m = n\n while n > 4:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == m:\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n > 4 which is part of a cycle of this process\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Collatz Conjecture\n\nA solution to this problem would disprove the *Collatz Conjecture*, also called the *3n + 1 problem*,\nas well as the *Generalized Collatz Conjecture* (see the next problem).\nAccording to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture):\n> Paul Erdos said about the Collatz conjecture: \"Mathematics may not be ready for such problems.\"\n> He also offered US$500 for its solution. Jeffrey Lagarias stated in 2010 that the Collatz conjecture\n> \"is an extraordinarily difficult problem, completely out of reach of present day mathematics.\"\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\n\nThe conjecture is to that all `n > 0` eventually reach `n=1`. If this conjecture is false, then\nthere is either a cycle or a sequence that increases without bound. This problem seeks a cycle.", + "weight": 1.0 }, { - "name": "StrJoiner_5", - "sat": "def sat(x: str, parts=['dyvachukache', 'ladovenyquecilaziset', 'jybuchoxih', 'requasidyk'], string=\"dyvachukachekybirihewezuchobytujladovenyquecilazisetkybirihewezuchobytujjybuchoxihkybirihewezuchobytujrequasidyk\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['dyvachukache', 'ladovenyquecilaziset', 'jybuchoxih', 'requasidyk'], string=\"dyvachukachekybirihewezuchobytujladovenyquecilazisetkybirihewezuchobytujjybuchoxihkybirihewezuchobytujrequasidyk\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "CollatzGeneralizedUnsolved:0", + "sat": "def sat(start: int):\n n = start # could be positive or negative ...\n while abs(n) > 1000:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == start:\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n which is part of a cycle of this process that has |n| > 1000\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Generalized Collatz Conjecture\n\nThis version, permits negative n and seek a cycle with a number of magnitude greater than 1000,\nwhich would disprove the Generalized conjecture that states that the only cycles are the known 5 cycles\n(which don't have positive integers).\n\nSee the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)", + "weight": 1.0 }, { - "name": "StrJoiner_6", - "sat": "def sat(x: str, parts=['lulate'], string=\"lulate\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['lulate'], string=\"lulate\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + "name": "CollatzDelay:0", + "sat": "def sat(n: int, t=197, upper=20):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "ans_type": "int", + "sol_header": "def sol(t=197, upper=20):", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"", + "sol_bodies": [ + " # Faster solution for simultaneously solving multiple problems is of course possible\n bound = t + 10\n while True:\n bound *= 2\n prev = {1}\n seen = set()\n for delay in range(t):\n seen.update(prev)\n curr = {2 * n for n in prev}\n curr.update({(n - 1) // 3 for n in prev if n % 6 == 4})\n prev = {n for n in curr if n <= bound} - seen\n if prev:\n return min(prev)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", + "weight": 1.0 }, { - "name": "StrJoiner_7", - "sat": "def sat(x: str, parts=['kyhelytextif', 'jakematext'], string=\"kyhelytextifgathatufyjakematext\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['kyhelytextif', 'jakematext'], string=\"kyhelytextifgathatufyjakematext\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "CollatzDelay:1", + "sat": "def sat(n: int, t=1000, upper=150):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "ans_type": "int", + "sol_header": "def sol(t=1000, upper=150):", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", + "weight": 1.0 }, { - "name": "StrJoiner_8", - "sat": "def sat(x: str, parts=['xatezetextet'], string=\"xatezetextet\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['xatezetextet'], string=\"xatezetextet\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "CollatzDelay:2", + "sat": "def sat(n: int, t=2000, upper=206):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "ans_type": "int", + "sol_header": "def sol(t=2000, upper=206):", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", + "weight": 1.0 }, { - "name": "StrJoiner_9", - "sat": "def sat(x: str, parts=['cugalufexyz', 'notyd', 'tosydufademyhelydich'], string=\"cugalufexyzgachyfechawanyzunotydgachyfechawanyzutosydufademyhelydich\"):\n \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"\n return x.join(parts) == string", - "sols": [ - "def sol(parts=['cugalufexyz', 'notyd', 'tosydufademyhelydich'], string=\"cugalufexyzgachyfechawanyzunotydgachyfechawanyzutosydufademyhelydich\"):\n if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "CollatzDelay:3", + "sat": "def sat(n: int, t=2283, upper=238):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "ans_type": "int", + "sol_header": "def sol(t=2283, upper=238):", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", + "weight": 1.0 }, { - "name": "StrParts_0", - "sat": "def sat(parts: List[str], sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):\n return string.split(sep)" + "name": "Lehmer:0", + "sat": "def sat(n: int):\n return pow(2, n, n) == 3", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find n such that 2^n mod n = 3\"\"\"", + "sol_bodies": [ + " return 4700063497" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "number_theory.py", + "notes": "Lehmer puzzle\n\nAccording to [The Strong Law of Large Numbers](https://doi.org/10.2307/2322249) Richard K. Guy states that\n D. H. & Emma Lehmer discovered that 2^n = 3 (mod n) for n = 4700063497,\n but for no smaller n > 1", + "weight": 1.0 }, { - "name": "StrParts_1", - "sat": "def sat(parts: List[str], sep=\"jachasurobithu\", string=\"watalachyquujachasurobithuba\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"jachasurobithu\", string=\"watalachyquujachasurobithuba\"):\n return string.split(sep)" + "name": "BirthdayParadox:0", + "sat": "def sat(n: int, year_len=365):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=365):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", + "weight": 1.0 }, { - "name": "StrParts_2", - "sat": "def sat(parts: List[str], sep=\"xusoquyvamathila\", string=\"bolifotinuwywyjochxusoquyvamathilazyvuxusoquyvamathilanifajatextethxusoquyvamathilafocharatefymoji\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"xusoquyvamathila\", string=\"bolifotinuwywyjochxusoquyvamathilazyvuxusoquyvamathilanifajatextethxusoquyvamathilafocharatefymoji\"):\n return string.split(sep)" + "name": "BirthdayParadox:1", + "sat": "def sat(n: int, year_len=60182):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=60182):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", + "weight": 1.0 }, { - "name": "StrParts_3", - "sat": "def sat(parts: List[str], sep=\"chixachal\", string=\"\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"chixachal\", string=\"\"):\n return string.split(sep)" + "name": "BirthdayParadox:2", + "sat": "def sat(n: int, year_len=2):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=2):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", + "weight": 1.0 }, { - "name": "StrParts_4", - "sat": "def sat(parts: List[str], sep=\"lochuv\", string=\"biflochuvzulothanodugedusilochuvlilochuvhobegikofero\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"lochuv\", string=\"biflochuvzulothanodugedusilochuvlilochuvhobegikofero\"):\n return string.split(sep)" + "name": "BirthdayParadox:3", + "sat": "def sat(n: int, year_len=3):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=3):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", + "weight": 1.0 }, { - "name": "StrParts_5", - "sat": "def sat(parts: List[str], sep=\"finoz\", string=\"\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"finoz\", string=\"\"):\n return string.split(sep)" + "name": "BirthdayParadoxMonteCarlo:0", + "sat": "def sat(n: int, year_len=365):\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=365):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", + "weight": 1.0 }, { - "name": "StrParts_6", - "sat": "def sat(parts: List[str], sep=\"baxef\", string=\"wunetextamoquebaxefjycilathachibyco\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"baxef\", string=\"wunetextamoquebaxefjycilathachibyco\"):\n return string.split(sep)" + "name": "BirthdayParadoxMonteCarlo:1", + "sat": "def sat(n: int, year_len=60182):\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=60182):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", + "weight": 1.0 }, { - "name": "StrParts_7", - "sat": "def sat(parts: List[str], sep=\"t\", string=\"\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"t\", string=\"\"):\n return string.split(sep)" + "name": "BirthdayParadoxMonteCarlo:2", + "sat": "def sat(n: int, year_len=2):\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=2):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", + "weight": 1.0 }, { - "name": "StrParts_8", - "sat": "def sat(parts: List[str], sep=\"sidyrychorujuvopymac\", string=\"\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"sidyrychorujuvopymac\", string=\"\"):\n return string.split(sep)" + "name": "BirthdayParadoxMonteCarlo:3", + "sat": "def sat(n: int, year_len=3):\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=3):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", + "weight": 1.0 }, { - "name": "StrParts_9", - "sat": "def sat(parts: List[str], sep=\"noluduzukyviti\", string=\"\"):\n \"\"\"Find parts that when joined give a specific string.\"\"\"\n return sep.join(parts) == string and all(sep not in p for p in parts)", - "sols": [ - "def sol(sep=\"noluduzukyviti\", string=\"\"):\n return string.split(sep)" + "name": "BallotProblem:0", + "sat": "def sat(counts: List[int], target_prob=0.5):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.5):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 }, { - "name": "ListSetLen_0", - "sat": "def sat(li: List[int], dups=42155):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=42155):\n return [1] * (dups + 1)" + "name": "BallotProblem:1", + "sat": "def sat(counts: List[int], target_prob=0.1791044776119403):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.1791044776119403):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 }, { - "name": "ListSetLen_1", - "sat": "def sat(li: List[int], dups=18793):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=18793):\n return [1] * (dups + 1)" + "name": "BallotProblem:2", + "sat": "def sat(counts: List[int], target_prob=0.03125):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.03125):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 }, { - "name": "ListSetLen_2", - "sat": "def sat(li: List[int], dups=70976):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=70976):\n return [1] * (dups + 1)" + "name": "BallotProblem:3", + "sat": "def sat(counts: List[int], target_prob=0.5803571428571429):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.5803571428571429):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 }, { - "name": "ListSetLen_3", - "sat": "def sat(li: List[int], dups=23476):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=23476):\n return [1] * (dups + 1)" + "name": "BallotProblem:4", + "sat": "def sat(counts: List[int], target_prob=0.7142857142857143):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.7142857142857143):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 }, { - "name": "ListSetLen_4", - "sat": "def sat(li: List[int], dups=17633):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=17633):\n return [1] * (dups + 1)" + "name": "BinomialProbabilities:0", + "sat": "def sat(counts: List[int], p=0.5, target_prob=0.0625):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.5, target_prob=0.0625):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 }, { - "name": "ListSetLen_5", - "sat": "def sat(li: List[int], dups=74086):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=74086):\n return [1] * (dups + 1)" + "name": "BinomialProbabilities:1", + "sat": "def sat(counts: List[int], p=0.7588822808660473, target_prob=0.41658075878732215):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.7588822808660473, target_prob=0.41658075878732215):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 }, { - "name": "ListSetLen_6", - "sat": "def sat(li: List[int], dups=8612):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=8612):\n return [1] * (dups + 1)" + "name": "BinomialProbabilities:2", + "sat": "def sat(counts: List[int], p=0.6569421516251613, target_prob=0.01872902529162693):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.6569421516251613, target_prob=0.01872902529162693):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 }, { - "name": "ListSetLen_7", - "sat": "def sat(li: List[int], dups=1740):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=1740):\n return [1] * (dups + 1)" + "name": "BinomialProbabilities:3", + "sat": "def sat(counts: List[int], p=0.20001220211746595, target_prob=0.13419930454361995):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.20001220211746595, target_prob=0.13419930454361995):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 }, { - "name": "ListSetLen_8", - "sat": "def sat(li: List[int], dups=52799):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=52799):\n return [1] * (dups + 1)" + "name": "BinomialProbabilities:4", + "sat": "def sat(counts: List[int], p=0.004837079863490135, target_prob=3.5517791266002235e-13):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.004837079863490135, target_prob=3.5517791266002235e-13):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 }, { - "name": "ListSetLen_9", - "sat": "def sat(li: List[int], dups=29174):\n \"\"\"Find a list with a certain number of duplicate items\"\"\"\n return len(set(li)) == len(li) - dups", - "sols": [ - "def sol(dups=29174):\n return [1] * (dups + 1)" + "name": "ExponentialProbability:0", + "sat": "def sat(p_stop: float, steps=10, target_prob=0.5):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=10, target_prob=0.5):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 }, { - "name": "ListMul_0", - "sat": "def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[17, 9, -1, 17, 9, -1], n=2):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "ExponentialProbability:1", + "sat": "def sat(p_stop: float, steps=43, target_prob=0.2661542669448821):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=43, target_prob=0.2661542669448821):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 }, { - "name": "ListMul_1", - "sat": "def sat(li: List[int], target=[-69358, -69358, -69358, -69358, -69358, -69358, -69358], n=7):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-69358, -69358, -69358, -69358, -69358, -69358, -69358], n=7):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "ExponentialProbability:2", + "sat": "def sat(p_stop: float, steps=91, target_prob=0.03729141037377781):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=91, target_prob=0.03729141037377781):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 }, { - "name": "ListMul_2", - "sat": "def sat(li: List[int], target=[-51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344], n=8):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344], n=8):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "ExponentialProbability:3", + "sat": "def sat(p_stop: float, steps=11, target_prob=0.9742781783529525):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=11, target_prob=0.9742781783529525):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 }, { - "name": "ListMul_3", - "sat": "def sat(li: List[int], target: List[int]=[], n=0):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[], n=0):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "ExponentialProbability:4", + "sat": "def sat(p_stop: float, steps=65, target_prob=0.8318555442956944):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=65, target_prob=0.8318555442956944):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 }, { - "name": "ListMul_4", - "sat": "def sat(li: List[int], target=[-25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766], n=4):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766], n=4):\n if n == 0:\n return []\n return target[:len(target) // n]" - ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "name": "HelloWorld:0", + "sat": "def sat(s: str):\n return s + 'world' == 'Hello world'", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when concatenated onto 'world' gives 'Hello world'.\"\"\"", + "sol_bodies": [], + "module": "trivial_inverse.py", + "notes": "Trivial example, no solutions provided", + "weight": 0.2 }, { - "name": "ListMul_5", - "sat": "def sat(li: List[int], target=[-48426, -78083, -6462, 87501, -24814, -86588, -34478, 27926, 47601, -48426, -78083, -6462, 87501, -24814, -86588, -34478, 27926, 47601], n=2):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-48426, -78083, -6462, 87501, -24814, -86588, -34478, 27926, 47601, -48426, -78083, -6462, 87501, -24814, -86588, -34478, 27926, 47601], n=2):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "BackWorlds:0", + "sat": "def sat(s: str):\n return s[::-1] + 'world' == 'Hello world'", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when reversed and concatenated onto 'world' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return ' olleH'", + " # solution methods must begin with 'sol'\n return 'Hello '[::-1]" ], - "module": "trivial_inverse", - "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "module": "trivial_inverse.py", + "notes": "We provide two solutions", + "weight": 0.2 }, { - "name": "ListMul_6", - "sat": "def sat(li: List[int], target=[23970, 23970, 23970, 23970], n=4):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[23970, 23970, 23970, 23970], n=4):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "StrAdd:0", + "sat": "def sat(st: str, a=\"world\", b=\"Hello world\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"world\", b=\"Hello world\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListMul_7", - "sat": "def sat(li: List[int], target=[-88188, 74911, 56756, -88188, 74911, 56756], n=2):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-88188, 74911, 56756, -88188, 74911, 56756], n=2):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "StrAdd:1", + "sat": "def sat(st: str, a=\"zine\", b=\"cerofilimybazine\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"zine\", b=\"cerofilimybazine\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListMul_8", - "sat": "def sat(li: List[int], target=[-70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789], n=7):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789, -70052, -10087, 34113, -52629, -88131, 25789], n=7):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "StrAdd:2", + "sat": "def sat(st: str, a=\"id\", b=\"xakid\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"id\", b=\"xakid\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListMul_9", - "sat": "def sat(li: List[int], target=[-54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480], n=8):\n \"\"\"Find a list that when multiplied n times gives the target list\"\"\"\n return li * n == target", - "sols": [ - "def sol(target=[-54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480, -54499, 17154, 83480], n=8):\n if n == 0:\n return []\n return target[:len(target) // n]" + "name": "StrAdd:3", + "sat": "def sat(st: str, a=\"dyr\", b=\"dyr\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"dyr\", b=\"dyr\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_0", - "sat": "def sat(li: List[int], n=85012):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=85012):\n return [1] * n" + "name": "StrAdd:4", + "sat": "def sat(st: str, a=\"s\", b=\"tos\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"s\", b=\"tos\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_1", - "sat": "def sat(li: List[int], n=969):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=969):\n return [1] * n" + "name": "StrSetLen:0", + "sat": "def sat(s: str, dups=2021):\n return len(set(s)) == len(s) - dups", + "ans_type": "str", + "sol_header": "def sol(dups=2021):", + "sol_docstring": " \"\"\"Find a string with dups duplicate chars\"\"\"", + "sol_bodies": [ + " return \"a\" * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_2", - "sat": "def sat(li: List[int], n=7051):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=7051):\n return [1] * n" + "name": "StrSetLen:1", + "sat": "def sat(s: str, dups=0):\n return len(set(s)) == len(s) - dups", + "ans_type": "str", + "sol_header": "def sol(dups=0):", + "sol_docstring": " \"\"\"Find a string with dups duplicate chars\"\"\"", + "sol_bodies": [ + " return \"a\" * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_3", - "sat": "def sat(li: List[int], n=9):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=9):\n return [1] * n" + "name": "StrSetLen:2", + "sat": "def sat(s: str, dups=1):\n return len(set(s)) == len(s) - dups", + "ans_type": "str", + "sol_header": "def sol(dups=1):", + "sol_docstring": " \"\"\"Find a string with dups duplicate chars\"\"\"", + "sol_bodies": [ + " return \"a\" * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_4", - "sat": "def sat(li: List[int], n=324):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=324):\n return [1] * n" + "name": "StrSetLen:3", + "sat": "def sat(s: str, dups=2):\n return len(set(s)) == len(s) - dups", + "ans_type": "str", + "sol_header": "def sol(dups=2):", + "sol_docstring": " \"\"\"Find a string with dups duplicate chars\"\"\"", + "sol_bodies": [ + " return \"a\" * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_5", - "sat": "def sat(li: List[int], n=893):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=893):\n return [1] * n" + "name": "StrMul:0", + "sat": "def sat(s: str, target=\"foofoofoofoo\", n=2):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"foofoofoofoo\", n=2):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_6", - "sat": "def sat(li: List[int], n=3):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=3):\n return [1] * n" + "name": "StrMul:1", + "sat": "def sat(s: str, target=\"biquacagegichisykbiquacagegichisykbiquacagegichisyk\", n=3):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"biquacagegichisykbiquacagegichisykbiquacagegichisyk\", n=3):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_7", - "sat": "def sat(li: List[int], n=166):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=166):\n return [1] * n" + "name": "StrMul:2", + "sat": "def sat(s: str, target=\"hutextogoxanithiru\", n=1):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"hutextogoxanithiru\", n=1):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_8", - "sat": "def sat(li: List[int], n=702):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=702):\n return [1] * n" + "name": "StrMul:3", + "sat": "def sat(s: str, target=\"sisisisisisisisisisisisisisi\", n=7):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"sisisisisisisisisisisisisisi\", n=7):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListLen_9", - "sat": "def sat(li: List[int], n=8):\n \"\"\"Find a list of a given length n\"\"\"\n return len(li) == n", - "sols": [ - "def sol(n=8):\n return [1] * n" + "name": "StrMul:4", + "sat": "def sat(s: str, target=\"fuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxe\", n=7):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"fuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxefuchomurybaxe\", n=7):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_0", - "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18):\n return li.index(target)" + "name": "StrMul2:0", + "sat": "def sat(n: int, target=\"foofoofoofoo\", s=\"foofoo\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"foofoofoofoo\", s=\"foofoo\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_1", - "sat": "def sat(i: int, li=[-62, -29, 73, -21, -45, -20, -74, -69, 30, -25, 16, 82, -31, 93, -20, 75, 68, 86], target=73):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[-62, -29, 73, -21, -45, -20, -74, -69, 30, -25, 16, 82, -31, 93, -20, 75, 68, 86], target=73):\n return li.index(target)" + "name": "StrMul2:1", + "sat": "def sat(n: int, target=\"\", s=\"jan\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"\", s=\"jan\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_2", - "sat": "def sat(i: int, li=[99, 51, -28, -69, -90, -15, 7, -67], target=51):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[99, 51, -28, -69, -90, -15, 7, -67], target=51):\n return li.index(target)" + "name": "StrMul2:2", + "sat": "def sat(n: int, target=\"koquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyc\", s=\"koquuwibehyc\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"koquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyckoquuwibehyc\", s=\"koquuwibehyc\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_3", - "sat": "def sat(i: int, li=[-68, 81, 13, -5, 81, 75, -3, -73, -89, 72], target=13):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[-68, 81, 13, -5, 81, 75, -3, -73, -89, 72], target=13):\n return li.index(target)" + "name": "StrMul2:3", + "sat": "def sat(n: int, target=\"kasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyz\", s=\"kasujyzkasujyz\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"kasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyzkasujyz\", s=\"kasujyzkasujyz\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_4", - "sat": "def sat(i: int, li=[51, -68, -57, 8, 77, -80, -28, -24, 11, 40, 57, 60, 53], target=11):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[51, -68, -57, 8, 77, -80, -28, -24, 11, 40, 57, 60, 53], target=11):\n return li.index(target)" + "name": "StrMul2:4", + "sat": "def sat(n: int, target=\"kedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuth\", s=\"kedezygijithequuthkedezygijithequuth\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"kedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuthkedezygijithequuth\", s=\"kedezygijithequuthkedezygijithequuth\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_5", - "sat": "def sat(i: int, li=[36], target=36):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[36], target=36):\n return li.index(target)" + "name": "StrLen:0", + "sat": "def sat(s: str, n=1000):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=1000):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_6", - "sat": "def sat(i: int, li=[-85, 33, 55, -18, -90, 13, -88, -1, 40, -6, -41, -31, -47], target=-88):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[-85, 33, 55, -18, -90, 13, -88, -1, 40, -6, -41, -31, -47], target=-88):\n return li.index(target)" + "name": "StrLen:1", + "sat": "def sat(s: str, n=39):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=39):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_7", - "sat": "def sat(i: int, li=[41, 14], target=41):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[41, 14], target=41):\n return li.index(target)" + "name": "StrLen:2", + "sat": "def sat(s: str, n=790):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=790):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_8", - "sat": "def sat(i: int, li=[-83, 33, -81, -86, -89, -50, -71, -30, 47, -27, -66, -3, 22, 84, -11, 19, -6], target=33):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[-83, 33, -81, -86, -89, -50, -71, -30, 47, -27, -66, -3, 22, 84, -11, 19, -6], target=33):\n return li.index(target)" + "name": "StrLen:3", + "sat": "def sat(s: str, n=485):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=485):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListAt_9", - "sat": "def sat(i: int, li=[-64, 22, -61, 75], target=-61):\n \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"\n return li[i] == target", - "sols": [ - "def sol(li=[-64, 22, -61, 75], target=-61):\n return li.index(target)" + "name": "StrLen:4", + "sat": "def sat(s: str, n=4031):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=4031):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_0", - "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91):\n return li.index(target) - len(li)" + "name": "StrAt:0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_1", - "sat": "def sat(i: int, li=[78, 91, -67, -5, 30, -42, 68, 32, 96, -55, -39, -46, 90], target=-39):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[78, 91, -67, -5, 30, -42, 68, 32, 96, -55, -39, -46, 90], target=-39):\n return li.index(target) - len(li)" + "name": "StrAt:1", + "sat": "def sat(i: int, s=\"quadyquady\", target=\"a\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"quadyquady\", target=\"a\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_2", - "sat": "def sat(i: int, li=[-60, 9, 1, -42, 31, 70, 5, 1, 42, -90, -20], target=-42):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[-60, 9, 1, -42, 31, 70, 5, 1, 42, -90, -20], target=-42):\n return li.index(target) - len(li)" + "name": "StrAt:2", + "sat": "def sat(i: int, s=\"quixatextofazejate\", target=\"i\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"quixatextofazejate\", target=\"i\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_3", - "sat": "def sat(i: int, li=[41, -52, -40, -35, 53, -98, 83, 63, -18, 74, -8, -93, -3, 22, 30], target=53):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[41, -52, -40, -35, 53, -98, 83, 63, -18, 74, -8, -93, -3, 22, 30], target=53):\n return li.index(target) - len(li)" + "name": "StrAt:3", + "sat": "def sat(i: int, s=\"thethe\", target=\"e\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"thethe\", target=\"e\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_4", - "sat": "def sat(i: int, li=[95, 51, 76, 63, -97, -32], target=-32):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[95, 51, 76, 63, -97, -32], target=-32):\n return li.index(target) - len(li)" + "name": "StrAt:4", + "sat": "def sat(i: int, s=\"bucudibucudibucudi\", target=\"b\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"bucudibucudibucudi\", target=\"b\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_5", - "sat": "def sat(i: int, li=[36, -29, 36, 76, -73, 87], target=-73):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[36, -29, 36, 76, -73, 87], target=-73):\n return li.index(target) - len(li)" + "name": "StrNegAt:0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_6", - "sat": "def sat(i: int, li=[-80, -85, -6, -63, -20, -64, -77, 2, 37, -47, 50, -61, 35, 98, 6, 63, -14], target=6):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[-80, -85, -6, -63, -20, -64, -77, 2, 37, -47, 50, -61, 35, 98, 6, 63, -14], target=6):\n return li.index(target) - len(li)" + "name": "StrNegAt:1", + "sat": "def sat(i: int, s=\"ch\", target=\"c\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"ch\", target=\"c\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_7", - "sat": "def sat(i: int, li=[-20, 67, 53, 73, -60, 23, -55, 47], target=-20):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[-20, 67, 53, 73, -60, 23, -55, 47], target=-20):\n return li.index(target) - len(li)" + "name": "StrNegAt:2", + "sat": "def sat(i: int, s=\"nydivimocuvacetext\", target=\"y\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"nydivimocuvacetext\", target=\"y\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_8", - "sat": "def sat(i: int, li=[14, 16, 91, 34, -60, -39, 12, 10, 48, 64, -10, 63, 24, 49, -3, -34, -86], target=34):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[14, 16, 91, 34, -60, -39, 12, 10, 48, 64, -10, 63, 24, 49, -3, -34, -86], target=34):\n return li.index(target) - len(li)" + "name": "StrNegAt:3", + "sat": "def sat(i: int, s=\"chyxchyx\", target=\"x\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"chyxchyx\", target=\"x\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListNegAt_9", - "sat": "def sat(i: int, li=[31, -38, 97, 81, -43, -12, -23, 20, 43, 71, 55, 87, 23, -42], target=87):\n \"\"\"Find the index of an item in a list using negative indexing.\"\"\"\n return li[i] == target and i < 0", - "sols": [ - "def sol(li=[31, -38, 97, 81, -43, -12, -23, 20, 43, 71, 55, 87, 23, -42], target=87):\n return li.index(target) - len(li)" + "name": "StrNegAt:4", + "sat": "def sat(i: int, s=\"tuchuworyquofojyzusutuchuworyquofojyzusutuchuworyquofojyzusu\", target=\"h\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"tuchuworyquofojyzusutuchuworyquofojyzusutuchuworyquofojyzusu\", target=\"h\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_0", - "sat": "def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrSlice:0", + "sat": "def sat(inds: List[int], s=\"hello world\", target=\"do\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"hello world\", target=\"do\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_1", - "sat": "def sat(inds: List[int], li=[-11, 92, 42, 18, -83, 55, 13, 14, -67, -58, -41], target=[-67]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[-11, 92, 42, 18, -83, 55, 13, 14, -67, -58, -41], target=[-67]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrSlice:1", + "sat": "def sat(inds: List[int], s=\"ninykofiwimninykofiwim\", target=\"\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"ninykofiwimninykofiwim\", target=\"\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_2", - "sat": "def sat(inds: List[int], li=[-53, -81, -92, 22, -67], target=[-53, -81, -92]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[-53, -81, -92, 22, -67], target=[-53, -81, -92]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrSlice:2", + "sat": "def sat(inds: List[int], s=\"limerybinylimerybiny\", target=\"n\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"limerybinylimerybiny\", target=\"n\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_3", - "sat": "def sat(inds: List[int], li=[-72, 70, 50, -41, 94, -82, -74, 8, -23], target=[-82]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[-72, 70, 50, -41, 94, -82, -74, 8, -23], target=[-82]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrSlice:3", + "sat": "def sat(inds: List[int], s=\"fyzihurothevirechahfyzihurothevirechah\", target=\"\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"fyzihurothevirechahfyzihurothevirechah\", target=\"\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_4", - "sat": "def sat(inds: List[int], li=[26, -25, -18, -53, 18, -71, -82, 20, -100, -84, -85], target=[-25]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[26, -25, -18, -53, 18, -71, -82, 20, -100, -84, -85], target=[-25]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrSlice:4", + "sat": "def sat(inds: List[int], s=\"kibozekiboze\", target=\"\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"kibozekiboze\", target=\"\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_5", - "sat": "def sat(inds: List[int], li=[65, -22, -94, 3, -20, 67], target=[65, -22, -94]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[65, -22, -94, 3, -20, 67], target=[65, -22, -94]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrIndex:0", + "sat": "def sat(s: str, big_str=\"foobar\", index=2):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"foobar\", index=2):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_6", - "sat": "def sat(inds: List[int], li=[-38, -24, -15, -59, -32, -91, -55, -45, 44, 35, 93, 38, -67, -73, 93], target=[-32]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[-38, -24, -15, -59, -32, -91, -55, -45, 44, 35, 93, 38, -67, -73, 93], target=[-32]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrIndex:1", + "sat": "def sat(s: str, big_str=\"fukulagatextuj\", index=10):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"fukulagatextuj\", index=10):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_7", - "sat": "def sat(inds: List[int], li=[92, -38, 6, -95, -79, -59, -51, 80, 71, -20, -40, -85, -80, -91, -67, -83, -40], target=[-80]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[92, -38, 6, -95, -79, -59, -51, 80, 71, -20, -40, -85, -80, -91, -67, -83, -40], target=[-80]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrIndex:2", + "sat": "def sat(s: str, big_str=\"nunalurejijunopyrewithocukopojot\", index=12):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"nunalurejijunopyrewithocukopojot\", index=12):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_8", - "sat": "def sat(inds: List[int], li=[-54, -16, -65, -13], target=[-13]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[-54, -16, -65, -13], target=[-13]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrIndex:3", + "sat": "def sat(s: str, big_str=\"fu\", index=1):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"fu\", index=1):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListSlice_9", - "sat": "def sat(inds: List[int], li=[41, -86, -41, 4, 58, -71, 45, 18, -97, -44, -67, -36, 30, 86, -54], target=[45]):\n \"\"\"Find three slice indices to achieve a given list slice\"\"\"\n i, j, k = inds\n return li[i:j:k] == target", - "sols": [ - "def sol(li=[41, -86, -41, 4, 58, -71, 45, 18, -97, -44, -67, -36, 30, 86, -54], target=[45]):\n from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + "name": "StrIndex:4", + "sat": "def sat(s: str, big_str=\"fatextemedyrotichipicecojon\", index=24):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"fatextemedyrotichipicecojon\", index=24):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_0", - "sat": "def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[17, 2, 3, 9, 11, 11], index=4):\n return li[index]" + "name": "StrIndex2:0", + "sat": "def sat(big_str: str, sub_str=\"foobar\", index=2):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"foobar\", index=2):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_1", - "sat": "def sat(item: int, li=[93, -13, -56, 19], index=2):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[93, -13, -56, 19], index=2):\n return li[index]" + "name": "StrIndex2:1", + "sat": "def sat(big_str: str, sub_str=\"quadox\", index=75):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"quadox\", index=75):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_2", - "sat": "def sat(item: int, li=[-79, 49, 4, -75, -66, -76, 37, -62, -35, -79, 68, 82, -11, -71, 63, -82, 22, 65], index=2):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[-79, 49, 4, -75, -66, -76, 37, -62, -35, -79, 68, 82, -11, -71, 63, -82, 22, 65], index=2):\n return li[index]" + "name": "StrIndex2:2", + "sat": "def sat(big_str: str, sub_str=\"votextymuvethic\", index=880):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"votextymuvethic\", index=880):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_3", - "sat": "def sat(item: int, li=[96, -61, 50, -49, -1, -23, -35], index=3):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[96, -61, 50, -49, -1, -23, -35], index=3):\n return li[index]" + "name": "StrIndex2:3", + "sat": "def sat(big_str: str, sub_str=\"pyrumymasekalihochyvibisamaquythifedetextityvath\", index=0):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"pyrumymasekalihochyvibisamaquythifedetextityvath\", index=0):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_4", - "sat": "def sat(item: int, li=[26, -90, 89], index=0):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[26, -90, 89], index=0):\n return li[index]" + "name": "StrIndex2:4", + "sat": "def sat(big_str: str, sub_str=\"nofufaxunetextesitocedezyxuxexyfoquichitiracyquat\", index=185):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"nofufaxunetextesitocedezyxuxexyfoquichitiracyquat\", index=185):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_5", - "sat": "def sat(item: int, li=[87, -88, 84, -52, -92, 37, -41, 18, 5, 26, 54, -79, 1, 11, 97], index=14):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[87, -88, 84, -52, -92, 37, -41, 18, 5, 26, 54, -79, 1, 11, 97], index=14):\n return li[index]" + "name": "StrIn:0", + "sat": "def sat(s: str, a=\"hello\", b=\"yellow\", length=4):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"hello\", b=\"yellow\", length=4):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_6", - "sat": "def sat(item: int, li=[-78], index=0):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[-78], index=0):\n return li[index]" + "name": "StrIn:1", + "sat": "def sat(s: str, a=\"vuzogaguzechicowejeguthemeralic\", b=\"kybyjifidoquifwejeguthemelihitextodeju\", length=11):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"vuzogaguzechicowejeguthemeralic\", b=\"kybyjifidoquifwejeguthemelihitextodeju\", length=11):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_7", - "sat": "def sat(item: int, li=[-16, -96, -36, 25, 66, -17, -98, -79, -51, -16, -24, -71, 1, -10, -30, -52, -2], index=5):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[-16, -96, -36, 25, 66, -17, -98, -79, -51, -16, -24, -71, 1, -10, -30, -52, -2], index=5):\n return li[index]" + "name": "StrIn:2", + "sat": "def sat(s: str, a=\"kehorithxyfurexatextoxivuquunusethawatextebu\", b=\"pxyfurexatextoxivuquuwynicixo\", length=20):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"kehorithxyfurexatextoxivuquunusethawatextebu\", b=\"pxyfurexatextoxivuquuwynicixo\", length=20):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_8", - "sat": "def sat(item: int, li=[-43, 9], index=0):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[-43, 9], index=0):\n return li[index]" + "name": "StrIn:3", + "sat": "def sat(s: str, a=\"bafywihequyjicivicharyquynikixuhinyqu\", b=\"syrapetagecvicharyquynirorazecheth\", length=12):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"bafywihequyjicivicharyquynikixuhinyqu\", b=\"syrapetagecvicharyquynirorazecheth\", length=12):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex_9", - "sat": "def sat(item: int, li=[59, 0, -90, 66, 21, 67], index=0):\n \"\"\"Find the item whose first index in li is index\"\"\"\n return li.index(item) == index", - "sols": [ - "def sol(li=[59, 0, -90, 66, 21, 67], index=0):\n return li[index]" + "name": "StrIn:4", + "sat": "def sat(s: str, a=\"diquatextaxubowafucevyhuquuthexitacavobychajexytextug\", b=\"thachevolatvyhuquuthexitacavobyjokobuchudymal\", length=20):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"diquatextaxubowafucevyhuquuthexitacavobychajexytextug\", b=\"thachevolatvyhuquuthexitacavobyjokobuchudymal\", length=20):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_0", - "sat": "def sat(li: List[int], i=29, index=10412):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=29, index=10412):\n return [i - 1] * index + [i]" + "name": "StrIn2:0", + "sat": "def sat(substrings: List[str], s=\"hello\", count=15):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"hello\", count=15):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_1", - "sat": "def sat(li: List[int], i=-99167, index=48792):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=-99167, index=48792):\n return [i - 1] * index + [i]" + "name": "StrIn2:1", + "sat": "def sat(substrings: List[str], s=\"rywixekugagethathulisitextanyp\", count=451):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"rywixekugagethathulisitextanyp\", count=451):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_2", - "sat": "def sat(li: List[int], i=-67679, index=87059):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=-67679, index=87059):\n return [i - 1] * index + [i]" + "name": "StrIn2:2", + "sat": "def sat(substrings: List[str], s=\"xetyvezitajithiban\", count=165):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"xetyvezitajithiban\", count=165):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_3", - "sat": "def sat(li: List[int], i=81395, index=79231):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=81395, index=79231):\n return [i - 1] * index + [i]" + "name": "StrIn2:3", + "sat": "def sat(substrings: List[str], s=\"rofegakusaquybemydomimibyzodycetextunoce\", count=799):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"rofegakusaquybemydomimibyzodycetextunoce\", count=799):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_4", - "sat": "def sat(li: List[int], i=63344, index=1583):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=63344, index=1583):\n return [i - 1] * index + [i]" + "name": "StrIn2:4", + "sat": "def sat(substrings: List[str], s=\"thacyt\", count=21):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"thacyt\", count=21):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_5", - "sat": "def sat(li: List[int], i=-22545, index=83757):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=-22545, index=83757):\n return [i - 1] * index + [i]" + "name": "StrCount:0", + "sat": "def sat(string: str, substring=\"a\", count=10, length=100):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"a\", count=10, length=100):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_6", - "sat": "def sat(li: List[int], i=-50200, index=90147):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=-50200, index=90147):\n return [i - 1] * index + [i]" + "name": "StrCount:1", + "sat": "def sat(string: str, substring=\"ky\", count=66, length=133):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"ky\", count=66, length=133):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_7", - "sat": "def sat(li: List[int], i=-17099, index=34646):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=-17099, index=34646):\n return [i - 1] * index + [i]" + "name": "StrCount:2", + "sat": "def sat(string: str, substring=\"jepy\", count=87, length=650):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"jepy\", count=87, length=650):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_8", - "sat": "def sat(li: List[int], i=51149, index=61676):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=51149, index=61676):\n return [i - 1] * index + [i]" + "name": "StrCount:3", + "sat": "def sat(string: str, substring=\"hothyfyt\", count=3, length=417):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"hothyfyt\", count=3, length=417):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIndex2_9", - "sat": "def sat(li: List[int], i=80068, index=26514):\n \"\"\"Find a list that contains i first at index index\"\"\"\n return li.index(i) == index", - "sols": [ - "def sol(i=80068, index=26514):\n return [i - 1] * index + [i]" + "name": "StrCount:4", + "sat": "def sat(string: str, substring=\"moz\", count=70, length=210):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"moz\", count=70, length=210):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_0", - "sat": "def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):\n return next(s for s in b if s in a)" + "name": "StrSplit:0", + "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!'], length=100):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['I', 'love', 'dumplings', '!'], length=100):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_1", - "sat": "def sat(s: str, a=['xetex', 'jomuboxuc', 'nyfiranuri', 'curu', 'jehykexethinun', 'bumekynuxinit', 'cymelatabegi', 'jumuvufotextasa', 'cotharasyfukakiwoc', 'fuvyvavi', 'gohavelomet', 'hibymomotohywehathi', 'jyzucakaq', 'chihyx', 'wukikogy', 'pegydozetebegafugyf', 'chywadetextekesyjup', 'xysecaw', 'ryzafusul', 'lojychurep', 'vivutolimifa', 'pysiquikywoty', 'thitexturykasoquifet', 'va', 'nagetextilac', 'tex', 'zechocha', 'susatexty', 'ch'], b=['vesaredu', 'textyjun', 'hijilenafotycoch', 'fofytextulidajekymos', 'thudothukuzaxug', 'dythezutolihibinafyj', 'hadid', 'zyly', 'mu', 'chywadetextekesyjup', 'zekyrivequi', 'pebycipohivam', 'texterekuwudut', 'c', 'sanidithuh', 'ritextuchik', 'ny', 'cym', 'cirok', 'kavuquithochazethej', 'zikechep', 'kesitabuduzu', 'duchequ', 'fuluhesowyjugehusab', 'tof', 'tu', 'textichagekochoquovo', 'bo', 'thac', 'hytextac', 'nerehufymex', 'jezyletextiquebositi', 'm', 'kathithowefyvoced', 'rityjivoxadydyzatiq', 'nuxaritutebacygevyq', 'thyjaxirumenaquuxy', 'gizydylot', 'textite', 'guchikek', 'fas', 'pabipapiro', 'fechiduchu', 'pexijis', 'gojep', 'quinatextit', 'chaqu', 'xyxyjos', 'pudibothytigiwumucex', 'josadubizy', 'jy', 'komazibomapothequev', 'licogatextuliletuxi', 'gus', 'nylyxyjibikimet', 'tafo']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['xetex', 'jomuboxuc', 'nyfiranuri', 'curu', 'jehykexethinun', 'bumekynuxinit', 'cymelatabegi', 'jumuvufotextasa', 'cotharasyfukakiwoc', 'fuvyvavi', 'gohavelomet', 'hibymomotohywehathi', 'jyzucakaq', 'chihyx', 'wukikogy', 'pegydozetebegafugyf', 'chywadetextekesyjup', 'xysecaw', 'ryzafusul', 'lojychurep', 'vivutolimifa', 'pysiquikywoty', 'thitexturykasoquifet', 'va', 'nagetextilac', 'tex', 'zechocha', 'susatexty', 'ch'], b=['vesaredu', 'textyjun', 'hijilenafotycoch', 'fofytextulidajekymos', 'thudothukuzaxug', 'dythezutolihibinafyj', 'hadid', 'zyly', 'mu', 'chywadetextekesyjup', 'zekyrivequi', 'pebycipohivam', 'texterekuwudut', 'c', 'sanidithuh', 'ritextuchik', 'ny', 'cym', 'cirok', 'kavuquithochazethej', 'zikechep', 'kesitabuduzu', 'duchequ', 'fuluhesowyjugehusab', 'tof', 'tu', 'textichagekochoquovo', 'bo', 'thac', 'hytextac', 'nerehufymex', 'jezyletextiquebositi', 'm', 'kathithowefyvoced', 'rityjivoxadydyzatiq', 'nuxaritutebacygevyq', 'thyjaxirumenaquuxy', 'gizydylot', 'textite', 'guchikek', 'fas', 'pabipapiro', 'fechiduchu', 'pexijis', 'gojep', 'quinatextit', 'chaqu', 'xyxyjos', 'pudibothytigiwumucex', 'josadubizy', 'jy', 'komazibomapothequev', 'licogatextuliletuxi', 'gus', 'nylyxyjibikimet', 'tafo']):\n return next(s for s in b if s in a)" + "name": "StrSplit:1", + "sat": "def sat(x: str, parts=['thala', 'chaliriliq', 'chufyselikizap'], length=116):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['thala', 'chaliriliq', 'chufyselikizap'], length=116):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_2", - "sat": "def sat(s: str, a=['bututimatabel', 'zezahabiry', 'mipytext', 'bujokacyrulihir', 'cyvagofaquothoseza', 'guhebalequepytex', 'tyhithuthygatextity', 'chizichuc', 'textoxodenekokechona', 'texte', 'mygafifet', 'vixathokivy', 'xe', 'moq', 'quokopy', 'cixoka', 'wiz', 'wyturasutabidipif', 'q', 'gochujuvub', 'textogow', 'rogizasog', 'fimoxynudob', 'byjythohimowyquich', 'moduxatanogococ', 'tunuchikywichykyxyge', 'namixotextes', 'nocoguthosoxonahu', 'xorydyhi', 'dadohojex', 'pi', 'wiquocaso', 'tyjegu', 'juquath', 'dythufyn', 'sehafur', 'sylupivyzequefujet', 'hotextylyquahudivov', 'wunich', 'fijyhilyc', 'rirymequunezuv', 'zizunylihadowys', 'zesuxikevaquus', 'thecisequevyth', 'cucyquefytextu', 'xy', 'quuxin', 'miherahita', 'texatextoxyta', 'tythyjuly', 'tehesyju', 'reg', 'ridilusycanejap', 'fo', 'chucatazyrejucathibi', 'textythacete', 'huhiquekychyh', 'xykuvebylyhinyc', 'zadedixoxoparyducena', 'wycathomoniva', 'textuwuwathiziq', 'textijiw', 'rigidichukuchexorute', 'majixodokalij', 'hexebitoxumuvodese', 'hybat', 'thojutextomochote', 'textaxuquyg', 'queluhatex'], b=['gume', 'zatum', 'kochaxybupy', 'gex', 'vithiby', 'lygarethaquedehabub', 'tochek', 'v', 'wis', 'remywerinyboweropot', 'nybichychafizurup', 'zokabugyc', 'ny', 'moruwicoponuricuw', 'zirijikuhabivywah', 'dus', 'toxirit', 'gilanih', 'hif', 'vuhezobinehahewi', 'quujihus', 'chej', 'g', 'pypomaquiwusisyvuma', 'to', 'c', 'chutesumalanozeb', 'chupehozukiquodisese', 'xygiwot', 'semubaquav', 'pihiwidosudetextet', 'quegatagicu', 'quutydychy', 'chuzeby', 'jefythasapag', 'bytathoti', 'thimobaquykisabepec', 'saluwax', 'thi', 'kyneroravexuquoto', 'jusudybahebuxypepahe', 'f', 'zapufefek', 'mumogawen', 'quotyhot', 'hybamukelo', 'picatextujycotodyj', 'be', 'pytextyfa', 'tile', 'dotextazuchubuk', 'choguc', 'wi', 'setepicydavumahebe', 'wyjo', 'mirukuwyfuwihoqu', 'q', 'kegytegu', 'kegoquibyguxexajebid', 'hyfech', 'humovomefoly', 'tupetox', 'gevogibax', 'vuxotext', 'miluparaj', 'bathad', 'tily', 'theranydygiryc', 'dasaxatext', 'guhebalequepytex', 'v', 'gocuxomecapylewaj']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['bututimatabel', 'zezahabiry', 'mipytext', 'bujokacyrulihir', 'cyvagofaquothoseza', 'guhebalequepytex', 'tyhithuthygatextity', 'chizichuc', 'textoxodenekokechona', 'texte', 'mygafifet', 'vixathokivy', 'xe', 'moq', 'quokopy', 'cixoka', 'wiz', 'wyturasutabidipif', 'q', 'gochujuvub', 'textogow', 'rogizasog', 'fimoxynudob', 'byjythohimowyquich', 'moduxatanogococ', 'tunuchikywichykyxyge', 'namixotextes', 'nocoguthosoxonahu', 'xorydyhi', 'dadohojex', 'pi', 'wiquocaso', 'tyjegu', 'juquath', 'dythufyn', 'sehafur', 'sylupivyzequefujet', 'hotextylyquahudivov', 'wunich', 'fijyhilyc', 'rirymequunezuv', 'zizunylihadowys', 'zesuxikevaquus', 'thecisequevyth', 'cucyquefytextu', 'xy', 'quuxin', 'miherahita', 'texatextoxyta', 'tythyjuly', 'tehesyju', 'reg', 'ridilusycanejap', 'fo', 'chucatazyrejucathibi', 'textythacete', 'huhiquekychyh', 'xykuvebylyhinyc', 'zadedixoxoparyducena', 'wycathomoniva', 'textuwuwathiziq', 'textijiw', 'rigidichukuchexorute', 'majixodokalij', 'hexebitoxumuvodese', 'hybat', 'thojutextomochote', 'textaxuquyg', 'queluhatex'], b=['gume', 'zatum', 'kochaxybupy', 'gex', 'vithiby', 'lygarethaquedehabub', 'tochek', 'v', 'wis', 'remywerinyboweropot', 'nybichychafizurup', 'zokabugyc', 'ny', 'moruwicoponuricuw', 'zirijikuhabivywah', 'dus', 'toxirit', 'gilanih', 'hif', 'vuhezobinehahewi', 'quujihus', 'chej', 'g', 'pypomaquiwusisyvuma', 'to', 'c', 'chutesumalanozeb', 'chupehozukiquodisese', 'xygiwot', 'semubaquav', 'pihiwidosudetextet', 'quegatagicu', 'quutydychy', 'chuzeby', 'jefythasapag', 'bytathoti', 'thimobaquykisabepec', 'saluwax', 'thi', 'kyneroravexuquoto', 'jusudybahebuxypepahe', 'f', 'zapufefek', 'mumogawen', 'quotyhot', 'hybamukelo', 'picatextujycotodyj', 'be', 'pytextyfa', 'tile', 'dotextazuchubuk', 'choguc', 'wi', 'setepicydavumahebe', 'wyjo', 'mirukuwyfuwihoqu', 'q', 'kegytegu', 'kegoquibyguxexajebid', 'hyfech', 'humovomefoly', 'tupetox', 'gevogibax', 'vuxotext', 'miluparaj', 'bathad', 'tily', 'theranydygiryc', 'dasaxatext', 'guhebalequepytex', 'v', 'gocuxomecapylewaj']):\n return next(s for s in b if s in a)" + "name": "StrSplit:2", + "sat": "def sat(x: str, parts=['lepytextati', 'ki', 'fy'], length=69):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['lepytextati', 'ki', 'fy'], length=69):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_3", - "sat": "def sat(s: str, a=['thachak', 'xuchyzyzazi', 'bilewejoquowylo', 'chogokim', 'kuloxozu', 'capokaf', 'didadadejunukosazi', 'zethucun', 'tygorub', 'lochydigyt', 'dyquuhycusi', 'wagupolovapy', 'chowace', 'zozawethychax', 'xohuhuqui', 'tatylisigar', 'c', 'kakopuzysycasewit', 'rekatebinidyvuchitet', 'popi', 'chepebaze', 'textut', 'fymehap', 'c', 'wodumogovolacabasot', 'tixihidafutexto', 'dycubichucyneweve', 'setofa', 'cudaxediquy', 'namof', 'qua', 'chetextof', 'cochydededaxyzuj', 'winutaj', 'nidyjutothovobydizy', 'sichequaxohojethihy', 'cubusycip', 'pynoconic', 'kyt', 'thop', 'kewotochelocyboz', 'z', 'c', 'q', 'bonyquyx', 'jothec', 'fyzozynygiperythada', 'lipadatuzisaduthyt', 'nithujyxymethot', 'vewariq', 'nejitextole', 'raxiv', 'hamim', 'qua', 'kytextehekaryp', 'jaquu', 'wozuthevith', 'f', 'jugevizyfu', 'cywo', 'w', 'surajotext', 'vilujetutitachivy', 'textequysuninutuqu', 'fevawybok', 'lythehythu', 'nykochachofitit', 'gikenadubit', 'thexyjy', 'piquyzyxichoc', 'rilaquucham', 'fa', 'mysihumotexto', 'xochogekumipoquidi', 'jimynusyte', 'textexysuzipichaw', 'mut', 'jiwyx', 'tojiwedoxevosubavy', 'dix', 'dogetexto', 'chysafyzelefocothin', 'xitext', 'machibokudyh', 'ronebupapapygyceb', 'dedytejyretavewytasi', 'jobog', 'namychyt', 'textycapudul', 'jaxybatexto', 'pamuwysafupaxowus', 'lycazivafyj', 'lelologufenofajogofi', 'thety', 'bunotextoca', 'nexaravuq', 'natu'], b=['namychyt', 'mathapachobat', 'timorohopotak']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['thachak', 'xuchyzyzazi', 'bilewejoquowylo', 'chogokim', 'kuloxozu', 'capokaf', 'didadadejunukosazi', 'zethucun', 'tygorub', 'lochydigyt', 'dyquuhycusi', 'wagupolovapy', 'chowace', 'zozawethychax', 'xohuhuqui', 'tatylisigar', 'c', 'kakopuzysycasewit', 'rekatebinidyvuchitet', 'popi', 'chepebaze', 'textut', 'fymehap', 'c', 'wodumogovolacabasot', 'tixihidafutexto', 'dycubichucyneweve', 'setofa', 'cudaxediquy', 'namof', 'qua', 'chetextof', 'cochydededaxyzuj', 'winutaj', 'nidyjutothovobydizy', 'sichequaxohojethihy', 'cubusycip', 'pynoconic', 'kyt', 'thop', 'kewotochelocyboz', 'z', 'c', 'q', 'bonyquyx', 'jothec', 'fyzozynygiperythada', 'lipadatuzisaduthyt', 'nithujyxymethot', 'vewariq', 'nejitextole', 'raxiv', 'hamim', 'qua', 'kytextehekaryp', 'jaquu', 'wozuthevith', 'f', 'jugevizyfu', 'cywo', 'w', 'surajotext', 'vilujetutitachivy', 'textequysuninutuqu', 'fevawybok', 'lythehythu', 'nykochachofitit', 'gikenadubit', 'thexyjy', 'piquyzyxichoc', 'rilaquucham', 'fa', 'mysihumotexto', 'xochogekumipoquidi', 'jimynusyte', 'textexysuzipichaw', 'mut', 'jiwyx', 'tojiwedoxevosubavy', 'dix', 'dogetexto', 'chysafyzelefocothin', 'xitext', 'machibokudyh', 'ronebupapapygyceb', 'dedytejyretavewytasi', 'jobog', 'namychyt', 'textycapudul', 'jaxybatexto', 'pamuwysafupaxowus', 'lycazivafyj', 'lelologufenofajogofi', 'thety', 'bunotextoca', 'nexaravuq', 'natu'], b=['namychyt', 'mathapachobat', 'timorohopotak']):\n return next(s for s in b if s in a)" + "name": "StrSplit:3", + "sat": "def sat(x: str, parts=['quyhigechyhy'], length=38):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['quyhigechyhy'], length=38):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_4", - "sat": "def sat(s: str, a=['quisolu', 'nixyquigaseq', 'fawaholafojelaxud', 'cuxoniso', 'defejaz', 'mytext', 'gochavowetheva', 'xijehychojexat', 'duthagobejudozi', 'thiquijuquorybu'], b=['cys', 'zatext', 'cifihihechujozimo', 'jycichithetyk', 'becitonamuhuligyv', 'sadak', 'hochavinapatanapiz', 'fiwidifop', 'funidosikeput', 'fewat', 'mypyhalevituvit', 'quytynuthothy', 'c', 'zydecodul', 'vahychuke', 'wy', 'mytext', 'tex', 'quevasowodique', 'hythiquunymychilyl', 'luxivyvocuwa']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['quisolu', 'nixyquigaseq', 'fawaholafojelaxud', 'cuxoniso', 'defejaz', 'mytext', 'gochavowetheva', 'xijehychojexat', 'duthagobejudozi', 'thiquijuquorybu'], b=['cys', 'zatext', 'cifihihechujozimo', 'jycichithetyk', 'becitonamuhuligyv', 'sadak', 'hochavinapatanapiz', 'fiwidifop', 'funidosikeput', 'fewat', 'mypyhalevituvit', 'quytynuthothy', 'c', 'zydecodul', 'vahychuke', 'wy', 'mytext', 'tex', 'quevasowodique', 'hythiquunymychilyl', 'luxivyvocuwa']):\n return next(s for s in b if s in a)" + "name": "StrSplit:4", + "sat": "def sat(x: str, parts=['je', 'pojacyda', 'papucet', 'wesobaq'], length=40):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['je', 'pojacyda', 'papucet', 'wesobaq'], length=40):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_5", - "sat": "def sat(s: str, a=['z', 'coxas', 'thefynakugucajanaw', 'xax', 'textiquyselakaruq', 'xenakachepygymusalif', 'cadehaxethydej', 'pitextyzusofawy', 'xewosytextijepajuto', 'milefary', 'dynuguna', 'witextisyleniraj', 'si', 'suquejuw', 'mosiran', 'gome', 'te', 'kotextewi', 'salomijukakijukivate', 'kujevudepo', 'ximoraziquacafeje'], b=['jox', 'text', 'chobexirif', 'chuzocacinyhutextit', 'fi', 'pinithupo', 'hacuh', 'cadutex', 'no', 'vasarydytextyt', 'vejyh', 'hime', 'wixefexewywi', 'bax', 'sizivolono', 'kimigute', 'thefynakugucajanaw', 'lyb', 'textetisutextuhepi', 'c', 'gyg', 'pulazozuhodavy', 'v', 'cenaz', 'xodulocybixosebagoce', 'tihaquufathyb', 'hatoquukilywoja', 'wocaritihy', 'kyzechomixyne', 'jibaxuv', 'voquydime', 'pubutuxatext', 'te', 'xili', 'chide', 'ji', 'jyka', 'chiwopyhafujucaquo', 'levuj', 'fahevamocho', 'waquycupoku', 'jumigolivageno', 'th', 'cokukal', 'pathicebe', 'chaquu', 'bicanalocuthihenaxy', 'dimopi', 'chequykycucyquowyte', 'nexe', 'dokut', 'quythimed', 'mizinyz', 'huroko', 'hac', 'ryt', 'methequawitextopoko', 'gokibaquodykyquo', 'vinuxitextakyhi', 'saluputipuqu', 'bogy']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['z', 'coxas', 'thefynakugucajanaw', 'xax', 'textiquyselakaruq', 'xenakachepygymusalif', 'cadehaxethydej', 'pitextyzusofawy', 'xewosytextijepajuto', 'milefary', 'dynuguna', 'witextisyleniraj', 'si', 'suquejuw', 'mosiran', 'gome', 'te', 'kotextewi', 'salomijukakijukivate', 'kujevudepo', 'ximoraziquacafeje'], b=['jox', 'text', 'chobexirif', 'chuzocacinyhutextit', 'fi', 'pinithupo', 'hacuh', 'cadutex', 'no', 'vasarydytextyt', 'vejyh', 'hime', 'wixefexewywi', 'bax', 'sizivolono', 'kimigute', 'thefynakugucajanaw', 'lyb', 'textetisutextuhepi', 'c', 'gyg', 'pulazozuhodavy', 'v', 'cenaz', 'xodulocybixosebagoce', 'tihaquufathyb', 'hatoquukilywoja', 'wocaritihy', 'kyzechomixyne', 'jibaxuv', 'voquydime', 'pubutuxatext', 'te', 'xili', 'chide', 'ji', 'jyka', 'chiwopyhafujucaquo', 'levuj', 'fahevamocho', 'waquycupoku', 'jumigolivageno', 'th', 'cokukal', 'pathicebe', 'chaquu', 'bicanalocuthihenaxy', 'dimopi', 'chequykycucyquowyte', 'nexe', 'dokut', 'quythimed', 'mizinyz', 'huroko', 'hac', 'ryt', 'methequawitextopoko', 'gokibaquodykyquo', 'vinuxitextakyhi', 'saluputipuqu', 'bogy']):\n return next(s for s in b if s in a)" + "name": "StrSplitter:0", + "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_6", - "sat": "def sat(s: str, a=['lumoguwamyhut', 'thajokotextejakizug', 'tynitextyq', 'quuquujolifysy', 'but', 'n', 'xifytextechafu', 'quujyb', 'n', 'pisaxokychadix', 'texteraqui', 'textizipite', 'kibowerulecijytextex', 'lypelylahutexty', 'hyk', 'vedycithifipyxidyhe', 'chakovixo', 'syquaga', 'sycekohododachiby', 'vutakagaralewiqui', 'quitextumaquefusux', 'tovyhezigageguti', 'defynorudabichyxo', 'quexanyvuthukaf', 'muquoquechok', 'vukydetextufyniso', 'chefojigoxa', 'sothawanerov', 'cykutozathoratextos', 'jiquibivug', 'kylubixoduvapefozelo', 'xotha', 'tekiritunothuxat', 'duxylyvitextocowug', 'fethachoga', 'pehujovowal', 'gizamyxojehuthequy', 'hygamokily', 'zomeque', 'zyma', 'chynybunegiz', 'p', 'kewibohaxiw', 'gaduhuxiquuzach', 'p', 'pichumuvythopy', 'rizaguquequychiw', 'gelorysyd', 'za', 'textapelusykerudub', 'jipudiradutext', 'lovyvutexto', 'relutechacowel', 'zycydonigutyfunir', 'textakedunaxoquu', 'konunykucewiduwopiw', 'd', 'piwuletextyp', 'textyseseq', 'hydydysoc', 'muquokiva', 'valochahelosoloveq', 'textyquygeredopotho', 'kymipulanygud', 'mygamozuwuquasep', 'putextozoxute', 'dothahegytextug', 'gatextechifidot', 'chydykysesu', 'soquolycavajylach', 'cuwyciquidozujizic', 'lahevapinasa', 'quixifejenithet', 'zebonada', 'lefysa', 've', 'bihothizecawudasewa', 'quafycobahymachoju', 'xitolegucuwec', 'guwyb', 'puchokudi', 'quokerufanogi', 'gikogachyquefic', 'lohyrosopechykoni', 'fy', 'pavehiquo', 'fusabubuq'], b=['habywafivukawuwosaqu', 'gymuholyhy', 'lanet', 'zy', 'zekitiket', 'vochonytapymajibimox', 'giwojyvelyte', 'thadomazotethytub', 'quicavas', 'piquekithefofy', 'thocuqui', 'cytex', 'quuheraquizywanu', 'jinadutex', 'fekytenuhuxubiziquy', 'rarytextakux', 'jyjihethiwath', 'chocolutextexiki', 'ledydiniki', 'w', 'qua', 'qui', 'x', 'cygathusachitex', 'soditome', 'hatylapyhafenetalut', 'korikycun', 'futhasybudovyxit', 'sisizojolequitum', 'x', 'xaxifotexte', 'zyrehugiquy', 'w', 'ciquysekijo', 'puxyzothadusaque', 'lycugeh', 'sutib', 'rafaganyquyzyt', 'mymecyjegygavaxesu', 'fith', 'j', 'thojigetoxewupyf', 'chunymikyl', 'quisahi', 'sowucibam', 'deputhuvigeg', 'thykugosi', 't', 'kavoquothezelo', 'textude', 'z', 'thyk', 'jathaxethujiz', 'nexasebetextyfav', 'dugoxosubocozuk', 'bypyhofedyr', 'j', 'text', 'textakedunaxoquu', 'warabejiwajudeholyc', 'quetextubusekexoquu', 'kahulycojis', 'chytextibapi', 'cekuthyc', 'hunazetytexta', 'purufoth', 'mazy', 'lo', 'raxotholamukarymi', 'themogyth', 'thiqu', 'pajathesaguliwi', 'filorererumycuce', 'ch', 'sijewedehytosod', 'hawogohethequ', 'ryh', 'wycyn', 'gebachahefijowoxyt', 'thovawemusetyq', 'jyxevylichoquysejyga', 'text', 'vapiwymexuno', 'chixemebusedakyveto', 'thosybygutextutexty', 'mopobytex', 'tytamivicocumyhyp', 'pezajuquukugakogot', 'riwutextucotodec', 'tigahanycoz', 'wo', 'thymekadequ', 'xevugochyvawitext', 'fopolane']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['lumoguwamyhut', 'thajokotextejakizug', 'tynitextyq', 'quuquujolifysy', 'but', 'n', 'xifytextechafu', 'quujyb', 'n', 'pisaxokychadix', 'texteraqui', 'textizipite', 'kibowerulecijytextex', 'lypelylahutexty', 'hyk', 'vedycithifipyxidyhe', 'chakovixo', 'syquaga', 'sycekohododachiby', 'vutakagaralewiqui', 'quitextumaquefusux', 'tovyhezigageguti', 'defynorudabichyxo', 'quexanyvuthukaf', 'muquoquechok', 'vukydetextufyniso', 'chefojigoxa', 'sothawanerov', 'cykutozathoratextos', 'jiquibivug', 'kylubixoduvapefozelo', 'xotha', 'tekiritunothuxat', 'duxylyvitextocowug', 'fethachoga', 'pehujovowal', 'gizamyxojehuthequy', 'hygamokily', 'zomeque', 'zyma', 'chynybunegiz', 'p', 'kewibohaxiw', 'gaduhuxiquuzach', 'p', 'pichumuvythopy', 'rizaguquequychiw', 'gelorysyd', 'za', 'textapelusykerudub', 'jipudiradutext', 'lovyvutexto', 'relutechacowel', 'zycydonigutyfunir', 'textakedunaxoquu', 'konunykucewiduwopiw', 'd', 'piwuletextyp', 'textyseseq', 'hydydysoc', 'muquokiva', 'valochahelosoloveq', 'textyquygeredopotho', 'kymipulanygud', 'mygamozuwuquasep', 'putextozoxute', 'dothahegytextug', 'gatextechifidot', 'chydykysesu', 'soquolycavajylach', 'cuwyciquidozujizic', 'lahevapinasa', 'quixifejenithet', 'zebonada', 'lefysa', 've', 'bihothizecawudasewa', 'quafycobahymachoju', 'xitolegucuwec', 'guwyb', 'puchokudi', 'quokerufanogi', 'gikogachyquefic', 'lohyrosopechykoni', 'fy', 'pavehiquo', 'fusabubuq'], b=['habywafivukawuwosaqu', 'gymuholyhy', 'lanet', 'zy', 'zekitiket', 'vochonytapymajibimox', 'giwojyvelyte', 'thadomazotethytub', 'quicavas', 'piquekithefofy', 'thocuqui', 'cytex', 'quuheraquizywanu', 'jinadutex', 'fekytenuhuxubiziquy', 'rarytextakux', 'jyjihethiwath', 'chocolutextexiki', 'ledydiniki', 'w', 'qua', 'qui', 'x', 'cygathusachitex', 'soditome', 'hatylapyhafenetalut', 'korikycun', 'futhasybudovyxit', 'sisizojolequitum', 'x', 'xaxifotexte', 'zyrehugiquy', 'w', 'ciquysekijo', 'puxyzothadusaque', 'lycugeh', 'sutib', 'rafaganyquyzyt', 'mymecyjegygavaxesu', 'fith', 'j', 'thojigetoxewupyf', 'chunymikyl', 'quisahi', 'sowucibam', 'deputhuvigeg', 'thykugosi', 't', 'kavoquothezelo', 'textude', 'z', 'thyk', 'jathaxethujiz', 'nexasebetextyfav', 'dugoxosubocozuk', 'bypyhofedyr', 'j', 'text', 'textakedunaxoquu', 'warabejiwajudeholyc', 'quetextubusekexoquu', 'kahulycojis', 'chytextibapi', 'cekuthyc', 'hunazetytexta', 'purufoth', 'mazy', 'lo', 'raxotholamukarymi', 'themogyth', 'thiqu', 'pajathesaguliwi', 'filorererumycuce', 'ch', 'sijewedehytosod', 'hawogohethequ', 'ryh', 'wycyn', 'gebachahefijowoxyt', 'thovawemusetyq', 'jyxevylichoquysejyga', 'text', 'vapiwymexuno', 'chixemebusedakyveto', 'thosybygutextutexty', 'mopobytex', 'tytamivicocumyhyp', 'pezajuquukugakogot', 'riwutextucotodec', 'tigahanycoz', 'wo', 'thymekadequ', 'xevugochyvawitext', 'fopolane']):\n return next(s for s in b if s in a)" + "name": "StrSplitter:1", + "sat": "def sat(x: str, parts=['kowot', 'quimimy'], string=\"kowottextihocavikirofegyfquimimy\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['kowot', 'quimimy'], string=\"kowottextihocavikirofegyfquimimy\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_7", - "sat": "def sat(s: str, a=['ch', 'xizolu', 'm', 'pupubomatykabuthythe', 'chubesache', 'zyzalygylohyfychi'], b=['ne', 'x', 'zonegyhachaf', 'thute', 'cifijigyfokexydogaj', 'nejy', 'piquehoquuguhy', 'misev', 'dyg', 'x', 'gu', 'buco', 'vepocy', 'kuruzewicyrup', 'zyzalygylohyfychi', 'romojafi', 'rymowemyfitesa', 'bybesynuromo', 'najamurusyhichyz', 'pavoxukyxytextalap', 'fevabequoxi', 'muxycikuvamathythija', 'nujovete', 'z', 'mogy', 'berevilox', 'hetesetextacetho', 'thyquycenethiheq', 'maxirygam', 'he', 'chudothaset', 'baxipeboquat', 'zuhapodude', 'sanuz', 'cehic', 'futohihowa', 'fyrerotexteg', 'dy', 'thisijoj', 'hequokotequavojus', 'quevapujijuko', 'textav', 'ryquixychimaxux', 'sirupuquogythofuce', 'roxysurazatexto', 'bithazagycawepatext', 'chunujeche', 'lutatextywahyket', 'pusy', 'cathazodyjuthyhu', 'quusequiquohith', 'bediwewexymova', 'cyloge', 'kadewathacynenici', 'roxykizewunetext', 'richub', 'viq', 'votextequykupoxanew', 'zopafa', 'boxino', 'tobadufidy', 'thovetex', 'balywefubyjoxykoc', 'dofurum', 'thabijonu', 'tomuwepavezehixyt', 'wocuhumethecetolur', 'quot', 'zolegydexu', 'gicasakax', 'fibalume', 'xijicenomisirop', 'ch', 'l', 'chezob', 'lilotitex', 'julychivesuzebej', 'fifefisulaxutext', 'chypy', 'textysip', 'bitiquyxudukedifu', 'w', 'naval', 'chukojozavepelovycho', 'giquyla', 'mov', 'gegopyzawotothic']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['ch', 'xizolu', 'm', 'pupubomatykabuthythe', 'chubesache', 'zyzalygylohyfychi'], b=['ne', 'x', 'zonegyhachaf', 'thute', 'cifijigyfokexydogaj', 'nejy', 'piquehoquuguhy', 'misev', 'dyg', 'x', 'gu', 'buco', 'vepocy', 'kuruzewicyrup', 'zyzalygylohyfychi', 'romojafi', 'rymowemyfitesa', 'bybesynuromo', 'najamurusyhichyz', 'pavoxukyxytextalap', 'fevabequoxi', 'muxycikuvamathythija', 'nujovete', 'z', 'mogy', 'berevilox', 'hetesetextacetho', 'thyquycenethiheq', 'maxirygam', 'he', 'chudothaset', 'baxipeboquat', 'zuhapodude', 'sanuz', 'cehic', 'futohihowa', 'fyrerotexteg', 'dy', 'thisijoj', 'hequokotequavojus', 'quevapujijuko', 'textav', 'ryquixychimaxux', 'sirupuquogythofuce', 'roxysurazatexto', 'bithazagycawepatext', 'chunujeche', 'lutatextywahyket', 'pusy', 'cathazodyjuthyhu', 'quusequiquohith', 'bediwewexymova', 'cyloge', 'kadewathacynenici', 'roxykizewunetext', 'richub', 'viq', 'votextequykupoxanew', 'zopafa', 'boxino', 'tobadufidy', 'thovetex', 'balywefubyjoxykoc', 'dofurum', 'thabijonu', 'tomuwepavezehixyt', 'wocuhumethecetolur', 'quot', 'zolegydexu', 'gicasakax', 'fibalume', 'xijicenomisirop', 'ch', 'l', 'chezob', 'lilotitex', 'julychivesuzebej', 'fifefisulaxutext', 'chypy', 'textysip', 'bitiquyxudukedifu', 'w', 'naval', 'chukojozavepelovycho', 'giquyla', 'mov', 'gegopyzawotothic']):\n return next(s for s in b if s in a)" + "name": "StrSplitter:2", + "sat": "def sat(x: str, parts=['f', 'thixaresiquagipoquas', 'fytylu', 'jywaxaw'], string=\"fdetthixaresiquagipoquasdetfytyludetjywaxaw\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['f', 'thixaresiquagipoquas', 'fytylu', 'jywaxaw'], string=\"fdetthixaresiquagipoquasdetfytyludetjywaxaw\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_8", - "sat": "def sat(s: str, a=['savasoqu', 'sy', 'tubuquigechuboretext', 'mefegewonathith', 'textohozacewyresatu', 'tikekozapexeviko', 'kusilogakuzyjichyf', 'sute', 'quyjechygenothimuwe', 'bothecytysixeda', 'towyza', 'jyvinuzochixud', 'mohurakunixorytextug', 'bopecik', 'githijoquyriha', 'xuborom', 'thysakocherubug', 'fitextypatextu', 'fevijulyl', 'vumuquuquyzofoc', 'thygyvi', 'fogo', 'bipucotextuthyr', 'kimotowizajiquoqua', 'futokojepanajyreb', 'fuwofacat', 'chedotexti', 'vefethofa', 'quurofahupux', 'kupajitha', 'kevituhinacicacuqu', 'wof', 'thyzygugunehigysykub', 'cho', 'thuxegubuthetex', 'kaquokirakochecepu', 'bomaxumykax', 'buviwipybo', 'katextoso', 'juwafijutiza', 'lotextip', 'ke', 'zemiquim', 'jetenusixul', 'fovit', 'tapejacugu', 'zyhesebinothi', 'fagohidyxy', 'jequuwicirequak', 'vutex', 'kuwedechuchalogyt', 'levuthucapezywesucy', 'cafyquul', 'textutiz', 'v', 'zyr', 'pybythixasefuzavav', 'dutextabisuxabath', 'ryrytextuchizijoxoh'], b=['gumumiparusath', 'jumepuwazolojithoth', 'bahynec', 'savasoqu', 'manybezesyhuwojobaxi', 'dacojutextasikaleq', 'kuwiquy', 'hefoquenejosypeh', 'zydabemuchib', 'nifaxynotexteth', 'gycithyquyceny', 'mikebununacute', 'zoquytextibe', 'chutech', 'samigebaloliquy', 'nyquah', 'raparu', 'thotextucipucalopu', 'chihychasuqu', 'sywuthop', 'tovyzydi', 'chuthipuchy', 'd', 'bytextozaquupajymote', 'zuc', 'dozukymitegocemabyb', 'textytolopetheza', 't', 'tohochifalith', 'jinathykijejyjyw', 'jez', 'xivafebomamepyp', 'chithapyq', 'bew', 'rubynejezakyr', 'hagifechuxachuw', 'nabelocupyxyt', 'hafotextu', 'malicajypo', 'jywat', 'guzyquugath', 'dykejegykanasixil', 'quokydu', 'kyvifejywy', 'zuc', 'xuchochodatujopethy', 'nyhutaj', 'xasyjychipymozu', 'vydu', 'pojekikyquosap', 'textyrukerilycemi', 'chobumipeb', 'vuthixymuvyte', 'g', 'zinigapochybyxamel', 'satextutu', 'syg', 'fatereq', 'hibethozojuchusijifi', 'jaz', 'xathoxij', 'faposezitasehof', 'silukatexta', 'fonajyvizilu', 'xud', 'quonyqu', 'textykexunyre', 'keki', 'nechexesutedyty', 'sohafurechecidohyka', 'lajirufybat', 'zefuquypot', 'suleceminucyr', 'thobyxethothy', 'hyvihacixexo', 'labutextibah', 'motatyfanochathuwac', 'ryquedyp', 'wofasicyxaho', 'cipequizozojykoxucu', 'xyruma', 'wuburiquom', 'cohychepach', 'lyj', 'hyxoxukofavolaxyc', 'h', 'gyloxepijer', 'kodywyth', 'xetogeca', 'cyji', 'degukabigokuthiwi']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['savasoqu', 'sy', 'tubuquigechuboretext', 'mefegewonathith', 'textohozacewyresatu', 'tikekozapexeviko', 'kusilogakuzyjichyf', 'sute', 'quyjechygenothimuwe', 'bothecytysixeda', 'towyza', 'jyvinuzochixud', 'mohurakunixorytextug', 'bopecik', 'githijoquyriha', 'xuborom', 'thysakocherubug', 'fitextypatextu', 'fevijulyl', 'vumuquuquyzofoc', 'thygyvi', 'fogo', 'bipucotextuthyr', 'kimotowizajiquoqua', 'futokojepanajyreb', 'fuwofacat', 'chedotexti', 'vefethofa', 'quurofahupux', 'kupajitha', 'kevituhinacicacuqu', 'wof', 'thyzygugunehigysykub', 'cho', 'thuxegubuthetex', 'kaquokirakochecepu', 'bomaxumykax', 'buviwipybo', 'katextoso', 'juwafijutiza', 'lotextip', 'ke', 'zemiquim', 'jetenusixul', 'fovit', 'tapejacugu', 'zyhesebinothi', 'fagohidyxy', 'jequuwicirequak', 'vutex', 'kuwedechuchalogyt', 'levuthucapezywesucy', 'cafyquul', 'textutiz', 'v', 'zyr', 'pybythixasefuzavav', 'dutextabisuxabath', 'ryrytextuchizijoxoh'], b=['gumumiparusath', 'jumepuwazolojithoth', 'bahynec', 'savasoqu', 'manybezesyhuwojobaxi', 'dacojutextasikaleq', 'kuwiquy', 'hefoquenejosypeh', 'zydabemuchib', 'nifaxynotexteth', 'gycithyquyceny', 'mikebununacute', 'zoquytextibe', 'chutech', 'samigebaloliquy', 'nyquah', 'raparu', 'thotextucipucalopu', 'chihychasuqu', 'sywuthop', 'tovyzydi', 'chuthipuchy', 'd', 'bytextozaquupajymote', 'zuc', 'dozukymitegocemabyb', 'textytolopetheza', 't', 'tohochifalith', 'jinathykijejyjyw', 'jez', 'xivafebomamepyp', 'chithapyq', 'bew', 'rubynejezakyr', 'hagifechuxachuw', 'nabelocupyxyt', 'hafotextu', 'malicajypo', 'jywat', 'guzyquugath', 'dykejegykanasixil', 'quokydu', 'kyvifejywy', 'zuc', 'xuchochodatujopethy', 'nyhutaj', 'xasyjychipymozu', 'vydu', 'pojekikyquosap', 'textyrukerilycemi', 'chobumipeb', 'vuthixymuvyte', 'g', 'zinigapochybyxamel', 'satextutu', 'syg', 'fatereq', 'hibethozojuchusijifi', 'jaz', 'xathoxij', 'faposezitasehof', 'silukatexta', 'fonajyvizilu', 'xud', 'quonyqu', 'textykexunyre', 'keki', 'nechexesutedyty', 'sohafurechecidohyka', 'lajirufybat', 'zefuquypot', 'suleceminucyr', 'thobyxethothy', 'hyvihacixexo', 'labutextibah', 'motatyfanochathuwac', 'ryquedyp', 'wofasicyxaho', 'cipequizozojykoxucu', 'xyruma', 'wuburiquom', 'cohychepach', 'lyj', 'hyxoxukofavolaxyc', 'h', 'gyloxepijer', 'kodywyth', 'xetogeca', 'cyji', 'degukabigokuthiwi']):\n return next(s for s in b if s in a)" + "name": "StrSplitter:3", + "sat": "def sat(x: str, parts=['tibuzumurun', 'hakebixutextolonyf', 'bothuraquobara'], string=\"tibuzumurunhocyxihakebixutextolonyfhocyxibothuraquobara\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['tibuzumurun', 'hakebixutextolonyf', 'bothuraquobara'], string=\"tibuzumurunhocyxihakebixutextolonyfhocyxibothuraquobara\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "ListIn_9", - "sat": "def sat(s: str, a=['bacyquawygitiforus', 'ragyrywekoziqui', 'memivothoveke', 'hyvapucuxythi', 'coth', 'wichug', 'mujechogeq', 'mefujysejilijygawy', 'viwygemuguwebanely', 'n', 'textuchynasyquufytex', 'b', 'fuchavyxechadukaf', 'si', 'gucasilowaq', 'thabupewaque', 'chok', 'riwurovothakyvijak', 'hyk', 'qu', 'textyzuthusonathyque', 'qu', 'datext', 'chekika', 'pathisonirade', 'fevavetusobu', 'zisupedevalewiwuj', 'textubiju', 'tarylachalucetext', 'zadechexud', 'xu', 'kamozu', 'ryxosiqu', 'ge', 'quojon', 'wothy', 'huquethasote', 'fycamyha', 'textaga', 'durequegawafoly', 'wamunariquegih', 's', 'hybukequudiduwutex', 'nebytymapucidebo', 'zyrohothetoxoxac', 'cula', 'nufetextisyx'], b=['lyg', 'mujechogeq', 'quury', 'c', 'dacygudasiquafycop']):\n \"\"\"Find an item that is in both lists a and b\"\"\"\n return s in a and s in b", - "sols": [ - "def sol(a=['bacyquawygitiforus', 'ragyrywekoziqui', 'memivothoveke', 'hyvapucuxythi', 'coth', 'wichug', 'mujechogeq', 'mefujysejilijygawy', 'viwygemuguwebanely', 'n', 'textuchynasyquufytex', 'b', 'fuchavyxechadukaf', 'si', 'gucasilowaq', 'thabupewaque', 'chok', 'riwurovothakyvijak', 'hyk', 'qu', 'textyzuthusonathyque', 'qu', 'datext', 'chekika', 'pathisonirade', 'fevavetusobu', 'zisupedevalewiwuj', 'textubiju', 'tarylachalucetext', 'zadechexud', 'xu', 'kamozu', 'ryxosiqu', 'ge', 'quojon', 'wothy', 'huquethasote', 'fycamyha', 'textaga', 'durequegawafoly', 'wamunariquegih', 's', 'hybukequudiduwutex', 'nebytymapucidebo', 'zyrohothetoxoxac', 'cula', 'nufetextisyx'], b=['lyg', 'mujechogeq', 'quury', 'c', 'dacygudasiquafycop']):\n return next(s for s in b if s in a)" + "name": "StrSplitter:4", + "sat": "def sat(x: str, parts=['fitextu', 'chythawequeku', 'th'], string=\"fitextufyhachochythawequekufyhachoth\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['fitextu', 'chythawequeku', 'th'], string=\"fitextufyhachochythawequekufyhachoth\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_0", - "sat": "def sat(x: int, a=93252338):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=93252338):\n return - a" + "name": "StrJoiner:0", + "sat": "def sat(x: str, parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_1", - "sat": "def sat(x: int, a=-7788910835979672):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-7788910835979672):\n return - a" + "name": "StrJoiner:1", + "sat": "def sat(x: str, parts=['tatext'], string=\"tatext\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=['tatext'], string=\"tatext\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_2", - "sat": "def sat(x: int, a=6734672221833987):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=6734672221833987):\n return - a" + "name": "StrJoiner:2", + "sat": "def sat(x: str, parts=[], string=\"\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=[], string=\"\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_3", - "sat": "def sat(x: int, a=-6405550227918699):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-6405550227918699):\n return - a" + "name": "StrJoiner:3", + "sat": "def sat(x: str, parts=['ruquug'], string=\"ruquug\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=['ruquug'], string=\"ruquug\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_4", - "sat": "def sat(x: int, a=-5741705983914418):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-5741705983914418):\n return - a" + "name": "StrJoiner:4", + "sat": "def sat(x: str, parts=['numegixuly', 'koxyfihimurukothasyl'], string=\"numegixulypyjetkoxyfihimurukothasyl\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=['numegixuly', 'koxyfihimurukothasyl'], string=\"numegixulypyjetkoxyfihimurukothasyl\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_5", - "sat": "def sat(x: int, a=-6295897925885854):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-6295897925885854):\n return - a" + "name": "StrParts:0", + "sat": "def sat(parts: List[str], sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_6", - "sat": "def sat(x: int, a=-8080281870614233):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-8080281870614233):\n return - a" + "name": "StrParts:1", + "sat": "def sat(parts: List[str], sep=\"jachasurobithu\", string=\"watalachyquujachasurobithuba\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"jachasurobithu\", string=\"watalachyquujachasurobithuba\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_7", - "sat": "def sat(x: int, a=-5790248626264272):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-5790248626264272):\n return - a" + "name": "StrParts:2", + "sat": "def sat(parts: List[str], sep=\"xusoquyvamathila\", string=\"bolifotinuwywyjochxusoquyvamathilazyvuxusoquyvamathilanifajatextethxusoquyvamathilafocharatefymoji\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"xusoquyvamathila\", string=\"bolifotinuwywyjochxusoquyvamathilazyvuxusoquyvamathilanifajatextethxusoquyvamathilafocharatefymoji\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_8", - "sat": "def sat(x: int, a=-4190266031592704):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=-4190266031592704):\n return - a" + "name": "StrParts:3", + "sat": "def sat(parts: List[str], sep=\"chixachal\", string=\"\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"chixachal\", string=\"\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNeg_9", - "sat": "def sat(x: int, a=1073212294304751):\n \"\"\"Solve a unary negation problem\"\"\"\n return -x == a", - "sols": [ - "def sol(a=1073212294304751):\n return - a" + "name": "StrParts:4", + "sat": "def sat(parts: List[str], sep=\"lochuv\", string=\"biflochuvzulothanodugedusilochuvlilochuvhobegikofero\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"lochuv\", string=\"biflochuvzulothanodugedusilochuvlilochuvhobegikofero\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_0", - "sat": "def sat(x: int, a=1073258, b=72352549):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=1073258, b=72352549):\n return b - a" + "name": "ListSetLen:0", + "sat": "def sat(li: List[int], dups=42155):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=42155):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_1", - "sat": "def sat(x: int, a=7176599374880969, b=1013347182263591):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=7176599374880969, b=1013347182263591):\n return b - a" + "name": "ListSetLen:1", + "sat": "def sat(li: List[int], dups=18793):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=18793):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_2", - "sat": "def sat(x: int, a=-6408240447142191, b=7741323537672506):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=-6408240447142191, b=7741323537672506):\n return b - a" + "name": "ListSetLen:2", + "sat": "def sat(li: List[int], dups=70976):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=70976):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_3", - "sat": "def sat(x: int, a=1918969259925371, b=3648647147996329):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=1918969259925371, b=3648647147996329):\n return b - a" + "name": "ListSetLen:3", + "sat": "def sat(li: List[int], dups=23476):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=23476):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_4", - "sat": "def sat(x: int, a=6476308373242647, b=-1096573562602401):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=6476308373242647, b=-1096573562602401):\n return b - a" + "name": "ListSetLen:4", + "sat": "def sat(li: List[int], dups=17633):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=17633):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_5", - "sat": "def sat(x: int, a=3541708844857762, b=8119147055443164):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=3541708844857762, b=8119147055443164):\n return b - a" + "name": "ListMul:0", + "sat": "def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[17, 9, -1, 17, 9, -1], n=2):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_6", - "sat": "def sat(x: int, a=2470722232128688, b=-5028343403938117):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=2470722232128688, b=-5028343403938117):\n return b - a" + "name": "ListMul:1", + "sat": "def sat(li: List[int], target=[-69358, -69358, -69358, -69358, -69358, -69358, -69358], n=7):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[-69358, -69358, -69358, -69358, -69358, -69358, -69358], n=7):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_7", - "sat": "def sat(x: int, a=6213545451615198, b=-5169743892107078):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=6213545451615198, b=-5169743892107078):\n return b - a" + "name": "ListMul:2", + "sat": "def sat(li: List[int], target=[-51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344], n=8):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[-51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344, -51721, -18394, -51187, -39897, 18547, 42761, -8992, 66683, 78344], n=8):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_8", - "sat": "def sat(x: int, a=-1793507176516986, b=906620763200238):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=-1793507176516986, b=906620763200238):\n return b - a" + "name": "ListMul:3", + "sat": "def sat(li: List[int], target=[], n=0):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[], n=0):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSum_9", - "sat": "def sat(x: int, a=-8219517037412163, b=-9529321409062134):\n \"\"\"Solve a sum problem\"\"\"\n return a + x == b", - "sols": [ - "def sol(a=-8219517037412163, b=-9529321409062134):\n return b - a" + "name": "ListMul:4", + "sat": "def sat(li: List[int], target=[-25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766], n=4):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[-25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766, -25821, -22076, 28354, -16195, 51325, 54104, -89614, 9766], n=4):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_0", - "sat": "def sat(x: int, a=-382, b=14546310):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=-382, b=14546310):\n return a + b" + "name": "ListLen:0", + "sat": "def sat(li: List[int], n=85012):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=85012):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_1", - "sat": "def sat(x: int, a=4461955033869751, b=-3951840325269410):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=4461955033869751, b=-3951840325269410):\n return a + b" + "name": "ListLen:1", + "sat": "def sat(li: List[int], n=969):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=969):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_2", - "sat": "def sat(x: int, a=9688203125538303, b=-293093369321912):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=9688203125538303, b=-293093369321912):\n return a + b" + "name": "ListLen:2", + "sat": "def sat(li: List[int], n=7051):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=7051):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_3", - "sat": "def sat(x: int, a=-8057207922876252, b=-3934955257447294):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=-8057207922876252, b=-3934955257447294):\n return a + b" + "name": "ListLen:3", + "sat": "def sat(li: List[int], n=9):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=9):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_4", - "sat": "def sat(x: int, a=-5902383651753979, b=304676399871652):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=-5902383651753979, b=304676399871652):\n return a + b" + "name": "ListLen:4", + "sat": "def sat(li: List[int], n=324):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=324):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_5", - "sat": "def sat(x: int, a=5498221257462810, b=-9891180759896604):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=5498221257462810, b=-9891180759896604):\n return a + b" + "name": "ListAt:0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_6", - "sat": "def sat(x: int, a=2546817180926413, b=-8288757594299903):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=2546817180926413, b=-8288757594299903):\n return a + b" + "name": "ListAt:1", + "sat": "def sat(i: int, li=[-62, -29, 73, -21, -45, -20, -74, -69, 30, -25, 16, 82, -31, 93, -20, 75, 68, 86], target=73):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[-62, -29, 73, -21, -45, -20, -74, -69, 30, -25, 16, 82, -31, 93, -20, 75, 68, 86], target=73):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_7", - "sat": "def sat(x: int, a=9039770925479206, b=-9382105729343163):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=9039770925479206, b=-9382105729343163):\n return a + b" + "name": "ListAt:2", + "sat": "def sat(i: int, li=[99, 51, -28, -69, -90, -15, 7, -67], target=51):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[99, 51, -28, -69, -90, -15, 7, -67], target=51):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_8", - "sat": "def sat(x: int, a=1111642902890242, b=-8616943790453980):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=1111642902890242, b=-8616943790453980):\n return a + b" + "name": "ListAt:3", + "sat": "def sat(i: int, li=[-68, 81, 13, -5, 81, 75, -3, -73, -89, 72], target=13):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[-68, 81, 13, -5, 81, 75, -3, -73, -89, 72], target=13):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub_9", - "sat": "def sat(x: int, a=2707884935014088, b=-4121789062688033):\n \"\"\"Solve a subtraction problem\"\"\"\n return x - a == b", - "sols": [ - "def sol(a=2707884935014088, b=-4121789062688033):\n return a + b" + "name": "ListAt:4", + "sat": "def sat(i: int, li=[51, -68, -57, 8, 77, -80, -28, -24, 11, 40, 57, 60, 53], target=11):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[51, -68, -57, 8, 77, -80, -28, -24, 11, 40, 57, 60, 53], target=11):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_0", - "sat": "def sat(x: int, a=8665464, b=-93206):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=8665464, b=-93206):\n return a - b" + "name": "ListNegAt:0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_1", - "sat": "def sat(x: int, a=1954051265970332, b=1312727165482691):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=1954051265970332, b=1312727165482691):\n return a - b" + "name": "ListNegAt:1", + "sat": "def sat(i: int, li=[78, 91, -67, -5, 30, -42, 68, 32, 96, -55, -39, -46, 90], target=-39):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[78, 91, -67, -5, 30, -42, 68, 32, 96, -55, -39, -46, 90], target=-39):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_2", - "sat": "def sat(x: int, a=-1159353965692778, b=4654551691407885):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=-1159353965692778, b=4654551691407885):\n return a - b" + "name": "ListNegAt:2", + "sat": "def sat(i: int, li=[-60, 9, 1, -42, 31, 70, 5, 1, 42, -90, -20], target=-42):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[-60, 9, 1, -42, 31, 70, 5, 1, 42, -90, -20], target=-42):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_3", - "sat": "def sat(x: int, a=7793575617602525, b=-4351726326349125):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=7793575617602525, b=-4351726326349125):\n return a - b" + "name": "ListNegAt:3", + "sat": "def sat(i: int, li=[41, -52, -40, -35, 53, -98, 83, 63, -18, 74, -8, -93, -3, 22, 30], target=53):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[41, -52, -40, -35, 53, -98, 83, 63, -18, 74, -8, -93, -3, 22, 30], target=53):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_4", - "sat": "def sat(x: int, a=-8783800228130606, b=-508993556991975):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=-8783800228130606, b=-508993556991975):\n return a - b" + "name": "ListNegAt:4", + "sat": "def sat(i: int, li=[95, 51, 76, 63, -97, -32], target=-32):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[95, 51, 76, 63, -97, -32], target=-32):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_5", - "sat": "def sat(x: int, a=6214511989468522, b=-8611041646123069):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=6214511989468522, b=-8611041646123069):\n return a - b" + "name": "ListSlice:0", + "sat": "def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_6", - "sat": "def sat(x: int, a=7674217578186899, b=-2906122028473779):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=7674217578186899, b=-2906122028473779):\n return a - b" + "name": "ListSlice:1", + "sat": "def sat(inds: List[int], li=[-11, 92, 42, 18, -83, 55, 13, 14, -67, -58, -41], target=[-67]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[-11, 92, 42, 18, -83, 55, 13, 14, -67, -58, -41], target=[-67]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_7", - "sat": "def sat(x: int, a=-1762426008738689, b=2542059490113964):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=-1762426008738689, b=2542059490113964):\n return a - b" + "name": "ListSlice:2", + "sat": "def sat(inds: List[int], li=[-53, -81, -92, 22, -67], target=[-53, -81, -92]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[-53, -81, -92, 22, -67], target=[-53, -81, -92]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_8", - "sat": "def sat(x: int, a=3024187717652921, b=-1062459210015505):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=3024187717652921, b=-1062459210015505):\n return a - b" + "name": "ListSlice:3", + "sat": "def sat(inds: List[int], li=[-72, 70, 50, -41, 94, -82, -74, 8, -23], target=[-82]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[-72, 70, 50, -41, 94, -82, -74, 8, -23], target=[-82]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSub2_9", - "sat": "def sat(x: int, a=1193813353593933, b=-5380052017072375):\n \"\"\"Solve a subtraction problem\"\"\"\n return a - x == b", - "sols": [ - "def sol(a=1193813353593933, b=-5380052017072375):\n return a - b" + "name": "ListSlice:4", + "sat": "def sat(inds: List[int], li=[26, -25, -18, -53, 18, -71, -82, 20, -100, -84, -85], target=[-25]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[26, -25, -18, -53, 18, -71, -82, 20, -100, -84, -85], target=[-25]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_0", - "sat": "def sat(n: int, a=14302, b=5):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=14302, b=5):\n return a // b" + "name": "ListIndex:0", + "sat": "def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[17, 2, 3, 9, 11, 11], index=4):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_1", - "sat": "def sat(n: int, a=-646156, b=-63):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=-646156, b=-63):\n return a // b" + "name": "ListIndex:1", + "sat": "def sat(item: int, li=[93, -13, -56, 19], index=2):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[93, -13, -56, 19], index=2):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_2", - "sat": "def sat(n: int, a=159568, b=59):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=159568, b=59):\n return a // b" + "name": "ListIndex:2", + "sat": "def sat(item: int, li=[-79, 49, 4, -75, -66, -76, 37, -62, -35, -79, 68, 82, -11, -71, 63, -82, 22, 65], index=2):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[-79, 49, 4, -75, -66, -76, 37, -62, -35, -79, 68, 82, -11, -71, 63, -82, 22, 65], index=2):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_3", - "sat": "def sat(n: int, a=-141336, b=72):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=-141336, b=72):\n return a // b" + "name": "ListIndex:3", + "sat": "def sat(item: int, li=[96, -61, 50, -49, -1, -23, -35], index=3):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[96, -61, 50, -49, -1, -23, -35], index=3):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_4", - "sat": "def sat(n: int, a=855955, b=33):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=855955, b=33):\n return a // b" + "name": "ListIndex:4", + "sat": "def sat(item: int, li=[26, -90, 89], index=0):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[26, -90, 89], index=0):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_5", - "sat": "def sat(n: int, a=508648, b=63):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=508648, b=63):\n return a // b" + "name": "ListIndex2:0", + "sat": "def sat(li: List[int], i=29, index=10412):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=29, index=10412):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_6", - "sat": "def sat(n: int, a=359259, b=-73):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=359259, b=-73):\n return a // b" + "name": "ListIndex2:1", + "sat": "def sat(li: List[int], i=-99167, index=48792):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=-99167, index=48792):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_7", - "sat": "def sat(n: int, a=415700, b=98):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=415700, b=98):\n return a // b" + "name": "ListIndex2:2", + "sat": "def sat(li: List[int], i=-67679, index=87059):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=-67679, index=87059):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_8", - "sat": "def sat(n: int, a=-2722, b=31):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=-2722, b=31):\n return a // b" + "name": "ListIndex2:3", + "sat": "def sat(li: List[int], i=81395, index=79231):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=81395, index=79231):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntMul_9", - "sat": "def sat(n: int, a=-419340, b=-89):\n \"\"\"Solve a multiplication problem\"\"\"\n return b * n + (a % b) == a", - "sols": [ - "def sol(a=-419340, b=-89):\n return a // b" + "name": "ListIndex2:4", + "sat": "def sat(li: List[int], i=63344, index=1583):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=63344, index=1583):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_0", - "sat": "def sat(n: int, a=3, b=23463462):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=3, b=23463462):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "ListIn:0", + "sat": "def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_1", - "sat": "def sat(n: int, a=-1, b=1594400229362061):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=-1, b=1594400229362061):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "ListIn:1", + "sat": "def sat(s: str, a=['xetex', 'jomuboxuc', 'nyfiranuri', 'curu', 'jehykexethinun', 'bumekynuxinit', 'cymelatabegi', 'jumuvufotextasa', 'cotharasyfukakiwoc', 'fuvyvavi', 'gohavelomet', 'hibymomotohywehathi', 'jyzucakaq', 'chihyx', 'wukikogy', 'pegydozetebegafugyf', 'chywadetextekesyjup', 'xysecaw', 'ryzafusul', 'lojychurep', 'vivutolimifa', 'pysiquikywoty', 'thitexturykasoquifet', 'va', 'nagetextilac', 'tex', 'zechocha', 'susatexty', 'ch'], b=['vesaredu', 'textyjun', 'hijilenafotycoch', 'fofytextulidajekymos', 'thudothukuzaxug', 'dythezutolihibinafyj', 'hadid', 'zyly', 'mu', 'chywadetextekesyjup', 'zekyrivequi', 'pebycipohivam', 'texterekuwudut', 'c', 'sanidithuh', 'ritextuchik', 'ny', 'cym', 'cirok', 'kavuquithochazethej', 'zikechep', 'kesitabuduzu', 'duchequ', 'fuluhesowyjugehusab', 'tof', 'tu', 'textichagekochoquovo', 'bo', 'thac', 'hytextac', 'nerehufymex', 'jezyletextiquebositi', 'm', 'kathithowefyvoced', 'rityjivoxadydyzatiq', 'nuxaritutebacygevyq', 'thyjaxirumenaquuxy', 'gizydylot', 'textite', 'guchikek', 'fas', 'pabipapiro', 'fechiduchu', 'pexijis', 'gojep', 'quinatextit', 'chaqu', 'xyxyjos', 'pudibothytigiwumucex', 'josadubizy', 'jy', 'komazibomapothequev', 'licogatextuliletuxi', 'gus', 'nylyxyjibikimet', 'tafo']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['xetex', 'jomuboxuc', 'nyfiranuri', 'curu', 'jehykexethinun', 'bumekynuxinit', 'cymelatabegi', 'jumuvufotextasa', 'cotharasyfukakiwoc', 'fuvyvavi', 'gohavelomet', 'hibymomotohywehathi', 'jyzucakaq', 'chihyx', 'wukikogy', 'pegydozetebegafugyf', 'chywadetextekesyjup', 'xysecaw', 'ryzafusul', 'lojychurep', 'vivutolimifa', 'pysiquikywoty', 'thitexturykasoquifet', 'va', 'nagetextilac', 'tex', 'zechocha', 'susatexty', 'ch'], b=['vesaredu', 'textyjun', 'hijilenafotycoch', 'fofytextulidajekymos', 'thudothukuzaxug', 'dythezutolihibinafyj', 'hadid', 'zyly', 'mu', 'chywadetextekesyjup', 'zekyrivequi', 'pebycipohivam', 'texterekuwudut', 'c', 'sanidithuh', 'ritextuchik', 'ny', 'cym', 'cirok', 'kavuquithochazethej', 'zikechep', 'kesitabuduzu', 'duchequ', 'fuluhesowyjugehusab', 'tof', 'tu', 'textichagekochoquovo', 'bo', 'thac', 'hytextac', 'nerehufymex', 'jezyletextiquebositi', 'm', 'kathithowefyvoced', 'rityjivoxadydyzatiq', 'nuxaritutebacygevyq', 'thyjaxirumenaquuxy', 'gizydylot', 'textite', 'guchikek', 'fas', 'pabipapiro', 'fechiduchu', 'pexijis', 'gojep', 'quinatextit', 'chaqu', 'xyxyjos', 'pudibothytigiwumucex', 'josadubizy', 'jy', 'komazibomapothequev', 'licogatextuliletuxi', 'gus', 'nylyxyjibikimet', 'tafo']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_2", - "sat": "def sat(n: int, a=12, b=-9988218457242775):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=12, b=-9988218457242775):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "ListIn:2", + "sat": "def sat(s: str, a=['bututimatabel', 'zezahabiry', 'mipytext', 'bujokacyrulihir', 'cyvagofaquothoseza', 'guhebalequepytex', 'tyhithuthygatextity', 'chizichuc', 'textoxodenekokechona', 'texte', 'mygafifet', 'vixathokivy', 'xe', 'moq', 'quokopy', 'cixoka', 'wiz', 'wyturasutabidipif', 'q', 'gochujuvub', 'textogow', 'rogizasog', 'fimoxynudob', 'byjythohimowyquich', 'moduxatanogococ', 'tunuchikywichykyxyge', 'namixotextes', 'nocoguthosoxonahu', 'xorydyhi', 'dadohojex', 'pi', 'wiquocaso', 'tyjegu', 'juquath', 'dythufyn', 'sehafur', 'sylupivyzequefujet', 'hotextylyquahudivov', 'wunich', 'fijyhilyc', 'rirymequunezuv', 'zizunylihadowys', 'zesuxikevaquus', 'thecisequevyth', 'cucyquefytextu', 'xy', 'quuxin', 'miherahita', 'texatextoxyta', 'tythyjuly', 'tehesyju', 'reg', 'ridilusycanejap', 'fo', 'chucatazyrejucathibi', 'textythacete', 'huhiquekychyh', 'xykuvebylyhinyc', 'zadedixoxoparyducena', 'wycathomoniva', 'textuwuwathiziq', 'textijiw', 'rigidichukuchexorute', 'majixodokalij', 'hexebitoxumuvodese', 'hybat', 'thojutextomochote', 'textaxuquyg', 'queluhatex'], b=['gume', 'zatum', 'kochaxybupy', 'gex', 'vithiby', 'lygarethaquedehabub', 'tochek', 'v', 'wis', 'remywerinyboweropot', 'nybichychafizurup', 'zokabugyc', 'ny', 'moruwicoponuricuw', 'zirijikuhabivywah', 'dus', 'toxirit', 'gilanih', 'hif', 'vuhezobinehahewi', 'quujihus', 'chej', 'g', 'pypomaquiwusisyvuma', 'to', 'c', 'chutesumalanozeb', 'chupehozukiquodisese', 'xygiwot', 'semubaquav', 'pihiwidosudetextet', 'quegatagicu', 'quutydychy', 'chuzeby', 'jefythasapag', 'bytathoti', 'thimobaquykisabepec', 'saluwax', 'thi', 'kyneroravexuquoto', 'jusudybahebuxypepahe', 'f', 'zapufefek', 'mumogawen', 'quotyhot', 'hybamukelo', 'picatextujycotodyj', 'be', 'pytextyfa', 'tile', 'dotextazuchubuk', 'choguc', 'wi', 'setepicydavumahebe', 'wyjo', 'mirukuwyfuwihoqu', 'q', 'kegytegu', 'kegoquibyguxexajebid', 'hyfech', 'humovomefoly', 'tupetox', 'gevogibax', 'vuxotext', 'miluparaj', 'bathad', 'tily', 'theranydygiryc', 'dasaxatext', 'guhebalequepytex', 'v', 'gocuxomecapylewaj']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['bututimatabel', 'zezahabiry', 'mipytext', 'bujokacyrulihir', 'cyvagofaquothoseza', 'guhebalequepytex', 'tyhithuthygatextity', 'chizichuc', 'textoxodenekokechona', 'texte', 'mygafifet', 'vixathokivy', 'xe', 'moq', 'quokopy', 'cixoka', 'wiz', 'wyturasutabidipif', 'q', 'gochujuvub', 'textogow', 'rogizasog', 'fimoxynudob', 'byjythohimowyquich', 'moduxatanogococ', 'tunuchikywichykyxyge', 'namixotextes', 'nocoguthosoxonahu', 'xorydyhi', 'dadohojex', 'pi', 'wiquocaso', 'tyjegu', 'juquath', 'dythufyn', 'sehafur', 'sylupivyzequefujet', 'hotextylyquahudivov', 'wunich', 'fijyhilyc', 'rirymequunezuv', 'zizunylihadowys', 'zesuxikevaquus', 'thecisequevyth', 'cucyquefytextu', 'xy', 'quuxin', 'miherahita', 'texatextoxyta', 'tythyjuly', 'tehesyju', 'reg', 'ridilusycanejap', 'fo', 'chucatazyrejucathibi', 'textythacete', 'huhiquekychyh', 'xykuvebylyhinyc', 'zadedixoxoparyducena', 'wycathomoniva', 'textuwuwathiziq', 'textijiw', 'rigidichukuchexorute', 'majixodokalij', 'hexebitoxumuvodese', 'hybat', 'thojutextomochote', 'textaxuquyg', 'queluhatex'], b=['gume', 'zatum', 'kochaxybupy', 'gex', 'vithiby', 'lygarethaquedehabub', 'tochek', 'v', 'wis', 'remywerinyboweropot', 'nybichychafizurup', 'zokabugyc', 'ny', 'moruwicoponuricuw', 'zirijikuhabivywah', 'dus', 'toxirit', 'gilanih', 'hif', 'vuhezobinehahewi', 'quujihus', 'chej', 'g', 'pypomaquiwusisyvuma', 'to', 'c', 'chutesumalanozeb', 'chupehozukiquodisese', 'xygiwot', 'semubaquav', 'pihiwidosudetextet', 'quegatagicu', 'quutydychy', 'chuzeby', 'jefythasapag', 'bytathoti', 'thimobaquykisabepec', 'saluwax', 'thi', 'kyneroravexuquoto', 'jusudybahebuxypepahe', 'f', 'zapufefek', 'mumogawen', 'quotyhot', 'hybamukelo', 'picatextujycotodyj', 'be', 'pytextyfa', 'tile', 'dotextazuchubuk', 'choguc', 'wi', 'setepicydavumahebe', 'wyjo', 'mirukuwyfuwihoqu', 'q', 'kegytegu', 'kegoquibyguxexajebid', 'hyfech', 'humovomefoly', 'tupetox', 'gevogibax', 'vuxotext', 'miluparaj', 'bathad', 'tily', 'theranydygiryc', 'dasaxatext', 'guhebalequepytex', 'v', 'gocuxomecapylewaj']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_3", - "sat": "def sat(n: int, a=0, b=-1230085432451862):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=0, b=-1230085432451862):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "ListIn:3", + "sat": "def sat(s: str, a=['thachak', 'xuchyzyzazi', 'bilewejoquowylo', 'chogokim', 'kuloxozu', 'capokaf', 'didadadejunukosazi', 'zethucun', 'tygorub', 'lochydigyt', 'dyquuhycusi', 'wagupolovapy', 'chowace', 'zozawethychax', 'xohuhuqui', 'tatylisigar', 'c', 'kakopuzysycasewit', 'rekatebinidyvuchitet', 'popi', 'chepebaze', 'textut', 'fymehap', 'c', 'wodumogovolacabasot', 'tixihidafutexto', 'dycubichucyneweve', 'setofa', 'cudaxediquy', 'namof', 'qua', 'chetextof', 'cochydededaxyzuj', 'winutaj', 'nidyjutothovobydizy', 'sichequaxohojethihy', 'cubusycip', 'pynoconic', 'kyt', 'thop', 'kewotochelocyboz', 'z', 'c', 'q', 'bonyquyx', 'jothec', 'fyzozynygiperythada', 'lipadatuzisaduthyt', 'nithujyxymethot', 'vewariq', 'nejitextole', 'raxiv', 'hamim', 'qua', 'kytextehekaryp', 'jaquu', 'wozuthevith', 'f', 'jugevizyfu', 'cywo', 'w', 'surajotext', 'vilujetutitachivy', 'textequysuninutuqu', 'fevawybok', 'lythehythu', 'nykochachofitit', 'gikenadubit', 'thexyjy', 'piquyzyxichoc', 'rilaquucham', 'fa', 'mysihumotexto', 'xochogekumipoquidi', 'jimynusyte', 'textexysuzipichaw', 'mut', 'jiwyx', 'tojiwedoxevosubavy', 'dix', 'dogetexto', 'chysafyzelefocothin', 'xitext', 'machibokudyh', 'ronebupapapygyceb', 'dedytejyretavewytasi', 'jobog', 'namychyt', 'textycapudul', 'jaxybatexto', 'pamuwysafupaxowus', 'lycazivafyj', 'lelologufenofajogofi', 'thety', 'bunotextoca', 'nexaravuq', 'natu'], b=['namychyt', 'mathapachobat', 'timorohopotak']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['thachak', 'xuchyzyzazi', 'bilewejoquowylo', 'chogokim', 'kuloxozu', 'capokaf', 'didadadejunukosazi', 'zethucun', 'tygorub', 'lochydigyt', 'dyquuhycusi', 'wagupolovapy', 'chowace', 'zozawethychax', 'xohuhuqui', 'tatylisigar', 'c', 'kakopuzysycasewit', 'rekatebinidyvuchitet', 'popi', 'chepebaze', 'textut', 'fymehap', 'c', 'wodumogovolacabasot', 'tixihidafutexto', 'dycubichucyneweve', 'setofa', 'cudaxediquy', 'namof', 'qua', 'chetextof', 'cochydededaxyzuj', 'winutaj', 'nidyjutothovobydizy', 'sichequaxohojethihy', 'cubusycip', 'pynoconic', 'kyt', 'thop', 'kewotochelocyboz', 'z', 'c', 'q', 'bonyquyx', 'jothec', 'fyzozynygiperythada', 'lipadatuzisaduthyt', 'nithujyxymethot', 'vewariq', 'nejitextole', 'raxiv', 'hamim', 'qua', 'kytextehekaryp', 'jaquu', 'wozuthevith', 'f', 'jugevizyfu', 'cywo', 'w', 'surajotext', 'vilujetutitachivy', 'textequysuninutuqu', 'fevawybok', 'lythehythu', 'nykochachofitit', 'gikenadubit', 'thexyjy', 'piquyzyxichoc', 'rilaquucham', 'fa', 'mysihumotexto', 'xochogekumipoquidi', 'jimynusyte', 'textexysuzipichaw', 'mut', 'jiwyx', 'tojiwedoxevosubavy', 'dix', 'dogetexto', 'chysafyzelefocothin', 'xitext', 'machibokudyh', 'ronebupapapygyceb', 'dedytejyretavewytasi', 'jobog', 'namychyt', 'textycapudul', 'jaxybatexto', 'pamuwysafupaxowus', 'lycazivafyj', 'lelologufenofajogofi', 'thety', 'bunotextoca', 'nexaravuq', 'natu'], b=['namychyt', 'mathapachobat', 'timorohopotak']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_4", - "sat": "def sat(n: int, a=1, b=9554566410382856):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=1, b=9554566410382856):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "ListIn:4", + "sat": "def sat(s: str, a=['quisolu', 'nixyquigaseq', 'fawaholafojelaxud', 'cuxoniso', 'defejaz', 'mytext', 'gochavowetheva', 'xijehychojexat', 'duthagobejudozi', 'thiquijuquorybu'], b=['cys', 'zatext', 'cifihihechujozimo', 'jycichithetyk', 'becitonamuhuligyv', 'sadak', 'hochavinapatanapiz', 'fiwidifop', 'funidosikeput', 'fewat', 'mypyhalevituvit', 'quytynuthothy', 'c', 'zydecodul', 'vahychuke', 'wy', 'mytext', 'tex', 'quevasowodique', 'hythiquunymychilyl', 'luxivyvocuwa']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['quisolu', 'nixyquigaseq', 'fawaholafojelaxud', 'cuxoniso', 'defejaz', 'mytext', 'gochavowetheva', 'xijehychojexat', 'duthagobejudozi', 'thiquijuquorybu'], b=['cys', 'zatext', 'cifihihechujozimo', 'jycichithetyk', 'becitonamuhuligyv', 'sadak', 'hochavinapatanapiz', 'fiwidifop', 'funidosikeput', 'fewat', 'mypyhalevituvit', 'quytynuthothy', 'c', 'zydecodul', 'vahychuke', 'wy', 'mytext', 'tex', 'quevasowodique', 'hythiquunymychilyl', 'luxivyvocuwa']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_5", - "sat": "def sat(n: int, a=0, b=-276228241058354):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=0, b=-276228241058354):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "IntNeg:0", + "sat": "def sat(x: int, a=93252338):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=93252338):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_6", - "sat": "def sat(n: int, a=0, b=-274724668334318):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=0, b=-274724668334318):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "IntNeg:1", + "sat": "def sat(x: int, a=-7788910835979672):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=-7788910835979672):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_7", - "sat": "def sat(n: int, a=9, b=6914625274738508):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=9, b=6914625274738508):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "IntNeg:2", + "sat": "def sat(x: int, a=6734672221833987):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=6734672221833987):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_8", - "sat": "def sat(n: int, a=0, b=-4177591550350946):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=0, b=-4177591550350946):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "IntNeg:3", + "sat": "def sat(x: int, a=-6405550227918699):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=-6405550227918699):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv_9", - "sat": "def sat(n: int, a=0, b=-849200640448927):\n \"\"\"Solve a division problem\"\"\"\n return b // n == a", - "sols": [ - "def sol(a=0, b=-849200640448927):\n if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + "name": "IntNeg:4", + "sat": "def sat(x: int, a=-5741705983914418):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=-5741705983914418):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_0", - "sat": "def sat(n: int, a=345346363, b=10):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=345346363, b=10):\n return a * b" + "name": "IntSum:0", + "sat": "def sat(x: int, a=1073258, b=72352549):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=1073258, b=72352549):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_1", - "sat": "def sat(n: int, a=-3411193412414137, b=-9070455318026063):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=-3411193412414137, b=-9070455318026063):\n return a * b" + "name": "IntSum:1", + "sat": "def sat(x: int, a=7176599374880969, b=1013347182263591):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=7176599374880969, b=1013347182263591):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_2", - "sat": "def sat(n: int, a=-1950797984487873, b=6211965468307518):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=-1950797984487873, b=6211965468307518):\n return a * b" + "name": "IntSum:2", + "sat": "def sat(x: int, a=-6408240447142191, b=7741323537672506):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=-6408240447142191, b=7741323537672506):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_3", - "sat": "def sat(n: int, a=1186580710227962, b=5023840456205809):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=1186580710227962, b=5023840456205809):\n return a * b" + "name": "IntSum:3", + "sat": "def sat(x: int, a=1918969259925371, b=3648647147996329):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=1918969259925371, b=3648647147996329):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_4", - "sat": "def sat(n: int, a=6976962948831358, b=7353202892973126):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=6976962948831358, b=7353202892973126):\n return a * b" + "name": "IntSum:4", + "sat": "def sat(x: int, a=6476308373242647, b=-1096573562602401):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=6476308373242647, b=-1096573562602401):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_5", - "sat": "def sat(n: int, a=6915856560694709, b=111742990835085):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=6915856560694709, b=111742990835085):\n return a * b" + "name": "IntSub:0", + "sat": "def sat(x: int, a=-382, b=14546310):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=-382, b=14546310):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_6", - "sat": "def sat(n: int, a=-1104852978631057, b=-2557967407440761):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=-1104852978631057, b=-2557967407440761):\n return a * b" + "name": "IntSub:1", + "sat": "def sat(x: int, a=4461955033869751, b=-3951840325269410):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=4461955033869751, b=-3951840325269410):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_7", - "sat": "def sat(n: int, a=-8329742804301532, b=-4106654512441311):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=-8329742804301532, b=-4106654512441311):\n return a * b" + "name": "IntSub:2", + "sat": "def sat(x: int, a=9688203125538303, b=-293093369321912):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=9688203125538303, b=-293093369321912):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_8", - "sat": "def sat(n: int, a=5829099404610510, b=-9465246152168141):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=5829099404610510, b=-9465246152168141):\n return a * b" + "name": "IntSub:3", + "sat": "def sat(x: int, a=-8057207922876252, b=-3934955257447294):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=-8057207922876252, b=-3934955257447294):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntDiv2_9", - "sat": "def sat(n: int, a=-9597642365529250, b=9338198117879192):\n \"\"\"Find n that when divided by b is a\"\"\"\n return n // b == a", - "sols": [ - "def sol(a=-9597642365529250, b=9338198117879192):\n return a * b" + "name": "IntSub:4", + "sat": "def sat(x: int, a=-5902383651753979, b=304676399871652):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=-5902383651753979, b=304676399871652):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_0", - "sat": "def sat(x: int, a=10201202001):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=10201202001):\n return int(a ** 0.5)" + "name": "IntSub2:0", + "sat": "def sat(x: int, a=8665464, b=-93206):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=8665464, b=-93206):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_1", - "sat": "def sat(x: int, a=2617350631613713636):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=2617350631613713636):\n return int(a ** 0.5)" + "name": "IntSub2:1", + "sat": "def sat(x: int, a=1954051265970332, b=1312727165482691):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=1954051265970332, b=1312727165482691):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_2", - "sat": "def sat(x: int, a=100703210763886864):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=100703210763886864):\n return int(a ** 0.5)" + "name": "IntSub2:2", + "sat": "def sat(x: int, a=-1159353965692778, b=4654551691407885):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=-1159353965692778, b=4654551691407885):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_3", - "sat": "def sat(x: int, a=12515426721927424):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=12515426721927424):\n return int(a ** 0.5)" + "name": "IntSub2:3", + "sat": "def sat(x: int, a=7793575617602525, b=-4351726326349125):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=7793575617602525, b=-4351726326349125):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_4", - "sat": "def sat(x: int, a=717898768141464900):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=717898768141464900):\n return int(a ** 0.5)" + "name": "IntSub2:4", + "sat": "def sat(x: int, a=-8783800228130606, b=-508993556991975):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=-8783800228130606, b=-508993556991975):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_5", - "sat": "def sat(x: int, a=34566678107587921):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=34566678107587921):\n return int(a ** 0.5)" + "name": "IntMul:0", + "sat": "def sat(n: int, a=14302, b=5):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=14302, b=5):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_6", - "sat": "def sat(x: int, a=2028472882871898241):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=2028472882871898241):\n return int(a ** 0.5)" + "name": "IntMul:1", + "sat": "def sat(n: int, a=-646156, b=-63):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=-646156, b=-63):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_7", - "sat": "def sat(x: int, a=528495436396871056):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=528495436396871056):\n return int(a ** 0.5)" + "name": "IntMul:2", + "sat": "def sat(n: int, a=159568, b=59):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=159568, b=59):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_8", - "sat": "def sat(x: int, a=170282665120852804):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=170282665120852804):\n return int(a ** 0.5)" + "name": "IntMul:3", + "sat": "def sat(n: int, a=-141336, b=72):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=-141336, b=72):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntSquareRoot_9", - "sat": "def sat(x: int, a=2665388170439145649):\n \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"\n return x ** 2 == a", - "sols": [ - "def sol(a=2665388170439145649):\n return int(a ** 0.5)" + "name": "IntMul:4", + "sat": "def sat(n: int, a=855955, b=33):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=855955, b=33):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_0", - "sat": "def sat(n: int, a=10000200001):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=10000200001):\n return -int(a ** 0.5)" + "name": "IntDiv:0", + "sat": "def sat(n: int, a=3, b=23463462):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=3, b=23463462):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_1", - "sat": "def sat(n: int, a=1153723843107852129):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=1153723843107852129):\n return -int(a ** 0.5)" + "name": "IntDiv:1", + "sat": "def sat(n: int, a=-1, b=1594400229362061):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=-1, b=1594400229362061):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_2", - "sat": "def sat(n: int, a=1940392439040171204):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=1940392439040171204):\n return -int(a ** 0.5)" + "name": "IntDiv:2", + "sat": "def sat(n: int, a=12, b=-9988218457242775):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=12, b=-9988218457242775):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_3", - "sat": "def sat(n: int, a=1256820805863398416):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=1256820805863398416):\n return -int(a ** 0.5)" + "name": "IntDiv:3", + "sat": "def sat(n: int, a=0, b=-1230085432451862):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=0, b=-1230085432451862):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_4", - "sat": "def sat(n: int, a=1001282815140004804):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=1001282815140004804):\n return -int(a ** 0.5)" + "name": "IntDiv:4", + "sat": "def sat(n: int, a=1, b=9554566410382856):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=1, b=9554566410382856):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_5", - "sat": "def sat(n: int, a=4297881936637423044):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=4297881936637423044):\n return -int(a ** 0.5)" + "name": "IntDiv2:0", + "sat": "def sat(n: int, a=345346363, b=10):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=345346363, b=10):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_6", - "sat": "def sat(n: int, a=901603700046197316):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=901603700046197316):\n return -int(a ** 0.5)" + "name": "IntDiv2:1", + "sat": "def sat(n: int, a=-3411193412414137, b=-9070455318026063):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=-3411193412414137, b=-9070455318026063):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_7", - "sat": "def sat(n: int, a=2156393767640395024):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=2156393767640395024):\n return -int(a ** 0.5)" + "name": "IntDiv2:2", + "sat": "def sat(n: int, a=-1950797984487873, b=6211965468307518):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=-1950797984487873, b=6211965468307518):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_8", - "sat": "def sat(n: int, a=1854864342930062025):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=1854864342930062025):\n return -int(a ** 0.5)" + "name": "IntDiv2:3", + "sat": "def sat(n: int, a=1186580710227962, b=5023840456205809):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=1186580710227962, b=5023840456205809):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "IntNegSquareRoot_9", - "sat": "def sat(n: int, a=131276886753682576):\n \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"\n return a == n * n and n < 0", - "sols": [ - "def sol(a=131276886753682576):\n return -int(a ** 0.5)" + "name": "IntDiv2:4", + "sat": "def sat(n: int, a=6976962948831358, b=7353202892973126):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=6976962948831358, b=7353202892973126):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_0", - "sat": "def sat(x: float, a=1020):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=1020):\n return a ** 0.5" + "name": "IntSquareRoot:0", + "sat": "def sat(x: int, a=10201202001):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=10201202001):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_1", - "sat": "def sat(x: float, a=6173281296):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=6173281296):\n return a ** 0.5" + "name": "IntSquareRoot:1", + "sat": "def sat(x: int, a=2617350631613713636):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=2617350631613713636):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_2", - "sat": "def sat(x: float, a=7987622700):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=7987622700):\n return a ** 0.5" + "name": "IntSquareRoot:2", + "sat": "def sat(x: int, a=100703210763886864):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=100703210763886864):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_3", - "sat": "def sat(x: float, a=2732656229):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=2732656229):\n return a ** 0.5" + "name": "IntSquareRoot:3", + "sat": "def sat(x: int, a=12515426721927424):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=12515426721927424):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_4", - "sat": "def sat(x: float, a=1873585696):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=1873585696):\n return a ** 0.5" + "name": "IntSquareRoot:4", + "sat": "def sat(x: int, a=717898768141464900):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=717898768141464900):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_5", - "sat": "def sat(x: float, a=1479828086):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=1479828086):\n return a ** 0.5" + "name": "IntNegSquareRoot:0", + "sat": "def sat(n: int, a=10000200001):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=10000200001):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_6", - "sat": "def sat(x: float, a=1072333649):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=1072333649):\n return a ** 0.5" + "name": "IntNegSquareRoot:1", + "sat": "def sat(n: int, a=1153723843107852129):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=1153723843107852129):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_7", - "sat": "def sat(x: float, a=164552138):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=164552138):\n return a ** 0.5" + "name": "IntNegSquareRoot:2", + "sat": "def sat(n: int, a=1940392439040171204):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=1940392439040171204):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_8", - "sat": "def sat(x: float, a=9291191277):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=9291191277):\n return a ** 0.5" + "name": "IntNegSquareRoot:3", + "sat": "def sat(n: int, a=1256820805863398416):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=1256820805863398416):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatSquareRoot_9", - "sat": "def sat(x: float, a=4371856557):\n \"\"\"Find a number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3", - "sols": [ - "def sol(a=4371856557):\n return a ** 0.5" + "name": "IntNegSquareRoot:4", + "sat": "def sat(n: int, a=1001282815140004804):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=1001282815140004804):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_0", - "sat": "def sat(x: float, a=1020):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=1020):\n return -a ** 0.5" + "name": "FloatSquareRoot:0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=1020):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_1", - "sat": "def sat(x: float, a=2681275499):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=2681275499):\n return -a ** 0.5" + "name": "FloatSquareRoot:1", + "sat": "def sat(x: float, a=6173281296):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=6173281296):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_2", - "sat": "def sat(x: float, a=1363713245):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=1363713245):\n return -a ** 0.5" + "name": "FloatSquareRoot:2", + "sat": "def sat(x: float, a=7987622700):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=7987622700):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_3", - "sat": "def sat(x: float, a=3858703402):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=3858703402):\n return -a ** 0.5" + "name": "FloatSquareRoot:3", + "sat": "def sat(x: float, a=2732656229):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=2732656229):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_4", - "sat": "def sat(x: float, a=3804892221):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=3804892221):\n return -a ** 0.5" + "name": "FloatSquareRoot:4", + "sat": "def sat(x: float, a=1873585696):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=1873585696):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_5", - "sat": "def sat(x: float, a=9399317163):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=9399317163):\n return -a ** 0.5" + "name": "FloatNegSquareRoot:0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=1020):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_6", - "sat": "def sat(x: float, a=7349408781):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=7349408781):\n return -a ** 0.5" + "name": "FloatNegSquareRoot:1", + "sat": "def sat(x: float, a=2681275499):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=2681275499):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_7", - "sat": "def sat(x: float, a=3812748747):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=3812748747):\n return -a ** 0.5" + "name": "FloatNegSquareRoot:2", + "sat": "def sat(x: float, a=1363713245):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=1363713245):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_8", - "sat": "def sat(x: float, a=4501107522):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=4501107522):\n return -a ** 0.5" + "name": "FloatNegSquareRoot:3", + "sat": "def sat(x: float, a=3858703402):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=3858703402):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "FloatNegSquareRoot_9", - "sat": "def sat(x: float, a=3192570063):\n \"\"\"Find a negative number that when squared is close to a.\"\"\"\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", - "sols": [ - "def sol(a=3192570063):\n return -a ** 0.5" + "name": "FloatNegSquareRoot:4", + "sat": "def sat(x: float, a=3804892221):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=3804892221):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" ], - "module": "trivial_inverse", + "module": "trivial_inverse.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.002564102564102564 + "weight": 0.2 }, { - "name": "Tutorial1_0", - "sat": "def sat(s: str):\n \"\"\"Find a string that when concatenated onto 'Hello ' gives 'Hello world'.\"\"\"\n return \"Hello \" + s == \"Hello world\"", - "sols": [ - "def sol():\n return \"world\"" + "name": "Tutorial1:0", + "sat": "def sat(s: str):\n return \"Hello \" + s == \"Hello world\"", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return \"world\"" ], - "module": "tutorial", + "module": "tutorial.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.2 + "weight": 1.0 }, { - "name": "Tutorial2_0", - "sat": "def sat(s: str):\n \"\"\"Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.\"\"\"\n return \"Hello \" + s[::-1] == \"Hello world\"", - "sols": [ - "def sol():\n return \"world\"[::-1]" + "name": "Tutorial2:0", + "sat": "def sat(s: str):\n return \"Hello \" + s[::-1] == \"Hello world\"", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return \"world\"[::-1]" ], - "module": "tutorial", + "module": "tutorial.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.2 + "weight": 1.0 }, { - "name": "Tutorial3_0", - "sat": "def sat(x: List[int]):\n \"\"\"Find a list of two integers whose sum is 3.\"\"\"\n return len(x) == 2 and sum(x) == 3", - "sols": [ - "def sol():\n return [1, 2]" + "name": "Tutorial3:0", + "sat": "def sat(x: List[int]):\n return len(x) == 2 and sum(x) == 3", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of two integers whose sum is 3.\"\"\"", + "sol_bodies": [ + " return [1, 2]" ], - "module": "tutorial", + "module": "tutorial.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.2 + "weight": 1.0 }, { - "name": "Tutorial4_0", - "sat": "def sat(s: List[str]):\n \"\"\"Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.\"\"\"\n return len(set(s)) == 1000 and all((x.count(\"a\") > x.count(\"b\")) and ('b' in x) for x in s)", - "sols": [ - "def sol():\n return [\"a\" * (i + 2) + \"b\" for i in range(1000)]" + "name": "Tutorial4:0", + "sat": "def sat(s: List[str]):\n return len(set(s)) == 1000 and all((x.count(\"a\") > x.count(\"b\")) and ('b' in x) for x in s)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.\"\"\"", + "sol_bodies": [ + " return [\"a\" * (i + 2) + \"b\" for i in range(1000)]" ], - "module": "tutorial", + "module": "tutorial.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.2 + "weight": 1.0 }, { - "name": "Tutorial5_0", - "sat": "def sat(n: int):\n \"\"\"Find an integer whose perfect square begins with 123456789 in its decimal representation.\"\"\"\n return str(n * n).startswith(\"123456789\")", - "sols": [ - "def sol():\n return int(int(\"123456789\" + \"0\" * 9) ** 0.5) + 1" + "name": "Tutorial5:0", + "sat": "def sat(n: int):\n return str(n * n).startswith(\"123456789\")", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer whose perfect square begins with 123456789 in its decimal representation.\"\"\"", + "sol_bodies": [ + " return int(int(\"123456789\" + \"0\" * 9) ** 0.5) + 1" ], - "module": "tutorial", + "module": "tutorial.py", "notes": "", - "taint_date": "2021-4-26", - "weight": 0.2 + "weight": 1.0 } ] \ No newline at end of file diff --git a/puzzles/split.json b/puzzles/split.json new file mode 100644 index 0000000..c4c1c3a --- /dev/null +++ b/puzzles/split.json @@ -0,0 +1,389 @@ +{ + "train": [ + "Abbreviate", + "AllQuadraticRoots", + "AnyPath", + "AnyTriangle", + "ArithmeticSequence", + "BallotProblem", + "BasicStrCounts", + "BillSums", + "BirthdayParadoxMonteCarlo", + "BoxVolume", + "CapitalizeFirstLetter", + "CenteredString", + "CheckersPosition", + "ClockAngle", + "CollatzCycleUnsolved", + "CollatzDelay", + "CollatzGeneralizedUnsolved", + "CombinationLock", + "CombinationLockObfuscated", + "CommonCase", + "CompareInAnyCase", + "CompleteParens", + "ConcatStrings", + "Conway99", + "Count47", + "CumulativeSum", + "Dada", + "DecreasingCountComparison", + "DistinctDigits", + "DistinctOddSum", + "DominoTile", + "Easy63", + "EasySum", + "EasyTwos", + "EightQueensOrFewer", + "EvenPath", + "FermatsLastTheorem", + "FindProductiveList", + "FindRepeats", + "FivePowers", + "FloatNegSquareRoot", + "FloatSquareRoot", + "FloatWithDecimalValue", + "FourSquares", + "GCD", + "GCD_multi", + "GimmeChars", + "GraphIsomorphism", + "HalfPairs", + "Harder63", + "HelloWorld", + "IfCases", + "IfProblemWithOr", + "IncDec", + "IntDiv", + "IntDiv2", + "IntMul", + "IntNeg", + "IntSquareRoot", + "IntSub", + "IntSub2", + "IntSum", + "InvertIndices", + "InvertPermutation", + "Kirkman", + "KnightsTour", + "LCM", + "LCM_multi", + "LearnParity", + "LearnParityWithNoise", + "Lehmer", + "LineIntersection", + "ListAt", + "ListDistinctSum", + "ListIn", + "ListMul", + "ListNegAt", + "ListPosSum", + "ListSetLen", + "ListSlice", + "LongestSubsetString", + "MatchingMarkers", + "MaxConsecutiveProduct", + "MaxConsecutiveSum", + "MaxDelta", + "MaybeReversed", + "MinConsecutiveSum", + "MinRotations", + "MonkeyAndCoconuts", + "Nash", + "NecklaceSplit", + "Nim", + "No3Colinear", + "NoRelativePrimes", + "OddPath", + "OnesAndTwos", + "PandigitalSquare", + "PenultimateRevString", + "PenultimateString", + "PostageStamp", + "QuadraticRoot", + "RepeatDec", + "ReverseCat", + "ReverseLifeStep", + "RockPaperScissors", + "SameDifferent", + "ShortestPath", + "Spaceship", + "SquareTiles", + "SquaringTheSquare", + "Sstriiinggssuubb", + "StrAdd", + "StrCount", + "StrIn", + "StrIn2", + "StrIndex", + "StrIndex2", + "StrJoiner", + "StrLen", + "StrParts", + "StrSlice", + "Study_1", + "Study_11", + "Study_13", + "Study_15", + "Study_17", + "Study_19", + "Study_21", + "Study_23", + "Study_25", + "Study_27", + "Study_29", + "Study_3", + "Study_5", + "Study_7", + "Study_9", + "SublistSum", + "SubstrCount", + "SumOfDigits", + "TotalDifference", + "Triple0", + "TripleDouble", + "Tutorial1", + "Tutorial2", + "Tutorial3", + "Tutorial4", + "Tutorial5", + "UNSOLVED_UncrossedKnightsPath", + "UncrossedKnightsPath", + "UnweightedShortestPath", + "VerbalArithmetic", + "VowelDrop", + "WaterPouring", + "ZipStr", + "Znam" + ], + "test": [ + "AllCubicRoots", + "AllPandigitalSquares", + "AllPrefixes", + "AlternatingFactorials", + "AntiShuffle", + "AnyEdge", + "ArrayDiff", + "BackWorlds", + "BackwardsDigits", + "BiPermutations", + "BigOdds", + "BiggestEven", + "BiggestK", + "Binarize", + "BinaryAverage", + "BinarySort", + "BinaryStrXOR", + "BinomialProbabilities", + "BirthdayParadox", + "BitSum", + "BooleanPythagoreanTriples", + "CardGame24", + "CatStrings", + "CeilingSquares", + "CertifiedGCD", + "ChangeBase", + "CharCounts", + "CharSum", + "ClosestInteger", + "ClosestPalindrome", + "CommonNumbers", + "CompleteSplit", + "ConsonantFilter", + "CubeRoot", + "CubicRoot", + "CumulativeSums", + "DateDiff", + "Dedup", + "DeepestParens", + "DelPalindrome", + "Derivative", + "DiffChars", + "DiscreteLog", + "DistinctChars", + "Drops", + "EngineerNumbers", + "EvaluateOperators", + "Even4Sum", + "EvenBetween", + "EvenOddDigits", + "EvenOddSum", + "EvenPalindromeNumbers", + "EvenWords", + "ExpandSpaces", + "ExponentialCoinMoves", + "ExponentialProbability", + "Factor47", + "FactorString", + "Factoring", + "FermatComposites", + "Fib3", + "Fib4", + "Fibonacci", + "FilenameOK", + "FilterInts", + "FindBored", + "FindCloseElements", + "FindClosePair", + "FindContainers", + "FindExtensions", + "FindHomogeneousSubstring", + "FindPositives", + "FindVowels", + "FirstNegCumulative", + "FlipCase", + "Frac", + "GCD17", + "GeometricSequence", + "Grader", + "GreatestHIndex", + "HalfSorted", + "HalfTag", + "HeronTriangle", + "HexPrimes", + "IdentifyZeroTrips", + "IfProblem", + "IfProblemWithAnd", + "IncreasingViolation", + "IntNegSquareRoot", + "IntegerLog", + "Intersperse", + "InverseSuperFactorial", + "InvestigateCrash", + "IsEven", + "LZW", + "LargestDivisor", + "LargestNegSmallestPos", + "LargestPrimeDigitSum", + "LargestPrimeFactor", + "LargestStringNum", + "LastLetters", + "LexPath", + "ListInc", + "ListIndex", + "ListIndex2", + "ListLen", + "LittleFermat", + "LongEarlySum", + "LongestMonotonicSubstring", + "LongestMonotonicSubstringTricky", + "LongestStr", + "Mastermind", + "MaxInt", + "Median", + "MinBigger", + "MinSquaredDeviation", + "MissingBananas", + "Monotonic", + "MoreQueens", + "MostUnique", + "Moving0s", + "NarrowerList", + "NearbyDuplicates", + "NumPasses", + "OddCase", + "OddCollatz", + "OddDegreePolynomialRoot", + "OddProduct", + "OneEnded", + "OptimalBridges", + "Oscillators", + "OverlappingCount", + "PackingHam", + "PairZeroSum", + "Palindrome", + "PalindromeContaining", + "ParenDepth", + "ParenthesesPermutation", + "ParityExchange", + "ParseMusic", + "PickNearNeighbors", + "PlanetRange", + "PlantedClique", + "PositiveDigitSums", + "PrimeFactorization", + "PrimeFib", + "PrimeIntervalIntersection", + "PrimeSel", + "PrimeWords", + "PrimesUpTo", + "ProductSigns", + "PythagoreanTriples", + "Quine", + "Rescale", + "RevQuine", + "RollingMax", + "RomanNumerals", + "RotateSort", + "RotateString", + "SecondSmallestUnique", + "SeparateParenGroups", + "SevenElevenThirteen", + "ShiftChars", + "ShortIntegerPath", + "ShortestDecDelta", + "SimplifyProductFraction", + "SlidingOne", + "SlidingPuzzle", + "SmallExponentBigSolution", + "SmallestEven", + "SortByDigitSum", + "SortNumbers", + "SortPlusPlus", + "SortedOdds", + "SpaceyRange", + "Sssuubbstriiingg", + "StonePiles", + "StrAt", + "StrLength", + "StrMul", + "StrMul2", + "StrNegAt", + "StrSetLen", + "StrSplit", + "StrSplitter", + "StrangeSplit", + "Study_10", + "Study_12", + "Study_14", + "Study_16", + "Study_18", + "Study_2", + "Study_20", + "Study_22", + "Study_24", + "Study_26", + "Study_28", + "Study_30", + "Study_4", + "Study_6", + "Study_8", + "SubstitutionCypher", + "Sudoku", + "SumProduct", + "ThreeCubes", + "ThreeCycle", + "ThreePrimes", + "Threeples", + "TicTacToeO", + "TicTacToeX", + "TowersOfHanoi", + "TowersOfHanoiArbitrary", + "TriangleArea", + "Tribonacci", + "TripleZeroSum", + "TwoThirdsSorted", + "UnevenFind", + "UniqueSorted", + "UnitsProduct", + "UpDownSort", + "UppercaseEven", + "ValidBracketSubsequence", + "VowelSandwich", + "WeirdDecodeVowels", + "WildSort", + "Zarankiewicz", + "ZeroSum", + "ZobristCollision" + ] +} \ No newline at end of file diff --git a/solvers/codex/138puzzles.json b/solvers/codex/138puzzles.json new file mode 100644 index 0000000..132d9ea --- /dev/null +++ b/solvers/codex/138puzzles.json @@ -0,0 +1,968 @@ +[ + { + "name": "Nash_0", + "sat": "def sat(strategies: List[List[float]], A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "sol_docstring": " \"\"\"Compute a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n [bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game). While this problem was known to be\n PPAD-hard in general. In fact the challenge is be much easier for an approximate\n [eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.\"\"\"", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[-1.0, -3.0], [0.0, -2.0]], B=[[-1.0, 0.0], [-3.0, -2.0]], eps=0.01):" + }, + { + "name": "ZeroSum_0", + "sat": "def sat(strategies: List[List[float]], A=[[0.0, -1.0, 1.0], [1.0, 0.0, -1.0], [-1.0, 1.0, 0.0]], eps=0.1):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "sol_docstring": " \"\"\"Compute minimax optimal strategies for a given\n [zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\n Linear Programming.\"\"\"", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.0, -1.0, 1.0], [1.0, 0.0, -1.0], [-1.0, 1.0, 0.0]], eps=0.1):" + }, + { + "name": "BirthdayParadox_0", + "sat": "def sat(n: int, year_len=365):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "sol_docstring": " \"\"\"Find `n` such that the probability of two people having the same birthday in a group of `n` is near `1/2`.\n The year length is year_len (365 is earth, while Neptune year is 60,182)\n See [Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category))\"\"\"", + "ans_type": "int", + "sol_header": "def sol(year_len=365):" + }, + { + "name": "ExponentialProbability_0", + "sat": "def sat(p_stop: float, steps=10, target_prob=0.5):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "sol_docstring": " \"\"\"Find stopping probability, so that the probability of stopping in `steps` or fewer time steps\n is the given `target_prob`.\n See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)\"\"\"", + "ans_type": "float", + "sol_header": "def sol(steps=10, target_prob=0.5):" + }, + { + "name": "LZW_0", + "sat": "def sat(seq: List[int], compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "sol_docstring": " \"\"\"Find a (short) compression that decompresses to the given string.\n We have provided a simple version of the *decompression* algorithm of\n [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\n so the solution is the *compression* algorithm.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):" + }, + { + "name": "PackingHam_0", + "sat": "def sat(words: List[str], num=100, bits=100, dist=34):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\n \n This is a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces) in coding theory.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol(num=100, bits=100, dist=34):" + }, + { + "name": "FindRepeats_0", + "sat": "def sat(indices: List[int], a0=123):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "sol_docstring": " \"\"\"Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n \n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n \n Sample input:\n 9\n \n Sample output:\n [0, 3, 6, ..., 2997]\n \n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \n Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\n for a_0 not divisible by 3.\n \n Inspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(a0=123):" + }, + { + "name": "FindProductiveList_0", + "sat": "def sat(li: List[int], n=6):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "sol_docstring": " \"\"\"Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n \n Sample input:\n 6\n \n Sample output:\n [_, _, _, _, _, _]\n \n (Sample output hidden because showing sample output would give away too much information.)\n \n Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\n exists for non-multiples of 3.\n \n Inspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=6):" + }, + { + "name": "HalfTag_0", + "sat": "def sat(li: List[int], n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]):\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "sol_docstring": " \"\"\"The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n \n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n \n Sample output:\n [0, 3, 5, 6, 8, 11]\n \n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \n Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=3, tags=[0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]):" + }, + { + "name": "AllQuadraticRoots_0", + "sat": "def sat(roots: List[float], coeffs=[1.3, -0.5]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "sol_docstring": " \"\"\"Find all (real) solutions for a [quadratic equation](https://en.wikipedia.org/wiki/Quadratic_formula)\n x^2 + b x + c (i.e., factor into roots)\"\"\"", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[1.3, -0.5]):" + }, + { + "name": "SumOfDigits_0", + "sat": "def sat(x: str, s=679):\n return s == sum([int(d) for d in x])", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "ans_type": "str", + "sol_header": "def sol(s=679):" + }, + { + "name": "FloatWithDecimalValue_0", + "sat": "def sat(z: float, v=9, d=0.0001):\n return int(z * 1/d % 10) == v", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "ans_type": "float", + "sol_header": "def sol(v=9, d=0.0001):" + }, + { + "name": "ArithmeticSequence_0", + "sat": "def sat(x: List[int], a=7, s=5, e=200):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i+1] for i in range(len(x)-1)])", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(a=7, s=5, e=200):" + }, + { + "name": "GeometricSequence_0", + "sat": "def sat(x: List[int], a=8, r=2, l=50):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i+1] for i in range(len(x)-1)])", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(a=8, r=2, l=50):" + }, + { + "name": "LineIntersection_0", + "sat": "def sat(e: List[int], a=2, b=-1, c=1, d=2021):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "sol_docstring": " \"\"\"Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(a=2, b=-1, c=1, d=2021):" + }, + { + "name": "IfProblem_0", + "sat": "def sat(x: int, a=324554, b=1345345):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "sol_docstring": " \"\"\"Simple if statement\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=324554, b=1345345):" + }, + { + "name": "IfProblemWithAnd_0", + "sat": "def sat(x: int, a=9384594, b=1343663):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "sol_docstring": " \"\"\"Simple if statement with and clause\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=9384594, b=1343663):" + }, + { + "name": "IfProblemWithOr_0", + "sat": "def sat(x: int, a=253532, b=1230200):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "sol_docstring": " \"\"\"Simple if statement with or clause\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=253532, b=1230200):" + }, + { + "name": "IfCases_0", + "sat": "def sat(x: int, a=4, b=54368639):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "sol_docstring": " \"\"\"Simple if statement with multiple cases\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=4, b=54368639):" + }, + { + "name": "ListPosSum_0", + "sat": "def sat(x: List[int], n=5, s=19):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "sol_docstring": " \"\"\"Construct a list of non-negative integers that sum up to some value\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=5, s=19):" + }, + { + "name": "ListDistinctSum_0", + "sat": "def sat(x: List[int], n=4, s=2021):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "sol_docstring": " \"\"\"Construct a list of distinct integers that sum up to some value\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=4, s=2021):" + }, + { + "name": "ConcatStrings_0", + "sat": "def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "sol_docstring": " \"\"\"Concatenate list of characters\"\"\"", + "ans_type": "str", + "sol_header": "def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):" + }, + { + "name": "SublistSum_0", + "sat": "def sat(x: List[int], t=677, a=43, e=125, s=10):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(t=677, a=43, e=125, s=10):" + }, + { + "name": "CumulativeSum_0", + "sat": "def sat(x: List[int], t=50, n=10):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "sol_docstring": " \"\"\"Number of values with cumulative sum less than target\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(t=50, n=10):" + }, + { + "name": "BasicStrCounts_0", + "sat": "def sat(s: str, s1=\"a\", s2=\"b\", count1=50, count2=30):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "sol_docstring": " \"\"\"Find a string that has `count1` occurrences of `s1` and `count1` occurrences of `s1` and starts and ends with\n the same 10 characters\"\"\"", + "ans_type": "str", + "sol_header": "def sol(s1=\"a\", s2=\"b\", count1=50, count2=30):" + }, + { + "name": "ReverseCat_0", + "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "sol_docstring": " \"\"\"Find a string that contains all the `substrings` reversed and forward\"\"\"", + "ans_type": "str", + "sol_header": "def sol(substrings=['foo', 'bar', 'baz']):" + }, + { + "name": "EngineerNumbers_0", + "sat": "def sat(ls: List[str], n=100, a=\"bar\", b=\"foo\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "sol_docstring": " \"\"\"Find a list of `n` strings starting with `a` and ending with `b`\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol(n=100, a=\"bar\", b=\"foo\"):" + }, + { + "name": "PenultimateString_0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s in strings and sum(t > s for t in strings) == 1", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):" + }, + { + "name": "PenultimateRevString_0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):" + }, + { + "name": "CenteredString_0", + "sat": "def sat(s: str, target=\"foobarbazwow\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "sol_docstring": " \"\"\"Find a substring of length `length` centered within `target`.\"\"\"", + "ans_type": "str", + "sol_header": "def sol(target=\"foobarbazwow\", length=6):" + }, + { + "name": "Abbreviate_0", + "sat": "def sat(s: str, word=\"antidisestablishmentarianism\", max_len=10):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "sol_docstring": " \"\"\"Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \n Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)\"\"\"", + "ans_type": "str", + "sol_header": "def sol(word=\"antidisestablishmentarianism\", max_len=10):" + }, + { + "name": "DecreasingCountComparison_0", + "sat": "def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "sol_docstring": " \"\"\"Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \n Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):" + }, + { + "name": "IncDec_0", + "sat": "def sat(n: int, ops=['x++', '--x', '--x'], target=19143212):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "sol_docstring": " \"\"\"This straightforward problem is a little harder than the Codeforces one.\n Given a sequence of operations \"++x\",\n \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the final value is the target value.\n \n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n \n Sample Output:\n 13\n \n Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(ops=['x++', '--x', '--x'], target=19143212):" + }, + { + "name": "SlidingOne_0", + "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "sol_docstring": " \"\"\"We are given a 5x5 bimatrix with a single 1 like:\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n \n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \n Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)\"\"\"", + "ans_type": "str", + "sol_header": "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):" + }, + { + "name": "SortPlusPlus_0", + "sat": "def sat(s: str, inp=\"1+1+3+1+3+2+2+1+3+1+2\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\n \n Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)\"\"\"", + "ans_type": "str", + "sol_header": "def sol(inp=\"1+1+3+1+3+2+2+1+3+1+2\"):" + }, + { + "name": "FindHomogeneousSubstring_0", + "sat": "def sat(n: int, s=\"0000111111100000\", k=5):\n return s[n:n + k] == s[n] * k", + "sol_docstring": " \"\"\"You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n \n Sample Input:\n s = 01010000111111100000, k = 5\n \n Sample Output:\n 8\n (or 9 or 10 or 15)\n \n Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(s=\"0000111111100000\", k=5):" + }, + { + "name": "FivePowers_0", + "sat": "def sat(s: str, n=7):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\n \n Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)\"\"\"", + "ans_type": "str", + "sol_header": "def sol(n=7):" + }, + { + "name": "CombinationLock_0", + "sat": "def sat(states: List[str], start=\"012\", combo=\"329\", target_len=6):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "sol_docstring": " \"\"\"Shortest Combination Lock Path\n \n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10)\n e.g.\n start = \"120\"\n combo = \"293\"\n \n output: ['220', '210', '200', '290', '291', '292']\n \n Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"012\", combo=\"329\", target_len=6):" + }, + { + "name": "CombinationLockObfuscated_0", + "sat": "def sat(states: List[str], start=\"012\", combo=\"329\", target_len=6):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "sol_docstring": " \"\"\"An obfuscated version of CombinationLock above\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"012\", combo=\"329\", target_len=6):" + }, + { + "name": "InvertPermutation_0", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\n \n Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)\"\"\"", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):" + }, + { + "name": "OnesAndTwos_0", + "sat": "def sat(seq: List[int], n=10000, length=5017):\n return set(seq) <= {1, 2} and sum(seq) == n and len(seq) == length", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\n \n Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=10000, length=5017):" + }, + { + "name": "MinConsecutiveSum_0", + "sat": "def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\n \n Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):" + }, + { + "name": "MaxConsecutiveSum_0", + "sat": "def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\n \n Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):" + }, + { + "name": "MaxConsecutiveProduct_0", + "sat": "def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\n \n Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):" + }, + { + "name": "MinRotations_0", + "sat": "def sat(rotations: List[int], target=\"dad\", upper=9):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "sol_docstring": " \"\"\"We begin with the string `\"a...z\"`\n \n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n \n For example if the string was `'fab'`, the minimal rotations would be `[5, -5, 1]` with a total of `11`.\n \n Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"dad\", upper=9):" + }, + { + "name": "KnightsTour_0", + "sat": "def sat(tour: List[List[int]], m=8, n=8):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "sol_docstring": " \"\"\"Knights Tour\n \n Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\n \n See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)\"\"\"", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8):" + }, + { + "name": "GCD_0", + "sat": "def sat(n: int, a=15482, b=23223, lower_bound=5):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "sol_docstring": " \"\"\"[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n (GCD)\n \n Find the greatest common divisor of two integers.\n \n See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=15482, b=23223, lower_bound=5):" + }, + { + "name": "GCD_multi_0", + "sat": "def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "sol_docstring": " \"\"\"[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n (GCD)\n \n Find the greatest common divisor of a *list* of integers.\n \n See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(nums=[77410, 23223, 54187], lower_bound=2):" + }, + { + "name": "LCM_multi_0", + "sat": "def sat(n: int, nums=[15, 27, 102], upper_bound=5000):\n return all(n % i == 0 for i in nums) and n <= upper_bound", + "sol_docstring": " \"\"\"[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n (LCM)\n \n Find the least common multiple of a list of integers.\n \n See also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(nums=[15, 27, 102], upper_bound=5000):" + }, + { + "name": "SmallExponentBigSolution_0", + "sat": "def sat(n: int, b=2, target=5):\n return (b ** n) % n == target", + "sol_docstring": " \"\"\"Small exponent, big solution\n \n Solve for n: b^n = target (mod n)\n \n Problems have small b and target but solution is typically a large n.\n Some of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n \n See [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)\"\"\"", + "ans_type": "int", + "sol_header": "def sol(b=2, target=5):" + }, + { + "name": "ThreeCubes_0", + "sat": "def sat(nums: List[int], target=10):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "sol_docstring": " \"\"\"Sum of three cubes\n \n Given `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\n Conjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n `a`, `b`, `c` may be positive or negative\n \n See [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n [Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(target=10):" + }, + { + "name": "FourSquares_0", + "sat": "def sat(nums: List[int], n=12345):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "sol_docstring": " \"\"\"Sum of four squares\n \n [Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n \n Given a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\n integers. The problem here is to find them. This is a nice problem and we give an elementary solution\n that runs in time \tilde{O}(n),\n which is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\n algorithm using quaternions is described in the book:\n [\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n \n The first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=12345):" + }, + { + "name": "Factoring_0", + "sat": "def sat(i: int, n=62710561):\n return 1 < i < n and n % i == 0", + "sol_docstring": " \"\"\"[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n [RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n \n The factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\n simple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\n which include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\n with hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\n continue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n \n From Wikipedia:\n \n RSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\n cash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\n unless considerable advances are made in integer factorization or computational power in the near future.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(n=62710561):" + }, + { + "name": "CollatzDelay_0", + "sat": "def sat(n: int, t=100, upper=10):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "sol_docstring": " \"\"\"Collatz Delay\n \n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1 in the Collatz process. For instance,\n the number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n 2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n \n Now, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\n number of bits of the solution to be upper.\n \n See [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(t=100, upper=10):" + }, + { + "name": "Tutorial1_0", + "sat": "def sat(s: str):\n return \"Hello \" + s == \"Hello world\"", + "sol_docstring": " \"\"\"Find a string that when concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Tutorial2_0", + "sat": "def sat(s: str):\n return \"Hello \" + s[::-1] == \"Hello world\"", + "sol_docstring": " \"\"\"Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Tutorial3_0", + "sat": "def sat(x: List[int]):\n return len(x) == 2 and sum(x) == 3", + "sol_docstring": " \"\"\"Find a list of two integers whose sum is 3.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Tutorial4_0", + "sat": "def sat(s: List[str]):\n return len(set(s)) == 1000 and all((x.count(\"a\") > x.count(\"b\")) and ('b' in x) for x in s)", + "sol_docstring": " \"\"\"Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Tutorial5_0", + "sat": "def sat(n: int):\n return str(n * n).startswith(\"123456789\")", + "sol_docstring": " \"\"\"Find an integer whose perfect square begins with 123456789 in its decimal representation.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "HelloWorld_0", + "sat": "def sat(s: str):\n return s + 'world' == 'Hello world'", + "sol_docstring": " \"\"\"Trivial example, no solutions provided\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "BackWorlds_0", + "sat": "def sat(s: str):\n return s[::-1] + 'world' == 'Hello world'", + "sol_docstring": " \"\"\"Two solutions, no inputs\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "StrAdd_0", + "sat": "def sat(st: str, a=\"world\", b=\"Hello world\"):\n return st + a == b", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "ans_type": "str", + "sol_header": "def sol(a=\"world\", b=\"Hello world\"):" + }, + { + "name": "StrSetLen_0", + "sat": "def sat(s: str, dups=2021):\n return len(set(s)) == len(s) - dups", + "sol_docstring": " \"\"\"Find a string with `dups` duplicate chars\"\"\"", + "ans_type": "str", + "sol_header": "def sol(dups=2021):" + }, + { + "name": "StrMul_0", + "sat": "def sat(s: str, target=\"foofoofoofoo\", n=2):\n return s * n == target", + "sol_docstring": " \"\"\"Find a string which when repeated `n` times gives `target`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(target=\"foofoofoofoo\", n=2):" + }, + { + "name": "StrMul2_0", + "sat": "def sat(n: int, target=\"foofoofoofoo\", s=\"foofoo\"):\n return s * n == target", + "sol_docstring": " \"\"\"Find `n` such that `s` repeated `n` times gives `target`\"\"\"", + "ans_type": "int", + "sol_header": "def sol(target=\"foofoofoofoo\", s=\"foofoo\"):" + }, + { + "name": "StrLen_0", + "sat": "def sat(s: str, n=1000):\n return len(s) == n", + "sol_docstring": " \"\"\"Find a string of length `n`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(n=1000):" + }, + { + "name": "StrAt_0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target", + "sol_docstring": " \"\"\"Find the index of `target` in string `s`\"\"\"", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):" + }, + { + "name": "StrNegAt_0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target and i < 0", + "sol_docstring": " \"\"\"Find the index of `target` in `s` using a negative index.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):" + }, + { + "name": "StrSlice_0", + "sat": "def sat(inds: List[int], s=\"hello world\", target=\"do\"):\n i, j, k = inds\n return s[i:j:k] == target", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific `target` in string `s`\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"hello world\", target=\"do\"):" + }, + { + "name": "StrIndex_0", + "sat": "def sat(s: str, big_str=\"foobar\", index=2):\n return big_str.index(s) == index", + "sol_docstring": " \"\"\"Find a string whose *first* index in `big_str` is `index`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(big_str=\"foobar\", index=2):" + }, + { + "name": "StrIndex2_0", + "sat": "def sat(big_str: str, sub_str=\"foobar\", index=2):\n return big_str.index(sub_str) == index", + "sol_docstring": " \"\"\"Find a string whose *first* index of `sub_str` is `index`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"foobar\", index=2):" + }, + { + "name": "StrIn_0", + "sat": "def sat(s: str, a=\"hello\", b=\"yellow\", length=4):\n return len(s) == length and s in a and s in b", + "sol_docstring": " \"\"\"Find a string of length `length` that is in both strings `a` and `b`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(a=\"hello\", b=\"yellow\", length=4):" + }, + { + "name": "ListSetLen_0", + "sat": "def sat(li: List[int], dups=42155):\n return len(set(li)) == len(li) - dups", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(dups=42155):" + }, + { + "name": "ListMul_0", + "sat": "def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2):\n return li * n == target", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(target=[17, 9, -1, 17, 9, -1], n=2):" + }, + { + "name": "ListLen_0", + "sat": "def sat(li: List[int], n=85012):\n return len(li) == n", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(n=85012):" + }, + { + "name": "ListAt_0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18):\n return li[i] == target", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18):" + }, + { + "name": "ListNegAt_0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91):\n return li[i] == target and i < 0", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91):" + }, + { + "name": "ListSlice_0", + "sat": "def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):\n i, j, k = inds\n return li[i:j:k] == target", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):" + }, + { + "name": "ListIndex_0", + "sat": "def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4):\n return li.index(item) == index", + "sol_docstring": " \"\"\"Find the item whose first index in `li` is `index`\"\"\"", + "ans_type": "int", + "sol_header": "def sol(li=[17, 2, 3, 9, 11, 11], index=4):" + }, + { + "name": "ListIndex2_0", + "sat": "def sat(li: List[int], i=29, index=10412):\n return li.index(i) == index", + "sol_docstring": " \"\"\"Find a list that contains `i` first at index `index`\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(i=29, index=10412):" + }, + { + "name": "ListIn_0", + "sat": "def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):\n return s in a and s in b", + "sol_docstring": " \"\"\"Find an item that is in both lists `a` and `b`\"\"\"", + "ans_type": "str", + "sol_header": "def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):" + }, + { + "name": "IntNeg_0", + "sat": "def sat(x: int, a=93252338):\n return -x == a", + "sol_docstring": " \"\"\"Solve unary negation problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=93252338):" + }, + { + "name": "IntSum_0", + "sat": "def sat(x: int, a=1073258, b=72352549):\n return a + x == b", + "sol_docstring": " \"\"\"Solve sum problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=1073258, b=72352549):" + }, + { + "name": "IntSub_0", + "sat": "def sat(x: int, a=-382, b=14546310):\n return x - a == b", + "sol_docstring": " \"\"\"Solve subtraction problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=-382, b=14546310):" + }, + { + "name": "IntSub2_0", + "sat": "def sat(x: int, a=8665464, b=-93206):\n return a - x == b", + "sol_docstring": " \"\"\"Solve subtraction problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=8665464, b=-93206):" + }, + { + "name": "IntMul_0", + "sat": "def sat(n: int, a=14302, b=5):\n return b * n + (a % b) == a", + "sol_docstring": " \"\"\"Solve multiplication problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=14302, b=5):" + }, + { + "name": "IntDiv_0", + "sat": "def sat(n: int, a=3, b=23463462):\n return b // n == a", + "sol_docstring": " \"\"\"Solve division problem\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=3, b=23463462):" + }, + { + "name": "IntDiv2_0", + "sat": "def sat(n: int, a=345346363, b=10):\n return n // b == a", + "sol_docstring": " \"\"\"Find `n` that when divided by `b` is `a`\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=345346363, b=10):" + }, + { + "name": "IntSquareRoot_0", + "sat": "def sat(x: int, a=10201202001):\n return x ** 2 == a", + "sol_docstring": " \"\"\"Compute square root of number.\n The target has a round (integer) square root.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=10201202001):" + }, + { + "name": "IntNegSquareRoot_0", + "sat": "def sat(n: int, a=10000200001):\n return a == n * n and n < 0", + "sol_docstring": " \"\"\"Compute negative square root of number.\n The target has a round (integer) square root.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(a=10000200001):" + }, + { + "name": "FloatSquareRoot_0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3", + "sol_docstring": " \"\"\"Compute square root of number.\n The target might not have a round solution.\n Accuracy of third decimal digit is required.\"\"\"", + "ans_type": "float", + "sol_header": "def sol(a=1020):" + }, + { + "name": "FloatNegSquareRoot_0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "sol_docstring": " \"\"\"Compute (negative) square root of number.\n The target might not have a round solution.\n Accuracy of third decimal digit is required.\"\"\"", + "ans_type": "float", + "sol_header": "def sol(a=1020):" + }, + { + "name": "LongestMonotonicSubstringTricky_0", + "sat": "def sat(x: List[int], length=20, s=\"Dynamic programming solves this puzzle!!!\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", + "sol_docstring": " \"\"\"Find the indices of the longest substring with characters in sorted order, with a twist!\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(length=20, s=\"Dynamic programming solves this puzzle!!!\"):" + }, + { + "name": "ClockAngle_0", + "sat": "def sat(hands: List[int], target_angle=45):\n hour, min = hands\n return hour in range(1, 13) and min in range(60) and ((60 * hour + min) - 12 * min) % 720 == 2 * target_angle", + "sol_docstring": " \"\"\"[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem)\n \n Easy variant checks if angle at li = [hour, min] is a given number of degrees.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(target_angle=45):" + }, + { + "name": "MonkeyAndCoconuts_0", + "sat": "def sat(n: int):\n for i in range(5):\n assert n % 5 == 1\n n -= 1 + (n - 1) // 5\n return n > 0 and n % 5 == 1", + "sol_docstring": " \"\"\"[The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts)\n \n Find the number of coconuts to solve the following riddle quoted from\n [Wikipedia article](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts):\n There is a pile of coconuts, owned by five men.\n One man divides the pile into five equal piles, giving the one left over coconut to a passing monkey,\n and takes away his own share. The second man then repeats the procedure, dividing the remaining pile\n into five and taking away his share, as do the third, fourth, and fifth, each of them finding one\n coconut left over when dividing the pile by five, and giving it to a monkey. Finally, the group\n divide the remaining coconuts into five equal piles: this time no coconuts are left over.\n How many coconuts were there in the original pile?\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "PostageStamp_0", + "sat": "def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]):\n return set(stamps) <= set(options) and len(stamps) <= max_stamps and sum(stamps) == target", + "sol_docstring": " \"\"\"[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)\n \n In this problem version, one must find a selection of stamps to achieve a given value.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(target=80, max_stamps=4, options=[10, 32, 8]):" + }, + { + "name": "NecklaceSplit_0", + "sat": "def sat(n: int, lace=\"bbbbrrbrbrbbrrrr\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "sol_docstring": " \"\"\"[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)\n \n Split a specific red/blue necklace in half at n so that each piece has an equal number of reds and blues.\"\"\"", + "ans_type": "int", + "sol_header": "def sol(lace=\"bbbbrrbrbrbbrrrr\"):" + }, + { + "name": "PandigitalSquare_0", + "sat": "def sat(n: int):\n return sorted([int(s) for s in str(n * n)]) == list(range(10))", + "sol_docstring": " \"\"\"[Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square\n \n Find an integer whose square has all digits 0-9 once.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "AllPandigitalSquares_0", + "sat": "def sat(nums: List[int]):\n return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174", + "sol_docstring": " \"\"\"All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares\n \n Find all 174 integers whose 10-digit square has all digits 0-9\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "VerbalArithmetic_0", + "sat": "def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "sol_docstring": " \"\"\"Find a substitution of digits for characters to make the numbers add up, like this:\n SEND + MORE = MONEY\n \n The first digit in any cannot be 0.\n See [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(words=['SEND', 'MORE', 'MONEY']):" + }, + { + "name": "AnyEdge_0", + "sat": "def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):\n return e in edges", + "sol_docstring": " \"\"\"Find any edge in a given [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)).\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):" + }, + { + "name": "UnweightedShortestPath_0", + "sat": "def sat(path: List[int], edges=[[0, 11], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "sol_docstring": " \"\"\"Unweighted Shortest Path\n \n Find a path from node u to node v, of a bounded length, in a given digraph on vertices 0, 1,..., n.\n \n See (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 11], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):" + }, + { + "name": "AnyPath_0", + "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "sol_docstring": " \"\"\"Any Path\n \n Find any path from node 0 to node n in a given graph on vertices 0, 1,..., n.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3]]):" + }, + { + "name": "EvenPath_0", + "sat": "def sat(path: List[int], edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "sol_docstring": " \"\"\"Even Path\n \n Find any path with an even number of nodes from node 0 to node n in a given graph on vertices 0, 1,..., n.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 2], [0, 1], [2, 1], [2, 3], [1, 3]]):" + }, + { + "name": "OddPath_0", + "sat": "def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "sol_docstring": " \"\"\"Odd Path\n \n *** Note the change to go from node 0 to node 1 ***\n \n Find any path with an odd number of nodes from node 0 to node 1 in a given graph on vertices 0, 1,..., n.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 2], [3, 1], [2, 3]]):" + }, + { + "name": "Zarankiewicz_0", + "sat": "def sat(edges: List[List[int]]):\n assert len(edges) == len({(a, b) for a, b in edges}) == 13 # weights\n assert all(i in range(4) for li in edges for i in li) # 4 nodes on each side\n for i in range(4):\n v = [m for m in range(4) if m != i]\n for j in range(4):\n u = [m for m in range(4) if m != j]\n if all([m, n] in edges for m in v for n in u):\n return False\n return True", + "sol_docstring": " \"\"\"[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)\n \n Find a bipartite graph with 4 vertices on each side, 13 edges, and no K_3,3 subgraph.\"\"\"", + "ans_type": "List[List[int]]", + "sol_header": "def sol():" + }, + { + "name": "GraphIsomorphism_0", + "sat": "def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "sol_docstring": " \"\"\"In the classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem,\n one is given two graphs which are permutations of one another and\n the goal is to find the permutation. It is unknown wheter or not there exists a polynomial-time algorithm\n for this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n \n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4]], g2=[[0, 4], [4, 1], [1, 2], [2, 3]]):" + }, + { + "name": "Study_1_0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 0", + "sol_docstring": " \"\"\"Find a string with 1000 'o's but no two adjacent 'o's.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_2_0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801", + "sol_docstring": " \"\"\"Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_3_0", + "sat": "def sat(li: List[int]):\n return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li)))", + "sol_docstring": " \"\"\"Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_4_0", + "sat": "def sat(li: List[int]):\n return len(li) == 10 and li.count(li[3]) == 2", + "sol_docstring": " \"\"\"Find a list of length 10 where the fourth element occurs exactly twice.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_5_0", + "sat": "def sat(li: List[int]):\n return all([li.count(i) == i for i in range(10)])", + "sol_docstring": " \"\"\"Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_6_0", + "sat": "def sat(i: int):\n return i % 123 == 4 and i > 10 ** 10", + "sol_docstring": " \"\"\"Find an integer greater than 10^10 which is 4 mod 123.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "Study_7_0", + "sat": "def sat(s: str):\n return str(8 ** 2888).count(s) > 8 and len(s) == 3", + "sol_docstring": " \"\"\"Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_8_0", + "sat": "def sat(ls: List[str]):\n return ls[1234] in ls[1235] and ls[1234] != ls[1235]", + "sol_docstring": " \"\"\"Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_9_0", + "sat": "def sat(li: List[int]):\n return [\"The quick brown fox jumps over the lazy dog\"[i] for i in li] == list(\n \"The five boxing wizards jump quickly\")", + "sol_docstring": " \"\"\"Find a way to rearrange the letters in the pangram \"The quick brown fox jumps over the lazy dog\" to\n get the pangram \"The five boxing wizards jump quickly\". The answer should be represented as a list of index\n mappings.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_10_0", + "sat": "def sat(s: str):\n return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11", + "sol_docstring": " \"\"\"Find a palindrome of length greater than 11 in the decimal representation of 8^1818.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_11_0", + "sat": "def sat(ls: List[str]):\n return min(ls) == max(ls) == str(len(ls))", + "sol_docstring": " \"\"\"Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element\n and is equal to the lexicographically smallest element.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_12_0", + "sat": "def sat(li: List[int]):\n return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000", + "sol_docstring": " \"\"\"Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first\n integer plus 4 is 9.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_13_0", + "sat": "def sat(x: float):\n return str(x - 3.1415).startswith(\"123.456\")", + "sol_docstring": " \"\"\"Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.\"\"\"", + "ans_type": "float", + "sol_header": "def sol():" + }, + { + "name": "Study_14_0", + "sat": "def sat(li: List[int]):\n return all([sum(li[:i]) == i for i in range(20)])", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_15_0", + "sat": "def sat(li: List[int]):\n return all(sum(li[:i]) == 2 ** i - 1 for i in range(20))", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_16_0", + "sat": "def sat(s: str):\n return float(s) + len(s) == 4.5", + "sol_docstring": " \"\"\"Find a real number such that when you add the length of its decimal representation to it, you get 4.5.\n Your answer should be the string form of the number in its decimal representation.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_17_0", + "sat": "def sat(i: int):\n return len(str(i + 1000)) > len(str(i + 1001))", + "sol_docstring": " \"\"\"Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "Study_18_0", + "sat": "def sat(ls: List[str]):\n return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split()", + "sol_docstring": " \"\"\"Find a list of strings that when you combine them in all pairwise combinations gives the six strings:\n 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin'\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_19_0", + "sat": "def sat(si: Set[int]):\n return {i + j for i in si for j in si} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}", + "sol_docstring": " \"\"\"Find a set of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n That is find set S such that, { i + j | i, j in S } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_20_0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128]))", + "sol_docstring": " \"\"\"Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_21_0", + "sat": "def sat(li: List[int]):\n return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3", + "sol_docstring": " \"\"\"Find a list integers containing exactly three distinct values, such that no integer repeats\n twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_22_0", + "sat": "def sat(s: str):\n return s[::2] in s and len(set(s)) == 5", + "sol_docstring": " \"\"\"Find a string s containing exactly five distinct characters which also contains as a substring every other\n character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs').\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_23_0", + "sat": "def sat(ls: List[str]):\n return tuple(ls) in zip('dee', 'doo', 'dah!')", + "sol_docstring": " \"\"\"Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_24_0", + "sat": "def sat(li: List[int]):\n return li.count(17) == 3 and li.count(3) >= 2", + "sol_docstring": " \"\"\"Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_25_0", + "sat": "def sat(s: str):\n return sorted(s) == sorted('Permute me true') and s == s[::-1]", + "sol_docstring": " \"\"\"Find a permutation of the string 'Permute me true' which is a palindrome.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_26_0", + "sat": "def sat(ls: List[str]):\n return \"\".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls)", + "sol_docstring": " \"\"\"Divide the decimal representation of 8^88 up into strings of length eight.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_27_0", + "sat": "def sat(li: List[int]):\n return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]]", + "sol_docstring": " \"\"\"Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and\n v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they\n share the same great-grandchildren. Represented this digraph by the list of children indices.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_28_0", + "sat": "def sat(si: Set[int]):\n return all(i in range(1000) and abs(i - j) >= 10 for i in si for j in si if i != j) and len(si) == 100", + "sol_docstring": " \"\"\"Find a set of one hundred integers between 0 and 999 which all differ by at least ten from one another.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_29_0", + "sat": "def sat(si: Set[int]):\n return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in si for j in si if i != j) and len(si) > 995", + "sol_docstring": " \"\"\"Find a set of more than 995 integers between 0 and 999, inclusive, such that each pair of integers have\n squares that differ by at least 10.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_30_0", + "sat": "def sat(li: List[int]):\n return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)])", + "sol_docstring": " \"\"\"Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one\n are between 0 and 999, inclusive, and are strictly increasing in terms of f(n).\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "RockPaperScissors_0", + "sat": "def sat(probs: List[float]):\n assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6\n return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6", + "sol_docstring": " \"\"\"Find optimal strategy for Rock-Paper-Scissors zero-sum game\n \n Can the computer figure out that 1/3, 1/3, 1/3 achieves the maximal expected value of 0\"\"\"", + "ans_type": "List[float]", + "sol_header": "def sol():" + } +] \ No newline at end of file diff --git a/solvers/codex/30puzzles.json b/solvers/codex/30puzzles.json new file mode 100644 index 0000000..26ee4c4 --- /dev/null +++ b/solvers/codex/30puzzles.json @@ -0,0 +1,212 @@ +[ + { + "name": "Study_1_0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 0", + "sol_docstring": " \"\"\"Find a string with 1000 'o's but no two adjacent 'o's.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_2_0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801", + "sol_docstring": " \"\"\"Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_3_0", + "sat": "def sat(li: List[int]):\n return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li)))", + "sol_docstring": " \"\"\"Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_4_0", + "sat": "def sat(li: List[int]):\n return len(li) == 10 and li.count(li[3]) == 2", + "sol_docstring": " \"\"\"Find a list of length 10 where the fourth element occurs exactly twice.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_5_0", + "sat": "def sat(li: List[int]):\n return all([li.count(i) == i for i in range(10)])", + "sol_docstring": " \"\"\"Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_6_0", + "sat": "def sat(i: int):\n return i % 123 == 4 and i > 10 ** 10", + "sol_docstring": " \"\"\"Find an integer greater than 10^10 which is 4 mod 123.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "Study_7_0", + "sat": "def sat(s: str):\n return str(8 ** 2888).count(s) > 8 and len(s) == 3", + "sol_docstring": " \"\"\"Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_8_0", + "sat": "def sat(ls: List[str]):\n return ls[1234] in ls[1235] and ls[1234] != ls[1235]", + "sol_docstring": " \"\"\"Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_9_0", + "sat": "def sat(li: List[int]):\n return [\"The quick brown fox jumps over the lazy dog\"[i] for i in li] == list(\n \"The five boxing wizards jump quickly\")", + "sol_docstring": " \"\"\"Find a way to rearrange the letters in the pangram \"The quick brown fox jumps over the lazy dog\" to\n get the pangram \"The five boxing wizards jump quickly\". The answer should be represented as a list of index\n mappings.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_10_0", + "sat": "def sat(s: str):\n return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11", + "sol_docstring": " \"\"\"Find a palindrome of length greater than 11 in the decimal representation of 8^1818.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_11_0", + "sat": "def sat(ls: List[str]):\n return min(ls) == max(ls) == str(len(ls))", + "sol_docstring": " \"\"\"Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element\n and is equal to the lexicographically smallest element.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_12_0", + "sat": "def sat(li: List[int]):\n return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000", + "sol_docstring": " \"\"\"Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first\n integer plus 4 is 9.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_13_0", + "sat": "def sat(x: float):\n return str(x - 3.1415).startswith(\"123.456\")", + "sol_docstring": " \"\"\"Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.\"\"\"", + "ans_type": "float", + "sol_header": "def sol():" + }, + { + "name": "Study_14_0", + "sat": "def sat(li: List[int]):\n return all([sum(li[:i]) == i for i in range(20)])", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_15_0", + "sat": "def sat(li: List[int]):\n return all(sum(li[:i]) == 2 ** i - 1 for i in range(20))", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_16_0", + "sat": "def sat(s: str):\n return float(s) + len(s) == 4.5", + "sol_docstring": " \"\"\"Find a real number such that when you add the length of its decimal representation to it, you get 4.5.\n Your answer should be the string form of the number in its decimal representation.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_17_0", + "sat": "def sat(i: int):\n return len(str(i + 1000)) > len(str(i + 1001))", + "sol_docstring": " \"\"\"Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.\"\"\"", + "ans_type": "int", + "sol_header": "def sol():" + }, + { + "name": "Study_18_0", + "sat": "def sat(ls: List[str]):\n return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split()", + "sol_docstring": " \"\"\"Find a list of strings that when you combine them in all pairwise combinations gives the six strings:\n 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin'\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_19_0", + "sat": "def sat(si: Set[int]):\n return {i + j for i in si for j in si} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}", + "sol_docstring": " \"\"\"Find a set of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n That is find set S such that, { i + j | i, j in S } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_20_0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128]))", + "sol_docstring": " \"\"\"Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_21_0", + "sat": "def sat(li: List[int]):\n return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3", + "sol_docstring": " \"\"\"Find a list integers containing exactly three distinct values, such that no integer repeats\n twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.)\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_22_0", + "sat": "def sat(s: str):\n return s[::2] in s and len(set(s)) == 5", + "sol_docstring": " \"\"\"Find a string s containing exactly five distinct characters which also contains as a substring every other\n character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs').\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_23_0", + "sat": "def sat(ls: List[str]):\n return tuple(ls) in zip('dee', 'doo', 'dah!')", + "sol_docstring": " \"\"\"Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_24_0", + "sat": "def sat(li: List[int]):\n return li.count(17) == 3 and li.count(3) >= 2", + "sol_docstring": " \"\"\"Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_25_0", + "sat": "def sat(s: str):\n return sorted(s) == sorted('Permute me true') and s == s[::-1]", + "sol_docstring": " \"\"\"Find a permutation of the string 'Permute me true' which is a palindrome.\"\"\"", + "ans_type": "str", + "sol_header": "def sol():" + }, + { + "name": "Study_26_0", + "sat": "def sat(ls: List[str]):\n return \"\".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls)", + "sol_docstring": " \"\"\"Divide the decimal representation of 8^88 up into strings of length eight.\"\"\"", + "ans_type": "List[str]", + "sol_header": "def sol():" + }, + { + "name": "Study_27_0", + "sat": "def sat(li: List[int]):\n return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]]", + "sol_docstring": " \"\"\"Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and\n v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they\n share the same great-grandchildren. Represented this digraph by the list of children indices.\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_28_0", + "sat": "def sat(si: Set[int]):\n return all(i in range(1000) and abs(i - j) >= 10 for i in si for j in si if i != j) and len(si) == 100", + "sol_docstring": " \"\"\"Find a set of one hundred integers between 0 and 999 which all differ by at least ten from one another.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_29_0", + "sat": "def sat(si: Set[int]):\n return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in si for j in si if i != j) and len(si) > 995", + "sol_docstring": " \"\"\"Find a set of more than 995 integers between 0 and 999, inclusive, such that each pair of integers have\n squares that differ by at least 10.\"\"\"", + "ans_type": "Set[int]", + "sol_header": "def sol():" + }, + { + "name": "Study_30_0", + "sat": "def sat(li: List[int]):\n return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)])", + "sol_docstring": " \"\"\"Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one\n are between 0 and 999, inclusive, and are strictly increasing in terms of f(n).\"\"\"", + "ans_type": "List[int]", + "sol_header": "def sol():" + } +] \ No newline at end of file diff --git a/solvers/codex/397puzzles.json b/solvers/codex/397puzzles.json new file mode 100644 index 0000000..c27ab92 --- /dev/null +++ b/solvers/codex/397puzzles.json @@ -0,0 +1,5150 @@ +[ + { + "name": "Study_1:0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 0", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string with 1000 'o's but no two adjacent 'o's.\"\"\"", + "sol_bodies": [ + " return ('h' + 'o') * 1000" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_2:0", + "sat": "def sat(s: str):\n return s.count('o') == 1000 and s.count('oo') == 100 and s.count('ho') == 801", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string with 1000 'o's, 100 pairs of adjacent 'o's and 801 copies of 'ho'.\"\"\"", + "sol_bodies": [ + " return 'ho' * (800 + 1) + 'o' * (100 * 2 - 1)" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_3:0", + "sat": "def sat(li: List[int]):\n return sorted(li) == list(range(999)) and all(li[i] != i for i in range(len(li)))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a permutation of [0, 1, ..., 998] such that the ith element is *not* i, for all i=0, 1, ..., 998.\"\"\"", + "sol_bodies": [ + " return [((i + 1) % 999) for i in range(999)]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_4:0", + "sat": "def sat(li: List[int]):\n return len(li) == 10 and li.count(li[3]) == 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of length 10 where the fourth element occurs exactly twice.\"\"\"", + "sol_bodies": [ + " return list(range(10 // 2)) * 2" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_5:0", + "sat": "def sat(li: List[int]):\n return all([li.count(i) == i for i in range(10)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list integers such that the integer i occurs i times, for i = 0, 1, 2, ..., 9.\"\"\"", + "sol_bodies": [ + " return [i for i in range(10) for j in range(i)]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_6:0", + "sat": "def sat(i: int):\n return i % 123 == 4 and i > 10 ** 10", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer greater than 10^10 which is 4 mod 123.\"\"\"", + "sol_bodies": [ + " return 4 + 10 ** 10 + 123 - 10 ** 10 % 123" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_7:0", + "sat": "def sat(s: str):\n return str(8 ** 2888).count(s) > 8 and len(s) == 3", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a three-digit pattern that occurs more than 8 times in the decimal representation of 8^2888.\"\"\"", + "sol_bodies": [ + " s = str(8 ** 2888)\n return max({s[i: i + 3] for i in range(len(s) - 2)}, key=lambda t: s.count(t))" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_8:0", + "sat": "def sat(ls: List[str]):\n return ls[1234] in ls[1235] and ls[1234] != ls[1235]", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of more than 1235 strings such that the 1234th string is a proper substring of the 1235th.\"\"\"", + "sol_bodies": [ + " return [''] * 1235 + ['a']" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_9:0", + "sat": "def sat(li: List[int]):\n return [\"The quick brown fox jumps over the lazy dog\"[i] for i in li] == list(\n \"The five boxing wizards jump quickly\")", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a way to rearrange the letters in the pangram \"The quick brown fox jumps over the lazy dog\" to get\n the pangram \"The five boxing wizards jump quickly\". The answer should be represented as a list of index\n mappings.\n \"\"\"", + "sol_bodies": [ + " return ['The quick brown fox jumps over the lazy dog'.index(t)\n for t in 'The five boxing wizards jump quickly']" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_10:0", + "sat": "def sat(s: str):\n return s in str(8 ** 1818) and s == s[::-1] and len(s) > 11", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a palindrome of length greater than 11 in the decimal representation of 8^1818.\"\"\"", + "sol_bodies": [ + " s = str(8 ** 1818)\n return next(s[i: i + le]\n for le in range(12, len(s) + 1)\n for i in range(len(s) - le + 1)\n if s[i: i + le] == s[i: i + le][::-1]\n )" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_11:0", + "sat": "def sat(ls: List[str]):\n return min(ls) == max(ls) == str(len(ls))", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of strings whose length (viewed as a string) is equal to the lexicographically largest element\n and is equal to the lexicographically smallest element.\n \"\"\"", + "sol_bodies": [ + " return ['1']" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_12:0", + "sat": "def sat(li: List[int]):\n return all(i + j == 9 for i, j in zip([4] + li, li)) and len(li) == 1000", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of 1,000 integers where every two adjacent integers sum to 9, and where the first\n integer plus 4 is 9.\"\"\"", + "sol_bodies": [ + " return [9 - 4, 4] * (1000 // 2)" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_13:0", + "sat": "def sat(x: float):\n return str(x - 3.1415).startswith(\"123.456\")", + "ans_type": "float", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a real number which, when you subtract 3.1415, has a decimal representation starting with 123.456.\"\"\"", + "sol_bodies": [ + " return 123.456 + 3.1415" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_14:0", + "sat": "def sat(li: List[int]):\n return all([sum(li[:i]) == i for i in range(20)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is i, for i=0, 1, 2, ..., 19.\"\"\"", + "sol_bodies": [ + " return [1] * 20" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_15:0", + "sat": "def sat(li: List[int]):\n return all(sum(li[:i]) == 2 ** i - 1 for i in range(20))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers such that the sum of the first i integers is 2^i -1, for i = 0, 1, 2, ..., 19.\"\"\"", + "sol_bodies": [ + " return [(2 ** i) for i in range(20)]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_16:0", + "sat": "def sat(s: str):\n return float(s) + len(s) == 4.5", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a real number such that when you add the length of its decimal representation to it, you get 4.5.\n Your answer should be the string form of the number in its decimal representation.\"\"\"", + "sol_bodies": [ + " return str(4.5 - len(str(4.5)))" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_17:0", + "sat": "def sat(i: int):\n return len(str(i + 1000)) > len(str(i + 1001))", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a number whose decimal representation is *a longer string* when you add 1,000 to it than when you add 1,001.\"\"\"", + "sol_bodies": [ + " return -1001" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_18:0", + "sat": "def sat(ls: List[str]):\n return [s + t for s in ls for t in ls if s != t] == 'berlin berger linber linger gerber gerlin'.split()", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of strings that when you combine them in all pairwise combinations gives the six strings:\n 'berlin', 'berger', 'linber', 'linger', 'gerber', 'gerlin'\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for s in 'berlin berger linber linger gerber gerlin'.split():\n t = s[:3]\n if t not in seen:\n ans.append(t)\n seen.add(t)\n return ans" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_19:0", + "sat": "def sat(li: List[int]):\n return {i + j for i in li for j in li} == {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of integers whose pairwise sums make the set {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n That is find L such that, { i + j | i, j in L } = {0, 1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 34}.\n \"\"\"", + "sol_bodies": [ + " return [0, 1, 2, 3, 17]" + ], + "module": "study.py", + "notes": "9/15/2021 Updated to take a list rather than a set because it was the only puzzle in the repo with Set argument.", + "weight": 1.0 + }, + { + "name": "Study_20:0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128]))", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"", + "sol_bodies": [ + " return [1, 3, 4, 12, 13, 14, 42, 126, 127]" + ], + "module": "study.py", + "notes": "A more interesting version of this puzzle with a length constraint is ShortIntegerPath in graphs.py", + "weight": 1.0 + }, + { + "name": "Study_21:0", + "sat": "def sat(li: List[int]):\n return all([li[i] != li[i + 1] for i in range(10)]) and len(set(li)) == 3", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list integers containing exactly three distinct values, such that no integer repeats\n twice consecutively among the first eleven entries. (So the list needs to have length greater than ten.)\n \"\"\"", + "sol_bodies": [ + " return list(range(3)) * 10" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_22:0", + "sat": "def sat(s: str):\n return s[::2] in s and len(set(s)) == 5", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a string s containing exactly five distinct characters which also contains as a substring every other\n character of s (e.g., if the string s were 'parrotfish' every other character would be 'profs').\n \"\"\"", + "sol_bodies": [ + " return \"\"\"abacadaeaaaaaaaaaa\"\"\"" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_23:0", + "sat": "def sat(ls: List[str]):\n return tuple(ls) in zip('dee', 'doo', 'dah!')", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of characters which are aligned at the same indices of the three strings 'dee', 'doo', and 'dah!'.\n \"\"\"", + "sol_bodies": [ + " return list(next(zip('dee', 'doo', 'dah!')))" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_24:0", + "sat": "def sat(li: List[int]):\n return li.count(17) == 3 and li.count(3) >= 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of integers with exactly three occurrences of seventeen and at least two occurrences of three.\"\"\"", + "sol_bodies": [ + " return [17] * 3 + [3] * 2" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_25:0", + "sat": "def sat(s: str):\n return sorted(s) == sorted('Permute me true') and s == s[::-1]", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a permutation of the string 'Permute me true' which is a palindrome.\"\"\"", + "sol_bodies": [ + " s = sorted('Permute me true'[1:])[::2]\n return \"\".join(s + ['P'] + s[::-1])" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_26:0", + "sat": "def sat(ls: List[str]):\n return \"\".join(ls) == str(8 ** 88) and all(len(s) == 8 for s in ls)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Divide the decimal representation of 8^88 up into strings of length eight.\"\"\"", + "sol_bodies": [ + " return [str(8 ** 88)[i:i + 8] for i in range(0, len(str(8 ** 88)), 8)]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_27:0", + "sat": "def sat(li: List[int]):\n return li[li[0]] != li[li[1]] and li[li[li[0]]] == li[li[li[1]]]", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider a digraph where each node has exactly one outgoing edge. For each edge (u, v), call u the parent and\n v the child. Then find such a digraph where the grandchildren of the first and second nodes differ but they\n share the same great-grandchildren. Represented this digraph by the list of children indices.\n \"\"\"", + "sol_bodies": [ + " return [1, 2, 3, 3]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Study_28:0", + "sat": "def sat(li: List[int]):\n return all(i in range(1000) and abs(i - j) >= 10 for i in li for j in li if i != j) and len(set(li)) == 100", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of one hundred integers between 0 and 999 which all differ by at least ten from one another.\"\"\"", + "sol_bodies": [ + " return list(range(0, 1000, 10))" + ], + "module": "study.py", + "notes": "9/15/2021: updated to a list since sets were removed from puzzle formats", + "weight": 1.0 + }, + { + "name": "Study_29:0", + "sat": "def sat(l: List[int]):\n return all(i in range(1000) and abs(i * i - j * j) >= 10 for i in l for j in l if i != j) and len(set(l)) > 995", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of more than 995 distinct integers between 0 and 999, inclusive, such that each pair of integers\n have squares that differ by at least 10.\n \"\"\"", + "sol_bodies": [ + " return [0, 4] + list(range(6, 1000))" + ], + "module": "study.py", + "notes": "9/15/2021: updated to a list since sets were removed from puzzle formats", + "weight": 1.0 + }, + { + "name": "Study_30:0", + "sat": "def sat(li: List[int]):\n return all([123 * li[i] % 1000 < 123 * li[i + 1] % 1000 and li[i] in range(1000) for i in range(20)])", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Define f(n) to be the residue of 123 times n mod 1000. Find a list of integers such that the first twenty one\n are between 0 and 999, inclusive, and are strictly increasing in terms of f(n).\n \"\"\"", + "sol_bodies": [ + " return sorted(range(1000), key=lambda n: 123 * n % 1000)[:21]", + " return list(range(1000))[::8][::-1]" + ], + "module": "study.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "TowersOfHanoi:0", + "sat": "def sat(moves: List[List[int]]):\n rods = ([8, 7, 6, 5, 4, 3, 2, 1], [], [])\n for [i, j] in moves:\n rods[j].append(rods[i].pop())\n assert rods[j][-1] == min(rods[j]), \"larger disk on top of smaller disk\"\n return rods[0] == rods[1] == []", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Eight disks of sizes 1-8 are stacked on three towers, with each tower having disks in order of largest to\n smallest. Move [i, j] corresponds to taking the smallest disk off tower i and putting it on tower j, and it\n is legal as long as the towers remain in sorted order. Find a sequence of moves that moves all the disks\n from the first to last towers.\n \"\"\"", + "sol_bodies": [ + " def helper(m, i, j):\n if m == 0:\n return []\n k = 3 - i - j\n return helper(m - 1, i, k) + [[i, j]] + helper(m - 1, k, j)\n\n return helper(8, 0, 2)" + ], + "module": "classic_puzzles.py", + "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this classic version one must move all 8 disks from the first to third peg.", + "weight": 1.0 + }, + { + "name": "TowersOfHanoiArbitrary:0", + "sat": "def sat(moves: List[List[int]], source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):\n state = [s[:] for s in source]\n\n for [i, j] in moves:\n state[j].append(state[i].pop())\n assert state[j] == sorted(state[j])\n\n return state == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(source=[[0, 7], [4, 5, 6], [1, 2, 3, 8]], target=[[0, 1, 2, 3, 8], [4, 5], [6, 7]]):", + "sol_docstring": " \"\"\"\n A state is a partition of the integers 0-8 into three increasing lists. A move is pair of integers i, j in\n {0, 1, 2} corresponding to moving the largest number from the end of list i to list j, while preserving the\n order of list j. Find a sequence of moves that transform the given source to target states.\n \"\"\"", + "sol_bodies": [ + " state = {d: i for i, tower in enumerate(source) for d in tower}\n final = {d: i for i, tower in enumerate(target) for d in tower}\n disks = set(state)\n assert disks == set(final) and all(isinstance(i, int) for i in state) and len(source) == len(target) >= 3\n ans = []\n\n def move(d, i): # move disk d to tower i\n if state[d] == i:\n return\n for t in range(3): # first tower besides i, state[d]\n if t != i and t != state[d]:\n break\n for d2 in range(d + 1, max(disks) + 1):\n if d2 in disks:\n move(d2, t)\n ans.append([state[d], i])\n state[d] = i\n\n for d in range(min(disks), max(disks) + 1):\n if d in disks:\n move(d, final[d])\n\n return ans" + ], + "module": "classic_puzzles.py", + "notes": "[Towers of Hanoi](https://en.wikipedia.org/w/index.php?title=Tower_of_Hanoi)\n\nIn this version one must transform a given source state to a target state.", + "weight": 1.0 + }, + { + "name": "LongestMonotonicSubstring:0", + "sat": "def sat(x: List[int], length=13, s=\"Dynamic programming solves this puzzle!!!\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] >= 0 for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=13, s=\"Dynamic programming solves this puzzle!!!\"):", + "sol_docstring": " \"\"\"\n Remove as few characters as possible from s so that the characters of the remaining string are alphebetical.\n Here x is the list of string indices that have not been deleted.\n \"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, -1)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[i][2] != -1:\n i = dyn[i][2]\n backwards.append(i)\n return backwards[::-1]" + ], + "module": "classic_puzzles.py", + "notes": "This is a form of the classic\n[Longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem\nwhere the goal is to find a substring with characters in sorted order.", + "weight": 1.0 + }, + { + "name": "LongestMonotonicSubstringTricky:0", + "sat": "def sat(x: List[int], length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"):\n return all(s[x[i]] <= s[x[i + 1]] and x[i + 1] > x[i] for i in range(length - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(length=20, s=\"Dynamic programming solves this classic job-interview puzzle!!!\"):", + "sol_docstring": " \"\"\"Find the indices of the longest substring with characters in sorted order\"\"\"", + "sol_bodies": [ + " # O(N^2) method. Todo: add binary search solution which is O(n log n)\n if s == \"\":\n return []\n n = len(s)\n dyn = [] # list of (seq length, seq end, prev index)\n for i in range(-n, n):\n try:\n dyn.append(max((length + 1, i, e) for length, e, _ in dyn if s[e] <= s[i]))\n except ValueError:\n dyn.append((1, i, None)) # sequence ends at i\n _length, i, _ = max(dyn)\n backwards = [i]\n while dyn[n + i][2] is not None:\n i = dyn[n + i][2]\n backwards.append(i)\n return backwards[::-1]" + ], + "module": "classic_puzzles.py", + "notes": "The same as the above problem, but with a twist!", + "weight": 1.0 + }, + { + "name": "Quine:0", + "sat": "def sat(quine: str):\n return eval(quine) == quine", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when evaluated as a Python expression is that string itself.\"\"\"", + "sol_bodies": [ + " return \"(lambda x: f'({x})({chr(34)}{x}{chr(34)})')(\\\"lambda x: f'({x})({chr(34)}{x}{chr(34)})'\\\")\"" + ], + "module": "classic_puzzles.py", + "notes": "[Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29)", + "weight": 1.0 + }, + { + "name": "RevQuine:0", + "sat": "def sat(rev_quine: str):\n return eval(rev_quine[::-1]) == rev_quine", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that, when reversed and evaluated gives you back that same string.\"\"\"", + "sol_bodies": [ + " return \"rev_quine\"[::-1] # thanks GPT-3!" + ], + "module": "classic_puzzles.py", + "notes": "Reverse [Quine](https://en.wikipedia.org/wiki/Quine_%28computing%29). The solution we give is from GPT3.", + "weight": 1.0 + }, + { + "name": "BooleanPythagoreanTriples:0", + "sat": "def sat(colors: List[int], n=100):\n assert set(colors) <= {0, 1} and len(colors) >= n\n squares = {i ** 2: colors[i] for i in range(1, len(colors))}\n return not any(c == d == squares.get(i + j) for i, c in squares.items() for j, d in squares.items())", + "ans_type": "List[int]", + "sol_header": "def sol(n=100):", + "sol_docstring": " \"\"\"\n Color the first n integers with one of two colors so that there is no monochromatic Pythagorean triple.\n A monochromatic Pythagorean triple is a triple of numbers i, j, k such that i^2 + j^2 = k^2 that\n are all assigned the same color. The input, colors, is a list of 0/1 colors of length >= n.\n \"\"\"", + "sol_bodies": [ + " sqrt = {i * i: i for i in range(1, n)}\n trips = [(sqrt[i], sqrt[j], sqrt[i + j]) for i in sqrt for j in sqrt if i < j and i + j in sqrt]\n import random\n random.seed(0)\n sol = [random.randrange(2) for _ in range(n)]\n done = False\n while not done:\n done = True\n random.shuffle(trips)\n for i, j, k in trips:\n if sol[i] == sol[j] == sol[k]:\n done = False\n sol[random.choice([i, j, k])] = 1 - sol[i]\n return sol" + ], + "module": "classic_puzzles.py", + "notes": "[Boolean Pythagorean Triples Problem](https://en.wikipedia.org/wiki/Boolean_Pythagorean_triples_problem)", + "weight": 1.0 + }, + { + "name": "ClockAngle:0", + "sat": "def sat(hands: List[int], target_angle=45):\n h, m = hands\n assert 0 < h <= 12 and 0 <= m < 60\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n return abs(hour_angle - minute_angle) in [target_angle, 360 - target_angle]", + "ans_type": "List[int]", + "sol_header": "def sol(target_angle=45):", + "sol_docstring": " \"\"\"Find clock hands = [hour, min] such that the angle is target_angle degrees.\"\"\"", + "sol_bodies": [ + " for h in range(1, 13):\n for m in range(60):\n hour_angle = 30 * h + m / 2\n minute_angle = 6 * m\n if abs(hour_angle - minute_angle) % 360 in [target_angle, 360 - target_angle]:\n return [h, m]" + ], + "module": "classic_puzzles.py", + "notes": "[Clock Angle Problem](https://en.wikipedia.org/wiki/Clock_angle_problem), easy variant", + "weight": 1.0 + }, + { + "name": "Kirkman:0", + "sat": "def sat(daygroups: List[List[List[int]]]):\n assert len(daygroups) == 7\n assert all(len(groups) == 5 and {i for g in groups for i in g} == set(range(15)) for groups in daygroups)\n assert all(len(g) == 3 for groups in daygroups for g in groups)\n return len({(i, j) for groups in daygroups for g in groups for i in g for j in g}) == 15 * 15", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Arrange 15 people into groups of 3 each day for seven days so that no two people are in the same group twice.\n \"\"\"", + "sol_bodies": [ + " from itertools import combinations\n import random\n rand = random.Random(0)\n days = [[list(range(15)) for _2 in range(2)] for _ in range(7)] # each day is pi, inv\n counts = {(i, j): (7 if j in range(k, k + 3) else 0)\n for k in range(0, 15, 3)\n for i in range(k, k + 3)\n for j in range(15) if j != i\n }\n\n todos = [pair for pair, count in counts.items() if count == 0]\n while True:\n pair = rand.choice(todos) # choose i and j to make next to each other on some day\n if rand.randrange(2):\n pair = pair[::-1]\n\n a, u = pair\n pi, inv = rand.choice(days)\n assert pi[inv[a]] == a and pi[inv[u]] == u\n bases = [3 * (inv[i] // 3) for i in pair]\n (b, c), (v, w) = [[x for x in pi[b: b + 3] if x != i] for i, b in zip(pair, bases)]\n if rand.randrange(2):\n b, c, = c, b\n # current (a, b, c) (u, v, w). consider swap of u with b to make (a, u, c) (b, v, w)\n\n new_pairs = [(a, u), (c, u), (b, v), (b, w)]\n old_pairs = [(u, v), (u, w), (b, a), (b, c)]\n gained = sum(counts[p] == 0 for p in new_pairs)\n lost = sum(counts[p] == 1 for p in old_pairs)\n if rand.random() <= 100 ** (gained - lost):\n for p in new_pairs:\n counts[p] += 1\n counts[p[::-1]] += 1\n for p in old_pairs:\n counts[p] -= 1\n counts[p[::-1]] -= 1\n pi[inv[b]], pi[inv[u]], inv[b], inv[u] = u, b, inv[u], inv[b]\n todos = [pair for pair, count in counts.items() if count == 0]\n if len(todos) == 0:\n return [[pi[k:k + 3] for k in range(0, 15, 3)] for pi, _inv in days]" + ], + "module": "classic_puzzles.py", + "notes": "[Kirkman's problem](https://en.wikipedia.org/wiki/Kirkman%27s_schoolgirl_problem)", + "weight": 1.0 + }, + { + "name": "MonkeyAndCoconuts:0", + "sat": "def sat(n: int):\n for i in range(5):\n assert n % 5 == 1\n n -= 1 + (n - 1) // 5\n return n > 0 and n % 5 == 1", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find the number of coconuts to solve the following riddle:\n There is a pile of coconuts, owned by five men. One man divides the pile into five equal piles, giving the\n one left over coconut to a passing monkey, and takes away his own share. The second man then repeats the\n procedure, dividing the remaining pile into five and taking away his share, as do the third, fourth, and\n fifth, each of them finding one coconut left over when dividing the pile by five, and giving it to a monkey.\n Finally, the group divide the remaining coconuts into five equal piles: this time no coconuts are left over.\n How many coconuts were there in the original pile?\n Quoted from https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts\n \"\"\"", + "sol_bodies": [ + " m = 1\n while True:\n n = m\n for i in range(5):\n if n % 5 != 1:\n break\n n -= 1 + (n - 1) // 5\n if n > 0 and n % 5 == 1:\n return m\n m += 5" + ], + "module": "classic_puzzles.py", + "notes": "[The Monkey and the Coconuts](https://en.wikipedia.org/wiki/The_monkey_and_the_coconuts)", + "weight": 1.0 + }, + { + "name": "No3Colinear:0", + "sat": "def sat(coords: List[List[int]], side=10, num_points=20):\n for i1 in range(len(coords)):\n x1, y1 = coords[i1]\n assert 0 <= x1 < side and 0 <= y1 < side\n for i2 in range(i1):\n x2, y2 = coords[i2]\n for i3 in range(i2):\n x3, y3 = coords[i3]\n assert x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) != 0\n return len({(a, b) for a, b in coords}) == len(coords) >= num_points", + "ans_type": "List[List[int]]", + "sol_header": "def sol(side=10, num_points=20):", + "sol_docstring": " \"\"\"Find num_points points in an side x side grid such that no three points are collinear.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n assert side <= 5 or side == 10, \"Don't know how to solve other sides\"\n\n def test(coords):\n return all(p[0] * (q[1] - r[1]) + q[0] * (r[1] - p[1]) + r[0] * (p[1] - q[1])\n for p, q, r in combinations(coords, 3))\n\n if side <= 5:\n grid = [[i, j] for i in range(side) for j in range(side)]\n return next(list(coords) for coords in combinations(grid, num_points) if test(coords))\n\n if side == 10:\n def mirror(coords): # rotate to all four corners\n return [[a, b] for x, y in coords for a in [x, side - 1 - x] for b in [y, side - 1 - y]]\n\n grid = [[i, j] for i in range(side // 2) for j in range(side // 2)]\n return next(list(mirror(coords)) for coords in combinations(grid, side // 2) if\n test(coords) and test(mirror(coords)))" + ], + "module": "classic_puzzles.py", + "notes": "[No three-in-a-line](https://en.wikipedia.org/wiki/No-three-in-line_problem)", + "weight": 1.0 + }, + { + "name": "PostageStamp:0", + "sat": "def sat(stamps: List[int], target=80, max_stamps=4, options=[10, 32, 8]):\n for s in stamps:\n assert s in options\n return len(stamps) <= max_stamps and sum(stamps) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=80, max_stamps=4, options=[10, 32, 8]):", + "sol_docstring": " \"\"\"Find a selection of at most max_stamps stamps whose total worth is the target value.\"\"\"", + "sol_bodies": [ + " from itertools import combinations_with_replacement\n for n in range(max_stamps + 1):\n for c in combinations_with_replacement(options, n):\n if sum(c) == target:\n return list(c)" + ], + "module": "classic_puzzles.py", + "notes": "[Postage stamp problem](https://en.wikipedia.org/wiki/Postage_stamp_problem)", + "weight": 1.0 + }, + { + "name": "Sudoku:0", + "sat": "def sat(x: str, puz=\"____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______\"):\n assert all(c == \"_\" or c == s for (c, s) in zip(puz, x))\n\n full = set('123456789')\n for i in range(9):\n assert {x[i] for i in range(9 * i, 9 * i + 9)} == full, \"invalid row\"\n assert {x[i] for i in range(i, i + 81, 9)} == full, \"invalid column\"\n assert {x[9 * a + b + i + 26 * (i % 3)] for a in range(3) for b in range(3)} == full, \"invalid square\"\n\n return True", + "ans_type": "str", + "sol_header": "def sol(puz=\"____9_2___7__________1_8_4____2_78____4_____1____69____2_8___5__6__3_7___49______\"):", + "sol_docstring": " \"\"\"Find the unique valid solution to the Sudoku puzzle\"\"\"", + "sol_bodies": [ + " \"\"\"Simple depth-first backtracking solver that branches at the square with fewest possibilities\"\"\"\n sets = [{int(c)} if c != '_' else set(range(1, 10)) for c in puz]\n\n groups = []\n for i in range(9):\n groups.append(list(range(9 * i, 9 * i + 9)))\n groups.append(list(range(i, i + 81, 9)))\n groups.append([9 * a + b + i + 26 * (i % 3) for a in range(3) for b in range(3)])\n\n inv = [[] for i in range(81)]\n for g in groups:\n for i in g:\n inv[i].append(g)\n\n def reduce():\n \"\"\"Reduce possibilities and return False if it's clearly impossible to solve, True otherwise.\n Repeatedly applies two types of logic:\n * When an entry has a single possibility, remove that value from all 20 neighbors\n * When a row/col/square has only one entry with k as a possibility, fill in that possibility\n \"\"\"\n done = False\n while not done:\n done = True\n for i in range(81):\n new = sets[i] - {k for g in inv[i] for j in g if j != i and len(sets[j]) == 1 for k in sets[j]}\n if not new:\n return False\n if len(sets[i]) != len(new):\n sets[i] = new\n done = False\n\n for g in groups:\n for k in range(1, 10):\n possibilities = [i for i in g if k in sets[i]]\n if not possibilities:\n return False\n if len(possibilities) == 1:\n i = possibilities[0]\n if len(sets[i]) > 1:\n done = False\n sets[i] = {k}\n\n return True\n\n ans = []\n\n counter = 0\n\n def solve_helper():\n nonlocal sets, ans, counter\n counter += 1\n assert len(ans) <= 1, \"Sudoku puzzle should have a unique solution\"\n old_sets = sets[:]\n if reduce():\n if all(len(s) == 1 for s in sets):\n ans.append(\"\".join(str(list(s)[0]) for s in sets))\n else:\n smallest_set = min(range(81), key=lambda i: len(sets[i]) if len(sets[i]) > 1 else 10)\n for v in sorted(sets[smallest_set]):\n sets[smallest_set] = {v}\n solve_helper()\n\n sets = old_sets\n\n solve_helper()\n assert ans, \"No solution found\"\n return ans[0]" + ], + "module": "classic_puzzles.py", + "notes": "The classic game of [Sudoku](https://en.wikipedia.org/wiki/Sudoku)", + "weight": 1.0 + }, + { + "name": "SquaringTheSquare:0", + "sat": "def sat(xy_sides: List[List[int]]):\n n = max(x + side for x, y, side in xy_sides)\n assert len({side for x, y, side in xy_sides}) == len(xy_sides) > 1\n for x, y, s in xy_sides:\n assert 0 <= y < y + s <= n and 0 <= x\n for x2, y2, s2 in xy_sides:\n assert s2 <= s or x2 >= x + s or x2 + s2 <= x or y2 >= y + s or y2 + s2 <= y\n\n return sum(side ** 2 for x, y, side in xy_sides) == n ** 2", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Partition a square into smaller squares with unique side lengths. A perfect squared path has distinct sides.\n xy_sides is a List of (x, y, side)\n \"\"\"", + "sol_bodies": [ + " return [[0, 0, 50], [0, 50, 29], [0, 79, 33], [29, 50, 25], [29, 75, 4], [33, 75, 37], [50, 0, 35],\n [50, 35, 15], [54, 50, 9], [54, 59, 16], [63, 50, 2], [63, 52, 7], [65, 35, 17], [70, 52, 18],\n [70, 70, 42], [82, 35, 11], [82, 46, 6], [85, 0, 27], [85, 27, 8], [88, 46, 24], [93, 27, 19]]" + ], + "module": "classic_puzzles.py", + "notes": "[Squaring the square](https://en.wikipedia.org/wiki/Squaring_the_square)\nWikipedia gives a minimal [solution with 21 squares](https://en.wikipedia.org/wiki/Squaring_the_square)\ndue to Duijvestijn (1978).", + "weight": 1.0 + }, + { + "name": "NecklaceSplit:0", + "sat": "def sat(n: int, lace=\"bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb\"):\n sub = lace[n: n + len(lace) // 2]\n return n >= 0 and lace.count(\"r\") == 2 * sub.count(\"r\") and lace.count(\"b\") == 2 * sub.count(\"b\")", + "ans_type": "int", + "sol_header": "def sol(lace=\"bbrbrbbbbbbrrrrrrrbrrrrbbbrbrrbbbrbrrrbrrbrrbrbbrrrrrbrbbbrrrbbbrbbrbbbrbrbb\"):", + "sol_docstring": " \"\"\"\n Find a split dividing the given red/blue necklace in half at n so that each piece has an equal number of\n reds and blues.\n \"\"\"", + "sol_bodies": [ + " if lace == \"\":\n return 0\n return next(n for n in range(len(lace) // 2) if lace[n: n + len(lace) // 2].count(\"r\") == len(lace) // 4)" + ], + "module": "classic_puzzles.py", + "notes": "[Necklace Splitting Problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem)", + "weight": 1.0 + }, + { + "name": "PandigitalSquare:0", + "sat": "def sat(n: int):\n s = str(n * n)\n for i in \"0123456789\":\n assert s.count(i) == 1\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer whose square has all digits 0-9 once.\"\"\"", + "sol_bodies": [ + " for n in range(10 ** 5):\n if sorted([int(s) for s in str(n * n)]) == list(range(10)):\n return n" + ], + "module": "classic_puzzles.py", + "notes": "[Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Square", + "weight": 1.0 + }, + { + "name": "AllPandigitalSquares:0", + "sat": "def sat(nums: List[int]):\n return [sorted([int(s) for s in str(n * n)]) for n in set(nums)] == [list(range(10))] * 174", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find all 174 integers whose 10-digit square has all digits 0-9 just once.\"\"\"", + "sol_bodies": [ + " return [i for i in range(-10 ** 5, 10 ** 5) if sorted([int(s) for s in str(i * i)]) == list(range(10))]" + ], + "module": "classic_puzzles.py", + "notes": "All [Pandigital](https://en.wikipedia.org/wiki/Pandigital_number) Squares", + "weight": 1.0 + }, + { + "name": "CardGame24:0", + "sat": "def sat(expr: str, nums=[3, 7, 3, 7]):\n assert len(nums) == 4 and 1 <= min(nums) and max(nums) <= 13, \"hint: nums is a list of four ints in 1..13\"\n expr = expr.replace(\" \", \"\") # ignore whitespace\n digits = \"\"\n for i in range(len(expr)):\n if i == 0 or expr[i - 1] in \"+*-/(\":\n assert expr[i] in \"123456789(\", \"Expr cannot contain **, //, or unary -\"\n assert expr[i] in \"1234567890()+-*/\", \"Expr can only contain `0123456789()+-*/`\"\n digits += expr[i] if expr[i] in \"0123456789\" else \" \"\n assert sorted(int(s) for s in digits.split()) == sorted(nums), \"Each number must occur exactly once\"\n return abs(eval(expr) - 24.0) < 1e-6", + "ans_type": "str", + "sol_header": "def sol(nums=[3, 7, 3, 7]):", + "sol_docstring": " \"\"\"Find a formula with two 3's and two 7's and + - * / (and parentheses) that evaluates to 24.\"\"\"", + "sol_bodies": [ + " def helper(pairs):\n if len(pairs) == 2:\n (x, s), (y, t) = pairs\n ans = {\n x + y: f\"{s}+{t}\",\n x - y: f\"{s}-({t})\",\n y - x: f\"{t}-({s})\",\n x * y: f\"({s})*({t})\"\n }\n if y != 0:\n ans[x / y] = f\"({s})/({t})\"\n if x != 0:\n ans[y / x] = f\"({t})/({s})\"\n return ans\n ans = {y: t\n for i in range(len(pairs))\n for x_s in helper(pairs[:i] + pairs[i + 1:]).items()\n for y, t in helper([x_s, pairs[i]]).items()}\n if len(pairs) == 3:\n return ans\n ans.update({z: u\n for i in range(1, 4)\n for x_s in helper([pairs[0], pairs[i]]).items()\n for y_t in helper(pairs[1:i] + pairs[i + 1:]).items()\n for z, u in helper([x_s, y_t]).items()\n })\n return ans\n\n derivations = helper([(n, str(n)) for n in nums])\n for x in derivations:\n if abs(x - 24.0) < 1e-6:\n return derivations[x]" + ], + "module": "classic_puzzles.py", + "notes": "[24 Game](https://en.wikipedia.org/wiki/24_Game)\n\nIn this game one is given four numbers from the range 1-13 (Ace-King) and one needs to combine them with\n + - * / (and parentheses)\nto make the number 24.\nThe solution to this tricky example is `7 * (3 + 3 / 7)`", + "weight": 1.0 + }, + { + "name": "Easy63:0", + "sat": "def sat(s: str):\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 2 and s.count(\"1\") == 1 and eval(s) == 63", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a formula using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"", + "sol_bodies": [ + " return \"8*8-1\"" + ], + "module": "classic_puzzles.py", + "notes": "An easy puzzle to make 63 using two 8's and one 1's.", + "weight": 1.0 + }, + { + "name": "Harder63:0", + "sat": "def sat(s: str):\n return set(s) <= set(\"18-+*/\") and s.count(\"8\") == 3 and s.count(\"1\") == 1 and eval(s) == 63", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an expression using two 8s and two 1's and -+*/ that evaluates to 1.\"\"\"", + "sol_bodies": [ + " return \"8*8-1**8\"" + ], + "module": "classic_puzzles.py", + "notes": "An harder puzzle to make 63 using three 8's and one 1's.", + "weight": 1.0 + }, + { + "name": "WaterPouring:0", + "sat": "def sat(moves: List[List[int]], capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]):\n state = init.copy()\n\n for [i, j] in moves:\n assert min(i, j) >= 0, \"Indices must be non-negative\"\n assert i != j, \"Cannot pour from same state to itself\"\n n = min(capacities[j], state[i] + state[j])\n state[i], state[j] = state[i] + state[j] - n, n\n\n return state == goal", + "ans_type": "List[List[int]]", + "sol_header": "def sol(capacities=[8, 5, 3], init=[8, 0, 0], goal=[4, 4, 0]):", + "sol_docstring": " \"\"\"\n Given an initial state of water quantities in jugs and jug capacities, find a sequence of moves (pouring\n one jug into another until it is full or the first is empty) to reaches the given goal state.\n moves is list of [from, to] pairs\n \"\"\"", + "sol_bodies": [ + " from collections import deque\n num_jugs = len(capacities)\n start = tuple(init)\n target = tuple(goal)\n trails = {start: ([], start)}\n queue = deque([tuple(init)])\n while target not in trails:\n state = queue.popleft()\n for i in range(num_jugs):\n for j in range(num_jugs):\n if i != j:\n n = min(capacities[j], state[i] + state[j])\n new_state = list(state)\n new_state[i], new_state[j] = state[i] + state[j] - n, n\n new_state = tuple(new_state)\n if new_state not in trails:\n queue.append(new_state)\n trails[new_state] = ([i, j], state)\n ans = []\n state = target\n while state != start:\n move, state = trails[state]\n ans.append(move)\n return ans[::-1]" + ], + "module": "classic_puzzles.py", + "notes": "[Water pouring puzzle](https://en.wikipedia.org/w/index.php?title=Water_pouring_puzzle&oldid=985741928)", + "weight": 1.0 + }, + { + "name": "VerbalArithmetic:0", + "sat": "def sat(li: List[int], words=['SEND', 'MORE', 'MONEY']):\n assert len(li) == len(words) and all(i > 0 and len(str(i)) == len(w) for i, w in zip(li, words))\n assert len({c for w in words for c in w}) == len({(d, c) for i, w in zip(li, words) for d, c in zip(str(i), w)})\n return sum(li[:-1]) == li[-1]", + "ans_type": "List[int]", + "sol_header": "def sol(words=['SEND', 'MORE', 'MONEY']):", + "sol_docstring": " \"\"\"\n Find a list of integers corresponding to the given list of strings substituting a different digit for each\n character, so that the last string corresponds to the sum of the previous numbers.\n \"\"\"", + "sol_bodies": [ + " pi = list(range(10)) # permutation\n letters = []\n order = {}\n steps = []\n tens = 1\n for col in range(1, 1 + max(len(w) for w in words)):\n for w in words:\n is_tot = (w is words[-1])\n if len(w) >= col:\n c = w[-col]\n if c in order:\n if is_tot:\n kind = \"check\"\n else:\n kind = \"seen\"\n else:\n if is_tot:\n kind = \"derive\"\n else:\n kind = \"add\"\n order[c] = len(letters)\n letters.append(c)\n steps.append((kind, order[c], tens))\n tens *= 10\n\n inits = [any(w[0] == c for w in words) for c in letters]\n\n def helper(pos, delta): # on success, returns True and pi has the correct values\n if pos == len(steps):\n return delta == 0\n\n kind, i, tens = steps[pos]\n\n if kind == \"seen\":\n return helper(pos + 1, delta + tens * pi[i])\n\n if kind == \"add\":\n for j in range(i, 10):\n if pi[j] != 0 or not inits[i]: # not adding a leading 0\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta + tens * pi[i]):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n if kind == \"check\":\n delta -= tens * pi[i]\n return (delta % (10 * tens)) == 0 and helper(pos + 1, delta)\n\n assert kind == \"derive\"\n digit = (delta % (10 * tens)) // tens\n if digit == 0 and inits[i]:\n return False # would be a leading 0\n j = pi.index(digit)\n if j < i:\n return False # already used\n pi[i], pi[j] = pi[j], pi[i]\n if helper(pos + 1, delta - tens * digit):\n return True\n pi[i], pi[j] = pi[j], pi[i]\n return False\n\n assert helper(0, 0)\n return [int(\"\".join(str(pi[order[c]]) for c in w)) for w in words]" + ], + "module": "classic_puzzles.py", + "notes": "Find a substitution of digits for characters to make the numbers add up in a sum like this:\nSEND + MORE = MONEY\n\nThe first digit in any number cannot be 0. In this example the solution is `9567 + 1085 = 10652`.\nSee [Wikipedia article](https://en.wikipedia.org/wiki/Verbal_arithmetic)", + "weight": 1.0 + }, + { + "name": "SlidingPuzzle:0", + "sat": "def sat(moves: List[int], start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):\n\n locs = {i: [x, y] for y, row in enumerate(start) for x, i in enumerate(row)} # locations, 0 stands for blank\n for i in moves:\n assert abs(locs[0][0] - locs[i][0]) + abs(locs[0][1] - locs[i][1]) == 1\n locs[0], locs[i] = locs[i], locs[0]\n return all(locs[i] == [i % len(start[0]), i // len(start)] for i in locs)", + "ans_type": "List[int]", + "sol_header": "def sol(start=[[5, 0, 2, 3], [1, 9, 6, 7], [4, 14, 8, 11], [12, 13, 10, 15]]):", + "sol_docstring": " \"\"\"\n In this puzzle, you are given a board like:\n 1 2 5\n 3 4 0\n 6 7 8\n\n and your goal is to transform it to:\n 0 1 2\n 3 4 5\n 6 7 8\n\n by a sequence of swaps with the 0 square (0 indicates blank). The starting configuration is given by a 2d list\n of lists and the answer is represented by a list of integers indicating which number you swap with 0. In the\n above example, an answer would be [1, 2, 5]\n \"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n import math\n d = len(start)\n N = d * d\n assert all(len(row) == d for row in start)\n\n def get_state(\n li): # state is an integer with 4 bits for each slot and the last 4 bits indicate where the blank is\n ans = 0\n for i in li[::-1] + [li.index(0)]:\n ans = (ans << 4) + i\n return ans\n\n start = get_state([i for row in start for i in row])\n target = get_state(list(range(N)))\n\n def h(state): # manhattan distance\n ans = 0\n for i in range(N):\n state = (state >> 4)\n n = state & 15\n if n != 0:\n ans += abs(i % d - n % d) + abs(i // d - n // d)\n return ans\n\n g = defaultdict(lambda: math.inf)\n g[start] = 0 # shortest p ath lengths\n f = {start: h(start)} # f[s] = g[s] + h(s)\n backtrack = {}\n\n todo = {start}\n import heapq\n heap = [(f[start], start)]\n\n neighbors = [[i for i in [b - 1, b + 1, b + d, b - d] if i in range(N) and (b // d == i // d or b % d == i % d)]\n for b in range(N)]\n\n def next_state(s, blank, i):\n assert blank == (s & 15)\n v = (s >> (4 * i + 4)) & 15\n return s + (i - blank) + (v << (4 * blank + 4)) - (v << (4 * i + 4))\n\n while todo:\n (dist, s) = heapq.heappop(heap)\n if f[s] < dist:\n continue\n if s == target:\n # compute path\n ans = []\n while s != start:\n s, i = backtrack[s]\n ans.append((s >> (4 * i + 4)) & 15)\n return ans[::-1]\n\n todo.remove(s)\n\n blank = s & 15\n score = g[s] + 1\n for i in neighbors[blank]:\n s2 = next_state(s, blank, i)\n\n if score < g[s2]:\n # paths[s2] = paths[s] + [s[i]]\n g[s2] = score\n backtrack[s2] = (s, i)\n score2 = score + h(s2)\n f[s2] = score2\n todo.add(s2)\n heapq.heappush(heap, (score2, s2))" + ], + "module": "classic_puzzles.py", + "notes": "[Sliding puzzle](https://en.wikipedia.org/wiki/15_puzzle)\nThe 3-, 8-, and 15-sliding puzzles are classic examples of A* search.\nThe problem is NP-hard but the puzzles can all be solved with A* and an efficient representation.", + "weight": 1.0 + }, + { + "name": "FindCloseElements:0", + "sat": "def sat(pair: List[float], nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):\n a, b = pair\n assert a in nums and b in nums and a != b\n return abs(a - b) == min(x - y for x in nums for y in nums if x > y)", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[0.17, 21.3, 5.0, 9.0, 11.0, 4.99, 17.0, 17.0, 12.4, 6.8]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the two closest distinct numbers in the list.\n\n Sample Input:\n [1.2, 5.23, 0.89, 21.0, 5.28, 1.2]\n\n Sample Output:\n [5.23, 5.28]\n \"\"\"", + "sol_bodies": [ + " s = sorted(set(nums))\n return min([[a, b] for a, b in zip(s, s[1:])], key=lambda x: x[1] - x[0])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#0", + "weight": 1.0 + }, + { + "name": "SeparateParenGroups:0", + "sat": "def sat(ls: List[str], combined=\"() (()) ((() () ())) (() )\"):\n for s in ls:\n assert s.count(\"(\") == s.count(\")\")\n assert all(s[:i].count(\"(\") > s[:i].count(\")\") for i in range(1, len(s))) # s is not further divisible\n return ''.join(ls) == combined.replace(' ', '')", + "ans_type": "List[str]", + "sol_header": "def sol(combined=\"() (()) ((() () ())) (() )\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of whitespace and groups of matched parentheses, split it\n into groups of perfectly matched parentheses without any whitespace.\n\n Sample Input:\n '( ()) ((()()())) (()) ()'\n\n Sample Output:\n ['(())', '((()()()))', '(())', '()']\n \"\"\"", + "sol_bodies": [ + " cur = ''\n ans = []\n depth = 0\n for c in combined.replace(' ', ''):\n cur += c\n if c == '(':\n depth += 1\n else:\n assert c == ')'\n depth -= 1\n if depth == 0:\n ans.append(cur)\n cur = ''\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#1", + "weight": 1.0 + }, + { + "name": "Frac:0", + "sat": "def sat(x: float, v=523.12892):\n return 0 <= x < 1 and (v - x).is_integer()", + "ans_type": "float", + "sol_header": "def sol(v=523.12892):", + "sol_docstring": " \"\"\"\n Given a floating point number, find its fractional part.\n\n Sample Input:\n 4.175\n\n Sample Output:\n 0.175\n \"\"\"", + "sol_bodies": [ + " return v % 1.0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#2", + "weight": 1.0 + }, + { + "name": "FirstNegCumulative:0", + "sat": "def sat(firsts: List[int], balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]):\n for i, bals in enumerate(balances):\n total = 0\n for b in bals:\n total += b\n if total < 0:\n assert total == firsts[i]\n break\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(balances=[[2, 7, -2, 4, 3, -15, 10, -45, 3], [3, 4, -17, -1], [100, -100, -101], [-1]]):", + "sol_docstring": " \"\"\"\n Given a list of numbers which represent bank deposits and withdrawals, find the *first* negative balance.\n\n Sample Input:\n [[12, -5, 3, -99, 14, 88, -99], [-1, 2, 5]]\n\n Sample Output:\n [-89, -1]\n \"\"\"", + "sol_bodies": [ + " firsts = []\n for bals in balances:\n total = 0\n for b in bals:\n total += b\n if total < 0:\n firsts.append(total)\n break\n return firsts" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#3", + "weight": 1.0 + }, + { + "name": "MinSquaredDeviation:0", + "sat": "def sat(x: float, nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):\n return sum((n - x) ** 2 for n in nums) * len(nums) <= sum((m - n) ** 2 for m in nums for n in nums) * .5 + 1e-4", + "ans_type": "float", + "sol_header": "def sol(nums=[12, -2, 14, 3, -15, 10, -45, 3, 30]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find x that minimizes mean squared deviation.\n\n Sample Input:\n [4, -5, 17, -9, 14, 108, -9]\n\n Sample Output:\n 17.14285\n \"\"\"", + "sol_bodies": [ + " return sum(nums) / len(nums) # mean minimizes mean squared deviation" + ], + "module": "human_eval.py", + "notes": "Loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#4\n\nThe HumanEval problem was simply to compute the mean absolute deviation. This problem is more interesting.\nIt requires minimizing the sum of squared deviations, which turns out to be the mean `mu`. Moreover, if\n`mu` is the mean of the numbers then a simple calculation shows that:\n\n`sum((mu - n) ** 2 for n in nums) == sum((m - n) ** 2 for m in nums for n in nums) / (2 * len(nums))`\n\nWe use 0.501 rather than 1/2 to deal with rounding errors.", + "weight": 1.0 + }, + { + "name": "Intersperse:0", + "sat": "def sat(li: List[int], nums=[12, 23, -2, 5, 0], sep=4):\n return li[::2] == nums and li[1::2] == [sep] * (len(nums) - 1)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, 23, -2, 5, 0], sep=4):", + "sol_docstring": " \"\"\"\n Given a list of numbers and a number to inject, create a list containing that number in between each pair of\n adjacent numbers.\n\n Sample Input:\n [8, 14, 21, 17, 9, -5], 3\n\n Sample Output:\n [8, 3, 14, 3, 21, 3, 17, 3, 9, 3, -5]\n \"\"\"", + "sol_bodies": [ + " ans = [sep] * (2 * len(nums) - 1)\n ans[::2] = nums\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#5", + "weight": 1.0 + }, + { + "name": "DeepestParens:0", + "sat": "def sat(depths: List[int], parens=\"() (()) ((()()())) (((((((())))))))\"):\n groups = parens.split()\n for depth, group in zip(depths, groups):\n budget = depth\n success = False\n for c in group:\n if c == '(':\n budget -= 1\n if budget == 0:\n success = True\n assert budget >= 0\n else:\n assert c == ')'\n budget += 1\n assert success\n\n return len(groups) == len(depths)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"() (()) ((()()())) (((((((())))))))\"):", + "sol_docstring": " \"\"\"\n Given a string consisting of groups of matched nested parentheses separated by parentheses,\n compute the depth of each group.\n\n Sample Input:\n '(()) ((()()())) (()) ()'\n\n Sample Output:\n [2, 3, 2, 1]\n \"\"\"", + "sol_bodies": [ + " def max_depth(s):\n m = 0\n depth = 0\n for c in s:\n if c == '(':\n depth += 1\n m = max(m, depth)\n else:\n assert c == ')'\n depth -= 1\n assert depth == 0\n return m\n\n return [max_depth(s) for s in parens.split()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#6", + "weight": 1.0 + }, + { + "name": "FindContainers:0", + "sat": "def sat(containers: List[str], strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):\n i = 0\n for s in strings:\n if substring in s:\n assert containers[i] == s\n i += 1\n return i == len(containers)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cat', 'dog', 'shatter', 'bear', 'at', 'ta'], substring=\"at\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list containing a given substring\n\n Sample Input:\n ['cat', 'dog', 'bear'], 'a'\n\n Sample Output:\n ['cat', 'bear']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if substring in s]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#7", + "weight": 1.0 + }, + { + "name": "SumProduct:0", + "sat": "def sat(nums: List[int], tot=14, prod=99):\n assert sum(nums) == tot\n p = 1\n for n in nums:\n p *= n\n return p == prod", + "ans_type": "List[int]", + "sol_header": "def sol(tot=14, prod=99):", + "sol_docstring": " \"\"\"\n Find a list of numbers with a given sum and a given product.\n\n Sample Input:\n 12, 32\n\n Sample Output:\n [2, 8, 2]\n \"\"\"", + "sol_bodies": [ + " ans = [prod]\n while sum(ans) > tot:\n ans += [-1, -1]\n ans += [1] * (tot - sum(ans))\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#8", + "weight": 1.0 + }, + { + "name": "RollingMax:0", + "sat": "def sat(maxes: List[int], nums=[1, 4, 3, -6, 19]):\n assert len(maxes) == len(nums)\n for i in range(len(nums)):\n if i > 0:\n assert maxes[i] == max(maxes[i - 1], nums[i])\n else:\n assert maxes[0] == nums[0]\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 4, 3, -6, 19]):", + "sol_docstring": " \"\"\"\n Find a list whose ith element is the maximum of the first i elements of the input list.\n\n Sample Input:\n [2, 8, 2]\n\n Sample Output:\n [2, 8, 8]\n \"\"\"", + "sol_bodies": [ + " return [max(nums[:i]) for i in range(1, len(nums) + 1)]", + " ans = []\n if nums:\n m = nums[0]\n for n in nums:\n m = max(n, m)\n ans.append(m)\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#9", + "weight": 1.0 + }, + { + "name": "PalindromeContaining:0", + "sat": "def sat(ans: str, s=\"so easy\", length=20):\n return ans == ans[::-1] and len(ans) == length and s in ans", + "ans_type": "str", + "sol_header": "def sol(s=\"so easy\", length=20):", + "sol_docstring": " \"\"\"\n Find a palindrome of a given length containing a given string.\n\n Sample Input:\n \"abba\", 6\n\n Sample Output:\n \"cabbac\"\n \"\"\"", + "sol_bodies": [ + " ls = list(s)\n for i in range(length - len(s) + 1):\n arr = ['x'] * length\n arr[i:i + len(s)] = ls\n a = length - i - 1\n b = length - (i + len(s)) - 1\n if b == -1:\n b = None\n arr[a:b:-1] = ls\n if arr == arr[::-1]:\n ans = \"\".join(arr)\n if s in ans:\n return ans\n assert False, \"shouldn't reach here\"" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#10", + "weight": 1.0 + }, + { + "name": "BinaryStrXOR:0", + "sat": "def sat(str_num: str, nums=['100011101100001', '100101100101110']):\n a, b = nums\n return int(str_num, 2) == int(a, 2) ^ int(b, 2)", + "ans_type": "str", + "sol_header": "def sol(nums=['100011101100001', '100101100101110']):", + "sol_docstring": " \"\"\"\n Find a the XOR of two given strings interpreted as binary numbers.\n\n Sample Input:\n \"0001\", \"1011\"\n\n Sample Output:\n \"1010\"\n \"\"\"", + "sol_bodies": [ + " a, b = nums\n ans = int(a, 2) ^ int(b, 2)\n return format(ans, \"b\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#11", + "weight": 1.0 + }, + { + "name": "LongestStr:0", + "sat": "def sat(ans: str, words=['these', 'are', 'some', 'pretty', 'long', 'words']):\n return ans in words and all(len(ans) >= len(w) for w in words)", + "ans_type": "str", + "sol_header": "def sol(words=['these', 'are', 'some', 'pretty', 'long', 'words']):", + "sol_docstring": " \"\"\"\n Find the longest of a list of strings\n\n Sample Input:\n [\"cat\", \"dog\", \"sheep\", \"chimp\"]\n\n Sample Output:\n \"sheep\"\n \"\"\"", + "sol_bodies": [ + " return max(words, key=len)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#12", + "weight": 1.0 + }, + { + "name": "CertifiedGCD:0", + "sat": "def sat(ans: List[int], m=200004931, n=66679984):\n gcd, a, b = ans\n return m % gcd == n % gcd == 0 and a * m + b * n == gcd and gcd > 0", + "ans_type": "List[int]", + "sol_header": "def sol(m=200004931, n=66679984):", + "sol_docstring": " \"\"\"\n Find the greatest common divisor of two integers m, n and a certificate a, b such that m*a + n*b = gcd\n\n Sample Input:\n 20, 30\n\n Sample Output:\n 10, -1, 1\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Derivation of solution below\n Recursive solution guarantees a * (big % small) + b * small == gcd\n Let d = big // small so (big % small) == big - small * d\n gives a * (big - small * d) + b * small == gcd\n or equivalently (b - a * d) * small + a * big == gcd\n \"\"\"\n\n def gcd_cert(small, big):\n \"\"\"Returns gcd, a, b, such that small * a + big * b == gcd\"\"\"\n assert 0 < small <= big\n if big % small == 0:\n return [small, 1, 0]\n gcd, a, b = gcd_cert(big % small, small)\n return [gcd, b - a * (big // small), a]\n\n if m < n:\n return gcd_cert(m, n)\n gcd, a, b = gcd_cert(n, m)\n return [gcd, b, a]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#13", + "weight": 1.0 + }, + { + "name": "AllPrefixes:0", + "sat": "def sat(prefixes: List[str], s=\"donesezichethofalij\"):\n return all(s.startswith(p) for p in prefixes) and len(set(prefixes)) > len(s)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"donesezichethofalij\"):", + "sol_docstring": " \"\"\"\n Find all prefixes of a given string\n\n Sample Input:\n \"aabcd\"\n\n Sample Output:\n [\"\", \"a\", \"aa\", \"aab\", \"aabc\", \"aabcd\"]\n \"\"\"", + "sol_bodies": [ + " return [s[:i] for i in range(len(s) + 1)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#14", + "weight": 1.0 + }, + { + "name": "SpaceyRange:0", + "sat": "def sat(ans: str, n=15):\n return [int(i) for i in ans.split(' ')] == list(range(n + 1))", + "ans_type": "str", + "sol_header": "def sol(n=15):", + "sol_docstring": " \"\"\"\n Find a string consisting of the non-negative integers up to n inclusive\n\n Sample Input:\n 4\n\n Sample Output:\n '0 1 2 3 4'\n \"\"\"", + "sol_bodies": [ + " return ' '.join(str(i) for i in range(n + 1))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#15", + "weight": 1.0 + }, + { + "name": "DistinctChars:0", + "sat": "def sat(ans: List[str], s=\"The quick brown fox jumps over the lazy dog!\", n=28):\n assert all(ans.count(c.lower()) == 1 for c in s)\n assert all(c == c.lower() for c in ans)\n assert all(c in s.lower() for c in ans)\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"The quick brown fox jumps over the lazy dog!\", n=28):", + "sol_docstring": " \"\"\"\n Find the set of distinct characters in a string, ignoring case\n\n Sample Input:\n 'HELlo', 4\n\n Sample Output:\n ['h', 'e', 'l', 'o']\n \"\"\"", + "sol_bodies": [ + " return list(set(s.lower()))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#16", + "weight": 1.0 + }, + { + "name": "ParseMusic:0", + "sat": "def sat(beats: List[int], score=\"o o o| o| .| .| .| o| o| o o o| .|\"):\n return \" \".join({1: '.|', 2: 'o|', 4: 'o'}[b] for b in beats) == score", + "ans_type": "List[int]", + "sol_header": "def sol(score=\"o o o| o| .| .| .| o| o| o o o| .|\"):", + "sol_docstring": " \"\"\"\n Parse a string of notes to beats, 'o'=4, 'o|'=2, '.|'=1\n\n Example input:\n 'o o .| o|'\n\n Example output:\n [4, 4, 1, 2]\n \"\"\"", + "sol_bodies": [ + " mapping = {'.|': 1, 'o|': 2, 'o': 4}\n return [mapping[note] for note in score.split()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#17", + "weight": 1.0 + }, + { + "name": "OverlappingCount:0", + "sat": "def sat(ans: List[int], s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):\n return all(sub == s[i:i + len(sub)] and i >= 0 for i in ans) and len(set(ans)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"Bananannanaannanaanananananana\", sub=\"anan\", count=7):", + "sol_docstring": " \"\"\"\n Find occurrences of a substring in a parent string *including overlaps*\n\n Sample Input:\n 'helllo', 'll'\n\n Sample Output:\n [2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(len(s) + 1):\n if s[i:i + len(sub)] == sub:\n ans.append(i)\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#18", + "weight": 1.0 + }, + { + "name": "SortNumbers:0", + "sat": "def sat(ans: str, s=\"six one four three two nine eight\"):\n nums = 'zero one two three four five six seven eight nine'.split()\n return [nums.index(x) for x in ans.split(\" \")] == sorted([nums.index(x) for x in s.split(\" \")])", + "ans_type": "str", + "sol_header": "def sol(s=\"six one four three two nine eight\"):", + "sol_docstring": " \"\"\"\n Sort numbers based on strings\n\n Sample input\n ---\n \"six one four\"\n\n Sample output\n ---\n \"one four six\"\n \"\"\"", + "sol_bodies": [ + " nums = 'zero one two three four five six seven eight nine'.split()\n arr = [nums.index(x) for x in s.split()]\n arr.sort()\n ans = \" \".join([nums[i] for i in arr])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#19", + "weight": 1.0 + }, + { + "name": "FindClosePair:0", + "sat": "def sat(inds: List[int], nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):\n a, b = inds\n assert a != b and a >= 0 and b >= 0\n for i in range(len(nums)):\n for j in range(i):\n assert abs(nums[i] - nums[j]) >= abs(nums[b] - nums[a])\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[0.31, 21.3, 5.0, 9.0, 11.0, 5.01, 17.2]):", + "sol_docstring": " \"\"\"\n Given a list of numbers, find the indices of the closest pair.\n\n Sample Input:\n [1.2, 5.25, 0.89, 21.0, 5.23]\n\n Sample Output:\n [4, 1]\n \"\"\"", + "sol_bodies": [ + " best = [0, 1]\n best_score = abs(nums[1] - nums[0])\n for i in range(len(nums)):\n for j in range(i):\n score = abs(nums[i] - nums[j])\n if score < best_score:\n best_score = score\n best = [i, j]\n return best" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#20", + "weight": 1.0 + }, + { + "name": "Rescale:0", + "sat": "def sat(ans: List[float], nums=[13.0, 17.0, 17.0, 15.5, 2.94]):\n assert min(ans) == 0.0 and max(ans) == 1.0\n a = min(nums)\n b = max(nums)\n for i in range(len(nums)):\n x = a + (b - a) * ans[i]\n assert abs(nums[i] - x) < 1e-6\n return True", + "ans_type": "List[float]", + "sol_header": "def sol(nums=[13.0, 17.0, 17.0, 15.5, 2.94]):", + "sol_docstring": " \"\"\"\n Rescale and shift numbers so that they cover the range [0, 1]\n\n Sample input\n ---\n [18.5, 17.0, 18.0, 19.0, 18.0]\n\n Sample output\n ---\n [0.75, 0.0, 0.5, 1.0, 0.5]\n \"\"\"", + "sol_bodies": [ + " nums = nums.copy()\n\n a = min(nums)\n b = max(nums)\n if b - a == 0:\n return [0.0] + [1.0] * (len(nums) - 1)\n for i in range(len(nums)):\n nums[i] = (nums[i] - a) / (b - a)\n return nums" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#21", + "weight": 1.0 + }, + { + "name": "FilterInts:0", + "sat": "def sat(candidates: List[str], int_indices=[2, 4, 7, 9, 101]):\n for i in int_indices:\n int(candidates[i])\n for i, s in enumerate(candidates):\n if i not in int_indices:\n try:\n int(s)\n return False\n except ValueError:\n pass\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(int_indices=[2, 4, 7, 9, 101]):", + "sol_docstring": " \"\"\"\n Find a list of strings where the only valid integers are at the given indices\n\n Sample input\n ---\n [2, 4, 5]\n\n Sample output\n ---\n [\"cat\", \"2.7\", \"2\", \"\", \"3\", \"-17\", \"free\"]\n \"\"\"", + "sol_bodies": [ + " if not int_indices:\n return []\n ans = [\"\"] * (1 + max(abs(i) for i in int_indices))\n for i in int_indices:\n ans[i] = \"17\"\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#22", + "weight": 1.0 + }, + { + "name": "StrLength:0", + "sat": "def sat(lengths: List[int], strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']):\n for length, s in zip(lengths, strs):\n try:\n s[length]\n return False\n except IndexError:\n s[length - 1]\n return len(lengths) == len(strs)", + "ans_type": "List[int]", + "sol_header": "def sol(strs=['pneumonoultramicroscopicsilicovolcanoconiosis', ' ', 'foo', '2.5']):", + "sol_docstring": " \"\"\"\n Find the lengths of a list of non-empty strings\n\n Sample input\n ---\n [\"foo\", \"bars\"]\n\n Sample output\n ---\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " return [len(s) for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#23", + "weight": 1.0 + }, + { + "name": "LargestDivisor:0", + "sat": "def sat(d: int, n=123456):\n return n % d == 0 and d < n and all(n % e for e in range(d + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=123456):", + "sol_docstring": " \"\"\"\n Find the largest integer divisor of a number n that is less than n\n\n Sample input\n ---\n 1000\n\n Sample output\n ---\n 500\n \"\"\"", + "sol_bodies": [ + " return next(d for d in range(n - 1, 0, -1) if n % d == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#24", + "weight": 1.0 + }, + { + "name": "PrimeFactorization:0", + "sat": "def sat(factors: List[int], n=123456, num_factors=8):\n assert len(factors) == num_factors\n prod = 1\n for d in factors:\n prod *= d\n assert d > 1\n return prod == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=123456, num_factors=8):", + "sol_docstring": " \"\"\"\n Factor number n into a given number of non-trivial factors\n\n Sample input\n ---\n 1000, 6\n\n Sample output\n ---\n [2, 2, 2, 5, 5, 5]\n \"\"\"", + "sol_bodies": [ + " if num_factors == 0:\n return []\n if num_factors == 1:\n return [n]\n ans = []\n for d in range(2, n):\n while n % d == 0:\n n //= d\n ans.append(d)\n if len(ans) == num_factors - 1:\n ans.append(n)\n return ans\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#25", + "weight": 1.0 + }, + { + "name": "Dedup:0", + "sat": "def sat(ans: List[int], li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):\n return set(ans) == set(li) and all(li.index(ans[i]) < li.index(ans[i + 1]) for i in range(len(ans) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[2, 19, 2, 53, 1, 1, 2, 44, 17, 0, 19, 31]):", + "sol_docstring": " \"\"\"\n Remove duplicates from a list of integers, preserving order\n\n Sample input\n ---\n [1, 3, 2, 9, 2, 1, 55]\n\n Sample output\n ---\n [1, 3, 2, 9, 55]\n \"\"\"", + "sol_bodies": [ + " seen = set()\n ans = []\n for n in li:\n if n not in seen:\n ans.append(n)\n seen.add(n)\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#26", + "weight": 1.0 + }, + { + "name": "FlipCase:0", + "sat": "def sat(ans: str, s=\"FlIp ME!\"):\n return len(ans) == len(s) and all({c, d} == {d.upper(), d.lower()} for c, d in zip(ans, s))", + "ans_type": "str", + "sol_header": "def sol(s=\"FlIp ME!\"):", + "sol_docstring": " \"\"\"\n Flip case\n\n Sample input\n ---\n 'cAt'\n\n Sample output\n ---\n 'CaT'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c.lower() if c.upper() == c else c.upper() for c in s)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#27", + "weight": 1.0 + }, + { + "name": "CatStrings:0", + "sat": "def sat(cat: str, strings=['Will', 'i', 'am', 'Now', 'here']):\n i = 0\n for s in strings:\n for c in s:\n assert cat[i] == c\n i += 1\n return i == len(cat)", + "ans_type": "str", + "sol_header": "def sol(strings=['Will', 'i', 'am', 'Now', 'here']):", + "sol_docstring": " \"\"\"\n Concatenate a list of strings\n\n Sample input\n ---\n ['cat', 'dog', 'bird']\n\n Sample output\n ---\n 'catdogbird'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(strings)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#28", + "weight": 1.0 + }, + { + "name": "FindExtensions:0", + "sat": "def sat(extensions: List[str], strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):\n i = 0\n for s in strings:\n if s.startswith(prefix):\n assert extensions[i] == s\n i += 1\n return i == len(extensions)", + "ans_type": "List[str]", + "sol_header": "def sol(strings=['cat', 'dog', 'shatter', 'donut', 'at', 'todo'], prefix=\"do\"):", + "sol_docstring": " \"\"\"\n Find the strings in a list starting with a given prefix\n\n Sample Input:\n ['cat', 'car', 'fear', 'center'], 'ca'\n\n Sample Output:\n ['cat', 'car']\n \"\"\"", + "sol_bodies": [ + " return [s for s in strings if s.startswith(prefix)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#29", + "weight": 1.0 + }, + { + "name": "FindPositives:0", + "sat": "def sat(positives: List[int], nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):\n stack = positives[::-1]\n for n in nums:\n assert n <= 0 or n == stack.pop()\n return stack == []", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2, 2342, -2, 32, -8, -5, 2342, 0, -9, 44, 11]):", + "sol_docstring": " \"\"\"\n Find the positive integers in a list\n\n Sample Input:\n [-1, 3, 19, -2, 0, 44, 0, 44, 11]\n\n Sample Output:\n [3, 19, 44, 44, 11]\n \"\"\"", + "sol_bodies": [ + " return [i for i in nums if i > 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#30", + "weight": 1.0 + }, + { + "name": "FermatComposites:0", + "sat": "def sat(certificates: List[int], nums=[1449, 14, 21, 105, 217]):\n return all(pow(cert, n - 1, n) > 1 for cert, n in zip(certificates, nums)) and len(certificates) == len(nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1449, 14, 21, 105, 217]):", + "sol_docstring": " \"\"\"\n Find Fermat composite certificates for a list of numbers > 1\n\n Sample Input:\n [1469]\n\n Sample Output:\n [3] # because (3 ** 1468) % 1469 != 1\n \"\"\"", + "sol_bodies": [ + " return [next(i for i in range(2, n) if pow(i, n - 1, n) > 1) for n in nums]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#31", + "weight": 1.0 + }, + { + "name": "OddDegreePolynomialRoot:0", + "sat": "def sat(root: float, coeffs=[1, 2, 3, 17]):\n return abs(sum(coeff * (root ** i) for i, coeff in enumerate(coeffs))) < 1e-4", + "ans_type": "float", + "sol_header": "def sol(coeffs=[1, 2, 3, 17]):", + "sol_docstring": " \"\"\"\n Find a real root of an odd degree polynomial from its coefficients\n\n Sample Input:\n [1, 0, 8]\n\n Sample Output:\n -2.0 # 1*(-2.0)^3 + 8 == 0\n \"\"\"", + "sol_bodies": [ + " def p(x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(coeffs))\n\n for attempt in range(100):\n a, b = -(10 ** attempt), (10 ** attempt)\n p_a, p_b = p(a), p(b)\n while p_a * p_b <= 0:\n mid = (a + b) / 2\n p_mid = p(mid)\n if abs(p_mid) < 1e-4:\n return mid\n assert mid not in [a, b]\n if p_mid * p_a > 0:\n a, p_a = mid, p_mid\n else:\n b, p_b = mid, p_mid\n\n assert False, \"Root finder failed on 100 attempts\"" + ], + "module": "human_eval.py", + "notes": "Polynomials of odd degree always have a real solution.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#32", + "weight": 1.0 + }, + { + "name": "TwoThirdsSorted:0", + "sat": "def sat(li: List[int], orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):\n assert orig[::3] == li[::3], \"Keep every third entry fixed\"\n assert sorted(li) == sorted(orig), \"Not even a permutation\"\n assert all(li[i] <= li[i + 1] for i in range(1, len(li) - 1, 3))\n assert all(li[i] <= li[i + 2] for i in range(2, len(li) - 2, 3))\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, -2, 3, 17, 8, 4, 12, 3, 18, 5, -29, 0, 0]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every third element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [8, 0, 2, 2, 4, 8, 1, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n your_list = orig[::3]\n sub = orig[:]\n for i in range(int((len(sub) + 2) / 3)):\n sub.pop((2 * i))\n sub = sorted(sub)\n answ = []\n for i in range(int(n / 3)):\n answ.append(your_list[i])\n answ.append(sub[i * 2])\n answ.append(sub[i * 2 + 1])\n if n % 3 == 1:\n answ.append(your_list[-1])\n if n % 3 == 2:\n answ.append(your_list[-1])\n answ.append(sub[-1])\n return answ" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#33", + "weight": 1.0 + }, + { + "name": "UniqueSorted:0", + "sat": "def sat(li: List[int], orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):\n for i in range(len(li) - 1):\n assert li[i] < li[i + 1]\n assert li[i] in orig\n for n in orig:\n assert n in li\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, 1, 3, 2, 0, 8, 32, -4, 0]):", + "sol_docstring": " \"\"\"\n Find an increasing sequence consisting of the elements of the original list.\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 4, -2, 8, 3]\n\n Sample Output:\n [-2, 0, 2, 3, 4, 7, 8, 9]\n \"\"\"", + "sol_bodies": [ + " my_list = sorted(set(orig))\n return my_list" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#34", + "weight": 1.0 + }, + { + "name": "MaxInt:0", + "sat": "def sat(m: int, hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]):\n return m in hello and not any(m < i for i in hello)", + "ans_type": "int", + "sol_header": "def sol(hello=[1, 31, 3, 2, 0, 18, 32, -4, 2, -1000, 3502145, 3502145, 21, 18, 2, 60]):", + "sol_docstring": " \"\"\"\n Find the largest integer in a sequence\n\n Sample Input:\n [8, 0, 1, 4, 9, 3, 4, -2, 8, 3]\n\n Sample Output:\n 9\n \"\"\"", + "sol_bodies": [ + " return max(hello)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#35", + "weight": 1.0 + }, + { + "name": "SevenElevenThirteen:0", + "sat": "def sat(li: List[List[int]], n=19723, lower=1000):\n assert len({(i, j) for i, j in li}) >= lower, \"not enough 7's (ignoring duplicates)\"\n return all(str(i)[j] == '7' and (i % 11 == 0 or i % 13 == 0) and 0 <= i < n and 0 <= j for i, j in li)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=19723, lower=1000):", + "sol_docstring": " \"\"\"\n Find all 7's in integers less than n that are divisible by 11 or 13\n\n Sample Input:\n 79, 3\n\n Sample Output:\n [[77, 0], [77, 1], [78, 0]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i in range(n) if (i % 11 == 0 or i % 13 == 0) for j, c in enumerate(str(i)) if c == '7']" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#36", + "weight": 1.0 + }, + { + "name": "HalfSorted:0", + "sat": "def sat(li: List[int], orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):\n return orig[1::2] == li[1::2] and li[::2] == sorted(orig[::2])", + "ans_type": "List[int]", + "sol_header": "def sol(orig=[1, 6, 3, 41, 19, 4, 12, 3, 18, 5, -29, 0, 19521]):", + "sol_docstring": " \"\"\"\n Start with a list of integers, keep every other element in place and otherwise sort the list\n\n Sample Input:\n [8, 0, 7, 2, 9, 4, 1, 2, 8, 3]\n\n Sample Output:\n [1, 0, 2, 2, 4, 8, 8, 8, 9, 3]\n \"\"\"", + "sol_bodies": [ + " n = len(orig)\n odds = orig[1::2]\n evens = sorted(orig[::2])\n ans = []\n for i in range(len(evens)):\n ans.append(evens[i])\n if i < len(odds):\n ans.append(odds[i])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#37", + "weight": 1.0 + }, + { + "name": "ThreeCycle:0", + "sat": "def sat(s: str, target=\"Hello world\"):\n\n def cycle3(trip):\n return trip if len(trip) != 3 else trip[2] + trip[:2]\n\n return target == \"\".join(cycle3(s[i: i + 3]) for i in range(0, len(s), 3))", + "ans_type": "str", + "sol_header": "def sol(target=\"Hello world\"):", + "sol_docstring": " \"\"\"\n Given a target string, find a string s such that when each group of three consecutive characters is cycled\n forward one character, you achieve the target string.\n\n Sample Input:\n \"This is a test\"\n\n Sample Output:\n 'hiT is aste st'\n \"\"\"", + "sol_bodies": [ + " def un_cycle3(trip):\n return trip if len(trip) != 3 else trip[1:3] + trip[0]\n\n return \"\".join(un_cycle3(target[i: i + 3]) for i in range(0, len(target), 3))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#38", + "weight": 1.0 + }, + { + "name": "PrimeFib:0", + "sat": "def sat(n: int, lower=123456):\n assert any((i ** 0.5).is_integer() for i in [5 * n * n - 4, 5 * n * n + 4]), \"n must be a Fibonacci number\"\n assert all(n % i for i in range(2, int(n ** 0.5) + 1)), \"n must be prime\"\n return n > lower", + "ans_type": "int", + "sol_header": "def sol(lower=123456):", + "sol_docstring": " \"\"\"\n Find a prime Fibonacci number bigger than a certain threshold, using Ira Gessel's test for Fibonacci numbers.\n\n Sample Input:\n 10\n\n Sample Output:\n 11\n \"\"\"", + "sol_bodies": [ + " m, n = 2, 3\n while True:\n m, n = n, (m + n)\n if n > lower and all(n % i for i in range(2, int(n ** 0.5) + 1)):\n return n" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#39\n\nIra Gessel observed that n is a Fibonacci number if and if either 5 n^2 - 4 or 5 n^2 + 4 is a perfect square", + "weight": 1.0 + }, + { + "name": "TripleZeroSum:0", + "sat": "def sat(inds: List[int], nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]):\n return len(inds) == 3 and sum(nums[i] for i in inds) == 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, 6, 41, 15, -10452, 18242, 10440, 6, 6, 6, 6]):", + "sol_docstring": " \"\"\"\n Find the indices of three numbers that sum to 0 in a list.\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " # \\tilde{O}(n^2) algorithm\n inv = {n: i for i, n in enumerate(nums)} # note that later duplicates will override earlier entries\n for i, n in enumerate(nums):\n if inv[n] == i:\n del inv[n]\n if any((-m - n) in inv for m in nums[:i]): # found solution!\n j, m = next((j, m) for j, m in enumerate(nums) if (-m - n) in inv)\n k = inv[-m - n]\n return sorted([i, j, k])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#40\n \nSimilar to but harder than PairZeroSum \\#43.\n \nThis is a version of the classic [3SUM](https://en.wikipedia.org/wiki/3SUM) problem.", + "weight": 1.0 + }, + { + "name": "NumPasses:0", + "sat": "def sat(count: int, n=981):\n for i in range(n):\n for j in range(n):\n count -= 1\n return count == 0", + "ans_type": "int", + "sol_header": "def sol(n=981):", + "sol_docstring": " \"\"\"\n Given n cars traveling East and n cars traveling West on a road, how many passings will there be?\n A passing is when one car passes another. The East-bound cars all begin further West than the West-bound cars.\n\n --Sample input--\n 2\n\n --Sample output--\n 4\n \"\"\"", + "sol_bodies": [ + " return n ** 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#41", + "weight": 1.0 + }, + { + "name": "ListInc:0", + "sat": "def sat(new_list: List[int], old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):\n return [i - 1 for i in new_list] == old_list", + "ans_type": "List[int]", + "sol_header": "def sol(old_list=[321, 12, 532, 129, 9, -12, 4, 56, 90, 0]):", + "sol_docstring": " \"\"\"\n Decrement each element of new_list by 1 and check that it's old_list\n\n Sample Input:\n [17, 15, 99]\n\n Sample Output:\n [18, 16, 100]\n \"\"\"", + "sol_bodies": [ + " return [i + 1 for i in old_list]" + ], + "module": "human_eval.py", + "notes": "Increment each element of a list by 1\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#42", + "weight": 1.0 + }, + { + "name": "PairZeroSum:0", + "sat": "def sat(inds: List[int], nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):\n a, b = inds\n return nums[a] + nums[b] == 0 and a >= 0 and b >= 0", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[12, -10452, 18242, 10440, 81, 241, 525, -18242, 91, 20]):", + "sol_docstring": " \"\"\"\n Find the indices of two numbers that sum to 0 in a list.\n\n Sample Input:\n [1, -4, -4, 7, -3]\n\n Sample Output:\n [1, 2]\n \"\"\"", + "sol_bodies": [ + " s = set(nums)\n for i in s:\n if -i in s:\n return [nums.index(i), nums.index(-i)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#43\n\nSimilar to TripleZeroSum \\#40", + "weight": 1.0 + }, + { + "name": "ChangeBase:0", + "sat": "def sat(s: str, n=142, base=7):\n return int(s, base) == n", + "ans_type": "str", + "sol_header": "def sol(n=142, base=7):", + "sol_docstring": " \"\"\"\n Write n in the given base as a string\n\n Sample Input:\n n=23, base=12\n\n Sample Output:\n '1A'\n \"\"\"", + "sol_bodies": [ + " assert 2 <= base <= 10\n ans = \"\"\n while n:\n ans = str(n % base) + ans\n n //= base\n return ans or \"0\"" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#44", + "weight": 1.0 + }, + { + "name": "TriangleArea:0", + "sat": "def sat(height: int, area=1319098728582, base=45126):\n return base * height == 2 * area", + "ans_type": "int", + "sol_header": "def sol(area=1319098728582, base=45126):", + "sol_docstring": " \"\"\"\n Find the height of a triangle given the area and base. It is guaranteed that the answer is an integer.\n\n Sample Input:\n area = 6, base = 3\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return (2 * area) // base" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#45", + "weight": 1.0 + }, + { + "name": "Fib4:0", + "sat": "def sat(init: List[int], target=2021):\n a, b, c, d = init\n for i in range(99):\n a, b, c, d = b, c, d, (a + b + c + d)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=2021):", + "sol_docstring": " \"\"\"\n Define a four-wise Fibonacci sequence to be a sequence such that each number is the sum of the previous\n four. Given a target number, find an initial four numbers such that the 100th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0, 0]\n for i in range(99):\n x = nums[3] - sum(nums[:3]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:3]\n return nums" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#46\n\nAlmost identical to problem 63", + "weight": 1.0 + }, + { + "name": "Median:0", + "sat": "def sat(x: int, nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):\n dev = sum(n - x for n in nums)\n return dev <= upper", + "ans_type": "int", + "sol_header": "def sol(nums=[132666041, 237412, 28141, -12, 11939, 912414, 17], upper=133658965):", + "sol_docstring": " \"\"\"\n Find an integer that minimizes the sum of absolute deviations with respect to the given numbers.\n\n Sample Input:\n [3, 6, 1, 2, 5, 4, 100], upper=105\n\n Sample Output:\n 4\n \"\"\"", + "sol_bodies": [ + " return sorted(nums)[len(nums) // 2] if nums else 0" + ], + "module": "human_eval.py", + "notes": "One definition of the median is a number that minimizes the sum of absolute deviations. When there are an\neven number of items, there is an interval of valid solutions.\n\nInspired by [HumanEval](https://github.com/openai/human-eval) \\#47", + "weight": 1.0 + }, + { + "name": "Palindrome:0", + "sat": "def sat(pals: List[bool], strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']):\n return all(pals[i] == (s == s[::-1]) for i, s in enumerate(strs))", + "ans_type": "List[bool]", + "sol_header": "def sol(strs=['palindrome', 'madamimadam', '', 'foo', 'eyes', '(-:-)']):", + "sol_docstring": " \"\"\"\n Test whether the given strings are palindromes\n\n Sample Input:\n [\"aba\", \"no\"]\n\n Sample Output:\n [True, False]\n \"\"\"", + "sol_bodies": [ + " return [s == s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#48", + "weight": 1.0 + }, + { + "name": "LittleFermat:0", + "sat": "def sat(exp_poly: List[int], d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):\n p = len(poly)\n assert p > 2 and all(p % i for i in range(2, p)), \"Hint: p is a prime > 2\"\n\n def val(coeffs, n): # evaluate polynomial mod p\n return sum(c * pow(n, i, p) for i, c in enumerate(coeffs)) % p\n\n return all(val(exp_poly, n) == pow(val(poly, n), d, p) for n in range(p))", + "ans_type": "List[int]", + "sol_header": "def sol(d=74152093423, poly=[1, 6, 3, 1, 0, 4, 4]):", + "sol_docstring": " \"\"\"\n Fermat's little theorem implies that any polynomial can be written equivalently as a degree p-1\n polynomial (mod p).\n Given the p coefficients of a polynomial poly, compute a polynomial equivalent to poly^d (mod p).\n\n Sample Input:\n d=2, poly=[1, 0, 0, 1, 0] # 1 + x^3\n\n Sample Output:\n [1, 0, 1, 2, 0] # 1+ x^2 + 2x^3 because (1 + x^3)^2 = 1 + 2x^3 + x^6 and x^6 = x^2 (mod 5)\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n Use repeated squaring to exponentiate polynomial\n \"\"\"\n p = len(poly)\n\n def prod(poly1, poly2): # multiply two polynomials mod p\n ans = [0] * p\n for i, a in enumerate(poly1):\n for j, b in enumerate(poly2):\n e = (i + j) % (p - 1)\n if e == 0 and i + j > 1:\n e = p - 1\n ans[e] = (ans[e] + a * b) % p\n return ans\n\n ans = [1] + [0] * (p - 1)\n while d:\n if d % 2:\n ans = prod(ans, poly)\n poly = prod(poly, poly)\n d //= 2\n # for i in range(d):\n # ans = prod(ans, poly)\n return ans" + ], + "module": "human_eval.py", + "notes": "Harder but loosely inspired by [HumanEval](https://github.com/openai/human-eval) \\#49", + "weight": 1.0 + }, + { + "name": "ShiftChars:0", + "sat": "def sat(orig: str, result=\"Hello, world!\", shift=7):\n n = len(result)\n assert len(orig) == n\n return all(ord(orig[i]) + shift == ord(result[i]) for i in range(n))", + "ans_type": "str", + "sol_header": "def sol(result=\"Hello, world!\", shift=7):", + "sol_docstring": " \"\"\"\n Find a string which, when each character is shifted (ascii incremented) by shift, gives the result.\n\n Sample Input:\n result='very good', shift=-1\n\n Sample Output:\n 'wfsz!hppe'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(c) - shift) for c in result)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#50", + "weight": 1.0 + }, + { + "name": "RemoveVowels:0", + "sat": "def sat(txt: str, text=\"Hello, world!\"):\n n = 0\n for c in text:\n if c.lower() not in \"aeiou\":\n assert txt[n] == c\n n += 1\n assert n == len(txt)\n return True", + "ans_type": "str", + "sol_header": "def sol(text=\"Hello, world!\"):", + "sol_docstring": " \"\"\"\n Remove the vowels from the original string.\n\n Sample Input:\n \"very good\"\n\n Sample Output:\n 'vry gd'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(c for c in text if c.lower() not in \"aeiou\")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#51\n\nRelated to FindVowels \\#54", + "weight": 1.0 + }, + { + "name": "BelowThreshold:0", + "sat": "def sat(indexes: List[int], nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):\n j = 0\n for i, n in enumerate(nums):\n if n < thresh:\n assert indexes[j] == i\n j += 1\n assert j == len(indexes)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[0, 2, 17, 4, 4213, 322, 102, 29, 15, 39, 55], thresh=100):", + "sol_docstring": " \"\"\"\n Find the indexes of numbers below a given threshold\n\n Sample Input:\n nums=[4, 7, 11, 5], threshold=10\n\n Sample Output:\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [i for i, n in enumerate(nums) if n < thresh]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#52", + "weight": 1.0 + }, + { + "name": "ListTotal:0", + "sat": "def sat(n: int, nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):\n return sum(nums + [-n]) == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[10, 42, 17, 9, 1315182, 184, 102, 29, 15, 39, 755]):", + "sol_docstring": " \"\"\"\n Find the number which when appended to the list makes the total 0\n\n Sample Input:\n [1, 2, 3]\n\n Sample Output:\n -6\n \"\"\"", + "sol_bodies": [ + " return sum(nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#53", + "weight": 1.0 + }, + { + "name": "DiffChars:0", + "sat": "def sat(c: str, a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):\n return (c in a) != (c in b)", + "ans_type": "str", + "sol_header": "def sol(a=\"the quick brown fox jumped over the lazy dog\", b=\"how vexingly quick daft zebras jump\"):", + "sol_docstring": " \"\"\"\n Find a character in one string that is not in the other.\n\n Sample Input:\n 'Do you like green eggs and ham?', 'I do not like green eggs and ham.'\n\n Sample Output:\n 't' # or .?yI\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).symmetric_difference(b))[0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#54", + "weight": 1.0 + }, + { + "name": "Fibonacci:0", + "sat": "def sat(nums: List[int], n=1402):\n return nums[0] == nums[1] == 1 and all(nums[i + 2] == nums[i + 1] + nums[i] for i in range(n - 2))", + "ans_type": "List[int]", + "sol_header": "def sol(n=1402):", + "sol_docstring": " \"\"\"\n Find the first n Fibonacci numbers\n\n Sample Input:\n 4\n\n Sample Output:\n [1, 1, 2, 3]\n \"\"\"", + "sol_bodies": [ + " ans = [1, 1]\n while len(ans) < n:\n ans.append(ans[-1] + ans[-2])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#55", + "weight": 1.0 + }, + { + "name": "MatchBrackets:0", + "sat": "def sat(matches: List[int], brackets=\"<<>><<<><>><<>>>\"):\n for i in range(len(brackets)):\n j = matches[i]\n c = brackets[i]\n assert brackets[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(brackets)", + "ans_type": "List[int]", + "sol_header": "def sol(brackets=\"<<>><<<><>><<>>>\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching brackets for each character in the string\n\n Sample Input:\n \"<><>\"\n\n Sample Output:\n [1, 0, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(brackets)\n opens = []\n for i, c in enumerate(brackets):\n if c == \"<\":\n opens.append(i)\n else:\n assert c == \">\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#56", + "weight": 1.0 + }, + { + "name": "Monotonic:0", + "sat": "def sat(direction: str, nums=[2, 4, 17, 29, 31, 1000, 416629]):\n if direction == \"increasing\":\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n if direction == \"decreasing\":\n return all(nums[i + 1] < nums[i] for i in range(len(nums) - 1))", + "ans_type": "str", + "sol_header": "def sol(nums=[2, 4, 17, 29, 31, 1000, 416629]):", + "sol_docstring": " \"\"\"\n Determine the direction ('increasing' or 'decreasing') of monotonic sequence nums\n\n Sample Input:\n [1, 2, 5]\n\n Sample Output:\n \"increasing\"\n \"\"\"", + "sol_bodies": [ + " return \"increasing\" if len(nums) > 1 and nums[1] > nums[0] else \"decreasing\"" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#57", + "weight": 1.0 + }, + { + "name": "CommonNumbers:0", + "sat": "def sat(common: List[int], a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):\n return all((i in common) == (i in a and i in b) for i in a + b + common)", + "ans_type": "List[int]", + "sol_header": "def sol(a=[2, 416629, 2, 4, 17, 29, 31, 1000], b=[31, 2, 4, 17, 29, 41205]):", + "sol_docstring": " \"\"\"\n Find numbers common to a and b\n\n Sample Input:\n [1, 2, 3], [3, 4, 5]\n\n Sample Output:\n [3]\n \"\"\"", + "sol_bodies": [ + " return sorted(set(a).intersection(set(b)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#58", + "weight": 1.0 + }, + { + "name": "LargestPrimeFactor:0", + "sat": "def sat(p: int, n=101076):\n\n def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return is_prime(p) and n % p == 0 and p > 0 and all(n % i or not is_prime(i) for i in range(p + 1, n))", + "ans_type": "int", + "sol_header": "def sol(n=101076):", + "sol_docstring": " \"\"\"\n Find the largest prime factor of n.\n\n Sample Input:\n 125\n\n Sample Output:\n 5\n \"\"\"", + "sol_bodies": [ + " def is_prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return next(n // i for i in range(1, n) if n % i == 0 and is_prime(n // i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#59", + "weight": 1.0 + }, + { + "name": "CumulativeSums:0", + "sat": "def sat(sums: List[int], n=104):\n return all(sums[i + 1] - sums[i] == i for i in range(n)) and sums[0] == 0", + "ans_type": "List[int]", + "sol_header": "def sol(n=104):", + "sol_docstring": " \"\"\"\n Find the sums of the integers from 1 to n\n\n Sample Input:\n 3\n\n Sample Output:\n [0, 1, 3, 6]\n \"\"\"", + "sol_bodies": [ + " ans = [0]\n for i in range(n):\n ans.append(ans[-1] + i)\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#60", + "weight": 1.0 + }, + { + "name": "ParenDepth:0", + "sat": "def sat(matches: List[int], parens=\"((())()(()()))(())\"):\n for i, (j, c) in enumerate(zip(matches, parens)):\n assert parens[j] != c and matches[j] == i and all(i < matches[k] < j for k in range(i + 1, j))\n return len(matches) == len(parens)", + "ans_type": "List[int]", + "sol_header": "def sol(parens=\"((())()(()()))(())\"):", + "sol_docstring": " \"\"\"\n Find the index of the matching parentheses for each character in the string\n\n Sample Input:\n \"()((()))\"\n\n Sample Output:\n [1, 0, 7, 6, 5, 4, 3, 2]\n \"\"\"", + "sol_bodies": [ + " matches = [-1] * len(parens)\n opens = []\n for i, c in enumerate(parens):\n if c == \"(\":\n opens.append(i)\n else:\n assert c == \")\"\n j = opens.pop()\n matches[i] = j\n matches[j] = i\n return matches" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#61\n\nNote that problems 61 and 56 are essentially the same", + "weight": 1.0 + }, + { + "name": "Derivative:0", + "sat": "def sat(derivative: List[int], poly=[2, 1, 0, 4, 19, 231, 0, 5]):\n\n def val(poly, x):\n return sum(coeff * (x ** i) for i, coeff in enumerate(poly))\n\n return all(abs(val(poly, x + 1e-8) - val(poly, x) - 1e-8 * val(derivative, x)) < 1e-4 for x in range(len(poly)))", + "ans_type": "List[int]", + "sol_header": "def sol(poly=[2, 1, 0, 4, 19, 231, 0, 5]):", + "sol_docstring": " \"\"\"\n Find the derivative of the given polynomial, with coefficients in order of increasing degree\n\n Sample Input:\n [3, 4, 1] # 3 + 4x + x^2\n\n Sample Output:\n [2, 4] # 4 + 2x^2\n \"\"\"", + "sol_bodies": [ + " return [i * poly[i] for i in range(1, len(poly))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#62\n\nThis puzzle gives the raw definition of a derivative in terms of small changes in x.", + "weight": 1.0 + }, + { + "name": "Fib3:0", + "sat": "def sat(init: List[int], target=124156):\n a, b, c = init\n for i in range(16):\n a, b, c = b, c, (a + b + c)\n return a == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=124156):", + "sol_docstring": " \"\"\"\n Define a triple-Fibonacci sequence to be a sequence such that each number is the sum of the previous\n three. Given a target number, find an initial triple such that the 17th number in the sequence is the\n given target number.\n\n Sample Input:\n 0\n\n Sample Output:\n [0, 0, 0]\n \"\"\"", + "sol_bodies": [ + " nums = [target, 0, 0]\n for i in range(16):\n x = nums[-1] - sum(nums[:-1]) # x is such that x + nums[:3] == nums[3]\n nums = [x] + nums[:-1]\n return nums" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#63\n\nAlmost identical to problem 46", + "weight": 1.0 + }, + { + "name": "FindVowels:0", + "sat": "def sat(vowels: List[str], texts=['Hello, world!', 'Goodbye, world!']):\n for v, t in zip(vowels, texts):\n i = 0\n for j, c in enumerate(t):\n if c.lower() in \"aeiou\" or c.lower() == 'y' and j == len(t) - 1:\n assert v[i] == c\n i += 1\n assert i == len(v)\n return len(vowels) == len(texts)", + "ans_type": "List[str]", + "sol_header": "def sol(texts=['Hello, world!', 'Goodbye, world!']):", + "sol_docstring": " \"\"\"\n Find the vowels from each of the original texts (y counts as a vowel at the end of the word)\n\n Sample Input:\n [\"You can do it!\", \"CAT\"]\n\n Sample Output:\n [\"ouaoi\", \"A\"]\n \"\"\"", + "sol_bodies": [ + " return [\"\".join(c for c in text if c.lower() in \"aeiou\") + (text[-1] if text[-1].lower() == \"y\" else \"\")\n for text in texts]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#64\n\nVery similar to RemoveVowels \\#51", + "weight": 1.0 + }, + { + "name": "CircularShiftNum:0", + "sat": "def sat(shifted: str, n=124582369835, shift=3):\n if shift > len(str(n)):\n return n == int(shifted[::-1])\n return n == int(shifted[-shift:] + shifted[:-shift])", + "ans_type": "str", + "sol_header": "def sol(n=124582369835, shift=3):", + "sol_docstring": " \"\"\"\n Shift the decimal digits n places to the left, wrapping the extra digits around. If shift > the number of\n digits of n, reverse the string.\n\n n=12345 shift=2 => '34512'\n \"\"\"", + "sol_bodies": [ + " s = str(n)\n if shift > len(s):\n return s[::-1]\n return s[shift:] + s[:shift]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#65", + "weight": 1.0 + }, + { + "name": "CharSum:0", + "sat": "def sat(tot: int, s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):\n for c in s:\n if c.isupper():\n tot -= ord(c)\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(s=\"Add ME uP AND YOU WILL GET A BIG NUMBER!\"):", + "sol_docstring": " \"\"\"\n Compute the sum of the ASCII values of the upper-case characters in the string.\n\n Sample Input:\n ARt\n\n Sample Output:\n 147 # = 65 + 82\n \"\"\"", + "sol_bodies": [ + " return sum(ord(c) for c in s if c.isupper())" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#66", + "weight": 1.0 + }, + { + "name": "MissingBananas:0", + "sat": "def sat(bananas: int, bowl=\"5024 apples and 12189 oranges\", total=12491241):\n bowl += f\" and {bananas} bananas\"\n return sum([int(s) for s in bowl.split() if s.isdigit()]) == total", + "ans_type": "int", + "sol_header": "def sol(bowl=\"5024 apples and 12189 oranges\", total=12491241):", + "sol_docstring": " \"\"\"\n Determine how many bananas are necessary to reach a certain total amount of fruit\n\n bowl=\"3 apples and 4 oranges\", total=12 => 5\n \"\"\"", + "sol_bodies": [ + " apples, oranges = [int(s) for s in bowl.split() if s.isdigit()]\n return total - apples - oranges" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#67", + "weight": 1.0 + }, + { + "name": "SmallestEven:0", + "sat": "def sat(val_index: List[int], nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):\n if val_index == []:\n return all(n % 2 == 1 for n in nums)\n v, i = val_index\n assert v % 2 == 0 and nums[i] == v\n return all(n > v or n % 2 == 1 for n in nums[:i]) and all(n >= v or n % 2 == 1 for n in nums[i:])", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[125123, 422323, 141, 5325, 812152, 9, 42145, 5313, 421, 812152]):", + "sol_docstring": " \"\"\"\n Given an array of nums representing a branch on a binary tree, find the minimum even value and its index.\n In the case of a tie, return the smallest index. If there are no even numbers, the answer is [].\n\n Sample Input:\n [1, 7, 4, 6, 10, 11, 14]\n\n Sample Output:\n [4, 2]\n \"\"\"", + "sol_bodies": [ + " if any(n % 2 == 0 for n in nums):\n return min([v, i] for i, v in enumerate(nums) if v % 2 == 0)\n else:\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#68", + "weight": 1.0 + }, + { + "name": "GreatestHIndex:0", + "sat": "def sat(h: int, seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):\n for i in seq:\n assert not (i > 0 and i > h and seq.count(i) >= i)\n return h == -1 or seq.count(h) >= h > 0", + "ans_type": "int", + "sol_header": "def sol(seq=[3, 1, 4, 17, 5, 17, 2, 1, 41, 32, 2, 5, 5, 5, 5]):", + "sol_docstring": " \"\"\"\n Find the h-index, the largest positive number h such that that h occurs in the sequence at least h times.\n h = -1 if there is no such positive number.\n\n Sample Input:\n [1, 2, 2, 3, 3, 3, 4, 4]\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " return max([-1] + [i for i in seq if i > 0 and seq.count(i) >= i])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#69", + "weight": 1.0 + }, + { + "name": "WildSort:0", + "sat": "def sat(strange: List[int], li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):\n assert sorted(strange) == sorted(li), \"Must be a permutation\"\n return all(n == (min, max)[i % 2](strange[i:]) for i, n in enumerate(strange))", + "ans_type": "List[int]", + "sol_header": "def sol(li=[30, 12, 42, 717, 45, 317, 200, -1, 491, 32, 15]):", + "sol_docstring": " \"\"\"\n Find the following strange sort of li: the first element is the smallest, the second is the largest of the\n remaining, the third is the smallest of the remaining, the fourth is the smallest of the remaining, etc.\n\n Sample Input:\n [1, 2, 7, 3, 4, 5, 6]\n\n Sample Output:\n [1, 7, 2, 6, 3, 5, 4]\n \"\"\"", + "sol_bodies": [ + " s = sorted(li)\n i = 0\n j = len(li) - 1\n ans = []\n while i <= j:\n if len(ans) % 2:\n ans.append(s[j])\n j -= 1\n else:\n ans.append(s[i])\n i += 1\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#70", + "weight": 1.0 + }, + { + "name": "HeronTriangle:0", + "sat": "def sat(coords: List[List[float]], sides=[8.9, 10.8, 17.0]):\n assert len(coords) == 3\n sides2 = [((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 for i, (x, y) in enumerate(coords) for x2, y2 in coords[:i]]\n return all(abs(a - b) < 1e-6 for a, b in zip(sorted(sides), sorted(sides2)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(sides=[8.9, 10.8, 17.0]):", + "sol_docstring": " \"\"\"\n Find the coordinates of a triangle with the given side lengths\n\n Sample Input:\n [3.0, 4.0, 5.0\n\n Sample Output:\n [[0.0, 0.0], [3.0, 0.0], [0.0, 4.0]]\n \"\"\"", + "sol_bodies": [ + " a, b, c = sorted(sides)\n\n s = sum(sides) / 2 # semi-perimeter\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 # Heron's formula\n\n y = 2 * area / a # height\n x = (c ** 2 - y ** 2) ** 0.5\n return [[0.0, 0.0], [a, 0.0], [x, y]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#71\n\nThat problem essentially asks for Heron's formula for the area of a triangle in terms of its three sides.\nIn our version, we consider the related problem (also solved by Heron's formula) of finding 2d coordinates\nof a triangle with the given sides. If one knows the area, this is a straightforward calculation.", + "weight": 1.0 + }, + { + "name": "InvestigateCrash:0", + "sat": "def sat(problem: int, weights=[1, 2, 5, 2, 1, 17], max_weight=100):\n if problem == -1:\n return sum(weights) > max_weight\n return weights[problem] != weights[- 1 - problem]", + "ans_type": "int", + "sol_header": "def sol(weights=[1, 2, 5, 2, 1, 17], max_weight=100):", + "sol_docstring": " \"\"\"\n An object will \"fly\" if its weights are a palindrome and sum to <= max_weight. The given object won't fly.\n You have to determine why. Find index where the weights aren't a palindrome or -1 if weights are too big.\n\n weights=[77, 40], max_weight=100 => -1\n\n weights=[1,2,3], max_weight=50 => 0 # because 1 != 3\n \"\"\"", + "sol_bodies": [ + " if sum(weights) > max_weight:\n return -1\n return next(i for i, w in enumerate(weights) if weights[-i - 1] != weights[i])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#72", + "weight": 1.0 + }, + { + "name": "ClosestPalindrome:0", + "sat": "def sat(pal: str, s=\"palindromordinals\"):\n assert pal == pal[::-1] and len(pal) == len(s)\n return sum(a != b for a, b in zip(pal, s)) == sum(a != b for a, b in zip(s, s[::-1])) // 2", + "ans_type": "str", + "sol_header": "def sol(s=\"palindromordinals\"):", + "sol_docstring": " \"\"\"\n Find the closest palindrome\n\n Sample Input:\n \"cat\"\n\n Sample Output:\n \"tat\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return s[:(n + 1) // 2] + s[:n // 2][::-1]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#73", + "weight": 1.0 + }, + { + "name": "NarrowerList:0", + "sat": "def sat(li: List[str], lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):\n width = sum(len(s) for s in li)\n for li2 in lists:\n assert width <= sum(len(s) for s in li2)\n return li in lists", + "ans_type": "List[str]", + "sol_header": "def sol(lists=[['this', 'list', 'is', 'narrow'], ['I', 'am', 'shorter but wider']]):", + "sol_docstring": " \"\"\"\n Find the list that has fewer total characters (including repetitions)\n\n Sample Input:\n [[\"sh\", \"ort\"], [\"longest\"]]\n\n Sample Output:\n [[\"sh\", \"ort\"]\n \"\"\"", + "sol_bodies": [ + " return min(lists, key=lambda x: sum(len(i) for i in x))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#74", + "weight": 1.0 + }, + { + "name": "ThreePrimes:0", + "sat": "def sat(factors: List[List[int]]):\n primes = set(range(2, 1000))\n for n in range(2, 1000):\n if n in primes:\n primes.difference_update(range(2 * n, 1000, n))\n assert all(p in primes for f in factors for p in f), \"all factors must be prime\"\n nums = {p * q * r for p, q, r in factors}\n return max(nums) < 1000 and len(nums) == 247", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find all 247 integers <= 1000 that are the product of exactly three primes.\n Each integer should represented as the list of its three prime factors.\n [[2, 2, 2], [2, 2, 3], [2, 2, 5], ...\n \"\"\"", + "sol_bodies": [ + " primes = set(range(2, 1000))\n for n in range(2, 1000):\n if n in primes:\n primes.difference_update(range(2 * n, 1000, n))\n 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]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#75", + "weight": 1.0 + }, + { + "name": "IntegerLog:0", + "sat": "def sat(x: int, a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849):\n return a ** x == n", + "ans_type": "int", + "sol_header": "def sol(a=3, n=1290070078170102666248196035845070394933441741644993085810116441344597492642263849):", + "sol_docstring": " \"\"\"Find an integer exponent x such that a^x = n\n Sample Input:\n a=2, n=1024\n\n Sample Output:\n x = 10\n \"\"\"", + "sol_bodies": [ + " m = 1\n x = 0\n while m != n:\n x += 1\n m *= a\n return x" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#76", + "weight": 1.0 + }, + { + "name": "CubeRoot:0", + "sat": "def sat(x: int, n=42714774173606970182754018064350848294149432972747296768):\n return x ** 3 == n", + "ans_type": "int", + "sol_header": "def sol(n=42714774173606970182754018064350848294149432972747296768):", + "sol_docstring": " \"\"\"Find an integer that when cubed is n\n\n Sample Input:\n 21\n\n Sample Output:\n 3\n \"\"\"", + "sol_bodies": [ + " # Using Newton's method\n m = abs(n)\n x = round(abs(n) ** (1 / 3))\n while x ** 3 != m:\n x += (m - x ** 3) // (3 * x ** 2)\n return -x if n < 0 else x" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#77\n\nWe made it harder by giving very large n for which `round(n ** (1/3))`", + "weight": 1.0 + }, + { + "name": "HexPrimes:0", + "sat": "def sat(primes: List[bool], n=\"A4D4455214122CE192CCBE3\"):\n return all(primes[i] == (c in \"2357BD\") for i, c in enumerate(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(n=\"A4D4455214122CE192CCBE3\"):", + "sol_docstring": " \"\"\"Determine which characters of a hexidecimal correspond to prime numbers\n\n Sample Input:\n \"123ABCD\"\n\n Sample Output:\n [False, True, True, False, True, False True]\n \"\"\"", + "sol_bodies": [ + " return [c in \"2357BD\" for c in n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#78", + "weight": 1.0 + }, + { + "name": "Binarize:0", + "sat": "def sat(b: str, n=5324680297138495285):\n assert b[:4] == b[-4:] == 'bits'\n inside = b[4:-4]\n assert all(c in \"01\" for c in inside)\n assert inside[0] == \"1\" or len(inside) == 1\n m = 0\n for c in inside:\n m = 2 * m + int(c)\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=5324680297138495285):", + "sol_docstring": " \"\"\"Write n base 2 followed and preceded by 'bits'\n Sample Input:\n 2\n\n Sample Output:\n bits10bits\n \"\"\"", + "sol_bodies": [ + " s = bin(n)[2:]\n return f'bits{s}bits'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#79", + "weight": 1.0 + }, + { + "name": "NearbyDuplicates:0", + "sat": "def sat(indices: List[int], s=\"I am an unhappy string!\"):\n i, j = indices\n return s[i] == s[j] and 0 <= i < j < i + 3", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"I am an unhappy string!\"):", + "sol_docstring": " \"\"\"A string is happy if every three consecutive characters are distinct. Find two indices making s unhappy.\n Sample Input:\n \"street\"\n\n Sample Output:\n [3, 4]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(s) - 2):\n if s[i] == s[i + 1]:\n return [i, i + 1]\n if s[i] == s[i + 2]:\n return [i, i + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#80", + "weight": 1.0 + }, + { + "name": "Grader:0", + "sat": "def sat(grades: List[str], gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):\n assert len(grades) == len(gpas)\n letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n for grade, gpa in zip(grades, gpas):\n i = letters.index(grade)\n assert gpa >= scores[i]\n assert i == 0 or gpa <= scores[i - 1]\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(gpas=[2.8, 3.1, 4.0, 2.2, 3.1, 2.5, 0.9]):", + "sol_docstring": " \"\"\"\n Convert GPAs to letter grades according to the following table:\n 4.0: A+\n 3.7: A\n 3.4: A-\n 3.0: B+\n 2.7: B\n 2.4: B-\n 2.0: C+\n 1.7: C\n 1.4: C-\n below: F\n\n Sample input: [4.0, 3.5, 3.8]\n Sample output: ['A+', 'A-', 'A']\n \"\"\"", + "sol_bodies": [ + " letters = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F']\n scores = [4.0, 3.7, 3.4, 3.0, 2.7, 2.4, 2.0, 1.7, 1.4, 0.0]\n ans = []\n for gpa in gpas:\n i = 0\n while gpa < scores[i]:\n i += 1\n ans.append(letters[i])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#81", + "weight": 1.0 + }, + { + "name": "FactorString:0", + "sat": "def sat(factor: str, s=\"catscatcatscatcatscat\"):\n return len(factor) < len(s) and s == factor * (len(s) // len(factor))", + "ans_type": "str", + "sol_header": "def sol(s=\"catscatcatscatcatscat\"):", + "sol_docstring": " \"\"\"Find a string which when repeated more than once gives s\n Sample Input:\n \"haha\"\n\n Sample Output:\n \"ha\"\n \"\"\"", + "sol_bodies": [ + " n = len(s)\n return next(s[:i] for i in range(1, len(s)) if s == s[:i] * (n // i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#82", + "weight": 1.0 + }, + { + "name": "OneEnded:0", + "sat": "def sat(nums: List[int], n=5):\n count = 18 * (10 ** (n - 2)) if n > 1 else 1\n strs = {str(n) for n in nums}\n return len(strs) == count and all(s.startswith(\"1\") or s.endswith(\"1\") and len(s) == n for s in strs)", + "ans_type": "List[int]", + "sol_header": "def sol(n=5):", + "sol_docstring": " \"\"\"Find all n-digit integers that start or end with 1\n\n 1 => [1]\"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(10 ** (n - 1), 10 ** n):\n assert len(str(i)) == n\n if str(i).startswith(\"1\") or str(i).endswith(\"1\"):\n ans.append(i)\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#83", + "weight": 1.0 + }, + { + "name": "BitSum:0", + "sat": "def sat(n: int, b=107, s=25):\n n_str = bin(n)[2:] # n in binary\n return len(n_str) == b and sum(int(i) for i in n_str) == s", + "ans_type": "int", + "sol_header": "def sol(b=107, s=25):", + "sol_docstring": " \"\"\"Find an b-bit integer with a bit-sum of s\n\n b=3, s=2 => 5 # 5 is 101 in binary\n \"\"\"", + "sol_bodies": [ + " return int(\"1\" * s + \"0\" * (b - s), 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#84", + "weight": 1.0 + }, + { + "name": "EvenOddSum:0", + "sat": "def sat(even_odd_sum: int, nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):\n for i in nums[1::2]:\n if i % 2 == 0:\n even_odd_sum -= i\n return even_odd_sum == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[2341, 125146894, 12521, -12451293476325, 535284623934, 132974693614350]):", + "sol_docstring": " \"\"\"Find the sum of the even elements that are at odd indices\n\n [1, 2, 8, 3, 9, 4] => 6\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[1::2] if i % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#85\n\nVery similar to OddEvenSum \\#121", + "weight": 1.0 + }, + { + "name": "AntiShuffle:0", + "sat": "def sat(s: str, orig=\"Hello world!!!\"):\n for a, b in zip(s.split(' '), orig.split(' ')):\n for i in range(len(a) - 1):\n assert a[i] <= a[i + 1], \"characters must s-words be in increasing order\"\n assert len(a) == len(b) and all(a.count(c) == b.count(c) for c in b), \"must have same chars\"\n return len(s) == len(orig)", + "ans_type": "str", + "sol_header": "def sol(orig=\"Hello world!!!\"):", + "sol_docstring": " \"\"\"Create a new string by taking s, and word by word rearranging its characters in ascii order\n Sample input:\n 'maltos wow'\n\n Sample output:\n 'almost oww'\n \"\"\"", + "sol_bodies": [ + " return \" \".join(\"\".join(sorted(w)) for w in orig.split(' '))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#86", + "weight": 1.0 + }, + { + "name": "UnevenFind:0", + "sat": "def sat(indices: List[List[int]], uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):\n for i, j in indices:\n assert uneven[i][j] == target\n for i, row in enumerate(uneven):\n for j, n in enumerate(row):\n assert n != target or [i, j] in indices\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(uneven=[[1, 3, 2, 32, 17], [17, 2, 48, 17], [], [9, 35, 4], [3, 17]], target=17):", + "sol_docstring": " \"\"\"Find the indices of all occurrences of target in the uneven matrix\n Sample input:\n uneven=[[2, 3, 2], [], [9, 2]], target=2\n\n Sample output:\n [[0, 0], [0, 2], [2, 1]]\n \"\"\"", + "sol_bodies": [ + " return [[i, j] for i, row in enumerate(uneven) for j, n in enumerate(row) if n == target]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#87", + "weight": 1.0 + }, + { + "name": "UpDownSort:0", + "sat": "def sat(up_down: List[int], nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):\n assert all(up_down.count(i) == nums.count(i) for i in set(up_down + nums)), \"not a reordering\"\n increasing_sign = 1 if ((nums[0] + nums[-1]) % 2 == 1) else -1\n return all((up_down[i + 1] - up_down[i]) * increasing_sign >= 0 for i in range(len(up_down) - 1))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[17, 2, 3, 523, 18, -2, 0, 2, -1]):", + "sol_docstring": " \"\"\"Reorder nums in increasing/decreasing order based on whether the first plus last element is even/odd\n\n Sample input:\n [1, 7, 4]\n\n Sample output:\n [1, 4, 7] # because 1 + 4 is odd\n\n Sample input:\n [1, 7, 5]\n\n Sample output:\n [8, 5, 1] # because 1 + 5 is even\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=(False if (nums[0] + nums[-1]) % 2 else True))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#88", + "weight": 1.0 + }, + { + "name": "SubstitutionCypher:0", + "sat": "def sat(encrypted: str, orig=\"Hello, world!\"):\n assert len(encrypted) == len(orig)\n return all(chr(ord(a) - 2 * 2) == b for a, b in zip(encrypted, orig))", + "ans_type": "str", + "sol_header": "def sol(orig=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Apply a substitution cypher in which each character is advanced by two multiplied by two places.\n\n 'substitution cypher' => 'wyfwxmxyxmsr$g}tliv'\n \"\"\"", + "sol_bodies": [ + " return \"\".join(chr(ord(b) + 2 * 2) for b in orig)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#89", + "weight": 1.0 + }, + { + "name": "SecondSmallestUnique:0", + "sat": "def sat(n: int, nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):\n assert n in nums\n return len({i for i in nums if i <= n}) == 2", + "ans_type": "int", + "sol_header": "def sol(nums=[17, -1023589211, -293485382500, 31, -293485382500, 105762, 94328103589]):", + "sol_docstring": " \"\"\"Find the second smallest unique number in the list nums.\n\n Sample input:\n [2, 5, 2, 7, 9]\n\n Sample output:\n 5\n \"\"\"", + "sol_bodies": [ + " return sorted(set(nums))[1]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#90", + "weight": 1.0 + }, + { + "name": "FindBored:0", + "sat": "def sat(boring: List[str], text=\"This is not boring. I am boring! I am sooo tired.\"):\n sentences = text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\")\n boring_and_exciting = boring + [s for s in sentences if s.split()[:1] != [\"I\"]]\n return sorted(boring_and_exciting) == sorted(sentences)", + "ans_type": "List[str]", + "sol_header": "def sol(text=\"This is not boring. I am boring! I am sooo tired.\"):", + "sol_docstring": " \"\"\"A bored sentence starts with the word \"I\". Find all bored sentences in s. Sentence delimiters are '.!?'\n\n --- Example input ---\n 'I wrote this. You read it? I think I am so cool. In another time, I would be lame.'\n\n --- Example output ---\n ['I wrote this', ' I think I am so cool']\n\n \"\"\"", + "sol_bodies": [ + " return [s for s in text.replace(\"!\", \".\").replace(\"?\", \".\").split(\".\") if s.split()[:1] == [\"I\"]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#91", + "weight": 1.0 + }, + { + "name": "IdentifyZeroTrips:0", + "sat": "def sat(zero_sums: List[bool], trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]):\n return len(zero_sums) == len(trips) and all(z == ((a + b + c) == 0) for z, (a, b, c) in zip(zero_sums, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[1253532, -3920635, 332], [-24, 18, 6], [0, 5, -5], [1, 1, 1], [-20, 17, 4]]):", + "sol_docstring": " \"\"\"Determine which triples sum to zero\n\n --- Example input ---\n [1, 2, 4, -3, 5]\n\n --- Example output ---\n [0, 1, 3]\n \"\"\"", + "sol_bodies": [ + " return [sum(t) == 0 for t in trips]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#92", + "weight": 1.0 + }, + { + "name": "WeirdDecodeVowels:0", + "sat": "def sat(s: str, target=\"Hello, world!\"):\n subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return s.swapcase() == target.translate(subs)", + "ans_type": "str", + "sol_header": "def sol(target=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Find string s that, when case is flipped gives target where vowels are replaced by chars two later.\n --- Example input ---\n 'THIS is a TEST'\n\n --- Example output ---\n 'thks KS C tgst'\n \"\"\"", + "sol_bodies": [ + " subs = {ord(c): ord(c) + 2 for c in \"aeiouAEIOU\"}\n return target.translate(subs).swapcase()" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#93", + "weight": 1.0 + }, + { + "name": "LargestPrimeDigitSum:0", + "sat": "def sat(ans: List[int], nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]):\n i, digit_sum = ans\n n = nums[i]\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return is_prime(n) and all(m <= n for m in nums if is_prime(m)) and digit_sum == sum(int(c) for c in str(n))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[23, 17, 201, 14, 10473, 43225, 421, 423, 11, 10, 2022, 342157]):", + "sol_docstring": " \"\"\"Find the index of the largest prime in the list and the sum of its digits\n\n --- Example input ---\n [2, 4, 7, 19, 21]\n\n --- Example output ---\n [3, 10]\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n n, i = max((n, i) for i, n in enumerate(nums) if is_prime(n))\n return [i, sum(int(c) for c in str(n))]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#94", + "weight": 1.0 + }, + { + "name": "OddCase:0", + "sat": "def sat(different: str, d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}):\n return different in d and all(k.islower() != different.islower() for k in d if k != different)", + "ans_type": "str", + "sol_header": "def sol(d={'cat': 'CAT', 'tree': 'T', 'pick me': 'not', 'OK': 'red', 'blah': 'blah', 'z': 'Z'}):", + "sol_docstring": " \"\"\"Find the dictionary key whose case is different than all other keys\n\n --- Example input ---\n {\"red\": \"\", \"GREEN\": \"\", \"blue\": \"orange\"}\n\n --- Example output ---\n \"GREEN\"\n \"\"\"", + "sol_bodies": [ + " for different in d:\n if all(k.islower() != different.islower() for k in d if k != different):\n return different" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#95", + "weight": 1.0 + }, + { + "name": "PrimesUpTo:0", + "sat": "def sat(primes: List[int], n=1234):\n assert all(1 < p for p in primes) and all(p % q for p in primes for q in primes if q < p)\n return len({i for p in primes for i in range(p, n, p)}) == max(n - 2, 0)", + "ans_type": "List[int]", + "sol_header": "def sol(n=1234):", + "sol_docstring": " \"\"\"Find all primes up to n\n\n --- Example input ---\n 9\n\n --- Example output ---\n [2, 3, 5, 7]\n \"\"\"", + "sol_bodies": [ + " primes = []\n candidates = set(range(2, n))\n for i in range(2, n):\n if i in candidates:\n primes.append(i)\n candidates.difference_update(range(i, n, i))\n return primes" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#96", + "weight": 1.0 + }, + { + "name": "UnitsProduct:0", + "sat": "def sat(prod: int, nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]):\n if not all(nums):\n return prod == 0\n for n in nums:\n k = abs(n % 10)\n if k == 0:\n return prod == 0\n assert prod % k == 0\n prod //= k\n return prod == 1", + "ans_type": "int", + "sol_header": "def sol(nums=[17, 24, 39, 15, 11, 201, 97, 65, 18]):", + "sol_docstring": " \"\"\"Find the product of the units digits in the numbers\n\n [12, 34] => 8\n \"\"\"", + "sol_bodies": [ + " prod = 1\n for n in nums:\n prod *= abs(n % 10)\n return prod" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#97", + "weight": 1.0 + }, + { + "name": "UppercaseEven:0", + "sat": "def sat(positions: List[int], s=\"ThIs is A tEsT, Or *IS* iT?\"):\n assert all(s[i] in \"AEIOU\" for i in positions)\n return all(i in positions or c not in \"AEIOU\" or i % 2 == 1 for i, c in enumerate(s))", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"ThIs is A tEsT, Or *IS* iT?\"):", + "sol_docstring": " \"\"\"Find the positions of all uppercase vowels (not counting Y) in even indices\n\n \"EAT here NOW\" => [0, 10]\n \"\"\"", + "sol_bodies": [ + " return [i for i, c in enumerate(s) if i % 2 == 0 and c in \"AEIOU\"]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#98", + "weight": 1.0 + }, + { + "name": "ClosestInteger:0", + "sat": "def sat(n: int, x=329437923.5):\n return abs(n - x) <= 0.5", + "ans_type": "int", + "sol_header": "def sol(x=329437923.5):", + "sol_docstring": " \"\"\"Round to nearest integer\n\n --- input ---\n 3.7\n\n --- output ---\n 4\n \"\"\"", + "sol_bodies": [ + " return round(x)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#99\n\nSince we can tolerate more than one answer per puzzle, we do not need to specify a tie-breaking rule.", + "weight": 1.0 + }, + { + "name": "StonePiles:0", + "sat": "def sat(li: List[int], n=909):\n return li[0] == n and len(li) == n and all(b - a == 2 for a, b in zip(li, li[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=909):", + "sol_docstring": " \"\"\"We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even\n number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones\n than the previous pile but as few as possible. Return the number of stones in each pile.\n\n 2 => [2, 4]\n \"\"\"", + "sol_bodies": [ + " return [n + 2 * i for i in range(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#100", + "weight": 1.0 + }, + { + "name": "CompleteSplit:0", + "sat": "def sat(splits: List[List[str]], string=\"Hello, world! You look like you're on turtles.\"):\n words, separators = splits\n assert len(words) == len(separators) + 1\n merged = []\n for w, s in zip(words, separators + [\" \"]):\n assert s.count(\" \") + s.count(\",\") == len(s) > 0\n assert w.count(\" \") + w.count(\",\") == 0\n merged += [w, s]\n return \"\".join(merged[:-1]) == string", + "ans_type": "List[List[str]]", + "sol_header": "def sol(string=\"Hello, world! You look like you're on turtles.\"):", + "sol_docstring": " \"\"\"\n Split a string of words separated by commas and spaces into 2 lists: words and separators\n\n Sample input: \"Hi there, Anna\"\n Sample output: [[\"Hi\", \"there\", \"Anna\"], [\" \", \", \"]]\n \"\"\"", + "sol_bodies": [ + " import re\n merged = re.split(r\"([ ,]+)\", string)\n return [merged[::2], merged[1::2]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#101", + "weight": 1.0 + }, + { + "name": "BiggestEven:0", + "sat": "def sat(x: int, a=145, b=24126846790974):\n if x == -1:\n return all(i % 2 == 1 for i in range(a, b + 1))\n return a <= x <= b and all(i % 2 == 1 for i in range(x + 1, b + 1))", + "ans_type": "int", + "sol_header": "def sol(a=145, b=24126846790974):", + "sol_docstring": " \"\"\"Return the biggest even number between a and b inclusive, or -1 if there is no such number\n\n Example input:\n a=20, b=99\n\n Example output:\n 98\n \"\"\"", + "sol_bodies": [ + " if a > b or (a == b and a % 2 == 1):\n return -1\n return b if b % 2 == 0 else b - 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#102", + "weight": 1.0 + }, + { + "name": "BinaryAverage:0", + "sat": "def sat(s: str, a=-103252, b=10657):\n n = int(s, 2)\n r = range(a, b)\n if len(r) == 0:\n return n == -1\n mu = sum(r) / len(r)\n return abs(mu - n) <= min(abs(mu - n - 1), abs(mu - n + 1))", + "ans_type": "str", + "sol_header": "def sol(a=-103252, b=10657):", + "sol_docstring": " \"\"\"Return the average of the numbers a through b rounded to nearest integer, in binary\n (or -1 if there are no such numbers)\n\n a=4, b=7 => '110' because the mean of 4, 5, 6 is 5 which is 110 in binary\n \"\"\"", + "sol_bodies": [ + " r = range(a, b)\n if len(r) == 0:\n return \"-1\"\n return bin(round(sum(r) / len(r)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#103", + "weight": 1.0 + }, + { + "name": "SortedOdds:0", + "sat": "def sat(sub: List[int], nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]):\n for i in range(len(sub)):\n n = sub[i]\n assert n == min(sub[i:])\n assert all(int(c) % 2 for c in str(abs(n))) # all odd digits\n assert sub.count(n) == nums.count(n)\n\n for n in nums:\n if n not in sub:\n assert any(int(c) % 2 == 0 for c in str(abs(n)))\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[17, 20, -100, 101, 423258, 19949, 0, 20174, 9351773, -11]):", + "sol_docstring": " \"\"\"Find the sublist of numbers with only odd digits in increasing order\n\n [17, 21, 18, 1, 4] => [1, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(n for n in nums if all(int(c) % 2 for c in str(abs(n))))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#104", + "weight": 1.0 + }, + { + "name": "BackwardsDigits:0", + "sat": "def sat(backwards_digits: List[str], nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]):\n digits = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4, \"five\": 5, \"six\": 6, \"seven\": 7, \"eight\": 8, \"nine\": 9}\n li = [digits[s] for s in backwards_digits]\n for i, n in enumerate(li):\n assert n == max(li[i: i + 2])\n assert nums.count(n) == li.count(n)\n\n return all(n not in range(1, 10) or n in li for n in nums)", + "ans_type": "List[str]", + "sol_header": "def sol(nums=[0, 2, 14, -2, 3, 8, 4, 5, 5, 7, 21, 101, 41, 2, 9, 6]):", + "sol_docstring": " \"\"\"Return the single digits in nums sorted backwards and converted to English words\n\n [2, 3, 4, 5, 17] => ['five', 'four', 'three', 'two']\n \"\"\"", + "sol_bodies": [ + " digits = {1: \"one\", 2: \"two\", 3: \"three\", 4: \"four\", 5: \"five\", 6: \"six\", 7: \"seven\", 8: \"eight\", 9: \"nine\"}\n return [digits[n] for n in sorted(nums, reverse=True) if n in digits]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#105", + "weight": 1.0 + }, + { + "name": "AlternatingFactorials:0", + "sat": "def sat(li: List[int], n=100):\n assert len(li) == n\n for i, m in enumerate(li):\n if i < 2:\n assert m == i + 1\n elif i % 2 == 1:\n assert m == li[i - 2] + i + (i + 1)\n else:\n assert m == li[i - 2] * i * (i + 1)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(n=100):", + "sol_docstring": " \"\"\"Output a list of n integers, where the mth entry is m! if m is even or else (1+2+...+m)\n\n 5 => [1, 2, 6, 9, 120]\n \"\"\"", + "sol_bodies": [ + " ans = []\n for i in range(n):\n if i < 2:\n m = i + 1\n elif i % 2 == 1:\n m = ans[i - 2] + i + (i + 1)\n else:\n m = ans[i - 2] * i * (i + 1)\n ans.append(m)\n\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#106", + "weight": 1.0 + }, + { + "name": "EvenPalindromeNumbers:0", + "sat": "def sat(pals: List[int], n=1099, count=49):\n return all(0 <= i <= n and str(i) == str(i)[::-1] and i % 2 == 0 for i in pals) and len(set(pals)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(n=1099, count=49):", + "sol_docstring": " \"\"\"Find all even palindromes up to n\n\n 3 => [0, 2]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(0, n + 1, 2) if str(i) == str(i)[::-1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#107", + "weight": 1.0 + }, + { + "name": "PositiveDigitSums:0", + "sat": "def sat(pos: List[int], nums=[-804, 9124, -945, 2410, 0, 21, -123]):\n for n in pos + nums:\n s = str(n)\n if int(s[:2]) + sum(int(c) for c in s[2:]) <= 0:\n assert n not in pos\n else:\n assert pos.count(n) == nums.count(n)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-804, 9124, -945, 2410, 0, 21, -123]):", + "sol_docstring": " \"\"\"Filter for the numbers in nums whose sum of digits is > 0, where the first digit can be negative.\n\n [12, -7, -102, -100] => [12, -102]\n \"\"\"", + "sol_bodies": [ + " def bad(n):\n s = str(n)\n return int(s[:2]) + sum(int(c) for c in s[2:]) <= 0\n\n return [n for n in nums if not bad(n)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#108", + "weight": 1.0 + }, + { + "name": "RotateSort:0", + "sat": "def sat(original: List[int], arr=[2, 3, -1, -1, 0, 1, 1]):\n assert str(original)[1:-1] in str(sorted(original) * 2), \"Not ring sorted\"\n return any(original == arr[:i] + arr[i + 1:] for i in range(len(arr) + 1))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[2, 3, -1, -1, 0, 1, 1]):", + "sol_docstring": " \"\"\"\n An array is ring-sorted if it is a \"rotation\" of a non-decreasing list.\n Remove at most one element from arr to make it ring-sorted.\n\n [1, 2, 3, -1, 6, 0] => [1, 2, 3, -1, 0]\n \"\"\"", + "sol_bodies": [ + " def sat(near):\n order_violations = 0\n erasures = 0\n for i, n in enumerate(near):\n if n < near[i - 1]: # -1 when i =0 gives last element\n order_violations += 1\n while n != arr[i + erasures]:\n erasures += 1\n return order_violations <= 1 and erasures <= 1\n\n candidates = [arr] + [arr[:i] + arr[i + 1:] for i in range(len(arr))]\n return next(near for near in candidates if sat(near))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#109\n\nThis puzzle (and RotateString from #154) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "ParityExchange:0", + "sat": "def sat(swaps: List[List[int]], nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]):\n copy1 = nums1[:]\n copy2 = nums2[:]\n for i, j in swaps:\n copy1[i], copy2[j] = copy2[j], copy1[i]\n return all(n % 2 == 0 for n in copy1)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(nums1=[1, 3, 2, 4, 5, 8, 7, 11], nums2=[0, 7, 0, 8, 19, 4, 41, 43, 42]):", + "sol_docstring": " \"\"\"\n Find a sequence of swaps (indices into two lists) such that, after making those swaps, all numbers in the\n first list are even\n\n [1, 3, 4] [2, 4, 5] => [0, 1]\n \"\"\"", + "sol_bodies": [ + " odds = [i for i, n in enumerate(nums1) if n % 2 == 1]\n evens = [i for i, n in enumerate(nums2) if n % 2 == 0]\n return [[i, j] for i, j in zip(odds, evens)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#110", + "weight": 1.0 + }, + { + "name": "CharCounts:0", + "sat": "def sat(s: str, counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}):\n chars = s.split()\n for c in chars:\n assert chars.count(c) == counts[c]\n return len(chars) == sum(counts.values())", + "ans_type": "str", + "sol_header": "def sol(counts={'a': 4, 'b': 17, 'd': 101, 'e': 0, 'f': 12}):", + "sol_docstring": " \"\"\"Find a string consisting of space-separated characters with given counts\n\n {\"f\": 1, \"o\": 2} => \"oof\"\n \"\"\"", + "sol_bodies": [ + " return \" \".join(c for c, i in counts.items() for _ in range(i))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#111", + "weight": 1.0 + }, + { + "name": "DelPalindrome:0", + "sat": "def sat(strings: List[str], a=\"this is a test\", b=\"cat\"):\n s, is_palindrome = strings\n i = 0\n for c in a:\n if c not in b:\n assert s[i] == c\n i += 1\n assert i == len(s)\n return is_palindrome == str(s == s[::-1])", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"this is a test\", b=\"cat\"):", + "sol_docstring": " \"\"\"\n Return a pair of a strings where the first string is the same as a with all the characters of b removed,\n and the second string is 'True' if this string is a palindrome otherwise 'False'.\n\n a=\"madam, I'm adam.\" b = \"Yes, we're here.\" => ['madamImadam', 'True']\n \"\"\"", + "sol_bodies": [ + " s = \"\".join(c for c in a if c not in b)\n return [s, str(s == s[::-1])]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#112", + "weight": 1.0 + }, + { + "name": "ReplaceMe:0", + "sat": "def sat(answers: List[str], lst=['234515', '21503', '2506236943']):\n if len(answers) != len(lst):\n return False\n for a, s in zip(answers, lst):\n if \"t\" in a:\n return False\n num_odds = sum(int(i) % 2 for i in s)\n if a.replace(str(num_odds), \"t\") != \"this is a test\":\n return False\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(lst=['234515', '21503', '2506236943']):", + "sol_docstring": " \"\"\"For each string in lst, count the number of odd digits. Find a string with no t's such that replacing\n this number by t gives the string 'this is a test'\n\n [\"123\", \"2\"] => [\"2his is a 2es2\", \"0his a 0es0\"]\n \"\"\"", + "sol_bodies": [ + " return [\"this is a test\".replace(\"t\", str(sum(c in \"13579\" for c in s))) for s in lst]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#113", + "weight": 1.0 + }, + { + "name": "MinSubArraySum:0", + "sat": "def sat(start_end: List[int], base=7, p=50741, upper=-4897754):\n start, end = start_end\n return sum(pow(base, i, p) - p // 2 for i in range(start, end)) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(base=7, p=50741, upper=-4897754):", + "sol_docstring": " \"\"\"Find the start and end of the smallest-sum subarray of [(base^i mod p) - p/2 for i=start,..., end]\n\n base=3, p=7, upper =-3 => [0, 3]\n # because -3 is the sum of the elements [0:3] of [-2, 0, -1, 3, 1, 2, -2, 0, -1, 3 ...\n \"\"\"", + "sol_bodies": [ + " tot = 0\n best_tot = 0\n best_end = 0\n best_start = 0\n largest_cumulative_sum = 0\n largest_cumulative_sum_index = 0\n\n n = 1\n\n for i in range(p + 1):\n if tot > largest_cumulative_sum:\n largest_cumulative_sum = tot\n largest_cumulative_sum_index = i\n if tot - largest_cumulative_sum < best_tot:\n best_tot = tot - largest_cumulative_sum\n best_start = largest_cumulative_sum_index\n best_end = i\n\n tot += (n - p // 2)\n n = (n * base) % p\n\n return [best_start, best_end]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#114\n\nThis is harder than \\#1114. The arrays here are chosen to be long enough that the brute-force n^2 algorithm takes\nwhile the O(n) algorithm takes milliseconds.", + "weight": 1.0 + }, + { + "name": "Buckets:0", + "sat": "def sat(wells: List[List[List[int]]], grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2):\n grid2 = [[0 for _ in row] for row in grid]\n for group in wells:\n assert len(group) <= capacity\n for i, j in group:\n assert grid2[i][j] == 0\n grid2[i][j] = 1\n assert sum(len(group) != capacity for group in wells) <= 1 # at most one under-capacity group\n return grid2 == grid", + "ans_type": "List[List[List[int]]]", + "sol_header": "def sol(grid=[[1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]], capacity=2):", + "sol_docstring": " \"\"\"Given a grid, partition the 1's into groups of capacity [x, y] pairs, with at most one incomplete group\"\"\"", + "sol_bodies": [ + " ans = []\n for i, row in enumerate(grid):\n for j, val in enumerate(row):\n if val == 1:\n if not ans or len(ans[-1]) == capacity:\n ans.append([])\n ans[-1].append([i, j])\n return ans" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#115", + "weight": 1.0 + }, + { + "name": "BinarySort:0", + "sat": "def sat(ordered: List[int], arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]):\n if sorted(ordered) != sorted(arr):\n return False # not even a permutation\n return all(bin(a).count(\"1\") <= bin(b).count(\"1\") for a, b in zip(ordered, ordered[1:]))", + "ans_type": "List[int]", + "sol_header": "def sol(arr=[4, 2, 3, -1, 15, 2, 6, 9, 5, 16, 1048576]):", + "sol_docstring": " \"\"\"Sort the numbers in arr based on the number of 1's in their binary representation.\n\n [1, 2, 3, 4, 6] => [1, 2, 4, 3, 6]\n \"\"\"", + "sol_bodies": [ + " return sorted(arr, key=lambda n: bin(n).count(\"1\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#116", + "weight": 1.0 + }, + { + "name": "ConsonantFilter:0", + "sat": "def sat(words: List[str], s=\"This is not a very hard puzzle\", n=3):\n i = 0\n for w in s.split():\n num_consonants = 0\n for c in w.lower():\n if c not in \"aeiou\":\n num_consonants += 1\n if num_consonants == n:\n if words[i] != w:\n return False\n i += 1\n return i == len(words)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"This is not a very hard puzzle\", n=3):", + "sol_docstring": " \"\"\"Find all words in the string with n consonants\n\n Sample input:\n s=\"An eye for an I\", n=1\n Sample output:\n [\"An\", \"eye\", \"an\"]\n \"\"\"", + "sol_bodies": [ + " return [w for w in s.split() if sum(c.lower() not in \"aeiou\" for c in w) == n]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#117", + "weight": 1.0 + }, + { + "name": "VowelSandwich:0", + "sat": "def sat(ham: str, s=\"Any vowel is OK\"):\n vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return ham in s and ham[0].lower() in cons and ham[1].lower() in vows and ham[2].lower() in cons", + "ans_type": "str", + "sol_header": "def sol(s=\"Any vowel is OK\"):", + "sol_docstring": " \"\"\"Find any vowel sandwich, a string consisting of a vowel between two consonants, contained in s\n\n \"sandwhich\" => \"hic\"\n \"\"\"", + "sol_bodies": [ + " vows = \"aeiou\"\n cons = \"bcdfghjklmnpqrstvwxz\"\n return next(s[i - 1:i + 2] for i in range(1, len(s) - 1)\n if s[i].lower() in vows and s[i - 1].lower() in cons and s[i + 1].lower() in cons)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#118", + "weight": 1.0 + }, + { + "name": "ParenthesesPermutation:0", + "sat": "def sat(perm: str, s=\"))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( ((((((((((\"):\n assert sorted(perm.split()) == sorted(s.split()), \"Must be a permutation of the space-delimited 'groups'\"\n return all(perm[:i].count(\"(\") >= perm[:i].count(\")\") for i in range(len(perm)))", + "ans_type": "str", + "sol_header": "def sol(s=\"))( )()()() )))(( ))))((( )))))(((( ))))))))((((((( ))))))((((( )))))))(((((( )))))))))((((((( ((((((((((\"):", + "sol_docstring": " \"\"\"The string s consists of groups of parentheses separated by spaces.\n Permute the groups such that the parentheses match.\n\n \"( ) )(\" => \"( )( )\"\n \"\"\"", + "sol_bodies": [ + " assert all(c in \"( )\" for c in s)\n parts = s.split()\n\n def min_depth(part):\n \"\"\"Returns the lowest depth <= 0\"\"\"\n ans = 0\n depth = 0\n for c in part:\n if c == \")\":\n depth -= 1\n ans = min(ans, depth)\n else:\n depth += 1\n return ans\n\n def greedy_reorder(subs):\n \"\"\"Reorder a bunch of parentheses substrings so as to maintain # ('s > # )'s \"\"\"\n queue = subs[:]\n subs[:] = []\n height = 0\n while queue:\n best = max([s for s in queue if min_depth(s) + height >= 0], key=lambda s: s.count(\"(\") - s.count(\")\"))\n height += best.count(\"(\") - best.count(\")\")\n subs.append(best)\n queue.remove(best)\n\n lefts = [s for s in parts if s.count(\"(\") >= s.count(\")\")]\n\n greedy_reorder(lefts)\n\n def mirror(sub):\n return \"\".join(\")\" if c == \"(\" else \"(\" for c in sub[::-1])\n\n rights = [mirror(s) for s in parts if s.count(\"(\") < s.count(\")\")] # mirror temporarily for reordering\n\n greedy_reorder(rights)\n return \" \".join(lefts + [mirror(s) for s in rights[::-1]])" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#119\n \nThis is harder version in which you need to find a permutation of many substrings. Brute force is too slow.", + "weight": 1.0 + }, + { + "name": "BiggestK:0", + "sat": "def sat(biggest: List[int], k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]):\n if len(biggest) != k:\n return False\n smallest = nums[:]\n for n in biggest:\n smallest.remove(n)\n return k == 0 or k == len(nums) or max(smallest) <= min(biggest)", + "ans_type": "List[int]", + "sol_header": "def sol(k=7, nums=[31, 1, 2, -10, -2, 4, 17, 18, 20, 14, 20, 21, 18, 0]):", + "sol_docstring": " \"\"\"Find the largest k numbers\n\n k=2, [1, 2, 3, 4, 5, 5, 3, 5, 2] => [5, 5]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, reverse=True)[:k]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#120", + "weight": 1.0 + }, + { + "name": "OddEvenSum:0", + "sat": "def sat(tot: int, nums=[18, 42152, 125023521, -1221873620123, 17, 19]):\n for i in nums[::2]:\n if i % 2 == 1:\n tot -= i\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(nums=[18, 42152, 125023521, -1221873620123, 17, 19]):", + "sol_docstring": " \"\"\"Find the sum of the odd elements that are at even indices\n\n [0, 1, 2, 3, 5, 6] => 5\n \"\"\"", + "sol_bodies": [ + " return sum(i for i in nums[::2] if i % 2 == 1)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#121\n\nVery similar to EvenOddSum from \\#85", + "weight": 1.0 + }, + { + "name": "LongEarlySum:0", + "sat": "def sat(tot: int, k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]):\n for n in nums[:k]:\n if len(str(abs(n))) > 2:\n tot -= n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(k=5, nums=[1252, 125273523, 0, 42, 100, 214532, 2, 0, 11, 14]):", + "sol_docstring": " \"\"\"Find the sum of the numbers among the first k with more than 2 digits\n\n k=3, nums=[2, 102, 12, 1000] => 102\n \"\"\"", + "sol_bodies": [ + " return sum(n for n in nums[:k] if len(str(abs(n))) > 2)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#122\n \nChanged slightly to make the answer not be a small integer.", + "weight": 1.0 + }, + { + "name": "OddCollatz:0", + "sat": "def sat(odds: List[int], n=1243272912731):\n num_odds = 0\n while True:\n if n % 2 == 1:\n num_odds += 1\n if n not in odds:\n return False\n if n <= 1:\n return num_odds == len(odds)\n n = (3 * n + 1) if n % 2 == 1 else n // 2", + "ans_type": "List[int]", + "sol_header": "def sol(n=1243272912731):", + "sol_docstring": " \"\"\"Find the odd numbers in the collatz sequence starting at n\n\n 3 => [3, 5, 1] # because the Collatz sequence starting with 3 is [3, 10, 5, 16, 8, 4, 2, 1]\n \"\"\"", + "sol_bodies": [ + " ans = []\n while True:\n if n % 2 == 1:\n ans.append(n)\n if n <= 1:\n return ans\n n = (3 * n + 1) if n % 2 == 1 else n // 2" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#123", + "weight": 1.0 + }, + { + "name": "DateDiff:0", + "sat": "def sat(s: str, target=-2075):\n assert all(c in \"0123457689-\" for c in s) and s[2] == s[5] == \"-\"\n m, d, y = [int(n) for n in s.split(\"-\")]\n assert m in range(1, 13)\n assert d in range(1, 32)\n if m in [4, 6, 9, 11]:\n assert d <= 30\n if m == 2:\n assert d <= 29\n return m - d - y == target", + "ans_type": "str", + "sol_header": "def sol(target=-2075):", + "sol_docstring": " \"\"\"Find a valid date mm-dd-yyyy such that the date, viewed as a mathematical expression, evaluates to target\n\n -2029 => \"10-18-2021\" # because 10-18-2021 == -2029\n \"\"\"", + "sol_bodies": [ + " if target >= -30:\n return \"12-01-\" + str(11 - target).zfill(4)\n return \"01-31-\" + str(-30 - target).zfill(4)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#124", + "weight": 1.0 + }, + { + "name": "StrangeSplit:0", + "sat": "def sat(lst: List[str], s=\"Hello, world!\"):\n if \" \" in s:\n return \" \".join(lst) == s\n if \",\" in s:\n return \",\".join(lst) == s\n return \"\".join(lst) == \"\".join(c for c in s if c.islower() and ord(c) % 2 == 0)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"Hello, world!\"):", + "sol_docstring": " \"\"\"Split s into strings if there is a space in s, otherwise split on commas if there is a comma, otherwise\n return the list of lowercase letters with odd order (order of a = 0, b = 1, etc.)\n\n \"a b c\" => [\"a\", \"b\", \"c\"]\n \"a,b\" => [\"a\", \"b\"]\n \"\"\"", + "sol_bodies": [ + " if \" \" in s:\n return s.split(\" \")\n if \",\" in s:\n return s.split(\",\")\n return [c for c in s if c.islower() and ord(c) % 2 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#125", + "weight": 1.0 + }, + { + "name": "IncreasingViolation:0", + "sat": "def sat(violation: List[int], nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]):\n if not violation:\n return all(nums[i] < nums[i + 1] for i in range(len(nums) - 1))\n i, j = violation\n return 0 <= i < j and nums[i] >= nums[j]", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 17, 18, 19, 20, 22, 24]):", + "sol_docstring": " \"\"\"\n Find the indices of two entries that show that the list is not in increasing order.\n If there are no violations (they are increasing), return an empty list.\n\n [1,2,3,0,4,5,6] => [1, 3]\n \"\"\"", + "sol_bodies": [ + " for i in range(len(nums) - 1):\n if nums[i] >= nums[i + 1]:\n return [i, i + 1]\n return []" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#126", + "weight": 1.0 + }, + { + "name": "PrimeIntervalIntersection:0", + "sat": "def sat(interval2: List[int], interval1=[32157, 93210127]):\n intersection_width = min(interval1[1], interval2[1]) - max(interval1[0], interval2[0])\n return intersection_width > 1 and all(intersection_width % i for i in range(2, intersection_width))", + "ans_type": "List[int]", + "sol_header": "def sol(interval1=[32157, 93210127]):", + "sol_docstring": " \"\"\"Find an interval whose intersection with a given interval has a width that is a prime integer.\n\n [7, 100] => [0, 10] # because 10-7=3 is prime\n \"\"\"", + "sol_bodies": [ + " a, b = interval1\n assert b - a >= 2\n return [a, a + 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#127", + "weight": 1.0 + }, + { + "name": "ProductSigns:0", + "sat": "def sat(n: int, arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]):\n tot = 0\n\n for i in arr:\n if tot >= 0:\n tot += abs(i)\n else:\n tot -= abs(i)\n if i < 0:\n tot = -tot\n elif i == 0:\n tot = 0\n break\n\n return n == tot", + "ans_type": "int", + "sol_header": "def sol(arr=[1, 7, -20052, 14, -3, -11, 1025235, 14]):", + "sol_docstring": " \"\"\"Find the sum of the magnitudes of the elements in the array with a sign that is equal to the product of\n the signs of the entries.\n\n [1, -2, 3] => -6 # negative because there is one negative\n \"\"\"", + "sol_bodies": [ + " tot = sum(abs(i) for i in arr)\n if all(arr):\n return tot if sum(i < 0 for i in arr) % 2 == 0 else -tot\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#128\n \nEasy puzzle since the answer is computed in the puzzle, but it is okay to have a few trivial puzzles.", + "weight": 1.0 + }, + { + "name": "LexPath:0", + "sat": "def sat(path: List[int], k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]):\n\n def check(prefix):\n for i, j in zip(path, prefix):\n if i != j:\n return i < j\n return len(prefix) >= k or all(check(prefix + [i]) for i in edges[prefix[-1]])\n\n return all(path[i] in edges[path[i - 1]] for i in range(1, k)) and all(check([i]) for i in range(len(edges)))", + "ans_type": "List[int]", + "sol_header": "def sol(k=10, edges=[[2, 4], [3], [4, 1], [4], [0]]):", + "sol_docstring": " \"\"\"Find the lexicographically smallest path of length k in graph with given edge matrix (and no dead ends)\n\n k=3, edges=[[1,3], [0, 3], [2], [3]] => [0, 1, 0] # because 0-1 and 1-0 are edges\n \"\"\"", + "sol_bodies": [ + " path = []\n while len(path) < k:\n path.append(min(edges[path[-1]]) if path else 0)\n return path" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#129", + "weight": 1.0 + }, + { + "name": "Tribonacci:0", + "sat": "def sat(seq: List[int], length=181):\n return all(seq[n] == (seq[n - 1] + seq[n - 2] + seq[n + 1] if n % 2 else 1 + n // 2) for n in range(length))", + "ans_type": "List[int]", + "sol_header": "def sol(length=181):", + "sol_docstring": " \"\"\"Find a sequence where seq[n] == 1 + n / 2 for even n, and\n seq[n] == seq[n - 1] + seq[n - 2] + seq[n + 1] for odd n < length.\"\"\"", + "sol_bodies": [ + " seq = []\n while len(seq) <= length:\n n = len(seq)\n if n % 2 == 0:\n seq.append(1 + n // 2)\n else:\n seq.append(sum(seq[-2:]) + (1 + (n + 1) // 2))\n return seq + [0] # appending 0 at the end makes it easier so that seq[n-2] == 0 for n == 1" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#130\n\nThis puzzle is a bit harder because the definition is slightly different at seq[1].", + "weight": 1.0 + }, + { + "name": "OddProduct:0", + "sat": "def sat(prod: int, n=14235764939971075543215213):\n\n for c in str(n):\n i = int(c)\n if i % 2 == 1:\n assert prod % i == 0\n prod //= i\n return prod == any(int(c) % 2 for c in str(n))", + "ans_type": "int", + "sol_header": "def sol(n=14235764939971075543215213):", + "sol_docstring": " \"\"\"Return the product of the odd digits in n, or 0 if there aren't any\n\n 12345 => 15\n \"\"\"", + "sol_bodies": [ + " if any(int(c) % 2 for c in str(n)):\n prod = 1\n for c in str(n):\n if int(c) % 2 == 1:\n prod *= int(c)\n return prod\n return 0" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#131", + "weight": 1.0 + }, + { + "name": "ValidBracketSubsequence:0", + "sat": "def sat(valid: str, s=\"]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[[\"):\n assert valid in s\n depths = [0]\n for c in valid:\n if c == \"[\":\n depths.append(depths[-1] + 1)\n elif c == \"]\":\n depths.append(depths[-1] - 1)\n return depths[-1] == 0 and min(depths) == 0 and max(depths) > 1", + "ans_type": "str", + "sol_header": "def sol(s=\"]]]]]]]]]]]]]]]]][][][][]]]]]]]]]]][[[][[][[[[[][][][]][[[[[[[[[[[[[[[[[[\"):", + "sol_docstring": " \"\"\"Find a valid substring of s that contains matching brackets, at least one of which is nested\n\n \"]][][[]]]\" => \"[][[]]\"\n \"\"\"", + "sol_bodies": [ + " left = []\n nested = False\n for i, c in enumerate(s):\n if c == \"[\":\n if len(left) == 2:\n left = [left[1], i]\n nested = False\n else:\n left.append(i)\n elif c == \"]\":\n if not left:\n continue\n if len(left) == 1 and nested:\n return s[left[0]:i + 1]\n elif len(left) == 2:\n nested = True\n left.pop()\n assert False", + " import re\n return re.search(r\"\\[(\\[\\])+\\]\", s).group(0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#132", + "weight": 1.0 + }, + { + "name": "CeilingSquares:0", + "sat": "def sat(running_squares: List[int], x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]):\n for i, v in enumerate(x):\n ceiling = int(v) + (v > 0 and not v.is_integer())\n square = ceiling ** 2\n if running_squares[i] != square + (i > 0 and running_squares[i - 1]):\n return False\n\n return len(running_squares) == len(x)", + "ans_type": "List[int]", + "sol_header": "def sol(x=[201.1, 301.4, -18.1, 1244122.0, 10101.0101, 10000000.0]):", + "sol_docstring": " \"\"\"Round each float in x up to the next integer and return the running total of the integer squares\n\n [2.4, 3.7, 0.1] => [9, 25, 26]\n \"\"\"", + "sol_bodies": [ + " from math import ceil\n running_squares = []\n tot = 0\n for v in x:\n tot += ceil(v) ** 2\n running_squares.append(tot)\n return running_squares" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#133", + "weight": 1.0 + }, + { + "name": "LastLetters:0", + "sat": "def sat(y: List[bool], x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']):\n assert len(x) == len(y)\n for s, b in zip(x, y):\n if len(s.split(\" \")[-1]) == 1:\n assert b == s[-1].isalpha()\n else:\n assert not b\n return True", + "ans_type": "List[bool]", + "sol_header": "def sol(x=['Hello, world!', 'cat', '', 'a test', 'test a', 'i e', 'o', 'I O U', 'You and I']):", + "sol_docstring": " \"\"\"Determine, for each string in x, whether the last character is an isolated letter\n\n [\"a b c\", \"abc\"] => [True, False]\n \"\"\"", + "sol_bodies": [ + " return [len(s.split(\" \")[-1]) == 1 and s[-1].isalpha() for s in x]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#134", + "weight": 1.0 + }, + { + "name": "Drops:0", + "sat": "def sat(drop_indexes: List[int], nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]):\n d = 0\n for i in range(1, len(nums)):\n if nums[i] < nums[i - 1]:\n assert drop_indexes[d] == i\n d += 1\n return d == len(drop_indexes)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[2, -1, 14, 8, 9, 9, 8, 4, 2, 4, 3, -100, 1000, 18, 4, -2, -3, -3, 1, 0]):", + "sol_docstring": " \"\"\"Find the indices for which the nums array drops.\n\n [1,2,3,0,2,4,1] => [3,6]\n \"\"\"", + "sol_bodies": [ + " return [i for i in range(1, len(nums)) if nums[i] < nums[i - 1]]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#135", + "weight": 1.0 + }, + { + "name": "LargestNegSmallestPos:0", + "sat": "def sat(extremes: List[int], nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]):\n neg, pos = extremes\n if neg == 0:\n assert nums == [] or min(nums) >= 0\n else:\n assert neg < 0 and neg in nums and all(n >= 0 or n <= neg for n in nums)\n if pos == 0:\n assert nums == [] or max(nums) <= 0\n else:\n assert pos > 0 and pos in nums and all(n <= 0 or n >= pos for n in nums)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[-10, -4, 100, -40, 2, 2, 3, 17, -50, -25, 18, 41, 9, 11, 15]):", + "sol_docstring": " \"\"\"Find the largest negative ans smallest positive numbers (or 0 if none)\n\n [-2, -4, 14, 50] => [-2, 14]\n [3, 22] => [0, 3]\n \"\"\"", + "sol_bodies": [ + " pos = [n for n in nums if n > 0]\n neg = [n for n in nums if n < 0]\n return [max(neg) if neg else 0, min(pos) if pos else 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#136", + "weight": 1.0 + }, + { + "name": "LargestStringNum:0", + "sat": "def sat(x: float, str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']):\n found = False\n for s in str_nums:\n y = float(s.replace(\",\", \".\"))\n assert y <= x\n if y == x:\n found = True\n return found", + "ans_type": "float", + "sol_header": "def sol(str_nums=['1,3', '-11', '17.5', '-11', '2', '2.2', '2,2', '4', '-18,18', '99.09']):", + "sol_docstring": " \"\"\"Find the largest number where commas or periods are decimal points\n\n [\"99,9\", \"100\"] => 100.0\n \"\"\"", + "sol_bodies": [ + " return max(float(s.replace(\",\", \".\")) for s in str_nums)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#137", + "weight": 1.0 + }, + { + "name": "Even4Sum:0", + "sat": "def sat(summands: List[int], n=1234567890):\n return sum(summands) == n and min(summands) > 0 and len(summands) == 4 and all(s % 2 == 0 for s in summands)", + "ans_type": "List[int]", + "sol_header": "def sol(n=1234567890):", + "sol_docstring": " \"\"\"Find four positive even integers whose sum is n\n\n 100 => [22, 24, 26, 28]\"\"\"", + "sol_bodies": [ + " return [2] * 3 + [n - 6]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#138", + "weight": 1.0 + }, + { + "name": "InverseSuperFactorial:0", + "sat": "def sat(nums: List[int], super_factorials=[1, 2, 1]):\n for i, sf in enumerate(super_factorials):\n n = nums[i]\n for j in range(n, 0, -1):\n k = j ** (n - j + 1)\n assert sf % k == 0, f\"{i} {sf} {j} {n}\"\n sf //= k\n assert sf == 1\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(super_factorials=[1, 2, 1]):", + "sol_docstring": " \"\"\"The super-factorial of n is n! (n-1)! (n-2)! ... 1!. Invert a given list of super-factorials.\n\n [1, 2, 2, 12] => [1, 2, 2, 3]\n \"\"\"", + "sol_bodies": [ + " queue = set(super_factorials)\n cache = {}\n n = 1\n fact = 1\n s_fact = 1\n while queue:\n fact *= n\n s_fact *= fact\n if s_fact in queue:\n queue.remove(s_fact)\n cache[s_fact] = n\n n += 1\n return [cache[sf] for sf in super_factorials]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#139", + "weight": 1.0 + }, + { + "name": "ExpandSpaces:0", + "sat": "def sat(orig: str, target=\"-Hello,_world!__This_is-so-easy!-\"):\n assert \"_\" not in orig and \"-\" not in orig\n new = \"\"\n space_count = 0\n for c in orig:\n if c == \" \":\n space_count += 1\n else:\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n new += c\n space_count = 0\n new += (\"-\" if space_count > 2 else \"_\" * space_count)\n return new == target", + "ans_type": "str", + "sol_header": "def sol(target=\"-Hello,_world!__This_is-so-easy!-\"):", + "sol_docstring": " \"\"\"Find a string such that, when three or more spaces are compacted to a '-' and one or two spaces are\n replaced by underscores, leads to the target.\n\n \"_o-k__?-\" => \" o k ? \"\n \"\"\"", + "sol_bodies": [ + " return target.replace(\"-\", \" \" * 3).replace(\"_\", \" \")" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#140", + "weight": 1.0 + }, + { + "name": "FilenameOK:0", + "sat": "def sat(valids: List[str], filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']):\n assert len(valids) == len(filenames)\n for v, f in zip(valids, filenames):\n n_digits = sum(c.isdigit() for c in f)\n if v == \"Yes\":\n prefix, ext = f.split(\".\")\n assert ext in [\"txt\", \"dll\", \"exe\"] and prefix[0].isalpha() and n_digits < 4\n else:\n assert v == \"No\"\n assert f.split(\".\")[1:] not in [['txt'], ['dll'], ['exe']] or not f[0].isalpha() or n_digits > 3\n return True", + "ans_type": "List[str]", + "sol_header": "def sol(filenames=['cat.txt', '!jog.dll', '31F9.html', 'Is this okay?.txt', '.exe', '']):", + "sol_docstring": " \"\"\"Return a list of Yes/No strings that determine whether candidate filename is valid. A valid filename\n should end in .txt, .exe, or .dll, and should have at most three digits, no additional periods\n\n [\"train.jpg\", \"doc10234.txt\", \"3eadme.txt\"] = [\"No\", \"No\", \"Yes\"]\n \"\"\"", + "sol_bodies": [ + " return [\"Yes\" if\n f.split(\".\")[1:] in [['txt'], ['dll'], ['exe']] and f[0].isalpha() and sum(c.isdigit() for c in f) < 4\n else \"No\"\n for f in filenames]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#141", + "weight": 1.0 + }, + { + "name": "FindStrangeSum:0", + "sat": "def sat(lst: List[int], tot=1125181293221):\n return sum(n ** 2 if n % 3 == 0 else n ** 3 if n % 4 == 0 else n for n in lst) == tot", + "ans_type": "List[int]", + "sol_header": "def sol(tot=1125181293221):", + "sol_docstring": " \"\"\"Find a list of integers such that tot is the sum of (n^2 if 3 | n, else n^3 if 4 | n, else n)\"\"\"", + "sol_bodies": [ + " residue = (tot - 1) % 12\n return [1] * residue + [tot - residue]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#142", + "weight": 1.0 + }, + { + "name": "PrimeWords:0", + "sat": "def sat(primes: str, s=\"This is a test of whether you would want to do such strange puzzles\"):\n\n def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n prime_words = primes.split()\n i = 0\n for word in s.split():\n if is_prime(len(word)):\n assert prime_words[i] == word\n i += 1\n\n return i == len(prime_words)", + "ans_type": "str", + "sol_header": "def sol(s=\"This is a test of whether you would want to do such strange puzzles\"):", + "sol_docstring": " \"\"\"Find the string consisting of all the words whose lengths are prime numbers\n\n \"A bird in the hand is worth two in the bush\" => \"in the is worth two in the\"\n \"\"\"", + "sol_bodies": [ + " def is_prime(n):\n return n > 1 and all(n % j for j in range(2, int(n ** 0.5) + 1))\n\n return \" \".join(w for w in s.split() if is_prime(len(w)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#143", + "weight": 1.0 + }, + { + "name": "SimplifyProductFraction:0", + "sat": "def sat(z: str, x=\"-8142432/763083\", y=\"66/-13474\", max_len=18):\n [[a, b], [c, d], [u, v]] = [[int(n) for n in s.split(\"/\")] for s in [x, y, z]]\n return a * c * v == b * d * u and len(z) <= max_len", + "ans_type": "str", + "sol_header": "def sol(x=\"-8142432/763083\", y=\"66/-13474\", max_len=18):", + "sol_docstring": " \"\"\"Write x * y as the shortest equivalent fraction using at most max_len chars\n\n x=\"-2/3\", y=\"-3/8\", max_len=3 => \"1/4\"\n \"\"\"", + "sol_bodies": [ + " [[a, b], [c, d]] = [[int(n) for n in s.split(\"/\")] for s in [x, y]]\n num, den = a * c, b * d\n if num < 0 and den < 0:\n num, den = -num, -den\n if num == 0:\n return \"0/1\"\n\n def gcd(a, b):\n a, b = min(a, b), max(a, b)\n if b % a == 0:\n return a\n return gcd(b % a, a)\n\n d = gcd(abs(num), abs(den))\n return f'{num // d}/{den // d}'" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#144", + "weight": 1.0 + }, + { + "name": "SortByDigitSum:0", + "sat": "def sat(ordered: List[int], nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]):\n digit_sums = [sum(int(c) for c in str(n) if c != \"-\") for n in ordered]\n return sorted(ordered) == sorted(nums) and digit_sums == sorted(digit_sums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[1, 0, -1, -100, 10, 14, 235251, 11, 10000, 2000001, -155]):", + "sol_docstring": " \"\"\"Sort the numbers by the sum of their digits\n\n [17, 21, 0] => [0, 17, 21]\n \"\"\"", + "sol_bodies": [ + " return sorted(nums, key=lambda n: sum(int(c) for c in str(n) if c != \"-\"))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#145", + "weight": 1.0 + }, + { + "name": "BigOdds:0", + "sat": "def sat(odds: List[int], nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]):\n assert all(o > 10 and odds.count(o) == nums.count(o) and int(str(o)[i]) % 2 for o in odds for i in [-1, 0])\n return all(n in odds or n <= 10 or int(str(n)[0]) % 2 == 0 or int(str(n)[-1]) % 2 == 0 for n in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[204, 109, 203, 17, 45, 11, 21, 99, 909, 16, -33, 3, 17]):", + "sol_docstring": " \"\"\"Find the numbers that are greater than 10 and have odd first and last digits\n\n [73, 4, 72] => [73]\n \"\"\"", + "sol_bodies": [ + " return [n for n in nums if n > 10 and (int(str(n)[0]) * int(str(n)[-1])) % 2]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#146", + "weight": 1.0 + }, + { + "name": "Threeples:0", + "sat": "def sat(trips: List[List[int]], a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221):\n assert len({tuple(t) for t in trips}) >= count\n return all(0 <= i < j < k and (a[i] + a[j] + a[k]) % 3 == 0 for i, j, k in trips)", + "ans_type": "List[List[int]]", + "sol_header": "def sol(a=[1, 0, -17, 42, 321, 36, 429, 35, 10, 923, 35, 18, 0, 17, 24, 32, 8], count=221):", + "sol_docstring": " \"\"\"Find all triples of increasing indices where the sum of the numbers is divisible by three\n\n a=[1, 2, 4, 8, 14, 10], count=2 => [[0, 2, 5], [1, 3, 4]] = > because 1 + 4 + 10, 2 + 8 + 14 are divisible by 3\n \"\"\"", + "sol_bodies": [ + " n = len(a)\n return [[i, j, k] for k in range(2, n) for j in range(k) for i in range(j) if (a[i] + a[j] + a[k]) % 3 == 0]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#147", + "weight": 1.0 + }, + { + "name": "PlanetRange:0", + "sat": "def sat(planets_between: List[str], a=\"Mars\", b=\"Neptune\"):\n assert \" \" not in \"\".join(planets_between)\n return \" \".join([a] + planets_between + [b]) in \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\"", + "ans_type": "List[str]", + "sol_header": "def sol(a=\"Mars\", b=\"Neptune\"):", + "sol_docstring": " \"\"\"Find all planets between the two given planets\n\n a=\"Jupiter\", b=\"Pluto\" => [\"Saturn\" \"Uranus\" \"Neptune\"]\n \"\"\"", + "sol_bodies": [ + " planets = \"Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto\".split()\n return planets[planets.index(a) + 1:planets.index(b)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#148", + "weight": 1.0 + }, + { + "name": "EvenWords:0", + "sat": "def sat(evens: List[str], words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']):\n lens = [len(w) for w in evens]\n assert all(lens[i] % 2 == 0 and lens[i] == max(lens[:i + 1]) and w in words for i, w in enumerate(evens))\n return all((len(w) % 2 == 1 or w in evens) for w in words)", + "ans_type": "List[str]", + "sol_header": "def sol(words=['The', 'worm', 'ate', 'a', 'bird', 'imagine', 'that', '!', 'Absurd', '!!']):", + "sol_docstring": " \"\"\"Find the even-length words and sort them by length.\n\n [\"soup\", \"not\", \"splendid\"] => [\"soup\", \"splendid\"]\n \"\"\"", + "sol_bodies": [ + " return sorted([w for w in words if len(w) % 2 == 0], key=lambda w: (len(w), w))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#149", + "weight": 1.0 + }, + { + "name": "PrimeSel:0", + "sat": "def sat(neighbors: List[int], nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]):\n\n def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n goods = set()\n for i, n in enumerate(nums):\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1])):\n goods.add(n)\n\n return set(neighbors) == goods and all(n == min(neighbors[i:]) for i, n in enumerate(neighbors))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[14, 7, 11, 13, 7, 4, 19, 2, 55, 13, 31, 14, 2, 9, -7, 0, 88, 13, 13]):", + "sol_docstring": " \"\"\"Find a list of all numbers that are adjacent to a prime number in the list, sorted without duplicates\n\n [2, 17, 16, 0, 6, 4, 5] => [2, 4, 16, 17]\"\"\"", + "sol_bodies": [ + " def prime(m):\n return all(m % i for i in range(2, m - 1))\n\n return sorted({\n n for i, n in enumerate(nums)\n if (i > 0 and prime(nums[i - 1])) or (i < len(nums) - 1 and prime(nums[i + 1]))\n })" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#150", + "weight": 1.0 + }, + { + "name": "EvenSqure:0", + "sat": "def sat(tot: int, xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]):\n for x in xs:\n if x.is_integer() and x > 0 and x % 2 == 0:\n tot -= int(x) ** 2\n\n return tot == 0", + "ans_type": "int", + "sol_header": "def sol(xs=[123.0, 872322.0, 542.2, -127.5, 18214.0, 3732.4, 12832.4, 23523800.0]):", + "sol_docstring": " \"\"\"Find the sum of the squares of the positive even integers\n\n [2.0, 3.0, 2.5, 4.0] => 20\n \"\"\"", + "sol_bodies": [ + " return sum(int(x) ** 2 for x in xs if x.is_integer() and x > 0 and x % 2 == 0)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#151", + "weight": 1.0 + }, + { + "name": "ArrayDiff:0", + "sat": "def sat(b: List[int], a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]):\n return len(b) == len(a) and all(i + j == k for i, j, k in zip(a, b, c))", + "ans_type": "List[int]", + "sol_header": "def sol(a=[1, 2, 3, 0, 4, 17, 2, 4, 5, 9, 8, 4], c=[1, 2, 3, 4, 0, 16, 2, 3, 5, 9, 8, 4]):", + "sol_docstring": " \"\"\"Find an array that when added to vector a gives array vector c\n\n [1, 2, 3], [4, 17, 5] => [3, 15, 2]\n \"\"\"", + "sol_bodies": [ + " return [k - i for i, k in zip(a, c)]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#152", + "weight": 1.0 + }, + { + "name": "StrongestExtension:0", + "sat": "def sat(s: str, class_name=\"TestClass\", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']):\n assert s.startswith(class_name + \".\")\n ext = s[len(class_name) + 1:]\n\n def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return ext in extensions and case_delta(ext) == max([case_delta(x) for x in extensions])", + "ans_type": "str", + "sol_header": "def sol(class_name=\"TestClass\", extensions=['extEnd', 'LOL', 'SuPeRbLy', 'v9ACLQWTEW', 'PickMe', 'AI']):", + "sol_docstring": " \"\"\"Find the class_name.extension for the extension that has the largest #capitals - #lowercase letters\"\"\"", + "sol_bodies": [ + " def case_delta(x: str):\n tot = 0\n for c in x:\n if c.isupper():\n tot += 1\n elif c.islower():\n tot -= 1\n return tot\n\n return class_name + \".\" + max(extensions, key=case_delta)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#153", + "weight": 1.0 + }, + { + "name": "RotateString:0", + "sat": "def sat(r: str, s=\"light star\", t=\"I love to look at the starlight!\"):\n return r in t and len(r) == len(s) and r in s + s", + "ans_type": "str", + "sol_header": "def sol(s=\"light star\", t=\"I love to look at the starlight!\"):", + "sol_docstring": " \"\"\"Find a rotation of string s that is a substring of t\n\n Input Example:\n s=\"test\", t=\"I love lattes\"\n\n Output Example:\n \"ttes\"\n \"\"\"", + "sol_bodies": [ + " return next(s[i:] + s[:i] for i in range(len(s)) if s[i:] + s[:i] in t)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#154\n\nThis puzzle (and RotateSort from #109) use the fact that a string is a rotation of r if it is a substring of r+r", + "weight": 1.0 + }, + { + "name": "EvenOddDigits:0", + "sat": "def sat(n: int, evens=17, odds=3):\n for c in str(n):\n if int(c) % 2 == 0:\n evens -= 1\n else:\n odds -= 1\n return evens == 0 and odds == 0", + "ans_type": "int", + "sol_header": "def sol(evens=17, odds=3):", + "sol_docstring": " \"\"\"Find an integer n >= 0 with the given number of even and odd digits.\n\n evens=3, odds=4 => 2381695\"\"\"", + "sol_bodies": [ + " return int(\"2\" * evens + \"1\" * odds)" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#155", + "weight": 1.0 + }, + { + "name": "RomanNumerals:0", + "sat": "def sat(roman: str, n=2414):\n key = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd',\n 100: 'c', 90: 'xc', 50: 'l', 40: 'xl',\n 10: 'x', 9: 'ix', 5: 'v', 4: 'iv',\n 1: 'i'}\n m = 0\n for base in [1000, 100, 10, 1]:\n for mul in [9, 4, 5, 1, 1, 1]: # up to three 1's, move on after 9 or 4\n val = base * mul\n if val in key and roman.startswith(key[val]):\n m += val\n roman = roman[len(key[val]):]\n if mul == 9 or mul == 4: # 9 or 4 can't be followed by anything else\n break\n return m == n", + "ans_type": "str", + "sol_header": "def sol(n=2414):", + "sol_docstring": " \"\"\"Convert integer 0 < n < 4000 to roman numerals, and make it lowercase\n\n 11 => \"xi\"\n \"\"\"", + "sol_bodies": [ + " units = dict(m=1000, cm=900, d=500, cd=400, c=100, xc=90, l=50, xl=40, x=10, ix=9, v=5, iv=4, i=1)\n roman = \"\"\n for s, i in units.items():\n while n >= i:\n roman += s\n n -= i\n return roman" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#156\n \nDo not add a reverse puzzle converting roman numerals to arabic numbers as it would give away the solution.", + "weight": 1.0 + }, + { + "name": "PythagoreanTriples:0", + "sat": "def sat(triples: List[List[int]], n=920, m=799):\n for a, b, c in triples:\n if not (a * a + b * b == c * c and 0 < a < b < c <= n):\n return False\n return triples == sorted(triples) and len(triples) >= m", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=920, m=799):", + "sol_docstring": " \"\"\"Find m Pythagorean triples a^2 + b^2 == c^2 for integers 0 < a < b < c <= n, in sorted order\n\n (n=6, m=1) => [[3, 4, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[a, b, int((a * a + b * b) ** 0.5)]\n for a in range(3, int(n / (2 ** 0.5)))\n for b in range(a + 1, int((n * n - a * a) ** 0.5) + 1)\n if ((a * a + b * b) ** 0.5).is_integer()]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#157", + "weight": 1.0 + }, + { + "name": "MostUnique:0", + "sat": "def sat(s: str, pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']):\n assert s in pool\n n = len(set(s))\n for p in pool:\n assert len(set(p)) <= n\n return True", + "ans_type": "str", + "sol_header": "def sol(pool=['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique']):", + "sol_docstring": " \"\"\"Select a string from the pool with the most unique characters\n\n [\"woooow\", \"cow\"] => \"cow\"\n \"\"\"", + "sol_bodies": [ + " return max(pool, key=lambda x: len(set(x)))" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#158", + "weight": 1.0 + }, + { + "name": "HungryRabbits:0", + "sat": "def sat(results: List[List[int]], stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]):\n assert len(results) == len(stats)\n for (tot, remaining), (eaten, need, stock) in zip(results, stats):\n assert tot - eaten == min(need, stock)\n assert stock < need and remaining == 0 or stock >= need and remaining + need == stock\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(stats=[[2, 3, 18], [4, 9, 2], [2, 5, 7], [3, 8, 12], [4, 9, 106]]):", + "sol_docstring": " \"\"\"For each triple of eaten, need, stock return a pair of total appetite and remaining\n\n [[2, 5, 6], [3, 9, 22]] => [[7, 1], [12, 13]]\n \"\"\"", + "sol_bodies": [ + " results = []\n for (eaten, need, stock) in stats:\n results.append([eaten + min(need, stock), max(0, stock - need)])\n return results" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#159", + "weight": 1.0 + }, + { + "name": "EvaluateOperators:0", + "sat": "def sat(ops: List[str], target=2021, nums=[4, 6, 2, 1, 1, 3, 9]):\n assert len(ops) == len(set(ops)) and set(ops) == {\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"}\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n return eval(expr) == target", + "ans_type": "List[str]", + "sol_header": "def sol(target=2021, nums=[4, 6, 2, 1, 1, 3, 9]):", + "sol_docstring": " \"\"\"Find a permutation of the operators +-*/^% which when inserted between nums evaluates to target\n\n target=3, nums=[7, 2, 3, 4, 5, 1, 6] => [\"+\", \"*\", \"**\", \"%\", \"//\", \"-\"]\n # because 7 + 2 * 3 ** 4 % 5 // 1 - 6 == 3\n \"\"\"", + "sol_bodies": [ + " from itertools import permutations\n for ops in permutations([\"**\", \"*\", \"+\", \"-\", \"//\", \"%\"]):\n expr = str(nums[0])\n for n, op in zip(nums[1:], ops):\n expr += op + str(n)\n try:\n if eval(expr) == target:\n return list(ops)\n except (ZeroDivisionError, SyntaxError):\n pass\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#160", + "weight": 1.0 + }, + { + "name": "ReverseCase:0", + "sat": "def sat(rev: List[str], strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']):\n assert len(rev) == len(strs)\n return all(r.swapcase() == s != r or r[::-1] == s == s.swapcase() for r, s in zip(rev, strs))", + "ans_type": "List[str]", + "sol_header": "def sol(strs=['cat', 'u8u', '12532', '', '191', '4tUn8', 'ewrWQTEW', 'i', 'IoU']):", + "sol_docstring": " \"\"\"Reverse the case of all strings. For those strings which contain no letters, reverse the strings.\n\n [\"Test\", \"!@#\"] => [\"tEST\", \"#@!\"]\n \"\"\"", + "sol_bodies": [ + " return [s.swapcase() if s.swapcase() != s else s[::-1] for s in strs]" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#161", + "weight": 1.0 + }, + { + "name": "ZobristCollision:0", + "sat": "def sat(positions: List[List[int]]):\n\n table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)]\n\n def zobrist(pos):\n h = 0\n for i in range(64):\n if pos[i]:\n h ^= table[i][pos[i]]\n return h\n\n a, b = positions\n return zobrist(a) == zobrist(b) and a != b", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a collision for the given Zobrist chess board hash: https://en.wikipedia.org/wiki/Zobrist_hashing\n\n Each of the two positions should be encoded as a list of 64 integers 0-12\"\"\"", + "sol_bodies": [ + " hashes = {}\n table = [[(i * 429436219 + j * 100239120) % 63491564 for j in range(13)] for i in range(64)]\n\n def zobrist(pos):\n h = 0\n for i in range(64):\n if pos[i]:\n h ^= table[i][pos[i]]\n return h\n\n for i in range(1, 100000000):\n pos = [(i * 42 + ((i + 1) * j * 12589) % 54321) % 13 for j in range(64)] # pseudo-random board\n h = zobrist(pos)\n if h in hashes:\n return [pos, hashes[h]]\n else:\n hashes[h] = pos" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#162\n\nThe original problem was to compute an MD5 hash. This puzzle is a problem in the space of hashing, but of a\ndifferent nature.", + "weight": 1.0 + }, + { + "name": "EvenBetween:0", + "sat": "def sat(ab: List[int], s=\"3298832990329923299432996329983300033002\"):\n return abs(ab[0] - ab[1]) > 4 and s == \"\".join(str(i) for i in range(min(ab), max(ab) + 1) if i % 2 == 0)", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"3298832990329923299432996329983300033002\"):", + "sol_docstring": " \"\"\"Find integers [a, b] that are at least 5 apart and such that concatenating the even numbers\n between them gives the string s\n\n \"32343638\" => [31, 38]\n \"\"\"", + "sol_bodies": [ + " for i in range(1, len(s)):\n n = int(s[:i])\n n -= (n + 1) % 2 # make n odd\n m = n + 1 # next even\n t = \"\"\n while len(t) < len(s):\n t += str(m)\n m += 2\n if s == t:\n return [n, m - 1]\n\n assert False" + ], + "module": "human_eval.py", + "notes": "Inspired by [HumanEval](https://github.com/openai/human-eval) \\#163\n\nThe original problem was trivial to list the even single-digit numbers between two numbers:\n`a=2, b=12` => `[4, 6, 8]`. In this puzzle, we consider the string of even numbers formed when counting from\n`a` to `b`, e.g., `\"1618202224262830\"` when counting from `15` to `30`. The puzzle is, given such a string,\nfind `a` and `b`.", + "weight": 1.0 + }, + { + "name": "IsEven:0", + "sat": "def sat(b: bool, n=10):\n i = 0\n while i <= n:\n if i + i == n:\n return b == True\n i += 1\n return b == False", + "ans_type": "bool", + "sol_header": "def sol(n=10):", + "sol_docstring": " \"\"\"Determine if n can be evenly divided into two equal numbers. (Easy)\"\"\"", + "sol_bodies": [ + " return n % 2 == 0" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 4 A](https://codeforces.com/problemset/problem/4/A)", + "weight": 1.0 + }, + { + "name": "Abbreviate:0", + "sat": "def sat(s: str, word=\"antidisestablishmentarianism\", max_len=10):\n if len(word) <= max_len:\n return word == s\n return int(s[1:-1]) == len(word[1:-1]) and word[0] == s[0] and word[-1] == s[-1]", + "ans_type": "str", + "sol_header": "def sol(word=\"antidisestablishmentarianism\", max_len=10):", + "sol_docstring": " \"\"\"\n Abbreviate strings longer than a given length by replacing everything but the first and last characters by\n an integer indicating how many characters there were in between them.\n \"\"\"", + "sol_bodies": [ + " if len(word) <= max_len:\n return word\n return f\"{word[0]}{len(word) - 2}{word[-1]}\"" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 71 A](https://codeforces.com/problemset/problem/71/A)", + "weight": 1.0 + }, + { + "name": "SquareTiles:0", + "sat": "def sat(corners: List[List[int]], m=10, n=9, a=5, target=4):\n covered = {(i + x, j + y) for i, j in corners for x in range(a) for y in range(a)}\n assert len(covered) == len(corners) * a * a, \"Double coverage\"\n return len(corners) <= target and covered.issuperset({(x, y) for x in range(m) for y in range(n)})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=9, a=5, target=4):", + "sol_docstring": " \"\"\"Find a minimal list of corner locations for a\u00d7a tiles that covers [0, m] \u00d7 [0, n] and does not double-cover\n squares.\n\n Sample Input:\n m = 10\n n = 9\n a = 5\n target = 4\n\n Sample Output:\n [[0, 0], [0, 5], [5, 0], [5, 5]]\n \"\"\"", + "sol_bodies": [ + " return [[x, y] for x in range(0, m, a) for y in range(0, n, a)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1 A](https://codeforces.com/problemset/problem/1/A)", + "weight": 1.0 + }, + { + "name": "EasyTwos:0", + "sat": "def sat(lb: List[bool], trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):\n return len(lb) == len(trips) and all(\n (b is True) if sum(s) >= 2 else (b is False) for b, s in zip(lb, trips))", + "ans_type": "List[bool]", + "sol_header": "def sol(trips=[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1]]):", + "sol_docstring": " \"\"\"\n Given a list of lists of triples of integers, return True for each list with a total of at least 2 and\n False for each other list.\n \"\"\"", + "sol_bodies": [ + " return [sum(s) >= 2 for s in trips]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 231 A](https://codeforces.com/problemset/problem/231/A)", + "weight": 1.0 + }, + { + "name": "DecreasingCountComparison:0", + "sat": "def sat(n: int, scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):\n assert all(scores[i] >= scores[i + 1] for i in range(len(scores) - 1)), \"Hint: scores are non-decreasing\"\n return all(s >= scores[k] and s > 0 for s in scores[:n]) and all(s < scores[k] or s <= 0 for s in scores[n:])", + "ans_type": "int", + "sol_header": "def sol(scores=[100, 95, 80, 70, 65, 9, 9, 9, 4, 2, 1], k=6):", + "sol_docstring": " \"\"\"\n Given a list of non-increasing integers and given an integer k, determine how many positive integers in the list\n are at least as large as the kth.\n \"\"\"", + "sol_bodies": [ + " threshold = max(scores[k], 1)\n return sum(s >= threshold for s in scores)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 158 A](https://codeforces.com/problemset/problem/158/A)", + "weight": 1.0 + }, + { + "name": "VowelDrop:0", + "sat": "def sat(t: str, s=\"Problems\"):\n i = 0\n for c in s.lower():\n if c in \"aeiouy\":\n continue\n assert t[i] == \".\", f\"expecting `.` at position {i}\"\n i += 1\n assert t[i] == c, f\"expecting `{c}`\"\n i += 1\n return i == len(t)", + "ans_type": "str", + "sol_header": "def sol(s=\"Problems\"):", + "sol_docstring": " \"\"\"\n Given an alphabetic string s, remove all vowels (aeiouy/AEIOUY), insert a \".\" before each remaining letter\n (consonant), and make everything lowercase.\n\n Sample Input:\n s = \"Problems\"\n\n Sample Output:\n .p.r.b.l.m.s\n \"\"\"", + "sol_bodies": [ + " return \"\".join(\".\" + c for c in s.lower() if c not in \"aeiouy\")" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 118 A](https://codeforces.com/problemset/problem/118/A)", + "weight": 1.0 + }, + { + "name": "DominoTile:0", + "sat": "def sat(squares: List[List[int]], m=10, n=5, target=50):\n covered = []\n for i1, j1, i2, j2 in squares:\n assert (0 <= i1 <= i2 < m) and (0 <= j1 <= j2 < n) and (j2 - j1 + i2 - i1 == 1)\n covered += [(i1, j1), (i2, j2)]\n return len(set(covered)) == len(covered) == target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=5, target=50):", + "sol_docstring": " \"\"\"Tile an m x n checkerboard with 2 x 1 tiles. The solution is a list of fourtuples [i1, j1, i2, j2] with\n i2 == i1 and j2 == j1 + 1 or i2 == i1 + 1 and j2 == j1 with no overlap.\"\"\"", + "sol_bodies": [ + " if m % 2 == 0:\n ans = [[i, j, i + 1, j] for i in range(0, m, 2) for j in range(n)]\n elif n % 2 == 0:\n ans = [[i, j, i, j + 1] for i in range(m) for j in range(0, n, 2)]\n else:\n ans = [[i, j, i + 1, j] for i in range(1, m, 2) for j in range(n)]\n ans += [[0, j, 0, j + 1] for j in range(0, n - 1, 2)]\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 50 A](https://codeforces.com/problemset/problem/50/A)", + "weight": 1.0 + }, + { + "name": "IncDec:0", + "sat": "def sat(n: int, ops=['x++', '--x', '--x'], target=19143212):\n for op in ops:\n if op in [\"++x\", \"x++\"]:\n n += 1\n else:\n assert op in [\"--x\", \"x--\"]\n n -= 1\n return n == target", + "ans_type": "int", + "sol_header": "def sol(ops=['x++', '--x', '--x'], target=19143212):", + "sol_docstring": " \"\"\"\n Given a sequence of operations \"++x\", \"x++\", \"--x\", \"x--\", and a target value, find initial value so that the\n final value is the target value.\n\n Sample Input:\n ops = [\"x++\", \"--x\", \"--x\"]\n target = 12\n\n Sample Output:\n 13\n \"\"\"", + "sol_bodies": [ + " return target - ops.count(\"++x\") - ops.count(\"x++\") + ops.count(\"--x\") + ops.count(\"x--\")" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 282 A](https://codeforces.com/problemset/problem/282/A)\n\nThis straightforward problem is a little harder than the Codeforces one.", + "weight": 1.0 + }, + { + "name": "CompareInAnyCase:0", + "sat": "def sat(n: int, s=\"aaAab\", t=\"aAaaB\"):\n if n == 0:\n return s.lower() == t.lower()\n if n == 1:\n return s.lower() > t.lower()\n if n == -1:\n return s.lower() < t.lower()\n return False", + "ans_type": "int", + "sol_header": "def sol(s=\"aaAab\", t=\"aAaaB\"):", + "sol_docstring": " \"\"\"Ignoring case, compare s, t lexicographically. Output 0 if they are =, -1 if s < t, 1 if s > t.\"\"\"", + "sol_bodies": [ + " if s.lower() == t.lower():\n return 0\n if s.lower() > t.lower():\n return 1\n return -1" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 112 A](https://codeforces.com/problemset/problem/112/A)", + "weight": 1.0 + }, + { + "name": "SlidingOne:0", + "sat": "def sat(s: str, matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):\n matrix = [m[:] for m in matrix] # copy\n for c in s:\n if c in \"01234\":\n i = \"01234\".index(c)\n matrix[i], matrix[i + 1] = matrix[i + 1], matrix[i]\n if c in \"abcde\":\n j = \"abcde\".index(c)\n for row in matrix:\n row[j], row[j + 1] = row[j + 1], row[j]\n\n return len(s) <= max_moves and matrix[2][2] == 1", + "ans_type": "str", + "sol_header": "def sol(matrix=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], max_moves=3):", + "sol_docstring": " \"\"\"\n We are given a 5x5 matrix with a single 1 like:\n\n 0 0 0 0 0\n 0 0 0 0 1\n 0 0 0 0 0\n 0 0 0 0 0\n 0 0 0 0 0\n\n Find a (minimal) sequence of row and column swaps to move the 1 to the center. A move is a string\n in \"0\"-\"4\" indicating a row swap and \"a\"-\"e\" indicating a column swap\n \"\"\"", + "sol_bodies": [ + " i = [sum(row) for row in matrix].index(1)\n j = matrix[i].index(1)\n ans = \"\"\n while i > 2:\n ans += str(i - 1)\n i -= 1\n while i < 2:\n ans += str(i)\n i += 1\n while j > 2:\n ans += \"abcde\"[j - 1]\n j -= 1\n while j < 2:\n ans += \"abcde\"[j]\n j += 1\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 263 A](https://codeforces.com/problemset/problem/263/A)", + "weight": 1.0 + }, + { + "name": "SortPlusPlus:0", + "sat": "def sat(s: str, inp=\"1+1+3+1+3+2+2+1+3+1+2\"):\n return all(s.count(c) == inp.count(c) for c in inp + s) and all(s[i - 2] <= s[i] for i in range(2, len(s), 2))", + "ans_type": "str", + "sol_header": "def sol(inp=\"1+1+3+1+3+2+2+1+3+1+2\"):", + "sol_docstring": " \"\"\"Sort numbers in a sum of digits, e.g., 1+3+2+1 -> 1+1+2+3\"\"\"", + "sol_bodies": [ + " return \"+\".join(sorted(inp.split(\"+\")))" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 339 A](https://codeforces.com/problemset/problem/339/A)", + "weight": 1.0 + }, + { + "name": "CapitalizeFirstLetter:0", + "sat": "def sat(s: str, word=\"konjac\"):\n for i in range(len(word)):\n if i == 0:\n if s[i] != word[i].upper():\n return False\n else:\n if s[i] != word[i]:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(word=\"konjac\"):", + "sol_docstring": " \"\"\"Capitalize the first letter of word\"\"\"", + "sol_bodies": [ + " return word[0].upper() + word[1:]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 281 A](https://codeforces.com/problemset/problem/281/A)", + "weight": 1.0 + }, + { + "name": "LongestSubsetString:0", + "sat": "def sat(t: str, s=\"abbbcabbac\", target=7):\n i = 0\n for c in t:\n while c != s[i]:\n i += 1\n i += 1\n return len(t) >= target and all(t[i] != t[i + 1] for i in range(len(t) - 1))", + "ans_type": "str", + "sol_header": "def sol(s=\"abbbcabbac\", target=7):", + "sol_docstring": " \"\"\"\n You are given a string consisting of a's, b's and c's, find any longest substring containing no repeated\n consecutive characters.\n\n Sample Input:\n `\"abbbc\"`\n\n Sample Output:\n `\"abc\"`\n \"\"\"", + "sol_bodies": [ + " # target is ignored\n return s[:1] + \"\".join([b for a, b in zip(s, s[1:]) if b != a])" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 A](https://codeforces.com/problemset/problem/266/A)", + "weight": 1.0 + }, + { + "name": "FindHomogeneousSubstring:0", + "sat": "def sat(n: int, s=\"0000101111111000010\", k=5):\n return s[n:n + k] == s[n] * k", + "ans_type": "int", + "sol_header": "def sol(s=\"0000101111111000010\", k=5):", + "sol_docstring": " \"\"\"\n You are given a string consisting of 0's and 1's. Find an index after which the subsequent k characters are\n all 0's or all 1's.\n\n Sample Input:\n s = 0000111111100000, k = 5\n\n Sample Output:\n 4\n (or 5 or 6 or 11)\n \"\"\"", + "sol_bodies": [ + " return s.index(\"0\" * k if \"0\" * k in s else \"1\" * k)", + " import re\n return re.search(r\"([01])\\1{\" + str(k - 1) + \"}\", s).span()[0]", + " if \"0\" * k in s:\n return s.index(\"0\" * k)\n else:\n return s.index(\"1\" * k)", + " try:\n return s.index(\"0\" * k)\n except:\n return s.index(\"1\" * k)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 96 A](https://codeforces.com/problemset/problem/96/A)", + "weight": 1.0 + }, + { + "name": "Triple0:0", + "sat": "def sat(delta: List[int], nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):\n return all(sum(vec[i] for vec in nums) + delta[i] == 0 for i in range(3))", + "ans_type": "List[int]", + "sol_header": "def sol(nums=[[1, 2, 3], [9, -2, 8], [17, 2, 50]]):", + "sol_docstring": " \"\"\"Find the missing triple of integers to make them all add up to 0 coordinatewise\"\"\"", + "sol_bodies": [ + " return [-sum(vec[i] for vec in nums) for i in range(3)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/69/A)", + "weight": 1.0 + }, + { + "name": "TotalDifference:0", + "sat": "def sat(n: int, a=17, b=100, c=20):\n return n + a == sum([b * i for i in range(c)])", + "ans_type": "int", + "sol_header": "def sol(a=17, b=100, c=20):", + "sol_docstring": " \"\"\"Find n such that n + a == b * (the sum of the first c integers)\"\"\"", + "sol_bodies": [ + " return -a + sum([b * i for i in range(c)])" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 546 A](https://codeforces.com/problemset/problem/546/A)", + "weight": 1.0 + }, + { + "name": "TripleDouble:0", + "sat": "def sat(n: int, v=17, w=100):\n for i in range(n):\n assert v <= w\n v *= 3\n w *= 2\n return v > w", + "ans_type": "int", + "sol_header": "def sol(v=17, w=100):", + "sol_docstring": " \"\"\"Find the smallest n such that if v is tripled n times and w is doubled n times, v exceeds w.\"\"\"", + "sol_bodies": [ + " i = 0\n while v <= w:\n v *= 3\n w *= 2\n i += 1\n return i" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 791 A](https://codeforces.com/problemset/problem/791/A)", + "weight": 1.0 + }, + { + "name": "RepeatDec:0", + "sat": "def sat(res: int, m=1234578987654321, n=4):\n for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return res == m", + "ans_type": "int", + "sol_header": "def sol(m=1234578987654321, n=4):", + "sol_docstring": " \"\"\"\n Find the result of applying the following operation to integer m, n times: if the last digit is zero, remove\n the zero, otherwise subtract 1.\n \"\"\"", + "sol_bodies": [ + " for i in range(n):\n m = (m - 1 if m % 10 else m // 10)\n return m" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 977 A](https://codeforces.com/problemset/problem/977/A)", + "weight": 1.0 + }, + { + "name": "ShortestDecDelta:0", + "sat": "def sat(li: List[int], n=149432, upper=14943):\n return len(li) <= upper and all(abs(a - b) <= 10 for a, b in zip([1] + li, li + [n]))", + "ans_type": "List[int]", + "sol_header": "def sol(n=149432, upper=14943):", + "sol_docstring": " \"\"\"\n Find a the shortest sequence of integers going from 1 to n where each difference is at most 10.\n Do not include 1 or n in the sequence.\n \"\"\"", + "sol_bodies": [ + " m = 1\n ans = []\n while True:\n m = min(n, m + 10)\n if m >= n:\n return ans\n ans.append(m)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 617 A](https://codeforces.com/problemset/problem/617/A)", + "weight": 1.0 + }, + { + "name": "MaxDelta:0", + "sat": "def sat(n: int, pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):\n assert sum(p - m for p, m in pairs) == 0, \"oo\"\n tot = 0\n success = False\n for p, m in pairs:\n tot -= m\n tot += p\n assert tot <= n\n if tot == n:\n success = True\n return success", + "ans_type": "int", + "sol_header": "def sol(pairs=[[3, 0], [17, 1], [9254359, 19], [123, 9254359], [0, 123]]):", + "sol_docstring": " \"\"\"\n Given a sequence of integer pairs, p_i, m_i, where \\sum p_i-m_i = 0, find the maximum value, over t, of\n p_{t+1} + \\sum_{i=1}^t p_i - m_i\n \"\"\"", + "sol_bodies": [ + " tot = 0\n n = 0\n for p, m in pairs:\n tot += p - m\n if tot > n:\n n = tot\n return n" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 116 A](https://codeforces.com/problemset/problem/116/A)", + "weight": 1.0 + }, + { + "name": "CommonCase:0", + "sat": "def sat(s_case: str, s=\"CanYouTellIfItHASmoreCAPITALS\"):\n caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return s_case == (s.upper() if caps > len(s) // 2 else s.lower())", + "ans_type": "str", + "sol_header": "def sol(s=\"CanYouTellIfItHASmoreCAPITALS\"):", + "sol_docstring": " \"\"\"\n Given a word, replace it either with an upper-case or lower-case depending on whether or not it has more\n capitals or lower-case letters. If it has strictly more capitals, use upper-case, otherwise, use lower-case.\n \"\"\"", + "sol_bodies": [ + " caps = 0\n for c in s:\n if c != c.lower():\n caps += 1\n return (s.upper() if caps > len(s) // 2 else s.lower()) # duh, just take sat and return the answer checked for" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 59 A](https://codeforces.com/problemset/problem/59/A)\n\nThis is a trivial puzzle, especially if the AI realizes that it can can just copy the solution from\nthe problem", + "weight": 1.0 + }, + { + "name": "Sssuubbstriiingg:0", + "sat": "def sat(inds: List[int], string=\"Sssuubbstrissiingg\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"substring\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"Sssuubbstrissiingg\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"substring\"\"\"", + "sol_bodies": [ + " target = \"substring\"\n j = 0\n ans = []\n for i in range(len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 + }, + { + "name": "Sstriiinggssuubb:0", + "sat": "def sat(inds: List[int], string=\"enlightenment\"):\n return inds == sorted(inds) and \"\".join(string[i] for i in inds) == \"intelligent\"", + "ans_type": "List[int]", + "sol_header": "def sol(string=\"enlightenment\"):", + "sol_docstring": " \"\"\"Find increasing indices to make the substring \"intelligent\" (with a surprise twist)\"\"\"", + "sol_bodies": [ + " target = \"intelligent\"\n j = 0\n ans = []\n for i in range(-len(string), len(string)):\n while string[i] == target[j]:\n ans.append(i)\n j += 1\n if j == len(target):\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 58 A](https://codeforces.com/problemset/problem/58/A)", + "weight": 1.0 + }, + { + "name": "Moving0s:0", + "sat": "def sat(seq: List[int], target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):\n s = seq[:] # copy\n for step in range(n_steps):\n for i in range(len(seq) - 1):\n if (s[i], s[i + 1]) == (0, 1):\n (s[i], s[i + 1]) = (1, 0)\n return s == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], n_steps=4):", + "sol_docstring": " \"\"\"\n Find a sequence of 0's and 1's so that, after n_steps of swapping each adjacent (0, 1), the target sequence\n is achieved.\n \"\"\"", + "sol_bodies": [ + " s = target[:] # copy\n for step in range(n_steps):\n for i in range(len(target) - 2, -1, -1):\n if (s[i], s[i + 1]) == (1, 0):\n (s[i], s[i + 1]) = (0, 1)\n return s" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 266 B](https://codeforces.com/problemset/problem/266/B)", + "weight": 1.0 + }, + { + "name": "Factor47:0", + "sat": "def sat(d: int, n=6002685529):\n return n % d == 0 and all(i in \"47\" for i in str(d))", + "ans_type": "int", + "sol_header": "def sol(n=6002685529):", + "sol_docstring": " \"\"\"Find a integer factor of n whose decimal representation consists only of 7's and 4's.\"\"\"", + "sol_bodies": [ + " def helper(so_far, k):\n if k > 0:\n return helper(so_far * 10 + 4, k - 1) or helper(so_far * 10 + 7, k - 1)\n return (n % so_far == 0) and so_far\n\n for length in range(1, len(str(n)) // 2 + 2):\n ans = helper(0, length)\n if ans:\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 122 A](https://codeforces.com/problemset/problem/122/A)", + "weight": 1.0 + }, + { + "name": "Count47:0", + "sat": "def sat(d: int, n=123456789):\n return d > n and all(i in \"47\" for i in str(str(d).count(\"4\") + str(d).count(\"7\")))", + "ans_type": "int", + "sol_header": "def sol(n=123456789):", + "sol_docstring": " \"\"\"\n Find a number bigger than n whose decimal representation has k 4's and 7's where k's decimal representation\n consists only of 4's and 7's\n \"\"\"", + "sol_bodies": [ + " return int(\"4444\" + \"0\" * (len(str(n)) - 3))" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 110 A](https://codeforces.com/problemset/problem/110/A)", + "weight": 1.0 + }, + { + "name": "MaybeReversed:0", + "sat": "def sat(s: str, target=\"reverse me\", reverse=True):\n return (s[::-1] == target) == reverse", + "ans_type": "str", + "sol_header": "def sol(target=\"reverse me\", reverse=True):", + "sol_docstring": " \"\"\"Either reverse a string or don't based on the reverse flag\"\"\"", + "sol_bodies": [ + " return target[::-1] if reverse else target + \"x\"" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 41 A](https://codeforces.com/problemset/problem/41/A)", + "weight": 1.0 + }, + { + "name": "MinBigger:0", + "sat": "def sat(taken: List[int], val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):\n advantage = 0\n assert len(taken) == len(val_counts) and sum(taken) <= upper\n for i, (val, count) in zip(taken, val_counts):\n assert 0 <= i <= count\n advantage += val * i - val * count / 2\n return advantage > 0", + "ans_type": "List[int]", + "sol_header": "def sol(val_counts=[[4, 3], [5, 2], [9, 3], [13, 13], [8, 11], [56, 1]], upper=11):", + "sol_docstring": " \"\"\"\n The list of numbers val_counts represents multiple copies of integers, e.g.,\n val_counts=[[3, 2], [4, 6]] corresponds to 3, 3, 4, 4, 4, 4, 4, 4\n For each number, decide how many to take so that the total number taken is <= upper and the sum of those\n taken exceeds half the total sum.\n \"\"\"", + "sol_bodies": [ + " n = len(val_counts)\n pi = sorted(range(n), key=lambda i: val_counts[i][0])\n needed = sum(a * b for a, b in val_counts) / 2 + 0.1\n ans = [0] * n\n while needed > 0:\n while val_counts[pi[-1]][1] == ans[pi[-1]]:\n pi.pop()\n i = pi[-1]\n ans[i] += 1\n needed -= val_counts[i][0]\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 160 A](https://codeforces.com/problemset/problem/160/A)", + "weight": 1.0 + }, + { + "name": "Dada:0", + "sat": "def sat(s: str, a=5129, d=17):\n return s.count(\"a\") == a and s.count(\"d\") == d and len(s) == a + d", + "ans_type": "str", + "sol_header": "def sol(a=5129, d=17):", + "sol_docstring": " \"\"\"Find a string with a given number of a's and d's\"\"\"", + "sol_bodies": [ + " return \"a\" * a + \"d\" * d" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 734 A](https://codeforces.com/problemset/problem/734/A)", + "weight": 1.0 + }, + { + "name": "DistinctDigits:0", + "sat": "def sat(nums: List[int], a=100, b=1000, count=648):\n assert all(len(str(n)) == len(set(str(n))) and a <= n <= b for n in nums)\n return len(set(nums)) >= count", + "ans_type": "List[int]", + "sol_header": "def sol(a=100, b=1000, count=648):", + "sol_docstring": " \"\"\"Find a list of count or more different numbers each between a and b that each have no repeated digits\"\"\"", + "sol_bodies": [ + " return [n for n in range(a, b + 1) if len(str(n)) == len(set(str(n)))]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 271 A](https://codeforces.com/problemset/problem/271/A)", + "weight": 1.0 + }, + { + "name": "EasySum:0", + "sat": "def sat(tot: int, nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):\n return tot == sum(1 if i < thresh else 2 for i in nums)", + "ans_type": "int", + "sol_header": "def sol(nums=[2, 8, 25, 18, 99, 11, 17, 16], thresh=17):", + "sol_docstring": " \"\"\"Add up 1 or 2 for numbers in a list depending on whether they exceed a threshold\"\"\"", + "sol_bodies": [ + " return sum(1 if i < thresh else 2 for i in nums)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 677 A](https://codeforces.com/problemset/problem/677/A)", + "weight": 1.0 + }, + { + "name": "GimmeChars:0", + "sat": "def sat(s: str, chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']):\n for c in chars:\n if c not in s:\n return False\n return True", + "ans_type": "str", + "sol_header": "def sol(chars=['o', 'h', 'e', 'l', ' ', 'w', '!', 'r', 'd']):", + "sol_docstring": " \"\"\"Find a string with certain characters\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 133 A](https://codeforces.com/problemset/problem/133/A), easy", + "weight": 1.0 + }, + { + "name": "HalfPairs:0", + "sat": "def sat(ans: List[List[int]], target=17):\n for i in range(len(ans)):\n a, b = ans[i]\n if b - a >= 2:\n target -= 1\n return target == 0", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=17):", + "sol_docstring": " \"\"\"\n Find a list of pairs of integers where the number of pairs in which the second number is more than\n two greater than the first number is a given constant\n \"\"\"", + "sol_bodies": [ + " return [[0, 2]] * target" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 467 A](https://codeforces.com/problemset/problem/467/A)", + "weight": 1.0 + }, + { + "name": "InvertIndices:0", + "sat": "def sat(indexes: List[int], target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]):\n for i in range(1, len(target) + 1):\n if target[indexes[i - 1] - 1] != i:\n return False\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(target=[1, 3, 4, 2, 5, 6, 7, 13, 12, 11, 9, 10, 8]):", + "sol_docstring": " \"\"\"Given a list of integers representing a permutation, invert the permutation.\"\"\"", + "sol_bodies": [], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 136 A](https://codeforces.com/problemset/problem/136/A)", + "weight": 1.0 + }, + { + "name": "FivePowers:0", + "sat": "def sat(s: str, n=7012):\n return int(str(5 ** n)[:-2] + s) == 5 ** n", + "ans_type": "str", + "sol_header": "def sol(n=7012):", + "sol_docstring": " \"\"\"What are the last two digits of 5^n?\"\"\"", + "sol_bodies": [ + " return (\"1\" if n == 0 else \"5\" if n == 1 else \"25\")" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 630 A](https://codeforces.com/problemset/problem/630/A)", + "weight": 1.0 + }, + { + "name": "CombinationLock:0", + "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n assert all(len(s) == len(start) for s in states) and all(c in \"0123456789\" for s in states for c in s)\n for a, b in zip([start] + states, states + [combo]):\n assert sum(i != j for i, j in zip(a, b)) == 1\n assert all(abs(int(i) - int(j)) in {0, 1, 9} for i, j in zip(a, b))\n\n return len(states) <= target_len", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"424\", combo=\"778\", target_len=12):", + "sol_docstring": " \"\"\"\n Shortest Combination Lock Path\n\n Given a starting a final lock position, find the (minimal) intermediate states, where each transition\n involves increasing or decreasing a single digit (mod 10).\n\n Example:\n start = \"012\"\n combo = \"329\"\n output: ['112', '212', '312', '322', '321', '320']\n \"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)", + "weight": 1.0 + }, + { + "name": "CombinationLockObfuscated:0", + "sat": "def sat(states: List[str], start=\"424\", combo=\"778\", target_len=12):\n return all(sum((int(a[i]) - int(b[i])) ** 2 % 10 for i in range(len(start))) == 1\n for a, b in zip([start] + states, states[:target_len] + [combo]))", + "ans_type": "List[str]", + "sol_header": "def sol(start=\"424\", combo=\"778\", target_len=12):", + "sol_docstring": " \"\"\"Figure out what this does only from the code\"\"\"", + "sol_bodies": [ + " n = len(start)\n ans = []\n a, b = [[int(c) for c in x] for x in [start, combo]]\n for i in range(n):\n while a[i] != b[i]:\n a[i] = (a[i] - 1 if (a[i] - b[i]) % 10 < 5 else a[i] + 1) % 10\n if a != b:\n ans.append(\"\".join(str(i) for i in a))\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 540 A](https://codeforces.com/problemset/problem/540/A)\nThis an obfuscated version of CombinationLock above, can the AI figure out what is being asked or that\nit is the same puzzle?", + "weight": 1.0 + }, + { + "name": "InvertPermutation:0", + "sat": "def sat(s: str, perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):\n return \"\".join((perm[(perm.index(c) + 1) % len(perm)] if c in perm else c) for c in s) == target", + "ans_type": "str", + "sol_header": "def sol(perm=\"qwertyuiopasdfghjklzxcvbnm\", target=\"hello are you there?\"):", + "sol_docstring": " \"\"\"Find a string that, when a given permutation of characters is applied, has a given result.\"\"\"", + "sol_bodies": [ + " return \"\".join((perm[(perm.index(c) - 1) % len(perm)] if c in perm else c) for c in target)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 474 A](https://codeforces.com/problemset/problem/474/A)", + "weight": 1.0 + }, + { + "name": "SameDifferent:0", + "sat": "def sat(lists: List[List[int]], items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):\n a, b = lists\n assert len(a) == len(b) == length\n assert len(set(a)) == len(a)\n assert len(set(b)) == 1\n for i in a + b:\n assert (a + b).count(i) <= items.count(i)\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(items=[5, 4, 9, 4, 5, 5, 5, 1, 5, 5], length=4):", + "sol_docstring": " \"\"\"\n Given a list of integers and a target length, create of the given length such that:\n * The first list must be all different numbers.\n * The second must be all the same number.\n * The two lists together comprise a sublist of all the list items\n \"\"\"", + "sol_bodies": [ + " from collections import Counter\n [[a, count]] = Counter(items).most_common(1)\n assert count >= length\n seen = {a}\n dedup = [i for i in items if i not in seen and not seen.add(i)]\n return [(dedup + [a])[:length], [a] * length]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1335 C](https://codeforces.com/problemset/problem/1335/C)", + "weight": 1.0 + }, + { + "name": "OnesAndTwos:0", + "sat": "def sat(seq: List[int], n=10000, length=5017):\n return all(i in [1, 2] for i in seq) and sum(seq) == n and len(seq) == length", + "ans_type": "List[int]", + "sol_header": "def sol(n=10000, length=5017):", + "sol_docstring": " \"\"\"Find a sequence of 1's and 2's of a given length that that adds up to n\"\"\"", + "sol_bodies": [ + " return [2] * (n - length) + [1] * (2 * length - n)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 476 A](https://codeforces.com/problemset/problem/476/A)", + "weight": 1.0 + }, + { + "name": "MinConsecutiveSum:0", + "sat": "def sat(start: int, k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) <= upper", + "ans_type": "int", + "sol_header": "def sol(k=3, upper=6, seq=[17, 1, 2, 65, 18, 91, -30, 100, 3, 1, 2]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is minimal\"\"\"", + "sol_bodies": [ + " return min(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 + }, + { + "name": "MaxConsecutiveSum:0", + "sat": "def sat(start: int, k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):\n return 0 <= start <= len(seq) - k and sum(seq[start:start + k]) >= lower", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=150, seq=[3, 1, 2, 65, 18, 91, -30, 100, 0, 19, 52]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose sum is maximal\"\"\"", + "sol_bodies": [ + " return max(range(len(seq) - k + 1), key=lambda start: sum(seq[start:start + k]))" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 + }, + { + "name": "MaxConsecutiveProduct:0", + "sat": "def sat(start: int, k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):\n prod = 1\n for i in range(start, start + k):\n prod *= seq[i]\n return prod >= lower", + "ans_type": "int", + "sol_header": "def sol(k=3, lower=100000, seq=[91, 1, 2, 64, 18, 91, -30, 100, 3, 65, 18]):", + "sol_docstring": " \"\"\"Find a sequence of k consecutive indices whose product is maximal, possibly looping around\"\"\"", + "sol_bodies": [ + " def prod(start):\n ans = 1\n for i in range(start, start + k):\n ans *= seq[i]\n return ans\n\n return max(range(-len(seq), len(seq) - k + 1), key=prod)" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 363 B](https://codeforces.com/problemset/problem/363/B)", + "weight": 1.0 + }, + { + "name": "DistinctOddSum:0", + "sat": "def sat(nums: List[int], tot=12345, n=5):\n return len(nums) == len(set(nums)) == n and sum(nums) == tot and all(i >= i % 2 > 0 for i in nums)", + "ans_type": "List[int]", + "sol_header": "def sol(tot=12345, n=5):", + "sol_docstring": " \"\"\"Find n distinct positive odd integers that sum to tot\"\"\"", + "sol_bodies": [ + " return list(range(1, 2 * n - 1, 2)) + [tot - sum(range(1, 2 * n - 1, 2))]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 1327 A](https://codeforces.com/problemset/problem/1327/A)", + "weight": 1.0 + }, + { + "name": "MinRotations:0", + "sat": "def sat(rotations: List[int], target=\"wonderful\", upper=69):\n s = \"abcdefghijklmnopqrstuvwxyz\"\n assert len(rotations) == len(target)\n for r, c in zip(rotations, target):\n s = s[r:] + s[:r]\n assert s[0] == c\n\n return sum(abs(r) for r in rotations) <= upper", + "ans_type": "List[int]", + "sol_header": "def sol(target=\"wonderful\", upper=69):", + "sol_docstring": " \"\"\"\n We begin with the string `\"a...z\"`\n\n An `r`-rotation of a string means shifting it to the right (positive) or left (negative) by `r` characters and\n cycling around. Given a target string of length n, find the n rotations that put the consecutive characters\n of that string at the beginning of the r-rotation, with minimal sum of absolute values of the `r`'s.\n\n For example if the string was `'dad'`, the minimal rotations would be `[3, -3, 3]` with a total of `9`.\n \"\"\"", + "sol_bodies": [ + " s = \"abcdefghijklmnopqrstuvwxyz\"\n ans = []\n for c in target:\n i = s.index(c)\n r = min([i, i - len(s)], key=abs)\n ans.append(r)\n s = s[r:] + s[:r]\n assert s[0] == c\n return ans" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 731 A](https://codeforces.com/problemset/problem/731/A)", + "weight": 1.0 + }, + { + "name": "BillSums:0", + "sat": "def sat(bills: List[int], denominations=[1, 25, 35, 84], n=980, max_len=14):\n return sum(bills) == n and all(b in denominations for b in bills) and len(bills) <= max_len", + "ans_type": "List[int]", + "sol_header": "def sol(denominations=[1, 25, 35, 84], n=980, max_len=14):", + "sol_docstring": " \"\"\"\n Find the shortest sequence (length <= max_len) that sum to n, where each number is in denominations\n \"\"\"", + "sol_bodies": [ + " \"\"\"\n This solution uses dynamic programming, I believe it could be further sped up without having to count\n all the way up to denominations.\n \"\"\"\n denominations = sorted(set(denominations)) # remove duplicates\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "Inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much harder when the denominations are non-American so the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "BoxVolume:0", + "sat": "def sat(sides: List[int], options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13):\n prod = 1\n for b in sides:\n prod *= b\n return prod == n and set(sides) <= set(options) and len(sides) <= max_dim", + "ans_type": "List[int]", + "sol_header": "def sol(options=[2, 512, 1024], n=340282366920938463463374607431768211456, max_dim=13):", + "sol_docstring": " \"\"\"\n Find the side lengths of a box in fewest dimensions (dimension <= max_dim) whose volume is n,\n where each side length is in options\n \"\"\"", + "sol_bodies": [ + " options = sorted(set(options))\n base = options[0]\n logs = []\n for i in options + [n]:\n j = 1\n log = 0\n while j < i:\n log +=1\n j *= base\n assert j == i, \"All numbers must be a power of the smallest number\"\n logs.append(log)\n denominations, n = logs[:-1], logs[-1]\n\n seqs = [[0 for _ in denominations] +[0]] # vectors\n for i in range(1, n + 1):\n _, j, k = min((seqs[i - k][-1], j, k) for j, k in enumerate(denominations) if k <= i)\n s = seqs[i - k]\n seqs.append([*s[:j], s[j] + 1, *s[j + 1:-1], s[-1] + 1])\n\n return [base ** k for k, count in zip(denominations, seqs[-1]) for _ in range(count)]" + ], + "module": "codeforces.py", + "notes": "(Also) inspired by [Codeforces Problem 996 A](https://codeforces.com/problemset/problem/996/A)\n\nWe make it much much harder by making it a multiplication problem where the greedy algorithm doesn't work.", + "weight": 1.0 + }, + { + "name": "QuadraticRoot:0", + "sat": "def sat(x: float, coeffs=[2.5, 1.3, -0.5]):\n a, b, c = coeffs\n return abs(a * x ** 2 + b * x + c) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[2.5, 1.3, -0.5]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^2 + b x + c where coeffs = [a, b, c].\n For example, since x^2 - 3x + 2 has a root at 1, sat(x = 1., coeffs = [1., -3., 2.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = ((-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a))\n return ans", + " a, b, c = coeffs\n if a == 0:\n ans = -c / b if b != 0 else 0.0\n else:\n ans = (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)\n return ans" + ], + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)", + "weight": 1.0 + }, + { + "name": "AllQuadraticRoots:0", + "sat": "def sat(roots: List[float], coeffs=[1.3, -0.5]):\n b, c = coeffs\n r1, r2 = roots\n return abs(r1 + r2 + b) + abs(r1 * r2 - c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[1.3, -0.5]):", + "sol_docstring": " \"\"\"Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]\"\"\"", + "sol_bodies": [ + " b, c = coeffs\n delta = (b ** 2 - 4 * c) ** 0.5\n return [(-b + delta) / 2, (-b - delta) / 2]" + ], + "module": "algebra.py", + "notes": "See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula).", + "weight": 1.0 + }, + { + "name": "CubicRoot:0", + "sat": "def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]):\n return abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(coeffs=[2.0, 1.0, 0.0, 8.0]):", + "sol_docstring": " \"\"\"\n Find any (real) solution to: a x^3 + b x^2 + c x + d where coeffs = [a, b, c, d]\n For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6, sat(x = 1., coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a2, a1, a0 = [c / coeffs[0] for c in coeffs[1:]]\n p = (3 * a1 - a2 ** 2) / 3\n q = (9 * a1 * a2 - 27 * a0 - 2 * a2 ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n c = cube ** (1 / 3)\n for w in [c, c * omega, c * omega.conjugate()]:\n if w != 0:\n x = complex(w - p / (3 * w) - a2 / 3).real\n if abs(sum(c * x ** (3 - i) for i, c in enumerate(coeffs))) < 1e-6:\n return x" + ], + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 + }, + { + "name": "AllCubicRoots:0", + "sat": "def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]):\n r1, r2, r3 = roots\n a, b, c = coeffs\n return abs(r1 + r2 + r3 + a) + abs(r1 * r2 + r1 * r3 + r2 * r3 - b) + abs(r1 * r2 * r3 + c) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol(coeffs=[1.0, -2.0, -1.0]):", + "sol_docstring": " \"\"\"Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).\n coeffs = [a, b, c]. For example, since (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6,\n sat(roots = [1., 2., 3.], coeffs = [-6., 11., -6.]) is True.\n \"\"\"", + "sol_bodies": [ + " a, b, c = coeffs\n p = (3 * b - a ** 2) / 3\n q = (9 * b * a - 27 * c - 2 * a ** 3) / 27\n delta = (q ** 2 + 4 * p ** 3 / 27) ** 0.5\n omega = (-(-1) ** (1 / 3))\n ans = []\n for cube in [(q + delta) / 2, (q - delta) / 2]:\n v = cube ** (1 / 3)\n for w in [v, v * omega, v * omega.conjugate()]:\n if w != 0.0:\n x = complex(w - p / (3 * w) - a / 3).real\n if abs(x ** 3 + a * x ** 2 + b * x + c) < 1e-4:\n if not ans or min(abs(z - x) for z in ans) > 1e-6:\n ans.append(x)\n if len(ans) == 3:\n return ans" + ], + "module": "algebra.py", + "notes": "See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula).", + "weight": 1.0 + }, + { + "name": "SumOfDigits:0", + "sat": "def sat(x: str, s=679):\n return s == sum([int(d) for d in x])", + "ans_type": "str", + "sol_header": "def sol(s=679):", + "sol_docstring": " \"\"\"Find a number that its digits sum to a specific value.\"\"\"", + "sol_bodies": [ + " return int(s / 9) * '9' + str(s % 9)" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "FloatWithDecimalValue:0", + "sat": "def sat(z: float, v=9, d=0.0001):\n return int(z * 1 / d % 10) == v", + "ans_type": "float", + "sol_header": "def sol(v=9, d=0.0001):", + "sol_docstring": " \"\"\"Create a float with a specific decimal.\"\"\"", + "sol_bodies": [ + " return v * d" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ArithmeticSequence:0", + "sat": "def sat(x: List[int], a=7, s=5, e=200):\n return x[0] == a and x[-1] <= e and (x[-1] + s > e) and all([x[i] + s == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=7, s=5, e=200):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an arithmetic sequence.\"\"\"", + "sol_bodies": [ + " return list(range(a, e + 1, s))" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "GeometricSequence:0", + "sat": "def sat(x: List[int], a=8, r=2, l=50):\n return x[0] == a and len(x) == l and all([x[i] * r == x[i + 1] for i in range(len(x) - 1)])", + "ans_type": "List[int]", + "sol_header": "def sol(a=8, r=2, l=50):", + "sol_docstring": " \"\"\"Create a list that is a subrange of an gemoetric sequence.\"\"\"", + "sol_bodies": [ + " return [a * r ** i for i in range(l)]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "LineIntersection:0", + "sat": "def sat(e: List[int], a=2, b=-1, c=1, d=2021):\n x = e[0] / e[1]\n return abs(a * x + b - c * x - d) < 10 ** -5", + "ans_type": "List[int]", + "sol_header": "def sol(a=2, b=-1, c=1, d=2021):", + "sol_docstring": " \"\"\"\n Find the intersection of two lines.\n Solution should be a list of the (x,y) coordinates.\n Accuracy of fifth decimal digit is required.\n \"\"\"", + "sol_bodies": [ + " return [d - b, a - c]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "IfProblem:0", + "sat": "def sat(x: int, a=324554, b=1345345):\n if a < 50:\n return x + a == b\n else:\n return x - 2 * a == b", + "ans_type": "int", + "sol_header": "def sol(a=324554, b=1345345):", + "sol_docstring": " \"\"\"Satisfy a simple if statement\"\"\"", + "sol_bodies": [ + " if a < 50:\n return b - a\n else:\n return b + 2 * a" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "IfProblemWithAnd:0", + "sat": "def sat(x: int, a=9384594, b=1343663):\n if x > 0 and a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=9384594, b=1343663):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an and clause\"\"\"", + "sol_bodies": [ + " if a > 50 and b > a:\n return b + a\n else:\n return b - a" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "IfProblemWithOr:0", + "sat": "def sat(x: int, a=253532, b=1230200):\n if x > 0 or a > 50:\n return x - a == b\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=253532, b=1230200):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with an or clause\"\"\"", + "sol_bodies": [ + " if a > 50 or b > a:\n return b + a\n else:\n return b - a" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "IfCases:0", + "sat": "def sat(x: int, a=4, b=54368639):\n if a == 1:\n return x % 2 == 0\n elif a == -1:\n return x % 2 == 1\n else:\n return x + a == b", + "ans_type": "int", + "sol_header": "def sol(a=4, b=54368639):", + "sol_docstring": " \"\"\"Satisfy a simple if statement with multiple cases\"\"\"", + "sol_bodies": [ + " if a == 1:\n x = 0\n elif a == -1:\n x = 1\n else:\n x = b - a\n return x" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ListPosSum:0", + "sat": "def sat(x: List[int], n=5, s=19):\n return len(x) == n and sum(x) == s and all([a > 0 for a in x])", + "ans_type": "List[int]", + "sol_header": "def sol(n=5, s=19):", + "sol_docstring": " \"\"\"Find a list of n non-negative integers that sum up to s\"\"\"", + "sol_bodies": [ + " x = [1] * n\n x[0] = s - n + 1\n return x" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ListDistinctSum:0", + "sat": "def sat(x: List[int], n=4, s=2021):\n return len(x) == n and sum(x) == s and len(set(x)) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=4, s=2021):", + "sol_docstring": " \"\"\"Construct a list of n distinct integers that sum up to s\"\"\"", + "sol_bodies": [ + " a = 1\n x = []\n while len(x) < n - 1:\n x.append(a)\n a = -a\n if a in x:\n a += 1\n\n if s - sum(x) in x:\n x = [i for i in range(n - 1)]\n\n x = x + [s - sum(x)]\n return x" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ConcatStrings:0", + "sat": "def sat(x: str, s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):\n return len(x) == n and all([x[i] == s[i] for i in range(n)])", + "ans_type": "str", + "sol_header": "def sol(s=['a', 'b', 'c', 'd', 'e', 'f'], n=4):", + "sol_docstring": " \"\"\"Concatenate the list of characters in s\"\"\"", + "sol_bodies": [ + " return ''.join([s[i] for i in range(n)])" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "SublistSum:0", + "sat": "def sat(x: List[int], t=677, a=43, e=125, s=10):\n non_zero = [z for z in x if z != 0]\n return t == sum([x[i] for i in range(a, e, s)]) and len(set(non_zero)) == len(non_zero) and all(\n [x[i] != 0 for i in range(a, e, s)])", + "ans_type": "List[int]", + "sol_header": "def sol(t=677, a=43, e=125, s=10):", + "sol_docstring": " \"\"\"Sum values of sublist by range specifications\"\"\"", + "sol_bodies": [ + " x = [0] * e\n for i in range(a, e, s):\n x[i] = i\n correction = t - sum(x) + x[i]\n if correction in x:\n x[correction] = -1 * correction\n x[i] = 3 * correction\n else:\n x[i] = correction\n return x" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "CumulativeSum:0", + "sat": "def sat(x: List[int], t=50, n=10):\n assert all([v > 0 for v in x])\n s = 0\n i = 0\n for v in sorted(x):\n s += v\n if s > t:\n return i == n\n i += 1\n return i == n", + "ans_type": "List[int]", + "sol_header": "def sol(t=50, n=10):", + "sol_docstring": " \"\"\"Find how many values have cumulative sum less than target\"\"\"", + "sol_bodies": [ + " return [1] * n + [t]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "BasicStrCounts:0", + "sat": "def sat(s: str, s1=\"a\", s2=\"b\", count1=50, count2=30):\n return s.count(s1) == count1 and s.count(s2) == count2 and s[:10] == s[-10:]", + "ans_type": "str", + "sol_header": "def sol(s1=\"a\", s2=\"b\", count1=50, count2=30):", + "sol_docstring": " \"\"\"\n Find a string that has count1 occurrences of s1 and count2 occurrences of s2 and starts and ends with\n the same 10 characters\n \"\"\"", + "sol_bodies": [ + " if s1 == s2:\n ans = (s1 + \"?\") * count1\n elif s1.count(s2):\n ans = (s1 + \"?\") * count1\n ans += (s2 + \"?\") * (count2 - ans.count(s2))\n else:\n ans = (s2 + \"?\") * count2\n ans += (s1 + \"?\") * (count1 - ans.count(s1))\n return \"?\" * 10 + ans + \"?\" * 10" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ZipStr:0", + "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz', 'oddball']):\n return all(sub in s[i::len(substrings)] for i, sub in enumerate(substrings))", + "ans_type": "str", + "sol_header": "def sol(substrings=['foo', 'bar', 'baz', 'oddball']):", + "sol_docstring": " \"\"\"\n Find a string that contains each string in substrings alternating, e.g., 'cdaotg' for 'cat' and 'dog'\n \"\"\"", + "sol_bodies": [ + " m = max(len(s) for s in substrings)\n return \"\".join([(s[i] if i < len(s) else \" \") for i in range(m) for s in substrings])" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "ReverseCat:0", + "sat": "def sat(s: str, substrings=['foo', 'bar', 'baz']):\n return all(sub in s and sub[::-1] in s for sub in substrings)", + "ans_type": "str", + "sol_header": "def sol(substrings=['foo', 'bar', 'baz']):", + "sol_docstring": " \"\"\"\n Find a string that contains all the substrings reversed and forward\n \"\"\"", + "sol_bodies": [ + " return \"\".join(substrings + [s[::-1] for s in substrings])" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "EngineerNumbers:0", + "sat": "def sat(ls: List[str], n=100, a=\"bar\", b=\"foo\"):\n return len(ls) == len(set(ls)) == n and ls[0] == a and ls[-1] == b and ls == sorted(ls)", + "ans_type": "List[str]", + "sol_header": "def sol(n=100, a=\"bar\", b=\"foo\"):", + "sol_docstring": " \"\"\"\n Find a list of n strings, in alphabetical order, starting with a and ending with b.\n \"\"\"", + "sol_bodies": [ + " return sorted([a] + [a + chr(0) + str(i) for i in range(n - 2)] + [b])" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "PenultimateString:0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s in strings and sum(t > s for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):", + "sol_docstring": " \"\"\"Find the alphabetically second to last last string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[-2]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "PenultimateRevString:0", + "sat": "def sat(s: str, strings=['cat', 'dog', 'bird', 'fly', 'moose']):\n return s[::-1] in strings and sum(t < s[::-1] for t in strings) == 1", + "ans_type": "str", + "sol_header": "def sol(strings=['cat', 'dog', 'bird', 'fly', 'moose']):", + "sol_docstring": " \"\"\"Find the reversed version of the alphabetically second string in a list.\"\"\"", + "sol_bodies": [ + " return sorted(strings)[1][::-1]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "CenteredString:0", + "sat": "def sat(s: str, target=\"foobarbazwow\", length=6):\n return target[(len(target) - length) // 2:(len(target) + length) // 2] == s", + "ans_type": "str", + "sol_header": "def sol(target=\"foobarbazwow\", length=6):", + "sol_docstring": " \"\"\"Find a substring of the given length centered within the target string.\"\"\"", + "sol_bodies": [ + " return target[(len(target) - length) // 2:(len(target) + length) // 2]" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "SubstrCount:0", + "sat": "def sat(substring: str, string=\"moooboooofasd\", count=2):\n return string.count(substring) == count", + "ans_type": "str", + "sol_header": "def sol(string=\"moooboooofasd\", count=2):", + "sol_docstring": " \"\"\"Find a substring with a certain count in a given string\"\"\"", + "sol_bodies": [ + " for i in range(len(string)):\n for j in range(i+1, len(string)):\n substring = string[i:j]\n c = string.count(substring)\n if c == count:\n return substring\n if c < count:\n break\n assert False" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "CompleteParens:0", + "sat": "def sat(t: str, s=\"))(Add)some))parens()to()(balance(()(()(me!)((((\"):\n for i in range(len(t) + 1):\n depth = t[:i].count(\"(\") - t[:i].count(\")\")\n assert depth >= 0\n return depth == 0 and s in t", + "ans_type": "str", + "sol_header": "def sol(s=\"))(Add)some))parens()to()(balance(()(()(me!)((((\"):", + "sol_docstring": " \"\"\"Add parentheses to the beginning and end of s to make all parentheses balanced\"\"\"", + "sol_bodies": [ + " return \"(\" * s.count(\")\") + s + \")\" * s.count(\"(\")" + ], + "module": "basic.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "EightQueensOrFewer:0", + "sat": "def sat(squares: List[List[int]], m=8, n=8):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares) and len(squares) == k\n return 4 * k == len({t for i, j in squares for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]})", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8):", + "sol_docstring": " \"\"\"Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other.\"\"\"", + "sol_bodies": [ + " # brute force\n k = min(m, n)\n\n from itertools import permutations\n for p in permutations(range(k)):\n if 4 * k == len(\n {t for i, j in enumerate(p) for t in [('row', i), ('col', j), ('SE', i + j), ('NE', i - j)]}):\n return [[i, j] for i, j in enumerate(p)]" + ], + "module": "chess.py", + "notes": "Eight (or fewer) Queens Puzzle\n\nSee Wikipedia entry on\n[Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nSee the MoreQueens puzzle below for another (longer but clearer) equivalent definition of sat\n\nHint: a brute force approach works on this puzzle.", + "weight": 1.0 + }, + { + "name": "MoreQueens:0", + "sat": "def sat(squares: List[List[int]], m=9, n=9):\n k = min(m, n)\n assert all(i in range(m) and j in range(n) for i, j in squares), \"queen off board\"\n assert len(squares) == k, \"Wrong number of queens\"\n assert len({i for i, j in squares}) == k, \"Queens on same row\"\n assert len({j for i, j in squares}) == k, \"Queens on same file\"\n assert len({i + j for i, j in squares}) == k, \"Queens on same SE diagonal\"\n assert len({i - j for i, j in squares}) == k, \"Queens on same NE diagonal\"\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=9, n=9):", + "sol_docstring": " \"\"\"\n Position min(m, n) > 8 queens on an m x n chess board so that no pair is attacking each other.\n \"\"\"", + "sol_bodies": [ + " t = min(m, n)\n ans = []\n if t % 2 == 1: # odd k, put a queen in the lower right corner (and decrement k)\n ans.append([t - 1, t - 1])\n t -= 1\n if t % 6 == 2: # do something special for 8x8, 14x14 etc:\n ans += [[i, (2 * i + t // 2 - 1) % t] for i in range(t // 2)]\n ans += [[i + t // 2, (2 * i - t // 2 + 2) % t] for i in range(t // 2)]\n else:\n ans += [[i, 2 * i + 1] for i in range(t // 2)]\n ans += [[i + t // 2, 2 * i] for i in range(t // 2)]\n return ans" + ], + "module": "chess.py", + "notes": "See Wikipedia entry on [Eight Queens puzzle](https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle).\n\nA brute force approach will not work on many of these problems.", + "weight": 1.0 + }, + { + "name": "KnightsTour:0", + "sat": "def sat(tour: List[List[int]], m=8, n=8):\n assert all({abs(i1 - i2), abs(j1 - j2)} == {1, 2} for [i1, j1], [i2, j2] in zip(tour, tour[1:])), 'legal moves'\n return sorted(tour) == [[i, j] for i in range(m) for j in range(n)] # cover every square once", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8):", + "sol_docstring": " \"\"\"Find an (open) tour of knight moves on an m x n chess-board that visits each square once.\"\"\"", + "sol_bodies": [ + " # using Warnsdorff's heuristic, breaking ties randomly\n import random\n for seed in range(100):\n r = random.Random(seed)\n ans = [(0, 0)]\n free = {(i, j) for i in range(m) for j in range(n)} - {(0, 0)}\n\n def possible(i, j):\n moves = [(i + s * a, j + t * b) for (a, b) in [(1, 2), (2, 1)] for s in [-1, 1] for t in [-1, 1]]\n return [z for z in moves if z in free]\n\n while True:\n if not free:\n return [[a, b] for (a, b) in ans]\n candidates = possible(*ans[-1])\n if not candidates:\n break\n ans.append(min(candidates, key=lambda z: len(possible(*z)) + r.random()))\n free.remove(ans[-1])" + ], + "module": "chess.py", + "notes": "See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)", + "weight": 1.0 + }, + { + "name": "UncrossedKnightsPath:0", + "sat": "def sat(path: List[List[int]], m=8, n=8, target=35):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=8, n=8, target=35):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (known solvable, but no solution given)\n\nThe goal of these problems is to match the nxn_records from [http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 + }, + { + "name": "UNSOLVED_UncrossedKnightsPath:0", + "sat": "def sat(path: List[List[int]], m=10, n=10, target=62):\n def legal_move(m):\n (a, b), (i, j) = m\n return {abs(i - a), abs(j - b)} == {1, 2}\n\n def legal_quad(m1, m2): # non-overlapping test: parallel or bounding box has (width - 1) * (height - 1) >= 5\n (i1, j1), (i2, j2) = m1\n (a1, b1), (a2, b2) = m2\n return (len({(i1, j1), (i2, j2), (a1, b1), (a2, b2)}) < 4 # adjacent edges in path, ignore\n or (i1 - i2) * (b1 - b2) == (j1 - j2) * (a1 - a2) # parallel\n or (max(a1, a2, i1, i2) - min(a1, a2, i1, i2)) * (max(b1, b2, j1, j2) - min(b1, b2, j1, j2)) >= 5\n # far\n )\n\n assert all(i in range(m) and j in range(n) for i, j in path), \"move off board\"\n assert len({(i, j) for i, j in path}) == len(path), \"visited same square twice\"\n\n moves = list(zip(path, path[1:]))\n assert all(legal_move(m) for m in moves), \"illegal move\"\n assert all(legal_quad(m1, m2) for m1 in moves for m2 in moves), \"intersecting move pair\"\n\n return len(path) >= target", + "ans_type": "List[List[int]]", + "sol_header": "def sol(m=10, n=10, target=62):", + "sol_docstring": " \"\"\"Find a long (open) tour of knight moves on an m x n chess-board whose edges don't cross.\"\"\"", + "sol_bodies": [], + "module": "chess.py", + "notes": "Uncrossed Knights Path (open problem, unsolved)\n\nSimilar to above, but the goal of these problems is to *beat* the nxn_records from\n[http://ukt.alex-black.ru/](http://ukt.alex-black.ru/)\n(accessed 2020-11-29).\n\nA more precise description is in this\n[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path).", + "weight": 1.0 + }, + { + "name": "LZW:0", + "sat": "def sat(seq: List[int], compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):\n index = [chr(i) for i in range(256)]\n pieces = [\"\"]\n for i in seq:\n pieces.append((pieces[-1] + pieces[-1][0]) if i == len(index) else index[i])\n index.append(pieces[-2] + pieces[-1][0])\n return \"\".join(pieces) == text and len(seq) <= compressed_len", + "ans_type": "List[int]", + "sol_header": "def sol(compressed_len=17, text=\"Hellooooooooooooooooooooo world!\"):", + "sol_docstring": " \"\"\"\n Find a (short) compression that decompresses to the given string for the provided implementation of the\n Lempel-Ziv decompression algorithm from https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch\n \"\"\"", + "sol_bodies": [ + " # compressed_len is ignored\n index = {chr(i): i for i in range(256)}\n seq = []\n buffer = \"\"\n for c in text:\n if buffer + c in index:\n buffer += c\n continue\n seq.append(index[buffer])\n index[buffer + c] = len(index) + 1\n buffer = c\n\n if text != \"\":\n seq.append(index[buffer])\n\n return seq" + ], + "module": "compression.py", + "notes": "We have provided a simple version of the *decompression* algorithm of\n[Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)\nso the solution is the *compression* algorithm.", + "weight": 1.0 + }, + { + "name": "PackingHam:0", + "sat": "def sat(words: List[str], num=100, bits=100, dist=34):\n assert len(words) == num and all(len(word) == bits and set(word) <= {\"0\", \"1\"} for word in words)\n return all(sum([a != b for a, b in zip(words[i], words[j])]) >= dist for i in range(num) for j in range(i))", + "ans_type": "List[str]", + "sol_header": "def sol(num=100, bits=100, dist=34):", + "sol_docstring": " \"\"\"Pack a certain number of binary strings so that they have a minimum hamming distance between each other.\"\"\"", + "sol_bodies": [ + " import random # key insight, use randomness!\n r = random.Random(0)\n while True:\n seqs = [r.getrandbits(bits) for _ in range(num)]\n if all(bin(seqs[i] ^ seqs[j]).count(\"1\") >= dist for i in range(num) for j in range(i)):\n return [bin(s)[2:].rjust(bits, '0') for s in seqs]" + ], + "module": "compression.py", + "notes": "This packing problem a [classic problem](https://en.wikipedia.org/wiki/Sphere_packing#Other_spaces)\nin coding theory.", + "weight": 1.0 + }, + { + "name": "Oscillators:0", + "sat": "def sat(init: List[List[int]], period=3):\n target = {x + y * 1j for x, y in init} # complex numbers encode live cells\n\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n live = target\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n if live == target:\n return t + 1 == period", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=3):", + "sol_docstring": " \"\"\"\n Find a pattern in Conway's Game of Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life that repeats\n with a certain period https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life\n \"\"\"", + "sol_bodies": [ + " # # generate random patterns, slow solution\n # def viz(live):\n # if not live:\n # return\n # a, b = min(z.real for z in live), min(z.imag for z in live)\n # live = {z - (a + b * 1j) for z in live}\n # m, n = int(max(z.real for z in live)) + 1, int(max(z.imag for z in live)) + 1\n # for x in range(m):\n # print(\"\".join(\"X\" if x + y * 1j in live else \",\" for y in range(n)))\n\n import random\n rand = random.Random(1)\n # print(f\"Looking for {period}:\")\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n completes = [[x + y * 1j for x in range(n) for y in range(n)] for n in range(30)]\n\n for _attempt in range(10 ** 5):\n n = rand.randrange(3, 10)\n m = rand.randrange(3, n * n)\n live = set(rand.sample(completes[n], m))\n if rand.randrange(2):\n live.update([-z for z in live])\n if rand.randrange(2):\n live.update([z.conjugate() for z in live])\n memory = {}\n for step in range(period * 10):\n key = sum((.123 - .99123j) ** z for z in live) * 10 ** 5\n key = int(key.real), int(key.imag)\n if key in memory:\n if memory[key] == step - period:\n # print(period)\n # viz(live)\n return [[int(z.real), int(z.imag)] for z in live]\n break\n memory[key] = step\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if sum(z + d in live for d in deltas) in range(3 - (z in live), 4)}\n\n return None # failed" + ], + "module": "conways_game_of_life.py", + "notes": "Oscillators (including some unsolved, open problems)\n\nThis problem is *unsolved* for periods 19, 38, and 41.\n\nSee\n[discussion](https://en.wikipedia.org/wiki/Oscillator_%28cellular_automaton%29#:~:text=Game%20of%20Life )\nin Wikipedia article on Cellular Automaton Oscillators.", + "weight": 1.0 + }, + { + "name": "ReverseLifeStep:0", + "sat": "def sat(position: List[List[int]], target=[[1, 3], [1, 4], [2, 5]]):\n live = {x + y * 1j for x, y in position} # complex numbers encode live cells\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return next_step == {x + y * 1j for x, y in target}", + "ans_type": "List[List[int]]", + "sol_header": "def sol(target=[[1, 3], [1, 4], [2, 5]]):", + "sol_docstring": " \"\"\"\n Given a target pattern in Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ),\n specified by [x,y] coordinates of live cells, find a position that leads to that pattern on the next step.\n \"\"\"", + "sol_bodies": [ + " # fixed-temperature MC optimization\n TEMP = 0.05\n import random\n rand = random.Random(0) # set seed but don't interfere with other random uses\n target = {x + y * 1j for x, y in target}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n def distance(live):\n visible = {z + d for z in live for d in deltas}\n next_step = {z for z in visible if sum(z + d in live for d in deltas) in ([2, 3] if z in live else [3])}\n return len(next_step.symmetric_difference(target))\n\n for step in range(10 ** 5):\n if step % 10000 == 0:\n pos = target.copy() # start with the target position\n cur_dist = distance(pos)\n\n if cur_dist == 0:\n return [[int(z.real), int(z.imag)] for z in pos]\n z = rand.choice([z + d for z in pos.union(target) for d in deltas])\n dist = distance(pos.symmetric_difference({z}))\n if rand.random() <= TEMP ** (dist - cur_dist):\n pos.symmetric_difference_update({z})\n cur_dist = dist\n print('Failed', len(target), step)" + ], + "module": "conways_game_of_life.py", + "notes": "Unsolvable for \"Garden of Eden\" positions, but we only generate solvable examples", + "weight": 1.0 + }, + { + "name": "Spaceship:0", + "sat": "def sat(init: List[List[int]], period=4):\n live = {x + y * 1j for x, y in init} # use complex numbers\n init_tot = sum(live)\n target = {z * len(live) - init_tot for z in live}\n deltas = (1j, -1j, 1, -1, 1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j)\n\n for t in range(period):\n visible = {z + d for z in live for d in deltas}\n live = {z for z in visible if 3 - (z in live) <= sum(z + d in live for d in deltas) <= 3}\n tot = sum(live)\n if {z * len(live) - tot for z in live} == target:\n return t + 1 == period and tot != init_tot", + "ans_type": "List[List[int]]", + "sol_header": "def sol(period=4):", + "sol_docstring": " \"\"\"\n Find a \"spaceship\" (see https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29 ) in Conway's\n Game of Life see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life with a certain period\n \"\"\"", + "sol_bodies": [], + "module": "conways_game_of_life.py", + "notes": "Spaceship (including *unsolved*, open problems)\n\nFind a [spaceship](https://en.wikipedia.org/wiki/Spaceship_%28cellular_automaton%29) in\n[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)\nwith a certain period.\n\nThis is an *unsolved* problem for periods 33, 34.", + "weight": 1.0 + }, + { + "name": "Nim:0", + "sat": "def sat(moves: List[List[int]], initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]):\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n state = initial_state[:] # copy\n for i, n in moves:\n assert 0 < n <= state[i], \"Illegal move\"\n state[i] -= n\n if set(state) == {0}:\n return True # you won!\n assert any(state), \"You lost!\"\n bot_move()", + "ans_type": "List[List[int]]", + "sol_header": "def sol(initial_state=[5, 9, 3, 11, 18, 25, 1, 2, 4, 1]):", + "sol_docstring": " \"\"\"\n Beat a bot at Nim, a two-player game involving a number of heaps of objects. Players alternate, in each turn\n removing one or more objects from a single non-empty heap. The player who takes the last object wins.\n - initial_state is list of numbers of objects in each heap\n - moves is a list of your moves: [heap, number of objects to take]\n - you play first\n \"\"\"", + "sol_bodies": [ + "\n state = initial_state[:]\n moves = []\n\n def bot_move(): # bot takes objects from the largest heap to make it match the second largest heap\n vals = sorted(state, reverse=True)\n i_largest = state.index(vals[0]) # largest heap\n state[i_largest] -= max(vals[0] - vals[1], 1) # must take some, take 1 in case of tie\n\n def losing(h): # return True if h is a losing state\n xor = 0\n for i in h:\n xor ^= i\n return xor == 0\n\n def optimal_move():\n assert not losing(state)\n for i in range(len(state)):\n for n in range(1, state[i] + 1):\n state[i] -= n\n if losing(state):\n moves.append([i, n])\n return\n state[i] += n\n assert False, \"Shouldn't reach hear\"\n\n while True:\n optimal_move()\n if max(state) == 0:\n return moves\n bot_move()" + ], + "module": "games.py", + "notes": "Compute optimal play for the classic two-player game [Nim](https://en.wikipedia.org/wiki/Nim)\n\nNim has an elegant theory for optimal play based on the xor of the bits in the heaps.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to determine winning states or beat a certain opponent.", + "weight": 10.0 + }, + { + "name": "Mastermind:0", + "sat": "def sat(transcripts: List[str], max_moves=10):\n COLORS = \"ABCDEF\"\n\n def helper(secret: str, transcript=\"\"):\n if transcript.count(\"\\n\") == max_moves:\n return False\n guess = min([t for t in transcripts if t.startswith(transcript)], key=len)[-4:]\n if guess == secret:\n return True\n assert all(g in COLORS for g in guess)\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return helper(secret, transcript + f\"{guess} {sum(perfect.values())}{almost}\\n\")\n\n return all(helper(r + s + t + u) for r in COLORS for s in COLORS for t in COLORS for u in COLORS)", + "ans_type": "List[str]", + "sol_header": "def sol(max_moves=10):", + "sol_docstring": " \"\"\"\n Come up with a winning strategy for Mastermind in max_moves moves. Colors are represented by the letters A-F.\n The solution representation is as follows.\n A transcript is a string describing the game so far. It consists of rows separated by newlines.\n Each row has 4 letters A-F followed by a space and then two numbers indicating how many are exactly right\n and how many are right but in the wrong location. A sample transcript is as follows:\n AABB 11\n ABCD 21\n ABDC\n\n This is the transcript as the game is in progress. The complete transcript might be:\n AABB 11\n ABCD 21\n ABDC 30\n ABDE 40\n\n A winning strategy is described by a list of transcripts to visit. The next guess can be determined from\n those partial transcripts.\n \"\"\"", + "sol_bodies": [ + " COLORS = \"ABCDEF\"\n\n transcripts = []\n\n ALL = [r + s + t + u for r in COLORS for s in COLORS for t in COLORS for u in COLORS]\n\n def score(secret, guess):\n perfect = {c: sum([g == s == c for g, s in zip(guess, secret)]) for c in COLORS}\n almost = sum(min(guess.count(c), secret.count(c)) - perfect[c] for c in COLORS)\n return f\"{sum(perfect.values())}{almost}\"\n\n def mastermind(transcript=\"AABB\", feasible=ALL): # mastermind moves\n transcripts.append(transcript)\n assert transcript.count(\"\\n\") <= max_moves\n guess = transcript[-4:]\n feasibles = {}\n for secret in feasible:\n scr = score(secret, guess)\n if scr not in feasibles:\n feasibles[scr] = []\n feasibles[scr].append(secret)\n for scr, secrets in feasibles.items():\n if scr != \"40\":\n guesser(transcript + f\" {scr}\\n\", secrets)\n\n def guesser(transcript, feasible): # guesser moves\n def max_ambiguity(guess):\n by_score = {}\n for secret2 in feasible:\n scr = score(secret2, guess)\n if scr not in by_score:\n by_score[scr] = 0\n by_score[scr] += 1\n # for OPTIMAL solution, use return max(by_score.values()) + 0.5 * (guess not in feasible) instead of:\n return max(by_score.values())\n\n # for optimal solution use guess = min(ALL, key=max_ambiguity) instead of:\n guess = min(feasible, key=max_ambiguity)\n\n mastermind(transcript + guess, feasible)\n\n mastermind()\n\n return transcripts" + ], + "module": "games.py", + "notes": "Compute a strategy for winning in [mastermind](https://en.wikipedia.org/wiki/Mastermind_%28board_game%29)\nin a given number of guesses.\n\nInstead of writing a program that plays the game interactively (since interaction is not allowed), we require\nthem to provide a provable winning game tree.", + "weight": 10.0 + }, + { + "name": "TicTacToeX:0", + "sat": "def sat(good_boards: List[str]):\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if X has a forced tie/win assuming it's X's turn to move.\n x |= 1 << [i for i in range(9) if (x | (1 << i), o) in board_bit_reps][0]\n return not win[o] and (win[x] or all((x | o) & (1 << i) or tie(x, o | (1 << i)) for i in range(9)))\n\n return tie(0, 0)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Compute a strategy for X (first player) in tic-tac-toe that guarantees a tie. That is a strategy for X that,\n no matter what the opponent does, X does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that X aims for, so no matter what O does there\n is always good board that X can get to with a single move.\n \"\"\"", + "sol_bodies": [ + " win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[o]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and o_move(x | (1 << i), o):\n good_boards.append(\"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + (i == j)] for j in range(9)))\n return True\n return False # O wins\n\n def o_move(x, o): # returns True if x wins or ties, x's turn to move\n if win[x] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not x_move(x, o | (1 << i)):\n return False\n return True # O wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" + ], + "module": "games.py", + "notes": "Since we don't have interaction, this problem asks for a full tie-guranteeing strategy.", + "weight": 1.0 + }, + { + "name": "TicTacToeO:0", + "sat": "def sat(good_boards: List[str]):\n board_bit_reps = {tuple(sum(1 << i for i in range(9) if b[i] == c) for c in \"XO\") for b in good_boards}\n win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)]\n\n def tie(x, o): # returns True if O has a forced tie/win. It's O's turn to move.\n if o | x != 511: # complete board\n o |= 1 << [i for i in range(9) if (x, o | (1 << i)) in board_bit_reps][0]\n return not win[x] and (win[o] or all((x | o) & (1 << i) or tie(x | (1 << i), o) for i in range(9)))\n\n return all(tie(1 << i, 0) for i in range(9))", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Compute a strategy for O (second player) in tic-tac-toe that guarantees a tie. That is a strategy for O that,\n no matter what the opponent does, O does not lose.\n\n A board is represented as a 9-char string like an X in the middle would be \"....X....\" and a\n move is an integer 0-8. The answer is a list of \"good boards\" that O aims for, so no matter what X does there\n is always good board that O can get to with a single move.\n \"\"\"", + "sol_bodies": [ + " win = [any(i & w == w for w in [7, 56, 73, 84, 146, 273, 292, 448]) for i in range(512)] # 9-bit representation\n\n good_boards = []\n\n def x_move(x, o): # returns True if o wins or ties, x's turn to move\n if win[o] or x | o == 511: # full board\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and not o_move(x | (1 << i), o):\n return False\n return True # O wins/ties\n\n def o_move(x, o): # returns True if o wins or ties, o's turn to move\n if win[x]:\n return False\n if x | o == 511:\n return True\n for i in range(9):\n if (x | o) & (1 << i) == 0 and x_move(x, o | (1 << i)):\n good_boards.append(\n \"\".join(\".XO\"[((x >> j) & 1) + 2 * ((o >> j) & 1) + 2 * (i == j)] for j in range(9)))\n return True\n return False # X wins\n\n res = x_move(0, 0)\n assert res\n\n return good_boards" + ], + "module": "games.py", + "notes": "Same as above but for 2nd player", + "weight": 1.0 + }, + { + "name": "RockPaperScissors:0", + "sat": "def sat(probs: List[float]):\n assert len(probs) == 3 and abs(sum(probs) - 1) < 1e-6\n return max(probs[(i + 2) % 3] - probs[(i + 1) % 3] for i in range(3)) < 1e-6", + "ans_type": "List[float]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find optimal probabilities for playing Rock-Paper-Scissors zero-sum game, with best worst-case guarantee\"\"\"", + "sol_bodies": [ + " return [1 / 3] * 3" + ], + "module": "games.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Nash:0", + "sat": "def sat(strategies: List[List[float]], A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[1.0, -1.0], [-1.3, 0.8]], B=[[-0.9, 1.1], [0.7, -0.8]], eps=0.01):", + "sol_docstring": " \"\"\"\n Find an eps-Nash-equilibrium for a given two-player game with payoffs described by matrices A, B.\n For example, for the classic Prisoner dilemma:\n A=[[-1., -3.], [0., -2.]], B=[[-1., 0.], [-3., -2.]], and strategies = [[0, 1], [0, 1]]\n\n eps is the error tolerance\n \"\"\"", + "sol_bodies": [ + " NUM_ATTEMPTS = 10 ** 5\n\n def sat(strategies: List[List[float]], A, B, eps):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert len(B) == m and all(len(row) == n for row in A + B), \"inputs are a bimatrix game\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n w = sum(B[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(B[i][j] * p[i] for i in range(m)) <= w + eps for j in range(n)))\n\n import random\n r = random.Random(0)\n dims = len(A), len(A[0])\n # possible speedup: remove dominated strategies\n for _attempt in range(NUM_ATTEMPTS):\n strategies = []\n for d in dims:\n s = [max(0.0, r.random() - 0.5) for _ in range(d)]\n tot = sum(s) + 1e-6\n for i in range(d):\n s[i] = (1.0 - sum(s[:-1])) if i == d - 1 else (s[i] / tot) # to ensure sum is exactly 1.0\n strategies.append(s)\n if sat(strategies, A, B, eps):\n return strategies" + ], + "module": "games.py", + "notes": "Computing a [Nash equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium) for a given\n[bimatrix game](https://en.wikipedia.org/wiki/Bimatrix_game) is known to be\nPPAD-hard in general. However, the challenge is be much easier for an approximate\n[eps-equilibrium](https://en.wikipedia.org/wiki/Epsilon-equilibrium) and of course for small games.", + "weight": 5.0 + }, + { + "name": "ZeroSum:0", + "sat": "def sat(strategies: List[List[float]], A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):\n m, n = len(A), len(A[0])\n p, q = strategies\n assert all(len(row) == n for row in A), \"inputs are a matrix\"\n assert len(p) == m and len(q) == n, \"solution is a pair of strategies\"\n assert sum(p) == sum(q) == 1.0 and min(p + q) >= 0.0, \"strategies must be non-negative and sum to 1\"\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n return (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n)))", + "ans_type": "List[List[float]]", + "sol_header": "def sol(A=[[0.0, -0.5, 1.0], [0.75, 0.0, -1.0], [-1.0, 0.4, 0.0]], eps=0.01):", + "sol_docstring": " \"\"\"\n Compute minimax optimal strategies for a given zero-sum game up to error tolerance eps.\n For example, rock paper scissors has\n A = [[0., -1., 1.], [1., 0., -1.], [-1., 1., 0.]] and strategies = [[0.33, 0.33, 0.34]] * 2\n \"\"\"", + "sol_bodies": [ + " MAX_ITER = 10 ** 4\n m, n = len(A), len(A[0])\n a = [0 for _i in range(m)]\n b = [0 for _j in range(n)]\n\n for count in range(1, MAX_ITER):\n i_star = max(range(m), key=lambda i: sum(A[i][j] * b[j] for j in range(n)))\n j_star = min(range(n), key=lambda j: sum(A[i][j] * a[i] for i in range(m)))\n a[i_star] += 1\n b[j_star] += 1\n p = [x / (count + 1e-6) for x in a]\n p[-1] = 1 - sum(p[:-1]) # rounding issues\n q = [x / (count + 1e-6) for x in b]\n q[-1] = 1 - sum(q[:-1]) # rounding issues\n\n v = sum(A[i][j] * p[i] * q[j] for i in range(m) for j in range(n))\n if (all(sum(A[i][j] * q[j] for j in range(n)) <= v + eps for i in range(m)) and\n all(sum(A[i][j] * p[i] for i in range(m)) >= v - eps for j in range(n))):\n return [p, q]" + ], + "module": "games.py", + "notes": "Compute minimax optimal strategies for a given\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game). This problem is known to be equivalent to\nLinear Programming. Note that the provided instances are all quite easy---harder solutions could readily\nbe made by decreasing the accuracy tolerance `eps` at which point the solution we provided would fail and\nmore efficient algorithms would be needed.", + "weight": 1.0 + }, + { + "name": "Conway99:0", + "sat": "def sat(edges: List[List[int]]):\n # first compute neighbors sets, N:\n N = {i: {j for j in range(99) if j != i and ([i, j] in edges or [j, i] in edges)} for i in range(99)}\n return all(len(N[i].intersection(N[j])) == (1 if j in N[i] else 2) for i in range(99) for j in range(i))", + "ans_type": "List[List[int]]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find an undirected graph with 99 vertices, in which each two adjacent vertices have exactly one common\n neighbor, and in which each two non-adjacent vertices have exactly two common neighbors.\n \"\"\"", + "sol_bodies": [], + "module": "graphs.py", + "notes": "Conway's 99-graph problem (*unsolved*, open problem)\n\nConway's 99-graph problem is an unsolved problem in graph theory.\nIn Conway's terminology, from [Five $1,000 Problems (Update 2017)](https://oeis.org/A248380/a248380.pdf)\n\"Is there a graph with 99 vertices in which every edge (i.e. pair of joined vertices) belongs to a unique\ntriangle and every nonedge (pair of unjoined vertices) to a unique quadrilateral?\"\n\nSee also this [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Conway%27s_99-graph_problem).", + "weight": 1.0 + }, + { + "name": "AnyEdge:0", + "sat": "def sat(e: List[int], edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):\n return e in edges", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 217], [40, 11], [17, 29], [11, 12], [31, 51]]):", + "sol_docstring": " \"\"\"Find any edge in edges.\"\"\"", + "sol_bodies": [ + " return edges[0]" + ], + "module": "graphs.py", + "notes": "Trivial [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem.", + "weight": 1.0 + }, + { + "name": "AnyTriangle:0", + "sat": "def sat(tri: List[int], edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n a, b, c = tri\n return [a, b] in edges and [b, c] in edges and [c, a] in edges and a != b != c != a", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):", + "sol_docstring": " \"\"\"Find any triangle in the given directed graph.\"\"\"", + "sol_bodies": [ + " from collections import defaultdict\n outs = defaultdict(set)\n ins = defaultdict(set)\n for i, j in edges:\n if j != i:\n outs[i].add(j)\n ins[j].add(i)\n for i in outs:\n for j in outs[i]:\n try:\n if j in outs:\n k = min(outs[j].intersection(ins[i]))\n return [i, j, k]\n except ValueError:\n pass" + ], + "module": "graphs.py", + "notes": "Easy [graph](https://en.wikipedia.org/w/index.php?title=Graph_(discrete_mathematics)) problem,\nsee [triangle](https://en.wikipedia.org/w/index.php?title=Triangle_graph)", + "weight": 1.0 + }, + { + "name": "PlantedClique:0", + "sat": "def sat(nodes: List[int], size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):\n assert len(nodes) == len(set(nodes)) >= size\n edge_set = {(a, b) for (a, b) in edges}\n for a in nodes:\n for b in nodes:\n assert a == b or (a, b) in edge_set or (b, a) in edge_set\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(size=3, edges=[[0, 17], [0, 22], [17, 22], [17, 31], [22, 31], [31, 17]]):", + "sol_docstring": " \"\"\"Find a clique of the given size in the given undirected graph. It is guaranteed that such a clique exists.\"\"\"", + "sol_bodies": [ + " # brute force (finds list in increasing order), but with a tiny bit of speedup\n if size == 0:\n return []\n from collections import defaultdict\n neighbors = defaultdict(set)\n n = max(max(e) for e in edges)\n for (a, b) in edges:\n if a != b:\n neighbors[a].add(b)\n neighbors[b].add(a)\n pools = [list(range(n + 1))]\n indices = [-1]\n while pools:\n indices[-1] += 1\n if indices[-1] >= len(pools[-1]) - size + len(pools): # since list is increasing order\n indices.pop()\n pools.pop()\n continue\n if len(pools) == size:\n return [pool[i] for pool, i in zip(pools, indices)]\n a = (pools[-1])[indices[-1]]\n pools.append([i for i in pools[-1] if i > a and i in neighbors[a]])\n indices.append(-1)\n assert False, f\"No clique of size {size}\"" + ], + "module": "graphs.py", + "notes": "Find a [planted clique](https://en.wikipedia.org/w/index.php?title=Planted_clique) of a given size\nin an undirected graph. Finding a polynomial-time algorithm for this problem has been *unsolved* for\nsome time.", + "weight": 1.0 + }, + { + "name": "ShortestPath:0", + "sat": "def sat(path: List[int], weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11):\n return path[0] == 0 and path[-1] == 1 and sum(weights[a][b] for a, b in zip(path, path[1:])) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(weights=[{1: 20, 2: 1}, {2: 2, 3: 5}, {1: 10}], bound=11):", + "sol_docstring": " \"\"\"\n Find a path from node 0 to node 1, of length at most bound, in the given digraph.\n weights[a][b] is weight on edge [a,b] for (int) nodes a, b\n \"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm (bound is ignored)\n u, v = 0, 1 # go from 0 to 1\n import heapq\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in weights[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + weights[i][j], j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" + ], + "module": "graphs.py", + "notes": "Shortest Path, see (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 + }, + { + "name": "UnweightedShortestPath:0", + "sat": "def sat(path: List[int], edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):\n assert path[0] == u and path[-1] == v and all([i, j] in edges for i, j in zip(path, path[1:]))\n return len(path) <= bound", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 11], [0, 7], [7, 5], [0, 22], [11, 22], [11, 33], [22, 33]], u=0, v=33, bound=3):", + "sol_docstring": " \"\"\"Find a path from node u to node v, of a bounded length, in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " # Dijkstra's algorithm\n import heapq\n from collections import defaultdict\n queue = [(0, u, u)] # distance, node, trail\n\n trails = {}\n neighbors = defaultdict(set)\n for (i, j) in edges:\n neighbors[i].add(j)\n\n while queue:\n dist, i, j = heapq.heappop(queue)\n if i in trails:\n continue\n trails[i] = j\n if i == v:\n break\n for j in neighbors[i]:\n if j not in trails:\n heapq.heappush(queue, (dist + 1, j, i))\n if v in trails:\n rev_path = [v]\n while rev_path[-1] != u:\n rev_path.append(trails[rev_path[-1]])\n return rev_path[::-1]" + ], + "module": "graphs.py", + "notes": "Unweighted Shortest Path\n\nSee (Dijkstra's algorithm)[https://en.wikipedia.org/w/index.php?title=Dijkstra%27s_algorithm]", + "weight": 1.0 + }, + { + "name": "AnyPath:0", + "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):\n for i in range(len(path) - 1):\n assert [path[i], path[i + 1]] in edges\n assert path[0] == 0\n assert path[-1] == max(max(edge) for edge in edges)\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):", + "sol_docstring": " \"\"\" Find any path from node 0 to node n in a given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " n = max(max(edge) for edge in edges)\n paths = {0: [0]}\n for _ in range(n + 1):\n for i, j in edges:\n if i in paths and j not in paths:\n paths[j] = paths[i] + [j]\n return paths.get(n)" + ], + "module": "graphs.py", + "notes": "Any Path", + "weight": 1.0 + }, + { + "name": "EvenPath:0", + "sat": "def sat(path: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):\n assert path[0] == 0 and path[-1] == max(max(e) for e in edges)\n assert all([[a, b] in edges for a, b in zip(path, path[1:])])\n return len(path) % 2 == 0", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [1, 2]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to n in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = max(max(e) for e in edges)\n for _ in range(n + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return even_paths.get(n)" + ], + "module": "graphs.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "OddPath:0", + "sat": "def sat(p: List[int], edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]):\n return p[0] == 0 and p[-1] == 1 == len(p) % 2 and all([[a, b] in edges for a, b in zip(p, p[1:])])", + "ans_type": "List[int]", + "sol_header": "def sol(edges=[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [5, 6], [6, 7], [6, 1]]):", + "sol_docstring": " \"\"\"Find a path with an even number of nodes from nodes 0 to 1 in the given digraph on vertices 0, 1,..., n.\"\"\"", + "sol_bodies": [ + " even_paths = {}\n odd_paths = {0: [0]}\n n = 1\n for _ in range(max(max(e) for e in edges) + 1):\n for i, j in edges:\n if i in even_paths and j not in odd_paths:\n odd_paths[j] = even_paths[i] + [j]\n if i in odd_paths and j not in even_paths:\n even_paths[j] = odd_paths[i] + [j]\n return odd_paths.get(n)" + ], + "module": "graphs.py", + "notes": "To make it even more different than EvenPath, we changed to go from node 0 to node *1*.", + "weight": 1.0 + }, + { + "name": "Zarankiewicz:0", + "sat": "def sat(edges: List[List[int]], z=20, n=5, t=3):\n from itertools import combinations\n edges = {(a, b) for a, b in edges if a in range(n) and b in range(n)} # convert to a set for efficiency\n assert len(edges) >= z\n\n return all(\n any((a, b) not in edges for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)\n )", + "ans_type": "List[List[int]]", + "sol_header": "def sol(z=20, n=5, t=3):", + "sol_docstring": " \"\"\"Find a bipartite graph with n vertices on each side, z edges, and no K_3,3 subgraph.\"\"\"", + "sol_bodies": [ + " from itertools import combinations\n all_edges = [(a, b) for a in range(n) for b in range(n)]\n for edges in combinations(all_edges, z):\n edge_set = set(edges)\n if all(any((a, b) not in edge_set for a in left for b in right)\n for left in combinations(range(n), t)\n for right in combinations(range(n), t)):\n return [[a, b] for a, b in edges]" + ], + "module": "graphs.py", + "notes": "[Zarankiewicz problem](https://en.wikipedia.org/wiki/Zarankiewicz_problem)", + "weight": 1.0 + }, + { + "name": "GraphIsomorphism:0", + "sat": "def sat(bi: List[int], g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]):\n return len(bi) == len(set(bi)) and {(i, j) for i, j in g1} == {(bi[i], bi[j]) for i, j in g2}", + "ans_type": "List[int]", + "sol_header": "def sol(g1=[[0, 1], [1, 2], [2, 3], [3, 4], [2, 5]], g2=[[0, 4], [1, 5], [4, 1], [1, 2], [2, 3]]):", + "sol_docstring": " \"\"\"\n You are given two graphs which are permutations of one another and the goal is to find the permutation.\n Each graph is specified by a list of edges where each edge is a pair of integer vertex numbers.\n \"\"\"", + "sol_bodies": [ + " # exponentially slow\n from itertools import permutations\n n = max(i for g in [g1, g2] for e in g for i in e) + 1\n g1_set = {(i, j) for i, j in g1}\n for pi in permutations(range(n)):\n if all((pi[i], pi[j]) in g1_set for i, j in g2):\n return list(pi)\n assert False, f\"Graphs are not isomorphic {g1}, {g2}\"" + ], + "module": "graphs.py", + "notes": "The classic [Graph Isomorphism](https://en.wikipedia.org/wiki/Graph_isomorphism) problem.\nIt is unknown whether or not there exists a polynomial-time algorithm\nfor this problem, though an unpublished quasi-polynomial-time algorithm has been announced by Babai.\n\nThe classic version is a decision problem: given two graphs, determine whether or not they are isomorphic.\nHowever, it is polynomial-time equivalent to the one below through a standard reduction. In particular, if you\ncould solve the search problem below (finding the actual bijection), then you can decide isomorphism because the\nsearch solver would simply fail on non-isomorphic graphs. Conversely, if you could solve the decision problem,\nthen you can find a bijection as follows: if the decider determines that the graphs are isomorphic, for each node\nin the first graph, find a corresponding node in the second graph as follows. Add N self-edges from the node to\nitself where N is the maximum degree in the graph + 1, and do that for each candidate node in the second graph.\nFor each of these additions, test isomorphism. If the graphs are isomorphic then there must be a bijection that maps\nthe first node to the second. Repeat this for each node until you have found a bijection. (If self-loops are not\nallowed, one can do this by adding N additional nodes for each test.", + "weight": 1.0 + }, + { + "name": "ShortIntegerPath:0", + "sat": "def sat(li: List[int]):\n return all(j in {i - 1, i + 1, 3 * i} for i, j in zip([0] + li, li + [128])) and len(li) == 9", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Find a list of nine integers, starting with 0 and ending with 128, such that each integer either differs from\n the previous one by one or is thrice the previous one.\n \"\"\"", + "sol_bodies": [ + " return [1, 3, 4, 12, 13, 14, 42, 126, 127]" + ], + "module": "graphs.py", + "notes": "This is a more interesting version of Study_20 with an additional length constraint. One can think of the graph\ndefined by the integer pairs.", + "weight": 1.0 + }, + { + "name": "BiPermutations:0", + "sat": "def sat(perms: List[List[int]], prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):\n n = len(prices0)\n perm0, perm1 = perms\n assert sorted(perm0) == sorted(perm1) == list(range(n)), \"Solution must be two permutations\"\n for i in range(n - 1):\n assert prices0[perm0[i]] <= prices0[perm0[i + 1]], \"Permuted prices must be nondecreasing (row 0)\"\n assert prices1[perm1[i]] <= prices1[perm1[i + 1]], \"Permuted prices must be nondecreasing (row 1)\"\n return all(heights0[i] > heights1[j] for i, j in zip(perm0, perm1))", + "ans_type": "List[List[int]]", + "sol_header": "def sol(prices0=[7, 7, 9, 5, 3, 7, 1, 2], prices1=[5, 5, 5, 4, 2, 5, 1, 1], heights0=[2, 4, 9, 3, 8, 5, 5, 4], heights1=[1, 3, 8, 1, 5, 4, 4, 2]):", + "sol_docstring": " \"\"\"\n There are two rows of objects. Given the length-n integer arrays of prices and heights of objects in each\n row, find a permutation of both rows so that the permuted prices are non-decreasing in each row and\n so that the first row is taller than the second row.\n \"\"\"", + "sol_bodies": [ + " n = len(prices0)\n prices = [prices0, prices1]\n orders = [sorted(range(n), key=lambda i: (prices0[i], heights0[i])),\n sorted(range(n), key=lambda i: (prices1[i], -heights1[i]))]\n jumps = [1, 1] # next price increase locations\n for i in range(n):\n for r, (p, o) in enumerate(zip(prices, orders)):\n while jumps[r] < n and p[o[jumps[r]]] == p[o[i]]:\n jumps[r] += 1\n\n to_fix = orders[jumps[0] < jumps[1]]\n j = i\n while heights0[orders[0][i]] <= heights1[orders[1][i]]:\n j += 1\n to_fix[i], to_fix[j] = to_fix[j], to_fix[i]\n\n return orders" + ], + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem A: Azulejos](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 2,287 characters.", + "weight": 1.0 + }, + { + "name": "OptimalBridges:0", + "sat": "def sat(indices: List[int], H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020):\n assert sorted({0, len(xs) - 1, *indices}) == indices, f\"Ans. should be sorted list [0, ..., {len(xs) - 1}]\"\n cost = alpha * (H - ys[0])\n for i, j in zip(indices, indices[1:]):\n a, b, r = xs[i], xs[j], (xs[j] - xs[i]) / 2\n assert max(ys[i], ys[j]) + r <= H, \"Bridge too tall\"\n assert all(ys[k] <= H - r + ((b - xs[k]) * (xs[k] - a)) ** 0.5 for k in range(i + 1, j)), \\\n \"Bridge too short\"\n cost += alpha * (H - ys[j]) + beta * (b - a) ** 2\n return cost <= thresh", + "ans_type": "List[int]", + "sol_header": "def sol(H=60, alpha=18, beta=2, xs=[0, 10, 20, 30, 50, 80, 100, 120, 160, 190, 200], ys=[0, 30, 10, 30, 50, 40, 10, 20, 20, 55, 10], thresh=26020):", + "sol_docstring": " \"\"\"\n You are to choose locations for bridge bases from among a given set of mountain peaks located at\n `xs, ys`, where `xs` and `ys` are lists of n integers of the same length. Your answer should be a sorted\n list of indices starting at 0 and ending at n-1. The goal is to minimize building costs such that the bridges\n are feasible. The bridges are all semicircles placed on top of the pillars. The feasibility constraints are that:\n * The bridges may not extend above a given height `H`. Mathematically, if the distance between the two xs\n of adjacent pillars is d, then the semicircle will have radius `d/2` and therefore the heights of the\n selected mountain peaks must both be at most `H - d/2`.\n * The bridges must clear all the mountain peaks, which means that the semicircle must lie above the tops of the\n peak. See the code for how this is determined mathematically.\n * The total cost of all the bridges must be at most `thresh`, where the cost is parameter alpha * (the sum of\n all pillar heights) + beta * (the sum of the squared diameters)\n \"\"\"", + "sol_bodies": [ + " # thresh is ignored\n n = len(xs)\n cost = [-1] * n\n prior = [n] * n\n cost[0] = beta * (H - ys[0])\n for i in range(n):\n if cost[i] == -1:\n continue\n min_d = 0\n max_d = 2 * (H - ys[i])\n for j in range(i + 1, n):\n d = xs[j] - xs[i]\n h = H - ys[j]\n if d > max_d:\n break\n if 2 * h <= d:\n min_d = max(min_d, 2 * d + 2 * h - int((8 * d * h) ** 0.5))\n max_d = min(max_d, 2 * d + 2 * h + int((8 * d * h) ** 0.5))\n if min_d > max_d:\n break\n if min_d <= d <= max_d:\n new_cost = cost[i] + alpha * h + beta * d * d\n if cost[j] == -1 or cost[j] > new_cost:\n cost[j] = new_cost\n prior[j] = i\n rev_ans = [n - 1]\n while rev_ans[-1] != 0:\n rev_ans.append(prior[rev_ans[-1]])\n return rev_ans[::-1]" + ], + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem B: Bridges](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\nwhich is 3,003 characters.", + "weight": 1.0 + }, + { + "name": "CheckersPosition:0", + "sat": "def sat(position: List[List[int]], transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):\n board = {(x, y): 0 for x in range(8) for y in range(8) if (x + y) % 2 == 0} # empty board, 0 = empty\n for x, y, p in position:\n assert -2 <= p <= 2 and board[x, y] == 0 # -1, 1 is regular piece, -2, 2 is king\n board[x, y] = p\n\n def has_a_jump(x, y):\n p = board[x, y] # piece to move\n deltas = [(dx, dy) for dx in [-1, 1] for dy in [-1, 1] if dy != -p] # don't check backwards for non-kings\n return any(board.get((x + 2 * dx, y + 2 * dy)) == 0 and board[x + dx, y + dy] * p < 0 for dx, dy in deltas)\n\n sign = 1 # player 1 moves first\n for move in transcript:\n start, end = tuple(move[0]), tuple(move[-1])\n p = board[start] # piece to move\n assert p * sign > 0, \"Moving square must be non-empty and players must be alternate signs\"\n assert all(board[x, y] == 0 for x, y in move if [x, y] != move[0]), \"Moved to an occupied square\"\n\n for (x1, y1), (x2, y2) in zip(move, move[1:]):\n assert abs(p) != 1 or (y2 - y1) * p > 0, \"Non-kings can only move forward (in direction of sign)\"\n if abs(x2 - x1) == 1: # non-jump\n assert not any(has_a_jump(*a) for a in board if board[a] * p > 0), \"Must make a jump if possible\"\n break\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert board[mid] * p < 0, \"Can only jump over piece of opposite sign\"\n board[mid] = 0\n board[start], board[end] = 0, p\n assert abs(x2 - x1) == 1 or not has_a_jump(*end)\n if abs(p) == 1 and any(y in {0, 7} for x, y in move[1:]):\n board[end] *= 2 # king me at the end of turn after any jumps are done!\n sign *= -1\n\n return True", + "ans_type": "List[List[int]]", + "sol_header": "def sol(transcript=[[[3, 3], [5, 5], [3, 7]], [[5, 3], [6, 4]]]):", + "sol_docstring": " \"\"\"\n You are given a partial transcript a checkers game. Find an initial position such that the transcript\n would be a legal set of moves. The board positions are [x, y] pairs with 0 <= x, y < 8 and x + y even.\n There are two players which we call -1 and 1 for convenience, and player 1 must move first in transcript.\n The initial position is represented as a list [x, y, piece] where piece means:\n * 0 is empty square\n * 1 or -1 is piece that moves only in the y = 1 or y = -1 dir, respectively\n * 2 or -2 is king for player 1 or player 2 respectively\n\n Additional rules:\n * You must jump if you can, and you must continue jumping until one can't any longer.\n * You cannot start the position with any non-kings on your last rank.\n * Promotion happens after the turn ends\n \"\"\"", + "sol_bodies": [ + " START_PLAYER = 1 # assumed\n\n class InitOpts:\n def __init__(self, x, y):\n self.x, self.y = x, y\n self.opts = {-2, -1, 0, 1, 2}\n if y == 0:\n self.opts.remove(-1)\n if y == 7:\n self.opts.remove(1)\n self.promoted = 2 ** 63 # on which step was it promoted t >= 0\n self.jumped = 2 ** 63 # on which step was it jumped t >= 0\n\n # def board2str(board): # for debugging\n # mapping = \".bBWw\"\n # ans = \"\"\n # for y in range(7, -1, -1):\n # ans += \"\".join(\" \" if (x+y)%2 else mapping[board[x,y]] for x in range(8)) + \"\\n\"\n # return ans\n\n init_opts = {(x, y): InitOpts(x, y) for x in range(8) for y in range(8) if (x + y) % 2 == 0}\n # board = {(x, y): (1 if y < 3 else -1 if y > 4 else 0) for x in range(8) for y in range(8) if\n # (x + y) % 2 == 0} # new board\n\n transcript = [[tuple(a) for a in move] for move in transcript]\n\n permuted_opts = init_opts.copy()\n sign = START_PLAYER\n for t, move in enumerate(transcript):\n start, end = tuple(move[0]), tuple(move[-1])\n p = permuted_opts[start] # opts to move\n assert p.jumped >= t\n p.opts -= {-sign, -2 * sign, 0}\n if any((y2 - y1) * sign < 0 for (x1, y1), (x2, y2) in zip(move, move[1:])): # backward move!\n if p.promoted >= t:\n p.opts -= {sign} # must be a king!\n\n for a, b in zip(move, move[1:]):\n if permuted_opts[b].jumped >= t:\n permuted_opts[b].opts -= {-2, -1, 1, 2} # must be empty\n assert permuted_opts[a].jumped >= t\n permuted_opts[a], permuted_opts[b] = permuted_opts[b], permuted_opts[a]\n # board[a], board[b] = board[b], board[a]\n (x1, y1), (x2, y2) = a, b\n if abs(x2 - x1) == 2: # jump\n mid = ((x1 + x2) // 2, (y1 + y2) // 2)\n assert permuted_opts[mid].jumped >= t\n permuted_opts[mid].opts -= {0, sign, 2 * sign} # Can only jump over piece of opposite sign\n permuted_opts[mid].jumped = t\n # board[mid] = 0\n\n if any(y in {0, 7} for x, y in move[1:]):\n if p.promoted > t:\n p.promoted = t\n # if abs(board[x2, y2]) == 1:\n # board[x2, y2] *= 2\n\n sign *= -1\n\n for y in range(7, -1, -1):\n for x in range(8):\n if (x, y) in init_opts:\n s = init_opts[x, y].opts\n if {1, 2} <= s:\n s.remove(2)\n if {-1, -2} <= s:\n s.remove(-2)\n\n def helper(): # returns True if success and store everything, otherwise None\n my_opts = init_opts.copy()\n sign = START_PLAYER # player 1 always starts\n\n for t, move in enumerate(transcript):\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n check_no_jumps = [a for a, p in my_opts.items() if p.jumped >= t and p.opts <= {sign, 2 * sign}]\n else:\n for a, b in zip(move, move[1:]):\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n check_no_jumps = [b]\n\n for x, y in check_no_jumps:\n p = my_opts[x, y]\n [o] = p.opts\n assert o * sign > 0\n dys = [o] if (abs(o) == 1 and p.promoted >= t) else [-1, 1] # only check forward jumps\n for dx in [-1, 1]:\n for dy in dys:\n target_o = my_opts.get((x + 2 * dx, y + 2 * dy))\n if target_o is not None and (0 in target_o.opts or target_o.jumped < t):\n mid_o = my_opts[x + dx, y + dy]\n if mid_o.jumped > t and mid_o.opts <= {-sign, -2 * sign}: # ok if jumped at t\n if target_o.jumped < t or target_o.opts == {0}:\n return False\n old_opts = target_o.opts\n for v in target_o.opts:\n if v != 0:\n target_o.opts = {v}\n h = helper()\n if h:\n return True\n target_o.opts = old_opts\n return False\n\n if abs(move[0][0] - move[1][0]) == 1: # not a jump\n a, b = move[0], move[1]\n my_opts[a], my_opts[b] = my_opts[b], my_opts[a]\n\n sign *= -1\n return True\n\n res = helper()\n assert res\n\n def get_opt(opts):\n if 0 in opts.opts:\n return 0\n assert len(opts.opts) == 1\n return list(opts.opts)[0]\n\n return [[x, y, get_opt(opts)] for (x, y), opts in init_opts.items()]" + ], + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem C: Checks Post Facto](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nNobody solved this problem during the competition -- it is pretty difficult!", + "weight": 1.0 + }, + { + "name": "MatchingMarkers:0", + "sat": "def sat(cut_position: int, ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):\n line = ring[cut_position:] + ring[:cut_position]\n matches = {c: 0 for c in line.lower()}\n for c in line:\n if c.islower():\n matches[c] -= (1 if matches[c] > 0 else len(line))\n else:\n matches[c.lower()] += 1\n return sum(i == 0 for i in matches.values()) >= lower", + "ans_type": "int", + "sol_header": "def sol(ring=\"yRrsmOkLCHSDJywpVDEDsjgCwSUmtvHMefxxPFdmBIpM\", lower=5):", + "sol_docstring": " \"\"\"\n The input is a string of start and end markers \"aaBAcGeg\" where upper-case characters indicate start markers\n and lower-case characters indicate ending markers. The string indicates a ring (joined at the ends) and the goal is\n to find a location to split the ring so that there are a maximal number of matched start/end chars where a character\n (like \"a\"/\"A\") is matched if starting at the split and going around the ring, the start-end pairs form a valid\n nesting like nested parentheses. Can you solve it in linear time?\n \"\"\"", + "sol_bodies": [ + " cumulatives = {c: [(0, 0)] for c in ring.lower()}\n n = len(ring)\n for i, c in enumerate(ring):\n v = cumulatives[c.lower()]\n v.append((i, v[-1][1] + (-1 if c.islower() else 1)))\n\n scores = [0]*n\n cumulatives = {c: v for c, v in cumulatives.items() if v[-1][1]==0}\n for c, v in cumulatives.items():\n if v[-1][1] != 0: # ignore things with unequal numbers of opens and closes\n continue\n m = min(t for i, t in v)\n for (i, t), (i2, t2) in zip(v, v[1:] + [(n, 0)]):\n if t == m:\n for j in range(i+1, i2+1):\n scores[j % n] += 1\n b = max(scores)\n for i in range(n):\n if scores[i] == b:\n return i" + ], + "module": "ICPC.py", + "notes": "Inspired by\n[ICPC 2019 Problem D: Circular DNA](https://icpc.global/worldfinals/problems/2019%20ACM-ICPC%20World%20Finals/icpc2019.pdf)\n\nThis is trivial in quadratic time, but the challenge is to solve it quickly (i.e., linear time).", + "weight": 1.0 + }, + { + "name": "ExponentialCoinMoves:0", + "sat": "def sat(states: List[List[int]], n=16385):\n assert states[0] == [1] * 5 and all(len(li) == 5 for li in states) and all(i >= 0 for li in states for i in li)\n for prev, cur in zip(states, states[1:]):\n for i in range(5):\n if cur[i] != prev[i]:\n break\n assert cur[i] < prev[i]\n assert (\n cur[i + 1] - prev[i + 1] == 2 * (prev[i] - cur[i]) and cur[i + 2:] == prev[i + 2:] # k decrements\n or\n cur[i:i + 3] == [prev[i] - 1, prev[i + 2], prev[i + 1]] and cur[i + 3:] == prev[i + 3:] # swap\n )\n\n return states[-1][-1] == 2 ** n", + "ans_type": "List[List[int]]", + "sol_header": "def sol(n=16385):", + "sol_docstring": " \"\"\"\n There are five boxes each having one coin initially. Two types of moves are allowed:\n * (advance) remove `k > 0` coins from box `i` and add `2k` coins to box `i + 1`\n * (swap) remove a coin from box `i` and swap the contents of boxes `i+1` and `i+2`\n Given `0 <= n <= 16385`, find a sequence of states that result in 2^n coins in the last box.\n Note that `n` can be as large as 16385 yielding 2^16385 coins (a number with 4,933 digits) in the last\n box. Encode each state as a list of the numbers of coins in the five boxes.\n\n Sample Input:\n `n = 2`\n\n Sample Output:\n `[[1, 1, 1, 1, 1], [0, 3, 1, 1, 1], [0, 1, 5, 1, 1], [0, 1, 4, 1, 1], [0, 0, 1, 4, 1], [0, 0, 0, 1, 4]]`\n\n The last box now has 2^2 coins. This is a sequence of two advances followed by three swaps.\n\n states is encoded by lists of 5 coin counts\n \"\"\"", + "sol_bodies": [ + " assert n >= 1\n ans = [[1] * 5, [0, 3, 1, 1, 1], [0, 2, 3, 1, 1], [0, 2, 2, 3, 1], [0, 2, 2, 0, 7], [0, 2, 1, 7, 0],\n [0, 2, 1, 0, 14], [0, 2, 0, 14, 0], [0, 1, 14, 0, 0]]\n\n def exp_move(): # shifts last 3 [..., a, 0, 0] to [..., 0, 2^a, 0] for a>0\n state = ans[-1][:]\n state[2] -= 1\n state[3] += 2\n ans.append(state[:])\n while state[2]:\n state[3], state[4] = 0, 2 * state[3]\n ans.append(state[:])\n state[2:] = [state[2] - 1, state[4], 0]\n ans.append(state[:])\n\n exp_move()\n assert ans[-1] == [0, 1, 0, 2 ** 14, 0]\n ans.append([0, 0, 2 ** 14, 0, 0])\n if n <= 16:\n ans.append([0, 0, 0, 2 ** 15, 0])\n else:\n exp_move()\n assert ans[-1] == [0, 0, 0, 2 ** (2 ** 14), 0]\n state = ans[-1][:]\n state[-2] -= 2 ** (n - 1)\n state[-1] = 2 ** n\n ans.append(state)\n return ans" + ], + "module": "IMO.py", + "notes": "This problem has *long* answers, not that the code to solve it is long but that what the solution outputs is long.\n\nThe version below uses only 5 boxes (unlike the IMO problem with 6 boxes since 2010^2010^2010 is too big\nfor computers) but the solution is quite similar to the solution to the IMO problem. Because the solution\nrequires exponential many moves, our representation allows combining multiple Type-1 (advance) operations\ninto a single step.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 10.0 + }, + { + "name": "NoRelativePrimes:0", + "sat": "def sat(nums: List[int], b=7, m=6):\n assert len(nums) == len(set(nums)) == m and min(nums) >= 0\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n for a in nums:\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n assert all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums)\n\n return True", + "ans_type": "List[int]", + "sol_header": "def sol(b=7, m=6):", + "sol_docstring": " \"\"\"\n Let P(n) = n^2 + n + 1.\n\n Given b>=6 and m>=1, find m non-negative integers for which the set {P(a+1), P(a+2), ..., P(a+b)} has\n the property that there is no element that is relatively prime to every other element.\n\n Sample input:\n b = 6\n m = 2\n\n Sample output:\n [195, 196]\n \"\"\"", + "sol_bodies": [ + " ans = []\n\n seen = set()\n deltas = set()\n\n def go(a):\n if a < 0 or a in seen or len(ans) == m:\n return\n seen.add(a)\n nums = [(a + i + 1) ** 2 + (a + i + 1) + 1 for i in range(b)]\n if all(any(i != j and gcd(i, j) > 1 for j in nums) for i in nums):\n new_deltas = [abs(a - a2) for a2 in ans if a != a2 and abs(a - a2) not in deltas]\n ans.append(a)\n for delta in new_deltas:\n for a2 in ans:\n go(a2 + delta)\n go(a2 - delta)\n deltas.update(new_deltas)\n for delta in sorted(deltas):\n go(a + delta)\n\n def gcd(i, j):\n r, s = max(i, j), min(i, j)\n while s >= 1:\n r, s = s, (r % s)\n return r\n\n a = 0\n\n while len(ans) < m:\n go(a)\n a += 1\n\n return ans" + ], + "module": "IMO.py", + "notes": "Inspired by [IMO 2016 Problem 4](https://www.imo-official.org/problems.aspx)\n\nQuestion: Is there a more efficient solution than the brute-force one we give, perhaps using the Chinese remainder\ntheorem?", + "weight": 1.0 + }, + { + "name": "FindRepeats:0", + "sat": "def sat(indices: List[int], a0=123):\n assert a0 >= 0 and a0 % 3 == 0, \"Hint: a_0 is a multiple of 3.\"\n s = [a0]\n for i in range(max(indices)):\n s.append(int(s[-1] ** 0.5) if int(s[-1] ** 0.5) ** 2 == s[-1] else s[-1] + 3)\n return len(indices) == len(set(indices)) == 1000 and min(indices) >= 0 and len({s[i] for i in indices}) == 1", + "ans_type": "List[int]", + "sol_header": "def sol(a0=123):", + "sol_docstring": " \"\"\"\n Find a repeating integer in an infinite sequence of integers, specifically the indices for which the same value\n occurs 1000 times. The sequence is defined by a starting value a_0 and each subsequent term is:\n a_{n+1} = the square root of a_n if the a_n is a perfect square, and a_n + 3 otherwise.\n\n For a given a_0 (that is a multiple of 3), the goal is to find 1000 indices where the a_i's are all equal.\n\n Sample input:\n 9\n\n Sample output:\n [0, 3, 6, ..., 2997]\n\n The sequence starting with a0=9 is [9, 3, 6, 9, 3, 6, 9, ...] thus a_n at where n is a multiple of 3 are\n all equal in this case.\n \"\"\"", + "sol_bodies": [ + " n = a0\n ans = []\n i = 0\n while len(ans) < 1000:\n if n == 3: # use the fact that 3 will repeat infinitely often\n ans.append(i)\n n = int(n ** 0.5) if int(n ** 0.5) ** 2 == n else n + 3\n i += 1\n return ans" + ], + "module": "IMO.py", + "notes": "Note: This problem is much easier than the IMO problem which also required a proof that it is impossible\nfor a_0 not divisible by 3.\n\nInspired by [IMO 2017 Problem 1](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 + }, + { + "name": "PickNearNeighbors:0", + "sat": "def sat(keep: List[bool], heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]):\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * n + n)), \"hint: heights is a permutation of range(n * n + n)\"\n kept = [i for i, k in zip(heights, keep) if k]\n assert len(kept) == 2 * n, \"must keep 2n items\"\n pi = sorted(range(2 * n), key=lambda i: kept[i]) # the sort indices\n return all(abs(pi[2 * i] - pi[2 * i + 1]) == 1 for i in range(n))", + "ans_type": "List[bool]", + "sol_header": "def sol(heights=[10, 2, 14, 1, 8, 19, 16, 6, 12, 3, 17, 0, 9, 18, 5, 7, 11, 13, 15, 4]):", + "sol_docstring": " \"\"\"\n Given a permutation of the integers up to n(n+1) as a list, choose 2n numbers to keep (in the same order)\n so that the remaining list of numbers satisfies:\n * its largest number is next to its second largest number\n * its third largest number is next to its fourth largest number\n ...\n * its second smallest number is next to its smallest number\n\n Sample input:\n [4, 0, 5, 3, 1, 2]\n n = 2\n\n Sample output:\n [True, False, True, False, True, True]\n\n Keeping these indices results in the sublist [4, 5, 1, 2] where 4 and 5 are adjacent as are 1 and 2.\n \"\"\"", + "sol_bodies": [ + " # Based on the judge's solution.\n n = int(len(heights) ** 0.5)\n assert sorted(heights) == list(range(n * (n + 1)))\n groups = [h // (n + 1) for h in heights]\n ans = [False] * len(heights)\n a = 0\n used_groups = set()\n while sum(ans) < 2 * n:\n group_tracker = {}\n b = a\n while groups[b] not in group_tracker or groups[b] in used_groups:\n group_tracker[groups[b]] = b\n b += 1\n ans[group_tracker[groups[b]]] = True\n ans[b] = True\n used_groups.add(groups[b])\n a = b + 1\n return ans" + ], + "module": "IMO.py", + "notes": "Inspired by [IMO 2017 Problem 5](https://www.imo-official.org/problems.aspx)\n\nThe puzzle solution follows the judge's proof closely.", + "weight": 1.0 + }, + { + "name": "FindProductiveList:0", + "sat": "def sat(li: List[int], n=18):\n assert n % 3 == 0, \"Hint: n is a multiple of 3\"\n return len(li) == n and all(li[(i + 2) % n] == 1 + li[(i + 1) % n] * li[i] for i in range(n))", + "ans_type": "List[int]", + "sol_header": "def sol(n=18):", + "sol_docstring": " \"\"\"\n Given n, find n integers such that li[i] * li[i+1] + 1 == li[i+2], for i = 0, 1, ..., n-1\n where indices >= n \"wrap around\". Note: only n multiples of 3 are given since this is only possible for n\n that are multiples of 3 (as proven in the IMO problem).\n\n Sample input:\n 6\n\n Sample output:\n [_, _, _, _, _, _]\n\n (Sample output hidden because showing sample output would give away too much information.)\n \"\"\"", + "sol_bodies": [ + " return [-1, -1, 2] * (n // 3)" + ], + "module": "IMO.py", + "notes": "Note: This problem is easier than the IMO problem because the hard part is proving that sequences do not\nexists for non-multiples of 3.\n\nInspired by [IMO 2010 Problem 5](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 + }, + { + "name": "HalfTag:0", + "sat": "def sat(li: List[int], tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]):\n n = max(tags) + 1\n assert sorted(tags) == sorted(list(range(n)) * 4), \"hint: each tag occurs exactly four times\"\n assert len(li) == len(set(li)) and min(li) >= 0\n return sum(li) * 2 == sum(range(4 * n)) and sorted([tags[i] for i in li]) == [i // 2 for i in range(2 * n)]", + "ans_type": "List[int]", + "sol_header": "def sol(tags=[3, 0, 3, 2, 0, 1, 0, 3, 1, 1, 2, 2, 0, 2, 1, 3]):", + "sol_docstring": " \"\"\"\n The input tags is a list of 4n integer tags each in range(n) with each tag occurring 4 times.\n The goal is to find a subset (list) li of half the indices such that:\n * The sum of the indices equals the sum of the sum of the missing indices.\n * The tags of the chosen indices contains exactly each number in range(n) twice.\n\n Sample input:\n n = 3\n tags = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 2]\n\n Sample output:\n [0, 3, 5, 6, 8, 11]\n\n Note the sum of the output is 33 = (0+1+2+...+11)/2 and the selected tags are [0, 0, 1, 1, 2, 2]\n \"\"\"", + "sol_bodies": [ + " n = max(tags) + 1\n pairs = {(i, 4 * n - i - 1) for i in range(2 * n)}\n by_tag = {tag: [] for tag in range(n)}\n for p in pairs:\n a, b = [tags[i] for i in p]\n by_tag[a].append(p)\n by_tag[b].append(p)\n cycles = []\n cycle = []\n while pairs:\n if not cycle: # start new cycle\n p = pairs.pop()\n pairs.add(p) # just to pick a tag\n tag = tags[p[0]]\n # print(\"Starting cycle with tag\", tag)\n p = by_tag[tag].pop()\n a, b = [tags[i] for i in p]\n # print(p, a, b)\n tag = a if a != tag else b\n by_tag[tag].remove(p)\n cycle.append(p if tag == b else p[::-1])\n pairs.remove(p)\n if not by_tag[tag]:\n cycles.append(cycle)\n cycle = []\n\n while any(len(c) % 2 for c in cycles):\n cycle_tags = [{tags[k] for p in c for k in p} for c in cycles]\n merged = False\n for i in range(len(cycles)):\n for j in range(i):\n intersection = cycle_tags[i].intersection(cycle_tags[j])\n if intersection:\n c = intersection.pop()\n # print(f\"Merging cycle {i} and cycle {j} at tag {c}\", cycles)\n cycle_i = cycles.pop(i)\n for i1, p in enumerate(cycle_i):\n if tags[p[0]] == c:\n break\n for j1, p in enumerate(cycles[j]):\n if tags[p[0]] == c:\n break\n cycles[j][j1:j1] = cycle_i[i1:] + cycle_i[:i1]\n merged = True\n break\n if merged:\n break\n\n ans = []\n for c in cycles:\n for i, p in enumerate(c):\n if i % 2:\n ans += p\n\n return ans" + ], + "module": "IMO.py", + "notes": "Inspired by [IMO 2020 Problem 3](https://www.imo-official.org/problems.aspx)", + "weight": 1.0 + }, + { + "name": "LearnParity:0", + "sat": "def sat(inds: List[int], vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]):\n return all(sum((v >> i) & 1 for i in inds) % 2 == 1 for v in vecs)", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[169, 203, 409, 50, 37, 479, 370, 133, 53, 159, 161, 367, 474, 107, 82, 447, 385]):", + "sol_docstring": " \"\"\"\n Parity learning: Given binary vectors in a subspace, find the secret set S of indices such that:\n $\\\\sum_{i \\in S} x_i = 1 (mod 2)$\n \"\"\"", + "sol_bodies": [ + " # Gaussian elimination\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n ans = []\n pool = [[0] * (d + 1) for _ in range(d)] + [v + [1] for v in vecs]\n for i in range(d):\n pool[i][i] = 1\n\n for i in range(d): # zero out bit i\n for v in pool[d:]:\n if v[i] == 1:\n break\n if v[i] == 0:\n v = pool[i]\n assert v[i] == 1 # found a vector with v[i] = 1, subtract it off from those with a 1 in the ith coordinate\n w = v[:]\n for v in pool:\n if v[i] == 1:\n for j in range(d + 1):\n v[j] ^= w[j]\n\n return [i for i in range(d) if pool[i][-1]]" + ], + "module": "lattices.py", + "notes": "Parity learning (Gaussian elimination)\n\nThe canonical solution to this \n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nis to use \n[Gaussian Elimination](https://en.wikipedia.org/w/index.php?title=Gaussian_elimination).\n\nThe vectors are encoded as binary integers for succinctness.", + "weight": 1.0 + }, + { + "name": "LearnParityWithNoise:0", + "sat": "def sat(inds: List[int], vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]):\n return sum(sum((v >> i) & 1 for i in inds) % 2 for v in vecs) >= len(vecs) * 3 / 4", + "ans_type": "List[int]", + "sol_header": "def sol(vecs=[26, 5, 32, 3, 15, 18, 31, 13, 24, 25, 34, 5, 15, 24, 16, 13, 0, 27, 37]):", + "sol_docstring": " \"\"\"\n Learning parity with noise: Given binary vectors, find the secret set $S$ of indices such that, for at least\n 3/4 of the vectors, $$sum_{i \\in S} x_i = 1 (mod 2)$$\n \"\"\"", + "sol_bodies": [ + " # brute force\n d = 0 # decode vectors into arrays\n m = max(vecs)\n while m:\n m >>= 1\n d += 1\n vecs = [[(n >> i) & 1 for i in range(d)] for n in vecs]\n\n import random\n rand = random.Random(0)\n target = (len(vecs) * 3) // 4\n max_attempts = 10 ** 5\n for _ in range(max_attempts):\n ans = [i for i in range(d) if rand.randrange(2)]\n if sum(sum(v[i] for i in ans) % 2 for v in vecs) >= len(vecs) * 3 / 4:\n return ans" + ], + "module": "lattices.py", + "notes": "Learn parity with noise (*unsolved*)\n\nThe fastest known algorithm to this\n[Parity learning problem](https://en.wikipedia.org/w/index.php?title=Parity_learning)\nruns in time $2^(d/(log d))$", + "weight": 1.0 + }, + { + "name": "FermatsLastTheorem:0", + "sat": "def sat(nums: List[int]):\n a, b, c, n = nums\n return (a ** n + b ** n == c ** n) and min(a, b, c) > 0 and n > 2", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find integers a,b,c > 0, n > 2, such such that a^n + b^n == c^n\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "[Fermat's last theorem](https://en.wikipedia.org/w/index.php?title=Fermat%27s_Last_Theorem)\n\nSupposedly unsolvable, but how confident are really in the super-complicated proof?\n\nSee [Wiles, Andrew. \"Modular elliptic curves and Fermat's last theorem.\" Annals of mathematics 141.3 (1995): 443-551.](https://www.jstor.org/stable/2118559)", + "weight": 1.0 + }, + { + "name": "GCD:0", + "sat": "def sat(n: int, a=15482, b=23223, lower_bound=5):\n return a % n == 0 and b % n == 0 and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(a=15482, b=23223, lower_bound=5):", + "sol_docstring": " \"\"\"Find a large common divisor of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return n", + " def gcd(m, n):\n if m > n:\n return gcd(n, m)\n if m == 0:\n return n\n return gcd(n % m, m)\n\n return gcd(a, b)" + ], + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 + }, + { + "name": "GCD_multi:0", + "sat": "def sat(n: int, nums=[77410, 23223, 54187], lower_bound=2):\n return all(i % n == 0 for i in nums) and n >= lower_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[77410, 23223, 54187], lower_bound=2):", + "sol_docstring": " \"\"\"Find a large common divisor of the list of integers.\"\"\"", + "sol_bodies": [ + " n = 0\n for i in nums:\n m, n = min(i, n), max(i, n)\n while m > 0:\n m, n = n % m, m\n return n" + ], + "module": "number_theory.py", + "notes": "[Greatest Common Divisor](https://en.wikipedia.org/w/index.php?title=Greatest_common_divisor&oldid=990943381)\n(GCD)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 + }, + { + "name": "LCM:0", + "sat": "def sat(n: int, a=15, b=27, upper_bound=150):\n return n % a == 0 and n % b == 0 and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(a=15, b=27, upper_bound=150):", + "sol_docstring": " \"\"\"Find a small common multiple of two integers.\"\"\"", + "sol_bodies": [ + " m, n = min(a, b), max(a, b)\n while m > 0:\n m, n = n % m, m\n return a * (b // n)" + ], + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 + }, + { + "name": "LCM_multi:0", + "sat": "def sat(n: int, nums=[15, 27, 102], upper_bound=5000):\n return all(n % i == 0 for i in nums) and 0 < n <= upper_bound", + "ans_type": "int", + "sol_header": "def sol(nums=[15, 27, 102], upper_bound=5000):", + "sol_docstring": " \"\"\"Find a small common multiple of a list of integers.\"\"\"", + "sol_bodies": [ + " ans = 1\n for i in nums:\n m, n = min(i, ans), max(i, ans)\n while m > 0:\n m, n = n % m, m\n ans *= (i // n)\n return ans" + ], + "module": "number_theory.py", + "notes": "[Least Common Multiple](https://en.wikipedia.org/wiki/Least_common_multiple)\n(LCM)\n\nSee also the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)", + "weight": 1.0 + }, + { + "name": "SmallExponentBigSolution:0", + "sat": "def sat(n: int, b=2, target=5):\n return (b ** n) % n == target", + "ans_type": "int", + "sol_header": "def sol(b=2, target=5):", + "sol_docstring": " \"\"\"Solve for n: b^n = target (mod n)\"\"\"", + "sol_bodies": [ + " for n in range(1, 10 ** 5):\n if pow(b, n, n) == target:\n return n" + ], + "module": "number_theory.py", + "notes": "Small exponent, big solution\n\nProblems have small b and target but solution is typically a large n.\nSome of them are really hard, for example, for `b=2, target=3`, the smallest solution is `n=4700063497`\n\nSee [Richard K. Guy \"The strong law of small numbers\", (problem 13)](https://doi.org/10.2307/2322249)", + "weight": 1.0 + }, + { + "name": "ThreeCubes:0", + "sat": "def sat(nums: List[int], target=983):\n assert target % 9 not in [4, 5], \"Hint\"\n return len(nums) == 3 and sum([i ** 3 for i in nums]) == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=983):", + "sol_docstring": " \"\"\"Given n, find integers a, b, c such that a^3 + b^3 + c^3 = n.\"\"\"", + "sol_bodies": [ + " assert target % 9 not in {4, 5}\n for i in range(20):\n for j in range(i + 1):\n for k in range(-20, j + 1):\n n = i ** 3 + j ** 3 + k ** 3\n if n == target:\n return [i, j, k]\n if n == -target:\n return [-i, -j, -k]" + ], + "module": "number_theory.py", + "notes": "Sum of three cubes\n\nGiven `n`, find integers `a`, `b`, `c` such that `a**3 + b**3 + c**3 = n`. This is unsolvable for `n % 9 in {4, 5}`.\nConjectured to be true for all other n, i.e., `n % 9 not in {4, 5}`.\n`a`, `b`, `c` may be positive or negative\n\nSee [wikipedia entry](https://en.wikipedia.org/wiki/Sums_of_three_cubes) or\n[Andrew R. Booker, Andrew V. Sutherland (2020). \"On a question of Mordell.\"](https://arxiv.org/abs/2007.01209)", + "weight": 1.0 + }, + { + "name": "FourSquares:0", + "sat": "def sat(nums: List[int], n=12345):\n return len(nums) <= 4 and sum(i ** 2 for i in nums) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=12345):", + "sol_docstring": " \"\"\"Find four integers whose squares sum to n\"\"\"", + "sol_bodies": [ + " m = n\n squares = {i ** 2: i for i in range(int(m ** 0.5) + 2) if i ** 2 <= m}\n sums_of_squares = {i + j: [a, b] for i, a in squares.items() for j, b in squares.items()}\n for s in sums_of_squares:\n if m - s in sums_of_squares:\n return sums_of_squares[m - s] + sums_of_squares[s]\n assert False, \"Should never reach here\"" + ], + "module": "number_theory.py", + "notes": "Sum of four squares\n\n[Lagrange's Four Square Theorem](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem)\n\nGiven a non-negative integer `n`, a classic theorem of Lagrange says that `n` can be written as the sum of four\nintegers. The problem here is to find them. This is a nice problem and we give an elementary solution\nthat runs in time \tilde{O}(n),\nwhich is not \"polynomial time\" because it is not polynomial in log(n), the length of n. A poly-log(n)\nalgorithm using quaternions is described in the book:\n[\"Randomized algorithms in number theory\" by Michael O. Rabin and Jeffery O. Shallit (1986)](https://doi.org/10.1002/cpa.3160390713)\n\nThe first half of the problems involve small numbers and the second half involve some numbers up to 50 digits.", + "weight": 1.0 + }, + { + "name": "Factoring:0", + "sat": "def sat(i: int, n=241864633):\n return 1 < i < n and n % i == 0", + "ans_type": "int", + "sol_header": "def sol(n=241864633):", + "sol_docstring": " \"\"\"Find a non-trivial factor of integer n\"\"\"", + "sol_bodies": [ + " if n % 2 == 0:\n return 2\n\n for i in range(3, int(n ** 0.5) + 1, 2):\n if n % i == 0:\n return i\n\n assert False, \"problem defined for composite n only\"" + ], + "module": "number_theory.py", + "notes": "[Factoring](https://en.wikipedia.org/w/index.php?title=Integer_factorization) and\n[RSA challenge](https://en.wikipedia.org/w/index.php?title=RSA_numbers)\n\n*See class FermatComposite in codex.py for an easier composite test puzzle*\n\nThe factoring problems require one to find any nontrivial factor of n, which is equivalent to factoring by a\nsimple repetition process. Problems range from small (single-digit n) all the way to the \"RSA challenges\"\nwhich include several *unsolved* factoring problems put out by the RSA company. The challenge was closed in 2007,\nwith hundreds of thousands of dollars in unclaimed prize money for factoring their given numbers. People\ncontinue to work on them, nonetheless, and only the first 22/53 have RSA challenges have been solved thusfar.\n\nFrom Wikipedia:\n\nRSA-2048 has 617 decimal digits (2,048 bits). It is the largest of the RSA numbers and carried the largest\ncash prize for its factorization, $200,000. The RSA-2048 may not be factorizable for many years to come,\nunless considerable advances are made in integer factorization or computational power in the near future.", + "weight": 1.0 + }, + { + "name": "DiscreteLog:0", + "sat": "def sat(n: int, g=44337, p=69337, t=38187):\n return pow(g, n, p) == t", + "ans_type": "int", + "sol_header": "def sol(g=44337, p=69337, t=38187):", + "sol_docstring": " \"\"\"Find n such that g^n is congruent to t mod n\"\"\"", + "sol_bodies": [ + " for n in range(p):\n if pow(g, n, p) == t:\n return n\n assert False, f\"unsolvable discrete log problem g={g}, t={t}, p={p}\"" + ], + "module": "number_theory.py", + "notes": "Discrete Log\n\nThe discrete logarithm problem is (given `g`, `t`, and `p`) to find n such that:\n\n`g ** n % p == t`\n\nFrom [Wikipedia article](https://en.wikipedia.org/w/index.php?title=Discrete_logarithm_records):\n\n\"Several important algorithms in public-key cryptography base their security on the assumption\nthat the discrete logarithm problem over carefully chosen problems has no efficient solution.\"\n\nThe problem is *unsolved* in the sense that no known polynomial-time algorithm has been found.\n\nWe include McCurley's discrete log challenge from\n[Weber D., Denny T. (1998) \"The solution of McCurley's discrete log challenge.\"](https://link.springer.com/content/pdf/10.1007/BFb0055747.pdf)", + "weight": 1.0 + }, + { + "name": "GCD17:0", + "sat": "def sat(n: int):\n i = n ** 17 + 9\n j = (n + 1) ** 17 + 9\n\n while i != 0: # compute gcd using Euclid's algorithm\n (i, j) = (j % i, i)\n\n return n >= 0 and j != 1", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find n for which gcd(n^17+9, (n+1)^17+9) != 1\"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "According to [this article](https://primes.utm.edu/glossary/page.php?sort=LawOfSmall), the smallest\nsolution is 8424432925592889329288197322308900672459420460792433", + "weight": 1.0 + }, + { + "name": "Znam:0", + "sat": "def sat(li: List[int], k=5):\n def prod(nums):\n ans = 1\n for i in nums:\n ans *= i\n return ans\n\n return min(li) > 1 and len(li) == k and all((1 + prod(li[:i] + li[i + 1:])) % li[i] == 0 for i in range(k))", + "ans_type": "List[int]", + "sol_header": "def sol(k=5):", + "sol_docstring": " \"\"\"Find k positive integers such that each integer divides (the product of the rest plus 1).\"\"\"", + "sol_bodies": [ + " n = 2\n prod = 1\n ans = []\n while len(ans) < k:\n ans.append(n)\n prod *= n\n n = prod + 1\n return ans" + ], + "module": "number_theory.py", + "notes": "[Znam's Problem](https://en.wikipedia.org/wiki/Zn%C3%A1m%27s_problem)\n\nFor example [2, 3, 7, 47, 395] is a solution for k=5", + "weight": 1.0 + }, + { + "name": "CollatzCycleUnsolved:0", + "sat": "def sat(n: int):\n m = n\n while n > 4:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == m:\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n > 4 which is part of a cycle of this process\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Collatz Conjecture\n\nA solution to this problem would disprove the *Collatz Conjecture*, also called the *3n + 1 problem*,\nas well as the *Generalized Collatz Conjecture* (see the next problem).\nAccording to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture):\n> Paul Erdos said about the Collatz conjecture: \"Mathematics may not be ready for such problems.\"\n> He also offered US$500 for its solution. Jeffrey Lagarias stated in 2010 that the Collatz conjecture\n> \"is an extraordinarily difficult problem, completely out of reach of present day mathematics.\"\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\n\nThe conjecture is to that all `n > 0` eventually reach `n=1`. If this conjecture is false, then\nthere is either a cycle or a sequence that increases without bound. This problem seeks a cycle.", + "weight": 1.0 + }, + { + "name": "CollatzGeneralizedUnsolved:0", + "sat": "def sat(start: int):\n n = start # could be positive or negative ...\n while abs(n) > 1000:\n n = 3 * n + 1 if n % 2 else n // 2\n if n == start:\n return True", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find n which is part of a cycle of this process that has |n| > 1000\n \"\"\"", + "sol_bodies": [], + "module": "number_theory.py", + "notes": "Generalized Collatz Conjecture\n\nThis version, permits negative n and seek a cycle with a number of magnitude greater than 1000,\nwhich would disprove the Generalized conjecture that states that the only cycles are the known 5 cycles\n(which don't have positive integers).\n\nSee the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)", + "weight": 1.0 + }, + { + "name": "CollatzDelay:0", + "sat": "def sat(n: int, t=197, upper=20):\n m = n\n for i in range(t):\n if n <= 1:\n return False\n n = 3 * n + 1 if n % 2 else n // 2\n return n == 1 and m <= 2 ** upper", + "ans_type": "int", + "sol_header": "def sol(t=197, upper=20):", + "sol_docstring": " \"\"\"\n Consider the following process. Start with an integer `n` and repeatedly applying the operation:\n * if n is even, divide n by 2,\n * if n is odd, multiply n by 3 and add 1\n Find `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n \"\"\"", + "sol_bodies": [ + " # Faster solution for simultaneously solving multiple problems is of course possible\n bound = t + 10\n while True:\n bound *= 2\n prev = {1}\n seen = set()\n for delay in range(t):\n seen.update(prev)\n curr = {2 * n for n in prev}\n curr.update({(n - 1) // 3 for n in prev if n % 6 == 4})\n prev = {n for n in curr if n <= bound} - seen\n if prev:\n return min(prev)" + ], + "module": "number_theory.py", + "notes": "Collatz Delay\n\nConsider the following process. Start with an integer `n` and repeatedly applying the operation:\n* if n is even, divide n by 2,\n* if n is odd, multiply n by 3 and add 1\nFind `0 < n < upper` so that it takes exactly `t` steps to reach 1.\n\n\nFor instance,\nthe number `n=9780657630` takes 1,132 steps and the number `n=93,571,393,692,802,302` takes\n2,091 steps, according to the [Wikipedia article](https://en.wikipedia.org/wiki/Collatz_conjecture)\n\nNow, this problem can be solved trivially by taking exponentially large `n = 2 ** t` so we also bound the\nnumber of bits of the solution to be upper.\n\nSee [this webpage](http://www.ericr.nl/wondrous/delrecs.html) for up-to-date records.", + "weight": 1.0 + }, + { + "name": "Lehmer:0", + "sat": "def sat(n: int):\n return pow(2, n, n) == 3", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find n such that 2^n mod n = 3\"\"\"", + "sol_bodies": [ + " return 4700063497" + ], + "module": "number_theory.py", + "notes": "Lehmer puzzle\n\nAccording to [The Strong Law of Large Numbers](https://doi.org/10.2307/2322249) Richard K. Guy states that\n D. H. & Emma Lehmer discovered that 2^n = 3 (mod n) for n = 4700063497,\n but for no smaller n > 1", + "weight": 1.0 + }, + { + "name": "BirthdayParadox:0", + "sat": "def sat(n: int, year_len=365):\n prob = 1.0\n for i in range(n):\n prob *= (year_len - i) / year_len\n return (prob - 0.5) ** 2 <= 1/year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=365):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" + ], + "module": "probability.py", + "notes": "Adaptation of the classic\n[Birthday Problem](https://en.wikipedia.org/wiki/Birthday_problem (Mathematical Problems category)).\n\nThe year length is year_len (365 is earth, while Neptune year is 60,182).", + "weight": 1.0 + }, + { + "name": "BirthdayParadoxMonteCarlo:0", + "sat": "def sat(n: int, year_len=365):\n import random\n random.seed(0)\n K = 1000 # number of samples\n prob = sum(len({random.randrange(year_len) for i in range(n)}) < n for j in range(K)) / K\n return (prob - 0.5) ** 2 <= year_len", + "ans_type": "int", + "sol_header": "def sol(year_len=365):", + "sol_docstring": " \"\"\"Find n such that the probability of two people having the same birthday in a group of n is near 1/2.\"\"\"", + "sol_bodies": [ + " n = 1\n distinct_prob = 1.0\n best = (0.5, 1) # (difference between probability and 1/2, n)\n while distinct_prob > 0.5:\n distinct_prob *= (year_len - n) / year_len\n n += 1\n best = min(best, (abs(0.5 - distinct_prob), n))\n\n return best[1]" + ], + "module": "probability.py", + "notes": "A slower, Monte Carlo version of the above Birthday Paradox problem.", + "weight": 1.0 + }, + { + "name": "BallotProblem:0", + "sat": "def sat(counts: List[int], target_prob=0.5):\n m, n = counts # m = num 1's, n = num -1's\n probs = [1.0] + [0.0] * n # probs[n] is probability for current m, starting with m = 1\n for i in range(2, m + 1): # compute probs using dynamic programming for m = i\n old_probs = probs\n probs = [1.0] + [0.0] * n\n for j in range(1, min(n + 1, i)):\n probs[j] = (\n j / (i + j) * probs[j - 1] # last element is a -1 so use probs\n +\n i / (i + j) * old_probs[j] # last element is a 1 so use old_probs, m = i - 1\n )\n return abs(probs[n] - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(target_prob=0.5):", + "sol_docstring": " \"\"\"\n Suppose a list of m 1's and n -1's are permuted at random.\n What is the probability that all of the cumulative sums are positive?\n The goal is to find counts = [m, n] that make the probability of the ballot problem close to target_prob.\n \"\"\"", + "sol_bodies": [ + " for m in range(1, 10000):\n n = round(m * (1 - target_prob) / (1 + target_prob))\n if abs(target_prob - (m - n) / (m + n)) < 1e-6:\n return [m, n]" + ], + "module": "probability.py", + "notes": "See the [Wikipedia article](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem) or\nor [Addario-Berry L., Reed B.A. (2008) Ballot Theorems, Old and New. In: Gyori E., Katona G.O.H., Lov\u00e1sz L.,\nS\u00e1gi G. (eds) Horizons of Combinatorics. Bolyai Society Mathematical Studies, vol 17.\nSpringer, Berlin, Heidelberg.](https://doi.org/10.1007/978-3-540-77200-2_1)", + "weight": 1.0 + }, + { + "name": "BinomialProbabilities:0", + "sat": "def sat(counts: List[int], p=0.5, target_prob=0.0625):\n from itertools import product\n a, b = counts\n n = a + b\n prob = (p ** a) * ((1-p) ** b)\n tot = sum([prob for sample in product([0, 1], repeat=n) if sum(sample) == a])\n return abs(tot - target_prob) < 1e-6", + "ans_type": "List[int]", + "sol_header": "def sol(p=0.5, target_prob=0.0625):", + "sol_docstring": " \"\"\"Find counts = [a, b] so that the probability of a H's and b T's among a + b coin flips is ~ target_prob.\"\"\"", + "sol_bodies": [ + " probs = [1.0]\n q = 1 - p\n while len(probs) < 20:\n probs = [(p * a + q * b) for a, b in zip([0] + probs, probs + [0])]\n answers = [i for i, p in enumerate(probs) if abs(p - target_prob) < 1e-6]\n if answers:\n return [answers[0], len(probs) - 1 - answers[0]]" + ], + "module": "probability.py", + "notes": "See [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution)", + "weight": 1.0 + }, + { + "name": "ExponentialProbability:0", + "sat": "def sat(p_stop: float, steps=10, target_prob=0.5):\n prob = sum(p_stop*(1-p_stop)**t for t in range(steps))\n return abs(prob - target_prob) < 1e-6", + "ans_type": "float", + "sol_header": "def sol(steps=10, target_prob=0.5):", + "sol_docstring": " \"\"\"\n Find p_stop so that the probability of stopping in steps or fewer time steps is the given target_prob if you\n stop each step with probability p_stop\n \"\"\"", + "sol_bodies": [ + " return 1 - (1 - target_prob) ** (1.0/steps)" + ], + "module": "probability.py", + "notes": "See [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution)", + "weight": 1.0 + }, + { + "name": "HelloWorld:0", + "sat": "def sat(s: str):\n return s + 'world' == 'Hello world'", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when concatenated onto 'world' gives 'Hello world'.\"\"\"", + "sol_bodies": [], + "module": "trivial_inverse.py", + "notes": "Trivial example, no solutions provided", + "weight": 0.2 + }, + { + "name": "BackWorlds:0", + "sat": "def sat(s: str):\n return s[::-1] + 'world' == 'Hello world'", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when reversed and concatenated onto 'world' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return ' olleH'", + " # solution methods must begin with 'sol'\n return 'Hello '[::-1]" + ], + "module": "trivial_inverse.py", + "notes": "We provide two solutions", + "weight": 0.2 + }, + { + "name": "StrAdd:0", + "sat": "def sat(st: str, a=\"world\", b=\"Hello world\"):\n return st + a == b", + "ans_type": "str", + "sol_header": "def sol(a=\"world\", b=\"Hello world\"):", + "sol_docstring": " \"\"\"Solve simple string addition problem.\"\"\"", + "sol_bodies": [ + " return b[:len(b) - len(a)]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrSetLen:0", + "sat": "def sat(s: str, dups=2021):\n return len(set(s)) == len(s) - dups", + "ans_type": "str", + "sol_header": "def sol(dups=2021):", + "sol_docstring": " \"\"\"Find a string with dups duplicate chars\"\"\"", + "sol_bodies": [ + " return \"a\" * (dups + 1)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrMul:0", + "sat": "def sat(s: str, target=\"foofoofoofoo\", n=2):\n return s * n == target", + "ans_type": "str", + "sol_header": "def sol(target=\"foofoofoofoo\", n=2):", + "sol_docstring": " \"\"\"Find a string which when repeated n times gives target\"\"\"", + "sol_bodies": [ + " if n == 0:\n return ''\n return target[:len(target) // n]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrMul2:0", + "sat": "def sat(n: int, target=\"foofoofoofoo\", s=\"foofoo\"):\n return s * n == target", + "ans_type": "int", + "sol_header": "def sol(target=\"foofoofoofoo\", s=\"foofoo\"):", + "sol_docstring": " \"\"\"Find n such that s repeated n times gives target\"\"\"", + "sol_bodies": [ + " if len(s) == 0:\n return 1\n return len(target) // len(s)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrLen:0", + "sat": "def sat(s: str, n=1000):\n return len(s) == n", + "ans_type": "str", + "sol_header": "def sol(n=1000):", + "sol_docstring": " \"\"\"Find a string of length n\"\"\"", + "sol_bodies": [ + " return 'a' * n" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrAt:0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):", + "sol_docstring": " \"\"\"Find the index of target in string s\"\"\"", + "sol_bodies": [ + " return s.index(target)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrNegAt:0", + "sat": "def sat(i: int, s=\"cat\", target=\"a\"):\n return s[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(s=\"cat\", target=\"a\"):", + "sol_docstring": " \"\"\"Find the index of target in s using a negative index.\"\"\"", + "sol_bodies": [ + " return - (len(s) - s.index(target))" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrSlice:0", + "sat": "def sat(inds: List[int], s=\"hello world\", target=\"do\"):\n i, j, k = inds\n return s[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(s=\"hello world\", target=\"do\"):", + "sol_docstring": " \"\"\"Find the three slice indices that give the specific target in string s\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(s) - 1, len(s) + 1), repeat=3):\n try:\n if s[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrIndex:0", + "sat": "def sat(s: str, big_str=\"foobar\", index=2):\n return big_str.index(s) == index", + "ans_type": "str", + "sol_header": "def sol(big_str=\"foobar\", index=2):", + "sol_docstring": " \"\"\"Find a string whose *first* index in big_str is index\"\"\"", + "sol_bodies": [ + " return big_str[index:]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrIndex2:0", + "sat": "def sat(big_str: str, sub_str=\"foobar\", index=2):\n return big_str.index(sub_str) == index", + "ans_type": "str", + "sol_header": "def sol(sub_str=\"foobar\", index=2):", + "sol_docstring": " \"\"\"Find a string whose *first* index of sub_str is index\"\"\"", + "sol_bodies": [ + " i = ord('A')\n while chr(i) in sub_str:\n i += 1\n return chr(i) * index + sub_str" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrIn:0", + "sat": "def sat(s: str, a=\"hello\", b=\"yellow\", length=4):\n return len(s) == length and s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=\"hello\", b=\"yellow\", length=4):", + "sol_docstring": " \"\"\"Find a string of length length that is in both strings a and b\"\"\"", + "sol_bodies": [ + " for i in range(len(a) - length + 1):\n if a[i:i + length] in b:\n return a[i:i + length]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrIn2:0", + "sat": "def sat(substrings: List[str], s=\"hello\", count=15):\n return len(substrings) == len(set(substrings)) >= count and all(sub in s for sub in substrings)", + "ans_type": "List[str]", + "sol_header": "def sol(s=\"hello\", count=15):", + "sol_docstring": " \"\"\"Find a list of >= count distinct strings that are all contained in s\"\"\"", + "sol_bodies": [ + " return [\"\"] + sorted({s[j:i] for i in range(len(s) + 1) for j in range(i)})" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrCount:0", + "sat": "def sat(string: str, substring=\"a\", count=10, length=100):\n return string.count(substring) == count and len(string) == length", + "ans_type": "str", + "sol_header": "def sol(substring=\"a\", count=10, length=100):", + "sol_docstring": " \"\"\"Find a string with a certain number of copies of a given substring and of a given length\"\"\"", + "sol_bodies": [ + " c = chr(1 + max(ord(c) for c in (substring or \"a\"))) # a character not in substring\n return substring * count + (length - len(substring) * count) * '^'" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrSplit:0", + "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!'], length=100):\n return len(x) == length and x.split() == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['I', 'love', 'dumplings', '!'], length=100):", + "sol_docstring": " \"\"\"Find a string of a given length with a certain split\"\"\"", + "sol_bodies": [ + " joined = \" \".join(parts)\n return joined + \" \" * (length - len(joined))" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrSplitter:0", + "sat": "def sat(x: str, parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):\n return string.split(x) == parts", + "ans_type": "str", + "sol_header": "def sol(parts=['I', 'love', 'dumplings', '!', ''], string=\"I_love_dumplings_!_\"):", + "sol_docstring": " \"\"\"Find a separator that when used to split a given string gives a certain result\"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return string * 2\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrJoiner:0", + "sat": "def sat(x: str, parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):\n return x.join(parts) == string", + "ans_type": "str", + "sol_header": "def sol(parts=['I!!', '!love', 'dumplings', '!', ''], string=\"I!!!!!love!!dumplings!!!!!\"):", + "sol_docstring": " \"\"\"\n Find a separator that when used to join a given string gives a certain result.\n This is related to the previous problem but there are some edge cases that differ.\n \"\"\"", + "sol_bodies": [ + " if len(parts) <= 1:\n return \"\"\n length = (len(string) - len(\"\".join(parts))) // (len(parts) - 1)\n start = len(parts[0])\n return string[start:start + length]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "StrParts:0", + "sat": "def sat(parts: List[str], sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):\n return sep.join(parts) == string and all(sep not in p for p in parts)", + "ans_type": "List[str]", + "sol_header": "def sol(sep=\"!!\", string=\"I!!!!!love!!dumplings!!!!!\"):", + "sol_docstring": " \"\"\"Find parts that when joined give a specific string.\"\"\"", + "sol_bodies": [ + " return string.split(sep)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListSetLen:0", + "sat": "def sat(li: List[int], dups=42155):\n return len(set(li)) == len(li) - dups", + "ans_type": "List[int]", + "sol_header": "def sol(dups=42155):", + "sol_docstring": " \"\"\"Find a list with a certain number of duplicate items\"\"\"", + "sol_bodies": [ + " return [1] * (dups + 1)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListMul:0", + "sat": "def sat(li: List[int], target=[17, 9, -1, 17, 9, -1], n=2):\n return li * n == target", + "ans_type": "List[int]", + "sol_header": "def sol(target=[17, 9, -1, 17, 9, -1], n=2):", + "sol_docstring": " \"\"\"Find a list that when multiplied n times gives the target list\"\"\"", + "sol_bodies": [ + " if n == 0:\n return []\n return target[:len(target) // n]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListLen:0", + "sat": "def sat(li: List[int], n=85012):\n return len(li) == n", + "ans_type": "List[int]", + "sol_header": "def sol(n=85012):", + "sol_docstring": " \"\"\"Find a list of a given length n\"\"\"", + "sol_bodies": [ + " return [1] * n" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListAt:0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=18):\n return li[i] == target", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=18):", + "sol_docstring": " \"\"\"Find the index of an item in a list. Any such index is fine.\"\"\"", + "sol_bodies": [ + " return li.index(target)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListNegAt:0", + "sat": "def sat(i: int, li=[17, 31, 91, 18, 42, 1, 9], target=91):\n return li[i] == target and i < 0", + "ans_type": "int", + "sol_header": "def sol(li=[17, 31, 91, 18, 42, 1, 9], target=91):", + "sol_docstring": " \"\"\"Find the index of an item in a list using negative indexing.\"\"\"", + "sol_bodies": [ + " return li.index(target) - len(li)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListSlice:0", + "sat": "def sat(inds: List[int], li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):\n i, j, k = inds\n return li[i:j:k] == target", + "ans_type": "List[int]", + "sol_header": "def sol(li=[42, 18, 21, 103, -2, 11], target=[-2, 21, 42]):", + "sol_docstring": " \"\"\"Find three slice indices to achieve a given list slice\"\"\"", + "sol_bodies": [ + " from itertools import product\n for i, j, k in product(range(-len(li) - 1, len(li) + 1), repeat=3):\n try:\n if li[i:j:k] == target:\n return [i, j, k]\n except (IndexError, ValueError):\n pass" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListIndex:0", + "sat": "def sat(item: int, li=[17, 2, 3, 9, 11, 11], index=4):\n return li.index(item) == index", + "ans_type": "int", + "sol_header": "def sol(li=[17, 2, 3, 9, 11, 11], index=4):", + "sol_docstring": " \"\"\"Find the item whose first index in li is index\"\"\"", + "sol_bodies": [ + " return li[index]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListIndex2:0", + "sat": "def sat(li: List[int], i=29, index=10412):\n return li.index(i) == index", + "ans_type": "List[int]", + "sol_header": "def sol(i=29, index=10412):", + "sol_docstring": " \"\"\"Find a list that contains i first at index index\"\"\"", + "sol_bodies": [ + " return [i - 1] * index + [i]" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "ListIn:0", + "sat": "def sat(s: str, a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):\n return s in a and s in b", + "ans_type": "str", + "sol_header": "def sol(a=['cat', 'dot', 'bird'], b=['tree', 'fly', 'dot']):", + "sol_docstring": " \"\"\"Find an item that is in both lists a and b\"\"\"", + "sol_bodies": [ + " return next(s for s in b if s in a)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntNeg:0", + "sat": "def sat(x: int, a=93252338):\n return -x == a", + "ans_type": "int", + "sol_header": "def sol(a=93252338):", + "sol_docstring": " \"\"\"Solve a unary negation problem\"\"\"", + "sol_bodies": [ + " return - a" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntSum:0", + "sat": "def sat(x: int, a=1073258, b=72352549):\n return a + x == b", + "ans_type": "int", + "sol_header": "def sol(a=1073258, b=72352549):", + "sol_docstring": " \"\"\"Solve a sum problem\"\"\"", + "sol_bodies": [ + " return b - a" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntSub:0", + "sat": "def sat(x: int, a=-382, b=14546310):\n return x - a == b", + "ans_type": "int", + "sol_header": "def sol(a=-382, b=14546310):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a + b" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntSub2:0", + "sat": "def sat(x: int, a=8665464, b=-93206):\n return a - x == b", + "ans_type": "int", + "sol_header": "def sol(a=8665464, b=-93206):", + "sol_docstring": " \"\"\"Solve a subtraction problem\"\"\"", + "sol_bodies": [ + " return a - b" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntMul:0", + "sat": "def sat(n: int, a=14302, b=5):\n return b * n + (a % b) == a", + "ans_type": "int", + "sol_header": "def sol(a=14302, b=5):", + "sol_docstring": " \"\"\"Solve a multiplication problem\"\"\"", + "sol_bodies": [ + " return a // b" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntDiv:0", + "sat": "def sat(n: int, a=3, b=23463462):\n return b // n == a", + "ans_type": "int", + "sol_header": "def sol(a=3, b=23463462):", + "sol_docstring": " \"\"\"Solve a division problem\"\"\"", + "sol_bodies": [ + " if a == 0:\n return 2 * b\n for n in [b // a, b // a - 1, b // a + 1]:\n if b // n == a:\n return n" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntDiv2:0", + "sat": "def sat(n: int, a=345346363, b=10):\n return n // b == a", + "ans_type": "int", + "sol_header": "def sol(a=345346363, b=10):", + "sol_docstring": " \"\"\"Find n that when divided by b is a\"\"\"", + "sol_bodies": [ + " return a * b" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntSquareRoot:0", + "sat": "def sat(x: int, a=10201202001):\n return x ** 2 == a", + "ans_type": "int", + "sol_header": "def sol(a=10201202001):", + "sol_docstring": " \"\"\"Compute an integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return int(a ** 0.5)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "IntNegSquareRoot:0", + "sat": "def sat(n: int, a=10000200001):\n return a == n * n and n < 0", + "ans_type": "int", + "sol_header": "def sol(a=10000200001):", + "sol_docstring": " \"\"\"Find a negative integer that when squared equals perfect-square a.\"\"\"", + "sol_bodies": [ + " return -int(a ** 0.5)" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "FloatSquareRoot:0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3", + "ans_type": "float", + "sol_header": "def sol(a=1020):", + "sol_docstring": " \"\"\"Find a number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return a ** 0.5" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "FloatNegSquareRoot:0", + "sat": "def sat(x: float, a=1020):\n return abs(x ** 2 - a) < 10 ** -3 and x < 0", + "ans_type": "float", + "sol_header": "def sol(a=1020):", + "sol_docstring": " \"\"\"Find a negative number that when squared is close to a.\"\"\"", + "sol_bodies": [ + " return -a ** 0.5" + ], + "module": "trivial_inverse.py", + "notes": "", + "weight": 0.2 + }, + { + "name": "Tutorial1:0", + "sat": "def sat(s: str):\n return \"Hello \" + s == \"Hello world\"", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return \"world\"" + ], + "module": "tutorial.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Tutorial2:0", + "sat": "def sat(s: str):\n return \"Hello \" + s[::-1] == \"Hello world\"", + "ans_type": "str", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.\"\"\"", + "sol_bodies": [ + " return \"world\"[::-1]" + ], + "module": "tutorial.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Tutorial3:0", + "sat": "def sat(x: List[int]):\n return len(x) == 2 and sum(x) == 3", + "ans_type": "List[int]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of two integers whose sum is 3.\"\"\"", + "sol_bodies": [ + " return [1, 2]" + ], + "module": "tutorial.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Tutorial4:0", + "sat": "def sat(s: List[str]):\n return len(set(s)) == 1000 and all((x.count(\"a\") > x.count(\"b\")) and ('b' in x) for x in s)", + "ans_type": "List[str]", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.\"\"\"", + "sol_bodies": [ + " return [\"a\" * (i + 2) + \"b\" for i in range(1000)]" + ], + "module": "tutorial.py", + "notes": "", + "weight": 1.0 + }, + { + "name": "Tutorial5:0", + "sat": "def sat(n: int):\n return str(n * n).startswith(\"123456789\")", + "ans_type": "int", + "sol_header": "def sol():", + "sol_docstring": " \"\"\"Find an integer whose perfect square begins with 123456789 in its decimal representation.\"\"\"", + "sol_bodies": [ + " return int(int(\"123456789\" + \"0\" * 9) ** 0.5) + 1" + ], + "module": "tutorial.py", + "notes": "", + "weight": 1.0 + } +] \ No newline at end of file diff --git a/solvers/codex/README.md b/solvers/codex/README.md new file mode 100644 index 0000000..61dcfc1 --- /dev/null +++ b/solvers/codex/README.md @@ -0,0 +1,29 @@ +# Running GPT-3 experiments + +These are instructions for re-running the Codex experiments. The results will be slightly different than those in +the paper because the API is non-deterministic. + +The requirements can be installed with `pip3 install -r requirements.txt`. + +`run_codex_experiments.py` runs the Codex experiments and prints the results to stdout. Change the +parameters in that file to run it on the 397puzzles (v0.2) or 138puzzles.json (v0.1 used in +first experiment) or 30puzzles.json (study) +or to use the davinci-codex engine vs cushman-codex. + +## Installation and execution. +You will need an open-ai Codex API access key which can be signed up for [here](https://openai.com/join/). +You will then need to set it as the `OPENAI_API_KEY` environmnet variable. If you want an extension added +to the engines such as "-msft", set the environment variable `export OPEN_AI_ENGINE_SUFFIX=-msft`. +We also recommend that you set the environment variable `export PYTHONHASHSEED=0` for determinism. + +The requirements can be installed with `pip3 install -r requirements.txt`. + +It was run with Python 3.6.9, sys.version = '3.6.9 (default, Jan 26 2021, 15:33:00) \n[GCC 8.4.0]', but should +be compatible with later versions as well. + +Then you simply run +`python run_codex_experiments.py`. It uses cacheing mechanisms with the first run +being quite slow and verbose, querying the API. However you can subsequently run it again and it will be +much faster and just output the results. The cacheing makes it deterministic so it should give the same +exact results when re-run. + diff --git a/solvers/codex/ezlog.py b/solvers/codex/ezlog.py new file mode 100644 index 0000000..3989b6d --- /dev/null +++ b/solvers/codex/ezlog.py @@ -0,0 +1,85 @@ +import os +import logging +import inspect +import io + +my_path = os.path.dirname(__file__) + + +def color_str(obj, code="\033[0;36m"): + return code + str(obj) + '\033[0m' + + +_configured = False + + +def configure_logging(stdio_level=logging.INFO, + file_level=logging.DEBUG, + filename=".easy.log", + filepath=os.path.join(my_path, "logs")): + os.makedirs(filepath, exist_ok=True) + filename = os.path.join(filepath, filename) + global _configured + if _configured: + warning("Re-configuring logging") + stdio_handler = logging.StreamHandler() + stdio_handler.setLevel(stdio_level) + file_hanlder = logging.FileHandler(filename) + file_hanlder.setLevel(file_level) + + logging.basicConfig( + format="%(asctime)s - %(levelname)s - %(name)s - %(message).200s", + datefmt="%m/%d/%Y %H:%M:%S", + level=min(stdio_level, file_level), + handlers=[stdio_handler, file_hanlder] + ) + + _configured = True + _get_or_create_logger().debug("Configured logging") + + +_loggers = {} + + +def _get_or_create_logger(): + global _configured, _loggers + if not _configured: + configure_logging() + try: + for frame in inspect.stack(): + name = inspect.getmodule(frame[0]).__name__ + if name != __name__: + break + except: + name = "_" + if name not in _loggers: + _loggers[name] = logging.getLogger(name) + return _loggers[name] + + +def print_to_string(*args, end="", **kwargs): + with io.StringIO() as buf: + print(*args, file=buf, end=end, **kwargs) + return buf.getvalue() + + +def debug(*args, **kwargs): + _get_or_create_logger().debug(print_to_string(*args, **kwargs)) + + +def info(*args, **kwargs): + _get_or_create_logger().info(print_to_string(*args, **kwargs)) + + +log = info + + +def warning(*args, **kwargs): + _get_or_create_logger().warning(print_to_string(*args, **kwargs)) + + +warn = warning + + +def error(*args, **kwargs): + _get_or_create_logger().error(print_to_string(*args, **kwargs)) diff --git a/solvers/codex/lm_solve/__init__.py b/solvers/codex/lm_solve/__init__.py new file mode 100644 index 0000000..e1fe3ba --- /dev/null +++ b/solvers/codex/lm_solve/__init__.py @@ -0,0 +1 @@ +from lm_solve.run import * diff --git a/solvers/codex/lm_solve/gpt_lib.py b/solvers/codex/lm_solve/gpt_lib.py new file mode 100644 index 0000000..26d6529 --- /dev/null +++ b/solvers/codex/lm_solve/gpt_lib.py @@ -0,0 +1,163 @@ +import os +import json +import openai +import ezlog +import time +import datetime + +assert 'OPENAI_API_KEY' in os.environ, "Need to set environment variable `OPENAI_API_KEY`" +openai.api_key = os.environ['OPENAI_API_KEY'] +OPEN_AI_ENGINE_SUFFIX = os.environ.get('OPEN_AI_ENGINE_SUFFIX', '') # add extension such as -msft to engine names + +_CACHE_PATH = os.path.join(os.path.dirname(__file__), "../.cache") +_CACHE_ENCODING = "utf-8" + + +# the cache file is just a list of (query params dictionary encoded as a string but without n, result list) +# multiple queries with the same params (except for n) are merged into a single big list +class Cache: + def __init__(self, filename): + self.filename = filename + self._cache = None + + def _load_cache(self): + """for lazy loading""" + assert self._cache is None, "gpt cache already loaded" + + if not os.path.exists(_CACHE_PATH): + ezlog.warn("Creating cache path") + os.makedirs(_CACHE_PATH) + + self._cache = {} + + if os.path.exists(self.filename): + time0 = time.perf_counter() + with open(self.filename, "r", encoding=_CACHE_ENCODING) as f: + for k, v in [eval(line) for line in f.readlines()]: + if k not in self._cache: + self._cache[k] = v + else: + self._cache[k].extend(v) + ezlog.info(f"Loaded cache `{self.filename}` in {time.perf_counter() - time0:.1f}s") + else: + ezlog.warn("No gpt cache yet") + + def defrag(self): + if self._cache is None: + self._load_cache() + + # def helper(k): # remove max_batch + # k2 = eval(k) + # del k2["max_batch"] + # return str(k2) + + if self._cache: + with open(self.filename, "w", encoding=_CACHE_ENCODING) as f: + # f.write("\n".join([str((helper(k), v)) for k, v in self._cache.items()]+[""])) + f.write("\n".join([str((k, v)) for k, v in self._cache.items()]+[""])) + ezlog.info("Defragged cache") + else: + ezlog.warn("No cache to defrag") + + + def get(self, item): + if self._cache is None: + self._load_cache() + + return self._cache.get(item, []).copy() # no monkey business changing cache + + def extend(self, key, values): + if self._cache is None: + self._load_cache() + + v = self._cache.setdefault(key, []) + v.extend(values) + + with open(self.filename, "a", encoding=_CACHE_ENCODING) as f: + f.write(str((key, values)) + "\n") + + return v.copy() # no monkey business changing cache + + +BATCH_SIZES = { + "davinci": 32, + "davinci-codex": 128, + "cushman-codex": 128 +} + +CACHES = {cache: Cache(os.path.join(_CACHE_PATH, cache + ".cache")) for cache in BATCH_SIZES} + +def query(prompt, n=10, max_tokens=150, temp=1.0, stop=None, notes=None, cache_only=False, verbose=True, + max_retries=10, engine="cushman-codex"): + """Query gpt + + :param prompt: Up to 2048 tokens (about 3-4k chars) + :param n: number of answers, None returns all cached answers + :param max_tokens: + :param temp: 0.9 seems to work well + :param stop: string to stop at or '' if not to stop + :param notes: notes you want to save or change in case you want to run the same query more than once! + :return: list of answers and then the response items + """ + global BATCH_SIZES + global CACHES + cur_cache = CACHES[engine] + max_batch = BATCH_SIZES[engine] + engine += OPEN_AI_ENGINE_SUFFIX # add tail to engine name + + if temp == 0 and n > 1: + ezlog.debug("Temp 0: no point in running more than one query") + n = 1 + + key = str(dict(prompt=prompt, max_tokens=max_tokens, temp=temp, stop=stop, rep=notes)) + + cached = cur_cache.get(key) + + if n is None: + return cached + + if len(cached) >= n: + return cached[:n] + + assert not cache_only, f'Entry not found in cache with prompt "{json.dumps(prompt)}"' + if verbose: + print("/" * 100) + print(f"Querying GPT {engine} with prompt:") + print(prompt) + s = stop and stop.replace('\n', '\\n') + print(f"/// n={n} ({n - len(cached)} new) max_tokens={max_tokens} temp={temp} max_batch={max_batch} stop={s}") + print("/" * 100) + + time0 = time.perf_counter() + + new = [] + n -= len(cached) + + while n > 0: + m = min(n, max_batch) + + try_number = 0 + while True: + try: + res = openai.Completion.create( + engine=engine, + prompt=prompt, + max_tokens=max_tokens, + temperature=temp, + n=m, + stop=stop or None + ) + break + except (openai.error.RateLimitError, openai.error.APIError): + if try_number == max_retries: + print("Rate limit error: Giving up!") + raise + sleep_secs = 10 * (2 ** try_number) + try_number += 1 + print(f"Rate limit error #{try_number}: Sleeping for {sleep_secs} seconds...") + time.sleep(sleep_secs) + + new += [c["text"] for c in res["choices"]] + n -= m + + return cur_cache.extend(key, new) diff --git a/solvers/codex/lm_solve/judge.py b/solvers/codex/lm_solve/judge.py new file mode 100644 index 0000000..cd07fea --- /dev/null +++ b/solvers/codex/lm_solve/judge.py @@ -0,0 +1,330 @@ +import hashlib +import os +import time +from utils import load_json +from pebble import ProcessPool +import multiprocessing as mp +from concurrent.futures import TimeoutError +from typing import List, Set, Tuple, Dict, Union, Any +from tqdm import tqdm +import functools + +import utils +import ezlog +import signal +import sys + +sys.setrecursionlimit(5000) + + +def _COPY(x): + return x + + +_ENV = dict( + List=List, + Set=Set, + Tuple=Tuple, + Dict=Dict, + COPY=_COPY, + type_check=utils.type_check, + test_puzzle=utils.test_puzzle, + os=None, + sys=None, + input=None, + open=None, + print=None, + compile=None, + copyright=None, +) +_UNSAFE = ["import", "builtin", "__class", "open("] + +MAX_WORKERS = mp.cpu_count() // 2 + +_CACHE_PATH = os.path.join(os.path.dirname(__file__), "../.cache") # ".cache" + + +class SetCache: + """Simple cache that stores a set of keys. Cannot remove values. Haven't yet implemented iteration.""" + + BYTE_LEN = 256 // 8 # for sha256 + + def __init__(self, name, path=_CACHE_PATH): + self._path = path + self.name = name + self._filename = os.path.join(path, f"{name}_set.cache") + self._set = None # the main set, loaded lazily + + def update(self, keys): + self._load() + hashes = [self._hash(k) for k in keys] + additions = {h for h in hashes if h not in self._set} + + if additions: + with open(self._filename, "ab") as f: # append to binary file + for h in additions: + f.write(h) + self._set.update(additions) + + def add(self, key): + self.update([key]) + + def _hash(self, key): + return hashlib.sha256(bytes(str(key), encoding="utf8")).digest() + + def __contains__(self, key: str): + self._load() + h = self._hash(key) + return h in self._set + + def __delitem__(self, key): + raise NotImplementedError + + def __len__(self): + self._load() + return len(self._set) + + def _load(self): + if self._set is None: # only load if not already loaded + if not os.path.exists(self._path): + ezlog.warn(f"Creating path for `{self.name}` cache") + os.makedirs(self._path) + + time0 = time.perf_counter() + if os.path.exists(self._filename): + with open(self._filename, "rb") as f: # read binary file + data = f.read() + self._set = { + data[j : j + self.BYTE_LEN] for j in range(0, len(data), self.BYTE_LEN) + } + else: + self._set = set() + dur = time.perf_counter() - time0 + ezlog.info(f"Loaded `{self.name}` cache of {len(self):,} items in {dur:.1f}s") + + +# def judge_wrapped(code_env): +# p = mp.Process(target=_judge) +# p.start() +# p.join(timeout) +# if p.is_alive(): +# print("killing process") +# p.kill() +# p.join() + + +# def worker_init_fn(): +# sys.setrecursionlimit( +# 5000 +# ) # if this is too big then recursive programs can break the whole system +# global print +# print("New worker thread starting") + +# def handler(signum, frame): +# print("Caught SIGALRM, raising exception") +# raise TimeoutError("Timeout caught through SIGALRM") + +# old_print = print +# print = lambda *args, **kwargs: old_print(f"[Process {os.getpid()}]", *args, **kwargs) + +# # Set the signal handler and a 5-second alarm +# signal.signal(signal.SIGALRM, handler) + + +# def judge_wrapped(code_env, timeout): +# code, env = code_env +# print(code) +# try: +# signal.alarm(int(timeout)) +# res = _judge(code, env) +# signal.alarm(0) # disable the alarm +# return res +# except TimeoutError as e: +# return False, e, code +# finally: +# print(f"done with {code}") + + +def _judge(code_env): + code, env = code_env + for u in _UNSAFE: + if u in code: + return False, Exception(f'unsafe: "{u}" not allowed in code'), code + try: + _env = env.copy() + exec(code, _env) # not sure if copy() is necessary + return True, None, code + except Exception as e: + return False, e, code + + +# Cache judge results (which are nondeterministic due to timeout) for reproducibility +_judge_success = SetCache("judge_success") +_judged_batches = SetCache("judged_batches") + + +# def judge_parallel(src_codes, timeout: int, max_workers=MAX_WORKERS, env=_ENV, force_compute=False): +# if timeout > 0: +# assert timeout >= 1, "fractional timeout not supported, only ints (rounds down)" +# global _judge_success, _judged_batches +# # force_compute means no cache +# if force_compute or src_codes not in _judged_batches: +# new_codes = utils.dedup(code for code in src_codes if code not in _judge_success) +# if new_codes: +# ezlog.info( +# f"Judging {len(new_codes)}/{len(src_codes)} new codes (removing duplicates/things in cache)" +# ) +# successes = [] + +# print("writing to file for debugging before judging") +# from train import save_json + +# save_json(new_codes, "results/tmp/new_codes.json") + +# with mp.Pool(processes=max_workers, initializer=worker_init_fn) as pool: +# with tqdm(total=len(new_codes), desc="Judging") as pbar: +# for success, exc, code in pool.imap_unordered( +# func=functools.partial(judge_wrapped, timeout=timeout), +# iterable=[(code, env) for code in new_codes], +# ): +# if success: +# successes.append(code) +# else: +# print(exc) +# pbar.update() +# _judge_success.update(successes) +# _judged_batches.add(src_codes) +# return [code in _judge_success for code in src_codes] + + +def judge_parallel(src_codes, timeout, max_workers=MAX_WORKERS, env=_ENV, force_compute=False): + global _judge_success, _judged_batches + # force_compute means no cache + if force_compute or src_codes not in _judged_batches: + new_codes = utils.dedup(code for code in src_codes if code not in _judge_success) + if new_codes: + ezlog.info( + f"Judging {len(new_codes)}/{len(src_codes)} new codes (removing duplicates/things in cache)" + ) + successes = [] + + # print("writing to file for debugging before judging") + # from train import save_json + # + # save_json(new_codes, "results/tmp/new_codes.json") + + with ProcessPool(max_workers=max_workers) as pool: + future = pool.map(_judge, [(code, env) for code in new_codes], timeout=timeout) + + results = future.result() + + i = 0 + while True: + try: + success, exc, code = next(results) + if success: + successes.append(new_codes[i]) + except StopIteration: + _judge_success.update(successes) + break + except (TimeoutError, Exception) as error: + pass + assert i < len(new_codes) + i += 1 + assert i == len(new_codes) + _judged_batches.add(src_codes) + + return [code in _judge_success for code in src_codes] + + # itr = pool.imap_unordered( + # func=_judge, iterable=[(code, env) for code in new_codes] + # ) + # i = 0 + # while True: + # try: + # success, exc = itr.next(timeout) + # if success: + # successes.append(new_codes[i]) + # print("yay") + # except StopIteration: + # _judge_success.update(successes) + # break + # except (TimeoutError, Exception) as error: + # print(error) + # pass + # assert i < len(new_codes) + # i += 1 + # pbar.update() + # assert i == len(new_codes) + # _judged_batches.add(src_codes) + # return [code in _judge_success for code in src_codes] + + # future = pool.map(_judge, , timeout=timeout) + + # results = future.result() + + # i = 0 + # while True: + # try: + # success, exc = next(results) + # if success: + # successes.append(new_codes[i]) + # except StopIteration: + # _judge_success.update(successes) + # break + # except (TimeoutError, Exception) as error: + # pass + # assert i < len(new_codes) + # i += 1 + # assert i == len(new_codes) + # _judged_batches.add(src_codes) + + +if __name__ == "__main__": + import sys + import pebble + + # worker_init_fn() + # res = judge_wrapped(("while True: pass", _ENV), 1) + res = judge_parallel( + [ + "def sol(a: int=10000200001):\n return (list(range(3 * a))[str(a)])\nx = sol()", + "while True: pass", + "def sol(): sol()\nsol()", + "1", + ], + timeout=1, + ) + print(res) + + sys.exit(0) + + # res = judge_parallel(["def foo():\n foo()\nfoo()"], 1) + + # sys.exit(0) + # for code in load_json("results/tmp/new_codes.json"): + # print(code) + # judge_wrapped((code, _ENV), 1) + # sys.exit(0) + + judge_parallel(load_json("results/tmp/new_codes.json"), 1, max_workers=1) + + sys.exit(0) + res = judge_parallel( + [ + """1+1 + """, + """assert False,'cats'""", + """assert False""", + """1[2]""", + """1/0""", + """while True: + pass""", + """for i in range(10**5): + pass""", + ] + + [f"while True:\n {' '*n} pass" for n in range(60)], + timeout=1, + max_workers=4, + ) + print(res) diff --git a/solvers/codex/lm_solve/run.py b/solvers/codex/lm_solve/run.py new file mode 100644 index 0000000..8ea2c72 --- /dev/null +++ b/solvers/codex/lm_solve/run.py @@ -0,0 +1,490 @@ +""" +Run experiments. + +""" + +from typing import List, Tuple, Dict, Set +from collections import Counter +import utils +import ast +import time +import re +import astor +import json +import random +import inspect +from tqdm import tqdm +import sys +import os +import logging +import math + +from . import gpt_lib +from . import judge + + +os.environ["TOKENIZERS_PARALLELISM"] = "false" # to avoid parallelism warnings from transformer tokenizer +if os.environ["PYTHONHASHSEED"] != '0': + print("Warning, please set environment variable PYTHONHASHSEED to 0 for determinism") + +def get_prompts(prefix, fs, sol_headers, multi_line=False, test_prefix=True): + """adds function numbers after prompt""" + + ans = [] + if test_prefix: + exec(prefix, dict(List=List)) + + if "def f1(" in prefix: + i = 1 + while f"def f{i}(" in prefix: + i += 1 + else: + i = "" + + assert len(sol_headers) == len(fs) + for f, head in zip(fs, sol_headers): + f = f.replace("def f(", f"def f{i}(") + head = head.replace("def g(", f"def g{i}(" ) + head = head.replace("def sol(", f"def g{i}(") + if multi_line: + ans.append(f"{prefix}{f}\n\n{head}") + else: + ans.append(f"{prefix}{f}\n\nassert True == f{i}(") + return ans + + +def load_puzzles(filename, remove_docstring): + """Returns list of functions and solution headers, one puzzle per problem""" + JS = utils.load_json(filename) + fs = [] + sol_headers = [] + seen = set() + + for j in JS: + name = j["name"].split(":")[0] # just one puzzle per problem + if name in seen: + continue + seen.add(name) + f = j["sat"].replace("def sat", "def f") + + fs.append(f) + sol_headers.append(j["sol_header"].replace("def sol", "def g") + ("" if remove_docstring else "\n" + j["sol_docstring"])) + + return fs, sol_headers + +_std_errs = {"orig": os.dup(2), "devnull": os.open(os.devnull, os.O_RDWR)} + +def ast_parse_quiet(s: str): + global _std_errs + try: + os.dup2(_std_errs["devnull"], 2) # to avoid printing the s_push parser when parsing stuff with "((((()))))" + return ast.parse(s) + except: + pass + finally: + os.dup2(_std_errs["orig"], 2) + + +def find_end(st: str, multi_line: bool): + """Takes a solution and looks for the end that would make it parse.""" + if multi_line: + lines = st.split("\n") + for i in range(1, len(lines)): + line = lines[i] + if line and line[0] not in " \t": + lines = lines[:i] + break + ans = "\n".join(lines) + + if ast_parse_quiet("def g():" + ans): + return ans + else: + return None + + + for i, c in enumerate(st): + if c == ")": + if ast_parse_quiet("(" + st[:i + 1]): + return st[:i].strip() + return None + + +_tokenizer = None # used only in num_tokens +_tokenizer_old_version = False + +def num_tokens(s: str): + """Compute the number of tokens according to GPT""" + global _tokenizer, _tokenizer_old_version + if _tokenizer is None: + import transformers + _tokenizer = transformers.GPT2TokenizerFast.from_pretrained("gpt2") + _tokenizer_old_version = (len(_tokenizer.tokenize("\n\nx")) == 2) # different between transformer versions :-( + return len(_tokenizer.tokenize(s)) + (s.count("\n\n") if _tokenizer_old_version else 0) + + +def get_inputs(sat: str): + """Extacts arguments past the first from a function string + def f(a: Dict[int, str], b=12): + test + """ + sat = sat.replace(" -> bool", "") + first_line = sat.split("\n")[0].strip() + if "#" in first_line: + first_line = first_line[:first_line.index("#")].strip() + if not (first_line.endswith("):") and first_line.startswith("def")): + print("Weird puzzle, cannot extract inputs", json.dumps(sat)) + return "" + arg_str = first_line[first_line.index("("):-len("):")] + depth = 0 + for i, c in enumerate(arg_str): + if c == "," and depth == 0: + return arg_str[i + 1:].strip() + elif c == "[": + depth += 1 + elif c == "]": + depth -= 1 + return "" + +def solve_puzzles(filename_or_puzzles, prefix="", n=1000, temp=0.9, timeout=1.0, sep="###", + cache_only=False, seed=0, engine=None, + multi_line=True, limit=None): + if not prefix: + assert multi_line == False, "Cannot solve multi-line without a prompt" + if seed == 0: + seed = None + + stop = "\nassert" if multi_line else "\n" + + print("=" * 100) + print(f"Solving with {num_tokens(prefix)} prefix tokens, engine={engine}") + for k in locals().copy(): + print(f"param {k}: {json.dumps(locals()[k])[:100]}") + time0 = time.time() + + if isinstance(filename_or_puzzles, str): + puzzles = utils.load_json(filename_or_puzzles)[:limit] + print(f"Loaded {len(puzzles)} from `{filename_or_puzzles}`") + else: + puzzles = filename_or_puzzles[:limit] # zzz + print(f"Solving {len(puzzles)} given directly") + + sol_headers = [f"def g({get_inputs(f)}):" for f in puzzles] + prefix = re.sub(r" +$", "", (prefix or "").lstrip(), flags=re.M) # delete leading/trailing whitespace on each line + prompts = get_prompts(prefix, puzzles, sol_headers, multi_line) + + successes = [] + for p_num, (f, head, prompt) in tqdm(enumerate(zip(puzzles, sol_headers, prompts)), total=len(puzzles)): + res = gpt_lib.query(prompt=prompt, temp=temp, n=n, stop=stop, cache_only=cache_only, notes=seed, engine=engine) + assert len(res) == n + + valids = [(find_end(g, multi_line), i) for i, g in enumerate(res)] + valids = [(g, i) for (g, i) in valids if g is not None] + # double parentheses are necessary to avoid cheating where it changes default parameters :-) + if multi_line: + if "def f1(" in prompt: + for kk in range(1, 10000): + if f"def f{kk}(" not in prompt: + break + kk -= 1 + else: + kk = "" + valids = [(g.replace(f"f{kk}(", "f("), i) for (g, i) in valids] + results = judge.judge_parallel([f"{f}\n\n{head}{g}\n\nassert test_puzzle(f, g())" for g, _i in valids], + timeout=timeout) + else: + results = judge.judge_parallel([f"{f}\n\nassert test_puzzle(f, ({g}))" for g, _i in valids], timeout=timeout) + curr = [g for (g, i), res in zip(valids, results) if res] + successes.append((f, curr)) + # if curr: + # ans1 = [a for a, _i in curr] + # if verbose: + # print(p_num, "-" * 80) + # print(strip_param_annotations(f)) + # summary = [(a if c == 1 else f"{a} ({c} times)") for a, c in Counter(ans1).most_common(10)] + # print(f"{len(curr)} sols, first at attempt #{curr[0][1]}:: {' | '.join(summary)}"[:200]) + + n_sol = sum(bool(s) for f, s in successes) + n_suc = sum(len(s) for f, s in successes) + print(f"Solved {n_sol:,}/{len(puzzles):,} puzzles with a total of {n_suc:,} solutions.") + print() + + return successes + + +def prompt_experiment(filename, experiment="prompt", prefix="", n=1000, temp=0.9, timeout=1.0, + cache_only=False, remove_docstring=False, seed=0, engine=None, + verbose=False): + """ + Just run n attempts per puzzle + + n is the number of attempts per puzzle + temp is like 0.9 + timeout is judging timeout + cache_only means do not call GPT-3 LM but instead insist on loading from cache + seed makes it so that you can run the experiment more than once without hitting the cache again. + + returns a list of (f, correct answers) for each puzzle string f + where correct answers is a list of (string, index found) + """ + + multi_line = (prefix != "") + if not prefix: + assert multi_line == False, "Cannot have multi-line bootstrap without a prompt" + if seed == 0: + seed = None + + stop = "\nassert" if multi_line else "\n" + + print("=" * 100) + print(f"{experiment} expt, remove_docstring={remove_docstring}, engine={engine}, n={n:,}") + for k in locals().copy(): + print(f"param {k}: {json.dumps(locals()[k])[:100]}") + time0 = time.time() + + fs, sol_headers = load_puzzles(filename, remove_docstring) + + prefix = re.sub(r" +$", "", (prefix or "").lstrip(), flags=re.M) # delete leading/trailing whitespace on each line + prompts = get_prompts(prefix, fs, sol_headers, multi_line) + + sat_sols = [] + for p_num, (f, head, prompt) in tqdm(enumerate(zip(fs, sol_headers, prompts)), total=len(fs)): + # prompt2 = re.sub(r'\bg\d\(', 'sol(', re.sub(r'\bf\d\(', 'sat(', prompt)) + # prompt2 = re.sub(r'\bg(?=\d\()', 'sol', re.sub(r'\bf(?=\d\()', 'sat', prompt)) + # prompt2 = prompt + res = gpt_lib.query(prompt=prompt, temp=temp, n=n, stop=stop, cache_only=cache_only, + notes=seed, engine=engine, verbose=True) + assert len(res) == n + # print(i, "-" * 80) + # print(f) + # print + valids = [(find_end(g, multi_line), i) for i, g in enumerate(res)] + valids = [(g, i) for (g, i) in valids if g is not None] + if multi_line: + # valids = [(g.replace("sat(", "f("), i) for (g, i) in valids] + # valids = [(g.replace("sat6(", "f("), i) for (g, i) in valids] + valids = [(g.replace("f6(", "f("), i) for (g, i) in valids] + results = judge.judge_parallel([f"{f}\n\n{head}{g}\n\nassert test_puzzle(f, g())" for g, _i in valids], + timeout=timeout) + + else: + results = judge.judge_parallel([f"{f}\n\nassert test_puzzle(f, ({g}))" for g, _i in valids], timeout=timeout) + curr = [g for (g, i), res in zip(valids, results) if res] + sol_counts = Counter(curr).most_common() + sat_sols.append({"sat": f, "n_sols": len(curr), "sol_counts": sol_counts}) + + if verbose: + print("=", p_num, "="*10, f"{len(valids)/n:.1%} valid generations:") + print(f) + print() + for v in valids: + print(v) + print("-"*100) + if curr: + if False: # len(ans1) < 1: + print(p_num, "-" * 80) + print(strip_param_annotations(f)) + summary = [(a if c == 1 else f"{a} ({c} times)") for a, c in Counter(curr).most_common(10)] + summary_str = ' | '.join(summary).replace("\n", "\\n") + print(f"{len(curr)} sols, first at attempt #{curr[0]}:: {summary_str}"[:200]) + print(curr[0]) + + n_sol = sum(bool(s_s["n_sols"]) for s_s in sat_sols) + n_suc = sum(s_s["n_sols"] for s_s in sat_sols) + print(f"Solved {n_sol:,}/{len(fs):,} puzzles with a total of {n_suc:,} total solutions.") + print() + + return dict( + experiment=experiment, + filename=filename, + engine=engine, + n=n, + prefix=prefix, + seed=seed, + tot_solved = n_sol, + tot_solutions = n_suc, + sat_sols = sat_sols, + ) + + +def bootstrap(filename, experiment="bootstrap", n = 1000, ppi=32, temp=0.9, seed=0, timeout=1.0, gen_tokens=150, + verbose=False, prefix="", cache_only=False, engine=None, remove_docstring=True): + """ + Run the bootstrapping experiment + + ppi is the number of attempts per puzzle per iteration + stop is the token to stop generating on + seed is the seed of the random number generator + temp is like 0.9 + timeout is judging timeout + max_tokens is the maximum number of tokens allowed in a prompt + gen_tokens is how many tokens to generate at most + cache_only means do not call GPT LM but instead insist on loading from cache + + returns a list of (num_gen, i, f, a) for each solved puzzle where f is the puzzle, i is the index of the puzzle, + a is the answer, and num_gen is number of attempts before generation (0-indexed) + """ + + + iterations = math.ceil(n / ppi) + if n % ppi != 0: + print(f"Bootstrap warning: {n} puzzles not divisible by ppi {ppi}, rounding up") + + max_tokens = (4096 if "davinci-codex" in engine else 2048) # zzzzz + + print("=" * 100) + print(f"Running GPT-bootstrap experiment with engine {engine}") + for k in locals().copy(): + print(f"param {k}: {json.dumps(locals()[k])[:100]}") + time0 = time.time() + rand = random.Random(seed) + + def get_prompt(f, sol_header): + """Returns prompt and function number""" + nonlocal solutions, rand, max_tokens, gen_tokens, prefix + + assert f not in [f2 for (_, _, f2, _) in solutions], "Puzzle already solved" + + s2 = solutions[:] + rand.shuffle(s2) + + entries = [] + for i, (_, _, f2, g) in enumerate(s2): + j = i + 1 + example = f2.replace('def f(', f'def f{j}(').strip() + example += "\n\n" + example += utils.rename_src_var("f", f'f{j}', utils.rename_src_var("g", f'g{j}', g)).strip() + example += "\n\n" + example += f"assert f{j}(g{j}())" + entries.append(example) + + ans = None + for k in range(len(entries) + 1): + + entries2 = ([prefix] if prefix else []) + entries[:k] + + j = k + 1 + + entries2.append(f.replace('def f(', f'def f{j}(')) + entries2.append(sol_header.replace("def sol(", "def g(", 1).replace("def g(", f'def g{j}(', 1)) + + prompt = "\n\n".join([e.strip() for e in entries2]) + + # print(k, num_tokens(prompt)) + if num_tokens(prompt) >= max_tokens - gen_tokens: + # print("TOO MANY TOKENS", num_tokens(prompt), num_tokens(last_prompt)) + break + ans = (prompt, j) + + return ans + + if isinstance(filename, str): + fs, sol_headers = load_puzzles(filename, remove_docstring=remove_docstring) + else: + fs = filename # zzz + + assert len(fs) == len(set(fs)) == len(sol_headers) + + time0 = time.time() + + tot = 0 + stats = [dict(f=f, sol_header=h, gs=[], i=i, raw=[]) for i, (f, h) in enumerate(zip(fs, sol_headers))] + solved_by_iteration = [] + solutions = [] + sat_sols = [{"sat": f, "failures": iterations * ppi} for f in fs] # alternative format + + + for it in (range(iterations) if verbose else tqdm(range(iterations))): + it_time0 = time.time() + solved_by_iteration.append(0) + + rand.shuffle(stats) # do each iteration in a random order + + for count, s in enumerate(stats): + if s["gs"]: + continue # already solved + if verbose: + print("*"*20, f"Iteration {it+1}/{iterations} #{count} solved {len(solutions)}/{len(fs)}: {solved_by_iteration}") + i = s["i"] + f = s["f"] + sol_header = s["sol_header"] + prompt, j = get_prompt(f, sol_header) + num_solved = sum(bool(s['gs']) for s in stats) + # if verbose: + # if count == 0: + # print("Prompt:" + ":" * 80) + # print(prompt) + # if count % 10 == 0: + # print(f" * It {it}/{iterations} ({count / len(stats):.0%}) puzzle {i} " + # f"solved {num_solved} temp={temp}", + # flush=True) + + res = gpt_lib.query( + prompt=prompt, + n=ppi, + temp=temp, + max_tokens=gen_tokens, + stop="\nassert" , + cache_only=cache_only, + notes=(seed, it), + engine=engine, + verbose=True + ) + s["raw"].append((prompt, res)) + assert len(res) == ppi + + valids = [(find_end(g, multi_line=True), i) for i, g in enumerate(res)] + valids = [(g, i) for (g, i) in valids if g is not None] + valids = [(sol_header + g.replace("f{j}(", "f("), i) for (g, i) in valids] + results = judge.judge_parallel([f"{f}\n\n{g}\n\nassert test_puzzle(f, g())" for g, _i in valids], + timeout=timeout) + + if any(results): + a, m = next((a, m) for ((a, m), res) in zip(valids, results) if res) + solutions.append((it * ppi + m, i, f, a)) + assert "sol" not in sat_sols[i] + sat_sols[i]["sol"] = a + sat_sols[i]["prompt"] = prompt + sat_sols[i]["failures"] = m + it * ppi + solved_by_iteration[-1] += 1 + s["gs"].append((a, it, m)) + if verbose: + print(f"# {len(solutions)}-th puzzle solved, iteration {it}: puzzle id={i}") + print(f) + print() + print(f"assert True == f({a})") + print() + it += 1 + num_solved = sum(bool(s['gs']) for s in stats) + assert sum(solved_by_iteration) == num_solved + # if verbose: + # print() + # print() + # print(f"+++ Iter {it}: {num_solved} solved {solved_by_iteration}") + # print(f"+++ {time.time() - it_time0:.1f}s it ({time.time() - time0:.1f}s)") + # print() + # print() + + print(f"Solved {len(solutions):,}/{len(fs):,} puzzles") + print("Solved by iteration", solved_by_iteration) + + return dict( + experiment=experiment, + filename=filename, + engine=engine, + n=n, + prefix=prefix, + seed=seed, + tot_solved = len(solutions), + sat_sols = sat_sols + ) + + + + + +def strip_puzzle(puz: str): + puz = puz.strip() + match = re.search(r"\n\S", puz) # newline followed by a non-newline character + if match: + return puz[:match.start()] + return puz diff --git a/solvers/codex/lm_solve/scratch.py b/solvers/codex/lm_solve/scratch.py new file mode 100644 index 0000000..697f459 --- /dev/null +++ b/solvers/codex/lm_solve/scratch.py @@ -0,0 +1,34 @@ +from collections import Counter + +def chars(filename, max_ord=300): + with open(filename, "r", encoding="utf8") as f: + counts = Counter(ord(c) for c in f.read()) + print(counts.most_common()) + print("max", max(counts)) + missing = [i for i in range(max_ord) if i not in counts] + print("missing", missing) + +chars(".cache/davinci-codex.cache") + +import time +time0 = time.perf_counter() +with open(".cache/davinci-codex.cache", "r", encoding="utf8") as f: + lines = f.readlines() +time1 = time.perf_counter() +print("duration", time1 - time0) + +time0 = time.perf_counter() +with open(".cache/davinci-codex.cache", "r", encoding="utf8") as f: + lines = f.readlines() +time1 = time.perf_counter() +print("duration", time1 - time0) + +import json +time0 = time.perf_counter() +elines = [json.loads(l) for l in lines] +time1 = time.perf_counter() +print("duration", time1 - time0) + +len(lines), len(set(lines)) +len(elines[0][0]) +list(eval(elines[0][0])) diff --git a/solvers/codex/requirements.txt b/solvers/codex/requirements.txt new file mode 100644 index 0000000..f569ecf --- /dev/null +++ b/solvers/codex/requirements.txt @@ -0,0 +1,9 @@ +astor==0.8.1 +numpy==1.22.0 +openai==0.6.3 +tqdm==4.60.0 +transformers==4.30.0 +Pebble==4.6.1 + +# we ran with Python version sys.version = '3.6.9 (default, Jan 26 2021, 15:33:00) \n[GCC 8.4.0]' +# distro-info===0.18ubuntu0.18.04.1 diff --git a/solvers/codex/results/results_397_cushman_codex_1k_full.json.gz b/solvers/codex/results/results_397_cushman_codex_1k_full.json.gz new file mode 100644 index 0000000..4ec6f2b Binary files /dev/null and b/solvers/codex/results/results_397_cushman_codex_1k_full.json.gz differ diff --git a/solvers/codex/run_codex_experiments.py b/solvers/codex/run_codex_experiments.py new file mode 100644 index 0000000..403dfc5 --- /dev/null +++ b/solvers/codex/run_codex_experiments.py @@ -0,0 +1,204 @@ +""" +This script runs the codex experiments. +For GPT-3 experiments see run_gpt3_experiments.py in https://github.com/microsoft/PythonProgrammingPuzzles/tree/v0.1 +It uses cacheing mechanisms so that if run twice with the same parameters, it will give exactly the same +results and will not query the API again and will not judge the resulting solutions again. Hence, the first +time you run it, it will be slow, but you can subsequently run it again and it will be fast. It will run the +experiment three times, with different seeds to get different results. +""" + +import lm_solve +import utils +import math +import numpy as np + +OUTPUT_FILENAME = "results_30_cushman_codex_32.json" +SEEDS = 1 # number of times to run it +PARAMS = dict( + temp=0.9, + timeout=1.0, # seconds to judge + n=32, # number of attempts per puzzle, usually 1000, or set small for a fast run + filename="30puzzles.json", # set to 397puzzles.json for a run on full v0.2 dataset + cache_only=False, # change this to True if you want to run a 2nd time without risking hitting API + engine="cushman-codex", # FAST-CODEX: "cushman-codex" CODEX: "davinci-codex" GPT3: "davinci" +) + +BOOTSTRAP_PARAMS = dict( + temp=PARAMS["temp"], + n=PARAMS["n"], + timeout=PARAMS["timeout"], + filename=PARAMS["filename"], + cache_only=PARAMS["cache_only"], + ppi=32, # puzzles per iteration + engine=PARAMS["engine"], + prefix="from typing import List\n\n", +) + +PREFIX = """from typing import List + +def f1(s: str): + return "Hello " + s == "Hello world" + +def g1(): + return "world" + +assert f1(g1()) + +def f2(s: str): + return "Hello " + s[::-1] == "Hello world" + +def g2(): + return "world"[::-1] + +assert f2(g2()) + +def f3(x: List[int]): + return len(x) == 2 and sum(x) == 3 + +def g3(): + return [1, 2] + +assert f3(g3()) + +def f4(s: List[str]): + return len(set(s)) == 1000 and all((x.count("a") > x.count("b")) and ('b' in x) for x in s) + +def g4(): + return ["a"*(i+2)+"b" for i in range(1000)] + +assert f4(g4()) + +def f5(n: int): + return str(n * n).startswith("123456789") + +def g5(): + return int(int("123456789" + "0"*9) ** 0.5) + 1 + +assert f5(g5()) + +""" # trailing newlines important + + +PREFIX_DOCSTR = '''from typing import List + +def f1(s: str): + return "Hello " + s == "Hello world" + +def g1(): + """Find a string that when concatenated onto 'Hello ' gives 'Hello world'.""" + return "world" + +assert f1(g1()) + +def f2(s: str): + return "Hello " + s[::-1] == "Hello world" + +def g2(): + """Find a string that when reversed and concatenated onto 'Hello ' gives 'Hello world'.""" + return "world"[::-1] + +assert f2(g2()) + +def f3(x: List[int]): + return len(x) == 2 and sum(x) == 3 + +def g3(): + """Find a list of two integers whose sum is 3.""" + return [1, 2] + +assert f3(g3()) + +def f4(s: List[str]): + return len(set(s)) == 1000 and all((x.count("a") > x.count("b")) and ('b' in x) for x in s) + +def g4(): + """Find a list of 1000 distinct strings which each have more 'a's than 'b's and at least one 'b'.""" + return ["a"*(i+2)+"b" for i in range(1000)] + +assert f4(g4()) + +def f5(n: int): + return str(n * n).startswith("123456789") + +def g5(): + """Find an integer whose perfect square begins with 123456789 in its decimal representation.""" + return int(int("123456789" + "0"*9) ** 0.5) + 1 + +assert f5(g5()) + +''' # trailing newlines important + + +def pass_at_k(k: int, successes: int, attempts: int): + fail_prob = 1.0 + for i in range(k): + fail_prob *= (attempts - successes)/attempts # gets right answer of 0 when attempts == successes + attempts -= 1 + return 1.0 - fail_prob + + + +def run(seed=0): + PARAMS_0 = {**PARAMS, "n": 0} + BOOTSTRAP_PARAMS_0 = {**BOOTSTRAP_PARAMS, "n": 0} + sols = [lm_solve.prompt_experiment(**PARAMS, experiment="short", prefix="", seed=seed), + lm_solve.prompt_experiment(**PARAMS, experiment="med", prefix=PREFIX, remove_docstring=True, seed=seed), + lm_solve.prompt_experiment(**PARAMS, experiment="long", prefix=PREFIX_DOCSTR, remove_docstring=False, seed=seed), + ] + num_puzzles = len(sols[0]["sat_sols"]) + assert all(len(s["sat_sols"]) == num_puzzles for s in sols) + + n = PARAMS["n"] + ks = [1] + while ks[-1] < n: + ks += [ks[-1] * i for i in [10]] # for i in [2, 5, 10]] + ks = [k for k in ks if k <= n] + if ks[-1] != n: + ks.append(n) + for s in sols: + s["pass@k"] = [ + ( + k, + np.mean([pass_at_k(k, s_s["n_sols"], n) for s_s in s["sat_sols"]]) + ) + for k in ks] + + bootstrap = lm_solve.bootstrap(**BOOTSTRAP_PARAMS, seed=seed) + bootstrap["pass@k"] = [(k, np.mean([s_s["failures"] < k for s_s in bootstrap["sat_sols"]])) for k in ks] + sols.append(bootstrap) + + print(f"run={seed} ALL DONE!\n\n") + print(f"run={seed} RESULTS " + "=" * 50) + print() + + for s in sols: + print(s["experiment"], "prefix:", s["prefix"].replace("\n", "\\n")[:250]) + print(" ", s["tot_solved"], "solved, pass@k", " ".join(f'{k} {p:.5f}' for k, p in s["pass@k"])) + + print(f"Pass at k [(k, {', '.join(s['experiment'] for s in sols)}) ...]") + print(list(zip([k for k, _p in sols[0]["pass@k"]], *[[p for _k, p in s["pass@k"]] for s in sols]))) + + return sols + +def main(): + res = [s for seed in range(SEEDS) for s in run(seed)] + + if OUTPUT_FILENAME: + FULL_FILENAME = OUTPUT_FILENAME.replace(".json", "_full.json.gz") + utils.save_json(res, FULL_FILENAME) + for s in res: + if "sat_sols" in s: + for t in s["sat_sols"] : + if "sol_counts" in t: + if t["sol_counts"]: + t["shortest_sol"] = min([s for s, c in t["sol_counts"]], key=len) + t["longest_sol"] = max([s for s, c in t["sol_counts"]], key=len) + t["common_sol"] = max(t["sol_counts"], key=lambda z: z[1])[0] + del t["sol_counts"] + utils.save_json(res, OUTPUT_FILENAME) + print(f"saved results to {OUTPUT_FILENAME} and {FULL_FILENAME}") + + +if __name__ == "__main__": + main() + diff --git a/solvers/codex/utils.py b/solvers/codex/utils.py new file mode 100644 index 0000000..1887bce --- /dev/null +++ b/solvers/codex/utils.py @@ -0,0 +1,137 @@ +import functools +import operator +import os +import re +import json +import time +import logging + +def get_lambda_arg_name(lam): + assert lam.startswith("lambda ") + return lam[len("lambda "):lam.index(":")].strip() + + +def stringify(const): + if type(const) is str: + return json.dumps(const) + return str(const) + + +def color_str(obj, code="\033[0;36m"): + return code + str(obj) + '\033[0m' + + +def prod(iterable): # like sum but product + return functools.reduce(operator.mul, iterable, 1) + + +def flatten(it): + return (e for a in it for e in (flatten(a) if isinstance(a, (tuple, list)) else (a,))) + +def save_json(obj, filename, make_dirs_if_necessary=False, indent=2, **kwargs): + """Saves compressed file if filename ends with '.gz'""" + import json + if make_dirs_if_necessary: + os.makedirs(os.path.dirname(filename), exist_ok=True) + if filename.endswith(".gz"): + import gzip + with gzip.open(filename, "wt") as f: + return json.dump(obj, f, indent=indent, **kwargs) + with open(filename, "w", encoding="utf8") as f: + return json.dump(obj, f, indent=indent, **kwargs) + +def load_json(filename): + """Loads compressed file if filename ends with '.gz'""" + import json + if filename.endswith(".gz"): + import gzip + with gzip.open(filename, "rt") as f: + return json.load(f) + with open(filename, "r", encoding="utf8") as f: + return json.load(f) + + +def viz_py(py): + import astor, ast + print(astor.dump_tree(ast.parse(py))) + + +def dedup(li): + seen = set() + return [x for x in li if x not in seen and not seen.add(x)] + + +def test_puzzle(f, x): + """Checks if x is of the correct type and makes f return True (literally True, not an integer or whatever) + + :param f: Puzzle + :param x: candidate answer + :return: + """ + answer_type = list(f.__annotations__.values())[0] + if not type_check(x, answer_type): + raise TypeError + return f(x) is True + + + +def type_check(obj, typ): + """ + check if obj is of type `typ` where `typ` is a `typing` module type annotation, eg List[int] + The way we do this to be compatible across versions is we first convert the type to a string. + """ + + type_str = str(typ).replace("typing.", "") + if type_str.startswith("= 2: + a = src.index('"""') + b = src.index('"""', a+1) + 3 + if count == 1: + h = helper(src[:a]) + if h != src[:a]: + return h + src[a:] + return helper(src[:a]) + src[a:b] + helper(src[b:]) + + return helper(src) + +logger = None + +def timeit(method): + global logger + if logger is None: + logger = logging.getLogger(__name__) + def timed(*args, **kw): + tick = time.time() + result = method(*args, **kw) + tock = time.time() + logger.debug(f'{method.__name__}: {tock - tick:.3f}s') + + return result + return timed + diff --git a/solvers/enumerative/requirements.txt b/solvers/enumerative/requirements.txt index 0bd8907..27d8f6f 100644 --- a/solvers/enumerative/requirements.txt +++ b/solvers/enumerative/requirements.txt @@ -3,6 +3,6 @@ orderedset numpy astor sklearn -torch==1.8.1 -transformers==2.11.0 +torch==1.13.1 +transformers==4.30.0 tensorboardX diff --git a/solvers/gpt3/README.md b/solvers/gpt3/README.md index d83c682..597bde7 100644 --- a/solvers/gpt3/README.md +++ b/solvers/gpt3/README.md @@ -5,7 +5,7 @@ the paper because the API is non-deterministic. The requirements can be installed with `pip3 install -r requirements.txt`. -This script runs the GPT-3 experiments and prints the results to stdout. +`run_gpt3_experiments.py` runs the GPT-3 experiments and prints the results to stdout. ## Installation and execution. You will need an open-ai GPT-3 access key which can be signed up for [here](https://openai.com/join/). @@ -21,9 +21,4 @@ Then you simply run being quite slow and verbose, querying the API. However you can subsequently run it again and it will be much faster and just output the results. The cacheing makes it deterministic so it should give the same exact results when re-run. - - -## Contact - -If you are interested in reproducing the exact results of the paper, please contact the authors to ensure the exact -same query results. \ No newline at end of file + \ No newline at end of file diff --git a/solvers/gpt3/ezlog.py b/solvers/gpt3/ezlog.py index a774f2f..3989b6d 100644 --- a/solvers/gpt3/ezlog.py +++ b/solvers/gpt3/ezlog.py @@ -33,19 +33,6 @@ def configure_logging(stdio_level=logging.INFO, level=min(stdio_level, file_level), handlers=[stdio_handler, file_hanlder] ) - # - # fh = logging.FileHandler('spam.log') - # fh.setLevel(logging.DEBUG) - # # create console handler with a higher log level - # ch = logging.StreamHandler() - # ch.setLevel(logging.ERROR) - # # create formatter and add it to the handlers - # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') - # fh.setFormatter(formatter) - # ch.setFormatter(formatter) - # # add the handlers to the logger - # logger.addHandler(fh) - # logger.addHandler(ch) _configured = True _get_or_create_logger().debug("Configured logging") diff --git a/solvers/gpt3/requirements.txt b/solvers/gpt3/requirements.txt index 19e9e42..f569ecf 100644 --- a/solvers/gpt3/requirements.txt +++ b/solvers/gpt3/requirements.txt @@ -1,121 +1,9 @@ astor==0.8.1 -numpy==1.19.1 +numpy==1.22.0 openai==0.6.3 tqdm==4.60.0 -transformers==2.11.0 +transformers==4.30.0 Pebble==4.6.1 # we ran with Python version sys.version = '3.6.9 (default, Jan 26 2021, 15:33:00) \n[GCC 8.4.0]' # distro-info===0.18ubuntu0.18.04.1 - -# asn1crypto==0.24.0 -# attrs==19.3.0 -# Automat==0.6.0 -# backcall==0.2.0 -# bleach==3.1.5 -# blinker==1.4 -# certifi==2020.12.5 -# chardet==4.0.0 -# click==7.1.2 -# cloud-init==19.4 -# colorama==0.3.7 -# command-not-found==0.3 -# configobj==5.0.6 -# constantly==15.1.0 -# cryptography==2.1.4 -# dataclasses==0.7 -# decorator==4.4.2 -# defusedxml==0.6.0 -# entrypoints==0.3 -# filelock==3.0.12 -# future==0.18.2 -# httplib2==0.9.2 -# hyperlink==17.3.1 -# idna==2.10 -# importlib-metadata==1.6.1 -# incremental==16.10.1 -# ipykernel==5.3.0 -# ipython==7.15.0 -# ipython-genutils==0.2.0 -# ipywidgets==7.5.1 -# jedi==0.17.1 -# Jinja2==2.11.2 -# joblib==1.0.1 -# jsonpatch==1.16 -# jsonpointer==1.10 -# jsonschema==3.2.0 -# jupyter==1.0.0 -# jupyter-client==6.1.3 -# jupyter-console==6.1.0 -# jupyter-core==4.6.3 -# keyring==10.6.0 -# keyrings.alt==3.0 -# language-selector==0.1 -# MarkupSafe==1.1.1 -# mistune==0.8.4 -# nbconvert==5.6.1 -# nbformat==5.0.7 -# netifaces==0.10.4 -# notebook==6.0.3 -# oauthlib==2.0.6 -# orderedset==2.0.3 -# packaging==20.4 -# PAM==0.4.2 -# pandocfilters==1.4.2 -# parso==0.7.0 -# pexpect==4.8.0 -# pickleshare==0.7.5 -# prometheus-client==0.8.0 -# prompt-toolkit==3.0.5 -# protobuf==3.13.0 -# ptyprocess==0.6.0 -# pyasn1==0.4.2 -# pyasn1-modules==0.2.1 -# pycrypto==2.6.1 -# Pygments==2.6.1 -# pygobject==3.26.1 -# PyJWT==1.5.3 -# pyOpenSSL==17.5.0 -# pyparsing==2.4.7 -# pyrsistent==0.16.0 -# pyserial==3.4 -# python-apt==1.6.5+ubuntu0.5 -# python-dateutil==2.8.1 -# python-debian==0.1.32 -# pyxdg==0.25 -# PyYAML==3.12 -# pyzmq==19.0.1 -# qtconsole==4.7.5 -# QtPy==1.9.0 -# regex==2020.7.14 -# requests==2.25.1 -# requests-unixsocket==0.1.5 -# sacremoses==0.0.43 -# scikit-learn==0.23.2 -# scipy==1.5.2 -# SecretStorage==2.3.1 -# Send2Trash==1.5.0 -# sentencepiece==0.1.92 -# service-identity==16.0.0 -# six==1.15.0 -# sklearn==0.0 -# ssh-import-id==5.7 -# systemd-python==234 -# tensorboardX==2.1 -# terminado==0.8.3 -# testpath==0.4.4 -# threadpoolctl==2.1.0 -# tokenizers==0.7.0 -# torch==1.6.0 -# tornado==6.0.4 -# traitlets==4.3.3 -# Twisted==17.9.0 -# ufw==0.36 -# unattended-upgrades==0.1 -# urllib3==1.26.4 -# WALinuxAgent==2.2.45 -# wcwidth==0.2.5 -# webencodings==0.5.1 -# widgetsnbextension==3.5.1 -# zipp==3.1.0 -# zope.interface==4.3.2 diff --git a/utils.py b/utils.py index 60a9d41..fe28632 100644 --- a/utils.py +++ b/utils.py @@ -6,6 +6,12 @@ my_path = os.path.dirname(__file__) +def check_hashseed(desired_seed = 0): + if os.environ.get('PYTHONHASHSEED') != desired_seed: + info(f"Ideally set PYTHONHASHSEED={desired_seed} for perfect reproducibility") + return False + return True + def inv_dict(d): ans = {} @@ -17,27 +23,45 @@ def inv_dict(d): def remove_docstring(f): - if '\n """' in f: # remove doc_string if present - i = f.index('\n """') - j = f.index('"""\n', i + 8) - return f[:i + 1] + f[j + 4:] - return f + """Remove docstring""" + assert '\n """' in f, f"No triple quote docstring (after four spaces) in: \n{f}" + i = f.index('\n """') + j = f.index('"""', i + 8) + return f[:i + 1] + f[j + 4:] + + +def get_docstring(f): + assert '\n """' in f, f"No triple quote docstring (after four spaces) in: \n{f}" + i = f.index('\n """') + j = f.index('"""', i + 8) + docstring = f[i + 1:j + 3] + if not docstring.strip(' "'): + warn(f"Empty docstring in:\n{f}") + return docstring def flatten(it): return (e for a in it for e in (flatten(a) if isinstance(a, (tuple, list)) else (a,))) - -def save_json(obj, filename, make_dirs_if_necessary=False, **kwargs): +def save_json(obj, filename, make_dirs_if_necessary=False, indent=2, **kwargs): + """Saves compressed file if filename ends with '.gz'""" import json if make_dirs_if_necessary: os.makedirs(os.path.dirname(filename), exist_ok=True) + if filename.endswith(".gz"): + import gzip + with gzip.open(filename, "wt") as f: + return json.dump(obj, f, indent=indent, **kwargs) with open(filename, "w", encoding="utf8") as f: - return json.dump(obj, f, **kwargs) - + return json.dump(obj, f, indent=indent, **kwargs) def load_json(filename): + """Loads compressed file if filename ends with '.gz'""" import json + if filename.endswith(".gz"): + import gzip + with gzip.open(filename, "rt") as f: + return json.load(f) with open(filename, "r", encoding="utf8") as f: return json.load(f)