<commit_before><commit_msg>Count of substrings<commit_after>import unittest
"""
Given a binary string, count the number of substrings starting and ending in 1.
Input: 00100101
Output: 3 (100101, 1001, 101)
"""

"""
Approach:
Damn! Nice trick.
1. Count the number of 1s in the string. Let this be m.
2. Return m(m-1)/2.
3. That's nothing but C(m,2). That is all possible pairs of 1s in the string. Each pair corresponds to
starting and ending of a substring.
"""


def count_substrings_starting_and_ending_in_1(binary_string):

    count_of_1s = binary_string.count(1)
    return count_of_1s * (count_of_1s - 1) / 2


class TestCountSubstrings(unittest.TestCase):

    def test_count_substrings(self):
        binary_string = [1, 0, 0, 1, 0, 0, 1, 1, 0, 0]
        self.assertEqual(count_substrings_starting_and_ending_in_1(binary_string), 6)
{'fraction_non_alphanumeric': 0.09869203329369798, 'fraction_numerical': 0.059453032104637336, 'mean_word_length': 4.329113924050633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3128482', 'n_tokens_mistral': 328, 'n_tokens_neox': 285, 'n_words': 96}