Code that runs the Game of Life on itself Write two rectangular blocks of code, each w characters wide and h characters tall, that implement Conway's Game of Life when arranged in a grid. (w and h may be any positive integers)
For example, the two code blocks might be: (w = 3, h = 2, not actual code)
XX|
--+

and
  |
--+

Treat the first block as if it is the "alive" cell in the Game of Life and the second block as if it is the "dead" cell.
Now arrange multiple copies of these two blocks into a larger program that represents a Game of Life grid, such as this glider:
  |  |  |  |  |
--+--+--+--+--+
  |  |XX|  |  |
--+--+--+--+--+
  |  |  |XX|  |
--+--+--+--+--+
  |XX|XX|XX|  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

Now here is the key point: when this code is run, the output must be the Game of Life grid that is the generation after this, using the same alive and dead code blocks for the cells.
So the output to the program above would be the next generation of the glider, which also serves as a runnable program:
  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |XX|  |XX|  |
--+--+--+--+--+
  |  |XX|XX|  |
--+--+--+--+--+
  |  |XX|  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

Running this would produce the next generation:
  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |  |  |XX|  |
--+--+--+--+--+
  |XX|  |XX|  |
--+--+--+--+--+
  |  |XX|XX|  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

And so on.
The process should be indefinitely repeatable and work for any arrangement of your alive and dead code blocks in a Game of Life grid.
The output grid should have the same the same dimensions as the program that it came from (5 by 6 above). Grid sizes as small as 1 by 1 should work, and they may be arbitrarily large. Naturally, an empty grid will just output itself.
Update: Being able to simulate grids of any dimensions without having to change the "tiles" would be ideal but since this seems very difficult I will accept answers that assume the grid is a certain size (maybe around 16*16).
The Game of Life rules are as follows:

Any live cell with less than 2 or more than 3 live (Moore) neighbors dies.
Any dead cell with exactly 3 live neighbors comes alive.
Other cells do not change.

Scoring
The challenge is to do this in the smallest code block area possible. Your score is w * h. The lowest score wins. In case of ties the highest voted answer wins.
Details

Besides the newlines needed to make things rectangular, your two code blocks (and therefore your Game of Life grid programs) should only contain printable ASCII characters (hex codes 20 to 7E, no tabs, no extra newlines).
Both code blocks must have exactly w * h characters (besides the necessary newlines) with at least a one character difference. Padding them with spaces or comments is fine. They should not change from one generation to the next.
The output should either go to a file or to stdout. There is no input.
The boundary conditions may either be periodic (where the top edge borders the bottom and the left edge borders the right) or infinite (where all out-of-bounds cells are always dead). Choose whatever suits you best.
Reading your own source code is not allowed.
Any language or tool that already does this is not allowed. (Just in case one exists.)

Note: The -|+ characters above were only used to emphasize the cell borders. Your blocks do not need any distinguishable border. However, when displaying your output it would be helpful if there was some distinguishable separation between blocks, perhaps made with a character never used in the program so it is easy to remove. e.g.
DD+DD+DD+DD
+++++++++++
AA+DD+AA+DD

instead of
DDDDDDDD
AADDAADD


Draw the ☣ (Biohazard Symbol) Draw the Biohazard symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the US Government.

Details

As output, writing to a file (raster and vector formats are permitted) or displaying on the screen are both allowed.
You can draw just the border or the filled shape.
If you use raster images, you should take a parameter (or two) as input that lets you adjust the resolution of the output (e.g. width/height).
The background must at least have the size of the bounding box of the symbol but may be larger.
Outputting the unicode symbol ☣ is not sufficient.
The exact ratios of the used distances are given in following diagram (which was originally from here):

I also tried to make an additional diagram with the same measurements that is hopefully a little bit easier to read:

(Inspired by a post on 99%invisible)

T-SQL, 442 441 426 355 349 344 bytes
DECLARE @ VARCHAR(MAX)=REPLACE(REPLACE(REPLACE('DECLARE @a5MULTIPOINT((0 31),(19 -2),(-19 -2))'',@b5MULTIPOINT((0 39),(26 -6),(-26 -6))'',@5POINT(0 9)'',@d5LINESTRING(0 9,0 99,90 -43,0 9,-90 -43)''SELECT @a830%b821)%86)%d81)%d84%819))).STUnion(@827%820)).STIntersection(@b819)))'
,8,'.STBuffer('),5,' GEOMETRY='''),'%',').STDifference(@')EXEC(@)

Saved 70+ bytes by using REPLACE() for long keywords and executing as dynamic SQL. See the post-replacement code in the screenshot below.
I doubled the coordinate values from the sample illustration and moved up 9 units, to reduce the number of decimals displayed.
This was done in SQL 2017, using geo-spatial features introduced in SQL 2008. Lots of useful built-in geometry functions, including STBuffer, which gives me a simple way to define circles of different sizes around a point.
Visual of output, with annotated code:

For more T-SQL drawing, see my Easter Bunny.
For more practical applications of this tech in SQL, read this article or watch this video. SE even has a related site, gis.stackexchange.com.
Edits:

Saved 1 byte by changing a coordinate from 104 to 99.
Saved 15 bytes by taking the STDifference of a STUnion of objects, instead of each individually.
Saved 71 bytes by using REPLACE() on repeated keywords, then executing as dynamic SQL. Reverted Edit 2, to leave more replacements of STDifference.
Saved 4 bytes by moving the center up 9 units, which changed a few coordinates to single (negative) digits. This also freed up the numeral 5 to use as a replacement character instead of '#', saving 2 more bytes on the quotes.
Saved 5 bytes by moving ) into the STDifference replacement string; thanks, @Nicholas!


Solving triangles with trigonometry Time to dig up your old trigonometry notes from high school! The challenge is to solve the unknown sides and angles of different triangles. And as is customary in code golf, the smallest working code wins.

This is not a trivial problem; my reference implementation in python is currently down to 838 837 characters, but I'm sure you'll be able to golf solutions far smaller.

Additionally, if you're stuck, this section on Wikipedia should get you going: Triangle: Computing the sides and angles.

Input

The following triangle shows the names of the sides and angles used in this challenge. Note that sides are lowercase and angles are uppercase.

