Math For Kids

I just created a couple of PHP scripts for my nephew to help him with his math. Actually, any kid or adult can use it. The program performs some basic mathematics such as addition, subtraction, multiplication and division. The numbers and result are totally random. You will get a different set of numbers and result each time. You can play with it as long as you want, and as often as you like.

The result of each equation is hidden when the page is initially loaded. You can click the “Display Answer” link to reveal the answer. Clicking the “New Question” link will generate a different set of random numbers. Navigation is located at the top. You can select: Addition, Subtraction, Multiplication and Division. Give it a try.

Just a couple of other things that I wanted to mention. I’m using Javascript to hide the answers when the documents are initially loaded. The math result is contained inside a hidden div. The div is toggled on or off or displayed or hidden, by simply clicking on a link. The Javascript that I use can be viewed and copied if you look at the source.

In addition, I’m using simple a rand() function to generate a set of numbers. I use basic PHP math operations to perform the math operations. I do a couple of checks in subtraction and division scripts to avoid the following: subtraction which results in negative number, division by zero, and a divisible number, meaning no remainders when performing divisions. The scripts can be easily modified.

Examples

Addition

$a = rand(0, 20);  // This generates a random number between 0 and 20.
$b = rand(0, 20);  // This generates a random number between 0 and 20.
$c = $a + $b; // Performs addition

Subtraction

$a = rand(0, 20);  // This generates a random number between 0 and 20.
$b = rand(0, 20);  // This generates a random number between 0 and 20.
if ($a>$b) {$c=$a-$b;} else {$c=$b-$a;}  // No negative results

Division

$a = rand(2, 100);  // This generates a random number between 2 and 100.
$b = rand(2, 100);  // This generates a random number between 2 and 100.
do {
$c = $a / $b;
} while ($a % $b != 0) // Checks if result is divisible

It was a fun little project.

Block Spam Using Math

In a normal day, I usually get over 1000 spam comments on my blog. Although I don’t have to delete the spam, it still takes up resource on the database. By the way, Akismet deletes all spam comments after two weeks. This gives the blog owner time to recover if a valid comment was mistakenly classified as spam.

If you really want to cut down on spam comments, you can implement Captcha. But, lots of people hate Captcha including myself, especially the ones that are unreadable. What is more frustrating than trying to guess a mangled captcha only to be thwarted again and again because it’s unreadable. Enter a solution using simple math.

So, I decided to install a WordPress plugin called Block-Spam-By-Math. The plugin adds a custom field to the comments form by posting a simple math problem. Anyone who passed at least first grade should be able to answer the addition problem. After all, 8 + 2 = is not that difficult to solve.

Automated bots that send spam will have problems submitting past the math problem. Unless, the bots become sophisticated enough to read text and solve the math problems themselves. It sounds like a whole lot of trouble, just to add that feature to send spam.

At least temporarily, spam has been cut down to almost zero. Now, I just have to deal with humans who send them. And that’s infrequent compared to bots.