Exemplo n.º 1
0
 def get_nice_string_count(self) -> int:
     """
     >>> StringSet.from_strings_text(
     ...     "jchzalrnumimnmhp\\nugknbfddgicrmopn").get_nice_string_count()
     1
     """
     return helper.iterable_length(self.get_nice_strings())
 def get_valid_triangle_count(self) -> int:
     """
     >>> TriangleSet.from_triangles_text(
     ...     '5 10 25\\n5 10 15\\n5 10 14').get_valid_triangle_count()
     1
     """
     return helper.iterable_length(self.get_valid_triangles())
Exemplo n.º 3
0
 def get_subset_count_that_add_up_to(self, total: int) -> int:
     """
     >>> Cupboard.from_jugs_text("20\\n15\\n10\\n5\\n5\\n")\\
     ...     .get_subset_count_that_add_up_to(25)
     4
     """
     return helper.iterable_length(self.get_subsets_that_add_up_to(total))
 def get_ip_count_with_ssl(self) -> int:
     """
     >>> Ip7SetExtended.from_ips_text(
     ...     'aba[bab]xyz\\nxyx[xyx]xyx\\naaa[kek]eke\\n'
     ...     'zazbz[bzb]cdb\\n').get_ip_count_with_ssl()
     3
     """
     return helper.iterable_length(self.get_ips_with_ssl())
 def get_ip_count_with_tls(self) -> int:
     """
     >>> Ip7Set.from_ips_text(
     ...     'abba[mnop]qrst\\nabcd[bddb]xyyx\\naaaa[qwer]tyui\\n'
     ...     'ioxxoj[asdfgh]zxcvbn\\n').get_ip_count_with_tls()
     2
     """
     return helper.iterable_length(self.get_ips_with_tls())
Exemplo n.º 6
0
 def get_safe_tile_count(self) -> int:
     """
     >>> Minefield.from_rows_text(
     ...     '.^^.^.^^^^').add_rows(9).get_safe_tile_count()
     38
     """
     return helper.iterable_length(1 for row in self.rows for trap in row
                                   if not trap)
Exemplo n.º 7
0
 def get_subset_count_that_add_up_to_with_size(self, total: int) -> int:
     """
     >>> CupboardExtended.from_jugs_text("20\\n15\\n10\\n5\\n5\\n")\\
     ...     .get_subset_count_that_add_up_to_with_size(25)
     3
     """
     min_size = self.get_minimum_number_of_containers_that_add_up_to(total)
     return helper.iterable_length(
         self.get_subsets_that_add_up_to_with_size(total, min_size))
Exemplo n.º 8
0
def get_bit_count(number: int) -> int:
    """
    >>> # noinspection PyUnresolvedReferences
    >>> [get_bit_count(x) for x in  range(8)]
    [0, 1, 1, 2, 1, 2, 2, 3]
    >>> get_bit_count(2 ** 16)
    1
    >>> get_bit_count(2 ** 16 - 1)
    16
    """
    from utils import helper
    return helper.iterable_length(int_to_bits(number))
Exemplo n.º 9
0
 def get_on_count(self) -> int:
     """
     >>> Life.from_life_text(
     ...     ".#.#.#\\n"
     ...     "...##.\\n"
     ...     "#....#\\n"
     ...     "..#...\\n"
     ...     "#.#..#\\n"
     ...     "####..\\n"
     ... ).step_many(4).get_on_count()
     4
     """
     return helper.iterable_length(filter(None, self.grid.values()))
    def step(self, sequence: str) -> str:
        """
        >>> LookAndSay().step("")
        ''
        >>> LookAndSay().step("1")
        '11'
        >>> LookAndSay().step("11")
        '21'
        >>> LookAndSay().step("21")
        '1211'
        >>> LookAndSay().step("1211")
        '111221'
        >>> LookAndSay().step("111221")
        '312211'
        """
        result = ""
        for content, items in groupby(sequence):
            count = helper.iterable_length(items)
            result += f"{count}{content}"

        return result
Exemplo n.º 11
0
 def get_viable_pair_count(self) -> int:
     return helper.iterable_length(self.get_viable_pairs())