I would like to show how to code the NAO robot to beat us at Jotto (5-letter Mastermind) with
Choregraphe. I will employ a brute force technique that does not require any knowledge of the English language, the frequency of its letters, or smart combinations of vowels and consonants to try to minimize the number of attempts. It goes like this:
- Gather all 5-letter words with no repeated letters in a list.
- Choose a random word from that list—your guess—, and ask it to be scored ala Mastermind.
- Filter through the list all words that share the same score with your guess; discard the rest.
- Go back to step 2 and repeat until the target word is found.
Coding this strategy in
python requires only four variables:
whole_dict: the list with all the words
step = [x for x in whole_dict]: A copy of
whole_dict, which is going to be shortened on each step (hence the name). Note that stating
step = whole_dictwill change the contents of
whole_dictwhen we change the contents of
step— not a good idea.
guess = random.choice(step): A random choice from the list
score: A string containing the two digits we obtain after scoring the guess. The first digit indicates the number of correct letters in the same position as the target word; the second digit indicates the number of correct letters in the wrong position.
attempts: optional. The number of attempts at guessing words. For quality control purposes.
At this point, I urge the reader to stop reading the post and try to implement this strategy as a simple script. When done, come back to see how it can be coded in the NAO robot.
Let so that too.
Show that and
I got this problem by picking some strictly positive value and breaking the integral as follows:
Let us examine now the factors and above:
We have thus proven that with At this point, all you have to do is pick (provided the denominator is not zero) and you are done.
We briefly explored Lindenmayer systems (or L-systems) in an old post: Toying with Basic Fractals. We quickly reviewed this method for creation of an approximation to fractals, and displayed an example (the Koch snowflake) based on tikz libraries.
I would like to show a few more examples of beautiful curves generated with this technique, together with their generating axiom, rules and parameters. Feel free to click on each of the images below to download a larger version.
Note that any coding language with plotting capabilities should be able to tackle this project. I used once again tikz for , but this time with the tikzlibrary lindenmayersystems.
Would you like to experiment a little with axioms, rules and parameters, and obtain some new pleasant curves with this method? If the mathematical properties of the fractal that they approximate are interesting enough, I bet you could attach your name to them. Like the astronomer that finds through her telescope a new object in the sky, or the zoologist that discover a new species of spider in the forest.
I have just received a copy of Instant SymPy Starter, by Ronan Lamy—a no-nonsense guide to the main properties of SymPy, the Python library for symbolic mathematics. This short monograph packs everything you should need, with neat examples included, in about 50 pages. Well-worth its money.
Segments and are equal. Lines and intersect at Form four circumcircles: Prove that the circumcenters form a rhombus, with
Note that if this construction works, it must do so independently of translations, rotations and dilations. We may then assume that is the origin, that the segments have length one, and that for some parameters it is We let SymPy take care of the computation of circumcenters:
import sympy from sympy import * # Point definitions M=Point(0,0) A=Point(2,0) B=Point(1,0) a,theta=symbols('a,theta',real=True,positive=True) C=Point((a+1)*cos(theta),(a+1)*sin(theta)) D=Point(a*cos(theta),a*sin(theta)) #Circumcenters E=Triangle(A,C,M).circumcenter F=Triangle(A,D,M).circumcenter G=Triangle(B,D,M).circumcenter H=Triangle(B,C,M).circumcenter
Finding that the alternate angles are equal in the quadrilateral is pretty straightforward:
In : P=Polygon(E,F,G,H) In : P.angles[E]==P.angles[G] Out: True In : P.angles[F]==P.angles[H] Out: True
To prove it a rhombus, the two sides that coincide on each angle must be equal. This presents us with the first challenge: Note for example that if we naively ask SymPy whether the triangle is equilateral, we get a False statement:
In : Triangle(E,F,G).is_equilateral() Out: False In : F.distance(E) Out: Abs((a/2 - cos(theta))/sin(theta) - (a - 2*cos(theta) + 1)/(2*sin(theta))) In : F.distance(G) Out: sqrt(((a/2 - cos(theta))/sin(theta) - (a - cos(theta))/(2*sin(theta)))**2 + 1/4)
Part of the reason is that we have not indicated anywhere that the parameter theta is to be strictly bounded above by (we did indicate that it must be strictly positive). The other reason is that SymPy does not handle identities well, unless the expressions to be evaluated are perfectly simplified. For example, if we trust the routines of simplification of trigonometric expressions alone, we will not be able to resolve this problem with this technique:
In : trigsimp(F.distance(E)-F.distance(G),deep=True)==0 Out: False
Finding that with SymPy is not that easy either. This is the second challenge.
How would the reader resolve this situation?
The first problem is very simple:
Multiples of 3 and 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multip les is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
One easy-to-code way is by dealing with arrays:
julia> sum( filter( x->((x%3==0) | (x%5==0)), [1:999] ) ) 233168
A much better way is to obtain it via summation formulas: Note that the sum of all multiples of three between one and 999 is given by
Similarly, the sum of all multiples of five between one and 995 is given by
Finally, we need to subtract the sum of the multiples of both three and five, since they have been counted twice. This sum is
The final sum is then,
If a pyramid is 250 cubits high and the side of its base 360 cubits long, what is its seked?
Take half of 360; it makes 180. Multiply 250 so as to get 180; it makes of a cubit. A cubit is 7 palms. Multiply 7 by
The seked is palms [that is, ].A’h-mose. The Rhind Papyrus. 33 AD
The image above presents one of the problems included in the Rhind Papyrus, written by the scribe Ahmes (A’h-mose) circa 33 AD. This is a description of all the hieroglyphs, as translated by August Eisenlohr:
The question for the reader, after going carefully over the English translation is: What does seked mean?
On January first, a pair of mice appeared in a house and bore six male mice and six female mice. At the end of January there are fourteen mice: seven male and seven female.
On the first of February, each of the seven pairs bore six male and six female mice, so that at the end of February there are ninety-eight mice in forty-nine pairs. From then on, each pair of mice bore six more pairs every month.
- Find the number of mice at the end of December.
- Assume that the length of each mouse is 4 sun. If all the mice line up, each biting the tail of the one in front, find the total length of miceJinkō-ki, 1715