# Convert AWG to Inches

AWG (American Wire Gauge) is a common way of specifying wire sizes. Your task in this challenge is to convert from a given gauge to the diameter of the wire in inches.

The size in inches for the gauges from 4/0 to 40 are shown in the table below:

## Gauge to inches table

| AWG | Diameter (Inches) |
|-----|-------------------|
| 4/0 | 0.46              |
| 3/0 | 0.4096            |
| 2/0 | 0.3648            |
| 1/0 | 0.3249            |
| 1   | 0.2893            |
| 2   | 0.2576            |
| 3   | 0.2294            |
| 4   | 0.2043            |
| 5   | 0.1819            |
| 6   | 0.162             |
| 7   | 0.1443            |
| 8   | 0.1285            |
| 9   | 0.1144            |
| 10  | 0.1019            |
| 11  | 0.0907            |
| 12  | 0.0808            |
| 13  | 0.072             |
| 14  | 0.0641            |
| 15  | 0.0571            |
| 16  | 0.0508            |
| 17  | 0.0453            |
| 18  | 0.0403            |
| 19  | 0.0359            |
| 20  | 0.032             |
| 21  | 0.0285            |
| 22  | 0.0253            |
| 23  | 0.0226            |
| 24  | 0.0201            |
| 25  | 0.0179            |
| 26  | 0.0159            |
| 27  | 0.0142            |
| 28  | 0.0126            |
| 29  | 0.0113            |
| 30  | 0.01              |
| 31  | 0.00893           |
| 32  | 0.00795           |
| 33  | 0.00708           |
| 34  | 0.0063            |
| 35  | 0.00561           |
| 36  | 0.005             |
| 37  | 0.00445           |
| 38  | 0.00397           |
| 39  | 0.00353           |
| 40  | 0.00314           |


## Clarifications

• For gauges less than 0, you can take the input as either 3/0 or 000
• You only have to support from the given 4/0 to 40
• The Wikipedia page has some helpful formulas you can try to use if you don't want to hardcode everything
• This , so shortest code in bytes wins!
• It's amazing what Americans can do to avoid using the metric system :-P Feb 16, 2017 at 23:38
• This isn't kolmogorov-complexity as it is a conversion to output and not a constant output Feb 17, 2017 at 1:02
• Can we take input as an array? 0000 as [0, 0, 0, 0] and 40 as  Feb 18, 2017 at 2:53

## JavaScript (ES7), 36 bytes

s=>.46/92**(((+s||1-s.length)+3)/39)


Takes input in "0000" format.

# J, 33 26 bytes

0.46%92^39%~*@".{3+".,~1-#


Try it online!

Takes input as a string with gauges less than zero as a string of zeroes. Finds the index of that string and divides 0.46 (the diameter of 0000) by the 39th root of 92 (the ratio between gauges) that many times.

## Explanation

0.46%92^39%~*@".{3+".,~1-#  Input: string S
#  Length of S
1-   Subtract it from 1
".,~     Eval S and append it, forms [1-len(S), eval(S)]
*@".            Sign of the eval
{           Use that to index into the previous list
39%~                Divide by 39
92^                    Raise 92 to that power
0.46%                       Divide 0.46 by that and return


# Bash + GNU utils, 47

bc -l<<<"e(l(92)*(36-(${1/\/0/*-1+1}))/39)/200"  Straightforward arithmetic expression evaluation using bc. Input given as a command-line parameter. Gauges less than 0 are given as n/0. The bash parameter expansion ${1/\/0/*-1+1} converts these to -ve numbers and adds one which makes the arithmetic come out right.

bc -l gives 20 decimal places by default. bc's exponentiation operator ^ can only handle integer exponents so ln(y*e(x)) is used instead.

• Maybe mention that the output values lack the leading zero or add it yourself? As a side note, there is also the possibility to solve this directly in a bc script, though in more bytes. Feb 17, 2017 at 15:28

# Jelly, 18 bytes

VoLC$+3÷39µ92*.46÷  Try it online! A monadic link taking a tring and returning a number. The '0...0' cases produce some extra output, but the return value is correct, as may be seen by ignoring the first two lines here. ### How? VoLC$+3÷39µ92*.46÷ - Main link: guageString
V                  - evaluate as Jelly code (a string of zeros evaluates to 0)
$- last two links as a monad L - length C - complement (1-length) o - Or (integer value for > 0, 1-lenght for strings of zeros) +3 - add 3 ÷39 - divide by 39 µ - monadic chain separation (call the result p) .46÷ - 0.46 divided by 92* - 92 raised to the power of p  # Python 3, 45 bytes lambda s:.46/92**((3+(int(s)or 1-len(s)))/39)  Try it online! # 05AB1E, 25 23 bytes 8Ø50/92ID1‹ig(>}3+39/m/  Try it online! Explanation 8Ø # push the 8th prime (0-indexed) = 23 50/ # divide by 50 = 0.46 92 # push 92 I # push input D1‹i } # if input < 1 g(> # calculate -len(input)+1 3+ # add 3 39/ # divide by 39 m # raise 92 to this power / # divide 0.46 by this  # Excel, 53 49 bytes =92^((36-IF(ISNUMBER(A1),A1,49-CODE(A1)))/39)/200  Takes gauges less than Zero as String (1/0, 2/0 etc.) # Perl 5, 39 + 1 (-p) = 40 bytes s/(.).0/1-$1/e;$_=.005*92**((36-$_)/39)


Try it online!

Takes the bigger gauges as "n/0".