Zadanie domowe 5
Zad 1
import random
polish_chars = "AĄBCĆDEĘFGHIJKLMNOÓPRSŚTUWYZŹŻ" + "aąbcćdeęfghijklmnoóprsśtuwyzźż"
+ "0123456789"
polish_text_content = ''.join(random.choices(polish_chars, k=100000))
with open('generated_polish_text_100000_chars.txt', 'w', encoding='utf-8') as
file:
file.write(polish_text_content)
print("File generated successfully.")
Plik tekstowy:  100 KB.
Po kompresji ZIP najmniejszy: 1–3 KB .
Po kompresji ZIP największy: 28–30 KB.
Zad 2
from PIL import Image
import numpy as np
width, height = 1200, 800
image_data = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
image_bmp = Image.fromarray(image_data)
bmp_file_path = '/mnt/data/generated_image.bmp'
image_bmp.save(bmp_file_path, format='BMP')
bmp_file_path
BMP (oryginalny): 2,880,054 bajty
PNG: 2,884,857 bajtów (stopień kompresji: ~1.00)
GIF: 1,306,326 bajtów (stopień kompresji: ~2.20)
JPEG: 577,436 bajtów (stopień kompresji: ~4.99)

Zad 3
H = log𝟐(𝒏^𝟐)
log𝟐(𝒏^𝟐) = 2log𝟐(𝒏)
Entropia tego źródła wynosi 2log𝟐(𝒏) bitów.