Let's write a simple Python application that changes its background image everytime you click on it. Here is a short code that helps you do that: import os, sys import Tkinter import Image, ImageTk def key(event): print "pressed", repr(event.char) event.widget.quit() root = Tkinter.Tk() root.bind_all(' ', key) root.geometry('+%d+%d' % (100,100)) dirlist = os.listdir('.') old_label_image = None for f in dirlist: try: image1 = Image.open(f) root.geometry('%dx%d' % (image1.size[0],image1.size[1])) tkpi = ImageTk.PhotoImage(image1) label_image = Tkinter.Label(root, image=tkpi) label_image.place(x=0,y=0,width=image1.size[0],height=image1.size[1]) root.title(f) if old_label_image is not None: old_label_image.destroy() old_label_image = label_image root.mainloop() # wait until user clicks the window except Exception, e: # Skip a
Solution here:
ReplyDeletehttp://mathproblems.info/images/prob1.pdf
Do you have an intuitive solution to Monty Hall problem? Why is the correct answer is correct?
ReplyDeleteThe Monty Hall problem is quite interesting because it makes us confused. I heard of it the first time in the movie "21" and my friend, Ondra, posed the problem again when we were in a train from Bolzano to Innsbruck. We discussed it during that time.
ReplyDeleteThere are three doors, one door has a car and the other two doors have goats behind them. You choose, let's say "Door 1". The host (who knows where the car is) opens another door, let's say "Door 3", which has a goat behind. Then he asks whether you want to switch your choice or not, i.e., to choose Door 2.
The answer is yes, switching to another door increases the probability that you would get the car.
The simplest way of explaining it, as for me, is:
First, when you choose Door 1, the probability that you would get the car is 1/3. The probability of having the car behind "Door 2" and "Door 3" together is 2/3.
Then, the host, with his knowledge, reveals one of the door which has a goat behind, hence increase the probability of having the car behind Door 2 to 2/3 (because he has eliminated the possibility that behind Door 3 is the car).
Hence, switching to Door 2, you will have the possibility of getting the car of 2/3, while if keeping your initial choice, Door 1, you will only have 1/3 possibility.
What confuses people most is that: When the host opens Door 3, leaving both Door 1 and Door 2 close, then Door 1 and Door 2 should have an equal possibility of 50% chance to have the car. But the fact is that the host opens either Door 2 or Door 3 (but not Door 1) based on his knowledge about where the car is. So the event that the host opens the door doesn't change the possibility of Door 1, but Door 2.
The most convincing and easy way to see the solution is to draw a table listing all possibilities where the car is and we will see it's clear that P(Door1=car) = 1/3 while P(Door3=goat|Door2=car) = 2/3.
Well done. Interestingly, this problem has confused not only people who normally do not deal with probabilities. Even great mathematicians got trapped by the issue. For instance, Paul Erdos, one of the greatest experts in probability theory could not understand the intuition behind the solution, it puzzled him a lot.
ReplyDeleteHere are some quotes:
======================
Vázsonyi told Erdös about the Monty Hall dilemma. “I told Erdös that the answer was to switch,” said Vázsonyi, “and fully expected to move to the next subject. But Erdös, to my surprise, said, ‘No, that is impossible. It should make no difference.’ At this point I was sorry I brought up the problem, because it was my experience that people get excited and emotional about the answer, and I end up with an unpleasant situation. But there was no way to bow out, so I showed him the decision tree solution I used in my undergraduate Quantitive Techniques of Management course.”
And then.
“An hour later he came back to me really irritated. “You are not telling me why to switch,” he said. ‘What is the matter with you?’ I said I was sorry, but I didn’t really know why and that only the decision tree analysis convinced me. He got even more upset.” Vázsonyi had seen this reaction before, in his students, but he hardly expected it from the most prolific mathematician of the twentieth century.
=============================
You are great, if you understood the solution right at the spot, or even more, was able to solve it yourself. For me it took a while ;)
Here is another nice exercise on probability, slightly related to the post topic.
Given an infinite chess board, where one cell is of the size 2*a. On this board a needle is thrown, whose size is 2*r < 2*a. Find the probability of the event that the needle falls entirely within one cell.
Hey, thanks for your interesting question. I'll think about it and come back later :)
ReplyDeleteThe formalization was a bit imprecise. By the size of a cell I mean the length of one side. And of course the size of the needle is also its length.
ReplyDeleteSeems it takes a while to solve it. Here is a hint: answer is 1-(r*a-r^2)/(pi*a^2).
ReplyDeleteBut how do we get there?
Hey, thanks for the hint. It was indeed complicated and I've been busy. But I will come back to the problem soon!
ReplyDelete:-)