Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Unique Prime Number Calculator #1589

Merged
merged 9 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# <p align="center">Unique Prime Number Calculator</p>

## Description :-

The Unique Prime Number Calculator is a web-based tool designed to identify and work with unique prime numbers. A unique prime number is a prime number that remains prime even after removing any single digit from it.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

Prime Check: Enter a number to determine if it is a unique prime. The calculator checks if the number is prime and if all resulting numbers from removing any single digit are also prime.

Range Finder: Input a range of numbers to find all unique prime numbers within that range. The tool will display all unique prime numbers that satisfy the conditions within the specified range.

## Screenshots :-

![image](https://github.com/user-attachments/assets/c9b7b3c6-11b9-4be1-bb94-213d099da413)
29 changes: 29 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Unique Prime Number Calculator</title>
</head>
<body>
<div class="container">
<h1>Unique Prime Number Calculator</h1>
<div class="calculator">
<input type="number" id="numberInput" placeholder="Enter a number"/>
<button onclick="checkUniquePrime()">Check Unique Prime</button>
<div id="result"></div>
</div>
<div class="range-calculator">
<h2>Find Unique Primes in Range</h2>
<input type="number" id="rangeStart" placeholder="Start" />
<input type="number" id="rangeEnd" placeholder="End" />
<button onclick="findUniquePrimesInRange()">
Find Unique Primes
</button>
<div id="rangeResult"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
65 changes: 65 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function isPrime(n) {
if (n <= 1) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (let i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0) return false;
}
return true;
}

function isUniquePrime(n) {
if (!isPrime(n)) return false;
let nStr = n.toString();
for (let i = 0; i < nStr.length; i++) {
let newNumber = parseInt(nStr.slice(0, i) + nStr.slice(i + 1));
if (!isPrime(newNumber)) return false;
}
return true;
}

function checkUniquePrime() {
let number = parseInt(document.getElementById("numberInput").value);
let result = document.getElementById("result");

if(isNaN(number)) {
result.textContent = `Please enter a number`;
return;
}

if (isUniquePrime(number)) {
result.textContent = `${number} is a unique prime number.
${number} remains prime even after removing any single digit.`;
} else {
result.textContent = `${number} is not a unique prime number.
${number} is either not prime or does not remain prime after removing any single digit.`;
}
}

function findUniquePrimesInRange() {
let start = parseInt(document.getElementById("rangeStart").value);
let end = parseInt(document.getElementById("rangeEnd").value);
let rangeResult = document.getElementById("rangeResult");
let uniquePrimes = [];

if(isNaN(start) || isNaN(end)) {
rangeResult.textContent = `Please enter a valid range`;
return;
}

if(start > end) {
rangeResult.textContent = `The starting number should be smaller than the ending number`;
return;
}

for (let num = start; num <= end; num++) {
if (isUniquePrime(num)) {
uniquePrimes.push(num);
}
}
if (uniquePrimes.length > 0) {
rangeResult.textContent = `Unique prime numbers in range: ${uniquePrimes.join(", ")}`;
} else {
rangeResult.textContent = `No unique prime numbers found in range.`;
}
}
58 changes: 58 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');

body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #74ebd5, #acb6e5);
}

.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
max-width: 400px;
font-family: 'Open Sans', sans-serif;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
color: #333;
margin: 7% auto;
text-align: center;
}

h1, h2 {
text-align: center;
font-family: 'Arial Black', sans-serif;
}

button {
width: 100%;
padding: 10px;
background-color: #14ca5a;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1.15em;
}

button:hover {
background-color: #279451;
}

.calculator, .range-calculator {
margin-bottom: 20px;
}

input {
margin: 5px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
width: calc(100% - 22px);
}

#result, #rangeResult {
margin-top: 20px;
font-size: 18px;
text-align: left;
padding: 0 11px;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4178,6 +4178,20 @@ <h3>Checks if a number is ugly number or not.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Unique Prime Number Calculator</h2>
<h3>Checks if a number is unique prime or not and finds unique prime numbers in a range.</h3>
<div class="card-footer">
<a href="./Calculators/Unique-Prime-Number-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Unique-Prime-Number-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Unit Calculator</h2>
Expand Down