Python all right, 72 74 75 chars
p=lambda i,j,k,l,m:j-i!=k-j and(k==j*j==j*i*i and m*m or m*l/k)or m+j-i
Thx to xnor for showing me the if
/else
to and
/or
trick and golfing off a char :)
Thx to flornquake for fixing the k==j*j==j*i*i
and saving another two chars :)
Actually, it gets one wrong... but that's a bug in the test patterns which was acknowledged yesterday but still not fixed.
Testing code, hopefully useful for all competitors to test with:
def check(func,title):
right = 0
print "===", title, "==="
for i,test in enumerate(open('patterns.txt')):
test = map(int,test.split(','))
try:
got, expected = func(*test[:5]), test[5]
except Exception as e:
got = e
if got != expected:
print "ERROR on line %d: %s != %d" % (i, got, expected)
print " test :", ", ".join(map(str,test))
plus = multi = cube = str(test[0])
for i in range(1, 6):
plus += ", %d" % (test[i-1]+(test[1]-test[0]))
multi += ", %s" % ((test[i-1]*(test[1]/test[0])) if test[0] else "DivZero")
cube += ", %d" % (test[i-1]**2)
print " as + :", plus
print " as * :", multi
print " as ^2:", cube
else:
right += 1
print right, "out of", i+1, "right!"
says:
ERROR on line 19: 23283064365386962890625 != 3273344365508751233
test : 5, 25, 625, 390625, 152587890625, 3273344365508751233
as + : 5, 25, 45, 645, 390645, 152587890645
as * : 5, 25, 125, 3125, 1953125, 762939453125
as ^2: 5, 25, 625, 390625, 152587890625, 23283064365386962890625
1834 out of 1835 right!