Share Your Experience: Take the 2024 Developer Survey

# Tag Info

## Hot answers tagged function

### Write a function

x86 / x64 machine code, 1 byte c3 Assembly: ret Try it online! (nasm) ¯\_(ツ)_/¯
• 2,201

### Black Box Trigonometry

Python 3.6.4 on Linux, 99 bytes Bit of a silly answer, but: lambda f:"asinh acos cos cosh atan atanh tan sin asin tanh sinh acosh".split()[hash(f(.029))%19%12] ...
• 39.1k

### Write a function

Jelly, 0 bytes Try it online! A monadic link that returns its argument. Since it is the first function to appear in the script, it can be called using ...
• 21.1k

### Write a function

Javascript, 6 bytes f=_=>0 Includes variable assignment. Not much to see here.
• 10.4k

### Approximate definite integrals using Riemann sums

R, 69 65 63 57 bytes function(a,b,n,k,f,w=(b-a)/n)sum(sapply(a+w*(1:n-k),f))*w Try it online! Takes k=FALSE for right-hand ...
• 28.6k

### Find the C-factor of a vote

R, 23 bytes function(o,v)mean(o!=v) Try it online! The challenge boils down to computing the proportion of values in v ...
• 15.6k

### Write a function

Haskell, 3 bytes o=9 This code defines a polymorphic function called o which takes one type parameter and one typeclass ...
• 947

### Write a function

Python 3, 9 bytes def f():1 Try it online!
• 927

### Half-Exponential Function

JavaScript (ES7), 51 48 bytes Saved 3 bytes thanks to @Arnauld f=i=>i?f[f[q=f(i-1),r=f[i]||q+1]=(i>1)<<i,i]=r:1 Takes in n and outputs the n'th item ...

### Write a function

ZX Spectrum BASIC, 6 bytes DEF FN f()=PI Hex dump: CE 66 28 29 3D A7. CE is a 1-byte ...
• 171k

### Write a function

R, 9 bytes body(t)=0 Try it online! I think this complies with the rules. The function t takes no input and outputs ...
• 15.6k

### Increment, decrement, undo, peek

Wolfram Language (Mathematica), 54 35 bytes Hold[1~#0~##,#0[-1,##],#0@##2,+##]& Try it online! Returns ...
• 20.6k

### Half-Exponential Function

Python 2, 60 bytes d={};a=n=1 while 1:print a;a=d.get(n,a+1);d[1%n*a]=2**n;n+=1 Try it online! Prints forever. Python, 61 bytes ...
• 145k

### Arbitrary Length Hashing

Haskell, 91 90 86 bytes -1 byte thanks to Laikoni -4 bytes thanks to xnor ...
• 6,266

### Arbitrary Length Hashing

R, 159 154 bytes ...
• 28.6k

• 47.2k

### Write a function

C (gcc), 5 bytes Defines a function f that takes no arguments and technically returns an undefined integer value. f(){} Try ...
• 4,637

### Write a function

Whitespace, 7 bytes Creates a subroutine that returns control to the caller. Explained in context: ...
• 3,220

### Write a function

[Wolfram Language (Mathematica)], 1 byte This one is slightly questionable: f Defines f, which can be "called" e.g. by ...
• 231

### Increment, decrement, undo, peek

JavaScript (ES6), 98 bytes f=(k=0,p='' )=>[(g=n=>(0+f).replace(/\S*/,f=(k=${k+n},p="${btoa(f)}"))(1),g(-1),atob(p),"_=>"+k] Try it ...
• 193k

### Increment, decrement, undo, peek

Python REPL, 67 61 59 bytes eval(s:='0,(n:="eval(s:=%r)")%("-~"+s),n%("~-"+s),n%s[2:]') Attempt This Online! Outputs ...
• 12k