This page includes working JavaScript that fetches the Google Doc and prints the grid, plus equivalent functions in Python, TypeScript, Java, Kotlin, C#, C++, Go, Rust, Swift, and Ruby.
import requests
from bs4 import BeautifulSoup
def decode_doc(url: str) -> None:
resp = requests.get(url)
resp.raise_for_status()
soup = BeautifulSoup(resp.text, "html.parser")
triples = []
for row in soup.select("table tr"):
cells = row.find_all("td")
if len(cells) != 3:
continue
x = cells[0].get_text(strip=True)
ch = cells[1].get_text(strip=True)
y = cells[2].get_text(strip=True)
try:
x = int(x)
y = int(y)
except ValueError:
continue
if ch:
triples.append((x, y, ch))
max_x = max(x for x, _, _ in triples)
max_y = max(y for _, y, _ in triples)
grid = [[" " for _ in range(max_x + 1)] for _ in range(max_y + 1)]
for x, y, ch in triples:
grid[y][x] = ch
for row in grid:
print("".join(row))
# Example:
# decode_doc("https://docs.google.com/document/d/e/2PACX-1vSvM5gDlNvt7npYHhp_XfsJvuntUhq184By5xO_pA4b_gCWeXb6dM6ZxwN8rE6S4ghUsCj2VKR21oEP/pub")
import fetch from "node-fetch";
import { JSDOM } from "jsdom";
async function decodeDoc(url) {
const res = await fetch(url);
const html = await res.text();
const dom = new JSDOM(html);
const doc = dom.window.document;
const rows = [...doc.querySelectorAll("table tr")];
const triples = [];
for (const row of rows) {
const cells = row.querySelectorAll("td");
if (cells.length !== 3) continue;
const x = parseInt(cells[0].textContent.trim(), 10);
const ch = cells[1].textContent.trim();
const y = parseInt(cells[2].textContent.trim(), 10);
if (!Number.isNaN(x) && !Number.isNaN(y) && ch) {
triples.push({ x, y, ch });
}
}
const maxX = Math.max(...triples.map(t => t.x));
const maxY = Math.max(...triples.map(t => t.y));
const grid = Array.from({ length: maxY + 1 }, () =>
Array.from({ length: maxX + 1 }, () => " ")
);
for (const { x, y, ch } of triples) {
grid[y][x] = ch;
}
console.log(grid.map(r => r.join("")).join("\n"));
}
// Example:
// decodeDoc("https://docs.google.com/document/d/e/2PACX-1vSvM5gDlNvt7npYHhp_XfsJvuntUhq184By5xO_pA4b_gCWeXb6dM6ZxwN8rE6S4ghUsCj2VKR21oEP/pub");
import fetch from "node-fetch";
import { JSDOM } from "jsdom";
interface Triple {
x: number;
y: number;
ch: string;
}
export async function decodeDoc(url: string): Promise<void> {
const res = await fetch(url);
const html = await res.text();
const dom = new JSDOM(html);
const doc = dom.window.document;
const rows = Array.from(doc.querySelectorAll("table tr"));
const triples: Triple[] = [];
for (const row of rows) {
const cells = row.querySelectorAll("td");
if (cells.length !== 3) continue;
const x = parseInt(cells[0].textContent!.trim(), 10);
const ch = cells[1].textContent!.trim();
const y = parseInt(cells[2].textContent!.trim(), 10);
if (!Number.isNaN(x) && !Number.isNaN(y) && ch) {
triples.push({ x, y, ch });
}
}
const maxX = Math.max(...triples.map(t => t.x));
const maxY = Math.max(...triples.map(t => t.y));
const grid: string[][] = Array.from({ length: maxY + 1 }, () =>
Array.from({ length: maxX + 1 }, () => " ")
);
for (const { x, y, ch } of triples) {
grid[y][x] = ch;
}
console.log(grid.map(r => r.join("")).join("\n"));
}
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.*;
public class Decoder {
public static void decodeDoc(String url) throws Exception {
Document doc = Jsoup.connect(url).get();
Elements rows = doc.select("table tr");
class Triple {
int x, y; String ch;
Triple(int x, String ch, int y) { this.x = x; this.ch = ch; this.y = y; }
}
List<Triple> triples = new ArrayList<>();
for (Element row : rows) {
Elements cells = row.select("td");
if (cells.size() != 3) continue;
try {
int x = Integer.parseInt(cells.get(0).text().trim());
String ch = cells.get(1).text().trim();
int y = Integer.parseInt(cells.get(2).text().trim());
if (!ch.isEmpty()) {
triples.add(new Triple(x, ch, y));
}
} catch (NumberFormatException ignored) {}
}
int maxX = triples.stream().mapToInt(t -> t.x).max().orElse(0);
int maxY = triples.stream().mapToInt(t -> t.y).max().orElse(0);
char[][] grid = new char[maxY + 1][maxX + 1];
for (int y = 0; y <= maxY; y++) Arrays.fill(grid[y], ' ');
for (Triple t : triples) {
grid[t.y][t.x] = t.ch.charAt(0);
}
for (int y = 0; y <= maxY; y++) {
System.out.println(new String(grid[y]));
}
}
}
import org.jsoup.Jsoup
data class TriplePoint(val x: Int, val ch: String, val y: Int)
fun decodeDoc(url: String) {
val doc = Jsoup.connect(url).get()
val rows = doc.select("table tr")
val triples = mutableListOf<TriplePoint>()
for (row in rows) {
val cells = row.select("td")
if (cells.size != 3) continue
val xText = cells[0].text().trim()
val ch = cells[1].text().trim()
val yText = cells[2].text().trim()
val x = xText.toIntOrNull()
val y = yText.toIntOrNull()
if (x != null && y != null && ch.isNotEmpty()) {
triples.add(TriplePoint(x, ch, y))
}
}
val maxX = triples.maxOfOrNull { it.x } ?: 0
val maxY = triples.maxOfOrNull { it.y } ?: 0
val grid = Array(maxY + 1) { CharArray(maxX + 1) { ' ' } }
for (t in triples) {
grid[t.y][t.x] = t.ch[0]
}
for (y in 0..maxY) {
println(String(grid[y]))
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using HtmlAgilityPack;
public class Decoder {
public static void DecodeDoc(string url) {
var web = new HtmlWeb();
var doc = web.Load(url);
var triples = new List<(int x, string ch, int y)>();
foreach (var row in doc.DocumentNode.SelectNodes("//table//tr") ?? new HtmlNodeCollection(null)) {
var cells = row.SelectNodes("td");
if (cells == null || cells.Count != 3) continue;
if (int.TryParse(cells[0].InnerText.Trim(), out int x) &&
int.TryParse(cells[2].InnerText.Trim(), out int y)) {
var ch = cells[1].InnerText.Trim();
if (!string.IsNullOrEmpty(ch)) {
triples.Add((x, ch, y));
}
}
}
int maxX = triples.Max(t => t.x);
int maxY = triples.Max(t => t.y);
char[][] grid = new char[maxY + 1][];
for (int y = 0; y <= maxY; y++) {
grid[y] = new char[maxX + 1];
for (int x = 0; x <= maxX; x++) grid[y][x] = ' ';
}
foreach (var t in triples) {
grid[t.y][t.x] = t.ch[0];
}
for (int y = 0; y <= maxY; y++) {
Console.WriteLine(new string(grid[y]));
}
}
}
#include <bits/stdc++.h>
#include <curl/curl.h>
using namespace std;
static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) {
((string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void decodeDoc(const string &url) {
// Fetch HTML via libcurl
CURL *curl = curl_easy_init();
string html;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
// Very naive parsing: look for <tr>...</tr> and <td>...</td>
struct Triple { int x, y; string ch; };
vector<Triple> triples;
size_t pos = 0;
while ((pos = html.find("<tr", pos)) != string::npos) {
size_t tr_end = html.find("</tr>", pos);
if (tr_end == string::npos) break;
string row = html.substr(pos, tr_end - pos);
pos = tr_end + 5;
vector<string> cells;
size_t cpos = 0;
while ((cpos = row.find("<td", cpos)) != string::npos) {
size_t td_start = row.find(">", cpos);
if (td_start == string::npos) break;
size_t td_end = row.find("</td>", td_start);
if (td_end == string::npos) break;
string cell = row.substr(td_start + 1, td_end - td_start - 1);
// strip tags and whitespace
cell.erase(remove_if(cell.begin(), cell.end(), ::isspace), cell.end());
cells.push_back(cell);
cpos = td_end + 5;
}
if (cells.size() == 3) {
try {
int x = stoi(cells[0]);
int y = stoi(cells[2]);
string ch = cells[1];
if (!ch.empty()) triples.push_back({x, y, ch});
} catch (...) {}
}
}
int maxX = 0, maxY = 0;
for (auto &t : triples) {
maxX = max(maxX, t.x);
maxY = max(maxY, t.y);
}
vector<string> grid(maxY + 1, string(maxX + 1, ' '));
for (auto &t : triples) {
grid[t.y][t.x] = t.ch[0];
}
for (int y = 0; y <= maxY; ++y) {
cout << grid[y] << "\n";
}
}
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
func decodeDoc(url string) {
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
log.Fatal(err)
}
type Triple struct {
x int
ch string
y int
}
var triples []Triple
doc.Find("table tr").Each(func(_ int, s *goquery.Selection) {
cells := s.Find("td")
if cells.Length() != 3 {
return
}
xText := strings.TrimSpace(cells.Eq(0).Text())
ch := strings.TrimSpace(cells.Eq(1).Text())
yText := strings.TrimSpace(cells.Eq(2).Text())
x, err1 := strconv.Atoi(xText)
y, err2 := strconv.Atoi(yText)
if err1 == nil && err2 == nil && ch != "" {
triples = append(triples, Triple{x, ch, y})
}
})
maxX, maxY := 0, 0
for _, t := range triples {
if t.x > maxX {
maxX = t.x
}
if t.y > maxY {
maxY = t.y
}
}
grid := make([][]rune, maxY+1)
for y := range grid {
grid[y] = make([]rune, maxX+1)
for x := range grid[y] {
grid[y][x] = ' '
}
}
for _, t := range triples {
grid[t.y][t.x] = []rune(t.ch)[0]
}
for y := 0; y <= maxY; y++ {
fmt.Println(string(grid[y]))
}
}
use reqwest::blocking::get;
use scraper::{Html, Selector};
pub fn decode_doc(url: &str) -> Result<(), Box<dyn std::error::Error>> {
let body = get(url)?.text()?;
let doc = Html::parse_document(&body);
let tr_sel = Selector::parse("table tr").unwrap();
let td_sel = Selector::parse("td").unwrap();
#[derive(Debug)]
struct Triple {
x: usize,
ch: String,
y: usize,
}
let mut triples = Vec::new();
for row in doc.select(&tr_sel) {
let cells: Vec<String> = row
.select(&td_sel)
.map(|c| c.text().collect::<String>().trim().to_string())
.collect();
if cells.len() != 3 {
continue;
}
if let (Ok(x), Ok(y)) = (cells[0].parse(), cells[2].parse()) {
let ch = cells[1].clone();
if !ch.is_empty() {
triples.push(Triple { x, ch, y });
}
}
}
let max_x = triples.iter().map(|t| t.x).max().unwrap_or(0);
let max_y = triples.iter().map(|t| t.y).max().unwrap_or(0);
let mut grid = vec![vec![' '; max_x + 1]; max_y + 1];
for t in triples {
grid[t.y][t.x] = t.ch.chars().next().unwrap();
}
for row in grid {
let line: String = row.into_iter().collect();
println!("{}", line);
}
Ok(())
}
import Foundation
func decodeDoc(_ urlString: String) {
guard let url = URL(string: urlString),
let data = try? Data(contentsOf: url),
let html = String(data: data, encoding: .utf8) else {
print("Failed to fetch")
return
}
// Very naive parsing: split by "<tr" and "<td>...</td>"
struct Triple { let x: Int; let ch: String; let y: Int }
var triples: [Triple] = []
let rows = html.components(separatedBy: "<tr")
for row in rows {
var cells: [String] = []
var search = row
while let tdRange = search.range(of: "<td") {
guard let gt = search.range(of: ">", range: tdRange.upperBound..<search.endIndex),
let end = search.range(of: "</td>", range: gt.upperBound..<search.endIndex) else {
break
}
let cell = String(search[gt.upperBound..<end.lowerBound]).trimmingCharacters(in: .whitespacesAndNewlines)
cells.append(cell)
search = String(search[end.upperBound...])
}
if cells.count == 3,
let x = Int(cells[0].trimmingCharacters(in: .whitespaces)),
let y = Int(cells[2].trimmingCharacters(in: .whitespaces)) {
let ch = cells[1].trimmingCharacters(in: .whitespacesAndNewlines)
if !ch.isEmpty {
triples.append(Triple(x: x, ch: ch, y: y))
}
}
}
let maxX = triples.map { $0.x }.max() ?? 0
let maxY = triples.map { $0.y }.max() ?? 0
var grid = Array(repeating: Array(repeating: Character(" "), count: maxX + 1), count: maxY + 1)
for t in triples {
grid[t.y][t.x] = t.ch.first ?? " "
}
for row in grid {
print(String(row))
}
}
require "open-uri"
require "nokogiri"
def decode_doc(url)
html = URI.open(url, &:read)
doc = Nokogiri::HTML(html)
triples = []
doc.css("table tr").each do |tr|
tds = tr.css("td")
next unless tds.size == 3
x_text = tds[0].text.strip
ch = tds[1].text.strip
y_text = tds[2].text.strip
begin
x = Integer(x_text)
y = Integer(y_text)
triples << [x, ch, y] unless ch.empty?
rescue ArgumentError
next
end
end
max_x = triples.map { |x, _, _| x }.max || 0
max_y = triples.map { |_, _, y| y }.max || 0
grid = Array.new(max_y + 1) { Array.new(max_x + 1, " ") }
triples.each do |x, ch, y|
grid[y][x] = ch
end
grid.each { |row| puts row.join }
end