<jupyter_start><jupyter_text>Day 2<jupyter_code>data = pd.read_csv('./day2_input', sep=' ', header=None)
data.columns = ['cond1','cond2','pwd']
data.dtypes<jupyter_output><empty_output><jupyter_text>Part A<jupyter_code>def conv_to_oneint(s1s2, first=True):
    s1, s2 = s1s2.split('-')
    
    if first:
        return int(s1)
    else:
        return int(s2)

data['cond_min'] = data['cond1'].apply(lambda x: conv_to_oneint(x, True) )
data['cond_max'] = data['cond1'].apply(lambda x: conv_to_oneint(x, False) )

data['cond_char'] = data['cond2'].apply(lambda x: x[0])
data['cond_char_cnt'] = data[['cond_char', 'pwd']].apply(lambda x: x[1].count(x[0]), axis=1)
data['valid_pwd'] = data[['cond_min', 'cond_max', 'cond_char_cnt']].apply(lambda x: x[2] >= x[0] and x[2] <= x[1], axis=1)
answer2A=data['valid_pwd'].sum()<jupyter_output><empty_output><jupyter_text>Part B<jupyter_code>data['pos1'] = data['cond_min'] - 1
data['pos2'] = data['cond_max'] - 1

data['check_pos1'] = data['pos1'] < len(data['pwd'])
data['check_pos2'] = data['pos2'] < len(data['pwd'])
data['check_pos2'].sum()
data['valid_pwd_2'] = data.apply(lambda x: (x['pwd'][x['pos1']] == x['cond_char']) != (x['pwd'][x['pos2']] == x['cond_char']), axis=1 )
answer2B=data['valid_pwd_2'].sum()
print(answer2B)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2357910906298003, 'fraction_numerical': 0.0314900153609831, 'mean_word_length': 7.2993630573248405, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, '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}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '413165', 'license': 'MIT', 'n_tokens_mistral': 565, 'n_tokens_neox': 562, 'n_words': 76, 'path': 'day2.ipynb', 'repo_name': 'Paijmans/advent_of_code', 'size': '1302'}