String Rotations

February 28, 2020

A string like abc has three rotations: abc, bca, and cab.

Your task is to write a program that computes all the rotations of a string. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

Pythagorean Quadruple

February 25, 2020

A Pythagorean quadruple consists of four positive integers a, b, c and d such that abcd and a² + b² + c² = d². For instance, (2 3 6 7) is a Pythagorean quadruple because 2² + 3² + 6² = 4 + 9 + 36 = 49 = 7².

Your task is to write a program that counts the Pythagorian quadruples with a, b, c less than or equal to some given N, and compute the number of Pythagorian quadruples with N = 1000. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

Formatted Dates

February 21, 2020

Regular readers of this blog know that I work with a team of programmers, sysadmins and database administrators to maintain a large legacy database application, running on Oracle and HP-UX, and Scheme is nowhere in sight. Lately I have been “stealth programming” by writing awk programs in shell wrappers, because shell programming is a normal part of our environment. One thing I have been doing is formatting reports with awk. That frequently requires a formatted date string, either for today or some other day; gawk provides the strftime function to format dates, but Posix awk, which is what HP-UX provides, doesn’t. So I wrote my own.

Your task is to write a function that formats dates; use any convention you like to determine how the date is formatted. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

Square Triple

February 14, 2020

We have a simple homework problem today:

Given a list of distinct integers, find all triples (x y z) where x, y and z are in the list and x * y = z².

Your task is to find the list of triples. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

Removing Spaces

February 11, 2020

We have a simple task today, with dozens of potential solutions:

Write a program to remove all spaces from a string.

Your task is to write a program to remove all spaces from a string. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

My Mailbag

February 7, 2020

I had two interesting emails from readers this week. I’ll discuss both of them, but suppress the names of the writers; they can identify themselves in the comments below if they wish.

One writer saw Johnny Ball’s video about Russian Multiplication on Numberphile and suggested it would make a good exercise. Indeed it would; in fact, we have already done it twice ([1] [2]).

Another writer suggested that the compose function in the Standard Prelude should return the identity function if called with no arguments, rather than reporting an error. That is, of course, correct; my apologies for the bug.

Your task is to write programs to perform russian multiplication and compose functions, as suggested above. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

Password Generator

February 4, 2020

Many web sites require passwords that have particular combinations of various types of characters; for instance, a web site might require a password that has at least ten characters, including at least one each from the sets of lower-case letters, upper-case letters, digits, and special characters.

Your task is to write a program that generates passwords according to specifications that you define. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2