The post The Rope of Dreams : Polynomials of the Second Order – Quadratic Equations appeared first on Alan Cowap.

]]>**The Rope of Dreams – Polynomial**

Imagine you are given a length of rope that is 120 meters long, and told that you can go to any place on Earth and whatever you enclose with the rope – is yours to keep, or do with whatever you wish. You can enclose only a single area, a single time, and then must return the rope. What would you do? You may not think of a Polynomial of the Second Order – a Quadratic Equation, but you probably should.

Say a big “Thanks”, take the rope, and start pondering the options. A likely plan is to think of where on Earth you want to go (a tropical island, a bustling city, a countryside retreat, maybe even Fort Knox – it’s your choice), and while en route to your destination figure out how to maximize the area the 120 meter rope can enclose. I’ll leave the destination to your own imagination (you can post in the Comments section below) and turn our attention for now to maximizing the area the rope can enclose once you get there. Did someone say Polynomial!

A likely first question you might have is to get an idea of just how long 120 meters is, so some reference examples might help, note that ‘m’ is short for ‘meter’. A soccer pitch is between 90m and 120m in length; A rugby pitch is 100m – the same as the 100m sprint in Athletics (Usain Bolt, Carl Lewis etc.); An American football pitch is 110m long; A CLG/GAA (Cumann Lúthchleas Gael / Gaelic Athletic Association) pitch is between 130m – 145m in length. For petrol heads, 120m is about 24 Nascars end-to-end, or 21 Formula1 cars end-to-end – that’s almost the entire grid – are you heading to Monaco with your rope?

A second question might be what shape to use, that is a great question and goes to the heart of this blog post. You might think of a **triangle** like the ancient Egyptians; or a **rectangle** shape like so many sports pitches and courts; an **oval** shape like running and race tracks; or a **square** shape like many public Parks. Or maybe you didn’t think about shape at all, maybe you thought shape doesn’t matter; but shape matters a whole lot and we’re about to find out why.

So a triangle could be a good shape to try, and let’s make it a long triangle because it seems logical that the longer it is the more area it will have. Let’s say we go with a triangle with sides of length 50m, 50m, and a base of 20m – that totals 120m. This type of triangle, with two sides of equal length is called an *isosceles triangle*. Now lets calculate the area of the triangle. using the formula below we get an area of \(490m^2\). That seems decent, for 120m length of rope we can cover an area of 490 sq.m.

For a Triangle: \( Area = \frac {base \cdot height} {2} \)

Herons Formula: \( Area = \sqrt {p(p-a)(p-b)(p-c)}\)

where p is half the perimeter i.e. \(p = \frac {a+b+c}{2}\)

Now let’s try another configuration of triangle, one that is more symmetric, in fact an *equilateral triangle* i.e. a triangle with 3 sides of equal length. The equilateral triangle will have sides of 40m, 40m, and 40m – all equal, and totalling 120m. Using Herons Formula above we see that we now have an area of \(693m^2\), that’s over 200 sq.m. more than the previous triangle. With a slight change in how we used our rope we’ve bagged ourselves a considerable area with an equilateral triangle of \(693m^2\).

Rectangle – Wrecked angle, broken square, get it. Heheheh. Ok, so if changing the shape of a triangle can bag us a bigger area, what about roping a rectangle! Once again we’ll go for a longer length and shorter width in the hope the longer dimension pays dividends. Let’s go with a rectangle of sides 50m and width 10m, that’s a total perimeter of 120m (50+10+50+10). This rectangle gives us an area of \(500m^2\). Hmm, that’s a bit better than our original isosceles triangle (490 sq.m.) but a lot less than our equilateral triangle (693 sqm.).

For a Rectangle: \( Area = length \cdot width \)

Now let’s try the same thing we did with the triangles i.e. go for a more symmetric shape, you can’t get a more symmetric rectangle than – a square. That’s right, a square is just a special case of a rectangle where the length and width are equal. A square will have 4 sides of 30m each, totaling 120m and using all our rope. The area of this square will be 30 times 30 i.e. \(900m^2\). That’s more like it, once again a reconfiguration of our shape has yielded a much greater area with a square yielding \(900m^2\).

Applying the lessons we learned from Triangles and Rectangles, it would seem that the more symmetric the shape the greater the area for a given circumference. So what shape is the most symmetric of all? Triangles, Squares, Pentagons, Hexagons, Heptagons, Octagons, and so on. But where does it end, what is the most sided shape you ca make?

Is the ultimate shape the humble Circle, as used in the World Heritage Site Brú na Bóinne in Ireland over 5200 years ago in the prehistoric passage tombs of Newgrange, Nowth and Dowth? Let us see. The perimeter i.e. circumference of the circle we can describe is 120 meters long, using the equations below we can determine the radius of the circle will be \( \frac {60} {\pi} \), we can use that to determine the area of the circle which is \(1146m^2\). Winner! Optimizing out shape by using a circle has yielded us a maximum area to enclose with our rope of \(1146m^2\).

For a Circle: \( Area = \pi r^2 = \pi {( \frac{d}{2} )}^2 \), and \( Perimeter = \pi d \)

Given circumference, C, \( Area = \frac {C^2} {4\pi} \)

Remember that all of these areas were obtained with the same 120 meter long rope, no magic, only mathematics!

\(490m^2\) – Isosceles triangle.

\(693m^2\) – Equilateral triangle.

\(500m^2\) – Long Rectangle.

\(900m^2\) – Square.

\(1146m^2\) – Circle.

I’m glad you asked. This all started when I was looking at numbers on a number line and squaring them and seeing how the values changed. Then I wondered, what is the difference between squaring a number (i.e. multiplying a number by itself); and multiplying the number to the left by the number on the right. So for example if I take the number 6, squaring it gives 36 (i.e. 6 * 6). Multiplying the number to the left by the number on the right is 5 * 7 = 35. 35 differs from 36 by 1. Interesting.

