That has all the hall marks of urban legend, but why let the truth get in the way of a great story.
I have said it for a very long time, Gates wasn't innovative in technology but he absolutely innovated in bringing the most ruthless business practices into software.
Feel free to correct the Wikipedia entry (which does not say anything about it being his last contribution though): https://en.wikipedia.org/wiki/DONKEY.BAS
And you may also want to correct this one about the Pancake Sorting algorithm he invented as a student that was not improved for another 30 years: https://en.wikipedia.org/wiki/Pancake_sorting#The_original_p...
It really sounds like an urban legend, but apparently, Bill Gates admits it here himself. Not sure if it was the last piece of code he wrote though: https://web.archive.org/web/20120213015238/http://www.micros...