Turn a sentence into a dictionary For this challenge, you will be given a long string as an input. With this string, you must create a dictionary.
Details:
This dictionary will contain all the words from the string - a word being any sequence of letters surrounded by non-letter characters (ASCII). Letter case of the entries of the dictionary should always be consistent (i.e. all lower case or all upper case, or only the first letter of each word is capitalised). The dictionary can be a list, array, or any other type so long as the words are distinct from each other. Finally, as this is a dictionary, the words must be in alphabetical order, and there may not be any duplicates.
You can assume no contractions will be used (the input will never contain it's, there's, etc.), and that there will always be at least one word
Some examples:
"this is an eXaMpLe of an Input" -> ["an","example","input","is","of","this"]
"Here is another example of an input, this time with Punctuation!" -> ["an","another","example","here","input","is","of","punctuation","this","time","with"]
"290(&79832aAa(*& *79 --=BBBb)bbBb ( x )*d -cxaAa_" -> ["aaa","bbbb","cxaaa","d","x"]

Scoring
Shortest code wins

JavaScript (ES6),  57  51 bytes
Returns a Set of words in lower case.
NB: In JS, the elements of a Set are guaranteed to appear in insertion order. In this case, this  is the order defined in the sorted array the Set is built from.

s=>new Set(s.toLowerCase().match(/[a-z]+/g).sort())

Try it online!


Sum \$\text{Square}^2\$ Let \$n=42\$ (Input)

Then divisors are : 1, 2, 3, 6, 7, 14, 21, 42

Squaring each divisor : 1, 4, 9, 36, 49, 196, 441, 1764

Taking sum (adding) : 2500

Since \$50\times 50=2500\$ therefore we return a truthy value. If it is not a perfect square, return a falsy value.

Examples :

42  ---> true
1   ---> true
246 ---> true
10  ---> false
16  ---> false

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

Thanks to @Arnauld for pointing out the sequence : A046655

R, 39 37 bytes

!sum((y=1:(x=scan()))[!x%%y]^2)^.5%%1

Try it online!

Uses the classic "test if perfect square" approach, taking the non-integral part of the square root S^.5%%1 and taking the logical negation of it, as it maps zero (perfect square) to TRUE and nonzero to FALSE.

Thanks to Robert S for saving a couple of bytes!


Golf the Subset-Sum Problem Task
Given a list of space-delimited integers as input, output all unique non-empty subsets of these numbers that each subset sums to 0.

Test Case
Input:  8 −7 5 −3 −2
Output: -3 -2 5

Winning Criterion
This is code-golf, so the shortest code in bytes wins!

Brachylog (2), 9 characters

{⊇.+0∧}ᵘb

Try it online!

{⊇.+0∧}ᵘb
 ⊇           subset
   +0        that sums to 0
  .  ∧       output the subset
{     }ᵘ     take all unique solutions
        b    except the first (which is the empty solution)


Reduce the list to a final number Inputs

A list (array) of numbers, or numerical strings if that makes it easier. You can assume there will always be at least two elements in the list and every element will be a natural number (integer larger than zero).

Outputs

A single number, or again, a numerical string.

Problem

The idea is to reduce the list of numbers by removing the last digit of the largest number at that current stage of the list, eventually ending with one number (only one number should be returned, even if there are multiple instances)

Example

[123,343,121,76,465,786] -- The last digit in 786 is dropped, so it becomes 78
[123,343,121,76,465,78]  -- New largest number is 465, so the 5 is dropped, making it 46
[123,343,121,76,46,78]   -- Repeat until left with one number
[123,34,121,76,46,78]
[12,34,121,76,46,78]
[12,34,12,76,46,78]
[12,34,12,76,46,7]
[12,34,12,7,46,7]
[12,34,12,7,4,7]
[12,3,12,7,4,7]
[1,3,1,7,4,7]            -- If there are multiple max numbers, you **must** remove the last digit from all of them
[1,3,1,4]
[1,3,1]
[1,1]                    -- You have your answer when there is one number, or multiple numbers that are equal
1                        -- Result

Loopholes

Standard loopholes apply

Other constraints

Your program must work for any list of random numbers (within reason of course)

Test Cases

[24,72,4]
[24,7,4]
[2,7,4]
[2,4]
[2]
2

[14, 7]
[1, 7]
[1]
1

[1278,232,98273,2334]
[1278,232,9827,2334]
[1278,232,982,2334]
[1278,232,982,233]
[127,232,982,233]
[127,232,98,233]
[127,232,98,23]
[127,23,98,23]
[12,23,98,23]
[12,23,9,23]
[12,2,9,2]
[1,2,9,2]
[1,2,2]
[1]
1

Scoring

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

Haskell, 16 bytes

minimum.map head

Try it online!


Golfing every ASCII character in 99 99 is a programming language I invented earlier this week for my challenge Write an interpreter for 99. (Invented but never needed to implement thanks to half a dozen of you. ;) ) The full language spec is in that challenge so I'm not bothering to repost it all here.

In 99 you can print individual ASCII characters to stdout, but due to the constraints of the language, it is not always clear how to print a particular character as concisely as possible.

For each of the 128 ASCII characters, write a 99 program that takes no input and outputs that sole character. You may code any or all of these answers by hand, or you can write another program (in any language you like) to generate them for you.

The sum of the characters in each of your 128 99 programs is your score. The lowest score wins. Newlines count as one character.

Remember, in 99, only even sized variables like 9999 output ASCII characters (odd sized variables output integers). Their value is divided by 9 and then taken mod 128, so values do not need to be in a certain range to map to ASCII characters. For example, the internal values 297, 1449, and -855 all correspond to the character ! because when they are divided by 9 and taken mod 128, they all become 33, which is the character code for !.

If you need an interpreter for 99, I'd suggest Mac's Python answer.

I know I said my next challenge would be more interactive but I'm still working on the stuff for that one.

One assignment, 2075 (optimal)

This should be the optimal value (unless I have a big error in reasoning or my testing sucks).

First of all. There are only 7 different numbers (mod 128) you can express in 99. All values of 7 or more 9 evaluate to the same number 71. (Because 10^8 mod 128 == 0, 10^9 mod 128 == 0, ...)

If one of the 4 values you can express with an even number of nines, than outputting this number is clearly the optimal solution.

Otherwise I try to reach the number with one assignment statement (assign to 99) and print 99. As it turns out the maximal program size with this approach is 22 char. Clearly using Goto takes definitely more than that. The only possibility that a one-assignment solution might be beaten is a solution with two assignments. I tested this (hopefully with no errors, the code for this is quite messy), and found no solution for any ASCII char.

Therefore only checking the 4 direct numbers and the one-assignment approach should be enough to find the optimal solution. The following Python (2 and 3 compatible) program generates all programs and sums up their lengths. It uses a simple IDA* approach.

from itertools import count

def nines_to_dec(nines):
    return ((10**nines - 1) // 9) % 128

def shortest_representation(ascii_value):
    # try simple output,
    # max code length is 8, (8 nines == 10 nines == 12 nines == ...)
    # if this works, than this is the shortest representation

    for nines in range(2, 9, 2):
        if nines_to_dec(nines) == ascii_value:
            return "9" * nines

    # otherwise try one assignment
    for length in count(1):
        result = assignment(ascii_value, length, [])
        if result:
            return "99 " + result + "\n99"

def assignment(value, left, nines_list):
    if left == 0:
        eval_numbers = [nines_to_dec(nines) for nines in nines_list]

        if (sum(eval_numbers[::2]) - sum(eval_numbers[1::2])) % 128 == value:
            return " ".join("9" * nines for nines in nines_list)
        else:
            return False

    for nines in range(1, 8):
        left2 = left - nines - 1 # -1 for space
        if left2 >= 0:
            result = assignment(value, left2, nines_list + [nines])
            if result:
                return result

    return False

lengths = []
for i in range(128):
    program =shortest_representation(i)
    lengths.append(len(program))
    print("ASCII-value: {}, ASCII-char: {}".format(i, chr(i)))
    print(program)

print(sorted(lengths))
print(sum(lengths))

The output is of the following form:

....
ASCII-value: 65, ASCII-char: A
99 9 999999 9999999
99
ASCII-value: 66, ASCII-char: B
99 9 99 9999 99
99
ASCII-value: 67, ASCII-char: C
99 9 99 9 99 9999
99
....

You can find the complete output at: http://pastebin.com/bKXLAArq

The char with the shortest program (2 char) is vertical tab - 11 with a program length of 2, the chars with the longest programs (22 char) are bell - 7 and A - 65.

The sum for all programs is 2075.

And by the way, I used the k/q interpreter from tmartin. I hat quite some troubles with the other ones (Python, Perl, CJam). Not sure if it was my fault.


Find a Similar Number We consider two integers to be similar if, when written in decimal, have the same length, and if we compare characters in any two positions for both decimal strings, the comparison results (less, equal or greater) must be the same in both strings.

Formally, for two number that can be written as decimal strings \$a_1a_2\cdots a_n\$, \$b_1b_2\cdots b_m\$, they're similar if and only if \$n=m\$ and \$a_i<a_j\ \leftrightarrow b_i<b_j\$ (\$\leftrightarrow\$ means if and only if) for all \$ i,j \in [1,n]\$.

For example, 2131 and 8090 are similar. 1234 and 1111, 1234 and 4321 are not similar.

The challenge

For a given positive integer, find a different non-negative integer similar to it. You can assume at least one such integer exists.

Your implementation shouldn't be too inefficient. It must be at least able to pass the samples in around one hour on an average computer. (If it doesn't end in a few seconds, consider providing a screenshot running it)
Your code can take the input and output as integers, strings or lists of digits. Standard loopholes are forbidden.

Since this is a code-golf, the shortest code in bytes wins!

Examples

It's (quite) possible to have different outputs on these inputs as long as inputs and outputs are different and similar.

1 - 0
3 - 9
9 - 1
19 - 23
191 - 121
1111 - 2222 (0 is not considered valid)
2020 - 9393
2842 - 1321
97892 - 31230
113582 - 113452
444615491 - 666807690
87654321000 - 98765432111
98765432111 - 87654321000
526704219279 - 536714329379
99887766553210 - 88776655443210

Sample inputs as a list:

1,3,9,19,191,1111,2020,2842,97892,113582,444615491,87654321000,98765432111,526704219279,99887766553210

Python 3, 58 52 bytes

lambda n:[9-(9in n)-sum(x>d for x in{*n})for d in n]

Try it online!

Input: The number n, as a list of digits.
Output: A similar number, as a list of digits.

-6 bytes thanks to @xnor!

How:
Reverses the list of unique digits, then maps them to 9,8,7,... or 8,7,6,... depending on whether n contains the digit 9 or not.
For example:

               | n = 1827 | n = 7899
Reverse unique |   8721   |   987
Maps to        |   9876   |   876
Results        | m = 6978 | m = 6788

Old solution

Python 3, 80 bytes

f=lambda n,i=9:(i in n)^(i-1in n)and[[d,d^i^~-i][i-2<d<=i]for d in n]or f(n,i-1)

Try it online!

Input: The number n, as a list of digits.
Output: A similar number, as a list of digits.

-1 byte thanks to @KevinCruijssen!

How
The solution tries to find a pair of consecutive digits \$(i-1,i)\$ such that one digit appears in \$n\$, and the other doesn't. It then replaces all occurrences of one digit with the other.
The pair of digits are searched from \$(8,9)\$ downward, in order to discourage replacing 1 with 0.


The first, the last, and everything between Given two integers, output the two integers, and then the range between them (excluding both).
The order of the range must be the same as the input.
Examples:
 Input        Output
 0,  5   ->   [0, 5, 1, 2, 3, 4]
