Created
April 29, 2020 14:31
-
-
Save NSLog0/8b611fa279b7db5136585926564900c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 138, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from typing import List\n", | |
"import doctest" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 139, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def changer(amount: int, given_coins: list , coint_left: int) -> list:\n", | |
"\tif sum(coint_left) == amount:\n", | |
"\t\tyield coint_left\n", | |
"\telif sum(coint_left) > amount:\n", | |
"\t\tpass\n", | |
"\telif given_coins == []:\n", | |
"\t\tpass\n", | |
"\telse:\n", | |
"\t\tfor c in change(amount, given_coins[:], coint_left+[given_coins[0]]):\n", | |
"\t\t\tyield c\n", | |
"\t\tfor c in change(amount, given_coins[1:], coint_left):\n", | |
"\t\t\tyield c" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 144, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"coint: [2, 5, 10, 10, 10, 10, 10]\n" | |
] | |
} | |
], | |
"source": [ | |
"\"\"\"\n", | |
"unit test\n", | |
"\n", | |
">>> min(changer(57, [1, 2, 5, 10], []), key=len)\n", | |
"[2, 5, 10, 10, 10, 10, 10]\n", | |
"\n", | |
">>> min(changer(40, [1, 2, 5, 10], []), key=len)\n", | |
"[10, 10, 10, 10]\n", | |
"\n", | |
">>> min(changer(1, [1, 2, 5, 10], []), key=len)\n", | |
"[1]\n", | |
"\"\"\"\n", | |
"\n", | |
"doctest.testmod()\n", | |
"\n", | |
"amount: int = 57\n", | |
"coins: list = [1, 2, 5, 10]\n", | |
"solutions: list = [s for s in changer(amount, coins, [])]\n", | |
"result_coint = []\n", | |
"\n", | |
"if len(solutions) > 0:\n", | |
" result_coint = min(solutions, key=len)\n", | |
"\n", | |
"print('coint: ', result_coint)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:dna_env] *", | |
"language": "python", | |
"name": "conda-env-dna_env-py" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment