diff --git a/2024/day22_monkey_market/Cargo.toml b/2024/day22_monkey_market/Cargo.toml new file mode 100644 index 0000000..7a78460 --- /dev/null +++ b/2024/day22_monkey_market/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "day22_monkey_market" +version = "0.1.0" +edition = "2021" + +[dependencies] + +[dev-dependencies] +# criterion = "0.5.1" + +[[bench]] +name = "test_benchmark" +harness = false diff --git a/2024/day22_monkey_market/challenge.md b/2024/day22_monkey_market/challenge.md new file mode 100644 index 0000000..eb7cfe9 --- /dev/null +++ b/2024/day22_monkey_market/challenge.md @@ -0,0 +1,148 @@ +As you're all teleported deep into the jungle, a [monkey](/2022/day/11) steals The Historians' device! You'll need get it back while The Historians are looking for the Chief. + +The monkey that stole the device seems willing to trade it, but only in exchange for an absurd number of bananas. Your only option is to buy bananas on the Monkey Exchange Market. + +You aren't sure how the Monkey Exchange Market works, but one of The Historians senses trouble and comes over to help. Apparently, they've been studying these monkeys for a while and have deciphered their secrets. + +Today, the Market is full of monkeys buying *good hiding spots*. Fortunately, because of the time you recently spent in this jungle, you know lots of good hiding spots you can sell! If you sell enough hiding spots, you should be able to get enough bananas to buy the device back. + +On the Market, the buyers seem to use random prices, but their prices are actually only [pseudorandom](https://en.wikipedia.org/wiki/Pseudorandom_number_generator)! If you know the secret of how they pick their prices, you can wait for the perfect time to sell. + +The part about secrets is literal, the Historian explains. Each buyer produces a pseudorandom sequence of secret numbers where each secret is derived from the previous. + +In particular, each buyer's *secret* number evolves into the next secret number in the sequence via the following process: + +* Calculate the result of *multiplying the secret number by `64`*. Then, *mix* this result into the secret number. Finally, *prune* the secret number. +* Calculate the result of *dividing the secret number by `32`*. Round the result down to the nearest integer. Then, *mix* this result into the secret number. Finally, *prune* the secret number. +* Calculate the result of *multiplying the secret number by `2048`*. Then, *mix* this result into the secret number. Finally, *prune* the secret number. + +Each step of the above process involves *mixing* and *pruning*: + +* To *mix* a value into the secret number, calculate the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the given value and the secret number. Then, the secret number becomes the result of that operation. (If the secret number is `42` and you were to *mix* `15` into the secret number, the secret number would become `37`.) +* To *prune* the secret number, calculate the value of the secret number [modulo](https://en.wikipedia.org/wiki/Modulo) `16777216`. Then, the secret number becomes the result of that operation. (If the secret number is `100000000` and you were to *prune* the secret number, the secret number would become `16113920`.) + +After this process completes, the buyer is left with the next secret number in the sequence. The buyer can repeat this process as many times as necessary to produce more secret numbers. + +So, if a buyer had a secret number of `123`, that buyer's next ten secret numbers would be: + +``` +15887950 +16495136 +527345 +704524 +1553684 +12683156 +11100544 +12249484 +7753432 +5908254 + +``` + +Each buyer uses their own secret number when choosing their price, so it's important to be able to predict the sequence of secret numbers for each buyer. Fortunately, the Historian's research has uncovered the *initial secret number of each buyer* (your puzzle input). For example: + +``` +1 +10 +100 +2024 + +``` + +This list describes the *initial secret number* of four different secret-hiding-spot-buyers on the Monkey Exchange Market. If you can simulate secret numbers from each buyer, you'll be able to predict all of their future prices. + +In a single day, buyers each have time to generate `2000` *new* secret numbers. In this example, for each buyer, their initial secret number and the 2000th new secret number they would generate are: + +``` +1: 8685429 +10: 4700978 +100: 15273692 +2024: 8667524 + +``` + +Adding up the 2000th new secret number for each buyer produces `*37327623*`. + +For each buyer, simulate the creation of 2000 new secret numbers. *What is the sum of the 2000th secret number generated by each buyer?* + +Your puzzle answer was `20071921341`. + +\--- Part Two --- +---------- + +Of course, the secret numbers aren't the prices each buyer is offering! That would be ridiculous. Instead, the *prices* the buyer offers are just the *ones digit* of each of their secret numbers. + +So, if a buyer starts with a secret number of `123`, that buyer's first ten *prices* would be: + +``` +3 (from 123) +0 (from 15887950) +6 (from 16495136) +5 (etc.) +4 +4 +6 +4 +4 +2 + +``` + +This price is the number of *bananas* that buyer is offering in exchange for your information about a new hiding spot. However, you still don't speak [monkey](/2022/day/21), so you can't negotiate with the buyers directly. The Historian speaks a little, but not enough to negotiate; instead, he can ask another monkey to negotiate on your behalf. + +Unfortunately, the monkey only knows how to decide when to sell by looking at the *changes* in price. Specifically, the monkey will only look for a specific sequence of *four consecutive changes* in price, then immediately sell when it sees that sequence. + +So, if a buyer starts with a secret number of `123`, that buyer's first ten secret numbers, prices, and the associated changes would be: + +``` + 123: 3 +15887950: 0 (-3) +16495136: 6 (6) + 527345: 5 (-1) + 704524: 4 (-1) + 1553684: 4 (0) +12683156: 6 (2) +11100544: 4 (-2) +12249484: 4 (0) + 7753432: 2 (-2) + +``` + +Note that the first price has no associated change because there was no previous price to compare it with. + +In this short example, within just these first few prices, the highest price will be `6`, so it would be nice to give the monkey instructions that would make it sell at that time. The first `6` occurs after only two changes, so there's no way to instruct the monkey to sell then, but the second `6` occurs after the changes `-1,-1,0,2`. So, if you gave the monkey that sequence of changes, it would wait until the first time it sees that sequence and then immediately sell your hiding spot information at the current price, winning you `6` bananas. + +Each buyer only wants to buy one hiding spot, so after the hiding spot is sold, the monkey will move on to the next buyer. If the monkey *never* hears that sequence of price changes from a buyer, the monkey will never sell, and will instead just move on to the next buyer. + +Worse, you can only give the monkey *a single sequence* of four price changes to look for. You can't change the sequence between buyers. + +You're going to need as many bananas as possible, so you'll need to *determine which sequence* of four price changes will cause the monkey to get you the *most bananas overall*. Each buyer is going to generate `2000` secret numbers after their initial secret number, so, for each buyer, you'll have *`2000` price changes* in which your sequence can occur. + +Suppose the initial secret number of each buyer is: + +``` +1 +2 +3 +2024 + +``` + +There are many sequences of four price changes you could tell the monkey, but for these four buyers, the sequence that will get you the most bananas is `-2,1,-1,3`. Using that sequence, the monkey will make the following sales: + +* For the buyer with an initial secret number of `1`, changes `-2,1,-1,3` first occur when the price is `*7*`. +* For the buyer with initial secret `2`, changes `-2,1,-1,3` first occur when the price is `*7*`. +* For the buyer with initial secret `3`, the change sequence `-2,1,-1,3` *does not occur* in the first 2000 changes. +* For the buyer starting with `2024`, changes `-2,1,-1,3` first occur when the price is `*9*`. + +So, by asking the monkey to sell the first time each buyer's prices go down `2`, then up `1`, then down `1`, then up `3`, you would get `*23*` (`7 + 7 + 9`) bananas! + +Figure out the best sequence to tell the monkey so that by looking for that same sequence of changes in every buyer's future prices, you get the most bananas in total. *What is the most bananas you can get?* + +Your puzzle answer was `2242`. + +Both parts of this puzzle are complete! They provide two gold stars: \*\* + +At this point, you should [return to your Advent calendar](/2024) and try another puzzle. + +If you still want to see it, you can [get your puzzle input](22/input). \ No newline at end of file diff --git a/2024/day22_monkey_market/src/lib.rs b/2024/day22_monkey_market/src/lib.rs new file mode 100644 index 0000000..c2b1dd5 --- /dev/null +++ b/2024/day22_monkey_market/src/lib.rs @@ -0,0 +1,109 @@ +use core::fmt::Display; +use std::{collections::{HashMap, HashSet}, num::ParseIntError}; + +#[derive(Debug, PartialEq, Eq)] +pub enum ParseError<'a> { + ParseIntError(std::num::ParseIntError), + LineMalformed(&'a str), +} + +impl From for ParseError<'_> { + fn from(value: ParseIntError) -> Self { + Self::ParseIntError(value) + } +} + +impl Display for ParseError<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::LineMalformed(v) => write!(f, "Line is malformed: {v}"), + Self::ParseIntError(e) => write!(f, "Unable to parse into integer: {e}"), + } + } +} + +fn next_secret(secret: usize) -> usize { + let mut secret = ((secret * 64) ^ secret) % 16777216; + secret = ((secret / 32) ^ secret) % 16777216; + ((secret * 2048) ^ secret) % 16777216 +} + +pub fn run(input: &str) -> Result<(usize, usize), ParseError> { + let mut secrets: Vec<_> = input.lines().map(|n| n.parse::()).collect::, _>>()?; + let mut mem = HashMap::new(); + secrets.iter_mut().for_each(|s| { + let mut seen = HashSet::new(); + let mut last_changes = Vec::with_capacity(4); + (0..4).for_each(|_| { + let next_secret = next_secret(*s); + let change = (next_secret % 10) as i8 - (*s % 10) as i8; + last_changes.push(change); + *s = next_secret; + }); + let last = (last_changes[0], last_changes[1], last_changes[2], last_changes[3]); + seen.insert(last); + mem.entry(last) + .and_modify(|price| *price += *s % 10) + .or_insert(*s % 10); + (4..2000).for_each(|_| { + let next_secret = next_secret(*s); + let change = (next_secret % 10) as i8 - (*s % 10) as i8; + last_changes.rotate_left(1); + last_changes[3] = change; + let last = (last_changes[0], last_changes[1], last_changes[2], last_changes[3]); + if !seen.contains(&last) { + mem.entry(last) + .and_modify(|price| *price += next_secret % 10) + .or_insert(next_secret % 10); + seen.insert(last); + } + *s = next_secret; + }); + }); + let first = secrets.iter().sum(); + let second = *mem.values().max().unwrap_or(&0); + Ok((first, second)) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs::read_to_string; + + fn read_file(name: &str) -> String { + read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string() + } + + #[test] + fn test_next() { + let expected = [ + 123, + 15887950, + 16495136, + 527345, + 704524, + 1553684, + 12683156, + 11100544, + 12249484, + 7753432, + 5908254, + ]; + expected.windows(2).for_each(|secrets| + assert_eq!(next_secret(secrets[0]), secrets[1]) + ); + } + + #[test] + fn test_sample() { + let sample_input = read_file("tests/sample_input"); + assert_eq!(run(&sample_input), Ok((37990510, 23))); + } + + #[test] + // #[ignore = "reason"] + fn test_challenge() { + let challenge_input = read_file("tests/challenge_input"); + assert_eq!(run(&challenge_input), Ok((20071921341, 2242))); + } +} diff --git a/2024/day22_monkey_market/tests/challenge_input b/2024/day22_monkey_market/tests/challenge_input new file mode 100644 index 0000000..52dd6ad --- /dev/null +++ b/2024/day22_monkey_market/tests/challenge_input @@ -0,0 +1,2397 @@ +10464004 +12619093 +15734299 +1948369 +7839229 +13345249 +11764600 +16346518 +8431009 +1408943 +7224409 +15178447 +3120276 +9319416 +11805113 +5288361 +12266326 +4494465 +9344573 +2576315 +16571547 +10748241 +3965080 +608620 +11913434 +13432980 +6323161 +11295660 +4656091 +1978581 +3677712 +9397110 +10324292 +12648692 +12063987 +16546028 +6645436 +5480430 +3998610 +10338860 +15010287 +16292381 +3870297 +5979028 +4605587 +5748790 +6363101 +1074342 +10560477 +12881528 +4607024 +12642427 +8755474 +4106938 +9430418 +11238280 +11447709 +13803277 +12744597 +500769 +14244258 +12340849 +6725813 +16362852 +7053427 +13130455 +7608758 +7547390 +12248334 +7104811 +8044779 +11211680 +10625730 +4276898 +11516349 +2783733 +5779287 +418689 +14418331 +15593096 +12689757 +15341808 +3614360 +10508086 +10781456 +1528343 +8193211 +6083704 +15284452 +2178739 +1358105 +3608924 +16351512 +382909 +2240641 +10884543 +4798388 +8826726 +6942317 +11787805 +694038 +11120050 +8825785 +6632520 +6518948 +5083235 +4865623 +2230081 +2167434 +8165541 +5216243 +12690306 +4832776 +2709726 +12026947 +14704201 +10704346 +277161 +7066698 +10455719 +7474228 +7166329 +5813655 +8373370 +6194222 +4295623 +12234502 +2226410 +15944203 +9362398 +4453192 +15344548 +12662900 +15060052 +12187588 +2744458 +1582523 +14824512 +16140337 +1700210 +8489850 +5733823 +4054904 +7619429 +12542779 +11399230 +6658342 +4670595 +16698469 +16406527 +5701355 +7618841 +1397176 +7524359 +11169587 +434216 +14278249 +15551306 +12892170 +16198702 +13642872 +15558709 +1267742 +5302537 +9055784 +13461322 +7860649 +16085350 +2270046 +7547967 +10919053 +12153472 +6856830 +6027890 +16378128 +8843700 +9612960 +1323773 +11992793 +9617904 +10992689 +10446244 +15499257 +3699952 +8726750 +10307616 +6887687 +10126069 +12492613 +8321495 +15534400 +6951111 +15495702 +9096971 +10273770 +6239392 +8589418 +442077 +13115920 +5489925 +9278902 +13802747 +3847389 +16143778 +12594250 +3161097 +1351854 +10101675 +12195146 +999911 +2503446 +3162786 +6868517 +10568908 +13569466 +3449084 +12620016 +7092496 +878877 +8755098 +8577672 +10315009 +1472521 +6298868 +7081524 +13773716 +7629380 +9876076 +16339591 +7459348 +5684973 +1989955 +12621146 +14864653 +6391742 +12513955 +16328014 +13025194 +3123724 +7767116 +279756 +12127123 +5309491 +11566977 +644458 +8757243 +6508956 +5052232 +3396022 +16358936 +2922600 +12237637 +4368034 +6959498 +2061610 +2874111 +13284468 +3624322 +5541598 +5969899 +1247420 +1459551 +3959480 +12235835 +3405543 +10509945 +14712826 +6274860 +10404627 +1303166 +15289194 +1887853 +7783004 +14889804 +11987870 +11103505 +10077259 +4510905 +12578418 +5673123 +1794572 +3952346 +2429124 +915945 +9240843 +3526287 +15998602 +8871498 +9467620 +15807222 +4945664 +6249951 +14142485 +1314628 +3162540 +3393235 +10653856 +2322972 +12689789 +1930763 +8094101 +6879200 +3040840 +5872832 +6703082 +15719936 +7493208 +5734470 +7749386 +4662070 +3888301 +9400878 +11553922 +6225351 +15452398 +13443208 +569500 +3829427 +5234417 +6434396 +13738524 +10479718 +2869509 +3133469 +5160006 +4713229 +8860929 +11130185 +5012999 +737555 +15064150 +8574087 +13959841 +2876807 +8093219 +6565859 +9822012 +12674348 +7986036 +10438986 +7457987 +4269052 +16671899 +12634342 +9507316 +14736519 +9522821 +6907261 +5967340 +13698892 +11115458 +15050733 +2414427 +2018960 +12868054 +4715351 +14720902 +168301 +9679913 +12802495 +10609020 +14196781 +9211314 +15134116 +3657008 +3032499 +11783472 +16198249 +768782 +3272646 +16015504 +15098955 +12297794 +6849431 +5168802 +8518450 +14813740 +13690471 +14253570 +7546570 +16013740 +10966415 +16216243 +5297135 +6579359 +3819102 +6973541 +4538602 +13967473 +5879603 +14066699 +6960324 +566231 +12108113 +3616468 +10687350 +4713153 +5574488 +14116634 +8143593 +16043563 +9826603 +1256531 +3850310 +15868646 +9045060 +13410681 +2109553 +12599927 +11980998 +9889973 +11058791 +2124034 +6810042 +9632145 +177310 +15194820 +11387608 +3884845 +10991785 +2238941 +10605046 +9610305 +7868388 +668164 +3086065 +8270360 +8214121 +3629753 +15975498 +4155836 +11136008 +4464775 +14061064 +15001321 +4930518 +14992246 +7980442 +7386730 +11300478 +6675015 +11575681 +1632449 +7040134 +14594023 +7026756 +14363126 +6162572 +9363874 +15417616 +12088233 +11487398 +3694777 +7971513 +3056209 +13301300 +9975968 +3759470 +5246440 +13539980 +3904444 +7087468 +13188062 +4059780 +5038689 +9103179 +13928571 +12883963 +8968960 +6345273 +8465289 +11889991 +9887179 +3795804 +5071640 +2709480 +2926979 +14725380 +1880839 +15303591 +2902564 +3221000 +2694098 +12913413 +4701162 +16025250 +16169709 +3875544 +13065621 +6343307 +1013182 +14369505 +10251019 +8088791 +9296368 +2494786 +2375000 +10701578 +734642 +7848171 +10343862 +6878068 +3718130 +1581135 +13737614 +1814641 +997241 +4301859 +15965830 +16178273 +1832750 +3505742 +14311013 +6783653 +3543452 +219585 +6765094 +7114141 +12478763 +15533464 +8976308 +3236566 +2343195 +14381734 +13924830 +14290441 +7876808 +12417883 +648079 +2706289 +7211564 +13659355 +8920522 +4573950 +7685638 +8123968 +12159504 +1174171 +1072744 +14392815 +7784839 +8093308 +15698905 +16521813 +11759570 +6012311 +6630514 +4569211 +3585487 +6117134 +12911555 +10517859 +15254610 +10384657 +7372935 +4187298 +4122818 +9108499 +6915676 +9198627 +8150207 +8240049 +11325695 +3346637 +13868613 +1585813 +921506 +16633462 +4554339 +9812452 +16299310 +3538292 +6740318 +8044638 +9062711 +2416151 +5874494 +11772743 +13441200 +6394951 +7067346 +15774841 +9144395 +4606179 +5479144 +14498725 +3489929 +10639473 +13781233 +6649280 +5042302 +150844 +7344476 +11899621 +13019949 +9907032 +15786987 +3203502 +3332196 +7513225 +3054793 +6109419 +3176402 +14368406 +6803843 +6446882 +7464941 +14730620 +15661826 +4119490 +10130721 +14604662 +14099070 +10490417 +15905906 +9481476 +4988584 +2270216 +13662888 +16422351 +8340405 +6707140 +10803610 +12501659 +1971117 +7648517 +10724391 +1238395 +10214418 +3234083 +7649758 +13431260 +2398799 +16381784 +12282135 +6950718 +5654629 +1564960 +4533468 +12306699 +15769370 +378531 +14032505 +13983588 +5646694 +6923776 +4222270 +14963073 +3567133 +13319211 +16430178 +7931366 +8660926 +3667176 +1545072 +15101082 +16361192 +14262735 +3421254 +10291553 +7680382 +398558 +14407126 +3917094 +3968614 +3873346 +14919799 +3068840 +14746572 +9359644 +6988498 +13163251 +6579005 +11713796 +16713939 +5515841 +3134263 +3302360 +6911047 +2773872 +9687241 +8799720 +14208042 +9953944 +6968448 +7697462 +6682576 +15241215 +5342287 +16714160 +9941318 +12734259 +5326655 +4129666 +10277507 +5410815 +2441091 +10363551 +15414814 +5062831 +16380720 +6553456 +8446545 +11491863 +15698685 +13023590 +15009582 +14779104 +7325849 +12171388 +5139184 +167375 +4940474 +13430889 +8549479 +15596493 +426895 +3323172 +7411545 +5985293 +15982155 +8276151 +13937860 +9895905 +11653515 +4801564 +14623942 +15641198 +9956794 +9394602 +7939305 +13831194 +9275416 +14993722 +223043 +15661849 +5884898 +1074589 +5185763 +10151042 +11139849 +11799085 +3875752 +15276048 +6733360 +6600602 +7199851 +2888380 +847867 +3520960 +10745393 +5375628 +10232199 +8505211 +9322681 +9039343 +16190619 +16591308 +2828395 +3640435 +9608024 +12116824 +2587232 +4502245 +1141876 +2712966 +10810552 +15804266 +13995396 +16027326 +15144234 +5488802 +11487924 +7667541 +4931876 +12319395 +14525230 +3664273 +4687729 +13093690 +12213163 +7902943 +6575810 +12735958 +5993489 +15483402 +4671990 +9159745 +12292487 +1541489 +14354014 +3718545 +13030274 +1275580 +12500146 +1267089 +6526715 +9517176 +15894182 +5821010 +13264811 +1507082 +16526478 +6035647 +11815508 +12618547 +2433945 +1579396 +14392606 +2839033 +11358618 +16069381 +979645 +6482500 +15831673 +6914275 +12251759 +521427 +11571362 +633575 +14797092 +16069974 +4417773 +12089951 +14020302 +1293432 +10366639 +10005099 +8306054 +6040703 +10211741 +1557501 +6610532 +10927579 +8026221 +5631533 +7020813 +3915913 +9053179 +2774214 +304749 +5770117 +6005481 +3792656 +658652 +4052687 +5013630 +11435350 +16296641 +3583892 +8576689 +3686888 +14286044 +5634781 +13565441 +10752017 +12965346 +9786149 +12433866 +132574 +7677289 +10621305 +16535692 +13523591 +9722918 +2667918 +11894899 +10258394 +9013830 +15362629 +4791607 +6676256 +3787295 +3569490 +3526716 +4103885 +9424032 +6915755 +8350321 +1840009 +14702040 +4836932 +5637222 +4190737 +9438603 +4953646 +14272346 +10415618 +3883532 +15235523 +15369744 +10582201 +4510167 +6226404 +6807671 +15778058 +15493607 +14794608 +8609303 +13012513 +4715403 +6580784 +16401266 +9882232 +7127925 +3234395 +12888652 +6342014 +5348584 +13579123 +16453418 +13103256 +13160024 +13441026 +903883 +11506619 +9279582 +3024861 +8861902 +4287815 +15629284 +9265186 +10698786 +5375104 +16257078 +15322633 +10086964 +2530470 +14689596 +11867563 +1132055 +12057746 +4634719 +515481 +2836798 +14535279 +14785410 +2892001 +10238631 +6949243 +4361273 +1094760 +6009710 +6008428 +3491276 +15696894 +4707375 +13659040 +13644205 +13949084 +4203647 +7491121 +15833058 +1842511 +1903929 +3138996 +10576509 +8088871 +16128553 +7614355 +14611569 +11414320 +688112 +13298110 +7240740 +14747646 +4510431 +1322222 +8340683 +7423961 +2076331 +260481 +2786839 +15241875 +2310321 +184777 +9385930 +7267430 +5859999 +4619676 +13475285 +12306147 +4683038 +7334881 +2175228 +14437377 +15871259 +6157348 +9684884 +1864864 +15836678 +11924004 +14121130 +15657381 +8964960 +9446661 +3973612 +11338685 +15349633 +592049 +9712865 +9563222 +3698822 +6031361 +12544609 +6660857 +16478671 +16039516 +9444107 +1275729 +5127271 +8795524 +2629656 +7748257 +15119907 +15869395 +6332741 +9522436 +477720 +3610929 +8544682 +10589476 +3809410 +13476318 +9944572 +6509903 +5059551 +10398304 +16573022 +6699197 +2134134 +3580371 +11271164 +11370744 +7826988 +8858725 +14221999 +3876545 +15535561 +368832 +12177541 +3956143 +7669386 +11167210 +9516917 +794336 +12020232 +16645989 +2275460 +14430115 +16152329 +7396388 +14842517 +2366942 +1235735 +2082427 +9283975 +12162816 +12079642 +16706605 +8585099 +235802 +12850802 +5047386 +14211739 +11184466 +1674840 +924258 +2807213 +15626597 +209023 +10309264 +8310925 +16119856 +16067903 +1154285 +7078281 +11256184 +8007306 +13759848 +10219731 +15089690 +13949771 +12321904 +2680367 +6653344 +7591356 +13413625 +7120281 +3894276 +2030449 +11072255 +12293838 +13083602 +16174278 +2544838 +415003 +14302048 +7492486 +3215169 +1235062 +3740889 +15704433 +14752884 +8459756 +2173489 +15614574 +5361410 +9059172 +4511929 +1355486 +8391083 +5054781 +10828794 +7474359 +5526023 +4702893 +13171213 +5979302 +4446377 +3115969 +14285830 +13524851 +9458532 +13308072 +12201330 +13073053 +10573463 +12567896 +9135848 +5090542 +6960428 +16776691 +1479611 +3881078 +4041254 +8046338 +1475244 +10123819 +1005509 +11329645 +6934293 +2057204 +11043972 +3780179 +5516445 +14423973 +150431 +1414911 +3798216 +13792253 +8055349 +16502003 +2430214 +7902039 +13695411 +634521 +11136701 +12710457 +14723294 +1305156 +393965 +11007364 +10067067 +15180851 +2791806 +4542584 +16753798 +4299994 +7490336 +16715057 +1331390 +2975542 +2643152 +9577132 +14576737 +7354576 +9955210 +9123041 +1712899 +15519531 +9229983 +3912095 +9108659 +7395229 +7130429 +4754301 +7064541 +7452415 +6216031 +14132779 +7289031 +13661575 +7733529 +6365422 +7064316 +4120521 +13678741 +15026229 +8682911 +7080016 +5930108 +11241824 +5062197 +5545056 +2766758 +555034 +2929489 +5032497 +13907176 +10890668 +15380314 +3446443 +15632565 +4400342 +16480426 +12499913 +13798159 +5800677 +1188145 +1097458 +6173333 +2067603 +12806694 +15374105 +4917035 +4724358 +7463238 +1221929 +7646879 +15798517 +5118650 +1905955 +13736464 +15798330 +1315318 +15604592 +12550271 +1364923 +3873422 +16219984 +2661350 +290230 +2588026 +1839298 +12592049 +2141208 +6380835 +4132151 +9466608 +15061165 +9375789 +13439518 +13726680 +15093853 +11957760 +4556511 +7548509 +1915473 +7624188 +11522051 +9973397 +3918666 +12089443 +6687511 +10711670 +3703642 +5014564 +8742319 +4511507 +4161461 +10996749 +11710721 +9819433 +4506393 +11728427 +4648675 +7576808 +8329411 +11665076 +13566838 +1194841 +13839248 +4690506 +3946654 +717196 +11522167 +5209885 +8916038 +1435864 +15934462 +7685923 +6031518 +2830580 +9400779 +11158651 +14077199 +5162619 +13147893 +14598656 +13342468 +5843866 +1074959 +16296458 +5610162 +14869301 +10603609 +8493692 +11953410 +15235466 +11141333 +15875210 +10999812 +6186667 +15358812 +4226501 +13081310 +1656746 +7400723 +8117390 +8127454 +2886938 +8815586 +15294820 +9602869 +9161194 +2920911 +12807743 +10876460 +8836625 +11731541 +225975 +12761299 +8758907 +11708916 +11883663 +9993984 +10146015 +14619739 +13456904 +9141240 +13207501 +7020204 +9907062 +16540264 +5301025 +7624820 +4937070 +15090544 +1084525 +12231393 +3250747 +6087419 +9570148 +15087091 +11165023 +6796629 +14058879 +2822697 +10267736 +16233698 +12702519 +2958930 +14029358 +504534 +11722224 +12386279 +2417925 +10439257 +12457392 +15064163 +5891911 +1294810 +5938713 +2375362 +3225339 +1110606 +1446074 +9230663 +12381811 +11189995 +5916925 +3765320 +6893425 +11680074 +16724263 +2392770 +1315575 +6991157 +14961096 +6883303 +8583397 +13788189 +5192423 +147923 +14590415 +13621753 +151993 +8513541 +3301311 +4043666 +11051098 +9081873 +1662422 +11229273 +5070902 +10664806 +14596184 +1730470 +8072485 +13389263 +4254762 +5249481 +11483165 +139432 +9137003 +2961522 +7163503 +5279357 +14492312 +10721043 +9223946 +6854922 +4064135 +2482772 +7934975 +9247813 +13217617 +2825528 +8072390 +8693566 +16309124 +8379017 +10061599 +16252764 +13872837 +16212250 +1313399 +3245690 +721811 +10062011 +9381293 +11618572 +3477986 +3472448 +2738899 +4630929 +12097504 +16255407 +6631759 +7796196 +3159177 +2090132 +10632687 +10874180 +5675373 +7906990 +4133939 +12242457 +1028491 +13750394 +2706657 +8787089 +7626526 +16409792 +7298622 +5180048 +4480741 +14796821 +2704100 +5423407 +14084743 +8754769 +446244 +5527682 +2845353 +13100061 +15627034 +14460416 +8114574 +2267500 +13075276 +16030026 +5951030 +8874522 +3294122 +15477940 +6816610 +12555287 +961264 +9400130 +14727991 +5182828 +16486493 +10892107 +13137122 +5576692 +930910 +14175300 +1655568 +15690737 +14413928 +13099457 +15709680 +14097859 +15696850 +15026608 +15877916 +15170725 +570502 +2089887 +6133446 +6865122 +7910604 +12621198 +13942138 +5592613 +7695400 +2133154 +15686101 +13077085 +1241681 +12170159 +16483271 +11723360 +2124224 +2333501 +13071425 +9368254 +15742204 +8271199 +8345207 +6923356 +1710076 +4679474 +365686 +133406 +4269918 +8052115 +12521778 +2888813 +12450554 +10507770 +14715898 +2352561 +7672447 +1338138 +15145455 +788141 +913979 +16542265 +2739946 +13088082 +9274885 +11695557 +12371499 +10004261 +1685872 +2862847 +491855 +10011437 +7467224 +13561611 +10004206 +13510253 +10862550 +6626055 +9732026 +12184890 +9998524 +9824794 +14349831 +10694965 +2963275 +4608959 +6649413 +10119040 +14549197 +217819 +9165879 +572540 +15578566 +6124359 +6614656 +9804254 +12533823 +14495456 +1570206 +12816357 +5434718 +5283879 +2245202 +10173285 +3099739 +4515513 +6575927 +2246396 +6871185 +4579589 +8558430 +12031451 +15161878 +453034 +8021418 +9191882 +6046193 +3023358 +6646779 +6951826 +7298366 +8241473 +330568 +6565006 +9750503 +6610165 +7328836 +16113957 +14146719 +3825099 +14305398 +16606722 +8152754 +934280 +10767183 +9012277 +2757643 +2033687 +10467153 +8166141 +2305113 +8000745 +15004185 +12373961 +5641917 +8714387 +1599720 +7171545 +8913840 +15977818 +10828596 +6198891 +14157293 +3807033 +10911675 +6614889 +15432997 +3582085 +7886775 +9888156 +7962909 +1497917 +13834472 +10424048 +4924793 +15116139 +1523602 +7425463 +997105 +7709966 +2192064 +8254946 +2839579 +10319401 +10740925 +9531629 +16117520 +10829971 +15650070 +2851796 +16409672 +13914451 +12650068 +5827429 +9733871 +16613671 +6241555 +16567934 +8062364 +9958928 +16330301 +1959464 +4402428 +5446740 +3709918 +4696340 +1292879 +10982862 +11118910 +876014 +2729736 +15666111 +1823964 +181742 +10859182 +2728366 +5357377 +5676656 +13804138 +8770122 +796129 +9045193 +720668 +1772916 +10426015 +11455056 +10415550 +14943208 +6381838 +14937983 +4688682 +1533245 +3146535 +14693178 +15535532 +11100950 +15723962 +4933275 +12811788 +3128480 +1410775 +1416541 +8773542 +10406527 +14885658 +11390619 +12219904 +16652685 +13696981 +12406994 +11923216 +13429950 +6333717 +10767933 +11116002 +7506074 +4777148 +9507594 +10404523 +16168904 +9808111 +11853247 +16307607 +1868800 +8816067 +12765673 +7715262 +8379622 +3503399 +5260891 +12390255 +6341112 +691917 +14000551 +12653038 +8954320 +10816860 +13582573 +4431424 +3463880 +4389862 +10688010 +5070874 +7582416 +8964208 +13427212 +2586959 +9798187 +10966856 +15349536 +16394305 +12661119 +3771591 +10908045 +12481732 +8604502 +10317156 +10873106 +13193677 +12562180 +16292837 +10111661 +202442 +10951255 +14231819 +8697384 +325428 +5776482 +8926266 +602580 +7998220 +9208071 +11009840 +8655262 +1147231 +13455038 +9231718 +6802499 +7618495 +13062482 +11220830 +4956518 +6103227 +4397360 +3076296 +5412241 +6451417 +2533891 +4354927 +478319 +9537385 +4190472 +12049811 +9162312 +4738992 +9744099 +12131969 +13656724 +11094384 +11928841 +13813070 +5009029 +2657951 +3471446 +14672068 +5847749 +8354147 +6914970 +4479731 +2959098 +10215909 +11702843 +5167910 +4791190 +2095464 +13430628 +9071753 +715301 +2719853 +14490951 +16008039 +3549623 +7965189 +2725215 +666747 +13719326 +6674592 +1528223 +2817712 +4222863 +1696165 +13636287 +8334722 +11710169 +13240055 +3259614 +5901852 +5363837 +2230595 +2862281 +13111652 +6601781 +13247861 +1778001 +263773 +15282664 +2874396 +5308419 +13707352 +4343476 +15189170 +8673188 +7823611 +11922360 +9361889 +15941574 +9612384 +13059896 +10274990 +12976044 +736054 +12675407 +4619346 +8446621 +12443995 +10036644 +3898632 +829602 +1051677 +15678378 +14217887 +3877759 +8663076 +9422267 +7798225 +15099001 +458982 +9278643 +12617368 +8749908 +7032964 +8919318 +14355365 +6878608 +13960207 +3713906 +2752761 +6556101 +13484873 +8866707 +4328244 +13889921 +13105500 +827442 +6366167 +10758101 +16464708 +9465622 +5196257 +3428159 +4943405 +505650 +508807 +3555898 +5054856 +16763635 +2665140 +975437 +1434449 +13793285 +11413498 +9104630 +13115048 +9478889 +11638839 +12533818 +8317642 +11822904 +14561773 +931118 +2261067 +2910459 +4030842 +555305 +4102557 +3188574 +3424489 +1751475 +13529051 +10673429 +16269791 +10151842 +11289399 +1431064 +15534184 +2907709 +1719450 +15047876 +5807328 +13379416 +727402 +389441 +7496742 +6777054 +12876024 +13571311 +6189177 +9174590 +14360992 +3143621 +576752 +15256727 +13457498 +12887781 +15690342 +5811841 +11269434 +16339288 +11227383 +15157139 +6330428 +6824343 +6677972 +836551 +15923389 +8834969 +15918070 +14864142 +13323496 +4812651 +15999175 +12712277 +14424774 +8671930 +13335859 +15894098 +11872140 +2525293 +2240969 +8409703 +15516001 +9618269 +5098164 +7287252 +3356942 +8214606 +15798306 +10873198 +6312381 +9054889 +1131164 +965347 +13161041 +6772482 +9607732 +11884149 +1225694 +5585222 +2362650 +15264754 +9302091 +7803483 +16371514 +6281317 +8870219 +11830608 +3842777 +11538661 +11640751 +2020992 +5466878 +5875816 +7381826 +3419879 +12979539 +11770488 +15069558 +7144087 +2735055 +264735 +7998091 +11563632 +6780933 +8079132 +14972695 +5269125 +15131715 +7718651 +16588906 +8714019 +8401629 +15116134 +4573881 +6506009 +11453457 +3133011 +5400000 +15294475 +14837720 +333684 +9463080 +3951999 +6651026 +3321752 +330477 +7326987 +2266943 +1800781 +2552032 +10609247 +12906283 +1740616 +6025328 +9277700 +8679267 +11741117 +1599216 +8375414 +4762943 +5640937 +13678053 +879041 +10929747 +12751009 +10129418 +7548950 +16161502 +7965641 +215638 +13958584 +7232874 +6299935 +1573253 +14238806 +10944210 +5268401 +14108294 +15813449 +6006827 +449488 +1399717 +14159456 +9757761 +2980440 +3825447 +15535247 +4788562 +9964616 +8940525 +5880492 +2460556 +12959183 +10777241 +9624154 +3877514 +672520 +1631179 +4254860 +5058960 +12505999 +7346998 +16060548 +4641962 +13602891 +14782827 +1870814 +4500997 +15213447 +6177984 +1514781 +8437753 +1550002 +5535222 +6436939 +3560212 +3080640 +5507306 +15399848 +9151817 +14430784 +5616152 +15571163 +594401 +1117942 +11930785 +9839855 +10308210 +2114480 +14225159 +13123161 +13316391 +9319368 +16629005 +8860569 +13354500 +7680918 +8382431 +7192127 +16637085 +6411720 +8462560 +15394067 +165796 +7590987 +7562409 +12454820 +10779978 +7409955 +5208058 +5240306 +3501057 +10759457 +3626436 +7922420 +2237556 +8379679 +5478644 +7315553 +7967949 +12471514 +5671951 +9460959 +14834778 +3083563 +8184214 +7617208 +15982237 +6554843 +4212627 +1600584 +2845535 +8723383 +14722257 +6069224 +892974 +9933344 +11355138 +6892190 +11173847 +7444379 +3819056 +3244726 +16637928 +12999777 +1837014 +2516347 +5002277 +13166654 +370800 +12076174 +9657879 +3737450 +12150863 +3530714 +2008136 +11003970 +15088169 +13074393 +13808578 +7411239 +3781170 +6367434 +6440849 +3576295 +9748777 +15824291 +8083338 +2904664 +8557700 +5359863 +10807982 +3843057 +11471493 +5899648 +6986630 +4263782 +3655697 +11589607 +1327020 +2539829 +8706794 +9703023 +7121014 +275048 +5798928 +15845695 +9110303 +10754212 +9494596 +2305731 +9641043 +6597819 +380331 +12808696 +7892773 +1580793 +15530813 +12551349 +13058955 +6801977 +10550709 +9037012 +2924135 +14503642 +10812575 +15280312 +6088173 +4872072 +701796 +5494014 +3537601 +11091857 +16115764 +5546546 +3166628 +1194107 +11630670 +9874715 +4398285 +10726962 +3404824 +11177641 +6074417 +1477123 +11296640 +11761857 +2849512 +11489365 +12898594 +15145744 +9618125 +8249000 +11036404 +10755486 +1437677 +9335602 +5918303 +12305988 +15328549 +9996296 +14021684 +8270126 +2128717 +5408069 +14884656 +338773 +7186138 +7353187 +9423481 +6879080 +8824233 +1225810 +6189335 +477638 +10841508 +15753878 +5266956 +7521836 +896681 +8701161 +13308870 +4647239 +3498912 +9338528 +4089403 +4270298 +5575214 +13120569 +15350634 +806429 +13792919 +4875280 +1419946 +15380205 +15404178 +5279849 +8280789 +5405383 +2383549 +11492725 +11753036 +8343537 +233246 +11321134 +13645949 +13415165 +7636176 +6783791 +16488408 +7913139 +3313512 +11511266 +6108911 +12311464 +14364923 +10775473 +16057589 +5039371 +3851713 +1921487 +1035958 +14199538 +2338168 +15989420 +5444348 +8261905 +5752922 +547568 +11038016 +5923580 +9566540 +9761051 +10225041 +662565 +10877530 +13354732 +3625438 +264556 +608535 +12755882 +4059357 +15467424 +1441667 +7089517 +6002516 +10073432 +12051806 +3928188 +9820864 +7604874 +9064083 +871087 +7626263 +9872573 +8976182 +6762697 +1024958 +7441200 diff --git a/2024/day22_monkey_market/tests/sample_input b/2024/day22_monkey_market/tests/sample_input new file mode 100644 index 0000000..201df76 --- /dev/null +++ b/2024/day22_monkey_market/tests/sample_input @@ -0,0 +1,4 @@ +1 +2 +3 +2024