/prime-numbers-scss

🔢✨ Finding prime numbers using SCSS only.

Primary LanguageHTMLMIT LicenseMIT

demo example

Prime numbers: SCSS only

GitHub OpenSource
I was wondering if it is possible to implement some useful algorithms on SCSS. Well, here is a simple primality test and the sieve of Eratosthenes.

How It Works

Simple test

Implemented in the is_prime() function in the simple.scss file. In it, we iterate through all possible odd divisors up to the square root of the divisible, and if the divisor was not found (meaning, if the number is prime), we return true.

Sieve of Eratosthenes

Implemented in the eratosthenes.scss file. After running this code, the primes list will be created. For primes, the value of the corresponding index (starting from 1) will be true. This algorithm is not optimal. In SCSS, you cannot replace a list element by its index. To get around this, the sift() function was created, which performs n more actions at each iteration, which is why the complexity of the algorithm is close to O(n2).

Сoloring the tables

To display the output data, two tables are used (file index.html). The number of cells (which corresponds to the maximum number you are looking for) is written in the file config.scss in the variable max_el. If the number is simple, it will be colored red. This is implemented in the style.scss file - we just check each number from 1 to $max_el in one of the above ways.

How to Use It

  1. Clone this project locally;
  2. In the main directory, run the npm i command to install all the necessary packages;
  3. To start the live server, run the command npm run dev or just gulp.
    You can also explore this online at Codepen.

Contributing

If you have any ideas or found any bugs here, plz open the issue or make a fork and offer a pull request. And it will be great if you tell me about these ideas, maybe I'm already working on them.

License

Code released under the MIT License. You can use the code for any purpose by providing a link to the author.

Author

The author of this repository and code - @dan-sazonov.
Reach me:
✈️ Telegram
📧 Email