Late-Night Puzzle Solving

First, a warning: this may be my geekiest post ever. If you want to give it a pass, you won’t hurt my feelings. In fact, I found a bunch of fluffy cats for you if you would prefer.

Anywhoo, I frequent a Web site called that is about statistics and math, and applying them to sports and politics. On Fridays, they pose little (and not-so-little) math challenges for readers. A couple of weeks ago, they posed a question about numbers that were the difference between two perfect squares. As I was reading the question an ad came up to the side, pointing out that 42 = 1 + 3 + 5 + 7.

The mandate was clear: solve the puzzle, using the information in the ad.

I noodled on the problem idly for a while, and came up with some interesting observations, but it wasn’t until I really, really couldn’t sleep the night before last that I lay in the darkness and chewed on the puzzle (long after the submission deadline to receive accolades on the site, but that’s not what matters).

The question is here, but I’ll copy the relevant chunk for you:

Benjamin likes numbers that can be written as the difference between two perfect squares. He thinks they’re hip. For example, the number 40 is hip, since it equals 72−32, or 49−9. But hold the phone, 40 is doubly hip, because it also equals 112−92, or 121−81.

With apologies to Douglas Adams, 42 is not particularly hip. Go ahead and try finding two perfect squares whose difference is 42. I’ll wait.

Now, Benjamin is upping the stakes. He wants to know just how hip 1,400 might be. Can you do him a favor, and figure out how many ways 1,400 can be written as the difference of two perfect squares? Benjamin will really appreciate it.

Let’s do this! First we need to dig a little deeper into the information in the advertisement: 42 = 1 + 3 + 5 + 7. It turns out you can make this into a rule: a2 = the sum of the first a odd integers. 122 is the sum of the first 12 odd integers, and so forth.

That’s pretty interesting, but the question was about the difference between two perfect squares, and that’s actually where the fun begins (for certain values of fun).

Consider 52 – 32. It’s the first five odd integers, minus the first three odd integers, leaving us with 7 + 9 = 16. The subtracted square cancels out part of the series of odd integers, and the difference is the sum of the ones left over.

So now we know that the difference between two squares can always be expressed as the sum of consecutive odd integers. And we also know that every series of consecutive odd integers sums to the difference between two squares.

Fun fact: Every odd number can be expressed as the difference between two squares: There will always be a value of a where a2 – (a-1)2 = n, where n is our odd number. Crazy!

A little side trip here to button things down: 5+7+9 adds up to a difference between what two perfect squares, a2 – b2? Knowing how to figure this will come in handy later to check assumptions. 9 is the fifth odd integer, so we know a is 5. We can solve that for any series that ends with n to say that a = (n+1)/2. The series we’re working on here is three numbers long, so we can quickly surmise that b = a – 3, or more generally, b = a – l, where l is the length of the series. In this case, 5 + 7 + 9 = 52 – 22 = 21.

So now with that info in hand, we can turn to the actual question, but rephrase it “how many different series of consecutive odd integers add up to 1400?”

This is how far I’d gotten on the problem before the long, terrible, sleepless night. A computational solution would be easy at that point, just walking the numbers and testing the results. I wanted to find an analytical solution, but I kind of assumed it would be beyond me, or that series of odd numbers wouldn’t lend itself to such a generalization.

Wide awake in the darkness at 2am, I started to think about the problem from a programming standpoint, trying to optimize the algorithm. What else do you do when you can’t sleep, amirite?

First Optimization: know when to stop. There’s no point in testing the sum of a series after any term goes past half the total.

Second Optimization: The target number is even, so there’s no point testing series with an odd number of terms.

In fact… somewhere around 3:00 am I found the twist from a computational approach to an analytical one, merely by using the optimizations and discarding the code.

If the series of consecutive odd integers has two terms that add up to 1400, then they must be centered on 1400/2. If there is a series of four consecutive integers that add up to 1400, those numbers must be centered on 1400/4.

