Hi, I'm Andinus.
@Algot Actually I had modified it to use @words array as the dictionary, I thought there won't be a dictionary file on that machine. But turns out I was wrong, there is a dictionary file.
In this case there are only 3 words in @words: hello, world, terminated & none are present in the grid so it failed.
It does find "perspective" when I use the dictionary.
@Algot Indeed it will be cool. What kind of solver are you thinking of? I think something that visualizes the problem solving will be cool. I'll try making something that does this... someday!
The three variables at the top are:
- @words: This is the dictionary.
- @puzzle: This is the puzzle, note that it's a two-dimensional array.
- @gray-squares: These are positions of starting points for the puzzle.
I'm glad you liked it :) Yes, feel free to link it on your website.
I want to solve this another way. Currently it's going over words in a dictionary and trying to find it in the grid. I'll try starting from the grid & checking to see if that word exist in the dictionary.
The idea is to check if there exists any word in the dictionary that starts with whatever we've build with the grid. If there are none then we try another path. We do this until we find a word in the grid that exist in the dictionary.
This method will be bad for real word-search puzzles but it might be fine for your puzzles because the starting points are restricted in them. I'm actually not sure if it'll be bad but I think so because we're going to load the whole dictionary in memory for this & then we will be performing lots of searching.
I already have some ideas to make that searching part better, we could pass the resulting array when we move ahead because any movement will give us a subset of word that the previous search had.
For example, "hello" will match a subset of matches of "hell" in dictionary. So, we don't have to search "hello" in whole dictionary, we just search it in the results of "hell" search.
This other way I described, my brain tries to solve it this way. It just follows the grid until it finds the word.
Hah, sorry for this wall of text. I'll implement Octans this way sometime in future & also the cgi thing.
And sorry for the delete & re-draft. I organized it properly, this is the final version of this toot!
@samurro Indeed, that's the case. I just ran a CPU intensive task & it showed around 100% CPU usage in top but the total CPU usage was just 25%.
Look at the screenshot I've uploaded, the task shows 97.41% CPU usage but then look at the total CPU usage in top-left corner, it's just 25.0%. You can get this output by running `top -1'.
So, what you're seeing as 40% in process CPU usage is just 10% total CPU usage. Should be lower but this can totally be normal, it depends on the web pages that you're visiting.
@samurro There might be a misunderstanding in what the CPU column actually means. It can go above 100%. In your case there are 4 cores so the total can go till 400%. I'm not totally sure about this, probably @_xhr_ could clarify.
Try running `top -1' to see combined CPU statistics for all processors. And look at that value, it'll represent the CPU usage percentage we're probably thinking of.
@samurro The spike when you load the web page is totally normal, does it show high usage in Task Manager even after a while with no activity?
I'm currently monitoring Firefox with top & the CPU usage is around 30% while I write this. But as I stop writing, it goes down to 3% or so.
It really depends on the sites you're visiting. Most of my active tabs are static HTML, they're not doing anything while idle.
Just a test:
- Restart Firefox.
- Load news.ycombinator.com on 10 tabs & then leave Firefox idle for a while.
- Check top output after a minute of leaving it idle, the CPU usage shouldn't be as high as 40%.
> Is it reading the grid from the image description?
Yes, it's reading the puzzle from the description.
> If I knew how to code in Raku, I would examine the repository to completely understand your implementation.
I added some more comments trying to explain the implementation. Reading a bit about Depth-First search would help understanding the word-search subroutine.
This program consists of 4 parts:
1. Set the puzzle in @puzzle & starting positions in @gray-squares.
2. Loop over the dictionary words & search the grid.
3. word-search subroutine: Searches the grid for given word.
4. neighbors subroutine: Returns the neighbors of given grid.
Also, do you know Perl? I could probably port it to Perl someday.
> I do like that it elegantly handles the asterisks, too.
Yeah, octans is specific to your word-search puzzles. It only starts at grids with an asterisks.
> It sounds like the program is designed to be downloaded to one's own computer and run from the command line (Linux required?)
It's a Raku script, you would need the Raku interpreter. Rakudo star bundle includes the interpreter along with zef (modules installer): https://rakudo.org/star
Octans requires the WWW module, it's not bundled with Rakudo star distribution so you would have to install it yourself with zef. It's as simple as running: zef install WWW
I just created a branch `without-www'. It's the same code but it'll work without WWW dependency: https://github.com/andinus/octans/tree/without-www
So, if you're able to get the Raku interpreter then you could try running `without-www' branch script. And if you're able to get zef running then simply install the module `WWW' and run the main script.
No, Linux is not required. It should work fine on macOS, Windows & BSDs. In fact I'm running it on OpenBSD.
> Could it also be set up as a CGI script?
Yeah, I could set it up as a CGI script.
@ColinTheMathmo CGI is very simple, just print the response header of any webpage & you can learn a lot by just reading them.
Modern web frameworks do all this in the background for you, with CGI you have to do it manually.
For example, do `curl -I https://www.google.com`, it'll return something like:
set-cookie: 1P_JAR=2021-01-14-09; expires=Sat, 13-Feb-2021 09:30:11 GMT; path=/; domain=.google.com; Secure
You see that `set-cookie` header? You pass cookies in the response header & the browser sets it.
So, the thing you have to print in CGI before "\n\n" is the response header. Everything after that is the payload.
HTTP/1.1 301 Moved Permanently
The only extra header is "Location". You have to set the status to "301 ..." & add a "Location" header to do a 301 in CGI.
Here is a list of all response status codes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
@samurro I use this addon called Auto Tab Discard along with uBO, NoScript and lots of other addons.
Auto Tab Discard will discard inactive tabs after a set threshold. Makes Firefox usable for me.
Have you checked if enabling SMP has an impact? It's disabled by default on OpenBSD.
Also, check `about:performance`.
> Some of us, who have made campaigning for digital freedom our goal, reject all nonfree programs. However, as a practical matter, even a little step towards that goal is good. A walk of a thousand miles consists of lots of steps.
So, yeah you can use non-free software if it necessary but make an effort to move to free-software.
I'm stuck after upgrading to #OpenBSD 6.8, any idea how to fix this?
@polettix Oh! I didn't check for 1.
Thanks for pointing this out! I pushed the fix: https://github.com/manwar/perlweeklychallenge-club/pull/2460
And also discovered another bug in the process.
Hi, I'm Andinus.
masto instance for the tildeverse