Abstract Rewriting Challenge (Robbers) This is a somewhat proof-golf-like cops-and-robbers challenge. This is the robbers' thread; the cops' thread is here.

Robbers

The cops will post abstract rewriting systems. Your task is to crack their submissions by proving that the target string either can or can not be reached from the source string by applying their rewrite rules. (You can do this either by posting a sequence of rewrite rules that starts with the source string and ends with the target, or by proving mathematically that this does, or does not, exist.)

See the cops' thread for details and definitions.

jimmy23013

Let's work backwards for this one. We first turn the digits into their binary representations. We go from VW626206555675126212043640270477001760465526277571600601 to VW++__+_++__+____++_+_++_++_+++_++++_+__+_+_++__+___+_+____+___++++_+______+_+++___+__++++++________++++++____+__++_+_++_+_+_++__+_+++++++_++++__+++_______++______+. Next, we keep applying the inverse of DCW:W+ and DW:W_ until we clear all symbols. Our result is now VDCDCDDDCDDCDCDDDCDDDDDCDCDDCDDCDCDDCDCDDCDCDCDDCDCDCDCDDCDDDCDDCDDCDCDDDCDDDDCDDCDDDDDCDDDDCDCDCDCDDCDDDDDDDCDDCDCDCDDDDCDDDCDCDCDCDCDCDDDDDDDDDCDCDCDCDCDCDDDDDCDDDCDCDDCDDCDCDDCDDCDDCDCDDDCDDCDCDCDCDCDCDCDDCDCDCDCDDDCDCDCDDDDDDDDCDCDDDDDDDCW. We now want to make this string match VD+C+W; that is, we want to move all of the Ds to the left of all of the Cs. This can be done by reversing DCC:CD. We do this by repeating the following algorithm:

Find the first D that is to the right of a block of Cs.
Move the D to the left of that block.
Double the number of Cs.

Through some math, we can determine that we will end up with 123 Ds and 4638704741628490670592103344196019722536654143873 Cs (you were right about this not fitting in an SE answer... I doubt this would fit if stored as states of all of the atoms in the Earth combined :P).

If we keep applying the reverse of V:VD, we can get rid of all of the Ds now, so we get VCCC.......CCCW. We convert the V back into YZ. Now we have YZCCC.......CCCW.

We want to be able to get rid of all of the Cs and have it in the form YAAA...AAABBB...BBBZW. Fortunately, this can be done by the following method. Firstly, we inverse-apply YB:Y 587912508217580921743211 times to get YBBB.......BBBZCCC.......CCCW. Then, we repeat the following sequence of steps (where [?*] means any number of ?, not necessarily greater than zero):

Inverse-apply CZ:ZC 587912508217580921743211 times to get Y[A*]BBB.......BBBCCC.......CCCZCCC.......CCCW
Inverse-apply CB:BC many times to get Y[A*]BCBCBC.......BCBCBCZCCC.......CCCW
Inverse-apply AZ:Z and AB:BCA many times to get Y[A*]ABBB.......BBBZCCC.......CCCW

Through induction, we see that we can move the BZ combination all the way to the end (except before the W) and then the number of As is 1/587912508217580921743211 of the number of Cs, leaving us with 7890127658096618386747843 As. We now have YAAA.......AAABBB.......BBBZW. Convert the ZW back to a U, then inverse-apply U:BU many times to keep only 2 Bs and then convert the BBU to a T, and you now have YAAA.......AAAT. Then, you can inverse-apply T:AAAAAT many times to get YAAAT because the number of As was 3 larger than a multiple of 5.

Thanks for the challenge!


Rooting for Trees With the Right Nodes Background
A rooted tree is an acyclic graph such that there is exactly one path from one node, called the root, to each other node. A node v is called the parent of another node u if and only if the path from the root to u goes through v and there is an edge connecting u and v. If node v is the parent of node u, node u is a child of node v.
Task
Write a program or function that, given a positive integer number of nodes and a set of non-negative integer numbers of children each parent has, outputs the number of possible rooted trees with that number of nodes (including the root) and each vertex having a number of children in the set, not counting those trees isomorphic to trees already found.
Two trees are isomorphic if one can be transformed into another by renaming the nodes, or in other words look the same when the nodes are unlabelled.
Examples
We shall represent trees as a 0-indexed list of children per index where 0 represents the root, for example [[1],[2],[]] represents that the root 0 has 1 as a child, node 1 has node 2 as a child, and node 2 has no children.
Inputs n=3 and set = [0,1,2]. This is equal to binary trees with three nodes.
The two possible trees are: [[1],[2],[]] and [[1,2],[],[]]. Because they are identical in structure to the two trees, we count neither [[2],[],[1]] nor [[2,1],[],[]]. There are two trees, so the output is 2 or equivalent.
Here is a visualization:  You can see that the second set of two trees are identical in structure to the first set of two and are thus not counted. Both sets are composed of two trees which have one of the following two structures (the root is the node at the top):

Inputs n=5 and set=[0,2]. The only possible tree is [[1,2],[3,4],[],[],[]]. Note that, for example, [[1,2],[],[3,4],[],[]] and [[1,3],[],[],[2,4],[]] are not counted again because they are isomorphic to the sole tree which is counted. The output is 1 or equivalent.
Here is another visualization:

Clearly, all of the trees are isomorphic, so only one is counted. Here is what the trees look like unlabeled:

Input n=4, set=[0,2]. There are no possible trees because each time children are generated from a node, there are either 0 or 2 more nodes. Clearly, 4 nodes cannot be produced by adding 2 or 0 successively to 1 node, the root. Output: 0 or falsey.
Input/Output
Input and output should be taken in a reasonable format.
Input is a positive integer representing n and a list of non-negative integers representing the set of valid numbers of children.
The output is a non-negative integer corresponding to how many trees can be formed.
Test cases
n ; set ; output
3 ; [0,1,2] ; 2
5 ; [0,2] ; 1
4 ; [0,2] ; 0
3 ; [0,1] ; 1
3 ; [0] ; 0
1 ; [0] ; 1
6 ; [0,2,3] ; 2
7 ; [0,2,3] ; 3

Rules

The set of numbers of children will always include zero.
The root node always counts as a node, even if it has no children (see the 1; [0] test case)
This is code-golf, so shortest code wins.

Haskell, 120 bytes

