#Pyth - 31 bytes Pretty simple, uses zip and modular indexing to get the switch. The actual calculation is really easy. s@C,Jc"FtBo"2,h/Ksttz2tyKhxJ<z2 [Test suite][1]. [1]: http://pyth.herokuapp.com/?code=s%40C%2CJc%22FtBo%222%2Ch%2FKsttz2tyKhxJ%3Cz2&input=Ft2&test_suite=1&test_suite_input=Bo3%0AFt2%0ABo5%0AFt3%0ABo9%0AFt5%0ABo51%0AFt26%0ABo199%0AFt100&debug=1