-3,  8   ->   [-3, 8, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
 4,  4   ->   [4, 4]
 4,  5   ->   [4, 5]
 8,  2   ->   [8, 2, 7, 6, 5, 4, 3]
-2, -7   ->   [-2, -7, -3, -4, -5, -6]

R, 39 33 30 bytes

c(a<-scan(),setdiff(a:a[2],a))

Try it online!

Thanks for saved bytes to user2390246 and J.Doe.


Is it zero- or one- indexed? Your task is to determine whether some arbitrary programming language has zero-indexed or one-indexed arrays based on sample inputs and outputs
Inputs

An array of integers with at least 2 elements
A positive integer index
The value of the array at that index

Output
One of four distinct values representing:

One-indexed if the language unambiguously has one-indexed arrays
Zero-indexed if the language unambiguously has zero-indexed arrays
Unknown if the given inputs aren't enough to determine whether the language is zero- or one- indexed because it is ambiguous.
Neither  if the language is not zero- or one-indexed because it is something else that may or may not make any sense.

Example Test Cases
Formatted as [array, elements][index] == value_at_index  =>  output
[2, 3][1] == 2  ==>  one-indexed
[2, 3][1] == 3  ==>  zero-indexed
[1, 2, 2, 3][2] == 2  ==>  unknown
[4, 5][1] == 17  ==>  neither
[-3, 5, 2][2] == 5  ==>  one-indexed
[-744, 1337, 420, -69][3] == -69  ==>  zero-indexed
[-744, 1337, 420, -69][3] == 420  ==>  one-indexed
[-744, 1337, 420, -69][3] == -744  ==>  neither
[42, 42, 42, 42, 42][2] == 42  ==>  unknown
[42, 42, 42, 42, 42][1] == 56  ==>  neither

Rules and Scoring

Use any convenient I/O methods
Use any convenient representation for each of the four distinct categories as long as it is consistent and each possible category is mapped to exactly one value.
You may assume that all array values are between \$-2^{31}\$ and \$2^{31} - 1\$, inclusive (i.e. the signed int32 range.)
You may assume that arrays are no longer than \$65535\$ elements.
You may assume that the index is in-bounds for both zero- and one-indexed semantics.

Shortest code wins. Happy golfing!

convey, 47 bytes
Returns 0 for neither, 1 for one-based, 2 for zero-based and 3 for unknown.
{2+~`0
?;\2:!2[
v^<]`
?;\?+2
v^< v*+}
!>>>=?^
2

Try it online!
Run for 1 2 2 3 with index 2 and value 2:

On the left we split the input lines with ;\ ^< into the three paths.
The first one pushes two zeroes after length of path + index time steps into the +. The second one path tries to push the array into + – if there are values waiting (the two zeroes), they get passed through unaltered. Otherwise, they get deleted ?]. The two values then get pushed into =, where they are compared to the third input. The result are two boolean bits. The second one gets multiplied by 2, then they get added together.


Redirect HTTP links to HTTPS with Javascript What is the shortest way to secure a site with Javascript?
I am new to Code Golfing, and this is what I've come up with so far. I bet that this could be improved though:
Challenge:

Make a script which redirects http:// to https:// with the least bytes of code

Attempts:
Original code (150ish BYTES!):
if (window.location.protocol != "https:") {
  window.location.href =
    "https:" + window.location.href.substring(window.location.protocol.length);
}

My code so far (68 bytes):
var l=location;':'==l.protocol[4]&&(l.href=l.href.replace(':','s:'))

Updated, thanks to @mypronounismonicareinstate (52 bytes):
l=location;l["protocol"][5]||(l["protocol"]="https")

Thanks to @arnauld (45 bytes):
(l=location)[p='protocol'][5]||(l[p]='https')

This works, thanks to @anderskaseorg (38 bytes):
with(location)protocol='https'+href[4]

However, this last answer would not be commonly used on a real site
Could this be minified more?

39 38 bytes

with(location)protocol='https'+href[4]

How it works

If location.href starts with http:, this assigns location.protocol = 'https:'.
If location.href starts with https:, this assigns location.protocol = 'httpss'.  According to the specification, this should have no effect because httpss is neither http nor https.  Firefox obeys this specification.  Chrome seems to try to find an external app to open the httpss scheme (bug).


Find the longest musical substring A musical string is any string that can be played on a piano keyboard.
For those of us who weren't forced to learn the piano as kids, here is what the keyboard looks like.

So the string feed a dead cabbage is a musical string because every single letter corresponds to one of these nots.
Your challenge is to write a program that takes a string as input from STDIN, and finds the longest musical substring. Then your program must print the substring, and it's length. Here are some sample inputs/outputs.

Input: "FEED ME! I'm hungry!"
Output: feed 4

Input: No no no, no musistrin!
Ouput: 0

Input: "A **bad** !!!fAd82342"
Output: abadfad 7

Input: "Good golfing!"
Output: dg 2

Rules

Your output may be upper or lower-case, but there must be no punctuation or spaces.

There will capitalization and punctuation in the input string, but this doesn't affect whether or not a substring is considered "musical" or not.

There must be a space between the musical substring, and the number.

Pyth, 25 23 bytes

pdJef!-T<G7+k.:@Grz0)lJ

2 bytes saved thanks to @Jakube.

Demonstration. Test harness.

Explanation:

rz0: The input, in lowercase.
@Grz0: Strip any non-alphabetic characters.
.:@Grz0): Generate all substrings.
+k.:@Grz0): Add in the empty string.
f ... +k.:@Grz0): Filter over these strings.
-T<G7: Filter each string for non musical characters.
!-T<G7: Negate the result. This is True if and only if the string was musical.
f!-T<G7+k.:@Grz0): Filter out the musical strings.
ef!-T<G7+k.:@Grz0): Take the last such string. .: orders substrings by size, so this is also the longest musical substring.
Jef!-T<G7+k.:@Grz0): Assign the result to J.
pdJ: Print J, with d, space, as the ending character.
lJ: Then, print the length of J.


2016 Time Capsule String: Coverage Consider the 74 characters from the 2016 time capsule string (note the leading space):

 !!!!!#$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````eefmpxy{||||~~~~~~~~~

Your task is to write as many programs as possible (in the same language) using these characters. The output of each program must be nonempty. When all of the programs and their outputs are considered, it must only use each of the 74 above characters no more than once.

Your score is determined by the number of programs you have written, with the total length of the programs being a tie-breaker (greatest length wins).

Some more rules:

Each program must terminate.
Each program must be a full program and output in a reasonable format.
All output to STDERR is ignored.
You may not run your program with any flags, except those required to run the program. (E.g., a -e flag that executes program source.)
If the program has output that cannot be suppressed, you may ignore when considering the output. (E.g., you may ignore trailing newlines.)
Each program should be able to be executed with empty stdin.

Example

If I had programs 4 and T1~ that outputted 4 and 9 respectively, they would, when considered together, be:

44T1~9

Which can be seen to be a subset of the capsule string. However, if I had programs 4@|4 and |e+ that outputted 4 and f respectively, they would be:

4@|44|e+f

And, since there are 3 4s, it is not a subset.

Japt, 11 13 programs, length 61

