Skip to content

Instantly share code, notes, and snippets.

@STashakkori
Created June 19, 2025 15:00
Show Gist options
  • Save STashakkori/b897ab1fd949bc608b12c7fdd1ad4f69 to your computer and use it in GitHub Desktop.
Save STashakkori/b897ab1fd949bc608b12c7fdd1ad4f69 to your computer and use it in GitHub Desktop.
DataAnnotations Challenge Solution
# 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