Sieve of Eratosthenes
How do I make an sieve of eratosthenes?
I implement a popular prime number generator.. What is a sieve of eratosthenes? How do you make a sieve of eratosthenes? This script and codes were developed by Mei Weng Brough-Smyth on 06 November 2022, Sunday.
Sieve of Eratosthenes - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Sieve of Eratosthenes</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html>
<head> <title>Primes!</title> <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
</head>
<body id="bohday"> <h1> Sieve of Eratosthenes :) </h1> <h4>A quick and simple algorithm for finding all primes under a number.</b> </h4> <input id="input" placeholder="Type integer here" onkeydown="validInteger()"/> <br> Primes output: <p id = "junk"></p>
</body> <script src="js/index.js"></script>
</body>
</html>
Sieve of Eratosthenes - Script Codes CSS Codes
#bohday { font-family: 'Open Sans', 'sans-serif'; background: skyBlue; color: white;
}
Sieve of Eratosthenes - Script Codes JS Codes
// Mei Weng Brough-Smyth
// beepboop.com.au
var limit;
// Take input and ensure it is an integer.
function validInteger(){ document.getElementById("junk").innerHTML = ""; var input = document.getElementById('input').value; limit = input.match(/^\d+$/); limit++; // Add 1 to compensate for place 0 doSieve(limit);
}
// Take limit and output using sieve of eratosthenes
function doSieve(limit) { // Create array with limit amount of elements var sieve= new Array(limit); // set 1 and 2 to false sieve[0] = false; sieve[1] = false; // Set elements that divide equally by 2 to false and the rest to true for (var i=2; i<limit; i++) { i%2===0 ? sieve[i] = false : sieve[i] = true; } // Get square root of limit var squareLimit = Math.sqrt(limit); // Get all primes from 2 to the square limit for (i=2; i<squareLimit; i++) { if (sieve[i]) { // Get all multiples of these primes and set them to false for (var j=i*2; j<=limit; j+=i) { sieve[j] = false; } } } // Print out prime result for (i=1; i<limit; i++) { if (sieve[i]) { document.getElementById("junk").innerHTML += i + ", "; } }
}
Developer | Mei Weng Brough-Smyth |
Username | melatonind |
Uploaded | November 06, 2022 |
Rating | 3 |
Size | 2,341 Kb |
Views | 18,216 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Word of the Day | 1,635 Kb |
Junk | 1,439 Kb |
Random Array | 1,551 Kb |
Hacker News 2 | 2,135 Kb |
A Pen by Mei Weng Brough-Smyth | 2,429 Kb |
Words to Colours | 2,363 Kb |
Twitch Follower | 2,345 Kb |
Array Amalgam | 1,502 Kb |
Simple Linear Regression with Editable Table | 3,264 Kb |
Hacker News | 2,844 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Responsive Menu I | Rodericksandoval | 3,045 Kb |
Coburg Banks SVG Logo | Mjtweaver | 3,875 Kb |
HTML5 Breakout | Jaysalvat | 4,873 Kb |
3D flipping card | Ssaakkaa | 2,238 Kb |
Break Out | AzazelN28 | 12,431 Kb |
AngularJS Animated Todo List | Ehaase | 2,975 Kb |
Iron Man SVG Loading Animation | Andythayer | 3,069 Kb |
RSW | JordanC | 3,726 Kb |
RollOver Effect 2 | Lmack90 | 2,162 Kb |
Myprofile | SoufianeAbid | 2,451 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!