Adding Numbers with Regex I want to try a new type of regex golf challenge, which asks you to solve nontrivial computational tasks with nothing but regex substitution. To make this more possible and less of a chore, you will be allowed to apply several substitutions, one after the other.

The Challenge

We'll start simple: given a string containing two positive integers, as decimal numbers separated by a ,, produce a string containing their sum, also as as a decimal number. So, very simply

47,987

should turn into

1034

Your answer should work for arbitrary positive integers.

The Format

Every answer should be a sequence of substitution steps, each step consisting of a regex and a replacement string. Optionally, for each of those steps in the sequence, you may choose to repeat the substitution until the string stops changing. Here is an example submission (which does not solve the above problem):

Regex    Modifiers   Replacement   Repeat?
\b(\d)   g           |$1           No
|\d      <none>      1|            Yes
\D       g           <empty>       No

Given the input 123,456, this submission would process the input as follows: the first substitution is applied once and yields:

|123,|456

Now the second substitution is applied in a loop until the string stops changing:

1|23,|456
11|3,|456
111|,|456
111|,1|56
111|,11|6
111|,111|

And lastly, the third substitution is applied once:

111111

Note that the termination criterion for loops is whether the string changes, not whether the regex found a match. (That is, it might also terminate if you find a match but the replacement is identical to the match.)

Scoring

Your primary score will be the number of substitution steps in your submission. Every repeated substitution will count for 10 steps. So the above example would score 1 + 10 + 1 = 12.

In the (not too unlikely) case of a tie, the secondary score is the sum of the sizes of all steps. For each step add the regex (without delimiters), the modifiers and the substitution string. For the above example this would be (6 + 1 + 3) + (3 + 0 + 2) + (2 + 1 + 0) = 18.

Miscellaneous Rules

You may use any regex flavour (which you should indicate), but all steps must use the same flavour. Furthermore, you must not use any features of the flavour's host language, like replacement callbacks or Perl's e modifier, which evaluates Perl code. All manipulation must happen exclusively through regex substitution.

Note that it depends on your flavour and modifiers whether each single replacement replaces all occurrences or only a single one. E.g. if you choose the ECMAScript flavour, a single step will by default only replace one occurrence, unless you use the g modifier. On the other hand, if you're using the .NET flavour, each step will always replace all occurrences.

