text:
Return 1 - Popularity Contest
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!

+1 four downvotes but 13 Answers?, if people are having fun with this question why so many downvotes?

13 answers, but only two of them have garnered any votes. Perhaps this is our version of the emacs vs vi question -- one where everyone has an answer but none of them are particularly better than another.

@anakata, because four (make that six now) people think that this is the kind of question they think would have been better not posted. Some people are against [tag:popularity-contest] on principle, and this is scraping the bottom of that category.

This is one of those places where codegolf fits uneasily into the stackexchange format. Compare the Collatz Conjecture, which is also trending right now. The answers are all pretty mundane (no offense), because it's not a good problem for creative golfing — the naive approach is also the shortest. Whereas in this question, the popularity-contest allows all kinds of interesting answers to a very trivial task. Far more enjoyable to read — but stackexchange is supposed to avoid open-ended stuff like this. Thus the downvotes.

@breadbox Point taken - I will make my challenges more interesting from now :)

in sql-server print '1'

@breadbox You could say this question is the Rube-Goldberg of all questions... ;)

possible duplicate of Most creative way to display 42

Golf Script
1

It took a long time to optimise this code to its most pure, and dare I say it - beautiful form. Such elegance of the language does not come without years of dedicated practice. The program that, without a Zero-Instruction-Set-Computer can literally never be compressed any further. My entire code golf career has been leading to this moment.
I am free. I am alive.
I see the code that underlies the universe.

Can you write a program that only uses a single bit?

@Kevin Only in Minecraft (I've done it before - made a 3x5 px screen and everything).

without a Zero-Instruction-Set-Computer can literally never be compressed any further. Our current computers can easily handle 0 instructions programs. All you need a language that has: "The empty program returns 1" in its specification

C
Two examples, using obscure language features such as “strong return” (return!) and the “approaches” operator (-->):
int foo(void) {
    return! 0;
}

int bar(void) {
    int i=7;
    while (i --> 0);
    return-i;
}

And the special return-i keyword :P

For those who want to learn more on '-->' see this
http://stackoverflow.com/questions/1642028/what-is-the-name-of-this-operator

Brainfuck
+++++++
+++++++
    +++
    +++
    +++
    +++
    +++
++++++++++
++++++++++.

Or if you are not fun at parties:
+++++++[->+++++++<]>.

That looks more like a lowercase l than a 1.

APL
one ← {⍴⍴⍴⍵}

⍴ gives you the dimensions of a vector. The dimension of that is always one-dimensional, so the dimension of that is always one. Or:
"Rho, rho, rho of X
Always equals one,
Rho is dimension; rho rho, rank
APL is fun!"
(I didn't write that verse, it's Stallman's.)

I have learned the Modern Major Generals Song, sung the Money song by Monty Python and Still Alive from Portal... and that is still the nerdiest song that has ever been stuck in my head.
Good find marinus! A good verse Stallman!

The same thing in J: # @: # @: # (Spaces are optional)

Java
public static int funWithOne() {
    try {
        try {
            return funWithOne();
        } finally {
            return funWithOne();
        }
    } catch (Throwable _) {
        return 1;
    }
}

This will call itself 21024 times (this number may vary on different platforms) before finally returning 1. Don't hold your breath, though; it will easily take much longer than the age of the universe.

"This will call itself 2^1024 times" Why? I think its a stack issue. Try to call yourself until you run out of stack, then do it again, and again?

@LegoStormtroopr there's some try finally stuff here that keeps the stack low, but still has a lot of calls

@LegoStormtroopr See this.

Unix Shell (Bourne, POSIX, bash, ksh, csh, …)
expr 0

This prints 0 but returns 1, which may come as a surprise to programmers used to other languages. You can turn off the printed output and see the return code by running expr 0 >/dev/null; echo $?.

I've been bit by this before.  You want to know if a process exists?  $(pidof progname) < 1

Fish
x sends the program counter in a random direction. # is a wall that the program counter "bounces" off. This will literally wander around aimlessly until it finds the "^" and then print 1 and finish.
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxx###xxxxxxxxxxxxxx
xxxxxxxxxx#;#xxxxxxxxxxxxxx
xxxxxxxxxx#n#xxxxxxxxxxxxxx
xxxxxxxxxx#1#xxxxxxxxxxxxxx
xxxxxxxxxx#^#xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx

+1 for both tiring the interpreter and letting other ><> pee in their pants. Lol.

It's nice how this is easily translated into Befunge 98; simply change every x into a ?, every # into a r, n into . and ; into @. However, this ><> program looks better than the equivalent Befunge. Translation shown here: http://ideone.com/ZyuSKk

Maybe I like this too much; here is another Befunge, but this one takes ~4 million operations to finish. I imagine that it can be directly translated into ><> by changing every ? into a x and every # into a ! (should work fine when left the same too) and (of course) . to n and @ to ;. http://ideone.com/gfApjT

@Quincunx looks like it should take about 2^10 tries, with an expected number of operation per try at about 10. This gives me about 2000 operations. Am I missing something?

@Quincunx Nevermind, it's 4^10. Got it. lol. FYI, I'm pretty sure that code can be minimized greatly and still do the same thing.

Java
This is one of my favorite Java specific question.
public static int ret1() {
    try {
        return 0;
    } finally {
        return 1;
    }
}

I don't get it...

Trying to return in a try block instantly fires finally which returns 1 before the other return statement can run.

Returning in a finally block should throw a compile error. I can't think of any legitimate use case for doing it.

In C# it does throw compile error, but in Java it is possible. Of course it doesn't mean it's useful, neither can I think of any legitimate use case

JavaScript
// we all know that OOP == good
function OneManager() {
    // constants == good too
    this.values = {
        ERROR: -1, // value on error
        ONE: 1 // desired value
    }
    this.value = this.values.ERROR // set the value to ERROR
    this.setValue = function(num) {
        if (typeof num !== "number") throw new Error('cannot set value to non-number')
        if (!this.value) this.value = this.values.ERROR // oh noes
        else this.value = num
    }
}
// initialize the one
OneManager.prototype.initializeOne = function() {
    this.setValue(this.values.ONE) // set the value to ONE
    return true // return true for success
}
// get the value
OneManager.prototype.getValue = function() {
    if (this.value == this.values.ERROR) { // if the value is ERROR
        throw new Error('value not initialized')
    } else return this.value // return the value
}

function getOne() {
    var m = new OneManager() // make a OneManager
    var success = m.initializeOne() // initialize the value
    if (success) return m.getValue() // return the value
    else  {
        // there was an error in the initialization
        var retVal = m.values.ERROR // we will return an error
        delete m // maybe it's corrupted
        return retVal // return an error
    }
}

alert(getOne())

That's one robust piece of code you got here.

@Kwaio I lost it reading your comment

OO == good or OO === good?

@JoshWillik: Yes. ;-)

JavaScript
function getOne() {
    return -~![];
}

Explanation:

first ![] evaluates to false.
then ~false becomes -1 because false is first casted to 0, and ~0 == -1.
finally, --1 evaluates to 1.

Alternate:
return +!([][~~{}])

Crazy alternate (each line is exactly 80 chars long):
this[693741..toString(36)]('acnuftiao nobcbdaterbaurn +abeba!!be'.replace(/b./g,
function(b){return '{}()'.split('')['aecd'.split('').indexOf(b.charAt(1))]})[''+
'replace'](new RegExp('a'+Array(5).join('(.)'),'g'),(a='$')+'4321'.split([]+[]).
join(a)))

-~{}+[] is another approach.  {}+[] evaluates to 0.

Haskell & The Church of the ADT
data One = One deriving (Eq, Ord, Bounded, Enum, Show, Read)

This defines the one true One. This One is both the type denoting Oneness, and the constructor One, which is itself the nullary function that returns the one true, and only one value of type One, which is, behold, One.
Usage in the ghci REPL:
λ: One                  -- One returns the one true One
One
λ: One == One           -- One is equal to itself, as no others are
True
λ: One < One            -- One is no less than itself
False
λ: minBound :: One      -- One is the least One there is, yet it is all you need
One
λ: maxBound :: One      -- One is as big as the universe of One, it is omnipotent
One
λ: [ One .. One ]       -- One is the beginning, and ending, of all that is One
[One]
λ: show One             -- The textual gospel of One
"One"
λ: read "One" :: One    -- To read the word of One, is to become one with One
One

The full Book of One is now on-line. Loading it gets you both testaments: Computation and Arithmetic. This enables you to explore more truths:
λ: One + One            -- One can only add to its magnificence
One
λ: negate One
*** Exception: One cannot be negated, mortal fool!

λ: One `div` One        -- One is indivisible
One
λ: One `mod` One
*** Exception: Nothing can modulate the power of One

λ: toRational One       -- Ye shall know One as both Numerator and Denominator
1 % 1
λ: toInteger One * 42   -- One multiplies all to wholeness
42
λ: toRational One / 2   -- Even divided, One is on top
1 % 2

Perl
sub ret1 { print $->$= }

(Despite appearances, the function doesn't print anything.)
I know Perl programmers like to say TMTOWTDI, but this is a task for which T really MTOWTDI.

PHP
<?php
function getOne() {
  return 0 + "one" == 0;
}

Edit:
If you prefer a longer one, here's an alternative (it doesn't print anything):
<?php
function getOne() {
    return print('the' + 'integer' + 'between' + 0 and 2);
}

C
float one(void)
{
    const int n = 24; // magic number
    float x = 0.5f;
    float y = x;
    int i;

    for (i = 0; i < n; ++i)
    {
        x *= 0.5f;
        y += x;
    }
    return y;
}

How did you come up with this?

It's the geometric series 1/2 + 1/4 + 1/8 + ... = 1.

and it loops 24 times because float has 24 bits of precision

Groovy
-"""
int getRandomNumber()
{
    return 4;   //chosen by fair dice roll.
                //guaranteed to be random.
}
""".indexOf(4)

Doesn't contain 4

I think i've seen this on xkcd.

Yes, that was the idea :)

