[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [FUN] A bit of code golfing
- From: Egor Skriptunoff <egor.skriptunoff@...>
- Date: Thu, 29 Sep 2016 00:20:12 +0300
I have a small programming problem for you to solve, just for fun.
Your task is to implement string-based function NVL(x,y) in Lua.
Both arguments of NVL are always strings.
NVL returns its first argument if it is not empty string, otherwise it returns its second argument.
assert(NVL("Hello", "World") == "Hello")
assert(NVL("", "Lua") == "Lua")
An example of implementation:
function NVL(x,y)return x==""and y or x end
The length of source code of this implementation is 43 bytes.
Your task is to fit your implementation in smaller size.
NVL seems to be a simple stupid function, but nevertheless it can be optimized.
I have two different solutions: 42 and 41 bytes. Try to find either of them.