implement solution based on lookup tables