Statistics

Problem Statement for "ColorCode"

Problem Statement

An electronics manufacturer has called you in to make a program to decode resistor color codes. You are given a String[] code containing three elements corresponding to the first three color bands on a resistor. Return the # of Ohms the resistor represents.

The first two bands of resistors represent the value, while the third is a multiplier, as shown in the following chart:
Color:      Value:       Multiplier:

black         0                   1
brown         1                  10
red           2                 100
orange        3               1,000
yellow        4              10,000
green         5             100,000
blue          6           1,000,000
violet        7          10,000,000
grey          8         100,000,000
white         9       1,000,000,000

For example if you are given { "yellow", "violet", "red" }, you would return 4700.

Definition

Class:
ColorCode
Method:
getOhms
Parameters:
String[]
Returns:
long
Method signature:
long getOhms(String[] code)
(be sure your method is public)

Notes

  • Actual resistors can have a 4th and even a 5th band representing the tolerance, and the amount the value might change in 1,000 hours of use, respectively, but for our purposes we will only deal with the first three bands.

Constraints

  • code consists of 3 elements each containing one of the color words above, all in lower case.

Examples

  1. { "yellow", "violet", "red" }

    Returns: 4700

    The example from the problem statement.

  2. { "green", "black", "black" }

    Returns: 50

  3. { "orange", "red", "blue" }

    Returns: 32000000

  4. { "green", "white", "red" }

    Returns: 5900

  5. { "violet", "yellow", "grey" }

    Returns: 7400000000

  6. { "black", "red", "white" }

    Returns: 2000000000

  7. { "white", "white", "white" }

    Returns: 99000000000

    The maximum possible.

  8. {"white", "white", "white" }

    Returns: 99000000000

  9. {"white", "black", "black" }

    Returns: 90

  10. {"black", "black", "black" }

    Returns: 0

  11. {"red", "black", "black" }

    Returns: 20

  12. {"orange", "orange", "orange" }

    Returns: 33000


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: