A chessboard is a gird, traditionally eight-by-eight squares for 64 positions. This game matrix can be implemented in code in a variety of ways, with a two-dimensional array being the most obvious. But this option isn’t what I chose when programming how a knight moves (from last week’s Lesson).
Continue reading
Author Archives: dgookin
Output a Colorful Chessboard
Difficulty: ★ ★ ★ ☆
Text mode need not be so dreary when it comes to generating a game of chess. You have several options, all of which stink to varying degrees.
Continue reading
Plotting Knight Moves
Computers and chess go together like Mr. Spock and Star Trek. The character of Spock is pure genius, a crazy addition to the mix that provided depth and wonder to the TV show and later movies. In chess, it’s the knight that provides the crazy addition, making the game of chess more than an advanced variation on checkers.
Continue reading
A Nifty Random Number Trick
I don’t believe I’ll ever absorb all the wondrous potential of Linux/Unix. Case in point is the /dev/random file. It’s exactly what the name implies: random stuff. And you can use this nifty file in your C programs to generate random values.
Continue reading
GMP Integers and Math
Continuing from last week’s Lesson, just as you can’t use the equal sign to assign an mpz_t huge integer value, you can’t use the standard arithmetic operators to do math — huge math. Nope, you must use special GMP library functions to do the math.
Continue reading
Playing with Ha-Yuge GMP Integers
I’ve written a few books on using external libraries, which I shamelessly plug later in this post. After confirming that the library is installed (see last week’s post), the next step isn’t to code, but rather to peruse the online documentation, the API or Application Programming Interface.
Continue reading
Palindromic Numbers – Solution
The challenge for this month’s Exercise is to output the first 100 palindromic numbers, which are integers that reflect the same digits on either side. Rather than devise a complex mathematical equation to determine these values, I cheated.
Continue reading
Really Ha-yuge Integers
Unlike real numbers, integers are stored in binary as-is: The bits are read and values set. The only limit on an integer’s value is on the number of bits in the binary chunk — the bit width — which sets the value’s range, positive and negative or just positive.
Continue reading
Palindromic Numbers
Difficulty: ★ ★ ★ ☆
I think most kids delight at discovering the palindrome, where a word or phrase contains the same letters read forward or backwards. For example, racecar, which is really two words but never mind! Imagine how such fun can be spoiled by applying the same rule to a number.
Continue reading
Reversing a String
The C language is weak when it comes to strings. Even the paltry assortment of string.h manipulation functions lacks quite a few tricks that are readily available to other languages. Among them is a function to reverse a string. So why not code your own?
Continue reading