_#0=1
i#j=div(i#(j-1)*(i+j-1))j
s!n|let(0?1)0=1;(0?_)_=0;(m?n)c=sum[s!m#j*((m-1)?(n-j*m)$c-j)|j<-[0..c]]=sum$(n-1)?n<$>s

Try it online!

How it works

i#j is i multichoose j.

(m?n)c is the number of n-node trees with c children at the root, each of which has a subtree of at most m nodes.  It’s computed by summation over j, the number of these subtrees that have exactly m nodes.

s!n is the number of n-node trees.  It’s computed by summation over c ∈ s, the number of children at the root.


Two Makes All The Difference - Robbers For the main cops' challenge, click here

  NOTICE - This challenge is now closed. Any cracks which are posted now will not be counted on the leaderboard and the accepted answer will not change.

Challenge

Given the original program, its output and the output of the changed program, you have to find out which characters need to be changed, removed or added to get the expected output.

When you crack someone's code, leave a comment with a link to your crack on their answer.

Formatting

# [<language>, <username of program owner>](<link to answer>)

## Description

<description of change and how you found it>

## Code

<changed code>

Winning

The person who has cracked the most solutions wins.

Leaderboard

13 cracks:

Dennis

8 cracks:

Alex Van Liew

5 cracks:

Sp3000
isaacg

3 cracks:

Luis Mendo
jimmy23013
Dom Hastings

2 cracks:

mbomb007
Sluck49

1 crack:

TheNumberOne
Jakube
ProudHaskeller
David Zhang
samgak
paul.oderso
rayryeng
mgibsonbr
n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳
Stewie Griffin
abligh

Ruby, histocrat

Description

Changed x to be an array instead of scalar by adding *

Changed the last 9 to be a string instead of a number by adding ?

The result is made of an array with a single element ([9]) multipled 9 times then imploded with "9" as separator.

Code

x=*9;puts x*9*?9


Movie Title Styled String Challenge

Ever seen those movie trailer titles (namely Martian, Interstellar, etc) where they have huge gaps in between letters slowly spreading out?

The challenge is to recreate this effect given a string, gap multiplier and direction, by inserting appropriate amount of spaces in between the letters.

Example

Input: 'INTERSTELLAR', Gap multiplier: 1.0, Direction: Increasing Inward

Output: I N  T   E    R     S      T     E    L   L  A R

The spacing is: [1, 2, 3, ... , 3, 2, 1]; replacing the spaces with '.' to better demonstrate the spacing:

I.N..T...E....R.....S......T.....E....L...L..A.R

Input: 'INTERSTELLAR', Gap multiplier: 0.5, Direction: Increasing Inward

Output: IN T E  R  S   T  E  L L AR

The spacing is multiplied by 0.5, therefore we get [0, 1, 1, 2, ... 2, 1, 1, 0] from integer division; using '.':

IN.T.E..R..S...T..E..L.L.AR

Input: 'CODEGOLF', Gap multiplier: 2.0, Direction: Increasing Outward

Output: C        O      D    E  G    O      L        F

The spacing is multiplied by 2, increasing outward, therefore we get [8,6,4,2,4,6,8]; replacing with '.':

C........O......D....E..G....O......L........F

Input: 'CODEGOLF', Gap multiplier: 0.4, Direction: Increasing Outward

Output: C O DEGO L F

The spacing is multiplied by 0.4, increasing outward, therefore we get [1,1,0,0,0,1,1]; replacing with '.':

C.O.DEGO.L.F

Rules

Takes 3 input: string, gap multiplier and direction
If input string is odd in length (even in # of gaps) e.g. 'HELLO', the spacing of the inner most 2 gaps should be the same H E  L  L O
The direction and gap multiplier can be parsed however you want, e.g. you could use -2 as 'increasing inward with a multiplier of 2', 1 as 'increasing outward with a multiplier of 1', etc.
It is only required to use spaces, however it is a bonus if the character filling is customizable.

Reference Animation

Have fun golfing!

JavaScript (ES6), 86 82 81 80 bytes
Input is expected in currying syntax f(s)(r), with:

s = string
r = ratio + direction: a negative float for inward or a positive float for outward

let f =

s=>r=>s.replace(/./g,(c,i)=>c+' '.repeat(n+=i<l?-r:r),l=s.length/2,n=r>0&&l*r+r)

console.log(f("INTERSTELLAR")(-1));
console.log(f("INTERSTELLAR")(-0.5));
console.log(f("CODEGOLF")(2));
console.log(f("CODEGOLF")(0.4));


Writing code for three tasks When you run your program first, it should print an integer sequence.  The
second run should print the 'Mary had a little lamb' song. The third run should
produce an ASCII image file.

Scoring

Your score will be the sum of your bytes of code and any file content at the
start of each of the 3 runs. Lowest score wins.

For example, myprog is 1500 bytes and does not change its size, but writes a 4
bytes file each run so it knows what to do on the next run. The score would be
1500 + (1500+4) + (1500+4) = 4508.

Output

The first output is this sequence of 133 integers, separated by single spaces:

0 89 98 179 188 197 269 278 287 296 359 368 377 386 395 449 458 467 476 485
494 539 548 557 566 575 584 593 629 638 647 656 665 674 683 692 719 728
737 746 755 764 773 782 791 809 818 827 836 845 854 863 872 881 890 908
917 926 935 944 953 962 971 980 1079 1088 1097 1169 1178 1187 1196 1259
1268 1277 1286 1295 1349 1358 1367 1376 1385 1394 1439 1448 1457 1466 1475
1484 1493 1529 1538 1547 1556 1565 1574 1583 1592 1619 1628 1637 1646 1655
1664 1673 1682 1691 1709 1718 1727 1736 1745 1754 1763 1772 1781 1790 1808
1817 1826 1835 1844 1853 1862 1871 1880 1907 1916 1925 1934 1943 1952 1961
1970

The second output is this text exactly (including capitals, punctuation, and
white space - the inconsistent punctuation is intentional):

Mary had a little lamb,
Little lamb, little lamb,
Mary had a little lamb,
Its fleece was white as snow

And everywhere that Mary went,
Mary went, Mary went,
Everywhere that Mary went
The lamb was sure to go

It followed her to school one day
School one day, school one day
It followed her to school one day
Which was against the rules.

It made the children laugh and play,
Laugh and play, laugh and play,
It made the children laugh and play
To see a lamb at school

The third output is this image in PPM ASCII(P3) format left in a file called
blue.ppm. This is the image in PNG format:

The PPM file should look something like this:

P3 50 50 255
255 255 255 255 255 255 255 255 255 255 255 255 ...
...
255 255 255

There is a copy of the full PPM file here.

Example run (on Linux)

# ls
myprog
# interpreter myprog
0 89 98 179 188 197 269 278 287 296 359 ...
# interpreter myprog
Mary had a little lamb,
Little ...
# interpreter myprog
# ls
blue.ppm
myprog
# cat blue.ppm
P3 50 50 255
255 255 255 255 255 ...

Rules

Your code may modify itself.
Running the program a fourth time is undefined behaviour.
You may write to a file in the current directory, but the size of this file
will add to your score at the start of each run. The final PPM file is
excluded from this.
The first two outputs are to stdout (or similar). The last output is written
to a file, with nothing sent to stdout.
The first two outputs may optionally have a trailing white space character (e.g. space or line feed).
You may not use compression or image libraries. You may use your own
compression or image functions but this code must be included in your program.
The standard loopholes are prohibited.


Format a Swedish phone number In some parts of the world, phone numbers are fixed-length, apparently. That sounds boring, though.

For this challenge, your task is to take the digits of a what is presumed to be a valid phone number, and format it based on some simplified rules around what a phone number looks like.

Input format

Your input will consist of nothing except the digits 0 through 9, and the input will contain between five and ten of them (both inclusive). Every input will be a valid phone number, according to the following simplified rules:

A full phone number consists of eight to ten digits and can be divided into an optional area code of two to four digits (the first of which is 0), and a mandatory subscriber number of five to eight digits (the first of which is not 0)
When calling someone from a landline phone who has the same area code as you, you do not need to dial the area code. Thus, your program must be able to handle inputs consisting only of a subscriber number with no area code.
The subscriber number consists of 5 to 8 digits, and the first one isn't 0.
The area code, if present, begins with 0, and has 2 to 4 digits. For this challenge's purposes, the length depends on the second digit:

The second digit of the area code will never be 0.
If the second digit is 8, the entire area code will be 2 digits long (so the entire area code will be 08)
If the second digit is 1, 2, 3, 4, or 7, the area code will be 3 digits long.
If the second digit is 5, 6, or 9, the area code will be 4 digits long.

However, for some inputs, the above cutoff point would cause the subscriber number to be too short or begin with a 0. Since we know the input is a valid phone number (because I say so) we have to conclude that the length of the area code is different from the above. If the length listed above does not work, you should pick a length which works, preferring 3-digit codes over 4-digit codes, and preferring either of those to 2-digit codes. You will not need to handle inputs like 0801234, which are invalid for all those cutoff points.

Output format

Your output should be the area code, followed by a dash (only if an area code is present), followed by the subscriber number which should be grouped in one of the following manners (with the groups separated by a single space):

xxx xxx xx
xxx xx xx
xx xx xx
xxx xx

That means numbers with area codes specified will have one of the following formats:

0x-xxx xxx xx
0x-xxx xx xx
0x-xx xx xx
0xx-xxx xx xx
0xx-xx xx xx
0xx-xxx xx
0xxx-xx xx xx
0xxx-xxx xx

Test cases

All numbers were randomly generated, and some of them could potentially be in use, so while I don't expect any of them to belong to anyone in particular, please don't try to call them.

27983516    ->  279 835 16     # No area code, 8 digits
6278304     ->  627 83 04      # No area code, 7 digits
627830      ->  62 78 30       # No area code, 6 digits
11865       ->  118 65         # No area code, 5 digits
067934821   ->  0679-348 21    # Simple 4+5
0927586130  ->  0927-58 61 30  # Simple 4+6
0374821096  ->  037-482 10 96  # Simple 3+7
042807961   ->  042-80 79 61   # Simple 3+6
04629873    ->  046-298 73     # Simple 3+5
0897106384  ->  08-971 063 84  # Simple 2+8
081859302   ->  08-185 93 02   # Simple 2+7
08379451    ->  08-37 94 51    # Simple 2+6
0480936572  ->  0480-93 65 72  # Area code couldn't be 048 to prevent subscriber number starting with 0
0957024168  ->  095-702 41 68  # Area code couldn't be 0957 for the same reason
06057291    ->  060-572 91     # Area code couldn't be 0605 because of subscriber number's length
04809714    ->  04-80 97 14    # Area code could neither be 048 nor 0480 didn't help
080062517   ->  0800-625 17    # Area code could neither be 08 nor 080
09106574    ->  09-10 65 74    # Area code had to be shortened twice from 0910 because shortening it to 091 didn't work

This is code-golf, shortest code in each language wins.

Retina, 78 73 bytes
(0(8|[569].?.?|..?0?)(?=[^0]....))?(...?)?(...?)(..)$
$1$#1*-$3$#3* $4 $5

Inspired by both @mazzy's PowerShell answer and @NahuelFouilleul's Perl 5 answer, so make sure to upvote them both as well!
-5 bytes thanks to @Neil.
Try it online.
Explanation:

Match the digit groups like this:
(                                )? # An optional group 1, which consists of:
 0                                  #  A leading 0
  ( |         |     )               #  followed by either (ignored inner group 2):
   8                                #   A single 8
    |[569]                          #   or one of 569,
          .?.?                      #      with one or two optional chars
              |.                    #   or any character,
                .?                  #      with one optional character,
                  0?                #      and an optional trailing 0
                     (?=        )   #  followed by an uncaptured inner group with:
                        [^0]        #   A character which is NOT a 0
                            ....    #   followed by any four characters
(    )?                             # An optional group 3, which consists of:
 ..                                 #  Two characters,
   .?                               #  followed by an optional character
(    )                              # A mandatory group 4,
 ...?                               #  which is similar as group 3
(  )                                # Followed by a mandatory group 5
    $                               # (at the end of the string), which consists of:
 ..                                 #  Any two characters

Then replace it with:
$1                                  # The content of group 1 (possibly empty)
  $#1*                              # If group 1 isn't empty:
      -                             #  A "-"
       $3                           # The content of group 3 (possibly empty)
         $#3*                       # If group 3 isn't empty:
             <sp>                   #  A " "
                 $4                 # The content of group 4
                   <sp>             # A " "
                       $5           # The content of group 5


Simplification of numbers How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook!
Obviously, the number 402 is easier to remember than the number 110010010, and the number 337377 is easier to remember than the number 957472.
This means that the memorized number, on the one hand, should contain as few digits as possible, and on the other hand, it is desirable that the number contains as many repeating numbers as possible.
As a criterion for the difficulty of remembering, we take the sum of the number of digits in number and the number of different digits in number. A memorized number can be written in another number system, perhaps then it will be easier to remember. For example, the number 65535 in the hexadecimal notation looks like FFFF.
Task
You need to write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be selected in the range from 2 to 36, then the numbers 0-9 and the English letters A-Z can be used to represent the number.
Input
The input contains a decimal integer from 1 to 999999999.
Output
The output must contain the base of the number system (from 2 to 36), minimizing the criterion of memorization complexity, and the number in the selected number system, separated by one space. If several bases give the same value for the criterion, then choose the smallest among them.
Notes

The letters must be uppercase(A-Z).

Test Cases
Input             Output
1               2 1
2              3 2
65535       16 FFFF
123          12 A3

Perl 6, 55 54 bytes

-1 byte thanks to Jo King.

{~map({$^b,.base($b)},2..36).min:{@$_+.Set}o*[1].comb}

Try it online!


The forbidden built-in In the standard loopholes, the following is forbidden:

  Claiming that your answer is written in "MyOwnLanguage", where the command x means "read a sequence of numbers, split them into groups of three, and print the last numbers of those groups where the second number is less than the first"

Here, we are going to do the exact same thing.

Task

Given a sequence of positive integers, whose length is divisible by 3, split them into groups of three, and print the last numbers of those groups where the second number is less than the first.

Testcases

Input               Output
[]                  []
[1,2,3,4,5,6,7,8,9] []
[2,1,3,5,4,6,8,7,9] [3,6,9]
[3,1,4,1,5,9,2,6,5] [4]
[100,99,123]        [123]
[123,123,456]       []
[456,123,789]       [789]

Scoring

This is code-golf. Shortest answer in bytes wins.

Standard loopholes apply, so remember not to have a built-in command x that does this task.

Octave, 32 bytes

@(L)L(x=3:3:end)(diff(L)(x-2)<0)

Try it online!
or
Verify test cases!
L3 = L(3:3:end)  %extract last elements of groups
d= diff(L)       % first difference of the list
y=d(1:3:end)     %extract first elements of each subgroup of the difference
idx = y<0        %check for negative numbers
result = L3(idx)


Almost Lexicographical List Comparison Input

Two lists A and B of nonnegative integers.

Output

Either 1, 0, or -1, depending on whether A is larger than, equal to, or smaller than B with respect to the twisted lexicographical ordering as defined below.
If you want, you can replace 1, 0 and -1 with any other three constant values.

The twisted lexicographical ordering is like the ordinary lexicographical ordering, in that you compare the lists element by element, and decide their order at the first differing index.
However, in the twisted version we use a different ordering for nonnegative integers at each index.
Namely, at every index i (indexing starts from 1), the order of the first i nonnegative integers (from 0 to i-1) is reversed, and they are moved above all the other numbers.
Moreover, the "missing element" that signifies one list being shorter than the other is moved directly below i-1.
Visually, the order at index i is

i < i+1 < i+2 < i+3 < ... < [missing element] < i-1 < i-2 < i-3 < ... < 2 < 1 < 0

Note that the first ... denotes infinitely many numbers. This means that the following lists are in ascending order with respect to the twisted lexicographical ordering:

[3,2,3,4]
[3,2,3,5]
[3,2,3,10]
[3,2,3,1341]
[3,2,3]
[3,2,3,3]
[3,2,3,2]
[3,2,3,1]
[3,2,3,0]

Rules

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

Test Cases

Output 1:
[0] []
[] [1]
[] [1,2,1,2]
[2,1] [1,1]
[0,1,2] [0,2,1]
[3,0] [3,1]
[3,1] [3]
[2] [2,2]
[2] [2,23]
[2,24] [2,23]
[2,1] [2,23]

Output 0:
[] []
[0] [0]
[1,1] [1,1]
[2,1,2] [2,1,2]

Output -1:
[1,2,1,1,2] [1,2,1,1,1]
[1,2,1,1,5] [1,2,1,1,4]
[1,2,1,1,5] [1,2,1,1]
[1,2,1] [1,2,1,1]
[1,2,1,1,5] [1,2,1,1,6]
[1,2,1,1,6] [1,2,1,1,7]

Python 2, 76 bytes

c=lambda*a:cmp(*[[(max(i-x,-1),x)for i,x in enumerate(L)]+[(0,)]for L in a])

This replaces each integer in both lists with a 2-tuple to account for the twisted ordering. Python 2's cmp builtin does the rest.

Usage:

>>> c([1,2,1,1,6], [1,2,1,1,7])
-1


Display a clock face Display the 12 numbers on a clock face exactly like this:

           12
     11           1

 10                   2

9                       3

  8                   4

      7           5
            6

To better see the grid, here's one with dots:

...........12............
.....11...........1......
.........................
.10...................2..
.........................
.........................
9.......................3
.........................
.........................
..8...................4..
.........................
......7...........5......
............6............

Note that the grid is stretched in width by a factor of two to make it look more square.

Also note that two-digit numbers are aligned with their ones digit in place. The 9 digit should be flush against the left.

Return or print the result as a multiline string (not a list of lines). Any trailing spaces are optional. The final newline also optional.

Charcoal, 40 bytes

Ｆ¹²«Ｍ⁻↔⁻¹⁴⊗÷×⁴ι³¦⁸⁻⁴↔⁻⁷÷×⁴﹪⁺³ι¹²¦³Ｐ←⮌Ｉ⊕ι

Try it online! Link is to verbose version of code. Explanation: Computes the offsets between each digit mathematically. Charcoal is 0-indexed (thus the ⊕ to output \$ 1 \ldots 12 \$), so the formulae for the horizontal and vertical offsets are as follows:

$$ \begin{align} \delta x &= \left \lvert 14 - 2 \left \lfloor \frac {4i} 3 \right \rfloor \right \rvert - 8 \\ \delta y &= 4 - \left \lvert 7 - \left \lfloor \frac {4i'} 3 \right \rfloor \right \rvert \end{align} $$

where \$ i' = i + 3 \pmod {12} \$.


Application screen shot Write the minimal code you need to take a screenshot of your application window. I am not asking for a function or program; just only a code segment.

It has obviously to be a GUI application; console applications not allowed.

Input:

None.

Output:

The valid outputs are:

Clipboard. Then post a screenshot of the Paste contents on a drawing program.
A file. Upload it somewhere and post a link to it here.
Inside any other window different from the window that was shoot. Post screenshot of the new window here.

As it is code-golf minimum number of characters wins!

Java 8, 82 80 77 bytes

Class that extends Frame:

ImageIO.write(new Robot().createScreenCapture(bounds()),"png",new File("a"));

Regular Class 98 Bytes:

ImageIO.write(new Robot().createScreenCapture(Frame.getFrames()[0].bounds()),"png",new File("a"));

Uses deprecated bounds() method.


The Art of Word Shaping The Art of Word Shaping
Given a binary matrix, and a string of letters, replace all 1's in the matrix from left, to right with the letters of the string. Once the letters have been formed into the shape of the matrix, print the matrix, replacing 0's with spaces. It's probably easier to just give an example or two.

Case: Base case...
Input One:
[0,0,1,0,0]
[0,1,0,1,0]
[1,0,0,0,1]
[0,1,0,1,0]
[0,0,1,0,0]

"PPCGPPCG"

Output One:
  P
 P C
G   P
 P C
  G

Case: If the input string is longer than the number of ones...
Input Two:
[1,0,0]
[0,1,0]
[1,0,1]

lambda

Output Two:
l
 a
m b

Case: If the input string is shorter than the number of ones...
Input Three:
[1,1,1]
[1,0,1]
[1,1,1]

PPCG

Output Three:
PPC
G P
PCG

Available Assumptions

You may assume the input string is never empty.
You may assume the matrix will never be empty.
You may not assume that the binary matrix will never be all zeros.

Rules

If the string is shorter than the number of ones, repeat the string; all ones must be replaced.
If the string is longer than the number of ones, only use what is needed.
You may use True/False in place of integers/bits for the input.
Trailing spaces ARE REQUIRED, all zeros must be replaced with spaces.
A single trailing newline is acceptable.
This is code-golf, lowest byte count wins.

Vim, 44 42 bytes

qqy$P0xjf1"_xP{@qq@q:s/0/ /g^M:s/,/^V^M/g^M{D

Saved 2 bytes thanks to @DjMcMoylex!

Here, the ^M is a literal newline, and the ^V is CTRL-V

Takes the input in this format:

PPCG
00100,01010,10001,01010,00100

Disclaimer: If the string is longer than ~40 chars long, your computer might run out of ram.

Explanation:

qq             @qq@q                            # Start recording a recursive macro.
  y$P0x                                         # Duplicate the string and cut out the first character
       jf1"_xP{                                 # Find the first 1, and replace it with the cut character from the string.
                                                # Now we have replaced all the 1's with their respective character, but we still have the array in the original format, and we have the string massivly duplicated at the first line, so we need to clean it up:
                    :s/0/ /g^M                  # Replace all 0's with a space
                              :s/,/^V^M/g^M     # Replace all ,'s with a newline. The ^V acts like a backslash, it escapes the newline so that the command isn't run too soon
                                           {D   # Delete the first line

Here's a gif of me "running" the "program":


The minimum fibonacci challenge! Challenge

  In this task you would be given an integer N (less than 106), find the minimum way in which you could sum to N using only Fibonacci numbers - this partition is called Zeckendorf representation.

You could use any Fibonacci number more than once and if there is more than one representation output any.

For example if the input is 67 then one possible output could be using the Fibonacci numbers 1,3,8,55 which is also the minimum number of Fibonacci numbers that could be used to get the sum 67.

The input N is given on a single line, the inputs are terminated by EOF.

Examples

Given in the format input: output

0: 0
47: 34+13
3788: 2584+987+144+55+13+5
1646: 1597+34+13+2
25347: 17711+6765+610+233+21+5+2
677: 610+55+8+3+1
343: 233+89+21
3434: 2584+610+233+5+2

Constraints

The number of inputs would not exceed 106 values.
Your program should not run more than 5 seconds for all inputs.
You can use any language of your choice.
Shortest solution wins!

Motorola 68000 assembly - 34 bytes

(GNU assembler syntax)

| short min_fib_partition(long N asm("%d2"), long *out asm("%a0"))
min_fib_partition:
    | Generate Fibonacci numbers on the stack (-1, 1, 0, 1, 1, 2, 3, ..., 1134903170).
    moveq #-1, %d0          | A = -1
    moveq #1, %d1           | B = 1
generate_loop:
    move.l %d0, -(%sp)      | Push A to the stack.
    exg.l %d0, %d1          | A' = B
    add.l %d0, %d1          | B' = A + B
    bvc.s generate_loop     | Stop when signed long overflows.

    | Go back up the stack, partitioning N using the greedy algorithm.
    moveq #0, %d0           | Initialize return value (number of terms).
subtract_loop:
    move.l (%sp)+, %d1      | Pop a Fibonacci number F off the stack.
    cmp.l %d1, %d2          | If N < F, continue to smaller Fibonacci number.
    blt.s subtract_loop
    addq.w #1, %d0          | Increment the term count.
    move.l %d1, (%a0)+      | Append F to the output array.
    sub.l %d1, %d2          | N -= F
    bne.s subtract_loop     | Continue if N has not yet reached zero.

    | Clear the stack by searching for that -1.
clear_stack_loop:
    tst.l (%sp)+
    bge clear_stack_loop

done:
    rts

36 → 34: Made Fibonacci generator stop on overflow rather than by counting, and fixed the 0 case so it outputs [0] rather than [].  However, passing a negative N crashes now.

The comment at the top is the C prototype of this function, using a language extension to identify what parameters go where (by default, they go on the stack).

My TI-89, with its 10MHz processor, takes 5 minutes to run this function on 1 – 1,000,000.

Although the machine code is (currently) fewer bytes than the GolfScript solution, it would probably be unfair to accept this as the shortest solution because:

Machine code is normally not counted as "source code".  Unlike source code, machine code usually has high symbol complexity and, more importantly, is unprintable.  See "Should executable binaries be considered a reasonable solution for code-golf?".
This solution only takes a single number as input, rather than multiple inputs.
This solution is a function, not a program.

If you have a TI-89/92/V200, you can download the full project here (outdated):

https://rapidshare.com/files/154945328/minfib.zip

Good luck coaxing RapidShare to give you the actual file.  Does anyone know of a good host for files this big?  8940 is an awful lot of bytes.


Maximize Sudoku King's tour Background

Sudoku is a number puzzle where, given an \$ n \times n \$ grid divided into boxes of size \$ n \$, each number of \$ 1 \$ to \$ n \$ should appear exactly once in each row, column and box.

In the game of Chess, the King can move to any of (at most) 8 adjacent cells in a turn. "Adjacent" here means horizontally, vertically or diagonally adjacent.

The King's tour is an analogy of the Knight's tour; it is a (possibly open) path that visits every cell exactly once on the given board with Chess King's movements.

Task

Consider a 6-by-6 Sudoku grid:

654 | 321
123 | 654
----+----
462 | 135
315 | 246
----+----
536 | 412
241 | 563

and a King's tour (from 01 to 36):

01 02 03 | 34 35 36
31 32 33 | 04 05 06
---------+---------
30 23 28 | 27 26 07
22 29 24 | 25 09 08
---------+---------
21 19 16 | 10 14 13
20 17 18 | 15 11 12

The tour forms the 36-digit number 654654564463215641325365231214123321.

Taking a different King's tour gives larger numbers; for example, I can find a path that starts with 65<6>56446556... which is definitely greater than the above. You can change the Sudoku board to get even higher numbers:

... | ...
.6. | ...
----+----
..6 | ...
.5. | 6..
----+----
.45 | .6.
6.. | 5..

This incomplete board gives the starting sequence of 666655546... which is the optimal sequence of 9 starting digits.

Your task is to find the largest such number for standard 9-by-9 Sudoku with 3-by-3 boxes, i.e.

... | ... | ...
... | ... | ...
... | ... | ...
----+-----+----
... | ... | ...
... | ... | ...
... | ... | ...
----+-----+----
... | ... | ...
... | ... | ...
... | ... | ...

Note that this challenge is not code-golf; the focus is to actually find the solutions rather than to write a small program that theoretically works.

Scoring & winning criterion

The score of a submission is the 81-digit number found by your program. The submission with the highest score wins. Your program should also output the Sudoku grid and the King's tour in human-readable form; please include them in your submission.

Your program may output multiple results; your score is the maximum of them.

There's no time limit for your program. If your program continues to run and finds a higher number afterwards, you can update the submission's score by editing the post. Tiebreaker is the earliest time to achieve the score, i.e. either the time of post (if it's not edited yet) or the time of edit when the score was updated (otherwise).


Create an interpreter for "Counter" "Counter" is a language I've created for the purpose of this question.

Rules

Commands are read from left to right from the first character.
Each command may be executed as it is read, or you may execute all commands together at the end.
In case of an error, all commands up till the error must be executed.
A program is written in exactly one line.
Data is stored in counters. At the start, there is exactly one counter. More can be created and deleted.
A counter holds an integer value between -100 and 100 (limits inclusive).
Exactly one counter is the selected counter at any point in time.
Counters are arranged in a 1d array, so one can move left (previous) or right (next) to change selected counter.

Commands

Any number between -100 and 100 - Set the currently selected counter to that value.
c - Create a counter immediately after the currently selected counter, make it the selected counter, and set it to 0.
d - Delete the currently selected counter, and make the previous one selected. If it is the first one, this is an error.
+ - Make the next counter the selected one.
- - Make the previous counter the selected one. (Ensure that this command is not immediately followed by a number.)
o - Output the value in the selected counter, followed by a space.
? - If the value in the selected counter is 0, apply the d command on it.
# - If the value in the selected counter is 0, ignore the next command.
 (space) - No meaning, but is to be treated like a command, if preceded by a #. Used to demarcate numbers.

Errors

Going left of the leftmost counter, or right of the rightmost counter.
Deleting the first counter.
Encountering a # as the last command. (Of course, this means all commands will get executed anyways)
A command that does not exist.
A number that's too long.

Task

Create an interpreter in any language. Code will be in a file or given as input (your choice). Shortest code wins.

Lengthy example

Consider the code:

7cc--13 12do?+?#0#o3od-7o

Here is a breakdown of the program. [] indicates the selected counter.

Cmd   Memory    Output

7     [7]
c     7 [0]
c     7 0 [0]
-     7 [0] 0
-13   7 [-13] 0
      7 [-13] 0
12    7 [12] 0
d     [7] 0
o     [7] 0     7
?     [7] 0
+     7 [0]
?     [7]
#     [7]
0     [0]
#     [0]
o     [0]
3     [3]
o     [3]       3
d     This is an error. Program terminates here.

Total output 7 3

Python3, 403 530 bytes
This is seriously golfable, but I can't think of how...
Thanks to @cat for 127 bytes!!! (I'm really bad at golfing in Python)
c=input()
a=[0]
s=0
i=0
def g(i,n):
 p=i
 if n:i+=1
 while c[i].isdigit():i+=1
 a[s]=int(c[p:i]);return i-1
def e():
 a.pop(s);s-=1
while i<len(c):
 d=c[i]
 if d.isdigit():i=g(i,0)
 elif d=='c':s+=1;a.insert(s,0)
 elif d=='d':e()
 elif d=='+':s+=1
 elif d=='-':
  if c[i+1].isdigit():i=g(i,1)
  else:s-=1
 elif d=='o':print(a[s],end=' ')
 elif d=='?':
  if a[s]==0:e()
 elif d=='#':
  if a[s]==0:i+=1
 i+=1


Print the phrase "And she said, 'But that's his.'" using only the alphabet Print the phrase And she said, 'But that's his.' using only the following characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ  No punctuation or non-alphabetic characters whatsoever.  You can use whatever programming language you want.  Whitespace is completely allowed.  Shortest program wins.

Whitespace, 417 414 349 265 bytes

265 bytes thanks to Kevin Cruijssen

Try it online!

Explained:

[S S T  T   T   T   T   T   T   N
_Push_-63_'][S S T  T   T   T   S S S N
_Push_-53_.][S S S T    T   S T N
_Push_13_s][S S S T T   N
_Push_3_i][S S S T  S N
_Push_2_h][S S T    T   S S S T T   S N
_Push_-70_space][S T    S S T   T   N
_Copy_0-based_3rd_s][S T    S S T   T   S N
_Copy_0-based_6th_'][S S S T    T   T   S N
_Push_14_t][S S T   T   S T N
_Push_-5_a][S S S T S N
_Push_2_h][S T  S S T   S N
_Copy_0-based_2nd_t][S T    S S T   T   S N
_Copy_0-based_6th_space][S T    S S T   N
_Copy_0-based_1st_t][S S S T    T   T   T   N
_Push-15_u][S S T   T   S S T   S S N
_Push_-36_B][S S T  T   T   T   T   T   T   N
_Push_-63_'][S T    S S T   S S N
_Copy_0-based_4th_space][S S T  T   T   T   S T S N
_Push_-58_,][S S T  T   S N
_Push_-2_d][S S S T T   N
_Push_3_i][S S T    T   S T N
_Push_-5_a][S S S T T   S T N
_Push-13_s][S T S S T   S T N
_Copy_0-based_3rd_space][S S T  T   N
_Push_-1_e][S S S T S N
_Push_2_h][S T  S S T   T   N
_Copy_0-based_3rd_s][S T    S S T   T   N
_Copy_0-based_3rd_space][S S T  T   S N
_Push_-2_d][S S S T S S S N
_Push_8_n][S S T    T   S S T   S T N
_Push_-37_A][N
S S N
_Create_Label_LOOP][S S S T T   S S T   T   S N
_Push_102][T    S S S _Add][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]


Pseudo-deterministic number generator Task

Write a function/full program that will be able to produce two different sequences of integers in [0, ..., 9]. You will take an input seed to decide whether to output your specific sequence or the common one. For that matter, you must choose one non-negative integer, let us call it k. When the input seed is equal to k, you will be dealing with your specific sequence s; when the input seed is anything else, you will be dealing with your common sequence c.

Both sequences should be such that the relative frequencies with which each digit appears tend to \$10\%\$. Be prepared to prove this if needed. Said another way, the running fraction of that digit's appearances needs to have a defined limit that equals \$0.1\$. Formally, this means that for every \$d \in \{0,...,9\}\$,

$$\lim_{n\rightarrow \infty}\dfrac{\left|\{i : i \in \{1\dots n\}, s_i=d\}\right|}{n} = 0.1$$

Adapted from What an Odd Function

There should be one extra restriction your sequences should satisfy: when zipped together* to form a sequence a of terms in [0, ..., 99], the relative frequency of each number should converge to 0.01 via a limit like the formula above.

*That is, the \$n\$th term of the sequence a is the two-digit number built this way: the digit in the tens place is the \$n\$th term of the sequence c and the digit in the units place is the \$n\$th term of the sequence s.

Input

A non-negative integer representing the "seed", which you use to decide whether to output the common sequence or the specific one.

Output

Your output may be one of the following:

an infinite stream with the sequence (and you take no additional input);
output the nth term of the sequence (by taking an additional input n that is 0- or 1-indexed);
output the first n terms of the sequence (by taking an additional positive input n).

Example pseudo-algorithm

Assuming I have defined seed as an integer, and for these choices I made for s and c:

input_seed ← input()
n ← input()
if input_seed = seed: print (n mod 10) # this is my sequence s
else: print ((integer div of n by 10) mod 10) # this is my sequence c

Both sequences output numbers in [0, ..., 9] and the frequency with which each digit appears tends to 0.1 as n → infinity. Similarly, zipping c and s together gives n mod 100 so it is also true that as n → infinity we have that the relative frequency with which each number in [0, ..., 99] shows up goes to 0.01.

Python 2, 23 22 bytes

Thanks @xnor for figuring out a really cool way to convert the seed to -1 or -2, which saved 1 byte.

lambda s,n:`n+9`[2/~s]

Try it online!

Input: The seed s (non-negative) and an index n (positive).
Output: The element at the nth index (the sequence is one-indexed)

If the seed is positive, the sequence is 0123456789 repeated infinitely.
If the seed is 0, the sequence is: 1111111111 2222222222 ... 9999999999 0000000000 (where each digit repeats 10 times) repeated infinitely.

How

`n+9` creates a string from a number that has at least 2 digits.
2/~s evaluates to -2 if s is 0, or -1 if s is positive
Thus `n+9`[2/~s] takes the last digit (unit digit) of \$n+9\$ if s is positive, or the second to last digit (ten digit) if s is 0.


196 algorithm code golf Write a short program for 196-algorithm.
The algorithm starts from an integer, then adds its reverse to it until a palindrome is reached.

e.g.

input = 5280
5280 + 0825 = 6105
6105 + 5016 = 11121
11121 + 12111 = 23232
output = 23232

Input

an integer, which is not a lyrchrel number (that is, it does eventually yield a palindrome under this algorithm, rather than continuing infinitely)

Output

the palindrome reached.

Python 2, 55 bytes
Following JPvdMerwe suggestion:

n=input()
while`n`!=`n`[::-1]:n+=int(`n`[::-1])
print n

Python 2, 62:
n=raw_input()
while n!=n[::-1]:n=`int(n)+int(n[::-1])`
print n


Where will the gem-picking robot end up? Related puzzle: Pathfinder (available on Puzzle Picnic)
Background
A robot is standing on a cell of a rectangular grid, where each cell has one or more gems except for the one with the robot. The robot can move to a horizontally or vertically adjacent cell in one step, and it picks up one gem from the cell it steps on.
The robot is programmed with which cell to choose for its next step, based on the number of gems each adjacent cell contains. The program is in the form of a > b > c > ... > z, which means that the robot prefers to move into the cell with a gems, followed by one with b gems, and so on. Any such program contains positive integers from 1 to n exactly once, where n is the length of the program. The robot will never move into any cell with no gems.
If there are multiple highest-priority cells around the robot, or all the cells around it are empty, it will get stuck at that point.
For example, if its program is 1 > 3 > 2 (meaning, it prefers the cell with only one gem the most, followed by the one with 3 gems, and then 2 gems) and the current state looks like this (R is the robot, the numbers are gems):
0 3 2
2 R 1
1 2 3

Then it will choose the cell on its right because 1 has the highest priority. Assuming the cell with R is empty, it will continue moving down, left, left, right, right, then get stuck since the cells around it have no gems left.
0 3 2     0 3 2     0 3 2     0 3 2     0 3 2     0 3 2     0 3 2
2 R 1 --> 2 0 R --> 2 0 0 --> 2 0 0 --> 2 0 0 --> 2 0 0 --> 2 0 0
1 2 3     1 2 3     1 2 R     1 R 2     R 1 2     0 R 2     0 0 R
       R         D         L         L         R         R

Using the 1 > 3 > 2 program, it will get stuck at any of the following cases:
0 R 0  # all adjacent cells are empty
2 0 1
1 2 2

3 1 0  # there are two 1s around the robot, so it can't decide where to go
2 R 1
1 0 2

Challenge
Given the initial state of the entire grid and the robot's program, find the position (horizontal and vertical coordinates) in the grid where the robot will eventually get stuck.
The initial state contains the numbers between 1 and 9 inclusive, except for a single 0 which denotes the initial position of the robot. The program is guaranteed to contain all positive numbers that appear in the grid, and the program is always valid (contains each of 1 to the maximum value on the grid exactly once).
You can take the input (grid and program) in any suitable format, and output the coordinates in any sensible way.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
In the example I/O provided, the program has the highest precedence coming first, and the coordinates are 1-based.
Grid:
0 2 1
3 3 2
1 1 3
Program: 3 1 2
Result: 2nd row, 3rd column (Path: DRDRUUD)

Grid: (one row)
0 3 2 3 1 4 4
Program: 4 2 3 1
Result: 1st row, 7th column (Path: RRLRRRRRLRLRLR)

Grid:
0 1 3
3 1 3
2 1 2
Program: 3 1 2
Result: 3rd row, 3rd column (Path: DRRULRDD)

Grid:
2 3 1 2 1
2 0 3 2 2
1 1 3 1 1
Program: 1 3 2
Result: 2nd row, 4th column (Path: DLUUDURRDDRRUULD)

Same grid as above, Program: 3 2 1
Result: 2nd row, 2nd column (Stuck at zero moves)

Python 2, 205 198 bytes

def s(g,w,r):
 p=g.index(0)
 while 1:
    a=[((r+[0]).index(v),n)for n,v in enumerate(g)if(abs(n-p)in[1,w])>(p-n)%w*(p/w!=n/w)];m,n=min(a)
    if~-sum(k[0]==m<len(r)for k in a):return p/w,p%w
    p=n;g[p]-=1

-6 bytes thanks to @ovs
-1 byte thanks to @user202729
Try it online!
Take the input grid as a flattened list with width also passed. Outputs 0-indexed (x,y) coordinates of the final position (I doubt index in the flattened list would be acceptable).
Explanation:
# Function of flattened grid g, width w, pRiorities r
def s(g,w,r):
    # starting position p
    p = g.index(0)
    while 1:
        a = [
            # pair (priority rank of the cell, cell id)
            # priority rank is n for v=0
            ((r+[0]).index(v),n)
            # for each adjacent cell id n with v gems
            for n,v in enumerate(g) if abs(n-p) in [1,w] and (p%w==n%w or p/w==n/w)
        ];
        # min comparison is done by tuple, so it selects one with minimum priority rank
        # m = min priority rank; n = corresponding cell id
        m,n = min(a)
        if sum( # how many adjacent cells
            k[0]==m # have priority rank equal to m
            <len(r) # and the cell value is not 0
            for k in a
        ) ^ 1: # If this count is not 1, then the robot is stuck; return
            return(p/w, p%w)
        # Otherwise, continue with updated position,
        p = n;
        # and take one gem
        g[p] -= 1


Special quines and code golf, hooray! Make a quine. Simple enough, except it has to be a palindrome and accept input.

Now, any side of a palindromic quine is one half of it. For example, one side of the hypothetical quine AAAA is AA. One side of AAAAA is AA (the center symbol is ignored).

Your job is to make a quine like this that accepts input. If the input is the whole quine, then the quine prints the left side of itself. If the input is either side of the quine then the quine prints itself. Of course, with quines with an odd number of symbols the center symbol is ignored. If the input is anything other than the cases specified, the program must do nothing.

This is code golf, so the shortest submission wins.

Haskell, 350 346 342 bytes

main=interact f;f s|s==l++r=l|s/=l,s/=r=[]|1<3=l++r;r=reverse l;l=q++shows q['-'];q="main=interact f;f s|s==l++r=l|s/=l,s/=r=[]|1<3=l++r;r=reverse l;l=q++shows q['-'];q="--"=q;]'-'[q swohs++q=l;l esrever=r;r++l=3<1|][=r=/s,l=/s|l=r++l==s|s f;f tcaretni=niam"=q;]'-'[q swohs++q=l;l esrever=r;r++l=3<1|][=r=/s,l=/s|l=r++l==s|s f;f tcaretni=niam

Prints its left half with itself as input: https://tio.run/##7ZAxCoUwEESvEmwsoohYxjlJSBEkYvhrJNnwbXJ3f8gd7H4zsMPsY5jD8scRPc9pfYAP2SW7ZbGrXXBhgKRMoMITaKiSoE2Z16X5KiG5r0vsBClClJKP62YRdT/2RkV0r0DHsUNUpp46Cr6vg6WMqGHhuL2iQqQkLOtcjK74iQeqUgjNRy3RyuTNJpeDR/D2fAX63/WdXX8
Prints itself with its left half as input: Try it online!
Prints itself with its right half as input: Try it online!
Prints nothing with anything else as input: Try it online!

Edit: -8 bytes thanks to Ørjan Johansen! Also changed to a version which does not need (<>).


Brachylog, 19 17 bytes
∧≜;1⟨∋{+|-}∋⟩ᵃ⁽?t

Try it online!
I guess I shouldn't be too surprised, but funnily enough this produces the exact same outputs as xash's solution--up to \$n = 13\$ after which both time out. Takes input through the output variable and outputs through the input variable.
   1                 Starting with 1,
             ᵃ       repeat on the list of previous results
∧≜;           ⁽      as few times as necessary:
       +             add
      { |-}          or subtract
    ⟨∋     ∋⟩        one element and another (not necessarily distinct),
               ?     such that the final list of results is the input variable
                t    and its last element is the output variable.


Longest path on a 2d plane You are provided a set of arbitary, unique, 2d, integer Cartesian coordinates:
e.g. [(0,0), (0,1), (1,0)]

Find the longest path possible from this set of coordinates, with the restriction that a coordinate can be "visited" only once. (And you don't "come back" to the coordinate you started at).

Important:

You cannot "pass over" a coordinate or around it. For instance, in the last note example (Rectangle), you cannot move from D to A without visiting C (which may be a revisit, invalidating the length thus found). This was pointed out by @FryAmTheEggman.

Function Input: Array of 2d Cartesian Coordinates
Function Output: Maximum length only
Winner: Shortest code wins, no holds barred (Not the most space-time efficient)

Examples

1: In this case shown above, the longest path with no coordinate "visited" twice is A -> B -> O (or O-B-A, or B-A-O), and the path length is sqrt(2) + 1 = 2.414

2: In this case shown above, the longest path with no coordinate "visited" twice is A-B-O-C (and obviously C-O-B-A, O-C-A-B etc.), and for the unit square shown, it calculates to sqrt(2) + sqrt(2) + 1 = 3.828.

Note: Here's an additional test case which isn't as trivial as the two previous examples. This is a rectangle formed from 6 coordinates:

Here, the longest path is: A -> E -> C -> O -> D -> B, which is 8.7147
(max possible diagonals walked and no edges traversed)

Pyth, 105 103 100 92 86 bytes

V.pQK0FktlNJ.a[@Nk@Nhk)FdlNI&!qdk&!qdhkq+.a[@Nk@Nd).a[@Nd@Nhk)J=K.n5B)=K+KJ)IgKZ=ZK))Z

              Z = 0 - value of longest path
              Q = eval(input())

V.pQ         for N in permutations(Q):
  K0           K = 0 - value of current path
  FktlN        for k in len(N) - 1:
    J.a          set J = distance of
    [@Nk                 Q[k] and Q[k+1]
    @Nhk)
    FdlN         for d in len(N):
I&                 if d != k && d != (k + 1)
!qdk
&!qdhk
q+                and if sum of
.a                   distance Q[k] and Q[d]
 [@Nk
 @Nd)
.a                   distance Q[d] and Q[k+1]
 [@Nd
 @Nhk)
J                    are equal to J then
  =K.n5              set K to -Infinity
  B                  and break loop
                     ( it means that we passed over point )
  )                   end of two if statements
=K+KJ                  K+=J add distance to our length
)                      end of for
IgKZ                   if K >= Z - if we found same or better path
  =ZK                  Z = K       set it to out max variable
))                     end of two for statements
Z                      output value of longest path

Try it here!


APL (Dyalog), 20 9 bytes

⊃{⌽[⍺]⍵}/

Try it online!

How?

/ - reduce - take the rightmost element in the input (the array) and apply the function with next left element as left argument

{⌽[⍺]⍵} - reverse in the left argument (⍺) dimension

⊃ - flatten the enclosed array


Triangle Area Side Side Side Given three sides of a triangle, print area of this triangle.
Test cases:
In: 2,3,4
Out: 2.90473750965556
In: 3,4,5
Out: 6
Given the sides \$a\$, \$b\$, and \$c\$, you can assume that \$a>0\$, \$b>0\$, \$c>0\$, \$a+b>c\$, \$b+c>a\$, and \$c+a>b\$.
This is code-golf, shortest answer per language in bytes wins.


TryItOnquine Challenge (based on this post and the ensuing discussion on chat -- also, much thanks to Dennis for TIO!)

The Challenge

Choose a language that's currently available on the TryItOnline site, for example PowerShell. Write code in that language on that page, that doesn't take any input, such that when the Run button is clicked, the output on that page is the exact same as what is in the "Plain URL" field when the Save/Store button is clicked instead.

For a fictitious example, suppose that aaa was the code for a solution to this in PowerShell. Then, the result of clicking Run with aaa as the code on https://tio.run/#powershell should output https://tio.run/##K8gvTy0qzkjNyfn/PzEx8f9/AA, which is also the "Plain URL" field when the Save/Store button is clicked.

Scoring

The resulting URL is your submission to this challenge. The winner is the shortest URL measured in bytes. For the example above, the URL https://tio.run/##K8gvTy0qzkjNyfn/PzEx8f9/AA is the submission to the challenge, at 44 bytes. The shortest URL that fulfills the rest of this challenge wins the challenge and earns brownie points (points not redeemable). Given that there is a distinct minimum possible length, if two submissions tie in length, the earlier submission wins.

URL Generation

This is the start of the URL generation algorithm in the repository. You can see how the main code area is taken, any extra elements are appended, the string is deflated and Base64 converted, and then ## prepended, etc. I won't go into full detail here; part of the challenge is to parse and understand how the URLs are generated in order to exploit any potential quirks in said algorithm.

Rules / Clarifications

The actual code should take no input and produce only the quine-URL as output.
-- This means the only text fields that should be populated when clicking into the URL are the Code, Header, Footer or corresponding "Compiler Flag" fields; the Input and Arguments fields are forbidden and must remain empty/unused. Clicking the Run button should only change the Output field. For this challenge, the Debug field is ignored in all situations.
Usual quine rules apply to the code to the extent possible (for example, the code cannot read its own source code via .code.tio).
Please include a description of how the code works in your submission.
Submitting a "cheaty" quine by submitting a Git pull request to the TIO repository to create a "trick" URL or shortcut or the like is not allowed.
Similarly, submitting a pull request to update a particular language to produce a "trick" URL is not allowed.
Please be nice to Dennis' servers and don't abuse them or attempt exploits for the sake of this challenge.