Let’s look a little deeper at the simplest case to deconstruct what that all means. 1400/2 = 700. the series of odd integers that centers on 700 is (699, 701). Just for giggles we can confirm that ((701+1)/2)2 – (((701+1)/2) – 2)2 = 1400. And it does!

By 3:30, doodling number lines in my head, I had observed that what I was doing was factoring 1400. But there was a hitch – I considered the number 10. There aren’t two consecutive odd numbers centered around five. I realized that both factors have to be even. For an even number to be the difference of two squares, it has to be a multiple of four. That’s why 42 is not hip.

So now we can finally get to the answer to the Riddler puzzle, by answering, “how many unique pairs of even factors does 1400 have?” To answer that, we can reduce 1400 to its prime factors, and count the different ways to arrange them into two buckets. 1400 is 23 x 52 x 7. Since both factors must be even, there must be a 2 in each bucket. That means there are two ways to distribute the remaining 2 (either in one bucket or the other), three ways to distribute the three 5’s (two in one bucket, one in each, or two in the other bucket), and two ways to distribute the 7. That means 2 x 3 x 2 ways to allocate the remaining factors. But there’s one final hitch, because that method will yield both 2 x 700 and 700 x 2. So the final answer is half of that, or 6.

There are six pairs of integers, a and b, such that a2b2 = 1400.

  • 2 x 700 = 699 + 701 = 3512 – 3492 = 1400
  • 4 x 350 = 347 + 349 + 351 + 353 = 1772 – 1732 = 1400
  • 10 x 140 = 131 + 133 + 135 + 137 + 139 + 141 + 143 + 145 + 147 + 149 = 752 – 652 = 1400
  • and three other examples that are too long to fit here.

I didn’t do the actual factoring that night; by then it was 4:30. But I knew how to get the answer, for that or any number. To find the solution for odd numbers the process is similar, but the length of the number series will always be odd, and obviously there will be no even factors.

There are simpler ways to solve this problem, but I’m pleased that I could put a mostly-useless factoid from an advertisement to good use, right on the Web page it was displayed on. And yesterday involved a whole lot of caffeine.


Gotta Ride, Part 4: Riding!

It was before noon when the package arrived. My new bike. “I’m pretty excited,” I told the FedEx guy.

“New bike?” he asked as he lifted the large box.


He handed me the box with no thought about whether a dumpy gray-bearded guy could handle it. It was bulky, but not very heavy. I opened the box and set to work.

It took me a while to get everything put together. This was mostly because I wanted to be very careful, and partly because there were parts in the shipment that didn’t apply to me, that I had to come to terms with mentally. At the bottom of the box was a pistachio shell. The human touch.

But before long the bike was assembled, and almost ready to ride.

“Almost” because this bike does not use traditional cables to shift gears, instead it uses an electrically-actuated system that can make subtle adjustments based on the gears selected. Which means my bike uses batteries, and the batteries were shipped with no charge.

The good news is that the day cooled somewhat over the three hours it took to get the batteries charged (I will need to recharge them monthly or perhaps more often if I ride a lot, but I can plan ahead and not be held up again.)

Finally, the batteries were charged. Then came the firmware updates. I now have an app on my phone for my bike’s drivetrain.

You might be wondering whether this hassle is worth it, but I have been waiting for three months now for a tool to help me maintain the cables on my other bike. It will get here eventually. In the meantime, I have a bike with no cables.

Batteries charged, firmware installed, it was time to ride!

My first trip was a loop around the neighborhood to get a feel for the bike and think about seat height. It was unlike any other experience I had ever had on a bicycle. First impression: This bike wants to turn. I’m going to have to get used to such a twitchy ride. Second impression: This bike wants to move. With tires hissing as I pedaled I was going faster than I had before.

A lot of that has to do with weight, obviously; the new bike weighs half what my faithful Giant, loaded with commuter gear, weighs. But there was a time when I weighed less, and the combined weight of rider and bike then was not that different than me on the Fezzari now. But this is an entirely different feeling.