\x:#).&~L // outputs 9  (41 & ~100)
~T+~Tf)p  // outputs 4  ((~0 + ~floor(0)) ** 2)
$~Q$ *\~Z // outputs 1  (~'"' * ~0)
I%A^O||@{=!(Hmy))  // outputs 4  (64 % 10 ^ {} || function(X,Y,Z) { return function() { return ((U = !(H.m("y")))) } })
`!        // outputs !
`!        // outputs !
`.        // outputs .
`@        // outputs @
`Q        // outputs Q
`e        // outputs e
`|        // outputs |
`~        // outputs ~
`~        // outputs ~

It's awfully hard to come up with an answer that isn't just a string literal and outputs something other than a number...

Output and programs combined:

 !!!!!#$$%&())))*+...1449:=@@@AHILOQQQTTZ\\^`````````eefmpxy{||||~~~~~~~~~

I think I got 'em all...

When stripped down to the bare minimum:

#)&~L
~T+~T)p
~Q*~Z
I%A
`!
`!
`.
`@
`Q
`e
`|
`~
`~

It leaves these chars for future programs/outputs:

 !$$()).:=@HO\\^fmxy{||

You can trade two of $, ), or | for two of any of the chars in the nine string literals; that is, two of any of !.@Qe|~.

Additionally, you can trade out the Q in the third program for H or O, and the Z for H, O, @, or {.


Partial Sum of Harmonic Sequence! Definition

In Mathematics, Harmonic Sequence refers to a sequence where
$$a_n = \frac 1 n$$
i.e. the \$n_{th}\$ term of the sequence equals the reciprocal of \$n\$.

Introduction
In this challenge, given a positive integer \$n\$ as input, output the Partial Sum of first \$n\$ terms of the Harmonic Sequence.

Input
You'll be given a positive integer (within the range of numbers supported by your language). It can be either of Signed and Unsigned (depends on you), since the challenge requires only positive integers.
You can take the input in any way except assuming it to be present in a predefined variable. Reading from file, terminal, modal window (prompt() in JavaScript) etc. is allowed. Taking the input as function argument is allowed as well.

Output
Your program should output the sum of the first \$n\$ terms of the Harmonic Sequence as a float (or integer if the output is evenly divisible by 1) with precision of 5 significant figures, where \$n\$ refers to the input. To convey the same in Mathematical jargon, you need to compute
$$\sum_{i=1}^n \frac 1 i$$
where \$n\$ refers to the input.
You can output in any way except writing the output to a variable. Writing to screen, terminal, file, modal window (alert() in JavaScript) etc. is allowed. Outputting as function return value is allowed as well.

Additional Rules

The input number can be either of 0-indexed or 1-indexed. You must specify that in your post.

You must not use a built-in to calculate the partial sum of the first \$n\$ elements. (Yeah, it's for you Mathematica!)

You must not abuse native number types to trivialize the problem.

Standard Loopholes apply.

Test Cases
The Test Cases assume the input to be 1-indexed
Input     Output
1         1
2         1.5
3         1.8333
4         2.0833
5         2.2833

Winning Criterion
This is code-golf, so the shortest code in bytes wins!

Python 3, 27 bytes

h=lambda n:n and 1/n+h(n-1)


Simple "hyena" program Write a program that takes a string as an input. For the input:

If the input doesn't match the source code, the program shall output the input intact. (Hence a cat)

Otherwise, the program shall fall in an infinite loop. (So actually not a cat)

Ruby -0p, 38 37 32 bytes
Saved 5 bytes thanks to a comment by @Sisyphus on another answer.

eval s="1until$_!='eval s=%p'%s"

Try it online!
The -0 flag sets the null byte as the input record separator. Without -0, a loop would also be entered if the input consisted of the code repeated on more than one line.


Check if an array (or equivalent) has the same number of odd and even numbers - Code Golf Edition! Inspired by this code review question, I am curious to see what happens if we turn that into a code-golf challenge!

The description is easy, the input is an array or any similar data structure with only unsigned integers, the output is a boolean if the number of odd numbers is equal to the number of even numbers inside (true or false doesn't matter, as long as the opposite is used in case the number doesn't match)

Here are some examples with true as output for matching (thanks to the original OP)

[5, 1, 0, 2]      ->  true
[5, 1, 0, 2, 11]  ->  false
[]                ->  true

Usual code-golf rules, shortest code wins.

Haskell, 20 bytes

(==0).sum.map((-1)^)

Try it online!


Logic Gates Manually Make a program that simulates the basic logic gates.

Input: An all-caps word followed by 2 1 digit binary numbers, separated by spaces, such as OR 1 0.  The gates OR, AND, NOR, NAND, XOR, and XNOR are needed.

Output: What the output of the entered logic gate would be given the two numbers: either 1 or 0.

Examples:
AND 1 0 becomes 0
XOR 0 1 becomes 1
OR 1 1 becomes 1
NAND 1 1 becomes 0

This is codegolf, so the shortest code wins.

Python 2, 38 bytes

lambda s:sum(map(ord,s))*3%61%37%9%7%2

Try it online!

A good ol' modulo chain applied to the sum of ASCII values of the input string, making for a solution that's just overfitting. The total ASCII value is distinct for each possible input, except that those with 0 1 and 1 0 give the same result, which is works out because all the logic gates used are symmetric.

The *3 separates out otherwise-adjacent values for inputs that different only in the bits, since these make it hard for the mod chain to split up. The length and size of numbers in the mod chain creates roughly the right amount of entropy to fit 18 binary outputs.

A shorter solution is surely possible using hash(s) or id(s), but I avoided these because they are system-dependent.

Python 2, 50 bytes

lambda s:'_AX0NRD'.find((s*9)[35])>>s.count('0')&1

Try it online!

A slightly more principled solution. Each logic gate gives a different result for each count of zeroes in the input, encodable as a three-bit number from 1 to 6. Each possible logic gate is mapped to the corresponding number by taking (s*9)[35], which are all distinct. For OR, this winds up reading one of the bits so the character could be 0 or 1, but it turns out to work to check if it's 0, and a 1 will correctly give a 1 result anyway.


Dennis, Doorknob, Martin Büttner, Chris Jester-Young - Pizzeria! Programming Puzzles & Code Golf is about to get a new moderator, Dennis! This challenge is a tribute to him and our other active (or recently active) moderators: Doorknob, Martin Büttner, and Chris Jester-Young. The challenge title is meant to be read to the tune of the Pepto Bismol song.
Basically, we're going to treat them all to pizza at The Nineteenth Bite Pizzeria, but we need to make sure they share it fairly because some of the mods are known to be pizza addicts!
The pizzas sold by the pizzeria are all rectangular blocks of text. The width and length of a pizza may be any non-negative integers as long as their product is divisible by four. Each grid space in the block of text pizza represents a slice, so it's always possible to split the slices up into four equal groups.
The mods will collectively order a single pizza, providing its width and length parameters to their server in any reasonable format such as [width],[length]. Just before the pizza arrives at their table, you need to label each slice with the initial of the mod who gets to eat it to ensure they all share fairly. Everyone should get the same number of slices.

E is for Dennis
D is for Doorknob
M is for Martin
C is for Chris

The mods are a little persnickety, however, and require that their respective sets of slices be path-connected, that is, that all their slices can be reached from one another by moving up, down, left, and right, not crossing anyone else's slices (and not moving diagonal). The don't care how you do this as long as it is done.
Once you've accurately labeled each slice, deliver the pizza to the mods with an optional trailing newline.
Your labeler may be a program or a function and can print or return the labeled pizza. The shortest labeler in bites wins.
Examples
Example 1
Order: 4,1
Some Possible Labeled Pizzas:
EDMC
MEDC
CDEM
Example 2
Order: 4,4
Some Possible Labeled Pizzas:
MMMM
CCCC
DDDD
EEEE
DEMC
DEMC
DEMC
DEMC
CCCC
DEEM
DEEM
DDMM
Example 3
Order: 8,3
Some Possible Labeled Pizzas:
MMMMMMCC
DDDDCCCC
DDEEEEEE
DDDCMMMM
DCDCMEEE
DCCCMEEE
Example 4
Order: 20,5
A Possible Labeled Pizza:
DDDDDDDDDDDDMCCCCCCCCCCC
DEEEEEEEEEEDMMMMMMMCCCCC
DEEEEEEEEEEDMMMCCCCCCCCC
DEEEEEEEEEEDMMMMMMMMCCCC
DDDDDDDDDDDDMMMMMMMMMMMC
(The D's here are not simply-connected but that's ok.)

CJam, 20 bytes

q~1$*4/"CEDM"e*/:$N*

I think this should work :)

Try it online

Explanation:

This first makes a pizza labeled CC…EE…DD…MM… from left to right and top to bottom, then sorts each row in alphabetical order. The only disconnections can happen between the C-E border and E-D border, or E-D border and D-M border (if they fall on adjacent rows). But the sorting ensures that the E's go to the right side and the D's go to the left side, as C<E>D<M, so the E's and the D's remain connected.

q~          read and evaluate the input
1$          copy the width
*4/         multiply with the height and divide by 4
"CEDM"e*    repeat each letter in "CEDM" that many times
/           split into rows of the given width
:$          sort each row
N*          join with newlines


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

Please post one tip per answer.

Use a=b=c=0 instead of a,b,c=0,0,0.

Use a,b,c='123' instead of a,b,c='1','2','3'.


Count stacking sequences Given a list of stack heights, calculate the number of ways those heights could have been arrived at by stacking blocks one at a time. Shortest code wins.

Test cases:

[2, 2] 6
[3,3,3] 1680
[1,5,9,1] 480480
[] 1
[10] 1
[2,2,2,10] 720720

Reference Python implementation:

def stacking_count(stacks):
     if sum(stacks) == 0:
         return 1
     count = 0
     for i, n in enumerate(stacks):
         if n == 0:
             continue
         stacks[i] -= 1
         count += stacking_count(stacks)
         stacks[i] += 1
     return count

Python 3, 85 bytes

f=lambda a:sum(f(a[:i]+[a[i]-1]+a[i+1:])for i in range(len(a))if a[i])if sum(a)else 1

Try it online!


Shortest code to produce infinite non-periodic output Not a dupe to this. That question asks specifically for counting up forever, while this question allows many other approaches.

Write a program or function which, given infinite time and memory, would print an infinite non-periodic output.

Clarifications

'Infinite' means the solution keeps outputting something without any further inputs or operations after successfully started the program or function.
'Non-periodic' means the output has no possibility of eventually repeating the same section forever (regardless of how long that period is). An example of a valid solution would be printing the digits of an irrational number.
Random solutions would not count unless you can prove that it fits the requirements. Date/time-based solutions may also be invalid if they are not stored with arbitrary precision.

Winner

Shortest code (in bytes) wins.

Python 2, 23 bytes

while 1:print id;id=id,

Try it online!

Prints

<built-in function id>
(<built-in function id>,)
((<built-in function id>,),)
(((<built-in function id>,),),)
((((<built-in function id>,),),),)

and so on. Starts with the built-in function id, the shortest pre-initialized variable name, and repeatedly turns it into a tuple of itself.

In Python 3, this solution is one byte longer because of print(), but the byte can be recovered from print outputting None:

while 1:id=print(id),id

or

while[print(id)]:id=id,


Integer Linear Programming Introduction
Write a solver for integer linear programming.
Challenge
Your task is write a solver for integer linear programming (ILP). In ILP, linear inequalities of a set of unknowns (all of which are integers) are given, and the goal is to find the minimum or maximum of a linear function.
For example, for the inequalities (example taken from Mixed Integer Linear Programming)
 4x+2y-15≤0
  x+2y- 8≤0
  x+ y- 5≤0
- x      ≤0
   - y   ≤0

and the objective function 3x+2y, the maximum of the objective function should be 12 (x=2,y=3), while the minimum should be 0 (x=y=0).
The input is given as an 2d array (or any equivalent following the standard specifications), each row corresponds to one inequality, with the exception of the final row. The numbers in the array are the coefficients, and the ≤0 part is always omitted. If there are n elements in each row, it means there are n-1 unknowns.
The last row of the array correspond to the linear function. The coefficients are listed.
For example, the input array for the problem above is
[[4,2,-15],[1,2,-8],[1,1,-5],[-1,0,0],[0,-1,0],[3,2,0]].

The output should be the minimum and the maximum, given in any reasonable form.
For the following problem (two of the restrictions are taken away from the problem above):
[[4,2,-15],[1,2,-8],[1,1,-5],[3,2,0]].

The maximum is still 12, but the minimum does not exist and the objective function can have arbitrarily large (in the sense of absolute value) negative values. In this case, the program should output 12, following a falsy value that is decided by the answerer. Another case is that there are no solution at all, for example,
[[4,2,-15],[-1,-2,7],[-1,0,3],[0,1,0],[3,2,0]].

In this case, falsy values should be output as well. It would be nice to discern the case where the "optimal value" for the objective function is infinity and the case where there are no solutions at all, but this is not necessary.
The input only contains integer coefficients both for the inequalities and for the objective function. All the unknowns are also integers. The coefficient matrix of the inequalities is guaranteed to have full rank.
Test Cases
Credit to @KirillL. for finding a bug in the original test suite and deepening my understanding of ILP problems.
Input
Output

[[4,2,-15],[1,2,-8],[1,1,-5],[-1,0,0],[0,-1,0],[3,2,1]]
[1,13]

[[4,2,-15],[1,2,-8],[1,1,-5],[3,2,0]]
[-inf, 12]

[[4,2,-15],[-1,-2,7],[-1,0,3],[0,1,0],[3,2,0]]
[NaN, NaN]

[[-1,-1,-1,-1,-1,8],[1,1,1,1,0,0],[5,5,5,5,6,7]]
[55, inf]

[[-1,-1,-1,-1,-1,8],[1,1,1,1,0,0],[0,0,0,0,0,4]]
[4, 4]

[[4,2,-15],[-1,-2,7],[-1,0,3],[0,1,0],[0,0,4]]
[NaN, NaN]

Specs

No need to worry about exception handling.

This is code-golf, the lowest number of bytes wins.

Maximal number of unknowns: 9. Maximal number of inequalities: 12.

You can take input and provide output through any standard form, and you are free to choose the format.

As usual, default loopholes apply here.

Python 3, 534 bytes

import itertools as t
import operator as o
I=float("inf")
e=lambda p,A:sum([i[0]*i[1]for i in zip(p,A[:-1])])+A[-1]
def w(x,j):
	d=len(x[0])-1;C=[0]*d;v,w=I,I
	while 1:
		L={(*n,):(sum([0 if e(n,A)<=0 else e(n,A)for A in x[:-1]]),j*e(n,x[-1]))for n in [[sum(a) for a in zip(C,c)]for c in t.product(*[[-1,0,1]]*d)]};C,P=min(L.items(),key=o.itemgetter(1))[0],C;v,w,p,q=L[C][0],L[C][1],v,w
		if(all([e(C,A)<=e(P,A)for A in x[:-1]]))*(j*(e(C,x[-1])-e(P,x[-1]))<0)+(p==v>0):return I
		if(p==v)*(q<=w):return j*q
f=lambda x:(w(x,1),w(x,-1))

Try it online!

Overview

It is an iterative algorithm, starting from the origo. It collects the neighbour positions and assigns a potential function: x:(a,b) where x is the position, a is the sum of the position's distances from the half-spaces of each linear inequality, b is the value of the objective at that position.

x:(a,b) < y:(c,d) iff a<c or a=c and b<d

The iteration stops, when:

the first coordinate of the potential hasn't decreased and positive: the system is infeasible
the distance from every half-space has decreased just like the objective: the system is unbounded.
none of previous and the potential hasn't decreased: it is the optimal value.


Day of Week - Natural language processing and date parsing You'll get a human-readable question matching one of the following syntaxes, and are expected to print/return the corresponding result. Finding similarities between the human-readable inputs and matching them with minimum size code is explicitly part of the task, so I won't give a formal definition.

"Will October begin on a Thursday if this year is a leap year, this month is January and this month begins on a Wednesday?" > "Yes."
"If this month begins on a Friday, this month is October and this year is not a leap year, will December start on a Tuesday?" > "No, it will be a Wednesday."
"If this month is August, this month begins on a Wednesday and this year is not a leap year, will October start on a Sunday?" > "No, it will be a Monday."
"Will December start on a Monday if this month begins on a Friday, this year is a leap year and this month is November?" > "No, it will be a Sunday."

"Formal" definition:
Input will always be generated by picking one of the above lines and swapping day names, month names, and the "not " in and out of "is *a leap year"
Further notes:

Each question will consider only one calendar year, i.e. you won't be asked for a date of the following or previous calendar year.
This is codegolf, shortest answer in bytes in each language wins.
In case you need it, remember leaps years are not strictly every 4 years.
No answer will be accepted.
Standard loopholes apply.
You can input and output in any reasonable way.

Just for reference:

'January', 'February','March','April', 'May','June','July','August', 'September','October','November','December'
'Monday','Tuesday', 'Wednesday','Thursday', 'Friday','Saturday', 'Sunday'

Inspired by Squarish's Kata on codewars.com

JavaScript (ES6), 254 bytes

s=>(F=e=>'0x'+'0A39135?2B?8602467'[parseInt(s.match(e+' ([A-Z]\\w+)')[1],33)%234%81%19],n=(F`s.{5}`-(g=m=>new Date(~F`(no|le).*`,m).getDay())(F`s`)+g(F`l`)+7)%7)-F` .{9}a`?`No, it will be a ${'Sun,Mon,Tues,Wednes,Thurs,Fri,Satur'.split`,`[n]}day.`:`Yes.`

Try it online!
How?
Given the leading part e of a regular expression, the helper function F looks for the capitalized word that immediately follows and turns it into either a 0-indexed day (from 0 = Sunday to 6 = Saturday) or a 0-indexed month (from 0 = January to 11 = December).
F = e =>                // e = regular expression part, as a string
  '0x' +                // parse as hexadecimal
  '0A39135?2B?8602467'[ // a digit between '0' and 'B'
    parseInt(           //   selected by 1) parsing
      s.match(          //     the sub-string in s that matches
        e +             //       the leading part of the regular expression
        ' ' +           //       followed by a space
        '([A-Z]\\w+)'   //       followed by a capturing group for
      )[1],             //       a capitalized word (which is what we keep)
      33                //     in base 33
    )                   //   end of parseInt()
    % 234 % 81 % 19     //   and 2) applying a modulo chain
  ]                     // end of digit lookup

Try the hash function online!
We invoke F with:

"s.{5}" to match "begins on a [day]"
"s" to match "is [month]"
"l" to match "will [month]" (the w may also be capitalized)
" .{9}a" to match either " start on a [day]" or " begin on a [day]"
"(no|le).*" to match either "not" or "leap", whichever comes first (this is a special case where the capitalized word is put in a 2nd capturing group and ignored)

The helper function g takes a month and returns a week day in [0..6]:
g = m => new Date(~F`(no|le).*`, m).getDay()

The expression ~F`(no|le).*` in there evaluates to -1 if "no" is matched (not leap) or to -4 if "le" is matched (leap). This works as expected because the year -4 is leap1 and the year -1 is not.
Using g and the data collected above, we create two dates in the same reference year and look for the difference between the corresponding week days, modulo 7. This allows us to answer the question.

1: At least that's what JS thinks. But this is apparently not true.


Check if number is a sum of consecutive numbers or not Write a program that checks if a given positive integer can be represented as sum of two or more consecutive positive integers.
Example:
43 can be represented as 21 + 22
10 = 1+2+3+4
but 4 cannot be represented in this way.
Input spec:  positive integer (as argument or stdin)
Output spec: truthy or falsy
Sample i/o
43 -> true
4 -> false

Shortest code wins.

JavaScript (31)

alert(!!((n=~~prompt())&(n-1)))

From my testing, I believe this gives correct solutions.

http://jsfiddle.net/3e9FZ/

Edit: (SPOILER ALERT!) Here is the justification for this answer:

All odd numbers greater than 1 can be trivially written as the sum of two consecutive numbers (ex 15 = 7+8, 23=11+12, etc.).
For even numbers having an odd factor where the odd factor is less than twice the even factor.  For example, 4*7, because 7 < (2*4 = 8).  Simply add 7 numbers with 4 at the center, 1+2+3+4+5+6+7.
For even numbers having an odd factor where the odd factor is more than twice the even factor.  For example, 4*9, because 9 > (2 * 4 = 8).  Double the even factor, and halve the odd factor to get 8*4.5.  You will add the 8 numbers centered at 4.5, i.e., 1+2+3+4+5+6+7+8.
The only numbers left are the even numbers having no odd factor, i.e., the powers of two.  The formula for the sum of a consecutive set of numbers is (avg * count).  Now if the count is odd, then avg is a whole number, and (avg * count) has an odd factor.  If count is even, then avg must be #.5, and thus avg * 2 is odd, and so avg * count has an odd factor.  Therefore, any sum using the formula (avg * count) must have an odd factor, which powers of two do not, and therefore have no solution.


Make a longer lenguage program Lenguage is a brainfuck dialect that is notorious for breaking source restriction challenges.  That is because Lenguage cares only about the length of it's source and not the contents.

First, the length of the program is calculated. Then, said length is converted to binary and left-padded by zeroes to a multiple of 3. The resulting binary string is split into chunks of 3 bits each of which is translated into a brainfuck command as such:

000 -> +
001 -> -
010 -> >
011 -> <
100 -> .
101 -> ,
110 -> [
111 -> ]

Finally the program is run as brainfuck1.

From here the challenge is pretty simple, write a lenguage program that takes no input and produces an output consisting of one byte repeated integer \$n\$ times, where \$n\$ is strictly greater than the length of your program.

Answers will be scored in bytes with fewer bytes being better.

Here's a hacky program to calculate lenguage from brainfuck

1: For this challenge we will use wrapping cells and a non-wrapping tape.

8437495638205698686671 bytes

This translates to the brainfuck program:

-[>>[>]+[->[>]+.[<]+<]<-]

Which prints exactly \$231584178474632390847141970017375815706539969331281128078915168015826259279614\$ SOH bytes.

This is calculated by the function

f(n)=2*f(n-1)+n
f(0)=0

with an input of 255.

Explanation:

-[         Loop 255 times
  >>[>]    Move to the end of a series of positive cells (initially empty)
  +        Add one cell to the end
  [-       Loop over each cell
    >[>]+  Add one cell to the end
    .      Print a SOH byte
    [<]+   Restore current cell
  <]       Move to next cell
<-]        Decrement counter


Selective character count (only non-alphanumeric)? Challenge (Easy)

  Write a function which takes an argument and returns the number of non-alphanumeric characters found.

Challenge (Hard)

  Write a function which takes an argument and returns the number of bytes used to store the number of non-alphanumeric characters found.  (ie: include calculation for multi-byte characters.)

Rules / Notes

Alphanumeric in this case is defined as:

abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
A null character should count as 0 characters, but as 1 byte when stored.

NUL
Showing multi-byte support (if too complicated) only has to demonstrate one character set or language reference / codepage (if this actually matters.  I don't know, so just putting it out there.)

Winner

Since this is code golf, the shortest code that correctly matches the challege wins.


How could Stringy be improved? I created a programming language for manipulating strings called Stringy. It's very different from other programming languages, since you only have one string (for manipulation) and some variables. With the various commands you can manipulate that one string. I created it because it might be useful for some challenges here. (challenged tagged string)

What could I add to this to make it better/more useful for challenges here?

Examples for the language can be found at GitHub at examples.txt. It might be a bit hard to understand though.

OK, I said I'd put my comments into a more comprehensible form so here they are.

Don't separate commands. Having to use ; every time you want to use a different command is costly. My recommendation on the interpreter side is to parse one character at a time and read more if the command necessitates it.
Add regex (to be honest, I don't know much regex -- it's somewhere on my list of things to learn -- but it seems logical to add it)
On the topic of not separating commands with ;, allow for whitespace to be removeable.
Add loops of some sort.
Add conditionals and conditional tests (equals, not, and, or, etc.)
Add a newline reserved character (n, perhaps?)
Add reserved characters for variables
You have uppercase and lowercase commands, why not add a capitalization one (one that capitalizes the string as if it were a sentence and maybe also capitalizes proper nouns that it can identify).
Add a command to count how many instances of a string are in another.
Add a length command to get the length of a string.
Add a terminate/break command.
Add an equivalent of Python's ord and chr functions.
Add a split at numerical value command (splits at a certain length), and add an alternative to that which splits at every multiple of the numerical value (e.g. for a string of length 10 at 3,6,9 if given the argument 3).
Add a duplication command (akin to Python's "String"*x)

You'll notice that some of these involve numbers -- I think that even for String challenges having a way of working with numbers is good. Perhaps have a stack for storing numbers that is accessed when certain commands are used (e.g. the length command pushes the length onto the number stack and then the split at numerical value uses this length to split the stack).

I'll add more ideas as I think of them, but I feel like my suggestions are pushing this in the direction of a more general-purpose golf language. Hopefully this input helps regardless of whether you use it or not.


Filter an array so that duplicate items are removed In the shortest amount of code in any programming language, filter out the duplicate items in an array of which the order is irrelevant.

Here are some test cases:

[1, 2, 2, 3, 1, 2, 4] => [1, 2, 3, 4]
['a', 'a', 'b', 'a', 'c', 'a', 'd'] => ['a', 'b', 'c', 'd']

  I also should note that there currently aren't any open questions that meet these exact criteria.

1-byte built-ins
05AB1E (legacy)
Ù

Try it online!
Alternatively:
ê

Try it online!
APL (Dyalog Unicode)
∪

Try it online!
Jelly
Q

Try it online!
W
U

Stax
u

MATL
u

Try it online!
MathGolf
▀

Try it online!
Seriously/Actually
╔

Japt
â

Try it online!
Pyth
{

Try it online!
Husk
u

Try it online!
Pyke
}

Try it online!
Canvas
Ｄ

Try it online!


Given a sequence of numbers, print out all possible sets such that the sum is less than a number The problem has 3 inputs.

L: a list of all numbers

size: the size each set can be

max: the max sum amongst each set

The challenge is as follows:

Given L, size and max, construct as many sets from L such that the number of elements is size and the sum of each of the elements does not exceed max.

Examples:

func(L=[1,2,3,4], size=2, max=5) = [{1,2}, {1,3}, {2,3}, {1,4}]

Notice how each of the values in the outputted set are sum <= max.

func(L=[1,2,3,4], size=3, max=6) = [{1,2,3}]

func(L=[1,2,3,4], size=3, max=5) = [{}] or empty list, whichever you want

Note that in the set you cannot have duplicated items. ie: {2,1} = {1,2}

Constraints on inputs:

L: 0 or more elements

size: 0 <= size <= len(L)

max: 0 or more

If a list has 0 items, then always return the empty set.

If the size is 0, then always return the empty set.

If max is 0, it is possible that there are negative values in L, in which case the returned sets need not be empty.

Shorted bytes wins!


Fastest python implementation of multiplication table I'd be interested to see who can come up with the fastest function to produce multiplication tables, in the following format:

   1   2   3   4   5   6   7   8   9  10  11  12
   2   4   6   8  10  12  14  16  18  20  22  24
   3   6   9  12  15  18  21  24  27  30  33  36
   4   8  12  16  20  24  28  32  36  40  44  48
   5  10  15  20  25  30  35  40  45  50  55  60
   6  12  18  24  30  36  42  48  54  60  66  72
   7  14  21  28  35  42  49  56  63  70  77  84
   8  16  24  32  40  48  56  64  72  80  88  96
   9  18  27  36  45  54  63  72  81  90  99 108
  10  20  30  40  50  60  70  80  90 100 110 120
  11  22  33  44  55  66  77  88  99 110 121 132
  12  24  36  48  60  72  84  96 108 120 132 144

Use the following template to benchmark your code using a 12-width table, and post your  code and the resulting time here.

#!/usr/bin/python
import timeit
cycles = 100000

referencecode = r'''

def multable(width):
  '\n'.join(''.join('{0:4}'.format(x*y) for x in range(1,width+1)) for y in range(1,width+1))

'''

yourcode = r'''

def multable(width):
  pass # Your function here

'''

referencetime = timeit.Timer('multable(12)', setup=referencecode).timeit(number=cycles)
yourtime = timeit.Timer('multable(12)', setup=yourcode).timeit(number=cycles)

print 'Your code completed', referencetime / yourtime, 'times faster than the reference implementation'

About 352 times faster, according to the benchmark code

(on my machine)  Python 2.7

Exactly how much faster it is will vary widely between machines. I tested it on my web server also and there it was only 288 times as fast.

import itertools as i, operator as o

def multable(width, m={}):
   if not width in m.keys():
      m[width] = '\n'.join(['%4d'*width]*width)%tuple(i.starmap(o.mul,i.product(range(1,width+1),repeat=2)))
   return m[width]

The actual algorithm is only about 1.25 times as fast as the reference one, but if you have a function which is called often, caching the result saves a lot of time.


Reverse words without changing capitals or punctuation Create a program with the lowest amount of characters to reverse each word in a string while keeping the order of the words, as well as punctuation and capital letters, in their initial place.

By "Order of the words," I mean that each word is split by a empty space (" "), so contractions and such will be treated as one word. The apostrophe in contractions should stay in the same place. ("Don't" => "Tno'd").

(Punctuation means any characters that are not a-z, A-Z or whitespace*).

Numbers were removed from this list due to the fact that you cannot have capital numbers. Numbers are now treated as punctuation.

For example, for the input:

Hello, I am a fish.

it should output:

Olleh, I ma a hsif.

Notice that O, which is the first letter in the first word, is now capital, since H was capital before in the same location.

The comma and the period are also in the same place.

More examples:

This; Is Some Text!

would output

Siht; Si Emos Txet!

Any language can be used. The program with the lowest amount of characters wins.

GolfScript, 58 54 48 characters
" "/{.{65- 223&26<}:A,\{.A{96&\)31&@+}*}%+}%" "*

This is a GolfScript solution which became rather long. Lots of the code is actually finding out if a character is in a-zA-Z. Maybe someone can find an even shorter way of testing it.
You can try the code online. Examples:
> Hello, I am fish.
Olleh, I ma hsif.

> This; Is Some Text!
Siht; Si Emos Txet!

> Don't try this at home.
Tno'd yrt siht ta emoh.


Random with your hands tied Task
Develop some code to generate a psuedo-random number between X and Y (taken as input). Explain why or how it works.
Conditions

Do not use any random generating seeds, pre-written randoms, or external source to generate the random number.
Make something as close to random as you can get. No hard coding of values.

Whoever gets the most upvotes for a new, innovative, out of the box, idea, wins.

C

not sure if the volatile keyword is needed (or what other OS dependencies are assumed here)

simply takes the address of a variable, and maps it to [min, max]:

int rand(int min, int max)
{
  volatile int order = max - min + 1;
  return min + (int)&order % order;
}


Implement a Stopwatch Implement a simple digital Stopwatch,
which will display the time elapsed in seconds and minutes, as described below.

Important
Please read both Display and Controls sections !

Display
Time elapsed, should be displayed in the MM:SS format,
by replacing the previously displayed time string "in-place"
(clearing the whole or a part of the screen is also allowed).
The stopwatch must be updated at least every second.
Examples:
0 minutes, 0 seconds
00:00

0 minutes, 33 seconds
00:33

1 minute, 50 seconds
01:50

Initially, you can start with '00:00' or with any other value in range [00:00-59:59].
Once your Stopwatch reaches 59:59, it should reset to 00:00 and continue afresh.
You can use a different base (instead of decimal) or even a different numeral system if you wish, as long as you follow the general pattern.
For example 13:03 can be displayed as:
Decimal
13:03

Hexadecimal
0D:03

Base64
N:D

Quater-imaginary base
10101:3

Roman Numerals
XIII:III

Beware that if you use a non-decimal numeral system/base, it must be encoded using printable ASCII (or Unicode) characters, e.g. using two binary (unprintable) bytes for minutes and seconds is not allowed.
You must also left-pad your output with zeroes as appropriate, if your numerical system allows for that.
Replacing the separator character : with any other printable character (including digits) is also acceptable.
Controls
The stopwatch should start paused, and stay in this state, until user explicitly starts it, by pressing the 'control' key (see below).
If, while stopwatch is counting, user presses the 'control' key again, the stopwatch should pause (keeping the current time), until the 'control' key is pressed a one more time.
The 'control' key can be a single keystroke, e.g. s,
or any combination of keys, e.g. Ctrl+Shift+X, but it must be 'atomic', pressing multiple keys in sequence, e.g. s then Enter, is not allowed.
The same 'control' key (or combination) must be used to pause and resume the stopwatch.
You must use a specific 'control' key, i.e. 'any key' is not allowed.
Alternatively, you can use a single or double mouse-click, instead of a keypress for 'control'.

Rules

This is code-golf, the shortest answer in bytes wins;
Standard code-golf loopholes apply;
Your program must (theoretically) be capable of running forever.

Python 2, 167 129 bytes

-36 bytes mostly* from using Maltysen's idea of catching ctrl-c using an exception - go give credit!
-4 bytes thanks to DLosc (init n and b to 0 rather than f())
-1 byte thanks to FlipTack (use p^=1 rather than p=1-p)
-2 bytes thanks to Felipe Nardi Batista (remove precision specifiers)

import time
f=time.time
n=b=p=0
while 1:
 try:n=[n,f()][p];t=n-b;print'\r%02d:%02d'%(t/60%60,t%60),
 except:b=[b-n+f(),b][p];p^=1

Works the same as my original, below, but with the control key sequence of ctrl+c.
(Tested by me with Python 2.7.8 on Windows 7, 64bit;
Tested by Brian Minton with Python 2.7.13 on linux, 64bit)

* also collapsed if statement to a list lookup in order to get the try as a one-liner.

My original:

import time,msvcrt as m
f=time.time
n=b=p=0
while 1:
 if m.kbhit()and m.getch()==b'p':b=[b-n+f(),b][p];p^=1
 if p:n=f()
 t=n-b;print'\r%0.2d:%0.2d'%(t/60%60,t%60),

(Tested by me with Python 2.7.8 on Windows 7, 64bit - this code, however, is Windows specific due to the use of the msvcrt library)

The control key is 'p'.

n and b are initialised to the same value at start-up, giving an "offset" of 0; p is initialised to 0, indicating a paused state.

Whenever the control key is pressed the value of p is switched. When switching from a paused state to an active state b is updated to a new value keeping any current offset from the previous active state(s) with b-n.

During an active state n is repeatedly updated to the current time by calling time.time().

The difference between n and b, t, is then the total number of seconds (including a fractional part) elapsed during active state(s).

The minutes elapsed are then t/60 and each of the minutes and seconds are displayed mod 60 with (t/60%60,t%60). Leading zeros are prepended for each using string formatting of the integer part with '...%0.2d...'. Printing a tuple (the trailing ,) where the first item has a leading carriage return (the \r) causes the previously printed text to be overwritten.


Generate the group table for Z_n Groups are a widely used structure in Mathematics, and have applications in Computer Science. This code challenge is about the fewest # of characters to create a group table for the additive group Zn.

How the table is constructed: For Zn, the elements are {0, 1, 2, ..., n-1}. The table will have n rows and n columns. For the ij-th entry of the table, the value is i+j mod n. For example, in Z3, the 1-2nd entry (2nd row, 3rd column if you count the starting row/column as 1) is (1+2)%3 = 0 (see sample output).

Input: a positive integer, n

Output: a table that is a textual presentation of Zn, constructed as described above, and displayed as shown below in the sample outputs. Spaces are optional

Sample input: 3

Sample output:

0 1 2
1 2 0
2 0 1

Sample input: 5

Sample output:

0 1 2 3 4
1 2 3 4 0
2 3 4 0 1
3 4 0 1 2
4 0 1 2 3

APL (10)

(Assuming ⎕IO=0. It works on ngn/apl by default, other APLs tend to need an ⎕IO←0 first.)

{⍵|∘.+⍨⍳⍵}

Explanation:

⍳⍵: the numbers [0..⍵)
∘.+⍨: create a sum table
⍵|: numbers in the table mod ⍵


Quining a Pristine World This challenge is based off of Helka Homba's question Programming a Pristine World. From that question, the definition of a pristine program is:

  Let's define a pristine program as a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of N characters, where 1 <= N < program length.

  For example, the three character Python 2 program

`8`

  is a pristine program (thanks, Sp) because all the programs resulting from removing substrings of length 1 cause errors (syntax errors in fact, but any type of error will do):

8`
``
`8

  and also all the programs resulting from removing substrings of length 2 cause errors:

`
`

  If, for example, `8 had been a non-erroring program then `8` would not be pristine because all the results of substring removal must error.

  Notes:

  Compiler warnings do not count as errors.
  The erroring subprograms can take input or give output or do anything else as long as they error no matter what eventually.

Your task is to create a program of non-zero length that prints its own source code exactly, follows the rules for a proper quine, and is pristine.

Shortest answer in bytes for each language wins.

Haskell, 132 bytes

q x=if length x==132then putStr x else fail[];main=q$(++)<*>show$"q x=if length x==132then putStr x else fail[];main=q$(++)<*>show$"

Try it online!

This is an extension of the quine

main=putStr$(++)<*>show$"main=putStr$(++)<*>show$"

which works by concatenating the data string with a quoted version (by using show) of itself and printing the result. However, this is not pristine as any characters in the data string can be removed without failing and also the $(++)<*>show$ or (++)<*> part could be dropped without the program breaking.

To fix this, a custom print function q is defined which checks the length of the given string and calls fail if it's shorter than 132. This catches the removing of any sequence from the data string and also the removals of $(++)<*>show$ or (++)<*>, as in both cases the resulting string passed to q is shorter.

In q the number 132 could be shortened to 1, 13, 32 or 2, but in each case again fail is called.

As far as I can tell, the removal of any other substring causes either an syntax or type error, so the program does not even compile in the first place. (Haskell's strict type system comes in handy here.)

Edit: Thanks to Ørjan Johansen and Shelvacu for pointing out a flaws!


Ring me when our cup noodles are ready I'm currently cooking us some cup noodles, but we're really sleepy at the moment. They'll be finished in 50 seconds from now, can you wake me up then?
Problem:
Write a program or function that waits 50 seconds of busy waiting (so that you too doesn't sleep) and then outputs at least 1 visible character to wake me up.
Busy waiting:
You can't use functions like sleep or delay or pause to wait for the 50 seconds, you have to keep checking the elapsed time.
Rules:

Your code must be somewhat consistent in time, between runs and between computers. A small error of +- 1 seconds is acceptable.
You can't output any visible characters between 1 and 50 seconds (let me sleep).
Whitespace characters (newline, space, tab, ...) are not considered visible characters for this challenge.
This is code-golf, so shortest code wins.

Octave, 22 21 bytes
Saved one byte by changing from while ... end to do ... until.
tic;do
until toc>50;1

tic starts a timer, while toc returns the number of decimal seconds since the last call to tic. We initiate a do - until loop, where we'll loop until toc>50, doing nothing inside the loop. The loop stops after 50 seconds, followed by ans = 1 on the screen.
Try it on TIO (time changed to 5 seconds) or paste it into Octave Online.


Animate the text in your terminal Animate the text in your terminal

The goal

The goal is to "animate" the string "Hello world" in your output so that each character gets capitalised after each other.

Your program can exit after each letter has been capitalised.

For example;

# Iteration 1
Hello world

# Iteration 2
hEllo world

# Iteration 3
heLlo world

# Iteration 4
helLo world

# Iteration 5
hellO world

# Iteration 6 (note: it should capitilize the space char (ie: a break between iteration 5 and iteration 7)
hello world

# Iteration 7
hello World

# Iteration 8
hello wOrld

# Iteration 9
hello woRld

# Iteration 10
hello worLd

# Iteration 11
hello worlD

It should only animate the string once and between each state there should be a 1 second delay.

Input

No input is required, but "Hello world" must be the string that is "animated".

Output

The string "Hello world" must be animated. The output must be as 1 line to create a sort of wave animation. An empty trailing new line is allowed. Example gif;

I saw this on a metasploit youtube video and thought the effect was pretty cool, which is where I recorded the gif from, so it's a little laggy, but I hope it illustrates the output fine

This is code-golf, lowest byte-count will be deemed the winner.

Sandbox Link

Vim 26 bytes

ihello world<ESC>qq~gsul@qq0@q

Explanation (no .gif yet):

First, we must enter the 'hello world' text. This is pretty straightforward. It's just:

ihello world<ESC>

At this point, the cursor is on the 'd' in 'world'. Next:

qq              " Start recording into register 'q'
  ~             " Swap the case of the character underneath the cursor, and move the cursor to the right
   gs           " Sleep for one second
     u          " Undo the last change (of swapping case).
      l         " Move one character to the right (Get it? 'l' == 'Right' because vim is intuitive!)
                " This will cause the error to break on the last character of the input.
       @q       " Call register 'q'
         q      " Stop recording
          0     " Move to the first character
           @q   " Call the recursive macro

There are also two other 26 byte versions I found:

ihello world<ESC>qq~gsulq011@q
ihello world<ESC>011@='~gsul'<cr>


Generate a random sequence of numbers The challenge:

Generate a random sequence of numbers. The only input should be the length of the sequence.
Extra internet points for pure-functional solutions.

Note: This is a code-trolling question. Please do not take the question and/or answers seriously. More information here.

Python

Grab a random wikipedia article, and take a sequence of html characters of length num, and get their numerical values

import urllib2
from random import randint
def getRandom(num):
    response = urllib2.urlopen('http://en.wikipedia.org/wiki/Special:Random')
    html = response.read()
    html = html.replace(" ", "")
    htmllen = len(html)
    #I especially love how I still grab a random number here
    l =  randint(0, htmllen - num)
    data = html[l:l+num]
    return [ ord(x) for x in list(data) ]

print getRandom(25)


Summing? That's my forte! Introduction

Forte is a very peculiar esoteric language based on the concept of modifying the values of numbers. In Forte numbers are not constants but variables, you can use the LET instruction to assign new values to them.

For example, after executing LET 2=4-1 from now on 2 assumes the value of 3, which means that whenever the value 2 comes up in an expression it is instead "replaced" by 3. The expression (1+1)*2 would now evaluate to 9.

This instruction in Forte is used both for storing information and for flow control (lines are numbered and by changing the value of their numbers you can determine the order of their execution). In this challenge we will not deal with this second aspect.

The challenge

You are required to write an interpreter for a simplified subset of Forte's LET expressions.

You will receive as input a series of lines following this grammar:

<line>::= <number>=<expression>

<expression>::= <number>|<expression>+<number>

Note: this grammar is not valid Forte because it lacks line numbers, LET, and parentheses (which are always mandatory)

That is, you will only need to deal with computing summations and assigning values to numbers. Parentheses won't be present in the input, and each expression will need to be evaluated from left to right: beware that partial results are affected by redefinitions!

Numbers will always be non-negative integers, up to the limit of your language's native integer type (or 2^32, whichever is higher).

For each line you should output the result of the expression and assign this result to the (possibly reassigned) value of the first number, which will affect how the following lines will be interpreted.

This is code-golf, the shortest code (in bytes) wins!

Other rules

The input format is flexible, you can for example take a single string with newlines, a list of strings, a list of lists of numbers... The same goes for the output, as long as it's clear what's the result of each expression in the input.
You may submit either a function, a full program, or a solution to be run in a REPL environment calling it once for each line.
Standard loopholes are forbidden, in particular you can't call an external Forte interpreter in your code.

Examples

These are all part of the same input. After each line the expected output relative to that line is shown, sometimes with a comment indicating relevant reassignments (not part of the required output).

5=4
4
6=5
4        # 5 -> 4
7=1+2+5
7
7=5+2+1
4        # Order of operations matters! 5+2 -> 4+2 -> 6 -> 4
18=5+6+7
12
5=3
3        # Remember: 5 -> 4
10=6+4
3        # 6 -> 4 -> 3, 3+3 = 6 -> 3

Perl 5, 92 bytes

90 bytes of code + -pl flags.

sub f{($b=$h{$a=pop}//$a)!=$a?f($b):$a}s%(\d+)\+(\d+)%f($1)+f$2%e&&redo;/=/;$_=$h{f$`}=f$'

Try it online!

I use the hashtable %h to store the mapping between numbers.
The function (sub) f returns the number to which its input map (or its input if it's mapped to no number): $h{$a=pop} retrieves the number toward which the input maps. If it's none, thanks to //$a, the value of ($b=$h{$a=pop}//$a) is the input ($a). We make sure that this values isn't the input itself to not loop infinitely (!=$a). Then, we either recursively call f or return the input.
The main program consists of two steps:
  - s%(\d+)\+(\d+)%f($1)+f$2%e&&redo evaluates the first addition on the right side, while there is still an addition: it replaces x+y by the result of the evaluation of f(x)+f(y).
  - /=/;$_=$h{f$`}=f$' does the assignment: /=/ allows to access the left side with $` and the right side with $', then $h{f$`}=f$' does the assignment. And we also assign it to $_ that is implicitly printed after each line.


Will you be my Weaver? I've been recently playing through 'The Weaver' and I think it presents an interesting challenge for code-golf.

Premise:

The Weaver is a game wherein you are given a number of ribbons coming from 2 directions 90 degrees apart and your goal is to swap them at certain intersections to achieve a desired output.

   Like this:         This is a swap:         This isn't:

Input:

3 arrays:

Top ribbons (left to right)
Left ribbons (top to bottom)
The coordinates of the intersections to swap

Output:

2 arrays:

Bottom ribbons (left to right)
Right ribbons (top to bottom)

Examples:

I'll use the above image as the first example:

Input: [r, y, b], [r, y, b], [(0, 1), (2, 1), (2, 2)]

What happens:

   r   y   b
   r   y   b
r r r r•y y y y
   r   r   b
y y y y y y y y
   r   r   b
b b b b•r r•b b
   r   b   r
   r   b   r

Where • represents a swap.

Output: [r, b, r], [y, y, b]

Input: [a, b, c], [d, e, f], [(0, 0), (2, 1)]

What happens:

   a   b   c
   a   b   c
d d•a a a a a a
   d   b   c
e e e e e e e e
   d   b   c
f f f f•b b b b
   d   f   c
   d   f   c

Output: [d, f, c], [a, e, b]

Input: [a, b], [a, b, c], [(0, 1), (1, 0), (1, 1), (2, 0), (2, 1), (3, 1)]

What happens:

   a   b
   a   b
a a a a•b b
   a   a
b b•a a•a a
   b   a
c c•b b•a a
   c   b
   c   b

Output: [c, b], [b, a, a]

Notes:

The examples show coordinates given as (row, column) though you may take them as (column, row).
The top row and left column may have ribbons of the same color
The board can be rectangular
All coordinates will be non-negative (>=0) (or strictly positive (>=1) if you choose 1-indexing)
Ignore any swaps that are outside the board
You may choose to work with letters ([a-zA-Z]), integers ([0-9]) or both
The ribbons in your output must match the ribbons in the input exactly (a -> a)
You may assume the list of swaps is sorted in any way you want, as long as it's consistent (if you do, please specify how it should be sorted)
You may take the swap coordinates as 0 or 1-indexed
Default loopholes are forbidden

More examples:

Input:
[b], [r], []
Output:
[b], [r]

Input:
[b], [r], [(0, 0)]
Output:
[r], [b]

Input:
[r, p, y], [r, y, p], [(0, 0), (1, 2), (2, 1), (3, 2)]
Output:
[r, p, y], [r, y, p]

Input:
[b, y, o, r],
[r, o, b, y],
[(0, 0), (2, 0), (3, 2)]
Output:
[b, y, y, r],
[b, o, r, o]

The last example relates to this case (if that makes it easier to visualize):

This is code-golf so the shortest answer in bytes for each language wins.

Python 3, 74 bytes

def g(a,b,l):
 for x,y in l:
  if x<len(a)and y<len(b):a[x],b[y]=b[y],a[x]

Try it online!

Requires l to be sorted in lexicographical order. a and b are lists of characters representing (left ribbon, top ribbon).

Returns by modifying the list a and b.


Score an asynchronous prisoner's dilemma game In a round of the prisoner's dilemma exercise, two players each decide whether to cooperate or defect for that round. The scoring for a round is:

Player A and Player B both cooperate: 1 point for both
Player A and Player B both defect: 2 points for both
Player A cooperates and Player B defects: 3 points for cooperating Player A and 0 points for defecting Player B

You don't need to worry about strategy, though: your program will merely be tabulating the score for a game. (In case you are already familiar with prisoner's dilemma, my "points" here correspond to "years in prison.")

Your challenge is to take input that represents the players' choices over several rounds and compute their respective total scores. One player submits choices in lowercase, c and d (for cooperate and defect), and the other submits choices in uppercase, C and D. These choices are supplied to your program as a string.

Normally, players in prisoner's dilemma submit their moves simultaneously and iteratively. In this challenge, however, the players may have submitted their choices for several rounds at once. If a player's move is out of sequence, the scoring program remembers it and matches it with the next available move from the opposing player.

Here's a sample input string:

cDCddDDCcCc

To show the matches that exist in this input, I'll call out the lowercase and uppercase separately, and pair them up:

cDCddDDCcCc
c  dd   c c => cddcc
 DC  DDC C  => DCDDCC

These will be paired into the rounds:

c vs D (3 pts for lowercase-player, 0 pts for uppercase-player)
d vs C (0 pts for lowercase-player, 3 pts for uppercase-player)
d vs D (2 pts for both)
c vs D (3 pts for lowercase-player, 0 pts for uppercase-player)
c vs C (1 pt for both)

Which produces the score 9 (lowercase) to 6 (uppercase), so the output should be 9,6 (or any unambiguous delimiter).

To express it in yet another way, here's each pairing pulled out on its own row:

cDCddDDCcCc
cD
  Cd
    dD
      D c
       C  c

There is one unmatched C, because the uppercase player submitted more moves than the lowercase player. That is acceptable, and it is totally ignored for scoring purposes.

Here are the requirements:

You must write a program or function that accepts a string of the regular-expression form /[cdCD]+/, through some input mechanism (STDIN, function argument, read from file, etc.). (Your program may optionally accept input with a trailing newline.)
Your program or function must output or return the players' scores as a string. The output format must start with the lowercase player's score, followed by the uppercase player's score, separated by any non-empty, non-numeric delimiter of your choice. (A trailing newline is optional.)
If one player has more moves than the other, the excess moves are ignored.
If all moves in the input are from exclusively one player (that is, no rounds have been played at all), then each player's score is 0.
The smallest submission in bytes wins.

Test cases

Input:  cDCddDDCcCc
Output: 9,6         -- or any delimiter; I chose commas here

Input:  cccDDD
Output: 9,0

Input:  DDDDDDccc
Output: 9,0

Input:  cDcDcD
Output: 9,0

Input:  dcDDC
Output: 5,2

Input:  CcdCDDcd
Output: 6,6

Input:  Ddd
Output: 2,2

Input:  ccccccccccc
Output: 0,0

Haskell, 139 134 bytes

g=filter
(n!m)(a,b)=(a+n,b+m)
f s=init$tail$show$foldr id(0,0)$zipWith(#)(g(>'a')s)$g(<'E')s
'c'# 'C'=1!1
'c'#_=3!0
_# 'D'=2!2
_#_=0!3

Usage example: f "cDCddDDCcCc" ->  "9,6"

15 bytes just to get the output format right, i.e. turning a pair of numbers (x,y) into a string "x,y".

How it works:

               g(>'a')s        -- extract all lowercase letters
                     g(<'E')s  -- extract all uppercase letters
         zipWith(#)            -- combine both lists element wise with function #
                               -- # calls ! depending on the combination of c/d/C/D
                               -- ! takes 2 numbers a and b and returns a function
                               -- that takes a pair (x,y) and returns (x+a,y+b)
                               -- now we have a list of such functions
    foldr id(0,0)              -- apply those functions starting with (0,0)
init$tail$show                 -- format output

Edit: @Zgarb helped me saving 5 bytes. Thanks!


05AB1E, 20 12 bytes

Saved 8 bytes thanks to Osable!

µNSDOsP‚¾>å½

Uses the CP-1252 encoding. Try it online!


Let's move the Mars rover! Summary

The task is to navigate the Mars rover and tell its final coordinates and direction.

Input:

First input:

First your program must take the input which will be in the following format:

[X-Coordinate],[Y-Coordinate],[Direction]

The direction must be: N or S or E or W (Starting letters of North, South, West, East)

Example:  10,20,N ( x = 10, y = 20, direction = N(North))

Second input:

The second input consists of series of R, L, M for right, left and move respectively.

For R and L (right and left) the direction of rover must change accordingly.

For M the rover must move 1 unit ahead in the direction which it was before moving.

Rules for calculating coordinates:

N = Y + 1
E = X + 1
S = Y - 1
W = X - 1

Output:

The final coordinates and the current direction of the rover.

Example:

Enter initial data:      1,2,N

Enter the instructions:  MRMLM

Output:                  2,4,N

The coordinates can be any integer and can be negative.

All the standard loopholes aren't allowed. If providing demo on sites like http://ideone.com etc. is possible, then please do so, so that I can verify :)

This is a popularity contest so be creative!

Following others' advice, I decide to make this a code-golf.

Ruby ≥ 2.0, 101

E,N,W,S=*0..3
x,y,i=eval"a="+gets
gets.bytes{|c|x+=c%2*1i**i=i+1-c&3}
$><<[(x+y.i).rect,"NWSE"[i]]*?,

This solution can be tested here: https://ideone.com/C4PLdE

Note that the solution linked on ideone is one character longer (1.i instead of 1i in line 3). The reason for this is that ideone only supports Ruby 1.9, which doesn't allow the short-hand syntax for complex literals.


Of Dumps and Cubes, and Structured Nonsense Your challenge is to translate a Cubically cube-dump to the format specified in this challenge.

Input

The input will represent a Rubik's Cube, formatted how Cubically prints its memory cube at the end of every program.

This is a solved cube:

   000
   000
   000
111222333444
111222333444
111222333444
   555
   555
   555

This is a cube scrambled with L2D2L2D2B2R2F2L2D2U2F2UF2U'R2UB2U'L2UB2U'LU'L2U'D'B2U'RBUBF'D' (Singmaster's notation):

   201
   501
   331
132505224540
512324533442
404513210411
   350
   254
   003

Output

If you already understand this format, hit page down a few times to skip lots of explanation.

The output will represent a Rubik's Cube, formatted how solutions to this challenge take input.

  The first 12 values are the edge cubies, and the next eight are the corners. The faces are U(p), D(own), R(ight), L(eft), F(ront), and B(ack). First the cubie that's in the UF position is given, by the color (in UFRDBL notation) that's on top first, and then the other color next, and so on.

This format is a bit confusing, so here's a way to visualize it. This is the solved cube:

That renders the output UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR.

If we were to swap, for example, the red-white edge and the red-blue edge, the visualization would look like this (with no changes to the hidden faces):

That renders the output UR UF UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR (which, btw, is an impossible cube state). Note that the order of the letters in cubies matter:

Above: UR UF UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
Below: RU FU UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR

The cube scrambled with L2D2L2D2B2R2F2L2D2U2F2UF2U'R2UB2U'L2UB2U'LU'L2U'D'B2U'RBUBF'D' creates this cube (only the top, front, and right faces are shown):

Solved:    UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
Scrambled: RU LF UB DR DL BL UL FU BD RF BR FD LDF LBD FUL RFD UFR RDB UBL RBU

As you can see in the comparison above and in the visualizations, the blue-red RU edge of the mixed cube is in the place of the red-white UF edge of the solved cube. The green-white LF edge is in the place of the red-blue UR edge, etc.

Rules

I/O will be done via any allowed means.
The output cubies must be delimited by any whitespace character you choose.
The input will be formatted exactly how it is shown in the challenge, including whitespace.
Your program may do whatever you like if the inputted cube is unsolvable.

Test cases

Input -> output: RU LF UB DR DL BL UL FU BD RF BR FD LDF LBD FUL RFD UFR RDB UBL RBU
Input -> output: UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
Input -> output: FU DL LB BU RU BR RF DR BD DF LF LU FUL FLD URB BLU RUF DBR BDL RFD

Here's a reference program using parts of Cubically's rubiks.c.

Winner

As this is code-golf, the shortest answer in bytes wins!

Clean, 150 145 143 bytes

Contains many non-printable characters.

import StdEnv
$d=map(\c=['ULFRBD ']!!(digitToInt(['96':d]!!(toInt c))))['!�B5J8P;H2)*\'&-,/$ "C76A43O1<Q:9']

Try it online!

Defines the function $, taking [Char], and giving [Char].

This works by mapping each character position in the input to another character position in the output (using the character codes in a string), taking advantage of the swapped 'cubies' in the output being paralleled by swapped colors in the corresponding position in the input.

Output is separated by spaces.


Make the PPCG Favicon Come November 1, Programming Puzzles and Code Golf will graduate, so in the next 11 months, we'll want to save some memories from when we were ungraduated.

Write a program that produces the PPCG favicon, seen below.

The image must be at least 64x64 pixels.
The blue must be the color #62B0DF. The background can be white or a light gray.
The image need not be pixelated like it is here.
Alternatively, create text (with dimensions at least 64x64 non-whitespace characters) using standard bright ANSI color codes of Cyan and White.
Built in images and importing the PPCG logo are not allowed.

This is code golf, so standard rules apply. Shortest code in bytes wins.

Bash (OSX), 33 27 23 18 Bytes

You heard the man, any way we like.

open http:yon.se/q

I am aware that this is a popularity contest. But hey, when you can code golf it, why not?

It is now a code golf. \o/ This was valid at the time of posting.

There was even an exception made for me at some point! But, as @AlexA. pointed out...

  "You can use whatever methods you want (except loading the image, with the exception of VoteToClose's response)" It isn't fair to allow exceptions for specific users/answers. - Alex A.

I agree with this, and, as of such, do not wish this to be picked as the answer. Doesn't mean I won't still try to golf it down more. ;)

Thanks to @ΚριτικσιΛίθος for shaving off 6 bytes with a fancy short URL!

Thanks to @ev3commander for shaving off ANOTHER 5 bytes with an even fancier, shorter URL!

Thanks to @kennytm for pointing out that I can reduce the protocol size and remove the quotes, saving me another 4 bytes!


Implement the dog bash utility dog is a command-line utility that takes in an arbitrary number of arguments,
the first of which is the text to be written and the others are arbitrarily many files.

The dog utility will split the text in equal portions over these files. If there is a remainder n, the first n files get an additional byte

dog is the opposite of cat, as such, forall x, the following should hold.

$> dog x a.txt b.txt ...
$> cat a.txt b.txt ...
x$>

Where ... indicates arbitrarily many files.

An example (12 bytes, 3 files, can be split evenly):

$> ./dog.py "Dogs vs Cats" a.txt b.txt c.txt
$> cat a.txt
Dogs$> cat b.txt
 vs $> cat c.txt
Cats$> cat a.txt b.txt c.txt
Dogs vs Cats$>

An example with remainder (13 bytes, 5 files, remainder 3):

9$>./dog.py "0123456789abc" a.txt b.txt c.txt d.txt e.txt
$> cat a.txt
012$> cat b.txt
345$> cat c.txt
678$> cat d.txt
9a$> cat e.txt
bc$> cat a.txt b.txt c.txt d.txt e.txt
0123456789abc$>

Pyth - 12 bytes
.wMC,cl.zz.z

Uses builtin split function and then uses splat-map on the write function. Doesn't work online.


The lowest initial numbers in a Fibonacci-like sequence Given a positive integer input N, output the two non-negative numbers, a and b, where a < b, with the lowest possible mean value that will result in the number N being part of the recurring relation sequence:

f(0) = a
f(1) = b
f(n) = f(n-2)+f(n-1)

In case there are more than one solution where the mean of a and b are minimal, then you should output the one with the lowest b.

Your can assume N is within the representative range of integers in your language / system.

Test cases

N = 1
a = 0, b = 1

N = 15
a = 0, b = 3

N = 21
a = 0, b = 1

N = 27
a = 0, b = 9   <- Tricky test case. [3, 7] is not optimal and [4, 3] is not valid

N = 100
a = 4, b = 10

N = 101
a = 1, b = 12

N = 102
a = 0, b = 3

N = 1000
a = 2, b = 10

APL (Dyalog), 75 71 64 59 53 48 44 43 bytes

2 bytes saved thanks to @Adám

12 bytes saved thanks to @ngn

⊃o/⍨k∊¨+\∘⌽⍣{k≤⊃⍺}¨o←a/⍨</¨a←,⍉|-\¨⍳2⍴1+k←⎕

Try it online!

Uses ⎕IO←0.

How? This had gone real nuts.

k←⎕ - assign input to k

⍳2⍴1+k←⎕ - Cartesian product of the range 0 to k with itself

|-\¨ - substract each right pair element from the left, and get absolute values

a←,⍉ - transpose, flatten and assign to a

o←a/⍨</¨a - keep only pairs where the left element is smaller than the right, and assign to o

o now contains list of all pairs with a < b, ordered by their arithematical mean

+\∘⌽⍣{k≤⊃⍺}¨o - for each pair in o, apply fibonacci (reverse the pair and cumsum) until k or higher term is reached

k∊¨ - then decide if k is this last term (meaning it is contained in the sequence)

o/⍨ - and keep pairs in o where the previous check applies

⊃ - return the first result.


Calculate the Orthocenter of a Triangle Try to write the shortest program or function you can that prints or returns the calculated orthocenter of a triangle.

The orthocenter of a triangle is the intersection point of the three altitudes of a triangle. The altitude of a triangle is a perpendicular segment from the vertex of the triangle to the opposite side.

Input:

Three points in 2D space correponding to the triangle's vertices

Output:

The calculated orthocenter of the triangle

A sample input would be

A(0,0)
B(3,6)
C(6,0)

and a sample output would be:

Calculated Othocenter (3, 1.5)

One formula for orthocenter can be written as

(x, y) = ((ax*tan(α) + bx*tan(β) + cx*tan(γ))/(tan(α) + tan(β) + tan(γ),
          (ay*tan(α) + by*tan(β) + cy*tan(γ))/(tan(α) + tan(β) + tan(γ))

Shortest program in bytes wins.

Python, 193 168
Should work for any valid triangle...
def h(a,A,b,B,c,C):
 if A==B:b,B,c,C=c,C,b,B
 m=(a-b)/(B-A)
 return m,C-m*c
def f(a,A,b,B,c,C):
 m,q=h(a,A,b,B,c,C)
 k,z=h(c,C,b,B,a,A)
 x=(q-z)/(k-m)
 return (x,k*x+z)


Line numbering - implement nl Your task is to implement a program similar to the nl command-line tool from the GNU core utilities.

Standard loopholes are banned.

You may not use any built-in or external function, program or utility for numbering the lines of a file or string, such as nl itself or the = command in GNU sed.

Specification

Input

The program accepts filenames as arguments. Your code does not have to be cross-platform; the filename format of the OS running the code should be used, i.e. if you happen to be on Windows, the directory separator can be \ or /.

You must be able to take 64 input files, including - if it is specified. If over 64 are given, only handle the first 64.

In the list of filenames, - represents standard input.

If filenames are given, read from the files in the order that they are given and concatenate their contents, inserting a new line between each one and at the end. If you cannot read from one or more of the filenames (because the file does not exist or you do not have read permissions for it), ignore them. If all filenames specified are invalid, output nothing.

If no filenames are given, read from standard input. Only read from standard input if no filenames are given or if - is given.

Output

The program will output, to standard output, the input with lines numbered thus (You may assume that the input has \n, \r\n or \r line endings; pick whichever is convenient for you, but specify which one):

<5 spaces>1<tab><content of line 1 of input>
<5 spaces>2<tab><content of line 2 of input>
...
<4 spaces>10<tab><content of line 10 of input>
...
<3 spaces>100<tab><content of line 100 of input>
...
...

6 characters of space are allocated for the line number, and it is inserted at the end of these characters; the rest become spaces (e.g. 1 will have 5 leading spaces, 22 will have 4 leading spaces, ...). If the input is sufficiently long, you will eventually run out of space for the line number, at line 999999. You must not output anything after line 999999.

If the input is empty, output nothing.

Exit status

The lower numbers take priority: if errors 1 and 2 were encountered, exit with status 1.

Exit with status 0 if the input was successfully received, and the lines successfully numbered and output.

Exit with status 1 if one or more of the files specified on the command line were not found or could not be read from.

Exit with status 2 if too many files (more than 64) were given.

Exit with status 3 if the input was too long (more than 999999 lines).\

Scoring

This is code-golf - shortest program wins!

I may add bonuses later for implementing certain options that nl has. There are no bonuses at the moment.


X+Y=Z - but in which base? The  Challenge
Given 3 numbers X, Y and Z in base B, find a Base in which the addition of X and Y yields Z. The inputs x = 20, Y = 12 and Z = 32 could yield 5 because 20 + 12 = 32 in base 5.

You may assume that there will always be a base in which the addition is correct (there are cases where no base exists, thanks to @MasonWheeler and @Not that Charles for some examples of that).
The lowest possible base is 1. You may use 1s or 0s as the digits in unary, but you may not mix those.

I/O

The digits of the input numbers will be non-negative integers.
You may assume that the input numbers contain leading zeros, so the have a specific (or all the same) length.
You may take the numbers in the most convenient format, as long as it's not preprocessed. This includes the overall format of the three input numbers and the format of the digits of each of those numbers. Please make it clear which format you use.
If there are multiple possible bases, you can output all or just one of them.
You may assume that the base and the input numbers will be within the numerical limits of your language.

Rules

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

Test cases
Input format here is a list of integers to represent each number. The three lists are separated by commas.
Note that there are sometimes multiple bases possible. Only one (random) solution is outputted here.

[12, 103],[4, 101],[16, 204] -> 349
[4, 21, 25],[5, 1, 20],[9, 23, 17] -> 28
[16, 11],[25, 94],[41, 105] -> 147
[2, 140],[21, 183],[24, 100] -> 223
[8, 157],[1, 28],[9, 185] -> 227
[2, 158],[88],[3, 12] -> 234
[8, 199],[1, 34],[9, 233] -> 408
[3, 247],[7, 438],[11, 221] -> 464
[3, 122],[3, 2],[6, 124] -> 480
[6, 328],[3, 31],[9, 359] -> 465
[2, 1, 0, 0, 0, 0],[1, 2, 0, 0, 1, 0, 1, 0],[1, 2, 2, 1, 1, 0, 1, 0] -> 3
[16, 105],[16, 120],[33, 84] -> 141
[15, 60],[9, 30],[24, 90] -> 268
[2, 0],[1, 2],[3, 2] -> 5
[1, 3, 3, 7],[1, 2, 3],[1, 4, 6, 0] -> 10
[0],[1, 12, 8],[1, 12, 8] -> 16
[1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1],[1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1],[1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0] -> 2
[1],[1],[1,1] -> 1

You can generate additional test cases with this Pyth program. Enter a base on the first line and the decimal values for X and Y on the following two lines.
Also you can use this Pyth program to create multiple test cases at once by using random values. Just enter the desired amount of test cases in the input.
Happy Coding!

Jelly, 16 11 7 bytes

_/N,‘FṀ

This approach is heavily based on @beaker's Octave answer.

Input format is Z, Y, X, with little-endian digit order, using the digit 0 for unary.

Try it online! or run all test cases.

How it works

Rather than incrementally testing potential bases, this solves the polynomial that corresponds to the array P := X + Y - Z. This returns either the largest coefficient of P ≠ 0 – which has to be a root, since there is at least one valid base – or the highest digit of X, Y and Z, incremented by 1.

_/N,‘FṀ  Main link. Argument: [Z, Y, X]

_/       Reduce by subtraction; yield Z - X - Y.
         This works since Z must have at least as many digits as X and Y.
  N      Negate to yield X + Y - Z.
    ‘    Yield [Z, Y, X], with all digits increments by 1.
   ,     Pair the results to the left and to the right.
     F   Flatten the resulting, nested list.
      Ṁ  Compute the maximum.


Is it a super-prime? Background

A super-prime is a prime number whose index in the list of all primes is also prime. The sequence looks like this:

  3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, ...

This is sequence A006450 in the OEIS.

Challenge

Given a positive integer, determine whether it is a super-prime.

Test Cases

2: false
3: true
4: false
5: true
7: false
11: true
13: false
17: true
709: true
851: false
991: true

Scoring

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

Jelly, 5 bytes

ÆRÆNċ

Try it online!

How it works

ÆRÆNċ  Main link. Argument: n

ÆR     Prime range; yield the array of all primes up to n.
  ÆN   N-th prime; for each p in the result, yield the p-th prime.
    ċ  Count the occurrences of n.


National Scheduling Conflict Championships (I meant to post this while 1542: Scheduling Conflict
was still the current xkcd, but I had a scheduling conflict.)

Input

The input will be a list of 3n elements, which represent n events. The
first element in each group of 3 will be the name of an event; the second and
third, the start and end time respectively. For example:

foo 12 34 bar 56 78

represents an event foo that starts at "time 12" (times are represented
simply by integers; you can think of them as minutes past midnight) and ends at
34, and a second event bar that starts at 56 and ends at 78.

The names of events will always consist of only alphanumeric characters, and
the times will always be integers ≥ 0 and < 1440. The end time will always be
at least 1 greater than the start time. They are not guaranteed to be sorted in
any way.

If you would like, you may take this as a single space-separated string;
otherwise it should be taken as an array, list, vector, or your language's
equivalent.

Output

The output should be a space-separated list of event names. The rules for which
event names to output are as follows:

None of the events that you output may conflict with each other. For example,
with the input a 0 10 b 5 15, you may not output both a and b because
the times conflict (that is, partially overlap). If an event ends exactly as
another one starts, you may include both.
You may not output the event called NSCC ("National Scheduling Conflict
Competition"), of which there will always be exactly one of in the input.
You also must output at least one event that conflicts (partially
overlaps) with NSCC (and there will always be at least one of those as
well).
You must output as many events as possible while following the above two
rules. (This is so that you look as busy as possible, so that missing the
NSCC seems more credible.)

This may also be output as either a single space-separated string or an array,
list, vector, etc.

There can be more than one possible output.

Test cases

Note that the outputs listed are only examples. Your code may output something
different, as long as it still follows the three rules above (notably, this
means there must be the same amount of events as the example).

In: UnderwaterBasketWeavingConvention 50 800 NSCC 500 550
Out: UnderwaterBasketWeavingConvention

In: SconeEating 0 50 RegexSubbing 45 110 CodeGolfing 95 105 NSCC 100 200
Out: SconeEating CodeGolfing

In: VelociraptorHunting 0 300 NerdSniping 200 500 SEChatting 400 700 DoorknobTurning 650 750 NSCC 725 775
Out: NerdSniping DoorknobTurning

In: NSCC 110 115 A 100 120 B 120 140 C 105 135 D 100 105 E 135 500
Out: C D E

In: A 800 900 NSCC 700 1000 B 650 750 C 950 1050 D 655 660 E 660 665 F 1030 1040 G 1040 1060
Out: A D E F G

In: A 10 11 B 11 12 C 12 13 D 13 14 NSCC 15 1090 E 10 16
Out: E

Feel free to add more test cases in an edit if there are edge-cases that I
missed.

Rules

Your code must complete within 30 seconds for all of the provided test cases
(this is more of a sanity check, as it should probably complete much faster
for all the test cases combined) on a reasonable personal machine.
This is code-golf, so the shortest code in bytes wins.

SWI-Prolog, 537 524 516 502 447 436 bytes
z(A:B:C,[D:E:F|G]):-(A=D;B>=F;E>=C),(G=[];z(A:B:C,G)).
u([A|B],C):-z(A,C),(B=[];u(B,C)).
y([A,B,C|D])-->[A:B:C],(y(D);{_=_}).
d-->[A:_],{write(A),tab(1)},d;{_=_}.
l([H|T],R):-T=[],R=H;length(H,N),l(T,X),length(X,M),(N>M,R=H;R=X).
v([],_,R,R).
v([A|T],Z,B,R):-u(A,A),\+z(Z,A),v(T,Z,[A|B],R);v(T,Z,B,R).
s([E|T],[F|N]):-E=F,(N=[];s(T,N));s(T,[F|N]).
x(A):-y(A,D,[]),K="NSCC":_,select(K,D,E),setof(L,s(E,L),B),v(B,K,[],R),l(R,S),d(S,[]),!.

Brief explanation of what each predicate does:

z(A,B) checks that an event A doesn't conflict with any event of a list of events B
u(A,B) checks that every event of a list A does not conflict with any event of a list B (used to check that there are no conflicts in list A by calling u(A,A))
y(A,B,C) splits a List into a list of triplets (to transform inputs into a list of events)
d(A) prints the names of events in a list A
l(A,R) evaluates the longest list of events R contained in the list of lists A
v(A,NSCC,C,R) returns a list R containing every list of events in A that have no internal conflict and that conflict with the event NSCC
s(A,B) true if B is a subset of A
x(A) main predicate, A is the input.

Test cases: execute test. in the interpreter after loading the code above with the following added after it:
test:-
    x(["UnderwaterBasketWeavingConvention",50,800,"NSCC",500,550]),
    nl,
    x(["SconeEating",0,50,"RegexSubbing",45,110,"CodeGolfing",95,105,"NSCC",100,200]),
    nl,
    x(["VelociraptorHunting",0,300,"NerdSniping",200,500,"SEChatting",400,700,"DoorknobTurning",650,750,"NSCC",725,775]),
    nl,
    x(["NSCC",110,115,"A",100,120,"B",120,140,"C",105,135,"D",100,105,"E",135,500]),
    nl,
    x(["A",800,900,"NSCC",700,1000,"B",650,750,"C",950,1050,"D",655,660,"E",660,665,"F",1030,1040,"G",1040,1060]),
    nl,
    x(["A",10,11,"B",11,12,"C",12,13,"D",13,14,"NSCC",15,1090,"E",10,16]).

This took me way more time than I thought it would. This can probably be golfed significantly more. Also you could probably use the various constraint programming libraries that exist to get shorter solutions.
Edit: Thanks to @Oliphaunt for the idea of using A:B:C instead of [A,B,C] for triplets. Saves 14 bytes.
Edit2: Thanks again to @Oliphaunt for  pointing out that the predicate ``t/3`was useless. Saves 55 bytes
Edit3: Gained 11 bytes using definitive clause grammar on predicates y and d.