text:
A Mnemonic for Remembering 23940
The major system is a mnemonic device for converting numbers into words so they can be memorized more easily.
It is based on how words sound phonetically, but to keep things simple for the challenge we'll only be concerned with how words are spelled. This means there will be some incorrect conversions, but that's alright.

To convert a number into a word using our simplified major system:

Replace each 0 with s or z. (Some could be s and some could be z. Same goes below.)
Replace each 1 with t or d or th.
Replace each 2 with n.
Replace each 3 with m.
Replace each 4 with r.
Replace each 5 with l.
Replace each 6 with j or sh or ch.
Replace each 7 with k or c or g or q.
Replace each 8 with f or v.
Replace each 9 with p or b.
Add the letters aehiouwxy anywhere in any amounts to make a real English word, if possible.
The only exception is that h may not be inserted after an s or c.

The number may actually be any string of the digits 0-9 (no decimals or commas or signs).
The word can only contain the lowercase letters a-z.

Examples
The number 32 must be converted as ?m?n?, where ? represents any finite string made from the letters aehiouwxy (a string from the free monoid if you prefer). There are many ways this could be made into a real English word: mane, moon, yeoman, etc.
The number 05 could be converted as ?s?l? or ?z?l?. Some possibilities are easily, hassle, and hazel. The word shawl is not allowed because h may not be placed after s; it would be incorrectly read as 65.
Challenge
Write a program or function that takes in a string of the digits 0-9 and finds all the words that it could be converted into using the simplified major system mnemonic.
Your program has access to a word list text file that defines what all the "real" English words are. There is one lowercase a-z word on each line of this file, and you may optionally assume it has a trailing newline. Here is a list of real words you can use for testing. You can assume this word list file is called f (or something longer) and lies in any convenient directory.
For a 35 byte penalty (add 35 to your score) you may assume the word list is already loaded into a variable as a list of strings. This is mainly for languages that can't read files, but any submission may take advantage of it.
Your program must output all the words in the word list that the input number can be converted to. They should be printed to stdout (or similar), one per line (with an optional trailing newline), or they can be returned as a list of strings if you chose to write a function. The word list is not necessarily alphabetized and the output doesn't need to be either.
If there are no possible words then the output (or the list) will be empty. The output is also empty if the empty string is input.
Take input via stdin, command line, or as a string argument to a function. The word list, or its file name, should not be part of the input, only the digit string.
You are only matching single words in the word list, not sequences of words. The word noon would probably be one of the results for 22, but the word sequence no one wouldn't.
Test Cases
Suppose this is the word list:
stnmrljkfp
zthnmrlshqfb
asatanamaralajakafapa
aizxydwwwnhimouooraleshhhcavabe
zdnmrlshcvb
zdnmrlshchvb
sthnmrlchgvb
shthnmrlchgvb
bob
pop
bop
bopy
boppy

The input 0123456789 should give all the long words except zdnmrlshchvb and shthnmrlchgvb:
stnmrljkfp
zthnmrlshqfb
asatanamaralajakafapa
aizxydwwwnhimouooraleshhhcavabe
zdnmrlshcvb
sthnmrlchgvb

The input 99 should give:
bob
pop
bop
bopy

(The output words may be in any order.)
Scoring
The shortest submission in bytes wins. Tiebreaker goes to the submission posted first.
Nifty related site: numzi.com.

Did you happen to get the idea for this challenge from this video? Because I actually just watched that yesterday. :P

@Doorknob Not that video, but that guy. Years ago I was given one of his Great Courses lectures. He's kinda zany but does really neat stuff. :)

Note for those interested in using the mnemonic major system in real life: it is only the sound that matters, not the spelling. So "c", while listed here as meaning 7, could actually mean 0 if in the word it is pronounced with an "s" sound (as in "ace" = 0). However, I'm sure that the OP simplified the challenge, as a dictionary with full phonetics is much harder to come by than a simple word list. Oh, and one rendering of 23940 is "numbers".

@ErikE I state that we're using a spelling based version in the second sentence of the post...

I see that now, though I did miss it at first--but it still seems to me that your explanation could be fleshed out just a little bit more and an example or two provided.

I get a 404 instead of the wordlist when I click the link.

Perl, 87 84
open A,f;"@ARGV"eq s/[cs]h/j/gr=~y/stnmrljkfpzdcgqvb\0-z/0-90177789/dr&&print for<A>

Takes input in as the command line parameter:
$perl m.pl 23940

Can be made somewhat shorter if the word list would be allowed on the standard input:
$perl -lnE'INIT{$;=pop}$;eq s/[cs]h/j/gr=~y/stnmrljkfpzdcgqvba-z/0-90177789/dr&&say' 99 <f

What does A mean in open A,f?

@feersum A file handle used later to read the file (<A>).

Python 2, 215 208 bytes
This Python solution builds a regex from parts indexed by the command line argument, then tests each word with that (rather large) regex.
import re,sys
a='[sz] (d|th?) n m r l (j|sh|ch) [kcgq] [fv] [pb]'.split()
b=z='((?<![sc])h|[aeiouwxy])*'
for i in sys.argv[1]:b+=a[int(i)]+z
for d in open('f'):
 d=d.strip()
 if re.match('^'+b+'$',d):print d

Original source before the minifier:
import re,sys
regexbits = '[sz] (d|th?) n m r l (j|sh|ch) [kcgq] [fv] [pb]'.split()

regex = other = '((?<![sc])h|[aeiouwxy])*'
for i in sys.argv[1] :
    regex += regexbits[int(i)] + other
print regex     # DEBUG

for word in open('f'):
    word = word.strip()
    if re.match('^'+regex+'$', word) :
        print word

For example, the regex for the test 99 is:
^((?<![sc])h|[aeiouwxy])*[pb]((?<![sc])h|[aeiouwxy])*[pb]((?<![sc])h|[aeiouwxy])*$

The (?<![sc])h bit is a "look behind negative assertion" component that makes sure a h does not follow a s or c in the general filler parts.
Thanks Calvin. This challenge motivated me to brush up on my rusty regex skills.

b=c='((?<![sc])h|[aeiouwxy])*' will save two bytes.

t|th -> th? saves a byte

You can avoid the map by taking int(i) directly.

Thanks matsjoyce, Sp3000, and xnor for useful golfing tips. Now edited with suggestions implemented.

Python 3, 170
import sys,re
t=str.maketrans('sztdnmrljkcgqfvpb','00112345677778899','aehiouwxy\n')
for s in open('f'):re.sub('sh|ch','j',s).translate(t)!=sys.argv[1] or print(s,end='')

Readable version:
import sys, re

table = str.maketrans('sztdnmrljkcgqfvpb', '00112345677778899', 'aehiouwxy\n')

for line in open('f'):
    line = re.sub('sh|ch', 'j', line)
    if line.translate(table) == sys.argv[1]:
        print(line, end='')

The code makes use of the fact that th is redundant (since it maps to the same number as t, and h is a padding character).
The static maketrans function creates a table mapping the characters of the first argument to those of the second argument, and the characters of the third argument to None (which will result in those characters being deleted).
The final code could be made a few bytes shorter by creating the table as a direct argument of translate.

You could save a couple of bytes using input() instead of sys.argv[1] and '[sc]h' for your regular expression.

@swstephe. Thanks for the feedback, but I don't think input() can be used, because it is called inside a loop. Also, your suggested regex is the same length as the one I'm already using (5 bytes).

I was thinking something like "z,t=input(),str.maketrans...", then just use z instead of sys.argv.  Okay, I thought my regex was 4-bytes.

sed,paste,grep,cut - 109
sed -e 's/[sc]h/6/g;s/[aehiouwxy]//g;y/sztdnmrljkcqgfvpb/00112345677778899/' w|paste w -|grep " $1$"|cut -f1

Takes a file "w", converts each word to its number, paste back to the original, grep for the number and return the word matched.  Note that the whitespace after the quote after grep is a tab, paste's default delimiter.
I know Perl is way ahead, just wanted a better shell version as an example.
Oh yeah, the $1 part means that this is supposed to be run from a shell script, (most shells should work), so it takes a command-line argument.

I was thinking about converting my answer to pure sed to avoid Perl's open and @ARGV overhead, but the lack of ranges and delete functions in y/// breaks it. Surprisingly though even though there are no variables you can express the logic itself directly in sed. Here is my 92 solution: sed -e'h;s/[sc]h/6/g;y/sztdnmrljkcqgfvpb/00112345677778899/;s/[^0-9]*//g;T;s/^$1$//;x;t;d' f

It seems to work, why not make it an answer?

Bash + coreutils, 216
sed -n "$(sed 's/[aeiouwxy]//g
:l
s/\([^sc]\)h/\1/g
tl'<w|grep -nf <(eval printf '%s\\n' `sed 's/0/{s,z}/g
s/1/{t,th,d}/g
y/2345/nmrl/
s/6/{j,sh,ch}/g
s/7/{k,c,g,q}/g
s/8/{f,v}/g
s/9/{p,b}/g'<<<$1`)|sed s/:.\*/p/)" w

The word list in a file called w
The innermost sed replaces digits with their possible replacements
The eval printf uses shell brace expansions to expand out all the possible substitutions
The second sed on the 1st line removes aeiouwxy and h (when not preceded by [sc]) from the word list
The grep prints out all matches, with line numbers
Since we have stripped out aeiouwxy and h from the word list, the last sed turns the results of grep (line numbers of each match) to another sed expression, which is processed by the outermost sed to reveal all possible words from the wordlist.

Output:
The word list file is specified as a command-line arg, followed by the number to mnemonicize:
ubuntu@ubuntu:~$ ./numzi.sh 99
bob
pop
bop
bopy
boppy
$ ./numzi.sh 0123456789
stnmrljkfp
zthnmrlshqfb
asatanamaralajakafapa
aizxydwwwnhimouooraleshhhcavabe
zdnmrlshcvb
sthnmrlchgvb
$

@Calvin'sHobbies Done.

Looks like you forgot to update your example.

tr, sed, grep, xargs, sh, 77
tr 0123456789 ztnmrljkfp|sed 's/ */[aehiouwxy]*/g'|xargs sh -c 'grep -x $0 f'

Expects the number in stdin and the word list should be stored in the file f.
Does not uses all replacements (1 will always be z, 7 will always be k), so it may be called a lazy solution, but it finds at least one mnemonic for 95 numbers in [1-100].

The question asks that you find all matching words in the word list. You can't make 1 always be z or 7 always k. This in invalid.

Fair enough, I'll remove my answer.


text:
Random Golf of the Day #3: Integer Partitions
About the Series
First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You can find the leaderboard along with some more information about the series in the first post.
Although I have a bunch of ideas lined up for the series, the future challenges are not set in stone yet. If you have any suggestions, please let me know on the relevant sandbox post.
Hole 3: Integer Partitions
Time to increase the difficulty a bit.
A partition of a positive integer n is defined as a multiset of positive integers which sum to n. As an example if n = 5, the following partitions exist:
{1,1,1,1,1}
{2,1,1,1}
{2,2,1}
{3,1,1}
{3,2}
{4,1}
{5}

Note that these are multisets, so there is no order to them, {3,1,1}, {1,3,1} and {1,1,3} are all considered identical.
Your task is, given n, to generate a random partition of n. Here are the detailed rules:

The distribution of partitions produced must be uniform. That is, in the above example, each partition should be returned with probability 1/7.
Of course, due to the technical limitations of PRNGs, perfect uniformity will be impossible. For the purpose of assessing uniformity of your submission, the following operations will be regarded as yielding perfectly uniform distributions:

Obtaining a number from a PRNG (over any range), which is documented to be (approximately) uniform.
Mapping a uniform distribution over a larger set of numbers onto a smaller set via modulo or multiplication (or some other operation which distributes values evenly). The larger set has to contain at least 1024 times as many possible values as the smaller set.

Since the partitions are multisets you may return them in any order, and this order does not have to be consistent. However, for the purpose of the random distribution, the order is ignored. That is, in the above example, {3,1,1}, {1,3,1} and {1,1,3} together must have a probability of 1/7 of being returned.
Your algorithm must have a deterministic runtime. In particular, you cannot generate random multisets and reject them if they don't sum to n.
Your algorithm's time complexity must be polynomial in n. In particular, you cannot simply generate all partitions and select a random one (since the number of partitions grows exponentially with n). You may assume that the PRNG you're using can return uniformly distributed values in O(1) per value.
You must not use any built-in function which solves this task.

You may write a full program or a function and take input via STDIN or closest alternative, command-line argument or function argument and produce output via return value or by printing to STDOUT (or closest alternative).
You may assume that n ≤ 65 (such that the number of partitions is less than 221). Output may be in any convenient, unambiguous list or string format.
If you submit a function, please consider also providing a little test program which calls the function a number of times and prints the results. It's okay if the parameters have to be tweaked in the code. This is just so people can check that the solution is at least approximately uniform.
This is code golf, so the shortest submission (in bytes) wins. And of course, the shortest submission per user will also enter into the overall leaderboard of the series.
Leaderboard
The first post of the series generates a leaderboard.
To make sure that your answers show up, please start every answer with a headline, using the following Markdown template:
# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
# Ruby, <s>104</s> <s>101</s> 96 bytes

(The language is not currently shown, but the snippet does require and parse it, and I may add a by-language leaderboard in the future.)

Python 2, 179 bytes
from random import*
m=r=input();i=q=r+1;h=[1]+[0]*q*q;exec"h[i]=h[i+~q]+h[i-i%q*q];i+=1;"*r*q
while r:
 x=random()*sum(h[r*q:r*q-~m]);m=0
 while x>0:m+=1;x-=h[r*q+m]
 print m;r-=m

I used formula (39) from this Knuth extract, which gives the number of partitions of n that have exactly m parts. This happens to equal the number of partitions of n that have m as the maximum element, which is the interpretation I'm using. The elements of the partition are generated from greatest to least. At each stage the formula is reused with the current remainder of n and maximum allowed element.

Dyalog APL, 67 59 51 bytes
p←{⍵,⊂1,⍨+/¨⌽⍵↑¨⍨⌽⍳⍴⍵}⍣⎕⊢⍬⋄f←{⍵=0:⍬⋄a,a∇⍵-a←{1++/(?+/⍵)>+\⍵}⍺↑⍵⊃p}⍨ (67 bytes)
p is a vector of vectors in which p[n][k] is the number of partitions of n into k summands, or equivalently: the number of partitions with greatest summand k.  We build p by starting with the empty vector ⍬, reading n (the ⎕ reads input) and repeatedly applying the following:
{⍵,⊂1,⍨+/¨⌽⍵↑¨⍨⌽⍳⍴⍵}
                 ⍴⍵   ⍝ the current length, initially 0
                ⍳⍴⍵   ⍝ 1 2 ... length
               ⌽⍳⍴⍵   ⍝ length ... 2 1
           ⍵↑¨⍨       ⍝ take length elements from p[1], length-1 from p[2], etc
                      ⍝ padded with 0-s, e.g. if p was (,1)(1 1)(1 1 1)(1 2 1 1)(1 2 2 1 1):
                      ⍝ we get:     (1 0 0 0 0)(1 1 0 0)(1 1 1)(1 2)(,1)
          ⌽           ⍝ reverse it: (,1)(1 2)(1 1 1)(1 1 0 0)(1 0 0 0 0)
       +/¨            ⍝ sum each:   1 3 3 2 1
    1,⍨               ⍝ append 1:   1 3 3 2 1 1
 ⍵,⊂                  ⍝ append the above to the vector of vectors

After n applications (⍣⎕), we have built p.
f picks a random partition.  n f k is a random partition of at most k summands.  f n is n f n.
{⍵=0:⍬⋄a,a∇⍵-a←{1++/(?+/⍵)>+\⍵}⍺↑⍵⊃p}⍨
                                     ⍨ ⍝ "selfie" -- use n as k if no k is provided
 ⍵=0:⍬                                 ⍝ if n=0 return empty
                                 ⍵⊃p   ⍝ pick the n-th element of p
                               ⍺↑      ⍝ take k elements from that
               {1++/(?+/⍵)>+\⍵}        ⍝ use them as weights to pick a random number 1...k
               {           +\⍵}        ⍝   partial sums of weights
               {    (?+/⍵)    }        ⍝   a random number 1...sum of weights
               {    (?+/⍵)>+\⍵}        ⍝   which partial sums is it greater than?
               {  +/          }        ⍝   count how many "greater than"-s
               {1+            }        ⍝   we're off by one
             a←                        ⍝ this will be the greatest number in our partition
         a∇⍵-a                         ⍝ recur with n1=n-a and k1=a
       a,                              ⍝ prepend a

Some improvements:

inline p at the cost of slightly worse (but still good enough) performance

in the computation of p rearrange ⌽ and 1, to save a character

turn {1++/(?+/⍵)>+\⍵} into a train with 1+ in front: 1+(+/(?+/)>+\)

make f an anonymous function and supply ⎕ (eval'ed input) as an argument to obtain a complete program

{⍵=0:⍬⋄a,a∇⍵-a←1+(+/(?+/)>+\)⍺↑⍵⊃{⍵,⊂⌽1,+/¨⍵↑¨⍨⌽⍳⍴⍵}⍣⍵⊢⍬}⍨⎕ (59 bytes)
Test with n=5
Test with n=65
And the following link runs n=5 thousands of times and gathers statistics about the frequency of each partition:
⎕rl←0 ⋄ {⍺,⍴⍵}⌸ {⍵=0:⍬⋄a,a∇⍵-a←1+(+/(?+/)>+\)⍺↑⍵⊃{⍵,⊂⌽1,+/¨⍵↑¨⍨⌽⍳⍴⍵}⍣⍵⊢⍬}⍨ ¨10000⍴5

More improvements, with help from Roger Hui:

replace {⍵=0:A⋄B} with {×⍵:B⋄A}.  Signum (×⍵) returns true for ⍵>0 and false for ⍵=0.

replace (+/(?+/)>+\) with +/b<?⊃⌽b←+\, it saves a character

use a matrix instead of vector of vectors to compute p: replace ⍵⊃{⍵,⊂⌽1,+/¨⍵↑¨⍨⌽⍳⍴⍵}⍣⍵⊢⍬ with ⊃↓(0,⍨⊢⍪⍨1 1⍉+\)⍣⍵⍪1.

{×⍵:a,a∇⍵-a←1++/b<?⊃⌽b←+\⍺↑⊃↓(0,⍨⊢⍪⍨1 1⍉+\)⍣⍵⍪1⋄⍬}⍨ (51 bytes)
test n=5; test n=65; freq stats

How does one get help from Roger Hui?

Write a toy APL interpreter to get yourself hired in the same company as him.  Pose the above expression as a challenge, promise a pint of beer for every character he takes out.  Then profit: fewer characters and more booze as he doesn't drink beer.

I see. That's a neat strategy, let's see if I can reproduce that… Can you ask him if Dyalog APL is going to get something like J's u/\. y any time soon?

For the record: https://twitter.com/FUZxxl/status/572377068555644929

Thank you for asking him. Now I wonder if it's possible in linear time, too.

GolfScript, 90 bytes
~[[[1.]]]\({..[[{{(\{)}%+}%1$,1$,-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`

Online demo
This is an adaptation of my (simpler) partition counting code which instead of merely tracking a count tracks both a count and a uniformly selected one of the counted elements.
Side-by-side comparison of the two:
~[[[1.]]]\({..[[{{(\{)}%+}%1$,1$,-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
 [[ 1  ]]\({..[[{          1$,1$,-=}%  0 @0=+     ]zip{{+}*                }:^%]\+}*0=^

Differences:

The initial ~ is because this is a program rather than a snippet.
The [1.] replacing 1 corresponds to the change in what's tracked.
The additional {(\{)}%+}% increments each element in that partition, and the {1+}% adds 1 to the partition.
0 becomes [0] (golfed to 1,) as part of the change in what's tracked, but because it needs to remain an array when prepended to another one it needs the extra [ ].
The simple sum {+}* becomes a weighted selection from the partitions, combined with a summing of their count.
The (;` removes the count from the output and puts the partition into a nice format.

Test framework
;7000,{;
  '5'

  ~[[[1.]]]\({..[[{{(\{)}%+}%1$,1$,-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`

}%
:RESULTS
.&${
  RESULTS.[2$]--,' '\n
}/

Tweak the initial 7000 if you want to run a different number of trials. Note that this is far too slow for an online demo.

Pyth, 64 bytes
Uses https://stackoverflow.com/a/2163753/4230423 except that a)No cache since Pyth automatically memoizes, b)Prints each instead of appending to list, and c) is translated to Pyth.
M?smg-Gddr1hhS,GHG1Akd,QOgQQWQFNr1hhS,QkKg-QNNI<dKB-=dK)N=kN-=QN

I'll post an explanation of this when I have the time, but here is the corresponding python code:
g=lambda G,H: sum(map(lambda d:g(G-d, d), range(1, (H if H<G else G) + 1))) if G else 1
Q=input()
k,d = Q,random.randrange(g(Q, Q))
while Q:
    for N in range(1, min(k, Q) + 1):
        K = g(Q-N, N)
        if d < K:
            break
        d -= K
    print N
    k=N
    Q -= N

Edit: I finally got around to doing the explanation:
M                Lambda g(G,H)
 ?         G     If G truthy
  s              Sum
   m             Map
    g            Recursive call
     -Gdd        G-d,d
    r            Range
     1           1 to
     h           +1
      hS         First element of sorted (does min)
       ,GH       From G and H
   1             Else 1
A                Double assign
 kd              Vars k and d
 ,               To vals
  Q              Q (evaled input)
  O              Randrange 0 till val
   gQQ           Call g(Q, Q)
WQ               While Q is truthy
 FN              For N in
  r              Range
   1             From one
   h             Till +1
    hS,QK        Min(Q,K)
  Kg             K=g(
   -QN           Q-N
   N             N
  I<dK           If d<k
   B             Break (implicit close paren)
  -=dk           Subtracts d-=k
 )               Close out for loop
 N               Prints N
 =kN             Set k=N
 -=QN            Subtracts Q-=N

Java, 285 267 bytes
int[][]p;void p(int n){p=new int[n+1][n+1];int a=n,b=k(n,a),c,d;for(b*=Math.random();n>0;System.out.print(c+" "),n-=a=c)for(c=0;c++<(a<n?a:n)&b>=(d=k(n-c,c));b-=d);}int k(int n,int k){if(p[n][k]<1)for(int a=0,b=0;b<k&b++<n;p[n][k]=a)a+=k(n-b,b);return n>0?p[n][k]:1;}

This is the same method as TheBestOne's answer, but it uses a simple array instead of a map. Also, instead of returning the random partition as a List, it prints them to the console.
Below is a test program that runs it 100000 times. For the example n=5, all sets were within 0.64% of a perfect 1/7 on my last run.
public class Partition {
    public static void main(String[] args) {
        Partition p = new Partition();
        for(int i=0;i<100000;i++){
            p.p(5);
            System.out.println();
        }
    }

    int[][]p;

    void p(int n){
        p=new int[n+1][n+1];
        int a=n,b=k(n,a),c,d;
        for(b*=Math.random();n>0;System.out.print(c+" "),n-=a=c)
            for(c=0;c++<(a<n?a:n)&b>=(d=k(n-c,c));b-=d);
    }

    int k(int n,int k){
        if(p[n][k]<1)
            for(int a=0,b=0;b<k&b++<n;p[n][k]=a)
                a+=k(n-b,b);
        return n>0?p[n][k]:1;
    }

}

Although you've golfed the Math.min call down to (k<n?k:n), you can go further by ditching it entirely and just doing two checks: b<k&b++<n. You can also easily ditch the n>0 part of the loop conditional (since n>0&b<n reduces to b<n when b is guaranteed non-negative).

@PeterTaylor Thanks. Taking another look let me get rid of the extra return statement and the separate int declaration also.

CJam, 64 56 bytes
ri_L{_0>{\,f{)_@1$-j+}{)@)2$+:Umr@<@@?U+}*}{!a\;}?}2j);p

You can test it with this script:
ria100*{_L{_0>{\,f{)_@1$-j+}{)@)2$+:Umr@<@@?U+}*}{!a\;}?}2j);}%__|\f{_,\2$a-,-}2/p

Explanation
ri_                  " Read an integer and duplicate. ";
L{                   " Create a memoized function of the maximum and the sum, which returns
                       a random partition, and the total number of partitions as the last item. ";
    _0>              " If sum > 0: ";
    {
        \,f{         " For I in 0..max-1: ";
            )_@1$-   " Stack: I+1 I+1 sum-I-1 ";
            j+       " Recursively call with the two parameters, and prepend I+1. ";
        }
        {            " Reduce on the results: ";
            )@)2$+   " Stack: partition1 total1 partition2 total1+total2 ";
            :Umr     " U = total1+total2, then generate a random number smaller than that. ";
            @<@@?    " If it is <total1, choose partition1, else choose partition2. ";
            U+       " Append the total back to the array. ";
        }*
    }
    {!a\;}?          " Else return [0] if negative, or [1] if zero. ";
}2j
);p                  " Discard the total and print. ";

You should remove the incorrect "not golfed very well" part of your answer ;)

@anatolyg Removed. But I believe it is still possible to remove some bytes. I'm just too lazy to do that.

Octave, 200
function r=c(m)r=[];a=eye(m);a(:,1)=1;for(i=3:m)for(j=2:i-1)a(i,j)=a(i-1,j-1)+a(i-j,j);end;end;p=randi(sum(a(m,:)));while(m>0)b=a(m,:);c=cumsum(b);x=min(find(c>=p));r=[r x];p=p-c(x)+b(x);m=m-x;end;end

Ungolfed:
function r=c(m)
  r=[];
  a=eye(m);
  a(:,1)=1;
  for(i=3:m)
    for(j=2:i-1)
      a(i,j)=a(i-1,j-1)+a(i-j,j);
    end;
  end;
  p=randi(sum(a(m,:)));
  while(m>0)
    b=a(m,:);
    c=cumsum(b);
    x=min(find(cumsum(b)>=p));
    r=[r x];
    p=p-c(x)+b(x);
    m=m-x;
  end
end

Construct a square matrix where each cell (m,n) reflects the number of partitions of m whose largest number is n, according to the Knuth extract @feersum so kindly cited. For example, 5,2 gives us 2 because there are two valid partitions 2,2,1 and 2,1,1,1. 6,3 gives us 3 for 3,1,1,1,3,2,1 and 3,3.
We can now deterministically find the p'th partition. Here, we are generating p as a random number but you can alter the script slightly so p is a parameter:
function r=c(m,p)
  r=[];
  a=eye(m);
  a(:,1)=1;
  for(i=3:m)
    for(j=2:i-1)
      a(i,j)=a(i-1,j-1)+a(i-j,j);
    end;
  end;
  while(m>0)
    b=a(m,1:m);
    c=cumsum(b);
    x=min(find(c>=p));
    r=[r x];
    p=p-c(x)+b(x);
    m=m-x;
  end
end

We can now deterministically show that each outcome is solely dependent on p:
octave:99> for(i=1:7)
> c(5,i)
> end
ans =

   1   1   1   1   1

ans =

   2   1   1   1

ans =

   2   2   1

ans =

   3   1   1

ans =

   3   2

ans =

   4   1

ans =  5

Thus, going back to the original where p is randomly generated, we can be assured each outcome is equally likely.

I'm not sure about your 5,2 example. Shouldn't the two partitions be (2,2,1) and (2,1,1,1,1) (since the two you've listed have numbers greater than 2).

You're right, I got things twisted up. There are two partitions with two components, and two partitions starting with 2. I meant the latter.

R, 198 bytes
function(m){r=c();a=diag(m);a[,1]=1;for(i in 3:m)for(j in 2:(i-1))a[i,j]=a[i-1,j-1]+a[i-j,j];p=sample(sum(a[m,]),1);while(m>0){b=a[m,];c=cumsum(b);x=min(which(c>=p));r=c(r,x);p=p-c[x]+b[x];m=m-x};r}

Ungolfed:
f <- function(m) {
    r <- c()
    a <- diag(m)
    a[, 1] <- 1
    for (i in 3:m)
        for (j in 2:(i-1))
            a[i, j] <- a[i-1, j-1] + a[i-j, j]
    p <- sample(sum(a[m, ]), 1)
    while (m > 0) {
        b <- a[m, ]
        c <- cumsum(b)
        x <- min(which(c >= p))
        r <- c(r, x)
        p <- p - c[x] + b[x]
        m <- m - x
    }
    return(r)
}

It follows the same structure as @dcsohl's great solution in Octave, and is thus also based on the Knuth extract posted by @feersum.
I'll edit this later if I can come up with a more creative solution in R. In the meantime, any input is of course welcome.

Java, 392 bytes
import java.util.*;Map a=new HashMap();List a(int b){List c=new ArrayList();int d=b,e=b(b,d),f=(int)(Math.random()*e),g,i;while(b>0){for(g=0;g++<Math.min(d, b);f-=i){i=b(b-g,g);if(f<i)break;}c.add(g);d=g;b-=g;}return c;}int b(int b,int c){if(b<1)return 1;List d=Arrays.asList(b,c);if(a.containsKey(d))return(int)a.get(d);int e,f;for(e=f=0;f++<Math.min(c, b);)e+=b(b-f,f);a.put(d,e);return e;}

Call with a(n). Returns a List of Integers
Indented:
import java.util.*;

Map a=new HashMap();

List a(int b){
    List c=new ArrayList();
    int d=b,e=b(b,d),f=(int)(Math.random()*e),g,i;
    while(b>0){
        for(g=0;g++<Math.min(d, b);f-=i){
            i=b(b-g,g);
            if(f<i)
                break;
        }
        c.add(g);
        d=g;
        b-=g;
    }
    return c;
}

int b(int b,int c){
    if(b<1)
        return 1;
    List d=Arrays.asList(b,c);
    if(a.containsKey(d))
        return(int)a.get(d);
    int e,f;
    for(e=f=0;f++<Math.min(c, b);)
        e+=b(b-f,f);
    a.put(d,e);
    return e;
}

Adapted from https://stackoverflow.com/a/2163753/4230423 and golfed
How this works: We can calculate how many partitions of an integer n there are in O(n2) time. As a side effect, this produces a table of size O(n2) which we can then use to generate the kth partition of n, for any integer k, in O(n) time.
So let total = the number of partitions. Pick a random number k from 0 to total - 1. Generate the kth partition.
As usual, suggestions are welcome :)

Python 2, 173 bytes
from random import*
N,M=input__
R=67;d=[(0,[])]*R*R
for k in range(R*R):p,P=d[k+~R];q,Q=d[k-k%R*R];d[k]=p+q+0**k,[[x+1 for x in Q],[1]+P][random()*(p+q)<p]
print d[N*R+M][1]

Recursively makes a dictionary d, with keys k representing a pair (n,m) by k=67*n+m (using the guaranteed n<=65). The entry is the tuple of the number of partition of n into m parts, and a random such partition. The counts are computed by the recursive formula (thanks to feersum for pointing it out)
f(n,m) = f(n-1,m-1) + f(n,n-m),
and the random partition is updated by picking one of the two of its branches with probability proportional to its count. The update is done by adding is done by appending a 1 for the first branch and incrementing every element for the second.
I had a lot of trouble getting out-of-bounds values of m and n to give counts of zero. At first, I used a dictionary that defaults to a count of 0 and an empty list. Here, I'm using a list and padding it with this default entry instead. Negative indices cause the list to be read from its end, which gives a default entry is nothing near the end as ever reached, and wraparounds only touch a region where m>n.

80386 machine code, 105 bytes
Hexdump of the code:
60 8b fa 81 ec 00 41 00 00 33 c0 8b f4 33 d2 42
89 14 06 42 33 ed 8b d8 03 2c 1e 2a fa 73 f9 83
c6 04 89 2c 06 42 3b d1 76 ea fe c4 3a e1 76 db
33 d2 0f c7 f0 f7 f5 86 e9 85 d2 74 1b 33 c0 8d
34 0c 39 14 86 77 03 40 eb f8 2b 54 86 fc 40 89
07 83 c7 04 2a e8 77 e1 42 89 17 83 c7 04 fe cd
7f f7 4a b6 41 03 e2 61 c3

As a C function: void random_partition(int n, int result[]);. It returns the result as a list of numbers in the supplied buffer; it doesn't mark the end of the list in any way, but the user can discover the end by accumulating the numbers - the list ends when the sum is equal to n.
How to use (in Visual Studio):
#include <stdio.h>

__declspec(naked) void __fastcall random_partiton(int n, int result[])
{
#define a(byte) __asm _emit 0x ## byte
a(60) a(8b) a(fa) a(81) a(ec) a(00) a(41) a(00) a(00) a(33) a(c0) a(8b) a(f4) a(33) a(d2) a(42)
a(89) a(14) a(06) a(42) a(33) a(ed) a(8b) a(d8) a(03) a(2c) a(1e) a(2a) a(fa) a(73) a(f9) a(83)
a(c6) a(04) a(89) a(2c) a(06) a(42) a(3b) a(d1) a(76) a(ea) a(fe) a(c4) a(3a) a(e1) a(76) a(db)
a(33) a(d2) a(0f) a(c7) a(f0) a(f7) a(f5) a(86) a(e9) a(85) a(d2) a(74) a(1b) a(33) a(c0) a(8d)
a(34) a(0c) a(39) a(14) a(86) a(77) a(03) a(40) a(eb) a(f8) a(2b) a(54) a(86) a(fc) a(40) a(89)
a(07) a(83) a(c7) a(04) a(2a) a(e8) a(77) a(e1) a(42) a(89) a(17) a(83) a(c7) a(04) a(fe) a(cd)
a(7f) a(f7) a(4a) a(b6) a(41) a(03) a(e2) a(61) a(c3)
}

void make_stack() // see explanations about stack below
{
    volatile int temp[65 * 64];
    temp[0] = 999;
}

int main()
{
    int result[100], j = 0, n = 64, counter = n;
    make_stack(); // see explanations about stack below

    random_partiton(n, result);

    while (counter > 0)
    {
        printf("%d ", result[j]);
        counter -= result[j];
        ++j;
    }
    putchar('\n');
}

Example output (with n = 64):

21 7 4 4 3 3 3 3 2 2 2 2 2 1 1 1 1 1 1

This requires much explanations...
Of course I used the algorithm that everyone else used as well; there wasn't any choice with the requirement about complexity. So I don't have to explain the algorithm too much. Anyway:
I denote by f(n, m) the number of partitionings of n elements using parts no greater than m. I store them in a 2-D array (declared in C as f[65][64]), where the first index is n, and the second m-1. I decided that supporting n=65 was too much trouble, so abandoned it...
Here is C code that calculates this table:
#define MAX_M 64
int f[(MAX_M + 1) * MAX_M];
int* f2;
int c; // accumulates the numbers needed to calculate f(n, m)
int m;
int k; // f(k, m), for various values of k, are accumulated
int n1;

for (n1 = 0; n1 <= n; ++n1)
{
    f2 = f;
    f2[n1 * MAX_M] = 1;
    for (m = 2; m <= n; ++m)
    {
        c = 0;
        k = n1;
        while (k >= 0)
        {
            c += f2[k * MAX_M];
            k -= m;
        }
        ++f2;
        f2[n1 * MAX_M] = c;
    }
}

This code has some obfuscated style, so it can be converted to assembly language easily. It calculates the elements up to f(n, n), which is the number of partitionings of n elements. When this code is finished, the temporary variable c contains the needed number, which can be used to select a random partitioning:
int index = rand() % c;

Later, this index is converted to the required format (list of numbers) using the generated table.
do {
    if (index == 0)
        break;

    m = 0;
    f2 = &f[n * MAX_M];
    while (f2[m] <= index)
    {
        ++m;
    }

    index -= f2[m-1];
    ++m;
    *result++ = m;
    n -= m;
} while (n > 0);

do {
    *result++ = 1;
    --n;
} while (n > 0);

This code is also optimized for conversion to assembly language. There is a small "bug": if the partitioning doesn't contain any 1 number at the end, the last loop encounters n = 0, and outputs an unneeded 1 element. It doesn't hurt, however, because the printing code tracks the sum of the number, and doesn't print this extraneous number.
When converted to inline assembly, this code looks like this:

__declspec(naked) void _fastcall random_partition_asm(int n, int result[])
{
    _asm {
        pushad;

        // ecx = n
        // edx = m
        // bh = k; ebx = k * MAX_M * sizeof(int)
        // ah = n1; eax = n1 * MAX_M * sizeof(int)
        // esp = f
        // ebp = c
        // esi = f2
        // edi = result

        mov edi, edx;
        sub esp, (MAX_M + 1) * MAX_M * 4; // allocate space for table
        xor eax, eax;
    row_loop:
        mov esi, esp;
        xor edx, edx;
        inc edx;
        mov dword ptr [esi + eax], edx;
        inc edx;

    col_loop:
        xor ebp, ebp;
        mov ebx, eax;

    sum_loop:
        add ebp, [esi + ebx];
        sub bh, dl;
        jae sum_loop;

        add esi, 4;
        mov [esi + eax], ebp;
        inc edx;
        cmp edx, ecx;
        jbe col_loop;

        inc ah;
        cmp ah, cl;
        jbe row_loop;

        // Done calculating the table

        // ch = n; ecx = n * MAX_M * sizeof(int)
        // eax = m
        // ebx =
        // edx = index
        // esp = f
        // esi = f2
        // ebp = c
        // edi = result

        xor edx, edx;
        rdrand eax; // generate a random number
        div ebp; // generate a random index in the needed range
        xchg ch, cl; // multiply by 256

    n_loop:
        test edx, edx;
        jz out_trailing;
        xor eax, eax;
        lea esi, [esp + ecx];

    m_loop:
        cmp [esi + eax * 4], edx;
        ja m_loop_done;
        inc eax;
        jmp m_loop;
    m_loop_done:

        sub edx, [esi + eax * 4 - 4];
        inc eax;
        mov [edi], eax;
        add edi, 4;
        sub ch, al;
        ja n_loop;

    out_trailing:
        inc edx;
    out_trailing_loop:
        mov dword ptr [edi], edx;
        add edi, 4;
        dec ch;
        jg out_trailing_loop;

        dec edx;
        mov dh, (MAX_M + 1) * MAX_M * 4 / 256;
        add esp, edx;
        popad;
        ret;
    }
}

Some fun things to note:

Generating a random number takes just 3 bytes of machine code (rdrand instruction)
By a coincidence, the size of the table is 64, so the size of one row is 256 bytes. I use this to hold row indices in "high-byte" registers like ah, which gives me automatic multiplication by 256. To take advantage of this, I sacrificed the support for n = 65. I hope I can be excused for this sin...
Allocating space on stack is performed by subtracting 0x4100 from the stack pointer register esp. This is a 6-byte instruction! When adding this number back, I managed to do it in 5 bytes:
    dec edx; // here edx = 1 from earlier calculations
    mov dh, (MAX_M + 1) * MAX_M * 4 / 256; // now edx = 0x4100
    add esp, edx; // this deallocates space on stack

When debugging this function in MS Visual Studio, I found out that it crashes when it writes data to the space that it allocated on stack! After some digging around, I discovered some sort of stack overrun protection: OS seems to allocate only a very limited range of virtual addresses for stack; if a function accesses an address too far away, OS assumes it's an overrun and kills the program. However, if a function has many local variables, OS does some extra "magic" to make it work. So I have to call an empty function that has a large array allocated on stack. After this function returns, extra stack VM pages are allocated and can be used.

    void make_stack()
    {
        volatile int temp[65 * 64];
        temp[0] = 999; // have to "use" the array to prevent optimizing it out
    }

source: Stack Exchange

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

sort: votes


text:
Different Way Forward
Given a list of integers produce a Forward Difference at a specified order/depth.
For the list of integers:
(10, 18, -12, 4, 8, -3, -5, 67, 9, 14)

The Forward Differences at the various orders/depths are:
0   10,   18,  -12,    4,    8,   -3,   -5,  67,  9,  14
1      8,  -30,   16,    4,  -11,   -2,   72, -58,  5
2       -38,   46,  -12,  -15,    9,   74, -130, 63
3           84,  -58,   -3,   24,   65, -204, 193
4            -142,   55,   27,   41, -269, 397
5               197,  -28,   14, -310, 666
6                 -225,   42, -324, 976
7                    267, -366, 1300
8                      -633, 1666
9                         2299

So with the input of
4, (10, 18, -12, 4, 8, -3, -5, 67, 9, 14)

You would return the list
(-142,   55,   27,   41, -269, 397)

Input
The input can be via STDIN or function parameters.
An integer specifying the depth to return.  This will be 0 to the length of the list minus 1
A list of integers to calculate the forward difference for
Output
The output can be via STDOUT or returned by the function.
The forward differences for the specified depth as a list of integers
Rules
Built in and 3rd Party functions that do this directly are not allowed.
Standard loophole restrictions apply.
Shortest code wins

Built in and 3rd Party functions that do this directly are not allowed. <- what is considered as "do this directly" - only recursive forward difference or even a single forward difference? Because I'm seeing many people using built-ins that do the latter.

J, 15 9 7 bytes
Very easy. Takes depth and list as left and right arguments.
-~/\~&2

As an explicit definition without all the adverbial trickery, this reduces to
4 : '(2 -~/\ ])^:x y'

-~/\~&2 y – The forwards difference of y.
x -~/\~&2 y – The x-th forwards difference of y.

If I were to make a serious (i. e. non-golfed) definition of this function, I would probably do something like this:
(}. - }:) : ($:@[&0)

The monadic case computes the forward difference whereas the dyadic case computes the x-th forward difference.
Even simpler, but not exactly equal:
+/\inv

+/\ yields a vector of the sums of the prefixes of the argument. inv (defined as ^:_1) is a conjunction that inverses a verb. This works wherever J knows how to inverse a verb and for the case of +/\, J knows how to.

This shows the power of adverbs and conjunctions as - is the only verb in this function.

Python, 61 59 bytes
f=lambda n,L:n and f(n-1,[x-y for x,y in zip(L[1:],L)])or L

Here we perform the subtraction by zipping all but the last of the list with all but the first of the list. zip(L[1:],L) is equivalent to zip(L[1:],L[:-1]), due to zip's nature of taking the minimum length of the two lists:
>>> zip([1,2,3],[4,5])
[(1, 4), (2, 5)]

An alternative that's just as long (Python 2 only):
f=lambda n,L:n and f(n-1,map(int.__sub__,L[1:],L[:-1]))or L

Unfortunately Python 2 doesn't cut off the end of the list, so I can't do map(int.__sub__,L,L[1:]). Annoyingly, Python 3 does, but map no longer returns a list so this ends up being a byte more (60 bytes):
f=lambda n,L:n and f(n-1,list(map(int.__sub__,L[1:],L)))or L

However, if we allow the input to be the depth followed by the list like f(3, 2, 5, 6, 7, 5, 10, 25) (i.e. depth 3 and list [2, 5, 6, 7, 5, 10, 25]), then this is 56 bytes:
f=lambda n,*T:n and f(n-1,*map(int.__sub__,T[1:],T))or T

Here's another alternative that would really annoy anyone who saw this in production code (this one destroys the original list):
f=lambda n,L:n and f(n-1,[L[1]-L.pop(0)for _ in L[1:]])or L

Your last code is incorrect. You would need L[1]-L.pop(0) instead.

@mbomb007 Thanks for the catch. That was awkward - I've had the arguments around the wrong way the whole time.

It was close, but something like every other depth had the signs reversed.

This is super late, but you can now do [*map(...)] in Python 3 for 57 bytes.

Mathematica 23 57 23 bytes
Martin Büttner's suggestion, exploiting the listability of subtraction.
 Rest@#-Most@#&~Nest~##&

e.g.
Rest@# - Most@# &~Nest~## & @@ {{10, 18, -12, 4, 8, -3, -5, 67, 9, 14}, 4}

{-142, 55, 27, 41, -269, 397}

Rest@#-Most@# carries out the subtraction that yields differences.
Nest performs said operation the specified number of times, operating always on the most recent list.

Haskell, 40 34 bytes
n#l=iterate(zipWith(-)=<<tail)l!!n

Usage example: 4 # [10,18,-12,4,8,-3,-5,67,9,14] which outputs [-142,55,27,41,-269,397].
How it works: repeatedly calculate the difference between neighbor elements and store the intermediate results in a list. Take the nth element from this list.
Edit: @Zgarb found 6 bytes to save. Awesome!

You can use the function monad and shorten the lambda to (zipWith(-)=<<tail).

JavaScript (ES6), 52 49 bytes
Simple recursive function, using map to scan the array and slice to drop the first element on each recursive call.
Edit 3 bytes saved, thanks @DocMax, really smart suggestion
F=(n,l)=>n?F(n-1,l.slice(1).map((a,k)=>a-l[k])):l

Test In Firefox/FireBug console
for(i=0;i<10;i++)console.log(F(i,[10, 18, -12, 4, 8, -3, -5, 67, 9, 14]))

[10, 18, -12, 4, 8, -3, -5, 67, 9, 14]
[8, -30, 16, 4, -11, -2, 72, -58, 5]
[-38, 46, -12, -15, 9, 74, -130, 63]
[84, -58, -3, 24, 65, -204, 193]
[-142, 55, 27, 41, -269, 397]
[197, -28, 14, -310, 666]
[-225, 42, -324, 976]
[267, -366, 1300]
[-633, 1666]
[2299]

Slice before map to efficiently avoid the need for p and save 3 chars: H=(n,l)=>n?H(n-1,l.slice(1).map((a,k)=>a-l[k])):l.

CJam, 15 bytes
l~{{_@-\}*;]}*p

Takes input as a CJam-style array and then the depth:
[10 18 -12 4 8 -3 -5 67 9 14] 4

and prints the result as a CJam-style array.
Test it here.
Explanation
l~              "Read and eval input.";
  {         }*  "Repeat this block N times, which computes the forward differences.";
   {    }*      "Fold this block onto the list - this is quite an abuse of folding semantics.";
    _           "Duplicate the current element (for the use in the next difference).";
     @          "Pull up the other copy of the last element.";
      -         "Subtract.";
       \        "Swap the difference and the other copy of the current element.";
          ;     "Discard the last element.";
           ]    "Wrap everything in an array again.";

Java, 122 119 bytes
int[]a(int[]a,int b){if(b<1)return a;int e=a.length-1,c[]=new int[e],i=e;for(;i-->0;)c[i]=a[i+1]-a[i];return a(c,b-1);}

Example Usage: http://ideone.com/ALgYez
3 bytes thanks to Geobits :v )>

You should get rid of the second int  and just assign i=e with the others.

Python, 70 68 67 59 bytes
f=lambda x,n:n and f([x[1]-x.pop(0)for i in x[1:]],n-1)or x

Non-golfed version before I went recursive:
def f(x,n):
    for j in range(n):
        for i in range(len(x)-1):
            x[i]=x[i+1]-x[i]
    return x[:-n]

><>  53  50 bytes
l:[2-&\~~]r1-:?!vr
&}-@:$/!?&:-1
:;!? &&  lo*84n~<

Usage: Prepopulate the stack (-v in python interpreter) with depth first, followed by the integers.
For example:
forward.fish -v 3 2 5 6 7 5 10 25

Returns
2 -3 10 3

Thanks to Sp3000 for the help.

Is it possible to use ?! and move some components around rather than 0=??

Nice catch! That helps a bunch

Prelude, 95 92 79 78 bytes
?    (1-vv- # ) v  !
  ?     #   ^   #
?(1-)   1  (#)  1)(#)
  1   #(# ) 1  (#

Input format is
N
M
n_1
n_2
...
n_M

where N is the depth of the differences and M is the number of integers in the input. Adding M was necessary, because there's no way for Prelude to distinguish a 0 from the end of the input. Output is also as a newline separated list of integers. I had to assume the slightly adjusted Prelude spec we devised for this challenge, because standard Prelude reads integers as byte values, which makes it impossible to enter negative numbers. Essentially, this is the Python interpreter with an additional NUMERIC_INPUT flag.
For reference there are only 48 38 37 non-space characters - the rest was merely needed to align the code correctly.
Explanation
In Prelude, each line is a separate "voice" that operates on its own stack. The program is executed column by column, where the separate voices are taken to operate "in parallel". All commands are single characters, and parentheses are Brainfuck-like loops (which are entered and repeated whenever the top of the stack is non-zero). Note that the vertical position of the closing parenthesis is irrelevant - putting it in a different voice still counts as matching with the most recent opening parenthesis, and the stack that is checked for the loop condition is always the voice where the ( appeared. Now on to this program...
The program can basically be separated in into two parts. The bottom two lines are merely used for most of the loops in the program (except the main loop over N), passing 1s back and forth. The top two lines contain the main loop and actual differencing. The following annotation has the code transposed, so I can annotate the individual columns:
? ?   # Read two integers. Read instructions are processed top to bottom, so the first voice
      # reads N and the third voice reads M.
  (   # Start a loop on the third voice. This loop will execute M times, reading the input list
      # and pushing M 1s onto the fourth voice - i.e. a unary representation of M.
 ?11  # Read an integer onto the second voice, push 1s onto the third and fourth voice.
  -   # Subtract the 1 from the third voice, decrementing M down to 0.
  )   # End of loop, if the third voice is not 0 yet, to back two columns.
(     # Start a loop on the first voice. This is the main loop and will execute N times. Each
      # iteration will compute the forward differences once and thereby shorten the list by one
      # element and also reduce the stack of 1s on the bottom voice by one.
1  #  # Push a 1 onto the first voice and pop a 1 from the last. Together with the next column,
      # this decrements both N and (the unary) M.
-  (  # Subtract the 1 from the first voice (decrementing N), and start a loop on the fourth
      # voice over whatever is left of M (the length of the resulting difference list). Note
      # that this column is *not* part of the loop, so the - on the first voice will only be
      # executed once. This loop builds the differences in reverse order on the first voice.
v#1#  # Pop a 1 from the fourth voice and push a 1 onto the third. This loops over M while
      # shifting its unary representation to the other stack. In addition, shift the top stack
      # element from the second to the first voice.
v     # Copy the next element from the second voice to the first, without popping.
-  )  # Subtract the two elements on the first voice and end the loop if the fourth voice is
      # empty. Note that his column *is* part of the loop.
  (   # Start a loop on the third voice. This is another loop over M, shifting the stack of 1s
      # back to the fourth voice, and reversing the differences by shifting them onto the
      # second.
#^#1  # As stated above, shift an element from the first to the second voice, a 1 from the
      # third to the fourth.
  )   # End the loop. After this point, we're back to the original situation, except that the
      # second voice has been replaced by its differences. The bottom stack element the
      # previous list is also still on that stack, but the decreasing loop lengths on the third
      # and fourth voices ensures that this element is never touched again.
)     # End the main loop when N has been reduced to 0.
   (  # Start another loop over the remaining list length, shifting and reversing the result.
v#1#  # Shift a 1 back to the third voice and an element from the second to the first voice.
  )   # End the loop. Note that this parenthesis is not on the same voice as the corresponding
      # opening parenthesis, but its exact position is irrelevant. Moving it to this voice
      # saves a byte.
  (   # Start one last loop over the length of the result.
! #   # Pop a 1 from the third voice while printing (and popping) one element of the result.
  )   # End the loop.

R, 48 39 46 44 bytes
Recursion!
function(x,y)if(x)Recall(x-1,diff(y)) else y

x is the number of iterations to perform, and y is a vector of integers.
if(x) is true as long as x>0.
Recall calls the current function but with new arguments.
Diff outputs the differences between consecutive list/vector elements.

Previous versions:
#does not work for x=0:
function(x,y){for(i in 1:x)y=diff(y);y}

#does not use diff function:
function(x,y){for(i in 1:x)y=y[-1]-head(y,-1);y}

y[-1]       is a list minus its first element
head(y,-1)  is a list minus its last element

Is there a better way to repeat the diff function x times? Using a for loop feels excessive.

There is Reduce, but it would cost more characters I think.

There is one small problem.  When called with 0 depth it returns depth 2

Went for a different approach, problem solved but had to add 7 chars.

Nice use of Recall().

39 bytes

Python, 92 87 86 bytes
def a(b,c):
 if c<1:return b
 d=[];e=b[0]
 for f in b[1:]:d+=f-e,;e=f
 return a(d,c-1)

This is my first Python golf. Any suggestions will be appreciated :)
5 6 bytes thanks to Sp3000 :D

I'd recommend a list comprehension.

You can turn the append into d+=f-e,. In general, for code-golf you'll never need to use L.append because of this.

c, 68 55 bytes
f(int *l){for(--l[-1]?f(l):0;*l;l++)*l=l[1]-*l;*--l=0;}

This might be taking liberties with the input spec a bit.  An int array is constructed such that element 0 is the depth and elements 1 to (n+1) are the input list elements 0 to n.  Then the address of element 1 is passed to the function.
The array must be zero terminated. The array is edited in place.
E.g:
#include <stdio.h>

f(int *l){for(--l[-1]?f(l):0;*l;l++)*l=l[1]-*l;*--l=0;}

int main (int argc, char **argv)
{
  int list[] = {4, 10, 18, -12, 4, 8, -3, -5, 67, 9, 14, 0};
  int *elem;

  f(list + 1);

  for (elem = list + 1; *elem; elem++) {
    printf("%d, ", *elem);
  }
}

http://ideone.com/m5PDgF

Why did you leave a space in int *l?

T-SQL, Too Many :)
When I first saw this problem, I wondered if there was a way to do this in a query.  While trivial for most languages, it's not so much for SQL query.
The input goes into variables @ (for depth) and @L for the integer list.
@L is a user defined table type
CREATE TYPE L AS TABLE(n INT IDENTITY(0,1),v INT)

Input setup
DECLARE @L L,@ INT=4
INSERT @L(v)values(10),(18),(-12),(4),(8),(-3),(-5),(67),(9),(14)

The query with some comments
WITH R AS(
    -- Recursive query to calculate the level of a pascal triangle with alternating negatives
    -- For 4 this is 1 -4  6 -4  1
    SELECT 1c,0g UNION ALL SELECT-c*(@-g)/(g+1),g+1FROM r WHERE g<@
    ),
    O AS(
    --Multiple N values of list by reversed pascal triangle values
    --shifting the start for each iteration (list length) - N
    SELECT c*v v,F
    FROM @L L
        CROSS APPLY(
            SELECT TOP((SELECT COUNT(*)FROM @L)-@)ROW_NUMBER()OVER(ORDER BY(SELECT\))-1F FROM sys.all_views a,sys.all_views b)c
        JOIN R ON N=F+@-G
    )
-- Sum the multiplied values
SELECT SUM(V)FROM o GROUP BY F ORDER BY F

Result
-142
55
27
41
-269
397

Factor, 25 bytes
[ [ differences ] times ]

Try it online!

times Call a quotation a certain number of times.

differences Calculate the first-order differences of a number sequence.

E.g. { 1 4 2 } -> { 3 -2 }

Powershell 115 111 bytes
$p={param($a, $b)0..($a-1)|%{$b=@($l=$b.length;for($i=0;$i-lt$l;$i++){$b[$i+1]-$b[$i]})[0..($l-2)]};$b-join','}

Execute as such:
.$p 4 @(10,18,-12,4,8,-3,-5,67,9,14)

Output:
-142,55,27,41,-269,397

Moving a curly brace to a different spot allows this to display every step to the answer.
8,-30,16,4,-11,-2,72,-58,5
-38,46,-12,-15,9,74,-130,63
84,-58,-3,24,65,-204,193
-142,55,27,41,-269,397

STATA, 126 bytes
di _r(a)_r(b)
token $b
gl $c=wordcount($b)
forv x=1/$a{
gl $c--
forv y=1/$c{
loc `y'=``y'+1'-``y''
}
}
forv z=1/$c{
di ``z''
}

Expects input as an integer representing the depth, followed by a space separated list of integers, both given via the standard prompt. Output is newline separated list of integers.
First it converts the list of integers (which it views as 1 long string) into a list of local variables whose names are 1,2,3,... Then it computes forward differences by setting the value of the yth local variable to be the value of the y+1th local variable minus the value of the yth local variable (i.e. 18-10=8), which overwrites existing values only after use. It does this $a (value of global variable a) times. Then it displays the value of each local variable, 1 at a time.

+1 for explanation. This is an awesomely convoluted way of processing lists.

@Zgarb, I don't know a way for STATA to take input as an array/list except via file (which wouldn't work here because of the other input). That's why it has to work like this.

Japt -h, 17 5 bytes
12 bytes saved thanks to @Shaggy
VÆ=än

Try it online!

13 bytes

Or a different implementation gives 12 bytes

You can replace äÏ-X with än in both of those to save 2 more bytes.

Got it down to 5 bytes!

@Shaggy damn you are too good at japt xD You should post your 5 bytes answer

Here's a fun 7 byter - you're more than welcome to any of those solutions.

K (ngn/k), 8 bytes
(1_-':)/

Try it online!
Sets up a do-over, running the code in parenthesis depth times, seeded with initial values. Results from one iteration are passed into the next.

-': take the deltas of the input
1_ drop the first delta (which is just the first value in x)

Vyxal, 3 bytes
(¯N

Try it Online!
Takes input like n, [list]

Thunno 2, 2 bytes
{Ṣ

Try it online!
Explanation
{Ṣ  # Implicit input
{   # Input number of times:
 Ṣ  #  Deltas
    # Implicit output

Swift, 51 bytes
{for _ in 0..<$0{$1=zip($1.dropFirst(),$1).map(-)}}

Takes (depth, &arr) and modifies the input array to contain the result.
Try it on SwiftFiddle!
Ungolfed/commented:
{ (depth: Int, arr: inout [Int]) in
  // Iterate the specified number of times. The iteration number isn't needed.
  for _ in 0..<depth {
    // Modify the input array to contain the next iteration:
    arr =
      // Get adjacent pairs in reverse order -- dropFirst returns a slice
      // without mutating the original array.
      zip(arr.dropFirst(), arr)
        // Subtract adjacent pairs. Swift lets you use an operator as if it
        // were a value of function type -- in this case, (Int, Int) -> Int.
        // This particular case is only legal because ((T, U)) -> V and
        // (T, U) -> V are equivalent types, but I think they're only
        // equivalent to make this kind of thing legal.
        .map(-)
  }
}

Uiua SBCS, 8 bytes
⍥(↘1°\+)

Try it!

Japt, 7 bytes
A couple of alternatives I'd made available to Luis for his solution.
_än}gNÅ

Try it
10 bytes
ÏÄ<V}f@=än

Try it

05AB1E, 2 bytes
Ties HyperNeutrino's Jelly answer for #1.
F¥

Try it online!
F¥  # full program
F   # for N in [0, 1, 2, ...,
    # ..., implicit input...
F   # ...minus 1]...
 ¥  # get differences of elements in...
    # implicit input...
 ¥  # or top of stack if not first iteration
    # implicit output

Pyth, 4 bytes
.+FE

Try it here!

You just ninjaed me on a 6 year old question...

x86-16 machine code, 20 bytes
00000000: 4951 568b fead 938b 042b c3ab e2f7 5e59  IQV......+....^Y
00000010: 4a75 edc3                                Ju..

Listing:
        DEPTH_LOOP:
49          DEC  CX                 ; decrement length
51          PUSH CX                 ; save length
56          PUSH SI                 ; save array pointer
8B FE       MOV  DI, SI             ; set array pointer for output
        DIFF_LOOP:
AD          LODSW                   ; load first WORD into AX, advance SI
93          XCHG AX, BX             ; save first to BX
8B 04       MOV  AX, WORD PTR[SI]   ; load second WORD into AX (don't advance)
2B C3       SUB  AX, BX             ; AX = AX - BX
AB          STOSW                   ; save result to current array index
E2 F7       LOOP DIFF_LOOP          ; loop until end of array
5E          POP  SI                 ; restore array pointer
59          POP  CX                 ; restore length
4A          DEC  DX                 ; decrement depth counter
75 ED       JNZ  DEPTH_LOOP         ; loop until end of depth
C3          RET                     ; return to caller

Input array at [SI], input length (in bytes) in CX, depth in DX.
Test with DOS DEBUG:

Note: data is shown as little endian hex in DEBUG (A 0 = 0x000a = 10, 72 FF = 0xff72 = -142).

Vyxal, 2 bytes
(¯

Try it Online!
(  # n times
 ¯ # take forward differences

Clojure, 47 bytes
#(if(= 0 %)%2(recur(dec %)(map -(rest %2)%2))))

A simple recursion on anonymous function. You save 1 byte if the order of arguments is swapped as now %2 occurs more frequently than %.

Jelly, 2 bytes
I¡

Try it online!
Explanation
I¡  Main Link
 ¡  Repeat `n` times; this repeats the previous link by <right argument> times
I   Get forward differences

Very straightforward answer :P

SmileBASIC, 76 bytes
Finally a reason to use ARYOP!
DEF F L,D
IF!D THEN@R
DIM B[0]COPY B,L
T=SHIFT(L)ARYOP 1,L,L,B
F L,D-1@R
END

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

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


text:
Python 3 - Tried Golfing My Assignment
Note: This isn't as much a golfing challenge; it is more so asking for golfing suggestions.
Recently I had a Python assignment for my web development class, in order to check whether we could code. Since I already feel comfortable in Python, I decided to try and golf it, and I was wondering if people could point out things that I missed.
I already know that there are extra spaces in some places, but I'm more interested in conceptual things, like using while r: when r is a variable, and then waiting for it to "run out"!
The assignment
import random
from collections import Counter
s=l=''
c=['yellow','blue','white','green','Black', 'purple', 'silver', 'cyan', 'magenta', 'red']
n=[10,15,1,10,6,15,10,25,1,12,5,10,4,6,5,12,0,10,1,1]
o=i=0
for y in c:l+=y[0]*(random.randint(n[o],n[o+1]));o+=2
l=list(l)
print("Welcome to the CIMS Gumball Machine Simulator\nYou are starting with the following gumballs:")
for b in c:print(str(l.count(b[0])) + " "+b);random.shuffle(l)
print("Here are your random purchases:")
while 'r' in l:
    random.shuffle(l); r=l.pop(); s+=r
    for j in c:
        if j[0] == r:print(j.capitalize())
print("You purchased %i gumballs, for a total of $%.2f \nMost common gumball(s):" % (len(s),len(s)*25/100))
a=Counter(s).most_common()
m=[x[1] for x in a]
while m[0] == m[i]:
    for j in c:
        if j[0] == a[i][0]:print(j.capitalize(), end=" ")
if(i<(len(m)-1)):i+=1
else:break

Also: I'm sorry if this isn't an appropriate question for the code golf page, since it is not a challenge and will remove it on request.

Putting the issue of on-topic-ness aside (since I'm not sure), perhaps take a look at the Python golf tips page? Also, which Python version? (I'm assuming 3 due to the parens around print, but just to check)

Have you attempted to golf it yet?

This code has a lot of simple golf improvements remaining. I think you'd learn better if you reviewed the golf tips and looked at other Python golfs, and did more to shorten it your code on your own. Then, if you post what you get, people can give more insightful advice.

Here's a whole bunch of micro-optimisations you can do:
Use .split() to create a long list (-17 bytes):
c=['yellow','blue','white','green','Black', 'purple', 'silver', 'cyan', 'magenta', 'red']
c='yellow blue white green Black purple silver cyan magenta red'.split()

Remove extraneous brackets (-2 bytes):
l+=y[0]*(random.randint(n[o],n[o+1]))
l+=y[0]*random.randint(n[o],n[o+1])

Use splat (-2 bytes):
random.randint(n[o],n[o+1])
random.randint(*n[o:o+2])

Use extended iterable unpacking to turn something into a list (-4 bytes):
l=list(l)
*l,=l

Import all the things (-15 bytes):
import random;random.randint;random.shuffle;random.shuffle
from random import*;randint;shuffle;shuffle

Use other functions that can do the same job here (-5 * 2 = -10 bytes):
j.capitalize()
j.title()

print separates by space by default (-11 bytes):
print(str(l.count(b[0])) + " "+b)
print(l.count(b[0]),b)

More unpacking (-3 bytes):
r=l.pop()
*l,r=l

Abuse side-effects (-1 byte, plus indents):
if j[0]==r:print(j.capitalize())
r!=j[0]or print(j.capitalize())

Anything reused and over 5 chars might be worth saving as a variable (-1 byte):
len(s);len(s)
L=len(s);L;L

Simplify fractions (-5 bytes):
len(s)*25/100
len(s)/4

Unary abuse (-4 bytes):
if(i<(len(m)-1)):i+=1
if~-len(m)>i:i+=1

Or the biggest one of all...
Look at your algorithm, and see if it needs changing altogether
from random import*
*s,P,S=print,shuffle
P("Welcome to the CIMS Gumball Machine Simulator\nYou are starting with the following gumballs:")
*l,c,C='yellow blue white green Black purple silver cyan magenta red'.split(),s.count
for x,y,z in zip(c,[10,1,6,10,1,5,4,5,0,1],[15,10,15,25,12,10,6,12,10,1]):n=randint(y,z);l+=[x]*n;P(n,x)
S(l)
P("Here are your random purchases:")
while'red'in l:S(l);*l,r=l;s+=r,;P(r.title())
L=len(s)
P("You purchased %i gumballs, for a total of $%.2f\nMost common gumball(s):"%(L,L/4))
for x in c:C(x)!=max(map(C,c))or P(x.title())

(If you ever find yourself importing Counter in a code-golf, you're probably doing something very wrong...)

Wow!! This is exactly what I was looking for. Thanks so much for your help!

You could probably obviate the need for .title() by precapitalizing everything. Also, assign s.count to a variable.

@isaacg I thought I'd try to keep the functionality of the original program. If the spec was all that counted, I'd drop a few of the long print statements since technically the assignment doesn't need them ;)

@Sp3000 In that case, why not put the .title() on the initial string? Saves one .title() use.

@isaacg Also, I did it by picking out of an array of each of the starting letters, and 'b' represented blue and 'B' represented black

Thanks again @Sp3000... This is the coolest thing to see ever, not to mention incredibly educational!

@aks. No worries, although I'm not sure about the fast accept (it hasn't been very long). I'm sure there's a lot more things that can be done, and other people probably have great ideas too, but I hope I've gotten my main point across :)

@Sp3000 okay I'll let it hang around a little longer... Although I wasn't expecting anything more than this and I think the other golfers should focus on real golf challenges

Hey @Sp3000, is there a way of simplifying l=list;*x,=input() into one equals operation?

In Python 3, I couldn't get it to work.

I'm trying to get a list of each character in the input, not just a list of the input

@aks. Not that I can think of at least, because by putting two things on the right hand side (e.g. l,*x=list,input()) you turn the right hand side into a tuple, which it traverses over (given the string in a list), rather than a string (which allows turning the string into a list of chars).


text:
List the Cases of Two Finnish Nouns
Introduction
In this challenge, your task is to correctly list the cases of two Finnish nouns.
The twist is that you may use one of the listings as a guide to produce the other.
The Nouns
We use the following two declination tables as our data.
They list the cases of two nouns, one case per line in the same order as in the Wikipedia article linked above, in the form singular : plural where applicable.
Table 1: Cases of ovi ("door")
ovi : ovet
oven : ovien
oven : ovet
ovea : ovia
ovessa : ovissa
ovesta : ovista
oveen : oviin
ovella : ovilla
ovelta : ovilta
ovelle : oville
ovena : ovina
oveksi : oviksi
ovin
ovetta : ovitta
ovine

Table 2: Cases of jalka ("foot")
jalka : jalat
jalan : jalkojen
jalan : jalat
jalkaa : jalkoja
jalassa : jaloissa
jalasta : jaloista
jalkaan : jalkoihin
jalalla : jaloilla
jalalta : jaloilta
jalalle : jaloille
jalkana : jalkoina
jalaksi : jaloiksi
jaloin
jalatta : jaloitta
jalkoine

The Task
Your task is to write two programs f and g (possibly with different names) that take one string as input, give one string as output, and have the following property.
If Table 1 is given to f as input, it outputs Table 2, and if Table 2 is given to g, it outputs Table 1.
All other inputs result in undefined behavior.
The tables must appear exactly as above in both input and output.
You may optionally assume that there is a trailing newline, but then it must be used in both tables, and in both input and output.
There is no preceding newline.
Rules and Bonuses
You can write f and g as either functions or full programs, but they must be of the same type, and they must be completely separate (if you write a helper function for f, you must re-write it in g if you want to use it there).
The lowest total byte count wins, and standard loopholes are disallowed.
There is a bonus of -25 % for not using regular expressions.
Some Clarifications
It is perfectly fine to write a function/program f that ignores its input and always returns Table 2, and a function/program g that always returns Table 1.
It is only required that f(Table 1) == Table 2 and g(Table 2) == Table 1; the behavior of f and g on all other inputs is irrelevant.
The "completely separate" part means the following.
Your answer provides two pieces of code, one for f and one for g, preferably in different code boxes.
If I put the code for f in a file and run it, it works, and the same for g.
Your score is the sum of the byte counts of the two pieces of code.
Any duplicated code is counted twice.

if Table 1 is given `f` as input How does one input a function into a table? I don't understand this part

@Reticality "If Table 1 is given to f as input"

Perl, 105 + 54 = 159
Program f (try me):
#!perl -p
s/vi /vka /;s/ve/va/g;s/en/an/;s/vi/voi/;s/ov/1&34960>>$.?jalk:jal/eg;s/ii/ihi/;s/loia/lkoje/;s/oia/oja/

Program g (try me):
#!perl -p
s/jalk?o?/ov/g;s/va /vi /;s/va/ve/g;s/an/en/;y/jh/i/d

An alternative version of f, only 2 bytes longer (this method can be also applied to g but it would be too long):
#!perl -p0
ka1a1a1koj1a1a1ka1koj1a1o0a1o0kaa2koih1a1o0a1o0a1o0ka1ko0a1o0o0a1o0ko=~s!\D+!"s/ov".'.'x$'."/jal$&/"!gree

Technically this still uses a regexp (to decode the substitution string and then to apply them) so I cannot claim the bonus here.

Wow, good work with s/jalk?o?/ov/g! That one's powerful.

Perl, 131 + 74 = 205
Table 1 to Table 2
$_=join"",<>;s/ee/kaa/;s/ii/koihi/;s/i(e|a)/koj$1/g;s/i(na|ne)/koi$1/g;s/v[ie](.?a| )/vka$1/g;s/vi/voi/g;s/ve/va/g;s/ov/jal/g;print

Expanded:
$_=join"",<>;
s/ee/kaa/;
s/ii/koihi/;
s/i(e|a)/koj$1/g;
s/i(na|ne)/koi$1/g;
s/v[ie](.?a| )/vka$1/g;
s/vi/voi/g;
s/ve/va/g;
s/ov/jal/g;
print

Table 2 to Table 1
$_=join"",<>;s/aan/aen/;s/jal(ka\b|oi|ko[ij]h?)/ovi/g;s/jalk?a/ove/g;print

Expanded:
$_=join"",<>;
s/aan/aen/;
s/jal(ka\b|oi|ko[ij]h?)/ovi/g;
s/jalk?a/ove/g;
print

(Thanks to @nutki for some Perl tips)
Despite the penalty on regexes, I decided to tackle it anyway and learn Perl while I was at it. I'm assuming there's some Perl tricks which might let me chain replacements, but I couldn't find any in my quick search online.
It's much harder to go from the ovi table to jalka table, which I'm guessing is because the jalka table has additional nuances to make words easier to pronounce.

Here's the replacement table I was working off:
i <-> ka
--------
ov i               jal ka

e <-> ka
--------
ov e a             jal ka a
ov e na            jal ka na

e <-> a
-------
ov e t             jal a t
ov e n             jal a n
ov e ssa           jal a ssa
ov e sta           jal a sta
ov e lla           jal a lla
ov e lta           jal a lta
ov e lle           jal a lle
ov e ksi           jal a ksi
ov e tta           jal a tta

i <-> oi
--------
ov i ssa           jal oi ssa
ov i sta           jal oi sta
ov i lla           jal oi lla
ov i lta           jal oi lta
ov i lle           jal oi lle
ov i ksi           jal oi ksi
ov i n             jal oi n
ov i tta           jal oi tta

i <-> koi
---------
ov i na            jal koi na
ov i ne            jal koi ne

i <-> koj
---------
ov i en            jal koj en
ov i a             jal koj a

i <-> koih
------------
ov i in            jal koih in

ee <-> kaa
----------
ov ee n            jal kaa n

Python 2, 371 - 25% = 278
When table 1 is the input to function f, it returns table 2. If the input is not table 1, it's output is undefined (however likely but not guaranteed to return table 2). For example, calling f(9**9**9**9) will probably not return table 2.
f=lambda a:'jalkaBatAanBkojenAanBatAkaaBkojaAassaBoissaAastaBoistaAkaanBkoihinAallaBoillaAaltaBoiltaAalleBoilleAkanaBkoinaAaksiBoiksiAoinAattaBoittaAkoine'.replace('A','\njal').replace('B',' : jal')

The same logic is used with function g:
g=lambda a:'oviBetAenBienAenBetAeaBiaAessaBissaAestaBistaAeenBiinAellaBillaAeltaBiltaAelleBilleAenaBinaAeksiBiksiAinAettaBittaAine'.replace('A','\nov').replace('B',' : ov')

The functions are independent.

VBA 1204 (1605 - 25%) 1191 (1587 - 25%)
The direct approach.
Edit: Corrected bug and used replace trick from @Maltysen
Function f(s)
    If Replace(s, " : ", ":") = "ovi:ovet" & vbLf & "oven:ovien" & vbLf & "oven:ovet" & vbLf & "ovea:ovia" & vbLf & "ovessa:ovissa" & vbLf & "ovesta:ovista" & vbLf & "oveen:oviin" & vbLf & "ovella:ovilla" & vbLf & "ovelta:ovilta" & vbLf & "ovelle:oville" & vbLf & "ovena:ovina" & vbLf & "oveksi:oviksi" & vbLf & "ovin" & vbLf & "ovetta:ovitta" & vbLf & "ovine" Then f = Replace("jalka:jalat" & vbLf & "jalan:jalkojen" & vbLf & "jalan:jalat" & vbLf & "jalkaa:jalkoja" & vbLf & "jalassa:jaloissa" & vbLf & "jalasta:jaloista" & vbLf & "jalkaan:jalkoihin" & vbLf & "jalalla:jaloilla" & vbLf & "jalalta:jaloilta" & vbLf & "jalalle:jaloille" & vbLf & "jalkana:jalkoina" & vbLf & "jalaksi:jaloiksi" & vbLf & "jaloin" & vbLf & "jalatta:jaloitta" & vbLf & "jalkoine", ":", " : ")
End Function

Function g(s)
    If Replace(s, " : ", ":") = "jalka:jalat" & vbLf & "jalan:jalkojen" & vbLf & "jalan:jalat" & vbLf & "jalkaa:jalkoja" & vbLf & "jalassa:jaloissa" & vbLf & "jalasta:jaloista" & vbLf & "jalkaan:jalkoihin" & vbLf & "jalalla:jaloilla" & vbLf & "jalalta:jaloilta" & vbLf & "jalalle:jaloille" & vbLf & "jalkana:jalkoina" & vbLf & "jalaksi:jaloiksi" & vbLf & "jaloin" & vbLf & "jalatta:jaloitta" & vbLf & "jalkoine" Then f = Replace("ovi:ovet" & vbLf & "oven:ovien" & vbLf & "oven:ovet" & vbLf & "ovea:ovia" & vbLf & "ovessa:ovissa" & vbLf & "ovesta:ovista" & vbLf & "oveen:oviin" & vbLf & "ovella:ovilla" & vbLf & "ovelta:ovilta" & vbLf & "ovelle:oville" & vbLf & "ovena:ovina" & vbLf & "oveksi:oviksi" & vbLf & "ovin" & vbLf & "ovetta:ovitta" & vbLf & "ovine", ":", " : ")
End Function

Run from the Immediate window:
msgbox f("ovi : ovet" & vbLf & "oven : ovien" & vbLf & "oven : ovet" & vbLf & "ovea : ovia" & vbLf & "ovessa : ovissa" & vbLf & "ovesta : ovista" & vbLf & "oveen : oviin" & vbLf & "ovella : ovilla" & vbLf & "ovelta : ovilta" & vbLf & "ovelle : oville" & vbLf & "ovena : ovina" & vbLf & "oveksi : oviksi" & vbLf & "ovin" & vbLf & "ovetta : ovitta" & vbLf & "ovine")

Wouldn't you only have to check if the first character is 'o' or 'j' ?

@Claudiu Actually, there's no need to check anything; functions that ignore their input and always return the same table are valid answers. I'll clarify that in the challenge.

@Claudiu I thought about that, but what if someone ran it by passing "o"?

@Zgarb It seems like you think my functions are ignoring their input, which they're not (technically). There's no translation of characters, though.

No, I'm just saying that they could simply ignore their inputs and still be valid.

@Zgarb While that would shorten my code significantly, I'll stick the the original spirit of the question. :)

Python - 462 - 25% = 346.5
This program does the obvious, direct approach except for a few data golfing tricks. For the undefined behavior it print the table just like the defined behavior. What an amazing "coincidence"! :)
x,y="""ovi:ovet
oven:ovien
oven:ovet
ovea:ovia
ovessa:ovissa
ovesta:ovista
oveen:oviin
ovella:ovilla
ovelta:ovilta
ovelle:oville
ovena:ovina
oveksi:oviksi
ovin
ovetta:ovitta
ovineXjalka:jalat
jalan:jalkojen
jalan:jalat
jalkaa:jalkoja
jalassa:jaloissa
jalasta:jaloista
jalkaan:jalkoihin
jalalla:jaloilla
jalalta:jaloilta
jalalle:jaloille
jalkana:jalkoina
jalaksi:jaloiksi
jaloin
jalatta:jaloitta
jalkoine""".replace(':',' : ').split('X')
f=lambda n:y
g=lambda n:x

Now, if one would consider this cheating (yeah right), I can follow the spirit of the rules for 20 more characters = 482 - 25%=361.5. Just replace the last two lines with:
f=lambda n:[x,y][n==x]
g=lambda n:[y,x][n==y]

This would make the undefined behavior return not the correct table but the input table.

It's perfectly fine to always return the same table. However, the challenge states that all code used to define the functions must be separate (this may have been a little ambiguous, I'll try to clarify it). In particular, you can't define x and y in one expression, and use one in f and the other in y.

"in y" -> "in g"

JavaScript (ES6) 271 (165 + 196 -25%)
Starting simple. The functions ignore input parameter at all.
Using split/join instead of replace to avoid regular expressions.
g=_=>'ovi1et0n1ien0n1et0a1ia0ssa1issa0sta1ista0en1iin0lla1illa0lta1ilta0lle1ille0na1ina0ksi1iksi\novin0tta1itta\novine'
.split(0).join('\nove').split(1).join(' : ov')
f=_=>'jalka1at0an1kojen0an1at0kaa1koja0assa1oissa0asta1oista0kaan1koihin0alla1oilla0alta1oilta0alle1oille0kana1koina0aksi1oiksi0oin0atta1oitta0koine'
.split(0).join('\njal').split(1).join(' : jal')

Test in Firefox/FireBug console
console.log(f('ovi : ovet\noven : ovien\noven : ovet\novea : ovia\novessa : ovissa\novesta : ovista\noveen : oviin\novella : ovilla\novelta : ovilta\novelle : oville\novena : ovina\noveksi : oviksi\novin\novetta : ovitta\novine'))

jalka : jalat
jalan : jalkojen
jalan : jalat
jalkaa : jalkoja
jalassa : jaloissa
jalasta : jaloista
jalkaan : jalkoihin
jalalla : jaloilla
jalalta : jaloilta
jalalle : jaloille
jalkana : jalkoina
jalaksi : jaloiksi
jaloin
jalatta : jaloitta
jalkoine

console.log(g("jalka : jalat\njalan : jalkojen\njalan : jalat\njalkaa : jalkoja\njalassa : jaloissa\njalasta : jaloista\njalkaan : jalkoihin\njalalla : jaloilla\njalalta : jaloilta\njalalle : jaloille\njalkana : jalkoina\njalaksi : jaloiksi\njaloin\njalatta : jaloitta\njalkoine"))

ovi : ovet
oven : ovien
oven : ovet
ovea : ovia
ovessa : ovissa
ovesta : ovista
oveen : oviin
ovella : ovilla
ovelta : ovilta
ovelle : oville
ovena : ovina
oveksi : oviksi
ovin
ovetta : ovitta
ovine