In North America, most electrical outlets/receptacles follow standards set by NEMA. For this challenge, you'll be given a few properties of a device you need to plug in, and your program (or function) should return all of the outlets that would be compatible.
For this challenge, an outlet has three properties: voltage, current rating, and grounding.
I/O:
Input will consist of a voltage, current usage, and grounding requirements for some device. The first two are positive integers, and the third can be represented by a boolean (though you are allowed to represent it in any reasonable way).
The output should be a list of outlets which are compatible, following the rules below. Each outlet's name is formatted as NN-nn
, with NN
and nn
being numbers. All outlets should either be returned as strings with this formatting, or arrays of [NN, nn]
. You can return the compatible outlets in an array, or separated with spaces/newlines/commas, or via any other reasonable method.
Requirements:
In order for an outlet to be compatible with the inputted device, it must meet three requirements:
- The voltage should be within ±10% of the device's voltage
- The current rating should be at least as high as the device's current usage
- If the device requires a grounded outlet, the outlet must be grounded (otherwise it may or may not be)
Outlets:
These are the outlets your program must be able to handle:
1-15 120 15
2-15 240 15
2-20 240 20
2-30 240 30
5-15 120 15 G
5-20 120 20 G
5-30 120 30 G
6-15 240 15 G
6-20 240 20 G
6-30 240 30 G
6-50 240 50 G
7-15 277 15 G
7-20 277 20 G
7-30 277 30 G
7-50 277 50 G
10-30 240 30
10-50 240 50
11-20 240 20
11-30 240 30
11-50 240 50
12-20 480 20
14-15 240 15 G
14-30 240 30 G
14-50 240 50 G
14-60 240 60 G
The first column is the name of the outlet, followed by the voltage, then the current rating, then a G
if it's grounded. Some of these may be slightly inaccurate.
Test Cases:
Formatted with a voltage, then current usage, then a G
for grounded or an x
for ungrounded. Some do not have any compatible outlets.
120 16 G 5-20, 5-30
260 5 x 2-15, 2-20, 2-30, 6-15, 6-20, 6-30, 6-50, 7-15, 7-20, 7-30, 7-50, 10-30, 10-50, 11-20, 11-30, 11-50, 14-15, 14-30, 14-50, 14-60
260 5 G 6-15, 6-20, 6-30, 6-50, 7-15, 7-20, 7-30, 7-50, 14-15, 14-30, 14-50, 14-60
260 35 x 6-50, 7-50, 10-50, 11-50, 14-50, 14-60
480 10 x 12-20
108 10 x 1-15, 5-15, 5-20, 5-30
528 20 x 12-20
249 50 G 6-50, 14-50, 14-60
250 50 G 6-50, 7-50, 14-50, 14-60
304 10 x 7-15, 7-20, 7-30, 7-50
480 10 G
480 25 x
400 10 x
600 10 x
180 10 x
80 10 x
Other:
This is code-golf, so shortest answer in bytes per language wins!