This month’s Exercise is based on code presented in the June 1 Lesson: split a string into separate words. The difference is that each word you pluck from the string is followed by the number of letters in that word.
Continue reading
Category Archives: Exercise
Primitive Math
In a recent Lesson, I explored upon the idea of creating binary math macros. This technique was popular in Assembly language programs where the processor lacks high order math functions, including basic multiplication and division. In C you can code one-line macros that mimic Assembly’s bit-shifting behavior required to multiply values.
Continue reading
Interesting Numbers
Long ago, I worked with a programmer who had a habit of referring to certain values as “interesting.” What was an interesting number to him? 43,690. Yeah, it seems dull, but in hex it’s 0xAAAA and in binary it’s 1010101010101010. Interesting.
Continue reading
Find the Duplicates
You’ll find multiple reasons to remove duplicates from a series of random numbers. The main reason is that the process or generating random numbers is capable of yielding duplicate values. But more importantly, if your list represents discrete items in the real world, such as playing cards, you can’t really have a duplicate value pop up.
Continue reading
The Wandering King
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
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