For two disks to interact, their centers must be exactly 2R apart
so the time of collision is
Now because disks are non-overlapping, the numerator is always non-positive; for the interaction time to be positive, the denominator must be negative.
To decide when the next collision is going to occur, one could
proceed something like the following:
do j=1,N
coltime(j)=bigtime
enddo
do j=1,N-1
delx=x(j+1)-x(j)
delv=v(j+1)-v(j)
dist=2R-(x_{j+1}-x_j})
if (dist .lt. 0.0) then
if (delv .lt. 0.0) then
coltime(j)=dist/delv
colpartner(j)=j+1
endif
endif
enddo
Now sort the collision times and see which particles will collide,
and move molecules
timestep=bigtime
do j=1,N-1
if (coltime(j) .lt. timestep) then
timestep=coltime(j)
k=colpartner(j)
endif
enddo
do j=1,N
coltime(j)=coltime(j)-timestep
x(j)=x(j)+v(j)*timestep
enddo