Identity sequences on the Rubik's Cube A move sequence is a sequence of moves (turns) on a Rubik's Cube (for the notation look down below). Beside the empty move sequence, there are many other other move sequences, that have no effect on the cube at all. We call these move sequences identity sequences.

Some of these identity sequences are obvious to determine, like U2 R R' U2 or U D2 U' D2. In the first one, two random moves are done U2 R and afterwards immediately undone R' U2. The second one is similar. First two random moves U D2 and afterwards they are undone, but in reversed order U' D2. This only works, because the move U effects only the pieces of the upper layer and the move D2 only effects pieces of the lower layer. You can see a visualization of these two move sequences.

Other identity sequences may be not obvious at all. For instance the sequence R' U' R' F' U F U' R' F R F' U' R U2 R. It pretty long, but also has no effect at the cube at all.

Move Notation

A move describes the turn of one layer of one of the six faces of the cube. A move consist of one letter representing the face followed by an optional suffix representing the turn angle.

The letters and their corresponding faces are U (Up - the side facing upwards), D (Down - the side facing downwards), R (Right - the side facing to the right), L (Left - the side facing to the left), F (Front - the side facing you) and B (Back - the side facing away from you).

If there is no suffix, the face is turned 90-degree clockwise, the suffix ' means, the face is turned 90-degree counterclockwise, and the suffix 2 means, the face is turned 180-degree clockwise.

It you have any problems with the notation, just use http://alg.cubing.net, where you can visualize such move sequences.

The Challenge

Your task is to write a program, that determines if a move sequences is an identity or not.

You may write a full program or a function. It should receive a string containing a move sequence (moves are separate by spaces) as input (via STDIN, command-line argument, prompt or function argument), and output (via return value or STDOUT) a Boolean value or a corresponding integer (True - 1 - identity sequence/ False - 0 - not identity sequence).

If you suffix ' creates problems in your programming language, you may use a different symbol, but not at digit. R F2 U3 is not allowed.

This is codegolf, therefore the shortest code (in bytes) wins.

Test Cases

"" -> True
"U2 R R' U2" -> True
"U D2 U' D2" -> True
"U2 R U2 R'" -> False
"R' U' R' F' U F U' R' F R F' U' R U2 R" -> True
"L'" -> False
"B B2 B' B2" -> True
"D D2 D'" -> False
"R F' D2 U B' F2 B' U2 D2 F2 B2 U F R'" -> True
"D2 U' R2 U F2 D2 U' R2 U' B' L2 R' B' D2 U B2 L' D' R2" -> False
"R U R' U' R' F R2 U' R' U' R U R' F' R2 U R2 U' R2 U' D R2 U' R2 U R2 D'" -> True
"R U R' U' R' F R2 U' R' U' R U R' F' R2 U' R2 U R2 U' D R2 U' R2 U R2 D'" -> False
"B2 F2 U' F2 U R2 F2 U2 B D' R' D' R2 D' F2 U' F U R2 U R B D B D2 L2 D' F2 U D' R' D B R2 D2 F2 R' F2 D2" -> True
"R U2 R' U R' U2 R U2 R U R' U' R' U R U2" -> False
"U F B' R' U F' R U' F' B L U' F L'" -> False
"R2 U' R' U' R U R U R U' R" -> False
"R' F R' B2 R F' R' B2 R2" -> False

Haskell, 263 261 247 243 characters

c[x]=[x]
c(x:"2")=[x,x]
c(x:_)=[x,x,x]
s!a@[x,y,z]=case s of
 'R'|x>0->[x,-z,y]
 'B'|y>0->[z,y,-x]
 'U'|z>0->[-y,x,z]
 'L'|x<0->[x,z,-y]
 'F'|y<0->[-z,y,x]
 'D'|z<0->[y,-x,z]
 _->a
r=[-2..2]
i=mapM id[r,r,r]
f w=i==foldr(map.(!))i(c=<<words w)

Rather straightworward algorithm; each cubelet is made out of 1,2,4 or 8 chunks encoding its position and orientation; 4 chunks per edge cubelet, 8 per corner cubelet, 7 cubelets are stationary.

c chomps each word of the input into a sequence of CW turns, and ! sends each chunk according to a turn. i is the identity position. f is the main function.

I'm not too happy with the chomp function, but I can't seem to find a way to shorten it either (@Nimi did, however)


JSFuck Golf - Hello World JSFuck is an esoteric language in which any Javascript statement can be accurately reproduced into another valid Javascript program that uses only the 6 characters []()!+.

The JSFuck converter, when given an input of alert("Hello World!"), produces a block of code that is 22,948 characters long. Because the program used a lot of automatic conversions to create that block, I believe that the code can be made a lot shorter using manual optimizations.

Your task is to build a Javascript program that performs the task alert("Hello World!"), using only the characters []()!+. The shortest code to do so wins.


Determine if all decimal digits are unique Deleted questions on Stack Overflow sometimes make for great golf material.

Write a function that takes a nonnegative integer as input, and returns true if all the digits in the base 10 representation of that number are unique. Example:

48778584 -> false
17308459 -> true

Character count includes only the function.

If you choose to answer in C or C++: no macros, no undefined behaviour; implementation-defined behaviour and compiler warnings are fine.

Golfscript, 8 7 characters:

