Penneys ante flow diagram

September 12, 2009
http://en.wikipedia.org/wiki/Walter_Penney

Here is a graph I made for this.  To make it a fair game, instead of flipping coins  until you reach a given state, throw 3 coins as one single event.

penny graph

the arrows mean: ‘beats this choice’

from wikipedia:

1st player’s choice 2nd player’s choice Odds in favour of 2nd player
HHH THH 7 to 1
HHT THH 3 to 1
HTH HHT 2 to 1
HTT HHT 2 to 1
THH TTH 2 to 1
THT TTH 2 to 1
TTH HTT 3 to 1
TTT HTT 7 to 1

Clock puzzle

August 5, 2009

Clock puzzle

After 5:15 what time will the hour and second hand both meet?

Solution:

Taking 0 degrees to be the uppermost point of the clock, at 5:15 the second hand is currently at 90 degrees and the hour hand is at 90+67.5=157.5 degrees. Let x be the degrees from the second hand at which the hands meet.

In 60 minutes the hour hand moves 5 marks, the second hand moves 60 marks. The hour hand moves at a rate of 1/12 of a mark each minute, (and the second hand moves a mark each minute.)

At the same point where they meet, the hour hand is at 157.5 degrees + 1/12*x and the second hand is at 90 degrees + 1*x.

Equating and solving:

157.5 + 1/12 * x = 90 + x

67.5 = 11/12 * x

x = 73.6364 degrees.

Therefore the second hand will travel a further 73.64 degrees, so the final position is 73.64+90 = 163.6364 degrees from 0.

163.6364/ 360*60 will give the minutes which is 27.2727… minutes.

So the hour and second hand both meet next at exactly 5:27:16.


5 coins puzzle

August 5, 2009

5 coins puzzle

Given 5 coins, 4 fair and 1 unfair (2 heads), and after randomly selecting one coin from the 5, what is the chance of the coin being the unfair coin if the event that 5 heads in a row are tossed.

Solution:

Using Bayes theorem try to find the conditional probability P(U|5H) where U is the unfair coin and 5H is the event 5 heads are tossed in a row.

P(U|5H) = P(5H|U) P (U) / P(5H)

P(5H|U), the probability of 5 heads given that it is the unfair coin being tossed is 1.

P(U), the probability of selecting the unfair coin: 1/5.

P(5H), the probability of tossing 5 heads, there is 4/5 chance of choosing the fair coins, and 1/(2^5) chance of them getting 5 heads in a row, and a 1/5 chance of choosing the unfair coin, with probability 1 of getting 5 heads in a row: 4/5*1/32 + 1/5*1.

P(U|5H) = ( 1*1/5 ) / (4/5*1/32 + 1/5*1)

= (1/5) / (1/40 + 1/5)

= (1/5) / (9/40)

= 1/5 * 40/9 = 8/9 = 0.8888.. = 88.8…%

So there is 88.8…% chance the coin is the unfair one.


RR algorithms

August 5, 2009

Working round robin tournament chess pairing code for Matlab and Java I wrote, free to use/distribute. Please credit.

Maybe useful to somebody?

RR code in Matlab:

function rr2(n,round)
if nargin<1
round = 1;
n = input(‘Enter number of players: ‘);
round = input(‘Enter round number: ‘);
end
players = 1:n;

if mod(n,2)==0 %even
fprintf(‘Round %i of %i\n’,round,n-1);
else
fprintf(‘Round %i of %i\n’,round,n);
players = [0 players]; %zero is imaginary player
n = n + 1;
end

%cs = mod(round-1,n-1);
if round ==1
cs = mod(round-1,n-1);
else
cs = mod((round-1)*((n/2)-1),n-1);
end
players = [players(1) players((end-cs+1):end) players(2:(end-cs))]

if mod(round,2)==1
pairone = players(1:2);
else
pairone = [players(2) players(1)];
end
k = (length(players)-2)/2;
w = players(3:(3+k-1));
b = players(end:-1:(3+k));

if pairone(1)==0
fprintf(‘%i gets a bye\n’,pairone(2));
end
if pairone(2)==0
fprintf(‘%i gets a bye\n’,pairone(1));
end
if (pairone(1)~=0 && pairone(2)~=0)
fprintf(‘(W %i %i B) ‘,pairone(1),pairone(2));
end
for i=1:length(w)
if w(i)==0
fprintf(‘%i gets a bye\n’,b(i));
end
if b(i)==0
fprintf(‘%i gets a bye\n’,w(i));
end
if (w(i)~=0 && b(i)~=0)
fprintf(‘(W %i %i B) ‘,w(i),b(i))
end
end
fprintf(‘\n’);
end

RR code in Java:

import java.lang.Math;

public class rr {
public static void main(String[] args){
//13/01/2009 12:14pm
// This is a self contained offline version.
// Create new package rr and compile.
int tournround = 0;
tournround++;

int n = 6; //tourn.players.size
tournround = 1; //tourn.round

int[] playerIndex;
if ( n % 2  == 0 ){
playerIndex = new int[n+1];
System.out.println(“Round ” + tournround + ” of ” + (int)(n-1));
for (int i=1;i<=n;i++) playerIndex[i]=i;
}
else{
System.out.println(“Round ” + tournround + ” of ” + n);
playerIndex = new int[n+2];
n++;
for (int i=1;i<=n;i++) playerIndex[i]=i-1;
}
int cs; //cycle shift
if (tournround==1) cs = (tournround-1) % (n-1);
else{cs = ((tournround-1)*(n/2-1)) % (n-1);    }

int firstlength = Math.max(0,n-cs-1);
int secondlength = Math.max(0,cs);
int[] first = new int[firstlength];
int[] second = new int[secondlength];

System.arraycopy(playerIndex,2,first,0,firstlength);
System.arraycopy(playerIndex,n-cs+1,second,0,secondlength);
System.arraycopy(first,0,playerIndex,secondlength+2,firstlength);
System.arraycopy(second,0,playerIndex,2,secondlength);

int[] pairone = new int[2];
if ((tournround % 2) ==1){
pairone[0] = playerIndex[1];
pairone[1] = playerIndex[2];
}
else{
pairone[0] = playerIndex[2];
pairone[1] = playerIndex[1];
}
int k = (n-2)/2; // 1,2,–k–|–k– <- length n
int[] w = new int[k];
int[] b = new int[k];
System.arraycopy(playerIndex,3,w,0,k);
System.arraycopy(playerIndex,k+3,b,0,k);
int[] br = new int[k];
for (int i=0;i<k;i++){
br[i] = b[k-1-i];
}
for (int i=0;i<k;i++){
b[i] = br[i];
}

if (pairone[0]==0){
System.out.println(pairone[1] + ” gets a bye. “);
}
if (pairone[1]==0){
System.out.println(pairone[0] + ” gets a bye. “);
}
if (pairone[0]!=0 && pairone[1]!=0){
System.out.println(“(W “+pairone[0]+” “+pairone[1]+” B)”);
}
for (int i=0;i<k;i++){
if (w[i]==0){
System.out.println(b[i] + ” gets a bye. “);
}
if (b[i]==0){
System.out.println(w[i] + ” gets a bye. “);
}
if (w[i]!=0 && b[i]!=0){
System.out.println(“(W “+w[i]+” “+b[i]+” B)”);
}
}

System.exit(0);
}
}

Another page with RR C code:

http://www.devenezia.com/javascript/article.php/RoundRobin1.html


Another solution to A Maths Puzzle: Balls

July 24, 2009

Problem

“If I put my juggling collection into piles of 2 I have one juggling ball left over.
If I put my collection into piles of 3 I have 2 left over.
If I put my collection into piles of 5 I have 4 left over.
If I put my collection into piles of 7 I have 6 left over.
If I put my collection into piles of 11 I have 10 left over.

