title: Acronym to phrase

text:
# Question
Title: Acronym to phrase
**Task:**

Create a program that will take an acronym as input, for example `dftba`, and generate some possible phrases that the acronym could stand for. You can use wordlist as word input. Inspired by https://www.youtube.com/watch?v=oPUxnpIWt6E

**Example:**

```
input: dftba
output: don't forget to be awesome

```

**Rules:**

* Your program can't generate the same phrase every time for the same acronym, there must be randomization
* Input will be all lowercase
* Post a few examples (input and output)
* Any language is accepted
* It's a , so most upvotes win!

# Answer
> 8 votes
# HTML, CSS, and JavaScript

### HTML

```
<div id='word-shower'></div>
<div id='letter-container'></div>

```

### CSS

```
.letter {
    border: 1px solid black;
    padding: 5px;
}

#word-shower {
    border-bottom: 3px solid blue;
    padding-bottom: 5px;
}

```

### JS

```
var acronym = 'dftba', $letters = $('#letter-container')
for (var i = 0; i < acronym.length; i++) {
    $letters.append($('<div>').text(acronym[i]).attr('class', 'letter'))
}

var $word = $('#word-shower')
setInterval(function() {
    $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://randomword.setgetgo.com/get.php') + '&callback=?', function(word) {
        word = word.contents.toLowerCase()
        $word.text(word)
        $letters.children().each(function() {
            if (word[0] == this.innerText) {
                this.innerText = word
                return
            }
        })
    })
}, 1000)

```

---

Uses a random word generator and shows live results as it looks for words.

Here is a fiddle if you want to run it yourself.

Here's a GIF of the output:

# Answer
> 7 votes
# Java

Fetches a word list from wiktionary. Chooses a random word from that list that starts with the correct letter. Then uses Google suggest recursively to look for possible next words. Outputs a list of possibilities. If you re-run it with the same acronym, you will get different results.

```
import java.io.*;
import java.net.*;
import java.util.*;

public class Acronym {

    static List<List<String>> wordLists = new ArrayList<List<String>>();
    static {for(int i=0; i<26; i++) wordLists.add(new ArrayList<String>());}
    static String acro;

    public static void main(String[] args) throws Exception {
        acro = args[0].toLowerCase();

        //get a wordlist and put words into wordLists by first letter
        String s = "http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/PG/2006/04/1-10000";
        URL url = new URL(s);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            if(inputLine.contains("title")) {
                int start = inputLine.indexOf("title=\"");
                int end = inputLine.lastIndexOf("\">");
                if(start>=0 && end > start) {
                    String word = inputLine.substring(start+7,end).toLowerCase();
                    if(!word.contains("'") && !word.contains(" ")) {
                        char firstChar = word.charAt(0);
                        if(firstChar >= 'a' && firstChar <='z') {
                            wordLists.get(firstChar-'a').add(word);
                        }
                    }
                }
            }
        }

        //choose random word from wordlist starting with first letter of acronym
        Random rand = new Random();
        char firstChar = acro.charAt(0);
        List<String> firstList = wordLists.get(firstChar-'a');
        String firstWord = firstList.get(rand.nextInt(firstList.size()));

        getSuggestions(firstWord,1);

    }

    static void getSuggestions(String input,int index) throws Exception {
        //ask googleSuggest for suggestions that start with search plus the next letter as marked by index
        String googleSuggest = "http://google.com/complete/search?output=toolbar&q=";
        String search = input + " " + acro.charAt(index);
        String searchSub = search.replaceAll(" ","%20");

        URL url = new URL(googleSuggest + searchSub);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            String[] parts = inputLine.split("\"");
            for(String part : parts) {
                if(part.startsWith(search)) {
                    //now get suggestions for this part plus next letter in acro
                    if(index+1<acro.length()) {
                        String[] moreParts = part.split(" ");
                        Thread.sleep(100);
                        getSuggestions(input + " " + moreParts[index],index+1);
                    }
                    else {
                        String[] moreParts = part.split(" ");
                        System.out.println(input + " " + moreParts[index]);
                    }
                }
            }
        }
        in.close();
    }
}

```

Sample output:

```
$ java -jar Acronym.jar ght
great harvest trek
great harvest tulsa
great harvest taylorsville
great harvest temecula
great harvest trek
great harvest twin
great harvest tempe
great harvest twin
great harvest turners
great harvest twitter
great horned toad
great horned toads
great horned tomato
great horned tomato
great horned turtle
great harvest trek
great harvest tulsa
great harvest taylorsville
great harvest temecula
great harvest trek
great harvest twin
great harvest tempe
great harvest twin
great harvest turners
great harvest twitter
great horned toad
great horned toads
great horned tomato
great horned tomato
great horned turtle
great harvest trek
great harvest tulsa
great harvest taylorsville
great harvest temecula
great harvest trek
great harvest twin
great harvest tempe
great harvest twin
great harvest turners
great harvest twitter
great horror thriller
great horror tv
great horror thriller
great horror titles
great horror tv
great holiday traditions
great holiday treats
great holiday toasts
great holiday tech
great holiday travel
great holiday treat
great holiday tips
great holiday treat
great holiday toys
great holiday tour
great harvest trek
great harvest tulsa
great harvest taylorsville
great harvest temecula
great harvest trek
great harvest twin
great harvest tempe
great harvest twin
great harvest turners
great harvest twitter
great horned toad
great horned toads
great horned tomato
great horned tomato
great horned turtle

```

Unfortunately, the Google suggest URL stopped working after a while - perhaps my IP was blacklisted by Google for mis-use?!

# Answer
> 5 votes
# Ruby

so ruby. many doge. wow.

Online Version

```
@prefix = %w[all amazingly best certainly crazily deadly extra ever few great highly incredibly jolly known loftily much many never no like only pretty quirkily really rich sweet such so total terribly utterly very whole xtreme yielding zippily]
@adjective = %w[appealing app apl attractive brave bold better basic common challenge c++ creative credit doge durable dare enticing entertain extreme fail fabulous few favourite giant gigantic google hello happy handy interesting in improve insane jazz joy j java known kind kiwi light laugh love lucky low more mesmerise majestic open overflow opinion opera python power point popular php practice quirk quit ruby read ready stunning stack scala task teaching talking tiny technology unexpected usual useful urban voice vibrant value word water wow where xi xanthic xylophone young yummy zebra zonk zen zoo]

def doge(input)
  wow = ""
  input.chars.each_slice(2) do |char1, char2|
    if char2 == nil
      wow << (@prefix + @adjective).sample(1)[0] + "."
      break
    end
    wow << @prefix.select{|e| e[0] == char1}.sample(1)[0]
    wow << " "
    wow << @adjective.select{|e| e[0] == char2}.sample(1)[0]
    wow << ". "
  end
  wow
end

puts doge("dftba")
puts doge("asofiejgie")
puts doge("iglpquvi")

```

Examples:

```
deadly favourite. terribly better. challenge.
all scala. only favourite. incredibly enticing. jolly giant. incredibly extreme.
incredibly gigantic. loftily popular. quirkily usual. very interesting.

```

# Answer
> 4 votes
# Mathematica

Some terms that commonly appear in acronyms.

```
terms = {"Abbreviated", "Accounting", "Acquisition", "Act", "Action", "Actions", "Activities", "Administrative", "Advisory", "Afloat", "Agency", "Agreement", "Air", "Aircraft", "Aligned", "Alternatives", "Analysis", "Anti-Surveillance", "Appropriation", "Approval", "Architecture", "Assessment", "Assistance", "Assistant", "Assurance", "Atlantic", "Authority", "Aviation", "Base", "Based", "Battlespace", "Board", "Breakdown", "Budget", "Budgeting", "Business", "Capabilities", "Capability", "Capital", "Capstone", "Category", "Center", "Centric", "Chairman", "Change", "Changes", "Chief", "Chief,", "Chiefs", "Closure", "College", "Combat", "Command", "Commandant", "Commander","Commander,", "Commanders", "Commerce", "Common", "Communications", "Communities", "Competency", "Competition", "Component", "Comptroller", "Computer", "Computers,", "Concept", "Conference", "Configuration", "Consolidated", "Consulting", "Contract", "Contracting", "Contracts", "Contractual", "Control", "Cooperative", "Corps", "Cost", "Council", "Counterintelligence", "Course", "Daily", "Data", "Date", "Decision", "Defense", "Deficiency", "Demonstration", "Department", "Depleting", "Deployment", "Depot", "Deputy", "Description", "Deskbook", "Determination", "Development", "Direct", "Directed", "Directive", "Directives", "Director", "Distributed", "Document", "Earned", "Electromagnetic", "Element", "Engagement", "Engineer", "Engineering", "Enterprise", "Environment", "Environmental", "Equipment", "Estimate", "Evaluation", "Evaluation)", "Exchange", "Execution", "Executive", "Expense", "Expert", "Exploration", "Externally", "Federal", "Final", "Financial", "Findings", "Fixed","Fleet", "Fleet;", "Flight", "Flying", "Followup", "Force", "Forces,", "Foreign", "Form", "Framework", "Full", "Function", "Functionality", "Fund", "Funding", "Furnished", "Future", "Government", "Ground", "Group", "Guidance", "Guide", "Handbook", "Handling,", "Hazardous", "Headquarters", "Health", "Human", "Identification", "Improvement", "Incentive", "Incentives", "Independent", "Individual", "Industrial", "Information", "Initial", "Initiation", "Initiative", "Institute", "Instruction", "Integrated", "Integration", "Intelligence", "Intensive", "Interdepartmental", "Interface", "Interference", "Internet", "Interoperability", "Interservice", "Inventory", "Investment", "Joint", "Justification", "Key", "Knowledge", "Lead", "Leader", "Leadership", "Line", "List", "Logistics", "Maintainability", "Maintenance", "Management", "Manager", "Manual", "Manufacturing", "Marine", "Master", "Material", "Materials", "Maturity", "Measurement", "Meeting", "Memorandum", "Milestone", "Milestones", "Military", "Minor", "Mission", "Model", "Modeling", "Modernization", "National", "Naval", "Navy", "Needs", "Network", "Networks", "Number", "Objectives", "Obligation", "Observation", "Occupational", "Offer", "Office", "Officer", "Operating", "Operational", "Operations", "Order", "Ordering", "Organization", "Oversight", "Ozone", "Pacific", "Package", "Packaging,", "Parameters", "Participating", "Parts", "Performance", "Personal", "Personnel", "Planning", "Planning,", "Plans", "Plant", "Point", "Policy", "Pollution", "Practice", "Preferred", "Prevention", "Price", "Primary", "Procedure", "Procedures", "Process", "Procurement", "Product", "Production", "Professional", "Program", "Programmatic", "Programming", "Project", "Proposal", "Protection", "Protocol", "Purchase", "Quadrennial", "Qualified", "Quality", "Rapid", "Rate", "Readiness", "Reconnaissance", "Regulation", "Regulations", "Reliability", "Relocation", "Repair", "Repairables", "Report", "Reporting", "Representative", "Request", "Requirement", "Requirements", "Requiring", "Requisition", "Requisitioning", "Research", "Research,", "Reserve", "Resources", "Responsibility", "Review", "Reviews", "Safety", "Sales", "Scale", "Secretary", "Secure", "Security", "Selection", "Senior", "Service", "Services", "Sharing", "Simulation", "Single", "Small", "Software", "Source", "Staff", "Standard", "Standardization", "Statement", "Status", "Storage,", "Strategy", "Streamlining", "Structure", "Submission", "Substance", "Summary", "Supplement", "Support", "Supportability", "Surveillance", "Survey", "System", "Systems", "Subsystem", "Tactical", "Target", "Targets", "Team", "Teams", "Technical", "Technology", "Test", "Tool", "Total", "Training", "Transportation", "Trouble", "Type", "Union", "Value", "Variable", "Warfare", "Weapon", "Work", "Working", "X-Ray", "Xenon", "Year", "Yesterday", "Zenith", "Zoology"};

```

---

## Code

```
f[c_]:=RandomChoice[Select[terms,(StringTake[#,1]==c)&]]
g[acronym_]:=Map[f,Characters@acronym]

```

---

## Examples

Ten randomly generated candidates for the acronym **ABC**.

```
Table[Row[g["ABC"], "  "], {10}] // TableForm

```

> Action Breakdown Corps
> Accounting Budget Commerce
> Air Budgeting Control
> Acquisition Breakdown Computer
> Action Budgeting Cost
> Aligned Breakdown Common
> Aligned Budgeting Course
> Advisory Budgeting Capability
> Aligned Battlespace Common
> Anti-Surveillance Battlespace Comptroller

---

**FMP**

```
Table[Row[g["FMP"], "  "], {10}] // TableForm

```

> Findings Manager Protocol
> Final Manual Purchase
> Flying Measurement Personnel
> Full Manufacturing Plans
> Form Measurement Programming
> Financial Model Programmatic
> Future Modernization Proposal
> Financial Measurement Package
> Form, Maintenance Planning
> Full Modeling Programmatic

---

**STM**

```
Table[Row[g["STM"], "  "], {10}] // TableForm

```

> Standardization Total Modernization
> Service Tactical Milestone
> Surveillance Transportation Management
> Subsystem Trouble Materials
> Structure Test Military
> Scale Test Materials
> Strategy Tool Modernization
> Small Technology Minor
> Supportability Transportation Manufacturing Status Tool Management

---

**CRPB**

```
Table[Row[g["CRPB"], "  "], {10}] // TableForm

```

> Cooperative Regulation Protection Business
> Commander Request Policy Base
> Changes Repair Programming, Business
> Closure Reviews Project Budget
> Commerce Regulations Parameters Base
> Contracts Rapid Price Base
> College Relocation Practice Budgeting
> Course Reporting Personnel Battlespace
> Course Requirement Procedures Budget

---

**SARDE**

```
Table[Row[g["SARDE"], "  "], {10}] // TableForm

```

> Supplement Actions Requiring Directives Estimate
> Scale Aligned Requirement Daily Estimate
> Secretary Atlantic Requisitioning Director Expense
> Software Action Review Direct Exploration
> Support Act Readiness Defense Electromagnetic
> Software Abbreviated Requirement Decision Exchange
> Submission Assessment Requisition Description Executive
> Streamlining Accounting Rate Depot Evaluation
> Surveillance Assistant Requisitioning Depot Engagement
> Survey Assistance Resources Deficiency Expense

# Answer
> 2 votes
## D

This mostly produces nonsense, but occasionally it will produce something sensible, or something so silly as to be humourous.

Words are pulled from this JSON file (~2.2MB).

Program takes the acronym from the first command line argument, and supports an optional second argument which tells the program how many phrases to generate.

