How many goals has Steven Gerrard scored?

JavaScript (ES6), 47 43 42 39 bytes

y=>+'0723135148933694'[y-1999]+y%20%9|0

How?

We compute an approximation x of the number of goals for a given year y with the formula:

x = y % 20 % 9

This is actually a very bad approximation, but it's always less than or equal to the expected value v and never less than v - 9, which allows to encode the difference with a single decimal digit.

y    | y % 20 | x = y % 20 % 9 | v  | v - x
-----+--------+----------------+----+------
1999 |     19 |              1 |  1 |     0
2000 |      0 |              0 |  7 |     7
2001 |      1 |              1 |  3 |     2
2002 |      2 |              2 |  5 |     3
2003 |      3 |              3 |  4 |     1
2004 |      4 |              4 |  7 |     3
2005 |      5 |              5 | 10 |     5
2006 |      6 |              6 |  7 |     1
2007 |      7 |              7 | 11 |     4
2008 |      8 |              8 | 16 |     8
2009 |      9 |              0 |  9 |     9
2010 |     10 |              1 |  4 |     3
2011 |     11 |              2 |  5 |     3
2012 |     12 |              3 |  9 |     6
2013 |     13 |              4 | 13 |     9
2014 |     14 |              5 |  9 |     4

Demo

let f =

y=>+'0723135148933694'[y-1999]+y%20%9|0

for(y = 1997; y <= 2017; y++) {
  console.log(y, f(y))
}


05AB1E, 25 24 bytes

•3ßÎó‚4Ëǝï•17в15ÝƵÊØ+Ikè

Try it online! or as a Test suite

Explanation

•3ßÎó‚4Ëǝï•                 # push the number 69255401071877657848
           17в              # convert to list of base-17 digits
                            # produces the list [1,7,3,5,4,7,10,7,11,16,9,4,5,9,13,9,0]

              15Ý           # push the range [0 ... 15]
                 ƵÊØ+       # add the 303rd prime (1999) to each
                     Ik     # get the index of the input in this list
                            # or -1 if outside the range
                       è    # get the element at that index in first list

JavaScript, 44 Bytes

y=>parseInt("173547a7bg9459d9"[y-1999],17)|0

Tags:

Code Golf