And what if I take the number 8, squaring gives 64; multiplying 7 * 9 = 63, once again this is one less. Interesting! Then I wondered if this relationship held for all numbers. Now multiplying an infinite amount of numbers is too much work, and that’s why we love Algebra because it saves us from all that extra work.

Let me call the number I pick, x. So the number to the left of x is one less i.e. x-1, and the number to the right of x is one more i.e. x+1. The examples above showed that:

My test cases showed: \( x^2 = (x-1)(x+1) + 1 \)

Multiplying this out: \( x^2 = x^2 + x -x -1 +1 \)

Simplifying: \( x^2 = x^2 \)

Q.E.D.

Next I wondered if there was a relationship between moving two spaces left and two spaces right. Taking 6 * 6 = 36, while 4 * 8 = 32; so a difference of 4. Interesting. Taking 8 * 8 = 64, while 6 * 10 = 60; again it is 4 less. Note that 4 is 2 squared i.e. 2 * 2 = 4.

Then I wondered about the relationship with moving 3 places. Since moving one space left a deficit of 1, moving 2 spaces left a deficit of 4, would moving 3 spaces leave a deficit of 9; or would it be 8? Let us see. Taking 6 * 6 = 36, while 3 * 9 = 27, so a deficit of 9. Interesting. Taking 8 * 8 = 64, while 5 * 11 = 55, again a deficit of 9. Note that 9 is 3 squared i.e. 3 * 3 = 9.

Once again, taking x as the initial number, and n as the number of places to move to the left and right, we can see the above results give us the generality:

\(\boxed{ x^2 = (x-n)(x+n) + n^2 }\)

Once again, we should prove the proposed equation.

Starting with \({ x^2 = (x-n)(x+n) + n^2 }\)

Multiplying out \({ x^2 = x^2 +nx -nx -n^2 +n^2 }\)

Simplifying: \( x^2 = x^2 \)

Q.E.D.

You can try the formula with your own values, please comment below if your calculations agree or disagree – and you can provide numbers used, calculations and results. You can confine your calculations to Integers i.e. positive and negative whole numbers including 0.

Great question, and the answer is Yes. The equation tells us algebraically and in a more general and proven way, what we found out empirically by choosing different types of shape. The ideal scenario is to choose a value of n = 0 i.e. not to wander away from the square condition. The further you wander, i.e. the greater n, then the greater \(n^2\) will become. If you move 2, the loss is the square (\(n^2\)) i.e. 4, if you move 3 the loss is 9, if you move 4 the loss is 16, if you move 5, the loss is 25 and so on. This is why the isosceles triangle of 50-50-20 was much worse than the equilateral triangle of 40-40-40. It is also why the rectangle of 50-10-50-10 was much worse than the square of 30-30-30-30.

Another great question. If you look carefully at the boxed equation above you may notice that it is very similar to the equation of a circle, and also very similar to Pythagoras Theorem. But really it boils down to symmetry, the way to get a maximum area with a given perimeter/circumference is to use a circle because it satisfies these equations and gives a maximum value. Corners are inefficient, curves are efficient.

Be mindful the opposite is true when it comes to packing and stacking i.e. corners are efficient and curves are inefficient. The Hexagon is a nice compromise between minimizing perimeter, maximizing area, and maximizing stacking and packing. Somehow bees seem to know this and build their nests accordingly.

Our equation: \(\boxed{ x^2 = (x-n)(x+n) + n^2 }\)

Eqn. of a Circle: \( r^2 = (x-h)^2 + (y-k)^2 \)

Pythagoras Theorem: \( c^2 = a^2 + b^2 \)

Take that Rope of Dreams, decide where you want to go, and if you want to maximize the area you cover – choose a circle. If you liked this post you will probably like the posts on the Monty Hall Problem – Can You Solve This Maths Puzzle? Enjoy!

The post The Rope of Dreams : Polynomials of the Second Order – Quadratic Equations appeared first on Alan Cowap.

]]>The post Monty Hall Proof – The Formula appeared first on Alan Cowap.

]]>Monty Hall Proof – The Formula is here. My two previous posts described the Monty Hall Problem – Can You Solve This Maths Puzzle? and Monty Hall Solution – Advanced! Well, this is the next installment of the trilogy, a simple mathematical proof.

If you don’t like Maths (Mathematics, Math) then, well, you have serious problems – get some help :^) This isn’t difficult at all, it’s just a bit of simple probability and algebra, yep ALGEBRA

The Probability that you will Win is the quotient of the Number of Cars, and (divided by) the Number of Doors. To represent that symbolically using algebra is simple:

\(P(W) = \frac{NC}{NDtot} \) … Equation (1)

The Probability that you will Lose is a little more interesting, it is the quotient of the Number of Doors less the Number of Cars, and (divided by) the Number of Doors, in symbolic notation this is:

\(P(L) = \frac {NDtot – NC}{NDtot} \) … Equation (2)

There’s one last equation we want, and it says the Probability that we either Win or Lose is 1 – since these are the only two possible events. In other words, we have to either win or lose – there are no other possible events (see my earlier post re the philosophical and physics debates on that general point). Anyway, to represent this symbolically:

\(P(W) + P(L) = 1 \) … Equation (3)

(Equation (3) is based on Kolmogorov’s second axiom i.e. \(P(\Omega) = 1\))

Those 3 Equations give us what we need to check the proof. If the Equations are correct then when we combine the equations the result should give us an equality – that’s why *equations* are also known as e*qualities*!

We start with Equation (3), into which we will substitute P(W) from Equation (1), and P(L) from Equation (2); as follows:

\(P(W) + P(L) = 1 \) … Equation (3)

\(\frac{NC}{NDtot} + \frac {NDtot – NC}{NDtot} = 1 \) … Substituting for P(W) and P(L) … Equation (4)

Now we want to simplify, an easy simplification is to combine the two terms of the left-hand-side of the equation since they have the same denominator (NDtot), which gives us:

\(\frac {NC + NDtot – NC}{NDtot} = 1 \) … Combining the left hand terms

Can you spot the next simplification? Take a look and see. Did you get it? That’s right, the ND and -ND will cancel each other out, giving us:

\(\frac {NDtot}{NDtot} = 1 \) … The NC terms cancel each other out

Can you finish the Monty Hall Proof? Yes, any term divided by itself equals 1, giving us:

\(\frac {1}{1} = 1 \) … we get 1 = 1 which is a proper equality, we did it!

**Q.E.D.**

So it seems we have this all wrapped up, but let’s try it with the actual numbers from the App. We have 3 doors, and 1 car, Recall Equation 4:

\(\frac{NC}{NDtot} + \frac {NDtot – NC}{NDtot} = 1 \)

Now let’s put in our values for total number of doors: NDtot =3, and number of cars NC = 1, giving us:

\(\frac{1}{3} + \frac {3 – 1}{3} = 1 \) … using our actual numbers from the App

\(\frac{1}{3} + \frac {2}{3} = 1 \) …do the math 🙂

\(\frac {3}{3} = 1 \) … great, it’s correct!

**Q.E.D.**

Go ahead and try with 2 cars and 3 doors; or try with 3 cars 3 doors, or 4 cars and 20 doors, it even works with 4 cars and 3 doors 😀

I hope you enjoyed the Monty Hall Proof, including the previous posts, and found them informative. Feel free to leave a comment, or if you see an error let me know, finally a nod to Andrey Kolmogorov and his pioneering work on Probability, he was born 115 years and 1 week ago.

Checkout the code here Alan Cowap GitHub.

Get your free Monty Hall Game on Google Play.

The post Monty Hall Proof – The Formula appeared first on Alan Cowap.

]]>The post Monty Hall Solution – Advanced! appeared first on Alan Cowap.

]]>This post “Monty Hall Solution” continues on from my previous post Monty Hall Problem – Can You Solve This Maths Puzzle? If you haven’t read that post, then read it now before reading this. Because I will now show you even more Monty Hall Solution coolness! We saw that you could increase (double) your chances of winning a car by understanding some maths, so let’s delve further into it and who knows, you might win something big (then again you might not, but hey!).

So what happens, if there are 4 doors instead of 3 doors? And what happens if there are 5 doors, 6 doors, hmmm, more code required – cool!

Checkout the code here Alan Cowap GitHub.

Get my free Monty Hall Game on Google Play.

For 4 doors we would expect that the odds would be 1/4 (**25%**) for not changing Vs 1.5/4 (**37.5%**) for changing. “*How did you get those figures?*” I hear you ask. Well, with 4 doors, each door has a 25% chance of being correct. Our 1st chosen door has a 25% chance – the other 3 doors have a combined 75% chance. When Monty removes one of those 3 doors by opening it -the remaining 2 doors still have a combined 75% chance – which is now divided by the 2 remaining doors i.e. 37.50% chance each. Once again the figures from the 70 million simulations are very precise.

Doors in Game: 4 Unchanged Wins: 2498993, Changed Wins: 3750566Unchanged Wins: 24.99%, Changed Wins: 37.51%Unchanged Wins: 2498720, Changed Wins: 3750419Unchanged Wins: 24.99%, Changed Wins: 37.50%Unchanged Wins: 2500812, Changed Wins: 3748980Unchanged Wins: 25.01%, Changed Wins: 37.49%Unchanged Wins: 2499171, Changed Wins: 3747829Unchanged Wins: 24.99%, Changed Wins: 37.48%Unchanged Wins: 2499602, Changed Wins: 3749207Unchanged Wins: 25.00%, Changed Wins: 37.49%Unchanged Wins: 2497548, Changed Wins: 3748332Unchanged Wins: 24.98%, Changed Wins: 37.48%Unchanged Wins: 2499206, Changed Wins: 3749860Unchanged Wins: 24.99%, Changed Wins: 37.50%

For 5 doors we would expect the odds to be 1/5 (**20%**) vs 1.33/5 (**26.66%**). These figures are derived as described above for 4 doors. So how does the simulation match up, well very precisely thank you:

Doors in Game: 5 Unchanged Wins: 1997315, Changed Wins: 2667064Unchanged Wins: 19.97%, Changed Wins: 26.67%Unchanged Wins: 1999994, Changed Wins: 2666099Unchanged Wins: 20.00%, Changed Wins: 26.66%Unchanged Wins: 2001180, Changed Wins: 2667386Unchanged Wins: 20.01%, Changed Wins: 26.67%Unchanged Wins: 1999664, Changed Wins: 2667039Unchanged Wins: 20.00%, Changed Wins: 26.67%Unchanged Wins: 2000629, Changed Wins: 2668808Unchanged Wins: 20.01%, Changed Wins: 26.69%Unchanged Wins: 1999954, Changed Wins: 2665963Unchanged Wins: 20.00%, Changed Wins: 26.66%Unchanged Wins: 1998652, Changed Wins: 2667357Unchanged Wins: 19.99%, Changed Wins: 26.67%

Odds are 1/6 (**16.66%**) for not changing door, vs 1.25/6 (**20.83%**) for changing door. And yes, the simulation agrees…

Doors in Game: 6 Unchanged Wins: 1663952, Changed Wins: 2083233Unchanged Wins: 16.64%, Changed Wins: 20.83%Unchanged Wins: 1667182, Changed Wins: 2083964Unchanged Wins: 16.67%, Changed Wins: 20.84%Unchanged Wins: 1666971, Changed Wins: 2083919Unchanged Wins: 16.67%, Changed Wins: 20.84%Unchanged Wins: 1666952, Changed Wins: 2083654Unchanged Wins: 16.67%, Changed Wins: 20.84%Unchanged Wins: 1666734, Changed Wins: 2083798Unchanged Wins: 16.67%, Changed Wins: 20.84%Unchanged Wins: 1666166, Changed Wins: 2082401Unchanged Wins: 16.66%, Changed Wins: 20.82%Unchanged Wins: 1667218, Changed Wins: 2086789Unchanged Wins: 16.67%, Changed Wins: 20.87%

And so on, as the number of doors increases we find that sticking or twisting becomes less important as 2 doors is an increasingly small fraction of the total number of doors i.e. 2/3, 2/4, 2/5, 2/6, 2/7 etc.

Just if you’re curious, here is a run of 10 million games for each number of doors (3-9), so a total of 70 million games. You can see the gap narrowing as the number of doors increases.

Doors in Game: 3 Unchanged Wins: 3332776, Changed Wins: 6667224Unchanged Wins: 33.33%, Changed Wins: 66.67%Doors in Game: 4 Unchanged Wins: 2500354, Changed Wins: 3749370Unchanged Wins: 25.00%, Changed Wins: 37.49%Doors in Game: 5 Unchanged Wins: 2000567, Changed Wins: 2665857Unchanged Wins: 20.01%, Changed Wins: 26.66%Doors in Game: 6 Unchanged Wins: 1665930, Changed Wins: 2083850Unchanged Wins: 16.66%, Changed Wins: 20.84%Doors in Game: 7 Unchanged Wins: 1430746, Changed Wins: 1713655Unchanged Wins: 14.31%, Changed Wins: 17.14%Doors in Game: 8 Unchanged Wins: 1250934, Changed Wins: 1458256Unchanged Wins: 12.51%, Changed Wins: 14.58%Doors in Game: 9 Unchanged Wins: 1111668, Changed Wins: 1271298Unchanged Wins: 11.12%, Changed Wins: 12.71%

Feel free to download/fork the code and test it yourself, modify the number of doors and play around with it and see how the numbers come out. There is still something I want to do with this Monty Hall Problem / Monty Hall Solution before I put it down. Hmm, more thinking and typing required, expect a final post on this topic …

Questions or comments welcome below, and contributions to the code are welcome too, it is available on here Alan Cowap Github

P.S. Nod to Cepheus~commonswiki for the images.

The post Monty Hall Solution – Advanced! appeared first on Alan Cowap.

]]>The post Monty Hall Problem – Can You Solve This Maths Puzzle? appeared first on Alan Cowap.

]]>The Monty Hall Problem is an interesting Maths Puzzle – with a hotly disputed answer. Monty Hall is a well known American TV Show presenter, and this particular maths puzzle gained some notoriety on his TV Show – hence the name “Monty Hall Problem”. The puzzle is quite simple to understand, but as is so often the case it is a little more tricky (and fun) to figure out the answer.

World famous mathematicians have gone to their grave disputing the answer. But I’ll explain it in easy to understand language, and demonstrate a proof using a computer simulation I wrote which played no less than 70 million games. The source code for the simulation is available here Alan Cowap GitHub so you can review it yourself

Get my free Monty Hall Game on Google Play.

Monty shows you 3 doors which are closed. You are told that behind one of the doors is a car, behind the other 2 doors lies a Goat. If you choose the correct door you win the car. The doors are labelled 1, 2, and 3. Let’s say you choose Door 1. In an unexpected twist Monty opens say Door 3 – behind which stands a goat! Monty then asks you “Do you want to stick with Door 1, or do you want to choose Door 2 instead?”.

So do you stick or twist? You can stick with Door 1 or try your luck with Door 2. Monty is waiting. Your heart is racing. The crowd are shouting in equal measure “Door 1” and “Door 2”, some jokers are even shouting “Door 3” ]:>

Not so fast. The fun is figuring out the correct answer – if there is a correct answer. What I’m going to do is put forward an answer and explanation, then I’ll write a software program to simulate this scenario 70,000,000 (70 million) times and see if it agrees with my proposed answer. Is it better to stick or to twist – or does it make any difference? I’ll share the results (and the code) of this simulation with you. In the meantime, you can try to solve the puzzle by yourself. But before that, I’ll propose an answer – spoiler alert – don’t read the next paragraph if you don’t want to see the proposed answer.

Ok then, you’ve racked your brains and thought through all sorts of statistical slight-of-hand and complex combinations and permutations and convinced yourself you have the correct answer. Stick or twist? Well , it turns out you should have …

changed to Door 2 – by doing so you will have doubled your chances of winning the car. If you got it right well done, if not sorry it looks like you’re getting the bus home!

As odd or counter-intuitive as this may seem the explanation is relatively straightforward. Each door had a 1/3 chance of being the correct door. You chose Door 1 – which had a 1/3 chance of being correct; however, jointly Door 2 and Door 3 have a 2/3 chance of being correct.

Once you discover that Door 3 is incorrect (when Monty opens it and the Goat is there) the odds for Door 2 and Door 3 being correct still remains at 2/3. But since Door 3 is ruled out that means Door 2 alone retains that 2/3 chance of being correct. Door 1 also retains it’s 1/3 chance of being correct. Therefore, sticking with Door 1 gives you 1/3 chance, while changing to Door 2 gives you a 2/3 chance.

If you find that hard to believe, and you think it’s a 1/2 (50:50) chance I can understand that. And you’re in good company, some world class mathematicians are with you. But I’m going to demonstrate that you should have changed to double your chances of winning!

You might be thinking that Door 1 and Door 2 now have a 1/2 chance each, but that would be ignoring history (a perilous endeavour in any part of life). Statistical trends will tend to be correct over a larger sample (number of samples, time, etc.) but statistics don’t always apply well to individual cases. Let’s look at an example: if you sample 100 families and find between them they have a total of 240 children, then statistically the average family has 2.4 children. Clearly this statistic can’t be applied to an individual family because no-one will have 0.4 of a child! However, as you increase the sample size you will find the statistic is reasonably accurate.

Another hypothetical example of statistics “remembering history” is this. You walk into a room and someone is about to roll a die (note that *die* is singular of *dice*) and they ask you to guess what number will be rolled. You know that each number has a 1/6 chance of being rolled, right? But then the person tells you “I’ve already rolled the die 5 times, and I rolled, 1,2,4,5,6”. Will this change your thinking of which number to pick. Will you now pick 3? Has knowing the history or the roll changed what the die is going to do? Knowing previous behaviour can be a predictor for future behaviour.

Like any scientist I propose that it’s critical to test a thesis against empirical data, thus we can either validate or invalidate the thesis. After all, we’re interested in verifiable, reproducible knowledge. So will we see the 1/3 to 2/3 distribution?

Umm, yes! First time running the computer simulation and the numbers were uncannily as expected. After 10 million simulations of the game the ratio was pretty precise at 1/3 (**33.33%**) vs 2/3 (**66.66%**) in favour of changing door. I ran the 10 million simulations 7 times and here are the results of those 70 million simulated games.

Doors in Game: 3 Unchanged Wins: 3332705, Changed Wins: 6667295Unchanged Wins: 33.33%, Changed Wins: 66.67%Unchanged Wins: 3335814, Changed Wins: 6664186Unchanged Wins: 33.36%, Changed Wins: 66.64%Unchanged Wins: 3334332, Changed Wins: 6665668Unchanged Wins: 33.34%, Changed Wins: 66.66%Unchanged Wins: 3333829, Changed Wins: 6666171Unchanged Wins: 33.34%, Changed Wins: 66.66%Unchanged Wins: 3333535, Changed Wins: 6666465Unchanged Wins: 33.34%, Changed Wins: 66.66%Unchanged Wins: 3331383, Changed Wins: 6668617Unchanged Wins: 33.31%, Changed Wins: 66.69%Unchanged Wins: 3331153, Changed Wins: 6668847Unchanged Wins: 33.31%, Changed Wins: 66.69%

Whaaaat! Having written the program I can see how these results are kind of inevitable*, so I decided to see if the results held up for different numbers of doors. That required a bit more flexibility in the code so no problems there w00t! ¯\_(ツ)_/¯

* it’s not possible to programmatically do anything “randomly”, we can only do pseudo-random. Indeed t’s a longstanding philosophical argument (which also persists in Physics) about whether things can happen “randomly” or whether things are causal and even deterministic. Schrödinger’s Cat vs Copenhagen Interpretation anyone meoow!

If you want to see some more cool work I did on this puzzle check out the follow on post Monty Hall Solution – Advanced! including having more than 3 doors (actually up to 9 doors and more)!! So many doors, so few cars (so many goats).

Questions or comments welcome below, and contributions to the code are welcome too, it is available here Alan Cowap Github

P.S. Nod to Cepheus~commonswiki for the images.

The post Monty Hall Problem – Can You Solve This Maths Puzzle? appeared first on Alan Cowap.

]]>The post Maths Puzzles are FUN !! appeared first on Alan Cowap.

]]>Maths Puzzles may not be everyones cup of tea, but I love puzzles and I love maths (and cups of tea). You can already see where this is going, right. Anyway I came across this simple enough puzzle and inevitably I started thinking about how to solve it. I say it’s simple because it only involves the numbers 1 to 9 with addition, subtraction, multiplication, and division. So, how hard can it be? Well…

- You must use the numbers 1 to 9 inclusive
- Each number can only be used once
- Note that : symbolises division

This type of puzzle is one of my less favoured types of puzzle because it’s solved mostly through trial and error, with just a sprinkling of inspiration. I prefer puzzles that are solved through some (optionally mind-bending) inspirational insight. Eureka moments, I like them, they’re a natural high. But what can make this simple type of puzzle more interesting is to take it to another level. How? First, you can calculate how many permutations there are, i.e. how many different ways can 9 numbers be uniquely ordered. The answer is there are **362,880 permutations** for 9 numbers (where there is no repetition, and order is important). Suddenly this simple puzzle doesn’t seem so simple. Another interesting twist is to calculate how many possible solutions there are, you didn’t assume there was just one possible answer did you? Oh dear, never assume! Hint: There is more than one solution, a lot more. I found **128 solutions**.

You’re probably wondering how I found that many solutions and how long it took me to find them. **It took less than 200 milliseconds to find all 128 solutions**. That’s the power of writing software to do the donkey work for you Writing the code took an hour or so and that was a much more enjoyable puzzle to solve, than manually solving the puzzle.

You can view and use the sourcecode which I have provided on GitHub under the GPLv2. Comments welcome, especially if you can see and errors or improvements. Enjoy!

Below are a list of all 128 valid solutions. First number goes in the top-leftmost square and insert the numbers in order. Easy peasy.

I have also created a Google Sheet with the answers and formula on so you can check your answers. You can view and download the Answer sheet too.

Winner: 1 2 6 4 7 8 3 5 9 : 66.0 : 1

Winner: 1 2 6 4 7 8 5 3 9 : 66.0 : 2

Winner: 1 3 2 4 5 8 7 9 6 : 66.0 : 3

Winner: 1 3 2 4 5 8 9 7 6 : 66.0 : 4

Winner: 1 3 2 9 5 6 4 7 8 : 66.0 : 5

Winner: 1 3 2 9 5 6 7 4 8 : 66.0 : 6

Winner: 1 3 4 7 6 5 2 9 8 : 66.0 : 7

Winner: 1 3 4 7 6 5 9 2 8 : 66.0 : 8

Winner: 1 3 6 2 7 9 4 5 8 : 66.0 : 9

Winner: 1 3 6 2 7 9 5 4 8 : 66.0 : 10

Winner: 1 3 9 4 7 8 2 5 6 : 66.0 : 11

Winner: 1 3 9 4 7 8 5 2 6 : 66.0 : 12

Winner: 1 4 8 2 7 9 3 5 6 : 66.0 : 13

Winner: 1 4 8 2 7 9 5 3 6 : 66.0 : 14

Winner: 1 5 2 3 4 8 7 9 6 : 66.0 : 15

Winner: 1 5 2 3 4 8 9 7 6 : 66.0 : 16

Winner: 1 5 2 8 4 7 3 9 6 : 66.0 : 17

Winner: 1 5 2 8 4 7 9 3 6 : 66.0 : 18

Winner: 1 5 3 9 4 2 7 8 6 : 66.0 : 19

Winner: 1 5 3 9 4 2 8 7 6 : 66.0 : 20

Winner: 1 9 6 4 5 8 3 7 2 : 66.0 : 21

Winner: 1 9 6 4 5 8 7 3 2 : 66.0 : 22

Winner: 1 9 6 7 5 2 3 4 8 : 66.0 : 23

Winner: 1 9 6 7 5 2 4 3 8 : 66.0 : 24

Winner: 2 1 4 3 7 9 5 6 8 : 66.0 : 25

Winner: 2 1 4 3 7 9 6 5 8 : 66.0 : 26

Winner: 2 3 6 1 7 9 4 5 8 : 66.0 : 27

Winner: 2 3 6 1 7 9 5 4 8 : 66.0 : 28

Winner: 2 4 8 1 7 9 3 5 6 : 66.0 : 29

Winner: 2 4 8 1 7 9 5 3 6 : 66.0 : 30

Winner: 2 8 6 9 4 1 5 7 3 : 66.0 : 31

Winner: 2 8 6 9 4 1 7 5 3 : 66.0 : 32

Winner: 2 9 6 3 5 1 4 7 8 : 66.0 : 33

Winner: 2 9 6 3 5 1 7 4 8 : 66.0 : 34

Winner: 3 1 4 2 7 9 5 6 8 : 66.0 : 35

Winner: 3 1 4 2 7 9 6 5 8 : 66.0 : 36

Winner: 3 2 1 5 4 7 8 9 6 : 66.0 : 37

Winner: 3 2 1 5 4 7 9 8 6 : 66.0 : 38

Winner: 3 2 4 8 5 1 7 9 6 : 66.0 : 39

Winner: 3 2 4 8 5 1 9 7 6 : 66.0 : 40

Winner: 3 2 8 6 5 1 7 9 4 : 66.0 : 41

Winner: 3 2 8 6 5 1 9 7 4 : 66.0 : 42

Winner: 3 5 2 1 4 8 7 9 6 : 66.0 : 43

Winner: 3 5 2 1 4 8 9 7 6 : 66.0 : 44

Winner: 3 6 4 9 5 8 1 7 2 : 66.0 : 45

Winner: 3 6 4 9 5 8 7 1 2 : 66.0 : 46

Winner: 3 9 2 8 1 5 6 7 4 : 66.0 : 47

Winner: 3 9 2 8 1 5 7 6 4 : 66.0 : 48

Winner: 3 9 6 2 5 1 4 7 8 : 66.0 : 49

Winner: 3 9 6 2 5 1 7 4 8 : 66.0 : 50

Winner: 4 2 6 1 7 8 3 5 9 : 66.0 : 51

Winner: 4 2 6 1 7 8 5 3 9 : 66.0 : 52

Winner: 4 3 2 1 5 8 7 9 6 : 66.0 : 53

Winner: 4 3 2 1 5 8 9 7 6 : 66.0 : 54

Winner: 4 3 9 1 7 8 2 5 6 : 66.0 : 55

Winner: 4 3 9 1 7 8 5 2 6 : 66.0 : 56

Winner: 4 9 6 1 5 8 3 7 2 : 66.0 : 57

Winner: 4 9 6 1 5 8 7 3 2 : 66.0 : 58

Winner: 5 1 2 9 6 7 3 4 8 : 66.0 : 59

Winner: 5 1 2 9 6 7 4 3 8 : 66.0 : 60

Winner: 5 2 1 3 4 7 8 9 6 : 66.0 : 61

Winner: 5 2 1 3 4 7 9 8 6 : 66.0 : 62

Winner: 5 3 1 7 2 6 8 9 4 : 66.0 : 63

Winner: 5 3 1 7 2 6 9 8 4 : 66.0 : 64

Winner: 5 4 1 9 2 7 3 8 6 : 66.0 : 65

Winner: 5 4 1 9 2 7 8 3 6 : 66.0 : 66

Winner: 5 4 8 9 6 7 1 3 2 : 66.0 : 67

Winner: 5 4 8 9 6 7 3 1 2 : 66.0 : 68

Winner: 5 7 2 8 3 9 1 6 4 : 66.0 : 69

Winner: 5 7 2 8 3 9 6 1 4 : 66.0 : 70

Winner: 5 9 3 6 2 1 7 8 4 : 66.0 : 71

Winner: 5 9 3 6 2 1 8 7 4 : 66.0 : 72

Winner: 6 2 8 3 5 1 7 9 4 : 66.0 : 73

Winner: 6 2 8 3 5 1 9 7 4 : 66.0 : 74

Winner: 6 3 1 9 2 5 7 8 4 : 66.0 : 75

Winner: 6 3 1 9 2 5 8 7 4 : 66.0 : 76

Winner: 6 9 3 5 2 1 7 8 4 : 66.0 : 77

Winner: 6 9 3 5 2 1 8 7 4 : 66.0 : 78

Winner: 7 1 4 9 6 5 2 3 8 : 66.0 : 79

Winner: 7 1 4 9 6 5 3 2 8 : 66.0 : 80

Winner: 7 2 8 9 6 5 1 3 4 : 66.0 : 81

Winner: 7 2 8 9 6 5 3 1 4 : 66.0 : 82

Winner: 7 3 1 5 2 6 8 9 4 : 66.0 : 83

Winner: 7 3 1 5 2 6 9 8 4 : 66.0 : 84

Winner: 7 3 2 8 5 9 1 6 4 : 66.0 : 85

Winner: 7 3 2 8 5 9 6 1 4 : 66.0 : 86

Winner: 7 3 4 1 6 5 2 9 8 : 66.0 : 87

Winner: 7 3 4 1 6 5 9 2 8 : 66.0 : 88

Winner: 7 5 2 8 4 9 1 3 6 : 66.0 : 89

Winner: 7 5 2 8 4 9 3 1 6 : 66.0 : 90

Winner: 7 6 4 8 5 9 1 3 2 : 66.0 : 91

Winner: 7 6 4 8 5 9 3 1 2 : 66.0 : 92

Winner: 7 9 6 1 5 2 3 4 8 : 66.0 : 93

Winner: 7 9 6 1 5 2 4 3 8 : 66.0 : 94

Winner: 8 2 4 3 5 1 7 9 6 : 66.0 : 95

Winner: 8 2 4 3 5 1 9 7 6 : 66.0 : 96

Winner: 8 3 2 7 5 9 1 6 4 : 66.0 : 97

Winner: 8 3 2 7 5 9 6 1 4 : 66.0 : 98

Winner: 8 5 2 1 4 7 3 9 6 : 66.0 : 99

Winner: 8 5 2 1 4 7 9 3 6 : 66.0 : 100

Winner: 8 5 2 7 4 9 1 3 6 : 66.0 : 101

Winner: 8 5 2 7 4 9 3 1 6 : 66.0 : 102

Winner: 8 6 4 7 5 9 1 3 2 : 66.0 : 103

Winner: 8 6 4 7 5 9 3 1 2 : 66.0 : 104

Winner: 8 7 2 5 3 9 1 6 4 : 66.0 : 105

Winner: 8 7 2 5 3 9 6 1 4 : 66.0 : 106

Winner: 8 9 2 3 1 5 6 7 4 : 66.0 : 107

Winner: 8 9 2 3 1 5 7 6 4 : 66.0 : 108

Winner: 9 1 2 5 6 7 3 4 8 : 66.0 : 109

Winner: 9 1 2 5 6 7 4 3 8 : 66.0 : 110

Winner: 9 1 4 7 6 5 2 3 8 : 66.0 : 111

Winner: 9 1 4 7 6 5 3 2 8 : 66.0 : 112

Winner: 9 2 8 7 6 5 1 3 4 : 66.0 : 113

Winner: 9 2 8 7 6 5 3 1 4 : 66.0 : 114

Winner: 9 3 1 6 2 5 7 8 4 : 66.0 : 115

Winner: 9 3 1 6 2 5 8 7 4 : 66.0 : 116

Winner: 9 3 2 1 5 6 4 7 8 : 66.0 : 117

Winner: 9 3 2 1 5 6 7 4 8 : 66.0 : 118

Winner: 9 4 1 5 2 7 3 8 6 : 66.0 : 119

Winner: 9 4 1 5 2 7 8 3 6 : 66.0 : 120

Winner: 9 4 8 5 6 7 1 3 2 : 66.0 : 121

Winner: 9 4 8 5 6 7 3 1 2 : 66.0 : 122

Winner: 9 5 3 1 4 2 7 8 6 : 66.0 : 123

Winner: 9 5 3 1 4 2 8 7 6 : 66.0 : 124

Winner: 9 6 4 3 5 8 1 7 2 : 66.0 : 125

Winner: 9 6 4 3 5 8 7 1 2 : 66.0 : 126

Winner: 9 8 6 2 4 1 5 7 3 : 66.0 : 127

Winner: 9 8 6 2 4 1 7 5 3 : 66.0 : 128

Calculations took 219 milliseconds

Permutations checked 362880

Winning matches 128

The post Maths Puzzles are FUN !! appeared first on Alan Cowap.

]]>The post Antipodes App now on Google Play appeared first on Alan Cowap.

]]>Antipodes App now on Google Play and it’s free

Ever wondered where or what is on the opposite side of Earth from where you are? Ok, maybe it’s just me, but since I’ve written the Anitpodes app, now you can find out for yourself.

“Antipodes” literally means “opposite feet”, and refers to the point on Earth exactly opposite your location.

Simply start the app, long press the Marker on the Map and drag it to your point of interest and WOOHOO it will draw a line to the other side of the Earth for you.

See if you can avoid the water, there is _lots_ of water on Earths surface

If you tap a Marker it’ll popup and show you the GPS coordinates of that location.

As with all Google Maps, you can tap the ‘GPS icon’ in the top right corner and it’ll go to your current location (if available).

Long press any location on map to make it the Podes, the map will update accordingly with a new Antipodes.

If you drag the Podes or Antipodes, it’s GPS coordinates will be updated and displayed in real-time.

If you have any suggestions or improvements, comment below, and download Antipodes now.

Enjoy and have fun antipoding (I may have made that word up )

Alan

P.S. Thanks to vectortemplates.com for the free to use graphics which I modified.

The post Antipodes App now on Google Play appeared first on Alan Cowap.

]]>The post Android Apps Published by my Amazing Students appeared first on Alan Cowap.

]]>Android Apps Published ! With 11 Apps developed for our Client Companies I think the class of 2014 can be super proud of their achievements. 6 of the Apps are publicly available on Google Play (links below), the others are either B2B or internal use. Without further ado, here they are:

GeoPal have their own successful app and were delighted with a library contribution which led to further work for the student who authored the library. Happy days!

Live at the Marquee App developed in collaboration with Clickworks on behalf of Aiken Promotions for the annual Live At The Marquee music festival.

Bedwetting App developed in collaboration with leading global pharmaceutical giant Ferring.

Sli Nua Careers are delighted with their App and are planning to add to it.

Clearview Coaching dipped their toe in the App arena, and their support paid off with this simple and effective app.

Hartley People got more than they bargained for with this feature rich App.

Other clients included Amnesty Interational (Ireland), Slattery Communications, tech super-startup Kitman Labs, Beaumex, and Wattless.

And to think these Apps were all written in a 12 week development cycle from start to finish is all the more impressive. It was an absolute pleasure to work with 24 students who, with a heap of hard work and a dollop of tenacity, went from zero to hero. Well done guys

—

The post Android Apps Published by my Amazing Students appeared first on Alan Cowap.

]]>The post Hello Linux Ubuntu, Goodbye Windows XP Alternative appeared first on Alan Cowap.

]]>Like about 20% of people who use a desktop computer I have one, ok two, that still run Windows XP. Well, not anymore. The end of support for XP last Tuesday 8-April-2014 was just the “stressor” (nod to Criminal Minds) I was looking for. So what is a suitable XP alternative ? Like plenty of people I’ve dabbled in various flavours of Linux over the years; Red Hat, SUSE, Fedora to mention a few of the better known ones. But they’d mostly been a hackers curiosity for me. For real(TM) work I’m not ashamed to say I wanted the reliability, simplicity, and compatibility of a Dell machine with Microsoft and Intel internals (yeah really).

But Linux has come a long way since then, no more messing around with tarballs, gcc, and editing scripts; mostly done through command line interfaces. And that’d be fine, I’d hacked OS code in college, but for me as a software developer the OS is just another tool. I just want it to work and be invisible. So I’m going with Ubuntu.

As a quick pointer on the steps awaiting you as you consider your XP alternative:

Ubuntu is currently the most popular flavour of Linux, it’s free, it’s open source, it’s available on the Ubuntu website.

You can try Ubuntu without removing XP at all. In fact you can run Ubuntu from a memory stick plugged into a USB slot. You may have to tweak your BIOS settings to get this to work (because typically the computer will try to boot from hard drives, floppy drives, and dvd drives before it looks for a USB key). Info on how to create a bootable Ubuntu USB key from within Windows are available on the Ubuntu Website.

Be sure to make a backup of all your user files on your computer. Things like documents, photo’s, videos, music etc. These are the things you don’t want to lose!

As an aside, check this out if you’re concerned about Heartbleed on your Android device.

Happy hacking, Alan!

The post Hello Linux Ubuntu, Goodbye Windows XP Alternative appeared first on Alan Cowap.

]]>The post More Android Apps by More of my Students appeared first on Alan Cowap.

]]>Following on from the success of the Android Apps from the first course I gave on App Development I had another fine batch of graduates who published their Apps.

All the Apps are free to download and are ad-free. These guys are too kind to you, so be kind to them

Here’s a list of the Apps and links…

Simple Stretching Exercises – No wonder it’s already >5k downloads and rating well, it does exactly what it says. Simple stretches with graphics and a description. Go on, you know you want to.

Irish Post – Track your package, or calculate the cost of delivery with this powerful App. Another great app that does the job well.

QB Stats Calculator – American Football Quarterbacks and their coaches can get a birds eye view of how the Quarterback is doing with this App which makes it easy to keep track of vital stats and calculate the “Passer Rating”.

App Paw Tizer – Got a pet dog and want to know if a particular food is safe – this App is for you (and your dog).

Leaving Cert Economics – Studying for the Irish Leaving Cert? This Economics App will help with your studying! The National Debt is testament to the fact we need some decent economists – so please get studying

Tides Ireland – Got that sinking feeling that the tide is going out on your life? No worries, this App will tell you when the two daily high and low tides are due in your Area (Ireland only), it’ll also tell you the tide heights!

RNG – Random Number Game – Finish off with a bit of craic while you play against your friends. Who has the highest number wins, loser has to .. well you decide!

7 weeks dev time is all these guys had, and for all of them it was their first time working through a software development life-cycle. They all became Oracle Certified Java Developers too. Onwards and upwards. Respect to those who do the do.

I’m currently working with 24 more students on 11 Apps for client companies, but more on that next month! Suffice to say, it’s super exciting…

The post More Android Apps by More of my Students appeared first on Alan Cowap.

]]>The post Android Apps by my Students appeared first on Alan Cowap.

]]>I recently gave a course in Android App development and all the participants published their own Android Apps on Google Play. Below is a list of the Apps. Bear in mind some of these guys had never coded before. They had 13 weeks to prepare for the very robust and forensic Oracle Certified Professional – Java Programmer Certification. This was followed by 7 weeks of Android development. They conceived, designed, and wrote all the code themselves. Impressive. And the list…

Irish Grid Reference – A simple app to convert GPS latitude and Longitude from the phone to the Irish Grid reference system for use with a map

Simple Fun – A simple game where the goal is to remove circles from the screen, if you miss a circle more get created elsewhere.

Vehicle Maintenance Schedule – Application to track your vehicle’s mileage and inform you of services required by the vehicle as they arise.

Dead Man Switch – Just what you’d expect from a Dead Man switch.

Kodaline – This is the OFFICAL Kodaline app for the musical band Kodaline.

GAA Team Sheet – This app allows managers to choose a team for their upcoming matches and sends it via SMS.

Word Quiz Tastic – With Word Quiz Tastic you will learn new vocabulary to help you write more descriptive essays and poems

Practical Shopping List – This simple practical app allows users to create and delete shopping lists, and use them while planning their grocery shopping.

Txt 2 English – This app translates written English into text speak(txt spk)and vice versa,also allows it to be sent as an SMS.

It’s an impressive list and shows what can be achieved in a relatively short space of time with a little guidance and a decent dob of coding effort. I should note that a couple more Apps aren’t included in this list because of Non-Disclosure-Agreements with client companies.

The post Android Apps by my Students appeared first on Alan Cowap.

]]>