This repository provides an algorithm to simulate the circulation of particles within a cyclotron. The algorithm is designed to handle different types of particles, including electrons, protons, and neutrons. The algorithm can create both closed and open cycles for each particle type.
To check the algorithm, follow the instructions below:
-
Clone the repository:
git clone https://github.com/gabrielh-silvestre/ll-cyclotron-algorithm
-
Navigate to the repository directory:
cd ll-cyclotron-algorithm
-
Include the algorithm in your project:
// Example usage for accelerating an electron const matrix = [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ]; const result = accelerateCyclotron('e', matrix); printMatrix(result);
-
Customize the input matrix based on the particle and desired acceleration.
The algorithm supports the following particle types:
- Electron (e): Represents an electron within the cyclotron.
- Proton (p): Represents a proton within the cyclotron.
- Neutron (n): Represents a neutron within the cyclotron.
The accelerateCyclotron
function takes two parameters: the particle type and the matrix representing the cyclotron.
accelerateCyclotron(particle, matrix);
particle
(str): Specifies the particle type. Valid options are "e" for electron, "p" for proton, and "n" for neutron.matrix
(list of lists): Represents the initial state of the cyclotron. Each element in the matrix can be either 1 (empty space) or the particle type.
The accelerateCyclotron
function returns the updated matrix representing the cyclotron after applying the particle's circulation.
Below are some examples of how to use the accelerateCyclotron
function:
-
Accelerating an electron:
const matrix = [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ]; const result = accelerateCyclotron('e', matrix); printMatrix(result); /* e, e, e, e 1, 1, 1, e 1, 1, 1, e 1, 1, 1, e */
-
Accelerating a proton:
const matrix = [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ]; const result = accelerateCyclotron('p', matrix); printMatrix(result); /* p, p, p, p p, 1, 1, p p, 1, p, 1 p, p, 1, p */
-
Accelerating a neutron:
const matrix = [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ]; const result = accelerateCyclotron('n', matrix); printMatrix(result); /* n, n, n, n 1, 1, 1, 1 1, 1, 1, 1 1, 1, 1, 1 */
The algorithm is designed to handle matrices of different sizes, ranging from 4x4 to NxN. It has been optimized for efficiency and takes advantage of good practices in data structure, functions, and algorithm design.