#Python 2, (削除) 174 (削除ここまで) 170
Python 2, (削除) 174 (削除ここまで) 170
#Python 2, (削除) 174 (削除ここまで) 170
Python 2, (削除) 174 (削除ここまで) 170
Thanks @Vioz for finding a shorter way to make D, and proving again that not is usually golfable. And also for writing the explanation.
from random import*
k,t=input() # Takes input in form k,t
D=D [0]*k= [0]*k # Empty array of size k is made for
# performing the simulation.
E=E D+[0]= D+[0] # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = e<1 # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
Thanks @Vioz for finding a shorter way to make D, and proving again that not is usually golfable.
from random import*
k,t=input() # Takes input in form k,t
D= [0]*k # Empty array of size k is made for
# performing the simulation.
E= D+[0] # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = e<1 # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
Thanks @Vioz for finding a shorter way to make D, and proving again that not is usually golfable. And also for writing the explanation.
from random import*
k,t=input() # Takes input in form k,t
D = [0]*k # Empty array of size k is made for
# performing the simulation.
E = D+[0] # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = e<1 # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
#Python 2, 174(削除) 174 (削除ここまで) 170
from random import*
k,t=input()
D=[0]*k
E=[0]*-~kE=D+[0]
def U(x):b=D[x];D[x]=0;return b and-~U(x-1)+U(-~x%k)
for x in[0]*t:r=randint(0,k-1);e=U(r);E[e-1]+=1;D[r]=not e1]+=1;D[r]=e<1
print E[:-1]
Thanks @Vioz for finding a shorter way to make D, and proving again that not is usually golfable.
from random import*
k,t=input() # Takes input in form k,t
D=[0]*kD= [0]*k # Empty array of size k is made for
# performing the simulation.
E=[0]*(k+1)E= D+[0] # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = note<1 e # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
#Python 2, 174
from random import*
k,t=input()
D=[0]*k
E=[0]*-~k
def U(x):b=D[x];D[x]=0;return b and-~U(x-1)+U(-~x%k)
for x in[0]*t:r=randint(0,k-1);e=U(r);E[e-1]+=1;D[r]=not e
print E[:-1]
from random import*
k,t=input() # Takes input in form k,t
D=[0]*k # Empty array of size k is made for
# performing the simulation.
E=[0]*(k+1) # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = not e # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
#Python 2, (削除) 174 (削除ここまで) 170
from random import*
k,t=input()
D=[0]*k
E=D+[0]
def U(x):b=D[x];D[x]=0;return b and-~U(x-1)+U(-~x%k)
for x in[0]*t:r=randint(0,k-1);e=U(r);E[e-1]+=1;D[r]=e<1
print E[:-1]
Thanks @Vioz for finding a shorter way to make D, and proving again that not is usually golfable.
from random import*
k,t=input() # Takes input in form k,t
D= [0]*k # Empty array of size k is made for
# performing the simulation.
E= D+[0] # Empty array of size k+1 is made for
# storing the magnitudes.
def U(x): # Define a function U that takes an int x
b = D[x] # Assign b to the value at x in D
D[x] = 0 # Clear the value at x in D
return b and U(x-1)+1 + U((x+1)%k) # Return the sum of U(x-1)+1 and U((x+1)%k)
# if b is a 1.
for x in[0]*t: # Perform t tests
r=randint(0,k-1) # Generate a random number between 0 and k-1
e=U(r) # Assign e to the value of U(r)
E[e-1]+=1; # Increment the magnitude array at position
# e-1
D[r] = e<1 # Set D[r] to be 1 if no earthquake happened.
print E[:-1] # Print the magnitude list
- 7.9k
- 1
- 26
- 53