Have many juggling balls do I own? Is there only one solution?”

http://www.youtube.com/watch?v=QmLzX3xn8RE

http://www.youtube.com/watch?v=zB2nbCCeSRI – thanks to singingbanana from youtube for adding a link to this page! :)

Solution:

Let n be the number of balls in the collection.

Then the first line of the statement can be written n = 2 * a  + 1 for some integer a.

Similiarly

n = 3 * b + 2

n = 5 * c + 4

n = 7 * d + 6

n = 11 * e + 10

for integers b,c,d, and e.

Now, try to count (n+1) balls. Add 1 to each side of the equation to get:

n+1 = 2 * a + 2 = 2* f, for some integer f.

Similiarly,

n+1 = 3*b + 3 = 3*g

n+1 = 5*c + 5 = 5 * h

n+1 =  7*d + 7 = 7* i

n+1 = 11 * e + 11 = 11 * j

for some integers g,h,i,j.

So therefore:

n+1: = 2*f = 3*g = 5*h = 7*i = 11*j

This has simplified the problem, as now it is known that the collection of (n+1) balls is divisible by 2,3,5,7 and 11 without remainder. As the numbers 2,3,5,7,11 are all prime, the lowest common multiple of these numbers is found by multiplying them together: 2*3*5*7*11=2310

We have found that n+1 = 2310, but we originally wanted to get n, so subtract 1 from each side to get n=2309, which is equal to the number of balls in the collection.

The solution is not unique, the lowest common multiple 2310 can be multiplied by any positive integer, so that it can still be divisible by 2,3,5,7 and 11.

Therefore, there are infinite solutions in the form n=2310*a-1 where a is a positive integer.


the 4 stages of learning

March 3, 2009

Currently, learning to drive, juggle new patterns, playing chess, programming, learning math and learn new things in general has made me revisit and question which learning stage I am. The 4 stages are:

Stage 1. unconcious incompetance – when you don;’t know how badly you are not doing it. this is when you don’t even know what it is you should be doing, and hence not doing it at all.

Stage 2. concious incompetance – when you know what you supposed to be doing, but doing it badly. when you are conciously aware of being unskilled or not able to do something which you are consciously trying to do.

Stage 3. concious competance – when you are doing something, and you are aware that you made a conscious attempt of doing something, and require a conscious attempt to be competant at something.

Stage 4. unconcious competance – when you repeatedly do something so well that it becomes natural and doesn’t require much or any conscious effort.

Stage 5. mastery is the fifth stage – you do something so well, it becomes second nature and are better than most people, and people would come to you for advice and recognise one as a master in that field. for example, my masters mathematics degree, people could come to me for advice about the very particular branch of math which I have expertise in.

reference: http://en.wikipedia.org/wiki/Four_stages_of_competence

In the wiki link I found:

“As a fifth level, I like what I call ‘reflective competence’. As a teacher, I thought “If unconscious competence is the top level, then how on earth can I teach things I’m unconsciously competent at?” I didn’t want to regress to conscious competence – and I’m not sure if I could even I wanted to! So, reflective competence – a step beyond unconscious competence. Conscious of my own unconscious competence, yes, as you suggest. But additionally looking at my unconscious competence from the outside, digging to find and understand the theories and models and beliefs that clearly, based on looking at what I do, now inform what I do and how I do it. These won’t be the exact same theories and models and beliefs that I learned consciously and then became unconscious of. They’ll include new ones, the ones that comprise my particular expertise. And when I’ve surfaced them, I can talk about them and test them. Nonaka is good on this”

I have an example of my own, during juggling club a while ago, I was trying to teach somebody kickups using clubs, and the thought never occured to me of how I would be able to teach it, and I went on to explain this very thing, that I had learnt it beyond the four stages, that it would be difficult to explain but effortless for me to do, and it would be better to learn from another person who is learning kickups too. Nevertheless I think I managed to teach kickups to the group of people.

IN driving, I am in stage 2/3 in normal driving, changing gear, moving about etc. Being aware of the stages makes it easier to classify which learnign stage you are currently at, and therefore become more aware of your own ignorance as plato said. There is a fine line between not knowing something, and knowing something, and the rest is just repetition, to get up through the stages. Because as the saying goes; it is easy when you know how.


2 windows 7 problems solved

February 26, 2009

sound – nforce3, installed – the nforce audio drivers and not ac’97 codec (no static)

network – a bsod with netr7s.sys was occuring with belkin usb driver, selected in device manager the whql tested and auto updated to ralink network driver (even though it isnt one) and it is working (no more crashes)


youtube tv beta

February 22, 2009

to test the new youtube tv without a ps3;

using firefox, download the addon user agent switcher: https://addons.mozilla.org/en-US/firefox/addon/59

after installation, restart firefox. go to tools, user agent switcher and options. add a new user agent with string:

Mozilla/5.0 (PLAYSTATION 3; 2.00)

name it PS3.

Go to tools, and change the user agent to ps3.

Now go to www.youtube.com/tv
press F11 to enter full screen mode in browser, and escape to exit it.

press up and down arrows to show/hi UI controls.


offline google maps for phone

February 21, 2009

Here are instructions to put a google maps on your phone for offline use.

1. Go to http://www.mapcacher.com/ and select the region that you want, select zoom level 0 to 15, click generate, and download the .map file.

2. install and run gMapMaker. search for gMapMaker-setup.exe – download is second bullet point down.

3. Browse to the .map file and select a folder to download to. Wait for the program to finish downloading the map. (1000 files will take about a minute and 4MB of memory ntfs) (You will see it connecting and retrieving files.)

4. Copy the folder to a memory location on the phone.

5. Install –> mgmaps.jar <– onto your mobile phone and run.

6. On your phone, select the options menu, press settings (keypad 7), goto map browsing and browse for the folder mgmapscache inside the folder with the map data. Once you have browsed the Mgcache folder it should go back to the screen.

7. Now, press back, press menu and exit the program to save changes, and run the program again.

8. Useful to know – press keypad 5 to enter toggle joystick mode, and use the num keys 1 2 3 4 6 7 8 9 to move the map. press* and # to zoom in and out resp. out of joystick mode press 4 to put a placemark, in settings it is possible to rotate the screen too, and choose which map to use etc…

9. Now every time you load this program on your phone, it will load the current map you have selected, so there is no need to repeat any of these previous steps if you are  viewing the same map.

I tested by making a world map in google maps (very hard to select polygonic regions on the mapcacher site!),  and it took 3.52 MB. The zoom level was 0 -9. The problem is the file system of my phone k800i, is the memory card m2, which is in fat/fat32, which means it has a minimum cluster size, (due to the number of files) this means it takes up a lot more room than is necessary. This means the folder will take up more space on the memory card than it states onthe folder size. It is a good idea to only select and download the minimum region and zoom level that is necessary to minimise the space taken.

Thanks for reading. Hope this helps you on saving mobile roaming charges and allowing you google maps on your phone!

Some screenshots here:


face recognition application

February 12, 2009

Face recognition makes its way into photo applications this year, in Google’s Picassa Web Albums.

First, there is a run through search of faces in all the photos in the album, then a option to name faces. Another option to use the face clustering option to tag many faces at once, in groups. There is an option to view by faces, and select and tag many similar faces at once. When looking at a photo with unknown faces, one can just click the face and name it, then it will create a training sample for which further faces which are similar to the face can be tagged easily.

This is a great and not well known application to pattern recognition found at : http://picasa.google.com/

I envisage pattern recognition applications to increase in usage in daily life in programs and general end user applications.