main
aprzn 1 year ago
parent d7a938783f
commit f0be378b5a

@ -1,6 +1,6 @@
PartI ← ( PartI ← (
▽×⊃(≤@9|≥@0|∘) # digits only ▽×⊃(≤@9|≥@0|∘) # digits only
parse⊟⊃(⊢|⊢⇌) # add them together ⋕⊟⊃(⊢|⊢⇌) # add them together
) )
PartII ← ( PartII ← (

@ -10,10 +10,10 @@ TestInput ←
# Original parsing solution # Original parsing solution
Colors ← {"red" "green" "blue"} Colors ← {"red" "green" "blue"}
Parse ← ( Parse ← (
⊢⇌↘1 regex "Game (\\d+): (.*)" °□⊢⇌↘1 regex "Game (\\d+): (.*)"
⊜(□⊜(⇌⊜((parse⊔⋅∘|⊙;)<3.⊃(⊗⊙Colors|∘)□)≠@ .)≠@,.)≠@;. ⊜(□⊜(⇌⊜((⋕°□⋅∘|⊙;)<3.⊃(⊗⊙Colors|∘)□)≠@ .)≠@,.)≠@;.
≡( ≡(
∧(⍜⊡+⊙:⍘⊟)⊃⊔0_0_0 ∧(⍜⊡+⊙:°⊟)⊃°□0_0_0
) )
) )
@ -21,7 +21,7 @@ Parse ← (
ColorsII ← "rgb" ColorsII ← "rgb"
ParseII ← ( ParseII ← (
↘+2⊗@:. ↘+2⊗@:.
⬚0⊜(⊕∘⍘⊟⍉∵(⊟⊃(⊗⊙ColorsII⊢|parse↘2)⇌⊔) regex "\\d+ [rgb]")≠@;. ⬚0⊜(⊕∘°⊟⍉∵(⊟⊃(⊗⊙ColorsII⊢|⋕↘2)⇌°□) regex "\\d+ [rgb]")≠@;.
↯¯1_3 ↯¯1_3
) )

@ -12,8 +12,8 @@ TestInput ←
Table ← ⊜(⊂:@.)≠@\n. Table ← ⊜(⊂:@.)≠@\n.
Adjacency ← ↯¯1_2-1⇡3_3 Adjacency ← ↯¯1_2-1⇡3_3
Numbers ← ⊜parse×⊃(≤@9|≥@0).♭ Numbers ← ⊜×⊃(≤@9|≥@0).♭
Classify ← ⍜(♭|⍜(⊜□|≡(□↯⧻)⊃(∘|+@\x80⇡⧻))×⊃(≤@9|≥@0).) Classify ← ⍜(♭|⍜(⊜□|≡(□↯⧻°□)⊃(∘|+@\x80⇡⧻))×⊃(≤@9|≥@0).)
PartI ← ( PartI ← (
×⊃(<@\x80|≠@.|∘) ×⊃(<@\x80|≠@.|∘)
@ -25,7 +25,7 @@ PartII ← (
⊚=@*. ⊚=@*.
⊠+:Adjacency ⊠+:Adjacency
≡(□⊝▽≥@\x80.≡(⊡)⊙¤)⊙¤ ≡(□⊝▽≥@\x80.≡(⊡)⊙¤)⊙¤
/+≡(/×⊏-@\x80)⊙¤▽=2≡⧻. /+≡(/×⊏-@\x80°□)⊙¤▽=2≡⧻.
) )
⊃(Classify|Numbers) Table TestInput ⊃(Classify|Numbers) Table TestInput

@ -6,7 +6,7 @@ $ Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
$ Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 $ Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
TestInput ← TestInput ←
Parse ← ∩(⊜parse≠@ .⊔)⍘⊟⊏1_3 ⊢regex "((\\d+\\s+)+)\\|((\\s+\\d+)+)" Parse ← ∩(⊜⋕≠@ .°□)°⊟⊏1_3 ⊢regex "((\\d+\\s+)+)\\|((\\s+\\d+)+)"
PartIPre ← ⌊ⁿ:2-1/+♭⊞=Parse PartIPre ← ⌊ⁿ:2-1/+♭⊞=Parse
PartIPost ← /+ PartIPost ← /+

@ -34,19 +34,19 @@ $ 56 93 4
TestInput ← TestInput ←
PartI ← ( PartI ← (
↘6⊃⊢(↘1)⊜□≠@\n. ↘6°□⊃⊢(↘1)⊜□≠@\n.
⊓( ⊓(
parse≠@ . ≠@ .
| ∧( | ∧(
>@9⊢. >@9⊢.°□
(⍜(⊔⊢⇌|(⊂|¤;)type.):⊜parse≠@ .|⊂⊙i;) (⍜(°□⊢⇌|(⊂|¤;)type.):⊜⋕≠@ .|⊂⊙i;)
)⊙{} )⊙{}
) )
∧( ∧(
+×⊙¬⊃⋅∘( +×⊙¬⊃⋅∘(
¤ °□¤
∩/+≡( ∩/+≡(
[⊙⊙∘] °[⊙⊙∘]
×⊃(≥⋅⊙⋅∘|<+⋅⊙⊙∘|:-:⊙⊙⋅∘) ×⊃(≥⋅⊙⋅∘|<+⋅⊙⊙∘|:-:⊙⊙⋅∘)
⊃∘×⊙+ ⊃∘×⊙+
) )
@ -56,27 +56,27 @@ PartI ← (
Prune ← ▽≡(≠0⊢⇌). Prune ← ▽≡(≠0⊢⇌).
PartII ← ( PartII ← (
↘6⊃⊢(↘1)⊜□≠@\n. ↘6°□⊃⊢(↘1)⊜□≠@\n.
⊓( ⊓(
↯¯1_2⊜parse≠@ . ↯¯1_2⊜≠@ .
| ∧( | ∧(
>@9⊢. >@9⊢.°□
( (
parse≠@ . ≠@ .
[⊙⊙∘]⊃(⋅∘|⋅⋅∘|-:) °[⊙⊙∘]⊃(⋅∘|⋅⋅∘|-:)
⍜(⊢⇌|(⊂|¤;)type.): ⍜(°□⊢⇌|(⊂|¤;)type.):
| ⊂⊙i; | ⊂⊙i;
) )
)⊙{} )⊙{}
) )
: :
∧( ∧(
⊙⊙[] ⊙⊙[]°□
∧( ∧(
⊙⊙[] ⊙⊙[]
∧( ∧(
⊙(↙2.) ⊙(↙2.)
≡\-◫2[⊃(∘|↧↥⊙:⊙⊙∘|↥⊙↧⊙⊙⋅∘|⋅∘)]∩⊟∩\+ ≡\-◫2[⊃(∘|↧↥⊙:⊙⊙∘|↥⊙↧⊙⊙⋅∘|⋅∘)]∩°⊟∩\+
⊃(⋅∘|Prune⊂⊏0_2⊙⋅∘|Prune⊂¤⍜⊢+⊡1⊙(⊡2)⊙⊙⋅∘) ⊃(⋅∘|Prune⊂⊏0_2⊙⋅∘|Prune⊂¤⍜⊢+⊡1⊙(⊡2)⊙⊙⋅∘)
): ):
; ;

@ -2,11 +2,11 @@ $ Time: 7 15 30
$ Distance: 9 40 200 $ Distance: 9 40 200
TestInput ← TestInput ←
Quadratic ← ⊃+-⊃(⍜√+|∘)⊃(¯÷×2|¯÷⊙⋅∘) Quadratic ← ⊃+-⊃(⍜°√+|∘)⊃(¯÷×2|¯÷⊙⋅∘)
Solve ← -1-:⊓⌈⌊ Quadratic ¯1 ⊙¯ Solve ← -1-:⊓⌈⌊ Quadratic ¯1 ⊙¯
PartI ← /× Solve ≡⍘⊟ ⍉⊜(⊜parse≠@ .↘9)≠@\n. PartI ← /× Solve ≡°⊟ ⍉⊜(⊜⋕≠@ .↘9)≠@\n.
PartII ← Solve ⍘⊟ ⍉⊜(parse▽≠@ .↘9)≠@\n. PartII ← Solve °⊟ ⍉⊜(⋕▽≠@ .↘9)≠@\n.
PartI TestInput PartI TestInput
PartII TestInput PartII TestInput

Loading…
Cancel
Save