• subscribe
June 22, 2005 12:00 AM

The Logical Puzzle

SQL Server Pro
InstantDoc ID #46366

JULY'S PUZZLE: ARITHMETIC MAXIMUM CALCULATION
Given the two input values m and n, calculate the maximum of the two by using a mathematical expression. Don't use programmatic flow/case elements in your solution.

SOLUTION TO JUNE'S PUZZLE
As a reminder, let's review last month's puzzle. You have two ropes, each of which takes exactly 1 hour to burn from end to end. Each rope has different material densities at different points, so there's no guarantee how long it will take different sections within the rope to burn—for instance, the first half might burn in 59 minutes and the second half in 1 minute. You need to find a way to measure exactly 45 minutes by burning these two ropes.

Here's the solution. Light both sides of one rope, and light one side of the other rope. As soon as the first rope is consumed (exactly 30 minutes), light the other side of the second rope. The second rope will be consumed exactly after an additional 15 minutes, letting you measure exactly 45 minutes in total.



ARTICLE TOOLS

Comments
  • Douglas
    6 years ago
    May 08, 2006

    I liked this puzzle.

  • stef ten bras
    7 years ago
    Aug 02, 2005

    Two point, call the A and B
    MAX(A,B) = (A+B)/2 + ABS(A-B)/2

  • charliewillits
    7 years ago
    Jul 13, 2005

    It's not "mathematical", but how about:

    DECLARE @a int, @b int SET @a = 600 SET @b = 500
    SELECT @b WHERE @b > @a
    UNION SELECT @a WHERE @a > @b

You must log on before posting a comment.

Are you a new visitor? Register Here