added deck sorting function

This commit is contained in:
ASPP Student 2025-09-24 10:46:11 +03:00
parent 874f984bd5
commit d025234754

View file

@ -36,9 +36,9 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"-- Deck 1: --\n", "-- Deck 1: --\n",
" ['The Lovers', 'Temperance', 'The Emperor', 'The Sun', 'The Fool', 'The Chariot', 'Death', 'Strength', 'Justice', 'The Star', 'Judgement', 'The World', 'The Tower', 'The Hanged Man', 'The Empress', 'The Hermit', 'The Devil', 'The High Priestess', 'The Moon', 'The Hierophant', 'Wheel of Fortune', 'The Magician']\n", " ['Judgement', 'The Hanged Man', 'The Tower', 'The Magician', 'The Star', 'The Fool', 'Justice', 'The Chariot', 'The World', 'The High Priestess', 'The Devil', 'Strength', 'The Sun', 'The Moon', 'Wheel of Fortune', 'The Lovers', 'The Hermit', 'The Hierophant', 'The Emperor', 'The Empress', 'Death', 'Temperance']\n",
"-- Deck 2: --\n", "-- Deck 2: --\n",
" ['The Fool', 'Death', 'The Hermit', 'Strength', 'The Moon', 'Wheel of Fortune', 'Judgement', 'The Lovers', 'The Star', 'The Hanged Man', 'The Empress', 'The Emperor', 'The Magician', 'The Tower', 'The Hierophant', 'The Chariot', 'The High Priestess', 'Temperance', 'The World', 'The Devil', 'The Sun', 'Justice']\n" " ['The Hierophant', 'The Star', 'Judgement', 'The Moon', 'Justice', 'Death', 'The Devil', 'Temperance', 'The Lovers', 'Strength', 'The Emperor', 'Wheel of Fortune', 'The High Priestess', 'The Magician', 'The Sun', 'The Chariot', 'The Tower', 'The Hermit', 'The Hanged Man', 'The World', 'The Fool', 'The Empress']\n"
] ]
} }
], ],
@ -69,16 +69,69 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"id": "48eb31e2", "id": "48eb31e2",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"# total complexity O(n)\n",
"def match_cards(deck1, deck2):\n",
" deck1_sort = sorted(deck1) # complexity O(1)\n",
" deck2_sort = sorted(deck2) # complexity O(1)\n",
" \n",
" pairs = [(ind, ind) for ind, card in enumerate(deck1_sort)] # complexity O(n)\n",
"\n",
" return pairs\n",
"\n",
"pairs = match_cards(deck1, deck2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "509dda71",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(0, 0),\n",
" (1, 1),\n",
" (2, 2),\n",
" (3, 3),\n",
" (4, 4),\n",
" (5, 5),\n",
" (6, 6),\n",
" (7, 7),\n",
" (8, 8),\n",
" (9, 9),\n",
" (10, 10),\n",
" (11, 11),\n",
" (12, 12),\n",
" (13, 13),\n",
" (14, 14),\n",
" (15, 15),\n",
" (16, 16),\n",
" (17, 17),\n",
" (18, 18),\n",
" (19, 19),\n",
" (20, 20),\n",
" (21, 21)]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pairs"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "509dda71", "id": "56593527",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
@ -86,7 +139,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3 (ipykernel)", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -100,7 +153,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.5" "version": "3.13.6"
} }
}, },
"nbformat": 4, "nbformat": 4,