Character by Character Your program must take in a string like:

test string

And must output each character adding one at a time like this:

t
te
tes
test
test
test s
test st
test str
test stri
test strin
test string

notice how spaces count!

Good luck!
Least Bytes win.
~N

05AB1E, 3 bytes

Uses CP-1252 encoding.

.p»

Try it online!

Explanation

     # implicit input
.p   # list of prefixes
  »  # join by newlines


Compressing RLE data to draw ASCII art This question is based on what I came up with to answer another question.

Sometimes the questions here ask to draw some ASCII art. One simple way to store the data for the art is RLE (run-length encoding). So:

qqqwwwwweeerrrrrtttyyyy

becomes:

3q5w3e5r3t4y

Now to draw a big ASCII art you maybe be getting data like this (ignoring the new line characters):

19,20 3(4)11@1$20 11@19,15"4:20 4)19,4:20 11@
   ^^^
   Note that this is "20 whitespaces"

(Character count: 45)

The characters used for the ASCII art are never going to be lowercase or uppercase letters or numbers, only signs, marks and symbols but always in the printable ASCII character set.

You want to save some space in that string, so you replace the numbers with the uppercase character set (being 'A' equals to 1, 'B' equals to 2 until 'Z' equals to 26), because you are never going to get more than 26 repetitions of a character. So you get:

S,T C(D)K@A$T K@S,O"D:T D)S,D:T K@

(Character count: 34)

And finally you notice that some groups of (letter+symbol) are repeating, so you substitute the groups that appear 3 times or more in the string by the lowercase character set, in order or appearance in the string, but storing in a buffer the substitutions made (in the format "group+substitution char" for each substitution), and leaving the rest of the string as is. So the following groups:

S, (3 times)
T  (4 times)
K@ (3 times)

gets substituted by 'a', 'b' and 'c', respectively, because there are never going to be more than 26 groups repeating. So finally you get:

S,aT bK@c
abC(D)cA$bcaO"D:bD)aD:bc

(Character count: 9+24=33)

[The last step only saves 1 byte because the groups that actually save characters after being substituted are the ones appearing 4 times or more.]

The challenge

Given a string containing the RLE data to draw an ASCII art (with the restrictions proposed), write the shortest program/function/method you can in order to compress it as described. The algorithm must print/return two strings: the first one containing the dictionary used for the compression, and the second one being the resulting compressed string. You may return the strings as a Tuple, an array, List or whatever, in the given order.

Note that if the string cannot be compressed in the step 2, the algorithm must return an empty string as first return value and the result of the step 1 as second return value.

You do not need to include the result of step 1 in the output values, I just include them in the examples for clarification purposes.

This is code-golf, so may the shortest answer for each language win!

Another test case

Input:                   15,15/10$15,15/10"10$10"10$10"10$10"15,15/

Output of step 1:        O,O/J$O,O/J"J$J"J$J"J$J"O,O/

Final algorithm output:  O,aO/bJ$cJ"d
                         abcabdcdcdcdab

---

Input:                   15,15/10$15,15/10"

Output of step 1:        O,O/J$O,O/J"

Final algorithm output:  <empty string>
                         O,O/J$O,O/J"


Row, Column, Diagonal, Block Write a square block of code that is N characters wide and N characters tall, for some positive integer N.

For instance, your N may be 5 and the block look like this:

ThisI
sMy5B
y5Cod
eBloc
kOkay

This block needs to behave as follows:

When the top row is extracted and run as a program, the exact text row needs to be printed to stdout.

For example, ThisI would print row.
When the left column is extracted and run as a program, the exact text col needs to be printed to stdout.

For example, Tsyek would print col.
When the main diagonal from the top left to the bottom right corners is extracted and run as a program, the exact text dia needs to be printed to stdout.

For example, TMCoy would print dia.
When the entire block is run as a program, including the newlines (with an optional trailing newline), the exact text blk needs to be printed to stdout.

For example,

ThisI
sMy5B
y5Cod
eBloc
kOkay

would print blk.

Details

All four programs are run in the same programming language.
The N2 characters in the original block may be anything but line terminators.
If your language does not have an stdout, you may use another common output method. It must be the same method across all four programs.

The submission whose original block contains the fewest distinct characters (not counting newlines) wins. Tiebreaker goes to the submission with the smaller N.

CJam, 13 12 unique characters, N = 5
"row"
cd;"a
oaiaa
l"aa;
"blk"

As straight forward as it gets
UPDATE : Converted space to a (no-op in this case) as pointed out by Runner112
Try it online here


Solve a Tetris Puzzle (pack predefined shapes into optimal form) The challenge is about finding an optimal solution on how to place a number of given shapes. It is oriented on the principle of Tetris, where it is optimal to pack the given pieces as tight as possible.

An optimal solution means that all shapes could be placed in one rectangle block filling the width of the playground. If there is no optimal solution possible, the code should find a solution where holes are placed as high as possible (thus allowing to have a subpart of the solution being optimal). Empty spaces on top of the solution are also counted as holes (see example at the bottom).

Rules

There are predefined Tetris shapes: I J L S Z O T
There could be multiple shapes of the same type available
There is a playground with a certain width X
The minimum width is 4, there is no maximum width
There is no limitation for the height of the playground
It is possible to rotate the shapes in 4 directions (Up, Left, Right, Down)
It is NOT possible to mirror the shapes (Turning L into J or S into Z)

Possible shapes:

T:      T
       TTT

I:     IIII

J:     JJJ
         J

L:       L
       LLL

S:      SS
       SS

Z:     ZZ
        ZZ

O:     OO
       OO

A bit of imagination is needed, but everyone who played Tetris should be familiar with the shapes.

Example

A call to a solution using Python could look like the following:

tetrissolver.py <Width> <Shape1> <Shape2> <ShapeN>

tetrissolver.py 4 S S T T L

The result would be some kind of output which shows the optimal solution (tightest possible packaging). Bonus points if the solution also returns if the found solution is optimal.

Possible output of the above input in a text format:

LLLT
LSTT
SSST
STSS
TTTS

The found solution is optimal

If there is no optimal solution available, the code should find a solution with the least amount of holes in it. Empty spaces on top of the package are counted as holes. The above example with an additional T element could look like the following in the solution (holes marked with X):

XTXX
TTTX
LLLT
LSTT
SSST
STSS
TTTS

The found solution is NOT optimal

Solution

The solution should find the most optimal package. Holes should be placed as high as possible. If two solutions generate the same quality of packages (optimal packages if possible, same amount of holes), the smallest solution wins.

Java - Theoretically Optimal Solution

I needed one of these anyway, so...

Code is viewable here.

The routine should theoretically produce an optimal solution for any input. It typically runs on the order of milliseconds or seconds for < 100 shapes, and the complexity appears to be roughly O(n log2 n) for random inputs. Packing hundreds or even thousands of random shapes should complete in a reasonable amount of time.

The worst case performance grows as O(nn ww), where n is the number of shapes to pack and w is the packing width. Thus this program earns the dubious distinction of having the worst worst case performance of any (non-busy-beaver) algorithm I've ever programmed. :P

Sample I/O

java TetPack 10 J T Z I I J Z O O J T S S O I

IIIIJOOTTT
IIIIJOOSTI
OOSJJZTSSI
OOSSZZTTSI
OOJSZJTZZI
OOJJJJJJZZ

Displayed solution is optimal.

java TetPack 3 T

XTX
TTT

9 J S I O S T T I I I S

XIIIIIIII
TTTSSIIII
TTSSJJJOO
TTSSSSJOO
TSSSSIIII

java TetPack 15 L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J

JJJJLLLLJLJJJJJ
JJJJLLJJJLJJJJJ
LLLLLLJJJLLLJJJ
LLLLLLJJLLLLJJJ
LLLLJJJJLLJLLLL
LLLLJJJJJLJJJLL
LLJJJJJJJLLLLLL
LLJJJJJJJLLLLLL
LLJJJJJLJLLLLLL
JJJJJJLLJJJLJLL
JJJJJJLLLLLLJLL
JJJJJLLLJJLJJLL
LLLJJLLLJJLJJJJ
LLLLLLLLJJLLLJJ
JLLLLLJLJJLLJJJ
JJJLLLJJJLLLJJJ

Displayed solution is optimal.

java TetPack 4 Z T

XZXX
ZZTX
ZTTT

java TetPack 30 J I O J J L T T T I O Z Z S I I O Z T O L L J I I L S Z Z I J I O S L L L L J J J I I O Z L J I L S I S Z I L I J I O J J L T T T I O Z Z S I I O Z T O L L J I I L S Z Z I J I O S L L L L J J J I I O Z L J I L S I S Z I L I

XXIIIIIIIIIIIIIIIIIIIIIIIIIIII
LIIIILIIIILIIIILIIIIJLIIIIJLOO
LIIIILJJJLLIIIILLLJJJLIIIIJLOO
LLJLJLLIJLLLZLJLLLJJJLLZZJJLLI
JJJLJJJILLLZZLJJJLJZZLLIZZZOOI
JJJLLILILZZZJLLSSOOIZZLILZZOOI
JJJJJILILLZZJSSSZOOIOOLILZTLLI
IJJJJILLSSZJJSSZZOOIOOTILLTTLI
IJJJJILSSZZSSZSZTOOIITTTOOTSLI
IJJJJLLZZZSSZZTTTTOOIIJJOOLSSI
ISSZILLLZZOOZTTTTJOOIIJLLLLTSI
SSZZILLOOJOOTZZTTJJJIIJLZZTTOO
LSZLIZZOOJJJTTZZTIIIIIJLLZZTOO
LSSLIJZZOOOOTSSSSSSTZZJJJLIIII
LLSLLJJJOOOOSSSSSSTTTZZLLLIIII


Write a narcissist program! A narcissist program is simple.  It is related to a quine.

If the input is equal to it's source code, it prints a truthy value, if not it prints a falsy one.  That is it.

Rules:

It can't read it's own file.
This is code-golf, so the shortest answer wins.
Hash functions are not allowed.  This trivializes it into just string matching.
The submission may be a function.

An example would be:

Code:

someprogramhere

Input:

someprogramhere

Output:

1

Or input:

a

Output:

0

Your code most certainly won't be someprogramhere, but you get the idea.

Go code.

JavaScript ES6, 14 bytes

$=_=>_==`$=`+$

Simple modification of the traditional "bling quine".


Finding internal rate of return (IRR) In investing, internal rate of return (IRR), the continuously compounded rate of return economically equivalent to a specified series of cashflows, is often a valuable concept.

Your challenge is to demonstrate how to compute IRR in the language of your choice in as few bytes as possible, subject to the following conditions:

Your code should accept arbitrary cashflows, subject only to the condition that the initial cashflow is negative.
You can assume that the cashflow has already been assigned to a variable f (use some other variable name if 'f' is a command name in your language).
Assume cashflow is specified as a series of (date, datum) pairs, in whatever format is most convenient for your language. This challenge is about the IRR computation, not parsing the input.
All functions built into your language are allowed except IRR() or the equivalent, if your language has it, because that's not interesting.
Output should be a real number (thus, 0.14, not "14%").

The solution requires numerical root-finding, and different methods and starting conditions will find slightly different answers. For the purposes of the contest, if you're within 0.001 of the answer reached by Excel's XIRR function, you're close enough.

Example 1:

f={{{2001, 1, 1}, -1}, {{2002, 1, 1}, .3}, {{2005, 1, 1}, .4}, {{2005, 1, 10}, .5}};

0.0584316

Example 2:

f = {{{2011, 1, 1}, -1}, {{2012, 2, 1}, -.3}, {{2015, 3, 1}, .4}, {{2015,3,15},.01}, {{2015, 4, 10}, .8}};

-0.2455921

Example 3:

f = {{{2011, 1, 1}, -1}, {{2012, 2, 1}, 3.3}, {{2015, 3, 1}, 5.4}, {{2015,3,15}, 6.01}, {{2015, 4, 10}, 17.8}};

2.4823336

More information available at http://en.wikipedia.org/wiki/Internal_rate_of_return

Maxima, 149

load(mnewton)$y(d):=?encode\-universal\-time(0,0,0,d[4],d[3],d[2])/31536000$mnewton(f[1][1]+sum(f[i][1]*(1+r)^(y(f[1])-y(f[i])),i,2,length(f)),r,.1);

This code has a bug where some payments might be off by 1/24 day (1 hour). This bug happens if your local time zone moves in or out of daylight-saving time. To fix this bug, add ,0 (2 characters) after d[2].

First set f to a list of lists in the form [[flow, year, month, day], ...]. Then paste this code at Maxima's prompt. The answer comes in the form [[r = float]]. If you want the float by itself, use part(%[1][1],2);

Example 1:

(%i150) f : [[-1, 2001, 1, 1], [.3, 2002, 1, 1], [.4, 2005, 1, 1],
             [.5, 2005, 1, 10]]$

(%i151) load(mnewton)$y(d):=?encode\-universal\-time(0,0,0,d[4],d[3],d[2])/31536000$mnewton(sum(f[i][1]*(1+r)^(y(f[1])-y(f[i])),i,1,length(f)),r,.1);
(%o153)                   [[r = .058394251994029284]]

Example 2:

(%i154) f : [[-1, 2011, 1, 1], [-.3, 2012, 2, 1], [.4, 2015, 3, 1],
             [.01, 2015, 3, 15], [.8, 2015, 4, 10]]$

(%i155) load(mnewton)$y(d):=?encode\-universal\-time(0,0,0,d[4],d[3],d[2])/31536000$mnewton(sum(f[i][1]*(1+r)^(y(f[1])-y(f[i])),i,1,length(f)),r,.1);
(%o157)                  [[r = - .017843072768412977]]

Example 3:

(%i158) f : [[-1, 2011, 1, 1], [3.3, 2012, 2, 1], [5.4, 2015, 3, 1],
             [6.01, 2015, 3, 15], [17.8, 2015, 4, 10]]$

(%i159) load(mnewton)$y(d):=?encode\-universal\-time(0,0,0,d[4],d[3],d[2])/31536000$mnewton(sum(f[i][1]*(1+r)^(y(f[1])-y(f[i])),i,1,length(f)),r,.1);
(%o161)                   [[r = 2.4823712861605407]]

My time zone is America/New_York. Because of the daylight-saving bug, other time zones might give slightly different answers.

Ungolfed

load(mnewton)$

/*
Returns the number of 365-day periods since the epoch, when called as
year([year, month, day]).
*/
year(date):=
?encode\-universal\-time(
  /* s, m, h, day, month, year, time zone */
  0, 0, 0, date[3], date[2], date[1], 0) /
31536000 /* seconds in 365 days */$

/*
Finds a numerical approximation for the internal rate of return for a
list of cash flows on a list of dates.  The dates must be a list of
lists in the form

    [[year, month, day], [year, month, day], ...]

The first date in the list is the present date for calculating the
present value of each cash flow.  Returns the rate for each 365-day
period.
*/
xirr(flows, dates):=
part(
  /* Solve for rate where net present value = 0. */
  mnewton(
    sum(
      /* present value of flows[i] on dates[i] */
      flows[i] * (1 + rate)^(year(dates[1]) - year(dates[i])),
      i, 1, length(flows)),
    rate  /* solve for rate */,
    .1    /* initial guess */)
  [1][1], /* extract 1st solution, 1st variable */
  2       /* value in variable = value */)$

Here xirr(flows, dates) is a function, but the golfed version only has an expression that looks at f.  The golfed version also removes the part call and adds the daylight-saving bug.


Compact a Befunge program Befunge is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it passes over, and changing direction when it hits an arrow (>^<v). Commands are stack-based; see this list. See also http://esolangs.org/wiki/Befunge.

The specification for Befunge-98 is available.

Problem

Write a program that transforms a Befunge program into a more compact representation. For example, the following program prints 0:

>   0   v

>   @   .

^       <

In this case, it could be compacted without changing the program's behavior by removing rows of spaces, to give

>0v
>@.
^ <

More sophisticated transformations could rotate or mirror sequences of commands and eliminate unnecessary control-flow commands in order to compact the program. For example, with this program:

>12345v
      6
v....7<
.
.
.
@

you might tuck the end of the program into the hole:

>12345v
>...@ 6
^....7<

For the first example, the most compact program possible is

>0.@

You may use any transformations as long as the output program gives the same result.

Input programs

Input programs are valid Befunge-98 programs.

You may assume that the input program is deterministic. That is, it does not use commands that read external state: the user input commands & and ~, the randomizer ?, and the self-modifying code commands p and g.

You may assume the input program terminates.

Scoring

This is not a code golf, but a problem to write a program that performs code golfing.

The input is a set of test cases (Befunge programs that satisfy the input restrictions above). The total score is the sum of the scores for the test cases.

Score for each test case

The score is the area of the convex hull of the non-empty cells in the output program, where each cell is treated as a square whose four corners are lattice points in the Cartesian plane. For example, a program of

>   v
 @  <

gets a score of 9.5.