For languages which have different substitution methods for single and global replacement (e.g. Ruby's sub vs. gsub), assume that single replacement is the default and treat global replacement like a g modifier.

Testing

If your chosen flavour is either .NET or ECMAScript, you can use Retina to test your submission (I'm being told, it works on Mono, too). For other flavours, you will probably have to write a small program in the host language which applies the substitutions in order. If you do, please include this test program in your answer.

.NET flavor, score:2
Regex        Modifiers  Replacement  Repeat?
<empty>      <none>     9876543210   No
<see below>  x          <empty>      No

I'm not bothered to golf it yet, and x is just for ignoring whitespaces.
It firstly insert 9876543210 at each position, then delete the original characters and the characters those are not the current digit of the sum.
The big regex (1346 bytes without whitespaces and comments):
# If the length of the left number <= right number, delete every digit on the left.
.(?=.*,(?<=^(?<len>.)*,)(?<-len>.)*(?(len)(?!)))|

# Do the opposite if it is not the case.
.(?<=(?(len)(?!))(?<-len>.)*(?=(?<len>.)*$),.*)|

# Remove leading zeros.
(?<=(^|,).{9})0|

# Delete everything that is not the current digit of the sum.
.(?!
    # For digits in the left part:
    (?<cur>.){0,9}               # cur = the matched digit
    (?=(.{11})*,)                # and find the position before the next digit.
    (?<first>)                   # first = true
    (                            # Loop on the less significant digits:
        (?<cur>){10}             # cur += 10
        (?<=                     # cur -= the current digit in this number.
            (
                0|^|
                1(?<-cur>)|
                2(?<-cur>){2}|
                3(?<-cur>){3}|
                4(?<-cur>){4}|
                5(?<-cur>){5}|
                6(?<-cur>){6}|
                7(?<-cur>){7}|
                8(?<-cur>){8}|
                9(?<-cur>){9}
            )
            .{10}
        )
        (?=
            (?<pos>.{11})*,      # pos = which digit it is.
            .*$(?<=              # cur -= the current digit in the other number.
                (
                    0|,|
                    1(?<-cur>)|
                    2(?<-cur>){2}|
                    3(?<-cur>){3}|
                    4(?<-cur>){4}|
                    5(?<-cur>){5}|
                    6(?<-cur>){6}|
                    7(?<-cur>){7}|
                    8(?<-cur>){8}|
                    9(?<-cur>){9}
                )
                .{10}
                (?(pos)(?!))     # Assert pos = 0.
                                 # Skip pos input digits from the end.
                                 # But stop and set pos = 0 if the comma is encountered.
                ((?<-pos>\d{11})|(?<=(?>(?<-pos>.)*),.{10}))*
            )
        )
        (?(first)                # If first:
            (?>((?<-cur>){10})?) #  cur -= 10 in case there is no carry.
                                 #  Assert cur = 0 or 1, and if cur = 1, set cur = 10 as carry.
            (?(cur)(?<-cur>)(?(cur)(?!))(?<cur>){10})
            (?<-first>)          #  first = false
        |                        # Else:
                                 #  cur is 10 or 20 at the beginning of an iteration.
                                 #  It must be 1 to 11 to make the equation satisfiable.
            (?<-cur>)            #  cur -= 1
            (?(cur)              #  If cur > 0:
                                 #   cur -= max(cur, 9)
                (?(cur)(?<-cur>)){9}
                (?(cur)          #   If cur > 0:
                                 #    Assert cur = 1 (was 11) and set cur = 10.
                    (?<-cur>)(?(cur)(?!))(?<cur>){10}
                |                #   Else:
                    .*(?=,)      #    cur was 2 to 10, break from the loop.
                )
            )                    #  Else cur is 0 (was 1) and do nothing.
        )
        (.{11}|,)                # Jump to the next digit.
    )*(?<=,)(?(cur)(?!))         # End the loop if it is the last digit, and assert cur = 0.
|
    # Do the same to the right part. So the sum will be calculated two times.
    # Both are truncated to the original length of the number on that side + 1.
    # Only the sum on the longer side will be preserved in the result.
    (?<cur>\d){0,9}
    (?=(\d{11})*$)
    (?<first>)
    (
        (?<cur>){10}
        (?<=
            (
                0|,|
                1(?<-cur>)|
                2(?<-cur>){2}|
                3(?<-cur>){3}|
                4(?<-cur>){4}|
                5(?<-cur>){5}|
                6(?<-cur>){6}|
                7(?<-cur>){7}|
                8(?<-cur>){8}|
                9(?<-cur>){9}
            )
            .{10}
        )
        (?=
            (?<pos>.{11})*$
            (?<=
                (
                    0|^|
                    1(?<-cur>)|
                    2(?<-cur>){2}|
                    3(?<-cur>){3}|
                    4(?<-cur>){4}|
                    5(?<-cur>){5}|
                    6(?<-cur>){6}|
                    7(?<-cur>){7}|
                    8(?<-cur>){8}|
                    9(?<-cur>){9}
                )
                .{10}
                (?(pos)(?!))
                ((?<-pos>\d{11})|(?<=^.{10})(?=(?>(?<-pos>.)*)))*
                ,.*
            )
        )
        (?(first)
            (?>((?<-cur>){10})?)
            (?(cur)(?<-cur>)(?(cur)(?!))(?<cur>){10})
            (?<-first>)
        |
            (?<-cur>)
            (?(cur)
                (?(cur)(?<-cur>)){9}
                (?(cur)
                    (?<-cur>)(?(cur)(?!))(?<cur>){10}
                |
                    .*$(?<end>)
                )
            )
        )
        (.{11}|$(?<end>))
    )*(?<-end>)(?(cur)(?!))
)

This made me think of the final level of Manufactoria... But I think .NET regex, which is obviously no longer "regular", can solve any problems in PH. And this is just an algorithm in L.


Tips for golfing in Postscript? As one of the less popular languages, it's difficult to find literature on the avant garde of postscript hackery. So what discoveries have the golfers here made to exploit the stack model (or other features) to overcome Postscript's inherent verbosity?

Embedded Decoder

A Postscript program has a unique(?) ability to read it's own program text as data. This is normally used by the image operator which receives a data-acquisition-procedure as input, and this procedure often uses currentfile followed by readline, readstring, or readhexstring. But seen another way, image is just another looping operator, so any loop can read-ahead. An example is the line-printer emulator from the Green Book.

Using the token operator invokes the scanner on a file or string, pulling off a number or space- (or otherwise-: see other answer) -delimited name.

A simple PS interpreter in PS:

{currentfile token not {exit} if dup type /arraytype ne {exec} if }loop

Binary Operator String Decoder

Since I can't seem to get raw binary tokens to work for me (see other answer), I've made use of the "embedded decoding" idea to exploit the binary token mechanism to pack code into 8-bit strings, and then manipulate and parse the commands from the string on the fly.

/.{
    <920>  % two-byte binary-encoded name template with 0x92 prefix
    dup 1 4 3 roll put  % insert number into string
    cvx exec  % and execute it
}def
/${
    //.   %the /. procedure body defined above
    73 .  %"forall" (by code number)
}def

The . procedure takes a number from the stack and inserts it as the second byte in a two-byte string, the first byte being the prefix-byte for a binary token, specifying an executable system name. We save a byte in the hexstring by using a rule of the scanner that an odd number of nibbles in the hexstring is padded with an extra 0 nibble, so 3 hex nibbles produces a 2-byte string. The string is then marked executable and called with exec which invokes the scanner, produces the desired executable system name, and then loads the name and executes the operator. The $ does this on each byte of a string on the stack, using the . procedure twice, once as the loop body, and then to execute the looping operator forall by number.

More compactly, these procedures look like this:

 /.{<920>dup 1 4 3 roll put cvx exec}def/${//. 73 .}def
%123457890123456789012345678901234567890123456789012345
%        1         2         3         4         5

So, 55 chars buys binary token strings. Or, for 6 (maybe 7, if you terminate it with a space) chars, you can load the G library with (G)run which defines . and $ as above (+ a few others to extend the range of ascii-reachable codes).

Further illustrated in my crossword puzzle answer.


The Squaring Sequence Each term in the squaring sequence, \$x_n\$, is created by taking \$x_{n-1}\$, squaring it, and removing all but the first four digits.
The sequence always begins with \$x_1 = 1111\$. Squaring this yields \$1234321\$, so \$x_2 = 1234\$
The first few terms are:
1111
1234
1522
2316
5363
...

The Challenge
Your task is to, given a non-negative integer \$n\$, calculate \$x_n\$. You may submit a full program which performs I/O, or a function which takes \$n\$ as a parameter.
Your solution can be zero or one indexed, as long as you specify which.
Because all the terms in this sequence are shorter than 5 digits, your code should be as short as possible too. Standard code-golf loopholes apply.
May the best golfer win!

Test Cases
Note: These are 1-indexed.
1   -> 1111
8   -> 6840
15  -> 7584
20  -> 1425
80  -> 4717

JavaScript (ES7), 44 43 36 bytes

f=n=>--n?(f(n)**2+f).slice(0,4):1111

This is a great example of abusing type coercion: ** converts both its arguments to numbers, and + converts both its arguments to strings unless they're both numbers. This means that f(n)**2+f first converts f(n) to a number and squares it, then concatenates the result with the string representation of f. We can then use .slice to retrieve the first 4 chars of the string.

Here are a few alternate approaches that don't use strings:

f=(n,x=1111)=>x<1e4?--n?f(n,x*x):x:f(n,x/10|0)
f=n=>--n?(x=f(n))*x/(x>3162?1e4:1e3)|0:1111

Test snippet

let f=n=>--n?(Math.pow(f(n),2)+f).slice(0,4):1111
<input id=I type="number" step="1" min="1" value="1"><button onclick="console.log(f(I.value))">Run</button>

Note: this uses Math.pow because ** isn't supported in all browsers.


Build a multiplying machine using NAND logic gates Based on my previous question of the same type, Build an adding machine using NAND logic gates, this time you're being asked to multiply instead of add.

Build a diagram of (two-wire) NAND logic gates that will take the input wires A1, A2, A4, B1, B2, B4, representing two binary numbers A to B from 0 to 7, and return values on the output wires C1, C2, C4, C8, C16, and C32, representing C, which is the product of A and B.

Your score is determined by the number of NAND gates you use (1 point per gate). To simplify things, you may use AND, OR, NOT, and XOR gates in your diagram, with the following corresponding scores:

NOT: 1
AND: 2
OR: 3
XOR: 4

Each of these scores corresponds to the number of NAND gates that it takes to construct the corresponding gate.

Lowest score wins.

60 55 50 48 gates

The original (60 gates) was the systematic approach - multiply each digit with each, and then sum them together. Namely, see Wallace trees and Dadda trees

The top half is the multiplication network - multiply each digit with each, and group output digits with the same weight. Some bits have been left inverted to save gates.

The second half is the adder network. Each box represents a single adder - either a half-adder (5 gates - 1x XOR and an inverter), or a full adder (9 gates - 2x XOR and NAND the inverted carry bits). The top are inputs, the bottom output is the sum, the left output is the carry-out.  see the previous challenge

The 2x2 multiplier has then been hand-optimised to a custom-built 13-gate network, which is the optimal size as found by @boothby. Thanks!

Pasting it into the low-bit corner and reoptimising the adder tree saves five gates (see revision #2). Pasting it into the high-bit corner as well, however, produces overlap. A little bit of math tells us, however, that dropping the low-bit of the high multiplier solves the overlap and what's left to do is to add the remaining two bits and sum up stuff.

This alone, unfortunately, does not provide any savings, but it does open two optimisations. First, the two multipliers have two gates in common, and can be fused together. At this point, we're back at 55. Second, in the addition network, we don't need a half-adder because we know its carry will be zero. We can replace it with an OR. An OR is a NAND with its inputs inverted. This produces us with two 2-chains of NOTs on each branch, which can then be removed, for a total saving of five gates. Unfortunately, the half-adder at C16 still carries, so we cannot do the same there. Third, a full adder has a useful property: if you invert its inputs and its outputs, it still behaves the same. Since all its inputs are already inverted, we can just as well move the inverters behind it. Twice. We could have done the same in the original, but... oh well. We still have a half-adder with two inverted inputs. I want optimise this part more, but I doubt I can.

Since we're pulling out a NOT from inside a component, we have to signify that somehow. We have obtained a half-adder with inverted carry (AKA tapped XOR) at a cost of four gates.

In the meantime, we have also redrawn the diagram significantly.


Convert a TIO answer to a CMC answer Let's for once do something useful.
Given the text from a Try It Online codegolf submission, produce the equivalent Chat Mini Challenge submission, which is of the form
Language, N bytes: [`code`](URL)

or (if submission is a single byte – TIO will add a trailing s on the first line only if needed)
Language, 1 byte: [`code`](URL)

You may assume that the submission

has only one line
does not contain backticks (`)
has no leading whitespace
has a regular format like in the examples below; the code line is indented with four spaces (    ), not with HTML tags (
…
), i.e. no trailing whitespace.

Note that the submission may have a syntax highlighting tag. See last example.
You may optionally include the title text, i.e. …url "Language - Try It Online".
Examples
Given
# [05AB1E], 1 byte

    Ô

[Try it online!][TIO-j3v72bss]

[05AB1E]: https://github.com/Adriandmen/05AB1E
[TIO-j3v72bss]: https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online"

return
05AB1E, 1 byte: [`Ô`](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA)

or
05AB1E, 1 byte: [`Ô`](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online")

Given
# [Brachylog], 4 bytes

    ḅhᵐc

[Try it online!][TIO-j3v75978]

[Brachylog]: https://github.com/JCumin/Brachylog
[TIO-j3v75978]: https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA "Brachylog – Try It Online"

return
Brachylog, 4 bytes: [`ḅhᵐc`](https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA)

Given
# [APL (Dyalog Unicode)], 15 bytes

    ⍴⍨¨⍳

[Try it online!][TIO-j44jgrps]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-j44jgrps]: https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ "APL (Dyalog Unicode) – Try It Online"

return
APL (Dyalog Unicode), 15 bytes: [`⍴⍨¨⍳`](https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ)

V, 37, 35 bytes

ç^</dj
H3xf]x3Ji[`A`]Jd2/:
xr(A)

Try it online!


Include a JavaScript script with JavaScript To dynamically include a JavaScript file in a web page, you'd normally insert a <script> tag pointing to your script. For example:

var js_file= document.createElement("script");
js_file.src='http://example.com/js.js';
document.body.appendChild(js_file);

Write JavaScript code will load an external JavaScript file in the current page and:

Shortest valid answer wins
The file is hosted on https://pastebin.com/raw/rV6dDDj9 (content is console.log('Good job!');)
The code must be vanilla JavaScript (no jQuery, etc.)
Answer validity test is done in the web browser console. Criteria:

URL requested and JS file downloaded.
Console prints Good job!

49 bytes

document.write`<script src=//v.ht/KvtI></script>`

no one clearly said: you should keep current page content


Sum of squares on GPU Write a program or function that:

Takes as input a list or array of 128 numbers.
Sends that array to a GPU
Performs a calculation on the GPU to square each element of the array and then sum them
Gets the answer from the GPU, and returns or displays it

So your program will simply return the sum of the squares of its input array, but it will perform the calculation on a GPU.

The input numbers should be sent to the GPU in the form of signed or unsigned integer types or floats, of 32 or more bits in size.

You may make any assumptions you like about hardware, e.g. you may assume a CUDA or OpenCl capable card is present without checking for it.

This is code-golf. The smallest code (in bytes) will be considered the winner for each language.

APL (Dyalog Unicode) with Co-dfns, 7 bytesSBCS

Anonymous prefix lambda. I have verified with the author of Co-dfns that the code will indeed run according to the required spec.

{+.×⍨⍵}

Try it online! (equivalent code, but TIO doesn't provide GPU access)

{…} compilable dfn; ⍵ is the argument vector

 +.× dot-product of

 ⍨ itself ("selfie")

 ⍵ using the argument as data


First sequence with no square differences Consider the sequence \$(a_n)\$ defined in the following way.

\$a_0=0\$
For all \$n=1, 2, 3, \dots\$, define \$a_n\$ to be the smallest positive integer such that \$a_n-a_i\$ is not a square number, for any \$0\leq i<n\$

In other words, this is the lexicographically first sequence where no two terms differ by a square. It is proven that this sequence is infinite, and it is A030193 in the OEIS. The sequence begins
0, 2, 5, 7, 10, 12, 15, 17, 20, 22, 34, 39, 44, 52, 57, 62, 65, 67, 72, 85, 95, 109, 119, 124, 127, 130, 132, 137, 142, 147, 150, 170, 177, 180, 182, 187, 192, 197, 204, 210, 215, 238, 243, 249, 255, 257, 260, 262, 267,...
Challenge
The challenge is to write a program or function which does one of these:

Takes a nonnegative integer n and returns or prints the n-th term of this sequence. Either 1-indexed or 0-indexed is acceptable.

Takes a positive integer n and returns or prints the first n terms of this sequence

Takes no input and returns or prints all terms of the sequence with an infinite loop or infinite list

Any reasonable form of input and output is allowed.
Example (0-indexed)
Input -> Output
0     -> 0
10    -> 34
40    -> 215

Rules

Standard loopholes forbidden.

Code golf: shortest program in bytes for each language wins.

Ruby, 72 62 57 50 47 bytes

0.step{|x|$*<<p(x)if$*.all?{|i|(x-i)**0.5%1>0}}

Try it online!
Prints all terms of the sequence indefinitely.
7 bytes saved by Dingus and further 3 by Sisyphus.
Ruby 2.7+, 45 bytes

0.step{|x|$*<<p(x)if$*.all?{(x-_1)**0.5%1>0}}


Inverse CIDR whitelist The task

The task is to write a program that turns a list of IPv6 addresses into a shortest possible list of CIDR masks, such that everything but those IPs is matched.

CIDR masks

A CIDR mask matches IPs by a prefix. ::/19 matches all IPs whose first 19 bits are zero, i.e. 0:0000-1fff:*:*:*:*:*:*. Similarly, 55aa::/16 matches all IPs that start with 0101010110101010 bit sequence, i.e. 55aa:*:*:*:*:*:*:*.
A /128 always matches only one IP. A /0 matches all IPs.

Input

Input is a list of IP addresses in full form: eight 4-digit hexadecimal groups separated by : in network order (most significant first). For example, 0000:0000:0000:0000:0000:0000:0000:0000.
You're free to choose any separation character for the input list, might it be newline, space, comma, \0, etc. You can also rely on a-f being in a particular case.

Output

Output is the shortest list of CIDR masks that cover all IP addresses except those listed in input.
Again you're free to choose any separation character.
The CIDR should be formatted as any representation of an IP followed by / and amount of bits in the prefix (in decimal). For example, 0243:F6A8:885A:308D:3131:98A2:0000:0000/112.
You are not required to shorten the IP at all, as in above example. However 243:f6a8:885a:308d:3131:98a2::/112 is not invalid.
The order of masks doesn't matter. If there are multiple representations using equal amount of masks - either will suffice.

Examples

I'm not posting complete outputs, since coming up with an algorithm is a part of the task :)
Instead I'm specifying how much masks does it take, according to my own calculations. If you find a mistake, or a shorter masklist, please report.

>>> 0000:0000:0000:0000:0000:0000:0000:0000
 [128 masks]
>>> 0000:0000:0000:0000:0000:0000:0000:0000 0000:0000:0000:0000:0000:0000:0000:0001
 [127 masks]
>>> ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 0000:0000:0000:0000:0000:0000:0000:0000
 [254 masks]
>>> 0000:0000:0000:0000:0000:0000:0000:ffff 0000:0000:0000:0000:0000:0000:0000:0000
 [142 masks]
>>> 0123:4567:89ab:cdef:fedc:ba98:7654:3210 0246:8ace:1357:9bdf:0246:8ace:1357:9bdf
 [248 masks]
>>> 0000:0000:0000:0000:0000:0000:0000:0000 0000:0000:0001:0000:0000:0000:0000:0000 0000:0000:0002:0000:0000:0000:0000:0000 0000:0000:0003:0000:0000:0000:0000:0000 0000:0000:0004:0000:0000:0000:0000:0000 < snip > 0000:0000:00ff:0000:0000:0000:0000:0000
 (256 IPs)
 [20520 masks]
>>> 0000:0000:0000:0000:0000:0000:0000:0000 0000:0000:0000:0000:0000:0000:0000:0001 0000:0000:0000:0000:0000:0000:0000:0002 0000:0000:0000:0000:0000:0000:0000:0003 0000:0000:0000:0000:0000:0000:0000:0004 < snip > 0000:0000:0000:0000:0000:0000:0000:0fff
 (4096 IPs)
 [116 masks]

Scoring

Amount of characters in the code, UTF-8 characters are counted as one, if you must.

Bonus points

-16  Cover the case of empty input list.
-32  Output shortened IPs: strip leading zeros, replace sequential zero groups with ::, etc. See this Wikipedia article.

-32 Do not use the v4-in-v6 form (dead::beef:1.2.3.4).

-64  Permit shortened IPs in input.

GolfScript, 120 (136 characters - 16 bonus)
n%{':'-{48^71%}%16base}%-1+2.7??:W+${\)1$1$-{}{129,-1%{2\?.2$)<3$@%!&}?:~2$W+16base(;{.48+\9>39*+}%4/':'*'/'+128@-+puts\2~?+\2~?-}/;;}*;

Assumes the addresses as separate lines on STDIN. A considerable amount of the code is actually used to input/output in the correct format. The algorithm itself is quite simple and described here.


A Program that Prints Programs Challenge

Your goal is to write a program that prints another program.
That printed program should print another program, and the new program should print another program, until the end.

Rules

Each program must less than 256 bytes. (If this needs to be changed, leave a comment)
The last program must be an empty program.
There must be a finite number of programs, so the program cannot be a quine.
The programs must all run in the same language.
No input is allowed.
The winning program is the program that prints as many programs as possible, counting itself.

Good Luck!

CJam, 4.56 × 10526 programs

2D#2b{"\256b_(256b:c'\s`_:(er`":T~{;38'ÿ*`{:T~{;63'ÿ*`{:T~{;88'ÿ*`{:T~{;114'ÿ*`{:T~{;140'ÿ*`{:T~{;166'ÿ*`{:T~{;192'ÿ*`{:T~{;219'ÿ*`{Q?\"_~"}s(\T}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}s(\T`}?\"_~"}_~

Exact score: 254219 + 254192 + 254166 + 254140 + 254114 + 25488 + 25463 + 25438 + 25413 + 3

All programs have to be saved using the ISO-8859-1 encoding to comply with the file size limit.

Thanks to @ChrisDrost who pointed out a bug and suggested the nesting approach.

Try it online in the CJam interpreter.

254219 + 2 ≈ 4.56 × 10526 programs

The line share of the score can be achieved by the following, much simpler program1.

"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"
{\256b_(256b:c'\s`_:(er`Q?\"_~"}_~

Running this program produces the program

"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþ"
{\256b_(256b:c'\s`_:(er`Q?\"_~"}_~

and after 254219 - 1 more iterations, the program

{\256b_(256b:c'\s`_:(er`Q?\"_~"}_~

This last non-empty program exits with an error2 and prints nothing (the empty program).

How it works

Assume the string is already on the stack.

{      e# Push a code block.
  \    e# Swap the string on top of the code block.
       e# This will cause a runtime error if there is no string on the stack.
  256b e# Convert the string (treated as a base-256 number) to integer (I).
  _(   e# Copy the integer and decrement the copy.
  256b e# Convert the integer into the array of its base-256 digits.
  :c   e# Cast each base-256 digit to character. Converts from array to string.
  '\s  e# Push a string that contains a single backslash.
  `    e# Push its string representation, i.e., the array ['" '\ '\ '"].
  _:(  e# Push a copy and decrement each character. Pushes ['! '[ '[ '!].
  er   e# Perform transliteration to replace "s with !s and \s with [s.
       e# This skips characters that require escaping.
  `    e# Push its string representation, i.e., surround it with double quotes.
  Q    e# Push an empty string.
  ?    e# Select the first string if I is non-zero, the empty string otherwise.
  \    e# Swap the selected string with the code block.
  "_~" e# Push that string on the stack.
}      e#
_~     e# Push a copy of the code block and execute it.
       e# The stack now contains the modified string, the original code block
       e# and the string "_~", producing an almost exact copy of the source.

254192 ≈ 5.35 × 10461 more programs

This is where things get a little crazy.

The first program is highly compressible. By writing a similar program that, instead of the empty program, eventually produces the first program from the above section, we can improve the score by 254192 programs3.

The program

"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"
{"\256b_(256b:c'\s`_:(er`":T~{;219'ÿ*`{Q?\"_~"}s(\T}?\"_~"}_~

is similar to the first program of the previous section, and running the former and its output for 254192 iterations produces the latter.

Assume the string is already on the stack:

{                           e# Push a code block.
  "\256b_(256b:c'\s`_:(er`" e# Push that string on the stack.
                            e# The characters inside it behave exactly as
                            e# they did in the previous section.
  :T~                       e# Save the string in T and evaluate it.
  {                         e# If the integer I is non-zero, keep the generated
                            e# string; else:
    ;                       e#   Pop the code block from the stack.
    219'ÿ*`                 e#   Push a string of 219 ÿ's (with double quotes).
    {Q?\"_~"}               e#   Push that block on the stack.
    s                       e#   Push its string representation.
    (\                      e#   Shift out the { and swap it with the tail.
    T                       e#   Push T.
  }?                        e#
  \                         e# Swap the selected string with the code block
                            e# or T with the tail of the code block.
  "_~"                      e# Push that string on the stack.
}                           e#
_~                          e# Push a copy of the code block and execute it.

Moar programs

The first program of the previous section is still highly compressible, so we can apply a similar method and write a program that, after 254166 iterations, produces the aforementioned program.

Repeating this technique over and over again until we hit the 255 byte limit, we can add a total of 254166 + 254140 + 254114 + 25488 + 25463 + 25438 + 25413 + 1 ≈ 1.59 × 10399 programs to those of the previous sections.

1 Newline added for clarity.
2 Per consensus on Meta, this is allowed by default.
3 or 0.0000000000000000000000000000000000000000000000000000000000000012 %


Expand Exponentiation Given two integers greater than one, A and B, output four mathematical expressions in this order:

The plain expression A^B (A to the power B). e.g. if A = 2 and B = 3, 2^3.

The expansion of A^B in terms of repeated multiplications of A. e.g. 2*2*2.

The expansion of A^B in terms of repeated additions of A. e.g. 2+2+2+2.

The expansion of A^B in terms of repeated additions of 1. e.g. 1+1+1+1+1+1+1+1.

The four expressions may be output in any reasonable way as long as they are in order and clearly distinct. For example, you might put them in a list, or print them on separate lines
2^3
2*2*2
2+2+2+2
1+1+1+1+1+1+1+1

or perhaps on one line separated by equals signs:
2^3=2*2*2=2+2+2+2=1+1+1+1+1+1+1+1

Spaces may be inserted next to math operators so
2^3 = 2 * 2 * 2 = 2 + 2 + 2 + 2 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

would be equally valid output when A = 2 and B = 3.
You may use symbols alternative to ^, *, and +, but only if the new symbols are more idiomatic for your language (e.g. ** instead of ^ in Python).
You may assume that A and B are sufficiently small so that A^B will not overflow your language's default integer type (given that that type has a reasonable maximum, 255 at least).
The shortest code in bytes wins.
Test Cases
One output per line. The input can be inferred as the first expression is always A^B.
2^2 = 2*2 = 2+2 = 1+1+1+1
2^3 = 2*2*2 = 2+2+2+2 = 1+1+1+1+1+1+1+1
2^4 = 2*2*2*2 = 2+2+2+2+2+2+2+2 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
2^5 = 2*2*2*2*2 = 2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
3^2 = 3*3 = 3+3+3 = 1+1+1+1+1+1+1+1+1
3^3 = 3*3*3 = 3+3+3+3+3+3+3+3+3 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
3^4 = 3*3*3*3 = 3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
3^5 = 3*3*3*3*3 = 3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
4^2 = 4*4 = 4+4+4+4 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
4^3 = 4*4*4 = 4+4+4+4+4+4+4+4+4+4+4+4+4+4+4+4 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
10^2 = 10*10 = 10+10+10+10+10+10+10+10+10+10 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
13^2 = 13*13 = 13+13+13+13+13+13+13+13+13+13+13+13+13 = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

Python 3.6, 88 74 bytes

-2 bytes thanks to Dada (use ~)
-5 bytes thanks to Erwan (use f-strings from Python 3.6)

lambda a,b:f"{a}^{b}={a}{f'*{a}'*~-b}={a}{f'+{a}'*~-a**~-b}=1"+"+1"*~-a**b

online ide anyone?

How?

This is an unnamed function taking the two integer inputs a and b each greater than 0 (even though the specification is only for those greater than 1).

In Python 3.6 a new feature is available, namely formatted string literals or "f-strings". These allow run-time evaluated string construction. A leading f (or F) creates such a construct, e.g. f"blah" or f'blah'. Inside an f-string anything between a pair of braces, {...}, is an expression to be evaluated.

As such f"{a}^{b}={a}{f'*{a}'*~-b}={a}{f'+{a}'*~-a**~-b}=1" evaluates each of a, b, a, f'*{a}'*~-b, a, and f'+{a}'*~-a**~-b} as expressions, keeping the ^, =, =, and =1 as strings,all of which gets concatenated together.

The a and b expressions evaluate to the representations of a and b respectively.

The f'*{a}' and f'+{a}' in turn are also f-strings inside these expressions, which evaluate to a with a leading '*' and a leading '+' respectively

To create the required number of as and operations for the * and + portions note that there will be b as multiplied together and a**(b-1) as added together. Each case then requires one less operator sign than the number of as. So we can repeat the f-strings f'*{a}and f'+{a}' (using *) as many times as there are operators and prepend each with a single a. (b-1) is ~-b and (a**(b-1))-1 is ~-a**~-b.

The same  is done for the 1s using (a**b)-1 being ~-**b, but we don't need the overhead of f-strings since 1 is constant, so a standard string repeated is concatenated with +.

Prior Python versions, 81:

lambda a,b:'%s^%s=%s=%s=1'%(a,b,('*%s'%a*b)[1:],('+%s'%a*a**~-b)[1:])+'+1'*~-a**b

Try it online!


Shortest conditional to run a specific statement: C code golf Currently I have the code (expanded for your benefit):

<number> != <number> ? printf("|\\"); : <number>;

The idea here, is to do this condition in the least number of characters. This is currently, roughly the same number of characters it would take to be doing the exact same thing using an if statement, due to the fact, that I am fulfilling the second argument of the ternary operator which does not need to be filled, it is simply filled, as otherwise the statement does not run. (the final number is really a variable).

Is there any possible way to do the same conditional but shorter? (in C)

if(x!=y)printf("foo\n");
x!=y?printf("foo\n"):0;
x==y||printf("foo\n");

Yes, you can save some characters with the ternary operator or with the shortcutting logic operators (&& and ||).  All three of the above do the same thing.  Which you can use depends on things like the return type of printf and whether you need the return value.

Does that answer your question?


Area of an ASCII polygon You should write a program or function which receives a string representing an ascii-art polygon as input and outputs ot returns the area of the polygon.

The input is a string consisting of the characters _ / \ L V space and newline defining a simple polygon (which means no extra segments, no self-touch and no self-intersect).

The area of a single character cell is 2

_ splits the cell into sizes 0 and 2
\ splits the cell into sizes 1 and 1
/ splits the cell into sizes 1 and 1
L splits the cell into sizes 0 and 2
V splits the cell into sizes 1 and 1 (The two sides of the V will always be on the same side of the polygon so they are treated together in the listing.)

Every character connects the two corners of its character cell which you expect (e.g. top left and top right in case of V).

An example with area of 7 (1+2+1 in the second row and 1+1+1 in the third one):

 _
/ \
V\/

Input

Input will form a rectangle, i.e. there will be the same number of characters between newlines.
There can be extra whitespace on any side of the polygon.
Trailing newline is optional.

Output

A single positive integer, the area of the polygon.

Examples

Outputs are after the last row of their inputs.

  _
  V

1

/L
\/

3

    /VV\
    L  /
     L/
14

  ____/\
  \    /
/\/   /
\____/

32

   /V\
  /   \__
  \     /
/\/   /V
L____/

45

This is code-golf so the shortest entry wins.

Pyth, 47 46 45 36 30
FNs.zx=Z}N"\/L"aY|}N"\/V"yZ;sY

Explanation:
FNs.z            For every character in input, except newlines...
  x=Z}N"\/L"     Swap state if /, \, or L.
  aY|}N"\/V"yZ;  Append 1 if /, \, or V, else 2 times the state to Y.
sY               Sum Y and print.

We have two states, "in the polygon", and "out of the polygon". The following characters each do the following when reading them from top-left to bottom-right:
/ \     swap state, add one to area
V                   add one to area
_ space             if in polygon, add two to area
L       swap state, if in polygon, add two to area

Note that "add one to area" and "if in polygon, add two to area" are mutually exclusive.


Create a random 3D asteroid Imagine you are working on a 3D adaptation of the classical video game Asteroids. Your task is to write an algorithm that can create a random 3D asteroid.

This is a popularity contest, not code golf. Write nice code and create interesting results. Add other cool features if you want.

Rules:

Your algorithm must actually create the model, not just load it from an external source or similar.
The results must be (pseudo-)random. Running the algorithm several times must create different results.
Real-time capability is desirable, but not necessary.
Low or high polygon count? Realistic or stylized? You decide...
The output must be a mesh, either in memory or as a file such as Wavefront OBJ. In either case you need to render it in some way.
Explain your algorithm, so that everybody can learn from it.
Show some images of your results.

Blender + Python
Blender's built-in Python scripting is perfect for this sort of thing.

Open a Python console and paste in the following:
import bpy
import random

def asteroid():
    bpy.ops.mesh.primitive_ico_sphere_add()
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.faces_shade_smooth()
    bpy.ops.mesh.select_mode(type='VERT')
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(1.1,1.4),random.uniform(1.1,1.4),random.uniform(1.1,1.4)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(1.05,1.15),random.uniform(1.05,1.15),random.uniform(1.05,1.15)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(0.92,1.05),random.uniform(0.92,1.05),random.uniform(0.92,1.05)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    stretch = random.uniform(0.9,1.5)
    bpy.ops.transform.resize(value=(stretch,1,1))
    bpy.ops.transform.rotate(value=(random.uniform(-1.57,1.57)), axis=(random.uniform(-1.57,1.57),random.uniform(-1.57,1.57),random.uniform(-1.57,1.57)))
    bpy.ops.object.mode_set(mode='OBJECT')

asteroid()

An asteroid will then be created at the position of your 3D cursor:

Want another asteroid? Move the 3D cursor somewhere else and then type asteroid() into the Python console again (or just ↑Enter to repeat the last line entered).
To make it look more like a piece of space rock and less like a blob of plastic, you need to apply a suitable material. The following procedural material works quite well. I used a diffuse colour of #635C5B, and #8D887F in the marble texture.

How it works:

Start by creating a simple icosahedron (bpy.ops.mesh.primitive_ico_sphere_add()).
Enter edit mode (bpy.ops.object.mode_set(mode='EDIT')) and apply smooth shading so that the individual facets blend into one another (bpy.ops.mesh.faces_shade_smooth()).
Select a random subset of the object's vertices (bpy.ops.mesh.select_random()).
Scale them randomly in the X, Y and Z directions (bpy.ops.transform.resize()).
Select the whole object (bpy.ops.mesh.select_all(action='SELECT')) and apply smooth subdivision to add new vertices by interpolating smoothly across the deformed object (bpy.ops.mesh.subdivide(smoothness=1)).
(Repeat steps 3–5 a couple more times.)
Stretch the object in the X direction to make it a bit less spherical (bpy.ops.transform.resize(value=(stretch,1,1)))
Apply a random rotation transform (bpy.ops.transform.rotate())
Finally, exit edit mode and leave the object selected (bpy.ops.object.mode_set(mode='OBJECT')).

More examples:


Is it a whole number? A number is whole if it is a non-negative integer with no decimal part. So 0 and 8 and 233494.0 are whole, while 1.1 and 0.001 and 233494.999 are not.

Input

A floating-point number in the default base/encoding of your language.

For example, the default integer representation for Binary Lambda Calculus would be Church numerals. But the default integer representation for Python is base 10 decimal, not Unary.

Output

A truthy value if the input is whole, a falsy value if it is not.

Note that if your language only supports decimal precision to, say, 8 places, 1.000000002 can be considered whole.

Input and output may be done via any standard I/O methods.

Test cases

Input        -> Output
332          -> true
33.2         -> false
128239847    -> true
0.128239847  -> false
0            -> true
0.000000000  -> true
1.111111111  -> false
-3.1415926   -> false
-3           -> false

Scoring

As with code-golf, the shortest submission wins. Good luck!

Haskell, 27 16 bytes

This function checks whether x is contained in the list of nonnegative integers that are not greater than x.

f x=elem x[0..x]

Try it online!


R, 54 bytes

Several bytes saved by @Giuseppe and @J.Doe.

f=function(m)if(ncol(m))c(m[,1],f(t(m[nrow(m):1,-1])))

Try it online!

Recursively strip off the first column and row-reverse/transpose (making the bottom row the new first column) the rest of the matrix until you end up with only one column. Ungolfed "traditional" version:

f <- function(m) {
 if(ncol(m) == 1) {
    m
  } else {
    c(m[,1], f(t(m[nrow(m):1,-1])))
  }
}

It was pointed out that ncol(m) could be golfed to sum(m) to save another byte because we are allowed to assume positive integer matrix values. But I'll leave it like this since it works for all matrices (even matrices of strings!)


One-to-one correspondence between pairs of integers and the positive integers It is well-known that there are one-to-one correspondences between pairs of integers and the positive integers. Your task is to write code defining such a correspondence (by defining a pair of functions/programs that are inverses of each other) in your programming language of choice, plus a correctness check (see below) with the smallest number of bytes for the correspondence definition (not taking the correctness check into account).

The solution must include :

the definition of a function/program f having two integer arguments and returning an integer (that's one direction of the bijection).
either the definition of a function/program g having one integer argument and returning a pair of integers (might be an array, a list, the concatenation of the two integers separated by something   ...) or two functions/programs a and b having an integer argument and returning an integer (that's the other direction).
an additional code snippet checking that for the f and g (or f and a,b) you defined above, you have g(f(x,y))=(x,y) (or a(f(x,y))=x and b(f(x,y))=y) for any integers x,y in the range -100 < x < 100,-100 < y < 100. Note that f and g have to work for values outside of this range as well.

You may rename a,b,f or g of course. The two solutions do not have to be written in the same language.

Below is a not-optimal-at-all solution in PARI/GP, with 597 characters for the function definitions.

plane_to_line(x,y)={
my(ax,ay,z);
ax=abs(x);
ay=abs(y);
if((ax<=ay)*(y<0),        z=4*y*y-2*y+x+2;);
if((ax<=ay)*(y>=0),       z=4*y*y-2*y-x+2;);
if((ay<=ax)*(x<0),        z=4*x*x    -y+2;);
if((ay<=ax)*(x>=0)*(y<0), z=4*x*x+4*x+y+2;);
if((ay<=ax)*(x>=0)*(y>=0),z=4*x*x-4*x+y+2;);
if((x==0)*(y==0),z=1;);
return(z);
}

line_to_plane(z)={
my(l,d,x,y);
l=floor((1+sqrt(z-1))/2);
d=z-(4*l*l-4*l+2);
if(d<=l,x=l;y=d;);
if((l<d)*(d<=3*l),x=2*l-d;y=l;);
if((3*l<d)*(d<=5*l),x=(-l);y=4*l-d;);
if((5*l<d)*(d<=7*l),x=d-6*l;y=(-l););
if((7*l<d)*(d<8*l) ,x=l;y=d-8*l;);
if(z==1,x=0;y=0;);
return([x,y]);
}

and the correctness-check code :

accu=List([])
m=100;
for(x=-m,m,for(y=-m,m,if(line_to_plane(plane_to_line(x,y))!=[x,y],\
listput(accu,[x,y]);)))
Vec(accu)

MATL, 43 36 bytes
This uses the spiral (1YL) function, which generates a square 2D array of given size with values arranged in an outward spiral. For example, with input 7 it produces
43 44 45 46 47 48 49
42 21 22 23 24 25 26
41 20  7  8  9 10 27
40 19  6  1  2 11 28
39 18  5  4  3 12 29
38 17 16 15 14 13 30
37 36 35 34 33 32 31

The center of the array, which contains 1,  corresponds to the tuple [0 0]. The upper left corner corresponds to [-3 -3] etc. So for example f (-3,-3) will be 43 and g (43) will be [-3 -3].
The code generates a 2D array with this spiral matrix, as large as needed to do the conversion. Note that larger sizes always give the same result for the entries already included in smaller sizes.
From Z2 to N (18 bytes):
|X>tEQ1YLGb+QZ}3$)

Try it online!
|X>   % input is a 2-tuple. Take maximum of absolute values
tEQ   % duplicate. Multiply by 2 and increase by 1. This gives necessary size of spiral
1YL   % generate spiral
G     % push input 2-tuple again
b+Q   % bubble up, add, increase by 1. This makes the center correspont to [0 0]
Z}    % split tuple into its values
3$)   % use those two value as indices into the spiral array to obtain result

From N to Z2 (25 18 bytes)
Eqt1YLG=2#fhw2/k-q

Try it online!
Eq      % input is a number. Multiply by 2, add 1. This assures size is enough and odd
t1YL    % duplicate. Generate spiral of that size
G=      % compare each entry with the input value
2#fh    % 2-tuple of row and column indices of matching entry
w2/k-q  % swap. Offset values so that center corresponds to [0 0]

Snippet for checking
Note that G needs to be modified to accomodate the fact that we have don't have a single input. The code is slow, so the link checks tuples with values from -9 to 9 only. For -99 to 99 just replace the first line.
The code tests each tuple with values in the defined range. It does the conversion to a number, then from that number back to a tuple, and then checks if the original and recovered tuple are equal. The results should all be 1, indicating that all comparisons give true.
It takes a while to run.
Try it online!
-9:9                     % Or use -99:99. But it takes long
HZ^!"@                   % Cartesian power: gives tuples [-9 -9] ... [9 9].
                         % For each such tuple
|X>tEQ1YL@b+QZ}3$)       % Code from Z^2 to N with `G` replaced by `@` (current tuple)
XJ                       % Copy result into clipboard J
Eqt1YLJ=2#fhw2/k-q       % Code from N to Z^2 with `G` replaced by `J`
@!X=                     % Compare original tuple with recovered tuple: are they equal?


Trilaterate your position Introduction
Imagine you are on a two dimensional cartesian plane and want to determine your position on it. You know 3 points on that plane and your distance to each of them. While it is always possible to calculate your position from that, doing that in your head is pretty hard. So you decide to write a program for that.
The Challenge
Given 3 points and your distance to them, output the cordinates of your position.

Input and output may be in any convenient format, including using complex instead of real numbers. Please clarify in your answer which format you use.
You will always get exactly 3 distinct points with their distance to you.
The coordinates and distances will be floats with arbitrary precision. Your output has to be correct to 3 decimal places. Rounding is up to you. Please clarify in your answer.
You may assume that the three points are not collinear, so there will be always an unique solution.
You are not allowed to bruteforce the solution.
You may not use any builtins that trivialize this particular problem. Builtins for vector norms, etc. are allowed though.

Hint to get started:

 Think about a circle around each of those 3 points with their distance to you as radius.

Rules

Function or full program allowed.
Default rules for input/output.
Standard loopholes apply.
This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.

Test cases
Input format for one point here is [[x,y],d] with x and y being the coordinates and d being the distance to this point. The 3 of those points are arranged in a list. Output will be x and then y in a list.

[[[1, 2], 1.414], [[1, 1], 2.236], [[2, 2], 1.0]] -> [2, 3]
[[[24.234, -13.902], 31.46], [[12.3242, 234.12], 229.953], [[23.983, 0.321], 25.572]] -> [-1.234, 4.567]
[[[973.23, -123.221], 1398.016], [[-12.123, -98.001], 990.537], [[-176.92, 0], 912.087]] -> [12.345, 892.234]

You can generate additional test cases with this Pyth program. Location goes on the first line of the input and the 3 points are on the following 3 lines.
Happy Coding!

Desmos, 122 bytes

Online use. Copy+paste each equation into an equation box, click "add all" for each box, then click on the point of intersection, then enter in each value as appropriate. each of A, B, and C are the distances for the points (a,b), (c,d), and (E,f), respectively. To get a square root in the value, type sqrt then the value in the box.

\left(x-a\right)^2+\left(y-b\right)^2=AA
\left(x-c\right)^2+\left(y-d\right)^2=BB
\left(x-E\right)^2+\left(y-f\right)^2=CC

Verify the first test case.

Or you can take a look here:


A guess the word game A guess the word game
The agreed dictionary.  All words are 6 letters long with all letters distinct
Rules:  This is a game of two players and the task will be to implement Player 2.
Player 1 chooses a word from the agreed dictionary
Player 2 repeatedly guesses a word from the agreed dictionary.
At each turn, Player 1 tells Player 2 how many letters the guess has in common with the secret word.  For example, youths and devout have three letters in common.
Goal
Player 2's goal is to guess the word in as few turns as possible.
Task
The task is to implement player 2 to minimize the maximum number of guesses they ever have to make. Your score is the maximum number of guesses made when considered over all the words in the agreed dictionary. A lower score is better.
You should test  your code by choosing each word from the agreed dictionary in turn and see how many guesses your implementation of Player 2 needs. You should then output the maximum.
Objective winning criteria
Answers will first be compared by the score they get using the rules above. Two answers with the same score will then be compared using code-golf rules. That is by the number of bytes in the code.

Ruby, 418 bytes, score 12 (on 'palest')

$dict = File.readlines('agreeddict.txt').map(&:chomp)

def search(wrd)
  words = 0
  fdic = $dict.clone
  guess = ''
  starters = ['earths','blowup','coding']

  chs = wrd.chars

  while guess!=wrd do
    guess = starters.pop || fdic.pop
    words += 1
    ghs = guess.chars
    chars = (chs|ghs).size
    fdic.select!{|w|(w.chars|ghs).size == chars}
  end

  words
end

upp = 0;

p $dict.map{|w|
  [search(w),w]
}.max

Try it online!

Runs in 15 seconds on my machine.

TIO link for reference only - does not work if the file is not in the current directory.

The trick

Instead of brute-force elimination, try a list of initializers first. A lot of words differ by only 1 character and it's easy to get stuck in a single-letter elimination loop.

The most difficult words to guess are those with 4-5 very common characters (a e r s t), 1-2 'outsiders' (c p x z...) and some anagrams in the dictionary.

For example, when we reach a word containing the letters "a e r s t" and the answer is 5: if we just filter all the entries containing these 5 characters, we are left with a dictionary of 40 similar words, and then we have to try almost all of them, removing only a few words at each step.

We need to remove these words first, and we filter on the least common character, so if we get to "earths", and Player 1 answers 5, we don't have a lot of words to check. The first 2 words we always check are "coding" and "blowup" (no pun intended).

Now we can try with  a word containing the 5 most common letters ("earths"). If the answer is 4 or 5 (which is likely), we don't have a lot of words to choose from, because we already filtered all the words containing only 1 or 2 uncommon letters (and we only used 3 guesses to get here).

Finding the right initializers was a little tricky, I started with a list of 5 "quasi orthogonal" words (with as few letters as possible in common, a good start was "sporty fuzing hawked climax jumble", missing only the letter z) and got to 13, then started a test on automatically generated smaller lists.

'palest' seems to be a worst case, having 6 anagrams and 4 very common letters, but it's not the only word requiring 12 guesses, so I don't think I could get a better score with this approach.

I don't want to golf this.


Smallest number of contiguous monotonic subsequences A monotonic subsequence is a sequence of numbers \$a_1, a_2, ..., a_n\$ such that
$$a_1 \le a_2 \le ... \le a_n \\
\text{or} \\
a_1 \ge a_2 \ge ... \ge a_n$$
[1, 3, 3, 7, 9, 13, 13, 100] is a monotonic (non-decreasing) subsequence, as well as [9, 4, 4, 3, 0, -10, -12] (this one is non-increasing), but [1, 3, 6, 9, 8] is not. Given a list of integers (in any reasonable format), output the smallest number N such that the sequence of these integers can be split into N monotonic sequences.
Examples
[1, 3, 7, 5, 4, 2] -> [[1, 3, 7], [5, 4, 2]] -> 2
[1, 2, 3, 4, 5, 6] -> [1, 2, 3, 4, 5, 6]     -> 1
[3, 1, 5, 5, 6]    -> [[3, 1], [5, 5, 6]]    -> 2
[4, 6, 8, 9, 1, 6] -> [[4, 6, 8, 9], [1, 6]] -> 2
[3, 3, 3, 3]       -> [[3, 3, 3, 3]]         -> 1
[7]                -> [[7]]                  -> 1
[]                 -> []                     -> anything (you don't actually have to handle an empty list case)
[1, 3, 2, -1, 6, 9, 10, 2, 1, -12] -> [[1, 3], [2, -1], [6, 9, 10], [2, 1, -12]] -> 4

Brachylog, 12 bytes
~c:{<=|>=}al

Try it online!
This returns false. for the empty list [].
Explanation
(?)~c                 Take a list of sublists which when concatenated result in the Input
     :{<=|>=}a        Each sublist must be either increasing or decreasing
              l(.)    Output is the length of that list

This will return the smallest one because ~c will generate choice points from the smallest number of sublists to the biggest.


Parse a list of lists into a Sad-List In this challenge, you must parse a list of lists, into a simpler list format.

This challenge is based on my sadflak parser. In my sadflak parser, it has all the () removed, replaced with the sum of the ()s at the start of the list, to make the program run faster.

To parse into a Sad-List, you have to do this (python implementation thing, uses a tuple of tuples):

def sadlistfunc(list):
    new-sadlist = [0]
    for i in list:
        if i == ():
            new-sadlist[0]+=1
        else:
            new-sadlist.append(sadlistfunc(i))

This is a recursive function. For a list, start a new list, starting with the number of () from the list input, then the rest of this list is sad-list versions of every list that was not a () from the list input, in order. return the list.

Input:

you may take input in a few different formats:

you may take it as a list
you may take it as a tuple
you may take it as a string

if you take it as a string, you should use some set of brackets, as appear in brain-flak. you may not use characters 1 and 2

just be reasonable

Input will always be inside one list, but your program may assume an implicit list layer outside of the input, i.e. ()()() = (()()()), or it may choose not to. Examples will be with explicit outside list

output:

may be list or tuple or string, or whatever. you may use whatever reasonable output format, as is the meta consensus.

Example:

(()()()) = [3]
(((()))) = [0,[0,[1]]]
((())()(())) = [1, [1], [1]]
() = invalid input, if the outside bracket is explicit.
((((())())())(())()) = [1, [1, [1, [1]]], [1]]

note that input is not strict. these inputs could be:

[[],[],[]]
[[[[]]]]
[[[]],[],[[]]]
[]
[[[[[]],[]],[]],[[]],[]]

or some other reasonable format

explained test case:

(()()((())())())

to "sadify" this, first we count the number of ()

 ()()        ()
(    ((())())  )

3. then we remove these, and add a 3 at the start

(3,((())()))

there is one list in this list. we sadify this

((())())

how many ()?

     ()
((())  )

1. we remove and add a 1 at the start

(1,(()))

this has one list in it

(())

count

 ()
(  )

remove and add count

(1)

then we put this back into its list

(1,(1))

then we put this back into its list

(3,(1,(1)))

done

This is code-golf, so shorter is better

Pyth, 13 bytes

L+]/bYyM-b]Yy

Test suite.

How it works

L+]/bYyM-b]Yy
L               define a function y with argument b:
   /bY              list 1: count how many [] can be found in b
  ]                         wrap into singleton
        -b]Y        list 2: filter out [] from b
      yM                    apply y (this function) to each
 +                  concatenate the two lists above
            y   apply y to the input


Additive Persistence The shortest code to pass all possibilities wins.

In mathematics, the persistence of a number measures how many times a certain operation must be applied to its digits until some certain fixed condition is reached.  You can determine the additive persistence of a positive integer by adding the digits of the integer and repeating.  You would keep adding the digits of the sum until a single digit number is found.  The number of repetitions it took to reach that single digit number is the additive persistence of that number.

Example using 84523:

84523
8 + 4 + 5 + 2 + 3 = 22
2 + 2 = 4

It took two repetitions to find the single digit number.
So the additive persistence of 84523 is 2.

You will be given a sequence of positive integers that you have to calculate the additive persistence of.  Each line will contain a different integer to process.  Input may be in any standard I/O methods.

For each integer, you must output the integer, followed by a single space, followed by its additive persistence.  Each integer processed must be on its own line.

Test Cases

Input Output

99999999999 3
10 1
8 0
19999999999999999999999 4
6234 2
74621 2
39 2
2677889 3
0 0

K - 29 Chars

Input is a filename passed as an argument, 29 chars not including filename.

`0:{5:x,-1+#(+/10_vs)\x}'.:'0:"file"

35 -> 31: Remove outside function.
31 -> 29: Remove parens.


Fastest tweetable integer factorizer The task is to find a non-trivial factor of a composite number.

Write code that finds a non-trivial factor of a composite number as quickly as possible subject to your code being no more than 140 bytes long.  The output should just be the factor you have found.

Your code can take input and give output in any way that is convenient including for example as arguments to a function.

Test cases which list all the factors (you only need to output  one)

187: 11 17
1679: 23 73
14369648346682547857: 1500450271 9576890767
34747575467581863011: 3628273133 9576890767
52634041113150420921061348357: 2860486313 5463458053 3367900313
82312263010898855308580978867: 264575131106459 311111111111113
205255454905325730631914319249: 2860486313 71755440315342536873
1233457775854251160763811229216063007: 1110111110111 1000000000063 1111111999999
1751952685614616185916001760791655006749: 36413321723440003717 48112959837082048697

I won't score your answer on the following difficult test case which may be of interest for testing:

513231721363284898797712130584280850383: 40206835204840513073 12764787846358441471

Score

Your score is the combined time to factor all the test cases above with a penalty of 10 minutes for each failed factorization (all rounded to the nearest second).  Your code should work for other integers too, that is shouldn't just hardcode these answers.

I will stop your code after 10 minutes.

If two people get the same score then the first answer wins.

Restrictions

Your code can't use any builtin or library function that performs integer factorization. You can assume the input takes less than 256 bits.  All input numbers will be composite.

How will I time?

I will literally run time ./myprog on my Ubuntu system  to do the timing so please also supply a complete program for me to run that includes any function you have defined.

A note for compiled languages

Compilation time must take no more than 1 minute on my machine.

Is it actually possible?

If you ignore the space constraints, then  each one can be factored in less than 2 seconds on my computer using pure Python code + pypy.

So what is a non-trivial factoring algorithm?

Pollard's rho algorithm is fast and suitable for golfing. Of course there are plenty of other ways to factor an integer as well.

Even faster is the Quadratic sieve.  It looks like a serious challenge to squeeze that into 140 bytes.

Leading scores

SEJPM, 10 minutes penalty for the last test case + 16 seconds in Haskell

Haskell, 100 97 91 89 87 72 67 Bytes
Try It Online!
-3 bytes thanks to @flawr
-6 bytes thanks to @flawr again
-2 bytes thanks to @flawr yet again
-2 bytes thanks to an optimized set of parameters
-1 byte thanks to @flawrs yet another time
-14 bytes thanks to requirement to only having to output one factor
-5 bytes thanks to @AndersKaseorg
f n|let s x=mod(x*x+7)n;a#b|d<-gcd(b-a)n,d>1=d|c<-s b=s a#s c=5#s 5

This works for the first 5 test cases in unnoticable time.
This will probably time-out on the largest test case.
In general this will usually return one non-trivial factor in time proportional to the square root of the smallest factor.
It will not work on every input because it doesn't vary the polynomial and detection of the exceptional case is hard to do in 140 bytes.
It will also not output the full factorization, but rather a non-trivial factor and the division of the input by this factor.
It will also not sort the factors by size.
The method used is Pollard-Rho-Factoring with the standard starting value of 2 (with the standard x^2+1 polynomial applied once) and the non-standard polynomial constant factor of 7 (because 1 didn't work with 1679) for all further evaluations.
Full program (factor.hs):
import System.Environment(getArgs)

f n|let s x=mod(x*x+7)n;a#b|d<-gcd(b-a)n,d>1=d|c<-s b=s a#s c=5#s 5

main= do
      args <- getArgs
      print$f (read $ head args :: Integer)

Compile as $ ghc factor.hs (needs ghc installed).
Run as $ ./factor <number>.
Example run:
$ ./factor 187
11

Ungolfed code:
f n=g 5 (s 5)
   where s x=mod(x*x+7)n
         g a b = if d>1 then d else g(s a)(s(s b))
               where d=gcd(b-a)n

Computes the non-trivial factor by calling g with initial values. The polynomial is pre-applied on 2 here and re-applied on the result (5) so that the input to g (in a "where" clause) can always be readily used for the gcd-test. g (golfed version uses infix #) then tries to compute a non-trivial factor d (in the where clause in the un-golfed version, in-line in the golfed one) as the difference between the two inputs to g, if it succeeds returns said factor, else retries. Here it may generate n as the output if a==b and thus returns only a trivial factor, the proper approach to handle this would be to either vary the starting values upon this event or change the polynomial.


Repeated Consecutive Digital Product Sum Convergence Given a positive integer n (Example: n=1234444999)

Separate into consecutive digit runs:

[1, 2, 3, 4444, 999]

Take the digital product of each run.

[1, 2, 3, 4*4*4*4, 9*9*9] = [1, 2, 3, 256, 729]

Sum it...

991

Repeat until this converges to a single number:

1234444999
991
82
10
1

Return last number.

Test Cases

BASE CASES:
0 = 0
...
9 = 9

OTHER CASES:
1234444999                     = 1
222222222222222                = 8
111222333444555666777888999000 = 9
11122233344455566677788899     = 8
1112223334445                  = 6
14536                          = 1
99                             = 9

Requested Example:

334455553666333
9+16+625+3+216+27
896
8+9+6
23
2+3
**5**

Winning?

It's code-golf, lowest byte-count is the winner.

05AB1E, 7 6 5 bytes

Thanks to Emigna for saving a byte!

vSγPO

Uses the 05AB1E encoding. Try it online!


Mirror quine (or my head hurts) I was reading Print your code backwards - reverse quine And I thought, this could be more interesting if your backwards code is also executable. So this challenge will have all the rules and requirements of the other, but must also be valid source once reversed (in the same or another language and still print its source backwards.
All rules and scoring from the reverse quine challenge apply, so all answers to this question will answer that one (but not score as well.)
Edit:
By request, all rules now copied here.
Rules:

write a program p which when executed produces output p' where p' is p backwards and p' when executed produces p.
No using other files (e.g. reverse.txt)
Minimum code length is two characters.
Your program cannot be a palindrome.

Scoring:

+50 if you use pull data from the Internet.
+25 if you read your own source code.
+1 point per character.
Lowest score wins.

GolfScript, 46 chars

0{`".~#"+.-1%+\.!@@}.~##~.}@@!.\+%1-.+"#~."`{1

Well, this is ugly, but it works.  The output equals the code reversed, and is also a valid GolfScript program which outputs the original code again.

OK, let me try to explain how I constructed it.  First, I started from the quine {".~"}.~, and modified it as in this answer to reverse itself.  To make the output an executable quine in itself, I made a copy of the code before reversing it, and included a # at the end of the code, so that the reversed version at the end became just a comment.  Thus, we get the palindromic quine:

{`".~#"+.-1%}.~##~.}%1-.+"#~."`{

However, by the rules, palindromes are not allowed, so I needed to break the symmetry somehow.  I figured the easiest way would be to include a 0 (which, in itself, is a quine in GolfScript) in the code and flip it to 1 with ! after creating the reversed copy.  Most of the remaining complexity is just ugly stack manipulation to get everything in the right order.


Subtract the next numbers Description

Subtract the next P numbers from a N number. The next number of N is N + 1.

Look at the examples to get what I mean.

Examples:

Input: N=2,P=3
Calculate: n - (n+1) - (n+2) - (n+3)     //Ending with 3, because P=3
Calculate: 2 -  2+1  -  2+2  - 2+3       //Replacing N with 2 from Input
Calculate: 2 -  3    -  4    - 5
Output: -10

Input: N=100,P=5
Calculate: n - (n+1) - (n+2) - (n+3) - (n+4) - (n+5)
Calculate: 100-  101 -  102  -  103  -  104  - 105
Output: -415

Input: N=42,P=0
Calculate: n
Calculate: 42
Output: 42

Input: N=0,P=3
Calculate: n - (n+1) - (n+2) - (n+3)
Calculate: 0 -  1    -  2    -  3
Output: -6

Input: N=0,P=0
Calulate: n
Calculate: 0
Output: 0

Input:

N: Integer, positive, negative or 0

P: Integer, positive or 0, not negative

Output:

Integer or String, leading 0 allowed, trailing newline allowed

Rules:

No loopholes
This is code-golf, so shortest code in bytes wins
Input and Output must be as described

Python 2, 26 24 23 bytes
-2 bytes thanks to @Adnan (replace p*(p+1)/2 with p*-~p/2)
-1 byte thanks to @MartinEnder (replace -p*-~p/2 with +p*~p/2

lambda n,p:n-p*n+p*~p/2

Tests are on ideone


Calculate probability of getting half as many heads as coin tosses. Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads.

For example, given 2 coins the possible outcomes are:

HH HT TH TT

where H and T are heads and tails. There are 2 outcomes (HT and TH) that are half as many heads as the number of coins. There are a total of 4 outcomes, so the probability is 2/4 = 0.5.

This is simpler than it looks.

Test cases:

2 -> 0.5
4 -> 0.375
6 -> 0.3125
8 -> 0.2734375

Pari/GP - 32 30 34 chars

print(binomial(n=input(),n\2)/2^n)


Turtle Graphics Version 2 Most of you have probably heard of the famous Turtle Graphics program, initially made popular by Logo.  This challenge is to implement a Turtle Graphics program in your language of choice.
Rules:

The floor must be a diagonal with dimensions input by the user through std-in in the form x/y, representing the x and y length, respectively.  x may not be more than 20 and y may not be more than 45,

When the pen is in the down state, it must draw in both the square (the x/y coordinate) the turtle leaves and the square the turtle enters.  This is what would happen in real life, so that is what your program should do.

Initial position and direction of the turtle must be input by the user in the form x,y,d, where x and y are the positions on the x- and y-axis, respectively, and d is the direction, entered as U, D, R, or L (up, down, right, and left, respectively).

You must stop the turtle and display an error message if the turtle hits the wall.  In other words, the turtle cannot walk through the wall.

The turtle must include these commands:

RESET - Resets board to blank - turtle goes back to initial position and direction.
DRAW and ERASE - These commands set the turtle to drawing and erasing, respectively.
UP and DOWN - These two commands set the active tool (pen or eraser) position to up and down, respectively.
DIRECTION x - This command turns the turtle to any direction North, Northeast, East, Southeast, South, Southwest, West, or Northwest, represented as the digits 1-8, with North (up) being 1, Northeast being 2...
FORWARD xx - Advances turtle xx squares; FORWARD 15 advances the turtle 15 squares.  If the turtle is facing N, E, S, of W, it will draw in x squares in that direction only.  If the turtle is facing NE, NW, SE, or SW, it will draw in x squares in both directions; i.e. in FORWARD 1 while facing NE, it will draw this:
 X
X

DISPLAY - Displays board, using X for filled squares (x/y coordinates) and a blank space   for empty squares.
POSITION - Prints turtle's x/y coordinate on the board.
SETPOS x y d - Sets the turtle to the x/y coordinate facing direction d, using the same notation as the DIRECTION command.
STOP - Displays the board, and terminates the program after the user enters the character ~.

Example commands:

DIRECTION 2 FORWARD 1 DIRECTION 4 FORWARD 1:
 X
X X

DIRECTION 2 FORWARD 1 DIRECTION 4 FORWARD 4:
 X
X X
   X
    X

DIRECTION 3 FORWARD 5:
XXXXX

This program will use standard atomic-code-golf scoring rules to try to allow non-esoteric programming languages, such as Java and C++, to compete.
Version 1 is here.  It did not require user input of board size and turtle start point, nor did it require diagonal movements.

Python 3.3 (354?)

I noticed this as an unanswered question and decided to give it a go:

v=input().split('/')+input().split(',')+[input().split(' '),0,1,'X','U','D','L','R']
w,h,x,y,d,c,p,r,m,n,s,l,e=v
w,h,x,y=int(w),int(h),int(x),int(y)
g=[[' 'for x in range(int(h))]for y in range(int(w))]
while p<len(c):
 i=c[p]
 if r:
  g[y][x]=m
 if i=='RESET':
  w,h,x,y,d,c,p,r,m,n,s,l,e=v
 if i=='DRAW':
  m='X'
 if i=='ERASE':
  m=' '
 if i=='UP':
  r=0
 if i=='DOWN':
  r=1
 if i=='DIRECTION':
  p+=1
  i=int(c[p])
  d=''
  if i in[8,1,2]:
   d+=n
  if i in[4,5,6]:
   d+=s
  if i in[6,7,8]:
   d+=l
  if i in[2,3,4]:
   d+=e
 if i=='FORWARD':
  p+=1
  i=int(c[p])
  for _ in range(i):
   if d.find(n)+1:
    y-=1
   if d.find(s)+1:
    y+=1
   if d.find(l)+1:
    x-=1
   if d.find(e)+1:
    x+=1
   if r:
    g[y][x]=m
 if i=='DISPLAY':
  for z in g:
   print(''.join(z))
 if i=='POSITION':
  print(x,y)
 if i=='SETPOS':
  p+=3
  x,y=c[p-2:p]
  d=''
  if i in[8,1,2]:
   d+=n
  if i in[4,5,6]:
   d+=s
  if i in[6,7,8]:
   d+=w
  if i in[2,3,4]:
   d+=e
 if i=='STOP':
  while input()!='~':
   pass
  exit
 if x>w or x<0 or y>h or y<0:
  print('!')
  exit
 p+=1

  PS I am unsure about the scoring setup so my score may be incorrect!


Briefest code to find vowels and print consonants Challenge: Read a string from user, print number of each vowel, then place all remaining chars in a line. Shortest answer wins!

Output must look like this:

  Enter String: Input

  Vowel Count: a: #, e: #, i: #, o: #, u: #

  Remaining characters: Vowel-less Input

For example:

Enter String: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!

05AB1E, 62 bytes

Code:

”‡Á•Ë: ÿ”,”Vowelš‹: ”?"aeiou"©vy": "¹y¢««}", "ý,“«¶šÞ: “ª¹®-J,

Explanation:

There is a lot of string compression going on here. Here is a list of all strings that are compressed:

”‡Á•Ë” is equivalent to Enter String.
”Vowelš‹” is equivalent to Vowel Count.
“«¶šÞ“ª is equivalent to Remaining characters.

To see how the actual string compression works, see the Hello, World! answer, or an even more elaborate explanation at the bottom of the Code Review question. Without the string compression, the code looks like this:

"Enter String: ÿ","Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,"Remaining characters: "¹®-J,

Or a more readable 3-part version:

"Enter String: ÿ",
"Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,
"Remaining characters: "¹®-J,

Part 1:

We first push the string "Enter String: ÿ". The ÿ here is used for string interpolation. But since the stack is empty, implicit input is requested. The ÿ will be substituted with the user input. We print this with a newline using ,.

Part 2:

We first print the "Vowel Count: " string without a newline using ?. After that, we push the aeiou string, ©opy that to the register and map over the string using v and do the following:

vy": "¹y¢««}    # Mapping loop

v          }    # The loop itself
 y              # Push the current letter (which is a, e, i, o or u)
  ": "          # Push this string
      ¹         # Push the first input again
       y        # Push the letter again
        ¢       # Count the number of occurences of that letter in the input
         ««     # Concatenate to one single string, (e.g. "a: 4")

This leaves 5 different string onto the stack, the stack looks like this now:

stack: ['a: 0', 'e: 1', 'i: 0', 'o: 2', 'u: 0']

We join each element in the stack with ", " using ý. After this, we print it with a newline using ,.

Part 3:

We first push the string "Remaining characters: ". We push the first input again using ¹. We then push "aeiou" which we retrieve from the register using ®. After this, we remove all letters in aeiou using - and Join this with the Remaining characters-string. Finally, we output this with a newline using ,.

Uses CP-1252 encoding. Try it online!.


Concentric rings on a snub square tiling This challenge takes place on the snub square tiling.
Start by choosing any triangle, and color it \$c_1\$.
Next, find all tiles which touch this triangle at any vertex, and color them \$c_2\$. Next, find all tiles which share a vertex with any \$c_2\$-colored tile, and color these \$c_3\$.
Continue this process ad infinitum.
Illustration

Initial terms
The sequence begins
  a(1) = 1
  a(2) = 9
  a(3) = 21
  a(4) = 35

Notice:

a(1) = 1 corresponds to the red triangle;
a(2) = 9 corresponds to the number of tiles in the second, orange layer;
a(3) = 21 corresponds to the number of tiles in the third, green layer; and so on.

(Note, this sequence is now in the OEIS; OEIS sequence A296368 is closely related.)
Challenge
Your goal is to write a program that takes in a positive integer n and returns the number of tiles that are colored \$c_n\$, (i.e. the number of tiles in the \$n\$-th layer.) This is a code-golf challenge, so the shortest code in bytes wins.

