How to Sphere Pack

Hey,

I have been trying to figure out how to pack spheres into a cylinder for a couple days now and have gotten pretty much nowhere! Does anyone know or would be willing to post their script on how they sphere pack? 

Thank you so much!