Skip to content

Commit

Permalink
Update docs on Wed Dec 25 06:14:29 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 25, 2024
1 parent d80c559 commit 98d20f1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions 2024/22/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ <h2 id="problem-name">Monkey Market</h2>
class Solution : Solver {

public object PartOne(string input) {
return GetNums(input).Select(x =&gt; (long)SecretNumbers(x).Last()).Sum();
return GetNums(input).Select(x =&gt; (long)SecretNumbers(x).Last()).Sum();
}

public object PartTwo(string input) {
Expand All @@ -305,7 +305,7 @@ <h2 id="problem-name">Monkey Market</h2>
var buyingOptions = new Dictionary&lt;string, int&gt;();
foreach (var num in GetNums(input)) {
var optionsBySeller = BuyingOptions(num);
foreach(var seq in optionsBySeller.Keys){
foreach (var seq in optionsBySeller.Keys) {
buyingOptions[seq] = buyingOptions.GetValueOrDefault(seq) + optionsBySeller[seq];
}
}
Expand All @@ -320,24 +320,24 @@ <h2 id="problem-name">Monkey Market</h2>
// a sliding window of 5 elements over the sold bananas defines the sequence the monkey
// will recognize. add the first occurrence of each sequence to the buyOptions dictionary
// with the corresponding banana count
for (var i = 5;i &lt; bananasSold.Length; i++) {
var slice = bananasSold[(i-5) .. i];
var seq = string.Join(&quot;,&quot;, Diff(slice));
for (var i = 0; i &lt;= bananasSold.Length - 5; i++) {
var slice = bananasSold[i..(i + 5)];
var seq = string.Join(&quot;,&quot;, Diff(slice));
if (!buyOptions.ContainsKey(seq)) {
buyOptions[seq] = slice.Last();
}
}
return buyOptions;
}
int[] Bananas(int seed) =&gt; SecretNumbers(seed).Select(n =&gt; n % 10).ToArray();
int[] Bananas(int seed) =&gt; SecretNumbers(seed).Select(n =&gt; n % 10).ToArray();

int[] Diff(IEnumerable&lt;int&gt; x) =&gt; x.Zip(x.Skip(1)).Select(p =&gt; p.Second - p.First).ToArray();

IEnumerable&lt;int&gt; SecretNumbers(int seed) {
var mixAndPrune = (int a, long b) =&gt; (int)((a ^ b) % 16777216);

yield return seed;
for(var i = 0;i&lt; 2000;i++) {
for (var i = 0; i &lt; 2000; i++) {
seed = mixAndPrune(seed, seed * 64L);
seed = mixAndPrune(seed, seed / 32L);
seed = mixAndPrune(seed, seed * 2048L);
Expand Down

0 comments on commit 98d20f1

Please sign in to comment.