Python 2, URL length = 170 bytes

https://tio.run/##K6gsycjPM/r/v9hWqQDCjqlISwPhYlvVIuvM3IL8ohKFpMTiVDMT64KizLwS9YySkoJiK339ksx8vaLSPH1lZXVtiAK9JDOT1Lzk/JRUDY1iVdViTT0YT70qJzNJXVMz2shK1yRWE2aHEkUW4Db//38A

s="python2\xff\xffs=%r;import base64;print'https://tio.run/##'+base64.b64encode((s%%s).encode(('zlib'))[2:-4])\xff\xff";import base64;print'https://tio.run/##'+base64.b64encode((s%s).encode(('zlib'))[2:-4])

Try it online!

This relies on three coincidences:

The default zlib level 6 happens to give the same results as zlib level 9 for this string, modulo the header that I strip.
The compressed length is divisible by 3, so base64 does not generate any = padding characters.
The base64 output does not contain any + characters.


Convert RGB integer value into RGB values For example, in traditional web hexadecimal, a certain base-16 number represents an RGB value. For example, 45A19C equals (69,161,156) in RGB.

You'll be converting from that number to RGB value, however, instead you'll be given that number in base-10 rather than base 16.

So in the example used above, 45A19C would equal 4563356 in base-10. Thus 4563356 converted to RGB would equal (69,161,156).

So assume the integer given is previously stored in variable n and is between 0 and 16777215. Take number n and convert it to RGB values between 0 and 255. Return or save in a variable the three values as a list [r,g,b].

An RGB to RGB int can be found here. This link converts the opposite of what your trying to do.

Shortest code wins.

If clarification is needed, please ask so I can fix my question to be more helpful.

AVR ABI, 0

Quantities larger than the registers in the AVR's registers are represented with multiple registers. So, when passing in a 32-bit 'n' to a function, it is passed as 4x8-bit registers. Effectively R(r24),G(r23), and B(r22) are directly addressable without any additional work by virtue of the CPU's register addressing.

Here's some 'C' code for the unpacking operation:

unsigned char r( unsigned long n ){return n>>16&255;}
unsigned char g( unsigned long n ){return n>>8&255;}
unsigned char b( unsigned long n ){return n>>0&255;}

disassembled examples from avr-gcc 4.8:

.global r
.type   r, @function
r:
ret
.size   r, .-r

.global g
.type   g, @function
g:
mov r24,r23
ret
.size   g, .-g

.global b
.type   b, @function
b:
mov r24,r22
ret
.size   b, .-b

