Even when I was young, I discovered that after a certain level of fatigue my coding became garbage, and after a night's sleep I had to delete it and redo it. After this tipping point, I just stop doing the hard stuff. If I still want to work, I work on routine things that didn't take much concentration.
I never understood how people can write complex code when fatigued. I just get negatively productive trying that.