Num Py Project Euler 4
Num Py Project Euler 4
net
#1. Create 3-digits numbers array a = numpy.arange(100, 1000) numpy.testing.assert_equal(100, a[0]) numpy.testing.assert_equal(999, a[-1]) #2. Create products array numbers = numpy.outer(a, a) numbers = numpy.ravel(numbers) numbers.sort() numpy.testing.assert_equal(810000, len(numbers)) numpy.testing.assert_equal(10000, numbers[0]) numpy.testing.assert_equal(998001, numbers[-1]) #3. Find largest palindromic number for i in xrange(-1, -1 * len(numbers), -1): s = str(numbers[i]) if s == s[::-1]: print s break
Have a Go
Although I am pretty sure this is the right solution, it might be a good idea to check the result. Find out which two 3-digit numbers produce our palindromic number by modifying the code a bit. Try implementing the last step in a NumPy way. If you liked this post and are interested in NumPy check out NumPy Beginners Guide by yours truly.