title: AppleSauce Fader

text:
# Question
Title: AppleSauce Fader
Back in the day, all the 1337 kids used text faders in chatrooms. I don't know about you guys, but I want to feel cool like they did. The only problem is that their old scripts and applications were heavily coupled to the software they were made for, so I can't just make use of this amazing functionality wherever I want. I also want the solution to be easily portable so you're going to need to make the code as small as possible so that it will fit on my floppy disk (I'd rather only carry one floppy but if your source code is too big I can carry more than one :P).

## Input

* A list of colors (rgb, hex, names, etc)
* Text to format

Your program should expect the list of colors to contain at least 2 colors.
Text to format can be any length greater than zero and characters will be limited to printable ascii. (Hint: Longer text inputs may require you to reuse intermediate colors for consecutive characters)

## Output

The output text should not differ from the input text in any way other than font and/or markup/styling (Note: if your output contains html markup then you'll need to html encode the input). You may output text with markup/styling (html style tags, console colors, etc.) or a picture of the faded text. All color hexes should be present in the output unless the input does not contain enough characters to meet this requirement. If this is the case, then consult the priority rules to determine which color hexes should be present in your output. **The order or these colors in your output should still be input order.**

### Color Priority Rules

1. In the event that the input is one character, the first color will be used
2. In the event that there are only two characters, the first and last color will be used
3. In the event that there are more than three colors and more colors than characters, the first and last colors should be prioritized, then the rest of the colors in their inputted order.
4. In the event that there are more characters than colors, the characters should fade from one color to the next using intermediate colors

Examples (Priority rules 1-3 respectively):
\# Colors | Color0 | ... | Colorn | Text
`3 ff0000 0000ff ffff00 M` -\>
`3 ff0000 0000ff ffff00 hi` -\>
`4 ff0000 0000ff ffff00 0fff00 sup` -\>

To be clear, the text color should fade from one color hex to the next. The fade does not have to be perfectly uniform but it shouldn't be an abrupt color change unless there aren't enough characters to fade nicely. Generally this fade is achieved by choosing intermediate colors for each of the characters by incrementing/decrementing the rgb values by some interval determined by the number of characters you have to work with and the difference between the colors. For example if we needed a single color between  (#ff0000) and  (#000000), we might choose  as it sits right in the middle. Optimal output will look rather pretty.

Example (Priority rule 4):
`3 ff0000 ff7f00 f0ff00 To be or not to be, that is the question...` -\>
**-OR-**

```
<span style="color:#ff0000;">T</span><span style="color:#ff0600;">o</span><span style="color:#ff0c00;"> </span><span style="color:#ff1200;">b</span><span style="color:#ff1800;">e</span><span style="color:#ff1e00;"> </span><span style="color:#ff2400;">o</span><span style="color:#ff2a00;">r</span><span style="color:#ff3000;"> </span><span style="color:#ff3600;">n</span><span style="color:#ff3c00;">o</span><span style="color:#ff4300;">t</span><span style="color:#ff4900;"> </span><span style="color:#ff4f00;">t</span><span style="color:#ff5500;">o</span><span style="color:#ff5b00;"> </span><span style="color:#ff6100;">b</span><span style="color:#ff6700;">e</span><span style="color:#ff6d00;">,</span><span style="color:#ff7300;"> </span><span style="color:#ff7900;">t</span><span style="color:#ff7f00;">h</span><span style="color:#fe8500;">a</span><span style="color:#fe8b00;">t</span><span style="color:#fd9100;"> </span><span style="color:#fc9700;">i</span><span style="color:#fb9d00;">s</span><span style="color:#fba400;"> </span><span style="color:#faaa00;">t</span><span style="color:#f9b000;">h</span><span style="color:#f9b600;">e</span><span style="color:#f8bc00;"> </span><span style="color:#f7c200;">q</span><span style="color:#f6c800;">u</span><span style="color:#f6ce00;">e</span><span style="color:#f5d400;">s</span><span style="color:#f4da00;">t</span><span style="color:#f4e100;">i</span><span style="color:#f3e700;">o</span><span style="color:#f2ed00;">n</span><span style="color:#f1f300;">.</span><span style="color:#f1f900;">.</span><span style="color:#f0ff00;">.</span>

```

**In your answer please specify how your output should be displayed (as html, in a console, as an image, etc.).**

* All black backgrounds are only for color emphasis and are not required

## Scoring

This is , so the shortest answer (in bytes) wins.
If you manage to add fade to individual characters then I'll forever think you're cool (but no bonus to score as this will not be fair for some langs)

# Answer
> 3 votes
## JavaScript (ES6), 290 bytes

```
h=a=>f(a,a.shift());f=
(a,w)=>[...w].map((c,i)=>{l=w.length-1;m=a.length-1;s=o.appendChild(document.createElement('span'));s.textContent=c;s.style.color=`#${i?i-l?a[r=l%m,n=l/m|0,i<r*n+r?++n:i-=r,k=i/n|0,k++].replace(/./g,(c,d)=>((parseInt(c,16)*(n-i%n)+i%n*parseInt(a[k][d],16))/n|0).toString(16)):a[m]:a[0]}`;})
```

```
<textarea rows=10 cols=40 oninput="o.textContent='';h(this.value.split`\n`)">Type the text here and the colours on subsequent lines.
FF0000
00FF00
0000FF</textarea><div id=o>
```

# Answer
> 1 votes
## Java, ~~702~~ 662 characters

Two functions golfed:

```
import java.awt.*;String f(Color C,char c){return"<span style=\"color:#"+Integer.toHexString(C.getRGB()).substring(2)+";\">"+c+"</span>";}String c(String t,String[]h){String r="";int l=h.length,e=t.length(),i=0,s=0,g=1,c=-1,p,q,u;double d,m=0,v;char[]T=t.toCharArray();Color C[]=new Color[l],H[],a,b;for(;i<l;)C[i]=Color.decode(h[i++]);if(l>e){H=java.util.Arrays.copyOfRange(C,0,e);H[e-1]=C[l-1];H[0]=C[0];C=H;l=e;}d=--e/(l-1.);for(;++c<e;){a=C[s];b=C[g];p=b.getRed()-a.getRed();q=b.getGreen()-a.getGreen();u=b.getBlue()-a.getBlue();v=m/d;r+=f(new Color(a.getRGB()+((int)(v*p)<<16|(int)(v*q)<<8|(int)(v*u))),T[c]);if(++m>d){m-=d;s=g++;}}return r+f(C[l-1],T[e]);}

```

As nobody can read this: here are both functions in there ungolfed version in a class:

```
import java.awt.*;

public class Q80554 {

    static String format(Color color, char character) {
        return "<span style=\"color:#" + Integer.toHexString(color.getRGB()).substring(2) + ";\">" + character + "</span>";
    }

    static String colorizeB(String text, String[] hexColors) {
        String result = "";
        int colorsLength = hexColors.length, textLength = text.length(), i, currentStartColorPos = 0, currentGoalColorPos = 1, currentCharPos = -1, diffColorRed, diffColorGreen, diffColorBlue;
        double difference, goneDifference = 0, relativeChange;
        char[] textArray = text.toCharArray();
        Color colors[] = new Color[colorsLength], changer[], currentStartColor, currentGoalColor;

        for (i = 0; i < colorsLength;)
            colors[i] = Color.decode(hexColors[i++]);

        if (colorsLength > textLength) {
            changer = Arrays.copyOfRange(colors, 0, textLength);
            changer[textLength - 1] = colors[colorsLength - 1];
            changer[0] = colors[0];

            colors = changer;
            colorsLength = textLength;
        }

        // fade
        difference = --textLength / (colorsLength - 1.); // space between colors

        for (; ++currentCharPos < textLength;) {
            currentStartColor = colors[currentStartColorPos];
            currentGoalColor = colors[currentGoalColorPos];

            diffColorRed = currentGoalColor.getRed() - currentStartColor.getRed();
            diffColorGreen = currentGoalColor.getGreen() - currentStartColor.getGreen();
            diffColorBlue = currentGoalColor.getBlue() - currentStartColor.getBlue();

            relativeChange = goneDifference / difference;

            result += format(new Color(currentStartColor.getRGB() + ((int) (relativeChange * diffColorRed) << 16 | (int) (relativeChange * diffColorGreen) << 8 | (int) (relativeChange * diffColorBlue))), textArray[currentCharPos]);

            if (++goneDifference > difference) {
                goneDifference -= difference;
                currentStartColorPos = currentGoalColorPos++;
            }
        }

        // last character always has last color
        return result + format(colors[colorsLength - 1], textArray[textLength]);
    }
}

```

Here you have an upper bound for your own code. Usage is by calling `colorize` (or c in the golfed version) and pass the text and an array of hex color codes. The function will return a String with HTML-tags like the OP did, thus you need some way to render the HTML.

The algorithm is easier as the question looks like. The first character always gets the first color, the last one always the last. ~~If we have more colors than chars in the text we just iterate over the text and colors and apply these.~~ The fun part is the one with the fades: I started of by finding out in what distance the colors are on the text. I basically calculate the red, green and blue difference between two given colors and then add a part of this difference to the first color, depending on where the char is between the colors. If it leaves the interval of two colors we start from new with the next two colors. This is repeated for all but the last character, which we know is always the last color. This gives a very beautiful fading.

That question was very much fun! Thanks!

### Updates

Now I don't handle all the cases specially. Instead I trim the colors if there are two much and apply the fade function to every string. If there were more colors than text then the colors will be trimmed and the fading function will work exactly as a simple mapping.

# Answer
> 1 votes
# Pyth, 126 bytes

Obligatory root-mean-square average instead of direct arithmetic mean.

```
L%"<span style=\"color:#%s\">%s</span>",smt.H+256s*255@d2ebhbMm+hG*-eGhGcdHH=Q^RL2Q+smsyMC,hdCgRlhdCedC,ctlQPzC,QtQy,ez?tlzeQh

```

Try it online!

Sample output:

---
Tags: code-golf
---


title: Parse a 1D language

text:
# Question
Title: Parse a 1D language
Given a string containing only 0's 1's, 2's and brackets, output the grammar tree of the string.

A `2` requires 2 arguments - one to the left and one to the right

A `1` requires a single argument - to either the left or right

A `0` doesn't require any arguments and is the base case

A pair of brackets counts as one argument and the contents of the brackets are evaluated separately from the rest of the string. Nested brackets are possible

A input string will always be a complete tree with no characters falling off. The string will also only have a single correct solution. Note that the functions are commutative and any arrangement of arguments for `2` will be acceptable. You will not have to handle input that doesn't conform to these requirements.

The output grammar format will be in the form `function(arguments)` recursively

### Test cases

```
0 --> 0
01 --> 1(0)
020 --> 2(0,0)
101 --> 1(1(0))
0120 --> 2(1(0),0)
0120210 --> 2(1(0),2(0,1(0)))
01210 --> 2(1(0),1(0))
(020)210 --> 2(2(0,0),1(0))
((020)20)1 --> 1(2(0,2(0,0)))

```

# Answer
> 3 votes
## Python 3.6 (pre-release), 199

Saved 6 bytes thanks to Morgan Thrapp

```
import re
def f(s):s=s.strip('()');i,j=[m.start()if m else-1for m in(re.search(c+'(?![^(]*\))',s)for c in'21')];return i>0and f'2({f(s[:i])},{f(s[i+1:])})'or j>=0and f'1({f(s[:j])or f(s[j+1:])})'or s

```

Explanation & ungolfed version:

```
import re

def f(s):
    s=s.strip('()')
    # Search for '2' and '1' outside of brackets
    i, j = [m.start() if m else -1
            for m in (re.search(c + '(?![^(]*\))', s) for c in '21')]

    if i > 0:
        # Call `f(s[:i])` and `f(s[i+1:])`, concatenate the results
        return f'2({f(s[:i])},{f(s[i+1:])})'
    elif j>=0:
        # Call `f(s[:j])` and `f(s[j+1:])`, choose the non-empty result
        return f'1({f(s[:j]) or f(s[j+1:])})'
    else:
        return s

```

---
Tags: code-golf, parsing
---


title: Will the beam hit?

text:
# Question
Title: Will the beam hit?
A laser shoots a straight beam in one of the four orthogonal directions, indicated by `<>^v`. Determine whether it will hit the target `O` on a rectangular grid.

Each of these will hit (True):

```
.....
...O.
.....
...^.
.....

>O.
...

v....
O....

...........
...........
O.........<
...........

```

These will miss (False):

```
......
......
.^..O.

......
.....>
O.....
......
......

.O.
...
.v.

.....<.
..O....

```

**Input:** A rectangular grid of `.`, sized at least 2x2, with exactly one target `O` and one laser that's one of `<>^v`. The lines can be a list of strings, a 2D array or nested list of characters, or a single newline-separated string with an optional trailing newline.

**Output**: A consistent truthy value if the laser beam hits the target, and a consistent falsy value if it misses.

I'll consider submissions that don't use regular expressions (or built-in pattern-based string matching) as a separate category. If you put `(no regex)` after the language name, your answer will appear separately in the leaderboard.

```
var QUESTION_ID=80196,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/80196/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://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
# Snails, 19 bytes

```
\>|\<l|\^u|\vd).,\O

```

The spec for this one can be implemented as literally as possible, no thinking required.
> 27 votes

# Answer
# Retina, ~~56~~ ~~52~~ ~~42~~ ~~38~~ ~~31~~ 30 bytes

*Saved 1 byte thanks to @MartinBüttner*

```
O.*<|>.*O|[vO](.*¶)[^O]*[O^]\1

```

Abuses properties of rectangles. Requires input to have a trailing newline.

Try it online

## Explanation

This works in three parts:

* Matching `>`
* Matching `<`
* Matching `^` and `v` this is because the logic for `^` and `v` are really the same, just the characters.

**Validating `<`**

This is simple:

```
O.*<

```

This matches an `O`, optionally followed by non-newline chars, then a `<`

**Validating `>`**

This is much the same as the previous way except the other way around. First a `>` is matched, then the `O`

**Validating `^` and `v`**

This was difficult to golf and took adverting of the input always being valid. First, we match whether it's `v` or an `O`:

```
[vO]

```

If it's an `^`, the first character that's encountered should be a `O`. So, this matches the first character to match. Next we count the amount of `.`s following it up to the newline:

```
(.*\n)

```

Next, this can go into two parts, I'll cover the first:

So first, we match until the following `O`, using:

```
[^O]*O

```

This optionally matches all non-`O` characters until an `O` is encountered, if this is successful, then it continues... if not, then the following happens...

Now, it attempts to find the `^` using:

```
[^^]*\^

```

`^` is a special character in regex so it needs to be escaped. `[^^]` matches all characters except `^`, this works the same as the above, if this succeeds, then the following happens...

So now, one of the above has matched succesfully, the `\1` checks and sees if the capture group from before `(.*\n)`, this capture group stored the amount of `.`s there were after either the `v` or `O` from before, so now `\1` just checks if the amount of dots in the same.
> 13 votes

# Answer
# Java (no regex), ~~413~~ ~~412~~ ~~246~~ ~~242~~ ~~212~~ ~~211~~ ~~209~~ 198 bytes

Competing in golf challenges using java has less sense than take a part in Formula 1 race on bicycle, but I'm not always doing thinks which makes any sense.

Here is my extremely long java solution Golfed version

```
boolean l(char[][]w){int[]t={},l={};for(int y=0;y<w.length;y++)for(int x=0;x<w[0].length;x++){if(w[y][x]=='O')t=new int[]{x,y};if(w[y][x]=='<')l=new int[]{x,y,1};if(w[y][x]=='>')l=new int[]{x,y,2};if(w[y][x]=='v')l=new int[]{x,y,3};if(w[y][x]=='^')l=new int[]{x,y,4};};return(l[2]==1&&l[1]==t[1]&&l[0]>t[0])||(l[2]==2&&l[1]==t[1]&&l[0]<t[0])||(l[2]==3&&l[0]==t[0]&&l[1]<t[1])||(l[2]==4&&l[0]==t[0]&&l[1]>t[1]);}

```

and ungolfed

```
boolean l(char[][] w) {
    int[] t = {}, l = {};
    for (int y = 0; y < w.length; y++)
        for (int x = 0; x < w[0].length; x++) {
            if (w[y][x] == 'O')
                t = new int[] { x, y };
            if (w[y][x] == '<')
                l = new int[] { x, y, 1 };
            if (w[y][x] == '>')
                l = new int[] { x, y, 2 };
            if (w[y][x] == 'v')
                l = new int[] { x, y, 3 };
            if (w[y][x] == '^')
                l = new int[] { x, y, 4 };
        }
    ;
    return (l[2] == 1 && l[1] == t[1] && l[0] > t[0])
            || (l[2] == 2 && l[1] == t[1] && l[0] < t[0])
            || (l[2] == 3 && l[0] == t[0] && l[1] < t[1])
            || (l[2] == 4 && l[0] == t[0] && l[1] > t[1]);
}

```

Seems like my entire concept was wrong, here is my shorter solution

```
boolean z(char[][]w){int x=0,y=0,i=0,a=w.length,b=w[0].length;for(;w[y][x]!=79;)if(++y==a){y=0;x++;}for(;i<(a<b?b:a);)if(i<b&w[y][i]==(i<x?62:60)|i<a&w[i][x]==(i++<y?'v':94))return 1<2;return 1>2;}

```

and ungolfed version

```
oolean z(char[][] w) {
        int x = 0, y = 0, i = 0, a = w.length, b = w[0].length;
        for (; w[y][x] != 79;)
            if (++y == a) {
                y = 0;
                x++;
            }
        for (; i < (a < b ? b : a);)
            if (i < b & w[y][i] == (i < x ? 62 : 60) | i < a
                    & w[i][x] == (i++ < y ? 'v' : 94))
                return 1 < 2;
        return 1 > 2;
    }

```

**EDIT** I rewrote code for looking for 'O', now it contains single loop is much shorter, and I also used @Frozn suggestion to replace some of characters with their ascii values.

In result,another 30 bytes bites the dust.

Another suggestion from @Frozn, and we are couple bytes closer to Python solution

Another rewrite drop one loop, and combine two if statements
> 9 votes

# Answer
# MATL (no regex), ~~26~~ ~~25~~ ~~24~~ 22 bytes

```
'>v<^'XJymfX!tZpYswJm)

```

Try it Online!

Modified version for all test cases

**Explanation**

```
        % Implicitly grab input
'>v<^'  % String literal indicating the direction chars
XJ      % Store in the J clipboard
y       % Copy the input from the bottom of the stack
m       % Check to see which of the direction chars is in the input. The
        % result is a 1 x 4 logical array with a 1 for the found direction char
f       % Get the 1-based index into '>v<^' of this character
X!      % Rotate the input board 90 degrees N times where N is the index. This
        % Way we rotate the board so that, regardless of the direction char,
        % the direction char should always be BELOW the target in the same column
t       % Duplicate
Zp      % Determine if any elements are prime ('O' is the only prime)
Ys      % Compute the cumulative sum of each column
w       % Flip the top two stack elements
J       % Grab '>v<^' from clipboard J
m       % Create a logical matrix the size of the input where it is 1 where
        % the direction char is and 0 otherwise
)       % Use this to index into the output of the cumulative sum. If the
        % direction char is below 'O' in a column, this will yield a 1 and 0 otherwise
        % Implicitly display the result

```
> 7 votes

# Answer
# CJam (no regex), 25

Earlier versions were wrong, this will have to do for now:

```
q~_z]{'.-HbI%}f%[HF].&~+,

```

Try it online

**Explanation:**

```
q~         read and evaluate the input (given as an array of strings)
_z         copy and transpose
]          put the original grid and transposed grid in an array
{…}f%      map the block to each grid (applying it to each string in each grid)
  '.-      remove all dots (obtaining a string of 0 to 2 chars)
  Hb       convert to base H=17, e.g. ">O" -> 62*17+79=1133
  I%       calculate modulo I=18
[HF]       make an array [17 15]
.&         set-intersect the first array (mapped grid) with 17 and 2nd one with 15
~+         dump and concatenate the results
,          get the array length

```

I tried a few mathematical formulas for distinguishing between "good" and "bad" strings, and for each type of formula I tried plugging in various numbers. I ended up with the `HbI%` above.

"good" strings for the original grid are "\>O" and "O\<" and they give the result 17
"good" strings for the transposed grid are "vO" and "O^" and they give the result 15
"bad" strings for both grids are: "\>", "\<", "^", "v", "O", "", "O\>", "Ov", "\<O", "^O" and they give the results 8, 6, 4, 10, 7, 0, 1, 3, 1, 3
> 5 votes

# Answer
# Python 3 (no regex), 184 bytes.

Hooray for eval hacking!

```
def f(a,o=0,d={},q=''):
 for r in a:
  i=0
  for c in r:d[c]=o,i;i+=1;q=(c,q)[c in'O.']
  o+=1
 z,y=d['O'];e,j=d[q];return eval("z%se and y%sj"%(('><'[q<'v'],'=='),('==',q))[q in'><'])

```
> 3 votes

# Answer
# TSQL (sqlserver 2012) (no regex), 358 bytes

```
DECLARE @ varchar(1000)=
'......'+ CHAR(13)+CHAR(10)+
'......'+ CHAR(13)+CHAR(10)+
'...0..'+ CHAR(13)+CHAR(10)+
'...^..'+ CHAR(13)+CHAR(10)
;

WITH C as(SELECT
number n,SUBSTRING(@,number,1)a,1+min(IIF(SUBSTRING(@,number,1)=char(13),number,99))over()m
FROM master..spt_values
WHERE'P'=type and
SUBSTRING(@,number,1)in('>','<','^','v','0',char(13)))SELECT
IIF(c.n%c.m=d.n%c.m and c.a+d.a in('0^','v0')or
c.n/c.m=d.n/c.m and c.a+d.a in('>0','0<'),1,0)FROM c,c d
WHERE c.n<d.n and char(13)not in(c.a,d.a)

```

Had to use funky linechange in the declaration to force the online version to execute it(assigning values to input variables doesn't affect the length calculation anyway)

Try it online!
> 3 votes

# Answer
# Pyth, 43 bytes

```
KxJ"^<v>"h@Js.z}\Ohc_W>K1hf}@JKTCW!%K2.z@JK

```

Live demo.
> 2 votes

# Answer
# Ruby, ~~71~~ ~~55~~ 54 bytes

Regex solution, which means that it's probably going to be easily beaten by Retina or Perl.

Returns an index number (truthy) if there is a match.

Now with a similar trick to @Downgoat Retina answer, matching for down and up beams at the same time.

```
->m{m=~/>\.*O|O\.*<|(?=[vO])(.{#{??+m=~/\n/}})+[O^]/m}

```
> 2 votes

# Answer
## JavaScript (ES6), 78 bytes

```
s=>s.match(`>.*O|O.*<|(?=v)([^]{${l=s.search`\n`+1}})+O|(?=O)([^]{${l}})+\\^`)

```

Regexp of course. Turned out to be similar in principle to the Ruby answer.
> 2 votes

# Answer
## JavaScript (ES6) (no regex), 126 bytes

```
s=>([n,o,l,r,u,d]=[..."\nO<>^"].map(c=>1+s.indexOf(c)),l>o&l-o<n&l%n>o%n||r&&r<o&o-r<n&r%n<o%n||u>o&u%n==o%n||d&&d<o&d%n==o%n)

```

Where `\n` represents the literal newline character.
> 2 votes

# Answer
# Julia (no regex), 98

```
a->(c=rotr90(a,findlast("i1Q/",sum(a-46)));
    f(n)=find(any(c.!='.',n));b=c[f(2),f(1)];
    (b'*b)[1]==97)

```

Function operating on an array of chars, normalizing by rotation, removing rows and columns containing only dots by range indexing and finally checking for location of 'O' taking into account if the remainder b is a column or row vector using matrix multiplication.

Try it online
> 2 votes

# Answer
## Clojure (no regex), 293 bytes

```
(defn z[f](let[v(sort(keep-indexed(fn[i v](if(some #{v}[\v\>\<\^\O])[(if(= v\O)\& v)i]))f))l(+(.indexOf f"\n")1)d((nth v 1)0)q((nth v 1)1)p((nth v 0)1)r(=(quot p l)(quot q l))i(> q p)](cond(= d\^)(and i(=(mod(- q p)l)0))(= d\v)(and(not i)(=(mod(- p q)l)0))(= d\>)(and(not i)r):else(and i r))))

```

Doesn't feel great. Straightforward solution, finding the index of corresponding characters and calculating if they're on the same line.

You can try it here https://ideone.com/m4f2ra
> 2 votes

# Answer
# Python (no regex), 105 bytes

```
def f(s):t=s.strip('.\n');return not['\n'in t,len(t)%(s.find('\n')+1)!=1,1]['>O<vO^'.find(t[0]+t[-1])//3]

```

returns True or False

First, strips '.' and '\n' from the ends so that the characters of interest, '0\<\>v^', are the first and last characters.

`'>O<vO^'.find(t[0]+t[-1])//3` \- checks if the characters are a potentially valid arrangement. Evaluates to 0 for '\>O' or 'O\<', to 1 for 'vO' or 'O^', and to -1 for anything else.

`'\n'in t` \- checks if the characters are in different rows,
`len(t)%(s.find('\n')+1)!=1` \- checks if they are in different columns, and
`1` \- is the default

The `not` inverts the result selected from the list, so the `return` expression is equivalent to:

```
t[0]+t[-1] in '>0<' and '\n' not in t or t[0]+t[-1] in 'vO^' and len(t)%(s.find('\n')+1)==1

```
> 2 votes

# Answer
## Python 2 (no regex), 268 bytes

```
import numpy
def q(i):
 s=numpy.asmatrix(i)
 for n in s:
  n=n.tolist()[0]
  try:
   a=n.index("0")
   if n.index(">")<a or n.index("<")>a:return 1
  except:0
 for n in range(len(i)):
  c=[x[0] for x in s[:,n].tolist()]
  try:
   a=c.index("0")
   if c.index("v")<a or c.index("^")>a:return 1
  except:0
 return 0

```

Truthy and Falsy values returned by the function are 1 and 0, respectively.

I haven't had a chance to golf yet. Honestly, I'm not too hopeful for this one...

Any suggestions would be greatly appreciated!
> 1 votes

# Answer
# C# (No Regex), 282 bytes

```
bool F(char[,]b){int k=0,l=1,m=1,n=0,o=0;for(int x=0;x<b.GetLength(0);x++)for(int y=0;y<b.GetLength(1);y++){char i=b[x,y];if(i=='O'){k=x;l=y;}if(new[]{'<','>','^','v'}.Contains(i)){m=x;n=y;o=i;}}return(o==60&&k==m&&l<n)||(o==62&&k==m&&l>n)||(o==94&&l==n&&k<m)||(o==118&&l==n&&k>m);}

```

Works like the java version but transpiled and reduced

### Expanded (Explanation included):

```
bool F(char[,] b)
{
    // declare variables for goal x, goal y, laser x, laser y, and laser direction respectively (laser direction is char code for directions)
    int k = 0, l = 0, m = 0, n = 0, o = 0;
    // go through each cell
    for (int x = 0; x < b.GetLength(0); x++)
    {
        for (int y = 0; y < b.GetLength(1); y++)
        {
            // get cell contents
            char i = b[x, y];
            // set goal position if goal
            if (i == 'O')
            {
                k = x;
                l = y;
            }
            // set laser position and direction if laser
            if (new[]{ '<', '>', '^', 'v' }.Contains(i))
            {
                m = x;
                n = y;
                o = i;
            }
        }
    }
    // check everything is on the same line and in right direction
    return (o == 60 && k == m && l < n) ||
           (o == 62 && k == m && l > n) ||
           (o == 94 && l == n && k < m) ||
           (o == 118 && l == n && k > m);
}

```
> 1 votes

# Answer
# C (ANSI) (No regex), 237 bytes

```
#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}i--;x--;z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));return z;}

```

Expanded:

```
#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{
    for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)
        if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}
    i--;x--;
    z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));
    printf("%i\n",z);
    return z;
}

```

I think I took a decently different approach here compared to the Java or C# implementations. I got coordinates of the 'O' and arrow ((c,d) and (x,y)) and then compared them to see if the arrow was pointing in the correct direction.

Returns 0 if false and 1 if true
> 0 votes

# Answer
## Grime v0.1, 31 bytes

```
n`\>.*a|a.*\<|\v/./*/a|a/./*/\^

```

Not a very interesting solution. Prints `1` for truthy instances, and `0` for falsy ones. Try it online!

## Explanation

We simply search the input rectangle for a minimal-size (n×1 or 1×n) pattern that contains the laser and target in the correct order. The `n`` flag makes the interpreter print the number of matches, of which there will always be at most one. The rest of the line consists of four patterns separated by `|`-characters, which means a logical OR: a rectangle is matched if it matches one of the patterns. The patterns work as follows:

```
\>.*a    Literal ">", horizontal row of any chars, one alphabetic char
a.*\<    One alphabetic char, horizontal row of any chars, literal "<"
\v/./*/a Literal "v", on top of vertical column of any chars, on top of one alphabetic char
a/./*/\^ One alphabetic char, on top of vertical column of any chars, on top of literal "^"

```
> 0 votes

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


title: Look and Say sequence in any base

text:
# Question
Title: Look and Say sequence in any base
We all already crossed the look and say sequence, and where asked to guess the next element. As its name tells it very well, you just have to say what you see :

```
1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
3 1 2 2 1 1
...

```

But, what if we had to use a different base to describe it? You could count it in base 3 as this OEIS squence do. You could even do it in whatever base you want! That will be your job in this challenge.

## Goal

Your have to write a program or a function that will accept two integers as input, either by STDIN or as function arguments. The first one will be the base `b` you have to work in, the second one will be the number `n` of elements to output. As this sequence never changes for `b>=4`, you will assume `0<b<5`.

The only restriction you have is to NOT use any base-converison built-in :).

The original sequence (in base 10) is the sequence A005150. It cannot be constructed simply by using a formula, so you can help yourself with the different implementations present on the sequence's page.

## Sample output

Here are the first 10 elements for each b

```
for b=1:
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111

for b=2:
1
11
101
111011
11110101
100110111011
111001011011110101
111100111010110100110111011
100110011110111010110111001011011110101
1110010110010011011110111010110111100111010110100110111011

for b=3:
1
11
21
1211
111221
1012211
1110112221
101102110211
111021101221101221
1011012211011222110112211

for b=4:
1
11
21
1211
111221
312211
13112211
1113212221
311312113211
132113111221131221

```

You can use whatever formating you want as long it is readable (so you could output it in Python-like lists, separated by commas/newline...).

This is code-golf, so the shortest code in byte wins. Have fun !

# Answer
# Pyth, 34 bytes

```
L?gbQ+y/bQ%bQ]bjms`Md.usyMsrN8tE]1

```

Try it online!
> 1 votes

---
Tags: code-golf, sequence, base-conversion
---


title: Get the most dominant color!

text:
# Question
Title: Get the most dominant color!
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

---

**Input**

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only `.png` extension.

---

**Output**

The most dominant color in any format. (But it should be accurate, you can't return `Red` for `#f88379`). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

---

**Test Cases**

**=\>** Red/#ff0000/rgba(255,0,0)

.

**=\>** "Equal"

**=\>** White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

---

**Note** *If your language contains a built-in for this, then you must NOT use it.* Please add a screenshot or a link to a screenshot to prove that your program works.

---

This is , so the shortest answer in bytes wins!

# Answer
> 4 votes
# Pyth, 18 bytes

FGITW.

```
?tJeM.MhZrS'Q8\=hJ

```

This is how it would theoretically work offline.

This is a proof that it works.

The two links differ by whether there is a "read file command" `'` (single-quote).

# Answer
> 4 votes
# JavaScript (ES6), ~~301~~ ~~328~~ 312 bytes

```
(u,b)=>{i=new Image;i.src=u;e=document.createElement`canvas`;c=e.getContext`2d`;i.onload=_=>{w=e.width=i.width;h=e.height=i.height;c.drawImage(i,0,0);d=c.getImageData(0,0,w,h).data;for(o={},i=0;i<d.length;)++o[s=d.slice(i,i+=4)]?0:o[s]=1;b(o[(a=Object.keys(o).sort((a,b)=>o[b]-o[a]))[0]]==o[a[1]]?"Equal":a[0])}}

```

Feel free to golf further, this feels as long as Java to me personally.

This supports transparent images so alpha channel is included in output value.

*The reason it's longer than before is because now that I've tested, ~~it requires~~* ~~`Image` *to contain the attribute* `crossOrigin`*, and*~~ *the arguments to* `getImageData()` *are not optional.*

See Meta PCG for removal of CORS from byte count.

## Usage

```
f("http://i.imgur.com/H5OmRVh.jpg", alert)

```

That will asynchronously `alert` a color quadruplet or "Equal" after the image is loaded and counted.

The callback is not considered part of the program length because it is allowed as input by the OP in this special case.

## How it works

It constructs an `Image`, a `Canvas`, and a `CanvasRenderingContext2D`, then draws the image to the canvas after setting its `width` and `height` correctly. It then counts occurrences of each color by implicitly converting each quadruplet to a string and generating a hash of counters. After that, it sorts the hash keys by descending count before comparing the highest two occurrences and determining whether to return the first quadruplet string in the sorted array or the string `"Equal"`.

*If the demo below displays a* `SecurityError`*, the domain of the image URL you chose does not support CORS.*

## Demo

```
f = (u, b) => {
  let i = new Image;
  i.crossOrigin = ''; // CORS added for demo
  i.src = u;
  let e = document.createElement `canvas`;
  let c = e.getContext `2d`;
  i.onload = _ => {
    w = e.width = i.width;
    h = e.height = i.height;
    c.drawImage(i, 0, 0);
    d = c.getImageData(0, 0, w, h).data;
    for (o = {}, i = 0; i < d.length;)
      ++o[s = d.slice(i, i += 4)] ? 0 : o[s] = 1;
    b(o[(a = Object.keys(o).sort((a, b) => o[b] - o[a]))[0]] == o[a[1]] ? "Equal" : a[0])
  }
}
l = i => {
  let p = i.nextElementSibling;
  p.src = i.value;
  f(`http://crossorigin.me/${i.value}`, c => p.nextElementSibling.value = c);
}
document.getElementById `i`.addEventListener('update', e => {
  l(e.target)
})
Array.prototype.slice.call(document.querySelectorAll`.i`, 0, 3).forEach(l)
```

```
input {
  display: block;
  box-sizing: border-box;
  width: 205px;
  height: 18px;
}

input.o {
  position: relative;
  top: -36px;
}

img {
  display: block;
  position: relative;
  box-sizing: border-box;
  top: -18px;
  left: 209px;
  height: 40px;
}
```

```
<input class=i disabled value="https://i.stack.imgur.com/rqsAX.png">
<img>
<input class=o disabled>
<input class=i disabled value="https://i.stack.imgur.com/KECpJ.png">
<img>
<input class=o disabled>
<input class=i disabled value="https://i.stack.imgur.com/DRCWd.png">
<img>
<input class=o disabled>
<input class=i id=i placeholder="Try any image!">
<img>
<input class=o id=o disabled>
```

# Answer
> 3 votes
# MATL, ~~30~~ ~~26~~ 23 bytes

Save some bytes by using mode with explicit output specification `6#XM`.

```
2#YiwX:6#XMgY)tn3>?x'='

```

Previously (26 byte solution)

```
2#YiwX:S&Y'tX>=Y)tn3>?x'='

```

Doesn't work online, because of `imread`. `imread` can take a path or directly read a url.

Explanation:

```
2#Yi       % read image, returns a matrix of colours, and a matrix
           % that indexes each pixel to the corresponding row of the colour matrix
w          % swap elements in stack
X:         % linearize index matrix to column array
6#XMg      % use mode to find most common colour indices, convert to matrix (g)
Y)         % get corresponding rows of colour matrix
tn3>       % duplicate and see if it has more than 3 elements
?          % if there is more than one most common colour
x          % delete most common colours from stack
'='        % push string onto stack
           % implicitly finish loop and display stack contents

```

