This commit is contained in:
Jakub Pokrywka 2022-03-13 19:06:06 +01:00
parent 957a824a21
commit 76c36fed60
1 changed files with 104 additions and 18 deletions

View File

@ -39,10 +39,20 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import random\n",
"from collections import Counter\n", "from collections import Counter\n",
"from dahuffman import HuffmanCodec" "from dahuffman import HuffmanCodec"
] ]
}, },
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"NR_INDEKSU = 375985"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -52,7 +62,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -61,7 +71,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -70,7 +80,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -92,7 +102,7 @@
" 's': 1})" " 's': 1})"
] ]
}, },
"execution_count": 5, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -103,7 +113,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 7,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@ -137,7 +147,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -160,7 +170,7 @@
" 's': (5, 31)}" " 's': (5, 31)}"
] ]
}, },
"execution_count": 7, "execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -171,7 +181,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -180,7 +190,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -189,7 +199,7 @@
"'1010010111010011010100110011100100001100110010101011111010110110000110101001110111111011'" "'1010010111010011010100110011100100001100110010101011111010110110000110101001110111111011'"
] ]
}, },
"execution_count": 9, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -214,7 +224,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -223,7 +233,7 @@
"'Ala ma kota. Jarek ma psa'" "'Ala ma kota. Jarek ma psa'"
] ]
}, },
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -234,7 +244,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -243,7 +253,7 @@
"25" "25"
] ]
}, },
"execution_count": 11, "execution_count": 12,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -254,7 +264,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -263,7 +273,7 @@
"11" "11"
] ]
}, },
"execution_count": 12, "execution_count": 13,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -276,7 +286,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Zadanie 1 ( 30 punktów)\n", "## Zadanie 1 ( 15 punktów)\n",
"\n", "\n",
"Weź teksty:\n", "Weź teksty:\n",
"- z poprzednich zajęć (lub dowolny inny) w języku naturalnym i obetnij do długości 100_000 znaków\n", "- z poprzednich zajęć (lub dowolny inny) w języku naturalnym i obetnij do długości 100_000 znaków\n",
@ -352,12 +362,20 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Zadanie 2 \n", "## Zadanie 2 (10 punktów)\n",
"\n", "\n",
"Powtórz kroki z zadania 1, tylko potraktuje wiadomości jako słowa (oddzielone spacją). Jeżeli występują więcej niż jedna spacja równocześnie- usuń je.\n", "Powtórz kroki z zadania 1, tylko potraktuje wiadomości jako słowa (oddzielone spacją). Jeżeli występują więcej niż jedna spacja równocześnie- usuń je.\n",
" \n", " \n",
"Do wniosków dopisz koniecznie porównanie między kodowaniem hoffmana znaków i słów.\n", "Do wniosków dopisz koniecznie porównanie między kodowaniem hoffmana znaków i słów.\n",
"\n", "\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### START ZADANIA" "### START ZADANIA"
] ]
}, },
@ -403,6 +421,74 @@
"### KONIEC ZADANIA" "### KONIEC ZADANIA"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Zadanie 3 (20 punktów)\n",
"\n",
"stwórz ręcznie drzewo Huffmana (zrób rysunki na kartce i załącz je jako obrazek) oraz zakoduj poniższy tekst "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"random.seed(123)\n",
"\n",
"tekst = list('abcdefghijklmnoprst')\n",
"\n",
"random.shuffle(tekst)\n",
"\n",
"tekst = tekst[: 5 + random.randint(1,5)]\n",
"\n",
"tekst = [a*random.randint(1,4) for a in tekst]\n",
"\n",
"tekst = [item for sublist in tekst for item in sublist]\n",
"\n",
"''.join(tekst)\n",
"\n",
"random.shuffle(tekst)\n",
"\n",
"tekst = ''.join(tekst)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ldddmpprphhopd'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tekst"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Start zadania"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Koniec zadania"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},