Input is given as six space-separated values, either on stdin or as command-line arguments (your choice). The six values correspond to the sides a, b, c and the angles A, B, C. The unknown sides are given as question marks (?). Both input and output angles has to be in radians. You may assume that the input values are correct (you don't have to validate anything). You may also assume that the input triangle is non-degenerate, and that all sides and angles are nonzero.

The following example input tells you that side a is 8, side b is 12 and angle A is 0.5 radians:

8 12 ? 0.5 ? ?

Output

Output is given in the same format as the input - six space-separated numbers on stdout. The only exception is when it is not possible to solve the input triangle - then the string "No solution" must be written to stdout. If two solutions are possible, they are both outputted with a newline between them.

Following is the output for the above input:

8.0 12.0 16.0899264342 0.5 0.802561439714 1.83903121388
8.0 12.0 4.97205505116 0.5 2.33903121388 0.302561439714

Output is not required to have a lot of precision, but at least a couple decimals is required.

Rules

Input is read from stdin or command-line arguments
Output is written to stdout
If two solutions are possible with the given input, output both
If there is too little information to get one or two clear solutions, consider it a "No solution" case
No built-in or pre-existing code may be used (of course you can use trig functions, but not "solveTriangle" or such)
Shortest code wins

Test cases

In   3 4 5 ? ? ?

Out 3.0 4.0 5.0 0.643501108793 0.927295218002 1.57079630572

In   ? 4 ? 0.64 0.92 1.57

Out 3.00248479301 4.0 5.02764025486 0.64 0.92 1.57

In   ? ? 5 ? 0.92 ?

Out No solution

In   ? ? 5 ? 0.92 1.57

Out 3.03226857833 3.97800936148 5.0 0.65159265359 0.92 1.57

In   8 12 ? 0.5 ? ?

Out (two solutions)

8.0 12.0 16.0899264342 0.5 0.802561439714 1.83903121388
8.0 12.0 4.97205505116 0.5 2.33903121388 0.302561439714

In   8 12 ? ? .5 ?

Out 8.0 12.0 18.3912222133 0.325325285223 0.5 2.31626736837

Good luck!

Python, 441 chars

from math import*
V=[map(float,raw_input().replace('?','0').split())+[0]]
for i in' '*9:
 W=[]
 for a,b,c,A,B,C,R in V:
  if B and C:A=A or pi-B-C
  if a:
   if A:R=R or a/sin(A)
   else:
    if b and c:A=acos((b*b+c*c-a*a)/2/b/c)
    elif R:N=asin(a/R);W+=[(b,c,a,B,C,N,R)];A=pi-N
  else:a=R*sin(A)
  W+=[(b,c,a,B,C,A,R)]
 V=W
V=[T for T in V if all(t>0 for t in T)]
if V:
 for T in V:print' '.join(map(str,T[:-1]))
else:print'No solution'

Does your typical trig to compute the answer.  The current possible solutions are stored as tuples in V.  Any unknown values are recorded as 0.  A seventh variable R is the value a/sin(A)==b/sin(B)==c/sin(C).

I use a trick where the a/b/c values are cycled each iteration to avoid lots of redundant logic.  The inner loop only needs to compute values of the A side or angle.


Validate a stem-and-leaf plot A stem and leaf plot displays a bunch of numerical values in groups, which are determined by all but the last digit. For example, suppose we have this set of data:

0, 2, 12, 13, 13, 15, 16, 20, 29, 43, 49, 101

We could produce this stem and leaf plot:

0|02
1|23356
2|09
3|
4|39
5|
6|
7|
8|
9|
10|1

The first row's stem is 0, so its "leaves" - the digits after the | - represent the values between 0 inclusive and 10 exclusive. The leaves on each stem are sorted. Stems with no leaves (like 3) still appear in the plot. The value of 101 is between 100 inclusive and 110 exclusive, so its stem is 10 (100 divided by 10).

Your challenge is to check whether a piece of text is a valid stem and leaf plot. A valid plot satisfies these rules:

Has exactly one row for every stem (i.e. 10-wide group) in the range of the data (including stems in the middle of the range with no leaves)
Has no stems outside the range
All leaves are sorted ascending to the right
All stems are sorted ascending down
Has only numeric characters (besides the separator |)

You do not have to deal with numbers that have fractional parts. You may approve or reject extra leading zeros in the stems, but a blank stem is not allowed. There will be at least one value. You may only assume extra spaces after the leaves on each row. You may assume a leading and/or trailing newline. All characters will be printable ASCII.

Your function or program should return or output (to screen or the standard output) a truthy value for a valid plot, or a falsy value for an invalid plot. You may take input from the standard input, from a file, as one big string, as an array of strings - whatever is most convenient.

Here are some test cases that are valid plots (separated by blank lines):

2|00003457
3|35
4|799
5|3

99|3
100|0556
101|
102|
103|8

0|0

Here are some test cases that are invalid plots, with commentary to the right:

|0               Blank stem

5|347            Missing a stem (6) in the range
7|9

4|               Has a stem (4) outside the range
5|26
6|7

11|432           Leaves aren't sorted correctly
12|9989

5|357            Stems aren't sorted correctly
4|002
6|1

4|5              Duplicate stem
4|6
4|6
5|1

51114            No stem and leaf separator
609

1|2|03           Multiple separators
2|779|

4|8abcdefg9      Invalid characters
5|1,2,3

75 | 4 6         Invalid characters (spaces)
76 | 2 8 8 9

This is code golf, so the shortest code wins! Standard loopholes are disallowed.


Find Possible Word Rectangles Johnny is trying to create crossword puzzles, but he is having difficulty making words match each other.

He has come up with several simple word rectangles: that is, groups of words that form a rectangle where all horizontal and vertical paths form a word.

//2x2
PA
AM

//2x3
GOB
ORE

//3x3
BAG
AGO
RED

//3x4
MACE
AGES
WEES

However, to make a good puzzle, he needs some word rectangles that are somewhat larger than 3x4. Instead of agonizing over the arrangement letters for hours, Johnny would prefer to have a program that does this for him--and in as few characters as possible, because long blocks of code are extremely intimidating for casual programmers like Johnny.

Given

a text file dictionary where words are separated by newlines in alphabetical order,
input specifying the number of rows and columns in the words rectangle (which can be provided however is most convenient in your programming language of choice)

generate at least one word rectangle. If it is not possible to generate a word rectangle with the given lexicon and dimensions, the program need not have defined behaviour. It is not necessary for the program to be able to generate rectangles which contain more than 64 letters or have dimensions that exceed 8 in either direction. The program should be able to complete in a reasonable amount of time, say, in thirty minutes or less.

EDIT: If you are doing an NxN rectangle, you are permitted to use a smaller dictionary file that only contains words that have a length of N letters.

Python, 232 chars
x,y=input()
H=[]
P={}
for w in open('words.txt'):
 l=len(w)-2
 if l==x:H+=[w]
 if l==y:
  for i in range(y+1):P[w[:i]]=1
def B(s):
 if(x+2)*y-len(s):[B(s+w)for w in H if all((s+w)[i::x+2]in P for i in range(x))]
 else:print s
B('')

It can only handle up to 6x6 in the 1/2 hour limit, though.


Reverse two sections of a string around a pivot Background

I am currently in an AP Comp Sci A: Java class, and I want to start some of my friends on code golfing. I have a challenge from the course, and I would like to see how many bytes the community can do this challenge in.

Challenge details:

Given two input strings, the main string and the pivot string, do the following:

If the pivot string is exactly once as a substring of the main string, the part of the main string that comes before the pivot string shall be swapped with the part that comes after, while preserving the order within said subtrings being swapped.

For example:

If the pivot string is empty or the pivot string is not found within the main string, the program does not have to have defined behavior.

If there is more than one instance of the pivot string, the split should occur at the first and only the first instance of the pivot.

Examples:
Given the main string OneTwoThreeTwoOne and the pivot string Two, the output should be ThreeTwoOneTwoOne.

Given the main string 1Two2Two3Two4 and pivot Two, the output should be 2Two3Two4Two1.

Given the main string OneTwoThree and the pivot string "Two", the output should be ThreeTwoOne.
Given the main string the rabbit is faster than the turtle and the pivot string

 is faster than

(note the single space trailing and preceding), the output should be the turtle is faster than the rabbit.

Given the main string 1-2-3-4-5-6 and the pivot -, the output should be 2-3-4-5-6-1.

Afterword:

This is my first ever question on code golf, so if you have suggestions or constructive criticism, then feel free to say so.

Additionally, my code for this project (written in Java because the course focuses on that) can be found below. If you have any tips, I'd love to see them. Its currently 363 bytes, but I bet you guys can come up with much better and smaller solutions.

import java.util.Scanner;interface Main{static<T>void D(T f){System.out.println(f);}static void main(String[]A){Scanner s=new Scanner(System.in);D("Enter the first String:");String a=s.nextLine();D("Enter the pivot String:");String p=s.nextLine();if(p.isEmpty()|!a.contains(p)){D("Error: Pivot String not found.");return;}String w[]=a.split(p,2);D(w[1]+p+w[0]);}}

Note: The text for the inputs and for the case that the pivot string is not found is mandatory for the original assignment, but not for this challenge.

Mathematica, 42 bytes
Reverse@StringSplit[##,2]~StringRiffle~#2&

Try it online!


Sum the means of the two integers There are quite a few means in mathematics, such as the arithmetic mean, the geometric mean, and many others...

Definitions and Task

Note that these are the definitions for two positive integers*:

The root mean square is the square root of the sum of their squares halved ().
The arithmetic mean is their sum, halved ().
The geometric mean is the square root of their product ().
The harmonic mean is 2 divided by the sum of their inverses ( = ).

Given two integers a and b  such that a, b ∈ [1, +∞), sum the means mentioned above of a and b. Your answers must be accurate to at least 3 decimal places, but you do not have to worry about rounding or floating-point precision errors.

Test Cases

a, b -> Output

7, 6 -> 25.961481565148972
10, 10 -> 40
23, 1 -> 34.99131878607909
2, 4 -> 11.657371451581236
345, 192 -> 1051.7606599443843

You can see the correct results for more test cases using this program. This is code-golf, so the shortest valid submissions that follows the standard rules wins.

* There are many other means, but for the purposes of this challenge we'll use the ones mentioned in the "Definitions" section.

Haskell, 48 bytes

a%b=sum[((a**p+b**p)/2)**(1/p)|p<-[2,1,-1,1e-9]]

Try it online!

This uses the fact that the root-square, arithmetic, harmonic, and geometric means are all special cases of the generalized mean ((a**p+b**p)/2)**(1/p) for p=2,1,-1,0. The geometric mean uses the limit p->0+, approximated as p=1e-9 which suffices for precision.


Modified Boggle Checker, with Modified Boggle-able Code Background

Boggle is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("adjacent" means horizontally, vertically or diagonally adjacent.) Also, same cell can't be used more than once in a word.

The following is an example board:

I L A W
B N G E
I U A O
A S R L

On this board, BINGO, ORANGE and WEARS are valid words, but SURGE and RUSSIA are not:

SURGE : There's no adjacent pair on the board having RG.
RUSSIA : S cannot be used twice.

Modified Boggle is a modified version of Boggle, with the following rules:

The board size is n-by-n, where n can be any positive integer.
Each cell can contain any one byte between 0 and 255 inclusive.
A cell can be used more than once, but not twice in a row.

Using the example board above, in addition to BINGO, ORANGE and WEARS, LANGUAGE becomes a valid string (since G is used twice, but not twice in a row) but RUSSIA is still not (due to SS pair).

Here is another example using a code fragment. The string from itertools import*\n can be found on the following board, but not from itertoosl import* or from itertools import *:

f   i   ' ' s
r   t   m   l
e   o   o   p
\n  *   t   r

Note that you need two o's in order to match the oo sequence.

Challenge

Write a function or program that, given a Modified Boggle board B (of any size) and a string s, determines if s can be found on B.

Restrictions

Your code itself should also fit on a Modified Boggle board b. That is, you must show the board b in your submission along with your code, so that your function/program outputs true if it is given b and your code as input.

Scoring

The score of your submission is the side length of the smallest board b where you can fit your code. Ties are broken by the usual code-golf rules, i.e. the length of your code in bytes. The submission with the lowest score (for both criteria) wins.

For example, from itertools import*\n has the score of 4 (using the board above) and code length of 23 bytes.

Input and Output

For input, you can take any convenient method for both B and s. This includes list of chars and list of charcodes, 2D or flattened or whatever makes sense. Also, you can optionally take the board size as a part of the input.

For output, you can choose one of the following:

Truthy and falsy values following your language's convention, or
One predefined value for true and false respectively.

Please specify your input/output method in your submission.

Python 2, score 3, 20972 bytes

exec'cecxc%c'%(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1)+…

Full code is the output of: Try it online!

Fits on the Boggle board:

e x (
c % 1
' + )

Decodes and executes this program:

cecxc=any
c,cec=input()
cxec=len(c)
cexec=lambda    cxc,cexc,c,cec:cexc<=''or   cxc[cec][c]==cexc[0]>0<cecxc(cexec(cxc,cexc[1:],cxcxc,cxcec)for cxcxc   in(c-(c>0),c,c+(+1+c<cxec))for  cxcec   in(cec-(cec>0),cec,cec+(+1+cec<cxec))if(cxcxc,cxcec)!=(c,cec))
cxc=range(cxec)
print   cecxc(cexec(c,cec,cexc,cxec)for cexc    in  cxc for cxec    in  cxc)

Which takes input like: ['ILAW','BNGE','IUAO','ASRL'], 'LANGUAGE'


Find the HTTP status code Given the name of an HTTP status code, such as OK or Continue, output or return the corresponding number. Your code is limited to 200 bytes, and the winner is the answer that correctly finds the number for the most status codes.
For this challenge, the status codes your program should handle are:
100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

Test cases:
Continue        -> 100
OK              -> 200
No Content      -> 204
Not Found       -> 404

For invalid status codes or ones not supported by your program, any behavior is fine. Input and output can be in any reasonable format. If there is a tie, the shortest program that can support that many status codes wins.

Node.js,  135 126 125  123 bytes, score 40
Saved 2 bytes by using unprintable characters, as suggested by @dingledooper
s=>Buffer('~>/6%sH~~d4~\\~i~~,~~~~~.~~~~n)W*~~~~;~CR@M"~1E~$~ _Z9~')[parseInt(s[0]+s[4]+s[19],34)*57%65]*209%523

Try it online!
Decoding example
Let's consider the input string "Internal Server Error".
We extract the characters at indices \$0\$, \$4\$ and \$19\$ and concatenate them together:
Internal Server Error
^   ^              ^
This gives "Iro".
We parse this string as a base-34 value, leading to \$\color{blue}{21750}\$.
Note: For many shorter entries, some characters are undefined. This leads to strings such as "Piundefined" and much higher integers.
We apply the hash formula:
$$(\color{blue}{21750}\times57)\bmod65=5$$
We extract the corresponding character from the lookup string (which is a "s") and take its ASCII code, leading to \$\color{blue}{115}\$.
We apply another black magic formula to turn this into the final HTTP status code:
$$(\color{blue}{115}\times209)\bmod 523=500$$
Given an HTTP status code \$c\$, the ASCII code \$k\$ of the encoding character is given by the following reverse formula:
$$k = \lfloor c / 100\rfloor \times 23 - (c \bmod 100) \times 5$$
Try it online!

Node.js, 84 bytes, score 40
With a built-in.
s=>Object.keys(c=require('http').STATUS_CODES).find(k=>c[k]==s)||413+(~s.length/6&3)

Try it online!
How?
There are 3 strings that do not match the values stored in STATUS_CODES for codes 413, 414 and 416. For these ones, we use the length of the input to figure out the correct answer.
 string                            | len | ~len/6  | &3 | +413
-----------------------------------+-----+---------+----+------
 "Request Entity Too Large"        |  24 | -4.1667 |  0 |  413
 "Request-URI Too Long"            |  20 | -3.5000 |  1 |  414
 "Requested Range Not Satisfiable" |  31 | -5.3333 |  3 |  416


Clock (transliterate) Cipher Introduction:

I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).

With a Clock Cipher we use the following image to encipher text:

So a sentence like this is a clock cipher would become:

t  h i s     i s     a     c l  o  c k     c i p  h e r    (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17

Challenge:

Given a string sentence_to_encipher, encipher it as described above.

Challenge rules:

You can assume the sentence_to_encipher will only contain letters and spaces.
You can use either full lowercase or full uppercase (please state which one you've used in your answer).
You are not allowed to add leading zeros for the single-digit enciphered letters b through j, but two zeros 00 are mandatory for spaces.
You should use : as separator, and an additional leading or trailing : is not allowed.
You are allowed to use lowercase am and pm instead of uppercase AM and PM, as long as it's consistent.

General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code (i.e. TIO).
Also, adding an explanation for your answer is highly recommended.

Test cases:

Input:  "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"

Input:  "test"
Output: "19:4:18:19"

Input:  "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"

Input:  "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"

Input:  "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"

Python 2, 74 72 bytes

lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)

Try it online!

Takes input as all lowercase


Smallest groups in an array Introduction
Let's observe the following array:
[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]

A group consists of the same digits next to each other. In the above array, there are 5 different groups:
[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]

 1, 1, 1
          2, 2
                1, 1, 1, 1
                            2, 2, 2
                                     1, 1, 1

The smallest group of these is [2, 2], so we output [2, 2].
Let's take another example:
[3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]

 3, 3, 3
          4, 4, 4, 4
                      5, 5
                            4, 4
                                  3, 3
                                        4, 4

You can see that there are multiple groups with the same length. The smallest groups are:
[3, 3], [4, 4], [4, 4] and [5, 5].

So we just output [3, 3], [4, 4], [4, 4], [5, 5] in any reasonable format. You may output these in any order.
The Task
Given an array consisting of only positive integers, output the smallest group(s) from the array. You can assume that the array will contain at least 1 integer.
Test cases
Input: [1, 1, 2, 2, 3, 3, 4]
Output: [4]

Input: [1]
Output: [1]

Input: [1, 1, 10, 10, 10, 100, 100]
Output: [1, 1], [100, 100]

This is code-golf, so the submission with the least amount of bytes wins!

Mathematica, 24 bytes

MinimalBy[Length]@*Split

This is a composition of two functions that can be applied to a list. Split takes all groups of consecutive numbers, and MinimalBy[Length] selects those with minimal length.


Is the electric garage door open? My electric garage door works like this:

There is just one push button to control the door
If the door is fully closed and I hit the button, the door starts to open.  It takes 10 seconds to open fully
If the door is fully open and I hit the button, the door starts to close.  It takes 10 seconds to close fully
If the door is part way through opening or closing and I hit the button, then the door stops and is left partially open.
Whenever the door stops moving, either from automatic completion of an open or close action, or from manual interruption by pushing the button partway through an action, then the mechanism will reverse and remember its direction for the next action.
If the button is pushed when the door is stopped but partially open, then the amount of time for it to complete its action will be a fraction of 10 seconds in proportion to the amount it needs to move to complete the action.

Assume the door is fully closed at the start.

An input list of integers will be given.  These integers are the number of seconds I wait between successive pushes of the control button.

Output two things:

a percentage indicating the state of the door once all button pushes are completed and the door has reached a steady state.  Output of % symbol is optional.
an unambiguous indication of what direction the door will travel on the next button push.  This may be up/down, U/D, +/-, 1/0 or whatever you choose.

You may assume the door takes infinitesimally less than 10 seconds to complete an open or close action.

Example inputs:

<empty list>  # button was pushed just once
20            # button was pushed twice with 20 seconds between
10
5
20 20
10 10
5 5
1 2 3
8 9 10 11
11 10 9 8 7

Expected outputs corresponding to above inputs

100% D
0% U
0% U
50% D
100% D
100% D
0% U
100% D
0% U
20% U

Worked example of the last test

Door starts off closed.  Button is pushed
Wait 11 seconds.  Door ends up fully opened.  Button is pushed.
Wait 10 seconds.  Door ends up fully closed.  Button is pushed.
Wait 9 seconds.  Button is pushed.  Door stops at 90% open.
Wait 8 seconds.  Button is pushed.  Door starts to close.
Wait 7 seconds.  Button is pushed.  Door stops at 20% open.  Next direction will be up.

Lua, 258 248 242 bytes
u,s,p=1>0,0>1,0;io.read():gsub("%d+",function(a)if(not s)then p=u and p+a or p-a;if(p>=10 or p<=0)then s,p=1>0,p>0 and 10 or 0;end;u,s=not u,not s else s=0>1;end end)if(not s)then p=u and 10 or 0;u=not u;end;print(10*p.."% "..(u and"U"or"D"))

Ungolfed
u,s,p=true,false,0;                          -- Up direction, Stopped, Position
io.read():gsub("%d+",function(t)             -- For each number in input
    if(not s)then                            -- If door wasn't stopped
        p=u and p+t or p-t;                  -- Position = Moving up ? +t : -t
        if(p>=10 or p<=0)then                -- If door fully opened or closed
            s,p=true,p>0 and 10 or 0;        -- Then door stopped at 0 or 10
        end
        u,s=not u,not s;                     -- Toggle direction and toggle stopped
    else
        s=false;                             -- If stopped, nothing happened, un-stop.
    end
end)
-------------------- Done pressing the button --------------------
if(not s)then                                -- If left off moving
    p=u and 10 or 0;                         -- Finish movement
    u=not u;                                 -- Toggle direction
end
print(10*p.."% "..(u and"U"or"D"))           -- Output answer

I don't see how your test cases can be right...
20 20 -- Initial push, after 20, garage is at 100, push to start it down, after 20, garage is at 0, push to start it up, garage finishes up.
10 10 -- Same as above
1 2 3 -- 0 U Moving, wait 1, 1 D Stopped, wait 2, 0 U stopped, wait 3, 100 D stopped

 OP Fixed


Slither Like a Snake The Idea

We've done matrix spirals before, and full rotations, and even diagonal
rotations,
but not, as far as I can find, snake rotations!

What is a snake rotation?

Imagine the rows of a matrix snaking back and forth, with dividers between
them like the dividers of long queue:

    +--------------+
      1  2  3  4  5|
    +------------  |
    |10  9  8  7  6|
    |  +-----------+
    |11 12 13 14 15|
    +------------  |
     20 19 18 17 16|
    +--------------+

Now imagine rotating these items by 2.  Each item advances, like people moving
in a line, and the items at the end spill out and return to the beginning:

    +--------------+
-->  19 20  1  2  3|
    +------------  |
    | 8  7  6  5  4|
    |  +-----------+
    | 9 10 11 12 13|
    +------------  |
<--  18 17 16 15 14|
    +--------------+

If there are an odd number of rows it will exit from the right, but still wrap
to the beginning. For example, here's a 3 rotation:

    +--------------+
      1  2  3  4  5|
    +------------  |
    |10  9  8  7  6|
    |  +-----------+
    |11 12 13 14 15
    +--------------+

    +--------------+
-->  13 14 15  1  2|
    +------------  |
    | 7  6  5  4  3|
    |  +-----------+
    | 8  9 10 11 12  -->
    +--------------+

A negative rotation will take you backwards.  Here's a -2 rotation:

    +--------------+
<--   3  4  5  6  7|
    +------------  |
    |12 11 10  9  8|
    |  +-----------+
    |13 14 15  1  2  <--
    +--------------+

The Challenge

Your function or program will take 2 inputs, in any convenient format:

A matrix
A integer (positive or negative) indicating how many places to rotate it.

It will return:

The rotated matrix

Notes:

Code golf.  Fewest bytes wins.
Matrixes need not be square, but will contain at least 2 rows and 2 columns
Positive integers will rotate row 1 toward the right
Negative integers will rotate row 1 toward the left
You may reverse the meaning of positive / negative rotation numbers, if convenient
The rotation number can be larger than the number of items.  In that case, it
will wrap.  That is, it will be equivalent to the number modulo the number of
items.
The matrix will contain only integers, but it may contain any integers,
including repeats

Test Cases

Format:

Matrix
Rotation number
Expected return value

4 5
6 7

1

6 4
7 5

2  3  4  5
6  7  8  9
10 11 12 13

-3

5  9  8  7
12 11 10 6
13 2  3  4

8 8 7 7
5 5 6 6

10

5 5 8 8
6 6 7 7

Jelly, 10 bytes
UÐeẎṙṁ⁸UÐe

A dyadic Link accepting the marix on the left and the rotation integer on the right (uses the reverse meaning of positive / negative)
Try it online!
How?
UÐeẎṙṁ⁸UÐe - Link: matrix of integers, M; integer, R
 Ðe        - apply to even indices of M:
U          -   reverse each
   Ẏ       - tighten
    ṙ      - rotate left by R
     ṁ     - mould like:
      ⁸    -   chain's left argument, M
        Ðe - apply to even indices:
       U   -   reverse each


Compute minimal string segment sizes A common optimization to save space in binaries is to merge string literals where one literal is the suffix of another. For instance, a binary with the string literals

a: foobar
b: bar
c: barbaz
d: foobarbaz
e: baz

might contain the following string literal pool (# representing the \0-terminator):

foobar#foobarbaz#

with the symbols a, b, c, and d having the following values relative to the beginning of the string pool:

a:  0
b:  3
c: 10
d:  7
e: 13

In this task, you have to compute the minimal size of a string pool for a given set of input strings.

Input

The input is a series of up to 999 strings each comprising up to 80 ASCII characters (not including the newline) in the range from 32 to 127 inclusive and then a single newline character.

Output

Find the shortest string such that each of the input strings (including the terminating newlines) are substrings of that string. The output shall be the length of that shortest string. Do not output the string, only its length.

Scoring

This challenge is code golf, standard loopholes apply. The solution with the least length in octets wins.

Examples

Input:

foobar
bar
barbaz
foobarbaz
baz

shortest string, # representing newline:

foobar#foobarbaz#

length: 17
Input:

foobar
foobaz
foobarbaz
barbaz

shortest string, # representing newline:

foobar#foobaz#foobarbaz#

length: 24

Pyth, 20 18 bytes
hljb-{.zsmteM./d.z

Demonstration.
{ can be removed if duplicates are not allowed.
Explanation:
hljb-{.zsmteM./d.z
                .z     The input, as a list of strings.
         m             Map each strings to
             ./d       all possible partitions of the string into separate strings.
           eM          take the last element of each, giving all suffixes.
          t            Remove the first suffix, giving all suffixes other than
                       the string itself.
        s              Sum, combining the list of lists into a single list.
    -{.z               From the set of input strings, remove all suffixes.
                       This is the list of strings in the minimal segment.
  jb                   Join the strings together on newlines.
 l                     Take the length of the resulting string.
h                      Add one and print.


Find real roots of a polynomial Write a self-contained program which when given a polynomial and a bound will find all real roots of that polynomial to an absolute error not exceeding the bound.

Constraints

I know that Mathematica and probably some other languages have a one-symbol solution, and that's boring, so you should stick to primitive operations (addition, subtraction, multiplication, division).

There is certain flexibility on the input and output formats. You may take input via stdin or command-line arguments in any reasonable format. You may allow floating point or require that some representation of rational numbers be used. You may take the bound or the reciprocal of the bound, and if you're using floating point you may assume that the bound will not be less than 2 ulp. The polynomial should be expressed as a list of monomial coefficients, but it may be big- or little-endian.

You must be able to justify why your program will always work (modulo numerical issues), although it's not necessary to supply full proofs inline.

The program must handle polynomials with repeated roots.

Example

x^2 - 2 = 0 (error bound 0.01)

Input could be e.g.

-2 0 1 0.01
100 1 0 -2
1/100 ; x^2-2

Output could be e.g.

-1.41 1.42

but not

-1.40 1.40

as that has absolute errors of about 0.014...

Test cases

Simple:

x^2 - 2 = 0 (error bound 0.01)

x^4 + 0.81 x^2 - 0.47 x + 0.06 (error bound 10^-6)

Multiple root:

x^4 - 8 x^3 + 18 x^2 - 27 (error bound 10^-6)

Wilkinson's polynomial:

x^20 - 210 x^19 + 20615 x^18 - 1256850 x^17 + 53327946 x^16 -1672280820 x^15 +
    40171771630 x^14 - 756111184500 x^13 + 11310276995381 x^12 - 135585182899530 x^11 +
    1307535010540395 x^10 - 10142299865511450 x^9 + 63030812099294896 x^8 -
    311333643161390640 x^7 + 1206647803780373360 x^6 -3599979517947607200 x^5 +
    8037811822645051776 x^4 - 12870931245150988800 x^3 + 13803759753640704000 x^2 -
    8752948036761600000 x + 2432902008176640000  (error bound 2^-32)

NB This question was in the Sandbox for approximately 3 months. If you think it needed improving before posting, visit the Sandbox and comment on the other proposed questions before they are posted on Main.

Mathematica, 223
r[p_,t_]:=Module[{l},l=Exponent[p[x],x];Re@Select[NestWhile[Table[#[[i]]-p[#[[i]]]/Product[If[i!=j,#[[i]]-#[[j]],1],{j,l}],{i,l}]&,Table[(0.9+0.1*I)^i,{i,l}],2*Max[Table[Abs[#1[[i]]-#2[[i]]],{i,l}]]>t&,2],Abs[Im[#]]<t^.5&]]

This solution implements the Durand–Kerner method for solving polynomials. Note that this is not a complete solution (as will be shown below) because I cannot yet handle Wilkinson's Polynomial to the specified precision. First an explanation of what I'm doing:

#[[i]]-p[#[[i]]]/Product[If[i!=j,#[[i]]-#[[j]],1],{j,l}]&:
Thus function computes for each index i the next Durand-Kerner approximation. Then this line is encapsulated in a Table and applied using a NestWhile to the input points generated by Table[(0.9+0.1*I)^i,{i,l}]. The condition on the NestWhile is that the max change (over all terms) from one iteration to the next is greater than the specified precision. When all terms have changed less than this, the NestWhile ends and Re@Select removes the zeros that do not fall on the real line.
Example output:
> p[x_] := x^2 - 2
> r[p, .01]
{1.41421, -1.41421}

> p[x_] := x^4 - 8 x^3 + 18 x^2 - 27
> r[p, 10^-6]
{2.99999, 3., 3.00001, -1.}

> p[x_] := x^20 - 210 x^19 + ... + 2432902008176640000 (Wilkinson's)
> Sort[r[p, 2^-32]]
{1., 2., 3., 4., 5., 6., 7.00001, 7.99994, 9.00018, 10.0002, 11.0007, \
11.9809, 13.0043, 14.0227, 14.9878, 16.0158, 16.9959, 17.9992, \
19.0001, 20.}

As you can probably see, when the degree grows higher this method begins to bounce around the correct values, never really homing in completely. If I set the stopping condition of my code to be anything stricter than "from one iteration to next the guesses changed by no more than epsilon" then the algorithm never stops. I guess I should just use Durand-Kerner as input to Newton's method?


2048-like array shift Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element.
Shift must return a new array, where every pair of consecutive equal elements is replaced with their sum, and pairs should not intersect.
Shifting is performed only once, so we don't need to merge resulting values again.
Notice that if we have 3 consecutive equal elements, we have to sum rightmost ones, so for example, [2, 2, 2] should become [2, 4], not [4, 2].

The task is to write shortest function which takes an array and returns a shifted array.

You may assume that all integers will be strictly positive.

Examples:

[] -> []
[2, 2, 4, 4] -> [4, 8]
[2, 2, 2, 4, 4, 8] -> [2, 4, 8, 8]
[2, 2, 2, 2] -> [4, 4]
[4, 4, 2, 8, 8, 2] -> [8, 2, 16, 2]
[1024, 1024, 512, 512, 256, 256] -> [2048, 1024, 512]
[3, 3, 3, 1, 1, 7, 5, 5, 5, 5] -> [3, 6, 2, 7, 10, 10]

I am also very interested in solution using reduce :)

Jelly, 10 9 8 bytes
Œg+2/€UF

TryItOnline or run all test cases
How?
Œg+2/€UF - Main link: a                 e.g. [2,2,2,4,4,8]
Œg       - group runs of equal elements      [[2,2,2],[4,4],[8]]
   2/€   - pairwise reduce for each with
  +      -     addition                      [[4,2],[8],[8]]
      U  - reverse (vectorises)              [[2,4],[8],[8]]
       F - flatten list                      [2,4,8,8]


Generate a modulo rosace The cool stuff

The following rosace can help calculate numbers modulo 7.

In order to do that, you must start at 0 and turn clockwise a number of steps given by the first digit. Then, for each successive digit, follow the arrow and then turn clockwise the number of steps given by that digit.

Here is how you proceed for number 294:

You start at circle 0.
You turn clockwise the number of steps given by the first digit (which is a 2, you end up at 2).
You follow the arrow there (you end up at 6).
You turn clockwise the number of steps given by the second digit (which is a 9, you end up at 1).
You follow the arrow there (you end up at 3).
You turn clockwise the number of steps given by the third number (which is 4, you end up at 0).
294 mod 7 = 0 (meaning 294 is multiple of 7).

(Video explanation if you still didn't get it)

The goal

Figure out how that works (I know but I won't tell you).

Create a program that takes a number n in parameter and that generates a rosace for mod n.

The rosace can be displayed by any means you want (ASCII, generate PNG, generate SVG, ...) as long as it could be used by a 8 years old child (so no list of rules, I want a picture)!

You can use strait lines, even if it's a bit less clear than what I made for the example, but you must show clearly the numbers that point to themselves with some kind of tail-biting arrow.

Test cases

(I only give the links between the numbers, feel free to edit my question once your program sucessfully generates them)

mod 2:

0 -> 0
1 -> 0

mod 3:

0 -> 0
1 -> 1
2 -> 2

mod 4:

0 -> 0
1 -> 2
2 -> 0
3 -> 2

mod 5:

0 -> 0
1 -> 0
2 -> 0
3 -> 0
4 -> 0

mod 6:

0 -> 0
1 -> 4
2 -> 2
3 -> 0
4 -> 4
5 -> 2

mod 7:

0 -> 0
1 -> 3
2 -> 6
3 -> 2
4 -> 5
5 -> 1
6 -> 4

mod 8:

0 -> 0
1 -> 2
2 -> 4
3 -> 6
4 -> 0
5 -> 2
6 -> 4
7 -> 6

mod 9:

0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
8 -> 8

mod 10:

0 -> 0
1 -> 0
2 -> 0
3 -> 0
4 -> 0
5 -> 0
6 -> 0
7 -> 0
8 -> 0
9 -> 0

Rules

This is code-golf, shortest code in bytes wins.

As usual, loopholes and cheats are forbidden.

Mathematica, 192 bytes

This type of challenge (nontrivial mathematical computation together with high-level graphics output) is what Mathematica is made for!

(d=#;r_~t~n_:=r{Sin[#],Cos[#]}&[6.3n/d];m=Mod[10#,d]&;Graphics@{Array[#~Text~t[9,#]&,d,0],Array[Arrow@{t[9,#+1/7],t[9,#+6/7]}&,d],Array[Arrow@BezierCurve@{t[8,#+1/9],{0,0},t[8,m@#-1/9]}&,d]})&

Expanded and explained:

[1] (
[2] d = #; r_~t~n_ := r {Sin[#], Cos[#]} &[6.3 n/d]; m = Mod[10 #, d] &;
[3] Graphics@{
[4]   Array[#~Text~t[9, #] &, d, 0],
[5]   Array[Arrow@{t[9, # + 1/7], t[9, # + 6/7]} &, d],
[6]   Array[Arrow@BezierCurve@{t[8, # + 1/9], {0, 0}, t[8, m@# - 1/9]} &, d]
[7]          }
[8] ) &

Lines 1 and 8 delimit an unnamed function of one argument. Lines 3 and 7 delimit several commands that output graphics.

Lines 2 stores the input as d; defines a binary function t giving the coordinates of a point n/d of the way around the circle of radius r, clockwise from the top (in the spirit of this site, I saved a byte by rounding 2π to 6.3!); and defines a unary function m calculating the destination of the arrow starting at its argument.

Line 4 renders the numbers 0 to d–1 equally spaced around the circle of radius 9 (the exact radius unimportant, chosen to maximize aesthetics subject to fitting in one byte).

Line 5 renders the clockwise straight arrows around the circumference of the circle. The 1/7 and 6/7 leave enough space to read the numbers.

Line 6 renders the curved arrows from each number to (10 times the number modulo d). BezierCurve automatically draws a Bézier curve using the given control points. Fortunately, using the origin as a single interior control point produces reasonable output.

Sample output (note that the cases 9, 10, and 11 are trivial in different ways):

d = 7

d = 8

d = 9

d = 10

d = 11

d = 12

d = 13

d = 37

This last input was chosen because 37 divides 10^3–1, and so the interior arrows (not counting the obligatory self-arrow from 0 to 0) form lots of triangular cycles.


Evaluate Words Based on "Rules" (Skeptics.SE Crossover) I came across this picture, which I initially questioned and thought about posting to Skeptics. Then I thought they'll only tell me if this one case is true, but wouldn't it be great to know how true any "rule" really is? Today you're going program a skeptic-bot

Challenge

Write a program or function which when given a dictionary of valid words and a rule determines if the rule is well applied

Rules

The dictionary is "words.txt" taken from here. Your submission must theoretically be able to review all words in the file, but for testing you may use a shortened list
"Rules" come in the form x before y except <before/after> z.  Your submission may take that input in any reasonable form, some examples below
Compliance is defined as: "There is an adjacent x and y in the word in the right order that are in the reverse order if before/after z"
Non-compliance is defined as: "There is an adjacent x and y in the word in the incorrect order or they are not reverse if before/after z"
Rules are evaluated case insensitive
Output or return a truthy value if the number of compliant words in the dictionary is greater than the number of non-compliant words, otherwise output a falsey value. Submissions cannot end in errors.
This is code-golf, so shortest submission in bytes wins

Example input:

["i","e","-","c"]  #list of values, "-" denotes "after"
[105,101,-99]    #list of values as ASCII numbers, "-99" denotes "after"
"ieac"           #string of values abbreviated

Test Cases

Below are sample cases as inputs, for clarity I list the matching words but this is not required

Example dictionary: ["caught", "lemon", "simplified", "queue", "qwerty", "believe", "fierce", "receive", "science", "foreign", "weird", "quit"]

Input: "I before E except after C"
Compliant: simplified, believe, fierce, receive
Noncompliant: science, foreign, weird
Output: Truthy

Input: "Q before U except before E"
Compliant: quit
Noncompliant: queue
Output: Falsey

Input: "C before E except before E"
Compliant: fierce, receive, science
Noncompliant:
Output: Truthy

Python3, 105 103 bytes
This is my first golf here so be kind =)
-2 bytes tanks to Chas Brown
lambda d,b,x,y,z:sum((x+y in i)-2*((z*b+x+y+z)[:3]in i)-(y+x in i)+2*((z*b+y+x+z)[:3]in i)for i in d)>0

Takes the dictionary d as any iterator of strings; a boolean 'b' (True being after); and the three letters x,y,z as Strings;
Try it online!
Explanation: might add later


Sum digits till Square Given is any integer x > 0 and any base y > 3.

Sum all digits of x (if written in the set base).
Multiply this by the highest possible digit (is always base -1).
Repeat until this value is (y - 1) ^ 2

Searched is the count of iterations and the steps.

Example 1:

x= 739
y= 7
searched: (7 - 1) ^ 2 = 36

based: (b7)2104
sum: (dec)7
mul: (dec)42

based: (b7)60
sum: (dec)6
mul: (dec)36

2 steps needed -> answer is [2, 739, 42, 36] or [739, 42, 36, 2]

Example 2:

x = 1712
y = 19
s: 324

step1: 1712 -> 360
step2:  360 -> 648
step3:  648 -> 324

3 steps needed -> answer is [3, 1712, 360, 648, 324] or [1712, 360, 648, 324, 3]

Special:
In some cases (some combinations with a base of 3) you will not be able to get to (y - 1) ^ 2 like for x = 53 and y = 3. For this reason y needs to be bigger than 3 and you can ignore this.

The count of iterations need to be the first or the last value

This is code-golf lowest byte-count wins.

Perl 6, 60 bytes

{$/=[$^x,*.polymod($^y xx*).sum*($y-1)...($y-1)²];$/-1,|$/}

Expanded:

{    # bare block lambda with placeholder parameters ｢$x｣ ｢$y｣

  $/ = [          # store in ｢$/｣ ( so that we don't have to declare it )

    # generate a sequence

    $^x,          # declare first parameter, and seed sequence generator

    # Whatever lambda

    *\            # the parameter to this lambda

    .polymod(     # broken down with a list of moduli

      $^y         # declare second parameter of the outer block lambda
      xx *        # an infinite list of copies of it

    )
    .sum
    *
    ( $y - 1 )

    # end of Whatever lambda

    ...           # repeat until it reaches

    ( $y - 1 )²
  ];

  # returns
  $/ - 1,         # count of values minus one
  |$/             # Slip ｢|｣ the list into the result
}

Usage:

# store it in the lexical namespace so that it is easier to understand
my &code = {$/=[$^x,*.polymod($^y xx*).sum*($y-1)...($y-1)²];$/-1,|$/}

say code  739,  7; # (2 739 42 36)
say code 1712, 19; # (3 1712 360 648 324)


Can you outgolf Bill Gates? Pancake sorting is the colloquial term for the mathematical problem of
sorting a disordered stack of pancakes in order of size when a spatula
can be inserted at any point in the stack and used to flip all
pancakes above it. A pancake number P(n) is the minimum number of
flips required for n pancakes. 1

In 1979, a young Bill Gates and Christos Papadimitriou, wrote a paper proving an upper bound of P(n) = (5n+5)/3. 2
I think it's safe to assume that Gates (and/or Papadimitriou) wrote a program to perform pancake sorting using the algorithm they developed (possibly  later than 1979). Since Gates was a skilled programmer, they probably tried to golf this code as well as they could, but the size of the source code is not publicly available (AFAIK).
Challenge:
Create a function / program that performs pancake sorting, where the maximum number of flips doesn't exceed the bound found by Gates and Papadimitriou.3 You may choose if you want the list ascending or descending, as long as it's consistent.
You may assume that n < 50. You must therefore limit the number of flips to (some randomly selected n-values):
 n   P(n)
38   65
49   83
50   85

The output should be the position of the spatula before each flip. The output may be zero or one-indexed, and you may choose if you count from the top or bottom.
Additional rules:

The runtime must be deterministic
There is no fixed time limit, but you must be able to provide the output for a list with 50 elements

Test lists:
I can't provide the hardest lists (if so, I would write a paper, not a challenge), so I'll provide some random lists of numbers you can test your functions/programs on. I might add others if it turns out these lists where "easy".
9, 63, 62, 75, 45, 78, 59, 75, 69, 3, 28, 94, 51, 10, 45, 93, 97, 80, 72, 36, 80, 88, 30, 93, 84, 80, 17, 31, 6, 80, 76, 91, 9, 76, 38, 33, 22, 15, 45, 46, 15, 98, 2, 56, 90, 27, 27, 26, 69, 25
...
74, 89, 57, 52, 70, 96, 16, 5, 77, 84, 54, 13, 90, 64, 31, 80, 3, 25, 13, 19, 13, 34, 1, 79, 35, 43, 4, 19, 82, 29, 48, 95, 97, 28, 45, 62, 64, 82, 70, 34, 38, 15, 51, 83, 21, 66, 4, 42, 74, 84
...
62, 73, 7, 90, 83, 18, 12, 35, 72, 71, 99, 67, 87, 62, 65, 70, 14, 72, 55, 92, 87, 3, 7, 4, 4, 95, 49, 25, 4, 18, 49, 39, 26, 1, 45, 64, 23, 66, 39, 17, 33, 24, 58, 72, 77, 46, 99, 71, 10, 21

Hopefully, Bill Gates and Papadimitriou will see this challenge, and provide their code, so that we can determine if you did in fact outgolf them.
3Better upper bounds have been found, but you do not need to care about those.

Python 2 (PyPy), 238 235 222 bytes

a=input();n=len(a);r=range(n);a=zip(a,r);a=map(sorted(a).index,a)+[n]
def s(u,m):
 if m<1:return[0]
 for k in r:
  v=u[k::-1]+u[k+1:]
  if sum(1<abs(v[i]-v[i+1])for i in r)<m:
   p=s(v,m-1)
   if p:return[k]+p
print s(a,5*n/3)

*(2 spaces = tab)
Try it online!
Saved 13 bytes borrowing a method for ranking a list.
DFS with a simple heuristic that checks whether a flip separates a pair of "pancakes" that would be adjacent when sorted. Sorts it in ascending order. Output is 0-indexed from the left where 0 flips the first 2 and so on. The number of moves used is (5/3)*n+1 < 5/3*(n+1) where (18/11)*n < (5/3)*n+1 < 5/3*(n+1) and (18/11)*n is a tighter upper bound found in 2009.


Find the Nth pair of twin primes Two prime numbers are defined as twin primes if they differ by two. For example, 3 and 5 are twin primes as are 29 and 31.

Write a program that finds the nth pair of twin primes (where n comes from STDIN) and prints them on STDOUT, separated by a comma and a space. This is code-golf, so the shortest code wins.

Sample input:

3

Sample output:

11, 13

Haskell 118
main=putStrLn.(!!)[show n++", "++show(n+2)|n<-[2..],all((>0).rem n)[2..n-1],all((>0).rem(n+2))[2..n]].(+)(-1)=<<readLn

Brute-force all twin primes and prints the nth pair.


Caddyshack or: How to compress already-golfed code In golf, a knowledgable caddie helps an already good golfer to be even better. In this challenge, you build a "caddie" to help you code golf. In particular, your caddie will compress golfed code in such a way that another program can uncompress and then run the code. A good caddie will compress golfed code to be much smaller than the original golfed code. In fact, in caddie-assisted Python (say), you might be able to golf on par with a Jelly golfer!

Formally, a caddie for a language L is a pair (E,D) of programs. The program E takes as input any code c in L and outputs a string s. The program D takes s as input along with any input x of c and returns the output of c(x). We do not require E and D to be written in L. You could say that E is a transpiler that converts c into a version s that runs in the language D. We are interested in transpilers E for which E(c) tends to be smaller than c, even when c is already golfed.

Write a caddie (E,D) for any language L of your choosing. When you first post a caddie here, its score is infinity. Use the following method to update your score:

Let C denote the challenge in code-golf with at least 10 points that was posted first after your submission.
Let c denote the shortest posted solution to C that is written in L.
Your score is infinity unless C and c both exist, at which point your score is size(E(c))/size(c).

Recompute your score whenever either C or c changes. Lowest score wins.

Python 3 Caddy, interprets BrainF***

Score: \$\frac{38}{224}\approx0.17\$ (with newlines removed)

Program E

from textwrap import wrap

x = input('Code: ')
i = ['<', '>', '+', '-', '[', ']', '.', ',']
o = ''
for c in x:
    if c in i:
        o += str(i.index(c) + 1)
if o:
    d = wrap(o, 6)
    d = [int(x) for x in d]
    o = ''
    for c in d:
        o += chr(int(c) + 128)
print('Compressed: ', o)

The way this works is by converting every instruction in the input to a digit, then concatenating those digits to a number. Then it splits that number into 6-digit groups and converts each to a Unicode character. (A number higher than 6 could be used, by that would cause errors for large programs). Then it outputs it.

Program D

x = input('Compressed: ')
p = input('Input: ')
p = list(p)
d = ''
for c in x:
    c = ord(c) - 128
    d += str(c)
d = d.replace('-', '')
i = ['<', '>', '+', '-', '[', ']', '.', ',']
o = ''
for n in d:
    n = int(n) - 1
    o += i[n]
tape = [0] * 30000
head = 0
m = {}
m2 = {}
stack = []
for i in range(len(o)):
    char = o[i]
    if char == '[':
        stack.append(i)
    elif char == ']':
        begin = stack.pop()
        m[begin] = i + 1
        m2[i] = begin
i = 0
while i < len(o):
    char = o[i]
    if char == '<':
        head -= 1
        i += 1
    elif char == '>':
        head += 1
        i += 1
    elif char == '+':
        tape[head] += 1
        i += 1
    elif char == '-':
        tape[head] -= 1
        i += 1
    elif char == '[':
        if tape[head] == 0:
            i = m[i]
        else:
            i += 1
    elif char == ']':
        if tape[head] != 0:
            i = m2[i]
        else:
            i += 1
    elif char == '.':
        print(chr(tape[head]), end='')
        i += 1
    elif char == ',':
        try:
            tape[head] = ord(p.pop(0))
        except:
            tape[head] = 0
        i += 1

This is pretty simple, it just reverses the compression algorithm and evaluates the result.


Which big number is bigger? Input

Integers a1, a2, a3, b1, b2, b3 each in the range 1 to 20.

Output

True if a1^(a2^a3) > b1^(b2^b3) and False otherwise.

^ is exponentiation in this question.

Rules

This is code-golf. Your code must terminate correctly within 10 seconds for any valid input on a standard desktop PC.

You can output anything Truthy for True and anything Falsey for False.

You can assume any input order you like as long as its specified in the answer and always the same.

For this question your code should always be correct. That is it should not fail because of floating point inaccuracies.  Due to the limited range of the input this should not be too hard to achieve.

Test cases

3^(4^5) > 5^(4^3)
1^(2^3) < 3^(2^1)
3^(6^5) < 5^(20^3)
20^(20^20) > 20^(20^19)
20^(20^20) == 20^(20^20)
2^2^20 > 2^20^2
2^3^12 == 8^3^11
1^20^20 == 1^1^1
1^1^1 == 1^20^20

Perl 6, 31 29 bytes

-2 bytes thanks to Grimy

*.log10* * ***>*.log10* * ***

Try it online!

Believe it or not, this is not an esolang, even if it is composed of mostly asterisks. This uses Arnauld's formula, with log10 instead of ln.


Approximate My Squares Inspired by this video by tecmath.

An approximation of the square root of any number x can be found by taking the integer square root s (i.e. the largest integer such that s * s ≤ x) and then calculating s + (x - s^2) / (2 * s). Let us call this approximation S(x). (Note: this is equivalent to applying one step of the Newton-Raphson method).

Though this does have quirk, where S(n^2 - 1) will always be √(n^2), but generally it will be very accurate. In some larger cases, this can have a >99.99% accuracy.

Input and Output

You will take one number in any convienent format.

Examples

Format: Input -> Output

2 -> 1.50
5 -> 2.25
15 -> 4.00
19 -> 4.37               // actually 4.37       + 1/200
27 -> 5.20
39 -> 6.25
47 -> 6.91               // actually 6.91       + 1/300
57 -> 7.57               // actually 7.57       + 1/700
2612 -> 51.10            // actually 51.10      + 2/255
643545345 -> 25368.19    // actually 25,368.19  + 250,000,000/45,113,102,859
35235234236 -> 187710.50 // actually 187,710.50 + 500,000,000/77,374,278,481

Specifications

Your output must be rounded to at least the nearest hundredth (ie. if the answer is 47.2851, you may output 47.29)
Your output does not have to have following zeros and a decimal point if the answer is a whole number (ie. 125.00 can be outputted as 125 and 125.0, too)
You do not have to support any numbers below 1.
You do not have to support non-integer inputs. (ie. 1.52 etc...)

Rules

Standard Loopholes are forbidden.

This is a code-golf, so shortest answer in bytes wins.

Python 2, 47 ... 36 bytes

-3 bytes thanks to @JungHwanMin
-1 byte thanks to @HyperNeutrino
-2 bytes thanks to @JonathanFrech
-3 bytes thanks to @OlivierGrégoire

def f(x):s=int(x**.5);print(x/s+s)/2

Try it online!


What logic gates work given the input? Introduction
Logic gates! Everyone knows them, everyone loves them (unless you're starting to learn them). Take two booleans, compare them, get a single boolean in return. AND, NAND, OR, NOR, XOR, XNOR. Fun! But, what if you only had the inputs and output, but not the operator?

Challenge
Given a three digit number, xyz, where x and y are inputs to the unknown gate(s) and z is the output, list all the possible gates. The output order doesn't matter but it must be all caps and separated by a space. This is code-golf, so the shortest answer wins!
Example Inputs and Outputs
Inputs:

001
101
111

Outputs:

NAND NOR XNOR
NAND OR XOR
AND OR XNOR

JavaScript (ES6),  58  56 bytes
n=>`25AND 41OR X37OR`.replace(/\d+/g,m=>m>>n%6&1?'':'N')

Try it online!
How?
Given the input \$n\$, we compute \$n\bmod 6\$ to get an index into 3 small lookup bit masks.
It's worth noting that all operations are commutative, i.e. \$(X \operatorname{op} Y)=(Y \operatorname{op} X)\$ even when \$X=\lnot Y\$. So the collisions between 011 and 101 and between 010 and 100 are actually very welcome.
 n (decimal) | n mod 6 | NAND | NOR | XNOR
-------------+---------+------+-----+------
  011 or 101 |    5    |   0  |  1  |  1
  010 or 100 |    4    |   1  |  0  |  0
         111 |    3    |   1  |  1  |  0
         110 |    2    |   0  |  0  |  1
         001 |    1    |   0  |  0  |  0
         000 |    0    |   1  |  1  |  1
                           |     |     |
                           |     |     +--> 0b100101 = 37
                           |     +--------> 0b101001 = 41
                           +--------------> 0b011001 = 25

We look for the bit masks in the string "25AND 41OR X37OR" and replace them with either "N" or an empty string.


Build me a brick road! I need help making a brick road to go beside my brick wall!

\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \
 \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__
__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\
\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \
 \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__
__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\
\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \
 \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__
__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\
\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \__\  \

This road is 10 characters long and 70 characters wide, seems familiar right?

We have to stay efficient with this road as well, no input and lowest byte count in some code that produces this pattern in an output wins!

This code-golf puzzle isn't the same as the predecessor mentioned above, as the output requires a different approach rather than just simply outputting what it asks (because the pattern is offscured and not exactly the same). It was purposefully included like this for the puzzle to match the theme of my page and also include a higher difficulty for the user (the original was very simple for some). This was mentioned below in the comments.

V, 20 bytes

123i\  \__ò70|lé
4x

Try it online!

As usual, here is a hexdump:

0000000: 3132 3369 5c20 205c 5f5f 1bf2 3730 7c6c  123i\  \__..70|l
0000010: e90a 3478                                ..4x

Explanation:

123                     " 123 times:
   i                    " Insert the following:
    \  \__              " '\  \__'
          <esc>         " Return to normal mode
               ò        " Recursively:
                70|     "   Move to the 70th column
                   l    "   Move one char over
                    é   "   Insert a single newline
4x                      "   Delete 4 characters


Sieve of Sundaram (for finding prime numbers) The Challenge

Implement the Sundaram sieve for finding prime numbers below n. Take an input integer, n, and output the prime numbers below n. You can assume that n will always be less than or equal to one million.

Sieve

Start with a list of the integers from 1 to n.
Remove all numbers that are in the form i + j + 2ij where:

i and j are less than n. j is always greater than or equal to i, which is greater than or equal to 1.
i + j + 2ij is less than or equal to n

Multiply the remaining numbers by 2, and add 1.

This will yield all the prime numbers (except 2, which should be included in your output) less than 2n + 2.

Here is an animation of the sieve being used to find primes below 202.

Output

Your output should be every prime integer ≤ n (in ascending order) followed by a newline:

2
3
5

Where n is 5.

Examples

> 10
2
3
5
7

> 30
2
3
5
7
11
13
17
19
23
29

Inputs are denoted by >.

Pyth, 23 bytes

2j@JSQmhyd-Jm+sdy*Fd^J2

Demonstration

Really just implements the algorithm as given.


Code-Golf: Farey sequence (I) Challenge

  In this task you would be given an integer N
  (less than 10^5), output the Farey
  sequence of order N.

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

Input

4
3
1
2

Output

F4 = {0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1}
F3 = {0/1, 1/3, 1/2, 2/3, 1/1}
F1 = {0/1, 1/1}
F2 = {0/1, 1/2, 1/1}

Constraints

The number of inputs would not exceed 10^6 values
You can use any language of your choice
Shortest solution wins!


Advent Challenge 8: Storage Cart Transport Planning! << Prev

Thanks to the PPCG community, Santa now has balanced his storage carts. Now, he needs to move them into the transport docks so that they can be sent to the loading bays. Unfortunately, the tracks to move the carts around are a mess, and he needs to figure out how to get them all around without them crashing together!

Challenge

You will be given the tracks for each of the carts as lists of "labels" (or stations). The carts must be moved such that at any time frame, no two carts are on the same label/station. Essentially, the carts move between positions that each have a unique label.

Task

Given the tracks for each of the carts as a list of lists of labels (which are all positive integers), determine when each cart should be released in order to send all the carts to their destinations safely in the shortest time possible.

Here's an explanation of how the entire track system works. Let's say cart i is released at time t_i onto a track with labels T_i_1, T_i_2, ..., T_i_n. Then, during t_1 to t_i-1, cart i is not on the grid and can be ignored.

At time frame t_i, the cart is on label T_i_1, and for each time frame t_k from t_i to t_i+n (half-inclusive), the cart is on label T_i_k+1.

For all time frames after and including t_i+n, the cart is at its destination and is no longer on the grid.

The total amount of time t_T taken is the last time frame with a cart still on a track in the system.

Specifications

Given a track system, return a list of time frames [t_1, t_2, ..., t_n] where the ith cart starts at time t_i, such that no other arrangement would allow the carts to safely get to their destinations with a lesser total amount of time.

In terms of "safely", if at any time frame from t_1 to t_T there is more than one cart on any label, then they collide and the arrangement was not "safe". Note that two carts can move from a, b to b, a and still be "safe" because the tracks are 2-way.

Formatting Specifications

Input will be given as a matrix of positive integers in any reasonable format. Output should be given as a list of positive integers in any reasonable format. You may give output in zero-indexed time frames, so then the output would be a list of non-negative integers in any reasonable format.

Rules

Standard Loopholes Apply
This is a code-golf so the shortest answer in bytes wins
No answer will be accepted

Test Cases

Input -> Output
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] -> [1, 1, 1]
[[1, 2, 3], [1, 2, 3]] -> [1, 2]
[[1, 2, 3], [3, 2, 1]] -> [1, 2]
[[1, 2, 3, 4], [4, 3, 2, 1]] -> [1, 1]
[[1, 1, 1], [1, 1, 1]] -> [1, 4]
[[1, 2, 3, 4], [2, 4, 3, 1]] -> [2, 1]
[[1, 2, 3, 4, 5, 6, 7], [2, 3, 3, 4], [5, 4, 3]] -> [1, 3, 4]
[[1, 2, 3, 4, 4], [1, 2, 3, 5, 4], [1, 2, 3, 4, 5]] -> [2, 3, 1]

Note: I drew inspiration for this challenge series from Advent Of Code. I have no affiliation with this site

You can see a list of all challenges in the series by looking at the 'Linked' section of the first challenge here.

Happy Golfing!

JavaScript (ES7), 172 bytes
Returns an array of 0-indexed time frames.
a=>(g=k=>a.map((a,i)=>[l=a.length+1,i,a,L=L<l?l:L]).sort(([a],[b])=>a-b).every(([,n,b],i)=>b.every((c,t)=>o[t+=A[n]=k/L**i%L|0]&1<<c?0:o[t]|=1<<c),o=[],A=[])?A:g(k+1))(L=0)

NB: This can only work with labels in [0-31]. This is a JS limit, not a limit of the algorithm.
Test cases

let f =

a=>(g=k=>a.map((a,i)=>[l=a.length+1,i,a,L=L<l?l:L]).sort(([a],[b])=>a-b).every(([,n,b],i)=>b.every((c,t)=>o[t+=A[n]=k/L**i%L|0]&1<<c?0:o[t]|=1<<c),o=[],A=[])?A:g(k+1))(L=0)

console.log(JSON.stringify(f([[1, 2, 3], [4, 5, 6], [7, 8, 9]])))                   // -> [0, 0, 0]
console.log(JSON.stringify(f([[1, 2, 3], [1, 2, 3]])))                              // -> [0, 1] or [1, 0]
console.log(JSON.stringify(f([[1, 2, 3], [3, 2, 1]])))                              // -> [0, 1] or [1, 0]
console.log(JSON.stringify(f([[1, 2, 3, 4], [4, 3, 2, 1]])))                        // -> [0, 0]
console.log(JSON.stringify(f([[1, 1, 1], [1, 1, 1]])))                              // -> [0, 3] or [3, 0]
console.log(JSON.stringify(f([[1, 2, 3, 4], [2, 4, 3, 1]])))                        // -> [1, 0]
console.log(JSON.stringify(f([[1, 2, 3, 4, 5, 6, 7], [2, 3, 3, 4], [5, 4, 3]])))    // -> [0, 2, 3]
console.log(JSON.stringify(f([[1, 2, 3, 4, 4], [1, 2, 3, 5, 4], [1, 2, 3, 4, 5]]))) // -> [1, 2, 0]

Commented
a => (                         // given a = array of tracks
  g = k =>                     // g = recursive function taking k = counter
    a.map((t, i) => [          // map each track t in a to a new entry made of:
      l = t.length + 1,        //   - its length + 1 (l)
      i,                       //   - its original index in the input array
      t,                       //   - the original track data
      L = L < l ? l : L        //   and update the maximum track length L
    ])                         // end of map()
    .sort(([a], [b]) =>        // let's sort the tracks from shortest to longest
      a - b                    // so that solutions that attempt to delay short
    )                          // tracks are tried first
    .every(([, n, b],          // for each track b with an original position n,
                      i) =>    // now appearing at position i:
      b.every((c, t) =>        //   for each label c at position t in b:
        o[t += A[n] =          //     add to t the time frame A[n] corresponding
          k / L**i % L | 0     //     to this position (i) and this combination (k)
        ] & 1 << c ?           //     if the station c is already occupied at time t:
          0                    //       make every() fail
        :                      //     else:
          o[t] |= 1 << c       //       mark the station c as occupied at time t
      ),                       //   end of inner every()
      o = [],                  //   start with: o = empty array (station bitmasks)
      A = []                   //               A = empty array (time frames)
    ) ?                        // end of outer every(); if successful:
      A                        //   return A
    :                          // else:
      g(k + 1)                 //   try the next combination
)(L = 0)                       // initial call to g() + initialization of L


Mirror, Mirror, in the Code Two-dimensional programming languages often have mirror commands like / and \ to redirect the instruction pointer on the grid:
>>>>\
    v
    v
<<<</

In this challenge, you're given an incoming direction and a mirror and you need to determine the outgoing direction.
Rules
The incoming direction will be given as one of the characters NESW and the mirror will be given as either / or \. You may receive these in any order. You must use uppercase letters.
You may take input in any convenient format, including a two-character string, a string using some separator between the characters, a pair of characters in a list, or even a pair of singleton strings. If you do use a string with separator, the separator cannot use any of the characters NWSE\/.
Output should be a character from NESW or single-character string.
You may write a program or a function and use any of the our standard methods of receiving input and providing output.
You may use any programming language, but note that these loopholes are forbidden by default.
This is code-golf, so the shortest valid answer – measured in bytes – wins.
Test Cases
There are only 8 possible inputs you need to handle, so there is no excuse for not testing your code on all of them:
N /   -->   W
N \   -->   E
E /   -->   S
E \   -->   N
S /   -->   E
S \   -->   W
W /   -->   N
W \   -->   S

Python, 40 38 bytes
-2 bytes thanks to @MitchSchwartz (ord(d)+ord(m))%8 -> ord(d)+ord(m)&7

lambda d,m:' NESSWNW'[ord(d)+ord(m)&7]

plain lookup of answer in a list (AKA string) indexed by the smallest mod of the sum of ordinals that works.
Test cases are on ideone


Check if input is permutation of source Inspired by Input ∩ Source Code.

Task

Your task is to determine whether the input is a permutation of the source code.

Input

A string. Input is flexible; it should be able to handle the character encoding used for the source code.

Output

You may only have two possible outputs, one when the input is a permutation of the source code, and one when it is not. Those outputs maybe be of any length (including 0) but must be distinct, consistent, and deterministic.

Specs

Similar to quine challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.

Example

If your source code is ppcg, then an input of cpgp or ppcg would be a permutation of the source code while cpg or cggp or caqp or cpaqr would not be.

Python 2.7, 135 112 bytes

print sorted(list(input()))==sorted(list('\''*7+'\\'*3+'print sorted(list(input()))==sorted(list(*7+*3+*2))'*2))


Convert Character Substrings to Numeric I often have to take character data and categorize it numerically at work. A common thing I do is to take character type variables and convert them to numeric type characters, keeping same categories according to the level of work I'm doing. (The longer the substring, the more in depth and specific, shorter substrings for broad level). Enough backstory...

The challenge: In as few bytes as possible, convert the input part A, a vector/list of unique strings, into the output, a vector/list of numbers, keeping unique categories within the length of substrings the same length, which is input part B. Feel free to ask questions for clarification.

Input:

w, Vector/list of unique strings of equal character length. n <= 10

These strings may be any combination of uppercase letters and numbers. Sorry if it seems my examples follow a pattern, I just created them after a similar pattern I see in the data I work with.
Some random examples of what input could look like: "A1", "7LJ1", "J426SIR", "4AYE28TLSR", or any other random combination of uppercase letters up to 10 characters. To repeat: Each element in the vector/list will be the same length.
Input may already be ordered by group, or non-contiguous, meaning elements lying within one group may be separated by elements of a different group. (See example 2)

s, where 1 <= s <= n

Output:

Output should have the indexes of the sorted, de-duplicated, trimmed values. See example 2. (I've included comments in my output to clarify, this is not required) This can be 0-based or 1-based index, as per your language uses.

Example Input 1:

#Input already alphabetized, but this input is not always guaranteed

s = 3, w =
[ABC01,
 ABC11,
 ABC21,
 ABD01,
 ABE01,
 ABE02,
 ACA10,
 ACA11,
 ACB20,
 ACB21]

Example Output 1:

[1, #ABC
 1,
 1,
 2, #ABD
 3, #ABE
 3,
 4, #ACA
 4,
 5, #ACB
 5]

Example Input 2:
s = 4, w =

[X1Z123,
 X1Z134,
 X1Y123,
 X1Y134,
 X1Y145,
 X1Y156,
 X1X123,
 X1X124,
 X1X234,
 X2Z123,
 X2Z134,
 X1X255,
 X1Y124,
 X2Z222,
 X2Z223,
 X2Z224]

Example 2 Output:

#Categorize by order of appearance
[1, #X1Z1
 1,
 2, #X1Y1
 2,
 2,
 2,
 3, #X1X1
 3,
 4, #X1X2
 5, #X2Z1
 5,
 4, #X1X2 again (to show input can be non-contiguous)
 2, #X1Y1 again
 6, #X2Z2
 6,
 6]

OR

#Input not alphabetized, but indexes still match original input indexes.
[4, #X1Z1
 4,
 3, #X1Y1
 3,
 3,
 3,
 1, #X1X1
 1,
 2, #X1X2
 5, #X2Z1
 5,
 2, #X1X2 again (to show input can be non-contiguous)
 3, #X1Y1 again
 6, #X2Z2
 6,
 6]

APL (Dyalog Extended), 8 7 6 bytesSBCS

Anonymous infix function. Takes s as left argument and w as a list of strings as right argument.

∪⍛⍳⍨↑¨

Try it online!

↑ take the first s characters from…
 ¨ each string in w

∪⍛…⍨ in the list of the ∪nique strings in that…
 ⍳ find the ɩndex of the first occurrence of each string


Implement Euler's method The goal of this challenge is to use Euler's method to approximate the solution of a differential equation of the form f(n)(x) = c.†

The input will be a list of integers in which the nth value represents the value of f(n)(0). The first integer is f(0), the second is f'(0), and so on. The last integer in this list is the constant and will always remain the same.

Also provided as input will be a positive (nonzero) integer x, which represents the target value (you are trying to estimate f(x)). The step size for Euler's method will always be 1. Thus, you will need to take x steps total.

If you are unfamliar with Euler's method, here is a detailed example with an explanation for the input [4, -5, 3, -1], x = 8.

x       f(x)      f'(x)     f''(x)    f'''(x)
0          4         -5          3         -1
1   4-5 = -1  -5+3 = -2   3-1 =  2         -1
2  -1-2 = -3  -2+2 =  0   2-1 =  1         -1
3  -3+0 = -3   0+1 =  1   1-1 =  0         -1
4  -3+1 = -2   1+0 =  1   0-1 = -1         -1
5  -2+1 = -1   1-1 =  0  -1-1 = -2         -1
6  -1+0 = -1   0-2 = -2  -2-1 = -3         -1
7  -1-2 = -3  -2-3 = -5  -3-1 = -4         -1
8  -3-5 = -8

Essentially, each cell in the generated table is the sum of the cell above it and the cell above and to the right. So, f(a) = f(a-1) + f'(a-1); f'(a) = f'(a-1) + f''(a-1); and f''(a) = f''(a-1) + f'''(a-1). The final answer is f(8) ≈ -8.††

The input list will always contain 2 or more elements, all of which will have absolute values less than 10. x ≥ 1 is also guaranteed. The output is a single integer, the approximation of f(x). Input may be taken in either order (the list before x, or x before the list). x may also be the first or last element of the list, if desired.

Test cases:

[4, -5, 3, -1], x = 8 => -8
[1, 2, 3, 4, 5, 6], x = 10 => 3198
[1, 3, 3, 7], x = 20 => 8611
[-3, 3, -3, 3, -3, 3, -3, 3, -3], x = 15 => -9009
[1, 1], x = 1 => 2

†: it is notable that using an approximation method in this situation is, in fact, stupid. however, the simplest possible function was chosen for the purposes of this challenge.

††: the actual value happens to be -25⅓, which would qualify this approximation as "not very good."

Haskell, 38 bytes

l%n|n<1=l!!0|m<-n-1=l%m+tail(l++[0])%m

Try it online!

Improved from 39 bytes:

l%0=l!!0
l%n=l%(n-1)+tail(l++[0])%(n-1)

Recursively expresses the output l%n. Moving up corresponds to decrementing n, and moving right corresponds to taking tail l to shift all list elements one space left. So, the output l%n is the value above l%(n-1), plus the value above and to the right (tail l)%(n-1)

The base case n==0 is to take the first list element.

Ideally, the input would be padded with infinitely many zeroes to the right, since the derivatives of a polynomial eventually become zero. We simulate this by appending a 0 when we take the tail.

Weird alt 41:

(iterate(\q l->q l+q(tail l++[0]))head!!)


Military projection of a cube Challenge closed, the shortest answer has been acccepted.
A military projection is a projection where all lengths and the angles in the X-Z plane remain unattuned.
Your task is to print a cube in military projection using /, |, \, -, and any whitespaces you want, given any integer greater than zero as it's side length. You can leave sides out that are not visible to the human eye.
Here are some examples:
  /-\
 /   \
|\   /| Side length:
| \ / | 2
 \ | /
  \|/

     /-\
    /   \
   /     \
  /       \
 /         \
|\         /|
| \       / | Side length:
|  \     /  |
|   \   /   | 5
|    \ /    |
 \    |    /
  \   |   /
   \  |  /
    \ | /
     \|/

 /-\  Side length:
|\ /|
 \|/  1

(Printing the side lengths is not required.)
For the uppermost corner you must use the dash.
As you can see, all sides are equal in length (when measured in characters).
You may use any kind of spacing you wish, and omit any characters that don't change the appearance of the cube.
This is code-golf, so the shortest answer in bytes wins!

Charcoal, 19 bytes

Ｎθ←¹↙θ↓θ→↘θ↑↑θ←↖θ‖Ｂ

Try it online!


Finding the smallest sets Consider three sets A, B and C each containing n integers.  From this we can make the set

S_n = {a * b + c | a in A, b in B, c in C}.

Given an n, there are one or more minimal sized S_n which depend on which sets A,B and C have been chosen.

The sets can contain any n distinct integers (positive, zero or negative). There is no need for them to be consecutive integers or for the sets to be equal to each other for example.  A = {-1, 0, 5, 10, 27}, B = {2, 5, 6, 10, 14} and C = {-23, 2, 100, 1000,10000} is acceptable (although not a good idea) for example.

Task

The task is to write code to find the smallest set S_n it can for each n from 1 to 20.

For each n from 1 to 20 your code should output the chosen A, B and C along with the resulting size of S_n

Score

Your score will be  the sum of the sizes of the S_n you create.  That is it will be a sum of twenty numbers.

The lower the score the better.

Examples

If A = B = C = {1, 2, 3, 4} then S_4 =  {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} which is of size 19.

This is however in no way optimal. For example, A = B = C = {-1, 0, 1, 2} gives S_4 = {0, 1, 2, 3, 4, 5, 6, -1, -3, -2} which  is of size 10.

Timings

As I will need to run your code to verify the output, please make sure it takes no more than 30 minutes and 4GB of RAM to run on a normal desktop.

Notes

Your code must actually compute the output. You are not allowed to hardcode precomputed answers into your code.

Rust, score 1412 1411

src/main.rs

extern crate gmp;

use std::collections::BinaryHeap;
use std::collections::hash_map::{HashMap, Entry};
use gmp::mpz::Mpz;

fn visit(
    queue: &mut BinaryHeap<(i32, i32, i32, Mpz, Mpz)>,
    visited: &mut HashMap<(i32, Mpz), i32>,
    score: i32,
    h: i32,
    k: i32,
    d: Mpz,
    c: Mpz,
) {
    match visited.entry((k, d.clone())) {
        Entry::Occupied(mut e) => {
            if *e.get() < score {
                e.insert(score);
                queue.push((score, h, k, d, c));
            }
        }
        Entry::Vacant(e) => {
            e.insert(score);
            queue.push((score, h, k, d, c));
        }
    }
}

fn main() {
    let mut total = 0;
    for n in 1..21 {
        let a_range = n / 2 - n + 1..n / 2 + 1;
        let min_ab = a_range.start * (a_range.end - 1);
        let mut ab = Mpz::zero();
        for a in a_range.clone() {
            for b in a_range.clone() {
                ab.setbit((a * b - min_ab) as usize);
            }
        }

        let heuristic = |k: i32, d: &Mpz| if k == n {
            0
        } else {
            k + 1 - n -
                (0..d.bit_length())
                    .map(|i| (&ab & !(d >> i)).popcount())
                    .min()
                    .unwrap() as i32
        };

        let mut queue = BinaryHeap::new();
        let mut visited = HashMap::new();

        let (k1, d1) = (0, Mpz::zero());
        let h1 = heuristic(k1, &d1);
        visit(&mut queue, &mut visited, h1, h1, k1, d1, Mpz::zero());
        while let Some((score, h, k, d, c)) = queue.pop() {
            if k == n {
                println!("n={} |S|={}", n, -score);
                println!("  A={:?}", a_range.clone().collect::<Vec<_>>());
                println!("  B={:?}", a_range.clone().collect::<Vec<_>>());
                println!(
                    "  C={:?}",
                    (0..c.bit_length())
                        .filter(|&i| c.tstbit(c.bit_length() - 1 - i))
                        .collect::<Vec<_>>()
                );
                total += -score;
                break;
            }

            let kd = (k, d);
            if score < visited[&kd] {
                continue;
            }
            let (k, d) = kd;

            let (k1, d1) = (k, &d >> 1);
            let h1 = heuristic(k1, &d1);
            visit(
                &mut queue,
                &mut visited,
                score - h + h1,
                h1,
                k1,
                d1,
                &c << 1,
            );

            let (k1, d1) = (k + 1, (&d | &ab) >> 1);
            let h1 = heuristic(k1, &d1);
            visit(
                &mut queue,
                &mut visited,
                score - h - (&ab & !&d).popcount() as i32 + h1,
                h1,
                k1,
                d1,
                &c << 1 | Mpz::one(),
            );
        }
    }

    println!("total={}", total);
}

Cargo.toml

[package]
name = "small"
version = "0.1.0"
authors = ["Anders Kaseorg <andersk@mit.edu>"]

[dependencies]
rust-gmp = "0.5.0"

Compile and run with cargo run --release.

Output

n=1 |S|=1
  A=[0]
  B=[0]
  C=[0]
n=2 |S|=3
  A=[0, 1]
  B=[0, 1]
  C=[0, 1]
n=3 |S|=5
  A=[-1, 0, 1]
  B=[-1, 0, 1]
  C=[0, 1, 2]
n=4 |S|=10
  A=[-1, 0, 1, 2]
  B=[-1, 0, 1, 2]
  C=[0, 1, 2, 3]
n=5 |S|=13
  A=[-2, -1, 0, 1, 2]
  B=[-2, -1, 0, 1, 2]
  C=[0, 1, 2, 3, 4]
n=6 |S|=21
  A=[-2, -1, 0, 1, 2, 3]
  B=[-2, -1, 0, 1, 2, 3]
  C=[0, 2, 3, 4, 5, 6]
n=7 |S|=25
  A=[-3, -2, -1, 0, 1, 2, 3]
  B=[-3, -2, -1, 0, 1, 2, 3]
  C=[0, 2, 3, 5, 6, 7, 8]
n=8 |S|=35
  A=[-3, -2, -1, 0, 1, 2, 3, 4]
  B=[-3, -2, -1, 0, 1, 2, 3, 4]
  C=[0, 3, 4, 6, 7, 8, 10, 11]
n=9 |S|=39
  A=[-4, -3, -2, -1, 0, 1, 2, 3, 4]
  B=[-4, -3, -2, -1, 0, 1, 2, 3, 4]
  C=[0, 3, 4, 6, 7, 8, 10, 11, 14]
n=10 |S|=53
  A=[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  B=[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  C=[0, 1, 4, 5, 6, 9, 10, 11, 14, 15]
n=11 |S|=58
  A=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  B=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  C=[0, 1, 4, 5, 6, 9, 10, 11, 14, 15, 19]
n=12 |S|=74
  A=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  B=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  C=[0, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 21]
n=13 |S|=80
  A=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  B=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  C=[0, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 21, 22]
n=14 |S|=100
  A=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  B=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  C=[0, 1, 6, 7, 8, 12, 13, 14, 15, 19, 20, 21, 26, 27]
n=15 |S|=106
  A=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  B=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  C=[0, 5, 6, 7, 11, 12, 13, 14, 18, 19, 20, 21, 25, 26, 27]
n=16 |S|=128
  A=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  B=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  C=[0, 6, 7, 8, 13, 14, 15, 16, 20, 21, 22, 23, 28, 29, 30, 36]
n=17 |S|=135
  A=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  B=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  C=[0, 6, 7, 8, 13, 14, 15, 16, 20, 21, 22, 23, 28, 29, 30, 36, 44]
n=18 |S|=161
  A=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  B=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  C=[0, 7, 8, 9, 15, 16, 17, 18, 23, 24, 25, 26, 27, 32, 33, 34, 35, 41]
n=19 |S|=167
  A=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  B=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  C=[0, 7, 8, 9, 15, 16, 17, 18, 23, 24, 25, 26, 27, 32, 33, 34, 35, 41, 42]
n=20 |S|=197
  A=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  B=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  C=[0, 1, 8, 9, 10, 11, 17, 18, 19, 20, 21, 26, 27, 28, 29, 30, 36, 37, 38, 46]
total=1411

On my laptop, this used about 8 minutes and about 1.5 GiB of memory.

How it works

We assume (without any particular justification) that A and B are the obvious range of consecutive integers centered at 0 or ½, then do an A* search for an optimal C given A and B.


Square from Digits with Largest Sum You should write a program or function which receives a list of digits as input and outputs or returns the largest sum achievable by putting these digits in a square.

Input will always contain a square number of digits. An example square arrangement for the input 9 1 2 3 4 5 6 7 7 could be

677
943
125

The sum is calculated as the sum of all rows and columns. For the above arrangement the sum would be 677 + 943 + 125 + 691 + 742 + 735 = 3913. Note that this is not the maximal sum so this isn't the expected output.

Input

A list with length n^2 (n>=1) containing non-zero digits (1-9).

Output

An integer, the largest sum achievable with the input digits put in a square.

Examples

Example format is input => output.

5 => 10

1 2 3 4 => 137

5 8 6 8 => 324

9 1 2 3 4 5 6 7 7 => 4588

2 4 9 7 3 4 2 1 3 => 3823

8 2 9 4 8 1 9 3 4 6 3 8 1 5 7 1 => 68423

5 4 3 6 9 2 6 8 8 1 6 8 5 2 8 4 2 4 5 7 3 7 6 6 7 => 836445

This is code golf so the shortest entry wins.

Pyth, 15 bytes

s*VSsM^^LTUQ2SQ

Demonstration. Test harness.

Note: Input in any python sequence format, such as a,b,c, or [a, b, c]. Fails on a.

This will be an explanation for the example input 5,8,6,8.

^LTUQ: This is a list of powers of 10, out to the length of Q. [1, 10, 100, 1000].

^ ... 2: Then, we take pairs of powers of 10. [[1, 1], [1, 10], ....

sM: Then, we sum those pairs. [2, 11, 101, ... Each number repesents the value of a grid location. The value of the bottom right corner is 2, because the digit placed there is in the ones place of the two numbers it is in. Note that 16 values were generated, even though we only need 4. This will be handled shortly.

S: Sort the value in increasing order. [2, 11, 11, 20, 101, .... Note that the only values which are relevant for this input are the first 4, because this square will not have hundreds or thousands places.

SQ: Sort the input in ascending order. [5, 6, 8, 8]

*V: Vectorized multiplication over the two lists. Pyth's vectorized multiplication truncates the longer input, so this performs [5*2, 6*11, 8*11, 8*20], equivalent to filling in the grid, smallest to largest, bottom right to top left.

s: Sum the results, 324. Printing is implicit.


Get the best of two Arrays You will be given two arrays of floating-point numbers. Your task is to pair the corresponding elements of the two arrays, and get the maximum of each pair. However, if the two corresponding elements are equal, you must take their sum instead.
For example, given the lists [1, 3, 3.2, 2.3] and [3, 1, 3.2, 2.6], you must do the following:

Pair the elements (or zip): [[1, 3], [3, 1], [3.2, 3.2], [2.3, 2.6]].

Go through each pair and apply the process above: [3, 3, 6.4, 2.6].

Specs

The arrays / lists will always have equal length. They may however be empty.

The numbers they contain will always fit your language's capabilities, as long as you do not abuse that. They may be positive, zero or negative, you must handle all types.

If it helps you reduce your byte count, you may also take the length of the lists as input.

Rules

This is code-golf, so shortest answer in bytes wins.
Standard input and output rules apply. You may take input (and output) in any reasonable format.
Default Loopholes are forbidden.

Test Cases

Array_1, Array_2 -> Output

[], [] -> []
[1, 2, 3], [1, 3, 2] -> [2, 3, 3]
[1, 3, 3.2, 2.3], [3, 1, 3.2, 2.6] -> [3, 3, 6.4, 2.6]
[1,2,3,4,5,5,7,8,9,10], [10,9,8,7,6,5,4,3,2,1] -> [10, 9, 8, 7, 6, 10, 7, 8, 9, 10]
[-3.2, -3.2, -2.4, 7, -10.1], [100, -3.2, 2.4, -7, -10.1] -> [100, -6.4, 2.4, 7, -20.2]

Python 2, 45 bytes
A mix of my initial solution and @ovs'.

lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)

Try it online!
Python 2, 49 bytes

lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]

Try it online!
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.

lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]

Try it online!

How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's bool class being a subclass of int.