Output is, for the first image, `1 0 0` (RGB triple), for the second `=`, and for the third, `1 1 1`. For example, a screenshot form Matlab:

Note that you need to escape string delimiters when running MATL code from the Matlab command window, hence the `''=''`. The `>` indicates MATL is asking for user input, in this I gave it the URL of the first test case, and the result is `1 0 0`.

# Answer
> 3 votes
# Python 3, 186 Bytes

```
from PIL import Image;from collections import*;c=Counter(Image.open(input()).convert("RGB").getdata());d=c.most_common();print("equal") if d[0][1]==d[1][1] else print(c.most_common()[0])

```

Image 1 prints: `((255, 0, 0), 139876)`
Image 2 prints: `equal`
Image 3 prints: `((255, 255, 255), 101809)`

Ungolfed:
```
from PIL import Image
from collections import *
c = Counter(Image.open(input()).convert("RGB").getdata())
d = c.most_common()
print("equal") if d[0][1] == d[1][1] else print(c.most_common()[0])

```

Proof:

# Answer
> 2 votes
# Unix tools + imagemagick, 122 bytes

```
convert png:- ppm:-|tail -n +4|xxd -c3 -p|sort|uniq -c|sort -n|tail -n2|awk '{S[NR]=$1}END{print S[1]==S[2]?"equal":S[2]}'

```

