Is there a way I can programmatically download the latest version of Craft?
In Craft 3:

You can download the latest Craft 3 release in zip or .tar.gz format by going to:

https://craftcms.com/latest.zip
https://craftcms.com/latest.tar.gz


Or since Craft 3 is Composer based, you can modify your composer.json's craftcms/cms line to install the specific version you're looking for.

In Craft 2: 

You can get the latest Craft 2 version in either zip or tar.gz format by going to:

https://craftcms.com/latest-v2.zip
https://craftcms.com/latest-v2.tar.gz