{`..&=}

` - stringify the argument
.. - clone twice
& - intersect with itself (remove duplicates)
= - check for equality.

if the function needs to be named (10 9 characters):

{`..&=}:a

if a program suffices (5 4 characters):

..&=


Happy Birthday, Finland! Introduction

As is known, in 2017, Finland celebrates its 100 years of independence. To mark the occasion, it is your job to produce a Finnish flag for everyone's enjoyment.

Challenge

Create a program or a function that produces the flag of Finland (the grey border is there for presentation purposes only):

Flag specifications

The ratio of the flag is 18:11, with the cross being 3 units thick, giving a horizontal ratio set of 5:3:10 and a vertical ratio set of 4:3:4.
The picture must be at least 180 x 110 pixels in size, or in case of ASCII art, 90 x 55 characters.
There is no official RGB colour for the blue, but use the closest approximation of (0, 53, 128). If your system doesn't support RGB values, use blue.
For the white colour, use RGB (255, 255, 255) or white.

Not so fast

As drawing the Finnish national flag would be simpler than last year's Icelandic challenge, we'll have to ramp up the difficulty a bit. Given that Finland's Independence Day is on 6 December, the decimal number 100 must appear somewhere on the flag when the date in Finland (UTC+02:00) is 2017-12-06 or later (your code should not assume that the machine it's running on is set to a particular timezone). Before the date, the number must not be there. The number must be printed in black (RGB (0, 0, 0) or black) but its placement and font parameters are up to you.

An example of such a render (again, ignore the border):

For testing purposes, it would be nice to include two additional versions of your solution, one with a fixed date in the past and one in the future.

Rules

Standard loopholes are forbidden, as are built-in flag images/libraries. Also, your code must not take any input.

Finns don't like small talk, and this is code-golf, so don't waste characters!

C (Windows), 361 bytes

#import<time.h>
#import<windows.h>
C(x){SetConsoleTextAttribute(GetStdHandle(-11),x);}F(I,N,l,a,n,d)time_t n;struct tm*d;{system("mode 90,65");time(&n);d=gmtime(&n);n=d->tm_year<<24|d->tm_mon<<16|d->tm_mday<<8|d->tm_hour;for(a=l=I=15;I++<70;a=l=I<35|I>49?15:9)for(N=n>1963656468&I<17?C(240),printf("100"):0;N++<90;a=N-25?a:9,a=N-40||l==9?a:15)C(a),putchar(70);}

Unrolled:

#import <time.h>
#import <windows.h>

C(x)
{
    SetConsoleTextAttribute(GetStdHandle(-11),x);
}

F(I,N,l,a,n,d) time_t n;struct tm*d;
{
    system("mode 90,65");

    time(&n);
    d = gmtime(&n);
    n = d->tm_year<<24 | d->tm_mon<<16 | d->tm_mday<<8 | d->tm_hour;

    for(a=l=I=15; I++<70; a=l=I<35|I>49?15:9)
        for(N=n>1963656468&I<17?C(240),printf("100"):0; N++<90; a=N-25?a:9,a=N-40||l==9?a:15)
            C(a), putchar(70);
}

Output:

Output when UTC time >= 2017-12-05-22-00:

Add the following in the code after d=gmtime(&n); to try it:

d->tm_year = 117;
d->tm_mon = 11;
d->tm_mday = 5;
d->tm_hour = 21;


m3ph1st0s's programming puzzle 1 (C++) This is the first of a series of C++ puzzles for you. Hope you will enjoy.

So, puzzle no.1:

Given the following program:

#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}

Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:

#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}

A new line with 15 characters was inserted so it's ok. However it does not solve the problem.

If this is too simple for you, don't worry, more is coming!!

We can get rid of a=1 by moving it into another scope:

#include <iostream>
main()
{
int a=0;if(0)
    const int a=1;
    const int b=2;
    const float c=0.5;
    std::cout << a/b-a*c;
}

This is I think 13 characters. Or better yet get a new a that also results in 0:

#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
if(int a=2)
   std::cout << a/b-a*c;
}

That's 11 characters


Shut down the computer! Challenge:

In the programming language of your choice, shut down the machine that your code was executed on.

Rules

No shutting down by resource exhaustion (e.g.: forkbomb to force shutdown)
You are allowed to write code that only works in a specific environment/OS, if you wish.
Standard loopholes are forbidden

This is code-golf, thus the lowest amount of bytes wins!

Assembly (x86/x64, Linux, as), 22 21 19 bytes

mov  $0x58,       %al  # 2 bytes: b0 58
mov  $0xfee1dead, %ebx # 5 bytes: bb ad de e1 fe
mov  $0x28121969, %ecx # 5 bytes: b9 69 19 12 28
mov  $0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
int  $0x80             # 2 bytes: cd 80

Must be run as root.

This is equivalent to pressing the power button and not a safe way to power off your PC. Make sure you close all open applications and execute sync to flush all file system buffers before executing this program, to at least minimize the risk of file corruption.

Test run

$ as -o poweroff.o poweroff.s
$ ld -o poweroff   poweroff.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078
$ sudo sh -c 'sync && ./poweroff'
root's password:

Followed by darkness.

How it works

int $0x80 invokes a software interrupt. It works on both x86 and x64, but has been deprecated for over a decade now and should not be used in production code. x64 code should use syscall instead. x86 should use sysenter, but it is too cumbersome for code golf.

The resulting action from the syscall depends on registers EAX - EDX, ESI, and EDI. The Linux Syscall Reference shows all syscalls that are available via int $0x80.

When EAX holds 0x58 (88), reboot is called, which can also be used to power off, put to sleep, or hibernate the computer, as well as switching kernels and disabling or enabling the Ctrl - Alt - Del key combo.

At the start of the program – and by compiling with as or gcc -nostdlib, we can make sure that we're actually at the start of the program – most registers are set to 0. This includes EAX, so we can use mov $0x58, %al to set the lower 8 bits of EAX to 0x58, thus setting EAX itself to 0x58. This saves two bytes over manually zeroing the register with xor %eax, %eax and one more over the straighforward mov $0x58, %eax which encodes 0x58 in 32 bits.

The first two arguments to reboot are magic numbers, presumably to prevent accidental reboots, and are read from registers EBX and ECX. Unless these numbers are equal to certain constants, reboot refuses to perform any action.

The first magic number must equal 0xfee1dead (feel dead), probably referring to the power off / death of the PC.
The second magic number can be equal to four different constants, although the latter three did not work in ancient versions of Linux. All of them seem to refer to the subsequent power on / birth of the PC.

0x28121969 represents Linus Torvalds's birthday (December 28, 1969).
0x05121996 represents Patricia Torvalds's birthday (December 5, 1996).
0x16041998 represents Daniela Torvalds's birthday (April 16, 1998).
0x20112000 represents Celeste Torvalds's birthday (November 20, 2000).

Patricia, Daniela, and Celeste Torvalds are Linus Torvalds's three daughters.
The EDX register selects the type of "reboot" we want. 0x4321fedc is RB_POWER_OFF, shutting the PC down and powering it off.
Finally, the value of the ESI register is ignored for RB_POWER_OFF; the value of the EDI register is ignored entirely by reboot.

Alternate version, x64-only, 19 bytes

On x64, we can use a proper syscall for the same byte count.

mov     $0xa9,       %al  # 2 bytes: b0 a9
mov     $0xfee1dead, %edi # 5 bytes: bf ad de e1 fe
mov     $0x28121969, %esi # 5 bytes: be 69 19 12 28
mov     $0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
syscall                   # 2 bytes: 0f 05

The only differences lie in the instruction (syscall vs int $0x80), the value of __NR_REBOOT (0xa9 vs 0x58), and the involved registers.


Word with greatest repeat of letters Recently there was a question on Stack Overflow where the OP was trying to write a function to find the word in a string that has the most repeated letters. It is of course not hard to write one up in seconds, and I wrote one in Javascript as short as I can for fun. But I'm not an expert in code golfing, so I wonder how much shorter can this simple program be!

Challenge

Write a program or function that takes in a string of words and return or print the word with the most repeating single letters.

Rules:

Choose the word with the greatest number of repeating single letters (see examples below)
If no word has repeating letters, return -1.
If two words have the same maximum number of repeating letters, choose the one closer to the start of the string.
The shortest submission in bytes wins.

Input

Take as input a string consisting of one or more space-delimited words. Input can be from STDIN (or closest alternative), command line parameters, or function arguments.

Output

Print the output to STDOUT to return it.

Examples

Consider the string aaabbb cccc. This contains two words: aaabbb and cccc. The word aaabbb has 3 a's and 3 b's, and cccc has 4 c's. So the maximum number of repeated letters in aaabbb is 3 and the maximum in cccc is 4. We want to choose the word with the maximum number of repeated single letters, so the output for aaabbb cccc should be cccc.

Other test cases:

Today, is the greatest day ever!  --> greatest
This is a great day               --> -1
aaabbb cccc                       --> cccc

C - GCC - 159 145 135 Bytes
x=0,w=0,i,j,c;main(int _,char**z){while(--_)for(j=i=0;_[z][i];j=++i,x=c>x?w=_,c:x)for(c=0;j--;)c+=z[_][i]==z[_][j];puts(x?z[w]:"-1");}

Will update when I can truncate it a bit
How to compile:         gcc -w cg.c
How to run:             ./a.out word1 word2 aass ddaaa ssdddd
Output:                 ssdddd
No-Output/No-match:     -1
First off, I cheated a bit, by taking in the words as program arguments, but getting GCC to parse the words and give me a word count for free was too much reward to pass up.
How does it work?
We have 3 nested loops. The first incrementing through each word, the next two are mimicking a bubble sort to compare values. The first letter is never compared with itself, and each subsequent letter is compared to each previous letter. Whenever a word has more same letters than a previous word, the word is stored in x, and the count of how many same letters is also stored.
GCC Abuse
We use implicit global auto int delcarations for our integers. We allow argv to be an int instead of a char (currently a char, this is a TODO). We make use of default functions such as puts and getchar. We also make use of the comma operator to overload our trinary (conditional) operator.
Want 2 less bytes?
Replace "-1" with *z and name the file -1
Program unobfuscated and untested:
int main(int argc, char * argv[])
{
    int word = 0           // Current most repeat letters word
    int count = 0;        // Current most repeat letters
    int i, j, increment; // Counter variables

    while(--argc != 0) // While we have words from program parameters
    {
        for(j = i = 0; argv[argc][i] != '\0'; j = ++i) // Iterate through each letter until end of word
        {
            for(increment = 0; j > 0; j--) // Iterative backwards through each letter
            {
                if(argv[argc][i] == argv[argc][j])
                {
                    increment++;
                }
            }
            if(increment > count) // New greatest lettered word
            {
                word = argc;
                count = increment;
            }
        }
    }

    if(word == 0)
    {
        puts("-1");
    }
    else
    {
        puts(argv[word]);
    }

    return 0;
}


Find the Oxidation States Challenge

Find the oxidation states of each of the atoms in a given molecule. These can be output as a list or otherwise.

Rules

The total oxidation state of a molecule will always be zero. The total oxidation state is the sum of the oxidation states of each of the individual atoms in the molecule.

The following atoms have constant oxidation states:

Hydrogen, H, always has state +1
Oxygen, O, always has state -2
All Group 1 elements have a state +1
All Group 2 elements have a state +2
Fluorine, F, always has state -1
Chlorine, Cl, always has state -1

In monatomic molecules (such as H2 or S8), all of the atoms always have a state 0. I.e. (H2 is 0, 0 and S8 is 0, 0, 0, 0, 0, 0, 0, 0)

The Group 1 elements are: Li, Na, K, Rb, Cs, Fr. The Group 2 elements are: Be, Mg, Ca, Sr, Ba, Ra.

You will be able to work out the states of every atom in the molecule given. There will be no ambiguous inputs (i.e. you won't be given H2O2 or P4Br6).

You should output the oxidation states of the individual atoms, not the total state.

If there is an element which is not listed in the list above in the molecule, you need to work out its oxidation state yourself since the sum of the oxidation states of all the atoms adds up to zero.

The molecules do not have to exist in real life.

You will never get a single atom such as Ti or F.

Built-in functions which access data about oxidation states are disallowed.

Examples

Input > Output
H2O > +1, +1, -2
CO2 > +4, -2, -2
CH4 > -4, +1, +1, +1, +1
H2SO4 > +1, +1, +6, -2, -2, -2, -2
NaHCO3 > +1, +1, +4, -2, -2, -2
XeF8 > +8, -1, -1, -1, -1, -1, -1, -1, -1
TiCl2 > +2, -1, -1
P4 > 0, 0, 0, 0

Winning

The shortest code in bytes wins.

Ruby, 288 255 bytes

->m{h={[?O]=>-2,%w[F Cl]=>-1,%w[H Li Na K Rb Cs Fr]=>1,%w[Be Mg Ca Sr Ba Ra]=>2};a=m.scan /([A-Z][a-z]*\d*)/;r=a.flat_map{|(b)|b=~/(\D+)(\d*)/;[a.size==1?0:h[h.keys.find{|v|v.include?$1}]]*($2=='' ? 1:$2.to_i)};r.map{|j|j||-((r-[p]).inject:+)/r.count(p)}}

Try it online!

Saved 1 byte thanks to Jenkar
Saved 32 more bytes by inlining definitions and removing parentheses

Ungolfed
oxidation_state = -> molecule {
    h = {
        %w[H] => 1,
        %w[O] => -2,
        %w[F] => -1,
        %w[Cl] => -1,
        %w[Li Na K Rb Cs Fr] => 1,
        %w[Be Mg Ca Sr Ba Ra] => 2,
    }
    find_oxidation = -> a {
        k = h.keys.find { |as| as.include?(a) }
        h[k]
    }
    atoms = molecule.scan(/([A-Z][a-z]*\d*)/)
    r = atoms.flat_map { |(a)|
        a.match(/([^\d]+)(\d*)/)
        [atoms.length == 1 ? 0 : find_oxidation[$1]] * ($2=='' ? 1 : $2.to_i)
    }
    r.map { |j|
        sum = r.compact.inject(:+)
        !j ? -sum / r.count(nil) : j
    }
}


Stealing sequences: Cops This is cops-and-robbers. This is the Cops thread. For the robbers thread, go here.
I've noticed a number of OEIS (On-line Encyclopedia of Integer Sequences) challenges since I joined the site. It seems only fair that we have a cops-and-robbers challenge that determines who is the master of online integer sequences, once and for all.
Edit: In order to prevent trivial answers, cops lose 1/2 point for each submission that is cracked. Additionally, for the purposes of this challenge, constant sequences are not allowed. This only applies to solutions posted after this edit.
Cops
Write a program or function that, given no input, deterministically prints any sequence from the OEIS. By deleting some subset of the characters, your program must be able to print a different OEIS sequence when run in the same language. The new sequence must be entirely new, not just the first by a different name or with a different offset. Neither sequence may be simply a repeated constant value.
You must provide the first function, along with the name of the OEIS sequence so correctness can be verified. It's OK if behavior gets questionable around your language's MAX_INT value or 256, whichever is larger.
Robbers
Delete characters from some Cop's submission such that your new program outputs any other sequence from the OEIS. Provide the new function along with the name of the new OEIS sequence. Here is a utility to make sure that your submission is valid (i.e. deletes characters without any funny business.  Doesn't check the sequence itself.)
It's in your best interest to delete as many characters from the Cop's submission as possible. If another robber (anyone except the Cop who authored the original program) comes along and finds a shorter solution that finds another different sequence, that robber steals your point. (Note that simply golfing off characters and printing the same sequence is not sufficient to steal the point.)
Rules & Scoring
If, after one week, nobody has been able to crack your solution, you can mark your solution as safe by providing the second program along with the name of the sequence it generates.
You get one point for each safe posting and one point for each submission you crack. Cops lose 1/2 point for each cracked submission. Note that another robber can steal your point from the cracked submission at any time by providing a shorter program that yields a different sequence.
Cops may only post one challenge per language, per person.
The player with the most points at 12:00 UTC on 7 July wins.

MarioLANG, 23 bytes cracked

   >+
 :<":
>+^!<
===#=

Try it online!

produces the odd numbers A005408


The thousand character classic Background

The Thousand Character Classic is a chinese poem written around the 4th Century CE in China, and memorized by large populations since then. The name comes from not only its length, but its number of characters: each character occurs only once in the text. It is commonly used to teach children chinese characters, and also, because of its commonness, as a means of enumerating the 1000 characters in the text.

The challenge

Here is a copy of the Thousand Character Classic, gotten from Wikipedia.

The Thousand Character Classic

Reproduce the entirety of the Thousand Character Classic in either UTF-8 or UTF-16, including punctuation, newlines, and heading numbers. Punctuation can be halfwidth or fullwidth, and the trailing newline is optional.

For those that want to analyze the unicode text for patterns, I've provided hexdumps of both encodings.

utf-8

utf-16

Rules

Because of the size of the text to reproduce, you may optionally supply a file for your submission to use as input. If this is done, add the byte length of the input file to the byte length of your code.

Otherwise, this is a standard issue code golf challenge, so standard loopholes apply, and shortest submission wins.

C, 50 + 3008 = 3058 bytes

I've tried out several simple compression methods, and found that outputting the UTF-16 input (trailing newline removed) directly is the best way. Input from stdin.

int b[999];main(){read(0,b,3008);write(1,b,3008);}

Python 3, 62 + 2145 = 2207 bytes

Evil built-in. Input filename is A, which is an xz-compressed file of UTF-16 version.

import lzma
print(lzma.open('A','rt',encoding='utf16').read())

Compressor code:

import lzma
open('A','wb').write(lzma.compress(open('utf16_file.txt','rb').read(),lzma.FORMAT_ALONE))


Pre-order + post-order to in-order Task

Given the pre-order and post-order traversals of a full binary tree, return its in-order traversal.

The traversals will be represented as two lists, both containing n distinct positive integers, each uniquely identifying a node. Your program may take these lists, and output the resulting in-order traversal, using any reasonable I/O format.

You may assume the input is valid (that is, the lists actually represent traversals of some tree).

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

Definitions

A full binary tree is a finite structure of nodes, represented here by unique positive integers.

  A full binary tree is either a leaf, consisting of a single node:

                                      1

  Or a branch, consisting of one node with two subtrees (called the left and right subtrees), each of which is, in turn, a full binary tree:

                                      1
                                    /   \
                                  …       …

Here’s a full example of a full binary tree:

                                        6
                                      /   \
                                    3       4
                                   / \     / \
                                  1   8   5   7
                                     / \
                                    2   9

The pre-order traversal of a full binary tree is recursively defined as follows:

  The pre-order traversal of a leaf containing a node n is the list [n].
  The pre-order traversal of a branch containing a node n and sub-trees (L, R) is the list [n] + preorder(L) + preorder(R), where + is the list concatenation operator.

For the above tree, that’s [6, 3, 1, 8, 2, 9, 4, 5, 7].

The post-order traversal of a full binary tree is recursively defined as follows:

  The post-order traversal of a leaf containing a node n is the list [n].
  The post-order traversal of a branch containing a node n and sub-trees (L, R) is the list postorder(L) + postorder(R) + [n].

For the above tree, that’s [1, 2, 9, 8, 3, 5, 7, 4, 6].

The in-order traversal of a full binary tree is recursively defined as follows:

  The in-order traversal of a leaf containing a node n is the list [n].
  The in-order traversal of a branch containing a node n and sub-trees (L, R) is the list inorder(L) + [n] + inorder(R).

For the above tree, that’s [1, 3, 2, 8, 9, 6, 5, 4, 7].

In conclusion: given the pair of lists [6, 3, 1, 8, 2, 9, 4, 5, 7] (pre) and [1, 2, 9, 8, 3, 5, 7, 4, 6] (post) as input, your program should output [1, 3, 2, 8, 9, 6, 5, 4, 7].

Test cases

Each test case is in the format preorder, postorder → expected output.

[8], [8] → [8]
[3,4,5], [4,5,3] → [4,3,5]
[1,2,9,8,3], [9,8,2,3,1] → [9,2,8,1,3]
[7,8,10,11,12,2,3,4,5], [11,12,10,2,8,4,5,3,7] → [11,10,12,8,2,7,4,3,5]
[1,2,3,4,5,6,7,8,9], [5,6,4,7,3,8,2,9,1] → [5,4,6,3,7,2,8,1,9]

Perl, 69 66 62 56 53 bytes

Includes +1 for -p

Takes postorder followed by preorder as one line separated by space on STDIN (notice the order of pre and post). Nodes are represented as unique letters (any character that is not space or newline is OK).

inpost.pl <<< "98231 12983"

inpost.pl:

#!/usr/bin/perl -p
s%(.)(.)+\K(.)(.+)\3(\1.*)\2%$4$5$3$2%&&redo;s;.+ ;;

Using the original purely numeric format needs a lot more care to exactly identify a single number and comes in at 73 bytes

#!/usr/bin/perl -p
s%\b(\d+)(,\d+)+\K,(\d+\b)(.+)\b\3,(\1\b.*)\2\b%$4$5,$3$2%&&redo;s;.+ ;;

Use as

inpostnum.pl <<< "11,12,10,2,8,4,5,3,7 7,8,10,11,12,2,3,4,5"


Intersection of two triangles Given 4 points on the 2D planes A, B, C, D, calculate the area of the intersection region of the triangles OAB and OCD, where O is the center of the plane, having coordinate (0, 0).

Algorithms that runs in constant time complexity (in terms of arithmetic operations) are encouraged, but not forced.

Rules

Each point is represented as two real numbers, denotes their X and Y coordinate.

Optionally, if your programming language (or some library of your programming language) has built-in Point type or equivalent, it is allowed to take Point object as input.

The input is given as 4 points, in the formats, including but not limited to:

A list of 8 coordinates.
A list of 4 points, each point can be represented in any convenient format.
Two lists of 2 points.
etc.

You cannot assume particular ordering of the points (counter-clockwise order or clockwise order)
You cannot assume that the point O is passed as input. In other word, program must not take and use extraneous input.
You cannot assume all the points are different. In other words, the triangles may be degenerate. You need to also handle that case (see test cases below)
The absolute or relative difference must be less than 10-3 for the sample test cases below.

Winning criteria

This is code-golf, the shortest answer in bytes win!

Sample test cases

Ax Ay Bx By Cx Cy Dx Dy area

5 1 1 3 -1 0 0 -1 0
5 1 1 3 -1 0 0 0 0
5 1 1 3 0 0 0 0 0
5 1 1 3 3 4 4 -3 4.50418
5 1 1 3 1 2 2 1 1.5
5 1 1 3 -2 5 4 -2 1.74829
5 1 1 3 -2 5 5 4 2.96154
5 1 1 3 3 5 5 4 1.88462
5 1 1 3 3 5 3 1 3.92308
5 1 1 3 3 5 4 -1 5.26619
5 1 1 3 5 1 4 -1 0
5 1 1 3 5 1 1 3 7
1 3 1 3 5 1 1 3 0
1 3 1 3 1 3 1 3 0
4 8 4 -1 -2 6 -2 -3 0

1.2 3.4 -0.3 4.2 5 7.6 -1.1 2.4 2.6210759326188535
3.1 0.6 0.1 7.2 5.2 0.7 0.9 8 9.018496993987977

If anyone want, here are the outputs for the first test case group in exact form:

0
0
0
46375/10296
3/2
1792/1025
77/26
49/26
51/13
23345/4433
0
7
0
0
0

Illustration image for test case 5 1 1 3 3 4 4 -3 (the area of the green quadrilateral is the expected output):

[]

Wolfram Language (Mathematica), 55 bytes

0&@@Area@BooleanRegion[And,Simplex[{0{,}}~Join~#]&/@#]&

Try it online!

Shaved a few bytes off the trivial answer.

%@{{{5, 1}, {1, 3}}, {{3, 4}, {4, -3}}} yields 46375/10296 or 4.504176379

Replacing Area with DiscretizeRegion will show the intersection.

By the way, this will work with any simplexes, not just triangles.

-1 Byte thanks to JungHwan Min

@user202729's suggestion added 4 bytes but makes it yield 0 for degenerate triangles


Build an alphabetised polyglot As TIO can show, every letter of the Latin alphabet is represented when it comes to languages. For every letter there is at least 1 programming language whose name begins with that letter. Your task is to create a polyglot in order to demonstrate that.
Your program should be runnable in between 2 and 26 different languages, each of which starts with a different letter. However, if your program runs in \$N\$ languages, the languages used must have the first \$N\$ letters of the alphabet as the first letter of their names. So if your program runs in 5 languages, the languages must start with A, B, C, D and E. (e.g. A Pear Tree, BrainSpace, C++, Dash and Enlist)
Your program should take no input, and output a constant string: the alphabet (case-irrelevant, in order), but with the letter of the language name removed. So the language beginning with A should output BCDEFGHIJKLMNOPQRSTUVWXYZ (or the equivalent lower case version). Case doesn’t have to be consistent for different languages, but it does between runs in the same language.
Any languages are fair game, so long as no letters are repeated. This rules out using different versions for most languages (e.g. Python 2 vs Python 3), but this is only as a consequence of having unique letters. Seriously and Actually, for example, are considered different versions, but can both be used in the same answer as they start with different characters.
If using languages with custom code pages, then, as is standard, the bytes must match between programs, not characters.
Submissions are scored by number of languages used, with a tie breaker of shortest code.

AsciiDots, Bash, Cardinal, Dash, evil, fish, goruby, Haystack, Implicit, J-uby, ksh, Ly, mksh, Numberwang, OSH, Python 3, QuadR, Ruby, Super Stack!, Taco, Unefunge-98 (Pyfunge), V (Vim), Wumpus, xonsh, yash, Zsh, 1009 bytes
9 shells, 3 Rubies, some 2D (and 1D!) languages and many languages I learned just for this challenge. I really enjoyed this challenge and learned some new languages and features. I enjoyed finding a shorter way than just the raw string in some languages (in some languages generating the string seemed longer) and trying to re-use the s variable as many times as possible was fun too. I've also tried to keep the byte-count as low as possible. If I find the time and the inclination, I wonder if I could start adding the letters of the alphabet to the end instead... Crazy talk...
' # "194940711909711999999999999940391270919999999999994039127zaeeeawawawawavaeeaaaaamvawvusb"' #165#1#1;.040;"ZYXWVTSRQPONMLKJIHGFEDCBA"8 3*k,q"ABCDEFGIJKLMNOPQRSTUVWXYZ"o¡72"8:é9:é8++:90+1®;65µ
'\&p"A""K"R"M""Z"R&o;';#   x%"ABDEFGHIJKLMNOPQRSTUVWXYZ"x.-$"BCDEFGHIJKLMNOPQRSTUVWXYZ" 0 65 65 if pop dup dup 83 sub if pop outputascii 0 fi pop 1 add dup 91 sub fi "ZYXVUTSRQPONMLKJIHGFEDCBA"#25&o   @"ABCDEFGHIJKLMNOPQRSUVWXYZ"
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'
0//1;
try:echo -n;print(s[0:23]+"YZ");
except:print(s[0:15]+s[16:]);"""/.__id__;begin ~:*;puts s.gsub ?J,"";rescue;begin A;puts s.gsub ?G,"";rescue;puts s.gsub ?R,"";end;end;'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;';/
('Q'⎕R'')⎕A⋄'\} #<esc>ggdG¬AZ:s/#\|V//"""#\'⍵

AsciiDots
The relevant code is:
.-$"BCDEFGHIJKLMNOPQRSTUVWXYZ"

This needs to be wrapped in [...] to avoid [Extended Brainfuck Type I] from outputting rubbish before the desired string because of the ..
Try it online!
Bash
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

This first line sets $s to be the full alphabet in uppercase, so -z  $s is false and skipped over. $status is unset, \e is treated as an escape, not a \ and e, $BASHPID is set, $_OVM_PATH is not and $USER_ID isn't set so B is replaced with the empty string in $s (${s/B/}) and echoed it out.
Try it online!
Cardinal
The relevant code is:
x%"ABDEFGHIJKLMNOPQRSTUVWXYZ"x

The cursors spawn from the % and are terminated by the xs. This needed to be moved slightly to prevent additional output.
Try it online!
Dash
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

As per Bash, this first sets $s to be the full alphabet in uppercase. so -z $s is false. $status is empty, \e is an escape sequence and doesn't match e, but $- is empty in Dash so that conditional is met and we echo out ABC followed by $s with the prefix ABCD removed (${s#ABCD}).
Try it online!
evil
The relevant code is:
zaeeeawawawawavaeeaaaaamvawvusb

Try it online!
fish
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

In fish, variables aren't assigned via the s=... syntax so $s is empty meaning the first conditional is hit, the required string is echoed out and then exit is called.
Try it online!
goruby + --disable=gems
This isn't available on TIO, but is distributed with the official Ruby source and can be compiled (after the normal autoconf and ./configure steps) with make goruby. Tested on version ruby 2.8.0dev (2020-08-24T10:24:07Z master 1eb1add68a) [x86_64-linux]. The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0
0//.../.__id__;begin ~:*&?,;puts s.gsub ?J,"";rescue;begin A;puts s.gsub ?G,"";rescue;puts s.gsub ?R,"";end;end

Haystack
The relevant code is:
"ABCDEFGIJKLMNOPQRSTUVWXYZ"o

which outputs the required string.
Try it online!
Implicit
The relevant code is:
¡72"8:é9:é8++:90+1®;65µ

This pushes  the range of 1..72 and joins the last 8 items on the stack to a string, duplicates the top the stack, increments all codepoints by 9, duplicates the stack again, increments all codepoints in the string by 8, pushes 90 to the stack and concatenates all, reverses the stack, pop off the top 65 elements then prints the stack.
Try it online!
J-uby
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0
0//.../.__id__;begin ~:*&?,;puts s.gsub ?J,"";rescue;begin A;puts s.gsub ?G,"";rescue;puts s.gsub ?R,"";end;end

This shares the declaration of s with the shells and other Ruby implementations and and .gsubs J from the string before putsing it as long as ~:*&?, doesn't cause an error.
Try it online!
ksh
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

$s is set as the other shells and $status is empty, \e doesn't match e, $- is not empty, but $BASHPID is so $s is echoed removing K (${s/K/}).
Try it online!
Ly
The relevant code is:
&p"A""K"R"M""Z"R&o;

which first clears the stack then pushes the Ranges from A-K and M-Z, before &outputting the stack contents and terminating (;).
Try it online!
mksh
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

As per the previous shells, the first line sets $s to be the full alphabet in uppercase, so -z $s is false and skipped over. $status is unset, \e is treated as an escape, not a \ and e, $BASHPID is set, $_OVM_PATH is not and $USER_ID is set so M is replaced with the empty string in $s (${s/M/}) and echoed it out. Tested on version 58-1.
Numberwang
The relevant code is the big number as Numberwang is just a transliteration of brainfuck:
194940711909711999999999999940391270919999999999994039127
>+[+[<]>>+<+]>>+++++++++++++[<.+>-]<+>++++++++++++[<.+>-]

There's a minor amount of work to balance 4s and 7s throughout the rest of the code, alongside making sure things appear in the right order, but nothing major. Might be able to save some bytes by moving stuff around here...
Try it online!
OSH
Oh look, another shell! As per the others the relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

The main difference here is that $_OVM_PATH is set in OSH, but not in Bash, so the correct string is echoed using tr to remove the O.
Try it online!
Python 3
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0
0//1;
try:echo -n;print(s[0:23]+"YZ");
except:print(s[0:15]+s[16:]);"""..."""

This shares the declaration of s with the shells and Rubies and is also shared with xonsh. The code in the try will fail in Python (echo -n), but works in xonsh so the code in the except is called, printing slices of s.
Try it online!
QuadR
The relevant code is:
('Q'⎕R'')⎕A⋄'...'⍵

In QuadR, when the final line contains ⍵ all the preceding lines are patterns to match and the final line is a transformation function. This particular transformation function just takes the alphabet ⎕A and ⎕Replaces 'Q' with '', the rest of the function after the statement separator (⋄) is just to close off all the other strings/comments/regex literals and comment out the end of the function.
Try it online!
Ruby
The relevant code is shared with J-uby and goruby:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0
0//.../.__id__;begin ~:*&?,;puts s.gsub ?J,"";rescue;begin A;puts s.gsub ?G,"";rescue;puts s.gsub ?R,"";end;end

Like the other Rubies, s is shared from the shells but in Ruby here, both the other clauses ~:*&?, and A will raise exceptions so the final statement is executed which replaces R in s with the empty string.
Try it online!
Super Stack!
The relevant code is:
0 65 65 if pop dup dup 83 sub if pop outputascii 0 fi pop 1 add dup 91 sub fi

This pushes 0 and 65 (twice) to the stack, then if (which is "while top of stack is truthy" - non-zero), pops the top element, duplicates the new top element twice, pushes 83 and subtracts it from the next stack item down. Then if top of stack is truthy (e.g. it's not 83 - S), pop it, outputascii, push 0 and terminate with fi (since top of stack is now 0). Finally, pop, push 1, add the two top elements together (increment), duplicate, push 91 and subtract, terminate the loop, which will happen if the last output char was 90 (Z).
Try it online!
TacO
The relevant code is:
@"ABCDEFGHIJKLMNOPQRSUVWXYZ"

Try it online!
Unefunge-98 (PyFunge)
The relevant code is:
"ZYXWVTSRQPONMLKJIHGFEDCBA"8 3*k,q

There are a few commands before this that are executed and push things to the stack, but basically this just pushes the required chars in reverse, then pushes 8 and 3 and multiplies them. The k command repeats the next command TOS (24) + 1 times, outputting the required string and quits.
Try it online!
V (vim) + -v
The relevant code is:
<esc>ggdG¬AZ:s/V//"...

Which first leaves insert mode (<esc>), goes to the first line of text (gg), deletes to the last line (dG), inserts the letters from A to Z (¬AZ), then finally replaces V with the empty string (:s/V//). The rest of the line is commented out (").
Try it online!
Wumpus
The relevant code is:
...#220#1#1;.
..."ZYXVUTSRQPONMLKJIHGFEDCBA"#25&o @

The #220#1#1 pushes 220, 1, 1 to the stack, then ; pops off the last item then calls . which jumps the IP to line 1, char 220 and executes. We need to just because TacO mandates only one @ in the code.
Try it online!
xonsh
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0
0//1;
try:echo -n;print(s[0:23]+"YZ");
except:print(s[0:15]+s[16:]);"""..."""

xonsh is a Python based shell so the code is shared with Python 3 and uses the same s var as the shells and Rubies. I've used a technique I've used in many polyglots with Ruby to get this code in. 0//1 is integer division and the echo -n works fine since xonsh is a shell so the execution of printing the required substring portion of s with the literal string YZ concatenated, then the rest of the program is a """ string.
yash
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

Like the other shells, but in yash, the sequence \e is not an escape sequence and so is just the string \e which matches e so $s is printed substituting Y for the empty string (${s/Y/}).
Try it online!
Zsh + --continueonerror
The relevant code is:
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";0#'...'
[ -z $s ]&&echo ABCDEGHIJKLMNOPQRSTUVWXYZ&&exit;echo `[ $status = 1 ]&&echo \${s/Z/}&&exit;[ \e =~ e ]&&echo \${s/Y/}&&exit;\[ -z \$- \]&&echo ABC\${s#ABCD}&&exit;[ -z \$BASHPID ]&&echo \${s/K/}&&exit;[ -z $_OVM_PATH ]||echo $s|tr -d O;[ -z $_OVM_PATH ]||exit;[[ -n $USER_ID ]]&&echo \${s/M/}||echo \${s/B/}`;'...' #

Zsh is less tolerant of errors in a script than the other shells and so necessitates the --continueonerror flag. In Zsh $status is also set (in fish too) when a command fails, so if $status is 1, then $s is echoed out, substituting Z for the empty string (${s/Z/}).
Try it online!

Validation suite.


Draw random black-and-white forest Your task is to write program which will draw 800x600 black-and-white image with something resembling a forest.

Like this (it is dithered photo):

Rules

You are disallowed to use any existing images - you should generate image purely algorithmically
Use only 2 colors - black and white (no grayscale)
Each time program runs image should be new - random every time
One tree is not a forest (let say 5 trees minumum)
Special libraries for drawing trees/forests are disallowed
Answer with most votes wins

C: 3863 1144 1023 999 942 927

The original solution saves 2 pnm files per run (one with g appended, before dithering). Because the dithering wasn't beautiful for the first few lines, there is a hack in place to render more lines than needed, and crop during output.

The golfed solution has a simpler dithering and saves only the dithered image.
(no warnings with gcc -std=c11 -pedantic -Wall -Wextra)

Example images from 3 original program runs and one run of the golfed version (last image):

Golfed version

  #include <math.h>
  #include <time.h>
  #include <stdlib.h>
  #include <stdio.h>
  #define D float
  #define R rand()/RAND_MAX
  #define Z(a,b,c) if(10.*R>a)T(h,s,j+b+c*R,g);
  #define U a[y][x]
  #define V e[y+1][x
  #define F(x) for(i=0;i<x;++i)
  int i,x,y,W=800,H=600;unsigned char a[600][800],c;D e[601][802],r,b,k,l,m,n,f,w,
  d,q=.01;void T(D h,D s,D j,D g){r=b=0;do{j+=.04*R-.02;h+=sin(j)*q;s+=cos(j)*q;b
  +=q;g+=q;f=525/d;r=.25-g/44;m=w*f+s*f+W/2;n=2*f-h*f+H/2;f*=r;for(y=n-f-2;y<n+f+2
  ;++y)if(y>=0&&y<H)for(x=m-f-2;x<m+f+2;++x)if(x>=0&&x<W)if(k=m-x,l=n-y,f>sqrt(k*k
  +l*l))if(U>d*3)U=d*3;}while(b<10*r+12*r*R&&r>q);if(r>q){Z(2,.26,.35)Z(2,-.26,-
  .35)Z(7,-.05,.1)}}int main(){FILE* o=fopen("i","wb");srand(time(0));F(W*H){y=i/W
  ;a[y][i%W]=(y<313)?255:6e3/(2*y-H);}F(200)w=1e2*R-60,d=80.*R+5,T(0,0,1.58,0);F(W
  *H){x=i%W;y=i/W;k=U+e[y][x+1];U=-(k>0);l=(k-U)*.1;e[y][x+2]+=l*4;V]+=l*2;V+1]+=l
  *3;V+2]+=l;}fprintf(o,"P5 800 600 255 ");fwrite(a,1,W*H,o);}

Original version

  #include <math.h>
  #include <stdio.h>
  #include <stdlib.h>

  #define W 800
  #define H 600
  #define SPEED 0.01
  #define HEIGHT 11.0

  #define R(m) ((double)(m) * rand() / RAND_MAX)
  #define RAD(deg) ((deg) / 180.0 * M_PI)
  #define LIMIT(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))

  void shade(void);
  void growTree(double dist, double side, double h, double s, double alpha, double grown);
  void plot(double dist, double side, double h, double s, double alpha, double diam);
  void dither(void);
  void writeImg(int dither);

  unsigned char img[H+10][W];
  double err[H+10+2][W+4];
  long tim;

  int main(void)
  {
     int i;
     tim = time(0);
     srand(tim);
     shade();
     for(i = 0; i < 200; ++i)
     {
        growTree(5 + R(75), -60 + R(120), 0.0, 0.0, RAD(90), 0.0);
     }
     writeImg(0);
     dither();
     writeImg(1);
  }

  void shade(void)
  {
     int y;
     for(y = -10; y < H; ++y)
     {
        double dist = H * 3.5 / (2 * y - H);
        unsigned char color = dist / 80 * 255;
        if(y <= H / 2 || dist > 80) color = 255;
        memset(img[y+10], color, W);
     }
  }

  void growTree(double dist, double side, double h, double s, double alpha, double grown)
  {
     double diam, branchLength = 0.0;

     do
     {
        alpha += R(RAD(3)) - RAD(1.5);
        h += sin(alpha) * SPEED;
        s += cos(alpha) * SPEED;
        branchLength += SPEED;
        grown += SPEED;
        diam = (1.0 - grown / HEIGHT) * 0.5;
        plot(dist, side, h, s, alpha, diam);
     } while(branchLength < 5 * diam + R(6 * diam) && diam > 0.02);

     if(diam > 0.02)
     {
        int br = 0;

        if(R(10) > 2) br++,growTree(dist, side, h, s, alpha + RAD(15) + R(RAD(20)), grown);
        if(R(10) > 2) br++,growTree(dist, side, h, s, alpha - RAD(15) - R(RAD(20)), grown);
        if(R(10) < 2 || br == 0) growTree(dist, side, h, s, alpha - RAD(2.5) + R(RAD(5)), grown);
     }
  }

  void plot(double dist, double side, double h, double s, double alpha, double diam)
  {
     int x, y;
     double scale = H / 4.0 * 3.5 / dist;
     double x0 = side * scale + s * scale + W / 2.0;
     double y0 = H / 2.0 + 2.0 * scale - h * scale;
     diam *= scale;
     h *= scale;
     s *= scale;
     for(y = y0 - diam / 2 - 2; y < y0 + diam / 2 + 2; ++y)
     {
        if(y < -10 || y >= H) continue;
        for(x = x0 - diam / 2 - 2; x < x0 + diam / 2 + 2; ++x)
        {
           double dx, dy, d;
           if(x < 0 || x >= W) continue;
           dx = x0 - x;
           dy = y0 - y;
           d = diam / 2 - sqrt(dx * dx + dy * dy) + 0.5;
           if(d > 0)
           {
              unsigned char color = dist / 80 * 255;
              if(img[y+10][x] > color) img[y+10][x] = color;
           }
        }
     }
  }

  void dither(void)
  {
     int x0, x, y;
     for(y = -10; y < H; ++y)
     {
        for(x0 = 0; x0 < W; ++x0)
        {
           double error, oldpixel;
           unsigned char newpixel;
           if(y%2) x = W - 1 - x0;
           else x = x0;
           oldpixel = img[y+10][x] + err[y+10][x+2];
           newpixel = oldpixel > 127 ? 255 : 0;
           img[y+10][x] = newpixel;
           error = oldpixel - newpixel;
           err[y+10  ][x+1+2*(1-y%2)] += error * 7 / 48;
           err[y+10  ][x+4*(1-y%2)] += error * 5 / 48;
           err[y+10+1][x  ] += error * 3 / 48;
           err[y+10+1][x+1] += error * 5 / 48;
           err[y+10+1][x+2] += error * 7 / 48;
           err[y+10+1][x+3] += error * 5 / 48;
           err[y+10+1][x+4] += error * 3 / 48;
           err[y+10+2][x  ] += error * 1 / 48;
           err[y+10+2][x+1] += error * 3 / 48;
           err[y+10+2][x+2] += error * 5 / 48;
           err[y+10+2][x+3] += error * 3 / 48;
           err[y+10+2][x+4] += error * 1 / 48;
        }
     }
  }

  void writeImg(int dither)
  {
     FILE* fp;
     char buffer[32];
     sprintf(buffer, "%ld%s.pnm", tim, dither ? "" : "g");
     fp = fopen(buffer, "wb");
     fprintf(fp, "P5\n%d %d\n255\n", W, H);
     fwrite(&img[10][0], 1, W * H, fp);
     fclose(fp);
  }


How many squares are guarded by chess queens? Today marks the 15th anniversary of Garry Kasparov's defeat against Deep Blue. Speaking of chess...
Input is a string that represents an 8x8 chess board containing only empty squares (.) and queens (Q). Output the number of squares that any queen can move to the next move. Queens can move any number of squares vertically, horizontally or diagonally.
Write either a program or a function. Shortest code wins, but most inventive solution gets the most upvotes.
Examples
Input:
Q.......
........
.Q......
........
........
........
........
........

Output:
37

Input:
QQQQQQQQ
QQQQQQQQ
QQQQQQQQ
QQQQ.QQQ
QQQQQQQQ
QQQQQQQQ
QQQQQQQQ
QQQQQQQQ

Output:
1

APL, 40 characters

≢⍸a<∨/(⍳8 8)∘.{∨/⊃=/(⊢,+/,-/)¨⍺⍵}⍸a←'Q'=

⍸a←'Q'= transforms the matrix in a nested vector whose elements are the coordinates of the given queens.

(⊢,+/,-/) returns for every cell: the coordinates, their sum, their difference.

{∨/⊃=/(⊢,+/,-/)¨⍺ ⍵} returns 1 if cells ⍺ & ⍵ share one coordinate, the coordinates sum or the coordinates difference; that is gives 1 if a queen can move orizontally, vertically or diagonally from ⍺ to ⍵.

