Today on the Internet to read a puzzle:
Solution: A Basket of eggs:
One 1, just take it out.
2, 2, 1 left.
3, 3, take it, just finish it.
4, 4, 1 left.
5, 5, 1.
6, 6, 3 left.
7, 7, take it, just finish it.
8, 8, 1 left.
9, 9, take it, just finish it.
Ask at least how many eggs in the basket
。。。。
So I tried it with Python, and then even came out:
# -*- coding:utf-8 -*-condition= "" "solution: a basket of eggs: 1 1 Take, just finish 2 a 2 to take, also left 1 3 a 3 take, just take 4 4 take, still have 1 a 5 5 Take, still 1 6 6 take, also left 3 7 7 take, just take 8 8 take, There are 1 9 and 9 to take, just take out ask how many eggs in the basket at least the hypothesis y = total number of eggs y / 2 Yu 1 y / 3 = 0 y / 4 Yu 1 y / 5 yu 4 y / 6 Yu 3 y / 7 = 0 y / 8 1    Y / 9 = 0 solution: using Python's exhaustive (while loop), The following conditions are the total number of eggs: y % 2== y % 4 == y % 8 and y % 3== 0 and y % 7 == 0 and y % 9 == 0 and y % 5 == 4 and y % 6 == 3 "" "Print conditiony = 1while (True): if y % 2== y % 4 == y % 8 and y % 3== 0 and y % 7 == 0 and y % 9 == 0 and y % 5 == 4 and y % 6 == 3: print "Total eggs in Basket: %s (a)"%y break y += 1
Results:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/84/wKiom1mBWXWiRrW9AADZmpE0Ll4921.png "title=" Eag.png "alt=" Wkiom1mbwxwirrw9aadzmpe0ll4921.png "/>
This article from "Lonely No Worry" blog, please be sure to keep this source http://jlnetc.blog.51cto.com/10920149/1952960
Python Answers Puzzles