```
import std.file : readText;
import std.conv : to;
import std.json, std.random, std.string, std.stdio, std.algorithm, std.array, std.range;

void main( string[] args )
{
    if( args.length < 2 )
        return;

    try
    {
        ushort count = 1;

        if( args.length == 3 )
            count = args[2].to!ushort();

        auto phrases = args[1].toUpper().getPhrases( count );

        foreach( phrase; phrases )
            phrase.writeln();
    }
    catch( Throwable th )
    {
        th.msg.writeln;
        return;
    }
}

string[] getPhrases( string acronym, ushort count = 1 )
in
{
    assert( count > 0 );
}
body
{
    auto words = getWords();
    string[] phrases;

    foreach( _; 0 .. count )
    {
        string[] phrase;

        foreach( chr; acronym )
        {
            auto matchingWords = words.filter!( x => x[0] == chr ).array();
            auto word = matchingWords[uniform( 0, matchingWords.length )];
            phrase ~= word;
        }

        phrases ~= phrase.join( " " );
    }

    return phrases;
}

string[] getWords()
{
    auto text = "words.json".readText();
    auto json = text.parseJSON();
    string[] words;

    if( json.type != JSON_TYPE.ARRAY )
        throw new Exception( "Not an array." );

    foreach( item; json.array )
    {
        if( item.type != JSON_TYPE.STRING )
            throw new Exception( "Not a string." );

        words ~= item.str.ucfirst();
    }

    return words;
}

auto ucfirst( inout( char )[] str )
{
    if( str.length == 1 )
        return str.toUpper();

    auto first = [ str[0] ];
    auto tail  = str[1 .. $];

    return first.toUpper() ~ tail.toLower();
}

```

**Examples**:

```
D:\Code\D\Acronym>dmd acronym.d

D:\Code\D\Acronym>acronym utf 5
Unchallenged Ticklebrush Frication
Unparalysed's Toilsomeness Fructose's
Umpiring Tableland Flimsily
Unctuousness Theseus Flawless
Umbrella's Tarts Formulated

```

# Answer
> 2 votes
# BASH

```
for char in $(sed -E s/'(.)'/'\1 '/g <<<"$1");
do
    words=$(grep "^$char" /usr/share/dict/words)
    array=($words)
    arrayCount=${#array[*]}
    word=${array[$((RANDOM%arrayCount))]}
    echo -ne "$word "
done
echo -ne "\n"

```

So: `$ bash acronym-to-phrase.sh dftba` resulted in

```
deodorization fishgig telolecithal bashlyk anapsid
demicivilized foretell tonogram besmouch anthropoteleological
doer fightingly tubulostriato bruang amortize

```

And: `$ bash acronym-to-phrase.sh diy` resulted in

```
decanically inarguable youthen
delomorphous isatin yen
distilling inhumorously yungan

```

Finally: `$ bash acronym-to-phrase.sh rsvp`

```
retzian sensitizer vestiarium pathognomonical
reaccustom schreiner vincibility poetizer
refractorily subspherical villagey planetule

```

...

My initial reaction? *whelpless transportal fireling*

# Answer
> 1 votes
# Python

So, this probably won't win any popularity contests, but I figured Python needed representation. This works in Python 3.3+. I borrowed @tony-h's json file of words (find it here). Basically, this code just takes the json list, and organizes all the words into a dictionary indexed on the letters of the alphabet. Then, whatever acronym is passed into the python application is used as an index into the dictionary. For each letter in the acronym, a random word is selected from all the words indexed under that letter. You can also provide a number of outputs desired, or if nothing is specified, 2 options will be generated.

The code (I saved it as phraseit.py):

```
import argparse
import json
import string
from random import randrange

parser = argparse.ArgumentParser(description='Turn an acronym into a random phrase')
parser.add_argument('acronym', nargs=1)
parser.add_argument('iters',nargs='?',default=2,type=int)
args = parser.parse_args()

acronym=args.acronym[0]
print('input: ' + acronym)

allwords=json.load(open('words.json',mode='r',buffering=1))

wordlist={c:[] for c in string.ascii_lowercase}
for word in allwords:
    wordlist[word[0].lower()].append(word)

for i in range(0,args.iters):
    print('output:', end=" ")
    for char in acronym:
        print(wordlist[char.lower()][randrange(0,len(wordlist[char.lower()]))], end=" ")
    print()

```

Some sample outputs:

```
$ python phraseit.py abc
input: abc
output: athabaska bookish contraster
output: alcoholism bayonet's caparison

```

Another:

```
$ python phraseit.py gosplet 5
input: gosplet
output: greenware overemphasiser seasons potential leprosy escape tularaemia
output: generatrix objectless scaloppine postulant linearisations enforcedly textbook's
output: gutturalism oleg superstruct precedential lunation exclusion toxicologist
output: guppies overseen substances perennialises lungfish excisable tweed
output: grievously outage Sherman pythoness liveable epitaphise tremulant

```

Finally:

```
$ python phraseit.py nsa 3
input: nsa
output: newsagent spookiness aperiodically
output: notecase shotbush apterygial
output: nonobjectivity sounded aligns

```

---
Tags: popularity-contest, word
---


title: Constant output program

text:
# Question
Title: Constant output program
I was wondering how one might go and produce a program that takes input from some kind of random source and uses it to produce constant output. An obvious way is, for example, to take an integer x and output x/x for 1, but that isn't too clever, is it? Therefore, the task is to write a program that outputs the same thing, no matter which input is given to it.

**Specifications**

* The program may assume that the input is either a number or a one line string (that is, valid characters are \[a-z\]\[A-z\]\[0-9\] and spaces). If you adopt one of those restrictions, specify which in your answer.
* The program must use the entered input in some way. To put it more formally, the contents of the variable that takes the input must be used afterwards in some calculation that affects the final variable to be printed.

The winner will be the most upvoted solution.

# Answer
**Python**

This question is boring. I'd rather sleep.

```
from time import sleep
sleep(input())

```

Input a number.
> 21 votes

# Answer
## GolfScript

```
~{.3*){.2%}{2/}until.@=!}do

```

This program will take a positive integer as input, and will output `1` unless the input is a counterexample to the Collatz conjecture. While the Collatz conjecture remains an open problem, it is known that there are no counterexamples below 5 × 260.
> 13 votes

# Answer
**Perl**

```
<>/0

```

produces for any input string:

```
Illegal division by zero at test5.pl line 1, <> line 1.

```
> 11 votes

# Answer
# Ruby

```
def a(x)
  4
end

```

I somehow felt this was related:
> 11 votes

# Answer
## Python

```
n=input()
p=37
print (n**p-n)%p

```

Takes an integer input, and always outputs 0. Uses Fermat's little theorem, which states that n^p == n mod p.
> 10 votes

# Answer
## J

```
=

```

Usage:

```
   =10
1

```

Always outputs 1.

Or how about an unhappy smiley verb:

```
{:0[

```

Usage:

```
   {:0[ 147
0

```

Always ouputs 0.
> 7 votes

# Answer
# C

This program reads an integer from stdin and then prints that integer, right?

```
main() {
    int i;
    printf("%d\n", scanf("%d", &i));
}

```

Well, no. It just prints `1`.

The input must be an integer though (otherwise it may output `0` or `-1`), which proves that the program "uses" the input.
> 5 votes

# Answer
## Javascript

```
var input = ~~prompt("Input an integer!");
if(Math.abs(input)<=Math.pow(2,31))
  console.log("It's too small! (not bigger than 2^31 = "+Math.pow(2,31)+")");
else console.log("It's quite big!");

```

Though JS can represent any integer between ±9,007,199,254,740,992, it will *always* print

> It's too small! (not bigger than 2^31 = 2147483648)

because bitwise operation is performed in range of 32bit.
> 3 votes

# Answer
**Ruby:**

```
p !gets

```

Always outputs `false`. `gets` takes user input, `!` negates that and since strings are truthy, the result will be `false`.
> 3 votes

# Answer
## Python 2

```
x=input()
print x^x

```

Only accepts integers. always outputs `0` by `xor`ing itself
> 3 votes

# Answer
## APL

```
⍴⍣≡

```

is the *shape* function, `⍴⍣≡` is the fixpoint of the shape function.

All APL values have a shape. Say, a 4x6x8 array has shape `4 6 8`; a scalar (like `3`) has shape  (no dimensions). Therefore,  always returns a one-dimensional list. This means that applying the output of  to  will always get you a one-dimensional list with one number in it. *That* means that applying  *again* will always get you a one-dimensional list with the number `1` in it.

Therefore,  converges to `1`; therefore `⍴⍣≡` will give `1` for all possible inputs.
> 3 votes

# Answer
## Golfscript

```
.=

```

Accepts any input and always prints `1`.
> 2 votes

# Answer
**Python**

```
def f(x):
    return 0*x

```
> 2 votes

# Answer
**JavaScript**

```
var input = prompt("Input something!");

console.log(new Number(input) === 1);

```

Will always return `false`, even with the input `1`
> 0 votes

# Answer
## Golfscript (4 chars)

```
~1\?

```

Accepts an integer. Outputs 1.
> 0 votes

# Answer
# Perl

```
$a=<>+1;for(1..length$a){$a=length$a}print$a

```

This program does use the input number, and it always prints 1.
> 0 votes

# Answer
## Python

This one works for numbers only.
I can't prove that it works for all numbers (can anyone?), but it prints "False" for all cases I've tested.
EDIT: Fixed a bug in the last line.

```
p=lambda x:x>1 and (i*i>x for i in xrange(2,x+1) if x%i==0 or i*i>x).next()
q=lambda x:(i<x for i in xrange(2,x+1) if p(i) and p(x-i) or i==x).next()
x = input()
print x%2==0 and x>2 and not q(x)

```

Explanation (for those who think my Python code is unclear):
`p(x)` tells you if x is a prime.
`q(x)` looks for two primes, whose some is x.
The program prints True if the number is even, greater than 2 and not the sum of 2 primes.
Please tell me if you find such a number.
> 0 votes

# Answer
## Python

```
print float("inf")*sum(map(ord,raw_input()))

```

Always returns 'infinity'.
> 0 votes

# Answer
# Q

Returns 1. Where no parameters are declared, Q implicitly uses x,y& z where appropriate. I think this satisfies the second condition...

```
{1}

```
> 0 votes

# Answer
## Python

`print input()*0`
> 0 votes

# Answer
## C

Produces 1 (prints and returns) for every input. (Input being the number of command line args)

```
j;main(c){j=0;while(c){j+=c%2;c/=2;}return j^1?main(j):printf("%d",j);}

```

This program does the same `#error 1` but cannot properly speaking be said to take input (unless you count the rest of the program after as input).
> 0 votes

# Answer
# Python

```
print eval('42#'+raw_input())

```

Accepts any input
> 0 votes

# Answer
# PostScript

This function takes one argument of any type, actively discards, and will always output ``, unless you didn't supply it with enough arguments (which I am going to define as being undefined behavior for this function), depending on the value of the argument. Here is its implementation:

```
/f {pop} def

```

This function will always take one more argument than is currently on the stack, so it will always output a `stackunderflow` error, depending on the input.

```
/f {clear pop} def

```

And here is a third, even more useful function, which I will define as having undefined behavior, depending on the number, types, and values of the arguments. Here is its implementation:

```

```
> 0 votes

# Answer
Common Lisp

```
(unless (read))

```

Always returns nil (unless you crash it with stupid input)
> 0 votes

# Answer
## Brainf\**k

Since the question is self-contradictory it's hard to give a serious answer, so here it is:

```
,[[->+<],]>[<->+<+>--<+>][->+>+[-]>+>+<<<<][->-<]+>[<->[-]]>[->--<----]+>[[---<->+<+>-]<->]>>[+>-<--]+>[[-]<->]<<[->-<-->+++>>>>>+<<<->+<<<+++++[>>++++++<<]]+>[<+>-]++>+<-<->>>>+<<<<->+<+>->>>[<]>[>]<[<[->-<]+>[<->[-]]<]+[>+>+>+>+<<---<<[-]]>>++<<[>>+[+<<<-]>>-<[<]+<<[<<->+]]>[->>+<<]>>[->+<]>[>+++++++++++<-]>[->+>+>+<<<]>[.>]

```

Accepts any string or number as input, always outputs "!!!". Have fun figuring out what it does.
> 0 votes

# Answer
# Clojure

```
(and(read-line)0)

```

Crudely equivalent to the prior common lisp submission, except that it makes no attempt to ensure that the line "read" is valid in any way shape or form. Compiled or interpreted, this program will read a single line and exit 0 in all cases.
> 0 votes

# Answer
## Game Maker Language

```
if argument0 return argument0/argument0 else return argument0

```

It can be any script, just call `script(argument)` \- it returns `true` if the number is not 0, else it returns `false`

If this was code golf, it would be `if argument0 a=1 return a` which is **25 characters** when compiled with the option "Treat all uninitialized variables as value 0".
> 0 votes

# Answer
# C++

Accepts any input. Prints ASCII equivalent of each character entered:

```
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cout << "Enter a string: ";
  cin >> s;

  cout << "ASCII characters of input:\n";

  for (int i = 0; i < s.size(); i++)
    cout << s[i] << ": " << int(s[i]) << endl;

  return 0;
}

```
> 0 votes

# Answer
# Befunge

```
&@

```

always returns nothing.

---

And a less pointless version:

```
&>:v
 -
 ^1_.@

```

Always returns 0
> 0 votes

---
Tags: code-challenge, popularity-contest
---


# Question
Title: Extract name of website from an absolute URL
You will take input such as

http://examples.example.co.nz/abcdefg

and return the name of the website, in which this example would be `example`.

To be more specific, I am looking for the Second Level Domain, which immediately precedes the TLD (Top Level Domain), but the Third Level Domain if the website is a Country Code Second-Level Domain.

Shortest bytes wins (competition ends March the 5th)!

# Answer
# Ruby, 15 characters

Assuming input is stored in variable `s`.

```
s.split(?.)[-2]

```

# GolfScript, 7

Exact translation.

```
"."/-2=

```

# Ruby with edge cases, 28

Such as `http://example.com/foo.bar`

```
s.split(?/)[2].split(?.)[-2]

```

# GolfScript with edge cases, 13

```
"/"/2="."/-2=

```
> 8 votes

# Answer
# JavaScript, 27 bytes

Assuming `a` is the variable and `c` is a 1 or 0,

```
i=a.split('.')[i.length-c];

```

would work. `c` is set to 3 if the domain is a `ccsld` and set to 2 if the domain isn't a `ccsld`. `c` can also be edited to a larger number if the page has dots in it.
> 4 votes

# Answer
# C, 120

```
char s[999],*p,*q,*r;main(){gets(s);for(q=p=strstr(s,"//")+2,*strstr(p,"/")=0;*p;p++)if(*p=='.')*p=0,r=q,q=p+1;puts(r);}

```
> 3 votes

# Answer
The 2 "solutions' above fail, what if the website has the URL www.some1.name.ext/whatever.this/www/?

The solution in JavaScript is:

```
var arr = myurl.split('/');
var domain = arr[2];
var arr2 = domain.split('.');
var name = arr2[arr2.length-2];

```

or

```
name = myurl.split('/')[2].split('.')[myurl.split('/')[2].split('.').length-2];

```
> 2 votes

# Answer
# Python - 30

