Skip to main content
Share Your Experience: Take the 2024 Developer Survey
31 votes

Write a function

x86 / x64 machine code, 1 byte c3 Assembly: ret Try it online! (nasm) ¯\_(ツ)_/¯
negative seven's user avatar
22 votes

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] ...
orlp's user avatar
  • 39.1k
22 votes

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 ...
Nick Kennedy's user avatar
  • 21.1k
14 votes

Write a function

Javascript, 6 bytes f=_=>0 Includes variable assignment. Not much to see here.
recursive's user avatar
  • 10.4k
10 votes

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 ...
Giuseppe's user avatar
  • 28.6k
10 votes

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 ...
Robin Ryder's user avatar
  • 15.6k
10 votes

Write a function

Haskell, 3 bytes o=9 This code defines a polymorphic function called o which takes one type parameter and one typeclass ...
Tanner Swett's user avatar
9 votes

Write a function

Python 3, 9 bytes def f():1 Try it online!
Dat's user avatar
  • 927
8 votes

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 ...
ETHproductions's user avatar
8 votes

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 ...
Neil's user avatar
  • 171k
8 votes

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 ...
Robin Ryder's user avatar
  • 15.6k
8 votes

Increment, decrement, undo, peek

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

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 ...
xnor's user avatar
  • 145k
7 votes

Arbitrary Length Hashing

Haskell, 91 90 86 bytes -1 byte thanks to Laikoni -4 bytes thanks to xnor ...
Delfad0r's user avatar
  • 6,266
7 votes

Arbitrary Length Hashing

R, 159 154 bytes ...
Giuseppe's user avatar
  • 28.6k
6 votes

Black Box Trigonometry

Perl 6, 75 bytes ->&f {([X~] ("","a"),<sin cos tan>,("","h")).min({abs(f(2i)-&::($_)(2i))})} Try it online! As it happens, all twelve of the ...
Sean's user avatar
  • 7,936
6 votes

Compute the most efficient binary function

Wow! I actually managed to make an efficient computation algorithm. I did not expect this at first. The solution is quite elegant. It repeatedly deduces more and more, then recurses all the way down ...
orlp's user avatar
  • 39.1k
6 votes
Accepted

Compute the most efficient binary function

Haskell, 110 bytes f q=head[i|let c=[(-1,0)]:[[(f a,f b)|n<-[0..k],a<-c!!n,b<-c!!(k-n)]|k<-[0..]],(p,i)<-zip(concat c)[0..],p==q] The argument ...
halfflat's user avatar
  • 261
6 votes

Black Box Trigonometry

C (gcc), 178 172 bytes ...
LambdaBeta's user avatar
  • 2,759
6 votes

Black Box Trigonometry

Python 3.6.5 on Linux, 90 85 bytes h=hash;lambda f:h(f(.0869))%3%2*"a"+"tscaionns"[h(f(.14864))%3::3]+h(f(.511))%5%2*"h" This builds upon orlp's answer; but ...
nthistle's user avatar
  • 1,311
6 votes
Accepted

Find the C-factor of a vote

Jelly, 3 bytes ạÆm Try it online! Literally just "absolute difference to mean". ...
hyper-neutrino's user avatar
  • 42.4k
6 votes

Find the C-factor of a vote

APL (Dyalog Unicode), 9 8 5 bytes ≠⌹⊢=⊢ Try it online! Anonymous train. Thanks to @Adám for a byte saved, and thanks to @ngn for 3 bytes! How: ...
J. Sallé's user avatar
  • 3,453
6 votes

Write a function

Perl 6, 5 bytes $!=!* Try it online! Creates a Whatever lambda that returns the boolean not of its parameter, and assigns it to the variable ...
Jo King's user avatar
  • 47.2k
6 votes

Write a function

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

Write a function

Whitespace, 7 bytes Creates a subroutine that returns control to the caller. Explained in context: ...
a stone arachnid's user avatar
6 votes

Write a function

[Wolfram Language (Mathematica)], 1 byte This one is slightly questionable: f Defines f, which can be "called" e.g. by ...
Lukas Lang's user avatar
6 votes

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 ...
Arnauld's user avatar
  • 193k
6 votes

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 ...
Mukundan314's user avatar
6 votes

Increment, decrement, undo, peek

Rust, 603 bytes ...
mousetail's user avatar
  • 12.6k
6 votes

Increment, decrement, undo, peek

Rust, 279 bytes ...
tjjfvi's user avatar
  • 7,350

Only top scored, non community-wiki answers of a minimum length are eligible