Castles in the Desert: Games of Chance and Math

January 17, 2016 3 comments

Introduction

early-vegas

modern-vegas

Casinos represent a mind boggling concentration of resources. It is not uncommon for casinos to be vast structures with hundreds of employees, restaurants, shopping , hotels, lavish finishes, advanced technology and extensive areas for gambling activities. All of these things are concentrated in the most unlikely of places, in a desert landscape where the blazing sun is plentiful and water is sparse. Under normal circumstances populations grow around areas high in resources like places where food can grow easily or that have access to large bodies of water. The casino hubs though, especially those in arid places like Nevada, grew because the business of gambling is extremely lucrative. The business is so lucrative that these companies can even build modern day castles in the desert.

 

 

The House Always Wins

The first thing to consider when looking at the math of gambling is the idea that the house always wins. The house, or the establishment that hosts the gambling activities, does not win every bet. There are times where individuals win both small and large sums of money. What we mean by the house always wins is that in the long term, over many, many betting transactions, the house is mathematically destined to win. For each winner there are many more losers. If the house always wins in the long run, you might ask: How often does the house win and by how much?

We’ll use a few concepts from an area of math called probability to gain an idea on how to answer that question. We’ll just scratch the surface, but it will give you an idea on how to learn more.

Basic Concepts

  • Randomness
    • Things happen without an order or predictable pattern
  •  Experiment
    • An experiment is when we do a random act to get an outcome. So we might roll a dice to see which number appears.
  • Event
    • The result of an experiment. In the dice rolling example we might roll a three.
  • Sample Space
    • All of the possible outcomes or events. A cube shaped dice has six possible outcomes.
  • Probability
    • The chance something will happen. Usually expressed as a fraction. The probability of all events in a sample space adds up to 1. I have a one in six chance that a three will be rolled on a dice
  • Independent Events
    • Events are independent if they do not influence one another. Each time I roll a dice it does not matter what has been rolled before.
  • Dependent Events
    • Events are dependent if they influence one another. If I draw a card and do not replace it in the deck, then I can’t draw that card again. Specifically, if I had 10 cards and removed one, the next time I drew a card there would only be nine cards to choose from.

One Dice

Let’s think about one dice. How many ways are there to roll the dice? A cube has 6 sides so there are six ways to roll one dice.

dice2

Two Dice

What about if we roll two dice? Well there are 6 ways to roll the first dice and six ways to roll the second. The first conceptual challenge here is how do we count the events in the sample space? It is always easier to use real numbers so let’s consider that we roll 1 on the first dice. How many ways can the second dice be rolled? (6) We can repeat the thought experiment by rolling a 2 first, then a three first etc. We get something that looks like 6+6+6+6+6+6 or 6*6. We can also visualize this by organizing the outcomes in a table.

dice-combinations

We can go further and look at how many times each sum appears in the table. We can use this information to determine the probability for each sum. For example a sum of two can be formed exactly one way (by rolling two ones) in all 36 combinations. Therefore the probability of the dice adding up to 2 is 1/36. The full distribution looks like this:

dice-probabilities

 

Craps

Craps is a gambling game where participants place bets on the results of rolling two dice. The rules of the game are as follows:

  • The player (known as the shooter) rolls a pair of fair dice
    • If the sum is 7 or 11 on the first throw, the shooter wins; this event is called a natural.
    • If the sum is 2, 3, or 12 on the first throw, the shooter loses; this event is called craps.
    • If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, this number becomes the shooter’s point. The shooter continues rolling the dice until either she rolls the point again (in which case she wins) or rolls a 7 (in which case she loses).

There are a wide variety of bets that relate to these activities. The purpose of this article is not to encourage gambling or explain the intricacies of the activity so we’ll only scratch the surface of this game. In fact the goal of this article is to help you understand how much a gambler can stand to lose in the long run.

Consider the case of winning on the first throw. There are 6 ways to roll a seven and two ways to roll an eleven. This means there are eight ways out of 36 to have a winning outcome.  We can pair this information with two related bets on this outcome

