Not all number sequence puzzles can be solved with a simple function. Sometimes you come across a sequence that you are expected to be familiar with already, in a disguised form. A very simple example:
31, 28, 31, 30, 31, ?
The answer, clearly, is 30, the number of days in the month of June. The sequence you are expected to recognise is the months of the year, 'disguised' by representing each month by the number of days it has.
This is a good thing to have in your repertoire of 'things to try' when faced with these puzzles. Here's an example of a harder one:
3, 3, 5, 4, 4, ?
Look away now if you don't want to know the answer which is below in very small writing:
3. They're the number of letters in the words 'one', 'two', 'three' and so on, and there are three letters in the word 'six'.