Question: import numpy as np np . random.seed ( 0 xDECAFBAD ) #set inital values time = np . arange ( 0 , 1 1 )

import numpy as np
np.random.seed(0xDECAFBAD)
#set inital values
time = np.arange(0,11)
def position(N,l,p):
vmax =5
v = np.zeros(N,dtype='int')
x = np.arange(N,dtype='int')
for t in time:
road =['.']*l
r = np.random.rand(N)
for i in range(N):
road[x[i]]= str(v[i])
#gap calc
gap0=(x[(i+1)%N]-x[i]-1)%l
print(gap0)
if v[i]> gap0:
v[i]= gap0
#acceleration
if v[i]< vmax and v[i]< gap0:
v[i]+=1
#randomisation
if r[i]< p and v[i]>0:
v[i]-=1
#updates position
x[i]=(x[i]+ v[i])%l
print(t,road)
position(2,10,0.6) how to fix this code the gap calc isnt working properly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!