text:
Divide and stay Happy. Who cares about the Conquer part?
Well, when I buy gifts for my two wives, I want them to feel equally important to me, but it's hard to go shopping with fixed budgets. Instead, I buy a bunch of stuff and divide them into two groups with as equal value as possible. Then I buy a bunch of chocolates to fix the rest.
But I don't want do all the hard lifting when my computer can do it. And you don't either. So solve this problem so that the next time you need to divide gifts among your wives, you know it would be easy.
Input
1 array of (N*2) elements where N*2 is specified in the 1st line.
The elements of the array in the following line.
Output
2 array of N elements each such that:
Difference of (Sum of elements of array 1) and (Sum of elements of array 2) is as close as possible to 0.
Example
Input
4
1 2 3 4

Output
1 4
2 3
diff=0

Disclaimer: I don't have two wives. But when I feel bad, I imagine having two wives. And suddenly, I am thankful and happy that I have only one. :D

As it stands, "2 array of N element each" forces the groups to be also equal in size. Is this intended? For example at the moment for input group 1 1 1 1 1 5 the correct answer would be 1 1 1 | 1 1 5, while 1 1 1 1 1 | 5 would make more sense.

Guess the problem also applies to twins and probably to other children-constellations, too. Christmas today is mostly a 'he got more than me'-event...

@shiona , yes, the equal size is intended.
@ TheConstructor , dividing among children is not as funny as dividing among two wives. :D

The tag [tag:code-challenge] requires an objective winning criterion. Also it is closely related to the subset sum problem which was asked here before.

@Howard there are important differences to subset sum: you need to build two equally size lists (not just equally valued), you need to use all elements, ...

@Howard I've removed the code-challenge tag

Hmm, I did this a couple weeks ago on SO.

Java
Trying to solve this problem in two phases:

Build two equally sized lists by adding the remaining biggest to the currently smaller list and the next to the other. Repeat.
Identify items from both lists that can be switched to reduce the difference in value

Input like

8
1 2 3 4 5 6 7 8

is already solved after phase 1 as e.g.

2 3 5 8
1 4 6 7
diff=0

and input like

6
1 4 5 6 7 8

will need both phases so that

1 5 8
4 6 7
diff=3

(after phase one) becomes the result of

1 6 8
4 5 7
diff=1

While I can guarantee this attempt will always provide a solution, I can not prove that a optimal solution is found in all cases. With the restriction of equally sized lists it however feels quite realistic that there are no corner cases left behind. Prove me wrong ;-)
Program on ideone.com
import java.util.*;

/**
 * Created to solve http://codegolf.stackexchange.com/q/23461/16293 .
 */
public class EqualSums {

    public static void main(String[] args) {
        final Scanner s = new Scanner(System.in);
        // Read number of elements to divide
        final int count = s.nextInt();
        if (count % 2 == 1) {
            throw new IllegalStateException(count + " can not be divided by 2. Consider adding a 0 value.");
        }
        // Read the elements to divide
        final SortedList valueStack = new SortedList(count);
        for (int i = 0; i < count; i++) {
            valueStack.add(s.nextLong());
        }

        final SortedList targetOne = new SortedList(count / 2);
        final SortedList targetTwo = new SortedList(count / 2);
        // Divide elements into two groups
        addInPairs(targetOne, targetTwo, valueStack);
        // Try to ensure groups have equal value
        retaliate(targetOne, targetTwo);

        // Output result
        System.out.println(targetOne);
        System.out.println(targetTwo);
        System.out.println("diff=" + Math.abs(targetOne.getSum() - targetTwo.getSum()));
    }

    private static void addInPairs(SortedList targetOne, SortedList targetTwo, SortedList valueStack) {
        SortedList smallerTarget = targetOne;
        SortedList biggerTarget = targetTwo;
        while (!valueStack.isEmpty()) {
            // Add biggest remaining value to small target
            smallerTarget.add(valueStack.removeLast());

            // Add second biggest remaining value to big target
            biggerTarget.add(valueStack.removeLast());

            // Flip targets if roles have changed
            if (smallerTarget.getSum() > biggerTarget.getSum()) {
                final SortedList temp = smallerTarget;
                smallerTarget = biggerTarget;
                biggerTarget = temp;
            }
        }

    }

    private static void retaliate(SortedList targetOne, SortedList targetTwo) {
        long difference;
        boolean changed;
        outer:
        do {
            difference = Math.abs(targetOne.getSum() - targetTwo.getSum());
            if (difference == 0) {
                return;
            }
            changed = false;
            // Try to find two values, that reduce the difference by changing them between targets
            for (Long valueOne : targetOne) {
                for (Long valueTwo : targetTwo) {
                    final Long tempOne = targetOne.getSum() + valueTwo - valueOne;
                    final Long tempTwo = targetTwo.getSum() - valueTwo + valueOne;
                    if (Math.abs(tempOne - tempTwo) < difference) {
                        targetOne.remove(valueOne);
                        targetTwo.add(valueOne);
                        targetTwo.remove(valueTwo);
                        targetOne.add(valueTwo);
                        changed = true;
                        continue outer;
                    }
                }
            }
        } while (changed);
    }

    public static class SortedList extends AbstractList<Long> {

        private final ArrayList<Long> list;
        private long sum = 0;

        public SortedList(int count) {
            list = new ArrayList<>(count);
        }

        // the next functions access list-field directly
        @Override
        public Long get(int index) {
            return list.get(index);
        }

        @Override
        public boolean add(final Long t) {
            final int i = Collections.binarySearch(list, t);
            if (i < 0) {
                // No equal element present
                list.add(-i - 1, t);
            } else {
                list.add(afterLastEqual(i, t), t);
            }
            sum += t;
            return true;
        }

        @Override
        public Long remove(int index) {
            final Long old = list.remove(index);
            sum -= old;
            return old;
        }

        @Override
        public int size() {
            return list.size();
        }

        // the next functions access list-field only through the functions above this point
        // to ensure the sum is well kept

        public long getSum() {
            return sum;
        }

        private int afterLastEqual(final int start, Object o) {
            int found = start;
            while (found < size() && o.equals(get(found))) {
                found++;
            }
            return found;
        }

        private int beforeFirstEqual(final int start, final Object o) {
            int found = start;
            while (found >= 0 && o.equals(get(found))) {
                found--;
            }
            return found;
        }

        @Override
        public int indexOf(Object o) {
            try {
                final int i = Collections.binarySearch(this, (Long) o);
                if (i >= 0) {
                    return beforeFirstEqual(i, o) + 1;
                }
            } catch (ClassCastException e) {
                // Object was not instance of Long
            }
            return -1;
        }

        @Override
        public int lastIndexOf(Object o) {
            try {
                final int i = Collections.binarySearch(this, (Long) o);
                if (i >= 0) {
                    return afterLastEqual(i, o) - 1;
                }
            } catch (ClassCastException e) {
                // Object was not instance of Long
            }
            return -1;
        }

        @Override
        public boolean remove(Object o) {
            if (o == null) {
                return false;
            }
            final int i = indexOf(o);
            if (i >= 0) {
                remove(i);
                return true;
            }
            return false;
        }

        public Long removeLast() {
            return remove(size() - 1);
        }

        public Long removeFirst() {
            return remove(0);
        }

        @Override
        public String toString() {
            Iterator<Long> it = iterator();
            if (!it.hasNext()) {
                return "";
            }

            StringBuilder sb = new StringBuilder();
            for (; ; ) {
                Long e = it.next();
                sb.append(e);
                if (!it.hasNext()) {
                    return sb.toString();
                }
                sb.append(' ');
            }
        }
    }
}

Brachylog 2
pᶠḍᵐ{+ᵐo-}ᵒh

Try it online!
This is a popularity contest, but that doesn't necessarily mean that golfing languages are a bad fit. (Really, I should have answered in Jelly because Jelly answers tend to get a disproportionate number of upvotes for some reason regardless of who submits them or how golfed they are, but Brachylog is more readable.)
We start off by taking the list of all permutations of the input (pᶠ), and splitting each (ᵐ) into two equal pieces (ḍ; we could give it a subscript if you had more than two wives for some reason). Then we order the split permutations ({…}ᵒ) by taking the sum (+) of each (ᵐ) half, taking the absolute difference (i.e. o-, "ordered difference"), and using those differences to define the sort order. The best result is the first one, so we take the head of the list with h to get the result.

Mathematica
Input forms
The input string is to be taken through STDIN.  assets refers to the amounts to be distributed among the wives (or twins).  length is the number of assets.
assets=ToExpression[Rest[s=StringSplit[input]]]
length=ToExpression[First[s]]

For the present purposes we will assume that the assets consist of the integers from 1 through 20.
assets=Range[20];
length=Length[Range[20]]

Processing
(* find all possible distributions to one wife; the other presumably gets the remaining assets *)
r=Subsets[assets,{length/2}];

(*order them according to the difference with respect to the total of half of the assets.
Remove the first set of assets.  One wife will get these.*)
s=SortBy[r/.{{a__Integer}:> {{a},Abs[Tr[Range[20]/2]-Tr[{a}]]}},Last][[1]];

(*The other wife's assets will be the complement.  The difference is carried over from the sorting routine. *)
Grid[{{Grid[{s[[1]],Complement[assets,s[[1]]]}]},{"difference = "<>ToString[s[[2]]]}}]

Is the distribution unfair? So, choose another.
@The Constructor notes that wife 2 may contest the fact that wife 1 got all the best assets.
So the following produces all of the "fair" (difference = lowest difference) shares for wife 1; wife 2 gets the remaining assets; the zero refers to the difference in assets for the wives.  There are 5448 ways to distribute assets weighted 1 through 20. Only a few lines are displayed.
The format is
s=SortBy[r/.{{a__Integer}:> {{a},Abs[Tr[Range[20]/2]-Tr[{a}]]}},Last];
z=Cases[s,{_List,x_}/;x==s[[1,2]]];
Short[z,10]
Length[z]

{{{1,2,3,4,5,16,17,18,19,20},0},{{1,2,3,4,6,15,17,18,19,20},0},{{1,2,3,4,7,14,17,18,19,20},0},{{1,2,3,4,7,15,16,18,19,20},0},{{1,2,3,4,8,13,17,18,19,20},0},{{1,2,3,4,8,14,16,18,19,20},0},{{1,2,3,4,8,15,16,17,19,20},0},{{1,2,3,4,9,12,17,18,19,20},0},{{1,2,3,4,9,13,16,18,19,20},0},{{1,2,3,4,9,14,15,18,19,20},0},{{1,2,3,4,9,14,16,17,19,20},0},{{1,2,3,4,9,15,16,17,18,20},0},{{1,2,3,4,10,11,17,18,19,20},0},{{1,2,3,4,10,12,16,18,19,20},0},
  <<5420>>,
  {{5,6,7,8,9,11,13,14,15,17},0},{{5,6,7,8,9,12,13,14,15,16},0},{{5,6,7,8,10,11,12,13,14,19},0},{{5,6,7,8,10,11,12,13,15,18},0},{{5,6,7,8,10,11,12,13,16,17},0},{{5,6,7,8,10,11,12,14,15,17},0},{{5,6,7,8,10,11,13,14,15,16},0},{{5,6,7,9,10,11,12,13,14,18},0},{{5,6,7,9,10,11,12,13,15,17},0},{{5,6,7,9,10,11,12,14,15,16},0},{{5,6,8,9,10,11,12,13,14,17},0},{{5,6,8,9,10,11,12,13,15,16},0},{{5,7,8,9,10,11,12,13,14,16},0},{{6,7,8,9,10,11,12,13,14,15},0}}
5448

The prior submission can be found among the edits. It is far more inefficient, relying as it does on Permutations.

Mathematica seems beautiful for such a task. One last thing is that real wives probably would argue as the 5 most valuable items are all on one stack. (Yeah granted, with 1 to 20 there is no solution without room for arguments)

@Actually, there are quite a few ways to distribute the assets. I listed some of the ways in an addendum.  Note: Only one wife's assets are listed; the other gets the complement.

That's one of the reasons I choose to build my inital stacks as I do: so normally the two most valuable things are not on the same stack. Your initial solution proves that there are 10 pairs of numbers with a sum of 21; you implicitly choose consecutive pairs.

Yes, I appreciate the logic of your approach.

J
There's a cheat sheet of all the J primitives at this link, in case you want to follow along at home. Remember: J is generally read from right to left, so that 3*2+1 is 7, not 9. Every verb (J for function) is either monadic, so in front like f y, or dyadic, so in between like x f y.
N =: (". 1!:1 ] 1) % 2          NB. number of items per wife
S =: ". 1!:1 ] 1                NB. list of items to distribute

bins =: #: i. 2 ^ 2*N           NB. all binary strings of length 2n
even =: bins #~ N = +/"1 bins   NB. select those with row-sum 1

NB. all distributions of equal numbers of items to each wife
NB. resultant shape: a list of 2xN matrices
NB. this /. adverb is where all the magic happens, see below
dist =: even ]/."1 S

diff =: | -/"1 +/"1 dist        NB. difference in wives' values
idx  =: (i. <./) diff           NB. index of the lowest difference

1!:2&2 idx { dist               NB. print the winning distribution of items
1!:2&2 'diff=', idx { diff      NB. and the difference of that distribution

Notes and explanations:

u/ means "fold u over", so perform the binary operation over each element in the list. So for example: +/ means Fold Plus, or Sum; <. is Lesser Of, so <./ means Fold Lesser Of, or Minimum.
u"1 means "perform u on 1-dimensional cells", i.e. over every row. Normally the verbs in J are either atomic, or apply to the whole argument. This applies to both arguments if the verb is used dyadically (with two arguments). Consider the following:
   i. 2 3        NB. just a 2x3 matrix of numbers
0 1 2
3 4 5
   +/   i. 2 3   NB. Sum the items
3 5 7
   +/"1 i. 2 3   NB. Sum the items of each row
3 12

#: is a verb that expands a number into its binary representation. When you use it on a list with more than one element, it will also align all the numbers properly, so that #:i.2^n will get you every binary string of length n.
/., when used dyadically, is called Key. It uses the elements of the list on the left side as keys, and those on the right side as values. It groups together each set of values that share a key, and then performs some operation on them.
In the case of ]/., the operation is just the identity verb, so nothing altogether special is happening there, but the fact that /. will partition up the list for us is the important bit. This is why we create the binary lists: so that for each list ("1), we can divvy up the gifts for the wives in all possible ways.
1!:1]1 and 1!:2&2 are the read-in and write-out operations, respectively. The 1!:n part is the verb and the other number is the file handle. 1 is console in, 2 is console out, and 3 4 5 are stdin, stdout, and stderr. We also use ". when reading so that we convert the input strings to numbers.

+1 for submitting an answer in J and AT LEAST TRYING to make it understandable.

MATLAB
Here is my solution:
%input array
presents=zeros(2,8);
presents(1,1)=8; %number of presents
presents(2,:)=[1 2 7 4 5 3 2 8]; %list of presents

%calculate the cumulative sum of all permutations
%its all about the gift values
how_many=presents(1,1);
options=perms(presents(2,:);
subtotals=cumsum(options,2);

%find the first index where the difference between the two parts is minimal
%makes both wives happy!!
[~, double_happiness] = min(abs(sum(presents(2,:))/2-subtotals(:,how_many/2)));

%create the present lists for Jennifer and Kate :)
for_jennifer=options(double_happiness,1:how_many/2)
for_kate=options(double_happiness,how_many/2+1:end)

For example the present list in my source code results in:
for_jennifer =

     8     2     5     1

for_kate =

     4     7     2     3

which is both 16.
If I golf my code, which is less fun I get a very unoptimised 132 chars. Beat that ;)
function f(p);o=perms(p(:,2));s=cumsum(o,2);[~,d]=min(abs(sum(p(:,2))/2-s(:,p(1,1)/2)));a={o(d,1:p(1,1)/2);o(d,p(1,1)/2+1:end)};a{:}

The input array must be square.

No, not square? But now I see the number of items should be in the first row. I'll change it.

Clojure
(defn divide [n]
 (loop [lv [] rv [] d (reverse (sort n))]
  (if (empty? d)
   [lv rv]
   (if (> (reduce + lv) (reduce + rv))
     (if (>= (count lv ) (count rv))
       (recur lv (conj rv (first d)) (into [] (rest d)))
       (recur (conj lv (last d)) rv (pop d)))
     (if (<= (count lv ) (count rv))
       (recur (conj lv (first d)) rv (into [] (rest d)) )
       (recur lv (conj rv (last d)) (pop d)))))))

 (defn display [[f s]]
   (println f)
   (println s)
   (println (str "Diff " (- (reduce + f) (reduce + s)))))

Test
 (->>
 [5 1 89 36 2 -4 20 7]
 divide
 display)

 =: [89 -4 1 2]
    [36 20 7 5]
    Diff 20

Result sets should be of equal size and the difference between the values inside each set should be printed. Judging by the results of a quick test on ideone you may have missed both points

add display method to print result.

Result set now equal size

For [1 4 5 6 7 8] your program calculated [8 5 4] [7 6 1] Diff 3 where clearly solutions with a difference of 1 exist.

PHP
Warning: Very dirty code
It tries every possible permutation of the input array.
Ideone sample for 4/1 2 3 4: http://ideone.com/gIi174
<?php
// Discard the first input line! It's useless :)
fgets(STDIN);
$numbers = explode(' ', rtrim(fgets(STDIN)));
$valuePerWife = array_sum($numbers) / 2;

// Taken from here: http://stackoverflow.com/a/13194803/603003
// Credits to dAngelov: http://stackoverflow.com/users/955185/dangelov
function pc_permute($items, $perms = array( )) {
    if (empty($items)) {
        $return = array($perms);
    }  else {
        $return = array();
        for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
         list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             $return = array_merge($return, pc_permute($newitems, $newperms));
         }
    }
    return $return;
}

foreach (pc_permute($numbers) as $permutation) {
    $sum = 0;
    $rest = [];

    for ($i=0; $i<count($permutation); $i++) {
        $sum += $permutation[$i];
        if ($sum == $valuePerWife) {
            $rest = array_slice($permutation, $i + 1);
            break;
        }
    }

    if (array_sum($rest) == $valuePerWife) {
        echo implode(' ', array_slice($permutation, 0, $i + 1)), "\n";
        echo implode(' ', array_slice($permutation, $i + 1)), "\n";
        echo 'diff=0';
        exit;
    }
}
exit('DIDNT FOUND ANY COMBINATION!');

Literate Haskell
> import Data.List
> import Data.Function

I made use of the list monad to split it up.
> divide []=return ([], [])
> divide (x:xs)=do
>   (w1, w2) <- divide xs
>   [(x:w1, w2), (w1, x:w2)]

Then we make a rater.
> rating (w1, w2)=abs $ (sum w1) - (sum w2)

And then a function that will minimize the difference.
> best = minimumBy (compare `on` rating) . filter (\(x,y)->length x == length y)

And something that combines them all.
> bestDivison=best . divide

Next a parser.
> parse::String->[Int]
> parse=fmap read . words

And an output formatter.
> output (w1,w2)=unlines [unwords (map show w1)
>                        , unwords ( map show w2)
>                        , "diff="++(show $ abs $ (sum w1) - (sum w2))]

And now the program
> main = do
>   getLine --Ignored, I don't need the arrays length
>   input <- fmap parse getLine
>   putStrLn "" --For readability
>   putStrLn $ output $ bestDivison input

Example:
λ <*Main>: main
8
5 1 89 36 2 -4 20 7

5 36 20 7
1 89 2 -4
diff=20

Result sets should be of equal size

Python:
import itertools as t
raw_input()
a=[int(i) for i in raw_input().split()]
a=list(t.permutations(a))
b=len(a[0])/2
c=[(d[b:],d[:b]) for d in a]
d=[abs(sum(d[b:])-sum(d[:b])) for d in a]
e=zip(d,c)
e.sort()
print " ".join([str(i) for i in e[0][1][0]])
print " ".join([str(i) for i in e[0][1][1]])
print "diff",e[0][0]

or a bit golfified:
import itertools as t
b=int(raw_input())/2
e=[(abs(sum(d[b:])-sum(d[:b])),(d[b:],d[:b])) for d in t.permutations([int(i) for i in raw_input().split()])]
e.sort()
f=e[0]
g=f[1]
print " ".join([str(i) for i in g[0]]),"\n"," ".join([str(i) for i in g[1]]),"\n","diff=",f[0]

Or even further golfified, since half the lines is just makeup. (assuming I can just dump the raw internal array, since this isn't specified in the op) You can leave away the print in (for example) the interactive shell, and add a [::-1] (on the very end, after [0]) if you really want the diff last.
import itertools as t
b=int(raw_input())/2
print sorted([(abs(sum(d[b:])-sum(d[:b])),(d[b:],d[:b])) for d in t.permutations([int(i) for i in raw_input().split()])])[0]

(results in (0, ((1, 2, 7, 8), (3, 4, 5, 6))))
This, however, is just bruteforcing all posible combinations, and shouldn't be considered remotely efficient.
However, if the list being equal lengths doesn't matter, this would also work (on large arrays):
raw_input()
a,b=[],[]
for i in sorted([int(i) for i in raw_input().split()])[::-1]:
    b.append(i)
    if sum(b)>sum(a): b,a=a,b
print a,b,abs(sum(b)-sum(a))

With the code under this for example, it runs with barely a difference at all: 500k on 10^10 max value isn't a lot, so to say. This is also a lot faster: where the other code probably wouldn't finish in under a year (and that's very optimistic), this runs in about half a second, even though your milage may vary.
def raw_input():
    import random
    return " ".join([str(random.randint(1,10**10)) for _ in range(10000)])

raw_input()
a,b=[],[]
for i in sorted([int(i) for i in raw_input().split()])[::-1]:
    b.append(i)
    if sum(b)>sum(a): b,a=a,b
print a,b,abs(sum(b)-sum(a))

Question: Why is this a CW post?


text:
Shortest Pong, AI vs AI
Your task is to write the shortest possible Pong game without human interaction, so AI plays vs AI. I assume all of you know Pong, just to make sure, this is the target (just as running code):http://www.youtube.com/watch?v=xeEFMhdnR6c
The following game rules apply:

No ASCII "graphics".
You must actually have code to count the scores, even if the AI never scores.
It must be possible to adjust the size of the output window/area in some way to any (reasonable) size. Which means you must include some form of output scaling.
No need for a menu or other features of the game, just what's in the video.

The following play fair rules apply as well:

No language specifically designed for code golfing.
You may only use standard libraries offered by the language of your choice. No external library downloading, no jQuery, no full-sized game-libraries.
Exception: if no library for graphical output is available with the default offering of the language of your choice, you are allowed to use a library that offers basic graphical output similar to what other languages include in their basic library set.
import statements (or however they are called in your language) can be skipped in the character count.
Doorknob-rule: The paddles may not be bigger than 15% of the game area.

Bonus points:

-50 if you include sound. External sound sources (e.g. wav) do not need to be added to the char count and may be downloaded during execution. If you choose to copy & paste the data into the code, only the actual data is allowed to be skipped for character count.
Another -150 (for -200 total) if you do not use external sounds but generate it. Generate means: you have some form of sound synthesizing, copy & pasting e.g. wav data does not count.

Your "No language specifically designed for code golfing." rule is basically the opposite of "fair"...

It is very fair, because otherwise the solution would be: A Where A is the language specifically designed to display an automatic AI vs AI Pong game.

Your wording suggests that golfing languages like J or GolfScript disallowed. Perhaps you may want to reword that. In any case, it's automatically disallowed in the first place.

No ASCII "graphics".
That's a bit mean to non-http languages, don't you think?

I don't think that a drawRect is that much longer than the definition of a colored div with style-sheets, the graphics are not that detailed after all. ;)
And both need to come up with a way to actually move those.

Pure HTML and CSS, 355 characters

0-0

You may need an up-to-date or beta browser for the CSS animation properties.
Here is a fiddle, with -webkit- vendor prefixes added so that it works in latest Chrome.

The ball just bounces back and forth. The AIs are extremely smart and know not to move.
The 0-0 at the bottom is the score, and you can resize the window.

It is now against the rules, but +1 for pointing that out. :P

@TwoThe that still will work as long as the ball doesnt go diagonal :P

@TwoThe Actually, the real playing area is much larger; I just took a small screenshot. See the fiddle.

It wouldn't be "as the video" anyways. Game field is sideways, ball needs to actually bounce off and paddles need to move.

@TwoThe You never specified it had to be sideways, the ball does bounce, and the paddles don't move because the AI is smart enough to know that they shouldn't move.

I specified "this is the target" followed by the video.

And you are also violating rule #2: There is no code to actually count the scores.

nitpicking after Doorknob escaped the rules :P

I just don't feel like writing several pages of rules. If someone doesn't want to play fair, there will always be a loop-hole. ;)

Scratch, 1605 – 50 = 1555
I don't know how to count the score here and it doesn't meet the "resizing the window" rule... I just thought it was fun. Some unrealistic speed though, and one known bug: if the ball hit the bar at an almost vertical angle, it will somehow get trapped.
Edit: updated score as per community consensus.
The bars will only move if the ball is moving towards its direction. I could make it always move, but I think that would be too boring.
Sprite1: the "ball"

Sprite2: the right vertical "bar" (don't know what it's called)

Sprite3: the left vertical "bar": essentially the same as Sprite2, except the first if condition, which is changed to direction of Sprite1 < 0
Note: you can change the "intelligence" of the AI by changing the glide speed. They will move slower, so higher chance of missing the ball.
Sprite4 and Sprite5 are two white vertical bars placed on either side of the "field". They have no scripts.
Code used for byte counting: (Using snippet to hide code)

when green flag clicked
set [score1 v] to [0]
set [score2 v] to [0]
forever
  go to x: (0) y: (0)
  wait (1) secs
  point in direction (pick random (70) to (290))
  repeat until <<touching [Sprite4 v] ?> or <touching [Sprite5 v] ?>>
    move (10) steps
    if <touching color [#000] ?> then
      play sound [pop v]
      point in direction (((360) - (direction)) + (pick random (-5) to (5)))
    end
    if <touching [edge v] ?> then
      if on edge, bounce
      point in direction ((direction) + (pick random (-5) to (5)))
    end
  end
  play sound [216090__richerlandtv__bad-beep-incorrect v]
  if <touching [Sprite4 v] ?> then
    change [score1 v] by (1)
  end
  if <touching [Sprite5 v] ?> then
    change [score2 v] by (1)
  end
end

when green flag clicked
forever
  if <[0] < ([direction v] of [Sprite1 v])> then
    if <([y position v] of [Sprite1 v]) > [140]> then
      glide (.1) secs to x: (x position) y: (140)
    else
      if <([y position v] of [Sprite1 v]) < [-140]> then
        glide (.1) secs to x: (x position) y: (-140)
      else
        glide (.1) secs to x: (x position) y: ([y position v] of [Sprite1 v])
      end
    end
  end
end

when green flag clicked
forever
  if <([direction v] of [Sprite1 v]) < [0]> then
    if <([y position v] of [Sprite1 v]) > [140]> then
      glide (.1) secs to x: (x position) y: (140)
    else
      if <([y position v] of [Sprite1 v]) < [-140]> then
        glide (.1) secs to x: (x position) y: (-140)
      else
        glide (.1) secs to x: (x position) y: ([y position v] of [Sprite1 v])
      end
    end
  end
end

Note: Code automatically generated using scratchblocks generator, modified as somehow the generator doesn't correctly handle decimal numbers (treating .1 as 0).
See it run online here.
Old version (the bars move randomly).
A screenshot:

I like that XD Whether or not that qualifies as "No use of full solution libraries" I leave up to the community votes. If you manage to join the Y-position of the paddles with the one of the ball, the AD should turn into AI, however there is no requirement for them being smart. ;)

@TwoThe Thanks for the tip, see edit.

Could someone please add the byte count? http://meta.codegolf.stackexchange.com/a/5013/34718

@mbomb007 Done.

HTML / JavaScript, 476
<body onload="for(p in r=c.getClientRects()[0])top[p[0]]=c[p]=r[p];t=c.getContext('2d');t.T=t.fillText;t.R=t.fillRect;A=B=0;a=b=h/2;H=h/9|0;x=w/2;y=h/2;v=w/550;z=h/250;setInterval('x<w/3&&(a+=a<y?3:-3);x>2*w/3&&(b+=b<y?3:-3);y<0|y>h?z=-z:0;x<8&&y>a&&yw-8&&y>b&&y<b+H?v=-v:0;x+=v;y+=z;(x<0?++A:x>w?++B:0)&&(x=w/2,y=h/2);with(t)clearRect(0,0,w,h),R(x,y,5,5),R(2,a,6,H),R(w-8,b,6,H),T(A,H,9),T(B,w-H,9)',16)"><canvas id=c>

Un-golfed:

<canvas id="c"></canvas>

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Swap genders on this page (code-golf)
Yesterday at work, the Google Doodle convinced me to share my rather long gender swap script here, but the code-golf criteria of the question i asked were not clear. As my question still got downvoted after giving examples, i changed the tag to popularity-contest, as suggested before i clarified it.
Here's a more golfy version:
The UN theme for International Women's Day 2014 is "Equality for Women is Progress for All".
In the interest of gender equality, write a program that correctly changes that Wikipedia page from a female to a male perspective. Names and anatomical details may be left unchanged. It should not change who is being referred to.
Example:
Before:

He said she took her girlish books on Feminism with her.

After:

She said he took his boyish books on Masculism with him.

All gendered pronouns and nouns, as well as all adjectival forms of such words, must be changed in the visible English text.
The shortest code that fully transforms the linked version of the IWD Wikipedia page according to the stated rules, wins.

Could still do with some scoping if you want it to be a code-golf. Must proper names be changed? Must words in URLs be changed? Should herstory become history, and vice versa?  Historian/herstorian? I can guess at your intent, but to make it objective it is best to spell out the tasks that must be done. "Adjectives e.g. boyish and girlish - MUST CONVERT, Proper names - DO NOT CONVERT, etc." In essence, we need to know how you will determine the page is "correctly" changed.

@JonathanVanMatre Please read carefully: "Names and anatomical details may be left unchanged."

Apologies for overlooking that sentence, but setting that example aside the point is the same: it is best to spell out what must be done. A single sentence that says something to the effect of "All gendered pronouns and nouns, as well as all adjectival forms of such words, must be changed." would suffice.

I added the proposed sentence and am getting downvoted without comment. On meta my original question only got an upvote. WTF.

5 hours in the sandbox on a weekend is a long way short of granting a reasonable expectation that more than a couple of people have seen it. There's no point putting something in the sandbox unless you're going to leave it there for two days or more. And recently people seem too eager to upvote in the sandbox: in the past couple of weeks I've seen people upvote things which then needed to go through three or four edits before becoming truly ready to post. This could still be improved by making explicit that it's a particular version of the page which needs changing, so it's a static target.

(Although even then it's not going to be a very good question: it's basically "work out what the altered text should be (the hardest part), and then find a minimum set of substitutions and a language which has a compact syntax for mass substitutions").

@PeterTaylor Again, please don't project. I linked to a static Wikipedia version and the sandbox didn't specify vote or time limits. As it was upvoted without comment like the 20+ hour old answers, i assumed it was ready.

@PeterTaylor Also, the hard part is to minimize the amount of code needed. Else one might easily do it manually and simply replace the whole page content.

"Again, please don't project"??! I'm not sure either what you think I'm projecting or when you think you've previously asked me not to.

Sorry, i meant being unclear in general, like the first comment.

Based on what @Peter said, and based on how the previous version of your question went, and based on the lack of any answers other than your own after nearly 2 weeks, I'm inclined to close this question.

@ChrisJester-Young I've restated the objective primary winning criterion at the end of the question.

@CeesTimmerman Very well.

What are the terms we need to replace?

JavaScript, 707 bytes (680 in web console)
javascript:(function(){l=function(s){return s.toLowerCase()};b=document.body;t=b.innerHTML;s="Actress;Actor;Daughters;Sons;Feminine;Masculine;Feminism;Masculism;Feminist;Masculist;Femininity;Masculinity;Mother;Father;Mothers;Fathers;Motherland;Fatherland;Motherhood;Fatherhood;Woman;Man;Female;Male;Females;Males;Girl;Boy;Girls;Boys;Girlfriends;Boyfriends;Grandmothers;Grandfathers;Her;His;She;He;Sister;Brother;Wives;Husbands;WomenWatch;MenWatch;Women;Men;Womensday;Mensday;Internationalwomensday;Internationalmensday;IWD;IMD";a=s.split(';');c=t.split(/\b/);d={};for(i=0;i<a.length;i+=2){x=a[i];y=a[i+1];d[x]=y;d[y]=x;d[l(x)]=l(y);d[l(y)]=l(x)}t='';for(i=0;i<c.length;++i)t+=d[c[i]]||c[i];b.innerHTML=t})()

This is a bookmarklet/favelet; set as URL of a bookmark/favorite and click to transform the loaded webpage.

I guess it simply can't get much shorter than that.

Hi, I tried it out and it is super awesome, but not all pronouns are swapped. I tried it on a random Wikipedia page and the pronoun him was not swapped, for example. it was this Wiki page But it's nice to have a gender-swap bookmark anyway. :)

@linse, thanks, but this code-golf challenge is about transforming this specific page. Here was a more generic popularity-contest answer, but that question was deleted for unclear reasons.

Not a completely worked out answer, but Cees' substitution solution reminded me of the str_replace syntax in PHP:
$body = file_get_contents($url);
$body = str_replace(
  array("Actress", "Daughters", "Feminine", "Feminism", "Feminist", "Femininity", "Mother", "Mothers", "Motherland", "Motherhood", "Woman", "Female", "Females", "Girl", "Girls", "Girlfriends", "Grandmothers", "Her", "She", "Sister", "Wives", "WomenWatch", "Women", "Womensday", "Internationalwomensday", "IWD"),
  array("Actor", "Sons", "Masculine", "Masculism", "Masculist", "Masculinity", "Father", "Fathers", "Fatherland", "Fatherhood", "Man", "Male", "Males", "Boy", "Boys", "Boyfriends", "Grandfathers", "His", "He", "Brother", "Husbands", "MenWatch", "Men", "Mensday", "Internationalmensday", "IMD"),
  $body);

You can shorten this by putting everything into one string, e.g.
str_replace(
  split(';', "Actor;Sons;Masculine;Masculism;Masculist;Masculinity;Father;Fathers;Fatherland;Fatherhood;Man;Male;Males;Boy;Boys;Boyfriends;Grandfathers;His;He;Brother;Husbands;MenWatch;Men;Mensday;Internationalmensday;IMD"),
   ....

but that only makes it marginally better. I'll leave it up to someone to come up with the creative solution.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Partially Solve the halting problem for brainf***
To solve the Halting Problem you are given a description of a program, and must determine whether or not it will ever finish. You can never do this for all programs. Yet for programs like (in brainf***):
>

It obviously will halt, and for programs like:
+[]

It obviously will not. Your challenge is to "solve" the halting problem for as many programs as possible. These programs will not use . or ,, and will not have input or output. You will be given a description of the program and must output either "Halts", "Does not halt", or "Unknown". When your program outputs "Halts" or "Does not halt", you have solved the input program. Here are some requirements.

It must solve at least an infinite amount of programs.
For every program it solves, its solution must be correct.
You may only output 1 of the 3 above choices.
You may assume that the running computer has infinite time and memory, so XKCD 1266 would not work (the tape is unlimited).
No external resources.
You may not use a programming language that can actually solve the halting problem.

You may have a non-code-golfed side program that takes a string that is a program, and generates some sort of abstract syntax tree of it if you like. Note, that isn't really scoring per se, but how to determine if one program beats another.

If program A solves an infinite number of programs that B doesn't, but B only solves finite or no programs that A solves, A automatically wins.
Otherwise, the program with the fewest characters wins. Do not count white space or comments, so do not obfuscate your code.

Tip: Timers won't work. You see, for any time T and given machine, there is an N, such that all programs longer than that have to take more than T time. This means that a timer can only achieve the solution of a finite number of programs, and, as you can see above, solving a finite number of programs doesn't help.

I don't think the scoring system will work.  Given any solution, it is easy to construct a better one as follows: Find any program P on which the solution S outputs "Unknown", create a new solution which outputs the correct answer on input P, the same answer on P with any number of >s added to the end (since these halt iff P halts), and outputs S's answer on all other inputs.  This new solution solves infinitely more problems than S.

These made not add any solutions though. For example, the original P could just say "if the last thing is >, ignore it." Then your thing would be redundant.

Right, so first create a solution S' which answers the same as S but ignores >s after the end of the program, then find a program P on which S' answers "Unknown", then create a new solution that answers correctly on P with >s appended and gives the answer of S' otherwise.  Since S' ignores >s then P with any number of >s appended will also not be solved by S'.

I am having trouble following. Reword as P(x) meaning  the solution (or nonsolution) of x according to P.

Never mind, I just realized I was assuming that appending >s wouldn't make a solution change from "Unknown" to the correct answer but this is not necessarily the case.

I don't understand requirement 6. I also don't understand why you say that the halting program can't be solved for all programs given that the reference implementation has a very finite state space.

"At least an infinite amount of programs"? Is there a bonus for solving more?  ;-)

What exactly does rule #2 mean?

@PeterTaylor Clarified

@KendallFrey Spell check error. Corrected.

Is there a limit on the number of data cells in the BF machine (bounded) or is it unlimited?

It is unlimited.

Since you're apparently not following the reference implementation, you should probably clarify all of the other implementation differences: cell size, behaviour on underflow and overflow, whether the tape is infinite in both directions or only one, and if only one what happens when you try to move past it. It's not the most tightly specified language...

You should change the rules so that only the number of correct "doesn't halt" answers are counted. Identifying infinitely numbers of programs that do halt is easy - all you have to do is run them for a long time and see if they halt. It's the ones that don't that make the problem hard.

What if two submissions a and b can solve programs in set A and B respectively, and both A\B and B\A are infinite? The shorter program wins?

Can the submission itself not halt for some inputs?

@user202729 nope

@user202729 exactly

Then which one win in that case?

@user202729 the shorter one

Python, ungolfed spaghetti code
Oh dear.
def will_it_halt(instructions):
    tape_length = 1
    LOOP_BOUND = 1000
    registry = [0] * tape_length
    pos = 0

    jumpbacks = []
    reached_states = set()

    pos_instructions = 0
    while True:
        letter = instructions[pos_instructions]
        if letter == "+":
            registry[pos] = (registry[pos] + 1) % 256
        elif letter == "-":
            registry[pos] = (registry[pos] - 1) % 256
        elif letter == ">":
            pos += 1
            if pos >= tape_length:
                registry += [0]*tape_length
                tape_length = len(registry)
        elif letter == "<":
            pos -= 1
            if pos <= 0:
                registry = [0]*tape_length+registry
                tape_length = len(registry)
                pos += tape_length
        elif letter == "[":
            if registry[pos] == 0:
                nests = 1
                while nests:
                    pos_instructions += 1
                    if instructions[pos_instructions] == "[": nests += 1
                    elif instructions[pos_instructions] == "]": nests -= 1

                if jumpbacks == []:
                    reached_states.clear()

            else:
                jumpbacks.append(pos_instructions-1)

        elif letter == "]":
            stripped_registry = [str(x) for x in registry if x != 0]
            translated_pos = pos - (len(registry) - len(stripped_registry))
            state = (translated_pos, pos_instructions, ".".join(stripped_registry))
            if state in reached_states: return "Does not halt"
            elif len(reached_states) > LOOP_BOUND: return "Unknown"
            else:
                reached_states.add(state)
                pos_instructions = jumpbacks.pop()
        pos_instructions += 1
        if pos_instructions >= len(instructions): break
    return "Halts"

Pretty brute-forcey solution to the problem: just run the bf code. We assume the tape length is arbitrarily long and that individual cells wrap at 256. At the end of every loop, we store the state of the tape with a set. States are of the form (our position on the tape, our position on the instructions, what the tape looks like with leading 0's stripped).
If we store the same state twice, then we're somewhere in an infinite loop, so the program does not halt. If we store over 1,000 states, then cut losses and return unknown. Once we leave a loop we check to see if we aren't in any larger loops. If not, we're never seeing any of the previous states ever again (at the very least, the instruction position will always be different!) so we can clear the set of states.
This should accurately determine any BF program who's loops aren't longer than 1,000 iterations, as well as many programs that repeat a state before 1,000 iterations in a loop. Not all of them, though: something like "{1 million +'s here}[-]>+[+-]" eventually repeats a state, but the [-] loop passes 1,000 iterations first.
Some examples:
>+>->+>-

No loops, so it reaches the end and halts.
+[+]

Loop ends after 256 iterations, so it reaches the end and halts.
+[+-]

Eventually repeats the state (0,5,"1"), so it does not halt.
+[->+]

This doesn't repeat any states but the loop never ends, so it should print "unknown". But the program kind of cheats here. Instead of storing the position on the tape, it adds an offset between the original registry and the stripped one. If all a loop does is translate the tape by some spaces, then it will continue translating it indefinitely (like a life glider), so we can say it does not halt.
+[>+]

Doesn't translate, doesn't repeat any states, prints unknown.
+++++++++++[-]

This does halt, but it would print "unknown" if LOOP_BOUND was 10.
There's a couple of ways to make this smarter. You could obviously increase LOOP_BOUND to reduce the number of unknowns. You could have smarter handling of nested loops. You could probably do something fancy with BB numbers and the size of loops to better detect if something should halt, but I'm not good enough at CS nor at Python to be able to do that yet.

GolfScript (23 chars, infinite correct answers)
'[]'&!
# 0 if there are brackets, so Unknown
# 1 if there are no brackets, so no looping, so definitely halts
'UnknownHalts'7/=

Saying infinite correct answers is unnecessary, as it was a requirement.

Rules abuse... Lol

Awk
A small extension in power from the two examples. If a program contains no loops at all, hence no decisions, it is still obviously determined to halt. Since we're assuming validity of the program, we also assume brackets are balanced and thus need only search for one or the other of the brackets.
BEGIN{RS=""}
!/\[/{print "Halts"; exit}
END{print "Unknown"}

For the second, it must check first if the loop runs at all, so we must simulate the straight-line code preceding the loop. Then, if the loop returns to the same cell (ie. number of >s is equal to the number of <s within the loop), and it performs no incs or decs at this cell (ie. for any position-balanced prefix of the balanced loop body, there are no instances of + or - before the next < or >, then the cell is unmodified). Implementing this part may take me more time. Ooh, wait, for the first part of checking if the loop runs at all, we can take this same idea and search the pre-loop program for balanced suffixes and insist that there be a + or - (unbalanced).

Haskell
Here is a really simple example answer. Feel free to include it in your answers (since you including multiple tests in an answer is a good idea.)
main=do
    p<-getLine
    if take 3 p == "+[]"
        then putStr "Does not halt"
        else putStr "Unknown"

It basically sees if there is a loop in the beginning. If that exact loop doesn't occur in the beginning, it just gives up. It doesn't even work for ++[]. It does solve an infinite number of programs though, and it is always correct when it solves it.

authors: n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳


text:
These are my lucky dice
Implement a program or function which simulates common dice for role playing games. It should handle at least the d6 and d20, the two most common dice.
However, it should work as stereotypical gamers expect them to work, and not as real dice work.
It is an in-joke between gamers, that one can have a specially lucky die for a very very important roll, by previously throwing a lot of dice, selecting those which resulted in a "1", then throwing them again, until you get a few which rolled a "1" multiple times. You then carefully preserve them, because they rolled a 1 multiple times in sequence, so the probability to roll a 1 next time should be extremely low.
Of course, this is not how dice work in real life, because the rolls are statistically independent.
Your simulated dice have to take previous rolls into account, and work similarly to how the gambler in the gambler's fallacy expects it to work. For example, if a lot of low numbers were rolled, the probability of rolling a higher number should be increased.
However, as this is cheating, you have to hide it well. This means, a casual glance upon the program should not reveal that you cheated. This means, explicitly saving the previous results and reading them on every throw would be too suspicious. You have to hide this "property" of your dice, and bonus points if you make it plausible deniable and disguise it as an honest mistake. (for example, you make your own RNG with an "unintentional" flaw)
Voters, please take into account how well hidden this "flaw" is.
The programs should be clear, and not obfuscated. It's too easy to hide evil code in an obfuscated program.

How well hidden are we talking about? IMO, anything beyond the language's equivalent of getRandomBetween(1,d) would cause me to look deeper into it.

@Geobits : you can find a very nice example for how to solve underhanded problems here: http://codegolf.stackexchange.com/questions/19569/underhanded-code-contest-not-so-quick-sort?rq=1  I mean you can do anything if you justify it well enough, of course, the justification can be a big lie.

Godmaydamnit, java doesnt has enough quirks for underhanded stuff...

Related: http://thedailywtf.com/articles/introducing-the-lucky-deuce

I'm voting to close this question as off-topic because underhanded challenges are off-topic now, and somehow this one slipped under the radar.

Java
public class GamerDie {
    private final java.util.Random rnd;
    private final int sides;

    public GamerDie(int sides) {
        this.sides = sides;
        this.rnd = new java.util.Random();
    }

    public int throw() {
        return rnd.nextInt(sides) + 1;
    }
}

It's so simple that it's obviously not hiding anything: but java.util.Random is a straightforward linear congruential generator, and it uses a discard technique to ensure uniformity, so it guarantees that in any run of the largest multiple of size smaller than 2^48 samples it will distribute the numbers evenly, satisfying the requirement.

cant get behind the explain how java.util.random works

The discarding that java.util.Random performs has very little to do with the behavior of this answer. Really, what this answer relies on is the fact that like any RNG, java.util.Random has a period, and if you generate a number of numbers on the order of the period, its statistical properties break down. That's not very interesting; the same would happen with even a cryptographically-secure RNG like Blum Blum Shub if you ran it long enough.

@user2357112, the discarding is relevant because the question requires uniformity, not a small bias to smaller numbers. In my opinion this answer epitomises underhandedness: the deliberate use of a standard library in a way which at first glance seems transparently correct but actually takes it outside of its design parameters.

Pretty much every RNG does the discarding thing, though. It's nothing special. You could have used this answer with literally any pseudorandom number generator, because if an RNG 1) has a period, and 2) can produce more than 1 different number, then within the scope of a single period, the more a number has shown up relative to other numbers, the less it will show up until the next period by a simple counting argument.

The analysis in this answer requires on the order of 2^48 rolls for an effect to show up. Maybe if you had used a more sophisticated analysis, showing that the use of an LCG causes measurable statistical anomalies to appear within a number of rolls that would plausibly appear in a tabletop game, this might be an okay answer. When you're talking about trillions of rolls, though, it's just not very underhanded.

Ruby
Currently only supports d6, will add d20 support later on...
Lo and behold - those dices are nasty!
# first idea was to create 6 super cool dices just by copy&paste
# -> each dice holds its number at the beginning of the array
# -> we don't need all of them now, so we comment them out
dice0 = %w[[[[[[[[[ 0 . : :. :: ::. ::: ]]]]]]]]
#dice1 = %w[[[[[[[ 1 : . :. ::. :: ::: ]]]]]]]
#dice2 = %w[[[[[[ 2 . : :. :: ::. ::: ]]]]]]
#dice3 = %w[[[[[[ 3 : . :. ::. :: ::: ]]]]]]]
#dice4 = %w[[[[[[[ 4 . : :. :: ::: ::. ]]]]]]]
#dice5 = %w[[[[[[[[ 5 . : :. :: ::. ::: ]]]]]]]]]

# and hey, those dices are almost ascii art ;)

# well, let's just create a standard dice
# -> get rid of the number at the beginning
# -> then sort (maybe we need that later due to the
#    currently unused dices being unsorted)
dice = dice0.select!{|e| /[:.]+/ === e}.sort

def roll(d)
  # rolling is easy
  # -> use size instead of hardcoded number,
  #   maybe we'll have other dices later
  d.slice!(rand(d.size - 1))
end

# and here you have 8 very underhanded dices!
dices = [dice]*8

# roll like a champion
roll(dices[0])
...

I'd add an "abort "requires ruby 2" if RUBY_VERSION < "2"' in there somewhere, as if you run it on earlier versions it spoils the trick

Haskell
Use one random thing to make another random thing: in this case, shuffle cards to generate dice throws.
import System.Environment
import System.Random
import Data.Array.IO
import Control.Monad
-- make random dice from random cards
suit c=map (\(a,b)->[a,b])$zip "A23456789TJQK" (repeat c)
deck=concatMap(\s->suit s) "♠♥♦♣"
-- just like casinos, use more decks for extra randomness
decks=concat$take 8$repeat deck
-- shuffle the cards
shuffle :: [a] -> IO [a]
shuffle xs = do
        ar <- newArray n xs
        forM [1..n] $ \i -> do
            j <- randomRIO (i,n)
            vi <- readArray ar i
            vj <- readArray ar j
            writeArray ar j vi
            return vj
  where
    n = length xs
    newArray :: Int -> [a] -> IO (IOArray Int a)
    newArray n xs =  newListArray (1,n) xs
-- convert a card to a die, by counting along the original deck
-- then taking mod (faces). If we don't have enough cards to make
-- a full set of faces, assign the 'extra' cards a value of 0
card2die faces card=
  let index=(head[i|(i,c)<-zip[0..]deck,c==card]) in
  if (index > (length deck-(length deck`mod`faces)))
  then 0
  else (index`mod`faces)+1
main=
  do
    args <- getArgs
    let faces = read (args!!0)
    -- throw away cards we can't map to die faces
    cards<-shuffle$filter (\card->card2die faces card/=0) decks
    mapM_ (\card->putStrLn (card++" -> "++(show (card2die faces card)))) cards

Takes one argument, the number of faces on the die. Output is like this:
./cards 20|head
2♦ -> 8
7♥ -> 20
J♦ -> 17
6♥ -> 19
9♥ -> 2
8♥ -> 1
5♥ -> 18
4♠ -> 4
Q♥ -> 5
2♣ -> 1

... and so on for all cards (discards are not printed). Too obvious?


text:
“Hello, world!” with n distinct characters
Write a series of programs in the same language that print “Hello, world!” using n distinct source characters, where n is in [1..10] inclusive (“distinct” meaning that duplicate characters are ignored from character count). The winner is the solution with the most programs, each with distinct n. I suggest making one solution per language, which is treated like a wiki.
Further rules:

Case-sensitive ('H' and 'h' are distinct characters)
In case-insensitive languages, all non-string-literal characters are assumed to be uppercase.
EDIT: No characters ignored by the compiler (comments)
Output must be exactly “Hello, world!” (without quotes) - no variations in punctuation or case, and no newline.
“Output” can mean either value of the expression or output to stdout.
Esoteric programming languages are very much allowed.
EDIT: The language must already exist (as of this question being asked).
If anyone gets all of [1..10], they are the accepted winner.

Here's a polyglot example:
'Hello, world'

It scores 11 (and thus is not part of a solution) because it includes distinct characters:
'Helo, wrd!

"Esoteric programming languages are very much allowed." Yet you have implicitly disallowed brainfuck and the HQ9+ 'family'

DC: 2, 3, 4, 5, 6, 7, 8, 9 and 10 distinct characters
Seeing as the value of an expression is accepted as valid, this should qualify for 2 distinct characters (newlines added for legibility):
1111111111111111111111111111111+
1111111111111111111111111111111+
1111111111111111111111111111111+
1111111111111111111111111111111+
1111111111111111111111111111111+
11111111111111111111111111111+1+
11111111111111111111111111111+1+
1111111111111111111111111111+11+
1111111111111111111111111111+11+
11111111111111111111111111+1111+
11111111111111111111111111+1111+
1111111111111111111111111+11111+
11111111111111111111111+1111111+
11111111111111111111111+1111111+
1111111111111111111111+11111111+
1111111111111111111111+11111111+
1111111111111111111111+11111111+
111111111111111111111+111111111+
111111111111111111111+111111111+
111111111111111111111+111111111+
11111111111111111111+1111111111+
11111111111111111111+1111111111+
11111111111111111111+1111111111+
11111111111111111111+1111111111+
11111111111111111111+1111111111+
11111111111111111111+1111111111+
1111111111111111111+11111111111+
1111111111111111111+11111111111+
1111111111111111111+11111111111+
11111111111111111+1111111111111+
11111111111111111+1111111111111+
11111111111111111+1111111111111+
11111111111111111+1111111111111+
11111111111111111+1111111111111+
11111111111111111+1111111111111+
1111111111111111+11111111111111+
1111111111111111+11111111111111+
1111111111111111+11111111111111+
1111111111111111+11111111111111+
1111111111111111+11111111111111+
1111111111111111+1111111111111+
1111111111111111+1111111111111+
111111111111111111+11111111111+
1111111111111111111+1111111111+
1111111111111111111+1111111111+
1111111111111111111+1111111111+
11111111111111111111111+111111+
11111111111111111111111+111111+
11111111111111111111111+111111+
11111111111111111111111+111111+
11111111111111111111111+111111+
1111111111111111111111111+1111+
1111111111111111111111111+1111+
11111111111111111111111111+111+
111111111111111111111111111+11+
111111111111111111111111111+11+
111111111111111111111111111111+
11111111111111111111111111111+
11111111111111111111111111111+
11111111111111111111111111111+
11111111111111111111111111111+
1111111111111111111111111+
1111111111111111111111111+
11111111111111111111111+
1111111111111111111111+
1111111111111111111111+
1111111111111111111111+
111111111111111111111+
111111111111111111111+
111111111111111111111+
111111111111111111111+
111111111111111111+
111111111111111111+
111111111111111111+
1111111111111111+
1111111111111111+
111111111111111+
111111111111111+
111111111111111+
111111111111111+

The above is equal to Hello, world!, which can be seen by printing it with P. Note that it yields an error, as the first plus sign doesn't have two values on the stack to work with, but that doesn't change the value of the expression (as the error doesn't stop the execution). Replace the first plus sign with a space for the solution with 3 distinct characters.
4 distinct characters:
11dd1d+++ddd++dP+1dd+d+++dP1ddd++d+++ddPP111dddP11d+d+P1d+d+d+dd+d+P+PP1dd+++PPdd++ddd++1+PP

The rest:
2i1001000011001010110110001101100011011110010110000100000011101110110111101110010011011000110010000100001P
3i12000022021201222010112112220012020100011020212102102112221212020P
4i1020121112301230123302300200131312331302123012100201P
5i100103122130403124020421012422302411143103141P
6i2324032511514252112222553531220321252053P
7i2106632145606024426126104063251063041P

Brainfuck, n=2, 3, 4, 5, 6, 7, 8
Case n=2: (new lines added for readability)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
+++++++++++++++++++++++++++++.
+++++++..
+++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++.
+++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++.

Case n=2 will be our basis.
For case n=3: we add - to the end of the n=2 source.
For case n=4: we add -> to the end of the n=2 source.
For case n=5: we add ->< to the end of the n=2 source.
For case n=6: we add [><] to the beginning of the n=2 source.
For case n=7: we add [><-] to the beginning of the n=2 source.
For case n=8: we add [><,-] to the beginning of the n=2 source.
Note: if you allow comments to be counted, add a anywhere for n=9 and add ab anywhere for n=10.

Emacs Lisp: One expression that returns "Hello, World!"
Exactly 10 distinct characters: [s, t, r, i, n, g, ), (, *, +]
(string

(*(+(*)(    *))(+(*(
*(+(*)(*    ))(+(*)(
*))))(*(    +(*)(*)(
*)(*))(*(*(+(*)(*))(
+(*)(*))(+(*)(*)))))
))(+(*)(    *(+(+(*)
(*))(+(*    )(*))))(
*(+(*)(*    ))(+(*)(

*))(+(*)(*))(+(*)(*)
)(+(*)(*)))(*(*(+(*)
(*))(+(*
)(*))(+(*)(*)))(+(*)
(*))(+(*)(*))(+(*)(*
))))(+(*
(+(*)(*))(+(*)(*)))(
*(+(*)(*))(+(*)(*))(

+(+(*)(*
))))(*(+
(*)(*))(
+(*)(*))
(+(*)(*)
)(+(*)(*
))(+(*)(*)))(*(*(+(*
)(*))(+(*)(*))(+(*)(

*)))(+(*
)(*))(*(
+(*)(*))
(+(*)(*)
))))(+(*
(+(*)(*)
)(+(*)(*)))(*(+(*)(*
))(+(*)(*))(+(+(*)(*

))))(*(+(*)(*))(+(*)
(*))(+(*)(*))(+(*)(*
))(+(*)(    *)))(*(*
(+(*)(*)    )(+(*)(*
))(+(*)(    *)))(+(*
)(*))(*(    +(*)(*))
(+(*)(*)))))(+(+(*)(
*)(*))(*(+(*)(*))(+(

*)(*))  (+(*  )(*)))
(*(+(*  )(*)  )(+(*)
(*)))(  *(+(  *)(*))
(+(*)(  *))(  +(*)(*
))(+(*  )(*)  )(+(*)
(*)))(  *(*(  +(*)(*
))(+(*)(*))(+(*)(*))
)(+(*)(*))(*(+(*)(*)

)(+(*)(*)))))(+(*)(*
)(*(+(*)(*))(*(+(*)(
*))(+(*)    (*))))(*
(+(*)(*)    (*)(*))(
*(*(+(*)    (*))(+(*
)(*))(+(    *)(*))))
)(*)(*))(+(*(*(+(*)(
*))(+(*)(*)))(*(+(*)

(*))(+(*)(*))(+(*)(*
)))))(+(*(*(+(*)(*))
(+(*)(*)    )(+(*)(*
))))(+(*    )(*)(*))
(*(+(*)(*))(+(*)(*))
(+(*)(*)   ))(*(+(
*)(*))(+    (*)(*))
)(*(+(*)     (*))(+(

*)(*))(+
(*)(*))(
+(*)(*))
(+(*)(*)
))(*(*(+
(*)(*))(
+(*)(*))(+(*)(*)))(+
(*)(*))(*(+(*)(*))))

)(+(+(*)(*)(*))
(*(+(*)(*))(+(*)(*))
(+(*)(*)    ))(*(+(*
)(*))(+(    *)(*)))(
*(+(*)(*    ))(+(*)(
*))(+(*)    (*))(+(*
)(*))(+(*)(*)))(*(*(
+(*)(*))(+(*)(*

))(+(*)(
*)))(+(*
)(*))(*(
+(*)(*))
(+(*)(*)
))))(+(*

)(*)(*(+

(*)(*))(+(*)(*)))(*(+(*)(*))(+
(*)(*)))(*(+(*)(*))(+(*)(*))(+
(+(*)(*))))(*(+(*)(*))(+(*)(*)
)(+(*)(*))(+(*)(*))(+(*)(*)))(
*(*(+(*)(*))(+(*)(*))(+(*)(*))
)(+(*)(*))(*(+(*)(*))(+(*)(*))
)))(+(*(+(*)(*))(+(*)(*)))(*(+
(*)(*))(+(*)(*))(+(+(*)(*))))(
*(+(*)(*))(+(*)(*))(+(*)(*))(+
(*)(*))(+(*)(*)))(*(*(+(*)(*))
(+(*)(*))(+(*)(*)))(+(*)(*))(*
(+(*)(*))(+(*)(*)))))(+(+(*)(*
))(+(*)(*))(*(+(*)(*))(+(*)(*)
)(+(*)(*))(+(*)(*))(+(*)(*)))(
*(*(+(*)(*))(+(*)(*))(+(*)(*))
)(+(*)(*))(+(*)(*))(+(*)(*))))
(+(*)(*(*(+(*)(*))(+(*)(*)))(*
(+(*)(*))(+(*)(*))(+(*)(*))))))

H9+
H
H0
H01
H012
H0123
H01234
H012345
H0123456
H01234567
H012345678

This is awkward. Wait, is the output exactly “Hello, world!”? What implementation are you using?

Yes, I'm pretty sure that's the exact output. I didn't run it, because I don't know of any online (read: convenient) interpreter.

This one doesn't give the correct answer. Please find one that does and run it yourself.

@JamesWood, this is exactly what you would have expected if you'd looked at any of the other Hello World questions before posting your one.

@JamesWood I've called out a question on account of that intepreter. It is (and I was) wrong. :) Also note, it's for HQ9+, which apparently doesn't ignore non-instruction symbols.

@JamesWood I was using that interpreter when I posted this. (see response)

@PeterTaylor my exactness rules were made to avoid HQ9+ winning. I might add a “no symbols ignored by the compiler” rule before someone makes a cheeky BF solution.

Actually, 10 bytes
HIKLPTUVZ]

Try it online!
All prefixes of the program output Hello, World!:
H
HI
HIK
HIKL
HIKLP
HIKLPT
HIKLPTU
HIKLPTUV
HIKLPTUVZ
HIKLPTUVZ]

99, 3 to 10 distinct chars
999 9 9
99 99999999 999 9
99
99 99999 9 999 9
99
99 99 999 999999
99
99
99 9999999 9999 999 9
99
99 99 9999999 9 999 9 999 9 999 9
99
99 99 999999 9 999999 9
99
9999
99 99999 999 999999 999 9
99
99 9999999 9999 9 999 9
99
99 99 999999 9
99
99 99 999999 999 9
99
99 99999 9999999 9
99

Try it online!
This is just standard 99.
For the rest, replace the 999 with 9a99, 9ab99, etc.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/