7 Steps For Solving a Problem With Programming

2 Steps

  1. Get A Task
  2. Write Working Code

7 Steps

  1. Solve a small version by hand
  2. Write down the exact steps you took
  3. Develop an algorithm
  4. Check the algorithm by hand
  5. Translate algorithm to code
  6. Run test cases
  7. Debug any failed test cases

Solve A Small

Version By Hand

Solve A Small Version By Hand

  • Small instance - 4 or 5 pieces of data
  • Make sure the problem is clear
  • Make sure you have domain knowledge

Solve returning rank by name

Write Down the

Exact Steps

Write Down the Exact Steps

  • Write precise steps
  • Stick to the exact instance
  • Don't gloss over anything!

Returning Rank By Name

  1. Find rank for "Emma", "F"
  2. Set rank to 0
  3. Open CSV
  4. Begin checking first row, set rank to 1
  5. Check first row - is name "Ava"?
  6. Check first row - is sex "F"?
  7. If No, move on to second row, set rank to 2
  8. Check second row - is name "Ava"?
  9. Check second row - is sex "F"?
  10. We've got a match, return rank.

Develop

an

Algorithm

Develop an Algorithm

  • Finding Repetitive Behavior (loops, iterations)
  • Find conditional behavior
  • Substitute specific data for variables
  • Move from the concrete to an abstract solution!

Returning Rank By Name

  1. Find rank for name, sex
  2. Set rank to 0
  3. Open CSV
  4. For each row:
    1. increment rank
    2. if row name and row sex match name and sex return rank

Check The

Algorithm By Hand

Check The Algorithm By Hand

  • Are there any incorrect patterns?
  • Were any steps missed?
  • Try with a few different outputs

Returning Rank By Name

  1. What happens if no match?
  2. What happens if unexpected data types are passed in?
  3. What happens if CSV is formatted incorrectly?
  4. What happens if there is a tie between number of names?

Translate Algorithm

To Code

This part we should just know how to do by now.

Run Test Cases

  • Execute the Program
  • Check answers

Debug Failed Test Cases

  • Use the tools of your environment
  • Log values
  • Use a debugger

Let's Practice!

  1. Solve a small version by hand
  2. Write down the exact steps you took
  3. Develop an algorithm
  4. Check the algorithm by hand

First 4 Steps

  1. Given an input of 0  to 10 numeric digits
  2. Decode the digits using a telephone alphanumeric keypad map to an English Word
    1.  364 would be "dog"
    2.  36449 would be "doggy" or "foggy"
    3. 0364490 would be "doggy" or "foggy"
  3. If a word can be decoded, return it.
  4. If there is more than one solution, return the longest word.
  5. If there is a tie for longest word, return the first found.
  6. If there is no word found, return an empty string.

Vanity Telephone Number Guesser Service

  1. You already have a service available which accepts a string and returns whether or not it is an English Word
  2. Here is the alphanumeric telephone map:

Assumptions / Tools

7 Steps For Solving a Problem With Programming

By Ryan Moore

7 Steps For Solving a Problem With Programming

A language agnostic methodology for software engineering.

  • 541