Average impact of multiple conversion errors Imagine four people stand in a line. The first looks at a thermometer, and tells the temperature to the person on their right. This continues down the line, until the last person writes the temperature on a sheet of paper. Unfortunately, due to a miscommunication, every person in the line converts the temperature to their preferred unit, without knowing which it already was.
Let's say the people's preferred units are celsius, fahrenheit, fahrenheit, celsius. The first reads the temperature as 20°C. The second converts to fahrenheit, and determines that it is 68°F. The third, not knowing they have received the temperature in °F already, determines that it is 154.4°F. Finally, it is converted back to °C by the fourth person, who determines that it is 68°C.
Task:
You will be given two inputs: a temperature (t), and a number of people (n). Your program (or function) should return the average difference between the original and resulting temperatures, for every possible assortment of n people.
There are two temperature units: °F and °C. To convert between them, you can use \$F=\frac95C+32\$ and \$C=\frac59(F-32)\$.
You can choose whether your program receives the inputted temperature in °F or °C. The first person should always receive an accurate temperature, converted to their preferred unit only if necessary.
As an example, we'll use an inputted temperature of 41°F, and just 3 people. There are 8 temperature preferences possible:
FFF   41°F  ->  41.0  ->  105.8  ->  222.44  ->  222.44°F
FFC   41°F  ->  41.0  ->  105.8  ->   41.00  ->  105.80°F
FCF   41°F  ->  41.0  ->    5.0  ->   41.00  ->   41.00°F
FCC   41°F  ->  41.0  ->    5.0  ->  -15.00  ->    5.00°F
CFF   41°F  ->   5.0  ->   41.0  ->  105.80  ->  105.80°F
CFC   41°F  ->   5.0  ->   41.0  ->    5.0  ->    41.00°F
CCF   41°F  ->   5.0  ->  -15.0  ->    5.00  ->    5.00°F
CCC   41°F  ->   5.0  ->  -15.0  ->  -26.11  ->  -15.00°F

