Tuesday, March 29, 2022

Tom Scott Longest Word on 7 Segment Display

I was watching Tom Scott's video about how he coded the longest word that can be displayed using 7 segment display. I noticed that he was using Javascript and I suppose there's nothing wrong with that. However, I was wondering how easy it is to do using Linux shell.




And so, I simply did it, and it only took 1 line. 4 lines if you separate the pipes, and 3 if you think that sorting is optional,  and it is optional if you specify 11 letters or above. But we're not sure about it, so let's just count everything and sort it out at the end. I cheated a bit by using awk and there are ways to do it using bash, but not as easy.




First line is the dictionary file. Second is filtering out the words. Here, I use "beghilos" for calculator display. Third is filtering out the length. No less than 3. No more than 11. And print out the length of the word before the actual word. Finally, just sort it out.


Simple. Running time is about 0.2s including display. 0.14s without. Sorting, of course, takes time, but you get all the words from shortest to longest, including duplicates!


And that's it for a quick coding session. The hardest part was looking up awk documentation since I'm rusty.


Incidentally, using the letters as Tom did yields "uncharacteristically" at 20 letters, with running time of 0.3s out of 31997 possible words.


Tuesday, March 22, 2022

Publish Javascript Code

 I wonder how to publish my Processing code. I suppose I can just release the source code and let others type them. Looking at the examples, though, it seems that it's done with Processing.js, which is Javascript.

Hmmm. I may need my own website for it. I doubt blogspot is compatible with it.


And it turns out that someone already did it.

http://dhetricks.blogspot.com/2012/01/how-to-insert-javascript-inside-blogger.html

So, there you go.



Saturday, March 19, 2022

Steganography part 6

 



And that's all for bootstrap code for Steganography Decode. Notice that I swapped Blue channel for Alpha channel. I want to keep things simple for now.


Saturday, March 12, 2022

Steganography part 5

 Steganography - Opague background 

Yes, I wrote the program in one go, and was feeling smug, until I realize that I never saved the picture! And I need to use createGraphic() in order to maintain alpha channel. 


Oh, well. Next version is coming up, next week. I will split the program proper: One to Encode. Another to Decode. Just to make sure.



Thursday, March 10, 2022

Steganography part 4

 



Steganography - EncodePic

The most time consuming part about this program is the design. I knew I want a header, but what should I put in? 

1. File id: 4 bytes+newline 

2. Version: 2 bytes+ newline

3. Format: 1 byte+ newline

4. Size: 4 bytes+newline

5. Filename: 16 bytes+newline


Total: 32 bytes header. Optional: multiple files. Repeating 3-5 until EOF.


Note: There's a bug as shown. loadPixel() needs to be called first. Move it to after printing Encode start and before Write Header comment. Otherwise, you'll get Null Pointer Exception because the pixels[] isn't instantiated. 


Tuesday, March 8, 2022

Steganography part 3

 



Steganography - Main Loop

Seems like I've been using this construct more often. I probably should think about doing it CLI on the command line.


Friday, March 4, 2022

Steganography part 2

 


Reading the bytes are surprisingly simple, as well as writing it, as long as it stays in the alpha channel. However, I think I will spread it around since Raspberry Pi works on RGB565 color scheme. We'll see how well that works.


Wednesday, March 2, 2022

Steganography part 1

 What is Steganography? It's hidden message. Usually, this is some message in a picture, but it can be anything. So, that's the core code. Of course, the devil is in the details! But that's part 2.


I do hate syntax coloring. We didn't use to have it, and it never held us back.