Skip to content

Instantly share code, notes, and snippets.

@namedgraph
Created December 23, 2025 13:50
Show Gist options
  • Select an option

  • Save namedgraph/4e5b6b54fa17094f4e0f8fe55bc8d87a to your computer and use it in GitHub Desktop.

Select an option

Save namedgraph/4e5b6b54fa17094f4e0f8fe55bc8d87a to your computer and use it in GitHub Desktop.
SPARQL Christmas tree
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?line
WHERE {
VALUES ?row { 1 2 3 4 5 6 7 }
# Width of the widest row (9 stars + 2 spaces = 11 total)
BIND(11 AS ?width)
# Calculate number of stars for this row
BIND(IF(?row <= 5, (2 * ?row) - 1, 1) AS ?numStars)
# Calculate spaces on each side
BIND((?width - ?numStars) / 2 AS ?numSpaces)
# Generate the line with balanced spacing
BIND(SUBSTR(" ", 1, ?numSpaces) AS ?spacePart)
BIND(SUBSTR("*********", 1, ?numStars) AS ?starPart)
BIND(CONCAT(?spacePart, ?starPart, ?spacePart) AS ?line)
}
ORDER BY ?row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment