doug — off the record

just a place to share some thoughts


A cutie-pie string problem

I had a university professor who would have called this a “cutie-pie” mathematics problem.  I hope that, by the end of the post, I can convince you that it would be a “cutie-pie” computer science problem.

If you’ve been watching social media recently, you might have come across this.

Do You Have An IQ Over 150? Solve This Puzzle And Find Out!

The complete article is located here and there’s a wonderful YouTube explanation, a challenge, and then a channel to follow if you want more.  Who doesn’t want more of a good mathematics challenge.  There have been a lot of comments about it largely centred around “too easy” which is easy to say when there isn’t a test to really understand your comprehension.  But that’s OK.  Maybe the world just has an IQ of 150.

So, where does the computer science stuff come in?

Warning, the rest of this post might be considered “spoiler” so don’t read on if you intend to try to solve it yourself.  At its best, I hope that it’s good enough to give to students to generate a computer solution.

What got me going about this particular angle was a conversation that I had with an AP Computer Science teacher at the recent CSTA Conference.  In his opinion, he couldn’t give his students enough problems involving string manipulation.  I liked his philosophy and did enjoy giving these types of problems to students myself.  It’s one of the best reasons for teaching computer science; it makes students think and many of them do so out loud with their friends.  It’s a study in itself.

I would actually just start by giving the students to puzzle to solve by discussion or pencil/paper if needed.  It’s one of those lovely activities that force the students to develop a new algorithm on the fly.  Then, we’re off for a computer solution.

It would be simple enough ….

  1. Enter the mathematical expression on the left side
  2. Determine the answer and output the expression and the answer

Very quickly, they’ll know, or have already determined, that this needs some new thinking.  Mathematics doesn’t cut it here.  After all,

6 + 4 ≠ 210

And yet, when someone enters “6 + 4”, we are going to display

6 + 4 = 210

as indeed the answer.

By now, you’ll know what’s needed.  We need to rip apart the expression entered as text and convert to the two numbers needed for the calculation.  This is always a good discussion point.  How do we know which characters form the numbers? Do we need to validate the input?

Then, using our algorithm, we’ll apply it to the numbers and then concatenate the results to display the answer.  As always, we need to consider the input – do zeros or negative numbers need special attention?

Then, the students will need to generate some test data and results and thoroughly make sure that their program works.  Because you’re switching between numeric and alphanumeric, you need to be very precise in calculations and output format.  With many programs, “close” is often good enough.  Here, you’ve got to attend to the details, spacing, character position, etc.

I think it’s a cute little ditty that includes so much.  Of course, I did it here to make sure that it plays well. 

It’s just a lot of fun.  This cutie-pie.



One response to “A cutie-pie string problem”

Please share your thoughts here. I’d enjoy reading them.

This site uses Akismet to reduce spam. Learn how your comment data is processed.