Sunday, December 18, 2016

Here come the drones!

Amazon Prime Air announced this week that they successfully delivered a package to a customer in the UK.


This is exciting news for the package delivery industry.  Drones have already made a mark in other industries like agriculture, construction, oil and gas.  They are very efficient in inspecting power lines or oil and gas lines and even oil tanks.  Those are niche usecases where a drone is perfectly suited. Delivery of goods is one area where lots of companies are trying to make headway.  Drones have been used to deliver medicine, blood, etc.  Healthcare can benefit from drones immensely when it comes to delivering care packages to remote areas.

Possibilities are endless with drones due to their VTOL (Vertical Take Off and Landing) capability as well as stability.  Equipped with a HD camera and a GPS, drones are basically robots on a mission.

Some think that drones are going to replace UPS/Fedex, but that is not going to happen.  Drone delivery is one of the delivery channels for a specific niche. It will never become mainstream and replace USPS or UPS or Fedex, due to its limitations.  Payload is one of the key limitations followed closely by range.

Payload is a limitation that will continue to keep drones to their niche.  But, range limitation can be overcome by several means.

Due to the limited range, drones can only deliver within a small radius from the distribution center (DC).  One way to solve this is by having a mobile DC that moves the products close to the delivery site and uses drones to dispatch the goods.  Imagine a small truck driving into a neighborhood, parking itself and dispatching as many as a dozen drones to deliver a dozen packages in one shot.  The drones will fly line of sight, thus reducing the distance to the target and the time for delivery.  Once the delivery is complete, the drones return back to the truck (mobile DC) and get recharged while the truck moves to another location.  The traveling salesman problem is simplified by a hub and spoke design for the last mile (the truck still needs to solve the TSP).  The hub being the mobile DC and drones making up the spokes.  Large number of deliveries (albeit, small) can quickly be achieved this way.

The next stage of this mobile DC would be larger drones replacing the trucks.  Imagine a large drone (mother ship) carrying the goods as well as smaller drones flying into a neighborhood and landing atop a 'perch'.  The perch could be a flat rooftop or a light pole.  People could rent their rooftops as perches for these mother ships.  The mother ship drone would land and dispatch individual smaller drones to the end point delivery.  Once the deliveries are complete, the drones will return back to the mother ship for recharging and their next assignment.

The beauty of this model is that the mother ships can recharge while waiting for the smaller drones to complete their delivery.  Imagine a rooftop drone perch with a power outlet.  If the perch is on a light pole, a power outlet can be created atop the pole.  This extends the range of the mother ship as well as the drones on board.  The only reason for the mother ship to return to a DC is to gather the next shipment of goods.  Remember, this DC that the mother ship returns to, could be a mobile DC itself!

The research that companies like Amazon are doing in the area of drone delivery can benefit other areas like healthcare, agriculture, power, oil & gas as well.  

Saturday, December 17, 2016

Programming Projects for Beginners - Bubble Sort

This exercise will introduce you to sorting and specifically Bubble Sort.  There are several methods for sorting and bubble sort is one of them.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Bubble Sort makes multiple passes through the list, while comparing adjacent elements.  It compares adjacent elements and swaps them if they are out of order.

Here is how it works:
Input list = [23, 4, 55, 12, 76, 3,41]
First pass:
[4,23,55,12,76,3,41] - Swap
[4,23,55,12,76,3,41] - No swap
[4,23,12,55,76,3,41] - Swap
[4,23,12,55,76,3,41] - No swap
[4,23,12,55,3,76,41] - Swap
[4,23,12,55,3,41,76] - Swap
Note that at the end of the first pass, the largest number is in its final place.  It has 'bubbled' up to its final location.

For the second pass, we can ignore the last element and sort the rest.  At the end of the second pass, the penultimate item will be in its final position.  This way, we keep shrinking the list until there is nothing else to sort.

Here is the usecase:
- Program displays a list of randomly ordered integers
- Program sorts the list using bubble sort
- Program displays the sorted list

Programming constructs used:
- Comparison
- Looping
- Conditional statements

Here is what the output would look like:

Note that I am printing the list at the end of each pass, but you don't need to do that.

You will also note that the sorting algorithm continues with the passes even though there is nothing to sort after the 6th pass.  This is because the algorithm is blindly running through the list once for every item in the list.

Bonus:
Improve the algorithm in such a way that it stops soon after the list is completely sorted.  The output should look like this:


Happy coding!

Programming Projects for Beginners - Hangman

This is the classic hangman game where the user guesses the chosen word in a given number of tries.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program asks user to guess a letter that makes up the chosen word
- User enters a letter
- Program checks if that letter is part of the word
- If the letter is not part of the word, the program starts drawing the hangman
- If the letter is part of the word, the program displays that part of the word and asks for the next letter
- If user keeps making guessing incorrect letters, the program continues to draw the hangman
- After several bad guesses, once the hangman drawing is complete, the user loses
- If the user guesses the word, the user wins

