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: 3: avg=3 |2-e| =0.282 3,2: avg=2.5 |2.5-e| =0.218 3,2,3: avg=2.667 |2.667-e|=0.052 3,2,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?