The story is of how Edsger Dijkstra and Jaap Zonneveld agreed to stop shaving until they had completed the implementation of X-1 Algol compiler is well documented. However, their underlying reason for doing so is not quite as well known. Here Dijkstra himself explains it in a letter addressed to Maarten van Emden:
We were to implement with five of us: Aad van Wijngaarden, Jaap Zonneveld, Joke Feringa, Freek Barning, and myself. Feringa and Barning left quite soon. Van Wijngaarden did not contribute — on the contrary! — but pretended otherwise to the outside world. I had been warned by Bram Loopstra and Carel Scholten [hardware designers formerly at the Mathematical Centre] that the little chief was not adverse to showing off other peoples’ work as his own. I was not in the mood to let that happen to me. At that time Jaap, van W. and I were clean-shaven; Jaap had a moustache. To make clear that the two of us were doing the work, Jaap and I decided not to shave until the implementation worked, being convinced that van W. would not follow us in this. In this way we made it clear who was responsible for the Algol compiler. Thus it happened; that was around Pentecost [a European holiday six weeks after Easter]. In August the system worked. Jaap got rid of his moustache and beard soon after; I retained them.
So the beards were their way of making sure that their boss didn't cheat them out of the credit for writing the the compiler!
For those who are interested, a description and listing of the Dijkstra-Zonnefeld compiler can be found here: F.E.J. Kruseman Aretz, The Dijkstra–Zonneveld ALGOL 60 compiler for the Electrologica X1, Note SEN-N0301 June 30, 2003