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 1 commit
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
19 changes: 19 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# <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 :-
33 changes: 33 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Unique Prime Number Calculator</title>
<link rel="stylesheet" href="styles.css" />
</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>
46 changes: 46 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 (isUniquePrime(number)) {
result.textContent = `${number} is a unique prime number.`;
} else {
result.textContent = `${number} is not a unique prime number.`;
}
}

function findUniquePrimesInRange() {
let start = parseInt(document.getElementById("rangeStart").value);
let end = parseInt(document.getElementById("rangeEnd").value);
let rangeResult = document.getElementById("rangeResult");
let uniquePrimes = [];
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.`;
}
}
69 changes: 69 additions & 0 deletions Calculators/Unique-Prime-Number-Calculator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');

body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(to right, #74ebd5, #acb6e5);
height: 100vh;
margin: 0;
}

.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
width: 400px;
font-family: 'Open Sans', sans-serif;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
color: #333;
margin: 12% 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;
}

#results {
display: none;
margin-top: 20px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}

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

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

#result, #rangeResult {
margin-top: 20px;
font-size: 18px;
}