Skip to main content
added 241 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20

Python 2, 46 65 5252 51 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.
  3. Went down to 51 bytes - Suggestion made by kirbyfan64sos (thanks again!) to remove the space between 1 and and. Apparently if you have a letter that follows a number, a space isn't needed... how weird, but cool!
 

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [40][10]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 1 False In [41][11]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 2 True In [42][12]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 3 True In [43][13]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 4 False In [44][14]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 5 True In [45][15]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 6 False In [46][16]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 7 True In [47][17]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 10 False In [48][18]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 15 False In [49][19]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 17 True In [50][20]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 20 False In [51][21]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 30 False 

Python 2, 46 65 52 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print n!=1 and all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [40]: n=input();print n!=1 and all(n%i for i in range(2,n)) 1 False In [41]: n=input();print n!=1 and all(n%i for i in range(2,n)) 2 True In [42]: n=input();print n!=1 and all(n%i for i in range(2,n)) 3 True In [43]: n=input();print n!=1 and all(n%i for i in range(2,n)) 4 False In [44]: n=input();print n!=1 and all(n%i for i in range(2,n)) 5 True In [45]: n=input();print n!=1 and all(n%i for i in range(2,n)) 6 False In [46]: n=input();print n!=1 and all(n%i for i in range(2,n)) 7 True In [47]: n=input();print n!=1 and all(n%i for i in range(2,n)) 10 False In [48]: n=input();print n!=1 and all(n%i for i in range(2,n)) 15 False In [49]: n=input();print n!=1 and all(n%i for i in range(2,n)) 17 True In [50]: n=input();print n!=1 and all(n%i for i in range(2,n)) 20 False In [51]: n=input();print n!=1 and all(n%i for i in range(2,n)) 30 False 

Python 2, 46 65 52 51 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.
  3. Went down to 51 bytes - Suggestion made by kirbyfan64sos (thanks again!) to remove the space between 1 and and. Apparently if you have a letter that follows a number, a space isn't needed... how weird, but cool!
 

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print n!=1and all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [10]: n=input();print n!=1and all(n%i for i in range(2,n)) 1 False In [11]: n=input();print n!=1and all(n%i for i in range(2,n)) 2 True In [12]: n=input();print n!=1and all(n%i for i in range(2,n)) 3 True In [13]: n=input();print n!=1and all(n%i for i in range(2,n)) 4 False In [14]: n=input();print n!=1and all(n%i for i in range(2,n)) 5 True In [15]: n=input();print n!=1and all(n%i for i in range(2,n)) 6 False In [16]: n=input();print n!=1and all(n%i for i in range(2,n)) 7 True In [17]: n=input();print n!=1and all(n%i for i in range(2,n)) 10 False In [18]: n=input();print n!=1and all(n%i for i in range(2,n)) 15 False In [19]: n=input();print n!=1and all(n%i for i in range(2,n)) 17 True In [20]: n=input();print n!=1and all(n%i for i in range(2,n)) 20 False In [21]: n=input();print n!=1and all(n%i for i in range(2,n)) 30 False 
added 186 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20

