title: Write a Binding Greeter

text:
# Question
Title: Write a Binding Greeter
You will write a Program which writes the Second Program.

Each program has one Input; which may be a command line argument, or be read from stdin. A Input is a single word made up of upper and/or lowercase letters (a-z)

Each program has Output; which may be to a file, or to stdout.

The Program (which you post here)

* accepts the Input Greeting, e.g. "Hello"
* the Output contains the source code of another program, which is described below

The Second Program

* accepts a Input of Name, e.g. "John"
* MUST NOT contain the Greeting in a format that could be read by an average computer programmer
* when executed makes the Output in the format of `{Greeting} {Name}`, e.g. "Hello John"
* MUST NOT use an encoding library or function, including but not limited to

+ base64/base32/baseN (unless manually implemented)
    + cryptography (unless manually implemented)

*"not be read by an average computer programmer"* is ambiguous, but here are some examples for the Greeting "Hello". Use common sense, and I'll downvote if you do one of those *Well he didn't say "He" + "ll" + "o" was against the rules*

* Good

+ "Dqkta"
    + \[9,3,5,1,6,1,5\]
    + ↛↝↧
    + a^|12..7
    + ..--..--!!--.--.----.-,,--.
* Bad

+ "Hello"
    + "hEllo"
    + "h3110"
    + "He" + "llo"
    + \["H", "e", "l", "l", "o"\]
    + "H\_e\_l\_l\_o"

---

Scoring:

* usual codegolf, least bytes wins
* addition command line arguments cost the usual 1 point
    + no command line arguments allowed for the Second Program
* scoring only applies to the first Program (the one you post here)

Please also include an example generated program and a description. If you're confused, see my example answer bellow.

# Answer
> 2 votes
### GolfScript, 15 / 11 characters

```
{)}%`'{(}%" "@'

```

Performs the same obfuscation as the example program. The resulting code for input `Howdy` is then

```
"Ipxez"{(}%" "@

```

For both programs input must be supplied on STDIN while output goes to STDOUT.

If it's ok to convert the string to codes only you can also take the 11 character solution

```
{}/32]`'\+'

```

(Thanks to Peter for an idea to save two more characters).

# Answer
> 6 votes
## APL(Dyalog), 16/20

Losing to GS again...

```
'⍞,⍨⊂⎕UCS',⎕UCS⍞

```

This may break the "no cryptography" rule. `⎕UCS` is a function to convert characters to unicode code points and back.

**Example**
First input: `Hello`
First output: `⍞,⍨⊂⎕UCS 72 101 108 108 111`
Second input: `John`
Second output: `Hello John` (Note the space before "Hello")

---

```
'⎕AV[','],⊂⍞',⍨⎕AV⍳⍞

```

Similar idea with the cryptography is manually implemented: Convert to/from index of some pre-defined character array (`⎕AV`) which includes all upper and lower alphabets.

# Answer
> 3 votes
## Tcl, 111

```
puts "binary scan [join [lmap a [split $argv {}] {format %c [expr [scan $a %c]+256]}] {}]Ġ\$argv a* a;puts \$a"

```

Exploits the way how Tcl converts strings to bytearrays.

The output for `Howdy` is

```
binary scan ňůŷŤŹĠ$argv a* a;puts $a

```

# Answer
> 3 votes
## R ~~113~~ ~~109~~ 97 characters

```
cat(unlist(sapply(utf8ToInt(scan(,"",n=1)),function(x)c(rep("+",x),".>"))),rep("+",32),".>+[,.]")

```

Takes an input as stdin and output a BrainF\**k program that prints the input of the first program, a space and then takes a second input and output it, character by character, until an EOF character (or an empty input depending on the BF interpreter used).

Example output with first input `Salut`:

```
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]

```

