Convert English to a number without built-ins or libraries This challenge is similar to this other, however I made a restriction (see bold text below) that I think would made it much diffent and (I hope) fun either.

The Challenge

Write a program or a function in any programming language that takes as input the English name of a positive integer n not exceeding 100 and returns n as an integer.

Standard loopholes are forbidden and you cannot use any built-in function, external tool, or library that already does this job.

Shortest source code in bytes wins.

Test

Here all the input->output cases:

one              -> 1
two              -> 2
three            -> 3
four             -> 4
five             -> 5
six              -> 6
seven            -> 7
eight            -> 8
nine             -> 9
ten              -> 10
eleven           -> 11
twelve           -> 12
thirteen         -> 13
fourteen         -> 14
fifteen          -> 15
sixteen          -> 16
seventeen        -> 17
eighteen         -> 18
nineteen         -> 19
twenty           -> 20
twenty-one       -> 21
twenty-two       -> 22
twenty-three     -> 23
twenty-four      -> 24
twenty-five      -> 25
twenty-six       -> 26
twenty-seven     -> 27
twenty-eight     -> 28
twenty-nine      -> 29
thirty           -> 30
thirty-one       -> 31
thirty-two       -> 32
thirty-three     -> 33
thirty-four      -> 34
thirty-five      -> 35
thirty-six       -> 36
thirty-seven     -> 37
thirty-eight     -> 38
thirty-nine      -> 39
forty            -> 40
forty-one        -> 41
forty-two        -> 42
forty-three      -> 43
forty-four       -> 44
forty-five       -> 45
forty-six        -> 46
forty-seven      -> 47
forty-eight      -> 48
forty-nine       -> 49
fifty            -> 50
fifty-one        -> 51
fifty-two        -> 52
fifty-three      -> 53
fifty-four       -> 54
fifty-five       -> 55
fifty-six        -> 56
fifty-seven      -> 57
fifty-eight      -> 58
fifty-nine       -> 59
sixty            -> 60
sixty-one        -> 61
sixty-two        -> 62
sixty-three      -> 63
sixty-four       -> 64
sixty-five       -> 65
sixty-six        -> 66
sixty-seven      -> 67
sixty-eight      -> 68
sixty-nine       -> 69
seventy          -> 70
seventy-one      -> 71
seventy-two      -> 72
seventy-three    -> 73
seventy-four     -> 74
seventy-five     -> 75
seventy-six      -> 76
seventy-seven    -> 77
seventy-eight    -> 78
seventy-nine     -> 79
eighty           -> 80
eighty-one       -> 81
eighty-two       -> 82
eighty-three     -> 83
eighty-four      -> 84
eighty-five      -> 85
eighty-six       -> 86
eighty-seven     -> 87
eighty-eight     -> 88
eighty-nine      -> 89
ninety           -> 90
ninety-one       -> 91
ninety-two       -> 92
ninety-three     -> 93
ninety-four      -> 94
ninety-five      -> 95
ninety-six       -> 96
ninety-seven     -> 97
ninety-eight     -> 98
ninety-nine      -> 99
one hundred      -> 100

C, 160 bytes

g(char*s){char i=1,r=0,*p="k^[#>Pcx.yI<7CZpVgmH:o]sYK$2";for(;*s^'-'&&*s;r+=*s++|9);r=r%45+77;for(;*p!=r;p++,i++);return((*s^'-')?0:g(s+1))+(i<21?i:10*(i-18));}

Test it

int main ()
{
    char* w[] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty-one", "twenty-two", "twenty-three", "twenty-four", "twenty-five", "twenty-six", "twenty-seven", "twenty-eight", "twenty-nine", "thirty", "thirty-one", "thirty-two", "thirty-three", "thirty-four", "thirty-five", "thirty-six", "thirty-seven", "thirty-eight", "thirty-nine", "forty", "forty-one", "forty-two", "forty-three", "forty-four", "forty-five", "forty-six", "forty-seven", "forty-eight", "forty-nine", "fifty", "fifty-one", "fifty-two", "fifty-three", "fifty-four", "fifty-five", "fifty-six", "fifty-seven", "fifty-eight", "fifty-nine", "sixty", "sixty-one", "sixty-two", "sixty-three", "sixty-four", "sixty-five", "sixty-six", "sixty-seven", "sixty-eight", "sixty-nine", "seventy", "seventy-one", "seventy-two", "seventy-three", "seventy-four", "seventy-five", "seventy-six", "seventy-seven", "seventy-eight", "seventy-nine", "eighty", "eighty-one", "eighty-two", "eighty-three", "eighty-four", "eighty-five", "eighty-six", "eighty-seven", "eighty-eight", "eighty-nine", "ninety", "ninety-one", "ninety-two", "ninety-three", "ninety-four", "ninety-five", "ninety-six", "ninety-seven", "ninety-eight", "ninety-nine", "one hundred"};

    int n;
    for (n = 1; n <= 100; n++)
    {
        printf ("%s -> %d\n", w[n], g(w[n]));
        if (n != g(w[n]))
        {
            printf ("Error at n = %d", n);
            return 1;
        }
    }
    return 0;
}

How it works

After some attempts, I found a function that maps the "exceptional" numbers one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, one hundred, to the printable ASCII characters k, ., [, <, *, , c, K, w, y, e, (, S, _, -, C, ), 7, =, 4, &, o, ], s, Y, g, m, N, respectively.

This function is:

char hash (char* s)
{
    char r = 0;

    while (*s)
    {
        r += *s|9;
        s++;
    }

    return r%45+77;
}

The golfed program computes the hash function of the input until it reaches the end of the string or the character -. Then it searches the hash in the string k.[<* cKwye(S_-C)7=4&o]sYgmN and determines the corresponding number. If the end of the input string was reached the number is returned, if instead a - was reached, then it is returned the number plus the result of the golfed program applied to the rest of the input string.


Sorting for search by monotomy Statement

Given N distinct integers, output them in order such that

for any integer J from 2 to N,

for any K>0 obtainable by dividing J by 2 (rounding down) at least one time,

the Jth integer output is larger than the Kth if and only if the division by 2 that gave K (i.e., the last division) divided an odd integer.

Note: this is for one-based index, as in common language, because it makes the statement less hairy. The motivating code below uses zero-based indexes.

This is a code golf. Output is a list of integers.

Example

Given the first 10 primes (in any order), the output must be in this order

 17  7  23  3  13  19  29  2  5  11

which, when rewritten as a binary tree, gives:

                 17
         /---------------\
        7                23
    /-------\         /------\
   3        13       19      29
  /-\      /
 2   5    11

Note: when walking up in this tree towards its root, the parent is obtained by dividing the (one-based) index by two. The statement's "odd" and "larger" correspond to node at index J being compared to one of it's ancestor node at index K situated on the left and above.

Motivation

This allows search in a static list by monotomy, simpler and typically faster than dichotomy.

// Search t in table *p of length n (with n<=MAX_INT/2 and n>=0)
// Returns the index (zero-based), or -1 for not found
// Assumes table *p is in monotomic order (see below)
int monotomy(const int *p, int n, int t) {
  int j;
  for( j = 0; j<n; j += (p[j]<t)+j+1 )
    if( p[j]==t )
      return j;
  return -1;
  }

// Return 1 iff table *p is in correct order for monotomy
// Table *p of length n is zero-based.
int monotomic(const int *p, int n) {
  int j,k,m;
  for( j = 2; j<n; ++j)
    for ( m = k = j; (k /= 2)>0; m = k)
      if ( (p[j-1]>p[k-1]) != (m%2) )  // zero-based indexes
        return 0;                      // incorrect order
  return 1;                            //   correct order
  }

// monotomy demo
#include <stdio.h>
int main(void) {
  const int p[] = { 17, 7, 23, 3, 13, 19, 29, 2, 5, 11, };
  #define n (sizeof(p)/sizeof(*p))
  int t, i, j;
  printf("monotomic = %d\n", monotomic(p, n) );
  for( t = i = 0; t<9999; ++t )
    if( ( j = monotomy(p, n, t) )>=0 )
      printf( "%d\n", p[++i, j] );
  if ( i!=n )
    printf("Incorrect\n");
  return 0;
  }

Jelly, 11 9 bytes

JBÇṙ€1ỤỤịṢ

Try it online! Explanation:

J           Create a range 1-(length of input array).
 B          Convert all the elements to binary.
  ṙ€1       Rotate each element left by 1.
     ỤỤ     Find each element's position within the sorted list.
       ịṢ   Apply that permutation to the sort of the input.


Write a program to output the nth fibonacci number in quinary Quinary is like binary, except that 1 is represented by the text of the program, and 0 is represented as the backwards text of the program.

The Fibonacci Sequence is the well known sequence

F(0) = 0, F(1) = 1, F(n) = F(n - 1) + F(n - 2)

Write a program that takes some input n and outputs the nth fibonacci number in quinary.

Standard code golf rules apply.

Python, 226 bytes
s='s=%r;a,b=0,1;exec"a,b=b,a+b;"*input();print"".join(map(lambda i:(s%%s)*int(i)+(s%%s)[::-1]*(1-int(i)),bin(a)[2:]))';a,b=0,1;exec"a,b=b,a+b;"*input();print"".join(map(lambda i:(s%s)*int(i)+(s%s)[::-1]*(1-int(i)),bin(a)[2:]))

It's quite a heavy modification to the standard Python Quine. It uses a,b=0,1;exec"a,b=b,a+b;" to generate Fibonacci numbers.


Write a binary counter in quine Write two code fragments, which we will call s_zero and s_one.

Program (l, n) consists of l copies of s_zero and s_one corresponding with the digits of n in binary, padded with s_zero on the left.

For example, if s_zero = foo and s_one = bar then
Program (4, 0) = foofoofoofoo
Program (4, 1) = foofoofoobar
Program (4, 2) = foofoobarfoo
etc.

Program (l, n) must print the source of Program (l, (n + 1) mod (2^l)) to standard out. In the example above, foobarfoofoo must print foobarfoobar when executed.

Your score is the sum of the lengths of fragments s_zero and s_one

CJam, 29 + 29 = 58 bytes

The 0 code:

0{"_~"]]z(3\+2b(2b2>a\+z~[}_~

The 1 code:

1{"_~"]]z(3\+2b(2b2>a\+z~[}_~

Explanation

0                       " Push the current bit. ";
{"_~"                   " The basic quine structure. ";
    ]                   " Make an array of the current bit, the function and _~.
                          That is the code fragment itself. ";
    ]                   " Make an array of all code fragments in the stack. ";
    z(                  " Extract the array of the bits. ";
    3\+2b(2b2>          " Convert from base 2, decrease by one and convert back,
                          keeping the length. ";
    a\+z                " Put the bits back to the original position. ";
    ~                   " Dump the array of code fragments back into the stack. ";
    [                   " Mark the beginning position of the array of the next code fragment. ";
}_~


Golfed fixed point combinator Write a fixed point combinator in as few characters as possible, in the language of your choice.

free form (i.e., whatever's shortest): whole program, actual function, code snippet
you may not use your standard library's if it has one
you may however extract it from other high-level functions it you'd rather do that than construct it from the bases

Please include a recursive factorial or Fibonacci that uses it as a demo.

In this question, self-reference is acceptable, the aim is solely to remove it from the recursive function it will apply to.

Haskell: 10 characters

y f=f$y f

Example of use to create recursive definitions of factorial or nth-Fibonacci:

> map ( y(\f n->if n <= 1 then 1 else n*f(n-1)) ) [1..10]
[1,2,6,24,120,720,5040,40320,362880,3628800]

> map ( y(\f n->if n <= 1 then 1 else f(n-1)+f(n-2)) ) [0..10]
[1,1,2,3,5,8,13,21,34,55,89]

Though, a more common way to use y would be to generate these sequences directly, rather than as functions:

> take 10 $ y(\p->1:zipWith (*) [2..] p)
[1,2,6,24,120,720,5040,40320,362880,3628800]

> take 11 $ y(\f->1:1:zipWith (+) f (tail f))
[1,1,2,3,5,8,13,21,34,55,89]

Of course, with Haskell, this is a bit like shooting fish in a barrel! The Data.Function library has this function, called fix, though implemented somewhat more verbosely.


Tips for golfing in CoffeeScript What tricks do you know to make CoffeeScript code shorter?

CoffeeScript is language that compiles into JavaScript ("transpiles" into ES3, to be exact). The golden rule is "It's just JavaScript", meaning there's no runtime overhead. Most of JavaScript Tips & Tricks apply as well.

As a side-effect that also means: developers coming from JavaScript (including myself) tend to use JavaScript constructs instead of shorter CoffeeScript alternatives.

This thread focuses on tips specific to CoffeeScript.

Links to related topics:

Tips for golfing in JavaScript

Tips for Golfing in ECMAScript 6 and above

Use destructuring assignments, if structure elements are used often

Eg. get elements of first argument array

func = ([x,y,z])->
    [i,j] = doSomething x, y, x+y
    doSomethingElse i, j

# instead of

func = (a)->
    b = doSomething a[0], a[1], a[0]+a[1]
    doSomethingElse b[0], b[1]

This can be combined with splats

[first, rest..., last] = doSmth()


Align lists like coreutils' `ls` Make program that takes the list from the files from STDIN, and aligns it nicely, just like ls command from coreutils. For example, assuming the following list (taken from The ASCII Collab, which takes place in the chatroom on this site).

alligator
ant
bear
bee
bird
camel
cat
cheetah
chicken
chimpanzee
cow
crocodile
deer
dog
dolphin
duck
eagle
elephant
fish
fly
fox
frog
giraffe
goat
goldfish
hamster
hippopotamus
horse
kangaroo
kitten
leopard
lion
lizard
llama
lobster
monkey
octopus
ostrich
otter
owl
oyster
panda
parrot
pelican
pig
pigeon
porcupine
puppy
rabbit
rat
reindeer
rhinoceros
rooster
scorpion
seal
shark
sheep
shrimp
snail
snake
sparrow
spider
squid
squirrel
swallow
swan
tiger
toad
tortoise
turtle
vulture
walrus
weasel
whale
wolf
zebra

Align the results, like the in the example below (the example shows columns set to 80). The terminal width is received as the first argument. If any argument is bigger than this argument, you can do anything. Try to use as many columns as possible with two space separators, as long nothing overflows.

alligator   crocodile  giraffe       llama    pig         shark     tiger
ant         deer       goat          lobster  pigeon      sheep     toad
bear        dog        goldfish      monkey   porcupine   shrimp    tortoise
bee         dolphin    hamster       octopus  puppy       snail     turtle
bird        duck       hippopotamus  ostrich  rabbit      snake     vulture
camel       eagle      horse         otter    rat         sparrow   walrus
cat         elephant   kangaroo      owl      reindeer    spider    weasel
cheetah     fish       kitten        oyster   rhinoceros  squid     whale
chicken     fly        leopard       panda    rooster     squirrel  wolf
chimpanzee  fox        lion          parrot   scorpion    swallow   zebra
cow         frog       lizard        pelican  seal        swan

Bash, 48 46 bytes

cd `mktemp -d`
xargs -d\\n tee
stty cols $1
ls

Guaranteed to work like ls.


Find the Smoothest Number Your challenge is to find the smoothest number over a given range. In other words, find the number whose greatest prime factor is the smallest.

A smooth number is one whose largest prime factor is small. Numbers of this type are useful for the fast Fourier transform algorithm, cryptanalysis, and other applications.

For instance, over the range 5, 6, 7, 8, 9, 10, 8 is the smoothest number, because 8's greatest prime factor is 2, whereas all of the other numbers have a prime factor of 3 or greater.

Input: The input will be two positive integers, which define a range. The minimum allowable integer in the range is 2. You may choose whether the range is inclusive, exclusive, semi-exclusive, etc, as long as an arbitrary range can be specified within the bounds of your language. You may take the numbers via function input, stdin, command line argument, or any equivalent method for your language. No encoding extra information in the input.

Output: Return, print or equivalent one or more integers in the input range which are maximally smooth (minimal greatest factor). Returning multiple results is optional, but if you choose to do so the results must be clearly delimited. Native output format is fine for multiple results.

Please state in your answer how you are taking input and giving output.

Scoring: Code golf. Count by characters if written in ASCII, or 8*bytes/7 if not in ASCII.

Test cases:

Note: These are Python-style ranges, including the low end but not the high end. Change as appropriate to your program. Only one result is necessary.

smooth_range(5,11)
8
smooth_range(9,16)
9, 12
smooth_range(9,17)
16
smooth_range(157, 249)
162, 192, 216, 243
smooth_range(2001, 2014)
2002

CJam - 13

q~,>{mfW=}$0=

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

Example input: 2001 2014
Example output: 2002

Explanation:

q~ reads and evaluates the input, pushing the 2 numbers on the stack (say min and max)
, makes an array [0 1 ... max-1]
> slices the array starting at min, resulting in [min ... max-1]
{…}$ sorts the array using the block to calculate the sorting key
mf gets an array with all the prime factors of a number, in order
W= gets the last element of the array (W=-1), thus obtaining the largest prime factor to be used as a sorting key
0= gets the first element of the (sorted) array


Recreation of Piet Mondrian Composition Good Afternoon,

Your goal is to, in the least amount of source code bytes, recreate any of Piet Mondrian's 'Composition' paintings (for instance, Composition #10).

The recreation can either use the actual colors, or replace it with the appropriate colours from the Windows Default 16 Color Palette.

Your recreation can be outputted in PNG, BMP or NetPBM, either to a file or to STDOUT, or directly to the screen.

Your recreation must be a resolution of 512x512 or higher.

Your recreation must not access the internet. If your program requires data files, then their size will be added to the size of your source.

Your score will be the size of your source file in bytes.

Please state with your entry which painting you're recreating, and provide a link to the original and a picture of your recreation.

Good Luck.

Tikz, 175 bytes

Composition III in Black and White, 175 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz{\def\b{;\draw[line width=}\def\a{)--(}\clip(1,1\a1,5\a5,5\a5,1)\b2mm](0,4\a6,4\a6,3\a4,3)\b1mm](4,0\a4,5);}\end{document}

Verify it in the Blogosphere

This is perhaps one of Mondrian's most minimalistic works and I am surprised no one has found it yet.  It is not however particularly interesting so I have included several other paintings in my answer.

Explanation

There is a bit of a wrapper that is associated with every tikz answer.  The wrapper is:

\documentclass[tikz]{standalone}\begin{document}\tikz{
}\end{document}

Once you get past the wrapper there are a few \def statements that save bytes but unfortunately obfuscate the code:

\def\b{;\draw[line width=}\def\a{)--(}

If we make all the proper substitutions our code comes out looking like:

\clip(1,1)--(1,5)--(5,5)--(5,1);
\draw[line width=2mm](0,4)--(6,4)--(6,3)--(4,3);
\draw[line width=1mm](4,0)--(4,5);

The first bit is a \clip and is very important, but we will skip over it for the time being.

Now we draw the first line on the blank canvas,  This line is rather thick so we use [line width=2mm] to set the thickness to 2mm:

\draw[line width=2mm](0,4)--(6,4)--(6,3)--(4,3);

This connects a couple of nodes and produces this shape:

Next we \draw a second stroke, however this stroke is thinner so we have to set the line thickness to 1mm:

\draw[line width=1mm](4,0)--(4,5);

Now our painting looks like:

This is close to the original but not quite, so here is where the \clip comes into play.  We use the \clip to remove all the extra lines from our canvas and set the canvas to the correct size.  With the canvas resized we get the image:

Composition With Yellow Patch, 214 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz[line width=2mm]{\clip(1,1)rectangle(7,7);\draw(0,8)rectangle(4,3.5)rectangle(6.5,1.2)rectangle(4,0);\draw[fill=yellow](6.5,3.5)rectangle(8,2.5);}\end{document}

Evaluate it in CyberSpace

Explanation to come

Composition II in Blue and Yellow, 225 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz[line width=2mm]{\clip(1,1)rectangle(7,10);\draw(8,9)rectangle(3,6)rectangle(0,0);\draw[fill=yellow](0,0)rectangle(3,2);\draw[fill=blue](0,11)rectangle(3,9);}\end{document}

Assess it over the Webbernetz!

Explanation to come

Composition B (No. 2) in Red, 232 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz[line width=2mm]{\clip(1,1)rectangle(10,13);\draw[line width=1mm](1.2,5)--(1.2,9);\draw[fill=red](0,14)rectangle(5,9);\draw(0,9)rectangle(11,5)(7,0)rectangle(5,14);}\end{document}

Attempt it within the Internet!

Explanation

First here is the code with line breaks inserted to make it more readable:

\documentclass[tikz]{standalone}
\begin{document}
\tikz[line width=2mm]{
\clip(1,1)rectangle(10,13);
\draw[line width=1mm](1.2,5)--(1.2,9);
\draw[fill=red](0,14)rectangle(5,9);
\draw(0,9)rectangle(11,5)(7,0)rectangle(5,14);
}
\end{document}

The first command of interest is

\draw[fill=red](0,14)rectangle(5,9);

This draws a red rectangle with a black outline.  For the upper left hand corner of the painting.

We then draw two more rectangles with white interiors and black outlines to create the grid pattern on the painting

\draw(0,9)rectangle(11,5)(7,0)rectangle(5,14);

We then draw in a thin line

\draw[line width=1mm](1.2,5)--(1.2,9);

And crop the image to the proper size

\clip(1,1)rectangle(10,13);

Composition II in Red, Blue and Yellow, 251 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz[line width=1mm]{\clip(1,1)rectangle(9,9);\draw[fill=yellow](8.5,6)--(0,6)--(8.5,6)--(8.5,2)rectangle(10,0);\draw[fill=red](3,3)rectangle(10,10);\draw[fill=blue](0,0)rectangle(3,3);}\end{document}

Test it upon the World Wide Web!

Explanation

First I will insert some line breaks to make my code readable

\documentclass[tikz]{standalone}
\begin{document}
\tikz[line width=1mm]{
\clip(1,1)rectangle(9,9);
\draw[fill=yellow](8.5,6)--(0,6)--(8.5,6)--(8.5,2)rectangle(10,0);
\draw[fill=red](3,3)rectangle(10,10);
\draw[fill=blue](0,0)rectangle(3,3);
}
\end{document}

The first line of importance is:

\draw[fill=yellow](8.5,6)--(0,6)--(8.5,6)--(8.5,2)rectangle(10,0);

This draws the following shape:

This strange shape is the yellow rectangle in the lower right corner and the two lines that are no the edge of a colored rectangle.  Next we insert the red square and cover up the extra lines made by the last shape:

\draw[fill=red](3,3)rectangle(10,10);

This comes out looking like:

Now we insert our blue square:

\draw[fill=blue](0,0)rectangle(3,3);

Now all that is left is to crop out all the unnecessary parts of the image using a \clip

\clip(1,1)rectangle(10,10);

Composition II, 308 bytes

\documentclass[tikz]{standalone}\begin{document}\tikz[line width=2mm]{\clip(1,1)rectangle(12.6,13);\draw(0,0)rectangle(10,4)rectangle(2,12)--(0,12);\draw[fill=red](10,1.6)rectangle(14,0);\draw[fill=yellow](6,12)rectangle(10,14);\draw[fill=blue](0,4)rectangle(2,8);\fill(10,10)rectangle(14,14);}\end{document}

Check it out on the Information-Super-Highway

Explanation to come


Reaching one's lucky numbers in reputation A new code-golfer, Joe, just registered to the site. He has 1 reputation but determined to reach all his lucky numbers in reputation exactly. Joe believes in higher powers which will help him to achieve his goal with minimal amount of (his or others) actions. As a new user he also believes that negative reputation is possible.

You should write a program or function which helps Joe to compute how many action should he expect.

Details

The actions can change the reputation by the following amounts (all actions are available at every step regardless of stackexchange rules):

answer accepted:     +15
answer voted up:     +10
question voted up:    +5
accepts answer:       +2
votes down an answer: −1
question voted down:  −2

Other special reputation changes are disregarded.
Lucky numbers can be negative and can be reached in any order.
Your solution has to solve any example test case under a minute on my computer (I will only test close cases. I have a below-average PC.).

Input

Joe's lucky numbers as a list of integers in a common form of your language.

Output

The number of minimum actions needed as a single integer.
Output could be printed to stdout or returned as an integer.

Examples

Input => Output (Example reputation states)

1                     => 0  (1)
3 2 1                 => 2  (1 -> 3 -> 2)
2 10 50               => 7  (1 -> 3 -> 2 -> 12 -> 10 -> 25 -> 40 -> 50)
10 11 15              => 3  (1 -> 11 -> 10 -> 15)
42 -5                 => 7  (1 -> -1 -> -3 -> -5 -> 10 -> 25 -> 40 -> 42)
-10                   => 6  (1 -> -1 -> -3 -> -5 -> -7 -> -9 -> -10)
15 -65                => 39
7 2015 25 99          => 142
-99 576 42 1111 12345 => 885

This is code-golf so the shortest entry wins.

Rust, 929 923 characters

use std::io;use std::str::FromStr;static C:&'static [i32]=&[-2,-1,2,5,10,15];fn main(){let mut z=String::new();io::stdin().read_line(&mut z).unwrap();let n=(&z.trim()[..]).split(' ').map(|e|i32::from_str(e).unwrap()).collect::<Vec<i32>>();let l=*n.iter().min().unwrap();let x=n.iter().max().unwrap()-if l>1{1}else{l};let s=g(x as usize);println!("{}",p(1,n,&s));}fn g(x:usize)->Vec<i32>{let mut s=vec![std::i32::MAX-9;x];for c in C{if *c>0&&(*c as usize)<=x{s[(*c-1)as usize]=1;}}let mut i=1us;while i<x{let mut k=i+1;for c in C{if(i as i32)+*c<0{continue;}let j=((i as i32)+*c)as usize;if j<x&&s[j]>s[i]+1{s[j]=s[i]+1;if k>j{k=j;}}}i=k;}s}fn p(r:i32,n:Vec<i32>,s:&Vec<i32>)->i32{if n.len()==1{h(r,n[0],&s)}else{(0..n.len()).map(|i|{let mut m=n.clone();let q=m.remove(i);p(q,m,&s)+h(r,q,&s)}).min().unwrap()}}fn h(a:i32,b:i32,s:&Vec<i32>)->i32{if a==b{0}else if a>b{((a-b)as f32/2f32).ceil()as i32}else{s[(b-a-1)as usize]}}

This was fun!

Commentary on the implementation

So I'm obviously not too happy with the size. But Rust is absolutely terrible at golfing anyway. The performance, however, is wonderful.

The code solves each of the test cases correctly in a near-instantaneous amount of time, so performance is obviously not an issue. For fun, here's a much more difficult test case:

1234567 123456 12345 1234 123 777777 77777 7777 777

for which the answer is 82317, which my program was able to solve on my (medium-performance) laptop in 1.66 seconds (!), even with the recursive brute-force Hamiltonian path algorithm.

Observations

First we should build a modified weighted graph, with the nodes being each "lucky" number and the weights being how many changes it takes to get from one reputation level to another. Each pair of nodes must be connected by two edges, since going up is not the same as going down in reputation value (you can get +10, for example, but not -10).
Now we need to figure out how to find the minimum amount of changes from one rep value to another.

For getting from a higher value to a lower value, it's simple: just take ceil((a - b) / 2) where a is the higher value and b is the lower value. Our only logical option is to use the -2 as much as possible, and then the -1 once if necessary.
A low to high value is a bit more complicated, since using the greatest possible value is not always optimal (ex. for 0 to 9, the optimal solution is +10 -1). However, this is a textbook dynamic programming problem, and simple DP is enough to solve it.

Once we have calculated the minimum changes from each number to every other number, we are essentially left with a slight variant of TSP (travelling salesman problem). Luckily, there are a small enough number of nodes (a maximum of 5 in the hardest test case) that brute force is sufficient for this step.

Ungolfed code (heavily commented)

use std::io;
use std::str::FromStr;

// all possible rep changes
static CHANGES: &'static [i32] = &[-2, -1, 2, 5, 10, 15];

fn main() {
    // read line of input, convert to i32 vec
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let nums = (&input.trim()[..]).split(' ').map(|x| i32::from_str(x).unwrap())
        .collect::<Vec<i32>>();

    // we only need to generate as many additive solutions as max(nums) - min(nums)
    // but if one of our targets isn't 1, this will return a too-low value.
    // fortunately, this is easy to fix as a little hack
    let min = *nums.iter().min().unwrap();
    let count = nums.iter().max().unwrap() - if min > 1 { 1 } else { min };
    let solutions = generate_solutions(count as usize);

    // bruteforce!
    println!("{}", shortest_path(1, nums, &solutions));
}

fn generate_solutions(count: usize) -> Vec<i32> {
    let mut solutions = vec![std::i32::MAX - 9; count];

    // base cases
    for c in CHANGES {
        if *c > 0 && (*c as usize) <= count {
            solutions[(*c-1) as usize] = 1;
        }
    }

    // dynamic programming! \o/
    // ok so here's how the algorithm works.
    // we go through the array from start to finish, and update the array
    //   elements at i-2, i-1, i+2, i+5, ... if solutions[i]+1 is less than
    //   (the corresponding index to update)'s current value
    // however, note that we might also have to update a value at a lower index
    //   than i (-2 and -1)
    // in that case, we will have to go back that many spaces so we can be sure
    //   to update *everything*.
    // so for simplicity, we just set the new index to be the lowest changed
    //   value (and increment it if there were none changed).
    let mut i = 1us;  // (the minimum positive value in CHANGES) - 1 (ugly hardcoding)
    while i < count {
        let mut i2 = i+1;
        // update all rep-values reachable in 1 "change" from this rep-value,
        //   by setting them to (this value + 1), IF AND ONLY IF the current
        //   value is less optimal than the new value
        for c in CHANGES {
            if (i as i32) + *c < 0 { continue; }  // negative index = bad
            let idx = ((i as i32) + *c) as usize;  // the index to update
            if idx < count && solutions[idx] > solutions[i]+1 {
                // it's a better solution! :D
                solutions[idx] = solutions[i]+1;
                // if the index from which we'll start updating next is too low,
                //   we need to make sure the thing we just updated is going to,
                //   in turn, update other things from itself (tl;dr: DP)
                if i2 > idx { i2 = idx; }
            }
        }
        i = i2;  // update index (note that i2 is i+1 by default)
    }

    solutions
}

fn shortest_path(rep: i32, nums: Vec<i32>, solutions: &Vec<i32>) -> i32 {
    // mercifully, all the test cases are small enough so as to not require
    //   a full-blown optimized traveling salesman implementation
    // recursive brute force ftw! \o/
    if nums.len() == 1 { count_changes(rep, nums[0], &solutions) }  // base case
    else {
        // try going from 'rep' to each item in 'nums'
        (0..nums.len()).map(|i| {
            // grab the new rep value out of the vec...
            let mut nums2 = nums.clone();
            let new_rep = nums2.remove(i);
            // and map it to the shortest path if we use that value as our next target
            shortest_path(new_rep, nums2, &solutions) + count_changes(rep, new_rep, &solutions)
        }).min().unwrap()  // return the minimum-length path
    }
}

fn count_changes(start: i32, finish: i32, solutions: &Vec<i32>) -> i32 {
    // count the number of changes required to get from 'start' rep to 'finish' rep
    // obvious:
    if start == finish { 0 }
    // fairly intuitive (2f32 is just 2.0):
    else if start > finish { ((start - finish) as f32 / 2f32).ceil() as i32 }
    // use the pregenerated lookup table for these:
    else /* if finish > start */ { solutions[(finish - start - 1) as usize] }
}


Last non-zero digit of n! Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive).  This is OEIS sequence A008904.

Your program needs finish within 10 seconds on a reasonable machine for any valid input.

Test Cases

1 => 1
2 => 2
3 => 6
4 => 4
5 => 2
6 => 2
7 => 4
8 => 2
9 => 8
10 => 8
100 => 4
1000 => 2
10000 => 8
100000 => 6
1000000 => 4

This is a code-golf so the shortest code in bytes wins!

Mathematica, 45 36 bytes

Last@Select[IntegerDigits[#!],#>0&]&

Very readable for a winning answer. :) (Then again, there's no GolfScript & Co. submission yet.)

This handles input 1,000,000 in about 5 seconds on my machine.


Alphabet printing challenge This challenge is related
Challenge
Your task is to write as many programs/snippets as you can, where each one outputs/prints/ returns an alphabet. The first program must output the letter A or a, the second one B or b and so on.
You can not reuse any characters between the programs (Except Whitespace, it can be reused through snippets). So, if the first program is: 0==0, then you may not use the characters 0 and = again in any of the other programs. Note: It's allowed to use the same character many times in one program.
Scoring:
The winner will be the submission that can print alphabets up to the highest, if anyone can print upto Z or z, it will receive an extra +50 bounty from me. In case there's a tie, the winner will be the submission that used the fewest number of bytes in total.
Rules:

You can only use a single language for all alphabets, polygots not supported
Snippets are allowed! But quine snippets like A which prints A are not allowed.
leading and trailing spaces  are not allowed. But newlines are allowed
You may disregard STDERR, as long as the correct output is returned to STDOUT
You cannot choose to output the letters to STDERR.
Letters are case sensitive a != A.
The programs/snippets must be independent
Whitespace can be reused
Output is case-insensitive, you may choose to either output a or A but not both!
You can't use a function, that does not print anything, such as f(){print a} will print a when it is called, but if you don't call the function, then that snippet/program is invalid.
Minimum submission length should be 1 byte, but again quines are not allowed


What associativity was it again Non-associative operators (for example the subtraction-operator) often are either left- or right associative, such that one has to write less parentheses. Consider for example the following:

$$
a-b-c
$$

Probably everybody read that as \$(a-b)-c\$, by default (usually) subtraction is left-associative.

Now let us consider some operation \$\diamond: X \times X \to X\$, the only thing we know about it is that it is not associative. In this case the following is ambiguous:

$$
a \diamond b \diamond c
$$

It could either mean \$(a \diamond b) \diamond c\$ or it could mean \$a \diamond (b \diamond c)\$.

Challenge

Given some possibly parenthesised expression that is ambiguous, your task is to parenthesise it such that there is no ambiguity. You can chooose freely whether the operator should be left- or right associative.

Since there is only one operation the operator is only implied, so for the above example you'll get abc as input. For left-associative you'll output (ab)c and for right-associative you'll output a(bc).

Input / Output

Input will be a string of at least 3 characters

the string is guaranteed to be ambiguous (ie. there are missing parentheses)
you're guaranteed that no single character is isolated (ie. (a)bc or a(bcd)e is invalid input)
the string is guaranteed to only contain alphanumeric ASCII (ie. [0-9], [A-Z] and [a-z]) and parentheses (you may choose (), [] or {})

Output will be a minimally1 parenthesized string that makes the string unambiguous

as with the input you may choose between (), [], {} for the parentheses
output may not contain whitespace/new-lines, except for leading and trailing ones (finite amount)

Test cases

These use () for parentheses, there is a section for each associativity you may choose (ie. left or right):

Left associative

abc -> (ab)c
ab123z -> ((((ab)1)2)3)z
ab(cde)fo(0O) -> ((((ab)((cd)e))f)o)(0O)
(aBC)(dE) -> ((aB)C)(dE)
code(Golf) -> (((co)d)e)(((Go)l)f)
(code)Golf -> ((((((co)d)e)G)o)l)f

Right associative

abc -> a(bc)
ab123z -> a(b(1(2(3z))))
ab(cde)fo(0O) -> a(b((c(de))(f(o(0O)))))
(aBC)(dE) -> (a(BC))(dE)
code(Golf) -> c(o(d(e(G(o(lf))))))
(code)Golf -> (c(o(de)))(G(o(lf)))

1: Meaning removing any pair of parentheses will make it ambiguous. For example a(b(c)) or (a(bc)) are both not minimally parenthesised as they can be written as a(bc) which is not ambiguous.

Retina 0.8.2, 61 bytes

+1`(\(((\()|(?<-3>\))|[^()])+(?(3)$)\)|[^()]){2}(?=[^)])
($&)

Try it online! Link includes test cases. Explanation: I'd really like to use a recursive regex (([^()]|\((?1)\)){2})(?=[^)]) here, but .NET only has balancing groups, so it's a bit verbose.

+1`

Repeatedly replace the first match each time. This ensures left-associativity.

(           Either
 \(          Match outer `(`
 (           Either
  (\()        Capture a `(` into $3
 |           Or
  (?<-3>\))   A `)` if it matched an earlier `(`
 |           Or
  [^()]       Something else
 )+          Match as much of the above as possible
 (?(3)$)     But don't leave `(`s unmatched
 \)          Match outer `)`
|           Or
 [^()]       Match something else
){2}        Match the above twice
(?=[^)])    Followed by a non-`)`

Either, a ( followed by a string containing balanced ()s,  followed by a ), or a non-(), twice, followed by a non-). This represents an ambiguous match.

($&)

Wrap the match in disambiguating parentheses.


Slowly converging zigzag Given a single positive odd integer as input, return a converging zigzag as a list of strings, list of lists of characters, or newline-separated string, in this form:

#
 #
  #
   #
    #
   #
  #
 #
  #
   #
  #

You can replace # with any consistent non-whitespace character. Trailing whitespace on each line is allowed and a trailing newline is allowed.

The zig-zag starts at column 1 and for each row moves right one column, until it reaches column n (where n is the input). Then, it moves left to 2, then right to n-1, then left to 3, with the two bounds converging in until the zigzag ends in the middle column ((n+1)/2).

Test Cases

The example above is the test case for 5.

The following are individual test cases:

3
#
 #
  #
 #

7
#
 #
  #
   #
    #
     #
      #
     #
    #
   #
  #
 #
  #
   #
    #
     #
    #
   #
  #
   #
    #
   #

1

#

C (gcc), 89 bytes

f(n,a,b){puts("0");for(a=n;--a>n/2;)for(b=n-2*a;b<=2*a-n;)printf(" %*d\n",a-abs(b++),0);}

Try it online!

Works by analyzing the sequence of number of spaces as (for n=7):

          0
1 2 3 4 5 6 5 4 3 2 1
    2 3 4 5 4 3 2
        3 4 3

And for n=3:

  0
1 2 1

We can see that the middle number (a in the code) runs from [n-1, n/2). Then, the difference between the first number and the middle number is:

a  n  b  2a-n
-------------
6  7  5  5
5  7  3  3
4  7  1  1
2  3  1  1

So, if we have b going through [-(2a-n), 2a-n], a-abs(b) will give us the desired sequence. This is essentially what the code does.


Most Populated WordSearch Write a program to generate a rectangular word-search of size 6x9. Words may go downwards, rightwards and diagonally (downwards and to the right), they may also overlap on the board.

The challenge is to include as many different English words as possible from https://www.ef.co.uk/english-resources/english-vocabulary/top-3000-words Your program may select desirable words itself to include. You score 1 point per word included.

For example:

For clarity I've used "." symbols below instead of random letters.

dolphin..
o.....o..
g.....u..
.....ono.
.........
.........

The above word-search contains {'do', 'dog', 'dolphin', 'hi', 'i', 'in', 'no', 'noun', 'on', and 'phi'} so from what is filled in so far scores 10 points.

In the unlikely event of a tie the shortest code size will be used to choose a winner.

Jelly, 20 bytes, score  53  57
“¦/œḌ⁼ƥ~ẹµḲ5&Ċd@ṡ»ḲY

Try it online!
Wordsearch:
a d m i s s i o n
h o u s e h o l d
s o m e t h i n g
g e n e r a l l y
p o t e n t i a l
t h e r e f o r e

Words:
admission generally household potential something therefore
general mission
house stair there thing
ally gene here hill hold miss some tent thin
air all due era for hat her ill oil old one pot see set son ten the use
ad ah at do go he hi ie in me ms oh on or so to us
i

Previous
...the dictionary referenced in the question has changed since this was posted so this would drop to a score of 33.
Jelly, 23 bytes, score  150 154 158  160
“RʂȥḄ0ḣq⁾÷yḊzIḥẊḥYx »ḲY

Try it online!
Used Python to search for boards; there are, no doubt, higher scores possible though.
The board:
donations
beverages
placement
performed
metallica
thousands

The words:
['a', 'ac', 'ace', 'ae', 'ag', 'age', 'ages', 'al', 'all', 'am', 'an', 'and', 'ar', 'art', 'as', 'at', 'ati', 'au', 'b', 'be', 'beverage', 'beverages', 'bp', 'c', 'ca', 'cd', 'ce', 'cement', 'cf', 'd', 'da', 'das', 'db', 'do', 'don', 'donation', 'donations', 'ds', 'e', 'ec', 'ed', 'ee', 'eh', 'el', 'em', 'en', 'ent', 'er', 'era', 'es', 'et', 'ev', 'eve', 'ever', 'f', 'fa', 'fo', 'for', 'form', 'formed', 'g', 'ge', 'gem', 'h', 'ho', 'i', 'ia', 'ic', 'in', 'io', 'ion', 'l', 'la', 'lace', 'le', 'lee', 'li', 'll', 'ls', 'm', 'me', 'med', 'men', 'ment', 'met', 'meta', 'metal', 'metallic', 'metallica', 'mi', 'min', 'mr', 'mt', 'n', 'na','nat', 'nation', 'nations', 'nd', 'ne', 'nec', 'ns', 'nt', 'nv', 'o', 'oe', 'og', 'ol', 'on', 'ons', 'or', 'ou', 'p', 'pe', 'per', 'perform', 'performed', 'pl', 'place', 'placement', 'pm', 'pp', 'ppm', 'r', 'ra', 'rage', 're', 'rf', 'rl', 'rm', 'rt', 's', 'sa', 'san', 'sand', 'ss', 'st', 'std', 't', 'ta', 'tall', 'td', 'th', 'thou', 'thousand', 'thousands', 'ti', 'tion', 'tions', 'to', 'tr', 'treo', 'u', 'us', 'usa', 'v', 'va', 'var', 've', 'ver']

The search

Note LIMIT_TO_N_BEST_NINES limits the search - lower numbers try fewer boards by never using the lower scoring rows (nine letter words) which will find "good" scores quicker, while higher numbers (up to 909 - the number of 9 letter words in the dictionary) will search more boards (and likely never complete!).
f = open(filePath, 'r')
ws = set(w.replace('\n', '').lower() for w in f.readlines())

def iterSubWords(w, ws):
    for l in range(1,len(w)+1):
        for s in range(len(w)-l+1):
            if w[s:s+l] in ws: yield w[s:s+l]

nines = sorted([w for w in ws if len(w) == 9], key=lambda w:len(tuple(iterSubWords(w, ws))), reverse=1)

def diags(rows):
    for rs in range(len(rows)):
        yield ''.join(rows[rs + x][x] for x in range(min(len(rows) - rs, len(rows[0]))))
    for cs in range(1, len(rows[0])):
        yield ''.join(rows[x][cs + x] for x in range(min(len(rows[0]) - cs, len(rows))))

def diagWords(rows, validWords):
    for d in diags(rows):
        for sw in iterSubWords(d, validWords): yield sw

def allWordsOnBoard(rows, validWords):
    r = set()
    for row in list(rows) + [''.join(col) for col in zip(*rows)]:
        for validWord in iterSubWords(row, validWords): r.add(validWord)
    for validWord in diagWords(rows, validWords): r.add(validWord)
    return r

from itertools import combinations, permutations

LIMIT_TO_N_BEST_NINES = 107

m = 0
for wl in combinations(nines[:LIMIT_TO_N_BEST_NINES], 6):
    fws = allWordsOnBoard(wl, ws)
    if len(fws) > m:
        for p in permutations(wl):
            fws = allWordsOnBoard(p, ws)
            if len(fws) > m:
                m = len(fws)
                print(m, p)


Determine the optimal cruise control options A cruise control has 3 different options to move the handle to set the speed you want to drive with.

Towards you: Adds 1 speed.
Upwards: Increases speed to the next multiple of 10 (e.g. 20-->30, 32-->40)
Downwards: Decreases speed to the next multiple of 10 (e.g. 20-->10, 32-->30)

Input

2 integers: the first is the starting speed and the second is your desired speed, both non-negative and in any form you like (array, two arguments, etc.)

Task

Determine the optimal way of using the handle to reach the desired speed and print out the moves in the correct order.

Rules

If you have the choice between pulling towards you and going upwards (like from 39 to 40) you can choose either option, but stay with whatever you choose for similar cases
You may use any 3 different (preferably visible) symbols to distinguish between the moves in the output (T, U and D for example).
The symbols can be seperated by new lines, spaces, etc. but don't have to be

Here are some test cases:

start speed, desired speed  -->  output
30, 40  -->  U
30, 43  -->  UTTT
43, 30  -->  DD
51, 39  -->  DDDTTTTTTTTT
29, 30  -->  T or U
29, 50  -->  TUU or UUU
12, 12  -->

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

JavaScript (ES6), 91 84 75 bytes

Saved 4 bytes thanks to @Neil

f=(s,d)=>s-d?(q=s+10-s%10)>d?s>d?0+f(s-(s%10||10),d):1+f(s+1,d):2+f(q,d):""

Uses 0 for D, 1 for T, and 2 for U.


Guide my eyes in the right direction Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source).
A valid answer:

Takes a number
\$w\$ and (assumed non-negative) integer \$x\$.
Starts with an integer list with a length of \$2^w\$, initially filled with zeroes.
For each number \$n\$ from \$0\$ to \$w-1\$ (inclusive), divides the list into sub-lists of size \$2^n\$, then increments all of the values in the sub-list that contains the index \$x\$.
Returns this list

(Of course a program doesn't have to do exactly this if it returns the right results. If someone finds a good declarative algorithm I will upvote it.)
Examples
(examples are 0 indexed, your answer doesn't have to be)
w=3, x=1
23110000

w=2, x=2
0021

w=3, x=5
00002311

w=4, x=4
1111432200000000

w=2, x=100
Do not need to handle (can do anything) because x is out of bounds

Example of basic algorithm for \$w=3, x=5\$

List is \$[0,0,0,0,0,0,0,0]\$
\$n\$ is \$0\$, list is split into \$[[0],[0],[0],[0],[0],[0],[0],[0]]\$, \$x\$ is in sixth sub-list, list becomes \$[0,0,0,0,0,1,0,0]\$
\$n\$ is \$1\$, list is split into \$[[0,0],[0,0],[0,1],[0,0]]\$, \$x\$ is in third sub-list, list becomes \$[0,0,0,0,1,2,0,0]\$
\$n\$ is \$2\$, array is split into \$[[0,0,0,0],[1,2,0,0]]\$, \$x\$ is in second half, array becomes \$[0,0,0,0,2,3,1,1]\$
Result is \$[0,0,0,0,2,3,1,1]\$

Jelly, 10 bytes
2*Ḷ^‘l2Ċ⁸_

A dyadic Link that accepts \$w\$ on the left and \$x\$ on the right and yields a list of integers.
Try it online!
How?
2*Ḷ^‘l2Ċ⁸_ - Link: integer, w; integer x   e.g.  3; 5
2          - two                                 2
 *         - (2) exponentiate (w)                8
  Ḷ        - lowered range                       [0,1,2,3,4,5,6,7]
   ^       - XOR (x)                             [5,4,7,6,1,0,3,2]
    ‘      - increment                           [6,5,8,7,2,1,4,3]
     l2    - log base two                        [2.58,2.32,3,2.80,1,0,2,1.58]
       Ċ   - ceiling                             [3,3,3,3,1,0,2,2]
        ⁸  - chain's left = w                    3
         _ - subtract                            [0,0,0,0,2,3,1,1]

Without floating points involved, also 10: 2*Ḷ^ḤBẈ⁸_‘
...would be 8 if 0 in binary were [] rather than [0] (2*Ḷ^BẈ⁸_)


Generate a 1920 x 1080 graphic with 2,073,600 unique colours Challenge:

Write a program that outputs a graphic file 1920 pixels wide by 1080 pixels high. Every one of the 2,073,600 pixels within the graphic must be a unique colour and no colour values should be repeated. The colours should be specified in RGB and start at 0,0,0 and count upwards in sequence towards 255,255,255. You'll find a 1920 x 1080 pixel image will contain lots of blacks, blues and greens only.

For example, (a smaller cut down version). If the height was set to 5 and the width was set to 5 a 25 pixel square graphic would be output and each pixel would be a unique colour. The RGB colour array would look like this:

Array (
[0] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 0
    )

[1] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 1
    )

[2] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 2
    )

[3] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 3
    )

[4] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 4
    )

[5] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 5
    )

[6] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 6
    )

[7] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 7
    )

[8] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 8
    )

[9] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 9
    )

[10] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 10
    )

[11] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 11
    )

[12] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 12
    )

[13] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 13
    )

[14] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 14
    )

[15] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 15
    )

[16] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 16
    )

[17] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 17
    )

[18] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 18
    )

[19] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 19
    )

[20] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 20
    )

[21] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 21
    )

[22] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 22
    )

[23] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 23
    )

[24] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 24
    )

)

Rules:

Any programming language can be used to generate the image.
The answer with the most upvotes wins.
Colours must only be used once.
Pixel in position 0,0 must start with colour 0,0,0
Colours must fall within the true color 24 bit range.
Image must be 1920 x 1080 pixels in size.
Colours must be in RGB format.
Using a library to output the image is ok.
Output must be in the format of a graphic file e.g. output.png
Output as text which represents the colour values doesn't count, the code must output a graphic file.
File size of the output image doesn't matter.
You must be able to view the output by opening it as a graphic in the chrome web browser.

I would be impressed if you mange to do this with really short code, your program also outputs the time in elapsed seconds taken to generate the image embedded within the image itself overlaid on the sequential pixels, your program outputs the image within 10 seconds. I would be really impressed if your program outputs the image within 1 second.

Python - 660+ bytes
Incremental Version

Full Size: http://www.pictureshack.net/images/57626_all_colors.png (4.52MB)
This is an image based on a Julia Set fractal. Each color is added to the image incrementally, although there is a substantial amount of pre-calculation.

Luminosity Version

Full size: http://www.pictureshack.net/images/95389_all_colors4.png (5.24MB)
I've added an option to iterate each color by luminosity, rather than by index. This doesn't qualify as "counting up" from zero, but this seems to be a lax requirement. It's interesting that these two orderings expose completely different structures in the image. To use this, set the use_luminosity flag to True.

Source
Requires PIL.
Be warned: this will take several minutes to execute. Using PyPy with Pillow runs in about one fifth the time of CPython with PIL, so I would recommend that, if possible.
from PIL import Image, ImageDraw

use_luminosity = True

dim = (1920,1080)

img = Image.new('RGB', dim)
draw = ImageDraw.Draw(img)

xstart = -.776707
ystart = -.134663

a = []

xd = 1.6 / 8192 / dim[0]
yd = 0.9 / 8192 / dim[1]

for x in range(dim[0]):
  print x
  for y in range(dim[1]):
    z = d = complex(xstart + x*xd, ystart + y*yd)
    c = 0
    while abs(z) < 2 and c < 5000:
      z = z*z + d
      c += 1
    a += [(c, -abs(z), x, y)]

a = a[1:]
a.sort(reverse = True)

t = [(i>>16, 255&i>>8, 255&i) for i in range(1, dim[0]*dim[1])]
if use_luminosity:
  t.sort(key = lambda c: c[0]*3 + c[1]*10 + c[2], reverse = True)

r = 0
for c,d,x,y in a:
  draw.point((x,y), t[r])
  r += 1

img.show()

Edit: updated so that #000000 is at the upper-left, as specified.
Edit: added a flag to iterate colors by luminosity.
Edit: switched to native complex calculations, and integer luminosity weights, which are slightly faster.

Solutions I worked on before the primary criterion became popularity-contest
PHP - 161 bytes
<?header('Content-type: image/bmp');
ob_start();
echo'BM'.pack('I5S2',0,0,26,12,70780800,1,24);
for(;$i=($i-256)%2073601;)echo pack('CS',~$i,~$i>>8);
ob_end_flush();

This is going for fastest output possible. No library is used, just a pre-computed header, and direct byte output. Runs in less than 2s on my comp. By incrementing by 256 rather than 1, it produces a pseudo-gradient effect, with no real computation needed. The only downfall is that (0, 0) is not black, but the result looks a lot nicer.
ob_start(); and ob_end_flush(); aren't strictly necessary, but buffering the output makes it run a lot faster.

Other interesting increments include:
17: http://i.stack.imgur.com/ieyyZ.png
103: http://i.stack.imgur.com/WD2wa.png
326: http://i.stack.imgur.com/c4DSF.png
557: http://i.stack.imgur.com/eTTWE.png
943: http://i.stack.imgur.com/7rrmR.png
2125: http://i.stack.imgur.com/Ct1kM.png
And many others. Although, most patterns that look like anything resemble stripes of some sort

PHP - 105 bytes
<?=BM.pack(I5S2,header('Content-type:'),0,26,12,70780800,1,24);
for(;$i<2073600;)echo pack(CS,$i,$i++>>8);

Reckless disregard version.

Given a broken Content-type header, Chrome will do its best to figure out what it was sent. In this case, it correctly identifies it as image/bmp. The lastest versions of FireFox and IE are also able to fix the broken header.
The barewords BM, I5S2, and CS will generate a NOTICE error. To prevent corruption of the image, error reporting in php.ini will need to be set to prevent this (e.g. error_reporting = E_ALL & ~E_NOTICE).
No output buffering. The image is constructed 3 bytes at a time, which is noticeably slower.
The point (0, 0) is considered to be the lower left, rather than upper left.

PHP-CLI - 83 bytes
<?=BM.pack(I5S2,0,0,26,12,70780800,1,24);
for(;$i<2073600;)echo pack(CS,$i,$i++>>8);

Run directly from the command line and piped to a file (e.g. $ php all-colors.php > out.bmp), no Content-type header is necessary. The resulting file is identical to the 105 byte version, and can be viewed in Chrome.


GPS: Golfed Positioning System Your mission, should you choose to accept it, is to write code for a GPS receiver.

Input

The current time, as nanoseconds from the Unix epoch. [EDIT: This is optional, please state whether you require it]
Four satellite signals, in the following format:

The time the signal was sent, as nanoseconds from the Unix epoch. You must be able to handle dates up to and including 2020.
The location of the satellite, as Cartesian coordinates, in metres. You must be able to handle values that fit into a signed 32-bit integer (-2,147,483,648 to 2,147,483,647). Only integer coordinates will be given. You may assume valid input (i.e. your position can be calculated)

Input can be provided from command-line arguments, standard input or equivalent, but not from a variable. The input can have any separator characters in it; please specify what your input format is.

Output

The coordinates of your receiver, to the nearest 1000 metres, using 299,792,458 m/s as the speed of light. Again, I will be lenient with the output format: any separators are acceptable.

Example

Input

1412349052664203400
[1412349052692915310,2267943, 13318342, 0]
[1412349052698278110,-3757960, 3500627, 0]
[1412349052691548521,4425976, -1533193, 3469445]
[1412349052687888295,10622179, 11246951, 84184]

Output

(6223615, 5673496, 0)

I have made a GeoGebra notebook for this example. Please excuse my extremely sloppy GeoGebra skills.

How GPS Works

Because the speed of light is finite, there will be a difference between your current time and the time the satellite sent the signal.

Use the difference to calculate the distance to the satellite, d.
You are clearly located somewhere on the surface of a sphere, centered on the satellite, with radius d.
Once you have two satellites and two spheres, you have to be located somewhere on the intersection of the two sphere surfaces, which is a circle.
Adding another satellite reduces the possible positions to just two points, where all three sphere surfaces intersect.
The fourth satellite allows you to decide on a specific one of these points. Your task is to calculate the location of this point, where all four spheres intersect. Since you assume valid input, such a point does exist.

Rules

Standard loopholes are banned.

MatLab/Octave (164)
I assumed the values to be saved in variables. As I said the posed problem seems to result in something about 200 to 300m off in the z coordinate compared to the given solution so this entry does not work within the 100m precision assuming the given test case is correct.
How it works
You can interpret your position as the intersectionpoint of four spheres, since you can calculate the distance to each sattelite by the runtime. The points [x,y,z] on a sphere with center [x,y,z] and radius r can be written as an equation (so 4 satelites = 4 equations):
(x-x0)^2 + (y-y0)^2 + (z-z0)^2 = r^2

Or when expanded / transformed:
-2*x0*x -2*y0*y -2*z0*z = r^2 - x0^2 - y0^2 - z0^2 - x^2 - y^2 - z^2

As you have 4 equations that look like that you can substract one from the other three, which eliminates the x^2+y^2+z^2 and get a system of 3 linear equations that can easily be solved for x,y,z.
But 3 intersecting spheres would result in two possible points, so a fourth is only needed for choosing the right one of those two points. But if the intersectionpoint of the first three is not exactly on the fourth sphere you cannot get an accurate answer.
Normally for gps you have the earth as fourth sphere, so three satelites could give you a line on which your current position must be (when the current exact time is unknonw). The line intersected with the earth surface results in only two possible points. So by comparing the different timestamps you could estimate on which side of the earth you are.
Code
%input
1412349052664203400

[1412349052692915310,2267943, 13318342, 0;
1412349052698278110,-3757960, 3500627, 0;
1412349052691548521,4425976, -1533193, 3469445;
1412349052687888295,10622179, 11246951, 84184]

%actual code
t=input('');d=input('');
c=299792458e-9;
p=d(:,2:4);
r=(d(:,1)-t)*c;
o=ones(3,1);
q=p(1:3,:)-o*p(4,:);
b=p(1:3,:).^2-o*p(4,:).^2;
s=r(1:3).^2-o*r(4).^2;
(-2*q)\(s-sum(b,2))

Output:
  1.0e+006 *

   6.223565252948585
   5.673559409007432
   0.000291267494418


Horizontally mirror a brainflak program Your task is to write a program or function which takes a pure brainflak program as input (assume it contains only balanced ()[]{}<>), and output a visually mirrored copy of it.

If you reversed a brainflak program as a string, say ({}()) (add one to an input), you would get ))(}{(, which is not valid.

Instead, you should mirror it, by reversing the direction of the parentheses/brackets/braces/angle-brackets, like what you would see if the program was placed in front of a mirror: ((){}).

Test cases (??? means anything is okay):

()               -> ()
({}[{}])         -> ([{}]{})
()[]             -> []()
<(){}[]>         -> <[]{}()>
([{<()[]{}<>>}]) ->([{<<>{}[]()>}])
(a)              -> ???
{>               -> ???
))(}{(           -> ???
()↵[]            -> ???

This is a code golf challenge, shortest answer per language wins.

Charcoal, 3 bytes

Ｓ‖Ｔ

Try it online! Link is to verbose version of code. Explanation: Ｓ reads the input and implicitly echos it, while ‖ is the mirroring operator, which normally just reverses the input, but the Ｔ modifies it to mirror the characters at the same time.


Build a polyglot for Hello World Produce a text file that prints "Hello World!" in as many programming languages as possible when compiled/interpreted, while also being as short as possible.

The score for your submission is calculated as C / 2 ^ ((L - 1) / 4), where "C" is the length of the text file in characters and "L" is the number of languages that the program is valid in. Lowest score wins, of course.

print("Hello World!")

Works in at least  Julia, Perl, PHP, Python2, Python3, Qbasic, R, Ruby ...


Does it Lead or Follow? In this challenge you are to write a program or function, that takes a string as input and outputs one of two possible values. We will call one of these values truthy and one falsy.  They do not need to actually be truthy or falsy.  For an answer to be valid it must meet four additional criteria

When you pass your program to itself it outputs the truthy value.
If you pass your program as input to any older answer it should output the truthy output (of the program you are passing to).
If you pass any older answer to your answer as input it should output the falsy output (of your program).
There must be an infinite number of strings that evaluate to truthy output in all answers on the challenge (including your new answer).

What this will do is it will slowly build up a chain of answers each of which can determine if other programs in the chain come before or after it.

The goal of this challenge is to build up a list of source restrictions that are applied to the successive answers making each one more challenging than the last.

Example

A chain (written in Haskell) could start:

f _ = True

Since there are no older programs, the criteria do not apply to this answer it need only output one of two possible values, in this case it always outputs True.

Following this could be the answer:

f x=or$zipWith(==)x$tail x

Try it online!

Which asserts that there is a character twice in a row somewhere in the string.  The first answer doesn't have this property while the second does (==). Thus this is a valid next answer.

Special rules

You may use any language you wish (that has a freely available implementation) as many times as you wish.
If you were the last person to answer you must wait at least 7 days before posting a new answer.
Your program may not read its own source.
Since the 4th rule is exceedingly difficult to verify if cryptographic functions are involved, such functions are disallowed.

Scoring criterion

Each time you add an answer you will get as many points as its place in the chain.  For example the 5th answer would gain it's writer 5 points.  The goal is to get as many points as you can.  The last answer will score its answerer -∞ points.  This will probably be more fun if you try to maximize your own score rather than "win" the challenge.  I will not be accepting an answer.

  Since this is answer-chaining you may want to sort by oldest

14. X86 Assembly (gcc 6.3), 324 bytes

.TITLE "a"#"a" ELTIT.
.data
i:.fill 25,1,0
s:.string "%25[^\n]"
t:.string "->Hi, Retina!"
f:.string "Bye Retina!"
.global main
main:
pushl $i
pushl $s
call scanf
addl $8, %esp
pushl $i
call strlen
addl $4, %esp
sub $21, %eax
jz y
pushl $f
call printf
addl $4, %esp
jmp en
y:
pushl $t
call printf
addl $4, %esp
en:
ret

Try it on ideone!

Note: this will return a runtime error because the exit code is not zero. Running this in the ideone editor will display all stdout output regardless of how the program concludes.

Truthy output: "->Hi, Retina!"
Falsy output: "Bye Retina!"

Satisfies:

The first character is a ..
It contains an e.
Its length is even.
Its length is a perfect square.
It contains an a.
It contains a > character.
Contains the exact string ->.
Contains the exact string Hi, Retina!.
The sum of the first two Unicode code points is a multiple of 5.
The 10-th character is a ".
The last non-empty line does not have any duplicate characters.
The first line is a palindrome of length > 5.
The first line is exactly 21 characters long (not including newline).

For future answers:

The first character is a ..
Its length is an even perfect square.
Contains the exact sequence ->.
Contains the exact string Hi, Retina!.
The second character's Unicode code point, mod 5, is 4.
The 10-th character is a ".
The last non-empty line does not have any duplicate characters.
The first line is a palindrome of length = 21


Replace all items with their counts Task:
Given an array of numbers as input (you can choose what subset, such as integers or natural numbers), replace all items with the number of times they appear within the array. As an example, [1, 2, 2, 1, 4, 8, 1] would become [3, 2, 2, 3, 1, 1, 3].
You can take input/produce output as arrays, lists, tuples, or any other reasonable representation of some numbers.
Test cases:
[1]                     [1]
[1, 2]                  [1, 1]
[1, 1]                  [2, 2]
[1, 4, 4]               [1, 2, 2]
[4, 4, 2]               [2, 2, 1]
[4, 4, 4, 4]            [4, 4, 4, 4]
[10, 20, 10, 20]        [2, 2, 2, 2]
[1, 2, 2, 4, 4, 4, 4]   [1, 2, 2, 4, 4, 4, 4]
[1, 2, 2, 1, 4, 8, 1]   [3, 2, 2, 3, 1, 1, 3]

Other:
This is code-golf, shortest answer (in bytes) per language wins!

Python 2, 23 bytes

lambda l:map(l.count,l)

Try it online!


Optimize Compiler for simple Reverse Polish Notation Programming Language Description

Imaginary programming language (IPL) uses Polish Reverse Notation. It has the following commands:

i -- input number and push it to the stack
o -- non-destructive output top of the stack (number stays on the stack)
d -- discard top of stack
integer number -- push this number to the stack
+-* -- pop two numbers from the stack, perform corresponding operation and push back the result. There is no division in IPL.

IPL works only with integers and is used for simple calculations. An IPL program is written on one line and separated by spaces.
Empty string is a valid IPL program.

IPL Program:

i i + o

Inputs two numbers, adds them together and outputs the result.

Input numbers and integers that can be pushed to stack are in range [-999, 999], however output can be any. If your language do not support big numbers it is okay though.

Input/output format

You may choose any input/output format as long as it clear to understand and read/write: string, list, tokens etc.

Task

You are given some IPL program, you need to optimize it (reduce length):

i 12 + 3 + o d 2 3 + d

After optimization will become

i 15 + o

You do not have to preserve stack state, but amount of inputs and outputs and their order should match for the original and optimized program.

So IPL program:

-40 i * 2 * o i + 3 1 + o i 2 *

After optimisation will become

i -80 * o i 4 o i

or

-80 i * o i 4 o i

(note that you have to save all inputs, even if they are irrelevant).

There should be no hardcoding for test cases, code should work on any arbitrary IPL program and produce shortest possible IPL program that meets the requirements.

Scoring

Default code-golf scoring.

UPDATE: changed scoring to pure code golf scoring, as per @Sanchises suggestion.

Test cases:

Input:

(empty string)

Possible output:

(empty string)

Input:

i 4 * 2 + 3 * 6 - o

Possible output:

i 12 * o

Input:

1 1 + o

Possible output:

2 o

Input:

i 2 + 3 + o d 2 3 + d

Possible output:

i 5 + o

Input:

-40 i * 2 * o i + 3 1 + o i 2 *

Possible output:

-80 i * o i 4 o i

Input:

i i 1 + i 1 + i 1 + i 1 + d d d d o

Possible output:

i i i i i d d d d o

Input:

i i i 0 * * * o

Possible output:

i i i 0 o

Input:

i i i 1 * * * o

Possible output:

i i i * * o

Input:

i 222 + i 222 - + o

Possible output:

i i + o

Input:

i 2 + 3 * 2 + 3 * 2 + 3 * i * d i 2 + 3 * i + d i o 2 + 2 - 0 * 1 o

Possible output:

i i i i i o 1 o

Input:

i 1 + 2 * 1 + o

Possible output:

i 2 * 3 + o

Input:

1 1 + o i 2 + 3 + o d 2 3 + d 4 i * 2 * o i + 3 1 + o i 2 * i i 1 + i 1 + i 1 + i 1 + d d d d o i i i 0 * * * o i i i 1 * * * o i 2 + i 2 - + o i 2 + 3 * 2 + 3 * 2 + 3 * i * d i 2 + 3 * i + d i o 2 + 2 - 0 * 1 o

Possible output:

2 o i 5 + o 8 i * o i 4 o i i i i i i d d d d o i i i 0 o i i i * * * o i i + o i i i i i o 1 o

Wolfram Language (Mathematica), 733 728 690 564 516 506 513 548 bytes

j=Integer;f=Flatten;s=SequenceReplace;A=FixedPoint[f@s[#,{{x_j,p,y_j,t}->{y,t,x*y,p},{x_j,y_j,p}->x+y,{x_j,y_j,t}->x*y,{x_j,p,y_j,p}->{x+y,p},{x_j,t,y_j,t}->{x*y,t},{0,p}|{1,t}->{},{0,t}->{d,0}}]//.{a___,Except[i|o]}->{a}&,#]&;B=Expand@Check[f@FoldPairList[f/@Switch[#2,i,{{i},{#,i@c++}},o,{{Last@#},#},d,{{},Most@#},p,{{},{#[[;;-3]],Tr@#[[-2;;]]}},t,{{},{#[[;;-3]],#[[-2]]*Last@#}},_,{{},{##}}]&,c=0;{},#],x]&;F=MinimalBy[w=A@f[#/.m->{-1,t,p}];z=B@w;s[#,{-1,t,p}->m]&/@A/@Select[Permutations@Join[w,Cases[z /.i@_->i,_j,∞]],B@#==z&],Length][[1]]&

Try it online!

This is a four-step tour-de-force that (1) replaces "-" with "-1 * +" so that we don't have to deal with subtractions, (2) simplifies the list of commands a bit, (3) makes a list of all permutations of this list of commands and picks out those that give the same result when parsed (executed), and (4) simplifies these lists of commands a bit and picks the shortest, after converting certain operations back to subtractions.

This code is terribly inefficient because it goes through the list of all permutations of the input code. For long input codes I don't recommend running this code; but as I read it there are no runtime or memory restrictions in this challenge.

This code does the optimization step after converting all "-" operations to "+" operations with signs flipped, and only at the end re-introduces the "-" operator when converting code back to strings. This implies for example that "i -1 i * + o" is correctly optimized to "i i - o".

As the i/o format requirement is quite loose, this code takes and returns code as lists, where the symbols "+", "-", "*" are represented by p, m, t, tokens respectively. The conversion from and to strings is done in the wrapper function given on TIO:

G[S_] := StringReplace[{"p" -> "+", "m" -> "-", "t" -> "*"}]@StringRiffle@
         Quiet@F@
         ToExpression[StringSplit[S] /. {"+" -> p, "-" -> m, "*" -> t}]

Un-golfed version, including the string-format wrapper and minimizing the final code string length instead of the number of tokens, and including a few more transformation niceties:

(* convert code string to list of operators *)
inputfilter[s_] := ToExpression[Flatten[StringSplit[s] /.
  {"i" -> i, "o" -> o, "d" -> d, "+" -> p, "-" -> {-1, t, p}, "*" -> t}]]

(* convert list of operators to code string *)
outputfilter[s_] := StringReplace[StringRiffle@Flatten@SequenceReplace[s,
  {{-1, t, p} -> m,                         (* convert "-1 t p" back to "-"             *)
   {x_ /; x < 0, p} -> {-x, m},             (* convert "y x +" to "y -x -" when x<0     *)
   {x_ /; x < 0, t, p} -> {-x, t, m}}],     (* convert "y x * +" to "y -x * -" when x<0 *)
  {"m" -> "-", "p" -> "+", "t" -> "*"}]     (* backsubstitution of symbols              *)

(* simplify a list of operators somewhat *)
simplifier[s_] := FixedPoint[Flatten@SequenceReplace[#,
  {{x_Integer, p, y_Integer, t} -> {y, t, x*y, p},  (*  "x + y *" -> "y * (xy) +"       *)
   {x_Integer, y_Integer, p} -> x + y,              (*  "x y +" -> "(x+y)"              *)
   {x_Integer, y_Integer, t} -> x*y,                (*  "x y *" -> "(xy)"               *)
   {x_Integer, p, y_Integer, p} -> {x + y, p},      (*  "x + y +" -> "(x+y) +"          *)
   {x_Integer, t, y_Integer, t} -> {x*y, t},        (*  "x * y *" -> "(xy) *            *)
   {0, p} | {1, t} -> {},                           (*  "0 +" and "1 *" are deleted     *)
   {x_Integer, i, p} -> {i, x, p},                  (*  "x i +" -> "i x +"              *)
   {x_Integer, i, t} -> {i, x, t},                  (*  "x i *" -> "i x *"              *)
   {0, t} -> {d, 0}}] //.                           (*  "0 *" -> "d 0"                  *)
  {a___, Except[i | o]} -> {a} &, s]                (* delete trailing useless code     *)

(* execute a list of operators and return the list of generated outputs *)
parse[s_] := Expand@Quiet@Check[Flatten@FoldPairList[  (* stack faults are caught here     *)
  Function[{stack, command},                        (* function called for every command*)
    Flatten /@ Switch[command,                      (* code interpretation:             *)
    i, {{i}, {stack, i[inputcounter++]}},           (* output "i" and add input to stack*)
    o, {{stack[[-1]]}, stack},                      (* output top of stack              *)
    d, {{}, Most[stack]},                           (* delete top of stack              *)
    p, {{}, {stack[[;; -3]], stack[[-2]] + stack[[-1]]}},  (* add two stack elements    *)
    t, {{}, {stack[[;; -3]], stack[[-2]]*stack[[-1]]}},    (* multiply two stack elements*)
    _, {{}, {stack, command}}]],                    (* put number onto stack            *)
    inputcounter = 0; {},                           (* start with zero input counter and empty stack*)
    s],                                             (* loop over code list              *)
  x]                                                (* return "x" if an error occurred  *)

(* the main function that takes a code string and returns an optimized code string *)
F[s_] := Module[{w, q},
  w = simplifier@inputfilter@s;      (* convert input to useful form *)
  q = parse[w];                      (* execute input code *)
  MinimalBy[
    outputfilter@*simplifier /@      (* simplify and stringify selected codes          *)
      Select[Permutations[w],        (* all permutations of code list                  *)
             parse[#] == q &],       (* select only those that give the correct output *)
    StringLength] // Union]          (* pick shortest solution by length               *)

Thanks to @redundancy for catching a bug: The parser needs a Expand applied to the output in order to handle distributive equivalence. 506→513

update

Now also optimizes 1 o 1 + o to 1 o 2 o. This was a surprisingly difficult case and made the code much slower. 513→548


Format a Drop Capital Introduction
Write a program or function that adds a drop capital to a paragraph. The program will input the text to format, the column width, and the number of lines to drop the capital. The drop capitals look like this:
Lines:        2     3      4
Drop capital: A|    A.|    A..|
              ~'    ..|    ...|    etc.
                    ~~'    ...|
                           ~~~'

This is a typography related challenge.
Input

Input a string of printable ASCII characters (no tabs or newlines) and 2 integers greater than one.
One integer is the number of columns that the output should have.
The other is the number of lines spanned by the drop capital.
The text string contains words separated by single spaces.
Assume none of the words will be longer than the column width.
That is, column width > longest word + drop capital height
All lines will have at least one word.
For this challenge, a word consists of any character other than a space.
Input may be in any convenient format following the rules above.

Output

A left-justified block of text containing a drop capital with the specified number of lines.
A line should contain as many words as possible without being longer than the column width.
There is a space between the drop capital and the rest of each line.
One trailing space or newline is allowed.

Examples
Lines: 2 Columns: 10 Text: The quick brown fox jumped over the lazy dog.

T| he
~' quick
brown fox
jumped
over the
lazy dog.

Lines: 3 Columns: 10 Text: (Same as above)

T.| he
..| quick
~~' brown
fox jumped
over the
lazy dog.

Lines: 4 Columns: 10 Text: (Same as above)

T..| he
...| quick
...| brown
~~~' fox
jumped
over the
lazy dog.

Lines: 2 Columns: 80 Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.

L| orem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.
~' Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec
consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero
egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem
lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.

Lines: 3 Columns: 80 Text: (Same as above)

L.| orem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.
..| Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec
~~' consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget
libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta
lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non
tortor.

Lines: 4 Columns: 80 Text: (Same as above)

L..| orem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
...| lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra
...| nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam
~~~' eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim,
ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies
a non tortor.

This is code-golf and standard loopholes apply.

C#, 244 bytes

string F(int d,int c,string t){var w=t.Substring(1).Split(' ');t=""+t[0];for(int i=0,x=c,y=0;i<w.Length;x+=w[i++].Length+1)t+=(1>(x=x+w[i].Length>c?0:x)?"\n"+(y++<d?(y<d?"| ":"' ").PadLeft(x=d+1,y<d?'.':'~'):""):" ")+w[i];return t.Remove(1,2);}

Indentation, new lines and comments for clarity:

string F(int d,int c,string t){
    var w=t.Substring(1).Split(' ');
    t=""+t[0];
    for(int i=0,x=c,y=0;i<w.Length;x+=w[i++].Length+1)
        t+=(1>(x=x+w[i].Length>c?0:x)?"\n"+(y++<d?(y<d?"| ":"' ").PadLeft(x=d+1,y<d?'.':'~'):""):" ")+w[i];
    return t.Remove(1,2);
}


A list of number modulus their indices in the list A simple one:
Take a list of positive integers as input and output the numbers modulus their 1-based index in the list.

If the input integers are {a, b, c, d, e, f, g} then the output should be {a%1, b%2, c%3, d%4, e%5, f%6, g%7} where % is the modulus operator.

Test cases:

10  9  8  7  6  5  4  3  2  1
 0  1  2  3  1  5  4  3  2  1

8 18  6 11 14  3 15 10  6 19 12  3  7  5  5 19 12 12 14  5
0  0  0  3  4  3  1  2  6  9  1  3  7  5  5  3 12 12 14  5

1
0

1  1
0  1

Haskell, 20 bytes

($[1..]).zipWith mod

Try it online!

A trick to flip I learned from a golf of Anders Kaseorg.


EBCDIC code golf (Happy birthday, System/360!) Pretty soon it's going to be 50 years since IBM unveiled its System/360 family of computers. These were the first to use the EBCDIC character set.

To mark the occasion, let's see who can write the shortest program capable of converting "ordinary" text to and from EBCDIC code page 037. We'll be using a translation table from Wikipedia that maps CP037 to a superset of ISO-8859-1:

EBCDIC037_to_Latin1 = [
    0x00,0x01,0x02,0x03,0x9c,0x09,0x86,0x7f,0x97,0x8d,0x8e,0x0b,0x0c,0x0d,0x0e,0x0f,
    0x10,0x11,0x12,0x13,0x9d,0x85,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f,
    0x80,0x81,0x82,0x83,0x84,0x0a,0x17,0x1b,0x88,0x89,0x8a,0x8b,0x8c,0x05,0x06,0x07,
    0x90,0x91,0x16,0x93,0x94,0x95,0x96,0x04,0x98,0x99,0x9a,0x9b,0x14,0x15,0x9e,0x1a,
    0x20,0xa0,0xe2,0xe4,0xe0,0xe1,0xe3,0xe5,0xe7,0xf1,0xa2,0x2e,0x3c,0x28,0x2b,0x7c,
    0x26,0xe9,0xea,0xeb,0xe8,0xed,0xee,0xef,0xec,0xdf,0x21,0x24,0x2a,0x29,0x3b,0xac,
    0x2d,0x2f,0xc2,0xc4,0xc0,0xc1,0xc3,0xc5,0xc7,0xd1,0xa6,0x2c,0x25,0x5f,0x3e,0x3f,
    0xf8,0xc9,0xca,0xcb,0xc8,0xcd,0xce,0xcf,0xcc,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22,
    0xd8,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0xab,0xbb,0xf0,0xfd,0xfe,0xb1,
    0xb0,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0xaa,0xba,0xe6,0xb8,0xc6,0xa4,
    0xb5,0x7e,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0xa1,0xbf,0xd0,0xdd,0xde,0xae,
    0x5e,0xa3,0xa5,0xb7,0xa9,0xa7,0xb6,0xbc,0xbd,0xbe,0x5b,0x5d,0xaf,0xa8,0xb4,0xd7,
    0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0xad,0xf4,0xf6,0xf2,0xf3,0xf5,
    0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xb9,0xfb,0xfc,0xf9,0xfa,0xff,
    0x5c,0xf7,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0xb2,0xd4,0xd6,0xd2,0xd3,0xd5,
    0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xb3,0xdb,0xdc,0xd9,0xda,0x9f];

Rules:

Your program should take two inputs: (a) a text string, and (b) a flag indicating the operation to be performed.
Based on this flag, your program should either convert each byte of text into the corresponding EBCDIC character, or vice versa.
Input can be obtained from any sensible sources (e.g., command line arguments, stdin, keyboard input), but must not be hard-coded into your program.
Output should be displayed on the screen (e.g., stdout, document.write) or written to a file/pipeline.
Don't use any built-in or external encoding conversion functions (iconv, etc.).
This is a code-golf challenge, so the shortest answer (fewest bytes) will win.

Examples:

(Note: These examples were produced in a terminal configured to use UTF-8 encoding. You may see different results depending on how your system is configured. Hex equivalents are shown for reference only, and don't have to be generated by your code.)

Input: "HELLO WORLD", convert to EBCDIC
Output: "ÈÅÓÓÖ@æÖÙÓÄ" (0xc8c5d3d3d640e6d6d9d3c4)

Input: "ÈÅÓÓÖ@æÖÙÓÄ", convert from EBCDIC
Output: "HELLO WORLD"

Input: "lower case mostly ends up as gremlins", convert to EBCDIC
Output "" <-- unprintable in utf-8
(0x9396a68599408381a285409496a2a393a840859584a240a4974081a24087998594938995a2)

Bash + tr, 240 bytes

Hexdump

00000000  58 3d 27 9c 09 86 7f 97  8d 8e 0b 2d 13 9d 85 08  |X='........-....|
00000010  87 18 19 92 8f 1c 2d 1f  80 2d 84 0a 17 1b 88 2d  |......-..-.....-|
00000020  8c 05 06 07 90 91 16 93  2d 96 04 98 2d 9b 14 15  |........-...-...|
00000030  9e 1a 20 a0 e2 e4 e0 e1  e3 e5 e7 f1 a2 2e 3c 28  |.. ...........<(|
00000040  2b 7c 26 e9 ea eb e8 ed  ee ef ec df 21 24 2a 29  |+|&.........!$*)|
00000050  3b ac 5c 2d 2f c2 c4 c0  c1 c3 c5 c7 d1 a6 2c 25  |;.\-/.........,%|
00000060  5f 3e 3f f8 c9 ca cb c8  cd ce cf cc 60 3a 23 40  |_>?.........`:#@|
00000070  27 5c 27 27 3d 22 d8 61  2d 69 ab bb f0 fd fe b1  |'\''=".a-i......|
00000080  b0 6a 2d 72 aa ba e6 b8  c6 a4 b5 7e 73 2d 7a a1  |.j-r.......~s-z.|
00000090  bf d0 dd de ae 5e a3 a5  b7 a9 a7 b6 bc bd be 5b  |.....^.........[|
000000a0  5d af a8 b4 d7 7b 41 2d  49 ad f4 f6 f2 f3 f5 7d  |]....{A-I......}|
000000b0  4a 2d 52 b9 fb fc f9 fa  ff 5c 5c f7 53 2d 5a b2  |J-R......\\.S-Z.|
000000c0  d4 d6 d2 d3 d5 30 2d 39  b3 db dc d9 da 9f 27 3b  |.....0-9......';|
000000d0  5b 20 24 31 20 5d 26 26  74 72 20 04 2d ff 20 22  |[ $1 ]&&tr .-. "|
000000e0  24 58 22 7c 7c 74 72 20  22 24 58 22 20 04 2d ff  |$X"||tr "$X" .-.|

Rather trivial solution. Reads from STDIN, prints to STDOUT.

How to use

To save the script and make it executable, run these commands:

base64 -d <<< WD0nnAmGf5eNjgstE52FCIcYGZKPHC0fgC2EChcbiC2MBQYHkJEWky2WBJgtmxQVnhogoOLk4OHj5efxoi48KCt8Junq6+jt7u/s3yEkKik7rFwtL8LEwMHDxcfRpiwlXz4/+MnKy8jNzs/MYDojQCdcJyc9IthhLWmru/D9/rGwai1yqrrmuMaktX5zLXqhv9Dd3q5eo6W3qae2vL2+W12vqLTXe0EtSa309vLz9X1KLVK5+/z5+v9cXPdTLVqy1NbS09UwLTmz29zZ2p8nO1sgJDEgXSYmdHIgBC3/ICIkWCJ8fHRyICIkWCIgBC3/ > ebcdic.sh
chmod +x ebcdic.sh

To convert to EBCDIC (encode), execute the plain command:

./ebcdic.sh

To convert from EBCDIC (decode), specify any first argument:

./ebcdic.sh -d


V, 189, 179, 175, 164, 161, 157, 155, 149, 145, 141, 135 bytes

¬19É`A0-=BS´
TAB³ qwertyuiop[]\
CAPS³ asdfghjkl;'ENTER
SHIFT´ ÄJizxcvbnm,./Í„A-Z ]/Õ&
ÍÓ«ü$/|||&
òÙÓ„|]/_
ÙÓ×«/Ü|¯
kkPÓ/_ _
kòÎx$x

Try it online!

This answer is now tweetable!

Watch it run! This is a slightly modified version that updates as it runs so you can sorta see how it works. This is an outdated version since I haven't gotten around to re-recording it yet, but the general approach is identical.

This is probably the longest V answer ever written. It certainly didn't help that V's interpreter is extremely slow. It took me around an hour to write the first revision, but I've been repeatedly coming back to it to shave a couple bytes off each time. Since the full keyboard is 1215 bytes, currently this answer is 91% shorter than the output, so I'm pretty happy with the results.

Since this contains some unprintable characters, and a lot of gross non-ASCII, here's a hexdump:

00000000: ac31 39c9 6041 302d 3d42 53b4 200a 5441  .19.`A0-=BS. .TA
00000010: 42b3 2071 7765 7274 7975 696f 705b 5d5c  B. qwertyuiop[]\
00000020: 0a43 4150 53b3 2061 7364 6667 686a 6b6c  .CAPS. asdfghjkl
00000030: 3b27 454e 5445 5220 0a53 4849 4654 b420  ;'ENTER .SHIFT.
00000040: 1bc4 4a69 7a78 6376 626e 6d2c 2e2f 1bcd  ..Jizxcvbnm,./..
00000050: 8441 2d5a 205d 2fd5 2620 0acd d3ab fc24  .A-Z ]/.& .....$
00000060: 2f7c 7c7c 260a f2d9 d384 7c5d 2f5f 0ad9  /|||&.....|]/_..
00000070: d3d7 ab2f dc7c af0a 6b6b 50d3 2f5f 205f  .../.|..kkP./_ _
00000080: 0a6b f2ce 7824 78                        .k..x$x

How the heck does it work?

Alright, this explanation is gonna be a doozy. You ready? First off, we need enter the letters so we can build up the keys around them. This is

¬19É`A0-=BS´
TAB³ qwertyuiop[]\
CAPS³ asdfghjkl;'ENTER
SHIFT´ <esc>ÄJizxcvbnm,./<esc>

Which inserts:

`1234567890-=BS
TAB   qwertyuiop[]\
CAPS   asdfghjkl;'ENTER
SHIFT    zxcvbnm,./SHIFT

It enters it pretty straightforward, but there are a few tricks that we use to save characters. For example, ¬19 enters "123456789", ³ enters three spaces, and we duplicate the shift so that we don't need to enter it multiple times.

Note how the letters are lowercase here. This is so that we can easily distinguish between the uppercase keys like "ENTER" and the single letters. Writing them this way makes it easier to tell which characters to put a bar before, and only adds one byte to convert them to lowercase later. So we do a substitute command to convert these to uppercase, and add one space after each of them:

Í               " Globally replace
 [^A-Z ]        " Anything but a uppercase alphabet character or a space
        /       " with
         Õ&     " The matched pattern made uppercase, followed by a space

Now, we take each key sequence (any run of non-whitespace), and put three bars before and after them:

Í           " Globally replace
 Ó«         "   Any number of non-space characters
   ü        "   or
    $       "   an end of line
     /      " with
      |||   "    Three bars
         &  "    And the matched pattern

At this point, the buffer looks like this:

|||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    |||
|||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ |||
|||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER |||
|||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    |||

Having three bars on the first and last columns is actually very convenient and ends up saving many bytes in the long run.

And here is where we run one giant loop. This will convert something like this:

|||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    |||

into something like this:

 ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________
||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

Everything between two instances of ò will run until an error happens, which will happen when we try to go up into a line that does exist yet. Since we just ran a globally substitute command, our cursor is on the last line, and we'll transform these working our way up.

ò         " Recursively:
 Ù        "   Duplicate this line
  Ó       "   Substitute all on this line:
   [^|]   "     Anything but a bar
       /  "   With:
        _ "     An underscore

This is the

|||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________|||

line.

Ù         "   Duplicate this line
 Ó        "   Subsitute all on this line:
  ×«      "     A run of *non-word characters* (that is, [^0-9A-Za-z_])
    /     "   With:
     Ü|¯  "     '\|/'

This is the

\|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|/

Line.

kk        "   Move up two lines (to the original text with "SHIFT")
  P       "   Paste the last line we duplicated (the one with all the underscores)
   Ó      "   Substitute:
          "     Since we don't give any regex here, it re-uses the last one
          "     (a run of *non-word* characters)
    /     "   With:
     _ _  "     '_ _'

This is the:

_ ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ _

Line.

k         "   Move up a line (this will throw an error, breaking the loop when we're done)
 ò        " Endwhile

Now we have the full keyboard, but each line contains either an extra bar, an extra slash (forward or backward), or an extra underscore. Super easy fix

Î             " On every line:
 x            "   Delete a character
  $           "   Move to the end of the line
   x          "   and delete another character

After all that madness, the buffer is implicitly printed.


Count the number of vowels in each word of a string This is a rather easy challenge.

Challenge

Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces.

Rules

The string will not be more than 100 characters in length.
The string will only contain alphabets A-Z , a-z and can also contain spaces.
Input must be consumed from the stdin or command line arguments.
Output must be outputted in the stdout.
You can write a full program, or a function that takes input from the stdin and outputs the result.
The vowels that your program/function needs to count are aeiou and AEIOU.

Test Cases

This is the first test case     --> 1 1 1 1 1 2
one plus two equals three       --> 2 1 1 3 2
aeiou AEIOU                     --> 5 5
psst                            --> 0
the quick brown fox jumped over the lazy dog --> 1 2 1 1 2 2 1 1 1

Scoring

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

C, 113 108 103 96 bytes

Thanks @andrea-biondo for a particularly nice 5 byte saving.

main(a,v,c)char**v;{do{for(a=0;c=*v[1]++%32;2016%(c+27)||a++);printf("%d ",a);}while(v[1][-1]);}

This still feels sort of bloated so hopefully I can get it down quite some bytes later tonight.

The interesting part is perhaps that

!(124701951%((c-65&31)+33))

will be 1 if c is an (upper or lower case) ASCII vowel, and 0 for other characters a-zA-Z. The subexpression c-65&31 maps 'a' and 'A' to 0, 'b' and 'B' to 2, etc. When we add 33 the vowels correspond to the numbers 33, 37, 41, 47, 53 respectively, all of which are (conveniently) prime. In our range only such numbers will divide 124701951 = 33*37*41*47*53, ie only for vowels will the remainder of 124701951%(...) be zero.

EDIT: In this way one can consider the expression !(n%((c-65&31)+s)) where (n,s) = (124701951, 33) as determining whether the character c is a vowel. In the comments @andrea-biondo pointed out that the pair (n,s) = (2016,28) can also be used in this expression to determine vowelhood. I'll leave the current explanation in terms of primes above, but the reason this shorter pairing works is again because in the range 28--53 the only numbers with prime factors entirely in the set of prime factors of 2016 are 28, 32, 36, 42, 48, which correspond precisely to the vowels.

EDIT2: Another 5 bytes saved since (c-65&31)+28 can be shortened to c%32+27.

EDIT3: Converted to a do-while loop to finally get it below 100 bytes.

Test cases:

$ ./vowelc "This is the first test case"
1 1 1 1 1 2
$ ./vowelc "one plus two equals three"
2 1 1 3 2
$ ./vowelc "aeiou AEIOU"
5 5
$ ./vowelc "psst"
0


How would you count score in a Scrabble® game? Let's say that we are programming a game that lets you play Scrabble®.

We have a board with tiles placed on it, and empty cells are either normal or have multiplier properties (double or triple the points for a word or for a single letter).
Each tile has a value and blank tiles have no value.

Thee goal here is to write a method that, given a new_word structure, will:

verify that this word can be placed onto the grid at the specified position (the originating rack has the missing letters, it is not out of board range, blank tiles will not be adjacent on the board)
return the number of points granted to the player.
letter multipliers have priority over word multipliers
all new words on the grid are counted (both horizontal and vertical)

Below are sample structures provided as an example.

// SCRABBLE® STRUCTURES

// a single Scrabble® tile.
struct tile
{
    // blank tiles are recognized by their value of 0.
    // The value of 'letter' is a space (L' ') until they
    // are positioned on the board. From that stage the
    // value of 'letter' contains what they represent.
    wchar_t      letter;
    unsigned int points;
};

// the bag with undrawed tiles
struct tile_bag
{
    // English version: 100 at start of game
    unsigned int  remaining_tiles;
    tile         *tiles;
};

// the content of a player rack
struct player_rack
{
    unsigned int     tile_count;
    tile            *tiles;
};

// a multiplier square
struct multiplier_cell
{
    enum
    {
        letter_scope,
        word_scope,
    } multiplier_scope;

    unsigned int multiplication_factor;
};

// a cell on the Scrabble® board
struct cell
{
    enum
    {
        normal,     // empty cell with no multiplier
        multiplier, // empty special cell, see multiplier_detail
        tile,       // cell with a tile on it, see tile_detail
    } cell_type;

    union
    {
        multiplier_cell multiplier_detail;
        tile            tile_detail;
    };
};

// a scrabble board;
struct board
{
    unsigned int width;  // usually 15
    unsigned int height; // usually 15
    cell **cells;
};

// a new word, placed on the grid
struct new_word
{
    // zero-terminated string representing the actual word.
    const wchar_t *zWord;

    // the same string, but with spaces for blanks that come
    // from the rack
    const wchar_t *zWord_with_blanks;

    // the rack the word originates from
    player_rack   *original_rack;

    // the cell position where the word begins
    unsigned int   verticalStart;
    unsigned int   horizontalStart;

    // the direction
    enum { vertical, horizontal, } direction;
};

// SCRABBLE® NUMERIC CONSTANTS

// how many tiles are allowed on the rack of a single player
// this is also the number of tiles that grant a bonus when
// placed onto the board at the same time.
// usually 7
extern const int max_allowed_tiles_on_a_rack;

// how many extra points are granted when scrabbling
// usually 50
extern const int scrabble_extra_points;

// GLOBAL VARIABLES

extern board        theBoard;
extern tile_bag     theBag;
extern int          theNumberOfPlayers;
extern player_rack *theRacks;

Haskell:

pointsFromWord :: [[Tile]] -> [Char] -> Word -> Maybe Int
pointsFromWord board rack (word, (x, y), Vertical) =
  pointsFromWord (transpose board) rack (Word word (y,x) Horizontal)
pointsFromWord board rack w@(word, (x, y), Horizontal) =
  if (validWord board w)
    then Just (wordScore board w)
    else Nothing

validWord :: [[Tile]] -> [Char] -> Word -> Bool
validWord board rack w@(word, (x, y), _) = x >= 0 && y >= 0 &&
  y < length board && (a + length word) < length (board!!y) &&
  foldl (\acc (c,t)->acc && characterFits t c) True (zip word wordLocation)
    where wordLocation = take (length word) (drop x (board!!y))
          characterFits (PlacedTile letter) c = letter == c
          characterFits _ c = contains rack c

wordScore :: [[Tile]] -> Word -> Int
wordScore board (word, (x, y), _) = (letterScore * multiplier) + scrabbleBonus
  where
    letterScore = foldl (\acc (c,t)->acc + value t c) 0 (zip word wordLocation)
    wordLocation = take (length word) (drop x (board!!y))
    value (LetterMultiplier mult) c = tileValue c * mult
    value (PlacedTile letter value) c = value
    value _ c = tileValue c

    multiplier = foldl (\acc t->acc * wordMultValue t) 1 wordLocation
    wordMultValue (WordMultiplier mult) = mult
    wordMultValue _ = 1

    scrabbleBonus = if length (filter fromRack wordLocation) == 7
                      then 50
                      else 0
    fromRack PlacedTile = False
    fromRack _ = True

A little longer than I'd like (especially the ton of where clauses on wordScore), but seems readable enough (at least to me).
I took a few liberties with the data structures themselves - transliterating the C structures into Haskell doesn't really work.
The board structure is a list of lists of tiles - a list of tiles forms a row, and a list of rows form a board.
Words contain, in order:

A [Char] containing the exact tiles used (including blanks where a blank will be used instead of a letter). I assume this is prescreened for the no-two-blanks-next-to-each-other condition, though I suppose I could validate that as well.
An (Int, Int) tuple specifying the location of the word
An Orientation type constructed with either Vertical or Horizontal, specifying the orientation of the word.

Additionally, the player's current rack of tiles is passed separately from the word being tested, because that makes more sense.
I also assume a tileValue function which takes a character (including space) and returns the standard value of a tile depicting that character.