Created
April 1, 2023 11:45
-
-
Save andrew-wilkes/5bd62b287591efa2e6e9507a6d00d2c6 to your computer and use it in GitHub Desktop.
Godot 4 code to extract sudoku puzzle from html table
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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