Problem: this year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards).
10/02/2001
when was the last date that this occurred on? (see if you can do it in your head!)
Solution: we know the year has to be less than 2001 since we already have the palindrome for 10/02. it can’t be any year in 1900 because that would result in a day of 91. same for 1800 down to 1400. it could be a year in 1300 because that would be the 31st day. so whats the latest year in 1300 that would make a month? at first i thought it would be 1321, since that would give us the 12th month, but we have to remember that we want the maximum year in the 1300 century with a valid month, which would actually be 1390, since 09/31 is a valid date.
but of course, a question like this wouldn’t be complete without an aha factor. and of course, there are not 31 days in september, only 30. so we have to go back to august 08 which means the correct date would be 08/31/1380.
palindromes also offer another great string question.
write a function that tests for palindromes
bool isPalindrome( char* pStr )
if you start a pointer at the beginning and the end of the string and keep comparing characters while moving the pointers closer together, you can test if the string is the same forwards and backwards. notice that the pointers only have to travel to the middle, not all the way to the other end (to reduce redundancy).
bool isPalindrome( char* pStr )
{
if ( pStr == NULL )
return false;
char* pEnd = pStr;
while ( *pEnd != '\0' )
pEnd++;
pEnd--;
while(pEnd > pStr)
{
if ( *pEnd != *pStr )
return false;
pEnd--;
pStr++;
}
return true;
}
"You can punch a hole in an apple using a straw. How do you think that makes your milkshake feel..???" Start Solving It...
Showing posts with label Intel Puzzle. Show all posts
Showing posts with label Intel Puzzle. Show all posts
Tuesday, June 21, 2011
Tuesday, March 22, 2011
Given the cube below, find the number of acute triangles formed by connecting three vertices and the number of right triangles formed by connecting 3
Given the cube below, find the number of acute triangles formed by connecting three vertices and the number of right triangles formed by connecting three vertices.
For example, the vertices 1-6-8 form an acute triangle while the vertices 1-2-3 form a right triangle.

Solution:
One approach is to look at each vertex and see how many acute and right triangles can be formed and then remove duplications at the end. This is not the most efficient way.
Another approach is as follows: To determine the number of acute triangles, we shall first find the probability that at a triangle formed will be acute and multiply that number by the total number of triangles that can be formed on the cube. Similarly, we can find the number of right triangles.
Let us start with an arbitrary vertex, say vertex 1. (Notice that we could have started with any vertex.) There are a total of 21 triangles that can be formed using this vertex.
Why are there 21? From the vertex 1, we can choose any of the other 7 vertices for the next vertex of the triangle. For the last vertex, we can choose any of the remaining 6 vertices, but now we have double-counted, since the triangle with vertices 1-2-3 is the same as the triangle with vertices 1-3-2. Thus, we have (7*6)/2 = 21 triangles.
There are three acute triangles, namely 1-6-8, 1-3-6, and 1-3-8.
There are eighteen right triangles, namely 1-2-3, 1-2-4, 1-2-5, 1-2-6, 1-2-7, 1-2-8, 1-3-4, 1-3-5, 1-3-7, 1-4-5, 1-4-6, 1-4-7, 1-4-8, 1-5-6, 1-5-7, 1-5-8, 1-6-7, and 1-7-8.
From that, we see that the probability of picking an acute triangle is 3/21 = 1/7 while the probability of picking a right triangle is 18/21 = 6/7.
In total, there are 56 different triangles that are possible. This comes from the formula for the binomial coefficient. In this case, we have 8 vertices and we are choosing 3 of them.

Thus, there are a total of (1/7)*56 = 8 acute triangles and (6/7)*56 = 48 right triangles that can be formed by connecting three vertices of a cube.
For example, the vertices 1-6-8 form an acute triangle while the vertices 1-2-3 form a right triangle.

Solution:
One approach is to look at each vertex and see how many acute and right triangles can be formed and then remove duplications at the end. This is not the most efficient way.
Another approach is as follows: To determine the number of acute triangles, we shall first find the probability that at a triangle formed will be acute and multiply that number by the total number of triangles that can be formed on the cube. Similarly, we can find the number of right triangles.
Let us start with an arbitrary vertex, say vertex 1. (Notice that we could have started with any vertex.) There are a total of 21 triangles that can be formed using this vertex.
Why are there 21? From the vertex 1, we can choose any of the other 7 vertices for the next vertex of the triangle. For the last vertex, we can choose any of the remaining 6 vertices, but now we have double-counted, since the triangle with vertices 1-2-3 is the same as the triangle with vertices 1-3-2. Thus, we have (7*6)/2 = 21 triangles.
There are three acute triangles, namely 1-6-8, 1-3-6, and 1-3-8.
There are eighteen right triangles, namely 1-2-3, 1-2-4, 1-2-5, 1-2-6, 1-2-7, 1-2-8, 1-3-4, 1-3-5, 1-3-7, 1-4-5, 1-4-6, 1-4-7, 1-4-8, 1-5-6, 1-5-7, 1-5-8, 1-6-7, and 1-7-8.
From that, we see that the probability of picking an acute triangle is 3/21 = 1/7 while the probability of picking a right triangle is 18/21 = 6/7.
In total, there are 56 different triangles that are possible. This comes from the formula for the binomial coefficient. In this case, we have 8 vertices and we are choosing 3 of them.

Thus, there are a total of (1/7)*56 = 8 acute triangles and (6/7)*56 = 48 right triangles that can be formed by connecting three vertices of a cube.
Subscribe to:
Posts (Atom)