You can argue the toss with me all day, it doesn’t matter - you are wrong. It is as simple as that. You cannot distribute or sell your derivative work in any way other than that already granted by the license of the original product.
You cannot use someone else’s code and there are numerous precedents for this. Tutorial code is subject to copyright (though most tutorial authors generally waive their rights to it if you want to sell a product using it, I’m pretty sure they would take offence if you start selling the code itself). A line of code is not a mathematical formula, that precedent does not apply. Small sections of code can (and frequently are) formally protected, and even authors who come to the same solution independently can come under fire (see Carmack’s Reverse).
The relevant legislation in the US is under Title 17 in the US Code. It is a long and painful document, however it state quite clearly that “a set of statements or instructions to be used directly or indirectly in a computer in order to bring about a certain result.” is subject to protection. Similar legislation also exists in the EU and a large number of other territories.