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.

Arrange 20 cubes in 4 piles using these clues:

All piles contain an even number of cubes.there are twice as many cubes in the first pile as in the 2nd pile. the largest number of cubes are in the first pile. all piles have different number of cubes. each pile has at least one cube.how many cubes in pile1,pile2,pile3,pile4????



Pile 2: x number of cubes
Pile 1: 2x
Each pile must have at least 2 cubes to have an even number.

x + 2x = 3x
3x < 20 so x < 6.67

Using trial and error, if pile 2 had 6 cubes and pile 3 had 12 cubes, there would be 2 cubes left. You can't make two piles with 2 cubes, because one is not an even number. If pile 2 had 5 cubes and pile 1 had 10 cubes, there would be 5 cubes left. This is an odd number and can't be divided into two even numbered piles. If pile 2 had 4 cubes and pile 1 had 8 cubes, there would be 8 cubes left. This can then be split into a piles of 2 and 6.

Pile 1: 8
Pile 2: 4
Pile 3: 6
Pile 4: 2

Measure ( Minutes With two SandGlasses of 4 MInutes & 7 Minutes

If you have two sand glasses One of them is for the 4 minute another one - is for 7 minutes If you have to measure 9 minutes with these two sand glasses in 9 minutes?

At 0 minutes, turn both the hourglasses.

After 4 minutes:
The 4 minute hourglass: 0 minutes left.
The 7 minute hourglass: 3 minutes left.
Turn the 4 minute hourglass.
After 7 minutes:
The 4 minute hourglass: 1 minute left.
The 7 minute hourglass: 0 minutes left.
Turn the 7 minute hourglass.

After 8 minutes:
The 4 minute hourglass: 0 minutes left.
The 7 minute hourglass: 1 minute left.
Turn the 7 minute hourglass.

After 9 minutes:
The 4 minute hourglass: 0 minute left.
The 7 minute hourglass: 0 minutes left.

Now you know you are finished.

Saturday, March 19, 2011

Bus Station Puzzle -A DP Approach

At a bus-station, you have time-table for buses arrival and departure. You need to find the minimum number of platforms so that all the buses can be accommodated as per their schedule.

Example: Time table is like below:


Bus


Arrival


Departure

BusA


0900 hrs


0930 hrs

BusB


0915 hrs


1300 hrs

BusC


1030 hrs


1100 hrs

BusD


1045 hrs


1145 hrs


Then the answer must be 3. Otherwise the bus-station will not be able to accommodate all the buses.


Answer:

Let’s take the same example as described above. Now if we apply dynamic programming and calculate the number of buses at station at any time (when a bus comes or leaves). Maximum number in that pool will be nothing but the maximum number of buses at the bus-station at any time, which is same as max number of platforms required.


So first sort all the arrival(A) and departure(D) time in an int array. Please save the corresponding arrival or departure in the array also. Either you can use a particular bit for this purpose or make a structure. After sorting our array will look like this:


0900


0915


1930


1030


1045


1100


1145


1300

A


A


D


A


A


D


D


D


Now modify the array as put 1 where you see A and -1 where you see D. So new array will be like this:


1


1


-1


1


1


-1


-1


-1


And finally make a cumulative array out of this:


1


2


1


2


3


2


1


0


Your solution will be the maximum value in this array. Here it is 3.

The complexity of this solution depends on the complexity of sorting.

Soln Provided By Aakash

Wednesday, March 16, 2011

Temple,Flowers and Magic Pond

There is a lake, of square shape. There are four temples on each
corner. There is a flower tree next to, say temple no 1. The pond has
this magic power, if a flower is dip into the water it doubles the
quantity. There is a warning note from the priest, saying "No flower
should be wasted".

So the puzzle is, how many flowers should be plucked from the tree and
should be offered in the temple and after offering at each temple, no
flower should be left. Each temple has to be offered the same number
of flower. Before offering, flowers has to be dipped in to the pond to
get it double, as he can pluck the flowers from the tree only once, so
he has to be care-full in choosing, the total number of flowers

There are infinite solutions to this problem. Say x flowers are plucked and
y flowers are offered in each temple. then -

2(2(2(2x-y) -y) -y) -y =0
i.e.
16x-15y=0;

any pair the x and y satisfying this equation is a solution.Smallest numbers
are 15, 16

Tuesday, March 15, 2011

Splitting Chocolate Bars

Assume you have a chocolate bar consisting, as usual, of a number of squares arranged in a rectangular pattern. Your task is to split the bar into small squares (always breaking along the lines between the squares) with a minimum number of breaks. How many will it take?
Ans. N-1

The number of moves needed to break it into separate squares is invariant with regard to the actual sequence of moves.

Proof (by induction)

1. If there are just two squares we clearly need just one break.
2. Assume that for numbers 2

Proof #2
Let start counting how many pieces we have after a number of breaks. The important observation is that every time we break a piece the total number of pieces is increased by one. (For one bigger piece have been replaced with two smaller ones.) When there is no pieces to break, each piece is a small square. At the beginning (after 0 breaks) we had 1 piece. After 1 break we got 2 pieces. As I said earlier, increasing the number of breaks by one increases the number of pieces by 1. Therefore, the latter is always greater by one than the former

Monday, March 14, 2011

10 Digit Number Problem

en-digit number. Find a 10-digit number whose first digit
is the number of 1’s in the 10-digit number, whose second
digit is the number of 2’s in the 10-digit number, whose
third digit is the number of 3’s in the 10-digit number, and
so on. The ninth digit must be the number of nines in the
10-digit number and the tenth digit must be the number of
zeros in the 10-digit number


I'll denote the digits a%5B1%5D, a%5B2%5D, ..., a%5B10%5D. Since there are a%5B1%5D 1's, a%5B2%5D 2's, ..., a%5B10%5D 0's, then sum%28a%5Bi%5D%2C+i+=+1%2C+10%29+=+10 because there are ten digits in the number.

Suppose a%5B10%5D+=+0. Then a contradiction would result, since there is at least one zero, so a%5B10%5D+%3E=+1.


Suppose a%5B10%5D+=+1. Then, this implies that there is exactly one zero within the number, and all the other a%5Bi%5D's are at least one, which also creates a contradiction due to the sum of digits. This can also apply to higher values of a%5B10%5D. If a%5B10%5D+=+n, then sum%28a%5Bi%5D%2C+i+=+1%2C+9%29+=+10-n. Also, if n of the numbers { a%5B1%5D, a%5B2%5D, ..., a%5B9%5D } are zero, then 9-n of these numbers are greater than or equal to 1, and they sum up to 10-n.

By the Pigeonhole principle, exactly one of the 9-n numbers is equal to 2 and all other nonzero numbers are equal to 1 (this means, 8-n numbers equal to 1). Therefore the number has n zeros, 8-n 1's and one 2. We can easily guess and check based on the value of n, which can only range between 2 and 8. We see that the number 2100010006 satisfies all the given constraints, which happens when n+=+6.