-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.rs
65 lines (59 loc) · 16 KB
/
14.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::collections::*;
static INPUT: [Op; 560] = [Op::Mask(b"X100110110X011000101000101XX11001X11"),Op::Mem(5201,1838761),Op::Mem(32099,25747352),Op::Mem(36565,72187),Op::Mem(31494,369864),Op::Mem(17260,3138),Op::Mem(64903,91484814),Op::Mask(b"0X00100101000XX0011110X10110X100X010"),Op::Mem(54866,120526),Op::Mem(57614,430839),Op::Mem(17916,648),Op::Mem(43192,325890),Op::Mem(23626,313518443),Op::Mem(45988,50484),Op::Mask(b"01001001X0001X00XXX110X010010XX0X001"),Op::Mem(60805,1352),Op::Mem(37516,5942314),Op::Mem(63169,237020309),Op::Mem(31655,274507),Op::Mask(b"010011010001110000010000X101X0X11X01"),Op::Mem(49875,15349586),Op::Mem(6956,13765452),Op::Mem(675,886107857),Op::Mask(b"01000001X1XX11011X1111X111X000X01X11"),Op::Mem(2135,5930),Op::Mem(1861,1009),Op::Mem(62754,145160),Op::Mem(1333,1153712),Op::Mem(15455,7454),Op::Mask(b"01X01X011X0011X0X10110001X1X1000X110"),Op::Mem(53253,667716),Op::Mem(47571,745817),Op::Mem(48582,5810),Op::Mem(3620,7851685),Op::Mem(41836,14080244),Op::Mem(39150,84103),Op::Mask(b"01001X01100X100010X111111X11100XX111"),Op::Mem(249,514),Op::Mem(25687,48545),Op::Mem(62083,208926),Op::Mem(39872,2590),Op::Mem(28491,267),Op::Mem(25340,115744),Op::Mem(31101,6781),Op::Mask(b"0100100100011101000XX001XX0010100X10"),Op::Mem(6053,6291996),Op::Mem(37941,514441),Op::Mem(22984,108425255),Op::Mem(30540,127685),Op::Mask(b"000X100101011X1X1010X1011110XX10X1X0"),Op::Mem(42567,253905),Op::Mem(45241,15790),Op::Mem(57132,480344),Op::Mem(29971,22597051),Op::Mask(b"XXX0111110001100010X1X01X10X0000000X"),Op::Mem(44680,428361054),Op::Mem(17571,4884),Op::Mask(b"X1X001010X0111101X11X100X10100101100"),Op::Mem(55107,2922),Op::Mem(8605,5742),Op::Mem(63754,289191),Op::Mask(b"01101001010X11000110111X11000X01X000"),Op::Mem(48186,7310),Op::Mem(30306,413),Op::Mem(1980,538481),Op::Mask(b"010011011XX011X110011111101X01101X1X"),Op::Mem(45241,11454771),Op::Mem(65349,36152803),Op::Mem(62368,34863),Op::Mem(26794,5220),Op::Mask(b"010X10XXX1001100011101X00X0110011110"),Op::Mem(15496,898),Op::Mem(59847,32170699),Op::Mem(5411,130682),Op::Mem(27017,205172),Op::Mem(48688,3072),Op::Mask(b"001X000X111X110000110XX0010100001110"),Op::Mem(17575,12630818),Op::Mem(51454,28544),Op::Mem(52745,45251),Op::Mask(b"000000010100X110X11101X101X1011010X1"),Op::Mem(49456,637756),Op::Mem(63169,99927),Op::Mem(50318,7599616),Op::Mem(42115,48825),Op::Mem(20469,5931716),Op::Mem(56899,2884),Op::Mask(b"01XX100X0100X10001XX011111X000001XX0"),Op::Mem(45630,2305),Op::Mem(28560,118602807),Op::Mem(45644,52185),Op::Mem(3682,56264),Op::Mem(63201,237495702),Op::Mem(63572,7683),Op::Mem(24477,370),Op::Mask(b"01X0X0XX0X011100011110000X0XX00X1111"),Op::Mem(14028,3492),Op::Mem(28452,213847),Op::Mem(57663,203516),Op::Mem(24701,45071697),Op::Mem(30226,856135),Op::Mem(59279,100557),Op::Mask(b"0110100001X0X1X0010XX1XX00X100000000"),Op::Mem(4237,60693),Op::Mem(51454,56389),Op::Mem(44364,12145),Op::Mem(53190,3825966),Op::Mask(b"0X0010000X011X0011111001100010X10100"),Op::Mem(45988,84435),Op::Mem(43613,171165),Op::Mem(39150,2025),Op::Mask(b"000001010X111100111101001000X00X000X"),Op::Mem(7204,243074994),Op::Mem(30540,2829011),Op::Mem(16986,171341),Op::Mask(b"01101X0101001X101X1111110X0X01X0010X"),Op::Mem(40006,276307),Op::Mem(50601,45),Op::Mem(2907,7955),Op::Mem(61049,14014170),Op::Mem(20722,52156072),Op::Mem(12299,1701485),Op::Mem(4643,2041760),Op::Mask(b"X1101000010X110X0111X011001101000000"),Op::Mem(29309,29638912),Op::Mem(23626,127552394),Op::Mem(39357,2743410),Op::Mask(b"XXX01000000110001111101X101X1XX0XX01"),Op::Mem(32322,110798340),Op::Mem(38758,20398089),Op::Mem(62368,6402),Op::Mem(12381,125762),Op::Mem(34042,46630),Op::Mask(b"0X1X100X0X01100X11X11111101100100001"),Op::Mem(56680,52806),Op::Mem(3416,5097254),Op::Mem(21217,959),Op::Mem(11134,22705),Op::Mem(39515,607),Op::Mem(31858,527794383),Op::Mask(b"011110010100X10001110111X0XXX00110X1"),Op::Mem(37752,3783),Op::Mem(27543,180509),Op::Mem(56503,26998899),Op::Mem(33984,2996098),Op::Mem(6471,16602683),Op::Mem(18585,5056811),Op::Mem(3477,16274),Op::Mask(b"010110011XXX110X01011XX11X0100110X00"),Op::Mem(43993,784),Op::Mem(12295,412860764),Op::Mem(62707,11253),Op::Mem(27017,1813664),Op::Mask(b"1XX0X001010X1010101100X000X0100XX000"),Op::Mem(25364,640),Op::Mem(35537,489258314),Op::Mem(356,47335),Op::Mem(46814,130),Op::Mem(21071,32074),Op::Mem(23980,1969160),Op::Mem(43457,28765451),Op::Mask(b"0X0XX00110XX1X00X10111110011X01X1001"),Op::Mem(37516,3409),Op::Mem(32451,486160),Op::Mem(31704,494261),Op::Mem(64905,489121330),Op::Mask(b"10001001X101111010X010X1X11X1001010X"),Op::Mem(19927,125979),Op::Mem(16164,163616),Op::Mem(41291,11806544),Op::Mem(13074,22666),Op::Mem(65160,1102),Op::Mem(21338,53735104),Op::Mask(b"00X00101X10111XX111101XX10X111111100"),Op::Mem(44736,13061),Op::Mem(62844,31422),Op::Mem(4643,59264),Op::Mem(45417,5454),Op::Mask(b"X0001X010X001101011X11001XX000101000"),Op::Mem(33984,13200),Op::Mem(15462,316464),Op::Mem(2638,1434216),Op::Mem(29044,1370180),Op::Mem(57663,77699993),Op::Mem(39191,9595034),Op::Mask(b"100X1X0X010111X011101011111111XX1000"),Op::Mem(60509,275540),Op::Mem(65073,8066),Op::Mem(64726,78129),Op::Mem(15719,724),Op::Mem(52499,43989105),Op::Mem(57518,6805488),Op::Mem(27827,1522993),Op::Mask(b"0X010110X011X100111X00000111X1110X10"),Op::Mem(395,16602),Op::Mem(21477,62043769),Op::Mem(24630,663408947),Op::Mem(3983,31082032),Op::Mem(30545,456250),Op::Mask(b"0100XX01X000X10X10011101100X11101X10"),Op::Mem(28174,110183887),Op::Mem(9644,12911),Op::Mem(62113,145),Op::Mask(b"010010X10000100100110000101X1XX11011"),Op::Mem(63016,127052),Op::Mem(49130,37),Op::Mem(25394,187810),Op::Mem(29779,11708792),Op::Mem(36144,1033),Op::Mask(b"00101001X10XX10X11111X1100000111X001"),Op::Mem(35746,498408),Op::Mem(15462,7839193),Op::Mem(5741,168870),Op::Mask(b"0010100100X011XX1111X1001001X1X10101"),Op::Mem(2256,10474689),Op::Mem(57428,8228),Op::Mem(34062,16609889),Op::Mem(45031,106065),Op::Mem(17162,138367053),Op::Mem(23302,14262),Op::Mask(b"001100110X1X11XX110100X0010100XX1000"),Op::Mem(33186,1012027),Op::Mem(34051,148436),Op::Mem(4762,25019364),Op::Mem(41825,102071658),Op::Mem(32580,739),Op::Mem(15455,151015),Op::Mask(b"01X1XX00X10001000100011001000000XX10"),Op::Mem(31330,300785),Op::Mem(30222,206857068),Op::Mem(27739,774225),Op::Mem(47798,12155),Op::Mem(57437,440075165),Op::Mem(49892,58),Op::Mem(44723,116116),Op::Mask(b"100X1X00000X100011X1X00100101X00010X"),Op::Mem(35368,5187),Op::Mem(24769,1425443),Op::Mem(62844,277),Op::Mem(30729,11517370),Op::Mask(b"0110100X0010110111X10X111000X11011X1"),Op::Mem(63295,139),Op::Mem(60805,381899),Op::Mem(6956,3979616),Op::Mem(12295,1828),Op::Mask(b"010010X10X00X00X00X11XX00001X1001X00"),Op::Mem(39150,459766),Op::Mem(52621,1962),Op::Mem(11891,5261559),Op::Mask(b"X11011X11X00110001011X1X110010000000"),Op::Mem(48473,3539),Op::Mem(13808,331),Op::Mem(30016,676),Op::Mem(9736,3140258),Op::Mem(12233,388562584),Op::Mem(42686,1048145655),Op::Mem(26132,67723),Op::Mask(b"01001X0X010X0001001X10101111X10110X1"),Op::Mem(35042,230878861),Op::Mem(8611,488144),Op::Mem(4290,942073),Op::Mem(12381,17121117),Op::Mem(15011,225),Op::Mem(8378,9255),Op::Mask(b"00001X0XX01X11X01101001101011110101X"),Op::Mem(49708,312037855),Op::Mem(19488,93439469),Op::Mem(57113,7931),Op::Mem(29037,210754),Op::Mask(b"0100X001X0X01X0100110X11X110001110X1"),Op::Mem(8519,38940),Op::Mem(49033,10564),Op::Mem(58481,4187786),Op::Mem(5201,230275712),Op::Mem(39296,886),Op::Mask(b"1000100X010X11101X1011011X0110X11XXX"),Op::Mem(38587,50240362),Op::Mem(42581,116256847),Op::Mem(37181,4441034),Op::Mem(16281,23027479),Op::Mem(32451,71649158),Op::Mem(33316,6511),Op::Mask(b"000001X11101111011X1X10X1X001X1X1000"),Op::Mem(26168,390),Op::Mem(11548,29301),Op::Mem(2731,3188615),Op::Mask(b"1100XX00X0X110001X111X000011X0X10001"),Op::Mem(32136,6436),Op::Mem(46206,225594),Op::Mem(33132,7862942),Op::Mem(15264,198),Op::Mask(b"01001001000X1101000111011X0011XXX10X"),Op::Mem(33733,14993993),Op::Mem(9905,246637292),Op::Mem(6373,2090),Op::Mem(53539,29386),Op::Mask(b"0X1010X1X01011XX11111100100XX110X00X"),Op::Mem(41520,452041),Op::Mem(8605,43647),Op::Mem(62764,3241680),Op::Mask(b"0X1X10X1010111X0X1110XXX00000110X001"),Op::Mem(38517,3338),Op::Mem(52745,4455),Op::Mem(33218,850605),Op::Mem(20495,315451),Op::Mask(b"0XX0X001010X11X01X111X1101X11X101000"),Op::Mem(32284,615642818),Op::Mem(62844,46924),Op::Mem(31120,146622),Op::Mem(21925,518931),Op::Mem(29515,1112),Op::Mem(31241,130404),Op::Mem(9905,5469165),Op::Mask(b"01101000001X110X1101101110XX1X1XX101"),Op::Mem(46432,346428972),Op::Mem(64522,218092103),Op::Mem(42311,2316477),Op::Mem(20060,565),Op::Mem(62919,261004),Op::Mem(50103,42134),Op::Mask(b"0101100101000100X1X01XX11X0X00111010"),Op::Mem(41199,48367827),Op::Mem(40992,886149),Op::Mem(19927,93429),Op::Mask(b"01001X01X0XX110X0XX1110X011110001101"),Op::Mem(40019,187824261),Op::Mem(3416,35491),Op::Mem(51276,173825792),Op::Mask(b"X100100110001X000X11010X00001010X001"),Op::Mem(21071,3775434),Op::Mem(41466,601899),Op::Mem(29191,163888869),Op::Mem(64981,1094832),Op::Mem(36745,7560),Op::Mem(44434,3179),Op::Mem(5040,16142),Op::Mask(b"0X101X011XX011111111010100010X0X01X0"),Op::Mem(44140,22478),Op::Mem(26863,31310307),Op::Mem(56680,131716),Op::Mem(3983,22050),Op::Mask(b"1X0X10010X011X1X101X1000X1100X000010"),Op::Mem(45724,5130),Op::Mem(38747,147724),Op::Mem(39515,58764331),Op::Mask(b"0X001101X10000010X1X00010XX001010101"),Op::Mem(50201,65493),Op::Mem(44879,7688011),Op::Mem(29782,85876639),Op::Mem(63157,57556),Op::Mask(b"00X00001010111X010X1X01X0101X01010XX"),Op::Mem(37667,539),Op::Mem(65058,928398),Op::Mem(16037,2162946),Op::Mask(b"X010100000X11X001111001011011001XX11"),Op::Mem(20601,689238135),Op::Mem(62832,22132331),Op::Mem(20030,421255),Op::Mem(38454,4898563),Op::Mask(b"01101XX0000111X001111100011000X01111"),Op::Mem(40968,287372),Op::Mem(32860,121630361),Op::Mem(6956,54910),Op::Mask(b"01101001100X11X0010X0101101010001X11"),Op::Mem(52270,852273185),Op::Mem(44434,5773),Op::Mem(40591,363113),Op::Mem(31075,550),Op::Mem(1148,237482),Op::Mask(b"0110100000001100X111X111111010X00X10"),Op::Mem(9807,919),Op::Mem(10050,284353),Op::Mem(11553,99307),Op::Mask(b"11X1X0X0010001000101100X1XX10X100X10"),Op::Mem(51707,59769),Op::Mem(17916,456671254),Op::Mem(15968,74716184),Op::Mem(61681,11534),Op::Mask(b"0X0010010000110X01X1X111X001X111100X"),Op::Mem(63572,19584),Op::Mem(12382,54348210),Op::Mem(7204,62681),Op::Mem(58309,718),Op::Mask(b"XX0X0X11X0XX1100X10110111101X1000101"),Op::Mem(19172,49321),Op::Mem(3972,156574486),Op::Mem(53411,371993),Op::Mem(34118,1245490),Op::Mem(63786,28834),Op::Mem(44434,1679),Op::Mask(b"0X010XX1101111001101110X1X0X1X1000X0"),Op::Mem(65433,41829624),Op::Mem(5383,3874764),Op::Mem(58309,40586),Op::Mem(34516,1861),Op::Mask(b"0X00100X000X1100111X0011100010011100"),Op::Mem(30691,6349),Op::Mem(26045,2259746),Op::Mem(35285,2525303),Op::Mem(56918,64290918),Op::Mem(34521,495146),Op::Mem(41173,1892852),Op::Mem(62708,2610505),Op::Mask(b"X1001000010XX10001011X10101000011000"),Op::Mem(41877,606935473),Op::Mem(10746,30201),Op::Mem(7236,2402617),Op::Mem(31075,394149597),Op::Mem(62893,2808512),Op::Mem(44723,5738170),Op::Mem(61147,2124552),Op::Mask(b"01X0100X0X0X1100X1111X11X00X01X01001"),Op::Mem(9905,376),Op::Mem(56967,457904468),Op::Mem(55040,2448),Op::Mem(65513,2222),Op::Mem(25340,23079),Op::Mem(39876,4874),Op::Mem(38909,16667453),Op::Mask(b"X0001X0X01011110101X10XX1X1X10X01100"),Op::Mem(19488,3061762),Op::Mem(26132,292794),Op::Mask(b"010010X101X01001001110X000X1011X11X0"),Op::Mem(1980,12162025),Op::Mem(37165,15333747),Op::Mem(39210,152686),Op::Mask(b"01X010X0010XX100011110000X000XX00101"),Op::Mem(27917,944976),Op::Mem(25099,11114),Op::Mem(7777,577171),Op::Mem(27080,16334871),Op::Mem(14285,531),Op::Mask(b"X1X0100001X01100X10X1111100X00111010"),Op::Mem(28216,2511),Op::Mem(37165,7141),Op::Mem(55924,439753),Op::Mem(11901,464),Op::Mem(38571,407),Op::Mem(782,10823),Op::Mask(b"0XX00X01010111XX11111110XX010010000X"),Op::Mem(54749,360481),Op::Mem(20495,5280),Op::Mem(37684,6039),Op::Mem(6345,2073116),Op::Mem(63110,22301539),Op::Mask(b"X0X1010110111100110X1001100X1X100100"),Op::Mem(20722,9600365),Op::Mem(19084,76987),Op::Mem(23777,740859),Op::Mask(b"001X000111X01X000X11X000110111101100"),Op::Mem(27917,52797296),Op::Mem(57636,322),Op::Mem(11553,70582),Op::Mem(8605,30966411),Op::Mem(25394,812862),Op::Mem(48296,317),Op::Mem(60466,1411129),Op::Mask(b"X110000X0XXX11101111001X100110100000"),Op::Mem(33339,4981),Op::Mem(40073,5710720),Op::Mem(33814,13208),Op::Mem(14664,1950645),Op::Mem(35042,35994943),Op::Mask(b"10101000X0X1X0XXX1X1101011001100000X"),Op::Mem(61417,114327),Op::Mem(26863,706549),Op::Mem(5651,118955),Op::Mask(b"011X10000010110111X10111X1001100101X"),Op::Mem(7679,272716),Op::Mem(24077,12277996),Op::Mask(b"X11XX000010001X00X011X1111X001XX0000"),Op::Mem(46531,35092779),Op::Mem(1116,11777757),Op::Mem(5932,519743),Op::Mem(36187,318),Op::Mem(38758,718897339),Op::Mask(b"01001X0110001000X0010X010010X01000X0"),Op::Mem(31101,257),Op::Mem(39813,30972074),Op::Mem(23252,1761211),Op::Mask(b"0X10100X00X0110X1111X1111010X1001101"),Op::Mem(17132,2823025),Op::Mem(62368,442239906),Op::Mem(24553,339245),Op::Mem(64751,66303),Op::Mem(56967,870173),Op::Mem(15383,342572184),Op::Mem(1647,20517),Op::Mask(b"00001XX000X11X0011X110X110XX1X010101"),Op::Mem(16037,1478),Op::Mem(33316,30615219),Op::Mem(6729,209640491),Op::Mask(b"01001000X1X1X100X1110100000X1X011X01"),Op::Mem(62368,29355190),Op::Mem(48784,1522851),Op::Mem(26590,14698075),Op::Mask(b"0XX0X0011X00X0000X11011010011110X101"),Op::Mem(249,746),Op::Mem(11553,236505210),Op::Mem(38328,823888),Op::Mem(58433,125568672),Op::Mask(b"X000X0000101X1101X10110X000X00111100"),Op::Mem(37813,4058843),Op::Mem(32745,9417061),Op::Mask(b"000XX110001111X01XX1XX01X00111110100"),Op::Mem(22103,2397),Op::Mem(40229,47978173),Op::Mem(3477,14703),Op::Mem(8594,2471),Op::Mem(22603,44648051),Op::Mem(11340,25471),Op::Mask(b"000001X1010111001X11X1X1100XX0101X0X"),Op::Mem(41160,52),Op::Mem(2907,827),Op::Mem(15719,107392281),Op::Mem(43537,19084747),Op::Mem(53742,3326211),Op::Mem(46206,51870),Op::Mem(30694,6031208),Op::Mask(b"0X10100000011100111X11100010X1111X01"),Op::Mem(31885,3110667),Op::Mem(40041,30422),Op::Mask(b"00XX0XX101X111XX11X10111001101001000"),Op::Mem(2874,10110),Op::Mem(21776,28380745),Op::Mem(32004,7076),Op::Mem(9644,526),Op::Mask(b"011010110001X1000XX110X0X0110000X011"),Op::Mem(35281,4670),Op::Mem(7204,115940579),Op::Mem(58380,17616),Op::Mem(40735,46877007),Op::Mem(30986,20371),Op::Mask(b"0XX01001010010X100111010110001111X10"),Op::Mem(43046,2060276),Op::Mem(20743,553391345),Op::Mem(20821,3685352),Op::Mem(43943,39969),Op::Mask(b"0010100101010X0011XXX01XX100XXX11111"),Op::Mem(29261,60453),Op::Mem(63512,94339357),Op::Mem(34827,18871625),Op::Mem(52359,322200),Op::Mem(38003,25491),Op::Mem(24795,461240689),Op::Mask(b"0000010X01011100101X010100X1X1101010"),Op::Mem(26894,3512),Op::Mem(1023,9354),Op::Mask(b"11010XXX100011001101011X1111011001X1"),Op::Mem(45476,4571),Op::Mem(2838,7601404),Op::Mem(30540,187),Op::Mask(b"X1X01X01X000110001011X010X0111X01001"),Op::Mem(32944,381053),Op::Mem(63110,7479218),Op::Mem(59783,121082),Op::Mem(56918,1237706),Op::Mem(32355,472),Op::Mem(44080,131839645),Op::Mem(56680,38523)];
#[derive(Clone,Copy)]
enum Op {
Mem(usize, usize),
Mask(&'static [u8]),
}
fn part_one() -> usize {
let mut mem = HashMap::new();
let mut mask: &[u8] = b"";
for &op in &INPUT {
match op {
Op::Mem(addr, mut v) => {
for (i,c) in mask.iter().rev().enumerate() {
match c {
b'0' => v &= !(1 << i),
b'1' => v |= 1 << i,
_ => {}
}
}
mem.insert(addr, v);
}
Op::Mask(m) => mask = m,
}
}
mem.values().sum()
}
fn write(
mem: &mut HashMap<usize, usize>,
mask: &[u8],
v: usize,
i: usize,
addr: usize,
) {
let bit = 1 << (35 - i);
match mask.get(i) {
Some(b'0') => write(mem, mask, v, i+1, addr),
Some(b'1') => write(mem, mask, v, i+1, addr | bit),
Some(b'X') => {
write(mem, mask, v, i+1, addr);
write(mem, mask, v, i+1, addr ^ bit);
}
_ => { mem.insert(addr,v); }
}
}
fn part_two() -> usize {
let mut mem = HashMap::new();
let mut mask: &[u8] = b"";
for &op in &INPUT {
match op {
Op::Mem(addr, v) => write(&mut mem, mask, v, 0, addr),
Op::Mask(m) => mask = m,
}
}
mem.values().sum()
}
aoc2020::main! {
(part_one(), part_two())
}