> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of R. Alan Monroe > Sent: Wednesday, August 22, 2007 5:41 PM > To: Python Tutorlist > Subject: [SPAM] [Tutor] A fun puzzle > Importance: Low > > I wrote a lame, but working script to solve this in a few minutes. A > fun puzzle. > > http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1- > _2D00_-What-numbers-under-one-million-are-divisible-by-their- > reverse_3F00_.aspx > > > Alan >
Here's mine and it does in fact yield the same six numbers! Since I am
learning Python, these challenges are important to me. I really appreciate
people posting "problems" that we can solve. I enjoy the solutions even
more.
def reverse(n):
rev = 0
while n > 0:
rev = (rev * 10) + (n % 10)
n = n / 10
return rev
def main():
for i in range(1, 1000000):
j = reverse(i)
if (i <> j) and (i % 10 <> 0) and (i % j == 0):
print str(i)
main()
Jeff Johnson
[EMAIL PROTECTED]
623-582-0323
Fax 623-869-0675
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.484 / Virus Database: 269.12.1/965 - Release Date: 8/21/2007
4:02 PM
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
