Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Can you write an aphorism in at most 4 lines of code ?

Code should read as much as possible as an aphorism in plain English and should return the boolean true.

Language: of choice.

Criteria for accepted answer: Most votes in 180 30 days. (8th of July 2014) [Increased from 30 days since the answers need to get a lot more attention and feedback from readers.]

Originality: can be an old aphorism but a creative one would be much more appreciated.

share|improve this question
1  
What is the max line length ? –  kyle k Jan 9 at 23:54
    
@kyle k, 90 characters should should suffice, mostly for estetic, readability reasons, also good aphorisms tend to be short :) –  Eduard Florinescu Jan 9 at 23:57
1  
Ruby - !!"[ insert whatever aphorism you want here ]" –  Doorknob Jan 10 at 2:54
1  
@DoorknobofSnow That would be a valid answer but I doubt that would get much of the votes. –  Eduard Florinescu Jan 10 at 8:50
1  
Not sure that Shakespeare quotes qualify as aphorisms. –  Blazemonger Jan 24 at 18:11
show 1 more comment

49 Answers

up vote 44 down vote accepted

Python

import this
love = this
this is love, love is not True or False, love is love
# (True, True, True)

Okay, this returns a tuple of Truths, but that itself evaluates as True anyway.

share|improve this answer
3  
+1 for perfectly readability –  RSFalcon7 Jan 28 at 18:05
3  
+1 for "import this" –  aditsu Feb 22 at 0:26
add comment

Haskell

Be original!

do otherwise

It returns True.

share|improve this answer
add comment

C

This quote is a line from My Fair Lady. See here https://www.youtube.com/watch?v=uVmU3iANbgk

#include <stdio.h>
/*the rain */int /*Spain falls*/ main/*ly*/(){return puts("on the plane")>0?1:0;}
share|improve this answer
add comment

Javascript

with = javascript = we = can = create = any = aphorism = returning = true;
share|improve this answer
    
Yes, but is it creative? ;) –  Doorknob May 16 at 23:47
add comment

Mathematica

 mo[thing__] := MemberQ[{thing}, money | problems | True]
 mo[money~mo~problems]
share|improve this answer
add comment

Java

for (Person person : people) {
    if (!HouseTypeEnum.GLASS_HOUSE.equals(person.getResidence().getHouseType()))
        throw new StonesException();
}
share|improve this answer
1  
Two problems: This doesn't compile because we don't have a Person class or a HouseTypeEnum or a StonesException or (etc). Also "should return the boolean true." This code doesn't return any value. –  Quincunx May 16 at 21:13
add comment

I got a wonderful error while attempting this:

It's very much inspired by Darren Stone's answer.

TypeError: Cannot use 'in' operator to search for 'tis nobler' in mind to suffer the The Slings and Arrows of outrageous fortune

Javascript

[2].be || ! [2].be ; this.is, "the question"

It returns an implicit true.

Slightly less terse, with a question mark:

[2].be || ! [2].be? is = this: !"the question"
share|improve this answer
add comment

Groovy

short Short;
short life = Short;
assert life.is(Short);
share|improve this answer
add comment

JavaScript

function healthy_community(diversity){
    return (diversity === true) ? true : false;
}
healthy_community(true);
share|improve this answer
    
why not just return diversity ? –  Eduard Florinescu Feb 26 at 22:27
    
well if you pass 'kinda sorta' it will return false. it must be absolutely true in type and value. –  Richard Andrew Lee Mar 3 at 16:41
add comment

Java (probably others too)

boolean hasExceptions(Rule rule) { return rule != this; }

"There are always exceptions, except to this rule." - by me.

share|improve this answer
add comment

C

main(int I,char **think) {char *a="there"; for (;--I;) a['m'];}
share|improve this answer
1  
You can remove the types in declarations. Also something has to be done to a's declaration... It gets in the way when you read –  mniip Jan 24 at 19:58
    
I left them because my compiler gave me errors without them, so I wanted to be very adherent :P –  jmc Jan 25 at 7:54
add comment

C++

int main() {
  int right,might;
  might==right;
}

Might is right.

share|improve this answer
add comment

T-SQL

I made several attempts at this challenge before arriving at an answer that expresses truth through the code itself. After a few attempts at turning favorite quotes into pithy code translations, I realized the way to go was to set aside quotation entirely and let the language of choice simply speak the wisdom it is capable of speaking.

Since SQL is verbose, I have chosen to break this 4-line program into more lines for ease of reading without horizontal scrolling. The properly "golfed" version may be found on this SQLFiddle.

DECLARE @mindInTurmoil BIT = 'True'
Samsara: SELECT 'equanimity' AS Attitude, 0 AS Ego INTO #Self
    WHERE @mindInTurmoil = 'True' 
IF (SELECT TOP 1 Attitude FROM #Self ORDER BY Ego) = 'equanimity' 
    SET @mindInTurmoil = 'False' ELSE GOTO Samsara
SELECT CASE @mindInTurmoil 
    WHEN 'True' THEN 'False' WHEN 'False' THEN 'True' END AS Liberation

Returns:

Liberation
----------
True
share|improve this answer
add comment

Not one of my favourite songs, still a great album.

PHP

$_GET['this'] or die(!0);

Reads as: Get this or die! (No!)

Get This
Slipknot
1999

share|improve this answer
add comment

Javascript

get: with(this) 1;

I think this makes sense.

Edit: was notified it didn't return true, well now it does.

share|improve this answer
    
Doesn't return true –  Eduard Florinescu Feb 4 at 20:41
add comment

JAVA

public static boolean think(){return true;}public static boolean so()
{return true;}public static boolean be(){return true;}static{boolean i=true;
    System.out.println((i==think())?so():i==be());
}

I think so i be --Descartes

share|improve this answer
add comment

Rebol

love: true 
war:  false

if true? any [love is blind and war is hell] [make love not war]
share|improve this answer
add comment

Is my use of the literal string true cheating?

This is an AutoHotkey script:

Be("true") to yourself

Be(msg) {
    MsgBox % msg
}
share|improve this answer
add comment

Python

love=[True];all,fair,war=love*3
all is fair in love and war
share|improve this answer
add comment

Ruby

Not the most elegant solution, but very easy to read

def you_know_meaning(x) true end

!!!("aphorism" != "aphorism" unless you_know_meaning "aphorism")

=> true
share|improve this answer
add comment

R

the_whole <- c(-1,-1)
the_part <- -1
the_whole > sum(the_part,the_part)

-Socrates

share|improve this answer
add comment

JavaScript

return (Do || !Do) || (there == !try);

return 2 * be || !(2 * be);
share|improve this answer
1  
Upvote for the Yoda one, but I am thinking there should be a ban on "To be or not to be". –  Jonathan Van Matre Feb 21 at 17:53
add comment

Python

be = that = the = question = 1
2 - be or not 2 - be
that is the & question
share|improve this answer
add comment

Ruby vs Friedrich Nietzsche

=> class Lie
=>   def self.is_a_condition_of?(life);true;end
=> end
=> Lie.is_a_condition_of?("life") # => true
share|improve this answer
1  
You're admitting also that self is a condition of life :) +1 –  Eduard Florinescu Jan 27 at 12:19
add comment

Perl

sub between (&@) { $_[1] if $_[0]->() } sub lies { $_[0] ne $_[1] }
my ($thought, $expression) = (1,1);

between {$thought and $expression} lies a => 'lifetime';

NB. Above works fine with (or without) strict and warnings pragmas.

share|improve this answer
add comment

C

int main(int fear, int* computers){ int

    i; do { !fear; computers[i]; fear; "the lack of them";

} while();return true;}

I do not fear computers, I fear the lack of them.

-Isaac Asimov

share|improve this answer
add comment

TI-BASIC 

2_be or not(2_be)
share|improve this answer
add comment

Rebol

Rebol []
between: :if thought: expression: true lies: func ['a 'b] [a != b]

between thought and expression [lies a lifetime]


Some explanation

The above code translates to:

if thought and expression [lies word-arg1 word-arg2]

The if statement is true so the lies function is called which returns true as along as the two arguments provided are different.

share|improve this answer
add comment

Lua

-- all search is in vain
function search() end
-- only the void is true
function void() return function() return true end, true end
-- and what remains is to
for ever in void() do repeat search("light") until true end
return true
share|improve this answer
add comment

A bit lazy, but my take.

Python:

life = short = True; art = long = True; life=art
life is short and art is long

JavaScript:

The = word = 'Yoga'
has = been = 'vulgarized'
and = does = not=  mean = anything =Date.now() ,!''
//Swami Rama 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.