My trick for falling asleep is not to count sheep but to think up some puzzle and try and figure it out. Last night I began to wonder how many possible musical phrases can you make from one octave (8 notes). Or for that matter the chromatic scale (13 notes). And if you really want to make it difficult - throw in note durations, say down to a 16th note (but that is way too advanced for me).
At any rate, I began by taking two notes, say A + B. Possible combinations are A+A, and A+B and B+A and B+B. So I figure it's the number of notes to that power, i.e. 2 to the second power. Then I start thinking about 3 notes... It seems to be something like 27 or 3 to the 3rd power... but then I get lost. So is that the correct formula? Would it be 8 to the 8th power? [At that point I have long since reached the land of Nod.]
Now once you throw in rests, and say note durations - whatever the formula is the same, except that each note can be 5 or 6 other notes depending on duration. You'd think at some point people would run out of melodies but the combinations are so numerous. And if you then throw in more octaves...