The seven bet pays out 4:1. So if a dollar is bet, the player nets $4 otherwise he loses his dollar. The gambler will win one in six tries in the long run or 16.7% of the time. So if the gambler places 1,000 one dollar bets he will win back $668  (167 * $4). However he will lose $833 (833 * $1) This means over the long run he walks out $165 poorer.

The eleven bet pays out 15:1. So if a dollar is bet,  the player nets $15 otherwise he loses his dollar. Similar to the 7 bet calculation , the player has a 5.6% chance of an 11 bet succeeding. If he places 1,000 one dollar bets, he will win back $840 (56 * $15) and lose $944 (944 * $1). The means over the long run he walks out $104 poorer.

In both of the previous cases the house was the long term winner. Even though the player may feel like they are winning at some points in time, over many betting cycles the house amasses a large influx of cash. The house’s winnings  are always net positive in the long run and the player’s are always net negative.

We can use the simulator in the references below to gather the long term results of all craps bet types  for our 1,000 one dollar bet scenario. Any way you go you will walk out poorer over the long run.

long-term-outcome-craps-for-the-player

Further analysis can be done on other games of chance. The outcomes are similar with the house winning in all scenarios over the long run. Some games like Black Jack provide the house a smaller edge allowing for skilled players to reap rewards. One can even observe the flow of the game and use probability to make large bets when the hands left in the deck are in the player’s favor. This is a method called card counting. This can be multiplied by having multiple players gathering information on the deck. However this practice, known as team play, is prohibited and casinos will quickly escort out or take action against players found doing it.

Just such a scenario went down when a group of MIT students devised a plan to do team play against single deck Black Jack and reap huge winnings. Their exploits are detailed in the book “Bringing Down the House”. Casinos quickly caught on to their tactics and black listed them from playing. Outside of the US the young students faced threats of physical violence when they tried to employ their tactics.

While one could argue that individuals who counted solo without the help of a team were just being good players and mastering the game, the casinos were not in the business of losing money. They quickly adjusted their games of chance to include multiple decks. This nullified the counting advantages that single decks offered. Building castles in the desert is an expensive venture and the house is going to do everything in their power to ensure that they keep winning in the long run.

So the next time you see a grand structure where there would normally not be one, think a little about why resources are concentrating there. Math is a tool that can help you solve this riddle.

Handouts

  • All Possible Outcomes of Rolling Two Dice
  • Probability Distribution of Rolling Two Dice

References

Videos

Advertisements
Categories: Math Tags: , ,

Dependency Checker

February 2, 2015 Leave a comment

Dependency Graph

Have you ever had software work on your machine and not work on a different machine? Missing dependencies is a common cause of software that works in one environment and not in another. Modern software is most often a tapestry of libraries and frameworks that must be present on a machine to function properly. Even the simple “Hello World” programs that are used so frequently to introduce programming languages require additional libraries to run outside of a development environment.

Windows Environments: Dependency Walker

Dependency Walker (depends.exe) is a tool that has been around for many generations of Microsoft windows. This tool is your basic tool for diagnosing Windows dependency problems in the field.

Unix Like Environments: ldd

ldd is a shell tool used to list dynamic dependencies (shared object files). This is your basic tool for diagnosing dependency problems in unix like environments.

Resolving Dependency Errors

Why is the dependency required?

Sometimes project templates for ISEs can incorporate common dependencies that you may not need for your specific application. Always determine why a dependency is needed. You should be able to account for every library and framework your application requires. This knowledge may also extend to the dependencies of your dependencies and so forth. While this process of tracing dependencies can be tedious, it can teach you a lot about the frameworks you use and the operating systems you distribute on. In simple terms, don’t carry any more dependencies than necessary. Each dependency is a potential vector for bugs and vulnerabilities.

Is your application built correctly?

