We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
**BY USING THIS CODE WE SOLVE THE ABOVE PROBLEM BUT THE THIRD CASE IS NOT COMPLETE **
def prime?(number)
return ary = (2..number-1).collect{|i| i if number%i==0}.compact.length==0
end
def palidrom?(num)
i = 0
num = num.to_s
j = num.length-1
while i<=j
if(num[i]!=num[j])
return false
end
i+=1
j-=1
end
return true
end
arr = []
num = gets.chomp.to_i
i = 0
number = 2
while(i!=num)
if(palidrom?(number) && prime?(number))
i+=1
arr.push(number)
end
number+=1
end
print arr
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lazy Evaluation
You are viewing a single comment's thread. Return to all comments →
**BY USING THIS CODE WE SOLVE THE ABOVE PROBLEM BUT THE THIRD CASE IS NOT COMPLETE ** def prime?(number) return ary = (2..number-1).collect{|i| i if number%i==0}.compact.length==0 end def palidrom?(num) i = 0 num = num.to_s j = num.length-1 while i<=j if(num[i]!=num[j]) return false end i+=1 j-=1 end return true end arr = [] num = gets.chomp.to_i i = 0 number = 2 while(i!=num)
end print arr