Skip to content

Commit

Permalink
Add a next multiple element (∆*)
Browse files Browse the repository at this point in the history
Closes #1377
  • Loading branch information
lyxal committed Aug 6, 2022
1 parent fb5cf52 commit b398360
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions documents/knowledge/elements.yaml
Expand Up @@ -1352,7 +1352,7 @@
- "[[3,1,2]] : [1,2,3]"
- "[312] : 123"
- '["bca"] : "abc"'
- '[0] : 0'
- "[0] : 0"

- element: "t"
name: Tail
Expand Down Expand Up @@ -4391,6 +4391,19 @@
- "[6] : [1, 1]"
- "[4] : [2]"

- element: "∆*"
name: Next Multiple
arity: 2
description: Get the next multiple of a number greater than another number
overloads:
num, num: get the next multiple of b that is greater than a
vectorise: true
tests:
- "[6, 5] : 10"
- "[4, 5] : 5"
- "[5, 5] : 10"
- "[0, -1] : -1"

- element: "øb"
name: Parenthesise
arity: 1
Expand Down Expand Up @@ -4553,7 +4566,7 @@
tests:
- '["ababa", "aba"] : 2'
- '["bbba", "ba"] : 1'
- '[[1, 2, 2, 1, 2, 1], [1, 2]] : 2'
- "[[1, 2, 2, 1, 2, 1], [1, 2]] : 2"
- '[[3, "3", 3, "3", 3], [3, "3", 3]] : 2'

- element: "øV"
Expand Down
12 changes: 12 additions & 0 deletions vyxal/elements.py
Expand Up @@ -3361,6 +3361,17 @@ def newline_split(lhs, ctx):
}.get(vy_type(lhs), lambda: vectorise(newline_split, lhs, ctx=ctx))()


def next_multiple(lhs, rhs, ctx):
"""Element ∆*
(num, num) -> get the next multiple of b that is greater than a
"""

ts = vy_type(lhs, rhs)
return {
(NUMBER_TYPE, NUMBER_TYPE): lambda: lhs + rhs - lhs % rhs,
}.get(ts, lambda: vectorise(next_multiple, lhs, rhs, ctx=ctx))()


def next_prime(lhs, ctx):
"""Element ∆Ṗ
(num) -> next prime after a
Expand Down Expand Up @@ -6631,6 +6642,7 @@ def zfiller(lhs, rhs, ctx):
"∆›": process_element(increment_until_false, 2),
"∆‹": process_element(decrement_until_false, 2),
"∆ǐ": process_element(prime_exponents, 1),
"∆*": process_element(next_multiple, 2),
"øḂ": process_element(angle_bracketify, 1),
"øḃ": process_element(curly_bracketify, 1),
"øb": process_element(parenthesise, 1),
Expand Down

0 comments on commit b398360

Please sign in to comment.