[RUBY] Google Recruit

A program that outputs the first prime number of 10 consecutive digits of the natural logarithm e.

Body


def prime?(number)
 if (number < 2) return false;
 elsif (number == 2) return true;
 elsif (number % 2 == 0) return false;
 end

 sqrt_num = Math.sqrt(number);
 3.step(sqrt_num,3) do |i|
  if number % i == 0
   return false
  end
 end

 return true
end

def read_exp
 exp = gets.to_s.chomp
end

exp = read_exp()

for i in 0..(exp.length - 10)
 number = exp[i..(i+9)].to_i
 prime = prime?(number)
 if prime 
  puts(number)
  break
 end
end

result


1828182845

Recommended Posts

google recruit
google recruit
google recruit
Google Recruit
Google Recruit
Google Recruit
Google Recruit
EX2: Google Recruit
Google recruit problem, exp and prime
google java format