I got home from the loop, nudged the seat up a bit, loaded up with beverages, and headed out for adventure. As I did, I made two mistakes. Afraid of damaging the carbon-fiber frame, I did not crank down the seat post clamp hard enough. It could happen to anybody. The BIG mistake was that I didn’t bring the adjuster wrench with me. As a result, I was soon riding with a seat much too low, and my brand-new seat post got some pretty bad scratches in it as it moved with my pedaling.

On the maiden voyage on any bike, bring all the tools.

But oh, what a ride. You know what you don’t worry about when you’re commuting? The lines you take through corners. And while my default route is pretty flat, there is one small climb that I literally laughed out loud while climbing — I reached for the granny gear on the bike and it was way too low. I pulled up that brief slope with confidence.

Were it not for the seat problem, I would have added a more serious climb at the end of my ride.

Strava runs on my watch while I ride, and every once in a while I would look at my wrist and just shake my head. I had to remind myself to be a responsible rider when other people were on the trail ahead of me.

Toward the end of my ride, back on urban streets, I caught up to a man who had his headwear held on by a scarf that went under his chin, his sandaled feet pushing the pedals of his bike. We stopped a light together, and I said hello.

“How are you today?” he asked.

“I am very happy,” I said.

He was a little surprised at my response, I think, but after he adjusted. He smiled. “That is good,” he said, as the light changed.


Gotta Ride, Part 3

Ohmygod ohmygod ohmygod, my new bike os ON THE WAY.

Quick recap for those just joining in: I have a very nice bike, a sturdy number with a massive cargo rack and a cushy seat and good mechanicals and several thousand miles of bonding time. But I need a new wheel, and what I thought would take days has instead taken weeks.

While I waited for my faithful bike to be road-worthy, I started drooling over much fancier bicycles. Bicycles I could buy RIGHT NOW and be riding again. But then I started looking for American small businesses, accepting that maybe I would pay yet more but I would be supporting something I believe in. In my search I found a bike that had my ideal drivetrain and glowing reviews for about 60% the cost of the big guys.

I am not one to underthink anything. I searched and scrabbled, but these guys seemed real. Finally, I placed my order. That included providing many, many measurements, so they could get the bike set up as close to perfectly as possible without actually meeting me.

First note about Fezzari – if anyone there has any doubts about the bikes they are building, they do a damn fine job of hiding it. The pride in what they do oozes from every communication. Second note – they take customer service seriously. They are a friendly and enthusiastic bunch.

In my previous installment in this series I mentioned that I would have to wait a few months to get my bike. After I placed my order I got a phone call to go over what I had requested and whether I had any questions. I had a couple, and the guy had easy, technically-trustworthy answers. We parted happily. A few seconds later, I got another call from Fezzari. Same guy. It seems he had forgotten to ask me an important question: If I was willing to forgo the teal color highlights in favor of olive, I could have my bike in four weeks instead of four months.

Big “fuck yeah” to that. In anticipation of the arrival, I ordered from my local bike shop pedals to match my shoes and light mounts so I could move lights from one bike to the other.

Four weeks shrank to four days, and now FedEx is bringing me my bike. Delivery estimate: Sunday. Day after tomorrow.

I was ready to wait months for this thoroughbred, confident that my trusty pony would have its new wheel any day now. My Giant is a great bike, and will always be my commuter vehicle, when the day comes that I commute again.

But I am giddy with excitement. I have planned my first ride on the new bike, which is essentially my default ride with a hill-climb option at the end. I have started to worry about not having padding in my pants. I’m telling my knee that soon all will be well.

My Fezzari arrives Sunday, some small amount of assembly required. If it’s late in the day when my new ride arrives, I’ll have to take Monday off. Mental health day.

Gotta ride.

I Voted Today

I was careful to deposit my ballot in a drop box that was not a fake. It seems the Republican Party in California has admitted to putting out drop boxes falsely marked as “official”.