Python's not too good for these things.

```
a.split("/")[2].split(".")[-2]

```

Doesn't work for TLDs with more than one `.`.
> 2 votes

# Answer
# Python2 172, Python3 156

This one is long, but i think it fullfills all the requeriments of the question.

```
s = "http://examples.example.co.nz/abcdefg"

#BEGIN_CODE
import re,urllib2
l=re.findall("..",urllib2.urlopen("http://goo.gl/molpki").read())
m=re.search(r"(?:\w+\.)*(\w+)\.(\w+)\.(\w+)",s)
g=m.groups()
r=g[0]if g[2]in l else g[1]
#END_CODE

print(r)

```

`l` contains a list of all country codes from wikipedia
`m` contains the last third, second and first level domains, dropping all the others
`r` contains the result

All could go in a line, but since `;` is the same as `\n` i leave it like this.

EDIT: Tested with `www.some1.name.ext/whatever.this/www/?` and returns `name` so i guess it works.

### Python 3 version

```
import re,requests as u
g=re.search(r"(?:\w+\.)*(\w+)"+"\.(\w+)"*2,s).groups()
r=g[0]if g[2]in re.findall("..",u.get("http://goo.gl/molpki").text) else g[1]

```

Same as above, r contains result.
> 1 votes

---
Tags: code-golf
---


# Question
Title: Program that prints mirror images of it's own self
Write a program that produces mirror images of itself. An example, would be the fantastic camel code that reads it's own code and produces two smaller 2x2 versions. Given the input:

```
                                           $_='ev
                                       al("seek\040D
           ATA,0,                  0;");foreach(1..3)
       {<DATA>;}my               @camel1hump;my$camel;
  my$Camel  ;while(             <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary           1=split(//);if(defined($
_=<DATA>)){@camel1hum        p=split(//);}while(@dromeda
 ry1){my$camel1hump=0      ;my$CAMEL=3;if(defined($_=shif
        t(@dromedary1    ))&&/\S/){$camel1hump+=1<<$CAMEL;}
       $CAMEL--;if(d   efined($_=shift(@dromedary1))&&/\S/){
      $camel1hump+=1  <<$CAMEL;}$CAMEL--;if(defined($_=shift(
     @camel1hump))&&/\S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if(
     defined($_=shift(@camel1hump))&&/\S/){$camel1hump+=1<<$CAME
     L;;}$camel.=(split(//,"\040..m`{/J\047\134}L^7FX"))[$camel1h
      ump];}$camel.="\n";}@camel1hump=split(/\n/,$camel);foreach(@
      camel1hump){chomp;$Camel=$_;y/LJF7\173\175`\047/\061\062\063\
      064\065\066\067\070/;y/12345678/JL7F\175\173\047`/;$_=reverse;
       print"$_\040$Camel\n";}foreach(@camel1hump){chomp;$Camel=$_;y
        /LJF7\173\175`\047/12345678/;y/12345678/JL7F\175\173\0 47`/;
         $_=reverse;print"\040$_$Camel\n";}';;s/\s*//g;;eval;   eval
           ("seek\040DATA,0,0;");undef$/;$_=<DATA>;s/\s*//g;(   );;s
             ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__   \124
               \1   50\145\040\165\163\145\040\157\1 46\040\1  41\0
                    40\143\141  \155\145\1 54\040\1   51\155\  141
                    \147\145\0  40\151\156 \040\141    \163\16 3\
                     157\143\   151\141\16  4\151\1     57\156
                     \040\167  \151\164\1   50\040\      120\1
                     45\162\   154\040\15    1\163\      040\14
                     1\040\1   64\162\1      41\144       \145\
                     155\14    1\162\       153\04        0\157
                      \146\     040\11     7\047\         122\1
                      45\15      1\154\1  54\171          \040
                      \046\         012\101\16            3\16
                      3\15           7\143\15             1\14
                      1\16            4\145\163           \054
                     \040            \111\156\14         3\056
                    \040\         125\163\145\14         4\040\
                    167\1        51\164\1  50\0         40\160\
                  145\162                              \155\151
                \163\163                                \151\1
              57\156\056