Ruby, 26 bytes

->n{~-n*12-496/4**n%4+1/n}

Try it online!

Revised version adding 1/n and subtracting 496/4**n%4 to get the +1,-3,-3,-1 offset for the first 4 terms.

Ruby, 32 bytes

->n{n>4?~-n*12:[0,1,9,21,35][n]}

Try it online!

After 4, the sequence settles down to (n-1)*12. See diagram below (the equilateral triangles have been distorted into 45 degree isosceles triangles and the entire diagram rotated 45 degrees, but it remains topologically equivalent.)


Significant Whitespace We define whitespace to be any of the three characters, tab (0x09), newline (0x0A) or space (0x20).

For this challenge, you're to write two programs or functions in the same programming language, which perform the following tasks:

Count the whitespace characters in a given string. For instance, the input

  123 -_-   abc
def

would return 7 (provided there is no trailing newline).
Split a given string at consecutive runs of whitespace. If the string starts or ends with whitespace, no empty strings should be returned at the ends. For instance, the same input

  123 -_-   abc
def

would return ["123", "-_-", "abc", "def"].

In either case you may take input via STDIN, command-line argument or function argument a return the result or print it STDOUT. For the second program, if you choose to print to STDOUT, please print each string on its own line, without surrounding quotes.

For both programs you may assume that the input contains only printable ASCII (0x20 to 0x7E) and whitespace.

Now here is the catch:

If all whitespace is removed from both programs/functions, the resulting strings have to be identical. That is, your two submissions may only differ in the number and placement of whitespace characters.
Neither program/function may contain any string or regex literals (character literals are fine, provided your language has a designated character type).
Neither program/function may contain any comments.
You must not read the program's source code, directly or indirectly.

This is code golf. Your score is the sum of the sizes of both solutions (in bytes). Lowest score wins.

Leaderboards

The following Stack Snippet generates both a regular leaderboard and an overview of winners by language. So even if your language of choice doesn't let you win the entire challenge, why not try to snatch a spot on the second list? I'd be very interested to see how people tackle this challenge in a variety of languages!

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

# Language Name, N bytes

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

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

You may also include the individual counts before the total count, e.g.

# Python 2, 35 + 41 = 76 bytes

The last number that is not struck through will be used by the snippet.

<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>site = 'meta.codegolf',postID = 5314,isAnswer = true,QUESTION_ID = 42253;jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)<\\/code><\/pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>

Python, 54 + 56 = 110 bytes
Counter:
m=lambda x:sum(y.isspace()for y in x)
+1
0<9or x.split()

Splitter:
m=lambda x:sum(y.isspace()for y in x)+10<9or x.split()

For the counter, we use the fact that Python is okay with having just an expression on a line. It's necessary to split up +1 and 0<9or x.split() to stop a NameError from being thrown, as 0<9 being True prevents x.split() from being evaluated due to short circuiting.
For the splitter, since the number of whitespace is always nonnegative, sum(y.isspace()for y in x)+10<9 is always False and the splitting function comes into play.

