Skip to content

Instantly share code, notes, and snippets.

@C10udburst
Last active May 30, 2022 09:50
Show Gist options
  • Save C10udburst/e82b7a89fa0f7cf18a336b8d261941a2 to your computer and use it in GitHub Desktop.
Save C10udburst/e82b7a89fa0f7cf18a336b8d261941a2 to your computer and use it in GitHub Desktop.
from functools import reduce
from http.client import HTTPConnection
from operator import add, and_
conn = HTTPConnection("informatyka.iq.pl")
conn.request("GET", "/downloads/sil.txt")
with conn.getresponse() as resp:
sil = [x.split(" ") for x in resp.read().decode('utf-8').strip().splitlines()]
print("Zad. 1.")
count = 0
for entry in sil:
ascii_sum = reduce(add, [ord(x) for x in entry[0]])
if ascii_sum == int(entry[1]):
count += 1
print(count)
print()
print("Zad. 2.")
count = 0
for entry in sil:
if len(set(entry[0])) != len(entry[0]):
count += 1
print(count)
print()
print("Zad. 3.")
count = 0
for entry in sil:
new_word = "".join([chr(int(x) + ord("A")) for x in entry[1]])
if new_word > entry[0]:
count += 1
print(count)
print()
print("Zad. 4.")
maks = -1
for entry in sil:
num = "".join([str(ord(x) - ord("A") + 1) for x in entry[0]])
num = int(num)
maks = max(maks, num)
print(maks)
print()
print("Zad. 5.")
counts = {"": -1}
for entry in sil:
key = " ".join(entry)
counts.setdefault(key, 0)
counts[key] += 1
maks = ""
for key in counts.keys():
if counts[key] > counts[maks]:
maks = key
print(f"{maks} {counts[maks]}")
del counts, maks, key
print()
print("Zad. 6.")
count = 0
for entry in sil:
nowe = "".join([chr(int(x) + ord("A")) for x in entry[1]])
res = entry[0].find(nowe)
if res < 0:
continue
res2 = entry[0].find(nowe, res+1)
if res2 > res:
count += 1
print(count)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment