I could do it correctly from the get-go. The program just saved me from drudgery many times over. Probably enough times to recoup my time investment to create the program, but in any case I enjoyed coding for its own sake.
I was on pretty good terms with my chemistry teacher, so...maybe? It's been a while, but I don't remember either showing it off or taking pains to keep it secret. To adults, that is; my nerdy friends and I delighted in showing off the cool stuff we did with our calculators.
I vaguely remember thinking that one likely reason shortcuts like mine were not prohibited was because no one in charge suspected that such things were even possible with current technology, or if they were, that a child would be able to exploit it. But as long as I kept to the letter of the rules, I considered myself ethically in the clear.
As a teen in the late 80's I had an HP calculator that I programmed to compute molecular weights given an input string like "H2SO4". It felt like having a secret superpower, especially when I participated in competitive exams. I was a very straightlaced kid and would not have used the program if it such things were explicitly forbidden, but as far as I could tell, they never were.