That… appalls me. Sure, voter suppression has long been a favorite tactic of the aging-out Republican minority to stay relevant, but to literally steal ballots is another level entirely. If no one spends serious jail time over that, I will not vote for a Republican for the rest of my life. (I had previously vowed that no Republican would get my vote until they got rid of Trump. Later in this rather muddled episode I will also introduce other ways Republicans can lose my vote. It comes down to “run honest campaigns and stop lying.”)

For fifty years the Republican Party has leaned more and more heavily on dirty tricks to stay in power. And the corruption has worked itself deep into the courts, as well. Take Texas. There’s a rule there right now that there can only be one ballot drop box per county. That means one drop box in Houston, a city of you-look-it-up millions of people. A judge ruled that this was a silly rule that had no justification other than voter suppression. Then other “conservative” judges overruled that rational decision.

They said pretty much, “you’re lucky to have drop boxes at all!” while ignoring the fact that in some (traditionally Republican) places there’s a drop box for every few thousand people, while in traditionally Democratic places, there’s a drop box for hundreds of thousands or even millions of voters. It’s just ridiculous.

But even that’s not stealing votes. And yes, in Pennsylvania seven Trump votes and two others were stolen and the election officials in charge immediately did the right thing and there was no cover-up and we can all talk honestly about it.

The California GOP says these “official” drop boxes are a “service”, but it undermines the provenance of the votes placed in them. I put my ballot in a box with a seal on it, and it will be recovered by an election official, and will never be “off the reservation.” I put my signature on the envelope, I put it in the box, and it is not touched again until it is in the hands of election officials. If someone else drops off my ballot in an official box, it requires another pair of signatures on the envelope. So, legally, none of those ballots in the GOP boxes should count. Thanks for your service, Republican Party!

Rambling on, I am encouraged by the huge turnout of early voters. Many of those motivated to vote early are those who have reason to believe that shenanigans are afoot, and before intimidation and suppression can really ratchet up in urban communities they are getting their votes in. Getting votes counted on Election Day will also affect the inevitable rants our current Presidential Embarrassment spews out.

January 20: the day Twitter can suspend Donnie’s account.

Meanwhile, the Senate might flip. Mitch will still be there, barring a miracle, and I wouldn’t bet against Lindsey, for all I hate them both. But they will be hoping that the populace forgives the Republicans for the last few years of criminal looting of our nation.

They will find no forgiveness from me. I will vote for no Republican at any level of government until Mitch and Lindsey are purged from the Republican roster. Oh, yeah, and Tom Cotton, too. He’s worse than all of them. No party with those people will ever get my vote. Ever.

Someday I will be an issues and governance voter again, I hope. I just need there to be more than one party playing that game.

My best-case scenario, which I genuinely think is possible, is that the Republican Party implodes and in that void the Democratic Party schisms. I’ve mentioned it before; already the best, most honest debates about the future of our nation occur within the Democratic Party. I would love to watch a throw-down between Alexandria Ocasio-Cortez and Joe Biden, when they didn’t have to be nice because the Republicans were watching.

Take away the dinosaur party, and the Democrats split in a nanosecond. Somewhat less likely is that Actual Conservatives form a meaningful party, or take over the Libertarians or the smoking remains of the Republican Party, and offer their voice to the discussion. I would have no problem with that, either. I just want to hear debate with substance, honest disagreement between parties who want a better nation but disagree on how to get there. That’s what politics is supposed to be.

We can disagree. We should disagree. That’s the thing people don’t seem to get. But it has to be honest. Stealing votes is not debate; it is oppression.

And dang, I got so caught up in the national stuff that I’m having to amend this post to talk about local issues. First: Uber can’t just spend money to counter a law it doesn’t like. Second: although it will destroy an entire genre of fiction, cash bail is evil, and I hope it ends in my state.

