The chessboard is empty. In the center is the king. He can move only one square at a time, but in any direction — or he can choose not to move at all. How many turns would it take him, moving randomly, to exit the chessboard?
Continue reading
Category Archives: Exercise
Fizz Buzz
The FizzBuzz problem is quite easy to explain, but not as easy to code because you can go in so many directions. It works like this:
Continue reading
The Whole Month from a Single Day
Months have a pattern: All months feature weeks of seven days. The month can start on any day of the week. And months have a varying number of total days, 28, 29, 30, or 31. Given this data, you can display the days and weeks of any month when given only a specific date and the day of the week upon which it falls.
Continue reading
Counting in Alphabedecimal
In C, you can easily count from 000 to 999 (decimal), from 000 to 777 (octal), and from 000 to FFF (hexadecimal). These examples are in bases 10, 8, and 16, respectively. When it comes to counting from AAAA to ZZZZ, however, you must code your own routine.
Continue reading
Initial Caps
A filter is a program that accepts standard input and generates standard output. These programs are fun to write, providing you have a goal in mind and some way to manipulate the incoming text in a manner that’s significant enough to notice in the output.
Continue reading
Shuffle That Playlist
Recently, I created a playlist of songs on a certain online subscription service. I chose to shuffle the tunes, but found that one song in particular played more often than the others. My immediate thought was, “Why can’t the programmers design a shuffled playlist that doesn’t overplay the same song”? Rather than email the programmers, I thought I’d present the puzzle as this month’s Exercise.
Continue reading
Duplicated Letters
I’ve been working on a program that counts unique words in a text file. It’s an interesting exercise and explores the larger realm of pattern matching. You can try such scanning on a smaller scale by coding a program that counts the frequency of letters within a string. And that task is presented as this month’s Exercise.
Continue reading
Fill My Grid
I’m fascinated by grids. Consider the chessboard, which is a grid. Or think about the most basic game grid, a 3-by-3 array for a game of tic-tac-toe. Programming a grid is a common thing, so your best hope is that this month’s Exercise is yet another super cinchy silly grid program.
Continue reading
The Leap Year Function
My brain’s algorithm for determining whether the current year is a leap year is based on US Presidential elections. They always happen on a leap year. Or do they?
Continue reading
Translating a Timestamp
A timestamp is one of those tricky chunks of data that’s not really a single value. Often it’s a clutch of integers or — worse — it’s a string. To do time calculations on the timestamp, you must translate it into a more useful form.
Continue reading