Expects the input png in stdin, prints the most dominant color in hex (RRGGBB) format.

**How it works**:

* `convert png:- ppm:-` converts a png file to binary P6 ppm format
* `tail -n +4` skips the ppm header
* `xxd -c3 -p` puts every RGB byte triplets on a new line in hex format
* `sort|uniq -c|sort -n` orders the colors by their number of occurrence
* `tail -n2` gets the two most dominant colors
* `awk ...`: prints the more dominant color or equal

# Answer
> 2 votes
## PowerShell v2+, 215 bytes

```
$a=New-Object System.Drawing.Bitmap $args[0]
$b=@{}
0..($a.Height-1)|%{$h=$_;0..($a.Width-1)|%{$b[$a.GetPixel($_,$h).Name]++}}
if(($c=$b.GetEnumerator()|Sort value)[-1].value-eq$c[-2].value){"Equal";exit}$c[-1].Name

```

<sub>(Newlines/semicolons are equivalent, so newlines left in for clarity)</sub>

Creates a new Bitmap object, based on the input argument, stores it to `$a`. Creates a new empty hashtable `$b`, which will be used for our pixel counting.

We then loop over the image a row at a time with two loops `%{...}`. Each inner loop we use the `.GetPixel` method to return a `Color` object for the particular x/y coordinate we're at. We take the `.Name` of that color (which is a hexadecimal of the form ARGB, for example `ffff0000` would be pure red fully opaque) and use that as the index into `$b`, incrementing that particular value by one.