Some operating systems (i.e. Windows) distinguish between debug and release libraries. There will often be restrictions on distributing debug libraries. Debug libraries are often associate with the developer’s machine only. The QT framework on windows is a perfect example of this. Applications linked for debug link to QT libraries  with ‘d’ prefix (qt5cored, qt5guid, qt5networkd, etc.) This is case where something working on a developer machine and not on another machine is expected behavior.

Can static linking help your problem?

Some languages, such as C++, allow dependencies to be completely pulled into an executable at compile time. This means that the operating system does not need to resolve the dependency at run time because everything is already in the executable. The downside of static linking is that executable sizes increase and dependency updates require an entirely new application to be published. This had helped me in the past to incorporate Boost program options into an application. Static linking is not only language dependent, but also conditional on your licensing situation. Static linking to certain GPL works can cause the linking application to become a derivative of the GPL work and force the linking application to comply with the GPL terms. Consult appropriate legal and technical council for more information on this advanced topic.

Can you detect when the dependency is not met?

One common approach to dependency resolution is to check that prerequisites are met before allowing the application to be used. Visual Studio is a prime example of this approach. Visual Studio requires a number of companion technologies to be installed before the application can be installed. This does not prevent future problems because a user can uninstall still remove a prerequisite at a later time but it does set a nice baseline for what the publisher expected the system state to be.

Would setting minimum system requirements help?

Sometimes large sets of dependent files are distributed as a single update. An example of this would be service packs for Microsoft operating systems or names versions on Mac OSX (Yosemite, Snow Leopard, Mountain Lion, etc.) Requiring a specific update set can be an easy way to ensure dependencies are met. For example, when a minimum version of the .NET frame work is required.

Are you future proof?

Libraries change. Sometimes the way your software is written can cause unnecessary coupling between your application and the specific version of a library. My work supporting applications on Ubuntu has highlighted this idea. At some point in the life the software specific library versions get referenced. When transitions occur between 10.04 ->12.04, 12.04 -> 13.04 and 12.04->14.04 the default distribution for a library is based lined at a newer version. The older version are simply not present in the canonical package repositories. Sometimes members of the community post back borts for commonly used libraries but there is no guarantee this will be the case.

How Should the dependency be resolved?

Should you distribute the dynamic library or shared object file with your application? Should you rely on a different installer or updater to put the files there? How you answer these questions depends on the technology being used. Software is generally licensed, not sold. Software licensing dictates the terms that the software can be used and distributed. License restrictions may forbid the component from being installed by a third party. Others may all distribution as long as attribution is made. Some operating systems forbid or discourage the distribution of key system components. For example, it would be inappropriate to distribute a component that is normally updated through Windows Update. In some instances it may be appropriate to rely on a different installer to add and remove a component. The OpenSSL libraries are a good example of this. Every piece of software on the planet has bugs, including mission critical security software. Once you take ownership of distributing a library you are also on the hook for distributing all future security updates. If you don’t do this your software can either be disabled by system administrators or used as an attack vector against flawed software.

Source Control

February 2, 2015 Leave a comment
Uncle Rico tried to buy a time machine online

Uncle Rico tried to buy a time machine online

Do you ever wish you had a time machine? Maybe you would like to see ancient history first hand or re-live an important decision in your life? While we can’t travel through time and space, we can achieve a close second in our technical work using source control. Source control is kind of like a time machine for your plain text files.

A simple form of source control could work like the following:

  1. Do some work in an electronic document
  2. Save the file off with with a unique name at a given point
  3. Repeat steps 1 and 2 until the work is complete

This model works well for a small project with a single author. But this approach becomes problematic when different circumstances emerge such as

  • Multiple authors are contributing work
  • Two or more parallel works need to be merged into one work
  • There are lots of files that need to be tracked
  • Additional meta data is needed such as author, time and change notes

When one or more of these conditions emerge it becomes appropriate to utilize source control software. As is true with many universal problems in the software industry, the problem of tracking revisions has been solved with many different tools over time. As a frame of reference I have directly or indirectly dealt with seven different source control systems over the course of 14 years. A thorough comparison of source control systems can be found here: http://en.wikipedia.org/wiki/Comparison_of_revision_control_software As with other articles in this series we will focus more on the factors to determine the right tool and less on any one solution.