The average distance from 41°F is 54.88°F, which is the program's output.
I/O:
Temperature should be represented as a float, decimal, or fraction of some sort. The accuracy should be within reasonable bounds; for inputs less than ten people at low temperatures there shouldn't be floating point errors or imprecision noticeable in the first four decimal digits.
You may represent the temperatures inputted and outputted as either °F or °C, but must be consistent (although the input can output can be different units as long as they don't change). Temperatures can be negative. The number of people will never be less than two.
The output is referred to as a temperature above, although it's technically the arithmetic mean of multiple temperatures.
Test Cases:
Input unit is the same as output unit for all test cases.
41°F   2   ->  25.2
41°F   3   ->  54.88
41°F   4   ->  77.236444...
41°F   10  ->  295.4268...
20°C   4   ->  57.21218...
-1°C   2   ->  12.133...
-20°C  2   ->  6.2222...
-40°F  4   ->  0

Other:
This is code-golf, shortest answer in bytes per language wins!

APL (Dyalog Unicode), 41 bytes

(|40+⎕)+.×(|÷≢)1-1.8*1(-,+)⍨⍣(⎕-2)⊢1-3|⍳4

Try it online!
A full program. Takes the number of people, then the initial temperature. TIO version is wrapped in a function for easier testing. As I pointed out in a comment, the initial and final units do not matter as long as they are equal.
The math
The code exploits the fact that Fahrenheit-Celsius conversion has a fixpoint at -40 (-40°F = -40°C). Then we can add 40 to all temperature readings, and then the whole series of conversion reduces into a (positive or negative) integer power of \$\frac95\$.
$$
F+40=\frac95(C+40), \quad C+40 = \frac59(F+40)
$$
Since every temperature value is offset by the constant value of 40, the difference between two offset temperature values is the same as that of the original. Therefore, it suffices to apply the offset to the initial temperature and ignore it to the end.
Let's call \$r = \frac95\$.
Now to the part of counting all conversion paths. Let's say the initial reading is in Fahrenheit. Then:

Initial conversion: F→F (\$r^0\$) or F→C (\$r^{-1}\$).
Final conversion: F→F (\$r^0\$) or C→F (\$r^1\$).
All inner conversions: C→F (\$r^1\$) or F→C (\$r^{-1}\$).

So the task reduces to finding all the individual terms in the expansion of \$(r^0 + r^{-1})(r^1+r^{-1})^{n-2}(r^1+r^0)\$. Then plug in the value of \$r\$, evaluate the average of differences to 1, and then multiply with the initial temperature (with offset).
The code
(|40+⎕)+.×(|÷≢)1-1.8*1(-,+)⍨⍣(⎕-2)⊢1-3|⍳4

⊢1-3|⍳4  ⍝ A fancy way to create an array of 0 ¯1 1 0
         ⍝ which represents the powers in (1+r^-1)(r+1)
⍣(⎕-2)   ⍝ Repeat n-2 times...
1(-,+)⍨  ⍝ multiply the given polynomial with (r+r^-1)
         ⍝ and list all powers
1.8*     ⍝ Plug in r = 1.8 and evaluate the powers
1-       ⍝ Difference of each value from 1
(|÷≢)    ⍝ Average of absolute differences from 1
+.×      ⍝ Product and sum with...
(|40+⎕)  ⍝ Absolute difference between -40 and t


Use threes to count the threes! Write a program or function that takes two numbers - x>3 and n>0 - as input, and finds all possible bases b where the digit 3 appears at least n times in (x in base b).

Input and output may be through command line or function arguments, stdin/stdout, graphical input/output, error messages, function returns, etc.

The code must consist entirely of three-symbol "words", where each symbol is a letter or number (in printable ASCII) and the words are each separated by one non-alphanumeric printable ASCII character or newline (see example). Furthermore, adding a space into any of the words must ruin the program.

Shortest code wins.

Example

The following code meets the first part of the specs (but doesn't actually work):

abc 123 fwe[3gY]4fs-es3=13N
338 w3W|W2w

Test Cases

5 1 ->

8 1 -> 5

23 1 -> 4 5 6 7 10 20

15 2 -> 4

111 2 -> 4 6 9 36

819 3 -> 4 16

A test program written in Java 8 can be found at http://pastebin.com/E8GpHbfB.

BBC Basic, 207 bytes

BBC Basic allows you to abbreviate keywords by ending them with a period (e.g., PRINT ↠ PRI., REPEAT ↠ REP.). I should really be using a named procedure here instead of a function declaration, but abbreviating DEF PROC_whatever to DEF PRO. just isn't going to work.

The rules make it impossible to use an IF statement, so instead I'm calculating the target line of a GOTO statement based on the result of a comparison. (In BBC Basic, true has a value of –1, so 101-ZIP is equal to 102 if ZIP is true, and 101 otherwise.)

The last line (103=000) ends the function definition and returns a value of zero.

Tested on BeebEm3. Lines 10–60 are excluded from the byte count.

10 READ X,N : IF X=0 THEN END
20 PRINT "x=";X;", n=";N
30 A = FNX(X,N)
40 GOTO 10
50 DATA 5,1,8,1,23,1,15,2,111,2,819,3,0,0
60 REM -------------------
100 DEF FNX(FOO,BAR)BAZ=004:REP.BAT=000:QUX=FOO:REP.XXD=QUX MOD BAZ:ZAP=XXD=003:BAT=BAT-ZAP:QUX=QUX-XXD:QUX=QUX/BAZ:UNT.QUX=000:ZIP=BAT<BAR:ZIP=101-ZIP:GOT.ZIP
101 PRI.BAZ
102 BAZ=BAZ+001:UNT.BAZ=FOO
103=000


Implement a strange automaton I was playing around with cellular automaton and I found one that had some interesting behavior.  Here's how it works:

It reads a binary string from left to right, if it encounters a 1 followed by 2 other values it will append a 0 to the result and continue reading.  If it encounters a 0 (or there are less than 3 values left) it will append the current value and a 1 and continue reading.  At the end of the string it will append a single 1 to the result.

Here's a worked out example of one generation

01011111
^

We first encounter a 0 so we append 01 to our result

01011111
 ^
01

Now we encounter a 1 so we append a zero and skip the next two values

01011111
    ^
010

We encounter another 1 so we do the same

01011111
       ^
0100

We now have another 1 but not enough space to jump so we append the current cell and a 1 (in this case 11)

01011111
        ^
010011

We are at the end so we append a single 1 and terminate this generation

01011111
        ^
0100111

Task

Given input in any reasonable format you must create a function or program that computes one generation of the automaton.

This is a code-golf question so answers will be scored in bytes, with fewer bytes being better.

Sample implementation

Here is a sample implementation in Haskell (defines a function d, but the program prints a iterations indefinitely):

d('1':_:_:x) = "0" ++ d x
d(a:x) = a:'1':d x
d x = "1"
r x = x:map d(r x)

Try it online!

V, 26 22 21 bytes

Thanks to @CowsQuack for 4 bytes by combining regexes! And @ØrjanJohansen for another byte with some regex combinations.

Ó1../3
Ó./&1
Ó31/0
A1

Try it online!

Uses substitute multiple times and appends a 1 at the end.  Nothing too fancy.  I have a version that remaps 1 and 0 in insert mode to get the desired effect, but it's quite a bit longer.

(Multiple replacement version: Try it online!)


Embedding Sets of Sets Setup: For two sets \$A,B\$, we say \$A \subseteq B\$  if every element in \$A\$ is also in \$B\$.

Another way of saying this, is that we can order the elements of \$A,B\$ into two lists \$L_A,L_B\$, such that \$L_A[i] = L_B[i]\$ where \$i\$ ranges over the indices of \$L_A\$.

We proceed to extend this idea, to define the relation \$\preceq\$. For two sets of sets, \$A,B\$, we say that \$A\preceq B\$ if we can arrange their elements into lists \$L_A,L_B\$, such that \$L_A[i]\subseteq L_B[i]\$ for all indices of \$L_A\$.

Task: Make a program/function which takes two sets of sets, A,B, determines if A ⪯ B as defined in the set up, and then appropriately returns Truthy or Falsy.

Input: You may give A and B to your input as sets. It is up to you how you wish have your function take A and B, be it separately, as a tuple, etc.

If you so choose, or if your language forces your hand, you can enter your input as lists, frozen sets or even submit elements one by one. Likewise, you may choose the datatype to represent the sets inside A and B.

For simplicity's sake, one may assume the elements of the sets in A and B are all integers.

Output: You can define whatever conditions you want to indicate your Truthy and Falsy inputs, as long as these conditions are independent of the output. (e.g. you can say "if my program never halts, this means Falsy")

Examples, with (1,0) indicating (Truthy, Falsy) respectively

A = {{4004,1}}, B = {{4},{4004,1}} => 1
# L_A = [{4004,1}], L_B = [{4004,1},{4}]

A = {{1,2},{5},{8}}, B = {{3,5},{6},{8},{7}} => 0
# {1,2} is not a subset of any set in B

A = {{4,44},{44,444},{4}}, B = {{4,44,444},{4,14},{4,40,44}} => 1
# L_A = [{4,44},{44,444},{4}], L_B = [{4,40,44},{4,44,444},{4,14}]

A = {{1,2,4},{6}}, B = {{1,2},{4},{6}} => 0
# {1,2,4} is not the subset of a single set in B, only the union of B

A = {{1},{1,2},{2}}, B = {{1,3},{2,3},{1,2}} => 1
# L_A = [{1},{1,2},{2}], L_B = [{1,3},{1,2},{2,3}]

A = {{-1},{8},{}}, B = {{-1,8,2},{8,-1,0}} => 0
# There are three elements in A, but only 2 in B, so the last item in L_A will not
# be paired with a superset, even for the empty set, {}. (vacuity be damned)

A = {{-1},{8},{}}, B = {{0,8},{9,-1},{100}} => 1
# L_A = [{-1},{8},{}], B =[{0,8},{9,-1},{100}]

A = {{1,2}{3,4}}, B = {{1,2,3,4},{}} => 0
# {1,2} and {3,4} are each subsets of {1,2,3,4}, and are not subsets of any other
# set in B, thus in the list, one of these will not be paired with their superset

Python 3, 84 62 58 bytes

Recursive function, A is a list of sets and B is a frozenset; returns false if \$A\preceq B\$ and true otherwise.

f=lambda A,B:A and all(A[0]-b or f(A[1:],B-{b})for b in B)

@PoonLevi and @SurculoseSputum helped save a great amount of bytes.

Explanation:

If A and B satisfy the relationship described, then this recursive statement makes sense:

The first set in A is contained in some i-th element of B and A', B' also satisfy the relationship, where
A' is A without the first set
B' is B without the said i-th element

Because I am returning the reverse, I am actually ensuring that, if the first element of A is contained in some element of B, then A' and B' cannot satisfy the relationship.

Try it online!


Find the minimum cost matching between arrays of integers Consider two sorted arrays of integers \$X\$ and \$Y\$ of size \$m\$ and \$n\$ respectively with \$m < n\$.  For example \$ X = (1,4)\$, \$Y = (2,10,11)\$.

We say that a matching is some way of pairing each element of \$X\$ with an element of \$Y\$ in such a way that no two elements of \$X\$ are paired with the same element of  \$Y\$.  The cost of a matching is just the sum of the absolute values of the differences in the pairs.

For example, with \$X = (7,11)\$, \$Y = (2,10,11)\$ we can make the pairs \$(7,2), (11,10)\$ which then has cost \$5+1 = 6\$.  If we had made the pairs \$(7,10), (11,11)\$ the cost would have been \$3+0 = 3\$.  If we had made the pairs \$(7,11), (11,10)\$ the cost would have been \$4+1 = 5\$.

As another example take \$X = (7,11,14)\$, \$Y = (2,10,11,18)\$. We can make the pairs \$(7,2), (11,10), (14,11)\$ for a cost of \$9\$.  The pairs \$(7,10), (11,11), (14,18)\$ cost \$7\$.

The task is to write code that, given two sorted arrays of integers \$X\$ and \$Y\$, computes a minimum cost matching.

Test cases

[1, 4],      [2, 10, 11]     => [[1, 2], [4, 10]]
[7, 11],     [2, 10, 11]     => [[7, 10], [11, 11]]
[7, 11, 14], [2, 10, 11, 18] => [[7, 10], [11, 11], [14, 18]]

Jelly, 15 14 12 11 bytes

Œ!ż€IASƊÞḢṁ

Try it online!

-1 byte thanks to Jonathan Allan
-1 byte thanks to Mr. Xcoder
-2 bytes thanks to an anonymous editor

Brute force. Takes input as \$Y\$ then \$X\$.

Œ!ż€IASƊÞḢṁ
Œ!                 All permutations of Y.
  ż€               Zip each of the permutations with X.

       ƊÞ          Sort by:
    I              Difference of each pair.
     A             Absolute value.
      S            Sum.
         Ḣ         Take the first matching.
          ṁ        Mold the result like X. Keeps only values up to the length
                   of X which removes unpaired values from Y.


Progression of Matrix Columns Consider the infinite matrix:

0  1  0  1  0  1  0  1  0  1  0  1  0  1  0  1
0  0  2  3  0  0  2  3  0  0  2  3  0  0  2  3
0  0  0  4  5  6  0  0  0  4  5  6  0  0  0  4 ...
0  0  0  0  7  8  9 10  0  0  0  0  7  8  9 10
0  0  0  0  0 11 12 13 14 15  0  0  0  0  0 11
              ...

Each new row of the matrix is constructed by starting with z zeros, where z is the length of positive digits we're using in that row. The positive digits are constructed by starting with 1 and incrementing and adding an additional digit each time you iterate rows. That pattern is repeated infinitely to the right. So, for example, the first row starts 0, 1, 0, 1... while the second row starts 0,0, 2,3, 0,0, 2,3.... Following the pattern, the third row starts 0,0,0, 4,5,6, 0,0,0, 4,5,6....

Given two integers as input, n and x, output the first (top-most) x numbers of the nth column of the above matrix. (You can choose 0- or 1-indexing for the columns, just specify which in your submission.)

For example, for input n = 0 (0-indexed), the column is entirely 0s, so the output would just be x 0s.

For input n = 15 and x = 6, the output would be [1, 3, 4, 10, 11, 0].

For input n = 29 and x = 15, the output would be [1, 0, 6, 8, 15, 0, 0, 34, 39, 0, 0, 0, 0, 0, 120].

For input n = 99 and x = 25, the output would be [1, 3, 4, 0, 15, 0, 0, 0, 37, 55, 56, 0, 87, 93, 0, 0, 151, 163, 176, 0, 0, 0, 0, 0, 325].

I/O and Rules

The input and output can be given by any convenient method.
The input and output can be assumed to fit in your language's native number type.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

JavaScript (ES6), 45 bytes
Takes input in currying syntax (n)(x).

n=>g=x=>x?[...g(x-1),n/x&1&&n%x+x*~-x/2+1]:[]

Try it online!
How?
We use a direct formula to get the value of the cell at column n (0-indexed) and row x (1-indexed):
n / x & 1 &&     // is this cell zero or non-zero?
n % x +          // column modulo row --> increment for a non-zero value at this position
x * ~-x / 2 + 1  // minimum value of non-zero values for this row:
                 // ∑(i=1...x-1)(i) + 1 = x(x - 1) / 2 + 1


Plain Hunt Bell-Ringing Your task is to create a plain hunt (a bell ringing pattern) with n bells. An example with 6 bells:

123456
214365
241635
426153
462513
645231
654321
563412
536142
351624
315264
132546
123456

Each number "bounces" off the side of the grid. From Wikipedia:

  Each bell moves one position at each succeeding change, unless they reach the first or last position, when they remain there for two changes then proceed to the other end of the sequence.

In other words, you swap the bells in adjacent pairs, alternating between taking pairs starting from the the first bell and from the second bell. (Thanks to @xnor for this explanation.) You finish in the same order as the start.

This rule be applied to any number of bells, taken as input.
Standard loopholes are forbidden.

Test Cases

6

123456
214365
241635
426153
462513
645231
654321
563412
536142
351624
315264
132546
123456

3

123
213
231
321
312
132
123

2

12
21
21
12

1

1

0: Falls in to "I don't care" situation.

Python 2, 93 bytes

lambda n:[[.5+abs((n+j-i*(-1)**(i+j))%(2*n)-n+.5)for j in range(n)]for i in range(2*n+(n>2))]

Try it online!

Outputs a list of lists of integer-valued floats.

The map (i,j) -> j-i*(-1)**(i+j) is very similar to multiplication in the dihedral group. This isn't a coincidence. If we let \$a\$ represent swapping every other element starting from the first, and \$b\$ doing so starting from the second, then these generate the dihedral group \$D_{2n}\$ gives by relations \$a^2 = b^2 =(ab)^n =1 \$. Note that the sequence we're asked to output has us alternate applying \$a\$ and \$b\$, and the fact that \$ (ab)^n =1 \$ confirms that we return to where we started after \$2n\$ total steps.

We can see the dihedral connection more clearly if we extend the top row to \$2n\$ elements rather than \$n\$, and write it zero-indexed. Doing the alternating swaps as usual gives a pattern like below for \$n=3\$. This is almost a multiplication table for the dihedral group \$D_{2n}\$, except that we invert the first group element before multiplying \$g,h \to g^{-1} h \$, giving zeroes (identity) on the diagonal \$g=h\$.

  012345
 +------
0|012345
1|103254
2|430521
3|345012
4|254103
5|521430

To return the values back into the range [0,1,2], we need to map back 3->2, 4->1, 5->0. In the code, surprisingly many characters as spent on the simple-looking mapping doing modular indexing into the palindromic "bouncing" list [1,2,...,n-1,n,n,n-1,...,2,1], We implement this as .5+abs((n+k)%(2*n)-n+.5). The Python 3.8 walrus can save at least 2 bytes, though I haven't optimized it.


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

Please post one tip per answer.

I'm not entirely sure whether this is a joke question or not, so I hope I don't get mocked for taking it seriously, but...
Tip 1: Don't End Your Program
The spec says that a program should be ended by three line-feeds, [LF][LF][LF], where the first is the flow control IMP, and the next two are the quit command, but many interpreters will just run your code without the proper ending. Saves you 3 characters in any program.


Find the area of the smallest rectangle to contain squares of sizes up to n This is a sequence question of the usual type, as applied to OEIS sequence A038666. That is, do either of the following:

Accept no or any input, and output A038666 until the heat death of the universe.
Accept a positive integer as input, and output the \$n\$th term of A038666 or its first \$n\$ terms. (If using \$0\$- instead of \$1\$-indexing, then of course you also have to output 1 on 0 input.)

The \$n\$th term of A038666 is the least area among rectangles that contain non-overlapping squares of sizes \$1\times1,2\times2,\dots n\times n\$ if you're using \$1\$-indexing.

Example:

The smallest-area rectangle which can contain non-overlapping squares of sizes \$1\times1\$ through \$4\times4\$ has dimensions \$7\times5\$:

4 4 4 4 3 3 3
4 4 4 4 3 3 3
4 4 4 4 3 3 3
4 4 4 4 2 2 1
x x x x 2 2 x

Therefore, \$a(4)=7\times5=35\$ (\$1\$-indexed).

Similarly, the least-area rectangle containing non-overlapping squares of sizes \$1\times1\$ through \$17\times17\$ has dimensions \$39\times46\$, so \$a(17)=39\times46=1794\$ (\$1\$-indexed).

JavaScript (ES6), 172 bytes

Slower but shorter version suggestion suggested by @JonathanAllan (also saving 4 bytes in the original answer):

f=(n,A,S=(n,c)=>n>=0?c(n)||S(n-1,c):0)=>S(A,w=>(F=(l,n)=>n?S(w-n,x=>S(A/w-n,y=>l.some(([X,Y,W])=>X<x+n&X+W>x&Y<y+n&Y+W>y)?0:F([...l,[x,y,n]],n-1))):A%w<1)([],n))?A:f(n,-~A)

Try it online!

Original answer,  209 183 178  174 bytes

Returns the \$N\$th term of the sequence, 1-indexed.

f=(n,A,S=(n,c)=>n>=0?c(n)||S(n-1,c):0)=>S(A,w=>A%w?0:(F=(l,n)=>n?S(w-n,x=>S(A/w-n,y=>l.some(([X,Y,W])=>X<x+n&X+W>x&Y<y+n&Y+W>y)?0:F([...l,[x,y,n]],n-1))):1)([],n))?A:f(n,-~A)

Try it online!

Commented

Helper function

We first define a helper function \$S\$ which invokes a callback function \$c\$ for \$n\$ to \$0\$ (both included) and stops as soon as a call returns a truthy value.

S = (n, c) =>               // n = integer, c = callback function
  n >= 0 ?                  // if n is greater than or equal to 0:
    c(n) ||                 //   invoke c with n; stop if it's truthy
    S(n - 1, c)             //   or go on with n - 1 if it's falsy
  :                         // else:
    0                       //   stop recursion and return 0

Main function

We start with \$A=1\$.

For each pair \$(w,h)\$ such that \$w\times h = A\$, we try to insert all squares of size \$1\times1\$ to \$n\times n\$ (actually starting with the largest one) in the corresponding area, in such a way that they don't overlap with each other.

We keep track of the list of squares with their position \$(X,Y)\$ and their width \$W\$ in \$l[\text{ }]\$.

We either return \$A\$ if a valid arrangement was found, or try again with \$A+1\$.

f = ( n,                    // n = input
      A ) =>                // A = candidate area (initially undefined)
S(A, w =>                   // for w = A to w = 0:
  A % w ?                   //   if w is not a divisor of A:
    0                       //     do nothing
  : (                       //   else:
    F = (l, n) =>           //     F = recursive function taking a list l[] and a size n
      n ?                   //       if n is not equal to 0:
        S(w - n, x =>       //         for x = w - n to x = 0
          S(A / w - n, y => //           for y = A / w - n to y = 0:
            l.some(         //             for each square in l[]
            ([X, Y, W]) =>  //             located at (X, Y) and of width W:
              X < x + n &   //               test whether this square is overlapping
              X + W > x &   //               with the new square of width n that we're
              Y < y + n &   //               trying to insert at (x, y)
              Y + W > y     //
            ) ?             //             if some existing square does overlap:
              0             //               abort
            :               //             else:
              F([ ...l,     //               recursive call to F:
                  [x, y, n] //                 append the new square to l[]
                ],          //
                n - 1       //                 and decrement n
              )             //               end of recursive call
          )                 //           end of iteration over y
        )                   //         end of iteration over x
      :                     //       else (n = 0):
        1                   //         success: stop recursion and return 1
    )([], n)                //     initial call to F with an empty list of squares
) ?                         // end of iteration over w; if it was successful:
  A                         //   return A
:                           // else:
  f(n, -~A)                 //   try again with A + 1


Generating PBM bitmap files from ASCII text The PBM (Portable BitMap) format is a very simple ASCII black and white bitmap format.

Here's an example for the letter 'J' (copy-pasted from the wikipedia link):

P1
# This is an example bitmap of the letter "J"
6 10
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0

It's time we build a small tool to generate files in this nifty little format!

Your goal is to write the shortest program (in any language) that conforms to the following rules:

Your program takes one string from stdin (for example CODEGOLF.STACKEXCHANGE.COM!)
It generates a PBM file with a bitmapped (readable) representation of the string.
Each character is constructed as a 8x8 grid.
You must support the characters [A-Z] (all uppercase), space, a point ('.') and an exclamation mark ('!').
No external libraries allowed (certainly no PBM related ones)!
The used character set must not simply be external to your program. Part of the challenge is storing the characters efficiently...

Testing for validness of the PBM format can be done with the GIMP (or others). Do show off sample input and output!

The shortest solution will be awarded the answer points on 2012-01-31.

Have fun golfing!

PS: I've added a bounty (percentage-wise a huge part of my codegolf reputation) to (hopefully) draw in more competitors.

Perl, 164 bytes, no zlib/gzip compression

After sleeping on the problem, I managed to figure out a much shorter solution than my first one.  The trick is to take advantage of a minor loophole in the rules: the characters need to fit in 8 by 8 pixels each, but nothing says they have to fill all that space.  So I drew my own 4 by 5 pixel font, allowing me to pack two characters into 5 bytes.

The output looks like this:

 (scaled x 4)

     (original size)

Before giving the actual code with the embedded font data, let me show a de-golfed version:

y/A-Z!./\0-\033/ for @a = <> =~ /./g;
say "P4 " . 8*@a . " 8";
for $p (qw'PACKED FONT DATA') {
    print chr vec $p, ord, 4 for @a;
}

In the actual code, the PACKED FONT DATA is replaced by a binary string consisting of eight whitespace-delimited rows (four 14-byte rows and one 13-byte one, plus three single null bytes for the blank rows).  I deliberately designed my font so that the packed data contains no whitespace, single quotes or backslashes, so that it could be encoded in qw'...'.

Since the packed font string contains unprintable characters, I've provided the actual script as a hex dump.  Use xxd -r to turn it back into executable Perl code:

0000000: 792f 412d 5a21 2e2f 002d 1b2f 666f 7240  y/A-Z!./.-./for@
0000010: 613d 3c3e 3d7e 2f2e 2f67 3b73 6179 2250  a=<>=~/./g;say"P
0000020: 3420 222e 382a 4061 2e22 2038 223b 666f  4 ".8*@a." 8";fo
0000030: 7224 7028 7177 2700 20e6 e6ff 9612 8999  r$p(qw'. .......
0000040: e6e6 7759 99f5 0420 9999 8898 128a df99  ..wY... ........
0000050: 9928 5999 1504 20ef 98ee fb12 8cb9 e9e9  .(Y... .........
0000060: 2659 6965 0420 9999 8899 928a 9989 ab21  &Yie. .........!
0000070: 599f 8220 e9e6 8f96 62f9 9986 972e 2699  Y.. ....b.....&.
0000080: f284 2000 2000 2729 7b70 7269 6e74 2063  .. . .'){print c
0000090: 6872 2076 6563 2470 2c6f 7264 2c34 666f  hr vec$p,ord,4fo
00000a0: 7240 617d                                r@a}

Here's how it works:

The first line (in the de-golfed version) reads a single line of input, splits it into an array of characters (conveniently omitting any trailing newlines) and maps the letters A to Z and the characters ! and . to the character codes 0 to 28, which normally correspond to unprintable control characters in ASCII / Unicode.  (A minor side effect of this is that any tabs in the input get printed as Js.)  The space character is left unmapped, since the output loop turns any codes above 28 into blanks anyway.
The second line just prints the PBM header.  It uses the Perl 5.10 say feature, so you need to run this script with perl -M5.010 for it to work.
The output loop takes a whitespace-delimited list of packed image rows and assigns each of them into $p in turn.  (I designed the font so that the packed data wouldn't contain any whitespace or ' characters.)  It then loops over the input characters in @a, using Perl's vec command to extract the 4-bit nibble corresponding to the mapped character code from the image row, pads it to an 8-bit byte and prints it.

Old answer, 268 bytes:

This is a quick and dirty first attempt.  I stole PleaseStand's font and compressed it along with my source code.  Since the resulting script is mostly unprintable, here's a hexdump; use xxd -r to turn it into executable Perl code:

0000000: 7573 6520 436f 6d70 7265 7373 275a 6c69  use Compress'Zli
0000010: 623b 6576 616c 2075 6e63 6f6d 7072 6573  b;eval uncompres
0000020: 7320 2778 da85 d03d 4b03 4118 85d1 452c  s 'x...=K.A...E,
0000030: b69c 72cb 7519 4894 552c 2c02 3319 ee5c  ..r.u.H.U,,.3..\
0000040: d7b8 5a89 6093 4634 7e82 c490 6c91 8597  ..Z.`.F4~...l...
0000050: 80fe 7267 d660 23ae e52d 0e0f dcd6 f8c3  ..rg.`#..-......
0000060: e9d1 5e6e ccec a15c ddb5 c5d5 495e 94a3  ..^n...\....I^..
0000070: 83b7 c7f9 73f3 5216 f9a8 787a 5fea 666c  ....s.R...xz_.fl
0000080: 9dd1 b763 dd98 76f8 2df6 0799 5811 7144  ...c..v.-...X.qD
0000090: 4acc ee9d b8b0 c90f 7e4a 8264 6016 cbd7  J.......~J.d`...
00000a0: 79f3 1b91 047c 4055 409e 9e54 1dda ed41  y....|@U@..T...A
00000b0: 9a20 8080 6adc 5c47 8488 7495 f621 01d7  . ..j.\G..t..!..
00000c0: 6b6c 902e b6c8 2a6a 6643 f56f e99c 115d  kl....*jfC.o...]
00000d0: 5c7a f1b2 13d0 3453 790f da74 c813 751d  \z....4Sy..t..u.
00000e0: 11ce d821 ad90 247f 2292 5b54 c14f 3c4e  ...!..$.".[T.O<N
00000f0: 49c5 4c53 a1a7 c478 391c 714c f113 0747  I.LS...x9.qL...G
0000100: ab6c 4482 9fd2 177a 5677 6327            .lD....zVwc'

The decompressed Perl code consists of the following preamble:

y;A-Z.! ;;cd,say"P4 ",8*length," 8"for$t=<>

followed by eight repetitions of the following code:

;$_=$t;y(A-Z.! )'BITMAP DATA HERE';print

with BITMAP DATA HERE replaced with 29 bytes encoding one row of the font.


Music Interval Solver In music theory, an interval is the difference between two pitches. Each pitch is defined by the number of half-steps (The difference between C and C#) or whole steps (The difference between C and D). One whole step is the same as two half-steps. Here is a list of all the default intervals and the number of half-steps they represent:
0     Perfect Unison
2     Major Second
4     Major Third
5     Perfect Fourth
7     Perfect Fifth
9     Major Sixth
11    Major Seventh
12    Perfect Octave

There are 3 variations on the default intervals, minor, diminished, and augmented.

A minor interval is one half-step lower than a major interval, but not a perfect interval. So you have a minor second (1), a minor third (3), a minor sixth (8), and a minor seventh (10). There is no such thing as a minor fourth, minor fifth, minor unison or minor octave since these are all perfect intervals.

A diminished interval is one half-step lower than a minor or perfect interval. There is diminished Second (0), diminished third (2), diminished fourth (4), diminished fifth (6), diminished sixth (7), diminished seventh (9) and diminished octave (11).

An augmented interval is one half-step higher than a major or perfect interval. We have Augmented Unison (1), Augmented Second (3), Augmented third (5), Augmented Fourth (6), Augmented fifth, (8), Augmented sixth (10), and Augmented seventh (12).

The challenge:
You must write a program or function that takes a number of half steps or whole steps and then prints one of the valid English descriptions of this interval. It doesn't matter which description you pick, as long as it exactly matches the IO table. You can take this as one string
"5w" == 5 whole steps
"3h" == 3 half steps

or as a number and a string/char.
5, "w" == 5 whole steps
3, "h" == 3 half steps.

You can assume that every input will be between 0 and 12 half steps.
IO table
Here is a full list mapping the number of half-steps to all acceptable outputs.
0       Perfect unison, Diminished second
1       Minor second, Augmented unison
2       Major second, Diminished third
3       Minor third, Augmented second
4       Major third, Diminished fourth
5       Perfect fourth, Augmented third
6       Diminished fifth, Augmented fourth
7       Perfect fifth, Diminished sixth
8       Minor sixth, Augmented fifth
9       Major sixth, Diminished seventh
10      Minor seventh, Augmented sixth
11      Major seventh, Diminished octave
12      Perfect octave, Augmented seventh

Here is some sample I/O:
5w      Minor Seventh
5h      Augmented Third
12h     Perfect Octave
12w     UNDEFINED
1w      Diminished third
2h      Major Second

Python 2.7, 155 bytes

s='second unison third fourth sixth fifth seventh octave Diminished Augmented'.split()
def f(n,c):x=0xDE9CB87561430>>[4,8][c>'h']*n;print s[x%2+8],s[x/2%8]


Create a list of snaking numbers under 50,000 Snaking Number Challenge

I wonder how many snaking numbers there are between 1 and 50,000?

Snaking Numbers, in this game, are numbers which can be typed out on a traditional numberpad (format below) by moving one key up, down, left, or right.

7 8 9
4 5 6
1 2 3
 0

For example, if you start with the number 5, you could select 4, 6, 8, or 2 as your next valid move - however 7, 3, 9, and 1 are off-limits as they are positioned diagonally to the current key.
So, if you have 5, then 2, your next viable key choices are 0, 1, 3, or 5 again.

In this Code Golf exercise, you are to output a list of all the positive snaking numbers between 1 and 50k, along with a final count of all the numbers that meet the criterion.

Rules

Numbers cannot start with a Zero.
Numbers must be whole positive integers.
Each consecutive number, read from left to right, must "snake" around the numberpad.
The snake cannot travel diagonally across keys
The number 0 can be accessed from both numbers 1 and 2
Numbers cannot be paired (eg: 22)

Examples of valid Snaking Numbers:

12369
45201
1254
10102
1
12
987

Examples of invalid numbers

1238 - 8 is not connected
0001 - multiple leading 0s
0101 - leading 0
159  - snake cannot travel diagonally
4556 - duplicate 5

As per normal Code Golfs, the aim is fewest bytes!

According to my maths and rules, you should have 670 valid snaking numbers in your list, plus 670 itself printed as the last number.

K (ngn/k), 60 57 bytes

(x;#x:{*/1=3!5&+/x*x:+1_-':(+0 1,'2*!3 3)@10\x}#1+!50000)

Try it online!

!50000 list of 0 .. 49999

1+ add 1 to all

{ }# filter with the function in { }

10\x decimal digits of the argument

( )@ use as indices in ...

!3 3 a pair of lists: (0 0 0 1 1 1 2 2 2;0 1 2 0 1 2 0 1 2)
2* multiply all by 2
0 1,' prepend 0 to the first list and 1 to the second
+ transpose (pair of lists -> list of pairs). this gives us the approx button coords.

-': subtract from each pair the previous pair. use 0 0 as an imaginary element before the first.

1_ drop the first

+ transpose

x*x: square (assign to x and multiply by x). here x is a pair of lists - ∆x-s and ∆y-s

+/ sum the two lists (element by element)

5& min with 5

3! mod 3

1= boolean list of where it's equal to 1

*/ product (boolean "and")

(x;#x: ) make a pair of the result and the length (#) of the result


Output MSB-set aligned, delimited ASCII Write some code that takes a single string as input and outputs MSB-set aligned ASCII.

Only ASCII characters less than 128 (0x80) will be in the input. The output format is generated as follows:

For each character convert it to its binary representation, remove the MSB (always 0 in the input) and then add a delimiter-bit (X) to both ends. The value will now be 9 bits long and both begin and end in X
Output each character in order, MSB to LSB, making sure that the MSB of each output byte is either 1 or X
If the MSB of the next byte would normally be 0, output the fewest .s needed between two consecutive Xs to align the MSB with a 1 or X
Output the data as binary digits, with X for each delimiter and . for each padding bit
At the end of the data, write a . after the last X, then as many .s as necessary to complete the last byte
Separate each byte (group of 8 digits) with a single whitespace character (space, tab, newline, etc.)
A whitespace character at the end of the last output line is optional
Empty input must produce ........ as the output
Your code must work on any length strings that your language can handle and at least 255 characters

Input: Hello, World!

Bytes    -> Delimited -> * Output    Start and End of each character
01001000    X1001000X    X1001000    'H'
01100101    X1100101X    XX110010    'e'       'H'
01101100    X1101100X    1X.X1101    'l'       'e'
01101100    X1101100X    100XX110    'l'       'l'
01101111    X1101111X    1100X.X1    'o'       'l'
00101100    X0101100X    101111X.              'o'
00100000    X0100000X    X0101100    ','
01010111    X1010111X    X.....X0    ' '       ','
01101111    X1101111X    100000XX    'W'       ' '
01110010    X1110010X    1010111X              'W'
01101100    X1101100X    X1101111    'o'
01100100    X1100100X    X.X11100    'r'       'o'
00100001    X0100001X    10XX1101    'l'       'r'
                         100X..X1    'd'       'l'
                         100100X.              'd'
                         X0100001    '!'
                         X.......              '!'

The * marks the Most Significant Bit in the output. Each bit in this column is either 1 or X. Removing any number of .s would cause either a 0 or . in the MSB column. If the input was Hello, W the last byte output would be .........

As usual, lowest score wins!

Python 3, 144 140 131 130 137 bytes
Damn bugs :(
O=""
for Q in input():
 C="X%07dX"%int(bin(ord(Q))[2:])
 while"1">C[8-len(O)%8]:C="."+C
 O+=C
O+="."
while O:print((O+"."*8)[:8]);O=O[8:]

This is really straight forward.
Ungolfed with explanation
# initialize output buffer
output = ""
# loop through input
for char in input():
    # get charcode, binary, remove 0b, parse as int, format
    code = "X%07dX" % int(bin(ord(char))[2:])
    # pad code while the line starting character would be 0
    while "1" > code[8 - len(output) % 8]:
        code = "." + code
    # append result to output buffer
    output += code
# add dot to ensure padding in end
output += "."
# loop while any output is left
while output:
    # print line of output, with padding
    print((output + "." * 8)[:8])
    # remove printed output
    output = output[8:]


Build a checkerboard For this challenge you will print the coordinates and color of each piece at the start of a game of checkers.

Enter the x and y (comma seperated) for every square (indexed 0-7) on a checkerboard, followed by a "r" or "b" (for red or black) where the top of the board (closer to y=0) is red and the bottom is black. newlines between pieces are required and no spaces are necessary.

This is code-golf so answers are scored in bytes with fewer bytes being better.

Trailing newlines are allowed but not necessary and the order must be exactly of that below.

Desired output:

0,0r
0,2r
0,4r
0,6r
1,1r
1,3r
1,5r
1,7r
2,0r
2,2r
2,4r
2,6r
5,1b
5,3b
5,5b
5,7b
6,0b
6,2b
6,4b
6,6b
7,1b
7,3b
7,5b
7,7b

05AB1E, 26 bytes

2ÝD5+«v4Fy',N·yÉ+„bry3‹èJ,

Try it online!

Explanation

2Ý                           # push [0,1,2]
  D5+                        # duplicate and add 5: [5,6,7]
     «                       # concatenate
      v                      # for each y in [0,1,2,5,6,7] do:
       4F                    # for each N in [0 ... 3] do:
         y                   # push y
          ',                 # push ","
            N·yÉ+            # push N*2+isOdd(y)
                 „br         # push "br"
                    y3‹è     # index into the string with y<3
                        J,   # join everything to a string and print


Challenge: compress co-occuring columns into cartesian product This challenge is inspired by a problem I encountered recently out in the real-world, though ultimately I cheated and found a workaround.

Challenge

The input is a space-separated table of characters (each line is a row, and every line will have the same number of columns). Your challenge is to group together co-occurring column values and output a 'compressed' table, and there may be duplicate rows. Let's look at an example:

input:

A X I
B X I
A Y I
B X I
B Y I

output:

AB XY I

The output is parsed as the cartesian product between each column:

AB XY = A X, B X, A Y, B Y

The union of cartesian products of columns in each output row must exactly match the set of all unique input rows. In other words, no skipping input rows and no specifying input rows that don't exist!

For further exampling, note that if the third column contained anything other than I, this would be harder to compress:

input:

A X I
B Y I
A Y $
B X I
B Y I

output:

A X I
A Y $
B XY I

Rules

no non-standard libraries or calls to high-level compression functions. The spirit of the question is to write the algorithm yourself!
output must be in the same format as inputs (zipping your output files is cheating)
no hard-coding the answers of each test file. Your program needs to be able to handle arbitrary (correct) inputs.

Scoring (lowest wins)

Size of your program in bytes (you may count the name of the input as a single byte)
Plus the size (in bytes) of all of your output files on the given tests.
-10% bonus if you have the fastest program (as it runs on my machine). Speed will be measured as the average time on 10 randomly generated test cases using generate.py 6 8 4 6 5 (the same 10 files for each program of course)

Test Files

These files are generated with this python script. The answer keys aren't guaranteed to be the minimum compression - you may be able to do better!

Input 1, Answer Key 1, generated with python generate.py 5 10 4 6 5
Input 2, Answer Key 2, python generator.py 7 6 2 4 6
Input 3, Answer Key 3, ...edit: the numbers here were wrong

I'll start things off with the simplest possible answer.. According to my own specifications, the input file qualifies as a 'compression' of itself (albeit not a very efficient one).

Python: 22+3359+183735+239 with 10% bonus = 168619.5

print open('testfile').read()


Parse a two-dimensional syntax Background

Alice and Bob are creating a golfing language to win every single PPCG challenge.
Alice wants to make a two-dimensional language, like ><>, but Bob prefers a prefix-infix syntax like in J.
As a compromise, they decide to create a two-dimensional prefix-infix language.
The parser is a pain to write, and they need your help!

Syntax specification

In Alice's and Bob's language, there are variables, which are represented by lowercase ASCII letters a-z, and functions, which are represented by uppercase ASCII letters A-Z.
A function can be invoked with one or two arguments.
A program is a rectangular grid of letters a-zA-Z and spaces, and the top left corner must not contain a space.
This is an example of a valid program:

F Gy
H
R x

When the program is parsed, it's transformed into an expression of a C-style language (C, Java, Python...) containing single-letter variables and function calls in the format <func>(<arg>) or <func>(<arg1>,<arg2>).
For example, the above program results in this expression:

F(H(R(x)),G(x,y))

The details of the parsing process are as follows:

The spaces are just filler, so they are not parsed.
Every variable a-z is always parsed as itself.
Every function A-Z is parsed as a function call. Its arguments are the closest expressions below it and to its right in the grid, in this order. If only one of these is present, it's given as the sole argument. You can assume that all functions have at least one argument in the grid.

In the above example, the variables x and y are parsed as themselves.
The function R has nothing below it and x to its right, so it's parsed as the one-argument invocation R(x).
Similarly, H is parsed as H(R(x)), since it has R below it.
The function G has x below it and y to its right, so it's parsed as G(x,y), and similarly for F.
The expression parsed at the top left corner is the result of the parsing process.

Input and output

Your input is a non-empty rectangular array of characters.
It will always be a valid program in Alice's and Bob's language, but it may contain expressions that are not used in the output.
Your output shall be the parsed expression resulting from the above process.

Rules and scoring

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

Test cases

These are given in the format grid <newline> expression, with hyphens --- between the cases.
The SE format leaves some lines blank, but they should be filled with spaces.

x
x
---
x y
z
x
---
Fx
F(x)
---
Fx
y
F(y,x)
---
ABu
A(B(u))
---
G
H
k
G(H(k))
---
ABCA
x xs
 DFk
A(x,B(D(F(k)),C(x,A(s))))
---
A  B

C  D x
A(C(D(x)),B(D(x)))
---
RT Hq
I xR k
R(I(x),T(H(R(k),q)))
---
A A  A a
 S A  b
B  C   Dx
d X  u f
A(B(d,C(D(f,x))),A(X(u),A(u,a)))

CJam, 67 62 60 58 57 54 bytes

Thanks to Dennis for saving 4 bytes.

{:Gsc_32&{"()"[GGz2{1m<_{S#}#>W<\}*z]{},{J}%',**+}|}:J

This defines a named block (function) J and leaves it on the stack. The function itself expects an array of strings on the stack, which represents the input grid, and leaves the desired string in its stead.

Test it here.

I've been meaning to tackle this one since it was posted, but apparently I needed a bounty and an overly long Pyth solution to motivate myself sufficiently.

Explanation

The solution is of course recursive and gradually builds up the string.

{
  :G       e#  Store the current grid in G.
  sc       e#  Convert the grid to a string, flattening it, then to a character, which
           e#  discards everything but the first character. This is a golfed 0=0=.
           e#  This character will either be an upper-case letter (function) or a lower-
           e#  case letter (variable).
  _32&     e#  Make a copy of the character and take bitwise AND with 32. This gives a
           e#  NULL character for functions and a space for variables.
  {        e#  If the result is falsy... (i.e. NULL, i.e. we have a function)
    "()"   e#   Push parentheses for later use.
    [      e#   Remember the current stack depth.
    GGz    e#   Push an array which contains the grid and its transpose.
    2{     e#   Run this block twice... (it will be applied once to each grid)
      1m<  e#    Rotate the rows. This has two effects: a) It removes the first row
           e#    from the front such that we can go looking for the next non-space
           e#    character down the first column from the start. b) It places a row
           e#    at the end which we know doesn't start with a space, which acts as
           e#    a guard in case there are no further letters below the current one.
      _    e#    Duplicate this grid.
      {    e#    Find the first index where this block yields something truthy...
        S# e#     Find the index of the first space in the current row. If the row
           e#     starts with a space, this is 0, i.e. falsy and the search continues.
           e#     If there is a space in any later position, that will be positive and
           e#     truthy, so this index gets returned. If there is no space at all,
           e#     the result is -1 which is also truthy and ends the search.
      }#
      >    e#     Discard all lines up to (but not including) the found index.
      W<   e#     Discard the guard row at the end.
      \    e#     Swap the grids so that the next pass processes the other grid.
    }*
    z      e#    Transpose the second grid back to its original orientation.
    ]      e#    Wrap both processed grids in an array.
    {},    e#    Remove a grid if it's empty.
    {J}/   e#    For each remaining grid, call J recursively.
    ',*    e#    Join the grids with commas if there are still two of them.
    *      e#    Wrap this string in the parentheses below on the stack.
    +      e#    Prepend the function name.
  }|
}:J


Pocket Pokemon Type Evaluator Yes, I know there are already three pokemon type questions, but almost all submissions hardcode the whole chart in one way or other. I think it'd be nice to change the requirement a bit to encourage more shortcut-taking typically seen in decision problems.

Objective

Write a program/function/whatever that accepts the attacking type and the defending type(s), and output something that can be identified as the final multiplier.

As usual, you can see the pokemon type chart here. Also available as text form (copied from another question linked above and modified a bit):

                                            Attacking Type
                No  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fr  Wa  Gr  El  Ps  Ic  Dr  Da  Fa
    Normal        1   2   1   1   1   1   1   0   1   1   1   1   1   1   1   1   1   1
    Fighting      1   1   2   1   1 0.5 0.5   1   1   1   1   1   1   2   1   1 0.5   2
D   Flying        1 0.5   1   1   0   2 0.5   1   1   1   1 0.5   2   1   2   1   1   1
e   Poison        1 0.5   1 0.5   2   1 0.5   1   1   1   1 0.5   1   2   1   1   1 0.5
f   Ground        1   1   1 0.5   1 0.5   1   1   1   1   2   2   0   1   2   1   1   1
e   Rock        0.5   2 0.5 0.5   2   1   1   1   2 0.5   2   2   1   1   1   1   1   1
n   Bug           1 0.5   2   1 0.5   2   1   1   1   2   1 0.5   1   1   1   1   1   1
d   Ghost         0   0   1 0.5   1   1 0.5   2   1   1   1   1   1   1   1   1   2   1
i   Steel       0.5   2 0.5   0   2 0.5 0.5   1 0.5   2   1 0.5   1 0.5 0.5 0.5   1 0.5
n   Fire          1   1   1   1   2   2 0.5   1 0.5 0.5   2 0.5   1   1 0.5   1   1 0.5
g   Water         1   1   1   1   1   1   1   1 0.5 0.5 0.5   2   2   1 0.5   1   1   1
    Grass         1   1   2   2 0.5   1   2   1   1   2 0.5 0.5 0.5   1   2   1   1   1
T   Electric      1   1 0.5   1   2   1   1   1 0.5   1   1   1 0.5   1   1   1   1   1
y   Psychic       1 0.5   1   1   1   1   2   2   1   1   1   1   1 0.5   1   1   2   1
p   Ice           1   2   1   1   1   2   1   1   2   2   1   1   1   1 0.5   1   1   1
e   Dragon        1   1   1   1   1   1   1   1   1 0.5 0.5 0.5 0.5   1   2   2   1   2
    Dark          1   2   1   1   1   1   2 0.5   1   1   1   1   1   0   1   1 0.5   2
    Fairy         1 0.5   1   2   1   1 0.5   1   2   1   1   1   1   1   1   0 0.5   1

You can choose to either accept one or two defending types (the final multiplier for two defending types is just the product of all individual defending types). Both types of submissions are allowed, as they will be in separate categories.

Rules

You can choose any methods of input in any form, structure or order (e.g ['fire',['water','rock']]/['fire',['rock']]/['fire','rock'], 'water,ice,ghost'/'water,ghost',dragondragonsteel/dragondragon).

The only requirement is that the types being inputted must be exactly their names and nothing else. Moreover, the types are required to be in one case only: so if you choose "psychic/Psychic/PSYCHIC", you must also use the same case for every other types (e.g "poison/Poison/POISON"). The available casing are: all lowercase, capital case and all uppercase.

You can output anything as long as different multipliers corresponds to one and only one output value.

There will not be two defensive types of the same type.

Standard loopholes are disallowed.

Shortest byte wins.

JavaScript (ES6), 270 246 221 bytes
Takes input in currying syntax (a)(d) where a is the attacking type as a string and d are the defending type(s) as an array of strings. The case doesn't matter.
Returns a standard multiplier as a float.

a=>d=>d.map(d=>r*='0124'["ijfkj{jjnjjJ[kefjiZj[jxnjni^YnEW]vfeziiz]okjZmniV{oZvjhjnmj[zrfijij[yVzej[jjejjhujkmjZkZ[fjiuznjjz~zjfRjbkjy".charCodeAt((i=g(d)*18+g(a))/3)>>i%3*2&3]/2,g=s=>parseInt(s,36)*64%97%54%21%18,r=1)&&r

Try it online! or check the whole chart
How?
The base-36 interpretation \$N\$ of a given Pokemon type string is converted to a coordinate \$C\$ in \$[0..17]\$ using the following minimal perfect hash function:
$$C=((((N\times64)\bmod97)\bmod54)\bmod21)\bmod18$$
The chart is rearranged using the new coordinates and encoded as a single string with 6 bits of payload data per character, using ASCII codes in the range \$[64..127]\$.
There are 2 bits per cell, so the length of the string is \$(18\times18\times2)/6=108\$ characters.
For the curious, here is the code that encodes the string.


Are these trees isomorphic? Introduction

In this challenge, your task is to write a program that decides whether two given trees are isomorphic.
A tree means a directed acyclic graph where every node has exactly one outgoing edge, except the root, which has none.
Two trees are isomorphic if one can be transformed into the other by renaming the nodes.
For example, the two trees (where every edge points up)

  0       0
 /|\     /|\
1 3 4   1 2 5
|\       /|
2 5     3 4

are easily seen to be isomorphic.

We encode a tree as a list L of nonnegative integers in the following way.
The root of the tree has label 0, and it also has nodes 1,2,...,length(L).
Each node i > 0 has an outgoing edge to L[i] (using 1-based indexing).
For example, the list (with the indices given under the elements)

[0,0,1,3,2,2,5,0]
 1 2 3 4 5 6 7 8

encodes the tree

  0
 /|\
1 2 8
| |\
3 5 6
| |
4 7

Input

Your inputs are two lists of nonnegative integers, given in the native format or your language.
They encode two trees in the manner specified above.
You can assume the following conditions about them:

They are not empty.
They have the same length.
Each list L satisfies L[i] < i for all (1-based) indices i.

Output

Your output shall be a truthy value if the trees are isomorphic, and a falsy value if not.

Rules and scoring

You can write either a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
There are no time restrictions, but built-ins that decide tree or graph isomorphism are disallowed.

Test cases

Truthy instances

[0] [0]
[0,1,2,1] [0,1,1,3]
[0,1,1,3,3] [0,1,2,2,1]
[0,1,0,1,2,3,3,0] [0,0,2,1,0,4,2,1]
[0,1,2,3,1,2,3,0,8] [0,1,0,3,3,4,4,7,7]

Falsy instances

[0,0] [0,1]
[0,1,2,0,3,3,4] [0,1,2,3,0,4,3]
[0,1,0,1,2,3,3,0] [0,0,2,1,0,5,2,1]
[0,1,1,0,1,3,2,1,5] [0,1,0,3,3,3,2,5,2]
[0,1,2,3,1,2,3,0,8] [0,1,0,1,4,4,5,6,6]
[0,1,0,2,0,3,0,4,0,5] [0,0,2,1,0,3,4,0,0,9]

Python, 83

The anonymous function on the 2nd line is my solution.

f=lambda l,i=0:sorted(f(l,j+1)for j,e in enumerate(l)if e==i)
lambda a,b:f(a)==f(b)

f returns a canonized form of a subtree which is a sorted list of its canonized children.  Then we must simply check if the canonized forms of each tree are equal.


Draw Growing Stacks of Boxes The Task

In this challenge, your task is to draw an ASCII art representation of several stacks of boxes of increasing height.
You are given as input the number of stacks, which is a positive integer.
The first stack contains one box of size 2x2.
The second stack contains 2 boxes of size 3x3.
In general, the kth stack contains k boxes of size (k+1)x(k+1).

The borders of each box are drawn using the characters -|+, and their interior consists of whitespace.
Adjacent boxes share their borders, and corners should always be drawn with +, even when they are part of a border of another box.

Examples

Output for 1:

++
++

Output for 2:

 +-+
 | |
 +-+
++ |
++-+

Output for 3:

   +--+
   |  |
   |  |
   +--+
   |  |
 +-+  |
 | +--+
 +-+  |
++ |  |
++-+--+

Output for 5:

          +----+
          |    |
          |    |
          |    |
          |    |
          +----+
          |    |
          |    |
          |    |
      +---+    |
      |   +----+
      |   |    |
      |   |    |
      +---+    |
      |   |    |
      |   +----+
   +--+   |    |
   |  +---+    |
   |  |   |    |
   +--+   |    |
   |  |   +----+
 +-+  +---+    |
 | +--+   |    |
 +-+  |   |    |
++ |  |   |    |
++-+--+---+----+

Rules and Scoring

The input can be received from STDIN, as a command line argument, or as a function argument.
Output must go to STDOUT or closest equivalent.
Any finite amount of trailing whitespace is allowed, as are preceding and trailing newlines, but there cannot be any extra preceding spaces.

This is code-golf, so the lowest byte count wins.
Standard loopholes are disallowed.

CJam, 64 60 58 bytes

]ri:X{'|'}{I))*\I**XX*)Se[s}:L~:M.e>S'-LaI*~M}fI]zN*'}/'+*

Constructing each column at a time.

Try it online here


Find the shortest way to advance a counter to a certain number I have a counter. It's a small device that looks like this:

The display goes from 0000 to 9999. It has a little push-button at the top that increases the count by 1, and a little knob at the right whose purpose is to reset the counter back to 0.

Now, the thing about the little knob is that if you turn it backwards, you can make it increase any digit that you want once you turn it forwards again. So if I push the counter button 10 times so that the counter shows 0010, I can then turn the knob backwards until i hear a tiny click, then turn it forwards again and make it go straight to 0090.

But, the knob will always increase all occurrences of the same digit by 1 every time it pushes numbers forward. So if the counter shows 6060, you can only make it increase to 7070, not to 6070 or 7060. Also, the knob will roll 9s over to 0 without carrying, so 0990 will advance to 0000 instead of 1000 or 1100.

I want to know the most efficient way to set the counter to a certain number. Your task is to write a program or function that will determine the shortest sequence of button pushes and knob advancements required to do so.

Your program will take as input a 4-digit number from 0000 to 9999, and return a series of steps in the following format:

> 0001
C
> 0093
C12345678C12345678CCC
> 1000
C12345678C12345678C12345678C12345678C12345678C12345678C12345678C
> 9999
012345678

Where C stands for "push the counter button" and any digit D from 0 to 9 stands for "use the knob to advance all occurrences of D by 1".

Your program must produce a valid sequence of steps for all possible four-digit combinations, and will be scored by the total number of steps required for all 10,000 cases. In the case of a tie (most likely when the optimal algorithm is found), the shorter code will win.

Lua, 327763 steps (optimum, 276 bytes)
Golfed version:
a={[0]=""}t=tonumber for i=0,52 do A={}for k,v in pairs(a)do A[k]=v L=("%04d"):format(k)for i=1,4 do c=L:sub(i,i)d=L:gsub(c,(t(c)+1)%10)e=a[t(d)]A[d]=(not e or #e>#v)and v..c or e end b=k+1 if k<9999then e=a[b]A[b]=(not e or #e>#v)and v.."C"or e end end a=A endprint(a[(...)])

Improved version of the examples in question (only 1000 is improved):
0001:C
0093:CCCCCCCCCC12345678CCC
1000:0CCCCCCCCCCC2345678C23456789
     (0000>1111>1122>1199>1200>1000)
9999:012345678

Ungolfed version:
a = {[0]=""}
for i=0,52 do
    A = {}
    for k,v in pairs(a) do
        A[k] = v
        L=("%04d"):format(k)
        for i=1,4 do
           c=L:sub(i,i)
           d=L:gsub(c,(tonumber(c)+1)%10)
           e=a[tonumber(d)]
           A[d] = (not e or #e > #v) and v..c or e
        end
        b=k+1
        if k < 9999 then
            e=a[b]
            A[b] = (not e or #e > #v) and v.."C" or e
        end
    end
    a=A
end
print(a[93],a[1000],a[9999])


Count the number of shortest paths to n This code challenge will have you compute the number of ways to reach \$n\$ starting from \$2\$ using maps of the form \$x \mapsto x + x^j\$ (with \$j\$ a non-negative integer), and doing so in the minimum number of steps.
(Note, this is related to OEIS sequence A307092.)
Example
So for example, \$f(13) = 2\$ because three maps are required, and there are two distinct sequences of three maps that will send \$2\$ to \$13\$:
$$\begin{array}{c} x \mapsto x + x^0 \\ x \mapsto x + x^2 \\ x \mapsto x + x^0\end{array} \qquad \textrm{or} \qquad \begin{array}{c}x \mapsto x + x^2 \\ x \mapsto x + x^1 \\ x \mapsto x + x^0\end{array}$$
Resulting in \$2 \to 3 \to 12 \to 13\$ or \$2 \to 6 \to 12 \to 13\$.
Example values
f(2)   = 1 (via [])
f(3)   = 1 (via [0])
f(4)   = 1 (via [1])
f(5)   = 1 (via [1,0])
f(12)  = 2 (via [0,2] or [2,1])
f(13)  = 2 (via [0,2,0] or [2,1,0], shown above)
f(19)  = 1 (via [4,0])
f(20)  = 2 (via [1,2] or [3,1])
f(226) = 3 (via [2,0,2,1,0,1], [3,2,0,0,0,1], or [2,3,0,0,0,0])
f(372) = 4 (via [3,0,1,0,1,1,0,1,1], [1,1,0,2,0,0,0,1,1], [0,2,0,2,0,0,0,0,1], or [2,1,0,2,0,0,0,0,1])

Challenge
The challenge is to produce a program which takes an integer \$n \ge 2\$ as an input, and outputs the number of distinct paths from \$2\$ to \$n\$ via a minimal number of maps of the form \$x \mapsto x + x^j\$.
This is code-golf, so fewest bytes wins.

JavaScript (ES6),  111 ... 84  80 bytes
Returns true rather than \$1\$ for \$n=2\$.

f=(n,j)=>(g=(i,x,e=1)=>i?e>n?g(i-1,x):g(i-1,x+e)+g(i,x,e*x):x==n)(j,2)||f(n,-~j)

Try it online!
Commented
f = (                     // f is the main recursive function taking:
  n,                      //   n = input
  j                       //   j = maximum number of steps
) => (                    //
  g = (                   // g is another recursive function taking:
    i,                    //   i = number of remaining steps
    x,                    //   x = current sum
    e = 1                 //   e = current exponentiated part
  ) =>                    //
    i ?                   // if there's still at least one step to go:
      e > n ?             //   if e is greater than n:
                          //     add the result of a recursive call with:
        g(i - 1, x)       //       i - 1, x unchanged and e = 1
      :                   //   else:
                          //     add the sum of recursive calls with:
        g(i - 1, x + e) + //       i - 1, x + e and e = 1
        g(i, x, e * x)    //       i unchanged, x unchanged and e = e * x
    :                     // else:
      x == n              //   stop recursion; return 1 if x = n
)(j, 2)                   // initial call to g with i = j and x = 2
|| f(n, -~j)              // if it fails, try again with j + 1


Compute every combination of operations written in a .TXT file Your task is to create a program that computes every combination of the operations written in a .TXT file.

Example TXT File:

1
+
2
/
3

Example Output:

1+2/3=1
1+3/2=2
2+1/3=1
2+3/1=5
3+2/1=5
3+1/2=2
1/2+3= //See bonuses. If your program does not feature float, leave blank result.
1/3+2= //See above.
2/1+3=5
2/3+1= //See above.
3/2+1= //See above.
3/1+2=5

Specs:

Every line of the .TXT file must contain a number or an operation;
The minimum length for the .TXT file is 5 lines;
The operations must be computed from left to right. E.g. 4+4/2 results in 4;
Your program should feature +, -, * and / operations;
Your program should work with any valid input of any valid length.

Scoring:

Code length is your starting score, but not the only parameter. Here's a short list of bonuses you can achieve to lower your score. The user with the lowest score wins.

Implement ^: -20;
Implement log (in base e): -30;
Implement logn (where n is any positive base): -50 (only -20 if you achieved the log bonus);
Implement e (and the number in the line below is the exponent of 10. So 1e4=10000): -20;
Can handle negative values: -10;
Can handle float values: -20;
There are no digits (0123456789) in the code: -10;
There is no call to eval or equivalent: -20;
All of the above: -100.

For a total of -250 bonus points.

Good luck!


Length of String Using Set Theory From Wikipedia Set-theoretic definition of natural numbers

  The set N of natural numbers is defined as the smallest set containing
  0 and closed under the successor function S defined by S(n) = n ∪ {n}.

  The first few numbers defined this way are 0 = {}, 1 = {0} = {{}}, 2 = {0,1} = {{},{{}}}, 3 = {0,1,2} = {{},{{}},{{},{{}}}}.

Using this definition of natural numbers count the length of a string.

Input  a string of characters from a-zA-Z of any length

Output the length of the string in set notation without separators

Examples

Input  Empty string

Output {}

Input  a

Output {{}}

Input  aaaa

Output {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}

For readability output for 'aaaa' with separators is

{
    {}
    {{}}
    {{} {{}} }
    {{}   {{}}   {{} {{} } }   }
}

Conditions

No digits 0 to 9 to appear in the code;
No use of character code conversion to generate numbers;
No use of +-*/ for arithmetic calculations including increment and decrement;
No mathematical operations other than Boolean Logic;
Input string does not count in determining byte length;

Winner Shortest code length in bytes.

As this is my first question I hope I have made it clear and rigorous enough. Friendly advice accepted.

Haskell function, 35 34 characters

f[]="{}";f(_:x)='{':f x++tail(f x)

Haskell program with hardcoded input, 48 or 49 47 or 48 characters

 f[]="{}";f(_:x)='{':f x++tail(f x);main=print$f"aaaa"

(47 characters if you don't mind extra quotes around the output; if you do, use putStr instead of print for a total of 48 characters)

Haskell program, 51 50 characters

f[]="{}";f(_:x)='{':f x++tail(f x);main=interact f


Convert any number (up to 1e3000) to text Given an input, calculate the correct suffix and output the number in a readable format in short scale (where 1 billion is 10^9). The suffixes must go to at least 10^3000, in which the rules for calculating them can be found here, or a list can be found here.

There is no need to output the exact numbers, this is focused on getting a huge number into a readable format.

For example:

10000 = 10.0 thousand
135933445 = 135.93 million
-2 = -2.0
-2.36734603 = -2.37
'1'+'9'*3000 = 2.0 nongennovemnonagintillion

 // out of range examples
'1'+'9'*3010 = 20000000000.0 nongennovemnonagintillion
'-1'+'9'*5000 = -inf nongennovemnonagintillion

I am aware it is similar to this question, though with 10x as many numbers and not having to read the names, there's potentially a lot more room for golfing. For the record, my result is 578 characters in Python.

Rules:

No getting things from external resources - it must all be calculated within the code.
External modules are fine, just don't break the above rule.
The code should work when input is either a string, integer or float (eg. you may wish to input the super large numbers as strings).
The output must always contain a decimal place.
The output must be rounded if above 2 decimal places. Using the inbuilt round function is fine, I am aware there are some floating point errors, so if the occasional '.045' doesn't round up to '.05' for example, don't worry about it.
Leaving multiple zeroes at the end is optional, as long as it doesn't go above 2 decimals (1.00 or 1.0 are both fine) and is consistent for all inputs (an input of 1 and 1.0 should output the same result).
An input too large shouldn't cause an error, inf is a valid value since it's part of float.

Scoring:

Score is the length of the code, including indents.
Lowest score wins.
Output can be either printed or returned.
Setting the input number does not count towards length.

As a starting point, here is an ungolfed version of some code in Python to generate the list of suffixes. Feel free to build upon this or start from scratch.

a = ['', 'un','duo','tre','quattor','quin','sex','septen','octo','novem']
c = ['tillion', 'decillion', 'vigintillion', 'trigintillion', 'quadragintillion', 'quinquagintillion', 'sexagintillion', 'septuagintillion', 'octogintillion', 'nonagintillion']
d = ['', 'cen', 'duocen', 'trecen', 'quadringen', 'quingen', 'sescen', 'septingen', 'octingen', 'nongen']

num_dict = ['']
num_dict.append('thousand')
num_dict.append('million')
num_dict.append('billion')
num_dict.append('trillion')
num_dict.append('quadrillion')
num_dict.append('quintillion')
num_dict.append('sextillion')
num_dict.append('septillion')
num_dict.append('octillion')
num_dict.append('nonillion')

for prefix_hundreds in d:

    #tillion can't be used first time round
    if not prefix_hundreds:
        b = c[1:]
    else:
        b = c

    for prefix_tens in b:
        for prefix in a:
            num_dict.append(prefix_hundreds+prefix+prefix_tens)

To get the ball rolling then, this is my version. Only the final number is converted to a float so there is no problem with large numbers if they're within range.
In terms of speed, it takes about 0.85 seconds to calculate 1000 random integers between -1e3000 and 1e3000.
Python 2 (574)
N=str(X).split('.');K=len;E=min(1000,(K(str(abs(int(N[0]))))-1)/3);P=N[0][:(-E*3if E else K(N[0]))];L=K(P);B=''.join(N);O='%.2f'%float((P+'.'+((B[L:L+3])or'0')));m,n,o,p,q,r,s,t,u,v,w,x,y,z='illion quadr quin sex sept oct non ing ag g tre duo c t'.split();a=[''];l=a+['thousand']+[i+m for i in['m','b','tr',n,o+z,p+z,q,r,s]]+[i+j+k for i in a+[i+'en'for i in[y,x+y,w+y,n+t,o+v,'sesc',q+t,r+t,s+v]]for k in[C+m for C in[z,'dec']+[B+'int'for B in['vig','trig',n+u,o+'quag',p+u,q+'uag',r+'og',s+u]]][not i:]for j in a+['un',x,w,'quattor',o,p,q+'en',r+'o','novem']];print O,l[E]

Then with some test cases:
>>> X = 100
100.0
>>> X = '100.0'
100.0
>>> X = '1037093920'
1.04 billion
>>> X = '-1540420004036040042.400642'
-1.54 quintillion
>>> X = '1540420' + '0'*153
1.54 duoquinquagintillion
>>> X = '1540496' + '0'*1553
154.05 quingenoctodecillion

Past the limit (just to show it doesn't throw an error and still handles negative value):
>>> X = '-10935' + '6'*3005
-1093566666.67 nongennovemnonagintillion
>>> X = '10935' + '6'*3250
1.09356666667e+254 nongennovemnonagintillion
>>> X = '10935' + '6'*3500
inf nongennovemnonagintillion


Negate a condition if a bool is FALSE Let's say I have a condition expression x and that I want to check if it is TRUE or FALSE depending on the value of a boolean y:

y ? x : !x

Is there a way to express it without repeating x expression? Something like how we can get a number or its opposite depending on a bool, without repeating the number in the expression:

number * (opposite ? -1 : 1)

Example, note the repetition of date.hour < 12 that I want to avoid:

tellTheThruth = FALSE; // or TRUE
if (tellTheThruth && date.hour < 12 || !tellTheThruth && !(date.hour < 12) {
    print "It's AM"
} else {
    print "It's PM"
}

Is it possible in all common languages (I was thinking in Javascript and I can't find a solution)? If not, is there some language in which you can?

for two booleans x and y, y ? x : !x can be rewritten as y ^ !x (y XOR NOT x) or similar in most languages.


Count strictly overlapping substrings Given two strings a and b, count how many times b occurs as a substring in a, but only when it overlaps with another instance of b.
(This means that 1 will never be a valid output, because in order for the substring to be strictly overlapping, there must be at least one other instance for it to overlap with.)
Test cases
input a              input b     output

trololololol         trol        0
trololololol         ol          0
trololololol         lol         4
trololololol         LOL         0
HAAAAHAAAAA          A           0
HAAAAHAAAAA          AA          7
Teeheeee             ee          3
123123123123123123   12312312    4
(empty string)       whatever    0

b will never be an empty string.
Rules

Matching must be case-sensitive
You may use any sensible IO format
Standard loopholes apply
This is code-golf, so the shortest code in bytes wins.

JavaScript (ES6), 69 bytes
Expects (a)(b).
a=>g=(b,i=(t=0)-.1,p)=>~i?g(b,a.indexOf(b,i+1),i,q=b[i-p]?t-=~!q:0):t

Try it online!
How?
Given the last position i of b in a, we use a.indexOf(b, i + 1) to get the position of the next occurrence. We keep track of the previous position in p and figure out whether they overlap by testing if b[i - p] is defined.
At the very beginning of the process, we initialize i to -0.1 so that it's neither -1 (that would stop the recursion) nor 0 that would mean that there's a match at position 0, while still being interpreted as 0 by .indexOf().
Exemple for a = "XABABA" and b = "ABA":
 iteration |         1 |        2 |    3 |   4
-----------+-----------+----------+------+-----
         i |      -0.1 |        1 |    3 |  -1
         p | undefined |     -0.1 |    1 |   3
     i - p |       NaN |      1.1 |    2 | n/a
     match |  "XABABA" | "XABABA" | none | n/a
                ^            ^
Commented
a =>                // outer function taking the haystack a
g = (               // inner recursive function g taking:
  b,                //   b = needle
  i = (t = 0) - .1, //   i = pointer in a, initialized to -0.1
                    //   t = output, initialized to 0
  p                 //   p = position of the previous occurrence
) =>                //
  ~i ?              // if i is not equal to -1:
    g(              //   do a recursive call:
      b,            //     pass b unchanged
      a.indexOf(    //     set i = position of the next occurrence
        b,          //       of b in a
        i + 1       //       starting at i + 1 (for the first iteration,
      ),            //       this gives -0.1 + 1 = 0.9, rounded to 0)
      i,            //     set p = i
      q =           //     the flag q is set to 0 if this is the first
                    //     occurrence in a chain of valid matches:
        b[i - p] ?  //       if i - p is less than the length of b:
          t -= ~!q  //         add 2 to t if q = 0, or only 1 otherwise
                    //         either way, set q to a non-zero value
        :           //       else:
          0         //         set q to 0
    )               //   end of recursive call
  :                 // else:
    t               //   stop the recursion and return t


Self replicating Hello World program Create a self-replicating Hello World Program. (The program has the ability to use the compiler, if you want).

For example:

void main()
{
    printf("Hello, World!");
    DuplicateFile("main.exe", "main2.exe");
}

Alternate challenge: A "quine" Hello World Program.

Bash - 43
echo $(echo Hello, World! >&2)$BASH_COMMAND

This prints "Hello, World!" on standard error, and itself on standard output.
For fun:
$ ./replicate-hello.bash
Hello, World!
echo $(echo Hello, World! >&2)$BASH_COMMAND
$ ./replicate-hello.bash | bash
Hello, World!
Hello, World!
echo $(echo Hello, World! >&2)$BASH_COMMAND
$ ./replicate-hello.bash | bash | bash
Hello, World!
Hello, World!
Hello, World!
echo $(echo Hello, World! >&2)$BASH_COMMAND
$ bash <<< $(echo ./replicate-hello.bash; \
             for ((i=0;i<100;i++)) ; do echo "| bash"; done)
Hello, World!
Hello, World!
Hello, World!
Hello, World!
... snip ...
Hello, World!
Hello, World!
Hello, World!
echo $(echo Hello, World! >&2)$BASH_COMMAND


Crazy chemical equations You should get string of chemical equation (no spaces, only letters (upper-case and lower-case), numbers, brackets and math signs) from user and print the answer if equation is balanced or not (any pair of positive/negative answers: Yes/No, true/false, 1/0). To make code shorter you can assume that input strings can contain only these elements: Al, Ar, B, Be, C, Cl, Cr, Cu, Fe, H, He, K, N, O, S. And one more thing: there could be - signs. It's all about math: + means addition, - means subtraction.

Examples:

Input:

C6H5COOH-O2=7CO2+3H2O

Output:

No

Input:

2Fe(CN)6+2SO2+202=Fe2(SO4)2+6C2N2

Output:

Yes

Input:

2SO2=2SO4-2O2

Output:

Yes

The shortest code wins.

Haskell, 400 351 308 characters

import Data.List
import Text.Parsec
(&)=fmap
r=return
s=string
l f b=(>>=(&b).f)
x=(=<<).replicate
m=sort&chainl1(l x(concat&many1(l(flip x)n i))n)((s"+">>r(++))<|>(s"-">>r(\\)))
i=between(s"(")(s")")m<|>(:[])&(l(:)(many lower)upper)
n=option 1$read&many1 digit
main=getContents>>=parseTest(l(==)(s"=">>m)m)

This just might have all the golf squeezed out of it. I don't know if there is another 100 51 8 characters to be saved!

& echo 'C6H5COOH-O2=7CO2+3H2O' | runhaskell Chemical.hs
False

& echo '2Fe(CN)6+2SO2+2O2=Fe2(SO4)2+6C2N2' | runhaskell Chemical.hs
True

& echo '2SO2=2SO4-2O2' | runhaskell Chemical.hs
True

Here's the ungolf'd version, in case anyone want to follow along. It is a simple Parsec based parser:

import Control.Applicative ((<$>), (<*>))
import Data.List
import Text.Parsec
import Text.Parsec.String (Parser)

type Atom = String

{- golf'd as x -}
multiple :: Int -> [Atom] -> [Atom]
multiple n = concat . replicate n

{- golf'd as m -}
chemicals :: Parser [Atom]
chemicals = sort <$> chainl1 molecules op
  where
    op :: Eq a => Parser ([a] -> [a] -> [a])
    op = (char '+' >> return (++))
     <|> (char '-' >> return (\\))

    molecules :: Parser [Atom]
    molecules = multiple <$> number <*> terms

    terms :: Parser [Atom]
    terms = concat <$> many1 term

    term :: Parser [Atom]
    term = flip multiple <$> item <*> number

{- gofl'd as i -}
item :: Parser [Atom]
item = between (char '(') (char ')') chemicals
   <|> (:[]) <$> atom
  where
    atom :: Parser Atom
    atom = (:) <$> upper <*> many lower

{- gofl'd as n -}
number :: Parser Int
number = option 1 $ read <$> many1 digit

{- gofl'd as main -}
main :: IO ()
main = getContents >>= parseTest chemEquality
  where
    chemEquality :: Parser Bool
    chemEquality = (==) <$> chemicals <*> (char '=' >> chemicals)


Output a number in PrettyFont I've designed a new font which I call PrettyFont. I've put much much time into perfecting it, but since I'm a working man I don't have time to finish it. Therefore it only contains 4 characters right now. One day when I've become rich it will become my life-long goal to finish it, but for now...

This is PrettyFont: (0, 1, 2, 3)

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

Each character is 4 pixels wide and 5 pixels high. Now! I want you to write me a program that outputs a number in PrettyFont so I can start sending designs to print.

Rules:

The input is a string number in base 4 (only characters 0-3), for example "01321". The program should be able to handle at least 10 characters in the string. BONUS points is given to the program that takes an actual base 10 integer instead of a string. EDIT clarification: the integer bonus means that one can enter any base 10 number, like 54321, and the program will convert it to base 4 and output it (in this case 31100301).

The output will be the number printed with PrettyFont. Example input and output:

> "321"
####
   #
 ###
   #
####

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

 ##
  #
  #
  #
 ###

Huge bonus to the program that can output it in a single row-fashion like this:

> "321"
#### ####  ##
   # #  #   #
 ###   #    #
   #  #     #
#### ####  ###

The '#' character is not a requirement, and can be replaced by any character.

In vertical output, an empty row is required between each PrettyFont character. If anyone makes the horizontal output, one white space character ' ' or a tab character is required between each PrettyFont character.

This is code golf, shortest code wins! (I need it short because my office computer has limited storage.)

k (118 117 72 71 69 66 chars)

I haven't made much of an effort to golf this yet but it achieves the desired horizontal output in not too many chars:

-1'" "/:'+(5 4#/:4 20#"# "@,/0b\:'0x066609ddd806db00e8e0)"I"$'0:0;

Takes input from stdin, prints output to stdout.

edit: By implementing a form of compression on the output "bitmap", I've reduced it to 72. The bitmap is now built by converting  64bit ints to binary and mapping the 0s and 1s to "#" or " ". I could do it from hex like a few of the other solutions but I think this would end up longer. Turns out hex is better.

Sample output for 012301:

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

//edit: -6 char


Hexagonal coordinates: Polar to Cartesian Wikipedia says about Polar Coordinates:

In mathematics, the polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point and an angle from a reference direction.

This seems perfect for describing hexagonal grids. Take the following hexagonal grid for example:
  A B C
 D E F G
H I J K L
 M N O P
  Q R S

Our reference point will be the center of the hexagon ('J'), and our reference angle will be to the top left corner of the hexagon ('A'). However, we'll describe the angle in terms of the number of clockwise steps around the outside of the hexagon from this point, not in angles. So we'll call it "Step number" instead of angle.
For example, 'C' is at (2, 2) because it has a radius of 2 (since it is two rings away from the center, 'J'), and an step number of 2 (2 clockwise steps forward from 'A'). Similarly, 'O' is at (1, 3), because it is one ring away from the center, and three clockwise steps forward from 'E' (which is on the reference angle).
For completeness, 'J' is at (0, 0), since you need 0 steps out and 0 steps clockwise to reach it.
Now, you can also describe a hexagonal with Cartesian Coordinates, but because of the offset this is a little weird. Just like with our polar coordinates, we will put the center at (0, 0). Each space takes up a coordinate also, so 'K' is at (2, 0), not (1, 0). This would put 'A' at (-2, 2), and 'O' at (1, -1).
The challenge
Given polar hexagonal coordinates, output the same coordinates in Cartesian coordinates. You may take these coords, and the output the answer in any reasonable format. This means that you may reverse the order of the inputs if you like. This also means you could output the coords as (Y, X), but if you do, please mention this in your answer to avoid confusion.
You do not have to handle negative radii, but you may get negative angles, or angles that go more than a full revolution around the hexagon. For example, you may receive (1, 10), or (1, -2) as input. These would both correspond to 'N' in our previous hexagon. You do not have to handle non-integers for input.
Sample IO
#Polar      #Cartesian
(0, 0)      (0, 0)
(1, 2)      (2, 0)
(6, 0)      (-6, 6)
(2, -3)     (-3, -1)
(4, 23),    (-5, 3)
(5, -3),    (-8, 2)
(10, 50),   (-20, 0)
(6, 10),    (10, 2)
(8, 28),    (0, -8)
(8, -20),   (0, -8)


CSV cleanup: remove all in col after ( Problem

Given a file with:

56 (65%), 33(75%), , 44, "“hello”,(5) world", goodbye
89 (25%), 33(75%), , 44, "hello world", goodbye
92 (97%), 33(75%), , 44, "hello world", goodbye

Goal

Write back to that file with:

56, 33, , 44, "“hello”,(5) world", goodbye
89, 33, , 44, "hello world", goodbye
92, 33, , 44, "hello world", goodbye

Example implementation [Python 518 bytes]

import csv
from sys import argv
from itertools import takewhile, imap

with open(argv[1], 'r+') as f0:
    r = csv.reader(f0, delimiter=',', quotechar='"')
    w = csv.writer(f0, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

    rows = tuple(imap(lambda line: ''.join(
        '{}\0'.format(''.join(
            takewhile(lambda ch: ch != '(', col))).rstrip() for col in line), r))
    f0.seek(0)
    tuple(imap(lambda line: w.writerow(line.split('\0')), rows))

Perl: 15 Bytes +1 for -p option

s/ ?\([^,"]+//g

Usage:

perl -pe 's/ ?\([^,"]+//g' file.csv


Cheap, Fast, Good - Common Factor (Greatest) Inspired by Cheap, Fast, Good, we're going to implement an algorithm which has exactly two of them.

The Math

Given two nonzero integers a and b, the GCF d is the largest integer that divides both a and b without remainder. Bézout coefficients are pairs of integers (x, y) such that ax + by = d. Bézout coefficients are not unique. For example, given:

a = 15, b = 9

We have

d =  3
x =  2
y = -3

Since 15*2 + 9*(-3) = 30 - 27 = 3.

A common way to calculate the GCF and a pair of Bézout coefficients is using Euclid's Algorithm, but it's by no means the only way.

The Code

Your program should take two integers as inputs. It should output/return the greatest common factor and one pair of Bézout coefficients.

Example input:

15 9

example output

3 (2, -3)

The output can be in any order and format, but it should be clear which is the GCF and which are the coefficients.

The Underhanded

Your program has the potential to be cheap, fast, and good. Unfortunately, it can only be two of those at once.

When it's not cheap, the program should use an excessive amount of system resources.
When it's not fast, the program should take an excessive amount of time.
When it's not good, the program output should be wrong.

The program should be able to do (well, not do) all three. Which is does when is up to you- it could be based on the time, the compiler, which input is larger, etc. Some additional notes:

Your program should not be obviously underhanded and should pass a cursory inspection. I'd be a little suspicious if you implemented three separate algorithms.
In the cheap case, "excessive amount of system resources" is anything that would slow down other programs. It could be memory, bandwidth, etc.
In the fast case, "excessive time" means relative to how it runs in the cheap and good cases. The program should still finish. The closer you can to "incredibly frustrating but not frustrating enough to stop the program" the (funnier and) better.
In the good case, the output shouldn't be obviously wrong  and should pass a cursory inspection. I'd be very suspicious if it gave me a GCF of "2 anna half".

This is a popularity contest, so most upvotes wins!

EDIT

To clarify, I'm looking for programs that can be "fast and cheap" and "cheap and good" and "fast and good" in different cases, not ones that just do one of them.

C
It's cheap and fast. You get gcd in the blink of an eye. However the guy who did it had no clue about that "Bézier co-something" so he simply divided a and b by gcd.
(to make things worse, at that point a and b are pretty far from their initial value because of the algorithm he wisely chose)
int main(int argc, char **argv){
    unsigned int a, b, tmp;
    a = (unsigned int)atoi(argv[1]);
    b = (unsigned int)atoi(argv[2]);
    for (tmp = 0; ((a | b) & 1) == 0; ++tmp){
        a >>= 1;
        b >>= 1;
    }
    while ((a & 1) == 0)
        a >>= 1;
    do {
        while ((b & 1) == 0)
            b >>= 1;
        if (a > b){
            unsigned int t = b;
            b = a;
            a = t;
        }
        b = b - a;
    } while (b != 0);
    tmp = a << tmp;
    printf("%u, (%u,%u)", tmp, a/tmp, b/tmp);
    return 0;
}


Smallest Prime with a Twist (A068103) The task at hand is, given a number n, find the smallest prime that starts with AT LEAST n of the number 2 at the beginning of the number. This is a sequence I found on  OEIS (A068103).

The first 17 numbers in the sequence are given below, if you want more I'll have to actually go implement the sequence, which I don't mind doing.

0  = 2
1  = 2
2  = 223
3  = 2221
4  = 22229
5  = 2222203
6  = 22222223                # Notice how 6 and 7 are the same!
7  = 22222223                # It must be **AT LEAST** 6, but no more than necessary.
8  = 222222227
9  = 22222222223             # Notice how 9 and 10 are the same!
10 = 22222222223             # It must be **AT LEAST** 9, but no more than necessary.
11 = 2222222222243
12 = 22222222222201
13 = 22222222222229
14 = 222222222222227
15 = 222222222222222043
16 = 222222222222222221

Just thought this would be a cool combination of string manipulation, prime detection and sequences. This is code-golf, lowest byte count will be declared the winner probably at the end of the month.

Java (OpenJDK 8), 164 110 bytes

a->{int i=0;for(;!(i+"").matches("2{"+a+"}.*")|new String(new char[i]).matches(".?|(..+)\\1+");i++);return i;}

Thanks to @FryAmTheEggman for a bunch of bytes!

Try it online!


Abstract Syntax Tree Golfing: FizzBuzz, Python Summary

Implement FizzBuzz in Python, with the fewest possible tokens.

Challenge

Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Programs must be written in some version of Python.

For more details, see 1, 2, Fizz, 4, Buzz

Scoring

Your score will be equal to the number of nodes in the abstract syntax tree of your code, as reported by this program for Python 3, or this program for Python 2. To run the programs, provide the filename of your code as  command line argument to the program. For instance:

python simple_counter.py fizzbuzz.py

These programs are based off of Python's ast module. If you have any difficulty, let me know.

To prevent trivial solutions, such as executing a long string with the actual program, or hardcoding the output, there are some additional restrictions:

No token in your code may be longer than 15 characters. The above programs will check this requirement for you. Note that for ease of implementation, the above programs count comments as tokens.
Code execution/evaluation is banned.

If you have questions as to whether something is allowed, ask me.

Scoring Heuristics

The following rules are typically enough to calculate the score of your program:

Block statements are 1 points: if, for ... in ..., while, else, etc.
Standalone statements are 1 point: print in Python 2, break, pass, etc.
Variables are 2 points
Single-token literals are 1 point: 2131, "Hello, world!", True
Functions are 3 points (2 for using a variable, 1 extra): print in Python 3, range, etc.
Operators are 2 points: +, *, %, and, not, etc.
= is 1 point
Augmented assignment is 2 points: +=, |=, etc.
Parentheses, indentation, etc. are 0 points.
A line containing an expression, as opposed to an assignment or an expression, is + 1 point.
Having code at all is 1 point.

Challenge:

The lowest score wins. Good luck!


How happy is this emoticon? (2.0) OG post
Task
In this challenge, you will be given an string emoticon, and your task will be to output its happiness.
How?
An emoticon will always have eyes and mouth. It can also include eyebrows and nose. Each part will influence the overall happiness rating, which is the sum of happiness ratings of all parts.  Emoticons may be flipped, reversing the order of parts. Here is the different possible parts and their happiness rating:
Symbol    Flipped symbol    Happiness rating

Eyebrows:

<None>    <None>            0
<         >                -2
[         ]                -1
|         |                 0
]         [                 1
>         <                 2

Eyes:

:         :                 0
;         ;                 1

Noses:

^         ^                 0
-         -                 0

Mouth

<         >                -3
(         )                -2
[         ]                -1
|         |                 0
]         [                 1
)         (                 2
>         <                 3

Test cases:
In        Out

:)        2
<:(      -4
|:-|      0
>;^)      5
(;        3
>-:<     -1
(:|       2

Rules

You must be able to handle flipped emoticons. If the input can be interpreted both ways (for example <:<) you can output either of the possible results
Standard loopholes and I/O rules apply.
This is code-golf, so shortest code wins.

05AB1E, 60 59 bytes
„:;S¡D€gÆI„()SkàĀ-dUv">)]|"')NXQ×K©.ºDysÃk®g<-X·<*yĀ*}I';åO

Try it online or verify all test cases.
Explanation:

„:;S              # Push string ":;", and convert it to a list of characters: [":",";"]
    ¡             # Split the (implicit) input-string on these characters
     D            # Duplicate the pair
      €g          # Get the length of each part
        Æ         # Reduce by subtracting
I                 # Push the input again
 „()S             # Push string "()", and convert it to a list of characters: ["(",")"]
     k            # Get the 0-based index of these characters in the string
                  # (or -1 if it isn't present)
      à           # Pop and push the maximum
       Ā          # Check that this is NOT 0 (0 if 0; 1 if -1, 1, 2, or 3)
-                 # Subtract the two from one another
 d                # Check that this is non-negative (>=0)
  U               # And pop and store this result in variable `X`
                  # (X=1 for faces where the mouth is left; X=0 for faces where the
                  # mouth is right or where we couldn't determine mouth/eyebrows)
v                 # Loop over the parts `y` in the pair we duplicated after the split:
 ">)]|"           #  Push string ">)]|"
         N        #  Push the 0-based loop-index
          XQ      #  Check if it's equal to variable `X` (1 if N==X, 0 if N!=X)
       ')   ×    '#  Repeat ")" that many times (")" if N==X, "" if N!=X)
             K    #  Remove that from string ">)]|"
              ©   #  Store this string in variable `®` (without popping)
               .º #  Mirror it with overlap: ">)]|"→">)]|[(<" or ">]|"→">]|[<"
 D                #  Duplicate this mirrored string
  y               #  Push the current part
   s              #  Swap so the copy of the mirrored string is at the top
    Ã             #  Keep only those characters in the part (removes noses "^"/"-")
     k            #  Get the 0-based index of the character in the mirrored string
      ®g          #  Push string `®`, and pop and push its length
        <         #  Decrease it by 1
         -        #  And subtract this from the index
 X                #  Push variable `X`
  ·               #  Double it
   <              #  Decrease it by 1
    *             #  And multiply the top two values
                  #  (negates the current value if X==0, or leaves it as is if X==1)
 y                #  Push the current part again
  Ā               #  Check that it's NOT empty (0 if empty; 1 otherwise)
   *              #  And multiply that as well, so empty parts become 0
}I                # After the loop, push the input again
  ';å            '# Check if it contains a ";" (1 if truthy; 0 if falsey)
O                 # And sum all values on the stack
                  # (after which the result is output implicitly)


Make some noise-cancelling headphones I am in desperate need of some ear defenders, so I can program in peace. Unfortunately, I don't have ear defenders. But I do have a pair of headphones, a microphone and a microcontroller, so I thought I'd make some noise-cancelling headphones.
However, there is one tiny problem. I can't program in noisy environments! So you'll need to write the code for me.
Task
Given a constant noisy input, output the input's "complement"; a value that will completely cancel out the input value (0x00 cancels 0xff, 0x7f cancels 0x80). Because the headphones block some noise, also take a value as input that you will divide the "complement" by, using the following algorithm: if (c < 0x80) ceil ( 0x7f - ( (0x7f - c) / n ) ) else floor ( ( (c - 0x80) / n ) + 0x80 ) where c is the "complement" and n is the value to divide by. (If the value exceeds the byte range, it should be clipped to 0 or 255.)
The input will always be a sequence of bytes, via stdin or function parameter (see bonuses) but the modifier can be given via any input method. The output sequence should be output via stdout or as a return value (see bonuses). The output should be a series of bytes (e.g. $.d<±3Ç/ó¢), or a set of numbers representing those bytes (e.g. 217 135 21 43 126 219).
Oh, and your code will have to be short, because there isn't much flash memory on the microcontroller (4096 bytes; and I need to fit on drivers too!).
Examples
In these examples, I have used hexadecimal codes to represent bytes, because DEL and NULL are somewhat hard to read. The actual input and output should be done as a string of bytes or as a byte-stream.
Modifier: 2
Input: 0x00 0x10 0xe0 ...
Output: 0xbf 0xb7 0x4f ...
Modifier: 128
Input: 0x00 0x10 0xe0 ...
Output: 0x80 0x80 0x7f ...
Modifier: 0.5
Input: 0x00 0x10 0xe0 ...
Output: 0xff 0xff 0x00 ...
Your code should cope with much longer inputs than this; these are just examples.
Bonuses
To add a bonus to a score, use the following formula: s * (100% - b) where s is the current score and b is the bonus as a percentage.

1% If you output as raw bytes.
5% If there's no stdin pipe (or byte input), get the bytes straight from the microphone, such as with parec.
5% If you output to the speakers as well as returning / outputting to stdout.

Pyth, 54 51 bytes
J128m.MZ,0h.mb,255?<dJ.E-tJc-tJdQs+c-dJQJm-255id16E

Try it here!
Explanation

J128m.MZ,0h.mb,255?<dJ.E-tJc-tJdQs+c-dJQJm-255id16E   # Q = modifier, E = input list

J128                                                  # set J to 128
                                         m        E   # map each input d
                                              id16    # convert to decimal
                                          -255        # get the complement
    m                                                 # map each complement d
                  ?<dj                                # if d < 128
                      .E-tJc-tJdQ                     # use the ceil-formula
                                 s+c-dJQJ             # otherwise use the floor-formular
          .mb,255                                     # minimum of the result and 255
    .MZ,0h                                            # maximum of the result and 0