# Stay away from zero

Given a non-negative integer n, output 1 if n is 0, and output the value of n otherwise.

# Input

A non-negative integer.

# Testcases

input output
0      1
1      1
2      2
3      3
4      4
5      5
6      6
7      7


# Scoring

This is , so shortest answer in bytes wins.

Standard loopholes apply.

• You should probably put a link to the TNB CMC, since that's where this challenge came from. Commented May 3, 2017 at 20:53
• Does the answer need to be a full function, or can it be the body? Commented May 3, 2017 at 20:58
• @CalebKleveter The default rule in PPCG is that the answer is either a function or a full program, but not snippets. Commented May 4, 2017 at 1:56
• Can we print the output with a leading zero? Commented Dec 26, 2017 at 21:54
• @MDXF yes, you can. Commented Dec 26, 2017 at 22:30

# Pyt, 3 bytes

1←↑


Try it online!

1       push 1
←      get input
↑     get maximum value on the stack; implicit print


# Python, 15 Bytes

lambda x:x or 1


Thanks for choosing a falsey value to avoid!

Try it online!

# Desmoslang, 14 13 Bytes

IS+1-\sgn(DOT


Old:

ISE\{D=0,D\}OT


# Lua, 24 bytes

print(0<0+...and...or 1)


Try it online!

# Python 3, 21 bytes

lambda n:{n:n,0:1}[n]


Try it online!

Also note that {0:1,n:n} doesn't work because if n is 0 the n:n overrides 0:1

# Gema, 5 characters

\A0=1


Sample run:

bash-5.2$gema '\A0=1' <<< '0' 1 bash-5.2$ gema '\A0=1' <<< '10'
10


var f={max(1,$0)}  Taking advantage of the "non-negative" rule here. # Easyfuck, 5 bytes Solution: +$":'


Explanation:

+ increments the cell at the pointer
\$ copies cell at the pointer into storage
" takes in an 8 bit integer
: puts max(current cell, storage) into the current cell
' outputs an 8 bit integer


## Excel VBA 17 bytes

[a1]=IIF(n=0,1,n)


Simple if else statement you can run it from vba immediate window

• Hey, just a note on convention with VBA and Excel VBA for PPCG - you must take input from either a cell or from a passed variable. You can output to the immediate window, msgbox, function value, to a cell or by modifying a passed variable. This means that your above solution is not valid as it does not take input from cell or a passed variable, but rather relies on the variable being passed to it. Commented Jun 14, 2017 at 20:29
• Save two bytes and make it a valid answer with ?-([A1]=0)+[A1] Commented Aug 7, 2017 at 14:00

# JS ES5, 26 bytes

function (n){return n?n:1}

• Save one byte by removing the space after function. Commented Aug 6, 2017 at 0:30
• n||1
– l4m2
Commented Dec 18, 2017 at 20:42
• I think you can also write this as function(n)n||1 (taking the n||1 idea from l4m2) Commented Jan 5, 2018 at 15:15