From 1c4a5f2c0e30317efe2767017a887c0b870de670 Mon Sep 17 00:00:00 2001 From: AftabMankapure Date: Mon, 19 Feb 2024 20:41:33 +0530 Subject: [PATCH 1/3] added circular prime --- .vscode/settings.json | 3 + .../Circular-Prime-Calculator/README.md | 31 ++++++ .../Circular-Prime-Calculator/index.html | 39 ++++++++ .../Circular-Prime-Calculator/script.js | 99 +++++++++++++++++++ .../Circular-Prime-Calculator/style.css | 78 +++++++++++++++ index.html | 14 +++ 6 files changed, 264 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Calculators/Circular-Prime-Calculator/README.md create mode 100644 Calculators/Circular-Prime-Calculator/index.html create mode 100644 Calculators/Circular-Prime-Calculator/script.js create mode 100644 Calculators/Circular-Prime-Calculator/style.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file 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..882955c58 100644 --- a/index.html +++ b/index.html @@ -1822,6 +1822,20 @@

Generates the QR Code according to the given input.

+
+
+

Circular Prime Checker

+

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

+ +
+
From acbdd2ac7a63a6f08c26c68ce07ec1bf73436948 Mon Sep 17 00:00:00 2001 From: Rakesh Roshan Date: Mon, 19 Feb 2024 23:24:15 +0530 Subject: [PATCH 2/3] Delete .vscode directory --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6f3a2913e..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5501 -} \ No newline at end of file From 95793c586e4e2607814833a4e860a62e73cad74d Mon Sep 17 00:00:00 2001 From: Rakesh Roshan Date: Mon, 19 Feb 2024 23:28:11 +0530 Subject: [PATCH 3/3] Update index.html --- index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 882955c58..3059b24b8 100644 --- a/index.html +++ b/index.html @@ -1824,14 +1824,14 @@

Generates the QR Code according to the given input.

-

Circular Prime Checker

-

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

+

Circular Prime Calculator

+

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