How have single-celled organisms learned to survive?
Nothing more than physics

Simple physics

If you drop a rock, the rock will fall to the ground. If there was a table underneath, the rock would stop its fall when reaching the table. Clearly the rock response to the environment but the rock does not need to be conscious (whatever you mean by "consciousness") of anything in order to response to the environment.

Explanations for a programmer

As you are a programmer, you will agree that when you do std::cout &lt;&lt; 3+2 &lt;&lt; std::endl;, nothing more than physics is happening so that the value 5 followed by a newline gets printed to the screen. It is relatively complex though. So complex as it may feel quite magical before having spend many hours learning about computer engineering.

You understand that if you write a, say, boids program, all that is happening is just a bunch of addition and multiplication (eventually a power). The program does not need to be "aware" of what it is doing (nor do the individual agent) in order to respond to the change of behaviour of a predator.

You could even write a self-learning algorithm and you would still accept that there is no consciousness involved but only very simple operations.

Biology

Living things are pretty much the same. They are relatively complex (more like a computer than like a rock) but essentially the same. Also, the response tot he stimulus is often (not always) adaptive as it has been selected. But at it's core there's nothing more than physics involved! 

More info

If you want to learn more about the mechanism of living things in general, you might want to just open an intro book or have a look at an intro course such as Khan Academy > Biology for example.

You can as well pick a simple response to an environmental stimulus and study its mechanism. How about having a look at chemotaxis for example!

Note that you might also want to follow a short and introductory course to evolutionary biology such as Understanding Evolution for example.