Skip to content

ffseq/adventofcode2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

adventofcode2022

My various solutions for Advent of Code 2022

Day 1

# Utils from BQNcrate
Split  ((-˜+`׬)=)
ToNum  (10×+˜´-'0')

# Sample data
data  "1000
2000
3000

4000

5000
6000

7000
8000
9000

10000"

# Parsing is the hard part
Parse  {
  # Prepending newline makes things easier later
  data @+10⟩∾𝕩
  # Each blank line looks like two 1's on a 2 window equals mask
  # "Find" these 1 1 windows, deshape
  # The window function reduces length by one, joining a 0 corrects for this...
  # ...so we can do a plus scan
  mask  +` 0∾ ⥊ 11 2↕ (@+10)=data
  # Group using mask, split on each subarray by newline, then drop the first empty list in each subarray
  # And convert to decimal from string with ToNum on depth 1
  ToNum1 1¨(@+10)Split¨ maskdata
}

# Solution itself is cake
SolutionPart1  ´+´¨Show SolutionPart1 Parse data

SolutionPart2  {+´3+´¨𝕩}

SolutionPart2 Parse data

Day 2

# Utils from BQNcrate
Split  ((-˜+`׬)=)

input  "A Y
B X
C Z
"
input ↩ (@+10) Split input

# Trick is realizing all 9 possible combos map 1-1 with integers 1-9,
# so we can use indexing in a simple list + 1
Score 1+"B X"
"C Y"
"A Z"
"A X"
"B Y"
"C Z"
"C X"
"A Y"
"B Z"
⟩⊐<

# Part 1Show +´ Score¨ input

# Part 2 is identical, just a different mapping
Score 1+"B X"
"C X"
"A X"
"A Y"
"B Y"
"C Y"
"C Z"
"A Z"
"B Z"
⟩⊐<

+´ Score¨ input

Day 3

# Utils from BQNcrate
Split  ((-˜+`׬)=)

input  "vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"

Halve  ((÷2˙)·↕)⊸⊔
FindLetter  ⊑ (⊑1⊸⊑)⊸/⟜⊑


prioritystring  ('a'+26)∾'A'+26
Priority 1+prioritystring⊸⊐

+´ PriorityFindLetterHalve¨ ((@+10) Split input)

About

My various solutions for Advent of Code 2022

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published