Alternative 1, 59 + 60 = 119 bytes
Counter:
m=lambda x:[x.split(),sum(y.isspace()for y in x)][min([1])]

Splitter:
m=lambda x:[x.split(),sum(y.isspace()for y in x)][m in([1])]

The results of both counting and splitting are stored in a two-element list. The list is indexed by either min([1]), returning the minimum of the one-element list containing 1, or m in([1]), which returns False (equivalent to 0) as m is not contained in [1].

Alternative 2, 67 + 69 = 136 bytes
Counter:
ted=1;s=lambda x:[x.split(),sum(y.isspace()for y in x)][not s or ted]

Splitter:
ted=1;s=lambda x:[x.split(),sum(y.isspace()for y in x)][not sorted]

Like above, the results of both counting and splitting are stored in a two-element list. sorted is a built-in function which is a truthy value, so not sorted returns False (equivalent to 0). For not s or ted, since s is a function and also truthy, not s is False and ted = 1 is returned.

Alternative 3, 59 + 60 = 119 bytes
Counter:
def f(s):a=s.split();a1=len(s)-len((s*0).join(a));return a1

Splitter:
def f(s):a=s.split();a1=len(s)-len((s*0).join(a));return a
1

This is a function where splitter's result is stored in the variable a, and counter's result is stored in the variable a1. Like before, Python is fine with having just an expression on a line, in this case 1. Splitting up a1 determines what to return from the function.


