Skip to content

Instantly share code, notes, and snippets.

View FaradayLab's full-sized avatar

Alex Wilkins FaradayLab

View GitHub Profile
@FaradayLab
FaradayLab / gist:be1069068d143978a6410eb822b457ce
Last active September 25, 2020 19:53 — forked from cescapa/gist:c655e8e0c1558660150f
Checks if a number is prime in a single line of Python
# Correcting exclusion of last factor that needs to be checked
# Micro optimization of code
# Code syntax/format preference changes
# Might as well be able to check any number
# The algorithm builds a list of factors including the number 2 and all odd numbers
# up to the square root of "a", and then checks if any of those numbers divides "a"
# without a remainder - if so then "a" is not prime, else it is
from math import sqrt