The Task
Create a function/subroutine which returns 1. You can make it as elaborate as you like, as long as it returns 1.
The Rules
The entry with the most upvote wins - just like any popularity contest. Good luck!
Perl
sub add # I'm very bad at math, I think 1 is the additive identity.
{
my ($a, $b) = @_;
if ($a==1)
{return $b;}
if ($b==1)
{return $a;}
return $a+$b;
}
print(&add(1,1));# prints 1+1:)
function returnOne(){return Math.log(Math.log(Math.log(Math.log(Math.round((Math.log(!![].join()^{}-({}=={})|(0x00|0x11111)-(0x111111&0x10111))/Math.log(2))/(Math.tan(Math.PI/4)*Math.tan(1.48765509)))+(0xFFFF))/Math.log(2))/Math.log(2))/Math.log(2))/Math.log(2)}
#include <setjmp.h>
int main(int argc, char **argv) {
jmp_buf env;
return setjmp(env) || (longjmp(env, 0), 0);
}
return true;
I don't know if this really counts, but when you print true
in C++, it prints 1.
(: '1 (\ 1 '1))
In Zozotez 1
is just a symbol so here I set 1 to be the anonymous function that has a list argument called 1
which is not used since I'm returning the symbol 1
. You can run it like this in a REPL:
(1 '2 '3 (p 'hello)) ; ==> 1 (prints hello)
A full program needs to be one expression so you wrap it in a lambda:
;; using set (:)
((\ ()
(: '1 (\ 1 '1))
(p (1 '2 '3 (p 'hello))))))
;; using bind
((\ (1)
(p (1 '2 '3 (p 'hello))))
(\ 1 '1))
Eg. (using bind)
%> echo "((\ (1) (p (1 '2 '3 (p 'hello)))) (\ 1 '1))" | bf zozotez.bf
hello
1
In scheme it's the same as this:
(define I (lambda I '1)) ; switch 1 with I some places to make it legal
(I 2 3 (display 'hello)) ; ==> 1 (prints hello)
Not sure how it works, but it seems legit.
long long int g(unsigned int i, unsigned int *j){
if (!j) { j = &i; i++; }
return i?(&i-j) + g(i-1,&i):0;
}
long long int one(unsigned int i) {
i|=1;
return g(i,NULL)/g(1,NULL)/i;
}
C 209
Euler's formula
#include <stdio.h>
#include <math.h>
int e(char i, double pi)
{
float z = ((cos(pi)) + (i)* sin(pi));
return (int)z;
}
int main()
{
char i = 'i';
double pi = 2*acos(0);
return -1 * e(i, pi);
}
C#
public static int return_1()
{
Random rng = new Random(new Random(12345).Next());
int x = rng.Next();
while (x < 1 || x > 1)
{
x = calc(((z, y) => z - y), x, rng.Next());
}
return x;
}
public static int calc(Func<int, int, int> f, int x, int y)
{
return f(x, y);
}
If you wait long enough it will return 1 ;)
Real coders are functional programmers; thus real coders never use integers; they rather use functions instead. Fortunately Alonzo Church gave a functional construction of integers. See here or here. Thus you have to define one
as:
(define one
(lambda (f) (lambda (x) (f x))))
And then you can return one
.
:)
\$\endgroup\$