diff --git a/Calculators/Circular-Prime-Calculator/README.md b/Calculators/Circular-Prime-Calculator/README.md new file mode 100644 index 000000000..d75461c4f --- /dev/null +++ b/Calculators/Circular-Prime-Calculator/README.md @@ -0,0 +1,31 @@ +#

Circular Prime Checker

+ +## Description :- + +Circular Prime Checker is a web application that allows users to check if a given number is a Circular Prime and find bouncy numbers within a specified range. + +* Checks if a number is a Circular Prime Checker. +* Finds Circular Prime numbers within a specified range. + +## What is a Circular Prime ? + + A prime number is said to be a circular prime if after any cyclic permutations of the digits, it remains a prime. + +Examples: + +Input : n = 113 +Output : Yes +All cyclic permutations of 113 (311 +and 131) are prime. + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Screenshots :- + +![CPC](https://github.com/Rakesh9100/CalcDiverse/assets/125949765/34d359b2-23d5-456c-b88f-51fb413bebbc) + + diff --git a/Calculators/Circular-Prime-Calculator/index.html b/Calculators/Circular-Prime-Calculator/index.html new file mode 100644 index 000000000..0cd8eec04 --- /dev/null +++ b/Calculators/Circular-Prime-Calculator/index.html @@ -0,0 +1,39 @@ + + + + + + + Circular Prime Checker + + + +

Circular Prime Checker

+ + + +
+
+

Circular Prime Checker

+ + + + +

+
+ +
+

Find Circular Primes in Range

+ + + + + + +

+
+
+ + + + diff --git a/Calculators/Circular-Prime-Calculator/script.js b/Calculators/Circular-Prime-Calculator/script.js new file mode 100644 index 000000000..def66694d --- /dev/null +++ b/Calculators/Circular-Prime-Calculator/script.js @@ -0,0 +1,99 @@ +function isPrime(num) { + if (num < 2) return false; + for (let i = 2; i <= Math.sqrt(num); i++) { + if (num % i === 0) { + return false; + } + } + return true; +} + +function checkCircularPrime() { + let number = document.getElementById('numberInput').value; + + if (!/^\d+$/.test(number)) { + alert('Please enter a valid positive integer.'); + return; + } + + let numStr = number.toString(); + let isCircularPrime = true; + let primePermutations = []; + + for (let i = 0; i < numStr.length; i++) { + let rotatedNumber = parseInt(numStr.slice(i) + numStr.slice(0, i)); + primePermutations.push(rotatedNumber); + + if (!isPrime(rotatedNumber)) { + isCircularPrime = false; + break; + } + } + + let result; + if (isCircularPrime) { + result = `Yes, it is a Circular Prime. Circular Permutations: ${primePermutations.join(', ')}`; + } else { + result = `No, it is not a Circular Prime. Circular Permutations: ${primePermutations + .map((num, index) => `${num} (${isPrime(num) ? 'Prime' : 'Not Prime'})`) + .join(', ')}`; + } + + document.getElementById('result').innerText = result; +} + +function findCircularPrimesInRange() { + let fromRange = parseInt(document.getElementById('fromRange').value); + let toRange = parseInt(document.getElementById('toRange').value); + + if (isNaN(fromRange) || isNaN(toRange) || fromRange >= toRange) { + alert('Please enter valid range values.'); + return; + } + + let circularPrimes = []; + + for (let num = fromRange; num <= toRange; num++) { + if (isPrime(num)) { + let numStr = num.toString(); + let isCircularPrime = true; + let primePermutations = []; + + for (let i = 0; i < numStr.length; i++) { + let rotatedNumber = parseInt(numStr.slice(i) + numStr.slice(0, i)); + primePermutations.push(rotatedNumber); + + if (!isPrime(rotatedNumber)) { + isCircularPrime = false; + break; + } + } + + if (isCircularPrime) { + circularPrimes.push({ number: num, permutations: primePermutations }); + } + } + } + + let result; + if (circularPrimes.length > 0) { + result = `Circular Primes in the range ${fromRange} to ${toRange}: ${circularPrimes + .map(cp => `${cp.number} `) + .join(', ')}`; + } else { + result = `There are no Circular Primes in the range ${fromRange} to ${toRange}.`; + } + + document.getElementById('rangeResult').innerText = result; +} + +function clearSection() { +document.getElementById('numberInput').value = ''; +document.getElementById('result').innerText = ''; +} + +function clearRangeSection() { +document.getElementById('fromRange').value = ''; +document.getElementById('toRange').value = ''; +document.getElementById('rangeResult').innerText = ''; +} \ No newline at end of file diff --git a/Calculators/Circular-Prime-Calculator/style.css b/Calculators/Circular-Prime-Calculator/style.css new file mode 100644 index 000000000..700652d3e --- /dev/null +++ b/Calculators/Circular-Prime-Calculator/style.css @@ -0,0 +1,78 @@ +body { + font-family: 'Arial', sans-serif; + text-align: center; + margin: 0; + padding: 0; + background-color: #091020; + color: #fff; +} + +.title { + padding: 20px; + margin: 0; + font-size: 36px; + font-weight: 900; + color: yellow; + padding-top: 90px; +} +.title:hover{ + color: red; + scale: 1.3; +} + +.calculator { + display: flex; + flex-wrap: wrap; + justify-content: center; +} + +.section { + width: 90%; + max-width: 400px; + margin: 20px; + padding: 20px; + box-sizing: border-box; + + border: 2px solid #da0808; + border-radius: 15px; +} + +.calculator-title { + color: #bbed06; + font-size: 24px; + font-weight: bold; + margin-bottom: 15px; +} + +input { + padding: 10px; + font-size: 16px; + margin-top: 10px; + width: 100%; + box-sizing: border-box; +} + +label{ + font-size: large; + color: white; +} +button { + padding: 10px 20px; + font-size: 20px; + cursor: pointer; + background-color: yellow; + color: red; + border: none; + border-radius: 5px; + margin-top: 10px; +} + +button:hover { + background-color: rgb(235, 192, 21); +} + +p { + font-size: 18px; + margin-top: 20px; + color: #d4eb0b; +} diff --git a/index.html b/index.html index 1dd8eacfb..3059b24b8 100644 --- a/index.html +++ b/index.html @@ -1822,6 +1822,20 @@

Generates the QR Code according to the given input.

+
+
+

Circular Prime Calculator

+

Checks if a number is circular prime and finds circular prime numbers in a range.

+ +
+