Electronic Arts (EA) | Online Technical Assessment | Move an atom
Got this question on an online SE assessment for Electronic Arts (EA). Applied through their career website. Seems easy-medium difficulty but wasn't able to solve it completely. Can anyone give me the correct solution?
Transcription of the images:
Objective
Move an atom on a grid using predefined actions.
Rules
You have discovered ancient alchemical processes for transmuting matter. You can add or remove protons and neutrons from an atom.
Your atom is placed in the game area. The x-axis represents the number of protons and the y-axis the number of neutrons.
You need to list the actions to be taken so that the atom reaches the expected number of protons and neutrons.
The following 3 predefined actions are available:
- PROTON: adds a proton to the atom. In the game area, this is equivalent to moving it one square to the right.
- NEUTRON: adds a neutron, moves the atom down one square.
- ALPHA: removes two protons and two neutrons by alpha decay, moves the atom two squares diagonally left and up.
You must return a list of strings corresponding to the actions to be performed.
For example, if you return a list containing the words ALPHA, PROTON, PROTON, PROTON, the atom will lose two protons and two neutrons, then regain 3 protons. In the end, it will move two squares up and one square to the right.
The order of the actions is not important. There's no need to minimize the number of actions. You are allowed to move your atom out of the grid, even through the upper and left borders.
Implementation
Implement the function solve(protons_start, neutrons_start, protons_target, neutrons_target). This function must return a list of strings: the successive actions to be performed to go from the supplied atom to the target atom.
The function takes 4 input parameters:
protons_startandneutrons_startrepresent the number of protons and neutrons in the initial atom.protons_targetandneutrons_targetrepresent the number of protons and neutrons in the desired atom.





