Posts

Programming Problem: Single-Edit Difference

May 13, 2016

This question is based on a problem found in Cracking the Coding Interview by Gayle Laakmann McDowell which contians nearly 200 problems.

Test if two strings are different by only a single-character edit.

An edit is defined as an inserted character, deleted character, or replaced character. Note that zero edits (same string) counts as a character replacement where the replaced character is the same. In other words, can you add a character, remove a character, or replace a character to result in the other string?

  • “save” and “safe” = true
  • “Mark Henry” and “MaRk Henry” = true
  • “sve” and “save” = true
  • “sve” and “saVe” = false

Give it a try in your preferred language then check out my solution below. In an interview, you may want to quickly go over any assumptions or observations before writing code.

assumptions

  • An empty string is acceptable.
  • The length of a string is manageable and reasonably short for our system.

observations

  • Difference in text length greater than one require more than one edit.
  • Cases to consider: insert, remove, replace.
  • Insert is the same as remove in reverse.
Continue reading...

Setup for Script Work with Bethesda's Creation Kit and Notepad++

Apr 29, 2016

Get setup for working on scripts and scripting events for TES V: Skyrim and Fallout 4 by Bethesda Game Studios using Creation Kit and Notepad++. For scripting the Creation Kit uses “Papyrus” scripting system, and you’ll need to setup for working with the “Papyrus Compiler.” Instead of working on scripts within the Creation Kit, you may find it preferable to work an external editor like Notepad++. Sublime and Visual Studio Code also support “Papyrus” syntax highlighting. Many scripts for Skyrim may also work for Fallout 4. Review the differences on this Creation Kit wiki article.

Resources:

Familiarity with using the command prompt, archive utilities, batch files, and some scripting or programming experience is assumed. The following example is for Skyrim.

Source files and compiler setup

You’ll need the game’s Papyrus source files (extension psc) and the “Papyrus Compiler” found with Creation Kit. (And the game, of course.) You may want to backup your game’s data files in case something gets overwritten, or a mod plugin stops working correctly.

If you haven’t yet, install Creation Kit which can be found in Steam by selecting Library and Tools in the drop-down. Find “Skyrim Creation Kit” and install. In the instructions below, if you need help finding your game folder, in Steam right-click the game, select properties, view “Local Files” tab and click “Browse Local Files” button.

Continue reading...

Snowy Crater Lake

Apr 21, 2016

CraterLPanoSnow

For National Park Week, the 100th anniversary of the US National Park System, my sister and I decided to visit Crater Lake National Park. It turned out to be a warm, beautiful day, very nice for April. For more photos of the park, see my post from last year.

Located in the Cascade Range near the southern end of Oregon, Crater Lake is the result of Mount Mazama volcano blast forming a caldera. The lake is roughly five miles wide and 1,900 feet deep. The highest peak along the rim is 8,150 feet elevation. One could imagine Mazama was once a good sized mountain.

These photos were taken from Rim Village visitor’s area on the south side. Snow piled high at about 14 feet deep, strolling along the rim trail was like walking among (shorter) tree tops. Calm, the water was glass.

Continue reading...

Instagram Joins the Algorithm Feed Fad

Apr 8, 2016

Instagram has jumped on the re-sorted-feed fad along with Twitter, LinkedIn, and Facebook. Stated on Instagram’s blog posted March 15th, “your feed will soon be ordered to show the moments we believe you will care about the most.” An algorithm (likely using a classifier) will sort the order of the feed. This post makes the claim that users “miss on average 70 percent of their feeds.”

My initial reaction:

  • What if the average user chooses to miss older posts by only viewing most recent?
  • Does this change address a problem or an observation?
  • Is it just about increasing ad views?

I follow what I like to see most, such as friends and favorite photographers, and use search and hashtags to see others. I see very nearly all of my feed, unless many days have gone by and I’m only interested in the recent posts. I can always go look at their pages to see all of their posts.

In the past two weeks I have found my freind’s series of photos getting scattered about out of sequence. Photos by my favorite photographers may get buried perhaps due to that I only comment or like photos by friends. Even if I interact less, I still care about art by pros and recent updates from International Space Station (ISS). Besides, my feed update appears mostly shuffled. Whatever comes first doesn’t seem consistent, and multiple photos by same user on same subject ends up shuffled with the others and out of order.

This brings up four points:

  1. A series works better in order.
  2. Order adds context.
  3. Immediacy matters to some users.
  4. Users interact in different ways.

In a reverse-chronological sequence, one only needs to glance at a handful of the time stamps to approximate relative post times for the others. The order of posts adds context, especially when related to a topic or in response to other posts. A photo series stands out that otherwise might become hidden.

I left feedback using the Instagram app about wanting to see recent posts first.

Continue reading...

Swift 3 Changes

Mar 29, 2016

As the apple / swift-evolution page on GitHub notes, Swift 3 should be ready later in 2016 with the goal of platform portability. Noteworthy for the programmer, Swift 3.0 refines language style including dropping some C-style syntax that doesn’t fit well. Coming from a C and Java background, I have two C-style writing habits that I must admit don’t really fit well in Swift.

Since ++ and – doesn’t provide any in-line advantages, they don’t really do much besides allowing a programmer like me to type quickly by habit. For reading, it doesn’t save much space over += 1 and -= 1. I’m accustomed to writing for loops with the wonky semi-colons, but I’ve been getting into the habit of using shorter, more readable, syntax. Swift has for-in statement which is much easier on the eyes without all the wonky attitude.

Instead of:

Swift 2.1 C-style for loop
for var i = 0; i < count; ++i {
// do something
}

Do this:

Swift for-in loop
for i in 0 ..< count {
// do something
}

That second block looks nicer, doesn’t it?

Other changes for Swift 3 include the first argument label is no longer optional and minor naming changes like “sort()” to “sorted()” and “repeatedValue” to “repeating.”