Saturday, December 17, 2016

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!

Thursday, November 24, 2016

Robot meets Trolley Problem in an Autonomous Car

Isaac Asimov's Laws of Robotics states that:
  1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.  
  2. A robot must obey orders given it by human beings except where such orders conflict with the First law.
  3. A robot must protect its own existence as long as such protection does not conflict with the First or Second law.
What is an autonomous vehicle but a robot programmed to ferry passengers and cargo around.

The famous Trolley problem is a thought experiment in ethics.  The general form of the problem is:
There is a runaway trolley barreling down the railway tracks.  Ahead, on the tracks, there are five people tied up and unable to move.  The trolley is headed straight for them. You are standing some distance off in the train yard, next to a lever.  If you pull this lever, the trolley will switch to a different set of tracks.  However, you notice that there is one person tied to this track and is unable to move.

What do you do?
Do nothing and kill five people or pull the lever and kill one person.
Which is the most ethical choice?

Ever since Artificial Intelligence (AI) and autonomous vehicles started getting closer to reality, this question of ethics is haunting the designers of autonomous vehicles and the algorithms governing them.  Imagine an autonomous car speeding along when it suddenly encounters a bunch of unexpected pedestrians on the road.  If it continues forward, it will kill the pedestrians.  If it swerves to avoid the pedestrians, it will fall off a bridge killing all its passengers.

Autonomous car meets trolley problem.
Robot meets a situation violating its laws.

How do we program a car to behave in a situation like this?
Eject all the passengers to safety and drive off the bridge.  Wish it was that easy.

There has been a lot of research into this area and MIT has even set up a web site to crowd source the opinion of the masses.  [side note: It will be interesting to go through the judging process as: a) a passenger, b) a pedestrian and c) as a third party onlooker.  I am sure that will skew your answers..]

One way to look at this problem is to equate the autonomous car to a chauffeured car.  In this case, the decisions are driven by the chauffeur.  As a human being, the driver's main motive is to stay alive and this skews the decision making.

The outcome of solving this problem may be that people will hesitate to buy or board a driverless car because of the fact that protecting its passengers may not be in the best interest of the vehicle.  What a dilemma!

Again, these are extreme end cases we are talking about.  Maybe, we should use a crowd sourced decision tree and apply it to all autonomous vehicles.  Today, the driver takes responsibility to the actions of the vehicle.  Tomorrow, we should not be blaming the manufacturer for the actions.  The actions should be governed by a set of rules appointed by a global body.

The reality is that millions of people are killed by vehicles manned by people.  This would dramatically reduce with autonomous vehicles and that fact will pivot people into accepting this new transport.  Similar to how horses made the decisions for us while we rode buggies, and when cars came around, no one wanted to trust a human being to make these decisions.  And, look where we are now.  One thing you have to give to the horses, though, is that they don't drink and pull carriages.

All along, designers of vehicles had been concentrating on protecting the passengers by installing seat belts, airbags and other safety equipment in vehicles.  Because of this new ethical dilemma, the designers of autonomous vehicles will have to start thinking of not only protecting the inhabitants of the vehicle, but also those in its vicinity in case an unfortunate event was to occur.  Designers are currently concentrating on the algorithm that powers these vehicles and assists in decision making.  That is all fine and good, but we need to start thinking outside the box to find the solution.

Thinking outside the box could lead into external airbags for vehicles which deploy when they detect an apparent (planned) collision with a living being.  It could also lead to apparel manufacturers designing safety wearables like jackets with airbags.  These could be for people who have high exposure to autonomous vehicle traffic, like construction workers.

But again, these are extreme edge cases we are talking about. 

Tuesday, October 11, 2016

Driverless pizza ovens

You order a pizza from your local pizzeria and a half hour later, a driverless car pulls up in front of your door and pings you to come out and pick up your pizza.  You go to the car, scan a code from your phone and a small door opens revealing your pizza box.  We all know this is bound to happen, or already happening in certain cities.



On a busy day, it can take up to a half hour for a pizza to be prepared and then transportation time is added on top of that.  This could easily add up to almost an hour, depending on how far you live from a pizzeria.  In general, a pizza takes about 3-4 minutes to prepare and 8-10 mins to bake.  Once baked, it tastes its best if consumed immediately.  Depending on the contents of the pizza, it starts to age and get soggy by the minute.

This is where the driverless oven comes into picture.

