it's coded in Python. it uses vectorization with numpy ndarrays
positions_nda += velocities_nda * iterations
In order to find the instant for points of light alignment, it uses minimize from scipy.optimize module,
fromscipy.optimizeimportminimizeimportnumpyasnpfromparseimportparsefilename='input'filepath=f'data/{filename}.plain'positions=[]velocities=[]pattern='position=<{px},{py}> velocity=<{vx},{vy}>'forlineinopen(filepath):result=parse(pattern,line)position=(int(result['px']),int(result['py']))positions.append(position)velocity=(int(result['vx']),int(result['vy']))velocities.append(velocity)positions_nda=np.array(positions)velocities_nda=np.array(velocities)defgen_area(iterations,initial_positions,velocities):positions=initial_positions+velocities*ix_min,y_min=positions.min(axis=0)x_max,y_max=positions.max(axis=0)w=x_max-x_minh=y_max-y_minarea=w*hreturnarea# identify the second that minimizes the dispersion of points
t=minimize(gen_area,0,(positions_nda,velocities_nda))second=int(np.round(t.x))positions_nda+=velocities_nda*seconddefdraw(positions_nda):x_min,y_min=positions_nda.min(axis=0)x_max,y_max=positions_nda.max(axis=0)foryinrange(y_min,y_max+1):line=''forxinrange(x_min,x_max+1):if[x,y]inpositions_nda.tolist():line+='#'else:line+='.'print(line)draw(positions_nda)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
my solution here 😃 thanks for your suggestions
it's coded in Python. it uses vectorization with numpy ndarrays
positions_nda += velocities_nda * iterations
In order to find the instant for points of light alignment, it uses minimize from scipy.optimize module,