Trang

Thursday, July 10, 2014

Verbal arithmetic

Verbal arithmetic, also known as alphameticscryptarithmeticcrypt-arithmeticcryptarithm or word addition, is a type of mathematical game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters. The goal is to identify the value of each letter. The name can be extended to puzzles that use non-alphabetic symbols instead of letters.
The equation is typically a basic operation of arithmetic, such as additionmultiplication, or division. The classic example, published in the July 1924 issue of Strand Magazine by Henry Dudeney,[1] is:
\begin{matrix}
     &   & \text{S} & \text{E} & \text{N} & \text{D} \\
   + &   & \text{M} & \text{O} & \text{R} & \text{E} \\
 \hline
   = & \text{M} & \text{O} & \text{N} & \text{E} & \text{Y} \\
\end{matrix}
The solution to this puzzle is O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7, R = 8, and S = 9.
Traditionally, each letter should represent a different digit, and (as in ordinary arithmetic notation) the leading digit of a multi-digit number must not be zero. A good puzzle should have a unique solution, and the letters should make up a cute phrase (as in the example above).
Verbal arithmetic can be useful as a motivation and source of exercises in the teaching of algebra.
The secret is to notice that the answer has more letters (5 letters) 
than the question (4 letters).

That M at the beginning of money is a carry from the thousands place, 
so M = 1.  Now we have:

     SEND
   + 1ORE
   -------
  = 1ONEY

Now, in the thousands place there is a 1, so the only value for S that 
could cause a carry is S = 9 and that means O = 10.  Now we have:

     9END
   + 10RE
   -------
  = 10NEY

Now look at the hundreds place. If there were no carry from the tens 
place, E and N would be the same because E+0 = N, but E and N can't be 
the same, so there must be a carry from the tens place.  Now we have:

    1 1    <-- carry
     9END
   + 10RE
   -------
  = 10NEY

Now the equation for the hundreds place is 1+E+0 = N or just 1+E = N. 
In the tens place we can have N+R = E+10 if there is no carry from the 
ones place, or we can have 1+N+R = E+10 if there is.

First test: no carry from the ones place:

N+R = E+10  and  1+E = N
(1+E)+R = E+10
1+R = 10
R = 10-1
R = 9

But S = 9, so R cannot = 9.  That means there is a carry from the ones 
place and we get:

1+N+R = E+10  and  1+E = N
1+(1+E)+R = E+10
2+R = 10
R = 10-2
R = 8

So now we have:

    1 11   <-- carry
     9END
   + 108E
   -------
  = 10NEY

N cannot be 0 or 1 because 0 and 1 are taken.
N cannot be 2 because 1+2+8 = 11 and then E would equal 1, but it 
cannot equal 1 because 1 is taken.
N could equal 3,4,5,6 or 7 but it cannot equal 8 or 9 because 8 and 9 
are taken (and E must be 2,3,4,5 or 6 because it is 1 smaller than N).

If E were 2, then for the ones place to carry D would have to be 8 or 
9, and both 8 and 9 are taken, so E cannot be 2 (and N cannot be 3).

If E were 3, then for the ones place to carry D would have to be 7,8, 
or 9, but D cannot be 7 because then Y would be 0, which is taken, so
E cannot be 3 (and N cannot be 4).

If E were 4, then for the ones place to carry D would have to be 
6,7,8, or 9.  D cannot be 6 because Y would be 0, but D cannot be 7 
because Y would be 1, and 0 and 1 are both taken, so E cannot be 4 
(and N cannot be 5).

The only two possibilities for E now are 5 and 6.

If E were 6, then N would be 7 and D would have to be 4 (which would 
make Y = 0), 5 (which would make Y = 1), 6 (which is taken by E), or 
7 (which is taken by N). There are no solutions for E = 6, so E must 
be 5.

So now we have:

    1 11   <-- carry
     956D
   + 1085
   -------
  = 1065Y

Do the same reasoning for D and Y and get the answer.

If you need more help check out this archived answer:

   Finding the Digits of SEND + MORE = MONEY
   http://www.mathforum.org/library/drmath/view/57968.html 

Sunday, July 6, 2014

Tập hợp(Collections) Java


  • Tập hợp dùng lưu trữ, thao tác trên một nhóm các đối tượng.
  • Các đối tượng của tập hợp có thể thuộc nhiều loại dữ liệu khác nhau
  • Số phần tử trong tập hợp có thể thêm hoặc bớt

  • List
    1. Lưu trữ các phần tử theo thứ tự được thêm vào
    2. Truy xuất các phần tử theo chỉ mục(index)
    3. Các phần tử trong List có thể trùng nhau.
  • Set 
    • Các phần tử trong Set lưu trữ không theo thứ tự đã thêm vào .
    • Không chấp nhận các phần tử trùng.
  1. SortedSet 
    • Thừa kế từ Set
    • Lưu trữ các phần tử th eo thứ tự tăng.
    • Không chấp nhận các phần tử trùng.
  • Queue  
Lp TreeSet 
  • Lưu giữ liệu theo cấu trúc “cây”.
  • Các phần tử được lưu trữ theo thứ tự tăng dần 
Map 
  • MAP lưu trữ dữ liệu theo từng cặp: khóa – giá trị (key-value)
  • Các giá trị được lấy từ MAP thông qua khóa của nó.
  • Các khóa trong MAP phải duy nhất.