⍵∘.{∨/⊃=/(⊢,+/,-/)¨⍺⍵}⍳8 8 applies the previous function to each queen and each cell in the chessboard.

∨⌿ returns the boolean matrix of cell reachable from some queens
≢⍸a< counts the cell reachable by the queens and not already occupied by queens.


Print rotation-safe numbers Background

You are working for some board-game manufacturer and need to produce wooden tiles with the numbers from 0 to n engraved on them for some game. However, without further ado, some tiles would become indistinguishable, e.g., 6 and 9. To avoid this, you have to equip numbers that can be confused with others (and only those) with a disambiguating dot, e.g., you would have tiles like 9. or 6089..

Unfortunately, you need to use some old, yet programmable wood-engraving device for this, whose interface is so broken that you have to encode every character of the program by hand in an unspeakably tedious process. Fortunately the device understands every existing programming language. Thus you are looking for the shortest program that prints such tiles.

Actual task

Write the shortest program that:

Takes a positive integer n as input. How the input is read is up to you.
Prints each of the numbers from 0 to n (0 and n included) exactly once in an order of your choice, separated by a single whitespace character (including newline). The numbers are to be printed without leading zeros.
Appends a dot (.) to every number that turns into another, valid number upon rotation by π (180 °), even if that number is larger than n. Your typeface’s 0 and 8 are rotation-symmetric and the 9 is a rotated 6. The 2 and 5 are distinct upon rotation; the 1 is not rotation-symmetric. Numbers with leading zeros are not valid.

Examples

Each of the following numbers has to be printed exactly this way:

2
4
5
6.
8
9.
16
60
66.
68.
69
906
909.
8088.
9806.
9886
9889.

CJam, 46 44 43 42 bytes

l~),{_A%g1$s_6890s-!\_69s_W%erW%=!&&'.*N}/

I think there's some room for improvement.

Test it here.

Explanation

l~),{_A%g1$s_6890s-!\_69s_W%erW%=!&&'.*N}/
l~                                         "Read an eval input.";
  ),                                       "Get range from 0 to n.";
    {                                   }/ "For each...";
     _                                     "Get a copy of the integer.";
      A%g                                  "Ends with digit other than 0?";
         1$s_                              "Get another copy, convert to string, get a copy.";
             0689s-!                       "Contains rotation-safe digits?";
                    \                      "Swap with other copy.";
                     _                     "Get another copy.";
                      69s_W%er             "Swap 6 and 9.";
                              W%           "Reverse.";
                                =!         "Is different from original?";
                                  &&       "AND all three conditions.";
                                    '.*    "If true, push a period (else, an empty string).";
                                       N   "Push a newline.";


The Ever-Increasing Graph Consider a one-dimensional sequence of numbers within a fixed range, i.e.

[1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩

The Ever-Increasing Graph* ** is a line that connects all the points in this sequence left to right, and always goes upwards or stays level. If necessary, the line wraps around from top to bottom and continues going up from there to meet the next point.

The goal of this challenge is to split the sequence in different subsequences that are all nondecreasing, so that when plotted together with a limited vertical axis they will form an Ever-Increasing Graph. This is done by adding an a point to the end of one subsequence and to the beginning of the next subsequence, so that the angle of the line that crosses the top boundary aligns with the line that crosses the bottom boundary, and the two crossing points have the same horizontal coordinate. The example above would give the following output:

[1, 2, 4, 6, 8, 10]
[-2, 0, 2, 7, 13]
[-3, 3]

And the corresponding graph will look as follows:

And with the axis extended for a better view:

The required output is a list of subsequences that form the parts of the Ever-Increasing Graph. Making a plot is not required but will earn you bonus points ;). The output must clearly separate the subsequences in some way.

Notes

The range will be always have zero as the left (inclusive) boundary, and the right boundary will be some integer N.
The sequence will never contain values that are not within the range.
The first subsequence does not have an additional point at the beginning.
The last subsequence does not have an additional point at the end.
It is not required to provide the starting indices that would be required to plot the subsequences.

Test cases

Input: [0, 2, 4, 6, 1, 3, 5, 0], 7
Output: [0, 2, 4, 6, 8], [-1, 1, 3, 5, 7], [-2, 0]
Input: [1, 1, 2, 3, 5, 8, 3, 1], 10
Output: [1, 1, 2, 3, 5, 8, 13],[-2, 3, 11],[-7, 1]
Input: [5, 4, 3, 2, 1], 10
Output: [5, 14],[-5, 4, 13],[-6, 3, 12],[-7, 2, 11],[-8, 1]
Input: [0, 1, 4, 9, 16, 15, 0], 17
Output: [0, 1, 4, 9, 16, 32], [-1, 15, 17], [-2, 0]

Scoring

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

*Not actual jargon
**Actually should be called Ever Non-Decreasing Graph, as @ngm pointed out, but that sounds less impressive.

R, 179 158 151 bytes
function(s,m){p=1;t=c(which(diff(s)<0),length(s));for(i in t){d=c(s[p]-m,s[(p+1):i],s[i+1]+m);if(p==1)d[1]=s[1];if(p==t[-1])d=head(d,-1);print(d);p=i}}

Try it online!
Edit: Code is now a function and takes input. (Thanks to Giuseppe, user202729 and JayCe for calmly pointing that out)
Edit: -21 bytes suggested by Giuseppe.
Edit: -7 bytes by removing d=NULL;.


Dot Product of Diagonals This challenge is very simple. You are given as input a square matrix, represented in any sane way, and you have to output the dot product of the diagonals of the matrix.
The diagonals in specific are the diagonal running from top-left to bottom-right and from top-right to bottom-left.
Test Cases
[[-1, 1], [-2, 1]]  ->  -3
[[824, -65], [-814, -741]]  ->  549614
[[-1, -8, 4], [4, 0, -5], [-3, 5, 2]]  ->  -10
[[0, -1, 0], [1, 0, 2], [1, 0, 1]]  ->  1

Jelly, 8 6 bytes

×UŒDḢS

Try it online! or verify all test cases

How it works

×UŒDḢS  Main link. Argument: M (matrix)

 U      Upend M, i.e., reverse each row.
,       Pair M and upended M.
  ŒD    Yield all diagonals.
    Ḣ   Head; extract the first, main diagonal.
     S  Reduce by sum.


Are We Fast And Furious? There are currently nine feature length films in the core Fast & Furious/The Fast and the Furious media franchise, a series of films about bald men scowling and driving cars very fast. The names of the films, as can be seen, follow a completely logical and sensible convention:

The Fast and the Furious
2 Fast 2 Furious
The Fast and the Furious: Tokyo Drift
Fast & Furious
Fast Five
Fast & Furious 6
Furious 7
The Fate of the Furious
F9

I'm a Hollywood producer working on the new, tenth Fast & Furious film, and I'm struggling to find a title which hasn't yet been used. Please write me a piece of code - as short as possible - which takes in my input string, and returns a truthy value if any of the following are true:

the input string is already an existing Fast & Furious film title
the input string differs from an existing Fast & Furious film title only by replacing an existing number with ten or 10
the input string differs from an existing Fast & Furious film title only by replacing & with and (or vice versa).

For instance, all of these strings would return a truthy value:

The Fast and the Furious (matches check 1)
The Fast & the Furious (matches check 3)
Fast and Furious 10 (matches checks 2 and 3)
10 Fast 2 Furious (matches check 2)
Furious Ten (matches check 2)
F10 and FTEN (match check 2)

And all of these strings would return a falsy value:

The Fast or The Furious
Fast Times at Ridgemont High
Fast/Furious 10
Too Fast Too Furious
Ten Furious
Fast Ten Furious
The Fast and the Furious: Kyoto Cruise

Fate of the Furious, as a pun, is obviously a tricky case. Unless you're very driven, you don't need to support puns, just exact text matches. If you can create a new Fast & Furious film title which is a pun, please share.
Clarifications

The matching is not case-sensitive, so the input string can be in lowercase. The film company design team will work out how to depict your title on the posters anyway, and the answer is 'in red, with speedy lines'.
I've clarified that the numbering match should only be true if an existing number in the title has been replaced with the string 10 or ten.

Python 3, 190 bytes

lambda a:re.match("(the '!the %(: tokyo drift)?|(2# ' (2# %|'!%|' (five#|'!% (6#|% (7#|the fate of the %|f(9#)$".translate({33:" (and|&) ",35:"|10|ten)",39:"fast",37:"furious"}),a)
import re

Try it online!
A very naive attempt at this.


Golf yourself a beer It's friday! Which means it's time for beer!
Sadly though, today we will be golfing beer instead of drinking it. :(

Challenge

Output a beer and drink it. The amount of sips you take changes your output.

Sips

Your program should take one input string. This string can solely consist out of concatenated sips.
If the input is an empty string, you should output a full beer glass, including foam.

The more sips you take, the emptier your beer glass will be.

If you take 0 sips, your beer still has foam. The output of this foam is always the same (see examples).

If you take 1 sip, you should output the beer glass, followed by a new line and the string Yuck, foam..

If you take 1 or more sips, your beerglass should not contain anymore foam, but should show the top of your glass. Drinking the foam counts as one sip.

If you take 6 or more sips, you should output an empty beer glass, followed by a new line and the string Burp.

For each sip you take, your beer glass should become emptier. How full your beerglass is depends on the amount of bubbles ° (&#176;) in your beer. For each sip you take after the foam, a line of bubbles should be removed. Each line of beer can contain a minimum of 1 and a maximum of 5 bubbles. The position of these bubbles should be 100% random.

Examples

input

empty input string, or no input at all

output

  oo  o oo
 oooooooooooo
o|  °     ° |\
 |     °    | \
 | °°    °  |} |
 |  °    °  | /
 |     °   °|/
 \__________/

input

sip sip sip

output

 ____________
 |          |\
 |          | \
 |     °    |} |
 |° °     ° | /
 | °    °   |/
 \__________/