Factors to Consider When Picking a Source Control Tool

What file types are being stored?

Most often source control systems focus on the task of versioning plain text (i.e. code and code like artifacts). They frequently do this using a difference concept where the changes from one version the next are captured. This also means that while some solutions are great at tracking plain text changes, they can also be terrible at tracking “binary” files such as images and office documents. If you are working with binary files, source control systems might not be a good choice

What is your environment?

One of the reasons why there are so many source control solutions is because there are so many ways to make software. Your environment might include one or more operating systems, official and unofficial IDEs of the team, and graphical vs. terminal workflows. For example, if you are using a Visual Studio based work flow in a Windows environment, Team Foundation Server may be a natural fit because it is seamlessly integrated with specific versions of Visual Studio. On the other hand if you have have a mix of Windows, Mac and Linux hackers you might want to consider a Git solution paired with visual clients like gitk.

What are your resources?

Some of the popular source control solutions have a price tag associated with them. Even “free” software can have a cost when paired with cloud services with a prime example being private repositories on GitHub. Different solutions may also require varying levels of infrastructure. Do you have a person who knows how to setup a server securely or setup a database? This infrastructure also needs maintenance over time to ensure availability, performance, and security.

What does the team prefer?

Developer productivity is an essential element in delivering a quality product. Productivity and morale will suffer a developer has to learn a complicated system or constantly fight a tool chain. Developers and other content creators should have a major say in the tools they are required to use. It is true that most developers like learning new things, but introducing too many new tools or technologies cripples a teams ability to craft new solutions. Keep the number of completely new tools and technology to one or two if you want to have any hope of making your schedule projections.

Common Workflows to Master

Regardless of which tool is selected as the right answer, team members will need to master a few common work scenarios. These skills are essential and should not be schlepped off to peers. Address avoidance of these tasks immediately because they could be:

  • An indicator that more hands on training is required
  • An indicator that the wrong source control solution was selected
  • An indicator that corrective action and coaching is needed at an individual level

Universal Source Control Tasks

  • Add a file or files to source control
  • Remove a file or files from source control
  • Obtain the newest version of a file or files
  • Obtain a specific version of a file or files
  • View revision history for a file or files
  • Fork or branch from a given version
  • Join or merge two versions
  • Roll back to a specific version
  • Create a new version and share it with others
  • View the changes between two versions
  • Mark or otherwise annotate specific versions

Software for Absolute Beginners

April 25, 2014 Leave a comment

What is Software?

Before we talk about the type of things robot software involves, let’s talk about software in general. You use software everyday when you log onto a computer, listen to a song on your mP3 player or read a book on a tablet. Software, or computer programs, refers to instructions stored in memory that are processed by a computer. Chain enough simple instructions together and complex creations such as games and robots become possible.  Let’s look at a few types of instructions that are useful when creating software.

Basic Math Instructions

Computer processors include electrical circuits to perform very fast math operations such as addition, subtraction, multiplication and division. Being able to do simple math becomes very powerful when you can do millions or billions of calculations per second. Suddenly you can calculate trajectories, process images and other useful things. For our discussion we will assume the math symbols we are familiar with (+, -, * and /) and the accepted order of operations.

1 + 2 is an example of a math instruction

Comparison Instructions

Comparison instructions allow the relationship of two numbers to be determined. For example we can calculate which number is large, which number is smaller and which numbers are equal. Comparisons form a mathematical statement that is either true or false. Statements that are true comply with our convention or agreement on how numbers work. “1 is less than 3”, this is a true statement because it agrees with what we know the number 1 and 3 to mean. “4 is greater than 5”, this is a false statement because it conflicts with what we have agreed 4 and 5 to mean. In the order of operations, comparisons are evaluated after math instructions. In our examples we will use the symbols <, >, == to mean less than, greater than and equals, respectively.

1 < 2 is a comparison that evaluates to true
1 == 2 is a comparison that evaluates to false