Rhetorical Java
You didn't say it had to be an integer 1.
float one_F(){
    return FloatFactoryFactory.getInstance(FloatFactoryFactory.
    defaultInstanceDescriptionString).getFactory(Locale.getLocale
    ("en-US")).createBuilder().setString("1.0").getResult();
}

Source: http://bash.org/?946461

JavaScript (ECMAScript really)
function one() { return Number.length; }

Time for some spec porn.
Section 15.7.3 states that the length property of the Number constructor is 1 (and we know that a constructor is a function object as mentioned in 4.3.4), and that's because section 15.3.5.1 says:

The value of the length property is an integer that indicates the “typical” number of arguments expected by the function. However, the language permits the function to be invoked with some other number of arguments.

…and since the Number constructor's typical number of arguments is 1, the length of Number is 1. So one could say that the length of a number in Javascript is 1.

Tcl
proc return1 {} {
    catch {(5+2-3)/4}
}

Does not work as you might think.
(5+2-3)/4 is not a valid command, so it throws an error (return -code 1), catch returns this number.

Perl
sub one{ $a[@a{@a[%a=map{@$a[@a{$a++=>$a}]+++$#$a+$a=>$a}$a]++}+$a] }

Open wide and say aaaaa.
The creative concept was to nest braces inside brackets inside braces... as deeply as possible, while still returning the desired result, and only using a "one" variable ($a, @a, %a, @$a and $#$a are of course all different variables).
Although this does modify its environment significantly, it will always return 1 on subsequent calls. To get a grasp of what it's doing, you might consider running this code:
use Data::Dump qw(dump);
for (1..8) {
  one();
  dump(@a);
  dump(%a);
  dump(@$a);
}

MATHEMATICA
In my opinion, the most elegant mathematical way to return 1 using Mathematica:
-Exp[I Pi]

The Euler Identity.

Java
public class print {
    public static char getNum() throws Exception{
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        return (char)Splitter.class.getMethod(method).invoke(null);
    }
}
class Splitter{
    public static char print1(){
        return P.getNum();
    }
}
class P{
    public static char getNum(){
        String s = Thread.currentThread().getStackTrace()[P.class.getDeclaredMethods().length].getMethodName();
        return s.charAt(s.length()-P.class.getSimpleName().length());
    }
    public void doNothing(){}
}

Can be adjusted to return any other positive number n by adding the methods printX for X from 1 to n into Splitter. For example, modifying Splitter to
class Splitter{
    public static char print1(){
        return P.getNum();
    }
    public static char print2(){
        return P.getNum();
    }
}

Will return '2', without any other changes necessary. The added methods should, apart from the name, be an exact duplicate of print1.
Uses reflection to get the number of methods in splitter, and call a function with that name. P.getNum, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.
Calling print.getNum() return the character '1'
Edit - modified to use no String/integer/etc literals.

C#
It should depend on hardware architecture:
return IntPtr.Size / (Environment.Is64BitOperatingSystem ? 8 : 4);

WOW!

Javascript 8 bytes
is this simple enough?
(+!~~{})

Returns can only be used in a function. Just saying.

@ӍѲꝆΛҐӍΛПҒЦꝆ fixed ;D

C#
Merging this (controversial) one with the neighboring (controversial) Collatz Conjecture:
public int CollatzOne()
{
    var current = new BigInteger(new Random().Next(1, Int32.MaxValue));
    var history = new[] { new BigInteger(-1), new BigInteger(-1), new BigInteger(-1) };
    do
    {
        history[0] = history[1];
        history[1] = history[2];
        history[2] = current;
        if (current.IsEven)
            current /= 2;
        else
            current = current * 3 + 1;
    } while (current != history[0]);
    return (int)history.Min();
}

Ruby
Abusing the RNG...
Random.new(56417).rand(10000)

Generates a "random" number between 0 and 10000, and because I picked the right seed it just so happens to be 1. ;)
Script I used to find the number:
irb(main):001:0> (1..100000).select{|x|Random.new(x).rand(10000) == 1}
=> [14033, 25845, 35101, 36955, 45334, 56417, 87438, 87460, 99178, 99451]

R
A classic:
TRUE + 0

+  tries to coerce its argument to a common type: here, because of the order of precedence, it coerces to integers. The coercion of TRUE to an integer gives 1.

Would +TRUE not work?

@Griffin  +TRUE happens to give TRUE.

Also FALSE + 1, am I correct?

@Timtech yes you are.

Turing Machine
Single-state Turing machine with B as the blank symbol, computes 1 (= 0.111... in base 2):
q B 1 R q

(This follows Turing's convention of starting with a blank tape, and prefixing '0.' to the generated infinite sequence.)

C
It even includes documentation on its parameters.
    int
  return_1
(x)     int
       x;{
      /*x
     can
    be:
  any
 val
ue.
***/ return
!x?1:x /x;}

But that's a 2!

So? It's fully documented!

Python
one = lambda zero = 0o11: zero > 1 and all(one(zero-1) for l in '1111111111') and 1 or one and zero or one()

one() will call itself 111,111,111 times, each time returning 1, before returning a final value of 1.
You can also specify the number of digits. For example, one(3) will return 1 only 111 times.
I might add an explanation later, but I really don't have time at the moment.

R
NA ^ 0

Any number to the power of 0 is 1.

Deadfish
riot

Ruby
Or any other language:
def one (n=111111)
    i=1
    n.times { |j| i^=j+1 }
    return i
end

Any integer containing only 1's could be used in the loop, except for 1 itself:
[11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111].each { |n| puts one n } # etc..

Java
The Method is at the bottom of the OnesManager class, but you should take a quick look through the other classes first for the full experience.
NotOneException class:
public class NotOneException extends Exception
{
    public NotOneException(String message)
    {
        super(message);
        System.out.println("If there's not one exception, how many are there?");
    }
}

One class:
import java.lang.Math;

import java.util.Random;

import java.math.BigInteger;
import java.math.BigDecimal;

public class One
{
    public int one;
    static boolean amIAwesome = true;
    static Random random = new Random();
    public One()
    {

    }

    One initializeOne()
    {
        if(random.nextInt(3) == 0)
        {
            return initializeOneOne();
        }
        else if(random.nextInt(2) == 0)
        {
            return initializeAOne();
        }
        else
        {
            return initializeASingleOne();
        }
    }

    One initializeOneOne()
    {
        String aOneInDisguise = "" + (int)((int)(Math.PI * Math.E / random.nextDouble()) * Math.pow(3, 3));
        int notYetOne;
        while(aOneInDisguise.length() > BigInteger.ONE.intValue())
        {
            notYetOne = 0;
            for(int i = 0; i < aOneInDisguise.length(); i++)
            {
                notYetOne += Integer.parseInt(aOneInDisguise.substring(i, i + 1));
            }
            aOneInDisguise = "" + notYetOne;
        }
        one = Integer.parseInt(aOneInDisguise) / 9;
        return this;
    }

    One initializeAOne()
    {
        one = (BigDecimal.ONE.intValue() >> 1) ^ 1;
        return this;
    }

    One initializeASingleOne()
    {
        one = 1;
        return this;
    }

    int getOne() throws NotOneException
    {
        try
        {
            return random.nextInt(3) == 0 ? random.nextInt(2) == 0 ? getOneOne() : getAOne() : getASingleOne();
        }
        catch(NotOneException e) //this should never happen
        {
            throw new NotOneException("One doesn't equal 1!");
        }
    }

    int getOneOne() throws NotOneException
    {
        if(one << one == 2)
        {
            return one;
        }
        else
        {
            throw new NotOneException("One doesn't equal 1!");
        }
    }

    int getAOne()
    {
        assert ((1 << 1) >> 1) == one == amIAwesome != (false && (true == ((1 ^ 0) == one)));
        return one;
    }

    int getASingleOne()
    {
        if(new Character((char)(Integer.toString(one).charAt((char)Integer.parseInt("" + one) - 1))).equals('1'))
        {
            return one;
        }
        else
        {
            return 1;
        }
    }
}

OnesManager class:
import java.util.Scanner;

public class OnesManager
{
    static One[] ones;
    static Scanner sc;
    static int choice;
    static One one;

    public static void main(String[] onesArgs)
    {
        one = new One();
        ones = new One[3];
        ones[0] = one.initializeOneOne();
        ones[1] = one.initializeAOne();
        ones[2] = one.initializeASingleOne();
        sc = new Scanner(System.in);

        System.out.print("which One do you want? (0, 1, or 2): ");
        choice = sc.nextInt();
        System.out.println("1");

        try
        {
            returnOne();
        }
        catch(NotOneException e)
        {
            System.out.println("whoops");
        }
    }

    static int returnOne()
    {
        return 1;
    }
}

If we were Golfing, I would lose so bad.

Python
import random
def ret_one():
    i = random.randint(0, ~(-1<<31))
    if i & 1:
        i = i & (i - 1)
    i = ~i & (i + 1)
    return i
print ret_one()

This is using some low-level bit hacks.
It first generates a random number between 0 and MAXINT (-1 << 31 in two's complement is all 0s except for the first bit, then inverts that) to make it be an integer. Then, if the number is odd, it turns off the rightmost bit. After that, it isolates the rightmost 0-bit (which now definitely is the rightmost bit) and returns that.
Another solution:
def ret_one():
    c = 1 + 20.37j
    return int(c.real)
print ret_one()

This makes use of Python's built-in complex number support. The term 1 + 20.37j creates a complex number with 1.0 as its real and 20.37 as its complex part. We then take the real part and turn it into an int.

C
Return that not no error has occured! ;)
#include <stdio.h>
#include <errno.h>

int main(void) {
    return !errno;
}

Bash
false

Yes, this returns 1. Check with
echo $? # 1

Why? Because 0 is the "sucess" return code, everything else is "not success".

C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>

void kill_user_processes(void) {
    kill(-1, 9);
}

// Not guaranteed to work.
void kernel_panic(void) {
    kill(1, 11);
    kill(1, 30);
    kill(1, 15);
    // Last resort
    kill(-1, 9);
}

int main(int argc, char *argv[]) {
    if (geteuid() != 0) {
        puts("It's strongly recommended that you run this program as root for extra "
             "functionality. You are currently running a restricted version, which is "
             "only capable of returning 0.");
        atexit(kill_user_processes);
        sleep(5);
        exit(0);
    } else {
        atexit(kernel_panic);
        sleep(5);
        exit(1);
    }
}

Non-alphanumeric JavaScript
[][(__=''+!!(_=+[]))[_$=-~-~-~_]+($$=''+{})[$=-~_]+($_=''+!_)[$]+$_[_]][$$[-~($+_$)]+$$[$]+(''+$/_)[$]+__[_$]+$_[_]+$_[$]+$_[$+$]+$$[-~($+_$)]+$_[_]+$$[$]+$_[$]](__[$]+__[$+$]+$_[_$]+$_[$]+$_[_]+"("+$+")")()
Explanation:
I'm using loose typing to generate objects and booleans, converting them to strings and using arrays to treat the generated strings as arrays of characters. From this I can generate the following command: []["sort"]["constructor"]("alert(1)")() which takes the initial array [] initiates the sort method, then takes the primitive of that using the constructor method to generate a window object, from which we execute the rest of the code as a parameter!

Python
If it's not against the rules to submit more than one:
one = lambda: 1

or
def one():
    return sum(map(int, str((True is not False).denominator)))

Python
def one(n):
    return reduce(lambda a, b: a^b, xrange(2**n+~(17<<n)^-3))

Returns 1 for any n (n must be a non-negative integer).
Example:
>>> one(7)
1
>>> one(20)
1

Ruby
def absolute_euler
  (Math::E.to_c ** ( Math::PI * "i".to_c )).abs.to_i
end

JavaScript
Why not write what we want?
function to() { return 1; }

to(); // 1

You answered during the 11th hour of the 1st day of August, and at the time of this writing have 1 upvote, 111 reputation and 1 badge.  You would win my vote but that would destroy the beauty of your answer.

@SimonT wow this is dat winner

@SimonT And your comment has one upvote. I must not upset this delicate balance O_o

Javascript
function IfIWont () {
  return +delete myBrowserHistory
}

Javascript
-~window.__proto__.__proto__.__proto__.__proto__

VB6
Dim aVariable As New AClass
Set aVariable = Nothing
MsgBox IIf(aVariable Is Nothing, "0", "1")

Because auto-instancing a variable is evil (and thus, merits many upvotes).

PowerShell
If you can read this, the below script should work for you.
Code
[int]((Invoke-Webrequest http://codegolf.stackexchange.com/a/16006/9387).StatusCode -eq 200)

Walkthrough
Invoke-Webrequest http://... is used to request this answer's page from the web. You could also call this as curl, iwr, or wget, but this isn't code-golf.
.StatusCode gets the HTTP status code that was returned for the request.
-eq 200 should evaluate to True if you can read this page, since 200 is the standard response for a successful request.
[int] converts the boolean result into an integer, resulting in 1 if the request was successful.
Special version for @Gilles
[math]::floor((curl http://codegolf.stackexchange.com/a/16006/9387).StatusCode/111)

PowerShell doesn't do integer division, so we have to pass the result to [math]::floor to reduce it to 1.

Comparison with 200 is disappointingly straightforward. How about (…).StatusCode / 111? I think it looks nicer the unix way: curl -Is http://codegolf.stackexchange.com/a/16006/994 | awk '{exit $2/111}'

@Gilles Better?

Perl
One never finds enough uses for this feature.
$one="i";
for(3,39,13,39,13,39,3,13){for(1..$_){for(1..$_){$one++;++$one;$one++;++$one}}}
die"one"eq$one;

Ruby
So... I decided to go with a Douglas Adams theme. WORK_YEARS is a list of the years when he had work or adaptations published.
WORK_YEARS = [1972, 1975, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1990, 1992, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2005]

def douglas_adams
  sum = 0
  mod = 1

  WORK_YEARS.each do |date|
    sum += date * mod
    mod *= -1
  end

  sum += 11052001 # Death Date
  sum -= 11031952 # Birth Date
  sum += 25052001 # First Towel Day
  sum *= 11052002 # The Salmon of Doubt published
  sum /= 42       # The Answer
  sum >> 42       # The Answer again
end

puts douglas_adams
# => 1

Delphi
This is an easy one =)
function getnumber:integer;
var b:byte;
begin
  b := $ff xor $fe;
  result := round (sin(b*90));
end;

Mathematica
False is generally taken as corresponding to the Boolean value, zero.
Boole[False]

0

But the quotient, False/False, is not undefined (as 0/0 is).
False/False

1

Python
def foo(n):
    l = [i*i for i in range((n-n)+1, 255 * n)]
    return l[0]

Ruby
def from_church(f)
  f(-> x {x.succ})[0]
end

def one
  from_church -> f {-> x {f[x]}}
end

This converts the Church numeral one into the integer one.
Here is another one using the 3x+1 function (and conversion to Church numerals just for fun):
def church(i)
  i.zero? ? -> f {-> x {x}} : -> f {-> x {f[church(i-1)[f][x]]}}
end

def one2
  collatz = -> x {x.even? ? (x / 2) : 3*x + 1}
  church(1132)[collatz][9780657630]
end

C/C++
I give two answers, the first will always work, the second is something I see far too often as a TA and it makes me sick inside
int foo(void)
{
    __asm
    {
        mov eax, 1
    }
}

int bar(int x)
{
    if (!x) return 1;

    bar(x - 1);
}

With the second answer, the return value propagates down through eax.

C & C++
C/C++:
int one(int x)
{
    return 0 < x < 2;
}

C++:
int one()
{
    return 1, not 0 or 2;
}

C#
Let's generate some IL at runtime
void Main()
{
    DynamicMethod return1 = new DynamicMethod("return1", typeof(int), null);
    ILGenerator il = return1.GetILGenerator();
    il.Emit(OpCodes.Ldc_I4_1);
    il.Emit(OpCodes.Ret);

    Func<int> return1Func = (Func<int>)return1.CreateDelegate(typeof(Func<int>));

    int one = return1Func();
}

C with (stupid) pointer arithmetics
int main()
{
    int r = main-main;
    return ++r;
}

Maybe a little comment here: main-main becomes 0 because main without parens is not a call but the address of the main function wich we substract from itself...

Perl
sub notOne {return 1!=one}
print &notOne == 1;
print &notOne

Output:
1
1

This explores the untruthiness that is programming. 1 is Not One and Not One is 1.

Python
def f():
    import math
    o = {0**0, -~0, len(str(0)), math.factorial(0)}.union({int()==float(), 0 is 0, not (), all([0]*0)})
    return (len(o)==min(o)==max(o)) * o.pop()

0s were cheap today :-)
>>> print(f())
1

JavaScript
Shameless Code Golf
(5 characters):
(0,1)

(I guess technically this works too, 3 characters):
(1)

Quomplex
1→A[*A;A%A+A→A]

Set A to 1
While true, output A and store the value of A % A + A in A

Outputs 1 continuously.

So is there a detailed spec or an interpreter or something for that?

@marinus Yes, it is an AMC shell interpreter or something similar.

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:)

https://eval.in/81256
`

Javascript
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)}

C
#include <setjmp.h>

int main(int argc, char **argv) {
    jmp_buf env;
    return setjmp(env) || (longjmp(env, 0), 0);
}

TI-BASIC
:Disp 1&.0&(1

C++
return true;

I don't know if this really counts, but when you print true in C++, it prints 1.

Zozotez
(: '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)

C
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);
}

Scheme (functional answer)
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.

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 ;)

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Who brings the croissants?
This question is inspired by a similar question first asked on StackOverflow by Florian Margaine, then asked in variant forms on CS by Gilles and on Programmers by GlenH7.
This time, it's a code golf, with specific metrics for success!
In an office of ten people, it's someone's turn to buy croissants every morning.  The goal is to produce a schedule that lists whose turn it is on any given day, subject to the following constraints:

Presence.  Each person is away from the office on business or vacation on average ~20% of the time.  Each time you schedule a person who is away, lose one point per person who didn't get to eat croissants.  For simplicity, generate the away-schedule with the random number generator seed = (seed*3877 + 29573) % 139968, starting with 42*(10*i + 1) as the initial (unused) seed, where i is the zero-indexed number of the employee; whenever seed is below 27994, that person will be away.  Note that if everyone is away, you can assign anyone and not lose points.
Fairness.  Each person will keep track of whether they have bought more or fewer croissants than the average.  A person who never buys more than 10 more than the average will give you one point (they understand that someone has to buy first, and they'll of course go above the average).  Otherwise, let k be the farthest above the average that a person has gotten in n days of buying; that person will give you 1 - (k-10)/100 points.  (Yes, this may be negative.)
Randomness.  The employees get bored if they can predict the sequence.  Gain ten times the number of bits of information revealed a typical choice; assume that the employees can search for repetitive patterns and know the order of how long it's been since each of them bought croissants.
Non-repetitiveness.  Employees hate buying croissants two days in a row.  Each time this happens, lose a point.
Brevity.  if b is the number of bytes of the gzipped* version of your solution, reduce your score by b/50.

The solution should be an output of letters or numbers (0-9 or A-J) indicating who should buy croissants on each day.  Run the algorithm for five hundred days (two years of work); give yourself a point if the output is in 10 rows of 50.
You only need to produce the sequence, not calculate the score.  Here is a reference program in Matlab (or Octave) that picks people completely at random except for avoiding people who are away:
function b = away(i)
b=zeros(500,1); seed=42*(10*i+1);
for j=1:500
  seed=mod((seed*3877+29573),139968);
  b(j)=seed<27994;
end
end

A=zeros(500,10);
for i=1:10
  A(:,i)=away(i-1);
end
for i=1:10
  who = zeros(1,50);
  for j=1:50
    k = 50*(i-1)+j;
    who(j)=floor(rand(1,1)*10);
    if (sum(A(k,:)) < 10)
      while (A(k,who(j)+1)==1)
        who(j)=floor(rand(1,1)*10);
      end
    end
  end
  fprintf(1,'%s\n',char(who+'A'));
end

Here is a sample run:
HHEADIBJHCBFBGBIDHFFFHHGGHBEGCDGCIDIAEHEHAJBDFIHFI
JFADGHCGIFHBDFHHJCFDDAEDACJJEDCGCBHGCHGADCHBFICAGA
AJAFBFACJHHBCHDDEBEEDDGJHCCAFDCHBBCGACACFBEJHBEJCI
JJJJJBCCAHBIBDJFFFHCCABIEAGIIDADBEGIEBIIJCHAEFDHEG
HBFDABDEFEBCICFGAGEDBDAIDDJJBAJFFHCGFBGEAICEEEBHAB
AEHAAEEAJDDJHAHGBEGFHJDBEGFJJFBDJGIAJCDCBACHJIJCDF
DIJBHJDADJCFFBGBCCEBEJJBAHFEDABIHHHBDGDBDGDDBDIJEG
GABJCEFIFGJHGAFEBHCADHDHJCBHIFFHHFCBAHCGGCBEJDHFAG
IIGHGCAGDJIGGJFIJGFBAHFCBHCHAJGAJHADEABAABHFEADHJC
CFCEHEDDJCHIHGBDAFEBEJHBIJDEGGDGJFHFGFJAIJHIJHGEBC

which gives a total score of -15.7:
presence:    0    (Nobody scheduled while away)
fairness:    6.6  (~340 croissants bought "unfairly")
randomness: 33.2  (maximum score--uniformly random)
no-repeat: -51.0  (people had to bring twice 51 times)
size:       -5.5  (275 bytes gzipped)
format:      1    (50 wide output)

Here is the reference Scala method I'm using to compute the score
def score(output: String, sz: Either[Int,String], days: Int = 500) = {
  val time = (0 until days)
  def away(i: Int) =
    Iterator.iterate(42*(10*i+1))(x => (x*3877+29573)%139968).map(_<27994)
  val everyone = (0 to 9).toSet
  val aways =
    (0 to 9).map(i => away(i).drop(1).take(days).toArray)
  val here = time.map(j => everyone.filter(i => !aways(i)(j)))
  val who = output.collect{
    case x if x>='0' && x<='9' => x-'0'
    case x if x>='A' && x<='J' => x-'A'
  }.padTo(days,0).to[Vector]
  val bought =
    time.map(j => if (here(j) contains who(j)) here(j).size else 0)
  val last = Iterator.iterate((0 to 10).map(_ -> -1).toMap){ m =>
    val j = 1 + m.map(_._2).max
    if (bought(j)==0) m + (10 -> j) else m + (who(j) -> j)
  }.take(days).toArray

  def log2(d: Double) = math.log(d)/math.log(2)
  def delayEntropy(j0: Int) = {
    val n = (j0 until days).count(j => who(j)==who(j-j0))
    val p = n.toDouble/(days-j0)
    val q = (1-p)/9
    -p*log2(p) - 9*q*log2(q)
  }
  def oldestEntropy = {
    val ages = last.map{ m =>
      val order =  m.filter(_._1<10).toList.sortBy(- _._2)
      order.zipWithIndex.map{ case ((w,_),i) => w -> i }.toMap
    }
    val k = last.indexWhere(_.forall{ case (k,v) => k == 10 || v >= 0 })
    (k until days).map{ j => ages(j)(who(j)) }.
      groupBy(identity).values.map(_.length / (days-k).toDouble).
      map(p => - p * log2(p)).sum
  }

  def presence =
    time.map(j => if (here(j) contains who(j)) 0 else -here(j).size).sum
  def fairness = {
    val ibought = (0 to 9).map{ i =>
      time.map(j => if (i==who(j)) bought(j) else 0).
        scan(0)(_ + _).drop(1)
    }
    val avg = bought.scan(0)(_ + _).drop(1).map(_*0.1)
    val relative = ibought.map(x => (x,avg).zipped.map(_ - _))
    val worst = relative.map(x => math.max(0, x.max-10))
    worst.map(k => 1- k*0.01).sum
  }
  def randomness =
    ((1 to 20).map(delayEntropy) :+ oldestEntropy).min*10
  def norepeat = {
    val actual = (who zip bought).collect{ case (w,b) if b > 0 => w }
    (actual, actual.tail).zipped.map{ (a,b) => if (a==b) -1.0 else 0 }.sum
  }
  def brevity = -(1/50.0)*sz.fold(n => n, { code =>
    val b = code.getBytes
    val ba = new java.io.ByteArrayOutputStream
    val gz = new java.util.zip.GZIPOutputStream(ba)
    gz.write(b, 0, b.length); gz.close
    ba.toByteArray.length + 9 // Very close approximation to gzip size
  })
  def columns =
    if (output.split("\\s+").filter(_.length==50).length == 10) 1.0 else 0

  val s = Seq(presence, fairness, randomness, norepeat, brevity, columns)
  (s.sum, s)
}

(there is a usage note^).
The winner is the one with the highest score!  Actually, there will be two winners: a globally optimizing winner and a short-notice winner for algorithms where earlier selections do not depend vacations that will happen in the future.  (Real office situations are in between these two.)  One entry may of course win both (i.e. it is short-notice but still outperforms other entries).  I'll mark the short-notice winner as the "correct" winner, but will list the globally optimizing winner first on the scoreboard.
Scoreboard:
Who            What                   Score   Short-notice?
============== ====================== ======= ===
primo          python-miniRNG          37.640  Y
Peter          Golfscript-precomputed  36.656  N
Rex            Scala-lottery           36.002  Y
Rex            Matlab-reference       -15.7    Y

*I'm using gzip 1.3.12 with no options; if there are multiple files, I cat them together first.
**A list prepared in advance is not considered short-notice unless it would be swapped out for a better list if an away-day appeared the day before; if this is a major issue (e.g. an unanticipated away day causes reversion to an algorithm that performs horribly) I'll define precise criteria.
^ If you use gzip, pass in the size as Left(287); otherwise if your code is in code (val code="""<paste>""" is useful here), use Right(code))

Items 3 and 5 of the scoring don't seem to be well defined. It's not at all clear (at least without trying to read the scoring code) what entropy is being used for item 3, because item 2 already seems to take care of per-token entropy (albeit in a non-linear fashion). As for item 5: even if gzip is deterministic, the size of the gzipped source will depend on the options and possibly on the version.

@PeterTaylor as for the entropy calculation I'm going to assume the Scala implementation is authoritative in this subject.

@PeterTaylor - Right now I try both n-ary delays and a histogram of the rank order of recency of bringing croissants.  I think that covers all cases that people are liable to notice intuitively.  Note that (2) is maximally satisfied with a fixed rotation pattern, while (3) is maximally not.  I've updated to state the authoritative gzip version (i.e. what I have on the machine I use most).

I've removed the [tag:code-golf] tag because it's only applicable to questions which are judged solely on code length.

@PeterTaylor - Fair enough.  Wasn't entirely clear to me given the tag description.

Your comment that (2) is maximally satisfied with a fixed rotation pattern appears to be incorrect. I've just tested it, and 0123456789...0123456789 scores 9.004 for fairness, whereas I know that it's possible to get 9.57.

@PeterTaylor - You're right; I was forgetting that I was scoring actual numbers of croissants, not turns taken.  So an attendance-aware method is superior.  The highest I've been able to get on any sequence is 9.621.

Python (37.640 points)
i=61
r=[420*n+42for n in range(10)]
for n in r:
 o=''
 for n in r*5:
    r=[(n*3877+29573)%139968for n in r]
    f=[n<27994for n in r]
    l=i
    while~-all(f)*f[i%10]or(i-l)%10<1:i=i**3%1699
    o+=str(i%10)
 print o

The second level of indentation is with literal tab characters.
Score breakdown:
presence:    0.0
fairness:    8.618
randomness:  31.502
no-repeat:   0.0
size:       -3.48
format:      1.0

The PRNG i'm using is a simplified version of Keith Randall's solution to the Diehard challenge, which despite its extreme brevity, passes all 15 tests. The solution is short notice: the absentee list is calculated on the day of, and all previous attendance is forgotten. The only thing which is recorded is who bought on the previous day, so that repetition may be avoided.
I suspect that the fairness score could be improved by keeping a queue of individuals who should have bought, but didn't, and adding them into the rotation as soon as possible. I'm not sure if this would lead to an overall improvement, though, due to a lower score for size.
About the randomness upper-bound, it is certainly higher than 32. Replacing line 7 with i=i**3%1699 (removing the attendance and repetition constraints) results in a randomness score of 32.966.
Update:
Most of the improvement comes from better zip compression, by renaming variables, and reusing constructs such as for n in r numerous times.

It might be possible to do better, but I don't see any strong contenders now.  Nice solution!  By the way the maximum entropy is 10*log2(10)=33.2.

I suspect 38 should be possible, with fairness of about 9.5 and a gzipped score of -4. If a better solution is submitted, you can always just switch the accepted answer ;)

GolfScript (36.656 points)
presence:    0
fairness:    9.498
randomness: 31.778
no-repeat:   0
size:       -5.62*
format:      1

* The Lempel-Ziv step is actually bad for this program: it would only be 5.46 (including the 9-character "penalty" from the Scala code) if strategy HUFFMAN_ONLY where used. (By my Huffman tree calculations, it should be 1839 bits, which suggests that there are 34 bytes of overhead - more than I remember from the last time I read the gzip file format spec, but my memory could be off).
'45274749890953461384092895296161282397696128454780712395638361237579450740141057012045098236468567830463395138297694808909654367173131250582012342078481734627820869476489062315253101230346792585956785940285674601914907495382306749019845658361271737890123953439852610678507814707530469358317402346278901984267190129362162512915678681507567831843423709082970928201432569730525454784512915686709218065814323413439817345681607567947860143456038712392671909236989193072045789650183645701325105856402426275'50/n*

Hahaha, good one.  I think I didn't make the output long enough to actually require a program given that there are no free input parameters.  I'll clarify what I mean by short-notice to indicate that this is not short-notice (because the entire solution is computed in advance; if at day d the away list is perturbed, this solution would not vary, so formally the algorithm depends on the entire future).

The presence score is by far the most important. That can easily be worth -700. fairness is constrained to be between 0 and 10; randomness varies from something like 20 to 32 (I haven't checked your claim that 33.2 is a hard but attainable upper bound); no-repeat can easily deduct 15 if you're not careful; so size isn't really a big issue anyway.

Entirely correct, and I chose these because I think it focuses attention on the interesting part of the solution space.  Fairness can be negative, though, e.g. if you make two people alternate buying the croissants.

My gzip yields 294 bytes for your program, for a score of -5.88, by the way.

Do you mean ZipOutputStream or GZIPOutputStream?  I don't think the latter has strategy hints.

It does, but you have to subclass it to gain access to its protected def field.

Ah.  Well, I just added to the scoring code something that calls default GZIPOutputStream to compute the size, which I will take as canonical.

I found a bug that was crashing my entropy-scoring routine and also caused slightly incorrect results.  It's fixed; in my hands your scores are now (36.48826335753452,List(0.0, 9.621000000000002, 31.64726335753452, 0.0, -5.78, 1.0)).

Scala (36.002 points)
Code (run in REPL):
val (p,d,s)=(0 to 9,0 to 499,Array.fill(10)(0d))
val h=p.map{i=>var s=42*(i*10+1);d.map{_=>s=(s*3877+29573)%139968;s>27993}}
val n=d.map{j=>h.count(_(j))}
var q=0
d.map{j=>val t=s.map(_+util.Random.nextGaussian);t(q)+=9;p.map{i=>if(h(i)(j))t(i)-=9};val k=t.indexWhere(_==t.min);q=k;s(k)+=0.3;k}.mkString.grouped(50).foreach(println)

Example output (for which score was calculated):
71756902145841391934765437292035652843760984098583
86397265015640974915628232730106147281529836713094
08565240287124932136398520876027407943071218763914
50987680167146425903575318020863656749795382985435
07941018246493815719641937560694585402820150738727
13126926431856275181072676938295301345412807480484
81839634956059251426350709373902682797204746548906
16175895303731651486209495295428383160620710851569
74013482373647246513814672019837413985207414790529
39206976935168020524260381937139452108673574826406

Score breakdown:
presence:    0
fairness:    9.094
randomness: 31.448
no-repeat:   0
size:       -5.54
format:      1

Short-notice: yes, here-list h is used on the day of selection only.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Make Me a Sandwich

Challenge: Write a makefile, which would lead to this behavior:
% make me a sandwich
What? Make it yourself
% sudo make me a sandwich
Okay

Rules:

Should work on a Linux machine, where the user isn't root but allowed to use sudo.
Must not say Okay to any shorter make command (e.g. sudo make sandwich).
The second command should work because of sudo, not because it's the second invocation.

Guidelines:

Keep it short (after all, it's a Code Golf site).
It would be nice if it would actually make a sandwich.
Try to cleverly hide why sudo makes a difference.

The winner will be decided by votes.

http://savannah.gnu.org/bugs/?23273

@ardnew, unfortunately, I specifically requested to write a makefile, which, I think, invalidates solutions based on patching make.

totally agree, @ugoren. didnt mean for that comment to dismiss the challenge or suggest a solution

Okay, I'll bite. This doesn't necessarily adhere to guideline #3, but it does a fair job on the other two guidelines. It also cleans up after itself, as any good sandwich-maker should.
.SILENT:

%:%.c
        $(CC) -o $@ $^ && rm -f $^

default:
        echo 'The makings for a sandwich are here.'

a.c:
        echo '#include <stdio.h>' > a.c
        echo 'int main() {' >> a.c
        echo '  char *txt[] = { "What? Make it yourself.", "Okay." };' >> a.c
        echo '  int n = 0;' >> a.c
        echo '  while (getchar() != EOF) n ^= 1;' >> a.c
        echo '  puts(txt[n]); return 0; }' >> a.c

me.c:
        echo '#include <stdio.h>' > me.c
        echo '#include <unistd.h>' >> me.c
        echo 'int main() {' >> me.c
        echo '  char *txt[] = { "/dev/null", "sandwich" };' >> me.c
        echo '  puts(txt[!getuid()]); return 0; }' >> me.c

sandwich:
        ./me | ./a | tee `./me`
        rm -f me a

clean:
        rm -f sandwich

(Less buggy, and hopefully a bit less boring, than my initial submission.)

Looks like it violates rule #2 - sudo make me sandwich.

&& test -e ./a

Argh, you're right. This version should do a better job of observing the rules.

you certainly have the most appropriate name, @breadbox

A fairly compact solution that ignores guideline #2 (127 characters, including some unnecessary whitespace). I follow breadbox's practice of cleaning up after myself. Don't put any other file in the same directory as the makefile! Also, note that the makefile must be called Makefile, other names will not work.
me: ; echo echo Okay >$@
a: ; chmod u=x me
sandwich: ; ./me 2>/dev/null || echo 'What? Make it yourself'; rm -f [!M]*
.SILENT:

Usage:
$ make me a sandwich
What? Make it yourself
$ sudo make me a sandwich
Okay
$ sudo make me sandwich
What? Make it yourself
$ sudo make a sandwich
chmod: cannot access `me': No such file or directory
make: *** [a] Error 1
$ sudo make sandwich
What? Make it yourself

I like the way this one deals with guideline #3. Just one press of Shift makes the difference.

Not mine, and not a true solution as it violates rule #2, but it has a very interesting story that led me here:
# With apologies to XKCD #149
me:
    @:
a:
    @:
sandwich:
    @[ "$$(id -u)" -eq 0 ] && { echo "Okay"; touch sandwich; } || echo "What? Make it yourself!"

So, where this came from?
I was just messing with the cloud-init script /boot/user-data in Ubuntu 22.04 Server image for Raspberry Pi, when I came into this example snippet:
## Write arbitrary files to the file-system (including binaries!)
#write_files:
#- path: /etc/default/console-setup
#  content: |
#    # Consult the console-setup(5) manual page.
#    ACTIVE_CONSOLES="/dev/tty[1-6]"
#    CHARMAP="UTF-8"
#    VIDEOMODE=
#    FONT="Lat15-Terminus18x10.psf.gz"
#    FONTFACE=
#    FONTSIZE=
#    CODESET="Lat15"
#  permissions: '0644'
#  owner: root:root
#- encoding: gzip
#  path: /root/Makefile
#  content: !!binary |
#    H4sICF2DTWIAA01ha2VmaWxlAFNWCM8syVBILMjPyU/PTC1WKMlXiPB2dlFQNjSx5MpNteLi
#    dLDiSoRQxYl5KeWZyRkgXrSCkoqKRmaKgm6pppKCbmqhgoFCrIKamkK1QmpyRr6Ckn92YqWS
#    NdC80uQMBZhOa4VahZoaqIrwjMQSewXfxOxUhcwShcr80qLi1Jw0RSUuAIYfEJmVAAAA
#  owner: root:root
#  permissions: '0644'

That binary blob caught my eye... was that an executable? A binary Makefile? It made no sense. Assuming this was plain text with base64 encoding, I tried in a terminal:
$ txt='H4sICF2DTWIAA01ha2VmaWxlAFNWCM8syVBILMjPyU/PTC1WKMlXiPB2dlFQNjSx5MpNteLi
> dLDiSoRQxYl5KeWZyRkgXrSCkoqKRmaKgm6pppKCbmqhgoFCrIKamkK1QmpyRr6Ckn92YqWS
> NdC80uQMBZhOa4VahZoaqIrwjMQSewXfxOxUhcwShcr80qLi1Jw0RSUuAIYfEJmVAAAA'
$ printf "$txt" | base64 -d
]�MbMakefileS�,�PH,���O�L-V(�W��vvQP64���M���t��J�Pŉy)��� ^�����Ff��n����nj���B����B�BjrF���vb��5м��
                                                                                �Nk�Z�������{���T�����Ң�Ԝ4E%.���

Ouch, a true binary indeed! What the hell..
Oh, wait... encoding: gzip. Hummm...
$ printf "$txt" | base64 -d | gunzip

Ta-da! The Makefile above appears!
What a convoluted Easter Egg from... well, I have no idea! And, what was that all about?
So I read the comic, experimented a bit with that Makefile, finally understood the joke, then googled for "make me a sandwich", and finally arrived here!

Welcome to Code Golf! This is certainly an unconventional way to arrive at a solution :p

This solution doesn't adhere to guideline #2 — or does being vaguely sandwich-shaped count? I went on a kind of palindrome theme at the beginning, but I could only find so many ways to make lines symmetric without resorting to lame real code # ecod laer. I didn't take guideline #1 very seriously, aesthetics comes first.
Remember that it's a makefile; the 3 successive lines beginning with if, rm and echo begin with a tab. The other indented lines begin with spaces.
me : mr ; env | grep -q DO_US || rm -- mr || SU_OD q- perg | vne ; rm : em
                            .SILENT:##:TNELIS.
                              . = a.  .a = .
$(.:.=):;:>$@
sandwich:
    if expr>/dev/null $$(id -u); then echo 'What? Make it yourself'; fi
    rm f- a me mr 2>/dev/null
    echo Okay
mr : ; true : ; touch me : em f- mr || rm -f me : em hcuot ; : eurt ; : rm

Usage (the commands can be issued in any order):
$ sudo make me a sandwich
Okay
$ sudo make me sandwich
make: *** [sandwich] Error 1
$ sudo make a sandwich
make: *** [sandwich] Error 1
$ sudo make sandwich
make: *** [sandwich] Error 1
$ make me a sandwich
What? Make it yourself
make: *** [sandwich] Error 1

As for guideline #3, this isn't cleverly hidden, just slightly weirdly. Some hints:

 There are two different tests: one search for SUDO_USER, and one test of whether id -u prints 0. Do you see why What? is not printed for root? Do you see how the lack of SUDO_USER causes Okay not to be printed?

Here is a first go using a different and simpler technique:
.SILENT:

reset_command:
    @rm -f command

me a sandwich: reset_command
    @echo $@ >> command
    -@make `cat command | tr "\n" "_"` 2>/dev/null

me_a_sandwich_: reset_command
    @if [ `whoami` == "root" ]; then echo "Okay"; else echo "What? Make it yourself."; fi

I'm pretty sure there is more that I can do with this - get it to respond to other input commands for instance. I'll have to work on the root switch obfuscation and the actual sandwich making.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Golf you a Double Quine for greater good!
Good Evening Ladies and Gentleman.
Tonight - we have a code challenge. A competition that will be defined not in the amount of points (a la Asteroids)  but simply whether you can finish it (a la Zelda). And for the sake of comparison, the amount of bytes (uh... but you said...).
Your challenge is to compose a single quine that compiles in both WhiteSpace and any other language of your choice. Both quines must have absolutely identical output (which as a quine is absolutely identical to the source code). Your quine must be more then 3 bytes in length.
Your score is the size of your source code in bytes.
Given that this challenge involves WhiteSpace, please escape your answers so that they are clear - preferably in the C style. Your score is the original source in bytes - not the escaped version.
Good luck.

Would an xxd hex dump do?

Yes. I'll accept it.

Whitespace and Perl, 992 975 characters
Good Evening Ladies and Gentlemen.
To start with, here is my submission encoded in base64, which I feel is the best way to communicate a large Whitespace program. (You really don't want to use an encoding that leaves any whitespace as-is, so there's no point in selecting something more "readable".)
c2F5PDwgeDI7c2F5PDwwLDAgIApzYXk8PCB4MjtzYXk8PDAsMCAgCgoJCQogICAJCSAgCSAgCSAJ
CSAgCSAgCQkgCSAJIAkJCQkJICAJCSAJCQkgCQkJCQkgCSAJIAkJIAkgCSAgIAkJCQkJICAgCQkg
IAkgCQkgCSAJCSAJICAgIAkJCQkgCSAgCSAJCSAJICAgIAkgCQkgICAJICAgICAgCQkJIAkJCQkJ
IAkJCSAJCQkJICAgICAJCQkgCSAgICAgIAkJCQkJICAgICAgCQkgICAJCSAgICAJCQkJCQkJCSAg
CSAJIAkgICAJCQkgICAJCQkJCSAgCQkJCSAJICAgIAkgCQkJCQkgCSAgICAgCSAgCSAJICAgICAg
CSAgICAJICAgICAJCSAgIAkJCSAJIAkJCQkJCSAJCSAJIAkgICAgICAgCQkgIAkgICAgICAgICAg
IAkJICAgCSAJCQkgCSAgICAgCQkJCQkJIAkgICAgCQkJCSAJCQkJICAJCQkgICAJCQkgCSAgCSAg
IAkJCQkgIAkJIAkJCSAgIAkJCSAJCQkgCQkJICAJCSAJICAJIAkJCSAJIAkgCQkgICAgIAkgCSAJ
ICAJICAJIAkJICAgICAJIAkgICAgCQkJCSAgCSAJCSAJIAkJIAkgIAkgCSAJCSAJCSAJCSAJCQkg
CQkJICAgIAkJCSAgCSAgCQogICAJICAgICAJCQkJCSAJCSAJIAkgCSAJICAJCQkgICAJICAgCSAg
ICAJCSAJICAgICAgICAgCSAgIAkJCQkgCQkgICAgCQkgCSAJICAJCQkgCQkJCSAJCQkgICAJICAg
IAkgCSAJCQkgIAkJCQkgCSAJCSAJIAkgCQkJCSAJICAJIAkJIAkgICAJCiAKICAKICAgIAogCSAg
CQoKICAJCiAKICAgIAkJCQkgCSAKCSAJCQkKICAgICAJCQkJIAkgCgkgCSAgCiAgIAkJCgkgIAoK
CQkJCiAKCgoJIAkKICAgCSAgIAkgIAoKIAkKIAkgIAkKCiAJIAogICAJIAoKIAkKCiAJIAoKIAkK
CQogCSAgIAkgCgogCQoKCgoKICAgCiAgIAogCiAKIAkKCiAJCgogICAgCiAKIAoJIAogCiAgICAJ
IAoJIAkJIAoJICAgCSAKCSAJIAogCSAgCgogIAogCiAgICAJCQoJIAkJICAJCSAJCQkKCSAgCiAg
CQkJICAgCgkgCQkgICAJICAgICAKCSAgIAkKICAgICAJCQoJIAkgIAogICAJCQoJICAKCgkJCiAK
CgoJCjAK

Here's an excerpt that highlights all of the visible parts of the source. ⇥ is used to indicate a tab and ↲ to indicate a newline.
say<< x2;say<<0,0  ↲
say<< x2;say<<0,0  ↲
↲
⇥⇥↲
   ⇥⇥  ⇥ [... etcetera ... skipping rest of a really long line ...]↲
   ⇥⇥⇥ ⇥⇥[... etcetera ... shorter but still quite a long line ...]↲
 ↲
  ↲
    ↲
 ⇥  ⇥↲
[... etcetera ... whole lotta whitespace in here ...]
⇥⇥↲
 ↲
↲
↲
⇥↲
0↲

Perl was the natural choice for the second language in this challenge, being one of the best general-purpose languages for writing compact quines. My shortest Perl quine is 19 bytes:
say<< x2
say<< x2

– and you can see how it was the seed for the Perl half of the double quine. My best Whitespace quine, in comparison, is 541 bytes long. (Though shorter ones do exist – 445 bytes is the best I've seen.)
From the Perl interpreter's point of view, the first line of the double quine's source file contains the two statements that make up the entire program proper, as the remaining contents are two quoted strings. The first string is the repeated line of Perl, and is delimited by the blank third line. The second string is all whitespace, and runs from the fourth line of the source all the way to the 0 delimiter at the bottom of the file.
When taken as a Whitespace program, the first four lines contain three instructions that are largely useless. (Their effect is to push two zero values onto the stack, and then discard the second one.) They're included just to get safely past the newlines that the Perl program requires – the real program starts after that. Rather than quote the unreadable source any further, here's a paraphrasing of the instructions that make up the Whitespace program, in an assembly-like format:
# Representation of "say<< ;say<<0,0  \n" in base 122 as ASCII chars.
PERLCODE = 44892457841068708924520433691075560592081

# Represention of the whitespace program, following the "push PERLCODE"
# instruction, in base 3 (see comments on wsout).
WSCODE = 9823454421986355730445143846606456399449033186160554878002671428613111806443504867738858766142050504887335990409088441824104338753030405625930185

# Set up the stack and the heap. The first three instructions are not
# particularly useful; they're just there to skip past the newlines in
# the Perl code. (Though the initial zero on the stack does get used
# at the very end.)

        push    0
        push    0
        jneg    wsout

        push    WSCODE
        push    PERLCODE
        dup
        dup
        push    0
        copy    1

# Output the first four lines of the file.

perl:   dup
        mod     122
        putchar
        div     122
        dup
        jnzero  perl
        pop
        jzero   perl
        push    68              # represents "jneg wsout"
        call    wsout

# Output the rest of the file.

        copy    1
        call    pushout
        push    2
        call    wsout
        call    pushout
        call    wsout
        putnum
        push    2
        call    wsout
        exit

# pushout: Output a Whitespace push instruction, using the number on
# the top of the stack as the instruction's argument. (Recursion is
# used to output the bits MSB-first.)

pushout:
        push    0
        dup
        call    wsout
        call    wsout
bits:   dup
        jzero   bitend
        dup
        mod     2
        swap
        div     2
        call    bits
bitend: call    wsout
        ret

# wsout: Output a sequence of whitespace characters as represented by
# the number on the top of the stack. The number is read in base 3,
# LSB-first, with 0 = SPC, 1 = TAB, 2 = NL. Calling wsout with a value
# of zero will output a single space.

wsout:
        dup
        mod     3
        mul     -23             # some ugly math that transforms
        mod     -24             # (0, 1, 2) into (32, 9, 10)
        add     32
        putchar
        div     3
        dup
        jnzero  wsout
        pop
        ret

The giant numbers at the top are what we Whitespace users have to use in lieu of actual strings. Don't bother trying to run this on a Whitespace interpreter that doesn't have proper bignum support.
Finally, here's the program again, but this time with C-style escapes, since it was specifically requested:
say<< x2;say<<0,0  \nsay<< x2;say<<0,0  \n\n\t\t\n   \t\t  \t  \t \t\t  \t  \t\t \t \t \t\t\t\t\t  \t\t \t\t\t \t\t\t\t\t \t \t \t\t \t \t   \t\t\t\t\t   \t\t  \t \t\t \t \t\t \t    \t\t\t\t \t  \t \t\t \t    \t \t\t   \t      \t\t\t \t\t\t\t\t \t\t\t \t\t\t\t     \t\t\t \t      \t\t\t\t\t      \t\t   \t\t    \t\t\t\t\t\t\t\t  \t \t \t   \t\t\t   \t\t\t\t\t  \t\t\t\t \t    \t \t\t\t\t\t \t     \t  \t \t      \t    \t     \t\t   \t\t\t \t \t\t\t\t\t\t \t\t \t \t       \t\t  \t           \t\t   \t \t\t\t \t     \t\t\t\t\t\t \t    \t\t\t\t \t\t\t\t  \t\t\t   \t\t\t \t  \t   \t\t\t\t  \t\t \t\t\t   \t\t\t \t\t\t \t\t\t  \t\t \t  \t \t\t\t \t \t \t\t     \t \t \t  \t  \t \t\t     \t \t    \t\t\t\t  \t \t\t \t \t\t \t  \t \t \t\t \t\t \t\t \t\t\t \t\t\t    \t\t\t  \t  \t\n   \t     \t\t\t\t\t \t\t \t \t \t \t  \t\t\t   \t   \t    \t\t \t         \t   \t\t\t\t \t\t    \t\t \t \t  \t\t\t \t\t\t\t \t\t\t   \t    \t \t \t\t\t  \t\t\t\t \t \t\t \t \t \t\t\t\t \t  \t \t\t \t   \t\n \n  \n    \n \t  \t\n\n  \t\n \n    \t\t\t\t \t \n\t \t\t\t\n     \t\t\t\t \t \n\t \t  \n   \t\t\n\t  \n\n\t\t\t\n \n\n\n\t \t\n   \t   \t  \n\n \t\n \t  \t\n\n \t \n   \t \n\n \t\n\n \t \n\n \t\n\t\n \t   \t \n\n \t\n\n\n\n\n   \n   \n \n \n \t\n\n \t\n\n    \n \n \n\t \n \n    \t \n\t \t\t \n\t   \t \n\t \t \n \t  \n\n  \n \n    \t\t\n\t \t\t  \t\t \t\t\t\n\t  \n  \t\t\t   \n\t \t\t   \t     \n\t   \t\n     \t\t\n\t \t  \n   \t\t\n\t  \n\n\t\t\n \n\n\n\t\n0\n