So, we've now got a fully populated hashtable of pixel colors, with the values of each entry corresponding to how many pixels of that color there are. We then take `$b` and pump it through a `Sort` based on those values, and store that sorted result back into `$c`. If the last `[-1]` and second-to-last `[-2]` `value`s are equal, we output `"Equal"` and `exit`. Else, we output the `.Name` of the last `[-1]` entry.

# Answer
> 1 votes
## Clojure, 204 bytes

```
(fn[n](let[p(javax.imageio.ImageIO/read(java.net.URL. n))w(.getWidth p)[[_ x][y z]](take-last 2(sort-by peek(frequencies(. p(getRGB 0 0 w(.getHeight p)nil 0 w)))))](if(= x z)(print"EQUAL")(printf"%x"y))))

```

prints colors as aarrggbb

Clojure isn't really great at golfing, but it's a fun language :)

proof screenshot: https://i.stack.imgur.com/vPgoq.png

ungolfed:

```
(fn[n]
  (let [p (javax.imageio.ImageIO/read (java.net.URL. n))
        w (.getWidth p)
        a (. p (getRGB 0 0 w (.getHeight p) nil 0 w))
        [[_ x] [y z]] (take-last 2 (sort-by peek (frequencies a)))]
    (if (= x z)
      (print "EQUAL")
      (printf "%x" y)))))

```

