paying with cash is too complicated, so please work out change for me in either python, rust, lua, or bash.

you get a target N and two lists (really multisets) of denominations, always positive integers. the first is the money you have and the second is the money the vendor has. just return a subset of each input such that the money you give minus the change you get back equals N. that's all. if it's impossible, don't worry about it.

Lua: a function entry that takes a number and two arrays of numbers and returns two arrays of numbers

Bash: a function entry that takes a numeric string followed by 4 namerefs to arrays of numeric strings. the first two are mine and theirs, and the other two are corresponding outparams.

defentry(n,x,y):# put all the money in a big pile # solve itl=x+y;p=n+sum(y);r=[];o=y[:];[l.remove(e:=__import__("random").choice(l))or(o.remove(e)ifeinoelser.append(e))or(p:=p-e)for_initer(lambda:p>0,False)];returnentry(n,x,y)ifpelse(r,o)# burn itdell[:]# return ashesreturnl,l

Olive¶:3

LyricLyreplying to¶Olivehi

## post a comment