Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Created April 1, 2023 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-wilkes/5bd62b287591efa2e6e9507a6d00d2c6 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/5bd62b287591efa2e6e9507a6d00d2c6 to your computer and use it in GitHub Desktop.
Godot 4 code to extract sudoku puzzle from html table
extends Control
func _on_button_pressed():
var html: String = $Src.text
# Find start of table
var idx1 = html.find("boardtable")
if idx1 > 0:
var idx2 = html.find("</table", idx1)
if idx2 > 0:
var table = html.substr(idx1, idx2 - idx1)
var lines = table.split("</td>")
var nums = []
for line in lines:
nums.append(line[-1])
var puzzle = nums.reduce(concat).replace(";", ".").rstrip(">")
print(puzzle)
func concat(a, b):
return a + b
@andrew-wilkes
Copy link
Author

We cut and paste the inner HTML code from https://www.sudokuwiki.org/Daily_Sudoku when using the browser developer tools via F12 when inspecting the Sudoku table code.

This Godot GDScript 4 code uses the reduce method on an array to do what the join method used to do in Godot 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment