Car Debugging: Misfire
Description:
Spark plugs, distributor wires, and firing order.
Your car's engine operates by containing tiny explosions caused by gas being ignited by spark plugs, which compresses a pistion, causing the engine to turn. Spark plugs are sparked by receiving electrical signal through a wire connected to a distributing system. If you're curious, here's an explanation of the whole process. If you watch the video, you can ignore the formulas, as this kata is about firing order, and not combustion physics.
In short, to make sure that this process is balanced, and engine rotation is maintained constantly, each cylinder of an engine is fired in an order determined by the manufacturer. There are a few cases where optimal order is very well documented. For example, with an inline 4-cylinder engine, 'I4'
the optimal firing order is 1-3-4-2
. Because of this, most (but not all...) manufacturers use this order. With different engine layouts, and sizes, sometimes manufacturers will change the order slightly to give more power but less balance, or less power and more engine longevity.
Please note: This is not car repair advice. If you think your car has a misfire, please look up the exact engine your car uses before attempting any of these sequences. AKA have fun, trust the mechanic instead of random internet man.
Your task is relatively simple
Write a function helps us diagnose where a misfire is located. A misfire is typically caused by a faulty wire, or old spark plug. This causes the engine to fire on every cylinder except the one that is bad. For example, with our typical inline 4 engine, if cylinder #3 has a misfire, the engine would receive full rotation in #1, #4, and #2, but #3 would give no rotation at all, causing major issues. For our case, we are assuming that an engine needs at least 1 cylinder functioning for us to diagnose the bad cylinders.
Your function should take one argument, which is a string with the following syntax:
MAKE | ENGINE SIZE | CURRENT ORDER
-----+--------------+----------------
Ford | V8 | 1-X-4-2-X-3-X-8
An "X"
indicates a cylinder that has not fired. Your goal is to return a string with the correct cylinder number, in the correct sequence for that make and engine size. In the example above, the correct return value is: "5-6-7"
. If there are no misfires, return an empty string. You have been provided with a python nested dictionary named CARS
that you can call as you please. All elements of CARS
are strings. The maker is the first key, the engine size is the second key. Below examples that will be included in the test cases.
INPUT: 'Ford V8 1-X-4-2-X-3-X-8'
| OUTPUT: '5-6-7'
INPUT: 'Cadillac V6 1-2-3-4-5-6'
| OUTPUT: ''
INPUT: 'GMC I4 1-X-4-2'
| OUTPUT: '3'
INPUT: 'Dodge V10 1-X-X-4-3-6-5-X-X-2'
| OUTPUT: '10-9-8-7'
Similar Kata:
Stats:
Created | Aug 15, 2023 |
Published | Aug 22, 2023 |
Warriors Trained | 209 |
Total Skips | 15 |
Total Code Submissions | 223 |
Total Times Completed | 93 |
Python Completions | 93 |
Total Stars | 2 |
% of votes with a positive feedback rating | 91% of 43 |
Total "Very Satisfied" Votes | 35 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 25 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |