XKCD: Keyboard Mash Anomalies Another XKCD inspired competition.
This one is based on Keyboard Mash.

Given a input string, identify the anomalous characters, assuming that the majority have been typed on a single row of the standard US QWERTY keyboard.
Input strings can contain shifted key strokes, but they will not contain carriage returns (Enter), CTRL/ALT affected characters, spaces, tabs and backspaces (because that would be silly).
The number pad will not be considered as part of the keyboard for this challenge.

The challenge is to output the characters that aren't on the same keyboard row as the majority of individual characters in the single string.  The output should contain each anomalous character only once and no other characters.

In the case of a equal count of anomalous characters across two or more rows, the tie break is determined in this order:

Shortest unique list
Top most row

Input

A string through either STDIN, ARGV or a function parameter

Output

A string to STDOUT or a function return.  It should have each anomalous character only once, but does not need to be ordered.

Examples

  Input: FJAFJKLDSKF7KFDJ  Output: 7

  Input: ASDF11111 Output: ASDF

  Input: lkjrhsDdftkjhrksRjd  Output: rtR

  Input: }*3%&2098@$2k234#@$M  Output: }

  Topmost row list returned  Input: ASD!@#Vcx  Output: !@#

  Shortest unique list returned  Input: ASdf1233qwER  Output: 123

  Topmost shortest list returned  Input: 12334QWTTSDFDSXVVBBX  Output: QWT

This is code golf, so shortest entry wins.

CJam, 111 89 88 86 84 83 bytes

la9*~"{}qwertyuiop ;':asdfghjkl ,./<>?zxcvbnm"{_32^}%_'ÿ,^a\S%+{[f&s\e|__|]:,}$0=&

Try it online in the CJam interpreter.

How it works

la9*~     e# Push the input 9 times on the stack.

"{}qwertyuiop ;':<STX>asdfghjkl ,./<>?zxcvbnm"

{_32^}%   e# XOR a copy of each character with 32.
_'<DEL>,^ e# Push a string of all ASCII characters that are missing.
a\        e# Wrap it in an array.
S%+       e# Split the string at spaces and concatenate with the array.
{         e# Sort the chunks according to the following:
  [       e#
    f&s   e# Push the string of characters from the input that are in this chunk.
    \e|   e# If the result is empty, replace it with the input.
    __|   e# Push a copy with duplicates removed.
  ]       e# Collect both strings in an array.
  :,      e# Replace each string with its length.
}$        e#
0=        e# Retrieve the minimum.
&         e# Intersect it with the input.


Fix the Meeesesessessesseesseessedessed upp teeexexextext This is inspired by Monday Mini-Golf #6: Meeesesessess upp teeexexextext

Background

ETHproductions have difficulty entering text on his usual webpage. Whenever he use digits or letters, the text will be meeesesessessesseesseessedessed up. Your task is to help him type so the normal behavior is achieved.

The transform

The transform affects runs of alphanumeric ([0-9A-Za-z]) characters delimited by any nonalphanumeric characters. In the following example, the first line would be transformed into the second (the other lines show the breakdown of the transform)

An12num:
Annn1n12n12nn12nn12nun12nun12numn12num
A
 nn
   n1
     n12
        n12nn12n
                n12nun12nu
                          n12numn12num

In particular, any alphanumeric character after the first in a run will be transformed into the entire run so far except for the first character. Furthermore, if the character is a letter (as opposed to a digit), the character will be turned into twice the run.

Thankfully, backspace will delete last character and also resets the beginning of the run.

Task

This time your task is not to perform the transformation. Instead, given an input string, you must return an encoded text that, if transformed, will result in the input. The output must be as short as possible, where \<char> counted as a single character.

Text is encoded as follows:

\                   -> \\
backspace character -> \b
linefeed            -> \n

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.

Test cases

Each test case is two lines, the first being input, the second output.

Heeeeeelp me. It shouldn't be messed up.
Hee \blp\b me\b. It\b sh\bou\bld\bn't be\b me\bss\bed\b up\b.

alert("Hello, world!");
al\ber\bt("He\bll\bo, wo\brl\bd!");

1223234234523456
123456

CJam, 207

{_,1>{:E1<_0{:I2$,+E=:C+:R1>C'9>)*+:P,E,<{EP#{L0}{PRI)1}?}{PE#L{R8cP,E,-*+}?0}?}g}&}:U;LqS+'a+{_'[,_el^A,s+&,V={+}{s\V!:V{L{:BU_aL?B,,1>Bf{_2$<U_{_W=8>S8c+*+\@>j+}{?;}?}+{,}$0=}j}|\}?}%s'\8cN++'\"\bn"f+er-2<

Try it online

Explanation:

Almost forgot to write this :p

The problem is solved in several steps:

the text is separated into runs of alphanumeric characters (let's call them words) and runs of non-alphanumeric characters (non-words)
non-words are printed as they are, and words are fixed
fixing a word is done recursively (with memoization): split the word into 2 chunks in every possible way (including empty 2nd chunk), try to unmess the first chunk (see below), fix the 2nd chunk and join the results with a space-backspace if needed; take the shortest sub-solution
unmessing a chunk means finding a minimal string of alphanumeric characters possibly followed by some backspaces (but with no backspaces in the middle) that when messed up, result in the given chunk; it is done with a simple greedy algorithm, going from left to right, building the unmessed string and its messed version in parallel, and determining the next needed character at each step; some chunks can not be unmessed


Approximate ∫((e^x)/(x^x))dx You are to approximate the value of:

Where your input is I.

Rules

You may not use any built-in integral functions.
You may not use any built-in infinite summation functions.
Your code must execute in a reasonable amount of time ( < 20 seconds on my machine)
You may assume that input is greater than 0 but less than your language's upper limit.
It may be any form of standard return/output.

You can verify your results at Wolfram | Alpha (you can verify by concatenating your intended input to the linked query).

Examples

(let's call the function f)

f(1) -> 2.18273
f(50) -> 6.39981
f(10000) -> 6.39981
f(2.71828) -> 5.58040
f(3.14159) -> 5.92228

Your answer should be accurate to ±.0001.

Julia, 79 77 38 bytes

I->sum(x->(e/x)^x,0:1e-5:min(I,9))/1e5

This is an anonymous function that accepts a numeric value and returns a float. To call it, assign it to a variable.

The approach here is to use a right Riemann sum to approximate the integral, which is given by the following formula:

In our case, a = 0 and b = I, the input. We divide the region of integration into n = 105 discrete portions, so ∆x = 1/n = 10-5. Since this is a constant relative to the sum, we can pull this outside of the sum and simply sum the function evaluations at each point and divide by n.

The function is surprisingly well-behaved (plot from Mathematica):

Since the function evaluates nearly to 0 for inputs greater than about 9, we truncate the input to be I if I is less than 9, or 9 otherwise. This simplifies the calculations we have to do significantly.

Ungolfed code:

function g(I)
    # Define the range over which to sum. We truncate the input
    # at 9 and subdivide the region into 1e5 pieces.
    range = 0:1e-5:min(I,9)

    # Evaluate the function at each of the 1e5 points, sum the
    # results, and divide by the number of points.
    return sum(x -> (e / x)^x, range) / 1e5
end

Saved 39 bytes thanks to Dennis!


Explain the decimals Given a decimal in the form of <float>, <precision>, you draw the graphical representation of the decimal part (i.e. fraction) of the float. Examples:

Input: 6.75, 4, output:

6||| 7
 ----

6.75 (first number from the input) is the number to explain, 4 (the second number from the input) is the number of dashes below the pipes.  6 is the floored 6.75, 7 is the ceiled 6.75. The number of pipes is the decimal part of first input number * second input number.
Input: 10.5, 6, output:

10|||   11
  ------

Input: 20.16, 12, output

20||          21
  ------------

.16 actually takes 1.92 pipes, but since I can't draw 1.92 pipes, I ceil it to 2.
Input: 1.1, 12, output:

1|           2
 ------------

.1 is 1.2 pipes in this case, so it's floored to 1 pipe.
Also, an edge case. Input: 5, 4 (i.e. the number is an integer), output:

5    6
 ----

The number to explain is the positive float, limited only by your language abilities.
The precision number is an even integer, greater than 2 (i.e. minimal required precision is 4). It can be arbitrary large too.
>= n.5 pipes are rounded up, to n+1 (i.e 1.5 is rounded to 2 and 2.5 is rounded to 3). < n.5 pipes are rounded to n (i.e. 1.4 is rounded to 1 and 2.4 is rounded to 2).
If it would be more convenient for your language, you can take the input as an array, e.g. [6.75, 4]. If you take the input in the reversed order, i.e. [4, 6.75], please specify it in your answer.

CJam, 32 bytes

l~1md@:X*mo'|*XSe]1$)NW$s,S*'-X*

Takes the precision first and the decimal second, separated by a space.

Run all test cases.

Explanation

l~   e# Read input and evaluate, pushing precision and decimal on the stack.
1md  e# Divmod 1, separating the decimal into integer and fractional part.
@:X  e# Pull up precision, store in X.
*mo  e# Multiply precision by fractional part and round.
'|*  e# Push that many vertical bars.
XSe] e# Pad with length X with spaces.
1$)  e# Copy integer part and increment.
N    e# Push linefeed.
W$   e# Copy integer part.
s,   e# Get number of digits as length of string representation.
S*   e# Push that many spaces, to indent the hyphens correctly.
'-X* e# Push X hyphens.


Rock, Polyglot, Scissors Write a program that is a polyglot in three languages that plays rock–paper–scissors.

The input for any version of the program is always one of the strings rock or paper or scissors.

In the first language the program must output the rock–paper–scissors choice that beats the input:

Input     Output
rock      paper
paper     scissors
scissors  rock

In the second language the program must output the rock–paper–scissors choice that ties the input:

Input     Output
rock      rock
paper     paper
scissors  scissors

In the third language the program must output the rock–paper–scissors choice that loses to the input:

Input     Output
rock      scissors
paper     rock
scissors  paper

The shortest code in bytes wins. Tiebreaker is higher-voted answer.

The inputs and/or outputs may optionally have a trailing newline but otherwise should only be the plain rock/paper/scissors strings. You may use uppercase ROCK, PAPER, SCISSORS if desired.

You may not use different versions of the same language (e.g. Python 2 and 3).

Python, brainfuck and JavaScript, 103 99 bytes Yay under 100 bytes!

0,[.5,];p=["rock","scissors","paper"]
1//1;lambda x:p[p.index(x)-1];"""
x=>p[-~p.indexOf(x)%3]//"""

In Python, this defines a function which beats the input, in brainfuck it's just a simple cat program, and in JavaScript it loses. Here's a version which gives the functions a name, f, and also prompts for input in JavaScript and Python 3:

0,[.5,];p=["rock","scissors","paper"]
1//1;f=lambda x:p[p.index(x)-1];"""
f=x=>p[-~p.indexOf(x)%3]//"""

1//1;"""
console.log(f(prompt())) // JavaScript
1//1"""; print(f(input())) # Python

Try it online (older version): Python,
 brainfuck, JavaScript

Explanation:

In Python, """...""" is a multiline string, which can be used as any token. When placed stand-alone it doesn't do anything at all. I use this to "hide" the JavaScript code from Python. The same goes for the (0,[.5,]) bit, it's just a tuple containing a 0 and a list of 5, and also the 1//1 part, // in Python is integer division, but starts a comment in JavaScript. Here's the code stripped of these tokens:

p=["rock","scissors","paper"]
lambda x:p[p.index(x)-1]

The first line is pretty self-explanatory, it just defines the list p to contain the different choices in rock-paper-scissors. The second line defines an unnamed function which takes one argument, x, and gives back the choice that beats x (eg. the previous element in p)

In JavaScript, // denotes a single-line comment. Similarly to Python, single tokens are ignored, so the code stripped of these tokens is:

p=["rock","scissors","paper"]
x=>p[-~p.indexOf(x)%3]

This works similarly to Python, by first setting the list p to contain the choices and then defining an anonymous function that gives the losing choice. -~x is the same as x+1 but with higher precedence so that I can skip the parens.

In brainfuck, every character except +-,.[]<> are removed, leaving this:

,[.,][,,]
[.-]
>[-.]

The command , reads one byte of input, . prints it and [...] loops while the value is non-zero. What this program does then is read the input and printing it one character at a time until the character \0 is found. Since we don't have that in the code, we can ignore the rest of the program. In effect, this just echoes back whatever the user types in, effectively tying them.


Calculate the probability of getting to the target first (exactly) Consider the following probability puzzle.
We start with a string of bits all set to 0. At each step we choose a bit uniformly and independently at random and flip it. The value your code has to compute is the probability of getting to the all 1s bit string before you get back to the all 0s bit string.
Let \$n\$ be the length of the starting bitstring.
Examples:
\$n = 1\$.  The output is 1.
\$n = 2\$.  The output is 1/2.
\$n = 3\$.  The output is 2/5.
The remaining outputs for n up to 20 are:
3/8,3/8,5/13,60/151,105/256,35/83,63/146,630/1433,1155/2588,6930/15341,12870/28211,24024/52235,9009/19456,9009/19345,17017/36362,306306/651745,2909907/6168632.

Your code should take \$n\$ as the input and give the right output. The output must be exact, for example as a fraction. There is no need for the fraction to be fully reduced.
Your code must work for \$n\$ up to at least \$20\$ and run without timing out on TIO .

Wolfram Language (Mathematica), 25 bytes
$$n! \div \left( \sum ^n _{k=0}  k!(n-k)! \right)$$
#!/Sum[k!(#-k)!,{k,0,#}]&

Try it online!
-4 bytes from @ovs


Tips for golfing in Grass What general tips do you have for golfing in Grass? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Grass (e.g. "remove no-op characters" is not an answer).

Please post one tip per answer.

Define λx.f x instead of copying f

In Grass you could usually copy something to the top of the stack to reduce the length of code referring to them.

But instead of defining the identity function and applying it:

wvWwwwww

You could define a new function that calls the original function instead:

wWWWWWw

Depending on the surrounding code and the number of items to be copied, it could be sometimes longer than the copying code. But it would likely still save you characters because it has one less item in the stack, and makes all references across this point shorter.

It doesn't work for characters that you would apply Out or Succ on them. It also cannot be used in a function. But it's likely you'll find other workarounds and make it still shorter.


Is it a sum-free set? A set is sum-free if no two (not necessarily distinct) elements when added together are part of the set itself.

For example, {1, 5, 7} is sum-free, because all members are odd, and two odd numbers when added together are always even. On the other hand, {2, 4, 9, 13} is not sum-free, as either 2 + 2 = 4 or 4 + 9 = 13 add together to a member of the set.

Write a program or function that takes a set as input, and outputs a Truthy value if the set is sum-free, and Falsy otherwise.

Examples:

Sum-free:
{}
{4}
{1, 5, 7}
{16, 1, 4, 9}

Not sum-free:
{0}
{1, 4, 5, 7}
{3, 0}
{16, 1, 4, 8}

Python 2, 41 bytes
lambda s:s==s-{a+b for a in s for b in s}

s should be a Python set.
Fun fact: sum-free is an anagram of my name.


Make a Geiger Counter A Geiger counter is a device that is used to detect radiation.

We will be making a Geiger counter program.

As we all know, when radiation hits a computer program it removes exactly 1 byte at random.  So a Geiger counter program is a program that itself does nothing, but when any byte is removed the modified program prints beep, to indicate the presence of radiation.

Answers will be scored in bytes with fewer bytes being better.  Answers must be at least 1 byte.

Your program may print beep with trailing a newline or print a single newline for empty output, so long as it does so consistently.  Your program may also use a different case for beep such as BEEP, bEEP, or Beep so long as it does so consistently.

Lost, 303 293 263 253 238 228 bytes

v^"peeb"<\>"beepvv"((>@@>>%%>>(((((([[[[[[\
>>>>>>>>>//>>>>>>>>>>>>>>/>>/>>>>>>>>>>>>>\\
>>>>>>>>//>>>>\>>>>>>>>>>/>>>>>>>>>>>>>>>>>\\
>/>>>>>>>/>>>>>>>>>>>>\>>>>>>>>>>>>>>>>>>>>>\\
>>>>>>>>>>>>>>>>>>>>>>\\>>>>\>>>>>>>>>>>>>>>>\

Try it online!

Verification script (borrowed from user 202729's answer). Unfortunately this can only test half of the code at a time, but rest assured I've tested the whole program.

Ouch, this was a tough one. I'll quote WW's deleted answer:

  Lost is perhaps the most interesting language for this challenge. In
  Lost the start location and direction of the pointer is entirely
  random, thus to make deterministic programs you must account for every
  possible start location and direction. At the same time, by the nature
  of this challenge you must also account for any single byte being
  removed.

Unfortunately, his answer didn't take into account removing newlines, which screwed everything up.

Explanation:

(note that a few bytes might be off here and there)

First let's talk about the general structure of the code:

v^^"peeb"<<\/"beepvv"((>>>@@>>%%>>(((((([[[[[[[\       Processing line
>>>>>>>>>>>//>>>>>>>>>>>>>>>>>>>/>>>>>>>>>>>>>>\\      Beep line
>>>>>>>>>//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\\     Back-up beep line
>//>>>>>>>>>>>>>>>>>>>>\\>>>>>>>>>>>>>>>>>>>>>>>>\\    Back-up return line
>>>>>>>>>>>>>>>>>>>>>>>>\\>>>>>>\>>>>>>>>>>>>>>>>>\    Return line

Everything but the processing line must be entirely composed of either > or one of \/. Why? Well, as an example, let's remove a newline:

v^^"peeb"<<\/"beepvv"((>>>@@>>%%>>(((((([[[[[[[\>>>>>>>>>>>//>>>>>>>>>>>>>>>>>>>/>>>>>>>>>>>>>>\\
>>>>>>>>>//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\\
>//>>>>>>>>>>>>>>>>>>>>\\>>>>>>>>>>>>>>>>>>>>>>>>\\
>>>>>>>>>>>>>>>>>>>>>>>>\\>>>>>>\>>>>>>>>>>>>>>>>>\

The first line is now way longer than the rest of the block. If a pointer were to spawn on a non->\/ character with vertical movement, then it would get stuck in an infinite loop.

The biggest radiation detector part is the section at the end of each line.

 \
 \\
 >\\
 >>\\
 >>>\

Normally an IP passing through this from the first line would exit out the last line. However, if any character on the line is removed, then that line shifts down one, e.g:

 \
 \\
 >\\
 >\\
 >>>\

And the IP instead exits out the line that is missing a byte (with the exception of the last line, where it exits out the second to last).

From there, each of the first four lines will redirect to the second line:

v
>>>>>>>>>>
>>>>>>>>//
>/

Which will then lead into either one of the two beepers.

v^"peeb"<<\/"beepvv"((>
>>>>>>>>>>//

If any of the bytes in the first beeper have been removed, then it instead goes to the second:

v^^"peb"<<\/"beepvv"((>
>>>>>>>>>>>//

Both beepers then lead back to the first line and the terminating @.

Some other miscellaneous parts:

The (((((([[[[[[[ is used to clear the stack when the pointer starts inside a pair of quotes and ends up pushing the whole first line to stack. It has to be so unfortunately long because the first newline can be removed to make the first line twice the size. Experimenting in generating the beep using arithmetic instead of quotes ended up longer.

The \s and /s scattered across the lines are there to golf bytes in the top line of code by redirecting the pointer to the correct lines. As most of the bottom lines are just filler, only the top line is able to be golfed. If anyone has any ideas for a shorter radiation proof stack clearer then what I've got now, feel free to comment.


Random script that isn't actually random As a little joke in the office someone wanted a script that randomly picks a name, and said person will make a round of drinks.

Let's call the people John, Jeff, Emma, Steve and Julie.

I thought it would be funny to make a script that seems random at a quick glance, but actually always gives the same person as the output (Up to you who you choose).

Highest voted answer wins after a week

And the winner is....

Paul R with (currently) 158 votes.

The answers here are great, and if anyone else has any other ideas what haven't been posted yet, please add them, I love reading through them.

C
It's important to decide who is buying as quickly as possible, so as not to waste precious drinking time - hence C is the obvious choice in order to get maximum performance:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    const char *buyer;
    int n;

    srand(time(NULL)); // make sure we get a good random seed to make things fair !
    n = rand();
    switch (n % 5)
    {
        case 0: buyer = "John";
        case 1: buyer = "Jeff";
        case 2: buyer = "Emma";
        case 3: buyer = "Steve";
        case 4: buyer = "Julie";
    }
    printf("The person who is buying the drinks today is: %s !!!\n", buyer);
    return 0;
}

Explanation:

 This would work just fine if there was a break; after each case in the switch statement. As it stands however each case "falls through" to the next one, so poor Julie always ends up buying the drinks.


Write a program which performs brute force letter combination until the word "password" is found The program should print every letter combination (lowercase or uppercase, it doesn't matter) in alphabetic order. It must start with a and the last printed combination should be password.

The output should be:

a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ... passwora passworb passworc password

Perl, 19 chars

say for a..password

Uses newlines as delimiters, per clarification above.  Run with perl -M5.010 (or just perl -E 'say for a..password') to enable the Perl 5.10+ say feature.  Per meta, this doesn't count as extra chars.

(If you insist on spaces as delimiters, $,=$";say a..password is only two chars longer.  However, it's also very slow and wasteful of memory, to the point of being unusable in practice, since it tries to build the entire list in memory before printing it.)


Optimal Othello/Reversi Move This is a code-golf challenge: Given a specific board in the game of Othello (Reversi), find a move for Black that will capture the maximum number of White pieces.

(Obviously, this may not be the true "optimal" play for Black, but to keep things simple we are only interested in finding the move that will capture the most pieces.)

If you are unfamiliar with the rules of Othello (Reversi), you may refer to: http://en.wikipedia.org/wiki/Reversi

Input will be provided as a file, or through stdin (your choice).
You may assume that the board will be a standard 8x8 size.
Black pieces will be indicated by b and White pieces will be indicated by w. Empty spaces will be indicated by .
The input may not necessarily be a valid board reachable by the rules of the game. Regardless, you must still find the optimal move following the rules of the game.
Your program must output the move by Black that will capture the most White pieces. If there is a tie, you may choose to output any (or all) of the moves. If there is no valid move, your program must indicate so by outputting x.
Your output can be provided as a coordinate, such as (3,4), or in algebraic notation, such as b5. When submitting your answer, please clearly indicate your output format and specify where your coordinate system starts from.

Sample input:

........
..b.....
...b....
...wwww.
...wb...
........
........
........

Sample output in (row,col) format, with (0,0) in the top-left corner:

(5,3)

Sample input:

........
......w.
.wwwwww.
.wwwwww.
.wwwwww.
.wwwwww.
.b....b.
........

Sample output in algebraic notation, with a1 in the bottom-left corner:

b7

Sample input:

........
........
..bbbb..
..bwwb..
..bwwb..
..bbbb..
........
........

Sample output:

x

This is code golf, so the shortest solution will be accepted.

Python, 184 chars

import os,re
M=os.read(0,99)
s=0
t='x'
for p in range(72):
 c=sum(len(re.match(r'\.w+b|',M[p::d]).group()[2:])for d in(-10,-9,-8,-1,1,8,9,10))
 if c>s:s=c;t='(%d,%d)'%(p/9,p%9)
print t

Coordinates are given as (y,x) with (0,0) in the upper left.

$ ./othello.py < othello1
(5,3)
$ ./othello.py < othello2
(1,1)
$ ./othello.py < othello3
x


Match this random string To-Do: Come up with a Better Title

Specification:
This challenge is similar to kolmogorov-complexity, but with a twist. You goal is to output a finite string that resembles the following string of psuedo-random characters as closely as possible:
BABBBBAAABBAABBBBAABBBAABBBABBAABABABBBBABBBBBBAABABBAABABBBABBBABAAAAABAAAABBAAABAAABBBBAABBABBBAABBBAABAAAABAAAABABABBBBBAABAAABBABAABAABABABBAABAAABBBABBABABBABAABABABBAABBBAABABABBBABAAABAABBBBBAABBBABABAABAABBAABABBBAABBAABAAABABABBBBBAAAAABBBAAABABAABBAABAABAAAABABBBAABBABBBBBAABAAAAABABBBAAAAAABAAAABBABAABABBAAABBBBBBAABABBAAAAAABABBAAABBABBABBBBAAAAAABABBBBBABBBABBAABBABAABAAAAABBAABABBABAABABABBBAAAAAABBBBBABABBBBBAABAABBBAAABABBABBAAABBABBABABBAABBAABAABBBABBABABBABABABABABBBAAABBBBBBABAAAAAABBAABBAABBBAAAAAAABBBBABBBBAABAABAABBABBAAAAAABABBABAAAAABABABAABAABBBAABBABAAABABAAAAABAABABAABBABAABBABBABAABABBBBAAAAAABAAAAAAAAABAABAAAAAAAABABAABBBABAAABABBBBBAAABAAAABBBBBABBBAAAAABBBABBAAAABAABBBBAABBABABAAABAABAAAAABBABBBABBBBAABBABABBAABAAAABAABBABABBBAABABABABAABAAAAABBABBBABBABBAAABAAAABBABABBBABBABABBBBABAAABBBBAAAABBABAAABABBBBBABABBAABBABAAABBABAAAAAABBBAAAABBBAAABABAAAAABBBBABAAABBBAAAABABBBBAAAAABBBBAABAABABBABABBABAAAABBBBAAABAABAAABBBBBBABBABAABABAABBBBBBBBAABBBAABAABABAABBAAABABAABAABBBBBBABBA

The string is 1024 characters long, and consists only of uppercase A and B characters. You must write a program takes up less than or equal to 256 bytes. The above string was generated completely randomly.
This challenge is not code-golf! Since 256 bytes is far too few characters (even for golfing languages), you may output any finite string. Your score is Levenshtein Distance between the 1024 byte string, and the string your program outputs (where the lower score is the best.)

Examples:
Input, Output
1024 "A" characters, 500 Points
1024 "B" characters, 524 Points
1024 characters alternating between "A" and "B" ("A" first), 348 Points
1024 characters alternating between "A" and "B" ("B" first), 346 Points

Notes:

The output must be finite and deterministic.

Unfortunately, this challenge is limited to languages that can be scored in bytes.

You may not substitute A and B for other characters. If your language cannot output such characters, it may not compete.

If a language cannot compete, it is still welcome to post non-competing answers. Just make sure to explain how you are scoring the challenge.

The winner of this challenge is on a per-language basis, since would be unlikely that an answer from Brainf*** would ever beat one from Jelly.

PHP, 246 printable bytes, distance 0
while($c=ord(base64_decode("vGec7K9+WXdBDEebnIQr5GkrI7WlZyuifOpMuZFfBxTJC5vkFwIaWPywLG3gX3ZpBlpXA+vk4tjazJ2tVcfoGZwHvJNgWgqTmiglNNpeBAEgFOi+IfcHYTzUSDd5rITXKpBu2Ia7Xo8NF9Zo0DhxQejheDyWtDxI/aU/zkpik/Y")[$i++]))echo strtr(sprintf("%08b",$c),10,BA);

or
while($c=base64_decode("vGec7K9+WXdBDEebnIQr5GkrI7WlZyuifOpMuZFfBxTJC5vkFwIaWPywLG3gX3ZpBlpXA+vk4tjazJ2tVcfoGZwHvJNgWgqTmiglNNpeBAEgFOi+IfcHYTzUSDd5rITXKpBu2Ia7Xo8NF9Zo0DhxQejheDyWtDxI/aU/zkpik/Y")[$i++])echo strtr(sprintf("%08b",ord($c)),10,BA);

Remarkable: gnuzip fails on the binary string. gzcompress adds 11 bytes and gzdeflate adds 5.
The fact that no 0x00 byte is in there saves 2 bytes on the first version;
no 0x30 saves 2 bytes on the second one.


Removing points from a triangular array without losing triangles I have a combinatorics problem that I'd like to put on the OEIS—the problem is that I don't have enough terms. This code challenge is to help me compute more terms, and the winner will be the user with the submission containing the greatest number of terms.

The Problem

Suppose I give you a triangular array of light bulbs with side length \$n\$:

     o
    o o
   o o o
  o o o o
 o o o o o
o o o o o o
1 2  ...  n

I'm going to turn on three lightbulbs that form an "upright" equilateral triangle as in the following example:

     o
    o x
   o o o
  o o o o
 o x o o x
o o o o o o

Before I turn on the lights, your job is to remove as many lightbulbs as possible from the array—without losing the ability to deduce the triangle of bulbs that has been turned on. To be clear, if a lightbulb has been removed, it is not lit up when its position is turned on.

For example, if you removed the following bulbs (marked by .) you would only see the following two lights turn on (marked by x), which is enough uniquely deduce the third (unlit) position:

     .              .
    . o            . x
   . . o          . . o
  o o o .   =>   o o o .
 o o o o .      o x o o . <- the third unlit position
o . . . o o    o . . . o o

Let a(n) be the maximum number of bulbs that can be removed without introducing any ambiguities.

Example

With a naive algorithm, I have checked values up to a triangle with side length 7, as seen below:

                                                                      .
                                                      .              . o
                                        .            . o            o . o
                           .           . .          . . o          . o o .
              .           . .         . o o        o o o .        o o . o .
 .           . .         . o o       o o . o      o o o o .      o . o . o o
. .         . o o       . o o o     o . . o o    o . . . o o    o . o . o o o

a(2) = 3    a(3) = 4    a(4) = 5    a(5) = 7     a(6) = 9       a(7) = 11

Scoring

The submission that computes the sequence [a(2), a(3), ..., a(n)] for the largest n wins. If two submissions have identical sequences, then the one that was posted earlier wins.

Although not necessary for the submission, it would be instructive to me if you post a construction of the resulting triangluar arrays, as in the example above.

Python 3, n=8

import itertools
from ortools.sat.python import cp_model

def solve(n):
    model = cp_model.CpModel()
    solver = cp_model.CpSolver()
    cells = {
        (y, x): model.NewBoolVar(str((y, x)))
        for y in range(n) for x in range(y + 1)}
    triangles = [
            {cells[v] for v in ((y1, x1), (y2, x1), (y2, x1 + y2 - y1))}
            for (y1, x1) in cells.keys() for y2 in range(y1 + 1, n)]
    for t1, t2 in itertools.combinations(triangles, 2):
        model.AddBoolOr(t1.symmetric_difference(t2))
    model.Minimize(sum(cells.values()))
    solver.Solve(model)
    return len(cells) - round(solver.ObjectiveValue())

for n in itertools.count(2):
    print('a(%d) = %d' % (n, solve(n)))

Uses Google OR-Tools' CP-SAT solver.

After running for ~30 seconds, it outputs the following:

a(2) = 3
a(3) = 4
a(4) = 5
a(5) = 7
a(6) = 9
a(7) = 11
a(8) = 13

I didn't event try to wait for n=9 as it would probably take hours (the number of constraints grows like \$n^6\$). After less than 30 minutes of computation I found out that a(9)=15. I'm leaving my score as n=8 because at the moment the time constraints are unclear, but half an hour is probably too long.

How it works

Take two distinct equilateral triangles \$T_1\$ and \$T_2\$. To avoid ambiguity, there should be at least one bulb on a vertex belonging to exactly one of \$T_1\$ and \$T_2\$.

Thus the question may be rephrased as a SAT problem, with one constraint for every pair of triangles.

PS:
I would very much like to include an example for n=8, but I'm having issues with the SAT solver which apparently wants to keep the solutions all for itself.


How many words of power did I shout? In Skyrim, the player character can use powerful magic shouts (Thu'ums) to achieve their goals. Every shout consists of three words, however, the player can use the first one or two words to achieve the same effect with less power but at a shorter cooldown.

Given a lowercase ASCII Thu'um phrase without punctuation or spaces, return how many words of power it contains.

Example:

fusrodah   -> 3
dur        -> 1
kaandrem   -> 2
odah       -> 2
vengaarnos -> 3

The input will always be a lowercase ASCII string formed by taking one of the shouts below, choosing the first 1, 2, or 3 words from that shout, and concatenating the words in order.

dur neh viir
faas ru maar
feim zii gron
fo krah diin
fus ro dah
gaan lah haas
gol hah dov
hun kaal zoor
iiz slen nus
joor zah frul
kaan drem ov
krii lun aus
laas yah nir
lok vah koor
mid vur shaan
mul qah diiv
od ah viing
raan mir tah
rii vaaz zol
strun bah qo
su grah dun
tiid klo ul
ven gaar nos
wuld nah kest
yol toor shul
zul mey gut
zun haal viik

So fus, fusro, and fusrodah are all valid inputs, but fusroviir isn't because it uses words from mixed shouts, and rodah isn't because it's not a prefix of a shout. You also don't have to handle the empty string input.

Shortest code in bytes wins.

Retina, 78 42 15 14 bytes
ul
xo
[aeiou]+

Try it online
tiidkloul is the only word that doesn't have the same amount of vowel sequences as the number supposed to be printed. Therefore we need to match the word to give it an extra vowel sequence. ou will only match tiidkloul and we can then replace ou with oxo which creates the extra sequence.
My initial approach wasn't this simple, but was build around removing all consonants, then removing a few vowel sequences (ai|ii|aa|...) and then finally counting the numbers of letters. But thanks to @Martin Büttner for thinking of [aeiou]+ instead.


Cops: The Hidden OEIS Substring This is a Cops and Robbers challenge. This is the cop's thread. The robber's thread is here.
As a cop, you must pick any sequence from the OEIS, and write a program p that prints the first integer from that sequence. You must also find some string s. If you insert s somewhere into p, this program must print the second integer from the sequence. If you insert s + s into the same location in p, this program must print the third integer from the sequence. s + s + s in the same location will print the fourth, and so on and so forth. Here's an example:

Python 3, sequence A000027
print(1)

The hidden string is two bytes.

The string is +1, because the program print(1+1) will print the second integer in A000027, the program print(1+1+1) will print the third integer, etc.
Cops must reveal the sequence, the original program p, and the length of the hidden string s. Robbers crack a submission by finding any string up to that length and the location to insert it to create the sequence. The string does not need to match the intended solution to be a valid crack, nor does the location it's inserted at.
Rules

Your solution must work for any number in the sequence, or at least until a reasonable limit where it fails do to memory restrictions, integer/stack overflow, etc.

The winning robber is the user who cracks the most submissions, with the tiebreaker being who reached that number of cracks first.

The winning cop is the cop with the shortest string s that isn't cracked. Tiebreaker is the shortest p. If there are no uncracked submissions, the cop who had a solution uncracked for longest wins.

To be declared safe, your solution must stay uncracked for 1 week and then have the hidden string (and location to insert it) revealed.

s may not be nested, it must concatenated end to end. For example, if s was 10, each iteration would go 10, 1010, 101010, 10101010... rather than 10, 1100, 111000, 11110000...

It is acceptable to start on the second term of the sequence rather than the first.

If your sequence has a finite number of terms, going past the last term is allowed to result in undefined behavior.

All cryptographic solutions (for example, checking the hash of the substring) are banned.

If s contains any non-ASCII characters, you must also specify the encoding being used.

MATL, sequence A005206. Cracked by SamYonnou

voOdoO

Try it online!

The hidden string has 8 bytes.


Convert a sample to an index We are putting balls into a fixed number a bins. These bins begin empty.
Empty bin (a=4): 0 0 0 0

And one by one we add balls to the bins.
0 0 0 1  or
0 0 1 0  or
0 1 0 0  or
1 0 0 0

We need a quick way to loop over all the possible states the bins take, without duplicates and without missing any and we don't want to enumerate all the possible bins. So instead we assign each bin-configuration an index.
We assign the index by sorting the possible configurations in a specific way:

Sort ascending by sum: so first 0 0 0 0, then the possible configurations with 1 ball added, then 2, etc.

Then sort within each sum in ascending order, from the first bin to the last:
0 0 0 2
0 0 1 1
0 0 2 0
0 1 0 1
0 1 1 0
0 2 0 0
etc

The index is then assigned ascending through this list:
0 0 0 0  -> 1
0 0 0 1  -> 2
0 0 1 0  -> 3
0 1 0 0  -> 4
1 0 0 0  -> 5
0 0 0 2  -> 6
0 0 1 1  -> 7
0 0 2 0  -> 8
0 1 0 1  -> 9
0 1 1 0  -> 10
0 2 0 0  -> 11

Rules
Create a function or program that takes a list of any size with non-negative integers and print or output its index. You can assume a to be at least 2. Shortest code wins. You may use 0-indexed output or 1-indexed, but specify which you use. NB: all examples here are 1-indexed.
Example code
Not golfed, in R:
nodetoindex <- function(node){
  a <- length(node)
  t <- sum(node)
  if(t == 0) return(1)

  index <- choose(t-1 + a, a)

  while(sum(node) != 0){
    x <- node[1]
    sumrest <- sum(node)
    if(x == 0){
      node <- node[-1]
      next
    }
    a <- length(node[-1])
    index <- index + choose(sumrest + a, a) - choose(sumrest - x + a, a)
    node <- node[-1]
  }
  return(index + 1)
}

Test cases
10 10 10 10 -> 130571
3 1 4 1 5 9 -> 424407
2 9 -> 69
0 0 0 -> 1
0 0 1 -> 2
0 0 0 0 0 0 -> 1
1 0 0 0 0 1 -> 23

Jelly, 8 bytes

S0rṗLSÞi

Try it online!

Brute-force solution. The first test case is too much for TIO, but I've verified it locally on my laptop. The second test case requires too much RAM, even for my desktop computer.

How it works

S0rṗLSÞi  Main link. Argument: A (array)

S         Compute the sum s of A.
 0r       Create the range [0, ..., s].
    L     Yield the length l of A.
   ṗ      Cartesian power; yield the array of all l-tuples over [0, ..., s], in
          lexicographical order.
     SÞ   Sort the l-tuples by their sums. The sorting mechanism is stable, so
          l-tuples with the same sum are still ordered lexicographically.
       i  Find the index of A in the generated array of tuples.


How many petals around the rose How many petals around the rose
How many petals around the rose is a dice game you can play with your friends. Similar to "can I join the music box", there is a person that knows how the game works and the others have to discover the rule.
In this game, someone rolls some dice (usually two or more) and then people have to call "how many petals are around the rose".
Algorithm
If you want to play it by yourself, you can play it over at TIO. Just hide the header (which is where the rule is implemented) and try passing different arguments (from 1 to 6) in the function.
spoiler, what follows is the rule you are invited to find by yourself!

 The "roses" here are the dice, and the "petals" are the black dots that are around a central dot. Because only the odd numbers have a central black dot, only numbers 1, 3, 5 matter for the petals. Those numbers have, respectively, 0, 2, 4 dots around the central dot, the "petals".

Input
Your input will be a non-empty list (or equivalent) of integers in the range [1, 6].
Output
The number of petals around the rose.
Test cases
Reference implementation in Python, that also generated the test cases.
1, 1 -> 0
1, 2 -> 0
1, 3 -> 2
1, 4 -> 0
1, 5 -> 4
1, 6 -> 0
2, 1 -> 0
2, 2 -> 0
2, 3 -> 2
2, 4 -> 0
2, 5 -> 4
2, 6 -> 0
3, 1 -> 2
3, 2 -> 2
3, 3 -> 4
3, 4 -> 2
3, 5 -> 6
3, 6 -> 2
4, 1 -> 0
4, 2 -> 0
4, 3 -> 2
4, 4 -> 0
4, 5 -> 4
4, 6 -> 0
5, 1 -> 4
5, 2 -> 4
5, 3 -> 6
5, 4 -> 4
5, 5 -> 8
5, 6 -> 4
6, 1 -> 0
6, 2 -> 0
6, 3 -> 2
6, 4 -> 0
6, 5 -> 4
6, 6 -> 0
3, 1, 5 -> 6
4, 5, 2 -> 4
4, 3, 5 -> 6
1, 4, 4 -> 0
5, 5, 2 -> 8
4, 1, 1 -> 0
3, 4, 1 -> 2
4, 3, 5 -> 6
4, 4, 5 -> 4
4, 2, 1 -> 0
3, 5, 5, 2 -> 10
6, 1, 4, 6, 3 -> 2
3, 2, 2, 1, 2, 3 -> 4
3, 6, 1, 2, 5, 2, 5 -> 10

This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!

Python 3, 30 bytes

lambda l:sum(n**3&6for n in l)

Try it online!

(test cases shamelessly borrowed from xnor's answer)

How?

Given \$1\le n\le6\$, the number of petals can be computed with:

$$p=n^{2k+1} \operatorname{and}6,\:k\in\mathbb{N}^*$$

where \$\operatorname{and}\$ is a bitwise operator.

This can also be written as:

$$p=2\times\left\lfloor\frac{n^{2k+1}\bmod 8}{2}\right\rfloor$$

And is based on the fact that, for any \$k\ge1\$:

$$n^{2k+1}\bmod 8=\cases{
n&\text{if $n$ is odd ($1$, $3$ or $5$)}\\
0&\text{if $n$ is even ($2$, $4$ or $6$)}
}$$

More specifically, choosing \$k=1\$:

$$p=n^3 \operatorname{and}6$$

As Python code, the resulting expression is just as long as the nice n%-2%n found by xnor. But because it ends with a digit, we can get rid of the space just before the for, saving a byte.

 n | n**3 | as binary  | AND 6
---+------+------------+-------
 1 |    1 | 00000 00 1 |   0
 2 |    8 | 00001 00 0 |   0
 3 |   27 | 00011 01 1 |   2
 4 |   64 | 01000 00 0 |   0
 5 |  125 | 01111 10 1 |   4
 6 |  216 | 11011 00 0 |   0


Simulate reproduction in a population of oozes Reproductive strategy of oozes can be summarized as follows:

  o O 8 oo

A population of oozes at generation N is described by a string, for example:

ooooo88ooOoOo8Ooooo8OOoo8Oo8Oo8oo8oooooo8OOooO88o

To compute the population at generation N+1, take one character randomly, and replace it by the result of ooze evolution:

If o, replace by O
If O, replace by 8
If 8, replace by oo

Generation 0 is the one-character string o. Your program or function should get a positive number N, and output the population of oozes at generation N. At each generation, each ooze should have the same chance (to within 1% accuracy) to evolve.

Test cases (actual results may vary due to randomness):

1 -> O
2 -> 8
3 -> oo
4 -> Oo
5 -> OO
10 -> OO8
20 -> oo8oooo
30 -> oOoooOO8O
100 -> 8o8oO8OOooOo8OOoo88oOO8OOO
200 -> 88OOo8oooo8OOoooOoOOO8O8OO88o8Oo8oooOooooooOo8OooO888
1000 -> 8Ooooo88OO8o8O8oooOOoOOO88oOoO88OOoO8OOOooOOo8OO88O8OO8OO8ooo8oOO8OoooO88OooooooooOo8oooOO8OO8Oo8Oooo8O88oooOooO8Oo8ooOOOOo8OooOo8OoooooooO8oOooooOooOO8oOO8ooo8Ooooo8ooo8ooOOooO8OOoO8oO8oo88ooo8oO8OO8o888oO8OOoO8o8ooO8O88OOOoO8oooO8OoOoOo88O88oo88ooo8oO8o8oOooOo

If your solution has running time of O(n), please specify it explicitly!

Python 3, 114 bytes

from random import*
def f(n,s=b'o'):k=randrange(len(s));return n and f(n-1,s[:k]+b'oO8o'[-~s[k]%3::3]+s[k+1:])or s

Try it online!

Interesting observation: the ascii values of oO8 are 111, 79, and 56, respectively. If you take these modulo 3, you get 0, 1 and 2.

Additional observation: you can validate the generation of your final string by substituting 'o' with 3, 'O' with 4 and '8' with 5; then taking the sum of your list and subtracting 3 from the total.

This works for all strings regardless of random variations, because each replacement in your string increases this sum by 1:

'o' (3) -> 'O'  (4)
'O' (4) -> '8'  (5)
'8' (5) -> 'oo' (3+3 = 6)

We then just need to correct for the offset of 3.

Validate it online!


The meeker number sequence The Meeker numbers are a 7 digit number in form of \$abcdefg\$, where \$a×b=10c+d\$ and \$d×e=10f+g\$. As an example \$6742612\$ is a meeker number, here \$6×7=10×4+2\$ and \$2×6=10×1+2\$, so it is a meeker number.
Additionally, a Meeker number does not have any leading zeros (so \$a \ne 0\$)
The Challenge
Your program can do one of the following tasks:

Take a positive integer \$n\$ and output the \$n\$th Meeker number (0 or 1 indexed, your choice. If 0 indexed, \$n\$ will be a non-negative integer)
Take a positive integer \$n\$ and output the first \$n\$ Meeker numbers
Output all 900 Meeker numbers

Rules

You may take an empty input if you output all Meeker numbers
Standard loopholes are forbidden.
Trailing whitespace is allowed.
If possible, please link to an online interpreter (e.g. TIO) to run your program on.
Please explain your answer. This is not necessary, but it makes it easier for others to understand.
Languages newer than the question are allowed. This means you could create your own language where the empty program calculates this number, but don't expect any upvotes.
This is code-golf, so shortest code in bytes wins!

The first few Meeker numbers are
1000000
1000100
1000200
1000300
1000400
1000500
1000600
1000700
1000800
1000900
1101000
1101101
1101202
1101303
1101404
1101505
1101606
1101707
1101808
1101909
...

Thanks to @Adám for the detailed analysis and @cairdcoinheringaahing for the editing rework

APL (Dyalog Extended), 45 bytes (SBCS)

Full program. Prints all meeker numbers. Requires 0-based indexing (⎕IO←0).
1e6+⍸{(×⌿i⊇⍵)≡10⊥⍵[2+i←0 1,⍪3 4]}¨10⊤¨1e6…1e7

Try it online! (limited to upper bound of 2 000 000 ― above code works offline)
1e6…1e7 numbers 1 000 000 through 10 000 000
10⊤¨ base-10 representation of each (splits digits of numbers into lists of digits)
{…}¨ apply the following lambda to each:
 ⍵[…] index the digits of the current number using the following:
  ⍪3 4 the column-vector [[3],[4]]
  0 1, prepend a column consisting of [0,1] yielding [[0,3],[1,4]]
  i← assign to i (for indices)
  2+ increase by two; [[2,5],[3,6]]
 10⊥ evaluate as base-10, using the top row as tens place and bottom row as ones place
 (…)≡ check if it matches the following:
 i⊇⍵ select the elements from the digits at indices i
 ×⌿ multiply the elements of the top row with the elements of the bottom row
⍸ ɩndices where true
1e6+ offset to the first candidate


Are they connected by a Brussels choice? Background
Two numbers, \$a\$ and \$b\$, are said to be connected by a Brussels choice operation* if \$b\$ can be reached from \$a\$ by doubling or halving (if even) a substring (the substring must not be empty and may not contain any leading 0s but it can be 0) in the base-10 representation of \$a\$
*This operation is slightly different from the one defined on this paper mainly that the operation defined in the paper allows empty substrings and does not allow choosing the substring "0"
For example, all the number that can be reached from 5016:
508     (50[16] half   -> 50[8])
2508    ([5016] half   -> [2508])
2516    ([50]16 half   -> [25]16)
5013    (501[6] half   -> 501[3])
5016    (5[0]16 half   -> 5[0]16)
        (5[0]16 double -> 5[0]16)
5026    (50[1]6 double -> 50[2]6)
5032    (50[16] double -> 50[32])
10016   ([5]016 double -> [10]016)
        ([50]16 double -> [100]16)
10026   ([501]6 double -> [1002]6)
10032   ([5016] double -> [10032])
50112   (501[6] double -> 501[12])

Task
Write a program/function that when given two positive integers as input outputs a truthy value if they can reach each other with a single Brussels choice operation and a falsey value otherwise.
Scoring
This is code-golf so shortest bytes wins.
Sample Testcases
2, 4       -> Truthy
4, 2       -> Truthy
101, 101   -> Truthy
516, 58    -> Truthy
58, 516    -> Truthy
516, 5112  -> Truthy
5112, 516  -> Truthy

1, 3       -> Falsey
123, 123   -> Falsey
151, 252   -> Falsey
112, 221   -> Falsey
101, 999   -> Falsey
999, 1001  -> Falsey
101, 1001  -> Falsey

Inspired by The Brussels Choice - Numberphile

Retina, 38 bytes
L$w`0|[1-9]\d*
$`$.(*2*)$'
m`^(.+),\1$

Try it online! Link includes test cases. Outputs 0 for Falsey, non-zero for Truthy. Explanation:
L$w`0|[1-9]\d*

Match all integer substrings of both inputs, including 0 but not integers beginning with 0.
$`$.(*2*)$'

List the result of doubling that substring only.
m`^(.+),\1$

Check to see whether this produces any pairs of equal integers.


Quick! Escape the black hole! It is the year 87,539,319 and solitary space-walking is now commonplace, many people travel into space by themselves, propelled by nothing but a jetpack on their backs, programming their course with a personal computer and keyboard as they go.

You are one such person; you were out on a lovely, peaceful spacewalk, when, all of a sudden, you were ensnared by the gravity of a black hole!

As you plummet towards this black hole, spiraling ever faster inwards, you realise your one chance of survival is to broadcast a distress message, and hope a nearby ship comes to rescue you.

So, you break out your keyboard, and begin typing away a program.

Your program can be in any language, and must print HELP! to stdout (your PC broadcasts all stdout far into the depths of space.)

However, as you are near a blackhole, your keyboard is slowly being ripped to shreds!

Assume you are using a QWERTY keyboard like the one below, and that the blackhole is to your left;

Remember, left and right shift are two different keys.

after every keypress, the left-most row of your keyboard (keys covered by left-most red line) is ripped off and flung into the black hole!

So, your first keypress could be any key on the keyboard, but from then onwards none of the leftmost Tab, Caps, Shift, Ctrl or ` keys may be used, at all. (r-shift and r-ctrl can still be used)

After the next keypress, the keys 1, Q, A,Z and Alt are flung into the abyss, and may not be used thereafter. After that, you lose Space, X, S, W, 2 and so forth.

Obviously, you want to complete your program as quickly as possible, so that rescue-time is increased; therefore, this is code-golf, and the shortest program in key presses wins!

Each answer should provide a list of keypresses, so, if my answer was this program (in the language squardibblyack)

!HELP\.

a keylist could look like:

Shift!HELP release shift \.

length: 8

I'm worried this challenge might be too difficult, but I'd love to see the kinds of answers submitted!

CJam, 11 keystrokes

The code is

"HELP*")9-

and the keylist is

Shift"HELP*") release shift 9-

and here is a demonstration of how it looks:

and here is how the code works:

"HELP*"              "This puts the string HELP* on stack";
       )             "This takes out the last character of the string and puts it
                      on the stack as a character";
        9-           "This simply reduces 9 from the ASCII code of * character
                      present on the stack which makes it an !";
                     "CJam automatically prints everything that is on stack";

Try the code here


The Take-back counting algorithm Kids who are learning how to count often know runs of numbers, but can't seem to put those runs together properly.
For example, they might say:
1,2,3,4,7,8,9,10

Sometimes kids will realize that they skipped some numbers, and go back:
1,2,3,4,7,8,5,6,7,8,9,10

This is clearly the superior pattern.  We need to identify them.
To identify these lists:

We identify the minimum M and the maximum N of the list

We step through the list.  If the current number is greater than or equal to any member of the list to its right, then we remove the current number.

Iff the remaining list contains all numbers from M to N, then we return a truthy value.

You can assume your input list will contain at least 1 element.  You can assume that all integers will be non-negative.
Test cases:
Truthy:
0
10
0 0 0
1 0 1
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 0 1 2 3
0 1 2 3 4 5 5
0 1 1 2 2 3
0 3 6 1 4 7 2 5 8 3 4 5 6 7 8
1 3 5 7 2 3 4 5 6 7
5 6 0 1 2 3 6 7 4 5 6 7
5 6 7 8
5 5 6 7 8
4 6 7 8 3 4 5 6 7 8

Falsy:
1 0
4 3 2 1
1 2 3 7 8 9
0 1 2 3 1 3
0 1 2 3 1 3 4
0 1 2 3 1 3 2 4
0 1 2 3 1 3 2 4 3
1 3 5 7 2 4 6 8
0 1 2 1 3 4 5 6
4 5 6 3 4 5

This is code-golf, so make your answers as short as possible!

05AB1E, 5 bytes

I am not 100% certain this works, but it passes all test cases and I couldn't find any situation where it fails.

Ú¥1QP

Try it online!

Ú¥1QP   Main link. Argument a
Ú       Reverse uniquify a, keeps only last occurence of each element
 ¥      Get all deltas - all 1 if ascending list
  1Q    Compare all deltas to 1
    P   Product of all results


Factorize it! ...badly A curious kid uses a program which can factorize a number or an expression into the following form: p1^e1 * p2^e2 * ... * pn^en. Exponents equal to 1 are omitted e.g. 360 = 2^3 * 3^2 * 5

The kid types this output into the program as new input but she doesn't understand the ^ sign so sometimes she skips one or more of those concatenating the corresponding prime-base and exponent. E.g. (360 =) 2^3 * 3^2 * 5 => 2^3 * 32 * 5 (= 1280)

Because of these mistakes she might get a different factorization which she can input again (with skipping 0 or more ^'s). She repeats the process until the factorization doesn't change anymore (maybe there are no more ^'s or she copied the output correctly).

You should write a program or function which given an integer n (n>1) outputs all the possible numbers in increasing order whose factorization could be the one the kid ended up with (including n). E.g. for input 16 the possible final factorizations are (16 =) 2^4, (24 =) 2^3 * 3, (23*3 =) 3 * 23

Input details:

input is a single integer bigger than 1
no input will be given which generates output number greater than 2^31-1
no input will be given which generates more than 1000 output numbers

Output details:

a list of integers in a convenient form for your language

Examples:

Input => Output

11    => 11
16    => 16 24 69
360   => 140 360 770 1035 1219 1280 2875 3680
605   => 560 605 840 2415
2048  => 211 2048
58564 => 230 456 1311 2508 9975 12768 13794 20748 58564 114114 322102

This is code-golf so shortest program wins.

CJam - 66

ria{_{:XmF{1=1>},La\{a1$\f++}/La-{XI{~#}%:*/I{si}%:**}fI}%|}1e3*$p

Try it at http://cjam.aditsu.net/

Explanation:

ria                       read token, convert to integer and wrap in array
{…}1e3*                   repeat 1000 times
    _                     duplicate array
    {…}%                  transform each array item (number) using the block
        :X                store the number in X
        mF                factorize with exponents
        {1=1>},           keep only the factors with exponent > 1
        La\{a1$\f++}/     get all the subsets (*)
        La-               remove the empty subset
        {…}fI             for I = each subset of prime factors with exponent > 1
            XI{~#}%:*/    divide X by all the factors in I
            I{si}%:**     multiply with the primes from I
                          concatenated with their exponents
    |                     add the new numbers to the array, removing duplicates
$                         sort
p                         print the final array

(*) Thanks Martin


Dovetail two blocks of bits Check if two blocks of bits dovetail perfectly.
Specifications

A block of bits is a fixed sequence of 8 bits just like this for example : 11110101.

For simplicity we refer to truthy/falsey values as 1/0 bits but they can be everything capable of representing those two states in a clear, well defined and consistent way, for example :0/1 x/y False/True "false"/"true" 'a'/'b' []/[...] odd/even >0 / <0  0 / !0

What does it mean dovetail perfectly?

1's bits of one block can fit only into 0's of the other block or outside it.

You can shift an entire block left or right but you cannot modify a block nor reverse it.

The resulting block must contain all 1's of both inputted blocks and only those.

There must not be any 0's between 1's while there can be any trailing and leading 0's.

The resulting block can be more than 8 bits long.

Example

 Input : [ 10010111, 01011010 ]

             10010111
             ↓  ↓ ↓↓↓
           01011010   &lt- shif by 2
  result   0111111111  =&gt dovetails perfectly

Input: two blocks of bits.

You don't need to handle empty blocks (all 0's).

Output: your solution have to clearly state if input blocks can dovetail perfectly as described above or not.

the resulting block won't be a valid answer.

Test cases.
00000000, 00000000 | you don't
00000000, ...      | need to
...     , 00000000 | handle these

11111111, 11111111 -> True
11111111, 10000000 -> True
11110000, 00101000 -> False
00101000, 10100000 -> True
10000000, 00111000 -> True
00110011, 11001100 -> True
00010000, 11101010 -> False
10000100, 10111101 -> True
01111010, 01011111 -> True
10010101, 00001101 -> False
01010011, 10110000 -> True
00000111, 00010011 -> False
00000011, 00000101 -> False

Rules

Input/output can be given by any convenient method.
You can print it to STDOUT, return it as a function result or error message/s.
Either a full program or a function are acceptable.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Sandbox

JavaScript (ES6),  63 54 52  50 bytes
Saved 2 bytes by applying an optimization similar to the one suggested by @AZTECCO on my C answer
Expects (a)(b), where a and b are bytes. Returns 0 if the blocks can dovetail perfectly or 1 otherwise.
a=>g=b=>b?a<<8&b|(c=a<<8|b,c+=c&-c)&c-1&&g(b<<1):1

Try it online!
How?
The recursive function g attempts to shift b to the left, 1 position at a time, until the following conditions are both met:

(a << 8) & b is equal to 0, i.e. a << 8 and b have no set bits in common
c = (a << 8) | b is a sequence of consecutive 1's, possibly followed by trailing 0's

For the second test, we add to c the rightmost set bit in c and see if this results in a single 1, by carry propagation along the sequence of consecutive 1's.
We use the following bitwise tricks:
c & -c      // returns the rightmost set bit in c

c & (c - 1) // returns c without the rightmost set bit in c
            // (0 if c is an exact power of 2)

Example:
0111111000 + (0111111000 & -0111111000) = 0111111000 + 0000001000 = 1000000000
1000000000 & (1000000000 - 1) = 1000000000 & 0111111111 = 0

We stop the recursion when b = 0, which means that all bits have been thrown away. (This is why we do b << 1 instead of b * 2, so that b is forced to a 32-bit integer rather than an IEEE 754 floating-point number.)


Excel, 153 149 Bytes

=IF(OR(A1<17,A1>99,AND(A1>19,A1<70)),A1,IF(A1<20,"10+"&A1-10,IF(A1<80,"60","4*20")&IF(A1=80,,IF(MOD(A1,20)>16,"+10+"&MOD(A1,20)-10,"+"&MOD(A1,20)))))

I'm sure this could be better, I struggled to find an efficient way to account for #80.

edit: Consolidated the 'Normal' cases better to save 4 bytes.  #80 still sucks.

Can't find a specific answer on here, not sure the rules of code-golf tbh.  Can I use multiple cells in Excel, and add the byte count of each?

ie. For an input in cell A1

A2: 11 Bytes

=MOD(A1,20)

A3 (result): 125 Bytes

=IF(OR(A1<17,A1>99,AND(A1>19,A1<70)),A1,IF(A1<20,"10+"&A1-10,IF(A1<80,"60","4*20")&IF(A1=80,,IF(A2>16,"+10+"&A2-10,"+"&A2))))

For a total of 136?


Today (September 24) is HONDA birthday today (24 of September) is birthday of company HONDA. Originally their company name is

本田技研工業株式会社

I want to ask to make a gift for HONDA. The task is to make program print company name. You can do it any way you want, but there is only one rule, Unicode is not allowed. It should be ASCII art.

I want to ask to post code and output. As always to determine winner I'll look at the length of code, however portrait in this case is also important.

EDIT: output have to look similar into this: 本田技研工業株式会社

Mathematica
Here the characters are individually rasterized.  The zero's of the binary image data of a reduced image are then replaced with asterisks and the array itself is then printed.
GraphicsGrid[ImageData@ImageResize[Binarize@Rasterize@Style[#, 136], 30]
/. {1 -> "", 0 -> "*"}] & /@ Characters["本田技研工業株式会社"]

Below all characters were rasterized as a single image. The asterisks are a bit more difficult to recognize as asterisks in this case.
GraphicsGrid[ImageData@ImageResize[Binarize@Rasterize@Style[#, 136], 300]
/. {1 -> "",  0 -> "*"}, ImageSize -> 1500] &["本田技研工業株式会社"]


Shortest common superstring Given a list of strings s_0, s_1, ..., s_n find the shortest string S that contains each of s_0, s_1, ..., s_n as a substring.

Examples:

S('LOREM', 'DOLOR', 'SED', 'DO', 'MAGNA', 'AD', 'DOLORE')='SEDOLOREMAGNAD'
S('ABCDE', 'BCD', 'C')='ABCDE'

Write the shortest program (or function) that solves this problem. You can represent strings as arrays or lists of characters/integers if you want. Standard libraries are OK. For input/output you can use whatever is more convenient: STDIN/STDOUT, user prompt, parameter/return value of a function etc.

Performance is not critical - let's say, for an input of total length < 100 characters the result must be computed in < 10 second on average modern hardware.

Python 2, 170 153/157/159

Shortened thanks to some of Baptiste's ideas.

from itertools import*
print min((reduce(lambda s,w:(w+s[max(i*(s[:i]==w[-i:])for i in range(99)):],s)[w in s],p)
for p in permutations(input())),key=len)

The second line break is not needed.

Input: 'LOREM', 'DOLOR', 'SED', 'DO', 'MAGNA', 'AD', 'DOLORE'
Output: SEDOLOREMAGNAD

Even with long input strings, this runs in less than 2 seconds if there are at most 7 input strings (as is the case in the example given, which runs in 1.7 1.5 seconds on my machine).  With 8 or more input strings, however, it takes more than 10 seconds, since the time complexity is O(n!).

As Baptiste pointed out, range(99) needs to be replaced with range(len(w)) if arbitrary input lengths should be supported (making the total length of the code 157 characters).  If empty input strings should be supported, it has to be changed to range(len(w)+1).  I think range(99) works correctly for any total input length less than 200, though.

More tests:

>>> "AD", "DO", "DOLOR", "DOLORE", "LOREM", "MAGNA", "SED", "ORE",  "R"
SEDOLOREMAGNAD

>>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvw
... xyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
... vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ZOOM', 'aZ', 'Za', 'ZA'
aZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZOOM


Longest hypercube path Challenge
You are given two distinct bit strings of the same length. (For example, 000 and 111.) Your goal is to find a path from one to the other such that:

At each step, you change only one bit (you can go from 000 to any of 001, 010, 100).
You cannot visit the same bit string twice.
The path is as long as possible, under these constraints.

For example, going from 000 to 111, we can take the path
000, 001, 011, 010, 110, 100, 101, 111

which visits all 8 bit strings of length 3, so it has to be the longest possible.
Rules

Standard loopholes apply.
You may take the input as two strings of zeroes and ones, or as two arrays of zeroes and ones, or as two arrays of boolean values.
You may not take the input as two integers with the right binary representation (writing 000 and 111 as 0 and 7 is not valid).
If you want, you may take the length of the bit strings as input.
Your program is allowed to output the path by printing the bit strings visited one at a time, or by returning an array of the bit strings visited (each in the same format as the input).
Your output should include the start and end of the path (which are your inputs).
This is code-golf, the shortest code in bytes wins.

Examples
0 1 -> 0, 1
10 01 -> 10, 00, 01 or 10, 11, 01
000 111 -> any of the following:

   000, 100, 110, 010, 011, 001, 101, 111

   000, 100, 101, 001, 011, 010, 110, 111

   000, 010, 110, 100, 101, 001, 011, 111

   000, 010, 011, 001, 101, 100, 110, 111

   000, 001, 101, 100, 110, 010, 011, 111

   000, 001, 011, 010, 110, 100, 101, 111

1001 1100 -> 1001, 0001, 0000, 0010, 0011, 0111, 0101, 0100, 0110, 1110, 1010, 1011, 1111, 1101, 1100 (other paths exist)

Husk, 27 26 24 bytes

→foΛεẊδṁ≠ÖLm↓≠⁰←ġ→PΠmṠe¬

Brute force, so very slow.
Try it online!

Explanation

Husk reads naturally from right to left.

←ġ→PΠmṠe¬  Hypercube sequences ending in second input, say y=[1,1,0]
     mṠe¬  Pair each element with its negation: [[0,1],[0,1],[1,0]]
    Π      Cartesian product: [[0,0,1],[1,0,1],..,[1,1,0]]
   P       Permutations.
 ġ→        Group by last element
←          and take first group.
           The permutations are ordered so that those with last element y come first,
           so they are grouped together and returned here.

ÖLm↓≠⁰  Find first input.
  m     For each permutation,
   ↓≠⁰  drop all elements before the first input.
ÖL      Sort by length.

foΛεẊδṁ≠  Check path condition.
fo        Keep those lists that satisfy:
    Ẋ      For each adjacent pair (e.g. [0,1,0] and [1,1,0]),
      ṁ    take sum of
       ≠   absolute differences
     δ     of corresponding elements: 1+0+0 gives 1.
  Λε       Each value is at most 1.

→  Finally, return last element (which has greatest length).


Black and white shirts This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here.

Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero durability. All shirts of a given color start with the same durability.

Every day, I pick out a clean shirt to wear, and it becomes dirty. Once I run out of all clean black shirts or all clean white shirts, I wash all my dirty shirts of both colors and start over. Clean shirts do not get washed. Whenever a shirt gets washed, its durability goes down by one. Immediately after washing, if the durability of a shirt reaches 0, it must be thrown out.

When picking which shirt to wear of a particular color, I always choose a shirt with the highest durability of that color to ensure even wear and tear among shirts.

Challenge:

Take in a sequence of two characters of infinite length (eg. b b b w b w w b...) representing my choice of shirt to wear on that day. Continue execution until either my last black shirt or my last white shirt is thrown out. Once this occurs, stop consuming input and halt execution immediately. Note that the program must not consume any more input than is required before halting.

Inputs:

Number of black shirts, number of white shirts, durability of black shirts, durability of white shirts, and an infinite number of two single characters, your choice (eg. b and w)

Note: if your language of choice does not support reading input of an infinite length (i.e. from a stream), assume an input of arbitrary length that is at least long enough for one color of shirt to run out.

Output:

None. The program must simply immediately halt when the last shirt of either color is thrown away.

Note: if your language does not support reading input of infinite length, then instead you should output the number of characters processed.

Test cases:

The following test cases represent the amount of input the program should process before halting. The sequence of w’s and b’s is infinite. The parenthetical afterwards is not part of the input or output, but simply represents the end state of how many shirts of each color have not been thrown out.

1 1 1 1 b
(0 b, 1 w left)

1 999 1 999 b
(0 b, 999 w left)

1 999 1 999 w w w w w w w w b
(0 b, 999 w left)

2 999 1 999 b w w w b
(0 b, 999 w left)

2 999 2 999 b w w w b w b w w w b
(0 b, 999 w left)

5 6 3 1 w w w w w b b b b b b b b b b b b b b w
(5 b, 0 w left)

General rules:

This is code-golf, so shortest answer in bytes wins.
Default input rules apply for the first four arguments. For the arbitrarily long input sequence after the first four arguments, input must come from a source which can provide input one character or byte at a time, of theoretically infinite length, such as STDIN or some other stream. If your language of choice does not support these features, see above.

05AB1E, 14 bytes

*Š*‚[ICÓ-W_iõq

Try it online!

Uses p instead of b, because pink is prettier than black.

Explanation:

*             # number of white shirts * durability of white shirts
 Š            # swap
  *           # number of pink shirts * durability of pink shirts
   ‚          # pair the two products in a list
[             # infinite loop
 I            # get the next input
  =           # print (only in the TIO version, not actually needed)
   C          # convert from binary (this yields 51 for p and 58 for w, don't ask why)
    Ó         # list of exponents in the prime factorization
     -        # subtract from the durability list
      W_i     # if the minimum of the list is now 0
         õq   # exit without printing anything


First Number to Contain Each Letter Given a single letter from A to Z (except J and K) as input, output the smallest non-negative integer containing that letter in its written form. Assume numbers never contain the word "and", so 101 is "one hundred one", not "one hundred and one". Assume American (short-scale) counting, so one million is 10^6 and one billion is 10^9.

a 1000                           one thousand
b 1000000000                     one billion
c 1000000000000000000000000000   one octillion
d 100                            one hundred
e 0                              zero
f 4                              four
g 8                              eight
h 3                              three
i 5                              five
j
k
l 11                             eleven
m 1000000                        one million
n 1                              one
o 0                              zero
p 1000000000000000000000000      one septillion
q 1000000000000000               one quadrillion
r 0                              zero
s 6                              six
t 2                              two
u 4                              four
v 5                              five
w 2                              two
x 6                              six
y 20                             twenty
z 0                              zero

J and K are not part of the input specification, so your behavior is undefined for them. Given one of the above letters, output the (decimal) number next to it. You can take input in lowercase or uppercase, but you cannot require that some inputs are lowercase and others uppercase.

This is code-golf, so the shortest answer in bytes wins.

JavaScript (Node.js),  78 75 74  73 bytes

c=>(n=([x]=Buffer(c+'8>P7 $(#%  +;! MD &"$%"&4 '))[x-96]-53)<0?n+21:10**n

Try it online!
How?
Each value is encoded with a single printable character. We use the ASCII range \$[32..52]\$ to encode \$n-32\$ and the range \$[53..80]\$ to encode \$10^{n-53}\$.
Commented
c =>                                   // c = input character
  ( n =                                //
    ( [x] =                            // let x be the 1st byte of the
        Buffer(                        // buffer made of:
          c +                          //   c followed by
          '8>P7 $(#%  +;! MD &"$%"&4 ' //   the encoded values
        )                              //
    )[x - 96]                          // let n be the encoded value corresponding to c
    - 53                               // minus 53
  ) < 0 ?                              // if n is negative:
    n + 21                             //   return n + 21
  :                                    // else:
    10 ** n                            //   return 10 ** n


You've got a book to make! You work at a virtual, old-fashioned printing press. To help you arrange your monospace letters faster, you decide to make the shortest program possible to help you. Given a string of text and a page size, generate and output each page of the text.

Examples

For example, with a page width of 14, height 7, and some text, here is your book:

14, 7, "Fruits make an extremely good snack due to their utterly scrumptious sweetness. They are also very healthy for you."
+------------+
| Fruits     |
| make an    |
| extremely  |
| good snack |
| due to     |
+------------+

+------------+
| their      |
| utterly    |
| scrumptio- |
| -us        |
| sweetness. |
+------------+

+------------+
| They are   |
| also very  |
| healthy    |
| for you.   |
|            |
+------------+

Here's the basic page setup:

|---i.e.14---|
+------------+ -
| Xxxxxxxxxx | |
| Xxxxxxxxxx | i.
| Xxxxxxxxxx | e.
| Xxxxxxxxxx | 7
| Xxxxxxxxxx | |
+------------+ -

A few things

There is a one-space margin between the page edges and the text.
The width and height include the box edges, if that wasn't clear.
Wraparound only occurs if a word can't fit on a single line.
The program needs to be able to output as many pages as needed, and only that many.
Your program has to support any page size, not just 14 by 7.
This is code golf, so the smallest solution in bytes (any language) wins.
Don't ruin the fun. Standard loopholes are obviously not allowed.

Oh, and, by the way:

+------------+
| May the    |
| best book  |
| publisher  |
| win. Good  |
| Luck!      |
+------------+

+------------+
| Best       |
| program    |
| so far:    |
| Charcoal   |
|            |
+------------+


Character counts in source code Write a program that outputs a list of the number of occurrences of each unique character in its source code.

For example, this hypothetical program {Source_Print_1}; should produce this output:

; 1
P 1
S 1
_ 2
c 1
e 1
i 1
n 1
o 1
p 1
r 2
t 1
u 1
{ 1
} 1

The formatting should match this example. No extraneous whitespace is allowed, except an optional final newline.

Your program may not read its own source code from the source file.

The characters listed must be in one of two orders. Either the order of character values in the character encoding used by your language (probably ASCII), or the order the characters appear in your source.

This question inspired by this comment by Jan Dvorak.

///, 12 bytes

  4
4 4

 4

A big thank you goes to @user23013, who suggested this improvement over my CJam code, outgolfing his own, highest-scoring answer in the process.

The characters are sorted by appearance. This code works in any language that just prints its own source code under the given circumstances (PHP, ASP, etc.).

CJam, 20 bytes

''S5N'5S5N'NS5N'SS5N

This approach doesn't use any built-in character counting.

Try it online in the CJam interpreter.

How it works

''S5N e# Push a single quote, a space, the integer 5 and a linefeed.
'5S5N e# Push the character 5, a space, the integer 5 and a linefeed.
'NS5N e# Push the character N, a space, the integer 5 and a linefeed.
'SS5N e# Push the character S, a space, the integer 5 and a linefeed.


Is there an unmatched parenthesis in this String? Introduction

Given a String containing an arithmetic expression, your task is to output a truthy or falsey value based on whether it contains unmatched parentheses.

Input

Your program should take in a String containing an arithmetic expression. It may take input in any way except assuming it to be present in a pre-defined variable. Reading from file, input box, modal dialog box etc. is fine. Taking input as function argument is allowed as well!

Output

Your program should output a truthy or falsey value based on whether the input String contains any unmatched parentheses. It may output in any way except except writing to a variable. Writing to file, screen, console, terminal etc. is allowed. Outputting with function return is allowed as well!

Rules

For the purpose of this challenge, a parentheses is defined as any one of [, {, (, ), }, ]. A parentheses is said to be unmatched if it does not have any corresponding opening/closing parentheses. For example, [1+3 does contain unmatched parentheses.
Ordering of parentheses does not matter in this challenge. So, ]1+3[ does not contain any unmatched parentheses. {[)(}] doesn't, as well.
The input String will only contain following characters : {, [, (, ), ], }, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, +, -, *, / and ^.
Your program should output a truthy value if the input String contains an unmatched parentheses.
Your program should output a falsey value if the input String does not contain an unmatched parentheses.
You must specify the truthy and falsey values in your post.
The input String will never be empty.
If the input String does not contain any parentheses, your program should output falsey value.
Standard loopholes apply.

Test Cases

Input            ->            Output

"{"                            Truthy
"{{{{}}"                       Truthy
"{[]}"                         Falsey
"[]]["                         Falsey
")()()()("                     Falsey
"1+4"                          Falsey
"{)"                           Truthy
"([)]"                         Falsey
"(()"                          Truthy
"2*{10+4^3+(10+3)"             Truthy
"-6+[18-{4*(9-6)}/3]"          Falsey
"-6+[18-{4*)9-6](/3}"          Falsey

Winning Criterion

This is code-golf, so the shortest code in bytes wins!

Note

I'll be adding a similar challenge but in which order will matter, after some time! Stay Tuned!

Python 2, 47 bytes

lambda s:map(s.count,'([{')!=map(s.count,')]}')

Try it online! Test cases from musicman523.

Checks if list of counts for each type of open paren matches that for the corresponding close parens.

The program is one byte longer

q=input().count
print map(q,'([{')!=map(q,')]}')


Invert Some Switches on a Switchboard Inspired by this challenge.
Goal:
Given a pre-configured switchboard and a list of indexes, invert the switches at the given indexes.
A switchboard is made up of some number of switches (v or ^) wrapped in -'s and arranged into rows of varying length. Here is an example switchboard:
-v-^-v-
-^-v-
-v-^-v-

To invert/flip a switch means changing it from v to ^, or from ^ to v.
The switches are indexed left-to-right, top-to-bottom. E.g., in the example above, the last v in the first row would be in position 3 and the ^ in the middle row would be at 4 (using 1-indexing).
Input:

A string (or list of strings) representing the switchboard. It is guaranteed to match the regex ((-[v^])+-)(\n(-[v^])+-)*.
A possibly empty list of numbers representing indexes, may be 0 or 1 (or some arbitrary number if you want) indexed. These are the switches that need to be flipped.

Output:

A switchboard in the same shape as the input with the specified switches inverted. Any unspecified switches should retain their initial state.

Rules:

Input will always be correctly formatted and no given indexes will be out of bounds.
The list of indexes will be sorted and will have no duplicates.
State in your answer what indexing you use, be it 0, 1, or some arbitrary one.
Trailing whitespace is fine as long as the output looks like the input.
This is code-golf so shortest code wins.

Examples:
#Using 1-indexing
input: #Empty Case
[],
-v-^-v-

output:
-v-^-v-

input: #Single switch
[1],
-v-

output:
-^-

input: #Skip a line
[3,5],
-^-v-v-
-v-
-^-^-

output:
-^-v-^-
-v-
-v-^-

input: #Flip one in each line + number wrap
[3,4,6],
-^-v-v-
-v-
-^-^-

output:
-^-v-^-
-^-
-^-v-

input: #Flip 'em all
[1,2,3,4,5,6],
-^-v-v-
-v-
-^-^-

output:
-v-^-^-
-^-
-v-v-

Vim, 60, 46, 38, 37 bytes/keystrokes

qq/\d
ggDJ@"/[v^]
sv^<esc>l?\V<C-r>"
x@qq4u@q

<esc> and <C-r> are both 1 byte/keystroke. Byte Counter

Test Case 1 (Verbose mode)

Test Case 2 (Verbose mode)

Thanks to Grimy for the ideas that led to a reduction of 22 bytes :)


Fill the holes in letters Sometimes when I'm bored, I take some text and fill the "holes" in the letters. But isn't filling the holes the most boring thing you can do? I think we should automate it, so we could use our time better.

Standard code-golf rules apply.

Input

A string containing sequence of alphanumeric characters (a-z, A-Z, 0-9) and spaces.

Output

Image containing string rendered and holes on it filled. You can use any human readable font as long as it still requires filling the holes. You can either save image to file i.png (in png format) or just display the image.

Image properties:

Black text
White or transparent background
Padding:

The dimensions of the image can be maximum two times the dimensions of the text
Padding should be same color as background, either white or transparent

Example

Input: Example text

Output:

Bash, 135 bytes

convert +antialias -pointsize 99 label:$1 -fill red -draw 'color 0,0 floodfill' -fill black -opaque white -fill white -opaque red i.png

Uses ImageMagick (convert).

Sample output:

convert
  +antialias                              # disable antialiasing
  -pointsize 99                           # annoyingly necessary (see below)
  label:$1                                # draw input text
  -fill red -draw 'color 0,0 floodfill'   # flood fill from (0,0) with red
  -fill black -opaque white               # replace all white with black
  -fill white -opaque red                 # replace all red with white
  i.png

Disabling antialiasing is required because otherwise antialiased interior parts of the letters wouldn't flood fill. Setting the font to a large size is also required because some fonts have "gaps" in letters that should have "holes" in them at small font sizes (in my tests, the a wasn't filled at the default small font size).


Make a polyglot generator A polyglot is a program that runs in several languages.
Your challenge is to:
Choose at least two languages (Different versions count as different languages)
Create a program or function that takes several positive integers (one for each language you chose) and returns a program that:
Is a valid program in all of those languages
When run in language A, outputs the first number;  When run in language B, outputs the second number; etcetera. Exiting by error is allowed, as long as the generated program prints the number first
The generator does not need to be in one of your chosen languages.
You can assume the inputted numbers within your chosen languages' limits. For example, if BF is one of your languages, the number for BF will be at most 255.
UPDATE
Explicitly checking the version number or implementation of the language is forbidden. To differentiate, use differences in language features.
Scoring
Your score is [code length] / [number of languages]2.
Example:
Let's say you were using JS/Python 3, in a JS program:
(x,y)=>`1//1;'''
console.log(${x})
//''';print(${y})`

Your score would be \$\frac{53}{2^{2}}\$ = 13.25.
The lower your score, the better.

Python 3, 167 bytes, produces Python 3.0, 3.1, ..., 3.9, 3.10, \${167 \over 11^2}\approx1.38\$
thanks to SuperStormer for refreshing my memory, allowing to add 3.10.

lambda r:'try:exec("%s");o=%d\nexcept:0\n'*10%sum(zip("0;int.bit_length;callable;u'';import enum;b''%();f'';breakpoint;(a:=0);{}|{}".split(';'),r),())+'print(o)'

Try it online!
This works by trying to evaluate expressions code that rely on new language features and updating the output value if successful. By including more subversions, the score could probably be decreased by quite a bit.

Version
Code
New Language feature

3.1
int.bit_length
New builtin

3.2
callable
New builtin

3.3
u''
Old syntax for unicode strings re-added from Python 2

3.4
import enum
New module called enum

3.5
b''%()
String formatting with % for bytes objects

3.6
f''
f-strings

3.7
breakpoint
New builtin function

3.8
(a:=0)
Assignment expressions

3.9
{}|{}
Dictionary union with |

3.10
a:x=0
postponed evaluation of annotations is now enabled by default


Help me Open the Box I have an ASCII-art box and I need a program to open it.

Examples

Input:

-------
|     |
|_____|

Output:

      /
     /
    /
   /
  /
 /
/
|     |
|_____|

Specification

The first line will only consist of -, at least 3 of them
The middle rows will start with | have spaces, and end with |

All the middle rows will be the same

The last row will start with | have _ and end with a |
All rows will be the same length

Opening the box:

Each - should be replaced by a / in ascending lines and position.

JavaScript ES6, 57 bytes

s=>s[r="replace"](/-+/,s=>s[r](/-/g,`
$'/`))[r](/-/g,' ')

Outputs a leading newline. Works by taking the row of -s and converting them into a triangle, then replacing the -s with spaces.

Edit: Saved 5 bytes thanks to @edc65.


Compute the Hausdorff Distance Introduction

The Hausdorff distance measures the difference between two subsets of a metric space.
Intuitively, a metric space is just some set with a built-in distance function; in this challenge, we will use natural numbers with the ordinary distance d(a, b) := abs(a - b).
The Hausdorff distance between two non-empty finite sets A and B is given by

max(max(min(d(a, b) for b in B) for a in A),
    max(min(d(a, b) for a in A) for b in B))

in Python-like notation.
The Hausdorff distance can be computed by finding the element of A for which the distance to the nearest element of B is maximal, and the element of B for which the distance to the nearest element of A is maximal, and then taking the maximum of these distances.
In other words, if the Hausdorff distance is d, then every element of A is within distance d of some element of B, and vice versa.

Input

Your input is a single list of integers.
It only contains the elements 0,1,2,3, which signify whether the given index of the list is an element of neither A nor B, only A, only B, or both A and B.
For example, the input [0,1,1,0,2,3] means that A = {1,2,5} and B = {4,5}, if we use 0-based indexing (which makes no difference, as our metrics are translation invariant).

Output

Your output is the Hausdorff distance between A and B; in the above example, it is 3.
If either set is empty, then the distance is not defined, and you shall return -1.

Rules

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

Test Cases

[] -> -1
[0] -> -1
[0,1,0] -> -1
[2,0,0,2] -> -1
[0,1,2,3] -> 1
[0,3,3,0,0,0,0,3] -> 0
[1,0,0,1,0,0,1,3,1] -> 7
[1,0,0,0,0,3,0,0,0,0,2] -> 5
[0,1,1,3,1,3,2,1,1,3,0,3] -> 2
[2,2,2,1,2,0,3,1,3,1,0,3] -> 3
[1,3,0,2,0,2,2,1,0,3,2,1,1,2,2] -> 2
[1,0,1,1,2,0,1,2,3,1,0,0,0,1,2,0] -> 4

CJam, 53 52 46 38 37 bytes

3,q~f{f&:L,{L=},}$~ff{-z}_z+::e<W+:e>

Takes input on STDIN as a CJam style array:

[0 1 2 3]

Here is a test harness which converts all the test cases to this format and runs the code on them. Although the results are in the input field, they are not used by the code (remove them if you don't trust me :)).

Explanation

First, we parse the input to get the two sets A and B:

3,q~f{f&:L,{L=},}$~
3,                  "Push [0 1 2]. 1 is for A, 2 is for B, and 0 we can luckily ignore
                     as we'll see later.";
  q~                "Read and evaluate the input.";
    f{          }   "Map this block onto the [0 1 2] array, copying in the input for
                     each iteration.";
      f&:L          "Take the bitwise AND with each element of the input and store the
                     result in L.";
          ,{  },    "Get the length N, and filter the range [0 .. N-1] by evaluating
                     the block for each element.";
            L=      "Check if the bitwise AND at that index yielded something non-zero.
                     This gives an empty array for 0, A for 1 and B for 2.";
                 $  "Sort the three arrays. This has two important effects: a) it moves
                     the empty array resulting from 0 to the front, and b) if only one
                     of A and B is empty, it moves the non-empty one to the end.";
                  ~ "Unwrap the array, dumping all three sets on the stack.";

And now we find the absolute differences and select the max of the mins:

ff{-z}_z+::e<W+:e>
ff{-z}             "Turn A and B into a matrix of absolute differences.";
      _z           "Duplicate and transpose.";
        +          "Add the two together, so I've got one row of distances for
                    each element in either A or B.";
         ::e<      "Find the minimum of each row.";
             W+    "Add a -1 in case one set was empty.";
               :e> "Get the overall maximum.";

Note that we've kept the empty array resulting from the initial 0 at the bottom of the stack all the time, but empty arrays don't contribute anything to the output.


Does the code terminate? This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.

def is_perfect(n):
    return sum(i for i in range(1, n) if n % i == 0) == n

n = 3
while not is_perfect(n):
    n = n + 2

Mathematicians conjecture that there are no odd perfect numbers, but it has never been proven, so no one knows if this piece of code will ever terminate. Can you come up with other pieces of code (perhaps relying on other open problems like the Collatz conjecture, or the twin primes conjecture) that are shorter, but for which it is unknown whether or not they terminate?

Edit: Some people have brought up a good additional rule - The solutions to the question should be deterministic. Although it might be even more interesting if you could find shorter solutions using nondeterminism. In this case, the rule would be to find a snippet for which the probability of termination is unknown.

Jelly, 7 bytes

!‘Æ²µ4#

Try it online!

Background

This will terminate once it finds a fourth solution to Brocard's problem, i.e. a solution n! + 1 = m² with (n,m) ≠ (4, 5), (5, 11), (7, 71) over the positive integers. The implementation doesn't use floating point arithmetic, so it will only terminate if it does find a fourth solution or if n! can no longer be represented in memory.

Brocard's problem was first used in this answer by @xnor.

How it works

!‘Æ²µ4#  Main link. No arguments. Implicit argument: 0

    µ4#  Convert the links to the left into a monadic chain and call it with
         arguments k = 0, 1, 2, ... until 4 of them return 1.
!        Factorial; yield k!.
 ‘       Increment; yield k! + 1.
  Æ²     Squareness; return 1 if k! + 1 is a perfect square, 0 if not.


Count the Unique Rectangles! In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangles, i.e. find the number rectangles that are all of different dimensions?

For example, consider 4 horizontal, or y lines at [-250,-50,50,250] and 4 vertical, or x lines at [-250,-70,70,250]. Graphing these on a coordinate plane with infinite dimensions results in the following 500 x 500 pixel closed grid, in which the length of each segment in pixels and the lines corresponding to their respected values from the arrays are shown:

which contains the 16 unique rectangles shown in this animated GIF:

However, if the topmost line (y = 250) were to be removed, there would only be 12 unique rectangles, as the top 3 rectangles would be factored out since they each won't be fully closed without the y = 250 line.

Task

So, as shown above, the task is counting the number of rectangles rectangles with different dimensions. In other words, given an input of 2 arrays, with the first one containing all equations of all x lines, and the latter containing those of all y lines, output the total number of rectangles of different dimensions created when the lines corresponding to those equations are graphed on a coordinate plane.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.
If either of the arrays have less than 2 elements, the output should be 0, since if there are less than 4 lines on the plane, there are no closed, 4 sided figures.
The input arrays are not guaranteed to be sorted.
You can assume that there are not any repeated values in either of the the input arrays.
A n x m rectangle is the same as a m x n rectangle. For example, a 300 x 200 rectangle is the same as a 200 x 300 one.
Standard loopholes are prohibited.

Test Cases

Given in the format Comma Separated Arrays Input -> Integer output:

[],[] -> 0
[-250,-50,50,250],[-250,-70,70,250] -> 16 (Visualized above)
[-250,-50,50,250],[-250,-70,70] -> 12
[-40, 40],[-80, 50] -> 1
[10],[10] -> 0
[60, -210, -60, 180, 400, -400], [250, -150] -> 12
[0,300,500],[0,300,500] -> 6
[0,81,90],[0,90,100] -> 9

Remember, this is code-golf, so shortest code wins!


Output an ASCII "splat" If you throw an ASCII egg in a given direction, you end up with an ASCII splat of size n. It "starts" with one o (the yolk), and continues in a given direction with "lines" consisting of 2 up to n *'s. The *'s are separated by one "space", and the o and all the "lines" of *'s are separated by "lines" of "space".

The direction of the splat can be any one of eight directions from o, for example:

1 2 3
4 o 5
6 7 8

Here are examples of ASCII splats of size 4 in directions 5, 2 and 3 respectively. On the left is the actual ASCII splat, and on the right is the same splat but with the "lines" of "space" replaced with actual "lines" (i.e. - or \ or | depending on the direction) just to clarify what is meant by a "line" of space.

Size 4, direction 5
      *      | | |*
    *        | |*|
  *   *      |*| |*
o   *       o| |*|
  *   *      |*| |*
    *        | |*|
      *      | | |*

Size 4, direction 2
* * * *     * * * *
            -------
 * * *       * * *
            -------
  * *         * *
            -------
   o           o

Size 4, direction 3
*           *
            \
* *         *\*
            \ \
* * *       *\*\*
            \ \ \
o * * *     o\*\*\*

Challenge

Given n ≥ 1 and one of the 8 possible directions, write a function or program that outputs the ASCII splat of size n in the given direction.

Input and output

Any consistent, reasonable input format is allowed. You don't need to map directions to the integers 1 to 8 in the same way I did - if some other way of specifying the direction is easier, go ahead. But say what you did if it isn't clear.

The output will consist of o, *, spaces (U+0020) and newlines (U+000A) that produce the ASCII splat. Leading, trailing, otherwise extra whitespace is permitted on any line.

Rules

This is code-golf. Standard rules apply.

More examples

Size 1, any direction
o

Size 3, direction 6
* * o

  * *

    *

Size 5, direction 7
    o

   * *

  * * *

 * * * *

* * * * *

Charcoal, 20 18 bytes

↘ＥＮ×*⊕ιＭ↗oＵＥ¬﹪η²⟲η

Try it online! Link is to verbose version of code. Explanation:

↘ＥＮ×*⊕ι

Draw a diagonal triangle of splats.

Ｍ↗o

Place the egg.

ＵＥ¬﹪η²

For even rotations, expand the splat horizontally to match the output requirement. This requirement doesn't match Charcoal's usual expectations. Try it online! (verbose) for how it looks without.

⟲η

Rotate the splat as required, using the following code for directions:

321
4o0
567

This 37 31-byte version avoids extraneous whitespace by only rotating in right angles:

¿﹪η²Ｇ↘←θ*«↘Ｅθ×*⊕ι↗»oＵＥ¹﹪η²⟲⊗÷η²

Try it online! Link is to verbose version of code.


Determine the area enclosed by slashes For example, let's look at the following ASCII art:
/\    - encloses a total of 2 cells - half a cell per slash
\/
 /\   - encloses 4 cells fully and half of 8 cells, for a total of 8
/  \
\  /
 \/

Your challenge is to write a program that determines (and outputs) the total area enclosed by ASCII art composed only of spaces, slashes and newlines. Slashes won't necessarily be a part of a shape with non-zero area. A point is defined as enclosed iff it is unreachable from any point outside the art's bounding box, if slashes are impassable.
Slashes have zero area and cells are assumed to be \$1\times1\$ squares. /s represent lines that connect the lower left corner with the upper right corner, and \s represent lines the connect the upper left corner with the lower right corner of the corresponding cells. Spaces represent empty space.
Test cases
/\/\
\   \
 \/\/

Encloses 3 cells fully and 10 partially, for a total of 8.
///\\\
//  \\
/ /\ \
\ \/ /
\\  //
\\\///

Encloses 12 cells fully (the four innermost slashes have both corresponding half-cells enclosed) and half of 12 cells, for a total of 18.
/\/\
/\/\
/\/\

Encloses 0 cells.
 /\
/  \
\/\/
/\/\
\  /
 \/

Encloses 8 cells fully and 12 cells partially, for a total of 14.
   /\
  /  \
 /  \ \
/   /  \
\ \/  \/
 \ \  /
  \   \
   \/\/

Encloses 25 cells fully and half of 18 cells, for an area of 34.
This is tagged code-golf, so the shortest answer wins.

JavaScript (ES6),  228 195 192  185 bytes
Expects a matrix of characters as input.
This can be quite slow on some inputs, such as the last test case.
m=>m.map((r,Y)=>r.map((_,X)=>n+=(g=(x,y,z,q=z&2,r=m[y],v=r&&r[x])=>v?(v|=64+(v>{})+!++v)^(r[x]|=v|4<<z)?g(x+--q*~z%2,y-q*z%2,z^2)&g(x,y,v&3?z^=v&2|1:z+1&3)|!(r[x]=v):1:0)(X,Y,0)),n=0)|n

Try it online!
How?
Grid encoding
We divide each cell into 4 areas as follows:

The current position is encoded as \$(x,y,z)\$, where \$(x,y)\$ is the position in the matrix and \$z\$ is the ID of the area.
The characters in the original matrix are converted on the fly to 7-bit integers as they are visited:
+---------> a marker to tell that this tile has been converted (always 1)
|      +--> 4 bits to tell whether a given area has been visited
|      |
|      |      +-----> set to 1 if the cell contains an anti-slash
|  ____|____  |  +--> set to 1 of the cell contains a slash
| /         \ |  |
1 z3 z2 z1 z0 AS S

The conversion is done with:
v |= 64 + (v > {}) + !++v

The expression (v > {}) is only true for '\' and !++v is true for either '/' or '\'. If v is already an integer, it is left unchanged.
Algorithm
Evaluating the area enclosed by slashes is equivalent to counting the number of cells from which we can't escape from the grid, starting from a given area ID. We arbitrary start from area #0, but that would work with any of them as long as it is consistent.
We iterate on all possible starting points and process some kind of flood-filling that takes the area IDs into account.
For each visited cell, we try to move to an adjacent cell (left figure) and  to another area within the same cell (right figure).

The recursion stops either when we escape the grid or when we get trapped.