Showing posts with label learntocode. Show all posts
Showing posts with label learntocode. Show all posts

Wednesday, June 8, 2022

Wordle Solver

 So, this popular word game called Wordle. I played it a few times, and of course, I immediately want to use the computer to do it. My usual computer is Raspberry Pi, and it turns out that it's so easy, I don't really need anything more than a bash CLI. 

My first guess was YODEL. The clue was YE aren't used, and ODL are misplaced. So, I use this command:


cat wordlistb.txt | grep -v [ye] | grep ^.[^o][^d].[^l]$ | grep o | grep d | grep l


Amazingly enough, it gives me 6 answers immediately.  Wordlistb.txt is the culled wordlist, by the way. The complete wordlist gives me 11 answers. That's quite a trim from the whole word list.

The command basically says 

1. Write out wordlistb.txt

2. Trim lines with letter y,e.

3. Include only lines with any-not o-not d-any-not l pattern

4. Include only lines with letter o

5. Include only lines with letter d

6. Include only lines with letter l

Looking at those 6 words, I search the word list from various possible letters. So, this is what I use:


grep [abcfs] wordlistb.txt


Among the word list, there is this word SCARF, that uses 4 of the missing letters. Hence, I put it in, and it reveals that none of the letters are used, except the letter F, which is misplaced.


cat wordlistb.txt | grep -v [ye] | grep ^.[^o][^d].[^lf]$ | grep o | grep d | grep l | grep f


And it gives me the answer immediately. Solvable in 3 tries!


Friday, November 6, 2020

DIY Typing Tutor in Bash

 


So, when somehow the 10fastfingers.com broke on me, I was left with no good way to practice typing. Well, I decided to write my own. Using BASH. That's shell scripting. 

I learned quite a bit about shell scripting, but there's more to do still. The biggest problem is not the coding. Actually, the biggest time sink is the design. I'm on my third design and still going on. 

The whole scripts is only about 4K. So, recreating this should only take an enjoyable afternoon. There's some advanced manipulation there, though.

Since this is done on Raspberry pi, I use pdftotext to extract texts to create my dictionary.  Turns out it's relatively quick, even on my RaspiZero. 100 most popular Project Gutenberg texts, however, took about 20 minutes to process all dictionary, the longest being top 100, 200 most common words.

I will update this later. I got some ideas about vt100 terminal cursor manipulation.