For red, GCC just emits the return code since the red byte just happens to be in the return register already. For green and blue it copies the corresponding register into the return register and returns. The actual packing/unpacking is handled by the ABI - when done somewhere other than a function call boundary, it's handled purely by the register addressing. Both the copies and return opcode are overhead required to view this happening in the CPU - the compiler can use these registers directly if not required to place the result in the return register. Free RGB packing/unpacking is available when handing any 32-bit integer.

Another way to think about it is that the AVR's registers represent large numbers as a list of 8-bit registers, and that list happens to unpack RGB for us.


Non-transitive dice game Those of you who like Numberphile would be familiar with Dr. James Grime, who described a non-transitive dice game on his channel.

The game consists of three 6-faced dice:

Die 1: 3,3,3,3,3,6
Die 2: 2,2,2,5,5,5
Die 3: 1,4,4,4,4,4

Two players each select a die to use. They roll them and the higher die wins, best-of-whatever.

Probabilistically, die 1 beats dies 2 with >50% chance. Similarly, die 2 beats die 3, and, interestingly, die 3 beats die 1.

Write a program taking 1, 2 or 3 as input. This indicates the die the user chooses. The program then choose the die that would beat the user and output the results of 21 rolls, and "Computer/User wins with x points"

Rules

Code-golf, votes as tiebreaker
You must use RNG (or the likes) to actually simulate the dice rolls.
I am not too strict on output format. It's okay as long as you show the dices, somehow separate between the 21 rolls (in a way different from how you separate the dice in the same roll), and output that sentence above.
Input can be stdin, command line argument, from screen, etc.

Example

Input

1

Output

4 3
4 3
4 3
4 3
4 3
4 3
4 3
4 3
4 3
4 6
1 3
4 3
4 3
1 3
4 3
1 3
4 3
4 3
4 3
4 3
4 6
 Computer wins with 16 points

Here, the user chooses die 1 and his rolls are shown on the right column. The program chooses die 3 and beats him.

APL (106 114)

'Computer' 'User'[1+X],'wins with','points',⍨|Z-21×X←11>Z←+/>/⎕←⍉↑{⍵[{?6}¨⍳21]}¨(↓5 6⍴545170074510753⊤⍨18⍴7)[⎕+⍳2]

Explanation:

(↓5 6⍴545170074510753⊤⍨18⍴7)[⎕+⍳2]: The big number is a base-7 representation of the dice. We make a 6x5 matrix containing the values of the dice in the order: 2 3 1 2 3. Ask for user input and add this to the vector 1 2, and select these lines from the matrix. Because the list of dice is shifted, the user now gets the one he selected (on the right) and the computer gets the stronger one.
{⍵[{?6}¨⍳21]}¨: do 21 rolls for each of these two dice.
⎕←⍉↑: put the rolls in matrix form and output them.
Z←+/>/: get the score of the computer (amount of times the computer's value was higher than the user's)
X←11>Z: set X to whether the user won (if 11 is higher than the computer's score).
'Computer' 'User'[1+X]. X is whether the user won.
'wins with','points',⍨|Z-21×X: Z is the computer's score, so if the computer won display Z, otherwise display 21-Z.


Golf a Brain-Flak Integer Integers are tedious to represent in Brain-Flak. There are 8 operators:

()      Evaluates to 1, but does not push anything on any stack
[]      Evaluates to an indeterminate value for the purposes of this question
{}      Removes the top of the stack and evaluates to it
<>      Switches to or back from the alternate stack and evaluates to zero
(foo)   Pushes the value of the expression foo to the stack and evaluates to it
[foo]   Evaluates to the negation of foo
{foo}   Evaluates the expression foo until the top of the stack is zero
<foo>   Evaluates to zero but executes foo anyway

foo may consist of multiple operators, in which case they are evaluated and summed. For example (()()) pushes 2 to the stack (and evaluates to 2 too).

Obviously, the (()...()) mechanism is not useful in Code Golf as large numbers would take n*2+2 bytes to represent. Your challenge is therefore to write a program or function that will output in as few bytes as possible a Brain-Flak program that will push a given positive integer n to the active stack. This program must not make any assumptions about the existing contents of the stacks, so it must not leave the stacks exchanged or add or remove extra values from the stacks.

Although your program or function must be capable of returning a working Brain-Flak program for all inputs from 1 to 1,000,000 the winner will be the program or function that generates the smallest set of appropriate Brain-Flak programs for all 1061 prime numbers between 1,000 and 10,000. You should note the total size of your outputs for those 1061 inputs as part of your submission. Your program or function may accept the integer and return the (string) Brain-Flak program in any of the usual acceptable I/O formats. Ties will be broken using the size of your program or function.

Python 2, 59394 59244 58534 58416 58394 58250

Ok here is my solution.
import re
import math

cache = {0:"<()>"}

def find(x,i,j):
    return i*((x**2+x)/2)+(j+1)*((x**2-x)/2)

def solve(x, i, j):
    a = (i + j + 1)/2.
    b = (i - j - 1)/2.
    c = -x
    return (-b + math.sqrt(b**2 - 4*a*c))/(2*a)

def size(i,j=0):
    return 4*(i+j)+14

def polynomials(n):
    upperBound = int(4*math.log(n,2))
    i = 0
    answers = []
    while size(i) < upperBound:
        for j in range(i):
            sol = int(solve(n, i-j, j)+.5)
            if find(sol, i-j, j) == n:
                answers.append((sol, i-j, j))
        i += 1
    return answers

def complement(character):
        dict = {"(":")","{":"}","<":">","[":"]",")":"(","}":"{",">":"<","]":"["}
        return dict[character]

def findMatch(snippet, index):
        increment = 1 if snippet[index] in "({<[" else -1
        stack = []
        if snippet[index] in "(){}<>[]":
                stack.append(snippet[index])
        while len(stack) > 0 and index + increment < len(snippet):
                index += increment
                if snippet[index] in "(){}<>[]":
                        if complement(snippet[index]) == stack[-1]:
                                stack = stack[:-1]
                        else:
                                stack.append(snippet[index])
        return index

def isPrime(n):
    return not [0 for x in range(2,int(n**.5)+1) if n%x==0] and n>1

def getPrimeFactors(n):
    return [x for x in range(2,n/2) if n%x==0 and isPrime(x)]

def divHardcode(n,m):
    assert n%m == 0
    assert m != 1
    assert n != 1
    binary = bin(m)[3:]
    return (binary.count("1")+len(binary))*"("+getBF(n/m)+")"*binary.count("1")+binary.replace("1","){}{}").replace("0","){}")

def isTriangular(n):
    #Triangles must be between sqrt(2n) and cbrt(2n)
    if n < 0: return isTriangular(-n)
    for x in range(int((2*n)**(1/3.)),int((2*n)**.5)+1):
        if (x**2+x) == 2*n:
            return True
    return False

def getTriangle(n):
    if n < 0: return -getTriangle(-n)
    #Triangles must be between sqrt(2n) and cbrt(2n)
    for x in range(int((2*n)**(1/3.)),int((2*n)**.5)+1):
        if (x**2+x) == 2*n:
            return x
    #If we don't find one we made a mistake
    assert False

def getSimpleBF(n):
    if n in cache:return cache[n]
    if n < 0:
        # There is room for better solutions here
        return "["+getSimpleBF(-n)+"]"
    elif n == 0:
        return ""
    elif n < 6:
        return "()"*n
    #Non-edge cases
    solutions = []
    factors = getPrimeFactors(n)
    if n >= 78 and isTriangular(n):
        solutions.append(
           min([push(getTriangle(n))+"{({}[()])}{}","<"+push(getTriangle(n)+1)+">{({}[()])}{}"],key=len)
        )
    polynomialSolutions = polynomials(n)
    for polynomial in polynomialSolutions:
        solutions.append("<%s>{%s({}[()])%s}{}"%(push(polynomial[0]),"({})"*polynomial[1],"({})"*polynomial[2]))
        #Mod 3 tricks
    if n % 3 == 2:
       solutions.append(("((%s)()){}{}")%getBF(n/3))
    elif n % 3 == 1:
       solutions.append(("((%s)()()){}{}")%getBF(n/3-1))
    #Basic solutions
    if isPrime(n):
        solutions.append(getSimpleBF(n-1) + "()")
    else:
        #TODO multithread
        solutions += map(lambda m:divHardcode(n,m),factors)
    return min(solutions,key=lambda x:len(unpack(x)))

def getBF(n):
    if n in cache: return cache[n]
    result = getSimpleBF(n)
    index = n - 1
    while index > n-(len(result)/2):
        score = getSimpleBF(index)+getSimpleBF(n-index)
        if len(score) < len(result):result = score
        index -= 1
    index = n + 1
    while index < n+(len(result)/2):
        score = getSimpleBF(index)+getSimpleBF(n-index)
        if len(score) < len(result):result = score
        index += 1
    cache[n] = result
    return result

def unpack(string):
    reMatch = re.match("\(*<",string)
    if reMatch:
        location =reMatch.span()
        return string[location[1]:findMatch(string,location[1]-1)] +string[:location[1]-1] + string[findMatch(string,location[1]-1)+1:]
    return string

def push(n):
    return unpack("("+getBF(n)+")")

def kolmo(string):
    code = push(ord(string[-1]))
    stringVector = map(ord,string)
    for x,y in zip(stringVector[-1:0:-1],stringVector[-2::-1]):
        code = "("+code+getBF(y-x)+")"
    code = code.replace("<()>)",")")
    return code

def kolmo(stringVector):
    code = push(stringVector[-1])
    for x,y in zip(stringVector[-1:0:-1],stringVector[-2::-1]):
        code = "("+code+getBF(y-x)+")"
    code = code.replace("<()>)",")")
    return code

if __name__ == "__main__":
    import primes
    sum = 0
    for prime in primes.nums:
        print push(prime)
        sum += len(push(prime))
    print sum

The relevant function is push(n). To call it simply call push on the integer you wish to represent.
Explanation
The main optimization done by the program is multiplication hard-coding.  The idea of multiplication hardcoding is pretty simple.  You push the a number and then pop and push it to create a new value.  For example to multiply by two you can use the following code ((n){}) where n code producing a specific number.  This works because both (n) and {} have a value of n.
This simple idea can be made more complex for larger numbers.  Take for instance 5 it was discovered a while ago that the best way to multiply by five was (((n)){}){}{}.  This code makes two copies of the n multiplies one by 4 and adds the two.  Using the same strategy I make every multiplication based on a number's binary representation.  I won't get into the details of how this works right now but I do this by chopping off the first one of the binary representation and replacing 0 with ){} and 1 with ){}{}.  It then makes sure that n is pushed the appropriate number of times and balances all the parentheses.  (If you want to know how this is done you can look at my code).  If you want to know why this works just ask me in a comment.  I don't think anyone actually reads all the updates to my post so I left the explanation out.
When the algorithm attempts to find a multiplication hardcode it attempts all of a numbers prime factors.  It ignores composite factors because at one point composite factors could always be expressed more concisely as its own prime factors it is not known if this is still true.
The other byte saving mechanism is a polynomial solution finder.  There are certain forms of polynomials that are easy to represent with decrementing loops.  These polynomials include, but are not limited to, polygonal numbers. This optimization finds polynomials that fit the form and creates the code that makes them.
Output
paste-bin


Outline words with their letters For the purposes of the current challenge to "outline" a word means to surround it successively with its own letters, starting with the last one, and finally to replace the original word in the center with spaces:

       oooooo
       onnnno
on ->  on  no
       onnnno
       oooooo

Task:

Given a list of words, consisting only of lowercase and/or uppercase English letters, outline each word and display all the resulting blocks next to each other horizontally, separated by a column of single space, vertically aligned at the centers of the blocks.

You can write a full program, or a function.

Input:

A list of words, or if you prefer - a space- or other symbol- delimited string

