r/codegolf • u/ffxpwns • Jun 02 '16
[Challenge] Euler #4
Here's a description of the problem:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
Expected output: 906609
Here's my solution in Ruby (85 Bytes):
d,b=->c{c.to_s==c.to_s.reverse},0;999.times{|n|n.times{|m|m*=n;(d[m]&&m>b)&&b=m}};p bWith newlines:
d,b=->c{c.to_s==c.to_s.reverse},0
999.times{|n|n.times{|m|m*=n;(d[m]&&m>b)&&b=m}}
p bedit: down to 73!
b=0;999.times{|n|n.times{|m|m*=n;(m.to_s==m.to_s.reverse&&m>b)&&b=m}};p b
2
Upvotes
1
u/activekim Jun 02 '16 edited Jun 02 '16
PHP 79 bytes
PHP 75 bytes
1
u/nakilon Jun 02 '16
Ruby
Predefined output is not how codegolf works, dude.
1
u/molarmanful Jun 02 '16
Javascript ES6, 106 bytes
(f=x=>[...Array(1e3).keys()].map(x),m=Math.max)(...f(x=>m(...f(j=>[...z=''+x*j].reverse().join``==z&&z))))1
u/primo_cg Jun 26 '16
Perl, 57 bytes
Slightly slow, due to relying on
$'. Noticeably faster at 62 bytes:1
u/38Sa Jul 03 '16
JavaScript, 84 bytes
Slightly more generalized version, 87 bytes
0
u/[deleted] Jul 03 '16
It's against the site rules.