[challenge] Largest prime palindrome 06-02-2015, 01:44 PM
#1
Woo! More math challenges!
The purpose of this challenge is to find the largest prime palindrome under 1000.
By prime I mean, well, prime. By palindromic, I mean the number must be the same forwards and backwards.
Rules:
-No imports (at all. I didn't even use require 'prime')
-No more than one semicolon per line
-Under 4 lines for a 15 NSP prize
(btw, this one's a pain in the fucking ass to do from scratch)
The purpose of this challenge is to find the largest prime palindrome under 1000.
By prime I mean, well, prime. By palindromic, I mean the number must be the same forwards and backwards.
Rules:
-No imports (at all. I didn't even use require 'prime')
-No more than one semicolon per line
-Under 4 lines for a 15 NSP prize
(btw, this one's a pain in the fucking ass to do from scratch)
Spoiler: My Solution (Ruby):
4 lines
Code:
def is_prime?(n); (2..n/2).none?{|i| n % i == 0} end
def is_palindrome?(n); n == n.to_s.reverse.to_i end
1.upto(1000) { |n| is_prime?(n) && is_palindrome?(n) ? $val = n : nil }
puts $valIt's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.
















![[+]](https://sinister.li/images/modern/collapse_collapsed.png)






![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)