lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Jul 5, 2021 at 9:53 PM Michal Kottman wrote:
On Sun, Jul 4, 2021, 14:21 Egor Skriptunoff wrote:
Problem #3
Hide a string of arbitrary length into an existing table without modifying its original content.
In other words, write functions hide(tab, str) and str=unhide(tab).
A user may assign non-nil values to existing keys of the table between hide() and unhide() invocations.

I may be misunderstanding the problem, but based on how I understand the constraints:

local secret_key={}
function hide(tab, str) tab[secret_key]=str end
function unhide(tab) return tab[secret_key] end

This does not "modify its original content".

This adds an additional key-value pair visible with pairs()
So, it can break some code (for example, a code might rely on every key being a string).

"without modifying its original content" should be replaced with "without modifying its content"