Python code to find all the Narcissus number __python

Source: Internet
Author: User

The number of daffodils is a 3-bit positive integer in which the sum of the 3 powers of the number on each bit is equal to itself. (For example: 1^3 + 5^3+ 3^3 = 153)

The following is a code to find all the number of daffodils: method One:

>>> 
>>> A = List (map (X:x[1], filter (       Range (0)]) print (a) [153, 370, 371, 

407]

Description

The code above can break down three lines of code:

Range (0)]
B = Filter (x:x[0], a)
c = List (map (x:x[1), b)
The first sentence is to use the list to traverse all three digits, each number marked, the Narcissus number is Mark True, not mark false, tag and sum into a single ancestor: (flag, value), all tuples in a list structure.

The second sentence indicates that a tuple marked as true is filtered out.

The third sentence indicates that the second value of the tuple that is filtered out in the first sentence is placed in the list structure.

Add the print statement, and perform the above three code to understand.


method Two: only use list derivation.

I*100+j*10+k = = i**3+j**3+k**3]
>>> Print (a)
[153, 370, 371, 407]


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.