this took an long time but each function is programmed with the exact same logic used in the processor for the counting cirit which runs loops in the computer