I voted for a couple of bonds (now is a favorable time to take out a loan) for long-term projects, but not bonds for spendy-money, and I voted for open space. The idea that protecting open space affects homelessness is disingenuous, pretty much a lie, which is when I stopped reading the “against” arguments. In generaI I voted against tinkering – “yeah the law says this, but this is better!” And of course I followed the money. The money doesn’t lie. When prison guards ask you to make laws that put more people in prison, it’s time to step back.

I voted today. If you disagree with me, you better get your ass to the polls.


Gotta Ride, part 2

Since the previous episode, when I had my eyes on a fancy bike that was sold right out from under me, I did not stop lusting over fancy bikes. I pored over the bike shop’s listings so thoroughly that when I went in there a few days ago to check on my wheel progress (I am unbiked right now while I wait for a wheel) I recognized individual bikes in the inventory. “Oh, that’s that sweet demo model with the 58cm frame!” (Too big for me.)

Side note: while I was at the bike shop, a family was shopping for the kid’s first bike. A big moment! They were looking at a few models but none was perfect. “If we order the other color, how long?” Mom asked. “About a year,” the bike store guy replied. “September 2021. Bikes are hard to find these days.” Dang.

I saw a matte gray bike from their “high-performance pack mule” line. I had studied the range of gear ratios between the two drivetrains offered at the top of this line — the SRAM 1×12 and the Shimano 2×11 drivetrains. For the nerds: SRAM has a lower granny gear, Shimano has a taller top end and smaller steps between gears. But you know how to stop having problems with the front derailleur? Don’t have one. 1×12 is simpler and lighter. And more expensive.

In person, I was struck by just how dang graceful the offerings from Trek are these days. Those are some pretty bikes. And there they were, just one credit-card transaction away, as I learned that one of my wheels was still in transit, and the other wasn’t set up yet.

(Iso-speed, a voice whispered in my head. Trek technology that reduces vibration reaching the rider, thus improving endurance.)

I had walked to the store, I could have ridden home. I did not. I might have given in, but I had already found a new object of desire, one that demanded less in return. Today I did two things at the same time: I ordered a new bike and I became one of those people who rides way more bike than he has any business riding.

The bike comes from Fezzari, an outfit out of Utah, known mainly for mountain bikes. They pioneered a construction technique that, rather than make carbon-fiber elements and join them together, builds the frame all in one go. No joints. The version of the drivetrain I most wanted in the world comes at an enormous discount on this frame, compared to Trek, Specialized, Giant and the rest.

This frame-is-a-single-piece thing allegedly also reduces vibration and rider fatigue, along with blah blah blah bike stuff. And this frame has apparently passed some series of mountain bike strength tests. Most road bikes could not pass those tests, my new best friends at Fezzari assure me. While true roadies might not find this important, I sometimes fall over. A tough frame can be nothing but good. Especially if the frame weighs less than two pounds.

Aesthetically, where Trek is a dolphin, Fezarri is a stealth fighter, angular and aggressive. In the almost-inconceivable world where my bike frame aerodynamics make a difference, I might have to upgrade again. In that world, I’m a professional bicyclist and someone else is picking up the cost.

This bike will be a pretty good climbing bike. Were it not for the big belly I carry around, I would have a climbing physique. I’m kind of… itching to climb. (Not so keen on descents.) I’m already scouting hills in my neighborhood. While long climbs around here involve interaction with cars, there are some great sprint-climbs nearby with no traffic. When I get my wheel I’ll start measuring myself on them with my current bike. When the new bike arrives a few months from now, I’ll be ready for the polka-dot jersey.

Yeah, a few months. The wait time is 16-18 weeks. Not a lot of uncertainty, but a lot of waiting. It is NOT the instant gratification I set out looking for; it is not the get-me-riding-right-now fix that started me on this quest. But the new bike will provide a riding experience that I think will keep me over the wheels for years to come. Although I will have to adapt to riding a bike that has no kickstand. Weird.

But when it’s raining, or when I need to carry stuff, or when I need my head up in traffic, my faithful old Giant will be there. It’s a great bike, and shall always be loved. While the Fezzari will become my bicycle, the Giant will remain my car.