A few examples of anagram guessing program, using several different computer languages. It's quite a good example to show the different between languages.
In here, you will learn quite few things:
- File access
- JSON
- Recursion (1 2)
- Threads
- Process (node.js)
- (List) Array operation
- Type converting (For strict type languages)
- Comprehension (Python)
- Math operation
- Algorithm
- SQL (using sqlite3) See the
pythonfolder with a web crawler example
And a few bits here and there.
This was developed on Pop!_OS (Ubuntu 20.10) and Deepin 20.x (Debian 10)
They all are a command line program, with one liner to execute in the following format:
$ [lang-ex] [path/to/script] [input]No dependencies, just need node.js installed (>= 12.x)
Run it like so:
$ node ./js/anagram.js abortThere is also another version call main.js. First you need to make the file executable:
$ chmod +x js/main.jsThen just run it like this:
$ js/main.jsFor developers using Deepin 20.x system, you might want to take a look at this note about setting up node.js on your system.
Also, I have written a development change log to explain more in depth about the why and how.
Again no dependencies, just need Python 3.x
$ python3 ./python/anagram.py abortIf you have python-is-python3 (on Ubuntu / Debian) then just python.
You can also call the interactive version main.py script in the /python folder; first you need to make it an executable file:
$ chmod +x python/main.pyThen you can just call it directly (at least it works on Linux)
$ python/main.pyIt will prompt you for input.
If you have tried the V.1 of the python version, whenever you provide a 5 or more letters word, You might run into the RecursionError.
You can read this note about how we fix the RecursionError: maximum recursion depth exceeded in comparison
Due to the PIA nature of Java. You need to install org.json.simple to your CLASSPATH before you can do anything with this code.
Or you can download the source then use ant to build it. Put the org folder (not the classes, one level down) into the /javalang folder. Then it should work (Given that you haven't setup your CLASSPATH, it will be just .)
$ cd javalang
$ java Anagram abortShould give you a result.
Basically I ran into this error:
Exception in thread "main" java.lang.SecurityException: Prohibited package name: java
Because I tried this:
$ java java/Test
And java thinks the package name is java.Test, and of course, it didn't like it. Also it doesn't really matter what you name your folder.
If you try to execute the program from outside the folder, java will think you are calling a Package, and it will fail. Therefore, you must cd into that directory before you can do anything.
It was develop using the latest PHP 8.x. You might have to install / upgrade first. You can read this note about what we have tried and tested.
To run the one liner version:
$ php php/anagram.php abortIf you want to run the interactive version then you first you need to do:
$ chmod +x php/main.php
$ php/main.phpThen you should see the prompt.
Didn't encounter any stack overflow problem, unlike Java, Javacript (node.js) and Python. And the PHP version add couple extra counter to show how many tries was happening. Sometime the random string generator (guessing a word) could calculate up to million times, but still only took a few mil second. That's really some performance improvement.
@TODO PHP 8 version
Coming soon
Coming soon
There are several Dockerfile-* on the root level (that's because we need to copy the /share folder, its outside the build context)
Therefore when you build the docker image, you need to do the following:
Well, I am using podman ...
$ docker build -f Dockerfile-[name-of-the-lang]
The dictionary is borrow from basicwords.org.
Joel Chu (c) 2021