LoginSignup
1
0

More than 5 years have passed since last update.

素数のときにJoJo - CoffeeScript -

Last updated at Posted at 2012-08-11

自分も CoffeeScript で作って見ました.

jojo_prime.coffee
isPrime = (x) ->
  return false if x < 2
  return true if x == 2
  return false if x % 2 == 0
  for i in [3..(Math.sqrt x)] by 2
    return false if x % i == 0
  true

for i in [1..100]
  console.log (if isPrime i then 'JOJO!' else i)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0