The function
f ( x , y , z ) = x x y + x y z
for all positive integers. What is the length of the longest chain of consecutive 0's in the simplified form of
f ( 4 , 5 , 6 )
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
How many hours were used for computation?
Mathematica Code
1 2 3 4 5 6 |
|
It takes 0.02 sec
how i solved it,
1 2 3 4 5 6 7 8 |
|
Ruby Code:
def f(x,y,z)
return x**(x**y) + x**(y**z)
end
a = f(4,5,6).to_s.split(/[^0]/) - [""] #return array containing only strings of 0s.
z = 0
a.each { |zeros| z = zeros.size if zeros.size > z}
Additional problem: What digit therefore has the longest chain?
Answer: Digit 1 (length of longest chain is 4)
Mathematica Code
1 2 3 4 5 |
|
Using Python code as follows:
f = x**(x**y)+x**(y**z)
s = str(f)
n = 0
m = 0
z = 'N'
for i in range(len(s)):
if int(s[i])==0:
m+= 1
z = 'Y'
elif int(s[i]) > 0 and z == 'Y':
if m > n:
n = m
print m, n
m = 0
z = 'N'
Problem Loading...
Note Loading...
Set Loading...
Python Code
The program first converts (f(4,5,6)) into a string. It then goes through each digit one at a time until it finds a zero. If the zero is the first of a continuous sub sequence of zeros,the program activates another loop and counts the size of the sub-sequence and checks if it is the longest sub-sequence found so far.