2018-12-02 - Inventory Management System
(original .ipynb)# Part 1 box_id_input = [ "lnfgdsywjyleogambzuchirkpx", "nnfqdskfjyteogambzuchirkpx", "lnfqdvvwjyteofambzuchirkpf", "lnfqdsvwjyteogvmbzuthirkpn", "ltfqdsvwjyoeogambxuchirkpx", "lnfqcsvwjytzogacbzuchirkpx", "lpfpdsvwjyteogambyuchirkpx", "pnfqdsvwjyteogqmbzuchinkpx", "lnfqdsvwjytyopambzpchirkpx", "lnfqisswjyteogadbzuchirkpx", "lnfqdsuwjcteogambzuchirepx", "lnfqdovwjnteigambzuchirkpx", "lnfbdsvwjxteogambzuchirkax", "lnfqdsawjyteogamxzuchiwkpx", "lncqdsvwjoteogambzuchirfpx", "lnfadsrwjyteogambzuchirktx", "lnfqdsvhjyteorazbzuchirkpx", "lwfqdsvwjytdogambzuchirkhx", "lnfqdhvwjyteogambzuhairkpx", "lnfqdsvwjytlogambzgchyrkpx", "lnfqdsvwjyteogamnzjwhirkpx", "lnfodsvwjyteogahuzuchirkpx", "lnfqdsvtjyteogamvzwchirkpx", "lnfqdsvwjzueogambzuxhirkpx", "lnfqxsvljytxogambzuchirkpx", "lnfqdsvwjyteogambpyvhirkpx", "lqzqdsvwjnteogambzuchirkpx", "lnfqdsvwjyteogumbzichirapx", "lnfqdbvwjytedgaubzuchirkpx", "lnfqdsvwpyteogabbhuchirkpx", "nnfqdsvwryteogambzuchiwkpx", "lrfqdsvwjeteogambzuchhrkpx", "lnfqdsvwxyteogamtzucyirkpx", "lnfsdsvwjyteogambzulhirknx", "lnfqdsvwjyreoyambzmchirkpx", "ltfqdsvwjytdogkmbzuchirkpx", "lnfqwbvcjyteogambzuchirkpx", "lnfqdsvwjyteogamrzfchirmpx", "lnfqdsvwjqteogambzucwirkpy", "lnfqdslwjyfeogambzuchikkpx", "lnfqdsvwjybeogambzuchikjpx", "lofqysvwjyteogasbzuchirkpx", "lnfqusvwjyteogambzucverkpx", "lnfqdsvwjyteogaibzuchfrkzx", "lnfqdsvwjyleogabbzuchirkcx", "lnfqdsvqjyteogambzuchdqkpx", "lnfqdsvwjwtewgambzuciirkpx", "lnfqisvwjatwogambzuchirkpx", "lnfqdgvwjyteogambzuchizkix", "lnfqdsxwjyteogambyuehirkpx", "lpffdsvwjyteogamrzuchirkpx", "lnirdsvwjyteogambzuchirkbx", "lnfqdsxdjyteogazbzuchirkpx", "lnfgdgvwyyteogambzuchirkpx", "lnfqxsvwjyteogambzmcwirkpx", "lnxqjsvwjyteogambzuchirkqx", "lnrqdsvwjpteogkmbzuchirkpx", "lnfqdstwjyteoeahbzuchirkpx", "lnfqdsvwtuteogambzuchixkpx", "lwfqvsvwjyteogambzughirkpx", "lnkqdsvwjyfeogambzuuhirkpx", "lvvqdsvwjyteogambzuchirkpn", "jndqdsvwjyteogzmbzuchirkpx", "enfqdszwjyteogambcuchirkpx", "lnfqdsvwiyteogakbauchirkpx", "lnfqdsvwjyteogtmbzxcdirkpx", "fnfqdswwjyteogawbzuchirkpx", "lnfqdsvwjydejqambzuchirkpx", "lnqqdsvwjyteogambzucbdrkpx", "lnfqdsvwjyteogadbzuchirxcx", "lnfqdslwjyyeogambzulhirkpx", "lnfqdsvwjytecgambzucgirkpb", "lbmqdsvwjyteogamkzuchirkpx", "lbfqdsvrjyteogambzuchirapx", "lnfqdsmwjyteogambzucfarkpx", "lnfqasvwoyteofambzuchirkpx", "bnfudsvwjyteogambzucharkpx", "lnfrdsvwjytxogambzuchirkpg", "lbfqdsvwjyteagambzucdirkpx", "lxfqdsvwjytuogambzucjirkpx", "lnfqdsvwjcteogamyzuchiikpx", "lnfodsvwjyteognmbzuchirapx", "ltfqdsvwjytedgaxbzuchirkpx", "lnfqdshwjyteogambzucsilkpx", "lnfqdsvwpyteohambzuchitkpx", "wnzqdsvwjyteogambiuchirkpx", "lnfqdsvwayteogambzhchirkpw", "ltfqcsvwjrteogambzuchirkpx", "lnfqdsvwaytekgamvzuchirkpx", "lnfqdsvwjyteogambzokpirkpx", "lnfqysbwjyeeogambzuchirkpx", "lnsqdsvwjyteogambzuchikkpd", "lrfqdsvwjyteogahbzochirkpx", "lnfqdsvwjyreoggmbzuchjrkpx", "lxfqdsvwjyteogkmbzuchirkpp", "enhqdbvwjyteogambzuchirkpx", "jnfqdsvwjyteogamczuuhirkpx", "lnfqdsvwuyteogadbzuchirkpw", "lnfqdsvjjytergambznchirkpx", "lnfqdsvwjyteoglmbzuceijkpx", "lwfqdsvwjyteogamieuchirkpx", "lnfqdsvwjfaeogambzqchirkpx", "lfbqdjvwjyteogambzuchirkpx", "lnfqdsvwjxteoaambzuchirkpp", "lnfqdsvwjyheogjmbzgchirkpx", "lnfqdskwjyteonambzuchiikpx", "lnfqdwvwjyteogambxuchirkph", "pnfqdsvwdyteogambzuchihkpx", "lnoqdsvwjyteogaybznchirkpx", "lnfqdsvwfyxefgambzuchirkpx", "lnfqdsvwjyteotamxzmchirkpx", "lnfqdsvwjyteigwmbzuchivkpx", "lnfqdsvwjytekgambcuchirkwx", "lnfqdsvwjuteogamrzulhirkpx", "lnfqdsvwjyteogambzucczrgpx", "wnfqzsvwjyteogambduchirkpx", "lnfqdsowjyteogambuuthirkpx", "lnfqdsvrjyteogcmbzuclirkpx", "knfqdsvwgyteogambzuchorkpx", "lnaqdsvwjytuogdmbzuchirkpx", "lnfrdsvwjyteogambluchigkpx", "lnfqqzvwjyteogambzkchirkpx", "lnfqdsvwjyteogamuzuchgrkux", "lnfqdsvnjyteogxmbznchirkpx", "lnfqdsvwjyteolajbzuchdrkpx", "lnfqdsvwjypeoiagbzuchirkpx", "lnrqdsvwjyteozamuzuchirkpx", "lnfqdsvwjytkogaubzucqirkpx", "lnkbdsvwjyteogacbzuchirkpx", "unfqdsvwjybeogambwuchirkpx", "lnfqfsvzjyteogambzuchiikpx", "lnfqdsvgjyreogahbzuchirkpx", "lnfqdsewjyteogavbeuchirkpx", "lnfqdsvwjdteogambbuchidkpx", "lnfqdsvwjythogambzcchirkvx", "lnfqdscwjyteorambzuchirgpx", "cnfqdzvwjyteogambzushirkpx", "lnfgdsgwjytedgambzuchirkpx", "lnfqdsvwbyteogimbzuchdrkpx", "lnfqdsswjyteogambzuohbrkpx", "lnfqdsvwjytqogabbzachirkpx", "lnfqdsvwjyteogmmbzucqiukpx", "lnfxdsrwjyteogambzuchnrkpx", "lnfqnqvwjyteogambzuchiwkpx", "lffqisvwjyteogambzulhirkpx", "lnfqdsxwjydeogambzucfirkpx", "lnfqdsvwjyteogambzucjirkrp", "lnfqdsnqjyteogambduchirkpx", "fnfqdmvwjyteogamlzuchirkpx", "lnfqvsvwjyteooamdzuchirkpx", "lnfqdsvcyyteogambzuchickpx", "onfqdsvwjyqeogambzuchirqpx", "znfqdcvwjyteoaambzuchirkpx", "lnfqdsvwjzteogambzuchidklx", "lnfqjsvwjyteogjmbzuchirkpv", "lnfqdsvwjytgorambzuchirppx", "lzfqdsvwpfteogambzuchirkpx", "lnfidsfwjyteogapbzuchirkpx", "lnfodsvwbyteobambzuchirkpx", "lnlqdsvwjytefgambzuchfrkpx", "lnkqdsvwjyteogambzkchgrkpx", "tnfqdsvwjyteoiamhzuchirkpx", "lnfqdsvwjyteogamllschirkpx", "lnfqdsvwjmthogamizuchirkpx", "lnfqdbvwjyteogafbzuchirkpb", "lnfxosvwjyteogahbzuchirkpx", "lnmqdsvwjyzeogambzuchirkcx", "lnfqdevbjytxogambzuchirkpx", "lnfqdsvwjyteogamzzudhipkpx", "lnfqdszwjyteoqambzuchirkpp", "lffqdsvwjyteogamtouchirkpx", "lnfqdsvhjytfogambzucharkpx", "hnfqdsvwjyteogembzschirkpx", "lnfqdsvwjateogambzuchirmpa", "lnfqdsvcjyteogambzocairkpx", "lnfqdsvwjyteogamwzmchirkpd", "lnfqzsvwjyteogdmbzuyhirkpx", "lnfqdsvwjytfyglmbzuchirkpx", "lnfndsvwjyteogambzuchirktf", "gnfqdnvwjytevgambzuchirkpx", "lnfqdsvwjyteoganbpuchorkpx", "lnfpdsvwnyteogambzucqirkpx", "fnfqdstejyteogambzuchirkpx", "lnfqlsvwjyteowambzuchirkmx", "lnfqdsvwjyteogmmdzuchtrkpx", "lnfqdsvwcyteogaqbzuchirkqx", "lnfqdsvwjytlogtmbzuchiwkpx", "lnfqdsvwoyteogambzuczirkwx", "lnfqdsvwjyteogzybzucdirkpx", "lnfqdvvwjyteogumbzuchiukpx", "lnfqbwvwjyteogambzuchjrkpx", "lnfgdsvwjyteogambzvchirkzx", "lnfqdsvwjvtjogambzuchiokpx", "lnfedsvwjyteogambzuchivkph", "lhfqusvwjytaogambzuchirkpx", "lnfqdsvwjyteogacbzuihirkpv", "lnfwdsvwjyteogambzucokrkpx", "lnfqtsvwjpteognmbzuchirkpx", "anfqdswwjyteogambzucairkpx", "lnfqdsvwjyteorambzuchirlsx", "lnfqdsvwjytgogambzychirkpc", "lnfqdhvwjyteogambzachirklx", "lnfwdsvwjyteogaobquchirkpx", "rnfqdsvwjiteogambzuhhirkpx", "lnfqdsuwjyemogambzuchirkpx", "hnfqdsvwjyteogambzuchprfpx", "anfqssvwjyteogambzumhirkpx", "lnfkdsvwjyteogafbzqchirkpx", "lnfqdsvwjyteogacqzuchirspx", "lnfqdskwjyteggambzuchiakpx", "lnnqdsvwjyteooambzuchihkpx", "lnlqdsvjjyteogambzuchgrkpx", "lnfqdsvwjyteogamszochirkex", "lnfqbsvwjyteogambzqchirepx", "lnfqdsbwjcteogambzhchirkpx", "lnfqdwvzjyteogambzechirkpx", "ynfadsvwdyteogambzuchirkpx", "tnfqdsvwjytuogambzuohirkpx", "lnfqdsvwjyteogambzaohivkpx", "mnfqisvwjyteogagbzuchirkpx", "lnfqbsvwjyueogambzuchirkhx", "ynfqdsvwjyteogdmbzuchinkpx", "lnfqdwhwjyteogambzuchirqpx", "mnfqdsvwjyteogambzfchkrkpx", "lnfqdsnwjyteogambzgchiqkpx", "lnfqdsvwjytergambzuchiuklx", "lnfqdqvjjyteogamtzuchirkpx", "lnfqdscwjyteorambzuchzrgpx", "enfqdevwjyteogaabzuchirkpx", "gnfqdsvbjyteogambzuchirkph", "lnfqdxvwjyteogambzubhixkpx", "lnfqdsvwjyteogambojchihkpx", "lnfqdsvwjytdogambzuzhilkpx", "lnfqdsvwjyteogamezuqhirtpx", "tnfhdsvwjyteogambzuvhirkpx", "lnfzdsvwjnteogahbzuchirkpx", "lnfqdsvwjyteogambzfzhirkvx", "lnfqqsvwjyteogambzuchirgpo", "lufqpsvwjythogambzuchirkpx", "lnfqdsvwjyteogzmbzuchimkix", "lnwqdspwjyteogambzcchirkpx", "lnfqdsowjyteogambzuchigypx", "lnfqdnvvjyteogambzucjirkpx", "lnfjdsvwryteogambzuchirkcx", "lnfqdsvwbyteogambzuchirfpb", "lnfqdsvwjyheogambzxchprkpx", "lnfqmsvwjytezgambzuchirlpx", "lnaqdsvwjyteogamdzuzhirkpx", "lnoqdsvwjytebgambfuchirkpx", "lnfqdtvwjytvogambzuchirkpv" ]
# Part 1 def calc_csum_digit_occurrences(box_id): occ = {} for digit in box_id: if digit in occ: occ[digit] += 1 else: occ[digit] = 1 return set(filter(lambda n: n == 2 or n == 3, [ occ[key] for key in occ ])) def csum(box_ids): occurrences = [ calc_csum_digit_occurrences(box_id) for box_id in box_ids ] twos = len([ occ for occ in occurrences if 2 in occ ]) threes = len([ occ for occ in occurrences if 3 in occ ]) return twos * threes print(csum(box_id_input))
7936
# Part 2 def fst(pair): return pair[0] def snd(pair): return pair[1] def box_id_diff(box1_id, box2_id): diff = [ p for p in zip(box1_id, box2_id) if fst(p) != snd(p) ] if len(diff) == 1: print("".join([ fst(p) for p in zip(box1_id, box2_id) if fst(p) == snd(p)])) for i, box_id in enumerate(box_id_input): for other_box_id in box_id_input[i:]: box_id_diff(box_id, other_box_id)
lnfqdscwjyteorambzuchrgpx