CGCC sings a song together This is a code-shuffleboard answer-chaining challenge, where the answers will aim to, together, output the lyrics to this beloved 80s song.
This is the full lyrics of the song, line by line.  The first answer will contain a program that will output the first line of the song (We're no strangers to love). The second will do the same, but for the second line (You know the rules and so do I) and so on. Some answers (the 7th, 14th, 22nd, 29th, 36th, 45th, 51st, 54th, 61st and 68th) will output a blank line.
Each answers' program, however, must be irreducible, meaning that it must not output the correct line if any non-zero number of characters (not necessarily consecutive) are removed.

print("We're no strangers to love") is an irreducible Answer 1 in Python 3
if 1: print("We're no strangers to love") is not, as we can remove if 1:  and it'll still output the first line
print("We're no str" + "angers t" + "o love") is also not, as the two " + "s can be removed, and it'll still produce the correct output.

Let \$\bar x_i\$ be the arithmetic mean of the lengths of the first \$i\$ lines, to 1 decimal place. This sequence begins \$26, 28, 32, 34, 34.6, 33\$ and converges to \$\bar x_{74} = 24.3\$ by the end of the song. Each answer has a score, which will eventually determine the overall winner. The score for the \$i\$th answer is defined as:

If the \$i\$th answer is \$n\$ bytes long, its score is \$|n - \bar x_i|\$

So, if the first answer is 10 bytes long, its score is \$16\$, and if the 72nd answer is 2 bytes long, its score is \$|2 - 24.2| = 22.2\$. A user's overall score is the arithmetic mean of the scores of all their answers. The user with the lowest overall score wins.
The full sequence of \$\bar x_i\$; the left column is \$i\$, the right is \$\bar x_i\$. Collapse the "Arguments" element for easier viewing.

Rules

You may either:

Output the line to STDOUT, or your language's closest alternative; or,
Return the line from a function

You should take no input, aside from an optional empty input

Each language may only be used once. This includes different versions of a language, such as Python 2 and Python 3. Generally, if two languages are considered versions of each other, such as Seriously and Actually, then only one is allowed to be used.

You may not post 2 answers in a row

You must wait 1 hour between answers

The challenge will end when the 74th answer is posted, at which point I will accept an answer of the winner's choice

Please format your answer as the following:
# [Num]. [Lang], score [score]

    code

[Try it online!]

[Everything else]

4. Husk, score 0
¨You wouldn't get this fromȦ?ØoĠÜy

Try it online!
Just wanted to use Husk before someone else could steal it. Simply a (partially) compressed string.


Find the sum of all possible base representations The objective of this challenge is to write a program to convert an inputed string of what can be assumed as containing only letters and numbers from as many bases between 2 and 36 as possible, and find the base 10 sum of the results.

The input string will be converted to all the bases in which the number would be defined according to the standard alphabet for bases up to 36: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ. For example, the input 2T would be valid in only bases 30 and up. The program would convert 2T from bases 30 through 36 to decimal and sum the results.

You may assume that the input string contains only letters and numbers. Your program may use uppercase or lowercase; it can, but does not need to, support both.

Test cases

Sample input: 2T

Chart of possible bases

Base   Value
30     89
31     91
32     93
33     95
34     97
35     99
36     101

Output: 665

Sample input: 1012

Chart of possible bases:

Base   Value
3      32
4      70
5      132
6      224
7      352
8      522
9      740
10     1012
11     1344
12     1742
13     2212
14     2760
15     3392
16     4114
17     4932
18     5852
19     6880
20     8022
21     9284
22     10672
23     12192
24     13850
25     15652
26     17604
27     19712
28     21982
29     24420
30     27032
31     29824
32     32802
33     35972
34     39340
35     42912
36     46694

Output: 444278

Sample input: HELLOworld

Chart of possible bases

Base   Value
33     809608041709942
34     1058326557132355
35     1372783151310948
36     1767707668033969

Output: 5008425418187214

An input of 0 would be read as 0 in all bases between 2 and 36 inclusive. There is no such thing as base 1.

This is code golf. Standard rules apply. Shortest code in bytes wins.

Python 3, 72 71 69 bytes
Thanks to FryAmTheEggman for saving a byte!
Thanks to DSM for saving 2 bytes!
N=x=0
y=input()
while N<36:
 N+=1
 try:x+=int(y,N)
 except:0
print(x)


When will Brexit happen? Well, Brexit happened. And Sky News, being the geniuses they are, have decided to create a countdown on the side of a bus.

Your job is to do something similar. The UK leaves the the EU on 31st of March 2019 and you have to create a digital countdown for this that changes every second (with a 0.05 second deviation allowed).
Input
Your program should take absolutely no input. It is banned!
Output
It should output the time until Brexit in the format ddd:hh:mm:ss. Leading and trailing newlines are allowed but the display should stay in the same place each time. It should look as though it is actually decreasing in place. As pointed out by @AnthonyPham this doesn't mean printing enough newlines to "clear" the screen, this means that you must actually clear the screen.
An output like this isn't allowed:
100:20:10:05
100:20:10:04

Neither is this
100:20:10:05
*A thousand newlines*
100:20:10:04

as they're on more than one line.
You don't have to worry about after Brexit. Your program only has to work up to 31/3/2019
Rules

Standard loopholes are disallowed
This is code-golf so shortest code in bytes wins.
Error messages (although I can't think how) are disallowed
The code should be able to be run in 2 years time (when the UK leaves the EU) and should display the actual time and not start from 730 again (see below)

Countdown rule
The countdown should not be hard-coded and should be able to run at any time before Brexit finishes and still produce the correct result. When a new day is begun the hour should follow the below format
712:00:00:01
712:00:00:00
711:23:59:59

Let me say again, the date Brexit finishes is 31/3/2019 at midnight for convenience (31:3:19 00:00:00 or 31:3:2019 00:00:00 or any other format you want)
NB: I think I have everything but I didn't post this in the Sandbox, otherwise the timing could have been off. Feel free to post any suggestions for improvements because it isn't perfect.

JavaScript, 134 129 113 bytes

setInterval("d=-new Date;document.body.innerHTML=`<pre>${d/864e5+17986|0}:`+new Date(d).toJSON().slice(11,19)",1)

Edit: Saved 2 bytes thanks to @Shaggy. Saved 11 bytes thanks to @l4m2.


Rotate a two-dimensional list by 45 degrees TASK

The goal is to write a program that rotates any two-dimensional list by 45 degrees, it must be able to do this up to 7*45 (at once) before returning the list. The list will not necessarily be square or rectangular. You must include output for the examples in your answer. It must also work for cases that are not in the examples... circles, triangles etc. You cannot use a pre-existing function to do the whole thing.

All lists will have at least one axis of symmetry (N,S,E,W). All sublists are to be assumed as center-aligned. Odd-even lists will shift to the left one to align properly. See example 4 for gaps in the middle of a sublist.

INPUT

Your program will use a variable named l containing the list, and a variable named n specifying the amount the list will be rotated (n*45) (n will always be less than 7, and can be 0). It will have to accept l containing sublists of any printable data type (decimal, List, int, String[].. etc), but sublists will only contain one data type at a time.

You do not need to accept console input or use stdin. The lines specifying the test values of l and n are not included in the character count, but must be included in the submitted code.

OUTPUT

Your program must print the list in the correct orientation, NIL can be used to pad lists if you desire, but padding is not necessary (you get a smiley face if they are padded, though). Sub-lists do not have to be indented or separated by newlines as in the examples.

EXAMPLES

1

IN
l=
[[0 , 1 , 2],
 [3 , 4 , 5],
 [6 , 7 , 8]]
n=1

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

2

IN
l=
[[a , b , c , d],
 [e , f , g , h]]
n=2

OUT
[[e , a],
 [f , b],
 [c , g],
 [h , d]]

3

IN
l=
[[A , B , C , D , E , F],
     [G , H , I , J],
         [K , L],
         [0 , 8],
         [M , N],
     [O , P , Q , R],
 [S , T , U , V , W , X]]
n=7

OUT
[          [F],
         [E],
       [D , J],
     [C , I],
   [B , H , L],
 [A , G , K , 8],
           [0 , N , R , X],
             [M , Q , W],
               [P , V],
             [O , U],
               [T],
             [U]          ]

4

IN
l=
[[9 , 8 , 7 , 6],
     [5],
 [4 , 3 , 2 , 1],
     [0]        ]
n=3

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

5

IN
l=
[    [Q],
 [X ,NIL, Y],
     [Z]    ]
n=2

OUT
[    [X],
 [Z ,NIL, Q],
     [Y]     ]

Python – 234 201

# example for defining lists and n
l=[[1,2,3,4],
     [5],
   [6,7,8,9]]
n=1

# counting code
j=1j
m=max(map(len,l))+len(l)
M=range(-m,m)
e=enumerate
d=[[v for x in M for i,u in e(l)for k,v in e(u)if[1,1+j,j,j-1,-1,-j-1,-j,1-j][n]*(k-(len(u)-1)/2+j*i)==x+y*j]for y in M]
print[x for x in d if x]

Ungolfed Version

rotation = [1,1+1j,1j,1j-1,-1,-1j-1,-1j,1-1j][n]
m = max(map(len,l))+len(l)
output = []
for y in range(-m,m):
    line = []
    for x in range(-m,m):
        for i,sublist in enumerate(l):
            for k,entry in enumerate(sublist):
                if rotation * ( k-(len(sublist)-1)/2 + i*1j ) == x + y*1j:
                    line += [entry]
    if line != []:
        output += [line]
print output

This uses that multiplication (of a complex number) by a complex number corresponds to rotating and stretching. [1,1+1j,1j,1j-1,-1,-1j-1,-1j,1-1j] are complex numbers corresponding to the required angles and using the smallest scaling factor such that for an integer complex input the output is again integer complex.


Character Counting System GOAL :
 To Implement a character counting program

This is how this counting system works :

input of the program is a set of printable ASCII characters . the program counts each type of character , and outputs the number of each character , starting from first mentioned character to last mentioned character .

Example :

input : aaaabbbbbcccc    123445b
output : 4 6 4 4 1 1 1 2 1

Which 4 is number of as , 6 is number of bs , 4 is number of cs , 4 is number of spaces () and so on . Also you can split answers with space (like example) , EOL , or anything other than numerals .

Rules

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet

It's optional to mention the ungolfed version of program and/or a short explanation  .

Test input :  ThIs Is ThE iNPUT , WITH 72/2 CHARS!

Test output :  4 2 3 2 7 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1

MATL, 3 bytes
8#u

Input is a string enclosed with quotation marks (which is allowed by default)
Try it online!
Explanation
u is the unique function, which essentially removes duplicates. It can produce up to four outputs. The fourth output is the count of unique characters, identified in order of appearance.
8# specifies that the fourth output of u should be produced. In general, 2# means "produce two outputs", 3# means "produce three outputs" etc. When the maximum number of function outputs is reached, larger numbers mean "take the first output only", or "the second only" etc. Thus, since u has four possible outputs, 4# would produce all four outputs; 5# produces the first, 6# the second, etc.