Programming constructs used:
- User input
- Comparison
- Looping
- Conditional statements
- Error handling
- Exception handling

Here is what a sample output would look like:

Another sample execution:

Hint:
For the hangman, create a list of the ASCII pictures with increasing degree of completion, and display them accordingly.

Bonus:
Read the list of words from a local file on disk.
Account for words with repeated letters.
Account for user typing an already found letter.

Happy coding!

Programming Projects for Beginners - Email Validator

We have all filled out forms where your email is requested.  In most advanced forms, as soon as you type your email, in case you made a mistake, the form would indicate that something is wrong.  This program does exactly that.  It checks the input text to ensure it is a valid email address.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program asks user for email address
- User enters email address
- Program checks validity and tells user if something is incorrect and asks user for the email address once more

Assume valid email addresses look like this:
abc@cde.com
where,
'abc' and 'cde' are alphanumeric text of any length (no special characters or spaces though)
'com' is either a two char or three char alpha string

Programming constructs used:
- User input
- String comparison
- Looping
- Conditional statements
- Error handling
- Exception handling

Here is what a sample output would look like:

Happy coding!

Programming Projects for Beginners - Guess the Number

This is a game where the computer selects a random number (say, between 0 and 10, to keep it simple), and the user guesses the number.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program picks a random number
- Program asks user to guess it
- User enters a guess
- Program tells user if (a) it is the correct guess (b) too high [say, if the guessed number is 5+- spaces away](c) too low (d) bit high or (e) bit low
- User guesses again until the answer is found

Programming constructs used:
- User input
- Libraries
- Comparison
- Looping
- Conditional statements
- Error handling

Here is what a sample output would look like:

As you notice above, I ran the program several times to give you a flavor of the output.

Bonus:
Handle invalid input as seen in the example above.
Count the number of tries the user takes and make an appropriate comment about it (as seen in the example).

Happy coding!

Programming Projects for Beginners - Texting Monitor

This was inspired by Shark Tank episode where Trisha Prabhu pitched her app 'ReThink' to stop cyber bullying.  As soon as I saw it, I thought a beginner could write a simple program to mimic what she is doing.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program asks user for text
- User types text
- Program analyzes text and if it is offensive, asks user if she really wants to post it
- Program does not send text if user agrees it is offensive
- Program sends text if user still wants to send it, but warns user of consequences

Programming constructs used:
- User input
- String operations
- Looping
- Conditional statements
- Error handling

You can keep a list of 'offensive' words and check if text contains any of them in order to decide if the text is offensive or not.

Here is what a sample output would look like:

In the screenshot above, I have run the program several times to show the different outputs.

Bonus:
Handle upper and lower case input (Eg: Y, y, yes, Yes,YES) as seen in the example.
Handle invalid input as seen in the example.

Happy coding!

Thursday, December 15, 2016

Programming Projects for Beginners - Python

I had signed up to teach programming as part of the Hour of Code movement to middle/high school kids and was pondering on what would be good and interesting programming exercises for beginners.  That got me thinking about simple programs that beginner students can write and feel proud about learning programming constructs and see them used in constructive ways.

After some thinking, here are five simple programming exercises that I came up with.  Each of these can be completed within an hour.

Note that I have solved these in python and will be including the screenshot of the output to give you an idea of how the program behaves and handles errors.

Python is a simple high level interpreted programming language with a rich set of libraries which makes it easy for beginners to learn. You can learn python here as well as run it in an online interpreter.  I often use repl for an online python interpreter. For some exercises, you will need to install python locally and run your programs.  We will go into the details later.

1. Texting monitor: This was inspired by Shark Tank episode where Trisha Prabhu pitched her app 'ReThink' to stop cyber bullying.  As soon as I saw it, I thought a beginner could write a simple program to mimic what she is doing.

2. Guess the number: This is a game where the computer selects a random number (say, between 1 and 100), and the user guesses the number.

3. Email validator: We have all filled out forms where your email is requested.  In most advanced forms, as soon as you type your email, in case you made a mistake, the form would indicate that something is wrong.  This program does exactly that.  It checks the input text to ensure it is a valid email address.

4. Hangman game: This is the classic hangman game where the user guesses the chosen word in a given number of tries.

5. Bubble sort: This exercise will introduce you to sorting a list of items.  Sorting is the process of placing the elements in a collection in a specific order.  In our case, we will sort a list of random integers into a list that contains the numbers in an ascending order.

I will post more details of each of these exercises in the coming days.  Look for those posts.

Happy coding!