Tag Archives: Problem of the Week

POW Answer – Circle, Square, Circle

Last week’s problem involved using your geometry/trigonometry skills to find areas of shapes. We start off with a large (black) circle which has a (black) square inscribed in it which in turn has a (red) circle inscribed in it:
Circle Inscribed In A Square Inscribed In Another Circle

  1. Let’s start off with the equation for the area of a circle: A = π × r2 (where r is the radius)
  2. Now let’s think about the equation for area of a square: A = s2 (where s is the length of one of the sides)
  3. Next we can say that the radius of the inner circle is r1.
  4. After that let’s find the area of the red inner circle relative to r1: A1 = π × r12
  5. Now let’s find the length of the diagonal of the square (d) in which the red circle is inscribed relative to r1. This will also be the diameter of the outer circle
    1. s = r1 + r1 = 2 × r1
    2. The above is true because the red circle is inscribed in the square.
    3. d2 = s2 + s2
    4. d2 = 2 × s2
    5. d = (2 × s2)1/2
    6. d = s × 21/2
    7. d = 2 × r1 × 21/2
  6. Next we should find the area of the black circle (A2), in which the black square is inscribed, relative to r1.
    1. We will use r2 to represent the radius of the outer circle:
      1. r2 = d / 2
      2. r2 = (2 × r1 × 21/2) / 2
      3. r2 = r1 × 21/2
    2. A2 = π × r22
    3. A2 = π × (r1 × 21/2)2
    4. A2 = π × r12 × 2
  7. Lastly we should find the area of the black outer circle while excluding the area covered by the red inner circle:
    1. Let’s make the area of the black doughnut shape be represented by A3.
    2. A3 = A2 - A1
    3. A3 = (π × r12 × 2) - (π × r12)
    4. A3 = (π × r12) + (π × r12) - (π × r12)
    5. A3 = π × r12

So after doing all of the math by using a little geometry and a little algebra we end up with the A1 (red area) being equal to A3 (black area).
Filled Circles

Even though the image makes it look like there is more red than black, there really isn’t. Interesting stuff, huh? :cool:

POW – Circle, Square, Circle

Recently a friend asked why I haven’t put up any new POWs (Problems of the Week). Part of the reason is because I got lazy but the other part is because the show Numb3rs is what inspired me before and I haven’t been watching any reruns lately :razz:. Yesterday I started watching a new show called Scorpion which has a little math in it and the second episode got me thinking about inscribed shapes. Take the following three shapes for example:
Circle Inscribed In A Square Inscribed In Another Circle

Above is a picture of a circle inscribed in a square which itself is inscribed in another circle. Now if I make the inner circle red and the remaining area black the image ends up looking as follows:
Filled Circles

Using the information given, is the red area bigger or the black area? If you remember a few things from trigonometry/geometry I’m sure this math problem will be a breeze :cool:. As usual the answer to this problem of the week became available a week after the POW was published and can be found here.

POW – Sequential Triad 24

Many people are familiar with the math game 24, but not many know about the sequential triad version. You must make each of the following sequences true by only inserting operators and without changing the order of the numbers:

0   1   2 = 24
1   2   3 = 24
2   3   4 = 24
3   4   5 = 24
4   5   6 = 24
5   6   7 = 24
6   7   8 = 24
7   8   9 = 24
8   9   0 = 24
9   0   1 = 24

You can use any of the following operators on the left-hand side of the equation, but the right-hand side of the equation must remain untouched:

  • Addition: +
  • Subtraction (and negation): +
  • Multiplication: ×
  • Division: /
  • Exponential: ^
  • Modulo: &
  • Absolute Value: abs(X)
  • Ceiling (round up): ceil(X)
  • Floor (round down): floor(X)
  • Square root: sqrt(X)
  • Factorial: X!
  • Parentheses: ( and )

Feel free to post your answers below or you can wait until the answers are posted next week. 8-)

POW – JavaScript Self Inequality

Assuming a normal JavaScript engine, what could you possibly pass into the following mystery() function that would not thrown an error?

function mystery(a) {
  if (a === a) {
    throw new Error('The first argument has self equality.');
  }
}

As is normal, this answer will be shown a week from when it was posted and will be linked to from here.The answer to this POW can now be found here.

POW Answer – Multiple Choice Question?

