Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Julia, 46 bytes

n=int(ARGS[1]);show(sum([n%i==0for i=1:n])==2)

An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show. Primality is checked using trial division with the same formulation as my R answermy R answer.

Note that the builtin function isprime uses the Miller-Rabin algorithm, which is probabilistic and is thus unsuitable for this challenge. (Thanks to Martin Büttner for pointing that out.)

Saved 4 bytes thanks to kvill.

Julia, 46 bytes

n=int(ARGS[1]);show(sum([n%i==0for i=1:n])==2)

An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show. Primality is checked using trial division with the same formulation as my R answer.

Note that the builtin function isprime uses the Miller-Rabin algorithm, which is probabilistic and is thus unsuitable for this challenge. (Thanks to Martin Büttner for pointing that out.)

Saved 4 bytes thanks to kvill.

Julia, 46 bytes

n=int(ARGS[1]);show(sum([n%i==0for i=1:n])==2)

An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show. Primality is checked using trial division with the same formulation as my R answer.

Note that the builtin function isprime uses the Miller-Rabin algorithm, which is probabilistic and is thus unsuitable for this challenge. (Thanks to Martin Büttner for pointing that out.)

Saved 4 bytes thanks to kvill.

added 285 characters in body
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 31 2746 bytes

show(isprime(intn=int(ARGS[1]);show(sum([n%i==0for i=1:n])==2)

This uses the builtin isprime to check primality. An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show. Primality is checked using trial division with the same formulation as my R answer.

Note that the builtin function isprime uses the Miller-Rabin algorithm, which is probabilistic and is thus unsuitable for this challenge. (Thanks to Martin Büttner for pointing that out.)

Saved 4 bytes thanks to kvill.

Julia, 31 27 bytes

show(isprime(int(ARGS[1])))

This uses the builtin isprime to check primality. An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show.

Saved 4 bytes thanks to kvill.

Julia, 46 bytes

n=int(ARGS[1]);show(sum([n%i==0for i=1:n])==2)

An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show. Primality is checked using trial division with the same formulation as my R answer.

Note that the builtin function isprime uses the Miller-Rabin algorithm, which is probabilistic and is thus unsuitable for this challenge. (Thanks to Martin Büttner for pointing that out.)

Saved 4 bytes thanks to kvill.

deleted 2 characters in body
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 31 2827 bytes

printshow(isprime(int(ARGS[1])))

This uses the builtin isprime to check primality. An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using printshow.

Saved 34 bytes thanks to kvill.

Julia, 31 28 bytes

print(isprime(int(ARGS[1])))

This uses the builtin isprime to check primality. An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using print.

Saved 3 bytes thanks to kvill.

Julia, 31 27 bytes

show(isprime(int(ARGS[1])))

This uses the builtin isprime to check primality. An integer is read as the first command line argument using int(ARGS[1]) and the result is printed to STDOUT using show.

Saved 4 bytes thanks to kvill.

added 62 characters in body
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119
Loading
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119
Loading