Car Crash
October 25, 2018
On Saturday morning I had a head-on collision at 75MPH, Medevac helicopter, serious internal bleeding, no broken bones. I spent four days in hospital, including one-and-a-half days in intensive care. I am home now, moving slowly but mostly okay.
I was alone in the car on an interstate highway early in the morning, heading to a weekend with friends away from home. About a minute ahead of me, an 18-wheel tractor/trailer rig hit a deer, lost control, jack-knifed and overturned, leaving the right lane blocked with the bottom of the tractor facing oncoming traffic. Because it was still astronomical twilight, with no moon and no street lamps, I did not see the tractor until it was within range of my headlights, and I was unable to avoid the collision, although I did partially swerve and struck only the right half of my car, from centerline to right side, spinning twice.
In the car about fifteen seconds behind me were four volunteer firefighters on their way to start their shift, so they were on the scene in seconds. They helped me out of the car, and I walked under my own power to the ambulance. The trainee driver of the truck was uninjured. The lead driver of the truck was asleep in the cab’s bed, and suffered a broken left leg.
My left ankle has a deep bruise, but is not broken, from striking the brake pedal; it is painful. My belly has a deep bruise from striking the steering wheel, and was the source of the internal bleeding; I take blood-thinning medication due to two prior pulmonary embolisms, so the bleeding was serious. I was flown from a local hospital to a regional first-class trauma center shortly after the crash. They monitored the bleeding, which stopped on its own after about two days without need for surgery (which was a real possibility). The bruise on my right belly is about twice the size of my right hand with fingers splayed wide, and is mostly black, with a few tinges of deep purple; it is not painful unless I bend or twist badly, which I have learned not to do. I am wearing a corset (the hospital calls it an abdominal binder) and taking a very low dose of pain-killers.
I’ve spoken to my boss; she even came to the hospital to visit and bring flowers. I’ll be away from work for at least several weeks, and away from blogging for just as long. I would appreciate it if my readers keep doing exercises while I am away; just look for any old exercises that strike your fancy.
Square Digit Chains
October 19, 2018
Today’s task appears on Project Euler, Rosetta Code, and Sloane’s, so it is well worth a look; we even did a version of this task in a previous exercise. Here is the Project Euler version of the problem:
A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example:
44 → 32 → 13 → 10 → 1 → 1
85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89
Therefore any chain that arrives at 1 or 89 will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at 1 or 89.
How many starting numbers below ten million will arrive at 89?
Your task is to write a program to find the count of starting numbers below ten million that arrive at 89, following the usual Project Euler rule that your computation may take no more than a minute of computation on a recent-vintage personal computer. 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.
Five Weekends
October 16, 2018
This task comes to us from Rosetta Code: The month of October 2010 has five Fridays, five Saturdays and five Sundays.
Your task is to count and make a list of all months from 1900 to 2100, inclusive, that have five Fridays, Saturdays and Sundays, and to count and make a list of all years from 1900 to 2100, inclusive, that have no such months. 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.
Boxing The Compass
October 12, 2018
Modern navigators use the 360° angles of a circle to point to compass directions, but traditional mariners use compass points with names like SW and ENE.
Your task is to write a program that converts from degrees to compass points. 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.
Babbage’s Number
October 9, 2018
Charles Babbage, whose Analytical Engine was a direct predecessor of today’s digital computer, gave this example of a problem that his Analytical Engine could solve in an 1837 letter to Lord Bowden:
What is the smallest positive integer whose square ends in the digits 269,696?
Babbage knew that 99,736 has a square with the required ending, but didn’t know if there was a smaller number.
Your task is to find Babbages’s number. 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.
Leap Year
October 5, 2018
Today’s exercise comes from a student who asked for homework help on the internet:
Write a program that determines whether or not a given year is a leap year. A year is a leap year if it is divisible by 4, except that it is not a leap year if it is divisible by 100, except that it is a leap year if it is divisible by 400.
Your task is to write a program to identify leap years. 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.
Palindrome List
October 2, 2018
Today’s exercise sounds like a homework problem:
Write a program that determines if a linked list of integers is palindromic — i.e., reads the same in both directions. Your solution must operate in O(1) space.
Your task is to write a program to determine if a list of integers is palindromic, in O(1) space. 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.