I was actually curious so I typed - waking up and counting numbers, since this is something that happened to me on several occasions in my late teens (Iam 34 now). When I read your story I immediately made a profile to tell you that the way you described it is almost identical to my case.
I would wake in the night in a state of distress or more like severe anxiety, start prancing back and forth between the kitchen and bathroom, as if I had to do something but I didn't know what. Meanwhile my mind seemed like it was counting numbers, what seemed like infinities. It was so much more pronounced than regular counting in your head, so much so that I felt overwhelmed. I guess I finally burned out, because I dont remember when I went back to sleep.
Prior to this the only experience similar to this was when I was even younger, whenever I would run a high fever I would wake up in the night screaming. My body would feel like its in a million pieces, proprioception gone and I wouldn't know where, what was, my arms, head etc.
I've had other experiences such as lucid dreaming or what seemed like an out of body experience while hearing screams but nothing as drastic as above mentioned.
What I am curious about whether or not we share other things in common, from a psychological to physiological stand point. If you care to share then I'll tell you a little about myself. Feel free to do the same, it might paint a better picture as to why our experiences were almost identical.
I had anxiety (still do) and tics when I was a little kid, I eat and write with my left hand but did everything else with my right. I say did because its very easy for me to switch hands and learn to use tools or eat with the other.
I am artistically gifted, could draw from memory and could recall events with very vivid details, even of things when I was an infant. My grades in school were always very good but my behaviour wasn't, most likely due to child abuse on behalf of my mother.
Not only was my memory vivid but also my perception, it seemed crystal clear like I always had a light bulb on above my head, sort of speak.
I've since diminished considerably to the point of vaguely remembering what that felt like. Mainly by drug abuse, depression, and a host of other stressors.
Another thing worth mentioning is that I was never good at making friends. I know I left out a lot more peculiar things about myself but this should be enough to tell you I am a bit different then most people you'll meet
Last but not least, sorry for a very late reply. I hope all is well with you.