```

it produces:

```
        JXXXXXXXXL.       JXXLm.       .mJXXL       .JXXXXXXXXL
       {XXXXXXXXXXX.     JXXXmXXXXm mXXXXmXXXL     .XXXXXXXXXXX}
      .XXXXXXXXXXXXXL.  {XXXXXXXXXF 7XXXXXXXXX}  .JXXXXXXXXXXXXX.
     JXXXXXXXXXXXXXXXXL.`XXXXXX.       .XXXXXX'.JXXXXXXXXXXXXXXXXL
    JXXXXXXXXXXXXXXXXXXXmXXXXXXX.     .XXXXXXXmXXXXXXXXXXXXXXXXXXXL
  .XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}     {XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
 .XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXF       7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX'7XXXXXXXXXXXXXXXXXXXXXXXXXF         7XXXXXXXXXXXXXXXXXXXXXXXXXF`XX
 XX {XXXFXXXXXXXXXXXXXXXXXXXF'           `7XXXXXXXXXXXXXXXXXXX7XXX} XX
 `X}{XXX'7XXXFXXXXX^XXXXX `'               `' XXXXX^XXXXX7XXXF`XXX}{X'
  `'XXX' {XXX'XXXXX 7XXXF                     7XXXF XXXXX`XXX} `XXX`'
   .XX}  {XXF {XXXX}`XXX}                     {XXX'{XXXX} 7XX}  {XX.
   {XX   `XXL  `7XX} 7XX}                     {XXF {XXF'  JXX'   XX}
   `XX    `XXL mXXF  {XX                       XX}  7XXm JXX'    XX'
    XX      7XXXF    `XX                       XX'    7XXXF      XX
    XX.    JXXXX.     7X.                     .XF     .XXXXL    .XX
   {XXL    7XF7XXX.   {XX                     XX}   .XXXF7XF    JXX}
   `XXX'              `XXXm                 mXXX'              `XXX'
                       ^^^^^               ^^^^^
    .mJXXL       .JXXXXXXXXL                JXXXXXXXXL.       JXXLm.
 mXXXXmXXXL     .XXXXXXXXXXX}              {XXXXXXXXXXX.     JXXXmXXXXm
 7XXXXXXXXX}  .JXXXXXXXXXXXXX.            .XXXXXXXXXXXXXL.  {XXXXXXXXXF
    .XXXXXX'.JXXXXXXXXXXXXXXXXL          JXXXXXXXXXXXXXXXXL.`XXXXXX.
   .XXXXXXXmXXXXXXXXXXXXXXXXXXXL        JXXXXXXXXXXXXXXXXXXXmXXXXXXX.
   {XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.    .XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.  .XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXF
     7XXXXXXXXXXXXXXXXXXXXXXXXXF`XX  XX'7XXXXXXXXXXXXXXXXXXXXXXXXXF
      `7XXXXXXXXXXXXXXXXXXX7XXX} XX  XX {XXXFXXXXXXXXXXXXXXXXXXXF'
        `' XXXXX^XXXXX7XXXF`XXX}{X'  `X}{XXX'7XXXFXXXXX^XXXXX `'
           7XXXF XXXXX`XXX} `XXX`'    `'XXX' {XXX'XXXXX 7XXXF
           {XXX'{XXXX} 7XX}  {XX.      .XX}  {XXF {XXXX}`XXX}
           {XXF {XXF'  JXX'   XX}      {XX   `XXL  `7XX} 7XX}
            XX}  7XXm JXX'    XX'      `XX    `XXL mXXF  {XX
            XX'    7XXXF      XX        XX      7XXXF    `XX
           .XF     .XXXXL    .XX        XX.    JXXXX.     7X.
           XX}   .XXXF7XF    JXX}      {XXL    7XF7XXX.   {XX
         mXXX'              `XXX'      `XXX'              `XXXm
        ^^^^^                                              ^^^^^
The use of a camel image in association with Perl is a trademark of O'Reilly &
Associates, Inc. Used with permission.

```

(The copyright text is optional.)

A simpler example would take the input:

```
#######
#
#
######
      #
#     #
 #####

```

and produce:

```
 #####      #####
#     #    #     #
      #    #
######      ######
#                #
#                #
#######    #######

#######    #######
#                #
#                #
######      ######
      #    #
#     #    #     #
 #####      #####

```

The entries should demonstrate art.

This is a popularity contest, so the entry with maximum (up)votes wins!

# Answer
> 15 votes
# Bash and common utils

*You may have to install `rev`*

I wasn't satisfied with merely reflecting character positions, it really messes up ascii-art input. So I tried to reflect characters too, modulo the ascii character set.

```
#!/bin/bash
half_width=39
left='/(q[{d>Ss'
right='\\)p]}b<Zz'
up='\\`!^qwWtupSs_'
down='/,ivdmMfnbZz\-'
function callback () {
line=${2: 0: half_width}
p=$((half_width-${#line}))
printf "%s%${p}s%${p}s%s\n" \
"$line" "" "" "$(rev<<<"$line" \
| tr $left$right $right$left)" ; }
if ! [ "$1" ]; then cat < "$0"; elif
[ "$1" == "-" ]; then cat; else cat < "$1"
fi | mapfile -c1 -Ccallback -t | tee >(tac | tr $up$down $down$up)

```

With no arguments, the script prints itself reflected 2x2, as requested:

```
$ ./2x2.sh
#!/bin/bash                                                        hzad\nid\!#
half_width=39                                                    93=htbiw_flah
left='/(q[{d>Ss'                                              'zZ<b}]p)\'=tfel
right='\\)p]}b<Zz'                                          'sS>d{[q(//'=thgir
up='\\`!^qwWtupSs_'                                        '_zZqutWwp^!`//'=qu
down='/,ivdmMfnbZz\-'                                    '-/sSdnfMmbvi,\'=nwob
function callback () {                                  } () kcadllac noitcnuf
line=${2: 0: half_width}                              {htbiw_flah :0 :2}$=enil
p=$((half_width-${#line}))                          (({enil#}$-htbiw_flah))$=q
printf "%s%${p}s%${p}s%s\n" \                    / "n/z%z{q}$%z{q}$%z%" ftnirq
"$line" "" "" "$(rev<<<"$line" \              / "enil$">>>ver)$" "" "" "enil$"
| tr $left$right $right$left)" ; }          { ; "(tfel$thgir$ thgir$tfel$ rt |
if ! [ "$1" ]; then cat < "$0"; elif      file ;"0$" > tac neht ;[ "1$" ] ! fi
[ "$1" == "-" ]; then cat; else cat < "" > tac ezle ;tac neht ;[ "-" == "1$" ]
fi | mapfile -c1 -Ccallback -t | tee >()< eet | t- kcadllacC- 1c- elifqam | if
t! | wabt!le _c1 _Ccallpack _f | fee >()< eef | f_ kcaqllacC_ 1c_ el!tdaw | !t
[ "$1" == "_" ]; fheu caf; elze caf < "" > fac esle ;fac uehf ;[ "_" == "1$" ]
!t i [ "$1" ]; fheu caf < "$0"; el!t      t!le ;"0$" > fac uehf ;[ "1$" ] i t!
| fr $letf$r!ghf $r!ghf$letf)" ; }          { ; "(ftel$fhg!r$ fhg!r$ftel$ rf |
"$l!ue" "" "" "$(re^<<<"$l!ue" /              \ "eu!l$">>>^er)$" "" "" "eu!l$"
br!uft "%z%${b}z%${b}z%z/u" /                    \ "u\s%s{d}$%s{d}$%s%" tfu!rd
b=$((halt-m!qfh_${#l!ue}))                          (({eu!l#}$_hfp!m-tlah))$=d
l!ue=${2: 0: halt-m!qfh}                              {hfp!m-tlah :0 :2}$=eu!l
tnucf!ou callpack () {                                  } () kcaqllac uo!fcunt
qomu='\`!^qwWtupSs/_'                                    '_\zZqutWwp^!`/'=umop
nb='//,ivdmMfnbZz-'                                        '-sSdnfMmbvi,\\'=dn
r!ghf='//)b]}p<Ss'                                          'zZ>q{[d(\\'=fhg!r
letf='\(d[{q>Zz'                                              'sS<p}]b)/'=ftel
halt-m!qfh=39                                                    93=hfp!m-tlah
#i\p!u\pazh                                                        hsaq/u!q/i#
$

```

You may also provide in input filename:

```
$ ./2x2.sh ppcg.fig
 ____  ____   ____ ____                                ____ ____   ____  ____
|  _ \|  _ \ / ___/ ___|                              |___ \___ \ / _  |/ _  |
| |_) | |_) | |  | |  _                                _  | |  | | (_| | (_| |
|  __/|  __/| |__| |_| |                              | |_| |__| |\__  |\__  |
|_|   |_|    \____\____|                              |____/____/    |_|   |_|

|-|   |-|    /----/----|                              |----\----\    |-|   |-|
|  --\|  --\| |--| |-| |                              | |-| |--| |/--  |/--  |
| |-) | |-) | |  | |  -                                -  | |  | | (-| | (-| |
|  - /|  - / \ ---\ ---|                              |--- /--- / \ -  |\ -  |
 ----  ----   ---- ----                                ---- ----   ----  ----
$

```

If the input filename is `-`, the script will read input from stdin:

```
$ cowsay moo | ./2x2.sh -
 _____                                                                  _____
< moo >                                                                < oom >
 -----                                                                  -----
        \   ^__^                                              ^__^   /
         \  (oo)\_______                              _______/(oo)  /
            (__)\       )\/\                      /\/(       /(__)
                ||----w |                            | w----||
                ||     ||                            ||     ||
                ||     ||                            ||     ||
                ||____m |                            | m____||
            (--)/       )/\/                      \/\(       \(--)
         /  (oo)/-------                              -------\(oo)  \
        /   v--v                                              v--v   \
 _____                                                                  _____
< woo >                                                                < oow >
 -----                                                                  -----
$

```

# Answer
> 7 votes
# Ruby

This one definitely took me a while. But it was really fun!

```
#
e=
"/+
+d.f
/(.-.
e*0*,+
(*1*e/*
.-.).,*e
/+/(.c.1/
,**-c.e**+
b*,*c+d+++*
*e.+.0/*+b/+
+d/+*e/a.1/(*
0/+*e/*.-/..-/
*/+.-*1*e.d.)/(
*0*.+a.a.f.1.e*1
+b/(/-/,/+*0/+*b/
+*e/*.-/..-/*/+.-*
1";eval e.tr("#{ }
 ",'').split('').
each_slice(?\x2.
ord+0x308333+0+
-3179315).map{
#............
|x|x. join .
tr(  '(-7',
'0-9A-F').
to_i(16).
chr.ord.
chr.ord
.chr.#
chr}*
'' +
''+
''
#

```

Output:

```
#                                   #
e=                                 ''
"/+                               ''+
+d.f                             '' +
/(.-.                           chr}*
e*0*,+                         .chr.#
(*1*e/*                       chr.ord
.-.).,*e                     chr.ord.
/+/(.c.1/                   to_i(16).
,**-c.e**+                 '0-9A-F').
b*,*c+d+++*               tr(  '(-7',
*e.+.0/*+b/+             |x|x. join .
+d/+*e/a.1/(*           #............
0/+*e/*.-/..-/         -3179315).map{
*/+.-*1*e.d.)/(       ord+0x308333+0+
*0*.+a.a.f.1.e*1     each_slice(?\x2.
+b/(/-/,/+*0/+*b/    ",'').split('').
+*e/*.-/..-/*/+.-* 1";eval e.tr("#{ }
1";eval e.tr("#{ } +*e/*.-/..-/*/+.-*
 ",'').split('').   +b/(/-/,/+*0/+*b/
each_slice(?\x2.     *0*.+a.a.f.1.e*1
ord+0x308333+0+       */+.-*1*e.d.)/(
-3179315).map{         0/+*e/*.-/..-/
#............           +d/+*e/a.1/(*
|x|x. join .             *e.+.0/*+b/+
tr(  '(-7',               b*,*c+d+++*
'0-9A-F').                 ,**-c.e**+
to_i(16).                   /+/(.c.1/
chr.ord.                     .-.).,*e
chr.ord                       (*1*e/*
.chr.#                         e*0*,+
chr}*                           /(.-.
'' +                             +d.f
''+                               "/+
''                                 e=
#                                   #
#                                   #
''                                 e=
''+                               "/+
'' +                             +d.f
chr}*                           /(.-.
.chr.#                         e*0*,+
chr.ord                       (*1*e/*
chr.ord.                     .-.).,*e
to_i(16).                   /+/(.c.1/
'0-9A-F').                 ,**-c.e**+
tr(  '(-7',               b*,*c+d+++*
|x|x. join .             *e.+.0/*+b/+
#............           +d/+*e/a.1/(*
-3179315).map{         0/+*e/*.-/..-/
ord+0x308333+0+       */+.-*1*e.d.)/(
each_slice(?\x2.     *0*.+a.a.f.1.e*1
 ",'').split('').   +b/(/-/,/+*0/+*b/
1";eval e.tr("#{ } +*e/*.-/..-/*/+.-*
+*e/*.-/..-/*/+.-* 1";eval e.tr("#{ }
+b/(/-/,/+*0/+*b/    ",'').split('').
*0*.+a.a.f.1.e*1     each_slice(?\x2.
*/+.-*1*e.d.)/(       ord+0x308333+0+
0/+*e/*.-/..-/         -3179315).map{
+d/+*e/a.1/(*           #............
*e.+.0/*+b/+             |x|x. join .
b*,*c+d+++*               tr(  '(-7',
,**-c.e**+                 '0-9A-F').
/+/(.c.1/                   to_i(16).
.-.).,*e                     chr.ord.
(*1*e/*                       chr.ord
e*0*,+                         .chr.#
/(.-.                           chr}*
+d.f                             '' +
"/+                               ''+
e=                                 ''
#                                   #

```

It's based on the same idea as my previous answer.

# Answer
> 6 votes
# Ruby

**UPDATE**: Check out my new answer, based on the same idea as this one!

```
$,                                    |
   e="s=  open(  $0).r  ead.s  pli    |
   t   (  1   0  .      ch     r);    |
   $   ,  =   3  2      .      chr    |
   ;s=s.  zip(s  .      r ev   ers    |
   e      )      .      m   a         |
   p      (      &:joi  n);pu   t     |
                                      |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

```

Output:

```
$,                                    | s(s+s.reverse)";eval e.gsub(/[\s|]/,'')
   e="s=  open(  $0).r  ead.s  pli    |                                       |
   t   (  1   0  .      ch     r);    |    p      (      &:joi  n);pu   t     |
   $   ,  =   3  2      .      chr    |    e      )      .      m   a         |
   ;s=s.  zip(s  .      r ev   ers    |    ;s=s.  zip(s  .      r ev   ers    |
   e      )      .      m   a         |    $   ,  =   3  2      .      chr    |
   p      (      &:joi  n);pu   t     |    t   (  1   0  .      ch     r);    |
                                      |    e="s=  open(  $0).r  ead.s  pli    |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'') $,                                    |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'') $,                                    |
                                      |    e="s=  open(  $0).r  ead.s  pli    |
   p      (      &:joi  n);pu   t     |    t   (  1   0  .      ch     r);    |
   e      )      .      m   a         |    $   ,  =   3  2      .      chr    |
   ;s=s.  zip(s  .      r ev   ers    |    ;s=s.  zip(s  .      r ev   ers    |
   $   ,  =   3  2      .      chr    |    e      )      .      m   a         |
   t   (  1   0  .      ch     r);    |    p      (      &:joi  n);pu   t     |
   e="s=  open(  $0).r  ead.s  pli    |                                       |
$,                                    | s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

```

It's "PPCG!" in ASCII art! :D

Here's a detailed explanation. First, I found out how to do the actual mirroring. Here's the mirroring code:

```
s = open($0).read.split "\n"
$, = ' '
s = s.zip(s.reverse).map &:join
puts s + s.reverse

```

Then I had to remove whitespace characters and double quotes (because escaping just gets messy), so I used Ruby's `Fixnum#chr`.

The basic structure of the program is now:

```
e="<code>"
eval e.gsub(/\s/,'')

```

Now I can make it into ASCII art! So, that's what I did. Then, I padded the ASCII art with spaces and `|`s at the end, and I made it to here:

```
e="s=  open(  $0).r  ead.s  pli       |
t   (  1   0  .      ch     r);       |
$   ,  =   3  2      .      chr       |
;s=s.  zip(s  .      r ev   ers       |
e      )      .      m   a            |
p      (      &:joi  n);pu   t        |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

```

However, that looked a bit ugly, since there wasn't enough padding around the ASCII art. Therefore, I added a bit of extra padding, and got where I am now! (`$, | x` is equivalent to `x` since `$,` is `nil` by default.)

# Answer
> 5 votes
## bash ( + `sed` \+ `tee` \+ `tac` ) -\> 102

```
sed -re 'h;s/$/\o1/;:a;s/(.)\o1(.*)$/\o1\2\1/;ta;s/^\o1//;G;s/^(.*)\n(.*)$/\2 \1/' ${1:-$0}|tee >(tac)

```

Sample useable

```
#!/bin/bash

sed -re 'h;s/$/\o1/;:a;s/(.)\o1(.*)$/\o1\2\1/;ta;
         s/^\o1//;G;s/^(.*)\n(.*)$/\2 \1/' ${1:-$0} |
    tee >(tac)

```

Sample detailed:

```
#!/bin/bash

sed -re '
    h;         # copy current line to hold space
    s/$/\o1/;  # add chr(1) at end of line
   :a;         # branch label for further goto
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end
    ta;        # goto :a if previous `s///` do match
    s/^\o1//;  # drop chr(1)
    G;         # Append newline + hold space to current line
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to
    tee >(     # tee would double stdout and pass feed to
      tac )    # tac as reverse cat.

```

This could result as:

```
./revmir.sh
#!/bin/bash hsab/nib/!#

sed -re ' ' er- des
    h;         # copy current line to hold space ecaps dloh ot enil tnerruc ypoc #         ;h
    s/$/\o1/;  # add chr(1) at end of line enil fo dne ta )1(rhc dda #  ;/1o\/$/s
   :a;         # branch label for further goto otog rehtruf rof lebal hcnarb #         ;a:
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s
    ta;        # goto :a if previous `s///` do match hctam od `///s` suoiverp fi a: otog #        ;at
    s/^\o1//;  # drop chr(1) )1(rhc pord #  ;//1o\^/s
    G;         # Append newline + hold space to current line enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    tee >(     # tee would double stdout and pass feed to ot deef ssap dna tuodts elbuod dluow eet #     (> eet
      tac )    # tac as reverse cat. .tac esrever sa cat #    ) cat

      tac )    # tac as reverse cat. .tac esrever sa cat #    ) cat
    tee >(     # tee would double stdout and pass feed to ot deef ssap dna tuodts elbuod dluow eet #     (> eet
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s
    G;         # Append newline + hold space to current line enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G
    s/^\o1//;  # drop chr(1) )1(rhc pord #  ;//1o\^/s
    ta;        # goto :a if previous `s///` do match hctam od `///s` suoiverp fi a: otog #        ;at
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s
   :a;         # branch label for further goto otog rehtruf rof lebal hcnarb #         ;a:
    s/$/\o1/;  # add chr(1) at end of line enil fo dne ta )1(rhc dda #  ;/1o\/$/s
    h;         # copy current line to hold space ecaps dloh ot enil tnerruc ypoc #         ;h
sed -re ' ' er- des

#!/bin/bash hsab/nib/!#

```

or formated to fixed line width:

```
printf -v spc '%74s';sed "s/\$/$spc/;s/^\(.\{74\}\) *$/\1/" <revmir.sh | ./revmir.sh -

```

give:

```
#!/bin/bash                                                                                hsab/nib/!#

sed -re '                                                                                ' er- des
    h;         # copy current line to hold space                                                     ecaps dloh ot enil tnerruc ypoc #         ;h
    s/$/\o1/;  # add chr(1) at end of line                                                                 enil fo dne ta )1(rhc dda #  ;/1o\/$/s
   :a;         # branch label for further goto                                                         otog rehtruf rof lebal hcnarb #         ;a:
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end                                       dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s
    ta;        # goto :a if previous `s///` do match                                             hctam od `///s` suoiverp fi a: otog #        ;at
    s/^\o1//;  # drop chr(1)                                                                                )1(rhc pord #  ;//1o\^/s
    G;         # Append newline + hold space to current line                             enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space   ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to     ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    tee >(     # tee would double stdout and pass feed to                                   ot deef ssap dna tuodts elbuod dluow eet #     (> eet
      tac )    # tac as reverse cat.                                                                             .tac esrever sa cat #    ) cat

      tac )    # tac as reverse cat.                                                                             .tac esrever sa cat #    ) cat
    tee >(     # tee would double stdout and pass feed to                                   ot deef ssap dna tuodts elbuod dluow eet #     (> eet
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to     ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space   ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s
    G;         # Append newline + hold space to current line                             enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G
    s/^\o1//;  # drop chr(1)                                                                                )1(rhc pord #  ;//1o\^/s
    ta;        # goto :a if previous `s///` do match                                             hctam od `///s` suoiverp fi a: otog #        ;at
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end                                       dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s
   :a;         # branch label for further goto                                                         otog rehtruf rof lebal hcnarb #         ;a:
    s/$/\o1/;  # add chr(1) at end of line                                                                 enil fo dne ta )1(rhc dda #  ;/1o\/$/s
    h;         # copy current line to hold space                                                     ecaps dloh ot enil tnerruc ypoc #         ;h
sed -re '                                                                                ' er- des

#!/bin/bash                                                                                hsab/nib/!#

```

and using `figlet`:

```
figlet -f banner 5 | ./revmir.sh -
#######   #######
#               #
#               #
######     ######
      #   #
#     #   #     #
 #####     #####

 #####     #####
#     #   #     #
      #   #
######     ######
#               #
#               #
#######   #######

```

And for fun:

```
figlet -f banner Code Golf. | ./asciiReduce |  ./revmir.sh -
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄       ▄▄▄   ▗▖▄▗▖▀▀▞  ▄▄▄ ▄▄▗▖▄▗▖▀▀▞
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖       ▖▄▙   ▐▐ ▌▖▄▗▌  ▖▄▙▌  ▐▐ ▌   ▌
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█   █▐  ▌   ▐▐ ▌▌  ▌    ▌▌  ▐▐ ▌▖  ▌
▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀   ▀▝  ▘▘▀▀▝▘▀▝ ▀▀▝  ▀▀▀ ▀▀▝▘▀▝ ▀▀▝

▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀   ▀▝  ▘▘▀▀▝▘▀▝ ▀▀▝  ▀▀▀ ▀▀▝▘▀▝ ▀▀▝
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█   █▐  ▌   ▐▐ ▌▌  ▌    ▌▌  ▐▐ ▌▖  ▌
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖       ▖▄▙   ▐▐ ▌▖▄▗▌  ▖▄▙▌  ▐▐ ▌   ▌
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄       ▄▄▄   ▗▖▄▗▖▀▀▞  ▄▄▄ ▄▄▗▖▄▗▖▀▀▞

```

He, he... This could not work because of half-chars could not be simply reversed.

For this, we have to run command in reversed order:

```
figlet -f banner Code Golf. |  ./revmir.sh - | asciiReduce
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄     ▗▄▄▖  ▗ ▄▄ ▞▀▀▖ ▗▄▄▖▗▄▄ ▄▄ ▞▀▀▖
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖      ▄▄▌  ▐▐  ▌▄▄ ▌  ▄▄▌▌ ▐▐  ▌   ▌
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█ ▐█   ▌  ▐▐  ▌▌  ▌    ▌▌ ▐▐  ▌▖  ▌
▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀ ▝▀   ▘▀▀▀ ▀▀ ▝▀▀  ▝▀▀▘▝▀▀ ▀▀ ▝▀▀
▗▄▄ ▗▄▖▗▄▄ ▄▄▄  ▗▄▄ ▗▄▖▗▄▄▖▖  ▗▄ ▗▄   ▖▄▄▄ ▄▄ ▗▄▄  ▗▄▄▖▗▄▄ ▄▄ ▗▄▄
▌  ▘▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█ ▐█   ▌  ▐▐  ▌▌  ▌    ▌▌ ▐▐  ▌▘  ▌
▌   ▌ ▐▐  ▌▛▀▘  ▌▝▀▘▌ ▐▐   ▛▀▘      ▀▀▌  ▐▐  ▌▀▀ ▌  ▀▀▌▌ ▐▐  ▌   ▌
▚▄▄▘▝▀▘▝▀▀ ▀▀▀  ▚▄▄▘▝▀▘▝   ▀▀▀     ▝▀▀▘  ▝ ▀▀ ▚▄▄▘ ▝▀▀▘▝▀▀ ▀▀ ▚▄▄▘

```

# Answer
> 2 votes
# C++

```
#include<iostream>
int main()
{
    char mirror[]={ 218,196,196,196,196,196,191,
                    218,196,196,196,196,196,191,'\n',
                    179,201,205,203,205,187,179,
                    179,201,205,203,205,187,179,'\n',
                    179,186,254,186,254,186,179,
                    179,186,254,186,254,186,179,'\n',
                    179,204,205,206,205,185,179,
                    179,204,205,206,205,185,179,'\n',
                    179,186,254,186,254,186,179,
                    179,186,254,186,254,186,179,'\n',
                    179,200,205,202,205,188,179,
                    179,200,205,202,205,188,179,'\n',
                    192,196,196,196,196,196,217,
                    192,196,196,196,196,196,217,'\n',
                    '\0'};
    std::cout<<mirror<<mirror;
    getch();
    return 0;
}

```

### output

This output looks like "Windows 4X4".

>

---
Tags: popularity-contest, source-layout
---