which you can test here.
Initial input can include printable ASCII characters from `!` onwards (spaces don't work because by default `scan()` uses spaces as separators). Example for `$!"§&`:

```
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]

```

# Answer
> 3 votes
# Brainfuck ~~122 120 109~~ 106

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

```

# Answer
> 2 votes
Here's a simple example. It's not competitive, but shows how it should work. This is JavaScript which runs on Node.js

```
var i, charCode, Greeting = process.argv[2], obfuscated = '';

// We're just doing a regular upshift of characters
// a becomes b, etc.
for ( i = 0; i < Greeting.length; i++ ) {
    charCode = Greeting.charCodeAt(i);
    obfuscated += String.fromCharCode(charCode + 1);
}

// You'll want to compress this somehow
var code = [
    "var i, deObfuscated = '';", "var Name = process.argv[2];", "var Greeting = '" + obfuscated + "';",
    "for (i=0; i<Greeting.length; i++) {", "charCode = Greeting.charCodeAt(i);",
    "deObfuscated += String.fromCharCode(charCode - 1);}", "console.log(deObfuscated + ' ' + Name)"];

console.log(code.join('\n'));

```

I'll call this file Program.js. It can be tested like so:

```
$ node Program.js Howdy > Second.js
$ node Second.js Partner
Howdy Partner

```

Second.js contains this. Notice how "Howdy" doesn't appear visibly in this code.

```
var i, deObfuscated = '';
var Name = process.argv[2];
var Greeting = 'Ipxez';
for (i=0; i<Greeting.length; i++) {
charCode = Greeting.charCodeAt(i);
deObfuscated += String.fromCharCode(charCode - 1);}
console.log(deObfuscated + ' ' + Name)

```

# Answer
> 2 votes
## Ruby, 63

```
$><<"puts ''<<"+gets.chop.each_codepoint.to_a*'<<'+"<<' '+gets"

```

Output for `Hello`:

```
puts ''<<72<<101<<108<<108<<111<<' '+gets

```

Output for `asdfASDF1234!@#$<>,.`:

```
puts ''<<97<<115<<100<<102<<65<<83<<68<<70<<49<<50<<51<<52<<33<<64<<35<<36<<60<<62<<44<<46<<' '+gets

```

# Answer
> 1 votes
# PHP, 58 ~~61~~ ~~64~~ ~~74~~ Bytes

```
<?=0?~0 ." $argv[1]":strtr(file(__FILE__)[0],[~$argv[1]]);

```

The script replaces all `0` in its own source code with the inverted greeting. If run as `php greeter.php Hello`, the output is:

```
<?=ÀÜôôÉ?~ÀÜôôÉ ." $argv[1]":strtr(file(__FILE__)[ÀÜôôÉ],[~$argv[1]]);

```

If you run this as `php greeter2.php John`, the output with full error reporting is

```
PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
Hello John

```

otherwise, just `Hello John`

---
Tags: code-golf
---


title: Theme of my birthday: up in flames

text:
# Question
Title: Theme of my birthday: up in flames
I need to light some candles. In fact, I need to light an *arbitrary* amount of candles. But only the good ones.

**OBJECTIVE** Given a block of text (containing lit, valid, and invalid candles) and a number `N` as input, write a program or function that lights an amount exactly equal to `N`, minus the number of already-lit candles. If `N` is greater than the number of valid candles, the program should print the number of missing, valid candles. If no candles are present, the output should be `:(`.

Here are some valid candles:

```
.
|   .       .
|   |   .   \
|   |   |   /

```

(ending with a `.`, containing only `|` or balanced, not necessarily adjacent `\` and `/`, can be of any length.)

Here are some invalid candles:

```
.       .   .   .
\       |   |   |
|           |   |
\   .   |   !

```

(unbalanced `\`, no candle stick, disconnected, non-`|` characters, not planted on the ground.)

A lit candle will replace the `.` on a valid candle with any of the following characters (your choice):

```
@ ^ & " ~

```

You must use at least one, and you get a `-10%` bonus for each character used in your program, in such a way that each character can appear on a lit candle. If you use the  emoji, you get a `-15` byte bonus, which is applied before the percentage bonuses, if used. ***THE BYTE COUNT IS ROUNDED DOWN!***

This is a , so the shortest code in bytes wins.

## Example IOs

```
input: 8,
.         .
| . ! . . |.  . . .
| | | | | | | | | |
output:
@         @
| @ ! @ @ |.  @ @ @
| | | | | | | | | |
input: 14,
   // nothing
output: :(
input: 15,
.   ..  . .  ". .
| . ||  | |  || !
output: 9 // more candles required; 15 - (6 unlit) = 9 (thanks to @AndersKaseorg for catching my mistakes (plural)!)
input: 7,
.
/        ~
|        \  .
/  &   " /  |
\  | @ | | . . . . .
\  | | | | | 1 l I |
output:
&
/        ~
|        \  .
/  &   " /  |
\  | @ | | ^ . . .
\  | | | | | 1 l I |
input: 5,
. .             |
i Q no candl es . |3-.
output: :(

```

## Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
# Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
# Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
# Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the leaderboard snippet:

```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=59664,OVERRIDE_USER=8478;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
> 4 votes
# Haskell, ⌊(269 bytes − 15) · 0.9⁵⌋ = 149

```
h('.',0)(e:f,c,o)=(f,2:c,e:o)
h(k,b)(f,c,o)|Just x<-lookup k$zip"\\|/"[4,0..]=(f,x+2*div b 2:c,k:o)|0<1=(f,2:c,k:o)
g l(f,c,o)=foldr h(f,[],'\n':o)$zip l c
d("",_,o)=o
d('@':_,_,_)=":("
d(f,_,_)=show$length f
f n=d.foldr g(take n$'@':cycle"^&\"~",repeat 1,"").lines

```

Example run:

```
*Main> putStr s
.
/        ~
|        \  .
/  &   " /  |
\  | @ | | . . . . .
\  | | | | | 1 l I |
*Main> putStr (f 3 s)
^
/        ~
|        \  .
/  &   " /  |
\  | @ | |  . . . @
\  | | | | | 1 l I |

```

Assumes that each input line is at least as long as the previous line, as allowed by one of the author’s comments.

# Answer
> 5 votes
# Python 2, 529 bytes with bonus, 303

* Assumes that the first line has an integer on it.
* Doesn't assume consistent spacing. Doesn't assume candles' column is empty.

Strategy:

* Get input as list.
* Reverse it and map it to a list of columns.
* Test and operate.
* Map it back into rows, reverse it, join the lines.

```
import re;R=raw_input;C=str.count;G=lambda x:[y if y else' 'for y in x];H=lambda x:[''.join(G(v))for v in map(None,*x)];F=re.findall;t,r,i,g,d=0,u"~\"&^@",[],r'^[|/\\]+[%s](?=\s|$)',R()
while d:i+=[d];d=R()
c=int(F('\d+',i.pop(0))[0]);i=i[::-1];m=H(i)
t+=sum(1 for x in m if F(g%r,x))
for p,n in enumerate(m):
 try:b=F(g%'\.',n)[0]
 except:continue
 if C(b,'/')==C(b,'\\')and t<c:t+=1;m[p]=re.sub('\.',r[0],n,1)
 if len(r)>1:r=r[1:]
m='\n'.join(H(m)[::-1])
d=":("if t<1 else`c-t`+" more candles required"if t<c else m;print d

```

Tests:

```
5,
*      *               *
  *        *
*
                 *
@     @       @     @
|     |   .   |     |
|     |   |   |     |

```

```
*      *               *
  *        *
*
                 *
@     @       @     @
|     |     |     |
|     |   |   |     |

```

---

```
3,
. . .
| \ |

```

```
1 more candles required

```

---

```
3,
. . .

. .      .
| |      |

```

```
. . .

 ~      "
| |      |

```

# Answer
> 3 votes
# JavaScript (ES6), 328 bytes (score: 184)

I tried to beat the Haskell solution but that's actually a pretty competitive entry given all of the logic that needs to happen.

Score calculated as:`Math.floor((328-15)*Math.pow(0.9,5))`, bytes counted in a file with UTF-8 encoding, tested and confirmed with `io.js --harmony_arrow_functions`.

**Solution**:

```
eval("(n,s)=>{q=x=>x[0].map((_,c)=>x#[c]));h='Q';c=5;t=n;m=q(s.split('\\n')X#.match(/^ *[Q][\\\\//|]+$/)&&xR\\L==xR/L&&t-->0?xR./,c>1?h[c--]:'@'):x);return t==n?':(':t>0?1+t:q(mX.join('\\n')R@/,'')}"[k='replace'](/[A-Z]/g,x=>({X:"#.split('')))#.join(''))",R:"[k](/\\",Q:'.@^&"~',L:"/g,'').length"}[x]))[k](/#/g,'.map(x=>x'))

```

**Requirements**: the array must be space-padded to be rectangular.

**Explanation**: all of the eval insanity sets one variable (the variable `k` to the string `replace` to save some bytes) and shaves 11 bytes off of a 339-byte string, which I can un-golf as:

```
(num_candles_desired, string) => {
    transpose = array => array[0].map((_, index) => array.map(row => row[index]));
    candle_tips = '.@^&"~';
    c = 5; // decrementing index into candle_tips when > 1.
    candles_left = num_candles_desired;
    transposed_normal_output = transpose(
            string.split('\n').map(line => line.split(''))
        ).map(col_array => col_array.join(''))
         // the next map does the actual logic: finds possible candles with
         // a regex, checks that the \ chars match the / chars in number,
         // then decrements the candles_left index while changing the . to a
         // lit flame.
         .map(col => col.match(/^ *[.@^&"~][\\//|]+$/)
                   && col.replace(/\\/g,'').length == col.replace(/\//g,'').length
                   && candles_left-- > 0 ? x.replace(/\./, c > 1 ? candle_tips[c--]
                                                                 : '~')
                                         : x);
    return candles_left == num_candles_desired ? ':('
                  : candles_left > 0 ? 1 + candles_left
                  : transpose(
                        transposed_normal_output.map(col => col.split(''))
                    ).map(row_array => row_array.join('')).join('\n')
                     // as promised, we include the emoji at least once if we can.
                     // the leading backslash is unnecessary and comes from the
                     // above metaprogramming-compression with eval().
                     .replace(/\@/,'')
}

```

Since example I/Os were requested, here was the test suite I ran,

```
Reference example #1, lighting 8 candles...
Input:
.         .
| . ! . . |.  . . .
| | | | | | | | | |
Output:
~
| " ! & ^ |.  @ @ @
| | | | | | | | | |
Reference example #2, lighting 14 candles...
Input:

Output:
:(
Reference example #3, lighting 15 candles...
Input:
.   ..  . .  ". .
| . ||  | |  || !
Output:
9
Reference example #4, lighting 7 candles...
Input:
.
/        ~
|        \  .
/  &   " /  |
\  | @ | | . . . . .
\  | | | | | 1 l I |
Output:
~
/        ~
|        \  .
/  &   " /  |
\  |  | | @ . . . @
\  | | | | | 1 l I |
Reference example #5, lighting 5 candles...
Input:
. .             |
i Q no candl es . |3-.
Output:
:(

```

---
Tags: code-golf, ascii-art
---


# Question
Title: How many languages can you use simultaneously in ONE functioning program in under 500 bytes
# Intro

In `Objective-C` (a superset of `C` and an object-oriented language), I can create an object called a `UIWebView`. There is a method for this object called `loadHTMLString:` in which I can load actual `HTML` into the `UIWebView` object itself. I can also inject Javascript into it using the method `stringByEvaluatingJavaScriptFromString:`.

If I were to write a program that created a UIWebView, loaded in my string (which happens to be HTML "code") and then injected a second string (which is Javascript code) I would be using 3 languages at once, in a functional program. (Not sure that `html` is really a programming language... so that's debatable haha)

You can also do things like embed `Python` into `C` (and other languages): https://docs.python.org/2/extending/embedding.html

---

This isn't too difficult, with any language you can use other languages inside it if you try hard enough.

---

# Challenge

The challenge here is to see how many languages you can cram into 1 functioning program in under 500 bytes. https://mothereff.in/byte-counter

The program can do literally any task, it just has to work. The languages all have to work together, so you can't have 2 languages running one task, and 3 other languages running a completely different task. So whatever your "task" may be (you decide), there should only be 1 task, and all `n` languages should work on just that 1 task in your 1 program.

---

# Objective

Your score is the number of languages you used. Whoever uses the most languages at once gets a cookie.

Since this is a popularity contest I will be accepting the answer with the most up-votes.

---

# Q&A

•Ray **asked**, "Just to clarify, you're looking for a program that uses multiple languages to accomplish different parts of a single task, as opposed to a polyglot that is a valid program in multiple languages?" ***Answer**, "Yes".*

•DanielM. **asked**, "does Regex count?" ***Answer**, "Yes, I personally WOULD count it. Again, this is a popularity contest, so it really is up to the voters to determine. HTML is not considered a programming language by some, but it has been successfully used in an answer already that has seen quite a few upvotes. (Also, Stack-overflow does define Regex as a programming language if that helps you make your decision to use it or not: https://stackoverflow.com/tags/regex/info)*

# Answer
# make, sh, awk, sed, regex, yacc, lex, C; 8 languages.

## Including the input and output languages: brainfuck and D; 10 languages

This is a brainfuck to D compiler. It takes the brainfuck program over standard input and prints the D code to standard output.

Make uses awk, sed, and sh to generate a yacc program, which in conjunction with a lex program is used to generate a C program that takes a brainfuck program as input and outputs an equivalent D program. I tried to only use languages in ways that were actually useful, instead of just throwing in a bunch of no-ops. The lex/yacc/C combination is fairly standard for simple compilers, the make/sh combination is useful for building, and the awk/sed line was the only way I could get the whole thing under 500 bytes. (It's at 498 bytes currently.)

## Code

```
define L
%%
[][+-<>.,] return *yytext;
. ;
%%
endef
define Y
%{
#include <stdio.h>
%}
%left '+' '-' '.' ',' '>' '<' '[' ']'
%%
q: q q {}
+ p[i]++
- p[i]--
> i++
< i--
, p[i]=getchar()
. putchar(p[i])
[ while(p[i]){
] }
%%
yywrap(){}yyerror(){}main(){puts("import std.stdio;int p[30000];int i;void main(){");yyparse();puts("}");}
endef
export L
export Y
a:
    @echo "$$L">y;lex y;echo "$$Y"|awk '/^[+-^]/{printf("q: X%sX {puts(\"%s;\");}\n",$$1,$$2)} /^[^+-^]/'|sed "y/X/'/">y;yacc y;cc *.c;./a.out;:

```

## Example of use

```
$ cat helloworld.bf
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
$ make < helloworld.bf > tmp.d
y: warning: 8 shift/reduce conflicts [-Wconflicts-sr]
$ dmd tmp.d && ./tmp
Hello World!

```
> 9 votes

# Answer
# HTML, CSS, PHP, JavaScript, CoffeeScript, RegEx, sed, bash; 8 languages

Displays colors of the rainbow.

*(Only 396 bytes)* will try to add more languages

HTML + CSS is turning complete and counts as a valid language on PPCG. I've been told CoffeeScript is different enough as JavaScript to be counted as a separate language. And RegEx has been specifically allowed also.

PHP allows for addition of many languages especially with `exec` and `shell_exec` functions.

Golfed to fit inside byte limit (ES6)

```
<html><style><?php foreach(explode(" ",exec('sed "s/;/ /g"<<<"red;orange;yellow;green;blue;violet"')) as $color){echo "#{$color} { color: $color }\n"}?></style><script>b="red orange yellow green blue violet".split(/ /).map(c=>`<p id="${c}">${c}</p>`)</script><script type="text/coffeescript">document.documentElement.innerHTML+=b.join "\n"</script><script src="http://v.ht/u31R"></script></html>
```

Uses:

* PHP to generate CSS
* PHP, uses exec to run bash
* sed to split color items for bash
* CSS to specify text colors
* JavaScript to generate elements
* RegEx to split color items for JS
* CoffeScript to print elements
* HTML as a wrapper / output

---

Faster & Ungolfed (All modern browsers)

```
<html>
<style>
  /* CSS */
  <?php// Loop through all colors
  foreach(explode(" ",
  exec('sed "s/;/ /g"<<<"red;orange;yellow;green;blue;violet"')) as $color) {
    // Print it out, add it to the CSS
    echo"#{$color} { color: $color }\n"}
 ?>
</style>

<script>
  // Create an element for each color, store as variable
  window.colors = "red orange yellow green blue violet".split(/ /).map(function(color) {
    return "<p id=\"" + color + "\">" + color + "</p>"
  });
</script>

<script type="text/coffeescript">
  document.documentElement.innerHTML += window.colors.join "\n"
</script>

<!-- CoffeScript Link -->
<script src="https://raw.githubusercontent.com/jashkenas/coffeescript/master/extras/coffee-script.js"></script>

</html>
```
> 9 votes

---
Tags: popularity-contest
---