Lazy Evaluation

  • + 0 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)

    if(palidrom?(number) && prime?(number))
    i+=1
    arr.push(number)
    end
    number+=1
    

    end print arr