Python 2, 46 65 52 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [30][40]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 1 TrueFalse In [31][41]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 2 True In [32][42]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 3 True In [33][43]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 4 False In [34][44]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 5 True In [35][45]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n)) 6 False In [46]: n=input();print n!=1 and all(n%i for i in range(2,n)) 7 True In [36][47]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 10 False In [37][48]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 15 False In [38][49]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n))) 17 True In [39][50]: n=input();print(n==1 orn!=1 and all(n%i for i in range(2,n)) 20 False In [51]: n=input();print n!=1 and all(n%i for i in range(2,n)) 12030 False 

Python 2, 46 65 52 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print(n==1 or all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [30]: n=input();print(n==1 or all(n%i for i in range(2,n))) 1 True In [31]: n=input();print(n==1 or all(n%i for i in range(2,n))) 2 True In [32]: n=input();print(n==1 or all(n%i for i in range(2,n))) 3 True In [33]: n=input();print(n==1 or all(n%i for i in range(2,n))) 4 False In [34]: n=input();print(n==1 or all(n%i for i in range(2,n))) 5 True In [35]: n=input();print(n==1 or all(n%i for i in range(2,n))) 7 True In [36]: n=input();print(n==1 or all(n%i for i in range(2,n))) 10 False In [37]: n=input();print(n==1 or all(n%i for i in range(2,n))) 15 False In [38]: n=input();print(n==1 or all(n%i for i in range(2,n))) 17 True In [39]: n=input();print(n==1 or all(n%i for i in range(2,n))) 120 False 

Python 2, 46 65 52 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print n!=1 and all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [40]: n=input();print n!=1 and all(n%i for i in range(2,n)) 1 False In [41]: n=input();print n!=1 and all(n%i for i in range(2,n)) 2 True In [42]: n=input();print n!=1 and all(n%i for i in range(2,n)) 3 True In [43]: n=input();print n!=1 and all(n%i for i in range(2,n)) 4 False In [44]: n=input();print n!=1 and all(n%i for i in range(2,n)) 5 True In [45]: n=input();print n!=1 and all(n%i for i in range(2,n)) 6 False In [46]: n=input();print n!=1 and all(n%i for i in range(2,n)) 7 True In [47]: n=input();print n!=1 and all(n%i for i in range(2,n)) 10 False In [48]: n=input();print n!=1 and all(n%i for i in range(2,n)) 15 False In [49]: n=input();print n!=1 and all(n%i for i in range(2,n)) 17 True In [50]: n=input();print n!=1 and all(n%i for i in range(2,n)) 20 False In [51]: n=input();print n!=1 and all(n%i for i in range(2,n)) 30 False 
Post Undeleted by rayryeng
Post Deleted by rayryeng
added 1130 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20

Python 2, 46 6565 52 bytes

Fix made thanks to feersum & Mauris

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

def fn=input(n):print;print(False if n==1 elseor all([n%in%i for i in range(2,n)])) 

Example Runs

I ran this in IPython:

In [31][30]: defn=input();print(n==1 for all(n%i for i in range(2,n):print(False)) 1 True In if[31]: n=input();print(n==1 elseor all([n%in%i for i in range(2,n)])) 2 True In [32]: fn=input(1);print(n==1 or all(n%i for i in range(2,n))) False3 True In [33]: fn=input();print(n==1 or all(n%i for i in range(2,n))) True4 False In [34]: fn=input(3);print(n==1 or all(n%i for i in range(2,n))) 5 True In [35]: fn=input(5);print(n==1 or all(n%i for i in range(2,n))) 7 True In [36]: fn=input(4);print(n==1 or all(n%i for i in range(2,n))) 10 False In [37]: fn=input(6);print(n==1 or all(n%i for i in range(2,n))) 15 False In [38]: fn=input(10) False In;print(n==1 [39]:or fall(13n%i for i in range(2,n))) 17 True In [40][39]: fn=input(15) False In;print(n==1 [41]:or fall(19) True Inn%i [42]:for fi in range(1202,n))) 120 False 

Python 2, 46 65 bytes

Fix made thanks to feersum & Mauris

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

def f(n):print(False if n==1 else all([n%i for i in range(2,n)])) 

Example Runs

I ran this in IPython:

In [31]: def f(n):print(False if n==1 else all([n%i for i in range(2,n)])) In [32]: f(1) False In [33]: f(2) True In [34]: f(3) True In [35]: f(5) True In [36]: f(4) False In [37]: f(6) False In [38]: f(10) False In [39]: f(13) True In [40]: f(15) False In [41]: f(19) True In [42]: f(120) False 

Python 2, 46 65 52 bytes

  1. Went up to 65 bytes - Fix made thanks to feersum & Mauris
  2. Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.

This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.

n=input();print(n==1 or all(n%i for i in range(2,n)) 

Example Runs

I ran this in IPython:

In [30]: n=input();print(n==1 or all(n%i for i in range(2,n))) 1 True In [31]: n=input();print(n==1 or all(n%i for i in range(2,n))) 2 True In [32]: n=input();print(n==1 or all(n%i for i in range(2,n))) 3 True In [33]: n=input();print(n==1 or all(n%i for i in range(2,n))) 4 False In [34]: n=input();print(n==1 or all(n%i for i in range(2,n))) 5 True In [35]: n=input();print(n==1 or all(n%i for i in range(2,n))) 7 True In [36]: n=input();print(n==1 or all(n%i for i in range(2,n))) 10 False In [37]: n=input();print(n==1 or all(n%i for i in range(2,n))) 15 False In [38]: n=input();print(n==1 or all(n%i for i in range(2,n))) 17 True In [39]: n=input();print(n==1 or all(n%i for i in range(2,n))) 120 False 
deleted 4 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20
Loading
added 277 characters in body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20
Loading
Rollback to Revision 1
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20
Loading
edited body
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20
Loading
Source Link
rayryeng
  • 1.6k
  • 1
  • 15
  • 20
Loading