If your program does not terminate in a reasonable amount of time and memory on a particular input, the score is that of the input program. (This is because you could trivially add a time-limiting wrapper that outputs the input program unchanged if your program doesn't terminate in time.)

If the test-case program has a different result (or fails to terminate) after processing with your program, the score is the score of the input program plus a penalty of 100 points.

I spent a long plane ride coding this one up.  I've written a pseudo befunge compiler which runs the befunge program, extracts basic blocks, and lays them out in a compact representation.

Link to the program.

When run on this 99 bottles program:

92+9*                           :. v  <
>v"bottles of beer on the wall"+910<
,:
^_ $                             :.v
            >v"bottles of beer"+910<
            ,:
            ^_ $                     v
>v"Take one down, pass it around"+910<
,:
^_ $                           1-v
                                 :
        >v"bottles of beer"+910.:_          v
        ,:
        ^_ $                          ^
                    >v" no more beer..."+910<
                    ,:
                    ^_ $$ @

It generates the following output:

92+9*:.019+"llaw eht no "v
v  _v# :"bottles of beer"<
>    ,:    v
^  _v#     <
    >$:.019+"reeb f"v
 v _  v#:"bottles o"<
 >     ,:  v
 ^ _  v#   <
      >$019+"dnuo"v
     v"pass it ar"<
     >" ,nwod eno"v
 v _    v#:"Take "<
 >       ,:v
 ^ _    v# <
        >$1-:v
 v _      v# <
 >         :.019+"reeb "v
  v_  v#   :"bottles of"<
  >        ,v
  ^_  v#   :<
      >    $019+"llaw"v
           v" on the "<
           >"reeb fo "v
^  _^#      :"bottles"<
          >019+"...r"v
v  _v#:" no more bee"<
>    ,:    v
^  _v#     <
    >$$@

It actually isn't much more compact than the source, but it will probably do better on larger/sparser programs.

The program is laid out with a routing area on the left and basic block contents on the right.  A basic block is usually laid out in an even number of rows so the entrance and exit adjoin the routing area.  At the end of each basic block, the gadget #^_v and variants, laid out right-to-left, do the conditional branch and route flow into columns.  At the start of each basic block, these columns are routed into the rows for the destination basic block.

In addition, if the output is short it just generates the output explicitly, like this:

"output">:#,_@

I haven't done anything to optimize the basic blocks themselves, just the layout.  Todo.

So where are the tests?


"Bit-borrow" two numbers Did you know that a small number can borrow bits from a larger number? Here's an example. Let's say our two numbers 5 and 14. First, write them out in binary:
5       14
000101  001110

First we take the smallest on bit away from the larger number, and we give it to the smallest off bit on the other number. So
This bit turns off
            |
            v
000101  001110
    ^
    |
This bit turns on

Now we have
000111  001100

and our numbers are 7 and 12. The first number is still smaller, so we continue.
000111  001100
001111  001000

Now we have 15 and 8, so we can stop. We'll call this set of operations "bit-borrowing" two numbers. Let's do another example. 20 and 61.
20        61
010100    111101
010101    111100
010111    111000
111111    100000
63        32

So our end result is 32, 63. Let's do one more. 31, and 12. 31 is already bigger than 12, so there's nothing to do! Bit-borrowing 31 and 12 gives 31 and 12, no change.
The challenge
Your challenge is to write a program or function that takes two numbers and bit-borrows them. The two numbers will always positive integers. Your input and output can be in any reasonable format.
Test IO:
Input: 2, 3
Output: 3, 2

Input: 3, 2
Output: 3, 2

Input: 8, 23
Output: 31, 0

Input: 42, 81
Output: 63, 0

Input: 38, 41
Output: 47, 32

Input: 16, 73
Output: 23, 0

Input: 17, 17
Output: 17, 17

Standard loopholes apply, and shortest answer in bytes wins!

Jelly, 11 bytes

~1¦&N$^µ</¿

Try it online! or verify all test cases.

Background

We can extract the last set bit of an integer n as follows.

n + 1 toggles all trailing set bits of n and the adjacent unset bit. For example, 100112 + 1 = 101002.

Since ~n = -(n + 1) = -n - 1, -n = ~n + 1, so -n applies the above to the bitwise NOT of n (which toggles all bits), thus toggling all bits before the last 1.

For example, -101002 = ~101002 + 1 = 010112 + 1 = 011002.

By taking n & -n the bitwise AND of n and -n all bits before the last set bit are nullified (since unequal in n and -n), thus yielding the last set bit of n.

For example, 101002 & -101002 = 101002 & 011002 = 001002.

Thus XORing n with n & -n unsets the last set bit of n.

Conversely, to unset the last set bit of n, it suffices to apply the above to ~n, from where we derive the formula n ^ (~n & -~n).

How it works

~1¦&N$^µ</¿  Main link. Argument: A (list of pairs)

          ¿  While loop:
        </     Condition: Reduce p by less-than. True iff x < y.
       µ       Body chain:
~1¦              Apply bitwise NOT to the x, first item of the pair.
     $           Convert the two links to the left into a monadic chain.
    N              Negate; multiply [~x, y] by -1, yielding [-~x, -y].
   &               Logical AND. Yields [-~x & ~x, -y & y].
      ^            Vectorized XOR with p. Yields [(-~x & ~x) ^ x, (-y & y) ^ y].


Cyclic Polyglot Challenge (Robbers) Cyclic Polyglot Challenge

This is the robbers thread. You can find the cops thread here.

Cyclic Polyglot

A N-element cyclic polyglot is a complete program that can be run in N different languages. In each language, when the program is run with no input (possibly subject to this exception), it should print the name of a language to STDOUT. Specifically, if the program is run in the Kth language, it should print the name of the (K+1)th language. If the program is run in the Nth language (that is, the final language in an N-element cycle), it should print the name of the first language.

An example might be useful.

a = [[ v = 7, puts('Befunge') ]]
__END__
= print("Ruby")
-->*+:292*++,,@
--3    9
--7    *
--^,:-5<

Running this program with Lua prints the string "Ruby". Running this program in Ruby prints the string "Befunge". Running this program in Befunge prints the string "Lua", completing the cycle. This program constitutes a 3-cycle consisting of Lua, Ruby, and Befunge.

The same language cannot appear twice in a cycle, and different versions of the same language (such as Python 2 and Python 3) cannot appear in the same cycle as one another.

Cops

Your challenge is to write an N-cyclic polyglot, where N is at least 2. Then, you must add, replace, and delete some number of characters to the program to produce an M-cyclic polyglot, where M is strictly greater than N. You should then post the shorter, N-cyclic polyglot (and the languages it runs in), as well as the number of characters you changed to produce the longer polyglot. Your score is N, the number of languages in your shorter cycle.

The robbers will try to identify your longer cycle. If, after seven days, no one has successfully cracked your solution, you should edit your answer declaring that it is safe. You should also post your longer M-cyclic polyglot at this time.

Robbers

Given a cop's N-cyclic polyglot and the number of characters they added to produce a larger polyglot cycle, your goal is to produce that larger cycle. If you can produce a longer cycle by adding, deleting, or replacing as many characters as the cop did or fewer characters, you have cracked the cop's polyglot. Your score is the length of the new cycle you've created. Your new polyglot need not be the same as or even similar to the cop's secret polyglot; it only needs to be larger than their existing one.

Your solution may also be cracked. If another robber comes along and produces a cycle strictly longer than yours, starting from the same cop's polyglot, they have stolen your points.

Valid Programming Languages

Since this challenge indirectly involves guessing programming languages used by other participant's, the definition of a programming language for the purposes of this challenge will be a little more strict than the usual definition. A programming language used in this challenge must satisfy all of the following conditions.

The language must satisfy the usual PPCG requires for a programming language.
The language must have either a Wikipedia article, an Esolangs article, or a Rosetta Code article at the time this challenge was posted.
The language must have a freely available interpreter or compiler.

Final Notes

The code you write should be a standalone program in every language that it is intended to run in. Functions or code snippets are not allowed.
Your program will be given no input through STDIN. Likewise, your program should print nothing to STDERR.
A cop's score is the number of languages in the cycle of the polyglot they posted. The cop should post the languages that the posted polyglot runs correctly in, as well as the number of characters they added to produce a longer polyglot. They are not responsible for posting the languages the longer, hidden polyglot runs in until their answer is safe.
A robber's score is the number of languages the modified polyglot runs in. As with the cop, the robber should post the list of languages the polyglot runs correctly in.
The number of characters changed should be computed in Levenshtein distance.

mdahmoune, added Ruby, Levenshtein = 10
#include<stdio.h>
#define print(a) main(){int z[1];if(sizeof(0,z)==4)printf("C(gcc)");else printf("Perl5");}
print($=?"Ruby":"C++(gcc)")

Cycle is C -> Perl5 -> Ruby -> C++ -> C
I don't really know what I did (and I really don't know why it's valid in C and C++), I just ripped it off this answer.
C (gcc): Try it online!
Perl5: Try it online!
Ruby: Try it online!
C++ (gcc): Try it online!


How many bystanders will help? Flavortext
The Bystander Effect is a phenomenon where individuals are less likely to help a victim if other people are present. The idea is that as there are more people around, the individual burden is less, and each individual thinks "someone else will help them", which results in the counterintuitive fact that fewer people will help when there are more people.
(This is why if you're in public and something bad happens and you / someone else needs help, you should address random individuals ("you in the red shirt") to help specifically rather than "someone please help" to bypass this psychological phenomenon)
Let's take a very simplified interpretation of this theory and assume everyone has a numerical threshold for helping.
Specification
A list of people will be given, each with a threshold to help. The threat level is 1. A person will help if and only if the threat level divided by the number of people in the crowd is greater than equal to their threshold. When a person decides to help, they leave the crowd. This means that the individual threat, which is the threat level (1) divided by the size of the crowd, is now higher as a result because the crowd is smaller.
The total threat level (1) never changes, for simplicity.
How many people end up helping?
Input
You are given a list of floating point numbers in any reasonable format. This list will be non-empty, and every number will be in the inclusive range from 0 to 1. You may assume the list is sorted in either order you would like.
Output
You are to output a single integer, indicating how many of the individuals decide to help.
Example
Consider the test case 0.2, 0.2, 0.3, 0.6, 0.8. The crowd has five people, so the threat to each individual is 0.2. Therefore, the first two people will help. Now, the crowd is 0.3, 0.6, 0.8. Since there are only three people, the threat to each individual is now 0.3. Therefore, the third person will now decide to help. The crowd is now 0.6, 0.8, so the individual threat is 0.5, and nobody decides to help anymore. Therefore, the final result is 3.
Test Cases
1                        -> 1
0.5, 0.8                 -> 2 # 0.8 initially won't help, but will when 0.5 leaves
0.2, 0.2                 -> 2 # both will help initially
0.2, 0.2, 0.3, 0.6, 0.8  -> 3 # 0.2 and 0.2 leaving prompts 0.3 to help, but the other two won't help
0, 0.25, 0.33, 0.5, 1    -> 5 # all of them help only after the previous person left, starting with 0
0, 0.25, 0.34, 0.34, 1   -> 2 # 0 and 0.25 help, but 0.34 is just a bit too indifferent to help, which means 1 will never help either
0.5, 0.5, 0.5            -> 0 # nobody helps. RIP

Reference Implementation
This implementation (Python) shows the final answer at the very end. It also breaks down the process stage-by-stage.

Jelly,  9 8  7 bytes
(Saved 1 when the assumption of sorted input was allowed, and another realising there was no need to floor the inverses.)
İ<Jṣ1ṪL

A monadic Link accepting a list of floating-point numbers in \$[0,1]\$ sorted in descending order that yields an integer.
Try it online! Or see the test-suite.
How?
Effectively this evaluates how many people need to be in the crowd to stop each person helping, identifies crowd sizes that would be too big for anyone to help if those most likely to help have been removed, then counts those in excess of the biggest of those crowd sizes.
İ<Jṣ1ṪL - Link: list of thresholds, T  e.g. [1, 0.34, .34, .25, 0]
İ       - inverse (T)                       [1, 2.94, 2.94. 4, inf]
  J     - range of length (T)               [1, 2, 3, 4, 5]
 <      - less than?                        [0, 0, 1, 0, 0]
   ṣ1   - split at ones                     [[0, 0], [0, 0]]
     Ṫ  - tail                              [0, 0]
      L - length                            2

Equivalently:
İ<JṚÄċ0
   Ṛ    - reverse                           [0, 0, 1, 0, 0]
    Ä   - cumulative sums                   [0, 0, 1, 1, 1]
     ċ0 - count zeros                       2


Assign Airliner Seats Inspired by last week's APL lesson.

Given an uppercase 2D seat map and a 1D list of customers, return the seat map and the customer list but modified as follows (to indicate occupied seats and seated customers):

For each unique letter in the input passenger list, lowercase that many (or all, if there are not enough) of that letter in the seat map, going left-to-right, top-to-bottom.

For each unique letter in the seat map, lowercase that many (or all, if there are not enough) of that letter in the passenger list, going left-to-right.

The input seat map only contains spaces and uppercase letters from the set {F,B,P,E}, and may be:

separated into rows by line breaks
a list of strings
a matrix of uppercase characters
in any other comparable format

The input customer list only contains uppercase letters from the set {F,B,P,E} and may be:

a string
a list of characters
in any other comparable format

The returned seat map must be identical to the input one, except that zero or more letters have been folded to lowercase
The returned customer list must be identical to the input one, except that zero or more letters have been folded to lowercase
Leading and trailing whitespace is allowed

Examples (shortened editions of United's aircraft)

ERJ145

Seat map input:

P
E
E  PP
E  EE
E  EE
E  EE
E  EE

P  PP
E  EE
E  EE
E  EE

Passenger list input:

FFEEEEEEEEEEEEEEEE

Seat map output:

P
e
e  PP
e  ee
e  ee
e  ee
e  ee

P  PP
e  eE
E  EE
E  EE

Passenger list output:

FFeeeeeeeeeeeeeeee

CRJ700

Seat map input:

F   FF
F   FF
PP  PP
PP  PP
PP  PP
EE  EE

PP  PP
EE  EE
EE  EE
EE  EE

Customer list input:

FFFFFFFFPPEEEEEEEEEEEEEEEEEEEEE

Seat map output:

f   ff
f   ff
pp  PP
PP  PP
PP  PP
ee  ee

PP  PP
ee  ee
ee  ee
ee  ee

Customer list output:

ffffffFFppeeeeeeeeeeeeeeeeEEEEE

B757

Seat map input:

F F  F F
F F  F F
F F  F F

PPP
PPP  PPP
PPP  PPP
PPP  PPP
EEE  EEE
EEE  EEE
PPP  PPP
EEE  EEE
EEE  EEE
     EEE

EEE  EEE
EEE  EEE
EEE  EEE
EEE

Passenger list input:

FEEEEEEEEFEEEFEEEEEEEEFEEFFEEFEFFFEE

Seat map output:

f f  f f
f f  f f
f f  F F

PPP
PPP  PPP
PPP  PPP
PPP  PPP
eee  eee
eee  eee
PPP  PPP
eee  eee
eee  eee
     eeE

EEE  EEE
EEE  EEE
EEE  EEE
EEE

Passenger list output:

feeeeeeeefeeefeeeeeeeefeeffeefefffee

B767

Seat map input:

 F   F   F
 F   F   F
BB  B B  BB
BB  B B  BB
BB  B B  BB
PP       BB
PP

PP  PPP  PP
PP  PPP  PP
PP  PPP  PP
PP  PPP  PP
PP  EEE  PP
EE  EEE  EE
EE  EEE  EE
EE  EEE  EE
EE  EEE  EE
EE  EEE  EE

Passenger list input:

PPFEFEEEEEEEBBEEFFPEBPEBBEEFEEEFEEEEEEFPEEEPB

Seat map output:

 f   f   f
 f   f   f
bb  b b  bb
BB  B B  BB
BB  B B  BB
pp       BB
pp

pp  PPP  PP
PP  PPP  PP
PP  PPP  PP
PP  PPP  PP
PP  eee  PP
ee  eee  ee
ee  eee  ee
ee  eee  ee
ee  EEE  EE
EE  EEE  EE

Passenger list output:

ppfefeeeeeeebbeeffpebpebbeefeeefeeeeeeFpeeepb

Python 2, 93 89 84 83 82 78 bytes

l=input()
for c in l[1]:l=[x.replace(c,c.lower(),c in l[0])for x in l]
print l

Try it online!

Takes input as two strings. Prints two strings

Saved

-5 bytes, thanks to Dead Possum
-4 bytes, thanks to Lynn


Compute the CRC32 table at compile-time The reference implementation of CRC32 computes a lookup table at runtime:

/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];

/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;

/* Make the table for a fast CRC. */
void make_crc_table(void)
{
    unsigned long c;

    int n, k;
    for (n = 0; n < 256; n++) {
        c = (unsigned long) n;
        for (k = 0; k < 8; k++) {
            if (c & 1) {
                c = 0xedb88320L ^ (c >> 1);
            } else {
                c = c >> 1;
            }
        }
        crc_table[n] = c;
    }
    crc_table_computed = 1;
}

Can you compute the table at compile-time, thus getting rid of the function and the status flag?

Here's a plain C solution:

crc32table.c

#if __COUNTER__ == 0

    /* Initial setup */
    #define STEP(c) ((c)>>1 ^ ((c)&1 ? 0xedb88320L : 0))
    #define CRC(n) STEP(STEP(STEP(STEP(STEP(STEP(STEP(STEP((unsigned long)(n)))))))))
    #define CRC4(n) CRC(n), CRC(n+1), CRC(n+2), CRC(n+3)

    /* Open up crc_table; subsequent iterations will fill its members. */
    const unsigned long crc_table[256] = {

    /* Include recursively for next iteration. */
    #include "crc32table.c"

#elif __COUNTER__ < 256 * 3 / 4

    /* Fill the next four CRC entries. */
    CRC4((__COUNTER__ - 3) / 3 * 4),

    /* Include recursively for next iteration. */
    #include "crc32table.c"

#else

    /* Close crc_table. */
    };

#endif

It relies on the nonstandard __COUNTER__ macro, as well as an evaluation semantics where __COUNTER__ is evaluated before it is passed as an argument to a macro.

Note that, since STEP evaluates its argument twice, and CRC uses eight nested invocations of it, there is a small combinatorial explosion in the code size:

$ cpp crc32table.c | wc -c
4563276

I tested this in GCC 4.6.0 and Clang 2.8 on 32-bit Linux, and both produce the correct table.


Are there N consecutive occurrences of a number in a row/column in a matrix? Take a matrix A consisting positive integers, and a single positive integer N as input, and determine if there are at least N consecutive occurrences of the same number in any row or column in the matrix.

You need only test horizontally and vertically.

Test cases

N = 1
A =
1
Result: True
----------------
N = 3
A =
1 1 1
2 2 3
Result: True
----------------
N = 4
A =
1 1 1
2 2 3
Result: False
----------------
N = 3
A =
3 2 3 4 2 1
4 1 4 2 4 2
4 2 3 3 4 1
1 1 2 2 3 4
3 2 3 1 3 1
1 1 2 2 3 4
Result: True
----------------
N = 1
A =
5 2 3 8
Result: True
----------------
N = 3
111   23  12    6
111   53   2    5
112  555   5  222
Result: False
----------------
N = 2
 4  2  6  2  1  5
 2  3  3  3  3  3
11 34  4  2  9  7
Result: True

Explanations are always a good thing :)

Husk, 9 bytes

≤▲mLṁgS+T

Takes a 2D array and a number, returns 0 for falsy instances and a positive number for truthy instances.
Try it online!

Explanation

Husk is a functional language, so the program is just a composition of several functions.

≤▲mLṁgS+T
        T  Transpose the array
      S+   and concatenate with original.
           We get a list of the rows and columns of the input array.
    ṁ      Map and concatenate
     g     grouping of equal consecutive elements.
           This gives all consecutive runs on rows and columns.
  mL       Map length over the runs,
 ▲         take the maximum of the results
≤          and see if it's at least the second input.


Spanning tree of a rectangular grid Background

A spanning tree (Wikipedia) of an undirected graph is a subgraph that is a tree which includes all of the vertices of the original graph. The following is an example of a spanning tree of a 4-by-4 grid graph.

Task

Given two positive integers w and h, output any valid spanning tree of the grid graph which has w vertices horizontally and h vertices vertically. There are lots of valid answers; just output one of them. Your code is even allowed to give different outputs across runs, as long as all of them are valid.

Input and output

The input is two positive integers w and h.

The output is a representation of a spanning tree. The output format is restricted to "a list of pairs of numbered vertices", in order to prevent various boring answers (as discussed in the sandbox). Also, the vertex numbering should be in row-major order, e.g.

0 - 1 - 2 - 3
|   |   |   |
4 - 5 - 6 - 7
|   |   |   |
8 - 9 - 10- 11

or

(0,0) - (0,1) - (0,2) - (0,3)
  |       |       |       |
(1,0) - (1,1) - (1,2) - (1,3)
  |       |       |       |
(2,0) - (2,1) - (2,2) - (2,3)

You can choose to use 0-based or 1-based indexing for vertices. Also, you may output nested or flattened arrays.

Scoring & winning criterion

The standard code-golf rules apply. The shortest valid submission in bytes wins.

Example I/O

w=3, h=2

If you want to output the following graph

+-+-+
| |
+ +-+

The list-of-vertex-pairs representation will be (using 0-based indexing for example):

[(0, 1), (0, 3), (1, 2), (1, 4), (4, 5)]

or

[((0, 0), (0, 1)),
 ((0, 0), (1, 0)),
 ((0, 1), (0, 2)),
 ((0, 1), (1, 1)),
 ((1, 1), (1, 2))]

w=1, h=1

The graph is a single vertex with no edges, and its only spanning tree is the graph itself. Your code should output an empty list (which means no edges).

K (ngn/k), 8 bytes

|\'2'+!:

Try it online!

this is a composition equivalent to the lambda {|\'2'+!x}. the trailing : forces ! (and therefore the whole composition) to be monadic.

 !2 3         /odometer
(0 0 0 1 1 1
 0 1 2 0 1 2)
 +!2 3        /flip
(0 0
 0 1
 0 2
 1 0
 1 1
 1 2)
 2'+!2 3      /pairs (sliding window size 2)
((0 0;0 1)
 (0 1;0 2)
 (0 2;1 0)
 (1 0;1 1)
 (1 1;1 2))
 |\'2'+!2 3   /cumulative(\) max(|) each(')
((0 0;0 1)
 (0 1;0 2)
 (0 2;1 2)
 (1 0;1 1)
 (1 1;1 2))


Verbose IP Range Generator The task is simple, given two IP adresses a and b, output all addresses within that range.

Examples

Example #1:

f(a = 192.168.0.1, b = 192.168.0.4)
    192.168.0.1
    192.168.0.2
    192.168.0.3
    192.168.0.4

Example #2 (TIO will truncate this, use a smaller range when testing):

f (a = 123.0.200.0, b = 124.0.0.0)
    123.0.200.0
    123.0.200.1
    ...            # Omitted pattern
    123.0.200.255
    123.0.201.0
    ...            # Omitted pattern
    123.0.201.255
    ...            # Omitted pattern
    123.0.255.255
    123.1.0.0
    ...            # Omitted pattern
    123.255.255.255
    124.0.0.0

Input and Output

a < b in other words:

Defined Programatically: a[0] < b[0] || (a[0] == b[0] && a[1] < b[1]) || (a[0:1] == b[0:1] && a[2] < b[2]) || (a[0:2] == b[0:2] && a[3] < b[3])
Defined in Words: a will always be lower than b (so you will have to increment the subnet to reach b).
No, you do not have to handle a == b (if you do, kudos).

Output should be in order from "lowest" to "highest" (see examples).
For this challenge, the valid syntax for an IP is: \d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3}.
You do not have to handle non-IP address input, if it's unexpected input you may error.
Output may be as an array or as a delimited string (using any whitespace character).

Winning

This is code-golf, lowest byte-count wins.

Pyth, 22
mj\.jd256}FmivMcd\.256

