euler/crystal/euler.cr

24 lines
438 B
Crystal
Raw Normal View History

# miscellaneous stuff
module Euler
def self.eratosthenes_sieve(n)
sieve = Array.new(n + 1, true)
sieve[0] = false
sieve[1] = false
2.step(to: Math.sqrt(n)) do |i|
if sieve[i]
(i * i).step(to: n, by: i) do |j|
sieve[j] = false
end
end
end
result = sieve.map_with_index { |b, i| b ? i : nil }.compact
end
def self.palindrome?(x)
x.to_s.reverse == x.to_s
end
end