Output:

The ASCII representation of the blocks for the outlined words. Leading/trailing
whitespaces are permitted.

Test cases:

Input 1: ["code", "golf"] (or "code golf")
Output 1:

    cccccccccccc gggggggggggg
    cooooooooooc goooooooooog
    coddddddddoc gollllllllog
    codeeeeeedoc golfffffflog
    code    edoc golf    flog
    codeeeeeedoc golfffffflog
    coddddddddoc gollllllllog
    cooooooooooc goooooooooog
    cccccccccccc gggggggggggg

Input 2: ["I", "am", "just", "a", "man"]  (or "I am just a man")
Output 2:

           jjjjjjjjjjjj
           juuuuuuuuuuj     mmmmmmmmm
    aaaaaa jussssssssuj     maaaaaaam
III ammmma justtttttsuj aaa mannnnnam
I I am  ma just    tsuj a a man   nam
III ammmma justtttttsuj aaa mannnnnam
    aaaaaa jussssssssuj     maaaaaaam
           juuuuuuuuuuj     mmmmmmmmm
           jjjjjjjjjjjj

Winning criteria:

The shortest code in bytes in each language wins. I will greatly appreciate if you comment/explain your code and approach.

Canvas, 22 20 bytes

ｌ ＊；±２１＊｛；ｌ└＊ｅ⟳｝ ］ｒ⤢

Try it here!

Explanation:

{                 ]    map over the inputs
 l *                     array of length spaces - the canvas of the current word
    ;                    get the word back on top
     ±                   reverse it
      21*                repeat each character twice
         {      }        for each character
          ;l└              push the height of the item below (the canvas)
             *             repeat the character that many times vertically
              e            and encase the canvas in that char column
               ⟳           and rotate it clockwise for encasing the next time
                 ∙      push another space as the separator of words
                   r   center the words
                    ⤢  and transpose the final output (as everything was built vertically)


Desperately Seeking Santa Find Santa and his reindeer in a crowded scene.

Input

Input will be on STDIN and will be a variable number of lines of characters of equal, but variable, length.
If Santa (represented by the character S) is in the scene, his sack of presents (represented by the character P) will be in one of the positions adjacent to him (horizontally, vertically or diagonally). His reindeer (each represented by the character R) will all be within the 5x5 square surrounding him. If an S appears in the scene that does not have a sack of presents, or is not accompanied by at least 4 reindeer, then it is not Santa.

Output

The scene cleared of all obfuscation (all non-Santa, non-presents, non-reindeer characters replaced with a space), showing Santa, his sack of presents, and his reindeer - all other characters should be replaced with spaces. If Santa and his reindeer are not in the scene, output it unchanged. It is guaranteed that there will only be one solution, so there will never be more than one valid Santa and he will never be carrying more than one sack of presents.

Examples

In these examples I'm just using the * character to make it easy to see the S, P, and R characters, but your program should be able to handle any ascii character from ! to ` (33 to 96). I've left out lower case characters and above to avoid confusion.

Input:

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********

Output: (ignore dots, they're to force the page to show the blank lines)

.
.
.
     R
      P
     S
     R
    R  R
.
.
.
.

Input: (not enough reindeer)

***********
***********
***********
***********
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********

Output:

***********
***********
***********
***********
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********

Input: (no sack of presents)

***********
***********
***********
*****R*****
***********
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********

Output:

***********
***********
***********
*****R*****
***********
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********

Input: (presents not close enough)

***********
***********
***********
*****R*****
***********
*****S*P***
*****R*****
****R**R***
***********
***********
***********
***********

Output:

***********
***********
***********
*****R*****
***********
*****S*P***
*****R*****
****R**R***
***********
***********
***********
***********

Input: (one of the reindeer not within the 5x5 square around Santa)

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R******
*******R***
***********
***********
***********

Output:

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R******
*******R***
***********
***********
***********

Test Scripts

As in some of my past questions, I've once again butchered some test scripts originally created by Joey and Ventero to provide some test cases for this question:

bash
Powershell

Usage: ./test [your program and its arguments]

Plain text version of the tests for reference: Plain text

Rewards

Each entry which I can verify that meets the spec, passes the tests and has obviously had some attempt at golfing will receive an upvote from me (so please provide usage instructions with your answer). The shortest solution by the end of 31/12/2013 will be accepted as the winner.


Convert a bytes array to base64 Your mission is to write a function/program that converts an array of bytes (i.e: an array of integers from 0 to 255), to base64.

Using built-in base64 encoders is not allowed.

The required base64 implementation is RFC 2045. (using "+", "/", and mandatory padding with "=")

Shortest code (in bytes) wins!

Example:

Input (int array): [99, 97, 102, 195, 169]

Output (string): Y2Fmw6k=

JavaScript, 177 187 198 characters
function(d){c="";for(a=e=b=0;a<4*d.length/3;f=b>>2*(++a&3)&63,c+=String.fromCharCode(f+71-(f<26?6:f<52?0:f<62?75:f^63?90:87)))a&3^3&&(b=b<<8^d[e++]);for(;a++&3;)c+="=";return c}

For adding linebreaks, \r\n, after each 76th character, add 23 characters to the code:
function(d){c="";for(a=e=b=0;a<4*d.length/3;f=b>>2*(++a&3)&63,c+=String.fromCharCode(f+71-(f<26?6:f<52?0:f<62?75:f^63?90:87))+(75==(a-1)%76?"\r\n":""))a&3^3&&(b=b<<8^d[e++]);for(;a++&3;)c+="=";return c}

Demo code:

var encode = function(d,a,e,b,c,f){c="";for(a=e=b=0;a<4*d.length/3;f=b>>2*(++a&3)&63,c+=String.fromCharCode(f+71-(f<26?6:f<52?0:f<62?75:f^63?90:87))+(75==(a-1)%76?"\r\n":""))a&3^3&&(b=b<<8^d[e++]);for(;a++&3;)c+="=";return c};

//OP test case
console.log(encode([99, 97, 102, 195, 169])); // outputs "Y2Fmw6k=".

//Quote from Hobbes' Leviathan:
console.log(
 encode(
  ("Man is distinguished, not only by his reason, but by this singular passion from " +
   "other animals, which is a lust of the mind, that by a perseverance of delight " +
   "in the continued and indefatigable generation of knowledge, exceeds the short " +
   "vehemence of any carnal pleasure.")
  .split('').map(function(i){return i.charCodeAt(0)})
 )
);


Finding Collatz-like rules with many loops This code-challenge is related to the code-golf question Analyzing Collatz-like sequences but the goal is quite different here.

If you are familiar with Collatz-like sequences you can skip to the section "The task".

We define a Collatz-like rule with 3 positive integers:

d > 1 divisor
m > 1 multiplier
i > 0 increment

(In the original Collatz sequence d = 2, m = 3 and i = 1.)

For a Collatz-like rule and a positive integer n starting value we define a sequence s in the following manner:

s(0) = n
if k > 0 and s(k-1) mod d = 0 then s(k) = s(k-1) / d
if k > 0 and s(k-1) mod d != 0 then s(k) = s(k-1) * m + i

An example sequence with d = 2, m = 3, i = 5 and n = 80 will be s = 80, 40, 20, 10, 5, 20, 10, 5, 20, ....

Every sequence will either reach higher values than any given bound (i.e. the sequence is divergent) or get into an infinite loop (for some t and u (t!=u) the s(t) = s(u) equality will be true).

Two loops are said to be different if they don't have any common elements.

The task

You should write a program which finds a Collatz-like rule with many different loops. Your score will be the number of found loops. (You don't have to find all of the possible loops and higher score is better.)

The program could be specialized in any manner to produce the best score.

For proof the program should output the values of d, m, i and the smallest values from every found loop.

Example

For d=3 m=7 i=8 the loops are

LOOP 15 5 43 309 103 729 243 81 27 9 3 1
LOOP 22 162 54 18 6 2
LOOP 36 12 4

So a valid proof with a score of 3 could be

d=3 m=7 i=8 min_values=[1 4 2]

You can validate your result with this Python3 code. The program expects a list of space-separated integers d m i min_value_1 min_value_2 ... as input.

GolfScript, arbitrary score

~:l 2:m.@?):d\1 l,{m\)?d-*}/abs.{1 m 3$)?-*m@)?d-m(*/}+l,/]' '*

This takes an integer on stdin and outputs a sequence with that many loops, in the input format of the Python tester. The online demo runs it for l = 4 and produces output 17 2 1755 117 405 1365 26325; this fork of the tester verifies it.

Explanation

In order to keep it simple, I restricted the analysis to primitive loops: ones with only one division.

(x -> mx + i)^n = (x -> m^n x + (m^n - 1)/(m-1) i)

so this means that I'm looking for solutions to

m^n x + (m^n - 1)/(m - 1)i = dx

or

(m^n - d) x + (m^n - 1)/(m - 1)i = 0

When n > 0, m > 1, m^n - d != 0 this has exactly one solution for x. m - 1 > 0 and m^n - 1 > 0, so in order for the solution to be positive we require m^n - d < 0, and in order for the solution to be an integer we require d - m^n to be a factor of (m^n - 1)/(m - 1)i.

The rest may already be obvious. We pick the desired score, l. We're going to find primitive loops of length 1 to l, so we want d - m^l > 0. To get a smallish output we pick m = 2, d = 2^l + 1. Then to get an easy guarantee of the divisibility constraints we pick i to be the absolute value of (m - d)(m^2 - d)...(m^l - d).


Swap program halves to test divisors Four integer sequences

In this challenge, you will test four different properties of a positive integer, given by the following sequences.
A positive integer N is

perfect (OEIS A000396), if the sum of proper divisors of N equals N. The sequence begins with 6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 2305843008139952128...
refactorable (OEIS A033950), if the number of divisors of N is a divisor of N. The sequence begins with 1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128...
practical (OEIS A005153), if every integer 1 ≤ K ≤ N is a sum of some distinct divisors of N. The sequence begins with 1, 2, 4, 6, 8, 12, 16, 18, 20, 24, 28, 30, 32, 36, 40, 42, 48, 54, 56...
highly composite (OEIS A002128), if every number 1 ≤ K < N has strictly fewer divisors than N. The sequence begins with 1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040...

Four programs

Your task is to write four programs (meaning full programs, function definitions or anonymous functions that perform I/O by any of the standard methods).
Each program shall solve the membership problem of one of these sequences.
In other words, each program will take a positive integer N ≥ 1 as input, and output a truthy value if N is in the sequence, and a falsy value if not.
You can assume that N is within the bounds of the standard integer type of your programming language.

The programs must be related in the following way.
There are four strings ABCD such that

AC is the program that recognizes perfect numbers.
AD is the program that recognizes refactorable numbers.
BC is the program that recognizes practical numbers.
BD is the program that recognizes highly composite numbers.

Scoring

Your score is the total length (in bytes) of the strings ABCD, or in other words, the total byte count of the four programs divided by two.
The lowest score in each programming language is the winner.
Standard code-golf rules apply.

For example, if the four strings are a{, b{n, +n} and =n}?, then the four programs are a{+n}, a{=n}?, b{n+n} and b{n=n}?, and the score is 2+3+3+4=12.

JavaScript (ES6), 46 + 55 + 6 + 36 = 282 274 ... 158 143 bytes

A:

n=>(r=0,D=x=>x&&D(x-1,n%x||(r++?q-=x:q=n)))(n)

B:

n=>(q=(g=D=x=>x&&!(n%x||(g|=m>2*(m=x),0))+D(x-1))(m=n))

C:

?!g:!q

D:

?(P=k=>--k?D(n=k)<q&P(k):1)(n):n%r<1

The result is 4 anonymous functions which give truthy/falsy values for their respective inputs (AC, AD, and BC give true/false, BD gives 1/0).

Test snippet

let AC =
n=>(r=0,D=x=>x&&D(x-1,n%x||(r++?q-=x:q=n)))(n)
?!g:!q

let AD =
n=>(r=0,D=x=>x&&D(x-1,n%x||(r++?q-=x:q=n)))(n)
?(P=k=>--k?D(n=k)<q&P(k):1)(n):n%r<1

let BC =
n=>(q=(g=D=x=>x&&!(n%x||(g|=m>2*(m=x),0))+D(x-1))(m=n))
?!g:!q

let BD =
n=>(q=(g=D=x=>x&&!(n%x||(g|=m>2*(m=x),0))+D(x-1))(m=n))
?(P=k=>--k?D(n=k)<q&P(k):1)(n):n%r<1

let update = n => O.innerText = [
  'perfect: ' + AC(n),
  'refactorable: ' + AD(n),
  'practical: ' + BC(n),
  'highly composite: ' + BD(n)
].join("\n")
<input type=number value=1 min=1 oninput=update(this.value)>


Make a regex that matches certain binary numbers Your task is to create a regular expression that matches most binary numbers with an even number of 0s and an odd number of 1s (e.g. "101100011").

The full criteria for the regex are:

matches 90% or more of all binary numbers between 0 and 11111111 with even number of 0s and an odd number of
1s,
doesn't match 90% or more of all binary numbers between 0 and 11111111 with odd number of 0s or an even number of
1s,
works in most common programming languages.

Ideally, it should be short and creative.

The input string always has a length that is greater than 1, less than infinity, and only contains 1s and 0s.

I will upvote any answer that seriously attempts to match the above criteria. Once the activity around this question dies down, I'll accept the highest-voted answer that is at least only 1.333... times the length of the shortest answer.

The following regex

(?=^1*(01*0)*1*$)^.(..)*$

works in many languages. It performs a perfect match for any binary of arbitrary length.

Basically, it consists of two parts which are joined via and by using a lookahead pattern:

^1*(01*0)*1*$ matches if an even number of zeros is provided.
^.(..)*$ tests for an odd number of digits in total.

The test run can be seen here.


Output numbers, more or less The Challenge
Given an input string (or array) consisting of < and >, output a sequence (array or string) of integers such that:

the operators are all correct when applied in order between consecutive numbers in the output
all integers are positive (1 or greater)
the sum of the integers is as small as is mathematically possible

Inputs can vary to match "greater than" and "less than" in your chosen language.
As an alternative output, just specify the sum of the numbers in the output. State which version you're solving in your Answer title.
Usual exclusions and rules apply, smallest bytes wins.
You can assume that the input string will never lead to an integer overflow in your language, if that helps.
Examples

> gives 2 1 which sums to 3
>>> gives 4 3 2 1 which sums to 10
>< gives 2 1 2 which sums to 5
 gives 1 which sums to 1
>>>>>>>>> gives 10 9 8 7  6 5 4 3 2 1 which sums to 55
>><<>><>>> gives 3 2 1 2 3 2 1 4 3 2 1 which sums to 24
><>><>><> gives 2 1 3 2 1 3 2 1 2 1 which sums to 18
<<<<> gives 1 2 3 4 5 1 which sums to 16
<<<<><<> gives 1 2 3 4 5 1 2 3 1 which sums to 22
>><< gives 3 2 1 2 3 which sums to 11

><>, 40 38 bytes

1v!rnr~<oa
?\i:0(?^3%\+$
{/?:-{:}-1/1:

Try it online!

An appropriate language. For reference ><> itself yields 2,1,2,1.

How it Works:

1v   Initialise the stack as 1 and enter loop
 \i:0(?^  If we're out of input, go to the first line
        3%\ Otherwise mod the input by 3, yielding 0 for < and 2 for >
        -1/Subtract 1 to get -1 and 1 respectively
    -{:}   Copy the previous number and subtract the above from it

 /?:    If the number is not 0, repeat the loop

?\        \+$  Otherwise:
                Increment each number until we reach the original 0
{/        /1:   And enter the first loop again

      ~<    When we're out of input, pop the extra -1 from EOF
   rnr      Output the first number
1v!         Push a 1
        oa  Print a newline and repeat, popping the extra 1 each time


Expand tabs (implement expand(1)) Your task this time is to implement a variant of the POSIX expand(1) utility which expands tabs to spaces.

Your program is to take a tabstop specification and then read input on standard in and replace tab characters in the input with the appropriate amount of spaces to reach the next tabstop.  The result should be written to standard out.

Tabstop specification

A tabstop specification consists of either a single number, or a comma-separated list of tabstops.  In the case of a single number, it is repeated as if multiples of it occurred in a comma-separated list (i.e. 4 acts as 4,8,12,16,20,...).  Each entry in a comma-separated list is a positive integer optionally prefixed by a +.  A + prefix indicates a relative difference to the previous value in the comma-separated list.  The first value in the list must be absolute (i.e. unprefixed).  The tabstops specify the column of the next non-space character (following the expanded tab), with the leftmost column taken as number 0.  Tabs should always expand to at least one space.

Input/output

The tabstop specification is either to be taken as the first command-line parameter to the program, or read from standard in as the first line of input (terminated by a newline), at your discretion.  After the tabstop has been read, the remaining input (all input, in the former case) until EOF is to be processed and expanded.  The expanded output shall be written to standard out.

All expanded tabstops, and all input, is assumed to be a maximum of 80 columns wide.  All expanded tabstops are strictly increasing.

Example

Tabstop specification 4,6,+2,+8 is equivalent to 4,6,8,16, and with both the input

ab<Tab>c
<Tab><Tab>d<Tab>e<Tab>f

is expanded into (␣ indicates a space)

ab␣␣c
␣␣␣␣␣␣d␣e␣␣␣␣␣␣␣f

01234567890123456   (Ruler for the above, not part of the output)
          1111111

Scoring is pure code-golf; shortest code wins.

Ruby 161 145

Reads the tabstop specification on the first line of input.

i=t=[]
gets.scan(/(\+)?(\d+)/){t<<i=$2.to_i+($1?i:0)}
81.times{|j|t<<j*i}
while gets
$_.sub!$&," "*(t.find{|s|s>i=$`.size}-i)while~/\t/
print
end

edit: Added two lines that makes the last read tabstop repeat so that tabstop specifications of a single number also works correctly

i is a temporary variable for holding the last parsed tabstop. t is the list of tabstobs, parsed from the gets.scan line. For good measure we add 81 multiples of the last parsed tabstop. the while gets loop keeps going until there is no more input. For each line of input we substitute tabs for spaces, one tab at the time because the string moves as we add the spaces and we must recalculate the correct tabstop.


Operator precedence: How wrong can I be? Say I have an expression:

9 * 8 + 1 - 4

This expression can be interpreted in six different ways, depending on operator precedence:

(((9 * 8) + 1) - 4) = 69 (* + -)
((9 * 8) + (1 - 4)) = 69 (* - +)
((9 * (8 + 1)) - 4) = 77 (+ * -)
(9 * ((8 + 1) - 4)) = 45 (+ - *)
((9 * 8) + (1 - 4)) = 69 (- * +)
(9 * (8 + (1 - 4))) = 45 (- + *)

Say I'm a developer, and I don't feel like memorizing precedence tables, etc., so I'm just going to guess.

In this case, the largest margin of error would be 45-77, which is a difference of 32. This means that my guess will only be off by a maximum of 32.

The challenge

Given an expression consisting of numbers and +, -, *, / (integer division) and %, output the absolute difference of the largest and smallest possible value for that expression, based on the precedence of operators.

Specifications

The input expression will not contain parenthesis and every operator is left-associative.
The input expression will only contain nonnegative integers. However, subexpressions may evaluate to negatives (e.g. 1 - 4).
You can take the expression in any reasonable format. For example:

"9 * 8 + 1 - 4"
"9*8+1-4"
[9, "*", 8, "+", 1, "-", 4]
[9, 8, 1, 4], ["*", "+", "-"]

The input will contain at least 1 and at most 10 operators.
Any expression that contains a division or modulo by 0 should be ignored.
You can assume that modulo will not be given negative operands.

Test Cases

9 * 8 + 1 - 4             32
1 + 3 * 4                  3
1 + 1                      0
8 - 6 + 1 * 0              8
60 / 8 % 8 * 6 % 4 * 5    63

Python 2, 171 156 bytes

lambda a:max(e(a))-min(e(a))
u=')%s('
def e(a,t=u):
 try:b=[eval(a)]
 except:b=[]
 return sum([e('(%s)'%a.replace(o,t%o),u%t)for o in"+-*/%"if' '+o in a],b)

Try it online!

How it works

We surround each operator with a different number of outward-facing pairs of parentheses to simulate different precedences (in all possible ways), and wrap enough inward-facing pairs of parentheses around the entire string, to get an expression we can eval.  For example, with

+ ↦ )+(
* ↦ ))*((
- ↦ )))-(((

we get

9 * 8 + 1 - 4 ↦ (((9 ))*(( 8 )+( 1 )))-((( 4))) = 77.


ASCII Odd/Even Cipher We'll define the ASCII Odd/Even Cipher via the below pseudocode:

Define 'neighbor' as the characters adjacent to the current letter in the string

If the one of the neighbors is out of bounds of the string, treat it as \0 or null

Take an input string

For each letter in the string, do
  If the 0-based index of the current letter is even, then
    Use the binary-or of the ASCII codes of both its neighbors
  Else
    If the ASCII code of the current letter is odd, then
      Use the binary-or of itself plus the left neighbor
    Else
      Use the binary-or of itself plus the right neighbor
  In all cases,
    Convert the result back to ASCII and return it
  If this would result in a code point 127 or greater to be converted, then
    Instead return a space

Join the results of the For loop back into one string and output it

For example, for input Hello, the output is emmol, since

The H turns to \0 | 'e' which is e
The e turns to 'e' | 'l', or 101 | 108, which is 109 or m
The first l also turns to 101 | 108 or m
The second l turns to 108 | 111, which is 111 or o
The o turns to 108 | \0, or l

Input

A sentence composed solely of printable ASCII characters, in any suitable format.
The sentence may have periods, spaces, and other punctuation, but will only ever be one line.
The sentence will be at least three characters in length.

Output

The resulting cipher, based on the rules described above, returned as a string or output.

The Rules

Either a full program or a function are acceptable.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples

Input on one line, output on the following. Blank lines separate examples.

Hello
emmol

Hello, World!
emmol, ww~ved

PPCG
PSWG

Programming Puzzles and Code Golf
r wogsmmoonpuu ~ meannncoooeggonl

abcdefghijklmnopqrstuvwxyz
bcfefgnijknmno~qrsvuvw~yzz

!abcdefghijklmnopqrstuvwxyz
aaccgeggoikkomoo qsswuww yy

Test 123 with odd characters. R@*SKA0z8d862
euutu133www|todddchizsscguwssr`jS{SK{z~|v66

Perl, 63 62 bytes

Includes +4 for -lp

Give input on STDIN

oddeven.pl:

#!/usr/bin/perl -lp
s%.%(--$|?$n|$':$&|(ord$&&1?$n:$'))&($n=$&,~v0)%eg;y;\x7f-\xff; ;

This works as shown, but to get the claimed score this must be put in a file without final ; and newline and the \xhh escapes must be replaced by their literal values. You can do this by putting the code above in the file and running:

perl -0pi -e 's/\\x(..)/chr hex $1/eg;s/;\n$//' oddeven.pl