Try it online.
               cd\.       # split string by "."
             vM           # eval list (convert strings to integers)
            i      256    # convert list of base256 digits to integer
           m          Q   # map the above over implicit input list
         }F               # inclusive range
    jd256                 # convert to list of base256 digits
 j\.                      # join by "."
m                         # map over inclusive range


Create a programs that counts the 0's in numbers from 0 to a billion This will be my very first post on stackexchange so bear with me.

Create a program that counts from 0 to 1,000,000,000.
Now the trick is to not print all these characters but to only print how many zeroes are in that number. And keep track of the total amount of zeroes you've encountered. For example

10

Will output;

1
2

because 10 has 1 zero in it. The two represents how many 0's you've seen in total, in this case the only zero you have encountered previously is 0 itself so you've seen a total of 2 zeroes.
The highest score will be given to the shortest code (no surprise here).

I hope that this is not too easy and that I've posted enough information, given the fact that I'm completely new here I'm not entirely sure about this.

Python (brute force, 80 chars)

def r(n):
    l=[str(i).count('0') for i in xrange(n+1)]
    return l[-1],sum(l)

Just to asure, i got the task right, it evaluates to:

r(10)
>>> (1, 2)
r(1000000000)
>>> (9, 788888899)


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

Avoid explicit loops at all costs

Forth has two looping constructs, x y do ... loop, and lesser known [begin] ... [until] x y where x and y are values for limit and index, or conditions to be noted, respectively.

These are very slow, very wordy (haha) and overall rather bloaty, so only use them if you need to.

Instead, like a proper functional language (which Forth is, really), one should prefer recursivity over explicit loops because it tends to be shorter and makes a better use of the language.


Take one to make one Challenge

Given a list of positive integers, find if there exists a permutation where taking up to one bit from each of the integers, a binary number consisting of all 1s can be created.

The number of bits in the resulting binary number is equal to the highest MSB in the list of integers.

Output

Your code must output or return a truthy/falsey value indicating if such a permutation exists.

Examples

Truthy:

With the list [4, 5, 2], and its binary representation [100, 101, 10], we can use the third, first, and second bits, respectively, to create 111:

4  ->  100  ->  100  ->  1
5  ->  101  ->  101  ->    1
2  ->  010  ->  010  ->   1
Result                   111

With the list [3, 3, 3], all of the numbers have both first and second bits set as 1, so we can take our pick with a number to spare:

3  ->  11  ->  11  ->  1
3  ->  11  ->  11  ->   1
3  ->  11  ->  11  ->
Result                 11

Falsey:

With the list [4, 6, 2], none of the numbers have the first bit set as 1, so the binary number cannot be created:

4  ->  100
6  ->  110
2  ->  010

With the list [1, 7, 1], only one of the numbers has the second and third bits set as 1, and the number cannot be created:

1  ->  001
7  ->  111
1  ->  001

Obviously, if the maximum number of set bits exceeds the number of integers, the result number can never be created.

Test cases

Truthy:

[1]
[1, 2]
[3, 3]
[3, 3, 3]
[4, 5, 2]
[1, 1, 1, 1]
[15, 15, 15, 15]
[52, 114, 61, 19, 73, 54, 83, 29]
[231, 92, 39, 210, 187, 101, 78, 39]

Falsey:

[2]
[2, 2]
[4, 6, 2]
[1, 7, 1]
[15, 15, 15]
[1, 15, 3, 1]
[13, 83, 86, 29, 8, 87, 26, 21]
[154, 19, 141, 28, 27, 6, 18, 137]

Rules

Standard loopholes are forbidden. As this is code-golf, shortest entry wins!

Jelly, 11 bytes

BUT€ŒpṬz0PẸ

Try it online!

How it works

BUT€ŒpṬz0PẸ  Main link. Argument: A (array)

             Example: A = [4, 5, 2]
