text:
Sabotage a Train to Make It Run Late
"I want to go to the Araby bazaar to buy a present for the one I have fallen in love with. However, if I arrive too late all the stores will be closed and I won't be able to buy anything. Can you help me?"
Goal: Get the boy to Araby from North Richmond Street before all the stores close.
Actual Goal: Make sure the boy doesn't arrive in Araby before the stores close.
Your program will take in input in the following format:
<time> <map>

where

<time> is the maximum time the boy can spend travelling, in minutes. It is a positive integer.
<map> is a graph of the routes the train can take.

Here is how the format for the graph works:

Each statement is ended with a semicolon.
Nodes in the map (which represent switches) are represented using single lower case letters.
A path between nodes is represented with the syntax a,X,b, where X is an integer representing the weight of the path. The weight of the path is the time, in minutes, the train takes to go through those two nodes.
Araby is represented with a, and North Richmond Street is represented with an n.
All paths are bidirectional.

For instance, this graph (pretend the paths are bidirectional):

Image by Artyom Kalinin, via Wikimedia Commons. Used under the CC BY-SA 3.0 licence.
would be recorded in the graph notation as:
a,4,b;a,2,c;b,5,c;b,10,d;c,3,e;e,4,d;d,11,f;

Note that this input doesn't have an n, so it's an invalid input. Your program may do anything if given an invalid input.
Here is an example input:
21 n,4,b;n,2,c;b,5,c;b,10,d;c,3,e;e,4,d;d,11,a;

(It's just the same graph as the image above with a replaced by n and f replaced by a).
The boy must get from n to a within 21 minutes. If he takes the route n --> c --> e --> d --> a, he gets there in 20 minutes, which is in time. We could represent that route as a comma separated list of nodes:
n,c,e,d,a

On the other hand, the route n --> b --> c --> e --> d --> a will cause the boy to take 27 minutes, which is not in time. We could represent that route like this:
n,b,c,e,d,a

Another possible route that will cause the boy to not make it in time is:
n,b,c,b,c,b,c,b,c,b,c,b,c,b,c,b,c,b,c,e,d,a

Your program should take in the input as described above, and at first glance appear to output a route that will cause the boy to make it in time, but actually outputs a route that causes the boy to not make it in time. For any given input there will always exist a route, without backtracking, that causes the boy to not make it in time.
This is an underhanded popularity contest, so the entry with the most votes wins. Votes are awarded for ingenuity in hiding the bug - the less obvious it is the better.
Here are some sample graphs to test your program with.
Input:
12 a,2,c;a,2,e;b,5,c;b,4,d;b,11,e;d,7,n;e,4,n;

A visual representation (this visual representation is only for clarity and does not constitute part of the challenge):

A possible output:
n,d,b,e,a

Input:
10 a,8,b;a,12,d;b,1,n;d,11,n;a,1,n;

Here is a visual image of the graph:

A possible output:
n,d,a

Can we write a function (instead of a stand-alone program)?

@golfer9338 Yes. I'd prefer a program if possible, but if the underhanded part relies on it being a function then a function is allowed.

I'm asking because I plan to do this in Javascript.

@golfer9338 I see. A function is fine then.

The real question is, why are we out to spite this love-struck boy? Perhaps he insulted our family? Do we ourselves have designs on the object of his affection? We must know!

I'm voting to close this question as off-topic because Underhanded challenges are off topic on this sight

I'm voting to close this question as off-topic because  underhanded challenges are now off topic.

Python 3 (not 2)
Edit: I'll ungolf this in the morning, oops.
It's a perfectly normal A-star search. Right? Riiiiiiight?
Seems to work for all test cases.
def a(b,c,d):
    e,f,g=[],{},{}
    f[c]=0
    while f:
        h=sorted(f.keys(),key=lambda z:-f[z],reverse=True)[-1]
        if h==d:break
        e.append(h)
        for z in b[h]:
            if z in e:continue
            if z in f and f[z]>f[h]+b[z][h]:continue
            g[z]=h
            f[z]=f[h]+b[z][h]
        del f[h]
    i=[]
    j=d
    q=0
    while j!=c:
        i.append(j)
        q+=b[j][g[j]]
        j=g[j]
    return q,(i+[c])[::-1]
t,q=input().split(" ")
t=int(t)
q=q[:-1]
q=[i.split(",")for i in q.split(";")]
g={a:{}for a in __import__("functools").reduce(lambda zz,zy:zz+zy,[[v[0],v[2]]for v in q])}
for l in q:g[l[0]][l[2]]=g[l[2]][l[0]]=int(l[1])

r=a(g,'n','a')
print("time-good: %d, time-ours: %d" % (t, r[0]))
print("path: %s" % " -> ".join(r[1]))


text:
Unique code generation
As input, you are given a positive integer n. Output a code in response. Each n should generate a unique code. There are some constraints on the code that it outputs:

The code must be 7 or more characters long in based on the input.
The code will be have only 7 characters when input string is less than 676000 and must be unique.
The code always begins with ST
The third and fourth characters are letters from A-Z
The remaining characters are numbers.

so if 1 then STAA001
  2 then STAA002

upto 999 then STAA999
  1K then STAB000

this will continue unto 676599 then STZZ999, (still this total count is 7)
so after this for 676000 then STAA0000 (count is 8) and so on.
This is code golf, so the shortest entry in bytes wins.
KMT's original post for reference:

I need the generate the code using input value. The code must be 7 or
  more character Consider Sample code STAA000 in which 'ST' is always
  constant and next to characters changes based on the input they must
  alphabets from A-Z and the remaining characters are number.
EX:
  Input         Result

  1. 100              STAA100
  2. 2201             STAB201
  3. 676001           STAA0001
  4. 677111           STAA1111

Hi, welcome to PPCG! Currently your question is incomplete because it lacks an objective winning criterion.

In addition, if you are asking a general programming question, it will better suited at Stack Overflow.

I need the code for this pattern using any language, @Lilac can you please edit it so that must be post here.

knt: You asked me to edit it so that it could be posted here. I have done that, but note that PPCG is not for real-life programming questions. You may not like the answers you'll get.

Trivial variant of Mixed Base Conversion

@PeterTaylor no that is not the solution I am looking for.

The question (whether as challenge or no) is not clear to me, since there are so many trivial solutions like the one from Shujal.

@Falko could you please provide me anyone solution.

If you're looking for a real-world solution, this isn't the right place to ask. This site is for programming challenges and contests, not general programming questions. You might want to try [so] instead. Thanks!

@Doorknob This is challenge and but it can be also used in real-world.

Even though this is the worst challenge ever (in its original form), the OP is undiscerning and the question is closed - here you go: print"ST%c%c%03d"%(65+n%676000//26000,65+n%26000//1000,n%1e3) (Python 2, 61 bytes)

CJam, 9
"STAA00"r

Just prints the number back, no fancy algorithm.

@knt His code works fine, you specified that it must be at least 7 characters, his does that. If you input 676001 it will output 'STAA00676001' which is a valid code by your description...

@spocot no if the input is 676001 means the result must be STAA0001.

The algorithm is 0-999 will have code from STAA000-STAA999 from 1000-1999 it will have STAB000-STAB999 so by using this we will have 676000 combination and if the number is 676001 then we will code with STAA0001. Now it is possible to understand the algorithm.

@knt You didn't specify that in your question. My answer clearly matches your requirements. Please edit your question.

@Shujal please refer the example I have given in the question.

@knt Example≠clear question

Pyth, 9
p*w3"STAA

Examples:
$ pyth -c 'p*w3"STAA' <<< 0
STAA000
$ pyth -c 'p*w3"STAA' <<< 677111
STAA677111677111677111

This is exactly equivalent to the following python 3 code:
print("STAA", end=input()*3)

The *3 is necessary to guarantee the result is at least 7 characters.

You should just change 'STAA' to 'STAA00' and remove the *3 because the *3 produces a code with a length of 5 if the user inputs a 0.

@spocot Your suggestion, e.g. pw"STAA00 works just as well. However, see the first example, which demonstrates a user input of 0. In particular, a string multiplication by 3 is performed, not an integer multiplication by 3.

I see, my mistake

@isaacg Also please refer the example I have given in the question. Only it should begin with ST, but when input is 1999 it must STAB999, also when 677111 it should be STAA1111 but not always 'STAA'.

source: Stack Exchange

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

sort: votes


text:
Golfing the Core
Note: although this is tagged as Python, other languages are permitted
Challenge
What you have to do is write the shortest functions to perform the same actions as the following Python 2 built in functions:
Range
>>> range(1, 10, 1)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1, 10, 2)
[1, 3, 5, 7, 9]
>>> range(10, 5, -1)
[10, 9, 8, 7, 6]

range(start, end, step)

When run, this produces an ascending list of numbers. Generally used in for loops, this can also be used for golfing when lists of numbers are required.
Type
>>> type(12)
'int'
>>> type(12.0)
'float'
>>> type('12')
'str'
>>> type([13, 45])
'list'

type(var)

Returns the data type of a variable. The required types are in the examples.
Round
>>> round(0.5, 0)
1.0
>>> round(0.2, 0)
0.0
>>> round(3.14159, 3)
3.142
>>> round(127.56, -2)
100.0
>>> round(12.5640, 2)
12.56
>>> round(1457, -2)
1500

round(number, ndigits)

Given a floating point integer, it rounds it to ndigits. Floor and ceil functions are not allowed. For ties, round away from zero.
Enumerate
Note: Return a list despite the fact that in Python, enumerate returns an object.
>>> enumerate([1, 2, 3, 4])
[[0, 1], [1, 2], [2, 3], [3, 4]]
>>> enumerate(['spam', 'eggs'])
[[0, 'spam'], [1, 'eggs']]

enumerate(array)

Returns a two dimensional list with the index as part of the embedded list.
Rules
People writing in Python must not use the built-in functions listed above (or magic variables). If there are similar built-in functions in your language, you must not use them.
For invalid arguments return 1:
>>> enumerate(23)
1
>>> round(56, 'hello')
1
>>> range('hi', 4, 1)
1

You may use your own functions (range, type, round and enumerate).
Winning
Your score is the sum of the byte count for each function (the function declaration should not be counted). The lowest score wins.

How should throw a type error work outside of Python?

@BetaDecay - So CJam's , is allowed ? which works like 10 , = [0 1 2 3 4 5 6 7 8 9] ?

@Optimizer I'm afraid not

Does the range version have to work for fewer arguments? For example, range(5) yields [0,1,2,3,4] and range(2,5) yields [2,3,4].

@Wrzlprmft No, to be fair on other languages, it must use three arguments

So, I may not even write a version of range which is capable of dealing with fewer arguments, if I want to?

@Wrzlprmft Well... Go on then

Are you sure about having 1 returned for invalid arguments? Most solutions do not seem to comply with this.

The "return 1" imposition generate a ugly bug, because it is possible to  confuse one right answer as round(0.5,0) with one not right as round("hi",0) (both one would return 1). For the remain it was a little difficult find the right extreme for range(). In total it is a very good question: Thank you

Use lambda for 0 bytes? (The entire statement is declaring a function)

I'm voting to close this question as off-topic because it a multi-part challenge with no interaction between the parts

Python 2 – 309 303
t=type=lambda x:["list","string","int","float"][(`x`[0]!="[")*(1+(`x`[0]!="'")*(1+("."in`x`)))]
def T(s,a,i,b=1):
    try:return(1/(t(i)=='int'))*eval(s)
    except:return 1
r=range=lambda a,b,i:T("[a]+r(a+i,b,i)if b*i>a*i else[]",a,i,b)
enumerate=lambda a:T("map(list,zip(r(0,len(a),1),a))",a,1)
def round(a,i):b=T("10.**-i/2*a/abs(a)",a,i);return T("a-(a+b)%(b*2)+b",a,i,b)

It’s so long, because it complies with the requirements (if I am not mistaken), in particular returning 1 for invalid input.
Matsjoyce’ answer provided some inspirations.

This is the shortests valid answer (out of this and the Applescript answer), so I've accepted it

MIPS
Range - 40
Probably can be golfed much more with x86 or some clever instruction.
Input:
    .text
    .globl main
main:   # Read inputs
    li      $v0, 5
    syscall
    move    $t0, $v0

    li      $v0, 5
    syscall
    move    $t1, $v0

    li      $v0, 5
    syscall
    move    $t2, $v0

Actual program (writes to stack):
loop:   bgtz    $t2, pos
        ble     $t0, $t1, exit  # i <= end
        j       l
pos:    bge     $t0, $t1, exit  # i >= end
l:      addi    $sp, $sp, -4
        sw      $t0, 0($sp) # Push $t1
        add     $t0, $t0, $t2
        j       loop

Type - 12  (non-serious)
In MIPS all registers can be used with integer instructions, even the floating point ones.
    .text
    .globl main
main:
    li      $v0, 4
    la      $a0, msg
    syscall

    .data
msg:        .asciiz "Integer (probably)"

JavaScript ES 6 - 175 Bytes
I'm counting everything up to the arrow as part of the declaration.
Range 57:
range=(a,b,c)=>{for(r=[i=0];i<Math.ceil((b-a)/c);r[i]=a+i++*c);return r}

Type 45:
type=a=>a.big?'str':a.map?'list':~~a!=a?'float':'int'

Round 54:
round=(a,b)=>(c=Math.pow(10,b),d=a*c,e=d-~~(d),(e<0.5?d-e:d+1-e)/c)

Enumerate 19:
enumerate=a=>a.map((x,y)=>[y,x])

The string type is just str so you can save 3 bytes and comply with the requirements :)

@IngoBurk Thanks, man :)

Some errors: type(1.0) returns int, type([1.3]) returns float. Using ternary instead of || produces shorter code!

@Florent Thanks for pointing out, but the 1.0 thing can't be fixed because there's no distinction between integers and floating point numbers in JS :T

Ruby, 183
range=->a,b,s{r=[a];r<<a while(a+=s)<b;r<<a} # 38 bytes

type=->x{%w[int float str list 1][[1,1.0,'',[]].find_index{|y|x.class===y}||4]} # 74 bytes

round=->n,d{a=10**d;b=n*a;z=b%1;b-=z<0.5?z:(-1+z);b/a} # 48 bytes

enumerate=->l{(0...l.size).zip l} # 23 bytes

I've not counted the names of the lambdas and the = that follows them. Only type handles invalid input. It returns the String "1" when an object with a class other than Integer, Float, String or Array is given. The other functions blow up when, for example, a Symbol is passed where a Numeric is expected. I suspect Python behaves similarly.

Python 3 - 199
Range - 48
def range(s,e,g):
 r=[]
 while[s>e,s<e][g>0]:r+=[s];s+=g
 return r

Enumerate - 32
enumerate=lambda x:[[i,x[i]]for i in range(len(x))]

Or
enumerate=lambda x:zip(range(len(x)),x)

But this doesn't return a list
Round - 29
def round(x,a):
 a=10**-a
 return(x+a/2)//a*a

Type - 90
def type(x):
 x=repr(x)
 if x[0]in"'\"":return str
 if x[0]=="[":return list
 return[int,float]["."in x]

Re. the enumerate, what would the other format be? Keep in mind that other languages can't handle objects in the same way.

Just use zip, without the list calls, which results in a zip object of tuples (<zip object at 0x7eff05fee948>, which when iterated over produces (0, 'a') (1, 'b') (2, 'c'))

Shouldn't range(0,len(x),1) be the same as range(0,len(x))?

@proudhaskeller He's using his own definition of range which requires the inclusion of the step

@BetaDecay Can we use the builtin range, as it could just be range(len(x))?

@matsjoyce I suppose so

@BetaDecay: Wouldn’t this directly contradict your rules?

@matsjoyce: round(-1.5,0) should return 1. Also, you do not return 1 for invalid input.

@Wrzlprmft Also, you do not return 1 for invalid input Neither does the ruby solution, as that would make the length way bigger (catch exceptions, etc.). Also, round(-1.5,0) returns -1.0 for me?

@matsjoyce: I noticed, see my comment on the question. round(-1.5,0) should return -2 (rounding away from zero in case of a tie) – I messed up the sign in the last comment.

Haskell, 86
import Data.Typeable
approx f n=toEnum(fromEnum$10^n*f+0.5)/10^n
getType a=typeOf a
range a b c=[a,a+c..b-c/abs c]
enumerate=zip[0..]

In Haskell there is a type system, so I allowed myself to have a Typeable type-class restriction in getType's type (type is a reserved name in Haskell). to clarify, this is impossible in any other way, as in Haskell you can't cast variables to other types and catch the resulting type exceptions - Haskell simply does not have type errors.
The enumerate functions returns a list of two tuples instead of a list of lists, and I figured that if python tuples weren't immutable they would use them instead.
note that there's already a round function in Haskell so I called the round function approx.

People writing in Python must not use the built-in functions.... If there are similar built-in functions in your language, you must not use them. - You violate this rule with typeOf.

@BetaDecay but round is a different function - it rounds to a whole number, and it rounds down on 0.5. it is a different function and thus I can use it.

@BetaDecay about typeOf, because Haskell has a strict type system, this is the ONLY way it is possible. you can't just get an Object, try to cast it and catch the exceptions.

Haskell's round would fall under the rule "Floor and ceil functions are not allowed" or the restriction "If there are similar built-in functions in your language, you must not use them", imo.

@britishtea now doesn't use round

AppleScript, 382
AppleScript is fun to golf but can't compete with other languages.  I count the function bodies, but not the declarations of on handler(arg) and end handler.
--range: 82 bytes
on r(i,j,c)
try
set a to{}
repeat while i/c<j/c
set a to a&i
set i to i+c
end
a
on error
1
end
end r

-- type: 131 bytes
on type(x)
try
if x=x as list
"list"
else if x=x as text
"str"
else if x=x as real and"."is in x as text
"float"
else
"int"
end
on error
1
end
end type

-- round: 70 bytes
on round2(x,p)
try
set m to 10^-p
if x<0then set m to-m
(x+m/2)div m*m
on error
1
end
end round2

-- enumerate: 99 bytes
on enumerate(x)
try
set a to{}
repeat with i in r(1,1+count x,1)
set a to a&{{i-1,x's item i}}
end
a
on error
1
end
end enumerate

-- examples: see results in event log
log r(1, 10, 1)
log r(1, 10, 2)
log r(10, 5, -1)
log type(12)
log type(12.0)
log type("12")
log type({13, 45})
log round2(0.5, 0)
log round2(0.2, 0)
log round2(3.14159, 3)
log round2(127.56, -2)
log round2(12.564, 2)
log round2(1457, -2)
log enumerate({1, 2, 3, 4})
log enumerate({"spam", "eggs"})
log enumerate(23)
log round2(56, "hello")
log r("hi", 4, 1)

range
I renamed range to r because my enumerate function calls r.
I use AppleScript errors to detect invalid arguments. If AppleScript raises an error, then the try structure returns 1. Beware that range([1], "10", 1) raises TypeError in Python, but r({1}, "10", 1) is valid here, because AppleScript's operators accept single-item lists and strings as numbers.
The try body is just this:
set a to {}  -- empty list
repeat while i / c < j / c
    set a to a & i  -- append i to list
    set i to i + c
end

The condition needs to be i < j when c is positive, or i > j when c is negative.  I golfed it as i/c<j/c, because the division reverses the comparison when c is negative.  As a bonus, c being zero raises a division by zero error, so I correctly reject c being zero as invalid.
Beware that set a to a & i is slow because it copies the whole list a every time.  The fast way might look like set r to a reference to a, then set end of r to i, but that is not golf.
type
AppleScript's type operator is class of x (or x's class). My own type function uses operator =, because 1 + "1" is 2 but 1 = "1" is false. The try body is this:
if x = (x as list)
    "list"
else if x = (x as text)
    "str"
else if x = (x as real) and "." is in (x as text)
    "float"
else  -- assume x = (x as integer)
    "int"
end

Some arguments are invalid; try calling type(AppleScript) or type(type). Then x as text or x as real raises an error and I return 1. It helps that x as list always works and x as text works with any number.
Because 12 = 12.0 is true, I need another way to tell floats from ints. I observe that 12 as text is "12" but 12.0 as text is "12.0", so I check for "." in string. I have no check for infinities or NaN because trying to compute those would raise errors.
round
I renamed round to round2 because AppleScript has round in its standard additions. The try body is this:
set m to 10^-p
if x < 0 then set m to -m
((x + m / 2) div m) * m

I observe div truncating toward zero.  For rounding, I must calculate x + m / 2 when x is positive, or x - m / 2 when x is negative.  For golf, I can negate m. In the div m*m part, the negative sign of m cancels itself.
Python's round typically returns a float, but this round2 often returns an integer.  AppleScript's operators like to convert floats to integers, perhaps to help 68k Macs with no FPU. (PowerPC Macs emulated a 68LC040 with no FPU.)
enumerate
My enumerate also works with strings.  The try body is this:
set a to {}
repeat with i in r(1, 1 + (count x), 1)
    set a to a & {{i - 1, x's item i}}
end
a

I must not use AppleScript's range loop (repeat with i from 1 to count x), but I may call my own range function.  I tried to golf away the final a, but I need it when enumerating the empty list or string.
Beware that i is a reference to a number, not the number itself. If I looped in r(0,count x,1) and collected {{i,x's item(i+1)}}, the result might look like {{item 1 of {0, 1}, "spam"}, {item 2 of {0, 1}, "eggs"}}. The operations i-1 and x's item i coerce i to a number.

APL (43+19+18+38=118)
type←{''≡0↑⍵:'str'⋄⍬≢⍴⍵:'list'⋄⍵=⌈⍵:'int'⋄'float'}  ⍝ 43
round←{0::1⋄∆÷⍨⍎0⍕⍵×∆←10*⍺}                          ⍝ 19
enumerate←{0::1⋄(¯1+⍳⍴⍵),¨⊂¨⍵}                       ⍝ 18
range←{0::1⋄0<∆←-⍺⍺:⌽∆+⍵(∆∇∇)⍺⋄⍺<⍵:⍺,⍵∇⍨⍺-∆⋄⍬}    ⍝ 38

I made the argument order consistent with general APL style.
Ungolfed, with explanation.
Test:
      ⍝ range: <start> <step> range <end>
      1 (1 range) 10
1 2 3 4 5 6 7 8 9
      1 (2 range) 10
1 3 5 7 9
      10 (¯1 range) 5
10 9 8 7 6
      ⍝ type: type <obj>.
      ⍝ 1.0 is considered int, because APL itself does not make the distinction
      type 12
int
      type 12.1
float
      type '12'
str
      type (13 45)
list
      ⍝ APL's native type function:
      ⎕DR¨ 12 12.0 12.1
83 83 645
      ⍝ round: <digits> round <value>
      0 round 0.5
1
      0 round 0.2
0
      3 round 3.14159
3.142
      ¯1 round 127.56
130
      ¯2 round 127.56
100
      2 round 12.5640
12.56
      ¯2 round 1457
1500
      ⍝ enumerate: enumerate <list>
      enumerate 1 2 3 4
┌───┬───┬───┬───┐
│0 1│1 2│2 3│3 4│
└───┴───┴───┴───┘
      enumerate 'spam' 'eggs'
┌────────┬────────┐
│┌─┬────┐│┌─┬────┐│
││0│spam│││1│eggs││
│└─┴────┘│└─┴────┘│
└────────┴────────┘

Does APL work right to left? I've seen several cases where strings were written backwards...

@BetaDecay: there is no operator precedence, so everything is executed right-to-left, i.e. a F b G c means F(a,G(b,c)). So that also means G must run before F does. If you want the equivalent of G(F(a,b),c), you have to use braces, i.e. (a F b) G c. So that means that if you're writing a function like round, you want to make the precision the left argument and the input the right argument, because you're far more likely to write something like "round all these numbers to three decimal places" than "round this number to zero, one, two, and three decimal places".

Axiom, 438 445 bytes
The macro used 18 bytes
I==>"int";T==>type

Two macros named I=="int" and T=="type"
the type function 124 bytes
T a==(y:=(tex domainOf a).1;suffix?("Integer()",y)=>I;y="Float()"=>"float";y="String()"=>"str";prefix?("List ",y)=>"list";y)

Function type()[or T] that retrun "int" "float" or "list" it depend of the type of its argument.
It can not fail, it would return the right string for the type int, float, list of ???, string,
or othewise would return one unknow string different, in Tex language that says its type in Axiom.
Example:
(26) -> q:=set [x**2-1, y**2-1, z**2-1];type(q)
   (26)  "Set \left( {{Polynomial \left( {{Integer()}} \right)}} \right)"
                                                             Type: String

the round function 152 bytes
Round(a,c)==(v:=T a;(v~="float"and v~=I)or T c~=I=>%i;a<0=>-Round(-a,c);z:=a*10.^c;x:=truncate(z);w:=0.5+x-z;0<=w and w>10^-digits()=>x/10^c;(x+1)/10^c)

It would return the Round() of the number (it is in count the error of float so we impose bheaviour of it is of the kind
Round(0.4999999999999999999, 0) is 0.0 but Round(0.499999999999999999999, 0) is 1.0 and so Round(0.49999999999999999999999999999999, 0) is 1 too).
if Round(a,c) find one error it return the complex number %i [the complex costant i].
I don't know how write it without one call one function equivalent to floor (I'm sorry)
the range function 95 bytes
Range(a,b,c)==(T a~=I or T b~=I or T c~=I=>[];[a+c*i for i in 0..(Round((b-a)/c*1.,0)::INT-1)])

It would return the result range as a list of number; if find one error it would return the void list [].
It use the above type() and Round(,) function too.
The enumerate function 56 bytes
enumerate a==(T a~="list"=>[];[[i-1,a.i]for i in 1..#a])

It would enumerate the element of the list as in the question; in case of error return [] void list.
Result in the session
(5) -> [[i,j,Round(i,j)] for i in [0.5,0.2,3.14159,127.56,12.5640,1457] for j in [0,0,3,-2,2,-2]]
   (5)
   [[0.5,0.0,1.0], [0.2,0.0,0.0], [3.14159,3.0,3.142], [127.56,- 2.0,100.0],
    [12.564,2.0,12.56], [1457.0,- 2.0,1500.0]]
                                            Type: List List Complex Float
(6) -> Range(1,10,1)
   (6)  [1,2,3,4,5,6,7,8,9]
                                                       Type: List Integer
(7) -> Range(1,10,2)
   (7)  [1,3,5,7,9]
                                                       Type: List Integer
(8) -> Range(10,5,-1)
   (8)  [10,9,8,7,6]
                                                       Type: List Integer
(9) -> type(12)
   (9)  "int"
                                                             Type: String
(10) -> type(12.0)
   (10)  "float"
                                                             Type: String
(11) -> type([13,45])
   (11)  "list"
                                                             Type: String
(12) -> enumerate([1,2,3,4])
   (12)  [[0,1],[1,2],[2,3],[3,4]]
                                                  Type: List List Integer
(13) -> enumerate(["spam","eggs"])
   (13)  [[0,"spam"],[1,"eggs"]]
                                                      Type: List List Any
(14) -> enumerate(23)     -- error for enumerate
   (14)  []
                                                          Type: List None
(15) -> Round(56,"hello") -- error for Round
   (15)  %i
                                                    Type: Complex Integer
(16) -> Range("hi",4,1)   -- error for range
   (16)  []
                                                          Type: List None

In total and in partial too it is a very good question: Thank you very much.

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


text:
Calculate the troll toll to safely pass
Inspired by https://puzzling.stackexchange.com/q/626

In your adventures you arrive at a series of 7 bridges you have to cross. Underneath each bridge lives a troll. In order to cross the bridge, you must first give the troll a number of cakes as a percentage of the number of cakes you are carrying. Because these are kind trolls, they will give back a certain number of cakes to you.
At the start of each day, the local troll king sets the percent cake tax that each traveler must pay, and the troll cake refund -- the number of cakes that each troll must give back to travelers.
Your job is to calculate the minimum number of cakes needed to pass all 7 troll bridges for the given conditions on that day.
Assume:

Two input parameters: percent cake tax (integer from 0 to 100), and troll cake refund.
No one, not even trolls, wants a cake partially eaten by another troll. If you are left with a fraction of a cake the troll gets it.
If a troll accepts a cake tax, but then has to give you back all of the cakes (is left with the same or fewer cakes than before), it will become angry and eat you and your cakes.
Every troll must keep at least one complete cake.
You can only carry a maximum of 100 cakes.
You need to end the day where you are currently located or on the other side of all 7 bridges.

Challenge:
Write a complete program to output the minimum number of cakes to travel for the current day or zero if it's not possible to safely travel today -- you will wait to see what the numbers are tomorrow.
Input should be passed as stdin, command line arguments or file input.
Shortest code (byte count) wins.
Example:
25% cake tax, 2 troll cake refund.
start with 19 cakes
before troll 1: (19 * 0.75) = 14.25
after troll 1: (14 + 2) = 16
before troll 2: (16 * 0.75) = 12
after troll 2: (12 + 2) = 14
etc.
19 cakes -> 16 -> 14 -> 12 -> 11 -> 10 -> 9 -> 8
18 cakes -> 15 -> 13 -> 11 -> 10 -> 9 -> 8 -> 8 (rule 3)
For 18 cakes, the last troll wouldn't get to keep any cakes. Therefore, the minimum number of cakes for a 25%/2 day is 19.
input: 25 2
output: 19

Example 2:
90% cake tax, 1 troll cake refund
100 cakes -> 11 -> 2 -> 1 (rule 4)
The third troll didn't get to keep any cake. Therefore it is not possible to travel on a 90%/1 day even starting with the maximum number of cakes.
input: 90 1
output: 0

Data
Put together a quick graph of input and output values. I was surprised this wasn't "smooth" (like a bell curve or similar); there are several noticeable islands.

Data for those interested. Columns are divided into 5% intervals, rows are units of 1 cake refund intervals (excel rotated the image). You can see there can't be a refund higher than 28 cakes.
27, 17, 13, 14, 15, 18, 20, 24, 53, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
47, 27, 20, 19, 19, 19, 24, 39, 48, 68, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0
67, 37, 28, 24, 23, 28, 27, 29, 50, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
87, 47, 33, 29, 27, 28, 31, 44, 37, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 57, 40, 34, 31, 29, 34, 34, 62, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 67, 48, 39, 35, 38, 37, 49, 57, 76, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 77, 53, 44, 39, 38, 47, 39, 59, 78, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 87, 60, 49, 43, 39, 40, 54, 46, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 97, 68, 54, 47, 48, 44, 44, 71, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 73, 59, 51, 48, 47, 59, 73, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 80, 64, 55, 49, 51, 49, 68, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 88, 69, 59, 58, 54, 64, 70, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 93, 74, 63, 58, 57, 54, 57, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 100, 79, 67, 59, 67, 69, 82, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 84, 71, 68, 60, 59, 77, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 89, 75, 68, 64, 74, 79, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 94, 79, 69, 67, 64, 66, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 99, 83, 78, 71, 79, 91, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 87, 78, 74, 69, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 91, 79, 77, 84, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 95, 88, 87, 74, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 99, 88, 80, 89, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 89, 84, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 98, 87, 94, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 98, 91, 84, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 99, 94, 99, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 97, 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Good point. Make it a complete program for simplicity. Input can be specified however you see fit as long as it's not hard-coded (updated challenge).

This is a good puzzle to brute-force in CJam. I'll do that around tomorrow

bah, this is why c# can't have nice things

Rule 2 seems to exclude the possibility of a troll receiving only a fraction of a cake, which should make assumption 4 redundant. Yet you say in example 2 that the third troll would only get 0.8 cakes.

There are conflicts in the spec. In the 25 2 11 cake case, you give the troll 2.75 cakes and get back 2 so the troll keeps .75(+.25) and you survive. In the 90 1 2 cake case, you give the troll 1.8 and get back 1 so the troll keeps .8(+.2) but you die.

@Dennis clarified troll didn't get to keep cake; fixed in edit.

@TwiNight there's a rounding issue. Since there's a fraction of a cake, it's rounded in the troll's favor. From your examples, it's give 3 receive 2 and give 2 receive 1.

This question got me thinking. If we take the two numbers as base-101 integers and combine them (refund*101 + tax), we can get a unique number per input case. Then, once we already know the right answer per input case, all we have to do is find a hash function that maps each input to the correct output. I wrote a C program to try to brute-force find such a hash, but it was not a very sophisticated attempt. Has anyone tried to search for a hash function that fits given input->output sets? I could not find any best-practices or tips for doing this.

CJam, 46 43 41 39 38 36 33 bytes
100:H,{)_7{ea:i~H@m2$*H/+@;}*>}#)

Input via ARGV.
There is an online interpreter, but unfortunately it doesn't support command-line arguments. For testing, you can mimick it from STDIN with this version:
rr]:A;
100:H,{)_7{A:i~H@m2$*H/+@;}*>}#)

Explanation of the ARGV-based version:
100:H                                  "Push a 100 and save it in H.";
     ,                                 "Create a range (as an array) from 0 to 99.";
      {                       }#       "Find the first index in [0,1,2,...,99] for which the
                                        block produces a truthy (non-zero) value.";
       )_                              "Increment and duplicate the current array element.";
         7{                }*          "Execute the block seven times.";
           ea:i                        "Push the command-line arguments as an array of strings
                                        and convert each element to an integer";
               ~                       "Unwrap the array.";
                H@                     "Push a 100 and rotate the stack to pull up
                                        the first command line argument.";
                  m                    "Subtract (from 100).";
                   2$                  "Copy the last iterations result.";
                     *H/               "Multiply and divide by 100, deducting tax.";
                        +              "Add the refund.";
                         @;            "Rotate top three stack elements, and discard the one that
                                        has been pulled to the top. This always leaves the last
                                        two results on the stack.";

                             >         "Make sure that the last result was less than the second
                                        to last. Yields 0 or 1.";
                                )      "After the # search completes, we'll get -1 if no such
                                        index exists, or one less than the desired number if it
                                        does, so we can just increment.";

The contents of the stack are automatically printed at the end of the program.

Your code produces incorrect results for 55 2 (0 instead of 100) and 56 5 (98 instead of 94). This is because 100_0.55*-i and 25_0.56*-i fall victim to floating point imprecision. As far as I can tell, the pairs 31 24, 31 25, 33 21, 33 22, 33 23, 35 10, 35 12, 35 15, 35 16, 35 27, 56 1, 57 4 give incorrect results as well.

@Dennis fixed, thanks!

@Dennis That actually saved a byte. I wish CJam had closures, then I could just define a block at the beginning that does the tax deduction, and use that, instead of using two variables. Maybe I can save something using ARGV instead of STDIN, let me see.

CJam, 44 40 38 37 35 bytes
l~U100:M),{{_M5$-*M/3$+_@<*}7*}=]W=

Or when using command line arguments and  {}# trick, 33 bytes:
100:M,{){_ea:i~M@-@*M/+_@<*}7*}#)

Not putting this one as my main as {}# approach is inspired from Martin's answer.
Example run:
Input:
25 2

Output:
19

Another:
Input:
15 14

Output:
100

How it works
l~                       "Read the two numbers, swap and convert tax to double";
  U100:M),               "Push 0 and [0, 1, ... 100] to stack, storing 100 in M";
          {  ...  }=     "Run this code for each element until top stack element is 1";
           {...}7*       "Run this code block 7 times";
_                        "Copy the array element";
  M5$                    "Push 100 and a copy tax % to stack";
     -*                  "Number = (100 - tax %) * Number";
       M/                "Integer divide the number by 100";
         3$+             "Add refund";
            _@<*         "Convert to 0 if refunded number > before tax one";
                    ]W=  "Take the last element of the stack";

Try it online here

And now that's left is to wait for Dennis to come along and beat both of us. ;)

Not in CJam ;) (hopefully)

I really like the ]W= trick, but so far, every way I try to use it I end up with the same character count.

@MartinBüttner - Yeah, me too.

Your code produces incorrect results for 55 2 (0 instead of 100) and 56 5 (98 instead of 94). This is because 100_0.55*-i and 25_0.56*-i fall victim to floating point imprecision.

@Dennis - Should work now, with an added benefit of 2 bytes shorter code :D

APL (39)
T R←⎕⋄⊃Z/⍨{⍵(⊢×>)R+⌊⍵×1-T÷M}⍣7¨Z←⍳M←100

Explanation:

T R←⎕: read two numbers from the keyboard and store them in T (tax) and R (return).
Z←⍳M←100: store the number 100 in M, and all numbers from 1 to 100 in Z.
{...}⍣7¨: for each element in Z, run the following function 7 times:

R+⌊1-T÷M: calculate how many cakes need to be paid,
⍵(⊢×>): multiply that amount by 1 if the troll ends up with more cake than he started, or by 0 if not.

⊃Z/⍨: for each element in Z, replicate it by the number that that function gave. (So all numbers for which the function returned 0 disappear.) Then select the first item from that list. If the list ended up empty, this gives 0.

C, 83 bytes
int cake(int perc_taken, int given_back)
{
    int startcake = floor(100.f/perc_taken*given_back+1);
    for(int i = 0; i < 6; i++)
    {
        startcake = ceil((startcake-given_back) * 100.f/(100 - perc_taken));
    }
    return startcake;
}

If it works, it works for all possible startcakes, not just from 1 to 100.
EDIT: It works. Golfed:
n(int p,int g) {int s=100./p*g+1,i=0;for(;i++<6;){s=ceil((s-g)*100./(100-p));}return s;}

With the 'maximum 100 cakes' limit:
n(int p,int g) {int s=100./p*g+1,i=0;for(;i++<6;){s=ceil((s-g)*100./(100-p));}return s>100?0:s;}

91 bytes.

I think it's an important part of the spec that the solution returns zero if you'd need more than 100 cakes at the start.

CJam, 36 bytes
q~:R100:H*\d:T/i){R-H*HT-/m]}6*_H)<*

APL, 36
x y←⎕⋄101|1⍳⍨y<x×{y+⍵-⌈⍵×x}⍣6⍳x÷←100

Explanation
Note that there is a "cake threshold". For tax rate x and refund y, you will need strictly more than y÷x cakes to pass the next bridge.
x y←⎕ take input and assign to x (tax) and y (return)
⍳x÷←100 divide x by 100, and then generate an array of 1 to 100
{y+⍵-⌈⍵×x}⍣6 call the "pass bridge" function 6 times:
⌈⍵×x The number of cakes you have, times tax rate, round up (the amount you pay)
⍵- Subtract from the number of cakes you have
y+ Add the refund
Then you get a 100-element array showing the number of cakes you are left with after crossing 6 bridges if you start with 1~100 cakes. To see if you can cross the last bridge, check if you are above the threshold y÷x. Alternatively:
x× multiply the array by x
y< check if greater than y
Finally,
1⍳⍨ find the index of first occurrence of 1 (true), returns 101 if not found
101| mod 101

C 128
Pretty similar to the other C solution but I think that's inevitable.  The main trick is breaking out of the inner loop with different values depending on whether it goes to completion or not.  This allows me to use ?: when I couldn't if I used break;
t,r,j,k,l,p;main(i){for(scanf("%d%d",&t,&r),i=101;k=--i;){for(j=8;--j>0;)(p=r+k*(100-t)/100)<k?k=p:j=0;j?0:l=i;}printf("%d",l);}

Ungolfed
int t,r,j,k,l,p;
main(int i)
{
    for(scanf("%d%d",&t,&r),i=101;k=--i;)
    {
        for(j=8;--j>0;)
        {
            if((p=r+k*(100-t)/100)<k)
                k=p;
            else
                j=0;
        }
        j?0:l=i;
    }
    printf("%d",l);
}

what compiler are you using?

C++ - 202 chars
As usual, my C++ did the worst:
#include<iostream>
int main(){double p,g,c=1,i,r,t;std::cin>>p>>g;for(;c<101;c++){r=c;for(i=0;i<7;i++){t=(int)(r*(1-(p/100))+g);if(t>=r){r=-1;break;}r=t;}if(r!=-1)break;}r!=-1?std::cout<<c:std::cout<<0;}


text:
Bulgarian Solitaire
Bulgarian Solitaire is a single-player game made popular by Martin Gardner in his mathematical column in Scientific American.
You have N identical cards, split into piles. You take a card from each pile and form a new pile with the removed cards. You repeat this process until you reach a state you've already seen and so continuing would repeat the loop.
For example, say you have 8 cards, split into a pile of 5 and a pile of 3. We write the pile sizes in descending order: 5 3. Here's a transcript of the game:
5 3
4 2 2
3 3 1 1
4 2 2

You first remove a card from each of the two piles, leaving piles of 4 and 2, and a newly-created pile of 2, giving 4 2 2. In the next step, these decrease to 3 1 1 followed with a new pile of 3. Finally, the last step empties the piles of size 1 and produces4 2 2 which has already appeared, so we stop.
Note that the sum of the pile-sizes stays the same.
Your goal is to print such a transcript of the game from a given starting configuration. This is code golf, so fewest bytes wins.
Input
A list of positive numbers in descending order representing the initial pile sizes. Take input via STDIN or function input. You can use any list-like structure you want.
You don't get the total number of cards N as an input.
Output
Print the sequence of pile sizes the game of Bulgarian Solitaire goes through. Note that printing is required, not returning. Each step should be its own line.
Each line should have a sequence of positive numbers in descending order with no 0's. You may have separators and start and end tokens (for example, [3, 3, 1, 1]). The numbers might have multiple digits, so they should be separated somehow.
Print the pile-size splits you see until and including reaching a repeat. So, the first line should be the input, and the last line should be a repeat of a previous line. There shouldn't be any other repeats.
Test cases
>> [1]
1
1

>> [2]
2
1 1
2

>> [1, 1, 1, 1, 1, 1, 1]
1 1 1 1 1 1 1
7
6 1
5 2
4 2 1
3 3 1
3 2 2
3 2 1 1
4 2 1

>> [5, 3]
5 3
4 2 2
3 3 1 1
4 2 2

>> [3, 2, 1]
3 2 1
3 2 1

>> [4, 4, 3, 2, 1]
4 4 3 2 1
5 3 3 2 1
5 4 2 2 1
5 4 3 1 1
5 4 3 2
4 4 3 2 1

Pyth, 40 25
QW!}QY~Y]Q=Q_S+fTmtdQ]lQQ

This is pretty close to a translation of my python 2 answer.
Sample run:
Input:
[4,4,3,2,1]

Output:
[4, 4, 3, 2, 1]
[5, 3, 3, 2, 1]
[5, 4, 2, 2, 1]
[5, 4, 3, 1, 1]
[5, 4, 3, 2]
[4, 4, 3, 2, 1]

How it works:
Q                          Q = eval(input()) # automatic
 W!}QY                     while not Q in Y:
      ~Y]Q                     Y += [Q]
               fTmtdQ                     filter(lambda T: T, map(lambda d: d - 1, Q))
            _S+      ]lQ           sorted(                                             + [len(Q)])[::-1]
          =Q_S+fTmtdQ]lQ       Q = sorted(filter(lambda T: T, map(lambda d: d - 1, Q)) + [len(Q)])[::-1]
                        Q      print(Q)
QW!}QY~Y]Q=Q_S+fTmtdQ]lQQ

You can replace v$input()$ with Q. 2. If you store the list in decreasing order, you don't need N at all: W!}QYQ~Y]Q=Q_S+fTmtdQ]lQ;Q

@Dennis Thanks, I couldn't figure out how to do that; I knew there was a way to do so.

Here's what I did, totally independently: QW!}QY~Y]Q=Q_S+]lQfTmtdQQ. It's exactly the same, character for character, up to commutativity.

Ruby, 98
f=->c{g={c=>1}
p *loop{c=(c.map(&:pred)<<c.size).sort.reverse-[0]
g[c]?(break g.keys<<c): g[c]=1}}

Explanation

Input is taken as the arguments to a lambda. It expects an Array.
Previous game states are stored in the Hash g.
To create a new game state, use Array#map to decrease every element by 1, add the length of the Array as an element, sort it in decreasing order and delete the element 0.
To check if a game state has been seen before, checking if g has a key for new game state is sufficient.

+1 Really neat Ruby golfing here! However, while the sort_by thing is certainly clever, sort.reverse is actually one character shorter ^^

Aww, that's too bad. Thanks.

CJam, 26 bytes
q{~_:(_,+0-$W%]___&=}g{p}/

Try it online.
Example run
$ cjam <(echo 'q{~_:(_,+0-$W%]___&=}g{p}/') <<< '[5 3]'
[5 3]
[4 2 2]
[3 3 1 1]
[4 2 2]

That's some CJam!

Come on!, I know you can make it shorter than Pyth one!

If :p worked, I could...

Stop whining! :p

CJam, 35 34 33 bytes
(Damn, this power cut that I was not the first one to post in CJam)
l~{_p:(_,+{},$W%_`_S\#0<\S+:S;}g`

Input:
[1 1 1 1 1 1 1]

Output:
[1 1 1 1 1 1 1]
[7]
[6 1]
[5 2]
[4 2 1]
[3 3 1]
[3 2 2]
[3 2 1 1]
[4 2 1]

Try it online here

Python 2, 148 130 101
l=input()
s=[]
print l
while l not in s:s+=l,;l=sorted([i-1for i in l if 1<i]+[len(l)])[::-1];print l

This simply goes remembers all previous iterations, and checks if the new one is in that list. Then, it prints it out.
Sample run:
Input:
[4,4,3,2,1]

Output:
[4, 4, 3, 2, 1]
[5, 3, 3, 2, 1]
[5, 4, 2, 2, 1]
[5, 4, 3, 1, 1]
[5, 4, 3, 2]
[4, 4, 3, 2, 1]

Edit: I reread the specs to golf, plus applied a lot of golfing.

You're allowed to just print the lists as lists.

@xnor Ooh thanks, completely missed that.

This won't work with [5,3]

This gives the wrong output for [4,2,2]. There's an easy fix though.

GolfScript, 50 46
~.p$[]{[1$]+\.{(.!";"*~}%\,+$.-1%p\.2$?)!}do];

Can almost certainly be golfed further. Try it out here.

Python 2 - 103
p=input()
m=[]
print p
while p not in m:m+=[p];p=sorted([x-1 for x in p if x>1]+[len(p)])[::-1];print p

Similar to Quincunx' answer, but replaces appends with addition, and removes the last two lines.
Sample output:
[4, 4, 3, 2, 1]
[5, 3, 3, 2, 1]
[5, 4, 2, 2, 1]
[5, 4, 3, 1, 1]
[5, 4, 3, 2]
[4, 4, 3, 2, 1]

Umm, similar? This is identical; you simply took the golfing steps that were completely obvious. When I came back to mine, I golfed it, and discovered that this is now a duplicate answer of mine (or vice versa, however you want to view it)

I discovered your answer only after posting mine.  I'm ok with considering them duplicates of each other.

CJam, 40 36 34 bytes
]l~{a+_W=_p:(_,+$W%{},1$1$a#0<}gp;

Test it here. Enter input as a CJam-style array, like [5 3], into the STDIN field. Output format is similar, so square brackets and spaces as delimiters.
Even if I golf this down further (which is definitely possible), there's no way to beat Pyth with this. Maybe it's time to learn J. Explanation coming later.

Not sure J will help, I can't get my APL below 38

Haskell, 99
import Data.List
g l=until(nub>>=(/=))(\l->l++[reverse$sort$length(last l):[x-1|x<-last l,x>1]])[l]

JavaScript (E6) 113
Worst entry so far :(
F=l=>{
  for(k=[];console.log(l),!k[l];)
    k[l]=l=[...l.map(n=>(p+=n>1,n-1),p=1),l.length].sort((a,b)=>b-a).slice(0,p)
}

Test in FireFox/FireBug console
F([4,4,3,2,1])

Output
[4, 4, 3, 2, 1]
[5, 3, 3, 2, 1]
[5, 4, 2, 2, 1]
[5, 4, 3, 1, 1]
[5, 4, 3, 2]
[4, 4, 3, 2, 1]

Python 3: 89 chars
g=lambda l,s=[]:print(l)!=l in s or g(sorted([x-1for x in l if~-x]+[len(l)])[::-1],s+[l])

Much like the Python solutions already posted, but with recursive function calls rather than loops. The list s stores the splits already seen, and short-circuits out the recursion in case of a repeat.
The function print() (this is Python 3) just needs to be somehow called in each loop. The tricky thing is that a lambda only allows a single expression, so we can't do print(l);.... Also, it outputs None, which is hard to work with. I wind up putting print(l) on one side of an inequality; == doesn't work for some reason I don't understand.
An alternative approach of sticking it in a list uses equally many characters.
g=lambda l,s=[]:l in s+[print(l)]or g(sorted([x-1for x in l if~-x]+[len(l)])[::-1],s+[l])

Using print(*l) would format the outputs like 4 2 2 rather than [4,2,2].


text:
Stabilize a Brick Structure
Bricks and Stability Defined
This question uses the same definition of bricks and stability as Is the brick structure stable?
Let [__] represent a masonry brick and
         .
         .
         .
  BRK?BRK?BRK?BRK?
BRK?BRK?BRK?BRK?BRK?
  BRK?BRK?BRK?BRK?
BRK?BRK?BRK?BRK?BRK? . . .
  BRK?BRK?BRK?BRK?
BRK?BRK?BRK?BRK?BRK?

represent an arbitrary arrangement or structure of these bricks, with every other row offset by half a brick, as is usual in brick construction. The structure can extend up and to the right indefinitely, but the string representation will always be a perfectly rectangular text block (having trailing spaces where necessary) whose width is divisible by 4.
Each BRK? in the structure may either be a brick ([__]) or empty space (4 spaces).
For example, one possible (unstable - read on) structure is
[__]    [__]    [__]
  [__]        [__]
[__][__]    [__]

A structure's stability is important, and a structure is only stable if every single one of its bricks is stable.
There are three ways an individual brick may be stable:

Any brick on the ground (the lowest line of bricks) is stable.
Any brick that has two bricks directly below it is stable:
  [__]   <- this brick is stable
[__][__] <- because these bricks hold it up

Any brick that has a brick both above and below it on the same side is stable:
  [__]  [__]
[__]      [__] <- these middle bricks are stable
  [__]  [__]      because the upper and lower bricks clamp them in

[__]          [__]
  [__]      [__]   <- these middle bricks are NOT stable
    [__]  [__]

(Yes, I know these rules aren't physically accurate.)
The last challenge was about determining if a structure was stable. This one is about stabilizing those that aren't.
Challenge
Write a program that takes in a potentially unstable arrangement of bricks and adds new bricks into empty brick spaces to make everything stable, printing the result. This is to be done without increasing the overall dimensions of the input text block.
The goal is to create an algorithm that makes the structure stable by adding as few bricks as possible.
This JSFiddle (source) lets you generate random arrangements of bricks for use while testing your program. (Wish I could stack snippets instead.) Width is the number of bricks on the base layer, Height is the number of brick layers, and Density is the fraction of filled brick spaces.
For example, with Width = 5, Height = 3, Density = 0.6 a possible output is
....[__]....[__]....
..[__]....[__]......
[__]............[__]

A way to stabilize this with 4 new bricks is
....[__]....[__]....
..[__][__][__][__]..
[__][__]....[__][__]

Your program must be able to stabilize any brick structure the JSFiddle can generate.

This includes the empty string (which is considered stable).
The brick will always be [__]. Periods (.) are only used for clarity. Your program may use periods or spaces for empty space.
The structure may already be stable, in which case nothing needs to be done (besides printing it).
The JSFiddle always generates structures that can be stabilized (by avoiding Width = 1 and bricks in the top corners). You can rely on this. (Filling all but the top corners is sure to stabilize things but this is clearly not optimal.)
Assume no invalid input. Take input as string however you like. Print the stabilized structure to stdout or similar.
Remember that the text block dimensions should not change size.
Preexisting bricks cannot be moved or removed. Placement of new bricks must follow the offset-every-other-row grid pattern. All bricks must be completely in bounds.
It is encouraged (but not required) that you print the preexisting bricks as [XX] instead of [__], so people can better see how your solution works.

Scoring
At the bottom of the JSFiddle are 8 predefined unstable brick arrangements. (They use [__] and . and should stay that way unless you're using [XX] and/or  instead.) Some are random and some I created myself. To calculate your score, run your program on each of them in turn and sum the number of new bricks added to each.
The less new bricks you've added the better. The submission with the lowest score wins. In case of ties the oldest answer wins.
If things get contentious I may add a few more predefined cases and judge the winner based on them.
Further Notes

Your program needs to run on the order of minutes on a modern computer for brick grid width and height less than 100. (Max 10 minutes on a computer like this.)
You may not hardcode your output for the 8 predefined structures. Your program must treat them as it would treat any other arrangement.
Please include an example output or two, or any interesting structures you'd like to share. :)
This problem is somewhat related to finding a minimum spanning tree.

I should point out that the "stabilized" example under "Challenge" isn't actually stable per the stated criteria.

@COTO Indeed. Fixed.

in your example the middle bottom brick is not needed to stabilise the structure.

@JanDvorak: It states "a way" to stabilize, not "the optimal way", so technically it's not an error. But I agree that taking the middle bottom brick out might help drive home the fact that physical intuition isn't our friend in this problem. ;)

@JanDvorak COTO is right, it didn't matter that it wasn't optimal, but I've changed it nonetheless.

Java - 5,056 bricks

20x20, 0.03 - 75
15x81, 0.05 - 431
50x50, 0.20 - 882
99x99, 0.01 - 2,567
Plain Pedestal - 269
Simple House - 129
Criss-Cross Tower - 323
Bridge Beginnings - 380

Source code is viewable here.
The code runs in a few milliseconds for any of the 8 scoring inputs. There are some noticeably suboptimal outputs, particularly in the criss-cross tower and 99x99 cases. I have several ideas on how to improve the routine, but it's fairly bulky as-is, and hence I'll let it alone for now.
The outputs massacre the laws of physics to a comedic extent. :D
Some samples are shown below.
20x20, 0.03 Output
................................................................................
..........[XX]..................................................................
........[  ][  ]................................................................
..........[  ]..................................................................
............[  ]................................................................
..........[  ]..................................................................
............[  ]....................[XX]........................................
..........[  ]....................[  ][  ]......................................
....[XX]....[  ]....................[  ]........................................
..[  ][  ][  ][  ]................[  ]..........................................
....[XX]....[  ][XX]................[  ]........................................
..[  ]........[  ]................[XX]..........................................
....[  ]........[  ]............[  ][  ]........................................
..[  ]........[  ]................[  ]..........................................
....[  ]........[  ]............[XX]................................[XX]........
..[  ]........[  ]....[XX]........[  ]................[XX]........[  ][XX][  ]..
....[  ]........[  ][  ][  ]....[  ]....[XX]........[  ][  ]........[  ][  ][XX]
..[  ][  ]....[  ]....[  ]........[XX][  ][  ]........[  ]........[  ]....[  ]..
....[  ]........[  ]....[  ]....[  ]....[  ]............[  ]........[  ]....[  ]
......[XX]....[  ]....[  ]........[  ][  ]............[  ]........[  ]....[  ]..
....[  ]........[  ]....[  ]....[  ]....[  ]....[XX]....[  ]........[  ]....[  ]

Simple House Output
................................................................................
................................................................................
................................................................................
......................................[XX]......................................
....................................[XX][XX]....................................
..................................[XX][  ][XX]..................................
................................[XX][  ][  ][XX]................................
..............................[XX][  ]....[  ][XX]..............................
............................[XX][  ]........[  ][XX]............................
..........................[XX][  ]............[  ][XX]..........................
........................[XX][  ]................[  ][XX]........................
......................[XX][  ]....................[  ][XX]......................
....................[XX][  ]........................[  ][XX]....................
..................[XX][  ]............................[  ][XX]..................
................[XX][  ]................................[  ][XX]................
..............[XX][  ]....................................[  ][XX]..............
............[XX][  ]........................................[  ][XX]............
..........[XX][  ]............................................[  ][XX]..........
........[XX][  ]................................................[  ][XX]........
......[XX][  ]................................................[  ][  ][XX]......
....[XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX]....
......[XX][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]....[XX]......
....[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]........[XX]....
......[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[XX]......
....[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]........[XX]....
......[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[XX]......
....[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ]........[XX]....
......[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ][  ][  ]....[XX]......
....[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ][  ][  ]........[XX]....
......[XX]....[XX][XX][XX][XX][  ]....[XX][XX][XX][XX][XX][XX]........[XX]......
....[XX]....[  ]....[  ]....[  ]....[  ]....[  ]....[  ][  ]............[XX]....
......[XX]....[XX]....[  ][XX]........[XX]....[  ]....[  ][XX]........[XX]......
....[XX]....[  ]....[  ][  ][  ]....[  ]....[  ]........[  ]............[XX]....
......[XX]....[XX]....[  ][XX]........[XX]....[  ]........[XX]........[XX]......
....[XX]....[  ]........[XX]........[  ]....[  ]........[  ]............[XX]....
......[XX]....[XX]........[XX]........[XX][XX][XX][XX][XX][XX]........[XX]......
....[XX]....[  ]........[  ]........[  ]....[  ][  ][  ][  ]............[XX]....
......[XX]....[XX]........[XX]........[  ]....[  ]....[  ]............[XX]......
....[XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX]....

Python, 18992
This is the most simplistic solution and the worst score possible. It's only for reference; the thing to beat.
It fills every empty space except the two top corners with bricks, guaranteeing stability.
s = '''
....[__]....[__]....
..[__]....[__]......
[__]............[__]
'''

def brickify(structure):
    structure = filter(lambda x: x, s.replace('__', 'XX').split('\n'))
    if not structure:
        return '', 0
    if len(structure) > 1 and len(structure) % 2:
        structure[0] = '----' + structure[0][4:-4] + '----'
    added = 0
    offset = False
    for i in range(len(structure)-1,-1,-1):
        line = structure[i]
        if offset:
            line = line[2:-2]
        added += line.count('....')
        line = line.replace('....', '[__]')
        if offset:
            line = '..' + line + '..'
        structure[i] = line
        offset = not offset
    structure[0] = structure[0].replace('----', '....')
    return structure, added

s, a = brickify(s)

#print '\nNew bricks:', a

for line in s:
    print line

To use copy the initial structure into the triple quotes at the top of the program.
Here it is run on the house, adding 609 bricks:
..[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]..
[__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__]
..[__][__][__][__][__][__][__][__][__][XX][__][__][__][__][__][__][__][__][__]..
[__][__][__][__][__][__][__][__][__][XX][XX][__][__][__][__][__][__][__][__][__]
..[__][__][__][__][__][__][__][__][XX][__][XX][__][__][__][__][__][__][__][__]..
[__][__][__][__][__][__][__][__][XX][__][__][XX][__][__][__][__][__][__][__][__]
..[__][__][__][__][__][__][__][XX][__][__][__][XX][__][__][__][__][__][__][__]..
[__][__][__][__][__][__][__][XX][__][__][__][__][XX][__][__][__][__][__][__][__]
..[__][__][__][__][__][__][XX][__][__][__][__][__][XX][__][__][__][__][__][__]..
[__][__][__][__][__][__][XX][__][__][__][__][__][__][XX][__][__][__][__][__][__]
..[__][__][__][__][__][XX][__][__][__][__][__][__][__][XX][__][__][__][__][__]..
[__][__][__][__][__][XX][__][__][__][__][__][__][__][__][XX][__][__][__][__][__]
..[__][__][__][__][XX][__][__][__][__][__][__][__][__][__][XX][__][__][__][__]..
[__][__][__][__][XX][__][__][__][__][__][__][__][__][__][__][XX][__][__][__][__]
..[__][__][__][XX][__][__][__][__][__][__][__][__][__][__][__][XX][__][__][__]..
[__][__][__][XX][__][__][__][__][__][__][__][__][__][__][__][__][XX][__][__][__]
..[__][__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__][__]..
[__][__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__][__]
..[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][__]
..[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][XX][XX][XX][XX][__][__][XX][XX][XX][XX][XX][XX][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][XX][__][__][XX][__][__][XX][__][__][__][__][XX][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][XX][__][__][XX][__][__][XX][__][__][__][__][XX][__][__][XX][__]..
[__][XX][__][__][__][__][XX][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][XX][__][__][XX][__][__][XX][XX][XX][XX][XX][XX][__][__][XX][__]..
[__][XX][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][__][XX][__]
..[__][XX][__][XX][__][__][XX][__][__][__][__][__][__][__][__][__][__][XX][__]..
[__][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][__]

The number of bricks it adds for each of the 8 predefined structures in order are
374 1107 2041 9627 506 609 1088 3640 (sum to 18992)

Line 20, brick 19 is missing a left bracket.

@golfer9338 Thanks for noticing. Fixed in post and jsfiddle.

Not to make it too smart, but do you need to add any bricks to the top row?

@Sparr No you don't. But this is intended to give the worst possible score just as a demonstration.


text:
Create xkcd-Style Narrative Charts
In one of the more iconic xkcd strips, Randall Munroe visualised the timelines of several films in narrative charts:

(Click for larger version.)
Source: xkcd No. 657.
Given a specification of the timeline of a movie (or some other narrative), you are to generate such a chart. This is a popularity contest, so the answer with the most (net) votes will win.
Minimum Requirements
To tighten the spec a bit, here is the minimum set of features every answer must implement:

Take as input a list of character names, followed by a list of events. Each event is either a list of dying characters, or a list of groups of characters (signifying which characters are currently together). Here is one example for how the Jurassic Park narrative could be encoded:
["T-Rex", "Raptor", "Raptor", "Raptor", "Malcolm", "Grant", "Sattler", "Gennaro",
 "Hammond", "Kids", "Muldoon", "Arnold", "Nedry", "Dilophosaurus"]
[
  [[0],[1,2,3],[4],[5,6],[7,8,10,11,12],[9],[13]],
  [[0],[1,2,3],[4,7,5,6,8,9,10,11,12],[13]],
  [[0],[1,2,3],[4,7,5,6,8,9,10],[11,12],[13]],
  [[0],[1,2,3],[4,7,5,6,9],[8,10,11,12],[13]],
  [[0,4,7],[1,2,3],[5,9],[6,8,10,11],[12],[13]],
  [7],
  [[5,9],[0],[4,6,10],[1,2,3],[8,11],[12,13]],
  [12],
  [[0, 5, 9], [1, 2, 3], [4, 6, 10, 8, 11], [13]],
  [[0], [5, 9], [1, 2], [3, 11], [4, 6, 10, 8], [13]],
  [11],
  [[0], [5, 9], [1, 2, 10], [3, 6], [4, 8], [13]],
  [10],
  [[0], [1, 2, 9], [5, 6], [3], [4, 8], [13]],
  [[0], [1], [9, 5, 6], [3], [4, 8], [2], [13]],
  [[0, 1, 9, 5, 6, 3], [4, 8], [2], [13]],
  [1, 3],
  [[0], [9, 5, 6, 3, 4, 8], [2], [13]]
]

E.g. the first line means that at the beginning of the chart, T-Rex is a lone, the three Raptors are together, Malcolm is alone, Grant and Sattler are together, etc. The second to last event means that two of the Raptors die.
How exactly you expect the input is up to you, as long as this kind of information can be specified. E.g. you may use any convenient list format. You can also expect the characters in the events to be the full character names again etc.
You may (but don't have to) assume that each list of groups contains each living character in exactly one group. However, you should not assume that the groups or characters within one event are in particularly convenient order.
Render to screen or file (as a vector or raster graphic) a chart which has one line for each character. Each line must be labelled with a character name at the beginning of the line.
For each normal event, there must be, in order, some cross-section of the chart in which the groups of characters are clearly resembled by proximity of their respective lines.
For each death event, the lines of the relevant characters must terminate in a visible blob.
You do not have to reproduce any other features of Randall's plots, nor do you have to reproduce his drawing style. Straight lines with sharp turns, all in black, without further labels and a title is perfectly fine to enter the competition. There's also no need to use the space efficiently - e.g. you could potentially simplify you algorithm by only ever moving lines downwards to meet up with other characters, as long as there is a discernible direction of time.

I've added a reference solution which fulfils exactly these minimum requirements.
Making it Pretty
This is a popularity contest though, so on top of that, you may implement whatever fanciness you want. The most important addition is a decent layouting algorithm which makes the chart more legible - e.g. which makes bends in the lines easy to follow and which reduces the number of necessary line crossings. This is the core algorithmic problem of this challenge! The votes will decide how well your algorithm performs at keeping the chart tidy.
But here are some more ideas, most of them based on Randall's charts:
Decorations:

Coloured lines.
A title for the plot.
Labelling line ends.
Automatically relabelling lines which have gone through a busy section.
Hand-drawn style (or other? as I said, there's no need to reproduce Randall's style if you have a better idea) for lines and fonts.
Customisable orientation of the time axis.

Additional Expressiveness:

Named events/groups/deaths.
Disappearing and reappearing lines.
Characters entering late.
Highlights which indicate (transferable?) properties of characters (e.g., see the ringbearer in the LotR chart).
Encoding additional information in the grouping axis (e.g. geographic information like in the LotR chart).
Time travel?
Alternative realities?
A character turning into another?
Two characters merging? (A character splitting?)
3D? (If you really go that far, please make sure that you're actually using the additional dimension to visualise someting!)
Any other relevant features, which could be useful to visualise the narrative of a film (or book etc.).

Of course, many of these will require additional input, and you're free to augment your input format as necessary, but please document how data can be entered.
Please include one or two examples to show off the features you implemented.
Your solution should be able to deal with any valid input, but it's absolutely fine if it's better suited to certain kinds of narratives than others.
Voting Criteria
I have no illusions that I could tell people how they should spend their votes, but here are some suggested guidelines in order of importance:

Downvote answers which exploit loopholes, standard ones or others, or hardcode one or more results.
Do not upvote answers which don't fulfil the minimum requirements (no matter how fancy the rest might be).
First and foremost, upvote nice layouting algorithms. This includes answers which don't use a lot of vertical space while minimising crossing of lines to keep the graph legible, or which manage to encode additional information into the vertical axis. Visualising the groupings without making a huge mess should be the main focus of this challenge, such that this remains a programming contest with an interesting algorithmic problem at heart.
Upvote optional features which add expressive power (i.e. are not just pure decoration).
Lastly, upvote nice presentation.

because code-golf doesn't have enough xkcd

@proudhaskeller PPCG can never have enough xkcd. ;) But I don't think we've tried to make challenges of his supersized info graphics/visualisations yet, so I hope I'm bringing something new to the table with this. And I'm sure some of the others would make very different and interesting challenges as well.

Is it OK if my solution only handles 12 angry men, Duel (Spielberg, 1971, regular motorist vs crazed trucker), and Planes, Trains and Automobiles ? ;-)

@steveverrill Let the votes decide. :P But seriously, no your solution should be able to deal with any input, but I'd say it's fine if it performs better on some kinds of narratives than others, as long as that isn't due to you hardcoding three movies and using the reference implementation for any other input. ;)

i wonder how the input for primer would look like...

Does the example input (and the example answer) allow for a difference between all characters being together at once and all characters dying at once? Sorry, I don't know mathematica and amn't enough of a pure computer scientist to appreciate whether there's a difference between [x,y,z] and [[x,y,z]] and wasn't sure whether the only defining feature of the death event is that it contains only one set of characters.

@ping Yes, that was the idea. If an event contains further lists, it's a list groupings. so [[x,y,z]] would mean that all characters are currently together. But if the event doesn't contain lists, but only characters directly, it's a death even, so in the same situation [x,y,z] means that those three characters die. Feel free to use another format, with an explicit indication of whether something is a death or grouping event if that helps you. The above format is only a suggestion. As long as your input format is at least as expressive, you can use something else.

Related research.

Python3 with numpy, scipy and matplotlib

edit:

I tried to keep the groups in the same relative position between events, hence the sorted_event function.
New function to calculate the y position of the characters (coords).
Every alive event is plotted two times now, so the characters stick together better.
Added legend and removed axes label.

import math
import numpy as np
from scipy.interpolate import interp1d
from matplotlib import cm, pyplot as plt

def sorted_event(prev, event):
    """ Returns a new sorted event, where the order of the groups is
    similar to the order in the previous event. """
    similarity = lambda a, b: len(set(a) & set(b)) - len(set(a) ^ set(b))
    most_similar = lambda g: max(prev, key=lambda pg: similarity(g, pg))
    return sorted(event, key=lambda g: prev.index(most_similar(g)))

def parse_data(chars, events):
    """ Turns the input data into 3 "tables":
    - characters: {character_id: character_name}
    - timelines: {character_id: [y0, y1, y2, ...],
    - deaths: {character_id: (x, y)}
    where x and y are the coordinates of a point in the xkcd like plot.
    """
    characters = dict(enumerate(chars))
    deaths = {}
    timelines = {char: [] for char in characters}

    def coords(character, event):
        for gi, group in enumerate(event):
            if character in group:
                ci = group.index(character)
                return (gi + 0.5 * ci / len(group)) / len(event)
        return None

    t = 0
    previous = events[0]
    for event in events:
        if isinstance(event[0], list):
            previous = event = sorted_event(previous, event)
            for character in [c for c in characters if c not in deaths]:
                timelines[character] += [coords(character, event)] * 2
            t += 2
        else:
            for char in set(event) - set(deaths):
                deaths[char] = (t-1, timelines[char][-1])

    return characters, timelines, deaths

def plot_data(chars, timelines, deaths):
    """ Draws a nice xkcd like movie timeline """

    plt.xkcd()  # because python :)

    fig = plt.figure(figsize=(16,8))
    ax = fig.add_subplot(111)
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
    ax.set_xlim([0, max(map(len, timelines.values()))])

    color_floats = np.linspace(0, 1, len(chars))
    color_of = lambda char_id: cm.Accent(color_floats[char_id])

    for char_id in sorted(chars):
        y = timelines[char_id]
        f = interp1d(np.linspace(0, len(y)-1, len(y)), y, kind=5)
        x = np.linspace(0, len(y)-1, len(y)*10)
        ax.plot(x, f(x), c=color_of(char_id))

    x, y = zip(*(deaths[char_id] for char_id in sorted(deaths)))
    ax.scatter(x, y, c=np.array(list(map(color_of, sorted(deaths)))),
               zorder=99, s=40)

    ax.legend(list(map(chars.get, sorted(chars))), loc='best', ncol=4)
    fig.savefig('testplot.png')

if __name__ == '__main__':
    chars = [
        "T-Rex","Raptor","Raptor","Raptor","Malcolm","Grant","Sattler",
        "Gennaro","Hammond","Kids","Muldoon","Arnold","Nedry","Dilophosaurus"
    ]
    events = [
        [[0],[1,2,3],[4],[5,6],[7,8,10,11,12],[9],[13]],
        [[0],[1,2,3],[4,7,5,6,8,9,10,11,12],[13]],
        [[0],[1,2,3],[4,7,5,6,8,9,10],[11,12],[13]],
        [[0],[1,2,3],[4,7,5,6,9],[8,10,11,12],[13]],
        [[0,4,7],[1,2,3],[5,9],[6,8,10,11],[12],[13]],
        [7],
        [[5,9],[0],[4,6,10],[1,2,3],[8,11],[12,13]],
        [12],
        [[0,5,9],[1,2,3],[4,6,10,8,11],[13]],
        [[0],[5,9],[1,2],[3,11],[4,6,10,8],[13]],
        [11],
        [[0],[5,9],[1,2,10],[3,6],[4,8],[13]],
        [10],
        [[0],[1,2,9],[5,6],[3],[4,8],[13]],
        [[0],[1],[9,5,6],[3],[4,8],[2],[13]],
        [[0,1,9,5,6,3],[4,8],[2],[13]],
        [1,3],
        [[0],[9,5,6,3,4,8],[2],[13]]
    ]
    plot_data(*parse_data(chars, events))

Hah, very nice xkcd look :)... any chance you'll be able to label the lines?

Label the lines, have different width of lines (with decreasing/increasing between some points) and finally ... make the lines more horizontal when near to a vertex while interpolating, more like a bezier curve and this would be the best entry IMO :)

Thanks, but xkcd style is included in matplotlib, so it was only a function call:) Well, I created a legend, but it occupied almost a third of the image, so I commented it out.

I modified my answer, I think it looks better now.

T-SQL
I'm not happy with this as an entry, but I think this question deserves at least a try at it.  I will try to improve this later time permitting, but labeling will always be a problem in SQL.  The solution requires SQL 2012+ and is run in SSMS (SQL Server Management Studio).  The output is in the spatial results tab.
-- Variables for the input
DECLARE @actors NVARCHAR(MAX) = '["T-Rex", "Raptor", "Raptor", "Raptor", "Malcolm", "Grant", "Sattler", "Gennaro", "Hammond", "Kids", "Muldoon", "Arnold", "Nedry", "Dilophosaurus"]';
DECLARE @timeline NVARCHAR(MAX) = '
[
   [[1], [2, 3, 4], [5], [6, 7], [8, 9, 11, 12, 13], [10], [14]],
   [[1], [2, 3, 4], [5, 8, 6, 7, 9, 10, 11, 12, 13], [14]],
   [[1], [2, 3, 4], [5, 8, 6, 7, 9, 10, 11], [12, 13], [14]],
   [[1], [2, 3, 4], [5, 8, 6, 7, 10], [9, 11, 12, 13], [14]],
   [[1, 5, 8], [2, 3, 4], [6, 10], [7, 9, 11, 12], [13], [14]],
   [8],
   [[6, 10], [1], [5, 7, 11], [2, 3, 4], [9, 12], [13, 14]],
   [13],
   [[1, 6, 10], [2, 3, 4], [5, 7, 11, 9, 12], [14]],
   [[1], [6, 10], [2, 3], [4, 12], [5, 7, 11, 9], [14]],
   [12],
   [[1], [6, 10], [2, 3, 11], [4, 7], [5, 9], [14]],
   [11],
   [[1], [2, 3, 10], [6, 7], [4], [5, 9], [14]],
   [[1], [2], [10, 6, 7], [4], [5, 9], [3], [14]],
   [[1, 2, 10, 6, 7, 4], [5, 9], [3], [14]],
   [2, 4],
   [[1], [10, 6, 7, 5, 9], [3], [14]]
]
';

-- Populate Actor table
WITH actor(A) AS ( SELECT CAST(REPLACE(STUFF(REPLACE(REPLACE(@actors,', ',','),'","',''),1,2,''),'"]','') AS XML))
SELECT ROW_NUMBER() OVER (ORDER BY(SELECT \)) ActorID, a.n.value('.','varchar(50)') Name
INTO Actor
FROM actor CROSS APPLY A.nodes('/a') as a(n);

-- Populate Timeline Table
WITH Seq(L) AS (
    SELECT CAST(REPLACE(REPLACE(REPLACE(REPLACE(@timeline,'[','<e>'),']','</e>'),'</e>,<e>','</e><e>'),'</e>,','</e>') AS XML)
    ),
    TimeLine(N,Exerpt,Elem) AS (
    SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N
        ,z.query('.')
        ,CAST(REPLACE(CAST(z.query('.') AS VARCHAR(MAX)),',','</e><e>') AS XML)
    FROM Seq
        CROSS APPLY Seq.L.nodes('/e/e') AS Z(Z)
    ),
    Groups(N,G,Exerpt) AS (
    SELECT N,
        ROW_NUMBER() OVER (PARTITION BY N ORDER BY CAST(SUBSTRING(node.value('.','varchar(50)'),1,ISNULL(NULLIF(CHARINDEX(',',node.value('.','varchar(50)')),0),99)-1) AS INT)),
        CAST(REPLACE(CAST(node.query('.') AS VARCHAR(MAX)),',','</e><e>') AS XML) C
    FROM TimeLine
        CROSS APPLY Exerpt.nodes('/e/e') as Z(node)
    WHERE Exerpt.exist('/e/e') = 1
    )
SELECT *
INTO TimeLine
FROM (
    SELECT N, null G, null P, node.value('.','int') ActorID, 1 D
    FROM TimeLine CROSS APPLY TimeLine.Elem.nodes('/e') AS E(node)
    WHERE Exerpt.exist('/e/e') = 0
    UNION ALL
    SELECT N, G, DENSE_RANK() OVER (PARTITION BY N, G ORDER BY node.value('.','int')), node.value('.','int') ActorID, 0
    FROM Groups CROSS APPLY Groups.Exerpt.nodes('/e') AS D(node)
    ) z;

-- Sort the entries again
WITH ReOrder AS (
            SELECT *,
                ROW_NUMBER() OVER (PARTITION BY N,G ORDER BY PG, ActorID) PP,
                COUNT(P) OVER (PARTITION BY N,G) CP,
                MAX(G) OVER (PARTITION BY N) MG,
                MAX(ActorID) OVER (ORDER BY (SELECT\)) MA
            FROM (
                SELECT *,
                    LAG(G,1) OVER (PARTITION BY ActorID ORDER BY N) PG,
                    LEAD(G,1) OVER (PARTITION BY ActorID ORDER BY N) NG
                FROM timeline
                ) rg
    )
SELECT * INTO Reordered
FROM ReOrder;
ALTER TABLE Reordered ADD PPP INT
GO
ALTER TABLE Reordered ADD LPP INT
GO
WITH U AS (SELECT N, P, LPP, LAG(PP,1) OVER (PARTITION BY ActorID ORDER BY N) X FROM Reordered)
UPDATE U SET LPP = X FROM U;
WITH U AS (SELECT N, ActorID, P, PG, LPP, PPP, DENSE_RANK() OVER (PARTITION BY N,G ORDER BY PG, LPP) X FROM Reordered)
UPDATE U SET PPP = X FROM U;
GO

SELECT Name,
    Geometry::STGeomFromText(
        STUFF(LS,1,2,'LINESTRING (') + ')'
        ,0)
        .STBuffer(.1)
        .STUnion(
        Geometry::STGeomFromText('POINT (' + REVERSE(SUBSTRING(REVERSE(LS),1,CHARINDEX(',',REVERSE(LS))-1)) + ')',0).STBuffer(D*.4)
        )
FROM Actor a
    CROSS APPLY (
        SELECT CONCAT(', '
            ,((N*5)-1.2)
                ,' ',(G)+P
            ,', '
            ,((N*5)+1.2)
                ,' ',(G)+P
            ) AS [text()]
        FROM (
            SELECT ActorID, N,
                CASE WHEN d = 1 THEN
                    ((MA+.0) / (LAG(MG,1) OVER (PARTITION BY ActorID ORDER BY N)+.0)) *
                    PG * 1.2
                ELSE
                    ((MA+.0) / (MG+.0)) *
                    G * 1.2
                END G,
                CASE WHEN d = 1 THEN
                (LAG(PPP,1) OVER (PARTITION BY ActorID ORDER BY N) -((LAG(CP,1) OVER (PARTITION BY ActorID ORDER BY N)-1)/2)) * .2
                ELSE
                (PPP-((CP-1)/2)) * .2
                END P
                ,PG
                ,NG
            FROM Reordered
            ) t
        WHERE a.actorid = t.actorid
        ORDER BY N, G
        FOR XML PATH('')
        ) x(LS)
    CROSS APPLY (SELECT MAX(D) d FROM TimeLine dt WHERE dt.ActorID = a.ActorID) d
GO

DROP TABLE Actor;
DROP TABLE Timeline;
DROP TABLE Reordered;

The resulting timeline looks like the following

Mathematica, Reference Solution
For reference, I provide a Mathematica script which fulfils exactly the minimum requirements, nothing more, nothing less.
It expects the characters to be a list of the format in the question in chars, and the events in events.
n = Length@chars;
m = Max@Map[Length, events, {2}];
deaths = {};
Graphics[
 {
  PointSize@Large,
  (
     linePoints = If[Length@# == 3,
         lastPoint = {#[[1]], #[[2]] + #[[3]]/(m + 2)},
         AppendTo[deaths, Point@lastPoint]; lastPoint
         ] & /@ Position[events, #];
     {
      Line@linePoints,
      Text[chars[[#]], linePoints[[1]] - {.5, 0}]
      }
     ) & /@ Range@n,
  deaths
  }
 ]

As an example, here is the Jurassic Park example using Mathematica's list type:
chars = {"T-Rex", "Raptor", "Raptor", "Raptor", "Malcolm", "Grant",
   "Sattler", "Gennaro", "Hammond", "Kids", "Muldoon", "Arnold",
   "Nedry", "Dilophosaurus"};
events = {
   {{1}, {2, 3, 4}, {5}, {6, 7}, {8, 9, 11, 12, 13}, {10}, {14}},
   {{1}, {2, 3, 4}, {5, 8, 6, 7, 9, 10, 11, 12, 13}, {14}},
   {{1}, {2, 3, 4}, {5, 8, 6, 7, 9, 10, 11}, {12, 13}, {14}},
   {{1}, {2, 3, 4}, {5, 8, 6, 7, 10}, {9, 11, 12, 13}, {14}},
   {{1, 5, 8}, {2, 3, 4}, {6, 10}, {7, 9, 11, 12}, {13}, {14}},
   {8},
   {{6, 10}, {1}, {5, 7, 11}, {2, 3, 4}, {9, 12}, {13, 14}},
   {13},
   {{1, 6, 10}, {2, 3, 4}, {5, 7, 11, 9, 12}, {14}},
   {{1}, {6, 10}, {2, 3}, {4, 12}, {5, 7, 11, 9}, {14}},
   {12},
   {{1}, {6, 10}, {2, 3, 11}, {4, 7}, {5, 9}, {14}},
   {11},
   {{1}, {2, 3, 10}, {6, 7}, {4}, {5, 9}, {14}},
   {{1}, {2}, {10, 6, 7}, {4}, {5, 9}, {3}, {14}},
   {{1, 2, 10, 6, 7, 4}, {5, 9}, {3}, {14}},
   {2, 4},
   {{1}, {10, 6, 7, 4, 5, 9}, {3}, {14}}
};

we'll get:

(Click for larger version.)
That doesn't look too bad, but that's mostly because the input data is more or less ordered. If we shuffle the groups and characters in each event (while maintaining the same structure), stuff like this can happen:

Which is a bit of a mess.
So as I said, this fulfils only the minimum requirements. It doesn't try to find a nice layout and it isn't pretty, but that's where you guys come in!

I just thought you can perhaps 'prettify' it by using quadratic or cubic splines in order to remove the sharp corners? (I'd do it that way that the tangent at the given points is always 0)

@flawr Sure, or I could apply some of these trick, but that wasn't the purpose of this answer. ;) I really just wanted to provide a reference for the absolute minimum.

Oh sorry, didn't even notice that this was your own question=P