Skip to content

Commit

Permalink
added halving element
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSecondComing123 committed Apr 25, 2022
1 parent 5e112f4 commit 1cf0e7b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codepage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FUNCTIONS = []
FUNCTIONS += ["+", "-", "×", "÷", "ⁱ", "g", "¶", "Đ"]
FUNCTIONS += ["Ŋ", "Ƣ", "!", "¡", "□", "i", "s", "t"]
FUNCTIONS += ["h"]
FUNCTIONS += ["h", "½"]

INDICATORS = ["↹", "{", "}"]

Expand Down
4 changes: 4 additions & 0 deletions element_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ def head(a: str, b: int):

def tail(a: str, b: int):
return a[b:]


def halvestr(a: str):
return a[:len(a) // 2]
3 changes: 2 additions & 1 deletion elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def __call__(self, *args, **kwargs):
"i": Element(arity=2, func=Index),
"s": Element(arity=3, func=Slice),
"h": Element(arity=2, func=Head),
"t": Element(arity=2, func=Tail)
"t": Element(arity=2, func=Tail),
"½": Element(arity=1, func=Halve)
}
7 changes: 7 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,10 @@ def Head(a, b, ctx=None):

def Tail(a, b, ctx=None):
return tail(safe_cast(a, str), safe_cast(b, int))


def Halve(a, ctx=None):
if typecheck(args=[a], types=[int]):
return divide(a, 2)
elif typecheck(args=[a], types=[str]):
return halvestr(a)

0 comments on commit 1cf0e7b

Please sign in to comment.