---
Tags: code-golf, image-processing
---


# Question
Title: Shortest program that demonstrates a language's complete syntax
## The Challenge

Write the shortest possible program that demonstrates a programming language's entire syntax: statements, expressions, operators, reserved words, etc.

Take the language's grammar (usually in EBNF) and create a program that uses all of it.

The program doesn't have to do anything particularly useful, but if it does that's a bonus :)

## Rules

* You must use all of the language's syntax: every type of statement, expression, operator, keyword, etc the language defines.
* It must be able to be run with no dependencies, except for the standard library included with the language (it doesn't need to use the entire standard lib though).
* Include a link to the language spec you used (e.g. here is the Python 2.7 grammar).

# Answer
> 9 votes
## Jot (2 chars)

```
10

```

http://semarch.linguistics.fas.nyu.edu/barker/Iota/#Goedel

# Answer
> 5 votes
## Brainfuck:

```
.[->+<],

```

with the syntax being:

```
S=> '.'S|','S|'>'S|'<'S|'-'S|'+'S|'['S']'S|emptyStr

```

# Answer
> 5 votes
## HQ9+ (4 chars)

```
HQ9+

```

It will print Hello World, then Quine, then 99 bottles of beer on the wall and then increment accumulator.

# Answer
> 5 votes
## Unary 1

```
0

```

With the syntax being

```
P => 0+

```

(syntax is technically more complicated, but I'm too lazy to figure out binary to unary conversion as an EBNF)

# Answer
> 5 votes
# Ook

```
Ook! Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook!

```

Ook. Ook. Ook. Ook. Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook.

# Answer
> 4 votes
## SK combinator calculus (4 chars)

```
K(S)

```

Grammar:

```
E ::= K | S | (E) | EE |

```

# Answer
> 2 votes
## Lambda calculus (9 chars)

```
λx. (x y)

```

### Grammar

```
E ::= Letter | (E E) | 'λ' Letter '. ' E
Letter ::= 'a' | 'b' | ... | 'z'

```

Looks how much more verbose than SK this is!

# Answer
> 2 votes
# Lisp (2 chars)

```
()

```

Of course, there are built in functions, such as `defun` and the basic arithmetic functions, but again, those are FUNCTIONS.

# Answer
> 1 votes
## Python 2 (13 chars)

Not sure if this is allowed:

```
exec(input())

```

**Example 1:**

Input: `'print "Hello World!"'`

Output: `Hello World!`

**Example 2:**

Input: `'import math; print math.pi'`

Output: `3.14159265359`

# Answer
> 1 votes
# Blub

```
Blub! Blub. Blub! Blub? Blub! Blub! Blub. Blub? Blub. Blub. Blub? Blub. Blub? Blub! Blub. Blub!

```

Output:

```
Blub. Blub. Blub. Blub. Blub! Blub? Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub! Blub! Blub? Blub! Blub. Blub? Blub! Blub? Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub? Blub. Blub! Blub! Blub? Blub! Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub. Blub. Blub. Blub. Blub. Blub. Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub. Blub. Blub? Blub! Blub. Blub. Blub? Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub! Blub.

```

# Answer
> 0 votes
# Seed, 3 chars

```
5 7

```

This seeds a Mersenne Twister with the number 7 and uses it to create a 5-character Befunge program.

---
Tags: code-golf
---


# Question
Title: Surjective, Injective, Bijective, or Nothing?
Given a mapping from the integers from 1 to N to the integers from 1 to N, determine if the mapping is surjective, injective, bijective, or nothing.

You may choose any character/digit for the four outputs.

# Specs

Input format: `n, arrays of pairs` (`n` is the highest number in the domain and range)

For example, if the first number is `3`, then both the domain and the co-domain are `{1,2,3}`.

For example, `{i+1 | i from 1 to 9}` (n=10) is represented by `10, [[1,2],[2,3],...,[9,10]]`.

The input **may** contain duplicate.

# Testcases

```
2, [[1,2],[2,1]] => bijective
2, [[1,1],[1,2]] => surjective
3, [[1,1]] => injective
3, [[1,2],[2,3]] => injective
4, [[1,2],[2,2],[3,2],[4,2]] => nothing
2, [[1,2],[1,2]] => injective
3, [[1,1],[1,2],[1,3]] => surjective
2, [[1,1],[1,1],[2,2]] => bijective

```

# Answer
> 1 votes
# Pyth - ~~10~~ ~~9~~ 13 bytes

```
im&{IdqSQSdE2

```

Takes domain and codomain separately as allowed by comments in OP.

Test Suite.

# Answer
> 1 votes
# Pyth, 15 bytes

```
+!-SQJeC{E*2{IJ

```

The output is identified by:

```
nothing   : 0
surjective: 1
injective : 2
bijective : 3

```

In pseudocode,

```
                  Q=input()                 # pre-initialized var, 'n'
+                 sum(                      # sur=1,in=2,thus bi=sur+in=3,no=0
 !                  not(                    # if 'filtrate'=[], true/surjective
  -SQ                 filter(range(1,Q),    # filter codomain by range
     JeC{E              J=transpose(deduplicate(input()))[-1]
                    ))  # find the "redundant" range, may corrspnd to diffrnt args
 *2{IJ              2*invariant(J,deduplicate)
                  ) # if J(redundnt range) invariant undr dduplicatn, true/injectiv

```

Test suite

Currently, the test suite returns two False's, namely for case 2 and case -2 (second-to-last). This has to do with the definition of "injective", and will be discussed with the OP.

# Answer
> 0 votes
# Python, ~~85~~ 82 bytes

The methodology here is basically:

* Remove duplicate points
* Check if the cardinality of the image of the domain + cardinality of domain is equal to twice the number of points
    + If true -\> injective -\> return 1
* Check if the cardinality of the image of the domain is equal to the cardinality of the codomain
    + If true -\> surjective -\> return 2
* If both true -\> bijective -\> return 3
* If neither -\> nothing -\> return 0

```
def f(n,t):l=len;d,c=zip(*set(t));x=l(set(c));return(x+l(set(d))==l(c)*2)+(x==n)*2

```

---

## Test Cases

```
print(f(2, [(1,2),(2,1)])==3)# => bijective
print(f(2, [(1,1),(1,2)])==2)# => surjective
print(f(3, [(1,1)])==1)# => injective
print(f(3, [(1,2),(2,3)])==1)# => injective
print(f(4, [(1,2),(2,2),(3,2),(4,2)])==0)# => nothing
print(f(2, [(1,2),(1,2)])==1)# => injective
print(f(3, [(1,1),(1,2),(1,3)])==2)# => surjective
print(f(2, [(1,1),(1,1),(2,2)])==3)# => bijective

```

---

**Update**

* **-3** \[16-05-26\] Multiplied by 2 instead of adding

---
Tags: code-golf, number-theory
---