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.
- Prepare
- Ruby
- Methods
- Lazy Evaluation
- Discussions
Lazy Evaluation
Lazy Evaluation
Sort by
recency
|
54 Discussions
|
Please Login in order to post a comment
The key take of Test case 3 is the order of checking if prime and palindrome.
It's quite clever to check the less complex operation first
**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
More elegant solution:
Here is Lazy evaluation problem solution - https://www.gyangav.com/2022/10/hackerrank-lazy-evaluation-problem-solution.html