Posts
Programming Problem: Single-Edit Difference
Article #5 in a 9-part series.
- 1 - Programming Problem: Determine if Two Strings Are Anagrams
- 2 - Programming Problem: Sum-Zero Triplet
- 3 - Programming Problem: Palindromes
- 4 - Problem: Validate a Phone Number
- 5 - this article
- 6 - Prime Factors Problem 1: LCM
- 7 - Prime Factors Problem 2: Largest Prime Factor
- 8 - How-To: Substrings in Swift
- 9 - Programming Problem: Pangram
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.
Setup for Script Work with Bethesda's Creation Kit and Notepad++
Article #11 in a 12-part series.
- 1 - Upgrade Skyrim with Mods
- 2 - Skyrim Immersion: Environment
- 3 - Pretty Skyrim: Elements
- 4 - Skyrim Life
- 5 - How to Install Skyrim Body Mods, Dual Sheath, and Animations
- 6 - Pretty Skyrim People
- 7 - Skyrim Gear 1: Clothing
- 8 - Skyrim Gear 2: Akavir
- 9 - Skyrim Gear 3: Light Armor
- 10 - Skyrim Gear 4: Heavy Armor
- 11 - this article
- 12 - Body Conversions for Skyrim Using BodySlide, Outfit Studio
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
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
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:
- A series works better in order.
- Order adds context.
- Immediacy matters to some users.
- 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
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:
Do this:
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.”