Skip to content

Commit

Permalink
add under for sort
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Sep 6, 2024
1 parent a628fab commit cb348ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/algorithm/invert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,17 @@ pub(crate) fn under_instrs(
(CopyToUnder(1), Fall, Dup, Rise, PushToUnder(1)),
(PopUnder(1), Select, PopUnder(1), Flip, Select)
),
// Sort
&pat!(
Sort,
(Dup, Rise, CopyToUnder(1), Select),
(PopUnder(1), Rise, Select),
),
&pat!(
SortDown,
(Dup, Fall, CopyToUnder(1), Select),
(PopUnder(1), Rise, Select),
),
// Index of
&maybe_val!(pat!(
IndexOf,
Expand Down
6 changes: 6 additions & 0 deletions tests/under.ua
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,9 @@ G ← ⍜(⊙⊙⊢) ⋅⊙∘
⍤⟜≍: "2 - 4" ⍜°$"_ - _"∩(×2⋕) "1 - 2"
⍤⟜≍: [1 20 30] ⍜°(⊂1)(×10) [1 2 3]
⍤⟜≍: map 2_1 4_30 ⍜°(insert1)(×10) map 1_2 3_4

# Experimental!

# Sort
⍤⟜≍: [4000 20 300 1] ⍜⍆(×ⁿ:10°⊏) [4 2 3 1]
⍤⟜≍: [4 200 30 1000] ⍜(⇌⍆|×ⁿ:10°⊏) [4 2 3 1]

0 comments on commit cb348ae

Please sign in to comment.