Re: [FUN] A bit of code golfing
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [FUN] A bit of code golfing
- From: "Soni L." <fakedme@...>
- Date: 2016年9月28日 18:28:21 -0300
On 28/09/16 06:20 PM, Egor Skriptunoff wrote:
Hi!
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.
-- Egor
NVL=load"return...==''and({...})[2]or..."
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.