'''Scene:
One truck broke the traffic rules, run away after colliding. Three witnesses at the scene witness the incident,
but they didn't remember the car number. Only noted some characteristics of the car number.
A said: the first two digits of the license plate are the same
B Said: the last last digits of the license plate are the same.
C is a mathematician, who said the car number of four digits is just the square of integer
According to the above clues to find out the car number
'''# the first two digits is xx# the last two digits is yy# the four digits is 1000*x+100*x+10*y+y = iimport time
# add timer to calculate the performance# Basic performance###############################################################
start = time.time()for x inrange(10):for y inrange(10):if x!=y:
i =1000*x+100*x+10*y+y
# if number<30, its square will smaller than 4 digits# if number>100, its square will bigger than 4 digitsfor temp inrange(31,100):if temp*temp == i:print("The car number is : ", i)
end = time.time()print("The Runtime is {0}".format((end-start)))# Better performance###############################################################
start = time.time()
flog =0for x inrange(10):if flog:breakfor y inrange(10):if flog:breakif x!=y:
i =1000*x+100*x+10*y+y
# if number<30, its square will smaller than 4 digits# if number>100, its square will bigger than 4 digitsfor temp inrange(31,100):if temp*temp == i:print("The car number is : ", i)
flog =1break
end = time.time()print("The Runtime is {0}".format((end-start)))
Output
The car number is:7744
The Runtime is0.0010006427764892578
The car number is:7744
The Runtime is0.0009949207305908203