Created
June 19, 2025 15:00
-
-
Save STashakkori/b897ab1fd949bc608b12c7fdd1ad4f69 to your computer and use it in GitHub Desktop.
DataAnnotations Challenge Solution
This file contains hidden or 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
# Working solution. Hope it helps someone | |
# $t@$h | |
import requests | |
from bs4 import BeautifulSoup | |
def decode_secret_message(doc_url): | |
# Get doc content | |
response = requests.get(doc_url) | |
html = response.text | |
soup = BeautifulSoup(html, 'html.parser') | |
text = soup.get_text(separator="\n") # Extract visible text only | |
lines = [line.strip() for line in text.splitlines() if line.strip().isdigit() or len(line.strip()) == 1] | |
# Convert to a list: (char, x, y) | |
data = [] | |
i = 0 | |
while i + 2 < len(lines): | |
try: | |
x = int(lines[i]) | |
char = lines[i + 1] | |
y = int(lines[i + 2]) | |
data.append((char, x, y)) | |
except ValueError: | |
pass # Skip malformed entries | |
i += 3 | |
if not data: | |
print("No matches found. Check document format.") | |
return | |
max_x = max(x for _, x, _ in data) # Get x dimensions | |
max_y = max(y for _, _, y in data) # Get y dimensions | |
# Fill grid of above dimensions with characters | |
grid = [[" " for _ in range(max_x + 1)] for _ in range(max_y + 1)] | |
for char, x, y in data: | |
grid[y][x] = char | |
print_grid(grid) # Print | |
def print_grid(grid): | |
for row in grid: | |
print("".join(row)) | |
decode_secret_message("https://docs.google.com/document/d/e/2PACX-1vQGUck9HIFCyezsrBSnmENk5ieJuYwpt7YHYEzeNJkIb9OSDdx-ov2nRNReKQyey-cwJOoEKUhLmN9z/pub") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment