Skip to content

Instantly share code, notes, and snippets.

@azureSparrowhawk
azureSparrowhawk / main.py
Last active February 8, 2025 16:12
Some code that can find all the prime numbers between any too numbers. May use a lot of memory with bigger numbers because all the prime numbers are stored in a list. One that should use less memory is here: https://gist.github.com/azureSparrowhawk/9e280d75b9ab7356d3ddc29892a0ecaa
from time import time
def isPrime(numberToCheck)->bool:
"""Checks if a number is prime by trying to divide it cleanly by all numbers from to to itself -1"""
if numberToCheck <= 1:
return False
if type(numberToCheck) == float:
return False
def primesUpTo(upperLimit, lowerLimit=0):
@azureSparrowhawk
azureSparrowhawk / main.py
Last active February 7, 2025 12:44
A piece of code that finds all prime numbers in a range. Immediately prints out every prime number once it's found, so this code doesn't(shouldn't) take up too much memory with bigger numbers.
from time import sleep, time
def isPrime(numberToCheck)->bool:
"""Checks if a number is prime by trying to divide it cleanly by all numbers from to to itself -1"""
if numberToCheck <= 1:
return False
if type(numberToCheck) == float:
return False
# noinspection PyArgumentList