[Tutor] [SPAM] A fun puzzle
Jeff Johnson
jeff at san-dc.com
Thu Aug 23 05:46:46 CEST 2007
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] 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
jeff at san-dc.com
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4232 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070822/b1cb43e2/attachment.bin
More information about the Tutor
mailing list