state = '##.##.##.##....##.##.##.##.##.##.##.##.##....##.##.##.##.##.##.##.##.##....##.##.##....##.##.##.##.##.##....##.##.##.##.##.##.##.##....##.##.##.##.##.##.##.##.##.##' gens = 50000000000 start_idx = gens - 64 res = 0 for i, pot_val in enumerate(state): pot_id = i + start_idx if pot_val == '#': res += pot_id print(res)