Program Sequence Generator Your challenge is to implement a cyclic Program Sequence Generator (PSG) in a language of your choice.

Given a language, L, a PSG in L is a program in L that outputs a PSG in L. Some properties of a PSG are:

Repeated execution of a PSG in L generates a sequence of programs in L.
A PSG is said to be cyclic if the sequence it generates is cyclic.
The period of a cyclic PSG, P, is written T(P) and is the period of the cycle in the sequence it generates. The period of a non-cyclic PSG is written the same way and is infinite.

A trivial example of a PSG is a quine; any quine is a cyclic PSG with period 1.

To make this challenge interesting, the period of your PSG must be at least 5.

Scoring is a bit different than typical code golf. Informally, your score is the sum of the length of all programs in one cycle of the sequence generated by your PSG divided by the period of your PSG. Formally: let P be your PSG, pₙ be the nth term in your PSG's sequence, and l(pₙ) be the length in bytes of pₙ. Then your score is:

For a non-cyclic PSG, since the limit of l(pₙ) as n goes to infinity is infinity, the score of any non-cyclic PSGs diverges to infinity.

The PSG with the lowest score wins

JavaScript (ES6), score 77 74 66
The period of this PSG is 5.  Each iteration of the sequence removes one asterisk in the block comment until it reaches 2, then goes back to 6.
f=_=>/**/`f=${f}`.replace('**/','*/').replace('/*\/','/******/')

Let's look at some partial sums to see what the limit approaches.
m     1     2     3     4     5
score 64    66    66.33 66.25 66

Edit: thanks to @ETHproductions for pointing out that I should put the comment first.  Not only is the code much shorter, it appears neater!


Print a specific value in this generated binary matrix Suppose we define an infinite matrix M, on N^2 -> {0, 1} (where N starts from 1 instead of 0) in this manner:

M(1, 1) = 0.
For every x > 1, M(x, 1) = 1 if x is prime, and 0 otherwise.
For every y > 1, M(1, y) = the yth term in the Thue-Morse sequence.
For every x, y > 1, M(x, y) = M(x, y-1) + M(x-1, y) mod 2.

The top-left 16x16 section of this matrix looks like (with x being rows and y being columns):

0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0
1 0 1 1 0 0 0 1 0 0 0 1 1 0 1 1
1 1 0 1 1 1 1 0 0 0 0 1 0 0 1 0
0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1
1 0 1 1 0 0 1 0 1 0 1 1 1 1 0 1
0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1
1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 1
0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1
0 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1
0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 0
1 0 1 1 1 0 0 1 1 0 1 0 1 0 1 1
0 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1
1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 0
0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1
0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1
0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 1

Your task is to build a program that will evaluate the value of an arbitrary entry in this matrix as accurately as possible.

Your program will take two integers x and y as input, in any form you choose, and return M(x, y), which will be either 0 or 1.

Your code may be written in any language, but must not exceed 64 kilobytes (65,536 bytes) of source code size or 2 MB (2,097,152 bytes) of total memory usage. Your program must start with empty memory (i.e. it cannot load data from somewhere else) and run independently for each input (that is, it may not store common data for multiple runs). Your program must also be able to evaluate all the entries in the top-left 8192x8192 square in a reasonable amount of time.

The program that evaluates the most entries correctly in the top-left 8192 x 8192 square will be the winner, with shorter code acting as a tie-breaker.

J - 42 38 char

Pretty fast, 100% accurate, and well within the memory constraints.

([{+2&(~:/@#:@#@],~:/\,(p:>:)&#)0:)&<:

The strategy is as follows: we will calculate successive antidiagonals of this matrix, performing a pairwise XOR to move along and adding the current Thue-Morse and prime bits to the ends. We then pull the required digit out of the antidiagonal when we get there.

Explanation by explosion:

(                                 )&<:  NB. decrement each of x and y
     &(                        )        NB. apply the following function...
   +                                    NB. ... (x-1)+(y-1) times...
                                0:      NB. ... starting with a zero:
    2             ~:/\                  NB.   pairwise XOR on the argument
                      ,(p:>:)&#         NB.   append prime bit (is 1+length prime?)
       ~:/@#:@#@],                      NB.   prepend TM bit (XOR of binary)
 [{                                     NB. take the x-th bit (at index x-1)

Usage of this verb is x m y for M(x, y) as specified in the question, where m is the verb.

   5 ([{+2&(~:/@#:@#@],~:/\,(p:>:)&#)0:)&<: 8
0
   m =: ([{+2&(~:/@#:@#@],~:/\,(p:>:)&#)0:)&<:
   1+i.16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
   m/~ 1+i.16
0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0
1 0 1 1 0 0 0 1 0 0 0 1 1 0 1 1
1 1 0 1 1 1 1 0 0 0 0 1 0 0 1 0
0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1
1 0 1 1 0 0 1 0 1 0 1 1 1 1 0 1
0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1
1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 1
0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1
0 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1
0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 0
1 0 1 1 1 0 0 1 1 0 1 0 1 0 1 1
0 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1
1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 0
0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1
0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1
0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 1

To save keystrokes we don't try to tell if we still need more prime or Thue-Morse bits, so we compute the entire antidiagonal to get the bit we want. However, 8192 m 8192 still runs in less than 0.07 s and about 100 KiB on my modest laptop.


Least Common Multiple The least common multiple of a set of positive integers A is the smallest postive integer B such that, for each k in A, there exists a positive integer n such that k*n = B.
Given at least two positive integers as input, output their least common multiple.
Rules

Builtins are allowed, but if your solution uses one, you are encouraged to include an alternate solution that does not use GCD/LCM builtins. However, the alternate solution will not count towards your score at all, so it is entirely optional.
All inputs and outputs will be within the natively-representable range for your language. If your language is natively capable of arbitrarily-large integers, then your solution must work with arbitrarily large inputs and outputs.

Test cases
[7, 2] -> 14
[8, 1] -> 8
[6, 4, 8] -> 24
[8, 2, 1, 10] -> 40
[9, 6, 2, 1, 5] -> 90
[5, 5, 7, 1, 1] -> 35
[4, 13, 8, 8, 11, 1] -> 1144
[7, 2, 2, 11, 11, 8, 5] -> 3080
[1, 6, 10, 3, 4, 10, 7] -> 420
[5, 2, 9, 10, 3, 4, 4, 4, 7] -> 1260
[9, 7, 10, 9, 7, 8, 5, 10, 1] -> 2520


Visualize Inclusion-Exclusion Inclusion-Exclusion lets you calculate the sizes of some unions and intersections between sets knowing some of the other values. I won't explain it exactly, but your challenge is to visualize inclusion-exclusion on a Venn Diagram.

Because I'm nice, you'll be using rectangles, not circles.

You will be given a list of rectangles denoted by top-left and bottom-right corner coordinates in any reasonable format (list of 4-tuples, list of pairs of pairs, list of pairs, etc). You can assume that all coordinates are non-negative and within your language's (reasonable) number range (please specify what it is if it's less than 128). You can choose to be left-inclusive or left-exclusive and right-inclusive or right-exclusive. Regardless of your chosen format, you can assume all rectangles are at least 1x1.

Then, you are to draw out each rectangle on the screen (ASCII canvas) using a single non-whitespace character k, which is yours to choose.

However, whenever two rectangles overlap, the overlapping area shall be drawn with another non-whitespace character l != k, also yours to choose.

Whenever three rectangles overlap, the overlapping area should be drawn with k, and for an odd number of rectangles covering, k, and an even number, l.

The background should be single whitespaces (0x20).

Test Cases (k = "#", l = ".")

0 0 9 9
1 1 10 10
2 2 11 11

#########
#........#
#.#######.#
#.#######.#
#.#######.#
#.#######.#
#.#######.#
#.#######.#
#.#######.#
 #........#
  #########

1 1 3 3
2 2 4 4

 ##
 #.#
  ##

1 1 9 9
2 2 8 8
3 3 7 7

 ########
 #......#
 #.####.#
 #.####.#
 #.####.#
 #.####.#
 #......#
 ########

Notes

Leading spaces and newlines (which occur if the minimum coordinate isn't 0, 0) must be present
Any trailing spaces and newlines are allowed to a reasonable extent (i.e. don't trail like 100000000 newlines, that's just annoying)
x- and y- axes can face either way but you must be consistent and specify which (default is x- right and y- down)
coordinates can be 0-, 1-, or 2- indexed.

Reference Proton Implementation

This is code-golf, so the objective is to have the shortest code. Happy golfing!

6502 machine code routine (C64), 57 bytes

20 44 E5 A0 03 84 FB 20 9B B7 A4 FB 96 22 C6 FB 10 F5 85 FC A6 24 20 F0 E9 A4
25 B1 D1 09 01 49 02 91 D1 C8 C4 23 D0 F3 E8 E4 22 D0 E9 A9 2C C5 FC F0 D0 A5
C6 F0 FC C6 C6 4C 44 E5

This is position-independent code, put it somewhere in RAM and use the correct start address calling it with sys.

Online demo (start address $C000 / 49152).

Usage: sys<startaddress>,<x1>,<y1>,<x2>,<y2>[,<x1>,<y1>,<x2>,<y2>[,...]]

Example: sys49152,0,0,9,9,1,1,10,10,2,2,11,11

On reasonable number ranges: The natural range on this 8-bit machine is [0-255], and the program will accept this as parameters. But the C64 screen only has 40 columns and 25 rows, therefore limiting the reasonable range to [0-40] for x values and [0-25] for y values. Using other values will have unpredictable behavior.

commented disassembly listing:

20 44 E5    JSR $E544           ; clear screen
 .mainloop:
A0 03       LDY #$03            ; index for reading coordinates
84 FB       STY $FB
 .inputrect:
20 9B B7    JSR $B79B           ; read 8bit value from parameter
A4 FB       LDY $FB
96 22       STX $22,Y           ; and store to $22-$25
C6 FB       DEC $FB
10 F5       BPL .inputrect      ; parameter reading loop
85 FC       STA $FC             ; store last character
A6 24       LDX $24             ; load y1
 .rowloop:
20 F0 E9    JSR $E9F0           ; get pointer to screen row in $d1/$d2
A4 25       LDY $25             ; load x1
 .colloop:
B1 D1       LDA ($D1),Y         ; load character at screen position
09 01       ORA #$01            ; set bit 0 ( -> '#')
49 02       EOR #$02            ; toggle bit 1 (toggle between '#' and '!' )
91 D1       STA ($D1),Y         ; store character at screen position
C8          INY                 ; next x
C4 23       CPY $23             ; equals x2?
D0 F3       BNE .colloop        ; no -> repeat
E8          INX                 ; next y
E4 22       CPX $22             ; equals y2?
D0 E9       BNE .rowloop        ; no -> repeat
A9 2C       LDA #$2C            ; load ','
C5 FC       CMP $FC             ; compare with last character from parsing
F0 D0       BEQ .mainloop       ; if ',', repeat reading coordinates
 .waitkey:
A5 C6       LDA $C6             ; load input buffer size
F0 FC       BEQ .waitkey        ; and repeat until non-empty
C6 C6       DEC $C6             ; set back to empty
4C 44 E5    JMP $E544           ; clear screen


If a program terminates and there is no one to see it, does it halt? It's time to face the truth: We will not be here forever, but at least we can write a program that will outlive the human race even if it struggles till the end of time.
Your task is to write a program that has a expected running time greater than the remaining time till the end of the universe.
You may assume that:

The universe will die from entropy in 101000 years.
Your computer:

Will outlive the universe, because it is made of Unobtainium.
Has infinite memory/stack/recursion limit.
Its processor has limited speed.

You must show that your program terminates (sorry, no infinite loops) and calculate its expected running time.
The standard loopholes apply.
This is a code golf challenge, so the shortest code satisfying the criteria wins.
EDIT:
Unfortunately, it was found (30min later) that the improbability field of Unobtainium interferes with the internal clock of the computer, rendering it useless. So time based programs halt immediately. (Who would leave a program that just waits as its living legacy, anyway?).
The computer processor is similar to the Intel i7-4578U, so one way to measure the running time is to run your program in a similar computer with a smaller input (I hope) and extrapolate its running time.

Podium
#CharsLanguageUpvotes        Author
1    5      CJam              20       Dennis
2    5      J                          5         algorithmshark
3    7      GolfScript       30        Peter Taylor
4    9     Python                 39        xnor
5    10   Matlab             5          SchighSchagh
* Upvotes on 31/08

JavaScript, 39

(function f(x){for(;x!=++x;)f(x+1)})(0)

Explanation

Since JavaScript does not precisely represent large integers, the loop for(;x!=++x;) terminates once x hits 9007199254740992.

The body of the for loop will be executed Fib(9007199254740992) - 1 times, where Fib(n) is the nth fibonacci number.

From testing, I know my computer will do less than 150,000 iterations per second. In reality, it would run much slower because the stack would grow very large.

Thus, the program will take at least (Fib(9007199254740992) - 1) / 150000 seconds to run. I have not been able to calculate Fib(9007199254740992) because it is so large, but I know that it is much larger than 101000 * 150,000.

EDIT: As noted in the comments, Fib(9007199254740992) is approximately 4.4092*101882393317509686, which is indeed large enough.


Raise a single number Introduction

Suppose you want to compute the tail maxima of a list of numbers, that is, the maximum of each nonempty suffix.
One way to do it is to repeatedly choose one number and replace it by a higher number occurring after it, until this is not possible anymore.
In this challenge, your task is to perform one step of this algorithm.

The task

Your input is a list of integers L, which may be empty.
Your output shall be the list L where exactly one number Li has been replaced by another Lj, where Li < Lj and i < j.

In other words, you shall replace one number with a higher number that occurs after it.

You can choose i and j freely among all valid pairs, and the choice can be nondeterministic.

If such i and j do not exist (i.e. L is non-increasing), your output shall be L unchanged.

Example

Consider the input L = [ 3, 1, 4, -1, 2 ].
The possible operations are to replace 3 by 4, replace 1 by 4, replace 1 by 2, or replace -1 by 2.
Thus the possible outputs are:

 [  3 ,   1 ,   4 ,  -1 ,   2 ]
 ------------------------------
 [( 4),   1 ,(  4),  -1 ,   2 ]
 [  3 ,(  4),(  4),  -1 ,   2 ]
 [  3 ,(  2),   4 ,  -1 ,(  2)]
 [  3 ,   1 ,   4 ,(  2),(  2)]

If you repeat the operation enough times, the end result will be [4,4,4,2,2], which is precisely the list of tail maxima of L.

Rules and scoring

You can write a full program or a function.
In the latter case, you can modify the input in place instead of returning a new array, if your language allows that.
Input and output formats are flexible within reason.

The lowest byte count wins.

Test cases

All possible outputs are shown.

[] -> []
[1] -> [1]
[1,2] -> [2,2]
[2,1] -> [2,1]
[4,4,4,4] -> [4,4,4,4]
[-1,-3,-10] -> [-1,-3,-10]
[1,3,10] -> [3,3,10] [10,3,10] [1,10,10]
[1,1,2,1] -> [2,1,2,1] [1,2,2,1]
[998,64,2,-94,-789] -> [998,64,2,-94,-789]
[998,2,64,-94,-789] -> [998,64,64,-94,-789]
[3,1,4,-1,2] -> [4,1,4,-1,2] [3,4,4,-1,2] [3,2,4,-1,2] [3,1,4,2,2]
[-1,4,0,4,7,2,3] -> [4,4,0,4,7,2,3] [0,4,0,4,7,2,3] [-1,4,4,4,7,2,3] [7,4,0,4,7,2,3] [-1,7,0,4,7,2,3] [-1,4,7,4,7,2,3] [-1,4,0,7,7,2,3] [2,4,0,4,7,2,3] [-1,4,2,4,7,2,3] [3,4,0,4,7,2,3] [-1,4,3,4,7,2,3] [-1,4,0,4,7,3,3]
[3542,-12311,7662,1672,6081] -> [7662,-12311,7662,1672,6081] [3542,7662,7662,1672,6081] [3542,1672,7662,1672,6081] [6081,-12311,7662,1672,6081] [3542,6081,7662,1672,6081] [3542,-12311,7662,6081,6081]

JavaScript (ES6), 41 40 39 38 bytes

Saved a byte thanks to @Neil, another thanks to @user81655

x=>x.map(c=>c<x[++i]>d?x[d=i]:c,d=i=0)

Just when it seems reduceRight might finally have a chance, .map shows up yet again...


Hilbert's Grand Hotel Introduction

Some of you may have heard of Hilbert's Grand Hotel. The manager there has lost his list of where the guests are staying but he still has the order in which they checked in. Each guest can not stay in a room with a room number less than their value and if a guest is added to a lower room, all guests in higher rooms with no empty space between them and the new guest are shifted up one room. Can you help him find where each of the guests are staying?

Requirements

Write a program which receives an ordered list of natural numbers as input and places them at their index. If there is already a value in that index, it is shifted up to the next entry in the list. This process repeats until the first empty (0 or undefined) space is found. Any undefined spaces between the current highest index and any new input will be filled by adding 0s. As this is Hilbert's Grand Hotel, rooms higher than the current highest occupied index do not exist.

Input and Output

Input will be an ordered list of natural numbers (allowed to be read through any accepted form of input)
Each number in the input is considered one guest arriving at the hotel and is in order of arrival

Output will be the final arrangement of guests (numbers)

Examples

  Input: 1 3 1
  Output: 1 1 3
  Step by step:
  1
  Create room at index 1 and place 1 in it
  1 0 3
  Create rooms up to index 3 and place 3 in room 3
  1 1 3
  Shift the contents of room 1 up one room and place 1 in room 1

  Input: 1 4 3 1 2 1
  Output: 1 1 2 1 3 4
  Step by step:
  1
  Create room at index 1 and place 1 in it
  1 0 0 4
  Create rooms up to index 4 and place 4 in room 4
  1 0 3 4
  Place 3 in room 3
  1 1 3 4
  Shift contents of room 1 up one room and place 1 in room 1
  1 2 1 3 4
  Shift contents of rooms 2 to 4 up one room and place 2 in room 2
  1 1 2 1 3 4
  Shift contents of rooms 1 to 5 up one room and place 1 in room 1

  Input: 10
  Output: 0 0 0 0 0 0 0 0 0 0 10
  Step by step:
  0 0 0 0 0 0 0 0 0 10
  Create rooms up to room 10 and place 10 in room 10

  Notes:
  Working with 0 indexed is fine and you may insert a 0 at the front of the output in that case

Standard loopholes are forbidden, shortest code in bytes wins

PHP 93 bytes

for(;$r=$g?$r+1:$g=$argv[++$i];[$g,$h[$r]]=[$h[$r],$g])$h=array_pad($h?:[],$g,0);print_r($h);

0 indexed. Uses a 2 in 1 loop that looks up the next guest after it gets a 0 (or a null form going beyond the current final room). Use like:

php -r "for(;$r=$g?$r+1:$g=$argv[++$i];[$g,$h[$r]]=[$h[$r],$g])$h=array_pad($h?:[],$g,0);print_r($h);" 1 4 3 1 2 1

Ungolfed:

for( $hotel = []; $room = $guest = $argv[ ++$i ]; )
{
    for( $hotel = array_pad( $hotel, $guest, 0 ); $guest; $room++ )
    {
        $last = $hotel[ $room ];
        $hotel[ $room ] = $guest;
        $guest = $last;
    }
}
print_r( $hotel );


Magrathea 2.0 - Building Mountains With the big crash of the universal economy also the demand for custom made planets plunged. The Magratheans had to look after more steady revenues also from a broader class of customers. Therefore, they invented the have-your-own chain of mountain (or short havoc-o-mountains) for people with smaller budget who could not afford a complete planet.
The mountains are build according to the customer's plan (a.k.a. strings of digits and dots) and delivered using ascii-art (consisting of  , /, \, ^ and v).
Task
Write a complete program which takes input (single string) either from STDIN or as argument and outputs to STDOUT. This puzzle is a code-golf so please show some attempt at golfing.
Input
A string of dots and digits providing the basis for the mountain chain. Each string is exactly as long as necessary to support the mountains and each peak is given by a digit instead of a dot, indicating the height of the peak.
Output
An ascii version of the mountain chain.

Each digit in the input represents exactly one peak (^) at exactly the height indicated by the digit (i.e. 9 is the highest height).
There must not be additional peaks in the output (i.e. at places where there is a dot in the input).
Mountains are of triangular shape, i.e. slopes are created using / and \ characters.
Passes where two mountains overlap are shaped using the character v.
No superfluous newlines nor blank lines.
Padding lines with trailing spaces is optional.

You may assume that the input provided is valid, i.e. there always exists a solution according to the rules (e.g. an input of 13.. would not result in a valid configuration and may be ignored). Moreover, on each side there are exactly as many dots such that the mountains must no be cropped.
Examples
The first line shows the input, all other lines constitute the desired output. (Actually the mountains look much better in my console than here.)
1
^

11
^^

1.2.
  ^
^/ \

.2.3..
   ^
 ^/ \
/    \

.2..3..
    ^
 ^ / \
/ v   \

...4...3...3..
   ^
  / \  ^   ^
 /   \/ \ / \
/        v   \

Javascript: 272 268 233 232 201 192 189 188 178 180 characters

Thanks to @Sam for reducing it from 268 to 233 characters, and for @manatwork for another 1 char. @VadimR for pointing out a bug.

p=prompt(r=t='');s=' ';for(d=10;d--;r=s+q+s,t+=q.trim()?q+'\n':'')for(q='',i=0;i<p.length;)q+=' \\/v^'[p[i++]==d?4:(/\^|\\/.test(r[i-1])+2*/\^|\//.test(r[i+1]))*(r[i]==s)];alert(t)

Properly idented and somewhat ungolfed version with comments:

// The output initialization is just a golfing trick suggested by @manatwork.
input = prompt(state = output = '');
space = ' ';

// Repeat for each line, from the top (the highest peak, highest digit) to the floor (digit 1). Start at 10 to avoid a bug.
for (digit = 10; digit--;

      // Update the state of our automaton, at the end of the iteration.
      // Add a space after and before to simplify the future pattern recognization.
      state = space + line + space,

      // Add the line to the output if it is not an empty line, at the end of the iteration.
      output += line.trim() ? q + '\n' : '')
{ // This curly brace was added for readability, it is not in the golfed source.

  // Analyze each character in the current state to produce a new state, like a cellular automaton.
  for (line = '', i = 0; i < input.length;)
  { // This curly brace was added for readability, it is not in the golfed source.
    line +=

        // If the input is the current digit number, evaluate to 4 and put a peak in this character.
        // Otherwise evaluate this expression with those rules:
        // 1 means that the hill is higher only at right in the previous iteration, we do climb it to the right in this one.
        // 2 means that the hill is higher only at left in the previous iteration, we do climb it to the left in this one.
        // 3 means that the hill is higher at both sides in the previous iteration, we are in a v-shaped valley.
        // 0 means nothing to do here. If the middle is not a space, it will be multiplied by 0 and become 0.
        ' \\/v^'[input[i++] == digit ? 4 : (/\^|\\/.test(state[i - 1]) + 2 * /\^|\//.test(state[i + 1])) * (r[i] == space)];
    } // This curly brace was added for readability, it is not in the golfed source.
} // This curly brace was added for readability, it is not in the golfed source.

// Give the final output.
alert(output);

As you may note from the code, this works as a cellular automaton, where each cells checks for a number in the input, looks to itself and to its two neighbours to decide what the next iteration will be. At each moment a cell may be a ^, /, \, v or . The input provided in the test cases produces the expected output.

Note that using the alert box sucks, since it normally does not have a monospaced font. You may copy & paste the text from the alert box to somewhere else for a better appreciation of the output, or you may replace the last line alert by console.log, but since this is code-golf, alert is shorter.

Further, it does not validates anything in the input. It simply considers unrecognized characters as spaces the same way it does to . (in fact . is an unrecognized character too).


Line through Polygon Input: A line of the standard slope-and-intercept form: mx+b, as well as a set of Cartesian points determining the vertices of a polygon. Assume that the x and y values of the points will be integers.

Output: A boolean, which is true if the line enters or touches the polygon, and is false otherwise.

This is a little tricky, so I'll give a clue: turn the vertices that determine an edge into lines.

Test Cases
2x+3 (1,2) (2,5) (5,10) -> False
5x+0 (5,10) (2,10) (2,-10) (5,-10) -> True
0.5x+3.1 (1, 2), (-1, 2), (5, 8), (6, 7), (2, 10) -> True

Shortest or most creative code wins. I don't know too many languages, so explain your algorithm in your post. Good luck!

Ruby, 103 101 characters
m,b,*q=gets.scan(/[\d\.]+/).map{|t|t.to_f}
s=t=!0
q.each_slice(2){|x,y|x=x*m+b;s|=x<=y;t|=x>=y}
p s&t

Input is on STDIN in the form specified in the question while output goes to STDOUT.


Radiation hardened cyclic quine polyglot Challenge

Write two programs that:

run in two different programming languages.

These may not be two versions of one language.

when one program is run, it outputs the second program, and vice versa.
The two programs must be different (no polyglots).

Here's the catch though:

The programs must be radiation hardened.

This means that when any set of \$n\$ (defined below) characters is removed from either of the two programs, their functionality is unaffected.
\$n\$ is defined as the number of characters that may be omitted with your program's functionality unaffected.
\$n\$ must be at least \$1\$.

Rules

Standard loopholes are disallowed.
Your programs must be proper cyclic quines. They may not read their own source code.
Scoring is performed as follows:

Your score is \$\frac{S_1+S_2}n\$…
where \$S_1\$ and \$S_2\$ are the size of your first and second programs respectively…
and \$n\$ is as defined above.

This is a code-challenge, lowest score wins.

Reward

As this challenge is difficult to answer, I will be giving a bounty to the first person to answer.

Gol><> and ><>, (117 bytes + 117 bytes)/1 = 234
Gol><>
\\<<'3d*}}}}~}:r0<}!o::! ?>~~a<o>Hr~Kl a}}:?%2l}}}ss2"<<\\
\\<<'3d*}}}}~}:r0<}!o::! ?>~~a<o>Hr~Kl a}}:?%2l}}}ss2"<<\\

Try it online!
><>
\\<<"2ss}}}l2%?:}}a lK~rH>o<a~~>? !::o!}<0r:}~}}}}*d3'<<\\
\\<<"2ss}}}l2%?:}}a lK~rH>o<a~~>? !::o!}<0r:}~}}}}*d3'<<\\

Try it online!
Verification!
These two programs are the same, just reversed. They both follow the same general code structure.
Explanation (Gol><> on top, ><> on the bottom)
\\<<                           <<\\  Transition to the copy of the code that is not radiated
\\<<                           <<\\

                              "    Wrapping string literal over the rest of the code
                              '

                           ss2     Push the string character
                           *3d

                        }}}        Rotate the "<<\" to the correct end of the stack
                        }}}

                 }}:?%2l           Use the extra \ to replace a possible irradiated copy
                    }~}:

       ~     lK                    Duplicate the code
        ~~>? !::o!}<0r             Print a copy of the code in reverse

                a                  Push a newline
       a
    Hr                             Reverse, print the rest of stack and terminate
    >o<                            Print the rest of the stack and terminate


What's the Mayan date? Just over seven years ago, everybody suddenly stopped talking about the Maya people. It is time to rectify that!

For clarification, I am talking about the Mesoamerican Long Count Calendar. Your program will have as input a date in the Gregorian Calendar, and as output the corresponding date from the aforementioned Mesoamerican calendar.

That calendar counts days since August 11, 3114 BCE. It divides that number of days into periods of different lengths. There's the single day, the Winal (20 days), the Tun (18 Winal, or 360 days), the K'atun (20 Tun, 7200 days), and the B'ak'tun (20 K'atun, 144 000 days).

So you have your number of days since the epoch, then you find out how many of each period fit in there. Let's take William the Conqueror's coronation date of December 25, 1066. We're not bothering with the Julian Calendar here - we're using the Proleptic Gregorian Calendar for dates in the distant past (including the Maya epoch): basically the system of leap days every four years, except years divisible by 100 but not by 400, which I trust you're all familiar with.

Between Christmas Day in 1066 and the Maya epoch date of August 11, 3114 BCE, there's 1526484 days. In that number, you can fit 10 periods of 144000 days, so that's our B'ak'tun. The remainder, 86484, can fit 12 periods of 7200 days, so that's the K'atun. The remainder is 84. That's less than 360, so our Tun is 0. You can fit 4 Winal though, leaving a remainder of 4 days.

Now concatenate all those numbers with full stops in between, in decreasing order of period length. The date of 25 December 1066 becomes 10.12.0.4.4.

(luckily, Wolfram|Alpha can verify it too)

Specification

Your program will take as input a date in the Gregorian Calendar, between January 1, 1 AD (7.17.18.13.3), and 31 December, 3999 AD (18.0.15.17.6). The date can be in any format you want (my test cases will be using ISO 8601) as long as it is in the Gregorian calendar.

That means, valid input formats include (but are not limited to) "22 MAR 2233", "7/13/2305", "20200107T000000Z", and "2020-01-07T00:00:00+00:00", even an array like "[7], [1], [2020]", depending on what your language parses the most easily or what approach you want to use. It is not allowed however to include any information beyond year, month, day of the month, time (has to be 00:00:00) and time zone (has to be GMT). Once I start allowing the day of the year, the Unix timestamp, a full-fledged DateTime data object (which contains a host of other values) or some other date tracking scheme, this issue would no longer be about converting a Gregorian date into a Mayan date, but only about representing a Mayan date. So basically, just stick with a primitive or a list of primitives for input.

It will output a string containing the corresponding Mayan date, as discussed above. It has to be a single string of numbers separated by periods; an int array is not allowed. Using a built-in Maya converter in your language (though I would be surprised if it had one) is not permitted either.

The question is tagged code-golf, so the shortest program in byte count wins!

Test cases

Gregorian; Mayan
1-1-1; 7.17.18.13.3
1-1-2; 7.17.18.13.4
1066-12-25; 10.12.0.4.4
2000-2-29; 12.19.7.0.1
2012-12-21; 13.0.0.0.0
2020-1-5; 13.0.7.2.11
2100-3-1; 13.4.8.8.6
2154-4-11; 13.7.3.6.10
3999-12-31; 18.0.15.17.6

Python 3, 149 \$\cdots\$ 145 140 bytes

from datetime import*
def f(d):
 n,s=(date(*d)-date(1,1,1)).days+1137143,""
 for i in[144000,7200,360,20,1]:s+=f".{n//i}";n%=i
 return s[1:]

Try it online!

Takes Gregorian date as [year, month, day] list and returns Mayan date as f"{B'ak'tun}.{K'atun}.{Tun}.{Winal}.{Day}"(loosely as a python f-string).


Shortest code to determine if a string is a palindrome A palindrome is some string that is spelled the same way both backwards and forwards.  For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE)

For this code golf, using the language of your choice, determine if a given string is a palindrome or not.

Edge Cases:

Punctuation is not counted towards palindrominess.
Control characters are not counted towards palindrominess.
Whitespace is not counted towards palindrominess.
Numbers are counted towards palindrominess.
Case in this challenge is not counted towards palindrominess.
There is no limit to the length of strings to evaluate, except for what is imposed by your language of choice.
For this challenge, limit yourself to the ASCII character set.

Technical Requirements:

Only method bodies are needed; additional things like method signatures, data structure declarations, etc. do not count towards the victory requirement.
Code must compile or interpret without compile-time errors or exceptions.
Code must not throw any unhandled exceptions or crash.  (Almost needless to say.  Almost.)
Code must return some value indicating palindrominess.  The data type depends on the language you use (e.g. a C# user might use a bool, whereas a JavaScript user could use a var.)
You may not write your own interpreter that performs this task as a 'native' capability so you can 'golf' a near-winning score.  (Hopefully needless to say.)

Victory Condition:

The shortest code in characters wins.

Current Leader: tmartin (k, 25 characters)

...Want the magic green check mark by your answer?  Beat this guy's answer!

K, 25
{x~|x:_x@&x in,/.Q`a`A`n}

.
k){x~|x:_x@&x in,/.Q`a`A`n}"Eva, can I stab bats in a cave?"
1b


Multiplication by Self-Modification ...at least for some definition of "self-modification".

The Task

In this challenge, your task is to write three strings A, B and C that satisfy the following properties.

The string B has length at least 1.
For every n ≥ 0, the string ABnC is a valid program (meaning full runnable program or function definition) in your programming language of choice. The superscript denotes repetition, so this means the strings AC, ABC, ABBC, ABBBC etc. Each program takes one string as input, and returns one string as output.
For any m, n ≥ 0, if the program ABmC is run with input ABnC, it returns ABm*n+1C. For inputs not of this form, the program may do anything, including crash.

Some examples in the format program(input) -> output:

AC(AC) -> ABC
ABC(AC) -> ABC
ABBBBBC(AC) -> ABC
AC(ABC) -> ABC
AC(ABBBBC) -> ABC
ABC(ABC) -> ABBC
ABBC(ABC) -> ABBBC
ABBBBC(ABBBC) -> ABBBBBBBBBBBBBC
ABBBC(ABBBBBBC) -> ABBBBBBBBBBBBBBBBBBBC

Rules and Scoring

Your score is the total length of A and C, lower score being better.
Note that while B is not counted toward the score, it must be produced by A and C as in the first example.

Standard loopholes are disallowed.
The programs are not allowed to directly or indirectly access their own source code (except when they are given it as input).
You are required to identify the strings A, B and C in your answer in some way, and encouraged to explain your solution.

CJam, 9 8 bytes

A: 1
B: 0
C:  r,(#0q

Try it online in the CJam interpreter.

How it works

(ABcode) e# Push the integer 10 ** len(Bcode).
<SP>     e# Noop. Separates (AB) and C for input reading.
r        e# Read the first whitespace-separated token from STDIN (ABinput).
,(       e# Push the string length minus 1: len(Binput)
#        e# Power operator: 10 ** len(Bcode) len(Binput) # ->
         e#   (10 ** len(Bcode)) ** len(Binput) = 10 ** (len(Bcode) * len(Binput))
0        e# Push an additional 0 to complete len(Bcode) * len(Binput) + 1 zeroes.
q        e# Read the remaining input (C).


Sort a string by a given ordering Your challenge is to sort a string, but rather than by the normal alphabetical order (abc..xyz), you will be sorting strings by a specified alphabet.

You must write a program or function that takes two inputs: An alphabet A and an string S. Both will only contain lowercase English letters, and both will contain at least one character.

You must move letters in S so that the letter that appears first in A appears first, then whichever letter appears second in A, etc. There may be some letters in S that do not appear in A, these should be left at the end and not moved around relative to each other.

Test cases:

A       S               Result
axd     haxuizzxaxduxha aaaxxxxdhuizzuh
a       xyz             xyz
abc     dcba            abcd
il      nmiuplliu       iillnmupu
asdf    qwerty          qwerty

Fewest bytes wins!

Python 3, 50 47 46 44 bytes

-3 bytes thanks to ngn!

-1 byte thanks to mypetlion

lambda a,s:s.sort(key=lambda c:a.find(c)%27)

Try it online!

Takes in a string as the alphabet and a list of chars as the string and sorts the list in place.

The %27 ensures that if the character is not in the alphabet, the index returned puts it after the rest of the alphabet.


Downward Number Race Your task is to create a program that adds random numbers to previous sums in the ultimate number racing showdown.

Each racer (column) starts at 0 and adds either 1 or 0 to the previous sum at each step of the race until all of the racers reach the score required to win. The 1 or 0 should be chosen at random (the standard definition of random can be found here). The output will show the result of the race, with each column representing one racer, in this format:

>> racers:5,score needed:2

0 0 0 0 0 # all racers start at 0
+ + + + + # add
1 0 0 0 1 # random 1 or 0
= = = = = # equals
1 0 0 0 1 # sum
+ + + + +
0 0 0 0 1
= = = = =
1 0 0 0 2 # winner!
+ + + +
1 1 1 1
= = = =
2 1 1 1
  + + +
  1 1 1
  = = =
  2 2 2   # losers

Note: only the numbers, +, and = need to be included in the output.

Input

Your program will accept the following two parameters as input:

the number of racers (columns), which must be greater than two
the score required to win, which must be greater than one

This is code-golf--the program with the least bytes wins.

Edit: there's a non-enforceable max score of 9--this is to preserve the integrity of the column. Also, spaces between columns can be omitted in the output.

Pyth, 38 34 bytes

j.tm+j\=jL\+C,.u+NYJ.WnsHQ+ZO2Y0J+\=QE
j.tmj\=jL\+.T,.u+NYJ.WnsHQ+ZO2Y0JE

Try it online!


Codegolf the Hafnian The challenge is to write codegolf for the Hafnian of a matrix.
The Hafnian of an 2n-by-2n symmetric matrix A is defined as:

Here S2n represents the set of all permutations of the integers from 1 to 2n, that is [1, 2n].

The wikipedia link talks about adjacency matrices but your code should work for any real valued symmetric input matrices.

For those interested in applications of the Hafnian, the mathoverflow link discusses some more.

Your code can take input however it wishes and give output in any sensible format but please include in your answer a full worked example including clear instructions for how to supply input to your code.

The input matrix is always square and will be at most 16 by 16. There is no need to be able to handle the empty matrix or matrices of odd dimension.

Reference implementation

Here is some example python code from Mr. Xcoder.

from itertools import permutations
from math import factorial

def hafnian(matrix):
    my_sum = 0
    n = len(matrix) // 2
    for sigma in permutations(range(n*2)):
        prod = 1
        for j in range(n):
            prod *= matrix[sigma[2*j]][sigma[2*j+1]]
        my_sum += prod
    return my_sum / (factorial(n) * 2 ** n)

print(hafnian([[0, 4.5], [4.5, 0]]))
4.5
print(hafnian([[0, 4.7, 4.6, 4.5], [4.7, 0, 2.1, 0.4], [4.6, 2.1, 0, 1.2], [4.5, 0.4, 1.2, 0]])
16.93
print(hafnian([[1.3, 4.1, 1.2, 0.0, 0.9, 4.4], [4.1, 4.2, 2.7, 1.2, 0.4, 1.7], [1.2, 2.7, 4.9, 4.7, 4.0, 3.7], [0.0, 1.2, 4.7, 2.2, 3.3, 1.8], [0.9, 0.4, 4.0, 3.3, 0.5, 4.4], [4.4, 1.7, 3.7, 1.8, 4.4, 3.2]])
262.458

The wiki page has now (March 2 2018) been updated by  ShreevatsaR to include a different way of calculating the Hafnian.  It would be very interesting to see this golfed.

R, 150 142 127 119 bytes

function(A,N=nrow(A),k=1:(N/2)*2)sum(apply(gtools::permutations(N,N),1,function(r)prod(A[cbind(r[k-1],r[k])])))/prod(k)

Try it online!

Uses the same trick I discovered golfing down this answer to index the matrix P, and @Vlo suggested an approach to entirely remove the for loop for -6 bytes!

To create a new test case, you can do matrix(c(values,separated,by,commas,going,across,rows),nrow=2n,ncol=2n,byrow=T).

Explanation: (the code is the same; it uses an apply rather than a for loop but the logic is otherwise identical).

function(A){
N <- nrow(A)                   #N = 2*n
k <- 1:(N/2) * 2               #k = c(2,4,...,N) -- aka 2*j in the formula
P <- gtools::permutations(N,N) #all N-length permutations of 1:N
for(i in 1:nrow(P))
 F <- F + prod(A[cbind(P[i,k-1],P[i,k])]) # takes the product of all A_sigma(2j-1)sigma(2j) for fixed i and adds it to F (initialized to 0)
F / prod(k)                    #return value; prod(k) == n! * 2^n
}


Show me some fireworks! Given, in any way and order,

dimensions (in whichever order you want)

a probability (in whatever format you want)

number of iterations (you may choose whether to count the initial state or not)

do one of the following:

animate, or

output each step of, or

return a list of states of

a spaces-filled sky of those dimensions.
For each iteration:

every sky character has the given probability of becoming a *

the eight characters that surround any * become
\ | /
-      -
/ | \, if they don't become stars, however,

if a character is within range of two *s, make it an X

Example
The 7×22 sky (frame for clarity only – don't output the frame)
┌──────────────────────┐
│                      │
│                      │
│                      │
│                      │
│                      │
│                      │
│                      │
└──────────────────────┘

could with 1% probability become
┌──────────────────────┐
│  *                   │
│                      │
│                      │
│                      │
│                      │
│           *          │
│                      │
└──────────────────────┘

and the next step
┌──────────────────────┐
│ - - *                │
│ /|\                  │
│          *           │
│                      │
│          \|/         │
│          - -         │
│          /|\         │
└──────────────────────┘

and then
┌──────────────────────┐
│    - -               │
│    /|\  \|/          │
│         - -          │
│         /|\          │
│                      │
│      * *             │
│                      │
└──────────────────────┘

and
┌──────────────────────┐
│                      │
│                      │
│                      │
│                      │
│     \|X|/            │
│     - X -            │
│     /|X|\          * │
└──────────────────────┘

and so on
┌──────────────────────┐
│                      │
│                      │
│                      │
│                   *  │
│                      │
│                   \|/│
│                   - -│
└──────────────────────┘


Compare Two Lists by Their Maximum Given two different lists of non-negative integers, return the list that has the highest maximum (e.g. [4, 2], [3, 3, 1] -> [4, 2]).
If they both have the same maximum, return the list that contains more instances of this maximum (e.g. [4, 2, 4], [4, 3, 3, 3, 1, 3] -> [4, 2, 4]).
If, after these comparisons, they are equal, do the same comparison but with their next highest item (e.g. [2, 3, 4, 4], [4, 4, 3, 3, 1] -> [4, 4, 3, 3, 1]).
If, after all these comparisons, they are still considered to be equal, output the longer list (e.g. [4, 3, 2, 1, 0], [1, 2, 3, 4] -> [4, 3, 2, 1, 0]).
Make your code as short as possible.
Test Cases
[4, 4, 4, 4, 2, 4], [4, 4, 4, 4, 3, 2] -> [4, 4, 4, 4, 2, 4]
[0], [] -> [0]
[0, 0], [0] -> [0, 0]
[1], [0, 0] -> [1]
[4, 4, 4, 4, 4, 2], [4, 4, 4, 4, 4] -> [4, 4, 4, 4, 4, 2]
[1, 0], [0, 0, 0] -> [1, 0]

Pyth, 4 bytes

eo_S

Try it online

Explanation

eo_S
 o  NQ    Order the inputs...
  _S      ... by their reversed sorted values...
e         ... and take the last.


Capped string ladder Given a string s and a positive integer N, gradually duplicate each character more and more until N duplicates, and then staying at N duplicates until N characters away from the end, then step down again.

For example, given abalone and 3:

a    we start with 1 copy
bb   then 2 copies
aaa  then 3 copies, which is our second parameter
lll  so we continue using 3 copies
ooo  until we reach the end
nn   where we use 2 copies
e    and then finally 1 copy

and the result would be abbaaalllooonne.

It is guaranteed that the string has length greater than 2N and only has characters from a to z.

More testcases:

N string       output
2 aaaaa        aaaaaaaa
3 abcdabcdabcd abbcccdddaaabbbcccdddaaabbbccd

This is code-golf. Shortest answer in bytes wins. Standard loopholes apply.

Jelly, 6 bytes

JṡFṢị⁸

Try it online!

How it works

JṡFṢị⁸  Main link. Arguments: s (string), n (integer)

J       Get the indices of s.
 ṡ      Split the indices into overlapping chunks of length n.
  F     Flatten the array of chunks.
   Ṣ    Sort the resulting array of indices.
    ị⁸   Get the characters of s at these indices.

Sample run

JṡFṢị⁸  "abalone", 3

J       [1, 2, 3, 4, 5, 6, 7].
 ṡ      [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]]
  F     [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7]
   Ṣ    [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7]
    ị⁸  "abbaaalllooonne"


Lets take Beal's $1,000,000 Beal's Conjecture has a million dollar prize if you prove/disprove it.

It states that if  where A, B, C, x, y, and z are positive integers with x, y, z > 2, then A, B, and C have a common prime factor.

The challenge is to write a program that searches for a counter example to disprove this!

Rules

Write a program searching for a counter example of Beal's Conjecture
You can perform an exhaustive search (i.e., all possible combinations of numbers that fit this form) or use some optimizations (e.g., A and B are symmetrical).
You must use arbitrary-precision integers.

Notes

This is a popularity contest, be creative!
Speed isn't necessary, but makes it more interesting. Optimize!
I am also interested in seeing the shortest code too. You will get a +1 from me!
I'll run the winning program on a supercomputer that I have access to!
This conjecture is considered to be true, but that doesn't mean we can't try!
Peter Norvig of Google  has attempted this problem too. You may use his page as guidance. He has a short Python program you can use as an example.
Some other guy (who also happens to work at Google) has greatly improved on Norvig's approach, his page (with source code) can be found here.
My SO question related to this from two years ago may also be helpful: Fin all A^x in a given range.

I'm being pathetically lazy (pun intended), but why not... seems to fulfill the rules.

Haskell, 204

import Control.Monad
import Control.Monad.Omega
main=print.filter(\[(a,x),(b,y),(c,z)]
 ->and$(a^x+b^y==c^z):zipWith(((>1).).gcd)[a,b,c][b,c,a])
 .runOmega$mapM(\_->liftM2(,)(each[1..])$each[3..])"123"

This prints1 all combinations which fulfill the counterexample property. I used the control-monad-omega package for diagonalising ℕ6... might be considered library-cheating. But seeing as someone will later post an APL answer where all this stuff is built into the language (or isn't it?), I don't give too much about it...

Of course, the program is way too slow (naïve exhaustion, and linked-lists as data structure) to be expectable of actually yielding a counterexample, but Haskell itself can actually achieve decent performance.

1Since it prints the tuples in list format, i.e. in one line, you need to switch your terminal's buffering off or you won't see when a result comes in. Alternatively, you can replace print with mapM_ print so you get a newline after each result, flushing a line-buffered terminal.

To test the program, change each[3..] to each[2..], then you'll simply get all non-coprime pythagorean tuples as result.


French license plates Sandbox

French License Plates

French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD

Challenge

Write a program or function that, for a given number, outputs the corresponding french license plate number. Your program should not handle any special case as specified in the linked page. It should be able to generate the full 26*26*1000*26*26 => 456 976 000 possible plates, or as far as your language can support.

The numbering system goes as follows:

AA-000-AA to AA-999-AA (numbers evolve first);
AA-000-AB to AA-999-AZ (then the last letter on the right);
AA-000-BA to AA-999-ZZ (then the first letter on the right);
AB-000-AA to AZ-999-ZZ (then the last letter on the left);
BA-000-AA to ZZ-999-ZZ (then the first letter on the left).

Input

The plate number's index as an integer

Output

The corresponding french license plate number

Additional information

Letters have to be uppercase
You can use both 0-based and 1-based indexing to generate the plates (meaning AA-000-AA can correspond to 0or 1, assuming all the other test cases use the same indexing.

This is code-golf, shortest answer in every language wins!

Test cases (0-based indexing)

          0 -> AA-000-AA
          1 -> AA-001-AA
        999 -> AA-999-AA
       1000 -> AA-000-AB
    675 999 -> AA-999-ZZ
    676 000 -> AB-000-AA
456 975 999 -> ZZ-999-ZZ

Pure Bash (no external utils), 64

2 bytes saved thanks to @NahuelFouilleul

x={A..Z}
eval f=($x$x-%03d-$x$x)
printf ${f[$1/1000]} $[$1%1000]

Try it online! - takes about 10s to run over the 7 testcases.

Line #1 is a simple assignment of a string to a variable
Line #2 is a brace expansion to build an array of printf format strings, one for all 456,976 possible letter combinations, with the digits not yet specified.  The eval is required to ensure variable expansion (of x) occurs before brace expansion.
Line #3 indexes the array to get the appropriate format string and takes the digits portion as its parameter.


Totally Invertible Submatrices (inspired by this question over on Math)

The Definitions

Given an n x n square matrix A, we can call it invertible if there exists some n x n square matrix B such that AB = BA = In, with In being the identity matrix of size n x n (the matrix with the main diagonal 1s and anything else 0), and AB and BA representing usual matrix multiplication (I won't go into that here - go take a linear algebra class).

From that, we can call an m x n matrix C totally invertible if every k x k submatrix (defined below) of C is invertible for all k > 1, k <= (smaller of m,n).

A submatrix is defined as the resulting matrix after deletion of any number of rows and/or columns from the original matrix. For example, the below 3x3 matrix C can be transformed into a 2x2 submatrix C' by removing the first row 1 2 3 and the middle column 2 5 8 as follows:

C = [[1 2 3]
     [4 5 6]    -->  C' = [[4 6]
     [7 8 9]]              [7 9]]

Note that there are many different submatrix possibilities, the above is just an example. This challenge is only concerned with those where the resulting submatrix is a k x k square matrix.

The Challenge

Given an input matrix, determine if it is totally invertible or not.

The Input

A single matrix of size m x n, in any suitable format.
Without loss of generality, you can assume m <= n or m >= n, whichever is golfier for your code, and take the input that way (i.e., you get a transpose operation for free if you want it).
The input matrix size will be no smaller than 3 x 3, and no larger than your language can handle.
The input matrix will consist of only numeric values from Z+ (the positive integers).

The Output

A truthy/falsey value for whether the input matrix is totally invertible.

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.

The Examples

Truthy

[[1 2 3]
 [2 3 1]
 [3 1 2]]

[[2 6 3]
 [1 12 2]
 [5 3 1]]

[[1 2 3 4]
 [2 3 4 1]
 [3 4 1 2]]

[[2  3  5  7  11]
 [13 17 19 23 29]
 [31 37 41 43 47]]

Falsey

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

[[1 6 2 55 3]
 [4 5 5 5  6]
 [9 3 7 10 4]
 [7 1 8 23 9]]

[[2 3 6]
 [1 2 12]
 [1 1 6]]

[[8 2 12 13 2]
 [12 7 13 12 13]
 [8 1 12 13 5]]

Jelly, 26 24 23 20 19 17 16 bytes
-1 byte thanks to @miles (unnecessary for each, €, when taking determinants)
-2 bytes, @miles again! (unnecessary chain separation, and use of Ð€ quick)
ZœcLÆḊ
œcÐ€JÇ€€Ȧ

TryItOnline! or all 8 tests
How?
œcÐ€JÇ€€Ȧ  - Main link: matrix as an array, M
    J      - range of length -> [1,2,...,len(a)] (n)
  Ð€       - for each of right argument
œc         -     combinations of M numbering n
     Ç€€   - call the last link (1) as a monad for €ach for €ach
        Ȧ  - all truthy (any determinant of zero results in 0, otherwise 1)
                 (this includes an implicit flattening of the list)

ZœcLÆḊ - Link 1, determinants of sub-matrices: row selection, s
Z      - transpose s
   L   - length of s
 œc    - combinations of transposed s numbering length of s
    ÆḊ - determinant


Hidden stereogram message You must generate an text stereogram according to an input string containing a paragraph of text, an empty line then the hidden message.
The result will be displayed as a pair of paragraphs, one with different spacing causing the effect of it being raised up when viewed stereographically (An explanation can be found here).

Example

Input:

I invented vegetarianism.  It is a diet involving no meat, just vegetables.  It is also common in cows - they are awesome.

vegetarianism. is awesome.

Output:

I      invented    I      invented
 vegetarianism.    vegetarianism.
It   is a  diet    It  is  a  diet
involving    no    involving    no
meat,      just    meat,      just
vegetables.  It    vegetables.  It
is  also common    is  also common
in cows  - they    in cows  - they
are    awesome.    are   awesome.

Bonuses

Add option to choose between parallel and cross-eyed as user input (-20)
Adjustable column width as user input (-50)

This is code golf, so shortest code after bonuses wins.

TeX 212

I am using a typesetting system, not ASCII.  The column width can be changed by changing 90pt in the fourth line, but I don't know if that's enough to qualify for the 50 bytes discount.  The distance between the two copies of the text can be changed by changing the 9pt, also in the fourth line.  The code can probably be made shorter.  One can replace each newline by a single space, but not remove them completely.

\let\e\expandafter\read5to\t\read5to\.\def\a#1
{\def\~##1#1##2\a{\def\t{##1\hbox{\
#1\~{}}##2}\a}\e\~\t\a}\e\a\.{}\shipout\hbox
spread9pt{\hsize90pt\fontdimen3\font\hsize\vbox{\t}\
\let\~\ \def\ {}\vbox{\t}}\end.

After calling tex filename.tex in the terminal, the user is prompted to give the main text, then prompted again for a list of words to shift.  No empty line in between.  The (space-separated) list of words given in the second line should appear exactly as it is in the main text (punctuation is treated just like a letter would be, only spaces delimit words).


Remove ambiguous plural(s)! Programming is very rigid. You can't tell a program to "output the banana count", you have to tell it to print(bananas).

But when you do that, you end up with a problem: you don't know how many bananas you have beforehand, so you don't know whether to use a plural.

Sometimes, programmers go the lazy way. Instead of checking, they just print there are X banana(s).

But that's ugly, so we need a program to fix this.

The method(s)

To remove the ambiguous plurals in a string, follow the following steps:

Split the string on spaces into a list of words.
For every word that ends with (s), do the following:

If the preceding word is a, an, 1 or one, remove the (s) at the end of the word.
Otherwise, if the word is the first word in the string or the preceding word is not a, an, 1 or one, replace the (s) at the end of the word with s.

Join the list of words back together into a string, preserving the original whitespace.

Example(s)

Let's take a string there's a banana(s) and three apple(s).

First, we split the string into a list of words: ["there's", "a", "banana(s)", "and", "three", "apple(s)"]

For the second step, we take the two words ending with (s): banana(s) and apple(s).

The word before banana(s) is a, so we remove the (s), making it banana.
The word before apple(s) is three, so we change the (s) to s, thus it becomes apples.

We now have ["there's", "a", "banana", "and", "three", "apples"]. Joining the list back together, we get there's a banana and three apples. This is our end result.

The challenge(s)

Create a program or function that takes an ambiguous string in any reasonable format and returns the un-ambiguated version of that string.

You may assume the string contains no newlines, tabs or carriage returns.

I forgot to specify whether to split on groups of spaces or spaces (i.e. whether okay then with two spaces should be ["okay", "then"] or ["okay", "", "then"]) when posting the challenge, so you may assume either form of splitting.

Test case(s)

Input                                         -> Output
there are two banana(s) and one leprechaun(s) -> there are two bananas and one leprechaun
there's a banana(s) and three apple(s)        -> there's a banana and three apples
apple(s)                                      -> apples
one apple(s)                                  -> one apple
1 banana(s)                                   -> 1 banana
banana                                        -> banana
preserve    original      whitespace(s)       -> preserve    original      whitespaces
11 banana(s)                                  -> 11 bananas
an apple(s)                                   -> an apple
this is a te(s)t                              -> this is a te(s)t
I am a (s)tranger(s)                          -> I am a (s)tranger

Scoring

As this is code-golf, the submission with the least bytes wins!

Mathematica, 151 148 bytes

StringReplace[j=" ";k=Except@j;j<>j<>#<>j,j~~a:k...~~s:j..~~w:k..~~"(s)"~~j:>{j,a,s,w,If[FreeQ[a,"a"|"an"|"1"|"one"],"s",""]}<>j]~StringTake~{3,-2}&

Explanation

j=" ";k=Except@j

Set j to a whitespace character(s). Set k to the pattern "not j" (= non-whitespace character).

j<>j<>#<>j

Prepend two whitespace(s) and append one whitespace(s) to the input.

j~~a:k...~~s:j..~~w:k..~~"(s)"~~j

For a substring(s) matching the pattern:

One whitespace(s), followed by
a length-zero or longer substring consisting of only non-whitespace character(s) (quantifier) (call this a), followed by
a length-one or longer substring consisting of only whitespace character(s) (call this s), followed by
a length-one or longer substring consisting of only non-whitespace character(s) (word) (call this w), followed by
the string "(s)", followed by
a whitespace(s)

If[FreeQ[a,"a"|"an"|"1"|"one"],"s",""]

If a is not one of the singular word(s), evaluate to "s", otherwise "".

StringReplace[..., ... :>{j,a,s,w,If[FreeQ[a,"a"|"an"|"1"|"one"],"s",""]}<>j]

Replace the matching pattern with j, a, s, w, If[FreeQ[a,"a"|"an"|"1"|"one"],"s",""], and j joined together.

... ~StringTake~{3,-2}

Take from position 3 to position -2 (1-indexed; negative indices count from the end). This is because we added three space(s) in the beginning.


Nameless to Brainf**k converter This is inspired by the Brainf*** to tinyBF converter challenge.

Brainf**k (which will be henceforth referred to as BF) is a well-known estoric programming language, so I won't go over it too much here.

Nameless language is a binary-looking version of BF. See the linked page for more info.

Your challenge is to implement a golfed Nameless-to-BF converter. It should implement all of the commands except for 1100 (which isn't really possible to implement in BF) and 1010 (that isn't really possible, either). Any characters other than 1's and 0's should be ignored because they can be used for comments (after all, you wouldn't want an unreadable program, right? ;).

Here's a simple table of a Nameless -> BF mapping:

0000 -> >
0001 -> <
0010 -> +
0011 -> -
0100 -> .
0101 -> ,
0110 -> [
0111 -> ]
1011 -> [-]
1000 -> adds the base 10 value of the next command to the current memory cell (see below)
1001 -> subtracts the base 10 value of the next command from the current memory cell (see below)

NOTE: I accidentally flipped < and >. Thanks to @IlmariKaronen for pointing that out.

For 1000 and 1001, you can directly implement it in the translator. For instance, this:

1000 0010

could be written as:

++

The translator determined the value of the next command in advance and wrote it out.

Invalid sequences (e.g. 1111) and the presence of 1000/1001 at the end of the program are undefined; you don't have to handle them.

MAY THE GOLFING BEGIN!!!

CJam, 58 bytes

q{As#)},:~4/2fb{(:X8<"><+-.,[]"X={XA<{("+-"X=*}"[-]"?}?o}h

Try it online.

Explanation

q               "Read the input.";
{As#)},         "Remove any extraneous characters (not '0' or '1').";
:~              "Evaluate each character ('0' -> 0, '1' -> 1).";
4/2fb           "Split into groups of 4 (Nameless commands) and numerically
                 evaluate each group as an array of binary digits.";
{               "While command values remain:";
  (:X             "Grab the next command value.";
  8<              "If the command value is less than 8:";
  "><+-.,[]"X=    "Then: It maps directly to a BF command. Look it up.";
  {               "Else:";
    XA<             "If the command value is less than 10:";
    {("+-"X=*}      "Then: It is 8 or 9. Grab the next command value and
                     produce a string of that many copies of '+' if the former
                     command value is 8, or '-' if it is 9.";
    "[-]"?          "Else: It is 11. Produce its translation, '[-]'.";
  }?
  o               "Output the BF translation.";
}h


In which number set do I belong? Introduction
Mathematicians often work with number sets. These are groups of numbers that share common properties. These are number sets are, in order from most specific to most broad:
Natural numbers   (symbol N): These are the counting numbers: 1, 2, 3, ...
Integers          (symbol Z): These are all the numbers without a fractional part: ..., -3, -2, -1, 0, 1, 2, 3, ...
Rational numbers  (symbol Q): These numbers are the quotients of two integers, such as: 1.1 (11/10), 5.67 (567/100), or 0.333333333... (1/3)
-----The following two numbers sets are equally specific in describing numbers-----
Real numbers      (symbol R): These are positive, zero, and negative numbers, such as: π (3.1415926...), e (2.7182818...), or √2 (1.4142135...)
Imaginary numbers (symbol I): Numbers that give negative values when squared; for this reason they aren't very useful in everyday life.
                              These numbers contain the letter i in them, with i representing the √-1.
                              Examples: 2i, -1.5i 78i, 9i, -3.1415i, i
-----------------------------------------------------------------------------------
Complex numbers   (symbol C): The sum of a real and an imaginary number in the form a + bi, examples: 2 + 7i, 3 + 3i, 1 - i, -8 + i

Note that when there is only a single i, it is not written 1i.
Challenge
Given a number from one of these number sets, print the symbol for the most specific number set that could describe it.
Test cases
Input              Output
73.0            -> N
4/2             -> N
-73             -> Z
-1/3            -> Q
0.56            -> Q
0.555...        -> Q
0.123123123...  -> Q
3.1415926535... -> R
-1.37i          -> I
7892/5 + 23/4i  -> C

Other info

Natural numbers and integers may be given with a decimal point followed by a string of zeros
To add on to the previous point, any input that can be converted into a simpler form shall have its output corresponding to the simplified input
Rational numbers may be given with a / to represent a fraction, or a sequence of numbers occurring 3 or more times followed by ...
Numbers ending with ... represent repeated decimals or un-terminated decimal real numbers
Any number sets less specific than Q can also have inputs be given as a fraction
You do not need to handle repeated decimals or un-terminated decimals for number sets other than Q and R
Any error caused by lack of precision in floating point numbers will not invalidate a submission

This is code golf, so shortest code wins. If there is something unclear, let me know in the comments' section or edit the question.

JavaScript (ES6), 121 110 bytes

s=>[...'QRCI'].find((_,i)=>[/(.+)\1\1\.\./,/\.\./,/.+[+-].*i/,/i/][i].test(s))||'QNZ'[k=eval(s),k%1?0:k>0?1:2]

Test cases

let f =

s=>[...'QRCI'].find((_,i)=>[/(.+)\1\1\.\./,/\.\./,/.+[+-].*i/,/i/][i].test(s))||'QNZ'[k=eval(s),k%1?0:k>0?1:2]

console.log(f('73.0'           )) // -> N
console.log(f('4/2'            )) // -> N
console.log(f('-73'            )) // -> Z
console.log(f('-1/3'           )) // -> Q
console.log(f('0.56'           )) // -> Q
console.log(f('0.555...'       )) // -> Q
console.log(f('0.123123123...' )) // -> Q
console.log(f('3.1415926535...')) // -> R
console.log(f('-1.37i'         )) // -> I
console.log(f('7892/5 + 23/4i' )) // -> C

Formatted and commented

s =>                  // given the input string s
  [...'QRCI'].find(   // we first apply some regular expressions:
    (_, i) => [       //   i = index
      /(.+)\1\1\.\./, //     i = 0 (Q): 3x the same pattern, followed by '..' -> rational
      /\.\./,         //     i = 1 (R): '..' without the repeated pattern -> real
      /.+[+-].*i/,    //     i = 2 (C): a real part +/- an imaginary part -> complex
      /i/             //     i = 3 (I): just an imaginary part -> imaginary
    ][i].test(s)      //   this is a find(), so we exit as soon as something matches
  ) || 'QNZ'[         // if all regular expressions failed:
    k = eval(s),      //   assume the expression can now be safely evaluated as JS code
    k % 1 ?           //   if there's a decimal part:
      0               //     -> rational
    :                 //   else:
      k > 0 ?         //     if strictly positive:
        1             //       -> natural
      :               //     else:
        2             //       -> integer
  ]                   //


Tiling a 2^N by 2^N Grid with L-Shaped Trominoes When students are first taught about the proof technique of mathematical induction, a common example is the problem of tiling a 2N×2N grid with L-shaped trominoes, leaving one predetermined grid space empty. (N is some nonnegative integer.)

I will leave it to you to go over the proof if you do not already know it. There are many resources that discuss it.

Your task here is to write a program that takes in a value for N, as well as the coordinates of the grid space to leave empty, and prints an ASCII representation of the resulting tromino tiled grid.

The character O will fill the empty space, and the 4 rotations of our tromino will look like this:

|
+-

 |
-+

-+
 |

+-
|

(Yes, it can be ambiguous which + goes with which - and | for certain arrangements, but that's ok.)

Your program must work for N = 0 (for a 1×1 grid) up to at least N = 8 (for a 256×256 grid). It will be given x and y values that are the coordinates for the O:

x is the horizontal axis. x = 1 is the left grid edge, x = 2N is the right grid edge.
y is the vertical axis. y = 1 is the top grid edge, y = 2N is the bottom grid edge.

Both x and y are always in the range [1, 2N].

So for a given N, x, and y, your program must print a 2N×2N grid, tiled completely with L-shaped trominoes, except for the x, y grid coordinate which will be an O.

Examples

If N = 0, then x and y must both be 1. The output is simply

O

If N = 1, x = 1, and y = 2, the output would be

-+
O|

N = 2, x = 3, y = 2:

+--+
||O|
|+-|
+--+

N = 2, x = 4, y = 1:

+-|O
||+-
|+-|
+--+

N = 3, x = 3, y = 6 (e.g. the image on this page):

+--++--+
|+-||-+|
||+--+||
+-|-+|-+
+--+||-+
||O|-+||
|+-||-+|
+--++--+

Details

You may write a function that takes the 3 integers instead of writing an entire program. It should print or return the grid string.
Take input from stdin, command line, (or function args if you write function).
The output may optionally contain a single training newline.
You are not required to use the tiling method that the proof normally suggests. It only matters that the grid is filled with L-shaped trominoes besides the O. (Trominoes may not be cut or go out of the grid bounds.)

The shortest code in bytes wins. Tiebreaker is earlier post. (Handy byte counter.)

C, 399 bytes

char*T=" |-+ | +-| ",*B;w;f(N,x,y,m,n,F,h,k,i,j){w=B?F=0,w:1<<N|1;char b[N?w*w:6];for(k=w;k--;)b[k*w-1]=10;B=!B?F=1,m=0,n=0,x--,y--,b:B;if(N>1){h=1<<N-1;i=x>--h,j=y>h;while(++k<4)if(k%2-i||k/2-j)f(N-1,!(k%2)*h,!(k/2)*h,m+k%2*(h+1),n+k/2*(h+1));f(1,h&i,h&j,m+h,n+h);h++;f(N-1,x-h*i,y-h*j,m+h*i,n+h*j);}else while(++k<4)B[w*(n+k/2)+m+k%2]=T[5*x+2*y+k];if(F)B[y*w+x]=79,B[w*w-w-1]=0,puts(N?B:"O"),B=0;}

No one's come forward with anything yet, so I'll offer up a meager solution. Mark my words, this is not the end. This will get shorter.
We define a function f that takes 10 arguments, but you need only call it with f(N, X, Y). Output goes to stdout.
Here's a readable version:
char*T=" |-+ | +-| ",*B;
w;
f(N,x,y,m,n,F,h,k,i,j){
    w=B?F=0,w:1<<N|1;
    char b[N?w*w:6];
    for(k=w;k--;)
        b[k*w-1]=10;
    B=!B?F=1,m=0,n=0,x--,y--,b:B;
    if(N>1){
        h=1<<N-1;
        i=x>--h,j=y>h;
        while(++k<4)
            if(k%2-i||k/2-j)
                f(N-1,!(k%2)*h,!(k/2)*h,m+k%2*(h+1),n+k/2*(h+1));
        f(1,h&i,h&j,m+h,n+h);
        h++;
        f(N-1,x-h*i,y-h*j,m+h*i,n+h*j);
    }
    else
        while(++k<4)
            B[w*(n+k/2)+m+k%2]=T[5*x+2*y+k];
    if(F)B[y*w+x]=79,B[w*w-w-1]=0,puts(N?B:"O"),B=0;
}

A taste of output for f(3, 2, 7):
+--++--+
|+-||-+|
||+--+||
+-|-+|-+
+--+||-+
|-+|-+||
|O|||-+|
+--++--+

It's a fairly simple recursive algorithm to fill the grid. I may upload an animation of the algorithm drawing trominoes since I think it's pretty neat. As usual, feel free to ask questions and shout at me if my code breaks!
Try it online!


What's my telephone number? Introduction

The telephone numbers or involution numbers are a sequence of integers that count the ways \$n\$ telephone lines can be connected to each other, where each line can be connected to at most one other line. These were first studied by Heinrich August Rothe in 1800, when he gave a recurrence equation where they may be calculated. It is sequence A000085 in the OEIS.

Some help

The first terms of the sequence are \$1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496\$
It can be described by the recurrence relation \$T(n)=T(n-1)+(n-1)T(n-2)\$ (starting from \$n=0\$)
It can be expressed exactly by the summation \$T(n)=\sum\limits_{k=0}^{\lfloor n/2 \rfloor}{n\choose 2k}(2k-1)!!=\sum\limits_{k=0}^{\lfloor n/2 \rfloor}\frac{n!}{2^k(n-2k)!k!}\$ (starting from \$n=0\$)
There are other ways to get the telephone numbers which can be found on the Wikipedia and OEIS pages

Challenge

Write a program or function which returns the \$n^{th}\$ telephone number.

I/O examples

(0 based indexing)
input --> output

0  -->            1
10 -->         9496
16 -->     46206736
22 --> 618884638912

Rules

Input will be the index of the sequence
The index origin can be anything
As the numbers can get very large, you only need to support numbers as large as your language can handle
Standard I/O rules apply
No standard loopholes
This is code-golf so shortest code in bytes wins

Python, 33 bytes

f=lambda n:n<2or~-n*f(n-2)+f(n-1)

Try it online!

Uses the recursive formula.


Cross platform... You wish Write a program that will produce differing behaviors on as many different platforms as you can. Each differing platform awards one point (including an initial platform, meaning you can't score less than 1*). Mechanisms intended for determining the target/executing platform (e.g. through platform compilation statements or APIs like .NET's Environment.OSVersion.Platform) must not be used. The answer with the highest score wins (where upvotes are the tiebreakers).

For example, consider the following program in the Blub language: print (1+2). If this program were to print 3 on every platform it is compiled and run on, its score would be 1. However, if, for any reason, it were to print 4 on PDP-11s, its score would be 2. Etc. But the following C snippet, for example, is an invalid entry: #ifdef WIN32 ... #endif.

Definitions/details:

Distinct platform: the combination of a) the hardware architecture b) the OS and its MAJOR version number (e.g. 1.0.0 and 1.1.0 are considered the same OS)
Differing behavior: two behaviors are the same iff they produce similar side-effects (e.g. creating the same file with the same contents), or if the side-effect are errors of the same kind. For example, if a program segfaults on two distinct platforms, but the segfault message is different on these platforms, this is still considered the same behavior; while a program producing a zero-division error on one platform and a stack overflow (see what I did there? ;) error on another is producing different behavior.
All undefined behaviors are considered equivalent.
Program must be invoked in an equivalent manner on all platforms (however; this does mean you can pass command-line parameters if you so desire)

* Well, I guess you'd score zero if your program ran on zero platforms. But um... Yeah nevermind.

C
I will take a stab at it with a textbook-like example:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[] = {1,2,3,4,5,6,7,8};
    if (sizeof(&a) > sizeof(int)) {
        printf("foo %d %d\n", *(int *)a, *(long *)a);
    } else {
        printf("bar %d %d\n", *(int *)a, *(long *)a);
    }
}

64-bit Platform prints: foo
32-bit Platform prints: bar
Little Endian Platforms: 67305985
Big Endian Platforms: 16909060
So there is at least 4 combinations.
On top of that, some very old platforms has int defined as 16-bits. And some platform has long defined as 64-bits. So the result will be different as well.
C has been quite platform specific, if you dig deep enough. It is not hard to come up with thousands of combinations (2^10+).


Swap, delete and repeat Introduction
Let's observe the following string:
ABCDEFGHIJKLMNOP

If we swap the ends of the string, which are these:
ABCDEFGHIJKLMNOP
^^            ^^

We get the following result:
BACDEFGHIJKLMNPO

After that, we delete the ends of the string, which in this case are B and O. The result is:
ACDEFGHIJKLMNP

If we repeat the process, we get the following list:
N     Result

2     ADEFGHIJKLMP
3     AEFGHIJKLP
4     AFGHIJKP
5     AGHIJP
6     AHIP
7     AP

You can see that for N = 5, the result is AGHIJP. At N = 7, the length of the string is smaller than 3, so N > 7 is considered invalid in this case.
The Task
Given a string S with at least length 4 and the number of repetitions N > 0, output the final result. You can assume that N is always valid.
Test cases
Input                               >  Output

N = 3, S = ABCDEFGHIJKLMNOP         >  AEFGHIJKLP
N = 1, S = Hello                    >  Hlo
N = 2, S = 123321                   >  11

This is code-golf, so the submission with the least amount of bytes wins! For the simplicity, you can assume that the string will only contain alphanumeric characters.

Retina, 44 20 bytes

Crossed out 44 is still regular 44 :(

+`'(\w).(.*).\B
$1$2

Assumes input in following format (in unary - counting character: '):
{number of repeats}{string}
For example: '''''''ABCDEFGHIJKLMNOP
There is no space between number of repeats and the string.

Thanks @MartinBüttner for shaving off 24 bytes!

Try it online!


Make an HTML page goto infinite loop? Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop.

Restrictions:

No looping or control structures of javascript and jQuery allowed. You can only use alert, events, etc.

$($);

May not meet your conditions, but I like it. (And it does crash your browser.)

More information about this: Why does $($) crash my page?


Use letters to make numbers shorter Challenge
Take a number and output it with 4 digits or less using letters and numbers. For example; 270,030 would turn into 270K.
Key
Billion -> B
Million -> M
Thousand -> K
Rules

You may choose to accept input numbers that include commas delimiting every three decimal places (such as 123,456,789).
Round to nearest, half-up.
Numbers will only go up to 999,499,999,999 .
The mantissa part of the answer should be at least 1.
All letters must be uppercase and as specified above.
Outputs must be 4 or less digits. (including letters such as B, K, and M)
Outputs must be as mathematically precise as possible. Example:

15,480 -> 20K NOT OK
15,480 -> 15.5K GOOD

If there are multiple outputs with the same mathematical precision, return either one. Example:

1000 -> 1000 GOOD
1000 -> 1K GOOD

Examples:

1,234,567 -> 1.23M
999,500 -> 1M
999,499 -> 999K
102 -> 102
1000 -> 1K
1001 -> 1001
100,000 -> 100K
12,345,678,912 -> 12.3B
1,452,815,612 -> 1.45B

Submissions

This is code-golf, so the shortest solution in each language wins
Standard Loopholes Apply

JavaScript, 84 79 bytes

i=>{I=i;for(x=-1;i>=999.5;x++)i/=1e3;return I<1e4?I:+i.toPrecision(3)+'KMB'[x]}

Try it online!

(Takes inputs as numbers)

Special cases the first one where if i < 1000, the number itself is always one of the shortest ways, if not the only shortest way.

Otherwise, it divides it by 1000 until dividing it would make it have no sigificant figures above 1, and chooses a suffix based on how many divisions were done.


Python, 32 bytes

lambda n:eval('['*n+'n'+']*n'*n)

Try it online!

Makes a string like "[[[n]*n]*n]*n" with n multiplcations, and evaluates it as Python code. Since the evaluation happens within the function scope, the variable name n evaluates to the function input.


Take It or Leave It II: A Game Show for Computers This is the second in a series of puzzles that I will be posting every Monday at Midnight PST. The first puzzle is located Here.
Context:

A reclusive billionaire has created a game show to attract the world's best and brightest programmers. On Mondays at the stroke of midnight, he chooses one person from a pool of applicants to be the contestant of the week, and provides them with a game. You are this week's lucky contestant!

This week's game:

The host provides you with API access to a stack of 10,000 digital envelopes. These envelopes are randomly sorted, and contain within them a dollar value, between $1 and $10,000 (no two envelopes contain the same dollar value).
You have 4 commands at your disposal:

Read(): Read the dollar figure in the envelope at the top of the stack.

Take(): Add the dollar figure in the envelope to your game show wallet, and pop the envelope off the stack.

Pass(): Pop off the envelope on the top of the stack.

Oracle(M): Returns the mean value of the next M envelopes in the stack, not including the one you can currently Read().

The Rules:

If you use Pass() on an envelope, the money within is lost forever.

If you use Take() on an envelope containing $X, from that point forward, you may never use Take() on an envelope containing < $X. Take() on one of these envelopes will add $0 to your wallet.

If you use Oracle(M) on turn T, envelopes T+1 through T+M's mean will be returned. Oracle() is disabled until turn T+M.

Write an algorithm that finishes the game with the maximal amount of money.
If you're writing your algorithm in Python, feel free to use this controller provided by @Maltysen: https://gist.github.com/livinginformation/70ae3f2a57ecba4387b5
Notes 1: "Maximal" in this case means the median value in your wallet after N >= 1000 runs. I expect, though I would love to be proven wrong, that the median value for a given algorithm will converge as N increases to infinity. Feel free to try to maximize the mean instead, but I have a feeling that the mean is more likely to be thrown off by a small N than the median is.
Note 2: as all solutions to the previous part of this puzzle are valid here, reposting them has little value. Only algorithmic improvements of previous puzzles will be considered for part II.
Edit: The prize condition has been removed, in light of this post on meta.

Groovy $713337 $817829 $818227

Bootstrap code:

class Instance {
    List values = new ArrayList(1..10000); {
        Collections.shuffle(values)
    }
    int i = 0
    int value = 0
    int max = 0
    int nextOracle = 0

    def pass() {
        if (i >= 10000)
            throw new NoSuchElementException()
        i++
    }

    def take() {
        if (i >= 10000)
            throw new NoSuchElementException()
        int v = values[i]
        if (v > max) {
            max = v
            value += v
        }
        i++
    }

    double oracle(int m) {
        if (m <= 0 || i < nextOracle || i + m >= 10000)
            throw new NoSuchElementException()

        nextOracle = i + m
        values.subList(i + 1, i + m + 1).stream().reduce { l, r -> r+l }.get() / m
    }

    int read() {
        if (i >= 10000)
            throw new NoSuchElementException()
        values[i]
    }
}

Algorithm

double square(double v) { v * v }
final double factor = Math.pow(1.5, 1.1)
int attempts = 5000
(1..attempts).stream().parallel().mapToLong {
    def puzzle = new Instance()

    int[] memory = 1..10000 // We will remember every envelope
    int memStart = 0

    while (memStart < 10000 - 3) {
        int value = puzzle.read()
        int i = Arrays.binarySearch(memory, memStart, 10000, value) - memStart
        if (i < 0) { // We can't use the money
            puzzle.pass()
            continue
        }
        if (i == 0) { // Of course we take the lowest
            puzzle.take()
            memStart++
            continue
        }
        int remaining = Arrays.stream(memory, i + 1 + memStart, 10000).sum() // Money we could win if taken
        int losing = Arrays.stream(memory, memStart, memStart + i).sum() // Money we cna't win if taken
        if (value > losing) { // If we pass, we lose money automatically
            puzzle.take()
            memStart += i + 1
        } else if ((losing - value * 16 / 7) * square(Math.log(i)) > remaining / factor) {
            System.arraycopy(memory, memStart, memory, ++memStart, i)
            puzzle.pass()
        } else {
            puzzle.take()
            memStart += i + 1
        }
    }

    // It's broken down to last three elements
    List values = Arrays.copyOfRange(memory, 10000 - 3, 10000)
    while (!values.contains(puzzle.read())) // Skip values we can't use
        puzzle.pass()
    int value1 = puzzle.read()
    int value2 = puzzle.oracle(1)
    if (value1 == values.max() && (
            values.contains(value2)
            ? (value1 * 2 < values.sum() && values.min() == value2)
            : (value1 < values.min() / 2 + (values - [value1]).max())
            )) {
        puzzle.pass()
    }

    // Finish it
    while (puzzle.i < puzzle.values.size()) {
        puzzle.take()
    }

    puzzle.value as Long
}.sum() / attempts // Sum runs and average

I compare remaining values with possible values. This script is not fast (takes 1-minute per 1000x simulations)... but it will perform the simulations simultaneously.

I have no idea why my algorithm works, but it was just trial and error: lumping mathematical operations together and manipulating the constants. I ran it 5000x for the current score, in an attempt to reduce the score's fluctuations (it's +/- $4000 depending on iteration count).

Even without the oracle at the end, it should still be (barely) beating @orlp's solution for the prior puzzle.


A Free Sample of Autocorrelation Consider a 1-dimensional, real-valued vector x that represents observations of some process measured at equally spaced intervals over time. We call x a time series.

Let n denote the length of x and x̄ denote the arithmetic mean of x. The sample autocovariance function is defined as

for all -n < h < n. This measures the linear dependence between two points on the same series observed at different times.

The sample autocorrelation function, or ACF, is defined as

This measures the linear predictability of the series x at time t, which we denote xt, using only the value xt+h.

Note that these sample estimates do not match the naïve calculations based on the theoretical properties. That is, the sample autocorrelation function is not equal to the Pearson correlation coefficient of x with the h-step lag of x.

Task

Given an array x and a nonnegative integer h, print or return the first h+1 lag autocorrelations of x, beginning with lag 0. The lag autocorrelations are those corresponding to negative inputs in the above formulas.

You can assume that 0 < h < n, where n is the length of x, and that 2 < n < 256.

Output should be correct to within 1E-4. There are no restrictions on the use of built-in functions or running time.

Examples

h, x -> output
--------------
5, [2.4, 2.4, 2.4, 2.2, 2.1, 1.5, 2.3, 2.3, 2.5, 2] -> [1.00000000,  0.07659298, -0.06007802, -0.51144343, -0.02912874, -0.10468140]
1, [2134, 1863, 1877, 1877, 1492, 1249] -> [1.0000000, 0.3343041]
2, [13067.3, 13130.5, 13198.4] -> [1.0000000000, -0.0002854906, -0.4997145094]

R, 3 31 25 bytes

# changes the builtin to only return the acf
body(acf)=body(acf)[1:18]

Usage (returns an array with the autocorrelations)

(acf(c(2.4, 2.4, 2.4, 2.2, 2.1, 1.5, 2.3, 2.3, 2.5, 2),5))
# , , 1
#
#             [,1]
# [1,]  1.00000000
# [2,]  0.07659298
# [3,] -0.06007802
# [4,] -0.51144343
# [5,] -0.02912874
# [6,] -0.10468140

Background:

The 31 byte solution based on the original acf built in

function(n,h)c(acf(n,h,,F)$acf)

Note that the 3 byte option  acf is the originalbuilt in that will plot (and print to 3 digits) while returning the required autocorrelation as an element in a list.

usage

 acf(c(2.4, 2.4, 2.4, 2.2, 2.1, 1.5, 2.3, 2.3, 2.5, 2),5)

output:

#    Autocorrelations of series ‘c(2.4, 2.4, 2.4, 2.2, 2.1, 1.5, 2.3, 2.3, 2.5, 2)’, by lag
#
#     0      1      2      3      4      5
# 1.000  0.077 -0.060 -0.511 -0.029 -0.105

If we want the correlations to display to more than 3 decimal places then 28 bytes will do it (or 31, if we want to suppress the plot)

# will still plot (28 bytes)
function(n,h)c(acf(n,h)$acf)
# won't plot (31 bytes)
function(n,h)c(acf(n,h,,F)$acf)


Solve the equation `a*x == b` with Int32 arithmetics In this thread we use 32-bit signed integers (assuming the usual two's complement). For simplicity I shall call this type Int32. The range is from -2147483648 through 2147483647. Any two values can be successfully multiplied (the result is an Int32 as well) since we use multiplication without overflow checking (we only keep the 32 least significant bits of the product).

For example, we have:

2147483647 * 2 == -2

and so on.

If your language does not have native support for 32-bit signed integers (with two's complement), you must emulate it.

Your task is to solve the equation:

a * x == b

where a and b are given as input, and it is assumed that a is an odd number (i.e. least significant bit is 1). You output an Int32 value.

The input to your program shall be two Int32 values a and b, and a will be odd
The output must be one Int32 value such that (if we call the output x) a*x == b
You do not have to handle invalid input; in particular, if the argument a is an even number, it does not matter what your code does
Code golf

Test cases:

Input                  Output

1,42                   42
3,126                  42
5,5                    1

-3,126                 -42
3,-126                 -42
-3,-126                42

2147483647,-2          2
2147483647,2           -2
2147483647,666         -666

3,0                    0
3,1                    -1431655765
3,2                    1431655766

-387907419,1342899768  1641848792
348444091,1076207126   -1334551070
10,14                  irrelevant (illegal input)

In the last case [a,b]==[10,14], even if there is a solution x = -1717986917 (not unique, x = 429496731 also works), you do not have to handle that case (10 is not odd).

Python 3, 39 bytes

lambda a,b,h=2**31:(a**~-h*b+h)%(2*h)-h

This is a theoretical solution that will take a long time unless a = 1. It uses the Euler-Fermat theorem to determine the modular inverse of a.

Alternate version, 47 bytes

lambda a,b,h=2**31:(pow(a,h-1,2*h)*b+h)%(2*h)-h

This does exactly the same, but in a more efficient manner.

Try it online!


Compute the inverse XOR Let f be the function that maps a bitfield ({0 1}) of size n+1 to bitfield of size n by applying XOR to the ith and i+1th bit and writing the result in the new bitfield.

Example: f("0101") = "111"

Informal calculation:

0 XOR 1 = 1

1 XOR 0 = 1

0 XOR 1 = 1

Let f_inverse be the inverse function of f. Since the inverse is not unique, f_inverse returns one valid solution.

Input: bitfield as string (i.e. "0101111101011") and a given natural number k

Output: bitfield as string, so that the string contains the result if f_inverse is applied k times to the input bitfield. (i.e. f_inverse(f_inverse(f_inverse(input))) )

Winning criteria: fewest Characters

Bonus:

-25 Characters if f_inverse is not applied recursively/iteratively, instead the output string is directly calculated

Testscript:

a = "011001"
k = 3

def f(a):
    k = len(a)
    r = ""
    for i in xrange(k-1):
        r += str(int(a[i]) ^ int(a[i+1]))
    return r

def iterate_f(a, k):
    print "Input ", a
    for i in xrange(k):
        a = f(a)
        print "Step " + str(i+1), a

iterate_f(a, k)

You can paste it for example here and then try it.

Pyth, 33 30 - 25 = 5 bytes

Jiz8K+lzQ%"%0*o",KuxG/G8rQ^2KJ

Run it by input from stdin like (online interpreter: https://pyth.herokuapp.com/):

111
3

and the result will be written to stdout.

This is a direct translation of:

Python 2, 127 118 79 - 25 = 54 bytes

def i(s,k):
 l=int(s,8);t=len(s)+k
 while k<1<<t:l^=l/8;k+=1
 print'%0*o'%(t,l)

Call it like i("111", 3), and the result will be written to stdout.

Note that we expect k not being too large, since for code-golfing purpose the inner loop will run for O(2k) times.

I think we usually call this operation "xorshift" or something. If we express the input as big-endian integers, then the function f is simply:

f(x) = x ⊕ (x ≫ 1)

If we apply f twice we will get:

f2(x) = x ⊕ (x ≫ 2)

However applying 3 times will have a different pattern:

f3(x) = x ⊕ (x ≫ 1) ⊕ (x ≫ 2) ⊕ (x ≫ 3)

Applying 4 times get back to the basic form:

f4(x) = x ⊕ (x ≫ 4)

And so on:

f2k(x) = x ⊕ (x ≫ 2k)

Note that if we choose a big-enough 2k, then (x ≫ 2k) = 0, meaning f2k(x) = x, and the inverse is trivially the identity function!

So the strategy for finding f-k(x) without calling f-1(x) at all is:

Find K such that:

K ≥ k
K > log2 x
K is a power of 2

Express f-k(x) = f-K + (K-k)(x) = f-K(fK-k(x)) = fK-k(x)
Thus, the result is f called K-k times
25 chars profit :p

Update 1: Used octal representation instead of binary so that we could use % formatting to save lots of bytes.

Update 2: Exploit the periodic structure of f. Retired the iterative version since the non-iterative one is shorter even without the -25 bytes bonus.

Update 3: Reduced 3 bytes from Pyth, thanks isaacg!


Shortest program to split special array Background

Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:

|              A              |
[0   0   0   0   1   2   3   0]
               |     B     |

Now say, we split the array A into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of A). For d = 3:

[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:

[0 3 3]

And discard zero sums:

[3 3]

The Challenge

You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

The small array B.
The size of the small array B (3 in the above example).
The size of the big array A (8 in the above example).
The index where the small array begins (4 in the above example).
The length d of the subarrays (3 in the above example).

The Rules

You are not allowed to construct the big array A explicitly!
You are not allowed to construct any of the subarrays of length d explicitly!
That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

CJam, 34 32 28 characters
{"ɚ광䃻噣攍圍숵셳ﶓ訙➰鑓쥾"2G#b126b:c~}

This is a compressed form of the following 31 bytes solution
{:D%0a*\+0\{+U):UD={0:U}*}%0-p}

This can be golfed further.
Try it online here
Input is in format of [small_array] index_where_small_array_begins divisor
For example:
[1 2 3] 5 3{"ɚ광䃻噣攍圍숵셳ﶓ訙➰鑓쥾"2G#b126b:c~}~

will give output
[1 5]

Explanation (outdated):
{                                   "Begin of function block";
 :D                                 "Store the divisor in D";
   %                                "Calculate index_where_small_array_begins%divisor";
    0a*                             "Get an array of 0 on length above number";
       \+                           "Prepend it to the small_array";
         _,{            }*          "Run this code block length(small_array) times";
            0\                      "Put 0 before small_array. This 0 marks the"
                                    "current sum of the current mini_array";
              {      }D*            "Run this code block divisor times";
               0+                   "Add 0 at the end of mini array";
                 (                  "Take out the first element from the mini array";
                  @                 "Rotate the stack to get current sum on top";
                   +                "Add the first element to the current sum";
                    \               "Swap to put current mini_array on top of stack";
                          ;]        "Pop the residual array and wrap the sums in an array";
                            0-p     "Remove 0 and print the sum_of_mini_arrays_array";
                               }    "End of function block";


What's the date, in Usenet time? September 1993 is known on Usenet as the September that never ended. Thus, for example, the day this question is being posted is Saturday, September 8740, 1993.

Your program or function should take any Gregorian date (with positive year) as input and return the same date as output if it's prior to September 1993 or the date on the September 1993 calendar if thereafter.

You may accept YYYY-MM-DD, YYYY/MM/DD, MM/DD/YYYY, DD/MM/YYYY, D-Monthnameabbr-YYYY, or any other popular format that uses the entirety of the year (as opposed to the year modulo 100). You need only accept one such format, of your choosing. Output format must match the input format.

Sample input → output:

Sunday, 6 August 2017 → Sunday, 8741 September 1993
Tuesday, 28 January 1986 → Tuesday, 28 January 1986

Or:

2017-08-06 → 1993-09-8741
1986-01-28 → 1986-01-28

In the interest of more interesting answers, the use of a built-in function designed for this purpose (such as the UN*X sdate command) is disallowed. Aside from that and the standard exceptions, this is golf, so the shortest answer wins.

Python 3, 109 bytes

from datetime import*
i=input()
z=date(*map(int,i.split())).toordinal()-727806
print([i,'1993 09 %d'%z][z>9])

Try it online!

-59 bytes thanks to notjagan
-3 bytes thanks to Mr. Xcoder
-2 bytes thanks to officialaimm
-12 bytes thanks to Jonathan Allan