B            Binary; convert each n in A to base 2.
                      [[1, 0, 0], [1, 0, 1], [1, 0]]
 U           Upend; reverse all arrays of binary digits.
                      [[0, 0, 1], [1, 0, 1], [0, 1]]
  T€         Truth each; for each binary array, get all indices of 1's.
                      [[3], [1, 3], [2]]
    Œp       Take the Cartesian product of all index arrays.
                      [[3, 1, 2], [3, 3, 2]
      Ṭ      Untruth; map each index array to a binary arrays with 1's at
             at the specified indices.
                      [[1, 1, 1], [0, 1, 1]]
       z0    Zip/transpose the resulting 2D array, filling shorter rows with 0's.
                      [[1, 0], [1, 1], [1, 1]]
         P   Take the columnwise product.
                      [1, 0]
          Ẹ  Any; yield 1 if any of the products is non-zero, 0 otherwise.
                      1


Implement Amb and Require The Challenge

Implement amb and its sister statement require in whatever language you wish. See http://community.schemewiki.org/?amb for an example implementation in Scheme. You can rename them to a and r.

amb statements select a value passed to it arbitrarily, and require statements written after amb contain conditionals that limit the possibilities that amb will return, as the conditionals must evaluate to true. statements The pseudocode

fun rand() {
    return amb(1, 2, 3, 4)
}

will return whatever the computer feels like as long as it is 1, 2, 3 or 4. However the pseudocode

fun arbitary2 {
    x = amb(1, 2, 3, 4)
    y = square(x)
    require(even(y))
    return x
}

can only ever eventually return 2 or 4, but a user may not know which one will return. Depending on implementation, 2 may always be returned, or 4, or 2 is returned 3% of the time and so on. require can be called any time after amb is called as long as both statements are in the same program, even outside of the scope of amb, so

fun foo() {
    amb(1,2,3,4)
}
x = foo()
y = foo()
require(x > y)

is valid and x will never be less than y when the program successfully terminates. The degree to which this is possible varies language by language, so try your best to implement this. The following code should not successfully terminate:

amb(1, 2, 3, read("notes.txt"))
require(false)
print("this will never be printed")

The actual names and exact syntax of amb and require don't matter. For example, if your implementation is in assembly, then having amb read from predefined registers is legitimate as long as the essence of amb is preserved, and require can checked whether a certain register contains a certain value.

Try your best and have fun!

Scoring

This has been changed from popcon to code-golf, so make your implementations short! Least number of characters wins. Don't cheat and rename existing implementations. Any submission which does something to the effect of:

#define r rename
#define a amb

will be disqualified.

Scala, 406/377 Bytes

I offer two golfed versions of my implementation, one that chooses the value randomly and one that (somehow) abuses the task description and always returns the first legal value. It's up to you, with one to consider (the latter one is shorter, obviously):

trait A[X]{def g=scala.util.Random.shuffle(l).head;def l:Seq[X];def -(d:X)};class M{def a[X](e:Seq[X])=new A[X]{var s=e;def l=s;def -(d:X)=s=s.filter(_!=d)};def r(v:A[Boolean])=v-false;def p[X,Y](a:A[X],b:A[Y])=new A[(X,Y)]{var x=List[Any]();def l=(for(e<-a.l;f<-b.l)yield(e,f)).diff(x);def -(d:(X,Y))=x::=d};def o[X,Y](v:A[X],f:X=>Y)=new A[Y]{def l=v.l.map(f);def -(d:Y)=v.l.filter(f(_)==d).foreach(v.-)}}
trait A[X]{def g=l(0);def l:Seq[X];def -(d:X)};class M{def a[X](e:Seq[X])=new A[X]{var s=e;def l=s;def -(d:X)=s=s.filter(_!=d)};def r(v:A[Boolean])=v-false;def p[X,Y](a:A[X],b:A[Y])=new A[(X,Y)]{var x=List[Any]();def l=(for(e<-a.l;f<-b.l)yield(e,f)).diff(x);def -(d:(X,Y))=x::=d};def o[X,Y](v:A[X],f:X=>Y)=new A[Y]{def l=v.l.map(f);def -(d:Y)=v.l.filter(f(_)==d).foreach(v.-)}}

This versions are more or less just golfed versions of my initial submission (some implementations have changed slightly, but the interfaces were quite stable). Therefore I will not explain it any further but refer to my initial post. Just have in mind that everything that was "for convenience" now disappeared. And a lot of renaming happened. The only difference is that pairs are now a bit like new amb-values: If you define conditions on top of pairs this will never effect the underlying values (nevertheless, manipulating the underlying values will still affect the pairs).

To give you a hint on how to use this versions, here is a short testing code I used while golfing:

  val m = new M
  val a1 = m.a(List(1, 2, 3, 4, 5))
  val a2 = m.a(List(4, 5, 6))
  val a12 = m.p(a1, a2)
  m.r(m.o(a12, (p:(Int, Int)) => p._1 > p._2))
  m.r(m.o(a1, (e: Int) => e%2==1))

  println(a1.l)
  println(a2.l)
  println(a12.l)
  println(a12.g)

As you can see, the offered functions are now instance-methods, hence, you need an instance of M to interact with my library (this saved me one glorious byte).

Note that my ungolfed version (which I will not update any more) now includes natural syntax for the most common Int- and Boolean-operations.

(my initial submission)

Right before posting this answer the Mathematica answer was stated and it looks as if my solution is based on similar assumptions. Nevertheless, I will offer my solution, too, because I didn't copied the former answer as it wasn't there when I started.

I didn't tried to recreate a natural syntax (like: (amb(1, 2, 3) + 3) * 5, etc), but this would be possible if you like to implement the necessary implicit conversions. I chose the functional way as you will see later.

Let's start with the two keywords:

import ambiguous.AmbOps.op

object Amb {
  def amb[A](args: A*): AmbType[A] =
        new BasicAmb[A](args.toList)
  def require(amb: AmbType[Boolean]): Unit =
        amb.del(false)
  def require[A](amb: AmbType[A], predicate: A => Boolean): Unit =
        require(op(amb, predicate))
  def require[A, B](amb: AmbType[(A, B)], predicate: (A, B) => Boolean): Unit =
        require(op(amb, predicate))
}

The amb-method is quite straight forward, you provide some values and get some container, that may return a value back (more on that later).
I offer three require methods but they are all based on the first one, so the others are just for convenience. Let me explain the first one (the others will become clear as you read on): If you have some boolean amb-Container and call require, all false values are eliminated.

But how is an amb-value of arbitrary type converted into a boolean value? By offering a conversion-policy:

object AmbOps {
  def op[A, B](amb: AmbType[A], op: A => B): AmbType[B] =
        new OpAmb[B, A](amb, op)
  def op[A, B, C](amb: AmbType[(A, B)], op: (A, B) => C): AmbType[C] =
        new OpAmb[C, (A, B)](amb, p => op(p._1, p._2))
  def pair[A, B](ambA: AmbType[A], ambB: AmbType[B]): AmbType[(A, B)] =
        new AmbPair[A, B](ambA, ambB)
}

Assume we have some numerical amb-value and want to square each element, then just call op with a corresponding function: op(amb(1, 2, 4), (e: Int) => e * e) // returns a value equivalent to amb(1, 4, 16) Following the same scheme you can convert the elements to boolean values for example with op(amb(1, 2, 4), (e: Int) => e%2 == 0)

If you have several amb-values and you want to define conditions between them, it isn't that easy to do with my approach when only using amb, require and op. Therefore I defined the method pair. With pair you can create tuples/pairs out of two amb-values (or any number if you again pair pairs with other values or pairs). If you then define conditions on top of this tuples, the illegal pairs will be eliminated. But the original values aren't always manipulated. Only if this process leads to the situation that one element from one of the initial amb-values is no longer legal in any tuple, than this value is completely eliminated from the initial amb-value. If now some other amb-value (or pair) is based on this manipulated amb-value, the dependent value will also miss the deleted element.

That means that if you need a pair of values fulfilling a condition, you have to get an element from the pair-value and you cannot always rely on the original values, but I think this is a acceptable limitation.

Just for convenience there is an additional op-method for tuples.

Now we have to dig deeper into the technical details of the amb-containers:

import scala.util.Random

trait AmbType[A] {
  def get: A = {
    if (list.isEmpty)
      throw new IllegalStateException("no value left")
    else list(Random.nextInt(list.length))}
  private[ambiguous] def list: List[A]
  private[ambiguous] def del(a: A): Unit
}

class BasicAmb[A](private var args: List[A]) extends AmbType[A] {
  override private[ambiguous] def list: List[A] = args
  override private[ambiguous] def del(a: A): Unit = { args = args.filterNot(_ == a)}
}

class OpAmb[A, B](amb: AmbType[B], op: B => A) extends AmbType[A] {
  override private[ambiguous] def list: List[A] = amb.list.map(op)
  override private[ambiguous] def del(a: A): Unit = amb.list.filter(op(_) == a).foreach(amb.del)
}

class AmbPair[A, B](ambA: AmbType[A], ambB: AmbType[B]) extends AmbType[(A, B)] {
  private var deleted: List[(A, B)] = List()
  override private[ambiguous] def list: List[(A, B)] =
    ambA.list.flatMap(a => ambB.list.map(b => (a, b))).diff(deleted)
  override private[ambiguous] def del(a: (A, B)): Unit = {
    deleted ::= a
    ambA.list.filter(a => !list.exists(_._1 == a)).foreach(a => {ambA.del(a); deleted = deleted.filterNot(_._1 == a)})
    ambB.list.filter(b => !list.exists(_._2 == b)).foreach(b => {ambB.del(b); deleted = deleted.filterNot(_._2 == b)})
  }
}

I don't want to say too much about the classes but one thing is worth mentioning: If you create pairs of two amb-values and define some conditions on top of them and afterwards define some further conditions on top of one of the original values, the pair-class misses to check if an element of the not-changed original value may be deleted as it doesn't appear as part of one pair any more. So some further observer-pattern would be great.

Now let's take a look on how to use this:

// create amb-values by invoking amb
val a = amb(1, 2, 3, 4)

// do some maths on a value
val b = op(a, (e: Int) => e + 2)

// define some conditions
require(b, (e: Int) => e%3 == 0)
// or first apply the condition to the value and afterwards pass the value to require
val filtered = op(b, (e: Int) => e%3 == 0)
require(filtered)

// pair values
val paired = pair(a, amb("hello", "welcome"))
// note that the amb-value a now only contains the elements 1 and 4 as the former requirement eliminated the other two

// state a condition on pairs
require(paired, (a: Int, b: String) => b.length % a == 0)
// now the amb-value a only contains the element 1 as there was no string with length divisible by 4

// query a value from our pairs (by calling get)
val selected = paired.get
// at this point only two pairs are left, so selected will always be either (1, "hello") or (1, "welcome")
val number = selected._1
val greetings = selected._2


Is the checkbox not not unchecked? Doing code review, I stumbled upon the following code, that tests the status of a checkbox:

if (!isNotUnchecked()) { ... }

I had to brainstorm for 30 minutes to find out what actual checkbox status the code was expecting. Please write me a program that can simplify these silly expressions!

The program should accept as input a string representing the expression to simplify (for example: !isNotUnchecked()). The program should output a logically equivalent simplified expression, either isChecked() or !isChecked().

The method name in the input expression always starts with is, contains 0..n Not, and ends with Checked() or Unchecked().
The method can be prefixed by any number of !.

Examples

isChecked() => isChecked()
isUnchecked() => !isChecked()
isNotChecked() => !isChecked()
!isNotChecked() => isChecked()
!!!isNotNotUnchecked() => isChecked()

Python, 51 bytes

lambda s:sum(map(s.count,'!NU'))%2*'!'+'isC'+s[-8:]

Try it online!


What's my question record? There's a confusing factor in the 'Curious' badge. The "Positive question record".

(total questions - negative questions - closed - deleted)/total questions is the formula of the question record. (negative, closed and deleted 'stack' with each other. that means if a question is negative and closed, it counts as two minus.)

Luckily, you know a list of your questions. Make a program that calculates your question record.

The Input

You will be given an array of question datas. A question data is made of 2 datas.

The votes (integer)
The state (o(open), c(closed), d(deleted), b (closed and deleted) is the default, You may change the type and the characters for each states.)

Examples

[[-1,'o'],[1,'o']] => 0.5 (2 total, 1 minus points)
[[-1,'d'],[2,'c']] => -0.5 (2 total, 3 minus points)
[[-1,'b']] => -2 (1 total, 3 minus points)
[[23,'o'],[7,'c'],[7,'c'],[-1,'o'],[-5,'b'],[-11,'d'],[-3,'d'],[-3,'b'],[-15,'b']] => -0.77778(The precision is 5 digits past decimal point, rounded half-up. fractions are acceptable) (Oh my, my question record is horrible.)
`
('Minus points' is the sum of negative, closed and deleted.)

Rules

Format of input is your choice. You don't necessarily need to use the format in the Examples.

Reference

dc, 8 bytes
I've been waiting to use dc's feature, that the input is both data and code, for quite some time.
0d?n47Pp

The idea behind the script is that all of the number crunching will be done by the question's state representation, a valid input string. The main script's task is then to initialize the counters, read the input (and execute it as code at the same time), and print the result when done, as a fraction.
Here are the strings I use to represent the state. The OP allows non-char types!

'o' -> "1r[1-]sX0>X0-+r1+r"
'c' -> "1r[1-]sX0>X1-+r1+r"
'd' -> "1r[1-]sX0>X1-+r1+rrr"

The extra "rr" part at the end changes nothing, it is there to differentiate the d state from c.

'b' -> "1r[1-]sX0>X2-+r1+r"

Try it online! The default input there is the last example.
Test run: from the 2nd example. Negative numbers in dc are given with _ as the minus sign. This is allowed by this meta consensus.
dc -f question_record.dc <<< "_1 1r[1-]sX0>X1-+r1+rrr 2 1r[1-]sX0>X1-+r1+r"
-1/2

Explanation of the script:
0d
# push 0 twice. The bottom cell will keep track of the number of questions, and the
#top cell of the sum part of the score.
?
# read input, which in this case is actually pairs of (data, code), that do all the
#number crunching
n47Pp
# print the 2 cells as a fraction: print top, print '/' (ASCII 47), print bottom

Explanation of the state's representation: I take the c state as example code
The stack at the start of this snippet is composed of the two bottom counters, plus the integer data (the votes) that was pushed on top before this. The snippet contains both the integer value of the state (minus points) and the dc code needed to apply it.
1r[1-]sX0>X1-+r1+r

I work with the following iterative algorithm (pseudo-code) to calculate the "positive question record":
result = 0
# main script: `0`
sum = 0
# main script: `d`
for each input question; do
# main script:`?`
    sum += 1
    # snippet: `1`
    sum -= v (0 if total votes are positive, 1 if negative)
    # snippet: `r[1-]sX0>X`
    sum -= minus_points (based on state)
    # snippet: `1-`, or `0-`, or `2-`
    result++
    # snippet: `r1+`
done
result = sum / result
# main script:`n47Pp`


Pyth, 11 - 50% = 5.5 bytes

L?+IbY_yMbb

Try it online: Demonstration or Test Suite.

This defines a function y. The additional 3 bytes <newline>yQ simply call the function with the input list and therefore doesn't need to be counted towards the bytes total.

Explanation:

L?+IbY_yMbb
L             define a function y(b), that returns:
 ?+IbY           if b + [] == b (test if b is a list):
      _yMb           recursively call y on all elements in b, then reverse the list
          b      else: b


Shortest Code to Legitimately Slack Off I'm a developer, and I don't feel like doing my work. I know from XKCD that the best excuse for slacking off is that your code's compiling. Because of this, I think I need some code that will compile forever! And because I'm lazy and don't want to have to type much, this has to be done with the shortest code possible.

So, your task is to write a program that is syntactically valid, but will cause the compiler to enter an infinite loop.

Specifications

You must use a language that has a compiler, obviously.
Specify the implementation used in each solution.
This is code-golf, so the shortest valid solution (in bytes) wins.
The compiler can terminate from running out of memory or stack space.

TikZ (pdfTeX 3.14159265-2.6-1.40.17), 85 79 74 24 22 21 bytes
A bunch of bytes saved thanks to wchargin
One byte saved thanks to Chris H
\input tikz
\tikz\pic

I actually encountered this one by accident when I was working on homework.  I spent quite a while waiting for it to compile before I realized what was happening.
This has two parts:
\input tikz

This loads the TikZ package
and:
\tikz\pic

This starts a \tikz environment and a draw command.
What is going on
The pdflatex compiler has trouble with \tikz\pic, and enters interactive mode causing it to stall indefinitely.


Tiling the unit square Background
By expanding and cancelling terms, it is easy to show the following identity:

However, it is an open problem whether all 1/n-by-1/(n+1) rectangles can tile the unit square.
The Task
Your program should take a positive integer N as input in any convenient manner, and pack all 1/n-by-1/(n+1) open rectangles with n between 1 and N inclusive into the unit square, such that no two overlap.
For each rectangle you must generate the following integers in order:

1 if the horizontal edges are longer than the vertical edges, else 0
The numerator and denominator of the x-coordinate of the bottom-left corner
The numerator and the denominator of the y-coordinate of the bottom-left corner

Note that we take the unit square to be (0, 1) x (0, 1), with x-values running from left to right, and y-values running from bottom to top.
The final expected output is the concatenation of these integers for each rectangle in order of increasing n, in any convenient format (e.g. printed to stdout, or as a list returned from a function).
Example Input and Output
Input:
3

Output:
0 0 1 0 1 1 1 2 0 1 1 1 2 1 3

This parses as the following:
0 (0/1, 0/1)  1 (1/2, 0/1)  1 (1/2, 1/3)

Scoring
This is a code-golf challenge, so the answer with the fewest bytes wins. However, your algorithm should also be reasonably efficient; it should be able to run for all N<=100 in a total of around 10 minutes.
Your solution must give valid solutions for all N<=100, but provably complete algorithms are also welcome even if they aren't the shortest.

Haskell, 263 262 bytes

import Data.Ratio;f m=let{(#)n z|n>m=[[]]|True=[a:y|(a,j)<-[((o,x,y),[c|c<-(u&w,h-v,x,g):(w-u,h&v,a,y):z,c/=b])|b@(w,h,x,y)<-z,(o,u,v)<-[(o,1%(n+1-o),1%(n+o))|o<-[0,1]],(a,g)<-[(x+u,y+v)|u<=w,v<=h],let(&)p q|w>h=p|True=q],y<-(n+1)#j]}in(1#[(1%1,1%1,0%1,0%1)])!!0

This follows the algorithm described in Paulhus 1997, An Algorithm for Packing Squares, doi:10.1006/jcta.1997.2836. The key observation in the paper, which is empirically if not theoretically verified, is that the region left over after placing a rectangle in a box can be split into two sub-boxes whose filling can then in turn be regarded as independent.

Rather than finding the smallest width sub-box to fit the next rectangle into, the code performs a search across all possible sub-boxes; in practice this does not make an appreciable slow down for n<100.

Output is in the form of a list of entries as tuples with the fraction marker % still included. The integers in the formatted output are in the desired order, but strictly speaking some post-processing would be required to produce the list of integers alone.

Sample run:

*Main> f 5
(0,0 % 1,0 % 1),(0,1 % 2,0 % 1),(0,1 % 2,1 % 2),(0,3 % 4,1 % 2),(1,1 % 2,5 % 6)

Edit: removed an errant space after a let.


Output an Animated Trigonometry Circle I want you to write a program that outputs a trigonometry circle like the one below. I also want you to animate this circle, having the sine line move along the circumference with the other lines move around it. The minimum number of unique frames is 5. Any lower and your entry will not be counted.

The lines you will need are:

Sine (Both)
Cosine (Both)
Secant
Cosecant
Tangent
Cotangent
OA (on diagram)

Edit: No longer a limit

This is a code golf challenge, but I want you to get your code to below my code which is written in BBC BASIC.

Note: I will remove this requirement if the challenge is too hard.

My code: BBC BASIC - 185 bytes, 232 characters (Thanks Steve)

a=0:REPEAT:CLS:a+=0.005:CIRCLE600,500,300:s=300*SIN(a)+500:c=300*COS(a)+600:sc=300*1/COS(a)+600:cs=300*1/SIN(a)+500:MOVE600,500:DRAWc,s:DRAWc,500:DRAW600,500:DRAWsc,500:DRAWc,s:MOVE600,500:DRAW600,cs:DRAWc,s:DRAW600,s:WAIT 1:UNTIL0

Mathematica, 142 bytes

Graphics[{Circle[],Line/@{{{c=Cos@t,0},{c,s=Sin@t},{0,s}},{{0,0},{1/c,0},{0,1/s},{0,0},{c,s}}},},PlotRange->{r={-2,2},r}]~Animate~{t,0.01,2Pi}

I'm plotting for angles between 0.01 and 2π which conveniently skips any angles where one of the lines would become actually infinite. You can make a GIF from it by replacing Animate with Table, adding a step width of 0.1 say and then using Export on the result:

So I got a bit bored and thought I'd give the full-blown thing a go (with all lines and colours). I omitted the labels, because they are really annoying to position and just clutter everything up.

Animate[
  c = Cos@t;
  s = Sin@t;
  h = Sign@c;
  v = Sign@s;
  i = .1 h;
  j = .1 v;
  Graphics[{
    Thick,
    Circle[],
    Line /@ {{{c, -s}, {0, 0}, {c, s}}, {{-i, 0}, {-i, j}, {0,
        j}}, {{-i + c, 0}, {-i + c, j}, {c, j}}, {{c - .1 s,
        s + .1 c}, {1.1 c - .1 s, 1.1 s + .1 c}, 1.1 {c, s}}},
    Circle[{0, 0}, 0.1, {t, Round[t, Pi]}],
    Blue,
    Line /@ {{{0, 0}, {c, 0}}, {{0, s}, {c, s}}},
    Red,
    Line /@ {{{0, 0}, {0, s}}, {{c, 0}, {c, s}}},
    Darker@Green,
    Line[{{c, 0}, {h, 0}}],
    Cyan,
    Line[{{0, s}, {0, v}}],
    Lighter@Lighter@Magenta,
    Line[{{h, 0}, {1/c, 0}}],
    Darker@Darker@Green,
    Line[{{0, v}, {0, 1/s}}],
    Orange,
    Line[{{0, 1/s}, {c, s}}],
    Lighter@Brown,
    Line[{{1/c, 0}, {c, s}}],
    Gray,
    Line[{{c, 0}, {c, -s}}],
    Lighter@Gray,
    Line[{{c, s}, {h, 0}}],
    Lighter@Pink,
    Line /@ {{{-.45 h, 0}, {-.55 h, 0}}, {{-.45 h, 1/s}, {-.55 h,
        1/s}}},
    Arrowheads[{-.05, .05}],
    Arrow[{{-.5 h, 0}, {-.5 h, 1/s}}],
    Darker@Cyan,
    Line /@ {{{0, -.45 v}, {0, -.55 v}}, {{1/c, -.45 v}, {1/
         c, -.55 v}}},
    Arrow[{{0, -.5 v}, {1/c, -.5 v}}],
    Dashed,
    Black,
    Line[{{c, s}, 1.3 {c, s}}],
    Lighter@Pink,
    Line /@ {{{0, 0}, {-.5 h, 0}}, {{0, 1/s}, {-.5 h, 1/s}}},
    Darker@Cyan,
    Line /@ {{{0, 0}, {0, -.5 v}}, {{1/c, 0}, {1/c, -.5 v}}}
    }, PlotRange -> {r = {-2, 2}, r}],
  {t, 0.01, 2 Pi}
  ];

Enjoy!

And because this is still a code-golf question I golfed this down as well, to see how short I could get it. Currently, 719 bytes:

Graphics[{Thick,Arrowheads@{-.05,.05},(z=Circle)[],(n=Line)/@{{p={c=Cos@t,s=Sin@t},o={0,0},{c,-s}},{-{i=.1(h=Sign@c),0},{-i,j=.1(v=Sign@s)},{0,j}},{{-i+c,0},{-i+c,j},{c,j}},{p+(q={-.1s,.1c}),1.1p+q,1.1p}},z[o,0.1,{t,Round[t,Pi]}],{e=Dashed,n[{p,1.3p}]},Blue,n/@{{o,a={c,0}},{b={0,s},p}},Red,n/@{{o,b},{a,p}},g=(d=Darker)@Green,n@{a,{h,0}},y=Cyan,n@{b,{0,v}},(l=Lighter)@l@Magenta,n@{{h,0},f={1/c,0}},d@g,n@{{0,v},u={0,1/s}},Orange,n@{u,p},l@Brown,n@{f,p},r=Gray,n@{a,{c,-s}},l@r,n@{p,{h,0}},l@Pink,n/@{q={{-.45h,0},{-.55h,0}},{u,u}+q},Arrow@{q={-.5h,0},u+q},{e,n/@{{o,q},{u,u+q}}},d@y,n/@{q={{0,-.45v},{0,-.55v}},{f,f}+q},Arrow@{q={0,-.5v},f+q},{e,n/@{{o,q},{f,f+q}}}},PlotRange->{r={-2,2},r}]~Animate~{t,0.01,2Pi,0.05}


A simple Knight's problem How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other?

A knight can move two squares horizontally and one square vertically, or two squares vertically and one square horizontally.

The knights have to be placed on different squares and the knights attack each other if one can reach the other in one move.

Input:

The first line contains the number of test cases T. Each of the next T lines contains two integers N and M, representing the dimensions of the board.

Output:

Output T lines, one for each test case, each containing the required answer for the corresponding test case.

Sample input:

3
2 2
2 3
4 5

Sample output:

12
26
312

Constraints

    1 <= T <= 10000
    1 <= N,M <= 100000
time limit 1 sec

Source Limit:

50000 Bytes

Winning criteria

Shortest code which runs with specified time limit decides the winner

i ll leave two days time for more users to try from today

GNU Octave, 55 56 58 78 87* 93 chars

a=t(:,1);b=t(:,2);-4*max(2*(g=a.*b)-3*(a+b)+4,0)+g.*--g

Octave doesn't take input from STDIN, so you've got to provide the input in the program:

t = [
    1 7;
    2 2;
    2 3;
    4 5;
    5000 6000
];                % test cases

a=t(:,1);b=t(:,2);-4*max(2*(g=a.*b)-3*(a+b)+4,0)+g.*--g

The logic is as follows:

nchoosek(n*m, 2) gives us the number of combinations of two positions we can have on a N*M board. We then multiply it by two since we have two different knights.

Then we work out how many 3*2 blocks fit in an N*M board. For each 3*2 block there are 4 different positions our knights can be attacking each other. So we multiply it by 4 and subtract it from the value we calculated above.

*thanks to a simplification of the nchoosek I shamelessly stole from Matt.

Edit

I've just tested this on my laptop to make sure it meets the time requirements.

It will compute 500,000 10,000,000 test cases in an average of 0.918787 0.231201 seconds


Longest non-repeating Game-of-Life sequence Given a positive integer N,
determine the starting pattern on a N x N-grid that yield
the longest non-repeating sequence under Game of Life-rules, and ends
with a fixed pattern (cycle of length 1), played on a torus.

The goal is not the shortest program, but the quickest.

Since the world is finite, you will eventually end up in a loop,
thus repeating an already visited state. If this loop has period 1, then the starting pattern is a valid candidate.

Output: Starting pattern and total number of unique states in the sequence (including starting pattern).

Now, the 1x1-torus is special, since a cell may be considered neighbouring to itself or not, but in practice, there is no problem, a single living cell will in either case just die (of overcrowding or loneliness).
Thus, input 1 yields a sequence of length 2, the sequence being one cell living, then forever dead.

The motivation for this question is that is an analogue of the busy beaver function, but definitely less complex, since we have a bound on memory. This will be a nice sequence to include on OEIS, as well.

For N=3, the sequence length is 3, any pattern on the left hand side reaches a completely black 3x3-square, and then dies. (All patterns that are part of 1-cycle removed).

C++ up to N=6

3x3 answer 3: 111 000 000
4x4 answer 10: 1110 0010 1100 0000
5x5 answer 52: 11010 10000 11011 10100 00000
6x6 answer 91: 100011 010100 110011 110100 101000 100000

This technique is centered around a fast next state function.  Each board is represented as a bitmask of N^2 bits, and bit-twiddly tricks are used to compute the next state for all cells at once.  next compiles down to about 200 100 assembly instructions for N <= 8.  Then we just do the standard try-all-states-until-they-repeat and pick the longest one.

Takes a few seconds up to 5x5, a few hours for 6x6.

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define N 6

typedef uint64_t board;

// board is N bits by N bits, with indexes like this (N=4):
//  0  1  2  3
//  4  5  6  7
//  8  9 10 11
// 12 13 14 15

#if N==3
#define LEFT_COL (1 + (1<<3) + (1<<6))
#define RIGHT_COL ((1<<2) + (1<<5) + (1<<8))
#define ALL 0x1ffULL
#elif N==4
#define LEFT_COL 0x1111ULL
#define RIGHT_COL 0x8888ULL
#define ALL 0xffffULL
#elif N==5
#define LEFT_COL (1ULL + (1<<5) + (1<<10) + (1<<15) + (1<<20))
#define RIGHT_COL ((1ULL<<4) + (1<<9) + (1<<14) + (1<<19) + (1<<24))
#define ALL 0x1ffffffULL
#elif N==6
#define LEFT_COL (1 + (1<<6) + (1<<12) + (1<<18) + (1<<24) + (1ULL<<30))
#define RIGHT_COL ((1<<5) + (1<<11) + (1<<17) + (1<<23) + (1<<29) + (1ULL<<35))
#define ALL 0xfffffffffULL
#else
#error "bad N"
#endif

static inline board north(board b) {
  return (b >> N) + (b << N*N-N);
}
static inline board south(board b) {
  return (b << N) + (b >> N*N-N);
}
static inline board west(board b) {
  return ((b & ~LEFT_COL) >> 1) + ((b & LEFT_COL) << N-1);
}
static inline board east(board b) {
  return ((b & ~RIGHT_COL) << 1) + ((b & RIGHT_COL) >> N-1);
}

board next(board b) {
  board n1 = north(b);
  board n2 = south(b);
  board n3 = west(b);
  board n4 = east(b);
  board n5 = north(n3);
  board n6 = north(n4);
  board n7 = south(n3);
  board n8 = south(n4);

  // add all the bits bitparallel-y to a 2-bit accumulator with overflow
  board a0 = 0;
  board a1 = 0;
  board overflow = 0;
#define ADD(x) overflow |= a0 & a1 & x; a1 ^= a0 & x; a0 ^= x;

  a0 = n1; // no carry yet
  a1 ^= a0 & n2; a0 ^= n2; // no overflow yet
  a1 ^= a0 & n3; a0 ^= n3; // no overflow yet
  ADD(n4);
  ADD(n5);
  ADD(n6);
  ADD(n7);
  ADD(n8);
  return (a1 & (b | a0)) & ~overflow & ALL;
}
void print(board b) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      printf("%d", (int)(b >> i*N+j & 1));
    }
    printf(" ");
  }
  if (b >> N*N) printf("*");
  printf("\n");
}

int main(int argc, char *argv[]) {
  // Somewhere in the starting pattern there are a 1 and 0 together.  Using translational
  // and rotational symmetry, we can put these in the first two bits.  So we need only consider
  // 1 mod 4 boards.

  board steps[10000];
  int maxsteps = -1;
  for (board b = 1; b < 1ULL << N*N; b += 4) {
    int nsteps = 0;
    board x = b;
    while (true) {
      int repeat = steps + nsteps - find(steps, steps + nsteps, x);
      if (repeat > 0) {
        if (repeat == 1 && nsteps > maxsteps) {
          printf("%d: ", nsteps);
          print(b);
          maxsteps = nsteps;
        }
        break;
      }
      steps[nsteps++] = x;
      x = next(x);
    }
  }
}


Identify the Conic Section Given 5 distinct points on a two-dimensional plane, determine the type of conic section formed by the points. The output shall be one of circle, hyperbola, ellipse, or parabola.
Rules

The points will be in general linear position, meaning that no three points are collinear, and thus the conic passing through them will be unique.
The coordinates of the 5 points will be decimal numbers between -10 and 10, inclusive.
The precision for the decimal/float values should be the precision of your language's native float/decimal type. If your language/data type is arbitrary-precision, you may use 12 digits after the decimal point as the maximum required precision, rounding toward zero (e.g. 1.0000000000005 == 1.000000000000).
Capitalization of the output does not matter.
Outputting ellipse when the conic section is actually a circle is not allowed. All circles are ellipses, but you must output the most specific one.

On floating point inaccuracies and precision:

I'm trying to make this as simple as possible, so that issues with floating point inaccuracies don't get in the way. The goal is, if the data type was "magical infinite precision value" instead of float/double, then everything would work perfectly. But, since "magical infinite precision value" doesn't exist, you write code that assumes that your values are infinite precision, and any issues that crop up as a result of floating point inaccuracies are features, not bugs.

Test Cases
(0, 0), (1, 5), (2, 3), (4, 8), (9, 2) => hyperbola
(1.2, 5.3), (4.1, 5.6), (9.1, 2.5), (0, 1), (4.2, 0) => ellipse
(5, 0), (4, 3), (3, 4), (0, 5), (0, -5) => circle
(1, 0), (0, 1), (2, 1), (3, 4), (4, 9) => parabola

JavaScript (ES6), 316 323 347

p=>[1,2,4].some(x=>(d=D(Q=[[x&1,x&2,x&4,0,0,0],...p.map(([x,y])=>[x*x,x*y,y*y,x,y,1])]))?[a,b,c]=Q.map((v,i)=>D(Q.map((r,j)=>(r=[...r],r[i]=x*!j,r)))/d):0,D=m=>m[1]?m[0].reduce((r,v,i)=>r+(i&1?-v:v)*D(m.slice(1).map(r=>r.filter((a,j)=>j-i))),0):m)&&(d=b*b-4*a*c)?d<0?!b&c==a?'Circle':'Ellipse':'Hyperbola':'Parabola'

Any language better suited for handling matrix and determinant should score better (APL, J, CJAM, Jelly)

References: General form of a conic, Five points determine a conic, System of linear equations, Determinant

In the cartesian plane, the general equation of a conic is

A*x*x + B*x*y + C*y*y + D*x + E*y + F = 0

having A or B or C not equal to 0 (otherwise it's a straight line)

A ... F are six unknowns to be found. With five pairs of (x,y) we can build a linear system with five equations, and scaling remove one dimension. That is, we can set one of A,B or C to 1 if it's not 0 (and we know that at least one is not 0).

I build and try to solve 3 systems: first trying A=1. If not solvable then B=1, then C. (There could be a better way, but that's my best at the time)

Having the values of A,B,C we can classify the conic looking at the discriminant d=B*B-4*A*C

d == 0 -> parabola
d > 0 -> hyperbola
d < 0 -> ellipse, particularly (A == C and B == 0) -> circle

Less golfed

F=p=>(
  // Recursive function to find determinant of a square matrix
  D=m=>m[1]
    ?m[0].reduce((r,v,i)=>r+(i&1?-v:v)*D(m.slice(1).map(r=>r.filter((a,j)=>j-i))),0)
    :m,
  // Try 3 linear systems, coefficients in Q
  // Five equation made from the paramaters in p
  // And a first equation with coefficient like k,0,0,0,0,0,1 (example for A)
  [1,2,4].some(
    x => (
      // matrix to calc the determinant, last coefficient is missing at this stage
      Q = [
        [x&1, x&2, x&4, 0,0,0] // first one is different
        // all other equations built from the params
        ,...p.map( ([x,y]) => [x*x, x*y, y*y, x, y, 1] )
      ],
      d = D(Q), // here d is the determinant
      d && ( // if solvable  then d != 0
        // add missing last coefficient to Q
        // must be != 0 for the first row, must be 0 for the other
        Q.map( r=> (r.push(x), x=0) ),
        // solve the system (Cramer's rule), I get all values for A...F but I just care of a,b,c
        [a,b,c] = Q.map((v,i)=>D(Q.map(r=>(r=[...r],r[i]=r.pop(),r))) / d),
        d = b*b - 4*a*c, // now reuse d for discriminant
        d = d<0 ? !b&c==a ? 'Circle' : 'Ellipse' // now reuse d for end result
        : d ? 'Hyperbola' : 'Parabola'
      ) // exit .some if not 0
    ), d // .some exit with true, the result is in d
  )
)

Test

F=p=>[1,2,4].some(x=>(d=D(Q=[[x&1,x&2,x&4,0,0,0],...p.map(([x,y])=>[x*x,x*y,y*y,x,y,1])]))?[a,b,c]=Q.map((v,i)=>D(Q.map((r,j)=>(r=[...r],r[i]=x*!j,r)))/d):0,D=m=>m[1]?m[0].reduce((r,v,i)=>r+(i&1?-v:v)*D(m.slice(1).map(r=>r.filter((a,j)=>j-i))),0):m)&&(d=b*b-4*a*c)?d<0?!b&c==a?'Circle':'Ellipse':'Hyperbola':'Parabola'

console.log=(...x)=>O.textContent+=x+'\n'

;[
 [[0, 0], [1, 5], [2, 3], [4, 8], [9, 2]]
,[[1.2, 5.3],[4.1, 5.6], [9.1, 2.5], [0, 1], [4.2, 0]]
,[[5, 0], [4, 3], [3, 4], [0, 5], [0, -5]]
,[[1, 0], [0, 1], [2, 1], [3, 4], [4, 9]]
].forEach(t=>console.log(t.join`|`+' => '+F(t)))


The Solar Eclipse Through a Pinhole Camera This challenge is a simple ASCII-art challenge inspired by the solar eclipse that happened on August 21, 2017. Given an input 0 <= n <= 4, output the corresponding stage of the eclipse described below:
n=0:
   *****
 **     **
*         *
*         *
**       **
  *******

n=1:
   *****
 **  *****
*   *******
*   *******
**   ******
  *******

n=2:
   *****
 *********
***********
***********
***********
  *******

n=3:
   *****
 *****  **
*******   *
*******   *
******   **
  *******

n=4:
   *****
 **     **
*         *
*         *
**       **
  *******

Rules

You can 0 or 1 index, state what you chose.
The chars used are space and *, you may use any printable char for * (other than space).
Trailing spaces are optional (you may or may not have them).
This is code-golf, lowest byte-count is the winner.


Fun with strings and numbers Here's a programming puzzle for you:

Given a list of pairs of strings and corresponding numbers, for example, [[A,37],[B,27],[C,21],[D,11],[E,10],[F,9],[G,3],[H,2]], output another list which will have just the strings in the following manner:

The total count of any string should be exactly equal to its corresponding number in the input data.
No string should be repeated adjacently in the sequence, and every string should appear in the output list.
The selection of the next string should be done randomly as long as they don't break above two rules. Each solution should have a non-zero probability of being chosen.
If no combination is possible, the output should be just 0.

The input list may be given in any order (sorted or unsorted), and the strings in the list may be of any length.

Sample output for the above sample input 1

[A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,C,A,C,A,C,A,C,A,C,A,C,A,C,A,C,A,C,A,C,D,C,D,C,D,C,D,C,D,C,D,C,D,C,D,C,D,C,D,C,D,C,E,F,E,F,E,F,E,F,E,F,E,F,E,F,E,F,E,F,E,G,H,G,H,G]

Input sample 2:

[[A,6],[B,1],[C,1]]

Output for second input:

0

since no list possible based on rules.

Sample input 3:

[[AC,3],[BD,2]]

valid output: [AC,BD,AC,BD,AC]

invalid output: [AC,BD,AC,AC,BD]

If further clarification is needed, please, do not hesitate to tell me in the comments and I will promptly act accordingly.

This is code-golf, so shortest code in bytes for each language wins!

Jelly, 11 bytes

Œṙ'Œ!⁻ƝẠ$ƇX

Try it online!

Œṙ'Œ!⁻ƝẠ$ƇX Arguments: z
  '         Flat: Apply link directly to x, ignoring its left and right depth properties
Œṙ            Run-length decode
   Œ!       Permutations of x
         Ƈ  Filter; keep elements of x for which the link returns a truthy result
        $     ≥2-link monadic chain
      Ɲ         Apply link on overlapping pairs (non-wrapping)
     ⁻            x != y
       Ạ        Check if all elements of x have a truthy value (+vacuous truth)
          X Pick a random element of x; return 0 if the list is empty.


The happy Ender problem The happy ending problem (actually a theorem) states that

  Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral.

The problem was so named by Paul Erdős when two mathematicians who first worked on the problem, Ester Klein and George Szekeres, became engaged and subsequently married.

Clarifications:

General position here means that no three points are collinear.
The quadrilateral formed by the four vertices will always be considered to be non-intersecting, irrespective of the order of the points. For example, given the four points [1 1], [1 2], [2 1], [2 2] the intended quadrilateral is the square, not the bow-tie:

A non-intersecting quadrilateral is convex if no interior angle exceeds 180 degrees; or equivalently if both diagonals lie inside the quadrilateral.

The challenge

Given 5 points with positive integer coordinates, output 4 of those points that form a convex quadrilateral.

Rules

If there are several solutions (that is, several sets of 4 points), you can consistently choose to output one of them or all.

Input and output formats are flexible as usual (arrays, lists, list of lists, strings with reasonable separators, etc).

Code golf, fewest bytes wins.

Test cases

Input:

[6 8] [1 10] [6 6] [5 9] [8 10]

There is only one possible output:

[6 8] [1 10] [6 6] [5 9]

Input:

[3 8] [7 5] [6 9] [7 8] [5 1]

There are five solutions:

[3 8] [7 5] [6 9] [7 8]
[3 8] [7 5] [6 9] [5 1]
[3 8] [7 5] [7 8] [5 1]
[3 8] [6 9] [7 8] [5 1]
[7 5] [6 9] [7 8] [5 1]

Input:

[4 8] [1 9] [9 9] [10 2] [1 6]

There are three solutions:

[4 8] [1 9] [10 2] [1 6]
[4 8] [9 9] [10 2] [1 6]
[1 9] [9 9] [10 2] [1 6]

To illustrate, here are the three solutions to this case:

CJam, 37 34 32 bytes

{e!Wf<{2*3ew{)f.-~W%.*:-V>},!}=}

Not sure if :-V is happy enough, but as K Zhang points out, there's the =} at the end. :)

This only prints one solution because removing duplicates would be more expensive.

Test it here.

Explanation

The idea is fairly simple. We generate all possible quadrilaterals (including all orderings of the points) and then just select the convex ones. We test convexity by looking at every pair of edges and checking that they're all turning in the same direction.

The turning sense can be obtained quite easily from a dot product. If you take the three consecutive points on a quadrilateral, and draw lines from the first to the second, and the first to the third, and then project the latter onto the perpendicular of the former... you get a number whose sign tells you whether these three points turn left or right. (I should probably add a diagram for this.) This "projecting onto the perpendicular" is sounds quite involved, but really just means that we reverse one of the two vectors and subtract the components after multiplication instead of adding them. So here's the code...

e!       e# Generate all permutations of the five input points.
Wf<      e# Discard the fifth point in each permutations, giving all
         e# possible quadrilaterals.
{        e# Select the first for which this block gives a truthy result...
  2*     e#   Double the list of points, so that it includes each cyclically
         e#   adjacent set of three points.
  3ew    e#   Get all sublists of length 3, i.e. all sets of three consecutive
         e#   points (with two duplicates).
  {      e#   Filter these sets of three points...
    )    e#     Pull off the last point.
    f.-  e#     Subtract it from the other two, giving vectors from it to
         e#     to those.
    ~    e#     Unwrap the array dumping both vectors on the stack.
    W%   e#     Reverse one of them.
    .*   e#     Element-wise multiplication.
    :-   e#     Subtract the second element from the first. This completes
         e#     the projection.
    V>   e#     Check whether it's greater than 0. This is *false* for right-
         e#     turning sets of three points.
  },     e#   If all corners are right-turning, this will result
         e#   in an empty array.
  !      e#   Logical NOT - hence, only quadrilaterals where all corners
         e#   are right-turning give something truthy.
}=


What are you waiting for? (A mahjong solver) Idea thanks to @MartinBüttner from a discussion in chat

Mahjong is a tile game that is immensely popular in Asia. It is typically played with four players, and the goal of the game is to be the first person to complete a valid hand using the tiles. For this challenge, we will consider a simplified version of the game — PPCG mahjong.

In PPCG mahjong, there are three suits – m, p and s – and the tiles are numbered from 1 to 9. There are exactly four copies of each tile, and the tiles are denoted by its number followed by its suit (e.g. 3m, 9s).

A completed PPCG mahjong hand consists of four sets of three and a pair, for a total of 14 tiles.

A set of three can be either:

Three of the same tile (e.g. 4s 4s 4s, but not 4m 4p 4s), or
A sequence of three consecutive tiles in the same suit (e.g. 1s 2s 3s or 6p 7p 8p but not 3s 4m 5m or 3p 5p 7p). Sequences do not wrap (so 9m 1m 2m is invalid).

A pair is simply two identical tiles (e.g. 5s 5s).

The challenge

Your program will receive a space-separated hand of 13 tiles, with each tile appearing no more than four times. You may write either a full program or a function which takes in a string.

Your task is to find all possible 14th tiles ("waits") which, when added to the hand, would form a completed PPCG mahjong hand. The outputted tiles should be space-separated, but can be in any order. Leading or trailing whitespace is allowed.

Your program should run in a reasonable amount of time, no longer than a minute.

Examples

Input: 1m 1m 1m 4s 4s 4s 7p 7p 7p 3m 3m 3m 9s
Output: 9s

Input: 1m 1m 1m 3m 3m 3m 5m 5m 5m 2s 3s 7p 8p
Output:

Input: 1m 2m 2m 3m 3m 3m 3m 4m 1s 1s 9s 9s 9s
Output: 1s

Input: 1m 1m 1m 2m 3m 4m 5m 6m 7m 8m 9m 9m 9m
Output: 1m 2m 3m 4m 5m 6m 7m 8m 9m

Input: 1m 1m 1m 5p 2m 3m 5p 7s 8s 5p 9s 9s 9s
Output: 1m 4m 6s 9s

In the first example, the 1m 4s 7p 3m all form existing triplets, leaving the lone 9s to form a pair.

In the second example, the 2s 3s and 7p 8p can only form sequences, and the remaining tiles can only form triplets. Hence no pair can be formed, and there is no output.

In the third example, the hand splits into 1m2m3m 2m3m4m 3m3m 1s1s 9s9s9s. Normally this would be a wait for 3m 1s, but as all four 3m have been used, the only available wait is 1s.

In the fourth example, all of the m tiles complete the hand. For example, for 1m, one could have 1m1m1m 1m2m3m 4m5m6m 7m8m9m 9m9m which is a completed hand.

Try to work out the rest of the fourth example and the fifth example :)

Scoring

This is code-golf, so the solution in the fewest bytes wins. Standard loopholes apply.

Python, 312 281 bytes

def W(S):H=lambda C,n=0,t=1:sum([m<C[0]and H([c-s for c in C][:l]+C[l:],n+1,u)for m,s,l,u in(2,3,1,t),(t,2,1,4),(4-5*all(C[:3]),1,3,t)])|H(C[1:],n,t)if C[2:]and max(C)<5else n>4;T=[i+s for s in"mps"for i in"12345678900"];return" ".join(t for t in T if("1"<t)*H(map((S+t).count,T)))

W takes a string as input and returns a string as output.

The small number of tiles (27) makes it fast enough to test if each of them completes the hand.
The problem becomes to check if a hand is valid.
The function uses a simple backtracking algorithm that considers all possible choices of sets and checks if any of them adds up to a complete hand.

Hands are represented as tile histograms, i.e. a list of tile counts (for all the tiles, not only the ones present in the hand.) This makes it easy to both check if we have a certain number of a certain tile, and if we have a sequence of adjacent tiles (padding between tiles of different suits prevent multi-suit sequences.)


Duct tape can fix Mother's Day Based on the Duct tape can fix anything question, that was too broad, with very similar rules. Only this time the objective is very specific:
The challenge
Your mission is to make a program that displays hello mom -- without ever writing a single line of code.
You can only use code which is already written for you, both in questions and answers from StackOverflow. All you can do is duct tape it all together the best you can. And of course, it's very important that we provide appropriate attribution so that we don't get our rights terminated.

Rules

You must include links to the questions/answers you used in your answer.

You may not modify the code you find, with the following exceptions:
a. You may rename variables, functions, and methods.  (This doesn't mean you can change a method invocation, by changing, say scanner.nextInt() to scanner.nextLine() and claiming that you're changing a method name.  The change must be in the definition or reference to the same entity.). The solution should still work if variables, functions or methods would be renamed again, so renaming code to contain hello mom as a variable name does not count.
b. You may adjust indentation appropriately.
c. You can assume that the proper modules are loaded for the code snippets to work.  (e.g., import statements for Java and Python, using statements for C# and C++, and their equivalents in all languages)  If the code snippet includes the imports for you, you can move them to the top of the code.
d. If the language requires the code to be in some kind of method body to execute (e.g., public static void main(String[] args) for Java, static int Main(string[] args) for C#, and so on), you can wrap your code in the appropriate method.  But the contents of that main method must remain unmodified.

You must supply an explicit list of any variable/method/function/class rename-ings performed.

You can't take snippets of snippets (meaning if you take a code block from a post, you take the whole thing)

Provide a brief description of what the code does for people who aren't intimate with the language you're using.

You must use snippets posted before this challenge was started.

Popularity contest, so the most upvotes wins!

Deadline
I will accept the the submission that has the most votes around the end of mothersday (midnight of the UTC-11 timezone), but later submissions can still get votes.

Brainfuck
Oh god why did I do this to myself?
It is actually possible to find each BF symbol by itself as a code snippet in some answer somewhere. The interesting bit was piecing together bits of other people's code, each representing a block of BF instructions. Unfortunately there are basically no unmatched [ and ] symbols out there, so I had to cheat a bit for those, and I had to get an awful lot of mileage out of a funky Haskell snippet which had a bunch of pluses in it. There are probably others out there. Beyond that, here's some Frankensteined code:
byte x = 1;
byte y = 2;
byte z = x + y;   // ERROR: Cannot implicitly convert type 'int' to 'byte'
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
[
int a = (b > 10) ? some_value
                 : another_value;
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
int a = (b > 10) ? c : d;
byte x = 1;
byte y = 2;
byte z = x + y;   // ERROR: Cannot implicitly convert type 'int' to 'byte'
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
?"<<-"
]
exec >{space}> (command)
byte z = (int) x + (int) y;
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
find . -type f -print -exec cat {} \;
git reset .
byte x = 1;
byte y = 2;
byte z = x + y;   // ERROR: Cannot implicitly convert type 'int' to 'byte'
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
System.out.print("B");
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
fatal: Failed to resolve 'HEAD' as a valid ref.
while read p; do
echo $p
done < $filename
static HMODULE hMod = NULL;
  static bool once = false;
  if (!once++)
    hMod = LoadLibrary("xxx");
 if (originalValue.length > size) {
static HMODULE hMod = NULL;
  static bool once = true;
  if (once--)
    hMod = LoadLibrary("xxx");
$ cd /usr/local/wherever
$ grep timmy accounts.txt
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}
ls -ld $(find .)
git commit --amend -m "New commit message"
wget -q -O - $line
git rebase --interactive $parent_of_flawed_commit
find . -type f -user 'user1' -maxdepth 1

And, since my mother is British, the output is quite simply hello mum
Bibliography:
https://stackoverflow.com/questions/17845014/what-does-the-regex-mean
[ and ], with apologies
https://stackoverflow.com/a/21460161/2581168
find . -type f -print -exec cat {} \;

https://stackoverflow.com/questions/6161328/what-exactly-does-this-do-exec-command
exec >{space}> (command)

https://stackoverflow.com/questions/20130538/what-is-in-haskell
addop = do {symb "+"; return Op Add}  +++ do {symb "-"; return Op Sub}

https://stackoverflow.com/questions/21947452/why-is-printing-b-dramatically-slower-than-printing
System.out.print("B");

https://stackoverflow.com/questions/941584/byte-byte-int-why
byte x = 1;
byte y = 2;
byte z = x + y;   // ERROR: Cannot implicitly convert type 'int' to 'byte'

https://stackoverflow.com/a/160295/2581168
int a = (b > 10) ? c : d;

And
int a = (b > 10) ? some_value
                 : another_value;

https://stackoverflow.com/questions/13273002/what-does-mean-in-r
?"<<-"

https://stackoverflow.com/questions/3450420/bool-operator-and
static HMODULE hMod = NULL;
static bool once = false;
if (!once++)
    hMod = LoadLibrary("xxx");

And
static HMODULE hMod = NULL;
static bool once = false;
if (!once--)
    hMod = LoadLibrary("xxx");

https://stackoverflow.com/questions/22776085/in-which-case-will-size-originalvalue-length-in-string-constructor-string
if (originalValue.length > size) {

https://stackoverflow.com/questions/3797795/does-mean-stdout-in-bash
wget -q -O - $line

https://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git/179147#179147
git commit --amend -m "New commit message"

And
git rebase --interactive $parent_of_flawed_commit

https://stackoverflow.com/questions/14763413/grep-ls-output-across-tabs/14763499#14763499
find . -type f -user 'user1' -maxdepth 1

https://stackoverflow.com/questions/945288/saving-current-directory-to-bash-history
$ cd /usr/local/wherever
$ grep timmy accounts.txt

https://stackoverflow.com/questions/348170/undo-git-add-before-commit/682343#682343
fatal: Failed to resolve 'HEAD' as a valid ref.