Skip to content

Commit

Permalink
day 22 uiua
Browse files Browse the repository at this point in the history
  • Loading branch information
KatieLG committed Dec 22, 2024
1 parent 0c843e0 commit 46a5198
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
13 changes: 9 additions & 4 deletions AOC/uiua/helpers/input.ua
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Strip ↚ ▽≠,@\r # remove any carriage returns

ReadInput ← (
&fras $"../data/_/dataset.txt" # read data
▽≠,@\r # remove any carriage returns
Strip
)

ReadSample ← (
ReadSample₁ ← (
&fras $"../data/_/sample\_part\_one.txt" # read data
▽≠,@\r # remove any carriage returns
Strip
)
ReadSample₂ ← (
&fras $"../data/_/sample\_part\_two.txt" # read data
Strip
)
15 changes: 12 additions & 3 deletions AOC/uiua/solutions/day22.ua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ Input ← (
⊜⋕≠,@\n
)

Xor ← °⋯⬚0≠∩⋯ # bitwise or
Mp ← ◿16777216 Xor # Mix and prune
Process ← Mp⊸×₂₀₄₈Mp⌊⊸÷₃₂Mp⊸×₆₄ # Process a secret
Xor ← °⋯⬚0≠∩⋯ # bitwise or
Mp ← ◿16777216 Xor # Mix and prune
Process ← memo(Mp⊸×₂₀₄₈Mp⌊⊸÷₃₂Mp⊸×₆₄) # Process a secret
Bananas ← ⇌◿10[⍥⊸Process2001] # bananas per secret
Diff ← -∩↘₁⊸↻₋₁◿10 # differences between bananas

# Part A
Input
/+⍥Process2000 # sum up after 2000 iterations of processing

# Part B
Input
⊸≡Diff≡Bananas # get differences between banana sales
◴♭₂≡(⧈∘4).⊙¤ # find the unique length 4 difference tuples
≡(/+≡⍣(⊡+4⊢⊚)0⌕)⊙¤ # find the sum of sales for each tuple
/↥ # take the best one
9 changes: 9 additions & 0 deletions AOC/uiua/tests/test_solutions.ua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Expected ← (
{"1,5,0,1,7,4,1,0,3" 47910079998866} # day 17
{322 "60,21"} # day 18
{226 601201576113503} # day 19
{1363 1007186} # day 20
{278748 ∞} # day 21
{14726157693 1614} # day 22
]
)
SolutionMap ← map+1⇡⊸⧻Expected
Expand Down Expand Up @@ -110,3 +113,9 @@ TestDay 18
now
~ "../solutions/day19.ua"
TestDay 19

SkipDay 20 "Runtime is too long"

SkipDay 21 "No solution"

SkipDay 22 "Runtime is too long"

0 comments on commit 46a5198

Please sign in to comment.