Forums - Open Redstone Engineers
python 1 line primechecker - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: python 1 line primechecker (/thread-5016.html)



python 1 line primechecker - Apuly - 11-06-2014

After some fucking around with python, I've been able to make a function that checks if a number is a prime number using only 1 line of code.

Code:
def prime(number): return not any(number % i == 0 for i in range(2,int(number**0.5)+1))

I like it. Its nice. Yay for python.


RE: python 1 line primechecker - AFtExploision - 11-06-2014

make it a lambda now


RE: python 1 line primechecker - Apuly - 11-06-2014

Gonna need to look into lambda in that case


RE: python 1 line primechecker - Apuly - 11-09-2014

Well that wasn't very hard.

Code:
lambda number: not any(number % i == 0 for i in range(2,int(number**0.5)+1))