A pizzeria gets its order.  The order contains not only the products purchased, but also the address to be delivered to.  Software can easily categorize orders based on the product as well as distance to be transported.  For those orders within closer reaches, the pizza can be baked in the store and loaded for delivery.  For those orders which have a larger travel time, the chef can prepare the pizza and load it into the delivery vehicle.  The pizza is baked in the vehicle's oven, and packaged once fully baked and readied for delivery automatically.  This would need an automated vehicle with an automated pizza oven inside it.  The oven could be designed to handle several pizzas which will be baked based on the distance to the destination.  Material handling robots would package the pizzas as they are cooked.  The vehicle decides when to start baking depending on the distance as well as traffic conditions.

This optimizes the baking and delivery of the pizza.  Delivering fresh baked pizzas would become a reality.  This can also free up the store over to service in-store customers.
PC: Dominos Pizza

Sunday, September 25, 2016

Maximizing store productivity

The other day I was at the mall and visited a clothing store.  Walking inside I noticed a line formed in front of the dressing rooms.  Here we had a bunch of customers who were wasting their time waiting to get into the dressing room rather than perusing the clothes and accessories being sold by the retailer.  What a great wasted opportunity.


What if they had an app that customers could download and use it to reserve the dressing room.  If no room was available, they would be put on a waiting list and pinged when one came available.  This would allow the customer to roam around and shop for more things.  Once the retailer's app is installed on the customer's mobile device, and once the customer logs into the app, the retailer will have all the customer's information so the app can provide tips or sales information to the customer based on her/his taste.



This would not only provide a pleasant experience to the shopper but also help the retailer maximize the customer's time in the store.  Which retailer would want a shopper standing in line rather than browsing the aisles and picking up products to purchase?  

Saturday, September 17, 2016

Alexa in the Enterprise

Amazon Echo has been the face of Alexa all these days and it is a hands-free speaker that you control with your voice.  It also acts as a virtual voice-controlled assistant with limited capabilities.

 

Amazon released Alexa API to developers for free and developers are flocking to it.  This is a great move by Amazon and this will herald a new wave of applications that make use of Alexa.  And the Alexa Champions Program was put in place to recognize creative and outstanding contributions to the ecosystem.

Alexa has been seen as a way to enter into everyone's living room and as an assistant for the home.  Even the Alexa Home Kit is geared towards helping create home based custom skills.  This is all good.  But, the next generation of skills are going to empower the enterprise.

Imagine walking into a sporting goods store and wondering where to find running shoes.  You walk up to a virtual assistant installed strategically on every pillar/corner and speak to it and ask your question.  It can then reply with the exact location of the running shoes.  A custom skill could be created to go into the store database and check the location of the product in question, verify its location on the store planogram and return the location for the virtual assistant to voice.  The database and its information should be store specific.


Taking it to the next level, imagine a virtual assistant answering questions about a product.  All the information about the product, its reviews, etc. are available and can be piped into the assistant without any human intervention.  Custom skills can be built to work with the store database.  In cases where the answer is not found or the question is not understood, the virtual assistant can page for a human assistant.

The next generation of Human Computer Interaction is already here: It is voice based.  We still have a long way to go before computers can read our minds (think, Firefox, the movie).  We do live in interesting times.

Update: With Echo Show, the enterprise use case is strengthened.  In the above sports store scenario, Echo Show can display the store planogram/plan and show the user how to reach the product of interest.  It can also display additional information (choices, etc.) on the product as well. 
Image Courtesy: Amazon.com

Saturday, May 14, 2016

Amazon IOT

Amazon has finally done it.  They have created a generic IOT Dash button.  Last year I wrote about how the Dash button was super specific to not only actions but also products, and they needed to make a generic programmable button.
Last year, the Dash button was first hacked to order pizza from Dominos.  Later, people started hacking the button and using it as an IOT device to perform various tasks.  This was the right direction for the button.  Amazon realized the potential and has taken a step in the right direction  The AWS IOT button is a generic device that can be programmed to do anything one wishes to accomplish.  The price point ($20) seems steep for the device.  The original Dash price point of $5 was perfect.

Amazon how has a IOT button (touch).  The next step would be for Amazon to create MEMS sensors to sense sight, sound, pressure, acceleration, etc..  This will give developers all the needed sensor capability for IOT.  Amazon could then expand their IOT ecosystem.