Hold on, there is a difference between “recreate” and “copy”. Copyright only applies to creative expressions. If the code is trivially “recreated”, it’s not particularly creative.
Copyrighted content can be used without the holder’s permission under “Fair Use”.
Don’t assume all code can be copyrighted. Purely functional expressions are not copyrightable. Code is math.
By the Curry-Howard correspondence no code should be able to be copyrighted since every program is a formal mathematical proof. However judges aren't usually mathematicians with a background in Computing Science so it's of little consequence.
No algorithm should be copyright-able but your expression of that algorithm should. Programming language choice, variable names, comments, code-style, etc are all creative expressions which are relatively independent of the underlying math.