If you remember the problem, the key is the fact that the problem never said to choose one of the answers from the multiple choice list. Also, the question never said that that question was the one that applied to the multiple choice questions. Having those two facts in mind, you now have to do the math and figure out what the odds actually are that you at least got the question “right in some way“. Since that phrase is used, “right in some way“, we can assume that more than one of the options are the answer. Knowing this, what are all of the possible answer permutations?

  1. a
  2. b
  3. c
  4. d
  5. e
  6. ab
  7. ac
  8. ad
  9. ae
  10. bc
  11. bd
  12. be
  13. cd
  14. ce
  15. de
  16. abc
  17. abd
  18. abe
  19. acd
  20. ace
  21. ade
  22. bcd
  23. bce
  24. bde
  25. cde
  26. abcd
  27. abce
  28. abde
  29. acde
  30. bcde
  31. abcde

As shown above, we have 31 different answers that could be right. Since we have been limited to picking one letter at random, to determine the odds that your answer at least partially matches one of the answers listed above, you will have to multiply 31 by 5. That comes to 155 total possible scenarios. Now the final part of the problem is to determine how many of those times the random answer that is chosen would actually be correct. Since we can only pick one letter at random and it has to be one of the ones listed above, the number of characters that appear above is the same as the total amount of times that you will be correct. There are 80 letters shown above. In conclusion, the chance that you will at least be partially correct is 80 out of 155 or about 52%.

I know that many people probably disagree with me on this one, but in the end, since I wrote the problem, I am not sure I can be wrong on this one. ;) Still, thanks for the feedback in advanced.

POW – Multiple Choice Question?

This Problem of the Week will make you question whether or not multiple choice questions really are easier. Here is the question:

Assuming the answer can be selected from the following list, if you were to choose one of the following at random, what is the chance that you would be right in some way?

  1. 25
  2. 20%
  3. Zero
  4. 40%
  5. 1/5

Post your answers as comments below. The actual answer to this will be posted next Monday.

POW Answer – Explain That SQL #1

To answer last week’s POW, the purpose of the SQL was to generate a random string of letters and numbers. I actually wrote two different JavaScript function that can produce the same results. The following is the slightly more straight-forward solution:

function randomChars(len) {
  for(var n, s = ""; --len;) {
    n = parseInt(Math.random() * 62);
    s = String.fromCharCode(n + (n < 26 ? 65 : n < 52 ? 71 : -4));
  }
  return s;
}

The next version is a bit harder to follow because it involves recursion:

function recRandomChars(len) {
  if(!len){ return ""; }
  var n = parseInt(Math.random() * 62);
  return recRandomChars(--len)
    + String.fromCharCode(n + (n < 26 ? 65 : n < 52 ? 71 : -4));
}

One practical application of this is to generate a password with random characters.

POW – Explain That SQL #1

Someone asked me to quickly write them some code in any language that would accomplish a certain task. The following, which is in PostgreSQL, is the second solution that I came up with after doing the first one in my favorite language, JavaScript:

SELECT ARRAY_TO_STRING(ARRAY(
    SELECT CHR(num
        + CASE
            WHEN num < 26 THEN 65
            WHEN num BETWEEN 26 AND 51 THEN 71
            ELSE -4
          END
      )
    FROM (
      SELECT FLOOR(RANDOM() * 62)::INT AS num,
        generate_series(1, 12)
    ) AS t
  ), '')

The question is, what does this SELECT statement actually do? If you were asked to write that as a JavaScript, substituting the 12 for a variable passed into the function, what would your function look like?

As usual, the answer to this Problem of the Week will be made available a week from today, on Wednesday, August 22, 2012.

The answer to this Problem of the Week can now be found here.

POW Answer – Unnamed Function #2

This answers the Problem of the Week from May 8, 2012. The identity of this well-known computer science function is the binary search. The following is the same code from before with the variables more properly named:

var binarySearch = (function(internal) {
  function search(array, item, temp1, temp2) {
    array = array[temp1 = parseInt((temp2 = array.length) / 2)] == item
      ? temp1
      : temp1 > 0 && array[temp1] > item
        ? +search.call(internal, array.slice(0, temp1), item)
        : temp1 < temp2 - 1 && array[temp1] < item
          ? temp1 + 1 + search.call(internal, array.slice(temp1 + 1), item)
          : internal;
    return this !== internal && isNaN(array) ? -1 : array;
  }
  return search;
})({});

To tell you the truth, after using the real names in the function definition, I realized that the code could be shortened a little more without changing the execution by doing the following:

var binarySearch = (function(internal) {
  return function(array, item, temp1, temp2) {
    array = array[temp1 = parseInt((temp2 = array.length) / 2)] == item
      ? temp1
      : temp1 > 0 && array[temp1] > item
        ? +binarySearch.call(internal, array.slice(0, temp1), item)
        : temp1 < temp2 - 1 && array[temp1] < item
          ? temp1 + 1 + binarySearch.call(internal, array.slice(temp1 + 1), item)
          : internal;
    return this !== internal && isNaN(array) ? -1 : array;
  };
})({});