Posts

Mother Dove Redux

May 8, 2015

An edited repost of my 2009 #FridayFlash for the final collector.


“What’s the matter with you?”

Fred winced at the familiar query. Crouched, he held the paintbrush tight. He knew what came next. It never failed. Dipping the brush into the can, he sloshed white paint onto the fence.

Leaning on her walker, Mother Dove stood on the porch glaring out over the yard. “Have a hole in your head?

Paint slapped on wood turning mottled gray white. Bristles splattered paint on Fred’s face. Frowning, he continued on pretending the old woman was dead.

“After Labor Day,” said Mother Dove. “The yard can’t wear white.”

Continue reading...

Programming Problem: Sum-Zero Triplet

May 8, 2015

In the previous problem, we looked at anagrams for fun and practice. In this post we search for the sum-zero triplet. Given an array of integers, find three integers with a sum of zero. I encountered this problem during a phone interview and asked to write the code live in collabedit. My first thought was to do some sort of mapping, but later I realized I could sort the array in order to break from a loop early. If you’re practicing for an interview, try writing your solution in a text editor rather than an IDE. At the bottom you’ll find two variations to my solution written in C# and a sample written in Java.

observations

The array must have at least three integers since the problem specifically asks for three, not three or fewer. Three zeros would do it, otherwise there needs to be at least one negative. Sorting an array allows us to use BinarySearch, direct our search for a third integer based on a starting pair, or break early realizing the lowest value is positive.

Continue reading...

Programming Problem: Determine if Two Strings Are Anagrams

May 3, 2015

How do we determine if two strings are anagrams?

For syntax coloring, Visual Studio Code without IntelliSense works well with support for many languages. I’ve provided my solution in C# (csharp) and Java followed by Objective-C (ObjC) and Swift at the bottom (updated for Swift 5).

observations

By definition, an anagram is a word or phrase formed from another word or phrase by rearranging the letters. Spaces and punctuation don’t count, just the letters ignoring case. Here are a few samples:

  • “Tom Marvolo Riddle” <-> “I am Lord Voldemort!”
  • “Dave Barry” <-> “Ray Adverb”
  • “debit card” <-> “bad credit”
  • “astronomer” <-> “Moon starer”
  • “School master” <-> “the classroom”

Since we must use all of the letters we can conclude that ignoring spaces and punctuation, the two strings must be the same length. Also, the same phrase is not an anagram of itself.

Notice that if we sort the letters of a phrase and its anagram we get identical strings.

Continue reading...

Computer Perfection and the User Experience

Apr 28, 2015

Like building a movie set, the virtual world created by software designers and artists begins clean and perfect. Computer models are pure, created at origin in perfect orientation. For a better experience, movie set artists add dirt and signs of aging. In a race simulator game, the track needs dirt, weathering, scuff marks, and trees require some randomness so they don’t appear too much alike. More signs of realism improves immersion and reduces distractions.

The two screenshots below reveal parked cars within racing games. Since these show off the car, likely before a racing event, clean cars are expected. The first screenshot is from Asseto Corsa by Kunos Simulazioni. The second screenshot comes from Forza Motorsport 4 by Turn 10 Studios. What’s unnatural about the parked cars in the two images?

Continue reading...

iPhone Cycling Health Data Update

Apr 9, 2015

Last autumn many cyclists noticed pedaling a bicycle with the iPhone 6 in a pocket counted towards steps in the Health app as noted in my post in December. Besides a concern about duplicated data, my interest is in the problem space of detecting cycling vs walking/running in the general case. A third-party app dedicated to recording activities updates Health app, but the pedometer continuing to record steps created duplicated data. Below is a screen capture of the Health app on December 11 showing my 27-mile rides on the 8th and 10th with a strikingly large distance in “Walking + Running” compared to the 9th and 11th. HealthCycleWkScr

Continue reading...