input

sip sip sip sip sip sip sip sip sip sip

output

 ____________
 |          |\
 |          | \
 |          |} |
 |          | /
 |          |/
 \__________/
Burp

This pastebin contains a list of inputs and outputs. Remember that the bubbles in the beerglass should be random!

Scoring

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

Happy drinking golfing!

Japt, 189 bytes

I almost went insane while trying to get this to work properly...

U?S+'_pC +R:"  oo  o oo\n "+'opC +"\no")+"\\, \\,} |, /,/"q', £(V=(!Y«U?"|: |" +SpA +'|+X,(1+5*Mr)o mZ=>Ul <Y*4+4©(V=Vh2+A*Mr ,'° ),V)qR +"\n \\"+'_pA +'/+R+(Ul ¥3?"Yuck, foam.":Ug22 ?`B¨p:

Try it online!

(Note: This program was made for an older version of Japt, and doesn't currently work in the latest version. To get around this, the older version is specified in the URL. Unfortunately, this also means the top-right code box doesn't work.)

This is by far the longest program I have ever written in Japt. Here's a breakdown:

Step 1: Create the top of the beer mug.

U?S+'_pC +R:"  oo  o oo\n "+'opC +"\no")

           // Implicit: U = input string
           // Begin the ASCII art with:
U?S+       //  If U is not an empty string, a space +
'_pC +R:   //   "_".repeat(12) + a newline.
:"..."+    //  Otherwise, this string +
'opC +     //   "o".repeat(12) +
"\no")     //   a newline and an "o".

If U is an empty string, this makes:

  oo  o oo
 oooooooooooo
o

Otherwise, this makes:

 ____________

Step 2: Create the middle rows of the mug.

+"\\, \\,} |, /,/"q', £(V=(!Y«U?"|: |" +SpA +'|+X,

+"..."    // Add to the previous string: this string,
q', £(    // split at commas, with each item X and its index Y mapped to:
V=(       //  Set variable V to the result of concatenating:
!Y«U?     //   If Y is 0 and U is an empty string,
"|: |"    //    "|"; otherwise, " |";
+SpA      //   10 spaces,
'|+X,     //   "|", and X.

This results in the previous string plus:

 |          |\
 |          | \
 |          |} |
 |          | /
 |          |/

Step 3: Add the bubbles.

(1+5*Mr)o mZ=>Ul <Y*4+4©(V=Vh2+A*Mr ,'° ),V)

            // Note: We're still looping through the five rows at this point.
(1+5*Mr)    // Generate a random integer between 1 and 5.
o           // Create an array of this many integers, starting at 0.
mZ=>        // Map each item Z in this range to:
Ul <Y*4+4©  //  If the length of U is less than Y*4+4,
            //  (in other words, if there's less than Y+1 "sip"s)
(V=Vh   '°  //   Insert "°" at position
2+A*Mr      //    2 + random number between 0 and 9.
),V)qR      // Finally, return V, and join the five rows with newlines.

At this point, the mug looks something like this:

 ____________
 |          |\
 |          | \
 |     °    |} |
 |° °     ° | /
 | °    °   |/

Step 4: Add the final row and optional text.

+"\n \\"+'_pA +'/+R+(Ul ¥3?"Yuck, foam.":Ug22 ?`B¨p:

+"\n \\"    // Add a newline and " \".
+'_pA       // Add 10 "_"s.
+'/+R       // Add a slash and a newline.
+(Ul ¥3?    // If the length of U is 3 (i.e. 1 "sip"),
"..."       //  add the string "Yuck, foam.".
:Ug22 ?     // Otherwise, if U has a character at position 22 (six or more "sip"s),
`B¨p        //  decompress this string ("Burp") and add it.
:           // Otherwise, add nothing.

Now everything is ready to be sent to output, which is done automatically. If you have any questions, feel free to ask!


Golf a Venn Diagram generator Golf a Venn Diagram generator

In order to properly celebrate John Venn's 180th birthday, today your task will be creating a program that outputs a Venn Diagram!

Input:

A positive integer N that will define the range of numbers appearing in the diagram (From zero to N) and three sets of positive integers.

Output:

A 3 set Venn diagram showing all integers from 0 to N and the relationships of the sets by displaying them in the proper regions of the diagram, similar to this one.

Notes

Use stdin (or whatever your language's equivalent is) to get the
values.
You can define the input format for the sets and for N (Separated by comma, slash or whatever works best for you).
Numbers that do not appear in any of the sets but are within the specified range must appear on the diagram, just not inside any region.
The sets don't need to be named.
The output can be a drawing or ascii-art.
The diagram can have any shape as long as the boundaries are unambiguously distinguishable (if you chose ASCII art, using + (or similar) for crossing boundaries is essential, for example).
The regions may but don't have to be shaded.
Any built-in functions or third party libraries that generate Venn Diagrams are disallowed.
Standard loopholes apply.

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

Ruby, 654 590 566 542 505 bytes

This was fun. I used ASCII. I wasn't able to test every possible combination yet, so if you find a glitchy test case, please let me know.

require'set'
u=(0..gets.to_i).to_set
a,b,c=eval(gets).map &:to_set
i=' '
m,M,n,N,o,O,p,P,q,Q,r,R,s,S=[a-b-c,b-a-c,c-a-b,a&b-c,b&c-a,a&c-b,a&b&c].map{|u|[t=u.to_a*i,t.size]}.flatten
H,V,X=?─,?│,?┼
puts'┌'+H*(A=[1+M+[P,S].max,1+R].max)+?┐+(u-a-b-c).to_a*i,V+i*M+?┌+(b=H*(T=-M+U=A-1)+X+H*(B=[N,Q].max))+?┐,V+m+V+p+i*(T-P)+V+n+i*(B-N)+V,'│┌'+H*(K=M-1)+X+b+X+H*(C=[O-B-1,0].max)+?┐,(v=V*2+i*K)+V+s+i*(T-S)+V+q+i*(B-Q)+V+i*C+V,v+?└+b+?┘+i*C+V,V*2+r+i*(U-R)+V+o+i*(-O+D=B+C+1)+V,'└┼'+H*U+?┘+i*D+V,' └'+H*(A+D)+?┘

It expects the input on STDIN in the following format

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

And will then reward you with this beauty

┌───────┐0 10
│   ┌───┼───┐
│4 5│1 3│6 8│
│┌──┼───┼───┼┐
││  │2  │   ││
││  └───┼───┘│
││9     │7   │
└┼──────┘    │
 └───────────┘

I don't think I can be bothered to add an ungolfed version. Please have a look at the original version in the edit history for a somewhat more readable version.

This could certainly be golfed further by making the set boundaries less tight or even keeping them fixed like some of the graphical ones do, but I prefer that it looks nice and is done "properly" despite being golfed.


Checkmate (aka the urinal problem) My Precalc teacher has one of his favorite problems that he made up (or more likely stole inspired by xkcd) that involves a row of n urinals. "Checkmate" is a situation in which every urinal is already occupied OR has an occupied urinal next to them. For instance, if a person is an X, then

X-X--X

is considered checkmate. Note that a person cannot occupy a urinal next to an already occupied urinal.

Task

Your program will take a number through stdin, command line args, or a function argument. Your program will then print out or return the number of ways that checkmate can occur in with the inputted number of urinals.

Examples

0 -> 1 (the null case counts as checkmate)
1 -> 1 (X)
2 -> 2 (X- or -X)
3 -> 2 (X-X or -X-)
4 -> 3 (X-X-, -X-X, or X--X)
5 -> 4 (X-X-X, X--X-, -X-X-, or -X--X)
6 -> 5 (X-X-X-, X--X-X, X-X--X, -X--X- or -X-X-X)
7 -> 7 (X-X-X-X, X--X-X-, -X-X--X, -X--X-X, X-X--X-, X--X--X or -X-X-X-)
8 -> 9 (-X--X--X, -X--X-X-, -X-X--X-, -X-X-X-X, X--X--X-, X--X-X-X, X-X--X-X, X-X-X--X, X-X-X-X-)
...

Scoring

The smallest program in bytes wins.

Oasis, 5 bytes

Code

cd+2V

Extended version

cd+211

Explanation

1 = a(0)
1 = a(1)
2 = a(2)

a(n) = cd+
       c      # Calculate a(n - 2)
        d     # Calculate a(n - 3)
         +    # Add them up

Try it online!


Play the "bzzt" game Winner: Aditsu's CJam answer! A whopping 25 bytes! Nice!
You may continue to submit your answer, however you can no longer win. Original post kept for posterity:

The "Bzzt" game is a game where you must count to a number (in this case 500). However, if the number has a 3 in it, or is divisible by 3, you don't say the number. Instead, you say "Bzzt".
Rules:

You can't hard-code the numbers.
The number only has to satisfy at least 1 of the following requirements

Divisible by 3
Number contains a 3

Some type of separator is mandatory (12bzzt14 doesn't count)
Score is measured in bytes.
You must count exactly to 500, starting at 1 or 0 (you chose).
The numbers must be output, but it doesn't matter how (e.g., stdout, writing to a text file, etc.).
0 can be divisible by 3 or not divisible. You can choose.
You can output the numbers one at a time (ex, output 1, then 2, then bzzt, then 4, etc) or all at once (e.g., output 1 2 bzzt 4 5).
You must replace the letter 3 with the word "bzzt". This is not case sensitive (bZzt, Bzzt, bzzt are all okay).

This is a code-golf challenge, so the shortest code wins.
This contest ends June 30th 2014 (7 days from posting).

CJam - 25

501{3sI3%<Is-I"bzzt"?N}fI

Thanks Howard :)

Try it at http://cjam.aditsu.net/

Explanation:

501{…}fI is basically for(int I=0; I<501; ++I) {…}
3s converts 3 to string, i.e. "3"
I3% is I % 3
< gets the left substring - "3".substring(0, I % 3) - which is "" for I % 3 == 0 and "3" otherwise
Is converts I to string
- with 2 strings does a set difference, resulting in an empty string iff I % 3 == 0 (the first string was empty) or I has a 3 digit in it
…I"bzzt"? is like … ? I : "bzzt"; the previous string is treated as a boolean value, where "" is false and any other string is true
N adds a newline


bfcat - encode a file as a brainf*** program Challenge

Write a program or function that given a string, returns a valid Brainfuck program that when compiled and executed as Brainfuck, returns that string..

Assume all inputs are encoded as ASCII.
Assume the outputted BF program will execute in an environment with an infinite tape.
Assume the pointer starts at cell 0 with every cell initialized to a value of zero.
Each example below represent one possible correct output for the given input. In particular, the examples include extra newlines and spaces to help human readability. Solutions are free to format the outputted BF code in any way.
The tape is doubly infinite.
All cells provided by the interpreter are exactly 8-bit cells. Overflow and underflow wrap around in a predictable and sane matter.

Examples

Space string

Given the input  , your program/function could return:

+++++ +++++
+++++ +++++
+++++ +++++
++ .

Exclamation point

Given the input ! , your program/function could return:

+++++ +++++
+++++ +++++
+++++ +++++
+++
.

Two letters

Given the input hi , your program/function could return:

+++++ +++++
+++++ +++++
+++++ +++++
+++++ +++++
+++++ +++++

+++++ +++++
+++++ +++++
+++++ +++++
+++++ +++++
+++++ +++++

++++
.
+
.

This is code-golf, so the code with the smallest number of bytes wins. Good luck.

Brainfuck, 55 51 bytes

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

Try it online!

Example output for hi (without the linefeeds):

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>

Explanation

This moves across the tape while writing the program. The surrounding ,[...,] is a standard input loop. For each character, we use four cells:

[... x a b c ...]

where x is the cell we write the input to.

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

This part uses cell a to write a 21 into cell b via a standard multiplication of 3 and 7.

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

Now we use that 21 to write 42 into a and 63 into c by multiplying by 2 and 3 respectively. Then <+< moves back to cell x while turning the 42 into a 43 (the code point of +). Recap:

[... x 43 21 63 ...]

Now the main output loop:

[>.<-]

That is, while decrementing x we print one + each time.

>+++.

After we're done we reuse the + cell, by adding 3 to give ..

>>-.

Finally, we move to the 63, decrement it to 62 (>) and output that as well. The next iteration will use this cell as x.


Formerly Composite Numbers Sequence Definition

Construct a sequence of positive integers a(n) as follows:

a(0) = 4
Each term a(n), other than the first, is the smallest number that satisfies the following:
a) a(n) is a composite number,
b) a(n) > a(n-1), and
c) a(n) + a(k) + 1 is a composite number for each 0 <= k < n.

So we start with a(0) = 4. The next entry, a(1) must be 9. It can't be 5 or 7 since those aren't composite, and it can't be 6 or 8 because 6+4+1=11 is not composite and 8+4+1=13 is not composite. Finally, 9+4+1=14, which is composite, so a(1) = 9.

The next entry, a(2) must be 10, since it's the smallest number larger than 9 with 10+9+1=20 and 10+4+1=15 both composite.

For the next entry, 11 and 13 are both out because they're not composite. 12 is out because 12+4+1=17 which is not composite. 14 is out because 14+4+1=19 which is not composite. Thus, 15 is the next term of the sequence because 15 is composite and 15+4+1=20, 15+9+1=25, and 15+10+1=26 are all each composite, so a(3) = 15.

Here are the first 30 terms in this sequence:

4, 9, 10, 15, 16, 22, 28, 34, 35, 39, 40, 46, 52, 58, 64, 70, 75, 76, 82, 88, 94, 100, 106, 112, 118, 119, 124, 125, 130, 136

This is OEIS A133764.

Challenge

Given an input integer n, output the nth term in this sequence.

Rules

You can choose either 0- or 1-based indexing. Please state which in your submission.
The input and output can be assumed to fit in your language's native integer type.
The input and output can be given by any convenient method.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Husk, 11 bytes

!üȯṗ→+fotpN

1-indexed.
Try it online!

Explanation

!üȯṗ→+fotpN  Implicit input, a number n.
          N  The list of positive integers [1,2,3,4,..
      f      Keep those
         p   whose list of prime factors
       ot    has a nonempty tail: [4,6,8,9,10,12,..
 ü           De-duplicate wrt this equality predicate:
     +       sum
    →        plus 1
  ȯṗ         is a prime number.
             Result is [4,9,10,15,16,..
!            Get n'th element.


TinyBF to Brainf*** converter We have a Brainf*** to TinyBF converter, but not the other way around, so here's one.

Rules:

Your interpreter must take a valid TinyBF program, on one line, and it must output the corresponding BrainF*** program, on one line, with optional trailing whitespace/newline. No leading whitespace is allowed
The input may or may not contain characters that are not any of the four TinyBF characters. If so, you must print all of these characters in the same spots.
An answer will be accepted on April 1st (not joking), based on some obscure criteria I will use (jk ;) I will accept the shortest program that does not cheat by the following rules)
No 0-byte or 1-byte solutions, because it ruins the fun if you make (or there is) a programming language just for this purpose)

Test Cases

Input 1: +++++>+++++=>=|>>+=>>+|=>|>+=>+| (Computes 5 (byte 1) + 5 (byte 2) = 10 (byte 3))
Output 1: +++++>+++++<[>>+<<-]>[>+<-]

Input 2: +++>++++Hi+++:P+=>=|>|>+>+=>>&&+|=>>|=>>=+!!>>=+|>>>+| (Computes 3 (byte 1) * 8 (byte 2) = 24 (byte 3))
Output 2: +++>++++Hi+++:P+<[>[>+>+<<&&-]>>[<<+!!>>-]<<<-]

Python 3, 97 bytes

This script is based on @Mego's answer

a=0
for c in input():a-=c=='=';print({'+':'+-','>':'><','|':'[]'}.get(c,c)[a%-2]*(c!='='),end='')


What surrounds my Minesweeper tile? Minesweeper is a puzzle game where mines are hidden around a board of nondescript tiles with the goal of identifying the location of all mines. Clicking on a mine loses the game, but clicking on any other tile will reveal a number from 0-8 which signifies how many mines directly surround it.

Given a number, you must display a random* possible combination of empty tiles and mines surrounding it. This should be in the form of a 3x3 array. The center tile should be the number of mines taken as input.

*Must have a non-zero chance for all combinations to occur.

Examples

_ = blank square
X = mine

0

___
_0_
___

1

_X_
_1_
___

1

___
_1_
X__

___
_1_
__X

4

_X_
X4X
_X_

4

X_X
_4_
X_X

4

___
X4X
X_X

8

XXX
X8X
XXX

Input

The number of mines surrounding the center tile (0-8)

Output

Any reasonable form of output that displays the 3x3 array of tiles

Other rules

Each combination does not have to have an equal chance of happening. There just must be a non-zero chance of each combination to occur when executing your program.
Any 2 characters can be chosen for the mine and empty tile.
This is code golf, the program with fewest bytes wins.

APL (Dyalog Unicode), 28 15 bytes

-13 bytes thanks to ngn!

{3 3⍴5⌽⍵,⍵≥8?8}

Explanation:

{...} A direct function (D-Fn), ⍵ is its right argument.

8?8 deal 8 random numbers from the list 1..8:

      8?8
7 2 1 8 4 6 5 3

⍵≥ is the argument greater or equal to each of them?:

      5 ≥ 7 2 1 8 4 6 5 3
0 1 1 0 1 0 1 1

⍵, prepend the argument to the boolean list:

      5 , 0 1 1 0 1 0 1 1
5 0 1 1 0 1 0 1 1

5⌽ rotate the list 5 positions to the left, so that the argument is in the center:

      5 ⌽ 5 0 1 1 0 1 0 1 1
1 0 1 1 5 0 1 1 0

3 3⍴ reshape the list to a 3x3 matrix:

      3 3 ⍴ 1 0 1 1 5 0 1 1 0
1 0 1
1 5 0
1 1 0

Try it online!

J, 15 bytes

Also many bytes thanks to ngn!

3 3$5|.],]>8?8:

Try it online!


Pyth, 6 bytes
f*FjQT

Verify all the test cases.
How it works

f*FjQT  ~ Full program.

f       ~ First positive integer where the condition is truthy.
   jQT  ~ The input converted to base of the current element.
 *F     ~ Product. If the list contains 0, then it's 0, else it is strictly positive.
          0 -> Falsy; > 0 -> Truthy.
        ~ Output the result implicitly.

Although Pyth's f operates on 1, 2, 3, 4, ... (starting at 1), Pyth treats numbers in base 1 (unary) as a bunch of zeros, so base 1 is ignored.


Can Jimmy hang on his rope? Yet another Jimmy challenge by his original father. See these other lovely challenges.

As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat as I mentioned before, and he's got other tricks up his sleeve.

One of these tricks is hanging by ropes. Here's an example of a rope Jimmy could hang from:

            ||
            ||
            ||
            ||
            ||
            ||

When Jimmy hangs on a rope, it looks like this:

            ||
            ||
           /o\
            ||
            ||
            ||

He can hang on the left or the right of the rope, so this:

            ||
            ||
            ||
            /o\
            ||
            ||

is also valid. But he cannot hang by just one body part, so anything like this:

            ||
            ||
            ||
          /o\|
            ||
            ||

is invalid. Note that when he is hanging by one body part the other half of the rope is visible because Jimmy does not cover it up.

Also, Jimmy does not like hanging on the bottom of the rope - it scares him - so this:

            ||
            ||
            ||
            ||
            ||
            /o\

is invalid.

The challenge

Take input of a Jimmy situation like the ones above, and output whether Jimmy will hang on to the rope or not through a truthy or falsy value.

The specifics

Write a program that takes input. This can be through a function or any other appropriate input method.

The input should be a scene of one Jimmy and a rope as exemplified above.

The program should output a truthy or falsy value to the console based on whether Jimmy can hang on to the rope or if he would fall off the rope, respectively.
The criteria for Jimmy being able to hang on the rope:

Two of his body parts are on the rope.
He is not on the bottom of the rope.
He is not floating in mid-air.

You can assume the rope will be straight, made up of || segments, and will be longer than one character in height.
You can assume one whole rope and one singular Jimmy will be present in your scene, no more and no less.
You can assume there will be no trailing newlines at the bottom of the rope.
You must cover any amount of leading or trailing spaces before and after the rope.

Test cases

           ||
           ||
           ||                 TRUTHY
           /o\
           ||
           ||

            ||
            ||
          /o\|                FALSY
            ||
            ||

        ||
       /o\                    TRUTHY
        ||

            ||
           /o\                FALSY

         /o\
          ||                  TRUTHY

            ||
            ||
       /o\  ||                FALSY
            ||
            ||

Scoring

This is code-golf, so lowest score in bytes wins after about a week.

Leaderboard

You can view the leaderboard for this post by expanding the widget/snippet below. In order for your post to be included in the rankings, you need a header (# header text) with the following info:

The name of the language (end it with a comma , or dash -), followed by...
The byte count, as the last number to appear in your header.

For example, JavaScript (ES6), 72 bytes is valid, but Fortran, 143 bytes (8-bit) is invalid because the byte count is not the last number in the header (your answer will be recognized as 8 bytes - don't take advantage of this).

<!-- Run the snippet to see the leaderboard. Report any bugs to @ozewski on Github. -->    <iframe src="https://ozewski.github.io/ppcg-leaderboard/?id=187759" width="100%" height="100%" style="border:none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>

Python 2 or 3,  33  30 bytes

-3 thanks to Maxwell

lambda l:'o'in map(max,l[:-1])

An unnamed function accepting a list of lines

Try it online!

How?

There needs to be a section of rope obscured by Jimmy that is not the bottom one.

lambda l:'o'in map(max,l[:-1])
lambda l:                      # a function taking l (the lines as strings)
                       l[:-1]  # strip off the last line
               map(max,      ) # maximum of each line (where '|'>'o'>'\'>'/'>' ')
         'o'in                 # was 'o' one of them? (hence Jimmy obscured all the rope)


Generate ordered binary combinations without repetitions Challenge

Write the shortest program that receives two signed integers n and i and for each i between 1 and 2^n - 1 returns the next ordered permutation based on the binary representation of the number.  There is no specific order of the combinations but the number of 1s in the binary representation must always stay the same or grow and numbers each output may happen only once

Clarification

The goal of this program is to generate all the combinations without repetitions of a set. To do so you may consider that each item is represented by a bit in a bit mask, that way if you have three items, A, B and C represented by 001, 010 and 100 respectively the combinations ABC, ACB, BCA, BAC, CAB and CBA are all represented as 111.

For increasing values of i your program should output a new combinations always with the same number of elements or more.

Input

You may read the input in the format

  n i

or just use n and i variables, whichever suits you best.

Output

You may output a single number k

Sample cases

Each test case is two lines, input followed by output with a binary representation here for demonstration purposes:

3 1
1 (001)

3 2
4 (100)

3 3
2 (010)

3 4
6 (110)

3 7
7 (111)

Rules

Shortest code wins (bytes)
The result can be returned by a function or printed by your program.
You may assume n and i variables already exist, there's no need to handle input if you don't want to.
The answers with the same number of 1 bits can be output in any order
The input is guaranteed to be well formed and 1 <= i <= 2^n - 1.

Happy Golfing!


A crowd of blank stares Problem

Given no input write a program or a function that outputs or returns the following string:

(<(<>(<>.(<>.<(<>.<>(<>.<>)<>.<>)>.<>).<>)<>)>)

Rules

Shortest program wins.
Trailing whitespace allowed.
Trailing newlines allowed.
Unused parameters for functions allowed.

05AB1E, 16 bytes

"(<>.".∞ηJÀ24£.∞

Try it online!

Explanation

"(<>."             # push this string
                   # STACK: "(<>."
      .∞           # intersected mirror
                   # STACK: "(<>.<>)"
        η          # compute prefixes
         J         # join to string
                   # STACK: "((<(<>(<>.(<>.<(<>.<>(<>.<>)"
          À        # rotate left
           24£     # take the first 24 chars
                   # STACK: "(<(<>(<>.(<>.<(<>.<>(<>."
              .∞   # intersected mirror
                   # STACK: "(<(<>(<>.(<>.<(<>.<>(<>.<>)<>.<>)>.<>).<>)<>)>)"


Have you mooed today? The Debian Linux distribution (and Debian-based distros, like Ubuntu, Kali and others) uses a package-manager called APT. To install program foo you would type into a terminal

sudo apt-get install foo

One little Easter Egg of APT is the following

apt-get moo

Which after typing will produce the following output

                 (__)
                 (oo)
           /------\/
          / |    ||
         *  /\---/\
            ~~   ~~
..."Have you mooed today?"...

You must write a program that produces this EXACT output in as few bytes as possible. (including trailing spaces and a new line)

Here is the same output with \n added to represent newline characters, and a * to represent trailing spaces

                 (__)*\n
                 (oo)*\n
           /------\/*\n
          / |    ||***\n
         *  /\---/\*\n
            ~~   ~~***\n
..."Have you mooed today?"...\n

As requested in the comments, here is the md5sum of the mooing.

35aa920972944a9cc26899ba50024115  -

CJam, 96

This uses a lot of nasty bytes, so here's a hex dump of it:

00000000  22 ee 51 1e 53 41 15 ee  51 20 53 41 15 9a 5f 5a  |".Q.SA..Q SA.._Z|
00000010  b9 5f 41 15 8c 5f 41 f9  38 24 2a 15 7e 55 1c 5f  |._A.._A.8$*.~U._|
00000020  b9 30 5f b9 41 15 a8 26  2a 26 2a 15 36 45 91 c3  |.0_.A..&*&*.6E..|
00000030  ed cb 41 f3 df eb 41 db  20 cb c9 41 e9 df c9 c3  |..A...A. ..A....|
00000040  f3 7f 45 36 15 22 7b 69  32 6d 64 5c 5f 63 5c 37  |..E6."{i2md\_c\7|
00000050  6d 64 22 20 5f 6f 2d 7c  7e 2e 22 3d 2a 3f 7d 2f  |md" _o-|~."=*?}/|

You can run the file with the java interpreter; it may be necessary to use ISO-8859-1 encoding, such as:
java -Dfile.encoding=ISO-8859-1 …

Try it online

Equivalent (and much longer) ASCII version:

[238 81 30 83 65 21 238 81 32 83 65 21 154 95 90 185 95 65 21 140 95 65 249 56 36 42 21 126 85 28 95 185 48 95 185 65 21 168 38 42 38 42 21 54 69 145 195 237 203 65 243 223 235 65 219 32 203 201 65 233 223 201 195 243 127 69 54 21]:c
{i2md\_c\7md" _o-|~."=*?}/

Try it online

Explanation:

There are 7 characters that have repetitions:  _o-|~.. Each of them can be encoded as a number n from 0 to 6. For each repeating sequence, I am encoding both the character's index (n) and the number of repetitions (k) in a single byte: 2 * (k * 7 + n), written as a character with that code. And I am encoding any single characters as 2 * c + 1, where c is the ASCII code. Everything goes in the initial string, and the rest of the program is decoding it:

{…}/      for each character in the string
  i       convert to integer (extended-ASCII code)
  2md     integer division by 2, obtaining the quotient (q) and remainder (r)
           r decides whether it's a repetition or single character
  \_      swap q and r, and duplicate q
  c\      convert q to character and move it before the other q
           this is for the r=1 case (single character)
  7md     divide q by 7, obtaining the quotient (k) and remainder (n)
  "…"=    get the corresponding character from that string (decoding n)
  *       repeat the character k times
  ?       use the single character or the repetition, depending on r

Old version (109):

" H(_2)
 H(o2)
 B/-6\/
 A/ | 4|2 3
 9* 2/\-3/\
 C~2 3~2 3
.6"{_'M,48>&{~*}&}/3/"Have you mooed today?"`*N

Try it online


Snakes and Ladders probability of winning (This is my first Q here, and I don't know much about code golfing.)

Your aim is to predict the winner of an ongoing Snakes and Ladders game.

INPUT

A single number (2-1000) indicating the number of spaces on the board, say x.
Another number (2-4) indicating number of players, say n.
n numbers, each giving the position of each player on the game board.
Another number (1-15) indicating number of snakes and ladders (combined), say s.
s lines of input, each with 2 numbers - the start and end of each snake/ladder.

OUTPUT

n decimal numbers, accurate to 2 decimal places, indicating the probability of each player winning.

WINNER

The person to give the fastest program wins, not necessarily the shortest code. This might help those using a different algorithm to gain a huge advantage.

Notes

Players start on space 1, not 0. They win on reaching space x.

All players use a fair 6 sided dice. There are no re-rolls for 6s.

We assume that there is no 'bad' input given, such as more than 4 players, or a snake starting at the last space.

Players are given the same order of play as your input. The first player is the first to roll now, then the second and so on.

Even if you overshoot the win space, you still win.

C, ~.25 seconds

I have calculated by using dynamic simulations instead of probability of each dice roll. The more accurate the probability, the slower... here a brief code...

Compile using:

gcc -o Snakes snakes.c

Code:

#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    srand(time(0));

    // initialize principal variables
    int NumberOfSpaces   = 100,
    NumberOfPlayers  = 4,
    PlayerPosition[] = { 46, 56, 36, 66 };
    //PlayerPosition[] = {0, 0, 0, 0};

    // arrays of positions, must be in numerical order,
    // must be in (start, end) format. correct - 1, 2, 5, 6, 8, 9
    //                               incorrect - 1, 2, 8, 9, 5, 6
    int LadderPositions[10] = { 3, 10, 5, 20, 20, 31, 22, 49, 44, 87 },      // positions of ladders
    SnakePositions[10] = { 11, 3, 15, 1, 35, 22, 54, 29, 60, 20 }, // positions of snakes
    SnakesLadders    = 10;                                       // # of snakes + ladders

    // static arrays to hold
    // # of dice rolls to complete game
    int Player1Wins[10000],
    Player2Wins[10000],
    Player3Wins[10000],
    Player4Wins[10000];

    int NumberOfSimulations = 10001;

    int OutsideLoop, Counter = 1, i, a, Win, EvenArray;
    for (OutsideLoop = 0; OutsideLoop < NumberOfPlayers; OutsideLoop++)      // do a simulation for each player
        for (a = 0; a < NumberOfSimulations; a++)                       // play for each simulation
        {
            for (i = PlayerPosition[OutsideLoop]; i <= NumberOfSpaces + 1; i += (rand() % 6 + 1)) // roll the dice for each turn
            {
                Counter++ ;
                for (EvenArray = 0; EvenArray < SnakesLadders; EvenArray+=2) // check if space is snake or ladder
                {
                    if (i == LadderPositions[EvenArray])
                        i = LadderPositions[EvenArray + 1];
                    if (i == SnakePositions[EvenArray])
                        i = SnakePositions[EvenArray + 1];
                }
             }
             // put value in array
             if (OutsideLoop == 0)
                 Player1Wins[a] = Counter;
             else if (OutsideLoop == 1)
                 Player2Wins[a] = Counter;
             else if (OutsideLoop == 2)
                 Player3Wins[a] = Counter;
             else if (OutsideLoop == 3)
                 Player4Wins[a] = Counter;
             Counter = 0;
        }

    // count how many time each person won
    int P1Wins = 0, P2Wins = 0, P3Wins = 0, P4Wins, Ties = 0;
    for (Win = 0; Win < NumberOfSimulations; Win++)
    {
        if (Player1Wins[Win] < Player2Wins[Win] && Player1Wins[Win] < Player3Wins[Win] && Player1Wins[Win] < Player4Wins[Win])
            P1Wins++;
        else if (Player2Wins[Win] < Player1Wins[Win] && Player2Wins[Win] < Player3Wins[Win] && Player2Wins[Win] < Player4Wins[Win])
            P2Wins++;
        else if (Player3Wins[Win] < Player1Wins[Win] && Player3Wins[Win] < Player2Wins[Win] && Player3Wins[Win] < Player4Wins[Win])
            P3Wins++;
        else if (Player4Wins[Win] < Player1Wins[Win] && Player4Wins[Win] < Player2Wins[Win] && Player4Wins[Win] < Player3Wins[Win])
            P4Wins++;
        else if (Player2Wins[Win] == Player1Wins[Win] == Player3Wins[Win])
            Ties++;
    }

    printf("[ + ] Namaste! Welcome to the Snakes & Ladders guess who wins program!\n");
    printf("[ + ] I will run 10K simulations of the game to make a guess on the probability of the winner.\n");
    printf("[ + ] Given %i players, with starting positions of :\n[ + ] P1 - %i\n[ + ] P2 - %i\n[ + ] P3 - %i\n[ + ] P4 - %i\n[ + ] Here's the probability I think each player has of winning...\n", NumberOfPlayers, PlayerPosition[0], PlayerPosition[1], PlayerPosition[2], PlayerPosition[3]);
    printf("[ + ] P1 = %i / 10000\n[ + ] P2 = %i / 10000\n[ + ] P3 = %i / 10000\n[ + ] P4 = %i / 10000\n[ + ] Ties = %i\n", P1Wins, P2Wins, P3Wins, P4Wins, Ties);
    return 0;
}

Environment - timed using time (bash command) on linux core i7

10    simulations ~ .003 second

10000 simulation  ~ .030 second

Sample outputs :

time ./Snakes
[ + ] Namaste! Welcome to the Snakes & Ladders guess who wins program!
[ + ] I will run 10K simulations of the game to make a guess on the probability of the winner.
[ + ] Given 4 players, with starting positions of :
[ + ] P1 - 10
[ + ] P2 - 21
[ + ] P3 - 50
[ + ] P4 - 70
[ + ] Here's the probability I think each player has of winning...
[ + ] P1 = 86 / 10000
[ + ] P2 = 254 / 10000
[ + ] P3 = 131 / 10000
[ + ] P4 = 9098 / 10000
[ + ] Ties = 0
real    0m0.036s
user    0m0.036s
sys 0m0.000s

Alt input position:

[ + ] Given 4 players, with starting positions of :
[ + ] P1 - 15
[ + ] P2 - 5
[ + ] P3 - 60
[ + ] P4 - 50
[ + ] Here's the probability I think each player has of winning...
[ + ] P1 = 955 / 10000
[ + ] P2 = 3041 / 10000
[ + ] P3 = 1833 / 10000
[ + ] P4 = 3572 / 10000
[ + ] Ties = 0
real    0m0.024s
user    0m0.024s
sys     0m0.000s

More input:

[ + ] Given 4 players, with starting positions of :
[ + ] P1 - 46
[ + ] P2 - 56
[ + ] P3 - 36
[ + ] P4 - 66
[ + ] Here's the probability I think each player has of winning...
[ + ] P1 = 94 / 10000
[ + ] P2 = 442 / 10000
[ + ] P3 = 2454 / 10000
[ + ] P4 = 6319 / 10000
[ + ] Ties = 0
real    0m0.018s
user    0m0.018s
sys     0m0.000s


Drawing 3d nets - Archimedean solids I have a weakness for 3d nets which when cut out and folded allow you to make 3d shapes out of paper or card.  The task is simple, written the shortest program you can that draws nets for the 13 Archimedean solids. The output should be an image file in any sensible format (png, jpg).

All thirteen shapes are described at http://en.wikipedia.org/wiki/Archimedean_solid and in the following table taken from there.

Input: An integer from 1 to 13.  Assume the shapes are numbered exactly as in the table above so that the "truncated tetrahedron" is number 1 and the "snub dodecahedron" is number 13.

Output: An image file containing the net for that shape. Just the outline including the internal lines is OK. There is no need to fill it in with colors

You can use any programming language you like as well as any library that was not made especially for this competition. Both should be available freely however (in both senses) online.

I will accept the answer with the smallest number of characters in exactly one week's time.  Answers will be accepted whenever they come.

(No) Winner yet.  Sadly no valid entrants. Maybe it is too hard?