Assignment Instructions

Assignment instructions allow your software to keep the result of a calculation or comparison for use later in the program. We’ll use the equals sign (=) from math to symbolize assignment. Assignment happens after all calculations have been perform and comparisons evaluated.

answer = 1 + 2 is an example of assigning the result of 1 + 2 to a variable named answer. If a calculation accesses the variable, the last value assigned to the variable will be used.

Memory Access Instructions

Memory uses electricity to store numerical information that can be retrieved at a later time. Some memory can continue to store information without electricity and other memory requires electricity to retain information. Instructions that read and write memory allow information to used after a piece of software has run.  Different pieces of hardware, such as sensors, can put information into memory that software can then read in when it executes. With this arrangement calculations can be run on information from the outside world. Our examples will only talk about memory in an abstract sense.

Conditional Instructions

Conditional instructions allow computers to make decisions and perform different instructions based on the outcome of the decision. The simplest form of decision we will discuss is an if-else statement. If a condition is true, one set of instructions will be executed. Otherwise a different set of instructions will occur. We say

if(condition)
     Do some instructions
else
    Do some other instructions

Looping Instructions

Looping instructions allow operations to repeated until a condition is satisfied. This means that a few instructions can be entered put in a piece of software but repeated thousands or millions of time. Our examples will use a while statement. While performs instruction while a condition remains true.

while(condition)
Do some instructions

 

Simple Software Examples

Let’s use a few of the instructions we have mentioned to write some simple software. For simplicity we will assume our programs begin executing at the top and stop executing at the bottom.

Friday if-else example

Let’s do one thing if it is Friday and another on other days

if(today == friday)
     Fun, fun, fun, fun, looking forward to the weekend
else
    Normal stuff

Cook some meat

Consider a robot that cooks meat. You ordered well done, so the meat needs to be cooked until it is fully cooked. Once it is cooked the food should be served.

while(food < well done)
      keep cooking
serve food

 

Robot Locomotion

Robots can often move throughout their environment. Examples of different ways for a machine to move include:

  • Wheels Tires
  • Treads and Tracks
  • Two legs
  • Four legs
  • Multi-legged
  • Fixed wings
  • Helicopter (rotating wings)
  • Swimming/Aquatic

Note: This article will be expanded after it is discussed in lecture

 

Categories: Robotics on a Budget Tags:

IR[1] = Robbie

Comprehension Questions

  • Who is Gloria?
  • Who is Robbie?
  • What were Robbie and Gloria playing?
  • What does Robbie like to be told?
  • Who is Mrs. Weston?
  • Who is George Weston?
  • Does Mrs. Weston like Robbie?
  • What was Robbie made for?
  • What is the first law of robotics?
  • Could George Weston hold his ground to keep the robot?
  • What was Robbie replaced with?
  • What happened to Gloria when Robbie wasn’t there?
  • Why does Gloria think they are going to the city?
  • Where did Gloria go in the museum?
  • Who was observing Gloria talk to the robot?
  • What happened to Gloria in the factory?

Discussion

  • Should robots be banned? If so, under what conditions?
Categories: Books Tags:

Robotics on a Budget Service Project

March 28, 2014 Leave a comment

Our course work centered on robotics, but our service project will center on humanity. Please select a project from the list below. You are welcome to think of other projects, but please get approval before you do them.

Each scholar must prepare a poster describing what was done for the act of service.

Emotions

  • Help someone scan and catalog all of their old family photos
  • Help someone convert old home movies into a digital format
  • Record a few life stories of a grandparent or an elderly person. Prepare a transcript of the recording and share their story with your friends and family

Creativity

  • Perform for a public audience as an individual or as part of a group in a play, concert or other production
  • With appropriate approvals, create a website for a school, church or community group.
  • Teach one or more people a skill or concept

Family

  • Use the internet and other resources to research about your ancestors and genealogy.
  • Help index historical documents such as tomb stones, census data and ship records.

 

Categories: Uncategorized Tags: