How can I generate a series of 2s and 3s such that the average of the generated values (so far) is as close to e as possible? For example: 2: avg=2 |2-e| =0.718 2,3: avg=2.5 |2.5-e| =0.218 2,3,3: avg=2.667 |2.667-e|=0.052 2,3,3,3: avg=2.75 |2.75-e| =0.032 Also, how can I *quickly* check if the nth index in the sequence is a 2 or 3?