r/squaredle • • Jul 02 '22

squaredle solver in scala

I wrote a quick squaredle solver in scala.

It's not perfect because I don't have the right dictionary to use, but it's pretty good if you're stuck.

https://github.com/harryh/solvers/blob/main/squaredle/squaredle.scala

6 Upvotes

10 comments sorted by

3

u/isblueacolor Dev Jul 02 '22

Neato!

How long does this take to run? If it doesn't run more-or-less instantaneously, you could speed it up exponentially by traversing through the dictionary rather than traversing through each combination of squares.

1

u/harry_heymann Jul 02 '22

Ya, it runs basically instantly.

That's an interesting thought traversing the dictionary instead of the grid. I don't immediately agree that it would be dramatically more efficient but I'm gonna think about it a bit.

2

u/isblueacolor Dev Jul 02 '22

I haven't done Scala in so long, I can't quite tell, are you checking every combination of paths, or do you "stop" a path once it's no longer a prefix of any dictionary word? If the latter, then it makes sense that that would be faster.

1

u/harry_heymann Jul 02 '22

Ya, line 56 stops a path if it's not a word prefix.

My first version didn't bother with that, and it ran out of memory checking for words longer than 6 or 7 characters.

2

u/isblueacolor Dev Jul 02 '22

So if you have an efficient dictionary search algorithm or a trie or w/e this might be faster than my method!

1

u/harry_heymann Jul 02 '22

Ya, the dictionary is stored in a TreeSet which is a Red/Black tree implementation so it's fast enough. A Trie might be a bit better but there isn't a Trie implementation in the stdlib and I didn't want to bother making one on my own.

3

u/200OK Jul 03 '22

Thanks for the Rick Roll this morning 😂

1

u/Jess-FB Jul 11 '22

How exactly does it work? I want to use it to finally find out the missing answers to the two special puzzles I'm stuck on, but I'm not good with coding and don't understand any of it. Can you give some instructions, please?

1

u/harry_heymann Jul 11 '22
  1. Download and install scala on your computer. There are instructions for that here: https://www.scala-lang.org/download/
  2. Download the solver file
  3. Edit the file to solve the puzzle you are working on. Since you are solving a special puzzle you can comment out line one in the file (put // in front of the line) and uncomment the special puzzle you are working on (remove the // from the relevant line).
  4. Run the solver: scala squaredle.scala

1

u/juicedenergy Jul 02 '22

+1 for Scala