I tried to cheat this exact same way with a test on the the Newton–Raphson method. My program even showed intermediate values so I could show my work.
The professor still got me, I wound up memorizing it because the effort it to write and debug the program.